Example #1
0
<?php

define('APPROOT', dirname(__FILE__)) . '/';
include_once APPROOT . '/lib/constants.php';
include_once APPROOT . '/model/pic.class.php';
include_once APPROOT . '/lib/functions.php';
$dbcnx = new PDO(DB_DSN, DB_USER, DB_PW, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
ORM::set_dbcnx($dbcnx);
$limit = PAGE_LIMIT_PIC;
list($params, $limit, $page) = build_iterator_where(PAGE_LIMIT_PIC);
$item_count = ORM::count('Pic', $params);
$maxpage = max(ceil($item_count / $limit) - 1, 0);
$item_count_on_last_page = $item_count - floor($item_count / $limit) * $limit;
if ($item_count_on_last_page == 0) {
    $maxpage -= 1;
}
$urlparams = $_GET;
$visited_pages = cookie_list('visited_pages');
include APPROOT . '/html/component/pager.html.php';
Example #2
0
function render_iterator($class, $page_limit, $template)
{
    list($params, $limit, $page) = build_iterator_where($page_limit);
    $item_count = ORM::count($class, $params);
    $pager_calculator = new PagerCalculator($item_count, $limit);
    $page = $pager_calculator->calculate($page);
    $offset = $pager_calculator->get_offset();
    $limit = $pager_calculator->get_limit();
    $maxpage = $pager_calculator->get_maxpage();
    $items = ORM::all($class, $params, array('ctime', 'desc'), array($offset, $limit));
    $urlparams = array('page' => $page, 'nick' => isset($params['nick']) && $params['nick'] !== null ? rawurlencode($params['nick']) : null, 'day' => isset($params['ctime']) && isset($_GET['day']) ? $_GET['day'] : null, 'week' => isset($params['ctime']) && isset($_GET['week']) ? $_GET['week'] : null, 'url' => isset($params['original_url']) && isset($_GET['url']) ? $_GET['url'] : null, 'limit' => $limit != $page_limit && isset($_GET['limit']) ? $limit : null);
    extract($GLOBALS);
    // since this is an ajax query with only the data included, we can set expires header safely when not on the last page
    if (is_xhr_request() && $page !== $maxpage) {
        header('Expires: ' . date('r', strtotime('+1 week', $_SERVER['REQUEST_TIME'])));
    }
    include APPROOT . '/' . $template;
}