set("query", trim($_GET['query'])); } /* pager */ $res = mysql_query("SELECT COUNT(*) FROM gallery_video WHERE gal_vis=1 AND gal_lang=$lang".$SQLw); list($n) = @mysql_fetch_row($res); @mysql_free_result($res); if ($_GET['page'] > 0 && $_GET['page'] <= ceil($n / $N)) $cur = (int)$_GET['page']; else $cur = 1; if ($cur > 1) $page_title2 = " ({$cur}/".ceil($n / $N).")"; if ($n > 0) { switcher($tpl, 'pager', $n, $cur, $N, 20); /* list of photo galleries */ $SQL = "SELECT *, UNIX_TIMESTAMP(gal_dt) AS dt FROM gallery_video WHERE gal_vis=1 AND gal_lang=$lang".$SQLw; $SQL .= " ORDER BY gal_pos ASC LIMIT ".(($cur-1)*$N).",$N"; $res = mysql_query($SQL); $i = 0; $C = 2; while ($row = @mysql_fetch_array($res)) { $tpl->set($row); $tpl->set("href", href("video_gallery", 0, $row['gal_id'])); make_item_dt($tpl, $row['dt']); $youtube_id = youtube_id($row['gal_link']); if ($youtube_id == '') continue; $tpl->set("youtube_id", $youtube_id); $tpl->parse("gallery_item", ".gallery_item"); if ( (++$i % $C) != 0 ) $tpl->parse("gallery_sep", ".gallery_item"); else { $tpl->parse("gallery_row", ".gallery_row"); $tpl->clear("gallery_item"); } } @mysql_free_result($res); if ( ($i % $C) != 0 ) { $tpl->parse("gallery_empty", ".gallery_item"); $tpl->parse("gallery_row", ".gallery_row"); } } else { $tpl->parse("gallery_nomatch", ".gallery_item"); $tpl->parse("gallery_row", ".gallery_row"); } /* list of most popular galleries */ $i = 0; $res = mysql_query("SELECT *, UNIX_TIMESTAMP(gal_dt) AS dt FROM gallery_video WHERE gal_vis=1 AND gal_lang=$lang ORDER BY gal_hits DESC LIMIT 10"); while ($row = @mysql_fetch_array($res)) { $tpl->set($row); $tpl->set("href", href("video_gallery", 0, $row['gal_id'])); make_item_dt($tpl, $row['dt']); $youtube_id = youtube_id($row['gal_link']); if ($youtube_id == '') continue; $tpl->set("youtube_id", $youtube_id); $tpl->parse("galright_row", ".galright_row"); if (++$i >= 3) break; } @mysql_free_result($res); $tpl->parse("main", "main"); /* ------------------------------------------------------------------- */ /* make page switcher */ /* $tpl - template object */ /* $blk - base switcher template block */ /* $n - total items */ /* $cur - current page */ /* $N - items per page */ /* $NN - max shown switcher items */ /* $pg - first/last item number for each page, if false - calc */ function switcher(&$tpl, $blk, $n, $cur, $N, $NN, $pg = false) { $href = rtrim($GLOBALS['rootweb'], '/')."/index.php/tpl/vgalleries/?page="; if ($N == 0) return; $pages = is_array($pg) ? count($pg)-1 : ceil($n/$N); $prefix = $suffix = ''; if ($NN && $pages > $NN) { $first = $cur - $NN/2; $last = $cur + $NN/2; while ($first < 0) { $first++; $last++; } while ($last > $pages) { $last--; $first--; } if ($first < 0) $first = 0; } else { $first = 0; $last = $pages; } /* adjust for the total number of items shown */ if ($first > 0) $first++; if ($last < $pages) $last--; /* first and previous page arrows */ if ($first > 0) { $p = max($first-$N, 0); //max($first-$NN/2, 0); /* if ($p > 0) { $tpl->set("href", $href.'1'); $tpl->parse($blk."_first", '.'.$blk); $tpl->parse($blk."_sep", '.'.$blk); }*/ $tpl->set("href", $href.($p+1)); $tpl->parse($blk."_prev", '.'.$blk); $tpl->parse($blk."_sep", '.'.$blk); } /* numeric selectors */ for ($i = $first; $i < $last; $i++) { if ($i > $first) $tpl->parse($blk."_sep", '.'.$blk); $tpl->set("page", 1 + $i, "n1", 1 + (is_array($pg) ? $pg[$i] : $i*$N), "n2", is_array($pg) ? $pg[$i+1] : min($i*$N+$N, $n), "href", $href.(1 + $i)); $tpl->parse($blk.($cur == $i+1 ? "_cur" : "_item"), '.'.$blk); } /* next and last page arrows */ if ($last < $pages) { $p = min($last+$N, $pages); //min($last+$pages/2, $pages-$NN/2); $tpl->set("href", $href.$p); $tpl->parse($blk."_sep", '.'.$blk); $tpl->parse($blk."_next", '.'.$blk); /* if ($last+$NN < $pages) { $tpl->set("href", $href.$pages, "pages", $pages); $tpl->parse($blk."_sep", '.'.$blk); $tpl->parse($blk."_last", '.'.$blk); }*/ } } ?> CYPRUS MIRROR Daily News | VIDEO GALLERY