<?php
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
// Количество тегов на страницу
$tagsppage = 20;
$tagsppage = intval($tagsppage);
$i = $cstart = ((isset($_GET['cstart']) ? intval($_GET['cstart']) : 1) - 1) * $tagsppage;
$is_change = false;
if ($config['allow_cache'] != "yes") { $config['allow_cache'] = "yes"; $is_change = true;}
$tpl->result['tags_cloud'] = dle_cache("tagscloud", $config['skin']);
if ($tpl->result['tags_cloud'] === false) {
$counts = array();
$tags = array();
$list = array();
$sizes = array( "clouds_xsmall", "clouds_small", "clouds_medium", "clouds_large", "clouds_xlarge" );
$min = 1;
$max = 1;
$range = 1;
$db->query("SELECT SQL_CALC_FOUND_ROWS tag, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag ORDER BY count DESC LIMIT 0,40");
while($row = $db->get_row()){
$tags[$row['tag']] = $row['count'];
$counts[] = $row['count'];
}
$db->free();
if (count($counts)) {
$min = min($counts);
$max = max($counts);
$range = ($max-$min);
}
if (!$range) $range = 1;
foreach ($tags as $tag => $value) {
$list[$tag]['tag'] = $tag;
$list[$tag]['size'] = $sizes[sprintf("%d", ($value-$min)/$range*4 )];
$list[$tag]['count'] = $value;
}
usort ($list, "compare_tags");
$tags = array();
foreach ($list as $value) {
if (trim($value['tag']) != "" ) {
$go_page = ($config['ajax']) ? "onclick=\"DlePage('do=tags&tag=".urlencode($value['tag'])."'); return false;\" " : "";
if ($config['allow_alt_url'] == "yes")
$tags[] = "<option value=\"".$config['http_home_url']."tags/".urlencode($value['tag'])."/\" class=\"{$value['size']}\" title=\"".$lang['tags_count']." ".$value['count']."\">".$value['tag']."</option>";
else
$tags[] = "<option value=\"$PHP_SELF?do=tags&tag=".urlencode($value['tag'])."\" class=\"{$value['size']}\" title=\"".$lang['tags_count']." ".$value['count']."\">".$value['tag']."</option>";
}
}
$tpl->result['tags_cloud'] = implode(", ", $tags);
$row = $db->super_query("SELECT FOUND_ROWS() as count");
if ($row['count'] >= 40) {
if ($config['allow_alt_url'] == "yes")
$tpl->result['tags_cloud'] .= "<br /><br /><a href=\"".$config['http_home_url']."tags/\">".$lang['all_tags']."</a>";
else
$tpl->result['tags_cloud'] .= "<br /><br /><a href=\"$PHP_SELF?do=tags\">".$lang['all_tags']."</a>";
}
create_cache ("tagscloud", $tpl->result['tags_cloud'], $config['skin']);
}
if ($do == "alltags") {
$tpl->result['content'] = dle_cache("alltagscloud".$cstart, $config['skin']);
if (!$tpl->result['content']) {
$tpl->load_template('tagscloud.tpl');
$counts = array();
$tags = array();
$list = array();
$sizes = array( "clouds_xsmall", "clouds_small", "clouds_medium", "clouds_large", "clouds_xlarge" );
$min = 1;
$max = 1;
$range = 1;
$db->query("SELECT tag, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag LIMIT ".$cstart.",".$tagsppage."");
while($row = $db->get_row()){
$tags[$row['tag']] = $row['count'];
$counts[] = $row['count'];
}
$db->free();
if (count($counts)) {
$min = min($counts);
$max = max($counts);
$range = ($max-$min);
}
$count_all = count($counts);
if (!$range) $range = 1;
foreach ($tags as $tag => $value) {
$list[$tag]['tag'] = $tag;
$list[$tag]['size'] = $sizes[sprintf("%d", ($value-$min)/$range*4 )];
$list[$tag]['count'] = $value;
}
usort ($list, "compare_tags");
$tags = array();
foreach ($list as $value) {
if (trim($value['tag']) != "" ) {
$go_page = ($config['ajax']) ? "onclick=\"DlePage('do=tags&tag=".urlencode($value['tag'])."'); return false;\" " : "";
if ($config['allow_alt_url'] == "yes")
$tags[] = "<a {$go_page} href=\"".$config['http_home_url']."tags/".urlencode($value['tag'])."/\" class=\"{$value['size']}\" title=\"".$lang['tags_count']." ".$value['count']."\">".$value['tag']."</a>";
else
$tags[] = "<a {$go_page} href=\"$PHP_SELF?do=tags&tag=".urlencode($value['tag'])."\" class=\"{$value['size']}\" title=\"".$lang['tags_count']." ".$value['count']."\">".$value['tag']."</a>";
}
}
$tags = implode(", ", $tags);
$tpl->set('{tags}', $tags);
$tpl->compile('content');
$tpl->clear();
// ================================================
// ПОСТРАНИЧНАЯ НАВИГАЦИЯ НАВИГАЦИЯ ПО ТЕГАМ
// ================================================
$tpl->load_template('navigation.tpl');
$no_prev = false;
$no_next = false;
if(isset($cstart) and $cstart != "" and $cstart > 0){
$prev = $cstart / $tagsppage;
if ($config['allow_alt_url'] == "yes") {
$prev_page = $config['http_home_url']."tags/page".$prev."/";
$tpl->set_block("'\\[prev-link\\](.*?)\\[/prev-link\\]'si", "<a href=\"".$prev_page."\">\\1</a>");
} else {
$prev_page = $PHP_SELF."?do=alltags&cstart=".$prev;
$tpl->set_block("'\\[prev-link\\](.*?)\\[/prev-link\\]'si", "<a href=\"".$prev_page."\">\\1</a>");
};
}else{ $tpl->set_block("'\\[prev-link\\](.*?)\\[/prev-link\\]'si", "<span>\\1</span>"); $no_prev = TRUE; }
if($tagsppage){
$counts = array();
$tags = array();
$list = array();
$db->query("SELECT tag, COUNT(*) AS count FROM " . PREFIX . "_tags GROUP BY tag");
while($row = $db->get_row()){
$tags[$row['tag']] = $row['count'];
$counts[] = $row['count'];
}
$db->free();
foreach ($tags as $tag => $value) {
$list[$tag]['count'] = $value;
}
usort ($list, "compare_tags");
$count_all_yasitemap = count($list);
$pages_count = @ceil($count_all_yasitemap/$tagsppage);
$pages_start_from = 0;
$pages = "";
$pages_per_section = 8;
if($pages_count > 6)
{
for($j = 1; $j <= $pages_per_section; $j++)
{
if($pages_start_from != $cstart)
{
if ($config['allow_alt_url'] == "yes")
$pages .= "<a href=\"".$config['http_home_url']."tags/page".$j."/\">$j</a> ";
else
$pages .= "<a href=\"$PHP_SELF?do=alltags&cstart=$j\">$j</a> ";
}
else
{
$pages .= "<span>$j</span> ";
}
$pages_start_from += $tagsppage;
}
if(((($cstart / $tagsppage) + 1) > 1) && ((($cstart / $tagsppage) + 1) < $pages_count))
{
$pages .= ((($cstart / $tagsppage) + 1) > ($pages_per_section + 2)) ? '... ' : ' ';
$page_min = ((($cstart / $tagsppage) + 1) > ($pages_per_section + 1)) ? ($cstart / $tagsppage) : ($pages_per_section + 1);//
$page_max = ((($cstart / $tagsppage) + 1) < ($pages_count - ($pages_per_section + 1))) ? (($cstart / $tagsppage) + 1) : $pages_count - ($pages_per_section + 1);
$pages_start_from = ($page_min - 1) * $tagsppage;
for($j = $page_min; $j < $page_max + ($pages_per_section - 1); $j++)
{
if($pages_start_from != $cstart)
{
if ($config['allow_alt_url'] == "yes")
$pages .= "<a href=\"".$config['http_home_url']."tags/page".$j."/\">$j</a> ";
else
$pages .= "<a href=\"$PHP_SELF?do=alltags&cstart=$j\">$j</a> ";
}
else
{
$pages .= "<span>$j</span> ";
}
$pages_start_from += $tagsppage;
}
$pages .= ((($cstart / $tagsppage) + 1) < $pages_count - ($pages_per_section + 1)) ? '... ' : ' ';
}
else
{
$pages .= '... ';
}
$pages_start_from = ($pages_count - $pages_per_section) * $tagsppage;
for($j=($pages_count - ($pages_per_section - 1)); $j <= $pages_count; $j++)
{
if($pages_start_from != $cstart)
{
if ($config['allow_alt_url'] == "yes")
$pages .= "<a href=\"".$config['http_home_url']."tags/page".$j."/\">$j</a> ";
else
$pages .= "<a href=\"$PHP_SELF?do=alltags&cstart=$j\">$j</a> ";
}
else
{
$pages .= "<span>$j</span> ";
}
$pages_start_from += $tagsppage;
}
}
else
{
for($j=1;$j<=$pages_count;$j++)
{
if($pages_start_from != $cstart)
{
if ($config['allow_alt_url'] == "yes")
$pages .= "<a href=\"".$config['http_home_url']."tags/page".$j."/\">$j</a> ";
else
$pages .= "<a href=\"$PHP_SELF?do=alltags&cstart=$j\">$j</a> ";
}
else
{
$pages .= "<span>$j</span> ";
}
$pages_start_from += $tagsppage;
}
}
$tpl->set('{pages}', $pages);
}
if($tagsppage < $count_all_yasitemap and $i < $count_all_yasitemap){
$next_page = $i / $tagsppage + 2;
if ($config['allow_alt_url'] == "yes") {
$next = $config['http_home_url']."tags/page".$next_page."/";
$tpl->set_block("'\\[next-link\\](.*?)\\[/next-link\\]'si", "<a href=\"".$next."\">\\1</a>");
} else {
$next = $PHP_SELF."?do=alltags&cstart=".$next_page;
$tpl->set_block("'\\[next-link\\](.*?)\\[/next-link\\]'si", "<a href=\"".$next."\">\\1</a>");
};
}else{ $tpl->set_block("'\\[next-link\\](.*?)\\[/next-link\\]'si", "<span>\\1</span>"); $no_next = TRUE;}
if (!$no_prev OR !$no_next){ $tpl->compile('nav_pages'); }
$tpl->clear();
$tpl->result['content'] = $tpl->result['content'] . $tpl->result['nav_pages'];
create_cache ("alltagscloud".$cstart, $tpl->result['content'], $config['skin']);
}
}
if ($is_change) $config['allow_cache'] = false;
?>