/** * Checks the range of integral values * * @param string $name The name of the option being validated * @param unknown_type $candidate The new value for this option * @param int $min The minimum (inclusive) value this option * can take * @param int $max The maximum (inclusive) value this option * can take * * @return void */ private static function _checkIntegerRange($name, $candidate, $min, $max, org_tubepress_api_message_MessageService $messageService) { if ($candidate < $min || $candidate > $max) { throw new Exception(sprintf($messageService->_('validation-int-range'), $name, $min, $max, $candidate)); } }
/** * Does the heavy lifting of generating pagination. * * @param int $totalitems The total items in this gallery. * @param int $page The current page number. * @param int $limit How many videos per page. * @param int $adjacents How many adjacents. * @param string $targetpage The target page * @param string $pagestring The query parameter controlling the page number. * * @return The HTML for the pagination */ private function _diggStyle($totalitems, org_tubepress_api_message_MessageService $messageService, $page = 1, $limit = 15, $adjacents = 1, $targetpage = '/', $pagestring = '?page=') { $prev = $page - 1; $next = $page + 1; $lastpage = ceil($totalitems / $limit); $lpm1 = $lastpage - 1; $pagination = ''; $url = new org_tubepress_api_url_Url($targetpage); if ($lastpage > 1) { $pagination .= '<div class="pagination">'; if ($page > 1) { $url->setQueryVariable($pagestring, $prev); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">« " . $messageService->_("prev") . '</a>'; } if ($lastpage < 7 + $adjacents * 2) { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) { $pagination .= "<span class=\"current\">{$counter}</span>"; } else { $url->setQueryVariable($pagestring, $counter); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">{$counter}</a>"; } } } elseif ($lastpage >= 7 + $adjacents * 2) { if ($page < 1 + $adjacents * 3) { for ($counter = 1; $counter < 4 + $adjacents * 2; $counter++) { if ($counter == $page) { $pagination .= "<span class=\"current\">{$counter}</span>"; } else { $url->setQueryVariable($pagestring, $counter); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">{$counter}</a>"; } } $pagination .= self::DOTS; $url->setQueryVariable($pagestring, $lpm1); $newurl = $url->toString(); $pagination .= " <a rel=\"nofollow\" href=\"{$newurl}\">{$lpm1}</a>"; $url->setQueryVariable($pagestring, $lastpage); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">{$lastpage}</a>"; } elseif ($lastpage - $adjacents * 2 > $page && $page > $adjacents * 2) { $url->setQueryVariable($pagestring, 1); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">1</a>"; $url->setQueryVariable($pagestring, 2); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">2</a>"; $pagination .= self::DOTS; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) { $pagination .= "<span class=\"current\">{$counter}</span>"; } else { $url->setQueryVariable($pagestring, $counter); $newurl = $url->toString(); $pagination .= " <a rel=\"nofollow\" href=\"{$newurl}\">{$counter}</a>"; } } $pagination .= self::DOTS; $url->setQueryVariable($pagestring, $lpm1); $newurl = $url->toString(); $pagination .= " <a rel=\"nofollow\" href=\"{$newurl}\">{$lpm1}</a>"; $url->setQueryVariable($pagestring, $lastpage); $newurl = $url->toString(); $pagination .= " <a rel=\"nofollow\" href=\"{$newurl}\">{$lastpage}</a>"; } else { $url->setQueryVariable($pagestring, 1); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">1</a>"; $url->setQueryVariable($pagestring, 2); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">2</a>"; $pagination .= self::DOTS; for ($counter = $lastpage - (1 + $adjacents * 3); $counter <= $lastpage; $counter++) { if ($counter == $page) { $pagination .= "<span class=\"current\">{$counter}</span>"; } else { $url->setQueryVariable($pagestring, $counter); $newurl = $url->toString(); $pagination .= " <a rel=\"nofollow\" href=\"{$newurl}\">{$counter}</a>"; } } } } if ($page < $counter - 1) { $url->setQueryVariable($pagestring, $next); $newurl = $url->toString(); $pagination .= "<a rel=\"nofollow\" href=\"{$newurl}\">" . $messageService->_('next') . ' »</a>'; } else { $pagination .= '<span class="disabled">' . $messageService->_('next') . ' »</span>'; } $pagination .= "</div>\n"; } return $pagination; }