Dotclear

source: plugins/cinecturlink2/inc/lib.cinecturlink2.context.php @ 3247

Revision 3247, 2.4 KB checked in by JcDenis, 10 years ago (diff)

Switch to Dotclear 2.6, Add dashboard icon, Clean up code

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of cinecturlink2, a plugin for Dotclear 2.
5#
6# Copyright (c) 2009-2013 Jean-Christian Denis and contributors
7# contact@jcdenis.fr http://jcd.lv
8#
9# Licensed under the GPL version 2.0 license.
10# A copy of this license is available in LICENSE file or at
11# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12#
13# -- END LICENSE BLOCK ------------------------------------
14
15class cinecturlink2Context
16{
17     public static function PaginationNbPages()
18     {
19          global $_ctx;
20
21          if ($_ctx->c2_pagination === null) {
22
23               return false;
24          }
25
26          $nb_posts = $_ctx->c2_pagination->f(0);
27          $nb_per_page = $_ctx->c2_params['limit'][1];
28
29          $nb_pages = ceil($nb_posts/$nb_per_page);
30
31          return $nb_pages;
32     }
33
34     public static function PaginationPosition($offset=0)
35     {
36          if (isset($GLOBALS['c2_page_number'])) {
37               $p = $GLOBALS['c2_page_number'];
38          }
39          else {
40               $p = 1;
41          }
42
43          $p = $p+$offset;
44
45          $n = self::PaginationNbPages();
46          if (!$n) {
47
48               return $p;
49          }
50
51          return $p > $n || $p <= 0 ? 1 : $p;
52     }
53
54     public static function PaginationStart()
55     {
56          if (isset($GLOBALS['c2_page_number'])) {
57
58               return self::PaginationPosition() == 1;
59          }
60
61          return true;
62     }
63     
64     public static function PaginationEnd()
65     {   
66          if (isset($GLOBALS['c2_page_number'])) {
67
68               return self::PaginationPosition() == self::PaginationNbPages();
69          }
70
71          return false;
72     }
73     
74     public static function PaginationURL($offset=0)
75     {
76          $args = $_SERVER['URL_REQUEST_PART'];
77
78          $n = self::PaginationPosition($offset);
79
80          $args = preg_replace('#(^|/)c2page/([0-9]+)$#', '', $args);
81
82          $url = $GLOBALS['core']->blog->url.$args;
83
84          if ($n > 1) {
85               $url = preg_replace('#/$#','',$url);
86               $url .= '/c2page/'.$n;
87          }
88
89          # If search param
90          if (!empty($_GET['q'])) {
91               $s = strpos($url,'?') !== false ? '&amp;' : '?';
92               $url .= $s.'q='.rawurlencode($_GET['q']);
93          }
94
95          return $url;
96     }
97
98     public static function categoryCurrent()
99     {
100          global $_ctx;
101
102          if (!isset($_ctx->c2_page_params['cat_id']) && !isset($_ctx->c2_page_params['cat_title'])) {
103
104               return false;
105          }
106          if (isset($_ctx->c2_page_params['cat_id']) && $_ctx->c2_page_params['cat_id'] == $_ctx->c2_categories->cat_id) {
107
108               return true;
109          }
110          if (isset($_ctx->c2_page_params['cat_title']) && $_ctx->c2_page_params['cat_title'] == $_ctx->c2_categories->cat_title) {
111
112               return true;
113          }
114
115          return false;
116     }
117}
Note: See TracBrowser for help on using the repository browser.

Sites map