This repository has been archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.php
187 lines (173 loc) · 4.83 KB
/
Model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
* The model class of Pagemanager_XH.
*
* PHP versions 4 and 5
*
* @category CMSimple_XH
* @package Pagemanager
* @author Christoph M. Becker <cmbecker69@gmx.de>
* @copyright 2011-2015 Christoph M. Becker <http://3-magi.net>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @version SVN: $Id$
* @link http://3-magi.net/?CMSimple_XH/Pagemanager_XH
*/
/**
* The model class of Pagemanager_XH.
*
* @category CMSimple_XH
* @package Pagemanager
* @author Christoph M. Becker <cmbecker69@gmx.de>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @link http://3-magi.net/?CMSimple_XH/Pagemanager_XH
*/
class Pagemanager_Model
{
/**
* The unmodified page headings.
*
* @var array
*/
var $headings;
/**
* Whether the pages may be renamed.
*
* @var array
*/
var $mayRename;
/**
* Returns whether a heading may be renamed.
*
* Renaming is only allow if the heading doesn't contain any markup,
* besides the generally recognized XML entities.
*
* @param string $heading A page heading.
*
* @return string
*
* @since 2.0.1
*/
function mayRename($heading)
{
return !preg_match('/<|&(?!(?:amp|quot|lt|gt);)/', $heading);
}
/**
* Returns a cleaned heading.
*
* Trims, strips off all tags and decodes HTML entities in the heading.
* For PHP 4 a simplified fallback is used which does not properly decode
* the HTML entities, but rather replaces them with the Unicode substitution
* character.
*
* @param string $heading A page heading.
*
* @return string
*
* @since 2.0.1
*/
function cleanedHeading($heading)
{
$heading = trim(strip_tags($heading));
if (version_compare(PHP_VERSION, '5', 'ge')) {
$heading = html_entity_decode($heading, ENT_COMPAT, 'UTF-8');
$heading = htmlspecialchars($heading, ENT_COMPAT, 'UTF-8');
} else {
$pattern = '/&(?!(?:amp|quot|lt|gt);).+;/';
$heading = preg_replace($pattern, "\xEF\xBF\xBD", $heading);
}
return $heading;
}
/**
* Initializes <var>$headings</var> and <var>$mayRename</var>.
*
* @return void
*
* @global array The content of the pages.
* @global array The configuration of the core.
* @global array The localization of the core.
*/
function getHeadings()
{
global $c, $h, $cf, $tx;
$empty = 0;
foreach ($c as $i => $page) {
$heading = $this->cleanedHeading($h[$i]);
if ($heading === '') {
$empty += 1;
$this->headings[$i] = $tx['toc']['empty'] . ' ' . $empty;
} else {
$this->headings[$i] = $heading;
}
$this->mayRename[$i] = $this->mayRename($h[$i]);
}
}
/**
* Returns whether the page structure is irregular.
*
* @return bool
*
* @global array The menu levels of the pages.
* @global int The number of pages.
*/
function isIrregular()
{
global $l, $cl;
$stack = array();
for ($i = 1; $i < $cl; $i++) {
$delta = $l[$i] - $l[$i - 1];
if ($delta > 1) {
return true;
}
}
return false;
}
/**
* Returns the available themes.
*
* @return array
*
* @global array The paths of system files and folders.
*/
function themes()
{
global $pth;
$themes = array();
$path = "{$pth['folder']['plugins']}pagemanager/jstree/themes/";
$dir = opendir($path);
if ($dir !== false) {
while (($entry = readdir($dir)) !== false) {
if ($entry[0] !== '.' && is_dir($path . $entry)) {
$themes[] = $entry;
}
}
}
natcasesort($themes);
return $themes;
}
/**
* Saves the content. Returns whether that succeeded.
*
* @param string $xml An XML document.
*
* @return bool
*
* @global array The contents of the pages.
* @global array The paths of system files and folders.
* @global array The configuration of the core.
* @global array The configuration of the plugins.
* @global object The page data router.
*/
function save($xml)
{
global $c, $pth, $cf, $plugin_cf, $pd_router;
include_once "{$pth['folder']['plugins']}pagemanager/classes/XMLParser.php";
$parser = new Pagemanager_XMLParser(
$c,
$plugin_cf['pagemanager']['pagedata_attribute']
);
$parser->parse($xml);
$c = $parser->getContents();
return $pd_router->model->refresh($parser->getPageData());
}
}
?>