source: branches/version-2_13-dev/data/class/SC_PageNavi.php @ 23605

Revision 23605, 6.3 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/* ※使用条件※
25    ・formタグに以下を追加する。
26        <input type='hidden' name='pageno' value="<!--{$tpl_pageno}-->">
27    ・ソースの最初に以下を記述する。
28        $objPage->tpl_pageno = $_POST['pageno'];
29    ・$func_nameに指定するJavaScriptの例
30        // ページナビで使用する。
31        eccube.movePage = function(pageno, mode, form) {
32            if (typeof form !== 'undefined') {
33                form = 'form1';
34            }
35            document.forms[form]['pageno'].value = pageno;
36            if (typeof mode !== 'undefined') {
37                document.forms[form]['mode'].value = 'search';
38            }
39            document.forms[form].submit();
40        };
41*/
42class SC_PageNavi
43{
44    public $now_page;      // 現在のページ番号
45    public $max_page;      // 最終のページ番号
46    public $start_row;     // 開始レコード
47    public $strnavi;       // ページ送り文字列
48    public $arrPagenavi = array(); // ページ
49
50    // コンストラクタ
51
52    /**
53     * @param string $func_name
54     */
55    public function __construct($now_page, $all_row, $page_row, $func_name, $navi_max = NAVI_PMAX, $urlParam = '', $display_number = true)
56    {
57        $this->arrPagenavi['mode'] = 'search';
58
59        //現在ページ($now_page)が正しい数値でない場合
60        if (!preg_match("/^[[:digit:]]+$/", $now_page) || $now_page < 1 || strlen($now_page) == 0) {
61            $this->now_page = 1;
62        } else {
63            $this->now_page = htmlspecialchars($now_page, ENT_QUOTES, CHAR_CODE);
64        }
65        $this->arrPagenavi['now_page'] = $this->now_page;
66
67        // 最終ページの計算
68        $this->max_page = ceil($all_row/$page_row);
69
70        // 最終ページよりも現在ページが大きい場合は、最初に戻す。
71        if ($this->max_page < $this->now_page) {
72            $this->now_page = 1;
73        }
74
75        $this->start_row    = ($this->now_page - 1) * $page_row;
76        $this->all_row      = $all_row;
77
78        // 開始行が不正な場合
79        if (!($this->start_row < $all_row && $this->start_row >= 0)) {
80            $this->start_row = 0;
81        }
82
83        if ($all_row > 1) {
84            //「前へ」「次へ」の設定
85            $before = '';
86            $next = '';
87            if ($this->now_page > 1) {
88                $this->arrPagenavi['before'] = $this->now_page - 1;
89                $urlParamThis = str_replace('#page#', $this->arrPagenavi['before'], $urlParam);
90                $urlParamThis = htmlentities($urlParamThis, ENT_QUOTES);
91                $before = "<a href=\"?$urlParamThis\" onclick=\"$func_name('{$this->arrPagenavi['before']}'); return false;\">&lt;&lt;前へ</a> ";
92            } else {
93                $this->arrPagenavi['before'] = $this->now_page;
94            }
95
96            if ($this->now_page < $this->max_page) {
97                $this->arrPagenavi['next'] = $this->now_page + 1;
98                $urlParamThis = str_replace('#page#', $this->arrPagenavi['next'], $urlParam);
99                $urlParamThis = htmlentities($urlParamThis, ENT_QUOTES);
100                $next = " <a href=\"?$urlParamThis\" onclick=\"$func_name('{$this->arrPagenavi['next']}'); return false;\">次へ&gt;&gt;</a>";
101            } else {
102                $this->arrPagenavi['next'] = $this->now_page;
103            }
104
105            // 表示する最大ナビ数を決める。
106            if ($navi_max == '' || $navi_max > $this->max_page) {
107                // 制限ナビ数の指定がない。ページ最大数が制限ナビ数より少ない。
108                $disp_max = $this->max_page;
109            } else {
110                // 現在のページ+制限ナビ数が表示される。
111                $disp_max = $this->now_page + $navi_max - 1;
112                // ページ最大数を超えている場合は、ページ最大数に合わせる。
113                if ($disp_max > $this->max_page) {
114                    $disp_max = $this->max_page;
115                }
116            }
117
118            // 表示する最小ナビ数を決める。
119            if ($navi_max == '' || $navi_max > $this->now_page) {
120                // 制限ナビ数の指定がない。現在ページ番号が制限ナビ数より少ない。
121                $disp_min = 1;
122            } else {
123                // 現在のページ-制限ナビ数が表示される。
124                $disp_min = $this->now_page - $navi_max + 1;
125            }
126
127            $this->arrPagenavi['arrPageno'] = array();
128            $page_number = '';
129            for ($i = $disp_min; $i <= $disp_max; $i++) {
130                if ($i == $this->now_page) {
131                    $page_number .= "<strong>$i</strong>";
132                } else {
133                    $urlParamThis = str_replace('#page#', $i, $urlParam);
134                    $urlParamThis = htmlentities($urlParamThis, ENT_QUOTES);
135                    $page_number .= "<a href=\"?$urlParamThis\" onclick=\"$func_name('$i'); return false;\">$i</a>";
136                }
137
138                $page_number .= ' ';
139
140                $this->arrPagenavi['arrPageno'][$i] = $i;
141            }
142
143            if ($before && $next) {
144                $this->strnavi = $before .(($display_number) ? $page_number : ' | ') .$next;
145            } elseif ($before || $next) {
146                $this->strnavi = $before .(($display_number) ? $page_number : '') .$next;
147            }
148        } else {
149            $this->arrPagenavi['arrPageno'][0] = 1;
150            $this->arrPagenavi['before'] = 1;
151            $this->arrPagenavi['next'] = 1;
152        }
153    }
154}
Note: See TracBrowser for help on using the repository browser.