CMSimple_XH 開発者ドキュメント
Pages.php
1 <?php
2 
14 namespace XH;
15 
27 class Pages
28 {
36  private $count;
37 
45  private $headings;
46 
54  private $urls;
55 
63  private $levels;
64 
72  private $contents;
73 
82  public function __construct()
83  {
84  global $h, $u, $l, $c;
85 
86  $this->count = count($c);
87  $this->headings = $h;
88  $this->urls = $u;
89  $this->contents = $c;
90  $this->levels = $l;
91  }
92 
102  public function isHidden($n)
103  {
104  return hide($n);
105  }
106 
112  public function getCount()
113  {
114  return $this->count;
115  }
116 
126  public function heading($n)
127  {
128  return $this->headings[$n];
129  }
130 
145  public function name($n)
146  {
147  return html_entity_decode(strip_tags($this->headings[$n]), ENT_QUOTES, 'UTF-8');
148  }
149 
157  public function url($n)
158  {
159  return $this->urls[$n];
160  }
161 
169  public function level($n)
170  {
171  return $this->levels[$n];
172  }
173 
181  public function content($n)
182  {
183  return $this->contents[$n];
184  }
185 
193  public function toplevels($ignoreHidden = true)
194  {
195  $result = array();
196  for ($i = 0; $i < $this->count; ++$i) {
197  if ($this->levels[$i] == 1
198  && (!$ignoreHidden || !$this->isHidden($i))
199  ) {
200  $result[] = $i;
201  }
202  }
203  return $result;
204  }
205 
216  public function children($n, $ignoreHidden = true)
217  {
218  global $cf;
219 
220  $result = array();
221  $ll = $cf['menu']['levelcatch'];
222  for ($i = $n + 1; $i < $this->count; ++$i) {
223  if ($ignoreHidden && $this->isHidden($i)) {
224  continue;
225  }
226  if ($this->levels[$i] <= $this->levels[$n]) {
227  break;
228  }
229  if ($this->levels[$i] <= $ll) {
230  $result[] = $i;
231  $ll = $this->levels[$i];
232  }
233  }
234  return $result;
235  }
236 
246  public function parent($n, $ignoreHidden = true)
247  {
248  for ($i = $n - 1; $i >= 0; --$i) {
249  if ($this->levels[$i] < $this->levels[$n]
250  && (!$ignoreHidden || !$this->isHidden($i))
251  ) {
252  return $i;
253  }
254  }
255  return null;
256  }
257 
268  public function getAncestorsOf($pageIndex, $ignoreHidden = true)
269  {
270  $result = array();
271  while (true) {
272  $parent = $this->parent($pageIndex, $ignoreHidden);
273  if ($parent === null) {
274  break;
275  }
276  $result[] = $parent;
277  $pageIndex = $parent;
278  }
279  return $result;
280  }
281 
289  public function pageWithHeading($heading)
290  {
291  for ($i = 0; $i < $this->count; $i++) {
292  if ($this->headings[$i] == $heading) {
293  return $i;
294  }
295  }
296  return -1;
297  }
298 
309  public function linkList($prefix = '', $ignoreHidden = true)
310  {
311  $result = array();
312  for ($i = 0; $i < $this->count; $i++) {
313  if (!$ignoreHidden || !$this->isHidden($i)) {
314  $indent = str_repeat("\xC2\xA0", 4 * ($this->level($i) - 1));
315  $heading = $prefix . $indent . $this->heading($i);
316  $result[] = array($heading, $this->url($i));
317  }
318  }
319  return $result;
320  }
321 }
content($n)
Definition: Pages.php:181
$l
Definition: cms.php:1003
getAncestorsOf($pageIndex, $ignoreHidden=true)
Definition: Pages.php:268
url($n)
Definition: Pages.php:157
children($n, $ignoreHidden=true)
Definition: Pages.php:216
name($n)
Definition: Pages.php:145
heading($n)
Definition: Pages.php:126
$i
Definition: cms.php:193
toplevels($ignoreHidden=true)
Definition: Pages.php:193
$cf
Definition: cms.php:272
hide($i)
Definition: functions.php:1100
$c
Definition: cms.php:964
level($n)
Definition: Pages.php:169
$u
Definition: cms.php:990
isHidden($n)
Definition: Pages.php:102
$h
Definition: cms.php:977
__construct()
Definition: Pages.php:82
pageWithHeading($heading)
Definition: Pages.php:289
linkList($prefix='', $ignoreHidden=true)
Definition: Pages.php:309
parent($n, $ignoreHidden=true)
Definition: Pages.php:246
getCount()
Definition: Pages.php:112