Ignore:
Timestamp:
Jan 12, 2014, 7:13:40 PM (10 years ago)
Author:
mistic100
Message:

integrate in new tags manager + rename in Coloured Tags
(my apologies to translators :-) )

Location:
extensions/typetags/include
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • extensions/typetags/include/events_public.inc.php

    r24342 r26665  
    11<?php
     2defined('TYPETAGS_PATH') or die('Hacking attempt!');
    23
    34/**
    45 * triggered by 'render_tag_name'
    56 */
    6 function typetags_render($tag)
     7function typetags_render($tag_name, $tag=array())
    78{
    8   global $pwg_loaded_plugins, $page;
    9  
    10   if ( defined('IN_ADMIN') and in_array($page['page'], array('photo', 'batch_manager')) )
     9  global $pwg_loaded_plugins, $page, $typetags_cache;
     10
     11  if (defined('IN_ADMIN') and in_array($page['page'], array('photo', 'batch_manager', 'tags')))
    1112  {
    12     return $tag;
     13    return $tag_name;
    1314  }
    14  
    15   $query = '
     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 = '
    1646SELECT 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 = "'.pwg_db_real_escape_string($tag).'"
    21 ;';;
    22   list($color) = pwg_db_fetch_row(pwg_query($query));
    23  
    24   if ($color === null)
     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)
    2556  {
    26     return $tag;
     57    $ret = $tag_name;
    2758  }
    2859  elseif (isset($pwg_loaded_plugins['ExtendedDescription']))
    2960  {
    30     return "[lang=all]<span style='color:".$color.";'>[/lang]".$tag."[lang=all]</span>[/lang]";
     61    $ret = '[lang=all]<span style="color:' . $color . ';">[/lang]' . $tag_name . '[lang=all]</span>[/lang]';
    3162  }
    3263  else
    3364  {
    34     return "<span style='color:".$color.";'>".$tag."</span>";
     65    $ret = '<span style="color:' . $color . ';">' . $tag_name . '</span>';
    3566  }
     67
     68  $typetags_cache['tags'][$tag_name] = $ret;
     69  return $ret;
    3670}
    3771
     
    4276{
    4377  global $template;
    44    
     78
    4579  $tags = $template->get_template_vars('related_tags');
    4680  if (empty($tags)) return;
    47  
     81
    4882  $query = '
    4983SELECT
    5084    t.id ,
    5185    tt.color
    52   FROM '.typetags_TABLE.' AS tt
     86  FROM '.TYPETAGS_TABLE.' AS tt
    5387    INNER JOIN '.TAGS_TABLE.' AS t
    5488      ON t.id_typetags = tt.id
     
    6599    }
    66100  }
    67  
     101
    68102  $template->clear_assign('related_tags');
    69103  $template->assign('related_tags', $tags);
     
    75109function typetags_tags()
    76110{
    77   global $template;
     111  global $template, $page, $tags;
     112
     113  if (empty($tags))
     114  {
     115    return;
     116  }
    78117
    79118  $query = '
    80119SELECT
    81     t.id ,
     120    t.id,
    82121    tt.color
    83   FROM '.typetags_TABLE.' AS tt
    84     INNER JOIN '.TAGS_TABLE.' AS t
    85       ON t.id_typetags = tt.id
     122  FROM ' . TYPETAGS_TABLE . ' AS tt
     123    INNER JOIN ' . TAGS_TABLE . ' AS t
     124    ON t.id_typetags = tt.id
    86125  WHERE t.id_typetags IS NOT NULL
    87126;';
    88   $tagsColor = simple_hash_from_query($query, 'id', 'color');
    89   if (empty($tagsColor)) return;
     127  $tagsColor = query2array($query, 'id', 'color');
    90128
    91   $display = $template->get_template_vars('display_mode');
    92   if ($display == 'letters')
     129  if (empty($tagsColor))
     130  {
     131    return;
     132  }
     133
     134  // LETTERS
     135  if ($page['display_mode'] == 'letters')
    93136  {
    94137    $letters = $template->get_template_vars('letters');
    95     if (empty($letters)) return;
    96138
    97     foreach ($letters as $k1 => $letter)
     139    foreach ($letters as &$letter)
    98140    {
    99       foreach ($letter['tags'] as $k2 => $tag)
     141      foreach ($letter['tags'] as &$tag)
    100142      {
    101143        if (isset($tagsColor[ $tag['id'] ]))
    102144        {
    103           $letters[$k1]['tags'][$k2]['URL'].= '" style="color:'.$tagsColor[ $tag['id'] ].';';
     145          $tag['URL'].= '" style="color:' . $tagsColor[ $tag['id'] ] . ';';
    104146        }
    105147      }
     148      unset($tag);
    106149    }
    107    
    108     $template->clear_assign('letters');
     150    unset($letter);
     151
    109152    $template->assign('letters', $letters);
    110153  }
    111   elseif ($display == 'cloud')
     154  // CLOUD
     155  else if ($page['display_mode'] == 'cloud')
    112156  {
    113157    $tags = $template->get_template_vars('tags');
    114     if (empty($tags)) return;
    115158
    116     foreach ($tags as $key => $tag)
     159    foreach ($tags as &$tag)
    117160    {
    118161      if (isset($tagsColor[ $tag['id'] ]))
    119162      {
    120         $tags[$key]['URL'].= '" style="color:'.$tagsColor[ $tag['id'] ].';';
     163        $tag['URL'].= '" style="color:' . $tagsColor[ $tag['id'] ] . ';';
    121164      }
    122165    }
    123    
    124     $template->clear_assign('tags');
     166    unset($tag);
     167
    125168    $template->assign('tags', $tags);
    126169  }
    127   elseif ($display == 'cumulus')
     170  // CUMULUS
     171  else if ($page['display_mode'] == 'cumulus')
    128172  {
    129173    $tags = $template->get_template_vars('tags');
    130     if (empty($tags)) return;
    131174
    132     foreach ($tags as $key => $tag)
     175    foreach ($tags as &$tag)
    133176    {
    134177      if (isset($tagsColor[ $tag['id'] ]))
    135178      {
    136179        $tagsColor[ $tag['id'] ] = str_replace('#', '0x', $tagsColor[ $tag['id'] ]);
    137         $tags[$key]['URL'].= '\' color=\''.$tagsColor[ $tag['id'] ].'\' hicolor=\''.$tagsColor[ $tag['id'] ];
     180        $tag['URL'].= '\' color=\'' . $tagsColor[ $tag['id'] ] . '\' hicolor=\'' . $tagsColor[ $tag['id'] ];
    138181      }
    139182    }
    140    
    141     $template->clear_assign('tags');
     183    unset($tag);
     184
    142185    $template->assign('tags', $tags);
    143186  }
    144187}
    145 
    146 ?>
Note: See TracChangeset for help on using the changeset viewer.