2021-09-07 12:33:18 +00:00
|
|
|
<?php
|
2021-09-07 13:21:38 +00:00
|
|
|
/**
|
|
|
|
* @brief cinecturlink2, a plugin for Dotclear 2
|
2021-11-02 22:55:41 +00:00
|
|
|
*
|
2021-09-07 13:21:38 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-02 22:55:41 +00:00
|
|
|
*
|
2021-09-07 13:21:38 +00:00
|
|
|
* @author Jean-Christian Denis and Contributors
|
2021-11-02 22:55:41 +00:00
|
|
|
*
|
2021-09-07 13:21:38 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-09-07 12:33:18 +00:00
|
|
|
class cinecturlink2Context
|
|
|
|
{
|
2021-09-07 13:21:38 +00:00
|
|
|
public static function PaginationNbPages()
|
|
|
|
{
|
|
|
|
global $_ctx;
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
if ($_ctx->c2_pagination === null) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
$nb_posts = $_ctx->c2_pagination->f(0);
|
2021-09-07 13:21:38 +00:00
|
|
|
$nb_per_page = $_ctx->c2_params['limit'][1];
|
2021-11-02 22:55:41 +00:00
|
|
|
$nb_pages = ceil($nb_posts / $nb_per_page);
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
return $nb_pages;
|
|
|
|
}
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 23:47:45 +00:00
|
|
|
public static function PaginationPosition($offset = 0)
|
2021-09-07 13:21:38 +00:00
|
|
|
{
|
|
|
|
if (isset($GLOBALS['c2_page_number'])) {
|
|
|
|
$p = $GLOBALS['c2_page_number'];
|
2021-09-07 23:47:45 +00:00
|
|
|
} else {
|
2021-09-07 13:21:38 +00:00
|
|
|
$p = 1;
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
$p = $p + $offset;
|
2021-09-07 13:21:38 +00:00
|
|
|
$n = self::PaginationNbPages();
|
|
|
|
if (!$n) {
|
|
|
|
return $p;
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
return $p > $n || $p <= 0 ? 1 : $p;
|
|
|
|
}
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
public static function PaginationStart()
|
|
|
|
{
|
|
|
|
if (isset($GLOBALS['c2_page_number'])) {
|
|
|
|
return self::PaginationPosition() == 1;
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
public static function PaginationEnd()
|
2021-11-02 22:55:41 +00:00
|
|
|
{
|
2021-09-07 13:21:38 +00:00
|
|
|
if (isset($GLOBALS['c2_page_number'])) {
|
|
|
|
return self::PaginationPosition() == self::PaginationNbPages();
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 23:47:45 +00:00
|
|
|
public static function PaginationURL($offset = 0)
|
2021-09-07 13:21:38 +00:00
|
|
|
{
|
|
|
|
$args = $_SERVER['URL_REQUEST_PART'];
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
$n = self::PaginationPosition($offset);
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
$args = preg_replace('#(^|/)c2page/([0-9]+)$#', '', $args);
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 23:47:45 +00:00
|
|
|
$url = $GLOBALS['core']->blog->url . $args;
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
if ($n > 1) {
|
2021-09-07 23:47:45 +00:00
|
|
|
$url = preg_replace('#/$#', '', $url);
|
|
|
|
$url .= '/c2page/' . $n;
|
2021-09-07 13:21:38 +00:00
|
|
|
}
|
|
|
|
# If search param
|
|
|
|
if (!empty($_GET['q'])) {
|
2021-11-02 22:55:41 +00:00
|
|
|
$s = strpos($url, '?') !== false ? '&' : '?';
|
2021-09-07 23:47:45 +00:00
|
|
|
$url .= $s . 'q=' . rawurlencode($_GET['q']);
|
2021-09-07 13:21:38 +00:00
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
return $url;
|
|
|
|
}
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
public static function categoryCurrent()
|
|
|
|
{
|
|
|
|
global $_ctx;
|
2021-09-07 12:33:18 +00:00
|
|
|
|
2021-11-02 22:55:41 +00:00
|
|
|
if (!isset($_ctx->c2_page_params['cat_id'])
|
2021-09-07 23:47:45 +00:00
|
|
|
&& !isset($_ctx->c2_page_params['cat_title'])
|
|
|
|
) {
|
2021-09-07 13:21:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
if (isset($_ctx->c2_page_params['cat_id'])
|
2021-09-07 23:47:45 +00:00
|
|
|
&& $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id
|
|
|
|
) {
|
2021-09-07 13:21:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
if (isset($_ctx->c2_page_params['cat_title'])
|
2021-09-07 23:47:45 +00:00
|
|
|
&& $_ctx->c2_page_params['cat_title'] == $_ctx->c2_categories->cat_title
|
|
|
|
) {
|
2021-09-07 13:21:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
|
2021-09-07 13:21:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-11-02 22:55:41 +00:00
|
|
|
}
|