source: extensions/typetags/typetags.php @ 15907

Last change on this file since 15907 was 15646, checked in by mistic100, 12 years ago

don't render typetags on admin dropdowns (breaks JS search)

File size: 3.2 KB
Line 
1<?php
2
3/**
4 * triggered by 'render_tag_name'
5 */
6function typetags_render($tag)
7{
8  global $pwg_loaded_plugins, $page;
9 
10  if ( defined('IN_ADMIN') and in_array($page['page'], array('photo', 'batch_manager')) )
11  {
12    return $tag;
13  }
14 
15  $query = '
16SELECT color
17  FROM '.typetags_TABLE.' AS tt
18    INNER JOIN '.TAGS_TABLE.' AS t
19      ON t.id_typetags = tt.id
20  WHERE t.name = "'.mysql_real_escape_string($tag).'"
21;';;
22  list($color) = pwg_db_fetch_row(pwg_query($query));
23 
24  if ($color === null) 
25  {
26    return $tag;
27  }
28  elseif (isset($pwg_loaded_plugins['ExtendedDescription']))
29  {
30    return "[lang=all]<span style='color:".$color.";'>[/lang]".$tag."[lang=all]</span>[/lang]";
31  }
32  else
33  {
34    return "<span style='color:".$color.";'>".$tag."</span>";
35  }
36}
37
38/**
39 * colors tags on picture page
40 */
41/*function typetags_picture()
42{
43  global $template;
44   
45  $tags = $template->get_template_vars('related_tags');
46  if (empty($tags)) return;
47 
48  $query = '
49SELECT
50    t.id ,
51    tt.color
52  FROM '.typetags_TABLE.' AS tt
53    INNER JOIN '.TAGS_TABLE.' AS t
54      ON t.id_typetags = tt.id
55  WHERE t.id_typetags IS NOT NULL
56;';
57  $tagsColor = simple_hash_from_query($query, 'id', 'color');
58  if (empty($tagsColor)) return;
59
60  foreach ($tags as $key => $tag)
61  {
62    if (isset($tagsColor[ $tag['id'] ]))
63    {
64      $tags[$key]['URL'].= '" style="color:'.$tagsColor[ $tag['id'] ].';';
65    }
66  }
67 
68  $template->clear_assign('related_tags');
69  $template->assign('related_tags', $tags);
70}*/
71
72/**
73 * colors tags on tags page
74 */
75function typetags_tags()
76{
77  global $template;
78
79  $query = '
80SELECT
81    t.id ,
82    tt.color
83  FROM '.typetags_TABLE.' AS tt
84    INNER JOIN '.TAGS_TABLE.' AS t
85      ON t.id_typetags = tt.id
86  WHERE t.id_typetags IS NOT NULL
87;';
88  $tagsColor = simple_hash_from_query($query, 'id', 'color');
89  if (empty($tagsColor)) return;
90
91  $display = $template->get_template_vars('display_mode');
92  if ($display == 'letters')
93  {
94    $letters = $template->get_template_vars('letters');
95    if (empty($letters)) return;
96
97    foreach ($letters as $k1 => $letter)
98    {
99      foreach ($letter['tags'] as $k2 => $tag)
100      {
101        if (isset($tagsColor[ $tag['id'] ]))
102        {
103          $letters[$k1]['tags'][$k2]['URL'].= '" style="color:'.$tagsColor[ $tag['id'] ].';';
104        }
105      }
106    }
107   
108    $template->clear_assign('letters');
109    $template->assign('letters', $letters);
110  }
111  elseif ($display == 'cloud')
112  {
113    $tags = $template->get_template_vars('tags');
114    if (empty($tags)) return;
115
116    foreach ($tags as $key => $tag)
117    {
118      if (isset($tagsColor[ $tag['id'] ]))
119      {
120        $tags[$key]['URL'].= '" style="color:'.$tagsColor[ $tag['id'] ].';';
121      }
122    }
123   
124    $template->clear_assign('tags');
125    $template->assign('tags', $tags);
126  }
127  elseif ($display == 'cumulus')
128  {
129    $tags = $template->get_template_vars('tags');
130    if (empty($tags)) return;
131
132    foreach ($tags as $key => $tag)
133    {
134      if (isset($tagsColor[ $tag['id'] ]))
135      {
136        $tagsColor[ $tag['id'] ] = str_replace('#', '0x', $tagsColor[ $tag['id'] ]);
137        $tags[$key]['URL'].= '\' color=\''.$tagsColor[ $tag['id'] ].'\' hicolor=\''.$tagsColor[ $tag['id'] ];
138      }
139    }
140   
141    $template->clear_assign('tags');
142    $template->assign('tags', $tags);
143  }
144}
145
146?>
Note: See TracBrowser for help on using the repository browser.