source: trunk/Packages/Common/Common.php@ 887

Last change on this file since 887 was 887, checked in by chronos, 5 years ago
  • Added: Static types added to almost all classes, methods and function. Supported by PHP 7.4.
  • Fixed: Various found code issues.
File size: 4.2 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Database.php');
4include_once(dirname(__FILE__).'/Image.php');
5include_once(dirname(__FILE__).'/Mail.php');
6include_once(dirname(__FILE__).'/NetworkAddress.php');
7include_once(dirname(__FILE__).'/PrefixMultiplier.php');
8include_once(dirname(__FILE__).'/RSS.php');
9include_once(dirname(__FILE__).'/UTF8.php');
10include_once(dirname(__FILE__).'/VarDumper.php');
11include_once(dirname(__FILE__).'/Error.php');
12include_once(dirname(__FILE__).'/Base.php');
13include_once(dirname(__FILE__).'/Application.php');
14include_once(dirname(__FILE__).'/AppModule.php');
15include_once(dirname(__FILE__).'/Config.php');
16include_once(dirname(__FILE__).'/Page.php');
17include_once(dirname(__FILE__).'/Locale.php');
18include_once(dirname(__FILE__).'/Update.php');
19include_once(dirname(__FILE__).'/Setup.php');
20include_once(dirname(__FILE__).'/Table.php');
21include_once(dirname(__FILE__).'/Process.php');
22include_once(dirname(__FILE__).'/Generics.php');
23include_once(dirname(__FILE__).'/BigInt.php');
24include_once(dirname(__FILE__).'/Int128.php');
25
26class PackageCommon
27{
28 public string $Name;
29 public string $Version;
30 public int $ReleaseDate;
31 public string $License;
32 public string $Creator;
33 public string $Homepage;
34
35 function __construct()
36 {
37 $this->Name = 'Common';
38 $this->Version = '1.2';
39 $this->ReleaseDate = strtotime('2020-03-29');
40 $this->Creator = 'Chronos';
41 $this->License = 'GNU/GPL';
42 $this->Homepage = 'https://svn.zdechov.net/PHPlib/Common/';
43 }
44}
45
46class Paging
47{
48 public int $TotalCount;
49 public int $ItemPerPage;
50 public int $Around;
51 public string $SQLLimit;
52 public int $Page;
53
54 function __construct()
55 {
56 global $System;
57
58 $this->ItemPerPage = $System->Config['Web']['ItemsPerPage'];
59 $this->Around = $System->Config['Web']['VisiblePagingItems'];
60 }
61
62 function Show(): string
63 {
64 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
65
66 $Result = '';
67 if (array_key_exists('all', $QueryItems))
68 {
69 $PageCount = 1;
70 $ItemPerPage = $this->TotalCount;
71 } else
72 {
73 $ItemPerPage = $this->ItemPerPage;
74 $Around = round($this->Around / 2);
75 $PageCount = floor($this->TotalCount / $ItemPerPage) + 1;
76 }
77
78 if (!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
79 if (array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
80 if ($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
81 if ($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
82 $CurrentPage = $_SESSION['Page'];
83
84 $Result .= 'Počet položek: <strong>'.$this->TotalCount.'</strong> &nbsp; Stránky: ';
85
86 $Result = '';
87 if ($PageCount > 1)
88 {
89 if ($CurrentPage > 0)
90 {
91 $QueryItems['page'] = 0;
92 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
93 $QueryItems['page'] = ($CurrentPage - 1);
94 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;</a> ';
95 }
96 $PagesMax = $PageCount - 1;
97 $PagesMin = 0;
98 if ($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
99 if ($PagesMin < ($CurrentPage - $Around))
100 {
101 $Result.= ' ... ';
102 $PagesMin = $CurrentPage - $Around;
103 }
104 for ($i = $PagesMin; $i <= $PagesMax; $i++)
105 {
106 if ($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
107 else {
108 $QueryItems['page'] = $i;
109 $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
110 }
111 }
112 if ($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
113 if ($CurrentPage < ($PageCount - 1))
114 {
115 $QueryItems['page'] = ($CurrentPage + 1);
116 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;</a> ';
117 $QueryItems['page'] = ($PageCount - 1);
118 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;&gt;</a>';
119 }
120 }
121 $QueryItems['all'] = '1';
122 if ($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
123
124 $Result = '<div style="text-align: center">'.$Result.'</div>';
125 $this->SQLLimit = ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage;
126 $this->Page = $CurrentPage;
127 return $Result;
128 }
129}
Note: See TracBrowser for help on using the repository browser.