[xiph-commits] r14675 - in branches/dir.xiph.org: . css inc templates
balbinus at svn.xiph.org
balbinus at svn.xiph.org
Tue Apr 8 02:44:32 PDT 2008
Author: balbinus
Date: 2008-04-08 02:44:32 -0700 (Tue, 08 Apr 2008)
New Revision: 14675
Modified:
branches/dir.xiph.org/by_format.php
branches/dir.xiph.org/by_genre.php
branches/dir.xiph.org/css/style.css
branches/dir.xiph.org/inc/prepend.php
branches/dir.xiph.org/search.php
branches/dir.xiph.org/templates/streams_list.tpl
Log:
Cleaner paging with actual display of links ;)
Modified: branches/dir.xiph.org/by_format.php
===================================================================
--- branches/dir.xiph.org/by_format.php 2008-04-08 09:38:47 UTC (rev 14674)
+++ branches/dir.xiph.org/by_format.php 2008-04-08 09:44:32 UTC (rev 14675)
@@ -2,7 +2,15 @@
include_once(dirname(__FILE__).'/inc/prepend.php');
+// Memcache connection
+$memcache = DirXiphOrgMCC::getInstance();
+
// Get the args
+$page_n = array_key_exists('page', $_GET) ? intval($_GET['page']) : 0;
+if ($page_n > (MAX_SEARCH_RESULTS / MAX_RESULTS_PER_PAGE))
+{
+ $page_n = 0;
+}
if (array_key_exists('PATH_INFO', $_SERVER))
{
$search_string = preg_replace('|^/([^\s/]+).*$|', '$1', $_SERVER['PATH_INFO']);
@@ -10,10 +18,7 @@
$tpl->assign('search_keyword', str_replace('_', ' ', $search_string));
$search_string = preg_replace('/[^A-Za-z0-9+_\-]/', '_', $search_string);
$search_string_hash = jenkins_hash_hex($search_string);
-
- // Memcache connection
- $memcache = DirXiphOrgMCC::getInstance();
-
+
// Get the data from the Memcache server
if (($results = $memcache->get(ENVIRONMENT.'_search_format_'.$search_string_hash)) === false)
{
@@ -45,18 +50,36 @@
if ($results !== false && $results !== array())
{
- $n_results = count($results);
- $results_pages = $n_results / MAX_RESULTS_PER_PAGE;
- if ($page_n > $results_pages)
+ $n_results = count($results);
+ $results_pages = ceil($n_results / MAX_RESULTS_PER_PAGE);
+ if ($page_n > $results_pages)
+ {
+ $page_n = 0;
+ }
+ $pages = array();
+ if ($results_pages < PAGES_IN_PAGER)
{
- $page_n = 0;
+ $pages = range(1, $results_pages);
}
- $offset = $page_n * MAX_RESULTS_PER_PAGE;
- $results = array_slice($results, $offset,
- MAX_RESULTS_PER_PAGE);
- $tpl->assign_by_ref('results', $results);
- $tpl->assign_by_ref('results_pages', $results_pages);
- $tpl->assign_by_ref('results_page_no', $page_n);
+ elseif ($page_n > PAGES_IN_PAGER)
+ {
+ $pages = range($page_n + 1 - PAGES_IN_PAGER, $pages_n + 1 + PAGES_IN_PAGER);
+ }
+ elseif ($page_n + PAGES_IN_PAGER > $results_pages)
+ {
+ $pages = range($results_pages - PAGES_IN_PAGER, $results_pages);
+ }
+ else
+ {
+ $pages = range(1, PAGES_IN_PAGER);
+ }
+ $offset = $page_n * MAX_RESULTS_PER_PAGE;
+ $results = array_slice($results, $offset,
+ MAX_RESULTS_PER_PAGE);
+ $tpl->assign_by_ref('results', $results);
+ $tpl->assign_by_ref('results_pages', $pages);
+ $tpl->assign_by_ref('results_pages_total', $results_pages);
+ $tpl->assign('results_page_no', $page_n + 1);
}
}
else
Modified: branches/dir.xiph.org/by_genre.php
===================================================================
--- branches/dir.xiph.org/by_genre.php 2008-04-08 09:38:47 UTC (rev 14674)
+++ branches/dir.xiph.org/by_genre.php 2008-04-08 09:44:32 UTC (rev 14675)
@@ -53,18 +53,36 @@
if ($results !== false && $results !== array())
{
- $n_results = count($results);
- $results_pages = $n_results / MAX_RESULTS_PER_PAGE;
- if ($page_n > $results_pages)
- {
- $page_n = 0;
- }
- $offset = $page_n * MAX_RESULTS_PER_PAGE;
- $results = array_slice($results, $offset,
- MAX_RESULTS_PER_PAGE);
- $tpl->assign_by_ref('results', $results);
- $tpl->assign_by_ref('results_pages', $results_pages);
- $tpl->assign_by_ref('results_page_no', $page_n);
+ $n_results = count($results);
+ $results_pages = ceil($n_results / MAX_RESULTS_PER_PAGE);
+ if ($page_n > $results_pages)
+ {
+ $page_n = 0;
+ }
+ $pages = array();
+ if ($results_pages < PAGES_IN_PAGER)
+ {
+ $pages = range(1, $results_pages);
+ }
+ elseif ($page_n > PAGES_IN_PAGER)
+ {
+ $pages = range($page_n + 1 - PAGES_IN_PAGER, $pages_n + 1 + PAGES_IN_PAGER);
+ }
+ elseif ($page_n + PAGES_IN_PAGER > $results_pages)
+ {
+ $pages = range($results_pages - PAGES_IN_PAGER, $results_pages);
+ }
+ else
+ {
+ $pages = range(1, PAGES_IN_PAGER);
+ }
+ $offset = $page_n * MAX_RESULTS_PER_PAGE;
+ $results = array_slice($results, $offset,
+ MAX_RESULTS_PER_PAGE);
+ $tpl->assign_by_ref('results', $results);
+ $tpl->assign_by_ref('results_pages', $pages);
+ $tpl->assign_by_ref('results_pages_total', $results_pages);
+ $tpl->assign('results_page_no', $page_n + 1);
}
}
else
Modified: branches/dir.xiph.org/css/style.css
===================================================================
--- branches/dir.xiph.org/css/style.css 2008-04-08 09:38:47 UTC (rev 14674)
+++ branches/dir.xiph.org/css/style.css 2008-04-08 09:44:32 UTC (rev 14675)
@@ -166,3 +166,18 @@
.inline-tags li {
display: inline;
}
+
+/* Pager */
+.pager {
+ list-style-type: none;
+ padding: 0;
+ margin: 0;
+}
+
+.pager li {
+ display: inline;
+}
+
+.pager li a.active {
+ font-weight: bold;
+}
Modified: branches/dir.xiph.org/inc/prepend.php
===================================================================
--- branches/dir.xiph.org/inc/prepend.php 2008-04-08 09:38:47 UTC (rev 14674)
+++ branches/dir.xiph.org/inc/prepend.php 2008-04-08 09:44:32 UTC (rev 14675)
@@ -30,6 +30,7 @@
define('MAX_RESULTS_PER_PAGE', 20);
define('MAX_SEARCH_RESULTS', 100);
+define('PAGES_IN_PAGER', 5);
$begin_time = microtime(true);
Modified: branches/dir.xiph.org/search.php
===================================================================
--- branches/dir.xiph.org/search.php 2008-04-08 09:38:47 UTC (rev 14674)
+++ branches/dir.xiph.org/search.php 2008-04-08 09:44:32 UTC (rev 14675)
@@ -90,21 +90,39 @@
false, 60);
}
- // Now assign the results to a template var
+ // Now assign the results to a template var
if ($results !== false && $results !== array())
{
- $n_results = count($results);
- $results_pages = $n_results / MAX_RESULTS_PER_PAGE;
- if ($page_n > $results_pages)
- {
- $page_n = 0;
- }
- $offset = $page_n * MAX_RESULTS_PER_PAGE;
- $results = array_slice($results, $offset,
- MAX_RESULTS_PER_PAGE);
- $tpl->assign_by_ref('results', $results);
- $tpl->assign_by_ref('results_pages', $results_pages);
- $tpl->assign_by_ref('results_page_no', $page_n);
+ $n_results = count($results);
+ $results_pages = ceil($n_results / MAX_RESULTS_PER_PAGE);
+ if ($page_n > $results_pages)
+ {
+ $page_n = 0;
+ }
+ $pages = array();
+ if ($results_pages < PAGES_IN_PAGER)
+ {
+ $pages = range(1, $results_pages);
+ }
+ elseif ($page_n > PAGES_IN_PAGER)
+ {
+ $pages = range($page_n + 1 - PAGES_IN_PAGER, $pages_n + 1 + PAGES_IN_PAGER);
+ }
+ elseif ($page_n + PAGES_IN_PAGER > $results_pages)
+ {
+ $pages = range($results_pages - PAGES_IN_PAGER, $results_pages);
+ }
+ else
+ {
+ $pages = range(1, PAGES_IN_PAGER);
+ }
+ $offset = $page_n * MAX_RESULTS_PER_PAGE;
+ $results = array_slice($results, $offset,
+ MAX_RESULTS_PER_PAGE);
+ $tpl->assign_by_ref('results', $results);
+ $tpl->assign_by_ref('results_pages', $pages);
+ $tpl->assign_by_ref('results_pages_total', $results_pages);
+ $tpl->assign('results_page_no', $page_n + 1);
}
}
}
Modified: branches/dir.xiph.org/templates/streams_list.tpl
===================================================================
--- branches/dir.xiph.org/templates/streams_list.tpl 2008-04-08 09:38:47 UTC (rev 14674)
+++ branches/dir.xiph.org/templates/streams_list.tpl 2008-04-08 09:44:32 UTC (rev 14675)
@@ -43,4 +43,18 @@
</tr>
{/foreach}
</table>
+{if !empty($results_pages)}
+ <ul class="pager">
+{if $results_page_no != 1}
+ <li><a href="?page={$results_page_no-2}">«</a></li>
{/if}
+{foreach item=page from=$results_pages}
+ <li><a{if $page == $results_page_no} class="active"{/if} href="?page={$page-1}">{$page}</a></li>
+{/foreach}
+{if $results_page_no != $results_pages_total}
+ <li><a href="?page={$results_page_no}">»</a></li>
+{/if}
+
+ </ul>
+{/if}
+{/if}
More information about the commits
mailing list