source: trunk/Packages/Common/Common.php

Last change on this file was 888, checked in by chronos, 2 years ago
  • Modified: Updated Common package to latest version.
  • Modified: Fixes related to PHP 8.x.
File size: 4.5 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__).'/View.php');
14include_once(dirname(__FILE__).'/Model.php');
15include_once(dirname(__FILE__).'/ModelDesc.php');
16include_once(dirname(__FILE__).'/Controller.php');
17include_once(dirname(__FILE__).'/System.php');
18include_once(dirname(__FILE__).'/Module.php');
19include_once(dirname(__FILE__).'/ModuleManager.php');
20include_once(dirname(__FILE__).'/Config.php');
21include_once(dirname(__FILE__).'/Page.php');
22include_once(dirname(__FILE__).'/Locale.php');
23include_once(dirname(__FILE__).'/Update.php');
24include_once(dirname(__FILE__).'/Table.php');
25include_once(dirname(__FILE__).'/Process.php');
26include_once(dirname(__FILE__).'/Generics.php');
27include_once(dirname(__FILE__).'/BigInt.php');
28include_once(dirname(__FILE__).'/Int128.php');
29include_once(dirname(__FILE__).'/Pdf.php');
30include_once(dirname(__FILE__).'/Modules/Setup.php');
31include_once(dirname(__FILE__).'/Modules/ModuleManager.php');
32
33class PackageCommon
34{
35 public string $Name;
36 public string $Version;
37 public int $ReleaseDate;
38 public string $License;
39 public string $Creator;
40 public string $Homepage;
41
42 function __construct()
43 {
44 $this->Name = 'Common';
45 $this->Version = '1.2';
46 $this->ReleaseDate = strtotime('2020-03-29');
47 $this->Creator = 'Chronos';
48 $this->License = 'GNU/GPLv3';
49 $this->Homepage = 'https://svn.zdechov.net/PHPlib/Common/';
50 }
51}
52
53class Paging
54{
55 public int $TotalCount;
56 public int $ItemPerPage;
57 public int $Around;
58 public string $SQLLimit;
59 public int $Page;
60
61 function __construct()
62 {
63 global $System;
64
65 $this->ItemPerPage = $System->Config['Web']['ItemsPerPage'];
66 $this->Around = $System->Config['Web']['VisiblePagingItems'];
67 }
68
69 function Show(): string
70 {
71 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
72
73 $Result = '';
74 if (array_key_exists('all', $QueryItems))
75 {
76 $PageCount = 1;
77 $ItemPerPage = $this->TotalCount;
78 } else
79 {
80 $ItemPerPage = $this->ItemPerPage;
81 $Around = round($this->Around / 2);
82 $PageCount = floor($this->TotalCount / $ItemPerPage) + 1;
83 }
84
85 if (!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
86 if (array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
87 if ($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
88 if ($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
89 $CurrentPage = $_SESSION['Page'];
90
91 $Result .= 'Počet položek: <strong>'.$this->TotalCount.'</strong> &nbsp; Stránky: ';
92
93 $Result = '';
94 if ($PageCount > 1)
95 {
96 if ($CurrentPage > 0)
97 {
98 $QueryItems['page'] = 0;
99 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
100 $QueryItems['page'] = ($CurrentPage - 1);
101 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;</a> ';
102 }
103 $PagesMax = $PageCount - 1;
104 $PagesMin = 0;
105 if ($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
106 if ($PagesMin < ($CurrentPage - $Around))
107 {
108 $Result.= ' ... ';
109 $PagesMin = $CurrentPage - $Around;
110 }
111 for ($i = $PagesMin; $i <= $PagesMax; $i++)
112 {
113 if ($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
114 else {
115 $QueryItems['page'] = $i;
116 $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
117 }
118 }
119 if ($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
120 if ($CurrentPage < ($PageCount - 1))
121 {
122 $QueryItems['page'] = ($CurrentPage + 1);
123 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;</a> ';
124 $QueryItems['page'] = ($PageCount - 1);
125 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;&gt;</a>';
126 }
127 }
128 $QueryItems['all'] = '1';
129 if ($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
130
131 $Result = '<div style="text-align: center">'.$Result.'</div>';
132 $this->SQLLimit = ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage;
133 $this->Page = $CurrentPage;
134 return $Result;
135 }
136}
Note: See TracBrowser for help on using the repository browser.