PageRenderTime 72ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/include/layout.inc

https://github.com/Robervaldo/web-php
PHP | 968 lines | 732 code | 122 blank | 114 comment | 117 complexity | f0ef7e3c35c9c28ee1247fe1ee0a53f7 MD5 | raw file
  1. <?php
  2. /* $Id$ */
  3. // Set the static content root differently on php.net
  4. if ($MYSITE == "http://www.php.net/" || $MYSITE == 'http://php.net/') {
  5. $_SERVER['STATIC_ROOT'] = 'http://static.php.net/www.php.net';
  6. } elseif ($MYSITE == 'https://www.php.net/' || $MYSITE == 'https://php.net/') {
  7. $_SERVER['STATIC_ROOT'] = 'https://static.php.net/www.php.net';
  8. } elseif (!isset($_SERVER['STATIC_ROOT'])) {
  9. $_SERVER['STATIC_ROOT'] = "";
  10. }
  11. // Use class names instead of colors
  12. ini_set('highlight.comment', 'comment');
  13. ini_set('highlight.default', 'default');
  14. ini_set('highlight.keyword', 'keyword');
  15. ini_set('highlight.string', 'string');
  16. ini_set('highlight.html', 'html');
  17. // Highlight PHP code
  18. function highlight_php($code, $return = FALSE)
  19. {
  20. // Using OB, as highlight_string() only supports
  21. // returning the result from 4.2.0
  22. ob_start();
  23. highlight_string($code);
  24. $highlighted = ob_get_contents();
  25. ob_end_clean();
  26. // This should eventually be a php_syntax_check() call when we move to PHP5
  27. // But use this ugly hack for now to avoid code snippets with bad syntax screwing up the highlighter
  28. if(strstr($highlighted,"include/layout.inc</b>")) $highlighted = '<span class="html">'.nl2br(htmlentities($code))."</span>";
  29. // Fix output to use CSS classes and wrap well
  30. $highlighted = '<div class="phpcode">' . str_replace(
  31. array(
  32. '&nbsp;',
  33. '<br />',
  34. '<font color="', // for PHP 4
  35. '<span style="color: ', // from PHP 5.0.0RC1
  36. '</font>',
  37. "\n ",
  38. ' ',
  39. ' '
  40. ),
  41. array(
  42. ' ',
  43. "<br />\n",
  44. '<span class="',
  45. '<span class="',
  46. '</span>',
  47. "\n&nbsp;",
  48. '&nbsp; ',
  49. '&nbsp; '
  50. ),
  51. $highlighted
  52. ) . '</div>';
  53. if ($return) { return $highlighted; }
  54. else { echo $highlighted; }
  55. }
  56. // Stats pages still need this
  57. function commonHeader($title) { site_header($title); }
  58. function site_header($title = '', $config = array())
  59. {
  60. if (myphpnet_beta()) {
  61. return site_header_beta($title, $config);
  62. }
  63. global $EXPL_LANG, $SIDEBAR_DATA, $RSIDEBAR_DATA, $PAGE_COLUMNS, $PGI;
  64. // Default to empty array if improper parameter passed
  65. if (!is_array($config)) { $config = array(); }
  66. // String defaults
  67. $lang_input = $canonical = $base = $meta = $layout_helper = '';
  68. // Count number of columns for layout. The number identifies
  69. // the layout precisely, as we have no page having a right
  70. // sidebar and no left sidebar
  71. $PAGE_COLUMNS = 1;
  72. if (!empty($SIDEBAR_DATA)) { $PAGE_COLUMNS++; }
  73. if (!empty($RSIDEBAR_DATA)) { $PAGE_COLUMNS++; }
  74. // Check which language we are presenting, default to english
  75. $lang = "en";
  76. if (isset($config["lang"])) {
  77. $lang = language_convert($config["lang"]);
  78. } elseif (isset($PGI, $PGI['head'], $PGI['head'][1])) {
  79. $lang = language_convert($PGI['head'][1]);
  80. }
  81. // Print out lang and charset headers
  82. if (!isset($config["charset"])) { $config["charset"] = "utf-8"; }
  83. header("Content-type: text/html;charset={$config['charset']}");
  84. header("Content-language: {$lang}");
  85. if (isset($config["generate_modified"]) && $config["generate_modified"]) {
  86. $timestamp = @filemtime($_SERVER["DOCUMENT_ROOT"] . "/" .$_SERVER["BASE_PAGE"]);
  87. if ($timestamp) {
  88. $tsstring = gmdate("D, d M Y H:i:s ", $timestamp) . "GMT";
  89. header("Last-Modified: " . $tsstring);
  90. }
  91. }
  92. if (isset($config["extra_headers"]) && is_array($config["extra_headers"])) {
  93. foreach($config["extra_headers"] as $key => $value) {
  94. header(sprintf("%s: %s", $key, $value));
  95. }
  96. }
  97. if (!empty($title)) { $title = ": $title"; }
  98. // This page should not be indexed by robots
  99. if (in_array("noindex", $config)) {
  100. $meta .= "\n <meta name=\"robots\" content=\"noindex\" />";
  101. }
  102. // Set onload handler if required
  103. $onload = (isset($config['onload']) ? ' onload="' . $config['onload'] . '"' : '');
  104. // Explicit language setting means that we should put that into the form
  105. if (isset($EXPL_LANG)) {
  106. $lang_input = "\n <input type=\"hidden\" name=\"lang\" value=\"$EXPL_LANG\" />";
  107. }
  108. // Link tags
  109. $link = "";
  110. if (isset($config['link']) && is_array($config['link'])) {
  111. foreach($config['link'] as $rel => $url) {
  112. if (!is_array($url)) {
  113. $link .= "\n <link rel=\"$rel\" href=\"$url\" />";
  114. } else {
  115. $link .= "\n <link ";
  116. foreach($url as $attr => $val) {
  117. $link .= "$attr=\"$val\" ";
  118. }
  119. $link .= "/>";
  120. }
  121. }
  122. }
  123. // Base href setting for URL shortcuts to work
  124. if (!empty($_SERVER['BASE_HREF'])) {
  125. $base = "\n <base href=\"{$_SERVER['BASE_HREF']}\" />";
  126. $canonical = '<link rel="canonical" href="//php.net/' . $_SERVER['BASE_PAGE'] . '" />';
  127. }
  128. // Define layout helper in case we need it
  129. if ($PAGE_COLUMNS > 2) {
  130. $layout_helper = "<div id=\"layout_{$PAGE_COLUMNS}_helper\">";
  131. }
  132. // Choose name of mirror site specific CSS file
  133. $mirror_specific_style = ($_SERVER['STATIC_ROOT'] ? 'phpnet' : 'mirror');
  134. // Support for more header tags
  135. $moreheadtags = '';
  136. if (isset($config['headtags'])) {
  137. if (is_array($config['headtags'])) {
  138. $moreheadtags = "\n " . join("\n ", $config['headtags']);
  139. } else {
  140. $moreheadtags = "\n " . ((string)$config['headtags']);
  141. }
  142. }
  143. $classname = "default";
  144. if(isset($_SERVER['BASE_PAGE'])) {
  145. $classname = dirname($_SERVER['BASE_PAGE']);
  146. if(empty($classname)) {
  147. $classname = "default";
  148. }
  149. }
  150. // Right-to-left support
  151. $rtl = "";
  152. /* Does not appear to work... commenting out.
  153. switch ($lang) {
  154. case "he":
  155. case "ar":
  156. $rtl = ' style="direction: rtl"';
  157. break;
  158. }
  159. */
  160. // RTL Hack. Edit styles/rtl.css for rtl specific CSS.
  161. $import_rtl = '';
  162. if (in_array($lang, array('ar', 'fa', 'he'))) {
  163. $import_rtl = '@import url("' . $_SERVER['STATIC_ROOT'] . '/styles/rtl.css");';
  164. }
  165. $profile = "";
  166. if (isset($config['profile']) && !empty($config['profile'])) {
  167. $profile = ' profile="';
  168. if (is_array($config['profile'])) {
  169. $profile .= implode(" ", $config['profile']);
  170. } else {
  171. $profile .= $config['profile'];
  172. }
  173. $profile .= '"';
  174. }
  175. print <<<END_HEADER
  176. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  177. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  178. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{$lang}" lang="{$lang}">
  179. <head{$profile}>
  180. <title>PHP{$title}</title>
  181. <style type="text/css" media="all">
  182. @import url("{$_SERVER['STATIC_ROOT']}/styles/site.css");
  183. @import url("{$_SERVER['STATIC_ROOT']}/styles/{$mirror_specific_style}.css");
  184. $import_rtl
  185. </style>
  186. <!--[if IE]><![if gte IE 6]><![endif]-->
  187. <style type="text/css" media="print">
  188. @import url("{$_SERVER['STATIC_ROOT']}/styles/print.css");
  189. </style>
  190. <!--[if IE]><![endif]><![endif]-->
  191. <meta http-equiv="Content-Type" content="text/html; charset={$config['charset']}"/>
  192. <link rel="shortcut icon" href="{$_SERVER['STATIC_ROOT']}/favicon.ico" />{$link}
  193. $canonical
  194. <script type="text/javascript" src="{$_SERVER['STATIC_ROOT']}/userprefs.js"></script>{$base}{$meta}{$moreheadtags}
  195. </head>
  196. <body{$onload}>
  197. <div id="headnav">
  198. <a href="/" rel="home"><img src="{$_SERVER['STATIC_ROOT']}/images/php.gif"
  199. alt="PHP" width="120" height="67" id="phplogo" /></a>
  200. <div id="headmenu">
  201. <a href="/downloads.php">downloads</a> |
  202. <a href="/docs.php">documentation</a> |
  203. <a href="/FAQ.php">faq</a> |
  204. <a href="/support.php">getting help</a> |
  205. <a href="/mailing-lists.php">mailing lists</a> |
  206. <a href="/license">licenses</a> |
  207. <a href="https://wiki.php.net/">wiki</a> |
  208. <a href="https://bugs.php.net/">reporting bugs</a> |
  209. <a href="/sites.php">php.net sites</a> |
  210. <a href="/conferences/">conferences</a> |
  211. <a href="/my.php">my php.net</a>
  212. </div>
  213. </div>
  214. <div id="headsearch">
  215. <form method="post" action="/search.php" id="topsearch">
  216. <p>
  217. <span title="Keyboard shortcut: Alt+S (Win), Ctrl+S (Apple)">
  218. <span class="shortkey">s</span>earch for
  219. </span>
  220. <input type="text" name="pattern" value="" size="30" accesskey="s" />
  221. <span>in the</span>
  222. <select name="show">
  223. <option value="all" >all php.net sites</option>
  224. <option value="local" >this mirror only</option>
  225. <option value="quickref" selected="selected">function list</option>
  226. <option value="manual" >online documentation</option>
  227. <option value="bugdb" >bug database</option>
  228. <option value="news_archive">Site News Archive</option>
  229. <option value="changelogs">All Changelogs</option>
  230. <option value="pear" >just pear.php.net</option>
  231. <option value="pecl" >just pecl.php.net</option>
  232. <option value="talks" >just talks.php.net</option>
  233. <option value="maillist" >general mailing list</option>
  234. <option value="devlist" >developer mailing list</option>
  235. <option value="phpdoc" >documentation mailing list</option>
  236. </select>
  237. <input type="image"
  238. src="{$_SERVER['STATIC_ROOT']}/images/small_submit_white.gif"
  239. class="submit" alt="search" />{$lang_input}
  240. </p>
  241. </form>
  242. </div>
  243. <div id="layout_{$PAGE_COLUMNS}">{$layout_helper}
  244. END_HEADER;
  245. // Print out left column
  246. if ($PAGE_COLUMNS > 1) {
  247. echo "\n <div id=\"leftbar\">\n$SIDEBAR_DATA\n </div>";
  248. }
  249. // Print out right column
  250. if ($PAGE_COLUMNS > 2) {
  251. echo "\n <div id=\"rightbar\">\n$RSIDEBAR_DATA\n </div>";
  252. }
  253. // Any layout workarounds?
  254. if (!empty($config["layout_workaround"])) {
  255. echo $config["layout_workaround"];
  256. }
  257. // Start main page content
  258. echo "\n <div id=\"content\" class=\"$classname\"{$rtl}>\n";
  259. }
  260. // Stats pages still need this
  261. function commonFooter() { site_footer(); }
  262. function site_footer($config = array())
  263. {
  264. if (myphpnet_beta()) {
  265. return site_footer_beta($config);
  266. }
  267. global $LAST_UPDATED, $PAGE_COLUMNS;
  268. $stats = (have_stats() ? "\n <a href=\"/stats/\">stats</a> |" : "");
  269. $rsslink = (isset($config["rss"]) ?
  270. "<a href=\"{$config["rss"]}\">RSS</a> |" :
  271. "");
  272. $atomlink = (isset($config["atom"]) ?
  273. "<a href=\"{$config["atom"]}\">Atom</a> |" :
  274. "");
  275. $viewsource = (isset($_SERVER['BASE_PAGE']) ?
  276. "<a href=\"/source.php?url=/{$_SERVER['BASE_PAGE']}\">show source</a> |" :
  277. "");
  278. $provider_url = mirror_provider_url();
  279. $provider_name = mirror_provider();
  280. $mirror_text = (is_official_mirror() ?
  281. "<a href=\"/mirror.php\">This mirror</a> generously provided by:" :
  282. "<a href=\"/mirror.php\">This unofficial mirror</a> is operated at:");
  283. $last_updated = strftime("%c %Z", $LAST_UPDATED);
  284. $layout_helper = ($PAGE_COLUMNS > 2 ? "</div>" : "");
  285. //$functionsjs = (in_array("functionsjs", $config) ? "\n<script src=\"" . $_SERVER['STATIC_ROOT'] . '/functions.js" type="text/javascript"></script>' : '');
  286. // Automate the Copyright year
  287. $current_year = date('Y');
  288. print <<<END_FOOTER
  289. </div>
  290. <div class="cleaner">&nbsp;</div>
  291. {$layout_helper}</div>
  292. <div id="footnav">
  293. $rsslink $atomlink $viewsource
  294. <a href="/credits.php">credits</a> |$stats
  295. <a href="/sitemap.php">sitemap</a> |
  296. <a href="/contact.php">contact</a> |
  297. <a href="/contact.php#ads">advertising</a> |
  298. <a href="/mirrors.php">mirror sites</a>
  299. </div>
  300. <div id="pagefooter">
  301. <div id="copyright">
  302. <a href="/copyright.php">Copyright &copy; 2001-{$current_year} The PHP Group</a><br />
  303. All rights reserved.
  304. </div>
  305. <div id="thismirror">
  306. {$mirror_text}
  307. <a href="{$provider_url}">{$provider_name}</a><br />
  308. Last updated: {$last_updated}
  309. </div>
  310. </div>
  311. <!--[if IE 6]>
  312. <script type="text/javascript">
  313. /*Load jQuery if not already loaded*/ if(typeof jQuery == 'undefined'){ document.write("<script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></"+"script>"); var __noconflict = true; }
  314. var IE6UPDATE_OPTIONS = {
  315. icons_path: "/ie6update/images/"
  316. }
  317. </script>
  318. <script type="text/javascript" src="/ie6update/ie6update.js"></script>
  319. <![endif]-->
  320. </body>
  321. </html>
  322. END_FOOTER;
  323. }
  324. // Resize the image using the output of make_image()
  325. // (considering possible HTML/XHTML image tag endings)
  326. function resize_image($img, $width = 1, $height = 1)
  327. {
  328. // Drop width and height values from image if available
  329. $str = preg_replace('!width=\"([0-9]+?)\"!i', '', $img);
  330. $str = preg_replace('!height=\"([0-9]+?)\"!i', '', $str);
  331. // Return image with new width and height added
  332. return preg_replace(
  333. '!/?>$!',
  334. sprintf(' height="%s" width="%s" />', $height, $width),
  335. $str
  336. );
  337. }
  338. // Return an <img /> tag for a given image file available on the server
  339. function make_image($file, $alt = FALSE, $align = FALSE, $extras = FALSE,
  340. $dir = '/images', $border = 0, $addsize = TRUE)
  341. {
  342. // If no / was provided at the start of $dir, add it
  343. $webdir = $_SERVER['STATIC_ROOT'] . ($dir{0} == '/' ? '' : '/') . $dir;
  344. // Get width and height values if possible
  345. if ($addsize && ($size = @getimagesize($_SERVER['DOCUMENT_ROOT'] . "$dir/$file"))) {
  346. $sizeparams = ' ' . trim($size[3]);
  347. } else {
  348. $sizeparams = '';
  349. }
  350. // Convert right or left alignment to CSS float,
  351. // but leave other alignments intact (for now)
  352. if (in_array($align, array("right", "left"))) {
  353. $align = ' style="float: ' . $align . ';"';
  354. } elseif ($align) {
  355. $align = ' align="' . $align . '"';
  356. } else {
  357. $align = '';
  358. }
  359. // Return with image built up
  360. return sprintf('<img src="%s/%s" alt="%s"%s%s%s />',
  361. $webdir,
  362. $file,
  363. ($alt ? $alt : ''),
  364. $sizeparams,
  365. $align,
  366. ($extras ? ' ' . $extras : '')
  367. );
  368. return $image;
  369. }
  370. // Print an <img /> tag out for a given file
  371. function print_image($file, $alt = FALSE, $align = FALSE, $extras = FALSE,
  372. $dir = '/images', $border = 0)
  373. {
  374. echo make_image($file, $alt, $align, $extras, $dir, $border);
  375. }
  376. // Shortcut to usual news image printing (right floating
  377. // image from the news dir with an alt and an URL)
  378. function news_image($URL, $image, $alt, $print = true)
  379. {
  380. $str = "<a href=\"$URL\">" . make_image("news/$image", $alt, "right") . "</a>";
  381. if ($print) {
  382. echo $str;
  383. }
  384. return $str;
  385. }
  386. // Return HTML code for a submit button image
  387. function make_submit($file, $alt = FALSE, $align = FALSE, $extras = FALSE,
  388. $dir = '/images', $border = 0)
  389. {
  390. // Get an image without size info and convert the
  391. // border attribute to use CSS, as border="" is not
  392. // supported on <input> elements in [X]HTML
  393. $img = make_image($file, $alt, $align, $extras, $dir, 0, FALSE);
  394. $img = str_replace(
  395. "border=\"$border\"",
  396. "style=\"border: {$border}px;\"",
  397. $img
  398. );
  399. // Return with ready input image
  400. return '<input type="image"' . substr($img, 4);
  401. }
  402. // Return a hiperlink to something within the site
  403. function make_link ($url, $linktext = FALSE, $target = FALSE, $extras = FALSE)
  404. {
  405. return sprintf("<a href=\"%s\"%s%s>%s</a>",
  406. $url,
  407. ($target ? ' target="' . $target . '"' : ''),
  408. ($extras ? ' ' . $extras : ''),
  409. ($linktext ? $linktext : $url)
  410. );
  411. }
  412. // Print a hyperlink to something, within the site
  413. function print_link($url, $linktext = FALSE, $target = FALSE, $extras = FALSE)
  414. {
  415. echo make_link($url, $linktext, $target, $extras);
  416. }
  417. // make_popup_link()
  418. // return a hyperlink to something, within the site, that pops up a new window
  419. //
  420. function make_popup_link ($url, $linktext=false, $target=false, $windowprops="", $extras=false) {
  421. return sprintf("<a href=\"%s\" target=\"%s\" onclick=\"window.open('%s','%s','%s');return false;\"%s>%s</a>",
  422. htmlspecialchars($url, ENT_QUOTES | ENT_IGNORE),
  423. ($target ? $target : "_new"),
  424. htmlspecialchars($url, ENT_QUOTES | ENT_IGNORE),
  425. ($target ? $target : "_new"),
  426. $windowprops,
  427. ($extras ? ' '.$extras : ''),
  428. ($linktext ? $linktext : $url)
  429. );
  430. }
  431. // print_popup_link()
  432. // print a hyperlink to something, within the site, that pops up a new window
  433. //
  434. function print_popup_link($url, $linktext=false, $windowprops="", $target=false, $extras=false) {
  435. echo make_popup_link($url, $linktext, $windowprops, $target, $extras);
  436. }
  437. // Print a link for a downloadable file (including filesize)
  438. function download_link($file, $title, $showsize = TRUE, $mirror = '')
  439. {
  440. // Construct the download link for this site or a mirror site
  441. $download_link = "get/$file/from/a/mirror";
  442. if ($mirror != '') {
  443. $download_link = $mirror . $download_link;
  444. } else {
  445. $download_link = "/" . $download_link;
  446. }
  447. // Print out the download link
  448. print_link($download_link, $title);
  449. // Size display is required
  450. if ($showsize) {
  451. // We have a full path or a relative to the distributions dir
  452. if ($tmp = strrchr($file, "/")) {
  453. $local_file = substr($tmp, 1, strlen($tmp));
  454. } else {
  455. $local_file = "distributions/$file";
  456. }
  457. // Try to get the size of the file
  458. $size = @filesize($local_file);
  459. // Print out size in bytes (if size is
  460. // less then 1Kb, or else in Kb)
  461. if ($size) {
  462. echo ' [';
  463. if ($size < 1024) {
  464. echo number_format($size, 0, '.', ',') . 'b';
  465. } else {
  466. echo number_format($size/1024, 0, '.', ',') . 'Kb';
  467. }
  468. echo ']';
  469. }
  470. }
  471. }
  472. function sect_to_file($string) {
  473. $string = strtolower($string);
  474. $string = str_replace(' ','-',$string);
  475. $string = str_replace('_','-',$string);
  476. $func = "function.$string.php";
  477. $chap = "ref.$string.php";
  478. $feat = "features.$string.php";
  479. $struct = "control-structures.$string.php";
  480. if(@is_file($func)) return $func;
  481. else if(@is_file($chap)) return $chap;
  482. else if(@is_file($feat)) return $feat;
  483. else if(@is_file($struct)) return $struct;
  484. else return "$string.php";
  485. }
  486. function clean($var) {
  487. return htmlspecialchars(get_magic_quotes_gpc() ? stripslashes($var) : $var, ENT_QUOTES);
  488. }
  489. // Clean out the content of one user note for printing to HTML
  490. function clean_note($text)
  491. {
  492. // Highlight PHP source
  493. $text = highlight_php(trim($text), TRUE);
  494. // Turn urls into links
  495. $text = preg_replace(
  496. '!((mailto:|(http|ftp|nntp|news):\/\/).*?)(\s|<|\)|"|\\\\|\'|$)!',
  497. '<a href="\1" rel="nofollow" target="_blank">\1</a>\4',
  498. $text
  499. );
  500. return $text;
  501. }
  502. function display_errors($errors)
  503. {
  504. echo '<div class="errors">';
  505. if (count($errors) > 1) {
  506. echo "You need to do the following before your submission will be accepted:<ul>";
  507. foreach ($errors as $error) {
  508. echo "<li>$error</li>\n";
  509. }
  510. echo "</ul>";
  511. }
  512. else {
  513. echo $errors[0];
  514. }
  515. echo '</div>';
  516. }
  517. // Displays an event. Used in event submission
  518. // previews and event information displays
  519. function display_event($event, $include_date = 1)
  520. {
  521. global $COUNTRIES;
  522. // Current month (int)($_GET['cm'] ?: 0)
  523. global $cm;
  524. // Current year (int)($_GET['cy'] ?: 0)
  525. global $cy;
  526. // Weekday names array
  527. for ($i = 1; $i <= 7; $i++) {
  528. $days[$i] = strftime('%A', mktime(12, 0, 0, 4, $i, 2001));
  529. }
  530. // Recurring possibilities
  531. $re = array(
  532. 1 => 'First',
  533. 2 => 'Second',
  534. 3 => 'Third',
  535. 4 => 'Fourth',
  536. -1 => 'Last',
  537. -2 => '2nd Last',
  538. -3 => '3rd Last'
  539. );
  540. $sday = (isset($event['start']) && !empty($event['start'])) ? strtotime($event['start']) : 0;
  541. $eday = (isset($event['end']) && !empty($event['end'])) ? strtotime($event['end']) : 0;
  542. ?>
  543. <table border="0" cellspacing="0" cellpadding="3" width="100%" class="vevent">
  544. <tr bgcolor="#dddddd"><td>
  545. <?php
  546. // Print out date if needed
  547. if ($include_date && (isset($event['start']))) {
  548. echo "<b>", date("F j, Y", $sday), "</b>\n";
  549. }
  550. // Print link in case we have one
  551. if ($event['url']) { echo '<a href="', htmlentities($event['url'], ENT_QUOTES | ENT_IGNORE, 'UTF-8'),'" class="url">'; }
  552. // Print event description
  553. echo "<b class='summary'>", stripslashes(htmlentities($event['sdesc'], ENT_QUOTES | ENT_IGNORE, 'UTF-8')), "</b>";
  554. // End link
  555. if ($event['url']) { echo "</a>"; }
  556. // Print extra date info for recurring and multiday events
  557. switch ($event['type']) {
  558. case 2:
  559. case 'multi':
  560. $dtend = date("Y-m-d", strtotime("+1 day", $eday));
  561. echo " (<abbr class='dtstart'>", date("Y-m-d",$sday), "</abbr> to <abbr class='dtend' title='$dtend'>", date("Y-m-d",$eday), "</abbr>)";
  562. break;
  563. case 3:
  564. case 'recur':
  565. $days = $re[$event['recur']]. " " .$days[$event['recur_day']];
  566. if (!$cm || $cy) {
  567. $cm = date("m");
  568. $cy = date("Y");
  569. }
  570. $month = date("M", mktime(0, 0, 0, $cm, 1, $cy));
  571. $dtstart = date("Y-m-d", strtotime($days . ' 0st' .$month. ' ' .$cy));
  572. echo ' (Every <abbr class="dtstart" title="'.$dtstart.'">', $days, "</abbr> of the month)";
  573. break;
  574. }
  575. // Event category
  576. if(isset($event['category']) && $event['category']) {
  577. $cat = array("unknown", "User Group Event", "Conference", "Training");
  578. echo ' [' . $cat[$event['category']] . '] ';
  579. }
  580. // Print out country information
  581. echo ' (<span class="location">' , $COUNTRIES[$event['country']] , '</span>)';
  582. ?>
  583. </td></tr>
  584. <tr bgcolor="#eeeeee" class="description"><td>
  585. <?php
  586. // Print long description
  587. echo preg_replace("/\r?\n\r?\n/", "<br /><br />", trim(htmlentities($event['ldesc'],ENT_QUOTES | ENT_IGNORE, 'UTF-8')));
  588. // If we have an URL, print it out
  589. if ($event['url']) {
  590. echo '<br /><br /><b>URL:</b> ',
  591. '<a href="', htmlentities($event['url'], ENT_QUOTES | ENT_IGNORE, 'UTF-8'), '">',
  592. htmlentities($event['url'], ENT_QUOTES | ENT_IGNORE, 'UTF-8'), '</a>';
  593. }
  594. ?>
  595. </td></tr>
  596. </table>
  597. <?php
  598. }
  599. /**
  600. * Print a view
  601. *
  602. * @param string $templateName
  603. * @param array $params
  604. * @return void
  605. */
  606. function print_view($templateName, array $params = array()) {
  607. $path = $_SERVER['DOCUMENT_ROOT'] . '/views/' . $templateName;
  608. if(file_exists($path)) {
  609. if(!empty($params)) {
  610. foreach($params as $key => $param) {
  611. $$key = $param;
  612. }
  613. }
  614. include_once $path;
  615. }
  616. }
  617. // Print news links for archives
  618. function news_archive_sidebar()
  619. {
  620. global $SIDEBAR_DATA;
  621. $SIDEBAR_DATA = '
  622. <h3>Latest news</h3>
  623. <p>
  624. For the latest news, <a href="/index.php" rel="home">check the homepage</a>,
  625. or <a href="/feed.atom">our Atom feed</a>.
  626. </p>
  627. <h3>Archives by year</h3>
  628. <ul class="toc">
  629. ';
  630. for ($i = date("Y"); $i >= 1998; $i--) {
  631. $pagename = "archive/$i.php";
  632. $classname = ($pagename == $_SERVER['BASE_PAGE'] ? ' class="active"' : '');
  633. $SIDEBAR_DATA .= "<li{$classname}><a href=\"/{$pagename}\">{$i}</a></li>\n";
  634. }
  635. $SIDEBAR_DATA .= '</ul>';
  636. }
  637. // Print news
  638. function print_news($news, $dog, $max = 5, $onlyyear = null, $return = false) {
  639. $retval = array();
  640. $count = 0;
  641. $news = $news ? $news : array(); // default to empty array (if no news)
  642. foreach($news as $item) {
  643. $vevent = "";
  644. $ok = false;
  645. // Only print entries in the provided s/dog/cat/ egory
  646. // If its a conference, use the hCalendar container
  647. foreach($item["category"] as $category) {
  648. if (in_array($category["term"], (array)$dog)) {
  649. $ok = true;
  650. ++$count;
  651. }
  652. if ($category["term"] === "conferences" || $category["term"] === "cfp") {
  653. $vevent = " vevent";
  654. }
  655. }
  656. if ($count > $max) {
  657. break;
  658. }
  659. if ($ok === false) {
  660. continue;
  661. }
  662. $image = "";
  663. if(isset($item["newsImage"])) {
  664. $image = news_image($item["newsImage"]["link"], $item["newsImage"]["content"], $item["newsImage"]["title"], false);
  665. }
  666. //$id = parse_url($item["id"], PHP_URL_FRAGMENT); 5.1.2
  667. $id = parse_url($item["id"]);
  668. $id = $id["fragment"];
  669. // Find the permlink
  670. foreach($item["link"] as $link) {
  671. if ($link["rel"] === "via") {
  672. $permlink = $link["href"];
  673. break;
  674. }
  675. }
  676. if (!isset($permlink)) {
  677. $permlink = "#" .$id;
  678. }
  679. // PHP4 strtotime() doesn't support RFC3339 timestamps
  680. $published = substr($item["published"], 0, 10);
  681. $nixtimestamp = strtotime($published);
  682. $newsdate = date("d-M-Y", $nixtimestamp);
  683. if ($onlyyear && date("Y", $nixtimestamp) != $onlyyear) {
  684. $count--;
  685. continue;
  686. }
  687. if ($return) {
  688. $retval[] = array(
  689. "title" => $item["title"],
  690. "id" => $id,
  691. "permlink" => $permlink,
  692. "date" => $newsdate,
  693. );
  694. continue;
  695. }
  696. echo <<< EOT
  697. <div class="newsItem hentry{$vevent}">
  698. <div class="newsImage">{$image}</div>
  699. <h2 class="summary entry-title"><a name="{$id}" id="{$id}" href="{$permlink}" rel="bookmark" class="bookmark">{$item["title"]}</a></h2>
  700. <div class="entry-content description">
  701. <abbr class="published newsdate" title="{$item["published"]}">{$newsdate}</abbr>
  702. {$item["content"]}
  703. </div>
  704. </div>
  705. EOT;
  706. }
  707. return $retval;
  708. }
  709. // BETA
  710. function site_header_beta($title = '', $config = array())
  711. {
  712. global $SIDEBAR_DATA;
  713. global $MYSITE;
  714. $defaults = array(
  715. "lang" => myphpnet_language(),
  716. "current" => "",
  717. "meta-navigation" => array(),
  718. 'classes' => '',
  719. );
  720. $config += $defaults;
  721. $lang = language_convert($config["lang"]);
  722. $curr = $config["current"];
  723. $classes = $config['classes'];
  724. if (empty($title)) {
  725. $title = "Hypertext Preprocessor";
  726. }
  727. // shorturl; http://wiki.snaplog.com/short_url
  728. if (isset($_SERVER['BASE_PAGE']) && $shortname = get_shortname($_SERVER["BASE_PAGE"])) {
  729. $shorturl = "http://php.net/" . $shortname;
  730. }
  731. // For static content
  732. // FIXME: How does static.php.net work? Will it get the /js/ folders?
  733. if (false && ($MYSITE == "http://www.php.net/" || $MYSITE == 'http://php.net/')) {
  734. $STATIC_ROOT = "http://static.php.net/www.php.net/";
  735. } elseif (false && !empty($_SERVER["STATIC_ROOT"])) {
  736. $STATIC_ROOT = $_SERVER["STATIC_ROOT"];
  737. } else {
  738. $STATIC_ROOT = "/";
  739. }
  740. require dirname(__FILE__) ."/header.inc";
  741. }
  742. function site_footer_beta($config = array())
  743. {
  744. require dirname(__FILE__) . "/footer.inc";
  745. }
  746. function news_toc($sections = null) {
  747. include dirname(__FILE__) . "/pregen-news.inc";
  748. $items = array(
  749. "news" => array(
  750. "title" => "News",
  751. "link" => "/archive/",
  752. "children" => print_news($NEWS_ENTRIES, "frontpage", 3, null, true),
  753. ),
  754. "conferences" => array(
  755. "title" => "Conferences",
  756. "link" => "/conferences/",
  757. "children" => print_news($NEWS_ENTRIES, "conferences", 3, null, true),
  758. ),
  759. "papers" => array(
  760. "title" => "Call for Papers",
  761. "link" => "/conferences/",
  762. "children" => print_news($NEWS_ENTRIES, "cfp", 3, null, true),
  763. ),
  764. );
  765. foreach($items as $section => $menu) {
  766. // only print requested sections.
  767. if (is_array($sections) && !in_array($section, $sections)) {
  768. continue;
  769. }
  770. echo "<dt><a href='{$menu["link"]}'>{$menu["title"]}</a></dt>\n";
  771. foreach($menu["children"] as $child) {
  772. echo "<dd><a href='{$child["permlink"]}'>{$child["title"]}</a></dd>\n";
  773. }
  774. }
  775. }
  776. function doc_toc($lang) {
  777. $file = dirname(__FILE__) . "/../manual/$lang/toc/index.inc";
  778. if (!file_exists($file)) {
  779. $lang = "en"; // Fallback on english if the translation doesn't exist
  780. $file = dirname(__FILE__) . "/../manual/en/toc/index.inc";
  781. }
  782. require dirname(__FILE__) . "/../manual/$lang/toc/index.inc";
  783. ?>
  784. <dl>
  785. <dt><a href="/manual/">PHP Manual</a></dt>
  786. <?php doc_toc_list($lang, $TOC, 'getting-started'); ?>
  787. <?php doc_toc_title($lang, $TOC, 'install', 'dd'); ?>
  788. </dl>
  789. <dl>
  790. <?php doc_toc_title($lang, $TOC, 'langref'); ?>
  791. <?php doc_sub_entry($lang, 'langref', 'language.basic-syntax'); ?>
  792. <?php doc_sub_entry($lang, 'langref', 'language.variables'); ?>
  793. <?php doc_sub_entry($lang, 'langref', 'language.operators'); ?>
  794. <?php doc_sub_entry($lang, 'langref', 'language.functions'); ?>
  795. <?php doc_sub_entry($lang, 'langref', 'language.oop5'); ?>
  796. </dl>
  797. <dl>
  798. <?php doc_toc_title($lang, $TOC, 'funcref'); ?>
  799. <?php doc_sub_entry($lang, 'refs.basic.vartype', 'book.array'); ?>
  800. <?php doc_sub_entry($lang, 'refs.calendar', 'book.datetime'); ?>
  801. <?php doc_sub_entry($lang, 'refs.basic.text', 'book.strings'); ?>
  802. <?php doc_toc_title($lang, $TOC, 'faq'); ?>
  803. </dl>
  804. <dl>
  805. <?php doc_toc_title($lang, $TOC, 'security'); ?>
  806. <?php doc_sub_entry($lang, 'security', 'security.database'); ?>
  807. <?php doc_sub_entry($lang, 'security', 'security.variables'); ?>
  808. <?php doc_sub_entry($lang, 'faq', 'faq.passwords'); ?>
  809. <?php doc_toc_title($lang, $TOC, 'appendices'); ?>
  810. </dl>
  811. <?php
  812. }
  813. function doc_sub_entry($lang, $file, $subfile, $elm = "dd") {
  814. static $cache = array();
  815. if (isset($cache["$lang.$file"])) {
  816. $TOC = $cache["$lang.$file"];
  817. } else {
  818. include dirname(__FILE__) . "/../manual/$lang/toc/$file.inc";
  819. }
  820. foreach($TOC as $entry) {
  821. if (substr($entry[0], 0, strlen($subfile)) == $subfile) {
  822. echo "\t<$elm><a href='/manual/$lang/{$entry[0]}'>{$entry[1]}</a></$elm>\n";
  823. }
  824. }
  825. }
  826. function doc_toc_list($lang, $index, $file) {
  827. include dirname(__FILE__) . "/../manual/$lang/toc/$file.inc";
  828. doc_toc_title($lang, $index, $file);
  829. foreach($TOC as $entry) {
  830. echo "\t<dd><a href='/manual/$lang/{$entry[0]}'>{$entry[1]}</a></dd>\n";
  831. }
  832. }
  833. function doc_toc_title($lang, $index, $file, $elm = "dt") {
  834. foreach($index as $entry) {
  835. if ($entry[0] == "$file.php") {
  836. $link = $entry[0];
  837. $title = $entry[1];
  838. break;
  839. }
  840. }
  841. echo "<$elm><a href='/manual/$lang/$link'>$title</a></$elm>\n";
  842. }
  843. /* vim: set et ts=4 sw=4 ft=php: : */