<?php
/**
* @author:  Bunzia Alexander <nifus@mail.ru> <http://www.weblancer.net/users/nifus/>
* @copyright: Copyright (c) 2010, Bunzia Alexander
* @version: 1.0
* @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @package: HiLo CMS
*/

/**
* Автоматически генерирует блоек тегов
* 
* @var: array $options
* @return: str
*/
function tags($options){
global $MAIN_DB;
  $table = array(
    1 => 'h5',
    2 => 'h5',
    3 => 'h4',
    4 => 'h4',
    5 => 'h3',
    6 => 'h3',
    7 => 'h2',
    8 => 'h2',
    9 => 'h1',
    10 => 'h1'
  );
 
  
  $sql = "
    SELECT tag_name,COUNT(tag_name)  as `count`
    FROM ".$MAIN_DB -> prefix("tags_link")." 
    GROUP BY (tag_name)
    ORDER BY tag_name ASC
    LIMIT 0,50";
  $res = $MAIN_DB -> query($sql);
  $rows = array();
  while( $row = $MAIN_DB -> fetch_array($res) ){
    $row['url']= MAIN_URL.'/tag/'.urlencode($row['tag_name']);
    $row['class']= $table[$row['count']];
    if ( empty($row['class']) ){
      $row['class']='h1';
    }
    $rows[]=$row;
  }
	
	$t = new PHPTAL( false );
	$t -> setSource(TMPL_TAGS);
	$t -> rows = $rows;
	return $t -> execute();
}

define('TMPL_TAGS',
'<div tal:condition="rows">
  <h3>Метки событий</h3>
  <a tal:repeat="r rows" class="${r/class}" href="${r/url}">${r/tag_name}</a>

</div>');
?>
