CMSimple_XH 開発者ドキュメント
tplfuncs.php
[詳解]
1 <?php
2 
29 {
30  global $sn, $u;
31 
32  $index = XH_findPreviousPage();
33  if ($index !== false) {
34  return '<link rel="prev" href="' . $sn . '?' . $u[$index] . '">';
35  } else {
36  return '';
37  }
38 }
39 
51 {
52  global $sn, $u;
53 
54  $index = XH_findNextPage();
55  if ($index !== false) {
56  return '<link rel="next" href="' . $sn . '?' . $u[$index] . '">';
57  } else {
58  return '';
59  }
60 }
61 
73 function head()
74 {
75  global $title, $cf, $pth, $tx, $hjs;
76 
77  $t = XH_title($cf['site']['title'], $title);
78  $t = '<title>' . strip_tags($t) . '</title>' . "\n";
79  foreach (array_keys(array_merge($cf['meta'], $tx['meta'])) as $i) {
80  $t .= meta($i);
81  }
82  $t = '<meta http-equiv="content-type" content="text/html;charset=UTF-8">'
83  . "\n" . $t;
84  $plugins = implode(', ', XH_plugins());
85  $o = $t;
86  if (error_reporting() > 0) {
87  $o .= '<meta name="generator" content="' . CMSIMPLE_XH_VERSION . ' '
88  . CMSIMPLE_XH_BUILD . ' - www.cmsimple-xh.org">'
89  . "\n"
90  . '<!-- plugins: ' . $plugins . ' -->' . "\n";
91  }
93  . '<link rel="stylesheet" href="' . XH_pluginStylesheet()
94  . '" type="text/css">' . PHP_EOL
95  . $hjs
96  . '<link rel="stylesheet" href="' . $pth['file']['stylesheet']
97  . '" type="text/css">' . "\n";
98  return $o;
99 }
100 
108 function sitename()
109 {
110  global $tx;
111 
112  return isset($tx['site']['title']) ? XH_hsc($tx['site']['title']) : '';
113 }
114 
115 
123 function pagename()
124 {
125  global $cf;
126 
127  return isset($cf['site']['title']) ? XH_hsc($cf['site']['title']) : '';
128 }
129 
130 
138 function onload()
139 {
140  global $onload;
141 
142  return ' onload="' . $onload . '"';
143 }
144 
145 
160 function toc($start = null, $end = null, $li = 'li')
161 {
162  global $cl, $s, $l, $cf;
163 
164  if (isset($start)) {
165  if (!isset($end)) {
166  $end = $start;
167  }
168  } else {
169  $start = 1;
170  }
171  if (!isset($end)) {
172  $end = $cf['menu']['levels'];
173  }
174  $ta = array();
175  if ($s > -1) {
176  $tl = $l[$s];
177  for ($i = $s; $i > -1; $i--) {
178  if ($l[$i] <= $tl && $l[$i] >= $start && $l[$i] <= $end) {
179  if (!hide($i)
180  || ($i == $s && $cf['show_hidden']['pages_toc'] == 'true')
181  ) {
182  $ta[] = $i;
183  }
184  }
185  if ($l[$i] < $tl) {
186  $tl = $l[$i];
187  }
188  }
189  sort($ta);
190  $tl = $l[$s];
191  } else {
192  $tl = 0;
193  }
194  $tl += 1 + $cf['menu']['levelcatch'];
195  for ($i = $s + 1; $i < $cl; $i++) {
196  if ($l[$i] <= $tl && $l[$i] >= $start && $l[$i] <= $end) {
197  if (!hide($i)) {
198  $ta[] = $i;
199  }
200  }
201  if ($l[$i] < $tl) {
202  $tl = $l[$i];
203  }
204  }
205  return $li($ta, $start);
206 }
207 
208 
217 function li(array $ta, $st)
218 {
219  $li = new XH\Li();
220  return $li->render($ta, $st);
221 }
222 
243 function XH_buildHc()
244 {
245  global $cl, $s, $cf, $si, $hc, $hl;
246 
247  $pages = new XH\Pages();
248  $si = -1;
249  $hc = array();
250  for ($i = 0; $i < $cl; $i++) {
251  if (!hide($i)
252  || ($cf['show_hidden']['pages_toc'] == 'true'
253  && ($i == $s || in_array($i, $pages->getAncestorsOf($s, false))))
254  ) {
255  $hc[] = $i;
256  }
257  if ($i == $s) {
258  $si = count($hc);
259  }
260  }
261  $hl = count($hc);
262 }
263 
272 function searchbox()
273 {
274  global $sn, $tx;
275 
276  return '<form id="searchbox" action="' . $sn . '" method="get">' . "\n"
277  . '<input type="search" class="text" name="search" title="'
278  . $tx['search']['label'] . '" placeholder="' . $tx['search']['label']
279  . '" size="12">' . "\n"
280  . '<input type="hidden" name="function" value="search">' . "\n" . ' '
281  . '<input type="submit" class="submit" value="'
282  . $tx['search']['button'] . '">' . "\n"
283  . '</form>' . "\n";
284 }
285 
286 
292 function sitemaplink()
293 {
294  return ml('sitemap');
295 }
296 
297 
305 function printlink()
306 {
307  global $tx;
308 
309  return '<a href="' . XH_printUrl() . '" rel="nofollow">'
310  . $tx['menu']['print'] . '</a>';
311 }
312 
325 function XH_printUrl()
326 {
327  global $f, $search, $file, $sn;
328 
329  $t = '&print';
330  if ($f == 'search') {
331  $t .= '&function=search&search=' . urlencode(stsl($search));
332  } elseif ($f == 'file') {
333  $t .= '&file=' . $file;
334  } elseif ($f != '' && $f != 'save') {
335  $t .= '&' . $f;
336  } elseif (sv('QUERY_STRING') != '') {
337  $t = sv('QUERY_STRING') . $t;
338  }
339  $t = XH_hsc($t);
340  return $sn . '?' . $t;
341 }
342 
350 function mailformlink()
351 {
352  global $cf;
353 
354  if ($cf['mailform']['email'] != '') {
355  return ml('mailform');
356  }
357 }
358 
367 function loginlink()
368 {
369  global $s, $tx;
370 
371  if (!XH_ADM) {
372  return a($s > -1 ? $s : 0, '&amp;login" rel="nofollow')
373  . $tx['menu']['login'] . '</a>';
374  }
375 }
376 
377 
389 function lastupdate($br = null, $hour = null)
390 {
391  global $tx, $pth;
392 
393  $t = $tx['lastupdate']['text'] . ':';
394  if (!(isset($br))) {
395  $t .= '<br>';
396  } else {
397  $t .= ' ';
398  }
399  $time = filemtime($pth['file']['content']) + (isset($hour) ? $hour * 3600 : 0);
400  return $t . '<time datetime="' . date('c', $time) . '">'
401  . XH_formatDate($time)
402  . '</time>';
403 }
404 
410 function locator()
411 {
412  $breadcrumbs = XH_getLocatorModel();
413  $last = count($breadcrumbs) - 1;
414  $html = '<span vocab="http://schema.org/" typeof="BreadcrumbList">';
415  foreach ($breadcrumbs as $i => $breadcrumb) {
416  list($title, $url) = $breadcrumb;
417  if ($i > 0) {
418  $html .= ' &gt; ';
419  }
420  $html .= '<span property="itemListElement" typeof="ListItem">';
421  $inner = '<span property="name">' . $title
422  . '</span><meta property="position" content="'. ($i + 1) . '">';
423  if (isset($url) && $i < $last) {
424  $html .= '<a property="item" typeof="WebPage" href="' . $url . '">'
425  . $inner . '</a>';
426  } else {
427  $html .= $inner;
428  }
429  $html .= '</span>';
430  }
431  $html .= '</span>';
432  return $html;
433 }
434 
447 function editmenu()
448 {
449  trigger_error('Function editmenu() is deprecated', E_USER_DEPRECATED);
450 
451  return '';
452 }
453 
464 function content()
465 {
466  global $s, $o, $c, $edit;
467  $heading = '';
468 
469  if (!($edit && XH_ADM) && $s > -1) {
470  if (isset($_GET['search'])) {
471  $search = XH_hsc(stsl($_GET['search']));
472  $words = explode(' ', $search);
473  $c[$s] = XH_highlightSearchWords($words, $c[$s]);
474  $heading = XH_highlightSearchWords($words, $heading);
475  }
476  $o .= $heading . preg_replace('/#CMSimple (.*?)#/is', '', $c[$s]);
477  return preg_replace('/<!--XH_ml[1-9]:.*?-->/isu', '', $o);
478  } else {
479  return preg_replace('/<!--XH_ml[1-9]:.*?-->/isu', '', $o);
480  }
481 }
482 
483 
497 function submenu($html = '')
498 {
499  global $s, $cl, $l, $tx, $cf;
500 
501  $ta = array();
502  if ($s > -1) {
503  $tl = $l[$s] + 1 + $cf['menu']['levelcatch'];
504  for ($i = $s + 1; $i < $cl; $i++) {
505  if ($l[$i] <= $l[$s]) {
506  break;
507  }
508  if ($l[$i] <= $tl) {
509  if (!hide($i)) {
510  $ta[] = $i;
511  }
512  }
513  if ($l[$i] < $tl) {
514  $tl = $l[$i];
515  }
516  }
517  if (count($ta) != 0) {
518  if ($html == '') {
519  $level = min($cf['menu']['levels'] + 1, 6);
520  return '<h' . $level . '>' . $tx['submenu']['heading']
521  . '</h' . $level . '>'
522  . li($ta, 'submenu');
523  } else {
524  return sprintf($html, $tx['submenu']['heading'])
525  . li($ta, 'submenu');
526  }
527  }
528  }
529 }
530 
540 function previouspage()
541 {
542  global $tx;
543 
544  $index = XH_findPreviousPage();
545  if ($index !== false) {
546  return a($index, '" rel="prev') . $tx['navigator']['previous'] . '</a>';
547  }
548 }
549 
559 function nextpage()
560 {
561  global $tx;
562 
563  $index = XH_findNextPage();
564  if ($index !== false) {
565  return a($index, '" rel="next') . $tx['navigator']['next'] . '</a>';
566  }
567 }
568 
580 function top($id = 'TOP')
581 {
582  global $tx;
583 
584  return '<a href="#' . $id . '">' . $tx['navigator']['top'] . '</a>';
585 }
586 
587 
597 function languagemenu()
598 {
599  global $pth, $cf, $sl;
600 
601  $r = XH_secondLanguages();
602  array_unshift($r, $cf['language']['default']);
603  $i = array_search($sl, $r);
604  unset($r[$i]);
605 
606  $langNames = explode(';', $cf['language']['2nd_lang_names']);
607  foreach ($langNames as $value) {
608  $langName[substr($value, 0, 2)] = substr($value, 3);
609  }
610 
611  $t = '';
612  foreach ($r as $lang) {
613  $url = $pth['folder']['base']
614  . ($lang == $cf['language']['default'] ? '' : $lang . '/');
615  $img = $pth['folder']['templateflags'] . $lang . '.gif';
616  if (!file_exists($img)) {
617  $img = $pth['folder']['flags'] . $lang . '.gif';
618  }
619 
620  $title = isset($langName[$lang])
621  ? $langName[$lang]
622  : $lang;
623 
624  $el = file_exists($img)
625  ? '<img src="' . $img . '" alt="' . $title . '" title="'
626  . $title . '" class="flag">'
627  : $title;
628  $t .= '<a href="' . $url . '">' . $el . '</a> ';
629  }
630  return $t;
631 }
632 
633 
642 {
643  header('HTTP/1.0 503 Service Unavailable');
644  header('Content-Type: text/html;charset=UTF-8');
645  echo '<!DOCTYPE html><head>'
646  . head()
647  . '</head><body '
648  . onload()
649  . '>'
650  . sitename()
651  . toc()
652  . content()
653  . loginlink()
654  . '</body></html>';
655  XH_exit();
656 }
657 
671 function poweredByLink($linktext = '')
672 {
673  global $sn;
674 
675  $linktext = $linktext ? $linktext : 'Site/CMS Info';
676  return '<a href="' . $sn . '?' . uenc('site/cms info') . '">'
677  . $linktext . '</a>';
678 }
content()
Definition: tplfuncs.php:464
$l
Definition: cms.php:1003
XH_emergencyTemplate()
Definition: tplfuncs.php:641
XH_plugins($admin=false)
Definition: functions.php:1443
top($id='TOP')
Definition: tplfuncs.php:580
XH_secondLanguages()
Definition: functions.php:2021
sitemaplink()
Definition: tplfuncs.php:292
sitename()
Definition: tplfuncs.php:108
li(array $ta, $st)
Definition: tplfuncs.php:217
sv($s)
Definition: functions.php:543
searchbox()
Definition: tplfuncs.php:272
previouspage()
Definition: tplfuncs.php:540
$s
Definition: cms.php:953
XH_findNextPage()
Definition: functions.php:907
toc($start=null, $end=null, $li='li')
Definition: tplfuncs.php:160
nextpage()
Definition: tplfuncs.php:559
editmenu()
Definition: tplfuncs.php:447
ml($i)
Definition: functions.php:980
$i
Definition: cms.php:193
const CMSIMPLE_XH_VERSION
Definition: cms.php:209
$si
Definition: cms.php:1167
pagename()
Definition: tplfuncs.php:123
$title
Definition: cms.php:100
$cf
Definition: cms.php:272
switch($f) $hc
Definition: cms.php:1149
XH_getLocatorModel()
Definition: functions.php:2786
$f
Definition: cms.php:836
$hl
Definition: cms.php:1158
hide($i)
Definition: functions.php:1100
XH_formatDate($timestamp)
Definition: functions.php:2547
lastupdate($br=null, $hour=null)
Definition: tplfuncs.php:389
$c
Definition: cms.php:964
$search
Definition: cms.php:652
XH_renderPrevLink()
Definition: tplfuncs.php:28
if(!isset($cf['folders']['content'])) if($cf['site']['timezone'] !=='' &&function_exists('date_default_timezone_set')) $sl
Definition: cms.php:331
$hjs
Definition: cms.php:141
$file
Definition: cms.php:640
XH_exit($status=0)
Definition: functions.php:2401
$u
Definition: cms.php:990
printlink()
Definition: tplfuncs.php:305
meta($n)
Definition: functions.php:957
$o
Definition: cms.php:113
$onload
Definition: cms.php:171
mailformlink()
Definition: tplfuncs.php:350
Definition: Li.php:29
onload()
Definition: tplfuncs.php:138
const CMSIMPLE_XH_BUILD
Definition: cms.php:213
$sn
Definition: cms.php:434
$tx
Definition: cms.php:363
XH_highlightSearchWords(array $words, $text)
Definition: functions.php:2589
stsl($t)
Definition: functions.php:606
const XH_ADM
Definition: cms.php:897
a($i, $x)
Definition: functions.php:931
locator()
Definition: tplfuncs.php:410
submenu($html='')
Definition: tplfuncs.php:497
XH_findPreviousPage()
Definition: functions.php:885
$pth
Definition: cms.php:230
XH_hsc($string)
Definition: functions.php:2204
XH_renderNextLink()
Definition: tplfuncs.php:50
uenc($s)
Definition: functions.php:1009
poweredByLink($linktext='')
Definition: tplfuncs.php:671
$edit
Definition: cms.php:602
XH_printUrl()
Definition: tplfuncs.php:325
loginlink()
Definition: tplfuncs.php:367
$cl
Definition: cms.php:918
XH_pluginStylesheet()
Definition: functions.php:1707
languagemenu()
Definition: tplfuncs.php:597
XH_title($site, $subtitle)
Definition: functions.php:1869
head()
Definition: tplfuncs.php:73
XH_buildHc()
Definition: tplfuncs.php:243