source: extensions/typetags/include/events_public.inc.php @ 26855

Last change on this file since 26855 was 26855, checked in by mistic100, 10 years ago

add strip_tags in meta keywords

File size: 4.1 KB
Line 
1<?php
2defined('TYPETAGS_PATH') or die('Hacking attempt!');
3
4/**
5 * triggered by 'render_tag_name'
6 */
7function typetags_render($tag_name, $tag=array())
8{
9  global $pwg_loaded_plugins, $page, $typetags_cache;
10
11  if (defined('IN_ADMIN') and in_array($page['page'], array('photo', 'batch_manager', 'tags')))
12  {
13    return $tag_name;
14  }
15
16  if (isset($typetags_cache['tags'][$tag_name]))
17  {
18    return $typetags_cache['tags'][$tag_name];
19  }
20
21  if (!isset($typetags_cache['colors']))
22  {
23    $query = '
24SELECT id, color
25  FROM ' . TYPETAGS_TABLE . '
26;';
27    $typetags_cache['colors'] = query2array($query, 'id', 'color');
28  }
29
30  if (!empty($tag['id_typetags']))
31  {
32    $color = $typetags_cache['colors'][ $tag['id_typetags'] ];
33  }
34  else
35  {
36    if (isset($tag['id']))
37    {
38      $where = 't.id = ' . $tag['id'];
39    }
40    else
41    {
42      $where = 't.name = "' . pwg_db_real_escape_string($tag_name) . '"';
43    }
44
45    $query = '
46SELECT color
47  FROM ' . TYPETAGS_TABLE . ' AS tt
48    INNER JOIN ' . TAGS_TABLE . ' AS t
49    ON t.id_typetags = tt.id
50  WHERE ' . $where . '
51;';
52    list($color) = pwg_db_fetch_row(pwg_query($query));
53  }
54
55  if ($color === null)
56  {
57    $ret = $tag_name;
58  }
59  elseif (isset($pwg_loaded_plugins['ExtendedDescription']))
60  {
61    $ret = '[lang=all]<span style="color:' . $color . ';">[/lang]' . $tag_name . '[lang=all]</span>[/lang]';
62  }
63  else
64  {
65    $ret = '<span style="color:' . $color . ';">' . $tag_name . '</span>';
66  }
67
68  $typetags_cache['tags'][$tag_name] = $ret;
69  return $ret;
70}
71
72/**
73 * colors tags on picture page
74 */
75/*function typetags_picture()
76{
77  global $template;
78
79  $tags = $template->get_template_vars('related_tags');
80  if (empty($tags)) return;
81
82  $query = '
83SELECT
84    t.id ,
85    tt.color
86  FROM '.TYPETAGS_TABLE.' AS tt
87    INNER JOIN '.TAGS_TABLE.' AS t
88      ON t.id_typetags = tt.id
89  WHERE t.id_typetags IS NOT NULL
90;';
91  $tagsColor = simple_hash_from_query($query, 'id', 'color');
92  if (empty($tagsColor)) return;
93
94  foreach ($tags as $key => $tag)
95  {
96    if (isset($tagsColor[ $tag['id'] ]))
97    {
98      $tags[$key]['URL'].= '" style="color:'.$tagsColor[ $tag['id'] ].';';
99    }
100  }
101
102  $template->clear_assign('related_tags');
103  $template->assign('related_tags', $tags);
104}*/
105
106/**
107 * colors tags on tags page
108 */
109function typetags_tags()
110{
111  global $template, $page, $tags;
112
113  if (empty($tags))
114  {
115    return;
116  }
117
118  $query = '
119SELECT
120    t.id,
121    tt.color
122  FROM ' . TYPETAGS_TABLE . ' AS tt
123    INNER JOIN ' . TAGS_TABLE . ' AS t
124    ON t.id_typetags = tt.id
125  WHERE t.id_typetags IS NOT NULL
126;';
127  $tagsColor = query2array($query, 'id', 'color');
128
129  if (empty($tagsColor))
130  {
131    return;
132  }
133
134  // LETTERS
135  if ($page['display_mode'] == 'letters')
136  {
137    $letters = $template->get_template_vars('letters');
138
139    foreach ($letters as &$letter)
140    {
141      foreach ($letter['tags'] as &$tag)
142      {
143        if (isset($tagsColor[ $tag['id'] ]))
144        {
145          $tag['URL'].= '" style="color:' . $tagsColor[ $tag['id'] ] . ';';
146        }
147      }
148      unset($tag);
149    }
150    unset($letter);
151
152    $template->assign('letters', $letters);
153  }
154  // CLOUD
155  else if ($page['display_mode'] == 'cloud')
156  {
157    $tags = $template->get_template_vars('tags');
158
159    foreach ($tags as &$tag)
160    {
161      if (isset($tagsColor[ $tag['id'] ]))
162      {
163        $tag['URL'].= '" style="color:' . $tagsColor[ $tag['id'] ] . ';';
164      }
165    }
166    unset($tag);
167
168    $template->assign('tags', $tags);
169  }
170  // CUMULUS
171  else if ($page['display_mode'] == 'cumulus')
172  {
173    $tags = $template->get_template_vars('tags');
174
175    foreach ($tags as &$tag)
176    {
177      if (isset($tagsColor[ $tag['id'] ]))
178      {
179        $tagsColor[ $tag['id'] ] = str_replace('#', '0x', $tagsColor[ $tag['id'] ]);
180        $tag['URL'].= '\' color=\'' . $tagsColor[ $tag['id'] ] . '\' hicolor=\'' . $tagsColor[ $tag['id'] ];
181      }
182    }
183    unset($tag);
184
185    $template->assign('tags', $tags);
186  }
187}
188
189function typetags_escape()
190{
191  global $template;
192  $template->set_prefilter('header', 'typetags_escape_prefilter');
193}
194function typetags_escape_prefilter($content)
195{
196  $search = '{$tag.name}';
197  $replace = '{$tag.name|strip_tags}';
198  return str_replace($search, $replace, $content);
199}
Note: See TracBrowser for help on using the repository browser.