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
RevLine 
[3609]1<?php
[26665]2defined('TYPETAGS_PATH') or die('Hacking attempt!');
[3609]3
[15149]4/**
5 * triggered by 'render_tag_name'
6 */
[26665]7function typetags_render($tag_name, $tag=array())
[3609]8{
[26665]9  global $pwg_loaded_plugins, $page, $typetags_cache;
10
11  if (defined('IN_ADMIN') and in_array($page['page'], array('photo', 'batch_manager', 'tags')))
[15646]12  {
[26665]13    return $tag_name;
[15646]14  }
[26665]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 = '
[15149]46SELECT color
[26665]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)
[15149]56  {
[26665]57    $ret = $tag_name;
[15149]58  }
59  elseif (isset($pwg_loaded_plugins['ExtendedDescription']))
60  {
[26665]61    $ret = '[lang=all]<span style="color:' . $color . ';">[/lang]' . $tag_name . '[lang=all]</span>[/lang]';
[15149]62  }
63  else
64  {
[26665]65    $ret = '<span style="color:' . $color . ';">' . $tag_name . '</span>';
[15149]66  }
[26665]67
68  $typetags_cache['tags'][$tag_name] = $ret;
69  return $ret;
[3609]70}
71
[15149]72/**
73 * colors tags on picture page
74 */
75/*function typetags_picture()
[3609]76{
[15149]77  global $template;
[26665]78
[15149]79  $tags = $template->get_template_vars('related_tags');
80  if (empty($tags)) return;
[26665]81
[15149]82  $query = '
83SELECT
84    t.id ,
85    tt.color
[26665]86  FROM '.TYPETAGS_TABLE.' AS tt
[15149]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;
[3609]93
[15149]94  foreach ($tags as $key => $tag)
[3609]95  {
[15149]96    if (isset($tagsColor[ $tag['id'] ]))
[3609]97    {
[15149]98      $tags[$key]['URL'].= '" style="color:'.$tagsColor[ $tag['id'] ].';';
[3609]99    }
100  }
[26665]101
[15149]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()
[3609]110{
[26665]111  global $template, $page, $tags;
[3609]112
[26665]113  if (empty($tags))
114  {
115    return;
116  }
117
[15149]118  $query = '
119SELECT
[26665]120    t.id,
[15149]121    tt.color
[26665]122  FROM ' . TYPETAGS_TABLE . ' AS tt
123    INNER JOIN ' . TAGS_TABLE . ' AS t
124    ON t.id_typetags = tt.id
[15149]125  WHERE t.id_typetags IS NOT NULL
126;';
[26665]127  $tagsColor = query2array($query, 'id', 'color');
[15149]128
[26665]129  if (empty($tagsColor))
[3609]130  {
[26665]131    return;
132  }
133
134  // LETTERS
135  if ($page['display_mode'] == 'letters')
136  {
[15149]137    $letters = $template->get_template_vars('letters');
138
[26665]139    foreach ($letters as &$letter)
[3609]140    {
[26665]141      foreach ($letter['tags'] as &$tag)
[15149]142      {
143        if (isset($tagsColor[ $tag['id'] ]))
144        {
[26665]145          $tag['URL'].= '" style="color:' . $tagsColor[ $tag['id'] ] . ';';
[15149]146        }
147      }
[26665]148      unset($tag);
[3609]149    }
[26665]150    unset($letter);
151
[15149]152    $template->assign('letters', $letters);
[3609]153  }
[26665]154  // CLOUD
155  else if ($page['display_mode'] == 'cloud')
[15149]156  {
157    $tags = $template->get_template_vars('tags');
[3609]158
[26665]159    foreach ($tags as &$tag)
[15149]160    {
161      if (isset($tagsColor[ $tag['id'] ]))
162      {
[26665]163        $tag['URL'].= '" style="color:' . $tagsColor[ $tag['id'] ] . ';';
[15149]164      }
165    }
[26665]166    unset($tag);
167
[15149]168    $template->assign('tags', $tags);
169  }
[26665]170  // CUMULUS
171  else if ($page['display_mode'] == 'cumulus')
[3609]172  {
[15149]173    $tags = $template->get_template_vars('tags');
174
[26665]175    foreach ($tags as &$tag)
[3609]176    {
[15149]177      if (isset($tagsColor[ $tag['id'] ]))
178      {
179        $tagsColor[ $tag['id'] ] = str_replace('#', '0x', $tagsColor[ $tag['id'] ]);
[26665]180        $tag['URL'].= '\' color=\'' . $tagsColor[ $tag['id'] ] . '\' hicolor=\'' . $tagsColor[ $tag['id'] ];
[15149]181      }
[3609]182    }
[26665]183    unset($tag);
184
[15149]185    $template->assign('tags', $tags);
[3609]186  }
187}
[26855]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.