CMSimple_XH 開発者ドキュメント
Publisher.php
1 <?php
2 
16 namespace XH;
17 
35 class Publisher
36 {
42  private $published = array();
43 
49  private $hidden = array();
50 
56  private $pages;
57 
63  public function __construct(array $removed)
64  {
65  global $pd_router, $cl, $edit;
66 
67  $pd_router->add_interest('published');
68  $pd_router->add_interest('publication_date');
69  $pd_router->add_interest('expires');
70  $pd_router->add_interest('linked_to_menu');
71  if (XH_ADM && $edit) {
72  $this->hidden = array_fill(0, $cl, false);
73  $this->published = array_fill(0, $cl, true);
74  } else {
75  foreach ($pd_router->find_all() as $index => $data) {
76  $this->hidden[$index] = $data['linked_to_menu'] == '0'
77  || !$removed[$index] && hide($index);
78  $this->published[$index] = !$removed[$index]
79  && $this->isPublishedInPageData($data);
80  }
81  }
82  $this->pages = new Pages;
83  }
84 
97  public function isPublished($index)
98  {
99  $parent = $index;
100  while (isset($parent) && $this->published[$parent]) {
101  $parent = $this->pages->parent($parent, false);
102  }
103  if (isset($parent)) {
104  return false;
105  }
106  return $this->published[$index];
107  }
108 
121  public function isHidden($index)
122  {
123  $parent = $index;
124  while (isset($parent) && !$this->hidden[$parent]) {
125  $parent = $this->pages->parent($parent, false);
126  }
127  if (isset($parent)) {
128  return true;
129  }
130  return $this->hidden[$index];
131  }
132 
138  public function getFirstPublishedPage()
139  {
140  for ($i = 0; $i < $this->pages->getCount(); $i++) {
141  if ($this->isPublished($i)) {
142  return $i;
143  }
144  }
145  return -1;
146  }
147 
155  private function isPublishedInPageData(array $data)
156  {
157  if ($data['published'] == '0') {
158  return false;
159  }
160  $publication_date = isset($data['publication_date'])
161  ? trim($data['publication_date'])
162  : '';
163  $expires = isset($data['expires']) ? trim($data['expires']) : '';
164  if ($expires != '' || $publication_date != '') {
165  $current = time();
166  $maxInt = defined('PHP_INT_MAX') ? PHP_INT_MAX : 2147483647;
167  $int_publication_date = ($publication_date != '')
168  ? strtotime($publication_date) : 0;
169  $int_expiration_date = ($expires != '')
170  ? strtotime($expires) : $maxInt;
171  if ($current <= $int_publication_date
172  || $current >= $int_expiration_date
173  ) {
174  return false;
175  }
176  }
177  return true;
178  }
179 }
getFirstPublishedPage()
Definition: Publisher.php:138
$i
Definition: cms.php:193
hide($i)
Definition: functions.php:1100
isHidden($index)
Definition: Publisher.php:121
const XH_ADM
Definition: cms.php:897
isPublished($index)
Definition: Publisher.php:97
__construct(array $removed)
Definition: Publisher.php:63
$pd_router
Definition: cms.php:929
$edit
Definition: cms.php:602
$cl
Definition: cms.php:918