CMSimple_XH 開発者ドキュメント
Li.php
1 <?php
2 
16 namespace XH;
17 
29 class Li
30 {
36  protected $ta;
37 
43  protected $st;
44 
50  protected $tf;
51 
57  protected $b;
58 
64  protected $lf;
65 
76  public function render(array $ta, $st)
77  {
78  global $s;
79 
80  $this->ta = (array) $ta;
81  $this->st = $st;
82  $tl = count($this->ta);
83  if ($tl < 1) {
84  return;
85  }
86  $t = '';
87  if ($this->st == 'submenu' || $this->st == 'search') {
88  $t .= '<ul class="' . $this->st . '">' . "\n";
89  }
90  $this->b = 0;
91  if ($this->st > 0) {
92  $this->b = $this->st - 1;
93  $this->st = 'menulevel';
94  }
95  $this->lf = array();
96  for ($i = 0; $i < $tl; $i++) {
97  $this->tf = ($s != $this->ta[$i]);
98  if ($this->st == 'menulevel' || $this->st == 'sitemaplevel') {
99  $t .= $this->renderULStartTags($i);
100  }
101  $t .= '<li class="' . $this->getClassName($i) . '">';
102  $t .= $this->renderMenuItem($i);
103  if ($this->st == 'menulevel' || $this->st == 'sitemaplevel') {
104  if ($this->getMenuLevel($i + 1) > $this->getMenuLevel($i)) {
105  $this->lf[$this->getMenuLevel($i)] = true;
106  } else {
107  $t .= '</li>' . "\n";
108  $this->lf[$this->getMenuLevel($i)] = false;
109  }
110  $t .= $this->renderEndTags($i);
111  } else {
112  $t .= '</li>' . "\n";
113  }
114  }
115  if ($this->st == 'submenu' || $this->st == 'search') {
116  $t .= '</ul>' . "\n";
117  }
118  return $t;
119  }
120 
128  protected function renderULStartTags($i)
129  {
130  $lines = array();
131  for ($k = $this->getMenuLevel($i - 1); $k < $this->getMenuLevel($i); $k++) {
132  $lines[] = "\n" . '<ul class="' . $this->st . ($k + 1) . '">' . "\n";
133  }
134  return implode('<li>' . "\n", $lines);
135  }
136 
144  protected function renderEndTags($i)
145  {
146  $html = '';
147  for ($k = $this->getMenuLevel($i); $k > $this->getMenuLevel($i + 1); $k--) {
148  $html .= '</ul>' . "\n";
149  if (isset($this->lf[$k - 1]) && $this->lf[$k - 1]) {
150  $html .= '</li>' . "\n";
151  $this->lf[$k - 1] = false;
152  }
153  }
154  return $html;
155  }
156 
166  protected function getMenuLevel($i)
167  {
168  global $l;
169 
170  return isset($this->ta[$i]) ? $l[$this->ta[$i]] : $this->b;
171  }
172 
182  protected function getClassName($i)
183  {
184  $className = '';
185  if ($this->isSelected($i)) {
186  $className .= 's';
187  }
188  $className .= 'doc';
189  if ($this->hasChildren($i)) {
190  $className .= 's';
191  }
192  return $className;
193  }
194 
202  protected function isSelected($i)
203  {
204  global $cf;
205 
206  return !$this->tf
207  || $cf['menu']['sdoc'] == "parent"
208  && $this->isAnchestorOfSelectedPage($i);
209  }
210 
223  protected function isAnchestorOfSelectedPage($i)
224  {
225  global $s, $u, $l, $cf;
226 
227  return $s > -1 && $l[$this->ta[$i]] < $l[$s]
228  && substr($u[$s], 0, 1 + strlen($u[$this->ta[$i]]))
229  == $u[$this->ta[$i]] . $cf['uri']['seperator'];
230  }
231 
243  protected function hasChildren($i)
244  {
245  global $cl, $l, $cf;
246 
247  for ($j = $this->ta[$i] + 1; $j < $cl; $j++) {
248  if (!hide($j)
249  && $l[$j] - $l[$this->ta[$i]] < 2 + $cf['menu']['levelcatch']
250  ) {
251  if ($l[$j] > $l[$this->ta[$i]]) {
252  return true;
253  }
254  break;
255  }
256  }
257  return false;
258  }
259 
269  protected function renderMenuItem($i)
270  {
271  global $h;
272 
273  if ($this->tf) {
274  $html = $this->renderAnchorStartTag($i);
275  } else {
276  $html ='<span>';
277  }
278  $html .= $h[$this->ta[$i]];
279  if ($this->tf) {
280  $html .= '</a>';
281  } else {
282  $html .='</span>';
283  }
284  return $html;
285  }
286 
294  protected function renderAnchorStartTag($i)
295  {
296  $x = $this->shallOpenInNewWindow($i) ? '" target="_blank' : '';
297  return a($this->ta[$i], $x);
298  }
299 
310  protected function shallOpenInNewWindow($i)
311  {
312  global $edit, $pd_router;
313 
314  $pageData = $pd_router->find_page($this->ta[$i]);
315  return !(XH_ADM && $edit) && $pageData['use_header_location'] === '2';
316  }
317 }
$l
Definition: cms.php:1003
renderEndTags($i)
Definition: Li.php:144
getClassName($i)
Definition: Li.php:182
renderAnchorStartTag($i)
Definition: Li.php:294
isSelected($i)
Definition: Li.php:202
$j
Definition: cms.php:204
hasChildren($i)
Definition: Li.php:243
shallOpenInNewWindow($i)
Definition: Li.php:310
$s
Definition: cms.php:953
renderMenuItem($i)
Definition: Li.php:269
getMenuLevel($i)
Definition: Li.php:166
$i
Definition: cms.php:193
$cf
Definition: cms.php:272
render(array $ta, $st)
Definition: Li.php:76
renderULStartTags($i)
Definition: Li.php:128
hide($i)
Definition: functions.php:1100
$u
Definition: cms.php:990
Definition: Li.php:29
$h
Definition: cms.php:977
const XH_ADM
Definition: cms.php:897
isAnchestorOfSelectedPage($i)
Definition: Li.php:223
a($i, $x)
Definition: functions.php:931
$pd_router
Definition: cms.php:929
$edit
Definition: cms.php:602
$cl
Definition: cms.php:918