pearweb_manual
[ class tree: pearweb_manual ] [ index: pearweb_manual ] [ all elements ]

Source for file pear-manual.php

Documentation is available at pear-manual.php

  1. <?php
  2. /*
  3.    +----------------------------------------------------------------------+
  4.    | PEAR Web site version 1.0                                            |
  5.    +----------------------------------------------------------------------+
  6.    | Copyright (c) 2001-2005 The PHP Group                                |
  7.    +----------------------------------------------------------------------+
  8.    | This source file is subject to version 2.02 of the PHP license,      |
  9.    | that is bundled with this package in the file LICENSE, and is        |
  10.    | available at through the world-wide-web at                           |
  11.    | http://www.php.net/license/2_02.txt.                                 |
  12.    | If you did not receive a copy of the PHP license and are unable to   |
  13.    | obtain it through the world-wide-web, please send a note to          |
  14.    | license@php.net so we can mail you a copy immediately.               |
  15.    +----------------------------------------------------------------------+
  16.    | Authors: Michael Gauthier <mike@silverorange.com>                    |
  17.    +----------------------------------------------------------------------+
  18.    $Id$
  19. */
  20.  
  21. require_once 'site.php';
  22.  
  23. $doc_languages = array(
  24.     'en' => 'English',
  25.     'fr' => 'French',
  26.     'de' => 'German',
  27.     'ja' => 'Japanese',
  28.     'nl' => 'Dutch',
  29.     'hu' => 'Hungarian',
  30.     // 'it' => 'Italian',
  31.     'pl' => 'Polish',
  32.     'ru' => 'Russian',
  33.     // 'es' => 'Spanish',
  34. );
  35.  
  36. $NEXT $PREV $UP $HOME = array(falsefalse);
  37. $TOC = array();
  38.  
  39. /**
  40.  * Fills global variables with navigational links.
  41.  *
  42.  * @param array $data Array containing home, next, prev, up and toc keys.
  43.  *
  44.  * @return void 
  45.  */
  46. function setupNavigation($data)
  47. {
  48.     global $NEXT$PREV$UP$HOME$TOC$tstamp;
  49.     $HOME    @$data['home'];
  50.     $HOME[0'./';
  51.     $NEXT    @$data['next'];
  52.     $PREV    @$data['prev'];
  53.     $UP      @$data['up'];
  54.     $TOC     @$data['toc'];
  55.     $tstamp  gmdate('D, d M Y'getlastmod());
  56. }
  57.  
  58. function wordWrapTitle($title$indent = false)
  59. {
  60.     $title     trim($title"\t\n :");
  61.     $wrapped   = array($title);
  62.     $maxLength ($indent? 22 : 24;
  63.  
  64.     if (strlen($title$maxLength && strpos($title'::'!== false{
  65.         // break long titles on scope operator
  66.         $wrapped explode('::'$title);
  67.         $partCount count($wrapped);
  68.         foreach ($wrapped as $i => $piece{
  69.             if ($i !== ($partCount - 1)) {
  70.                 $wrapped[$i$wrapped[$i'::';
  71.             }
  72.         }
  73.     elseif (strlen($title$maxLength{
  74.         // word wrap titles
  75.         $wrapped = array();
  76.         while (strlen($title$maxLength{
  77.             $chunk substr($title0$maxLength);
  78.             $pos strrpos($chunk' ');
  79.             if ($pos === false{
  80.                 $pos $maxLength;
  81.             }
  82.             $wrapped[trim(substr($title0$pos));
  83.             $title trim(substr($title$pos));
  84.         }
  85.         $title trim($title);
  86.         if (strlen($title> 0{
  87.             $wrapped[$title;
  88.         }
  89.     }
  90.  
  91.     return $wrapped;
  92. }
  93.  
  94. function navigationSidebar($id$this '')
  95. {
  96.     global $NEXT$PREV$UP$HOME$TOC$DOCUMENT_ROOT;
  97.     global $LANG$CHARSET;
  98.  
  99.     echo "\n\n<!-- START MANUAL SIDEBAR -->\n";
  100.     echo "<div class=\"manual-sidebar\" id=\"manual-sidebar\">\n";
  101.  
  102.     echo " <div class=\"manual-sidebar-top\">\n";
  103.     echo "  <ul>\n";
  104.     echo "   <li>" . make_link('./'$HOME[1]"</li>\n";
  105.     echo "  </ul>\n";
  106.     echo " </div>\n\n";
  107.  
  108.     if (($HOME[1!= $UP[1]&& $UP[1]{
  109.         echo " <div class=\"manual-sidebar-up\">\n";
  110.         echo "  <ul>\n";
  111.         echo "   <li>" . make_link($UP[0]$UP[1]"</li>\n";
  112.         echo "  </ul>\n";
  113.         echo " </div>\n\n";
  114.     }
  115.  
  116.     echo " <div class=\"manual-sidebar-pages\">\n";
  117.     echo "  <ol>";
  118.  
  119.     $package_name getPackageNameForId($id);
  120.     $indent = false;
  121.  
  122.     $toc_count count($TOC);
  123.     for ($i = 0; $i $toc_count$i++{
  124.         list($url$title$TOC[$i];
  125.         if (!$url || !$title{
  126.             continue;
  127.         }
  128.  
  129.         // decode any entities
  130.         $title_fmt html_entity_decode($titleENT_QUOTES$CHARSET);
  131.  
  132.         // trim unnecessary duplication of package name in title
  133.         if (!is_null($package_name)) {
  134.             $title_fmt preg_replace('/^\s*' $package_name '[_\w]*::/'''$title_fmt);
  135.         }
  136.  
  137.         // word wrap it, get each line as an array element
  138.         $title_parts wordWrapTitle($title_fmt);
  139.  
  140.         // encode XML special chars for each line
  141.         foreach ($title_parts as $j => $part{
  142.             $title_parts[$j@htmlspecialchars($partENT_QUOTES$CHARSET);
  143.         }
  144.  
  145.         // implode it back to a single string
  146.         $title_fmt implode('<br />'$title_parts);
  147.  
  148.         // if we're in indentation mode for methods, we have to stop the
  149.         // indentation when we find 'Class Summary'
  150.         if ($indent && substr($title_fmt013== 'Class Summary'{
  151.             echo "</li>\n";
  152.             echo '</ol>';
  153.             $indent = false;
  154.         }
  155.  
  156.         // No need to spell out the constructor, lets just keep it short
  157.         if (substr($title_fmt011== 'constructor'{
  158.             $title_fmt 'Constructor';
  159.         }
  160.  
  161.         // display the title
  162.         $class ($indent'manual-sidebar-page-nested' 'manual-sidebar-page';
  163.         echo "\n" '   <li class="' $class '">'
  164.                 . (($url == $id? "<strong>$title_fmt</strong>"
  165.                                      : make_link($url$title_fmt)) '</li>';
  166.  
  167.         // after 'Class Summary' (or 'constructor', if 'Class Summary' doesn't
  168.         // exist, we want to indent the methods
  169.         if (    substr($title_fmt013== 'Class Summary'
  170.             || ($title_fmt == 'Constructor' && !$indent)
  171.            {
  172.             $indent = true;
  173.             echo '<ol class="manual-sidebar-pages-nested">';
  174.         }
  175.     }
  176.  
  177.     if ($indent{
  178.         echo "  </li>\n";
  179.         echo '</ol>';
  180.     }
  181.  
  182.     echo "\n";
  183.  
  184.     echo "  </ol>\n";
  185.     echo " </div>\n";
  186.  
  187.     // if we have a package name, add links to the package and the API docs
  188.     if (!is_null($package_name)) {
  189.         echo "\n";
  190.  
  191.         echo " <div class=\"manual-sidebar-info\">\n";
  192.         echo "  <ul>\n";
  193.         echo "   <li>" . make_link('/package/' $package_name'Package Info'"</li>\n";
  194.         echo "   <li>" . make_link('/package/' $package_name '/docs/latest/''API Documentation'"</li>\n";
  195.         echo "  </ul>\n";
  196.         echo " </div>\n";
  197.     }
  198.  
  199.     echo "</div>\n";
  200.     echo "<!-- END MANUAL SIDEBAR -->\n\n";
  201. }
  202.  
  203. function navigationBar($id$title$loc)
  204. {
  205.     global $NEXT$PREV$tstamp$CHARSET;
  206.  
  207.     $navClass ($NEXT[1|| $PREV[1]?
  208.         'manual-navigation' 'manual-navigation manual-navigation-no-nav';
  209.  
  210.     echo "<!-- START MANUAL NAVIGATION -->\n";
  211.     echo "<div class=\"{$navClass}\" id=\"manual-navigation-{$loc}\">\n";
  212.  
  213.     if ($PREV[1]{
  214.         $link $PREV[1];
  215.         if (strlen($link> 45{
  216.             $link str_replace('::''::<br />'$link);
  217.         }
  218.  
  219.         // not using make_link because of embedded <span>
  220.         $accesskey ($loc == 'top'' accesskey="r"' '';
  221.         echo " <a class=\"manual-previous\" href=\"{$PREV[0]}\"{$accesskey}>";
  222.         echo $link "\n";
  223.         echo '<span class="title">(P<span class="accesskey">r</span>evious)</span>';
  224.         echo "</a>\n";
  225.     }
  226.  
  227.     echo "\n";
  228.  
  229.     if ($NEXT[1]{
  230.         $link $NEXT[1];
  231.         if (strlen($link> 45{
  232.             $link str_replace('::''::<br />'$link);
  233.         }
  234.  
  235.         // not using make_link because of embedded <span>
  236.         $accesskey ($loc == 'top'' accesskey="x"' '';
  237.         echo " <a class=\"manual-next\" href=\"{$NEXT[0]}\"{$accesskey}>";
  238.         echo $link "\n";
  239.         echo '<span class="title">(Ne<span class="accesskey">x</span>t)</span>';
  240.         echo "</a>\n";
  241.     }
  242.  
  243.     echo "\n";
  244.  
  245.     echo " <div class=\"manual-clear\"></div>\n";
  246.  
  247.     if ($loc == 'bottom'{
  248.  
  249.         // info and download links
  250.         echo " <div class=\"manual-info\">";
  251.         echo "Last updated: {$tstamp}";
  252.         // UTF-8 em-dash
  253.         echo " \xe2\x80\x94 " . make_link('/manual/''Download Documentation');
  254.         echo "</div>\n";
  255.  
  256.         echo "\n";
  257.  
  258.         // bug report links
  259.         $package_name getPackageNameForId($id);
  260.         echo " <div class=\"manual-bug\">\n";
  261.         echo '  Do you think that something on this page is wrong?';
  262.         echo '  Please <a href="' getBugReportLink($package_name'">file a bug report</a> ';
  263.         echo '  or <a href="/notes/add-note-form.php?redirect=' htmlentities($_SERVER['REQUEST_URI']ENT_QUOTES'UTF-8''&amp;uri=' htmlspecialchars(urlencode($id)) '">add a note</a>. ';
  264.         echo "\n";
  265.         echo " </div>\n";
  266.  
  267.         echo "\n";
  268.  
  269.         // language chooser
  270.         global $LANGUAGES$LANG;
  271.         $langs = array();
  272.         foreach ($LANGUAGES as $code => $name{
  273.             if (file_exists("../$code/$id")) {
  274.                 $langs[= array(
  275.                     'code'  => $code,
  276.                     'title' => $name,
  277.                     'link'  => make_link("../$code/$id"$name)
  278.                 );
  279.             }
  280.         }
  281.  
  282.         $file substr($id0-4);
  283.         if (file_exists("html/{$file}.html")) {
  284.             $langs[= array(
  285.                 'code'  => null,
  286.                 'title' => 'Plain HTML',
  287.                 'link'  => make_link("html/{$file}.html"'Plain HTML')
  288.             );
  289.         }
  290.  
  291.         if (count($langs)) {
  292.             echo " <div class=\"manual-languages\">\n";
  293.             echo 'View this page in:';
  294.             echo "  <ul class=\"manual-language-list\">\n";
  295.             $count = 0;
  296.             foreach ($langs as $lang{
  297.                 echo "   <li class=\"manual-language\">";
  298.                 if ($count > 0{
  299.                     // UTF-8 bullet
  300.                     echo " &nbsp;\xe2\x80\xa2&nbsp; ";
  301.                 }
  302.                 if ($lang['code'== $LANG{
  303.                     echo '<strong>' $lang['title''</strong>';
  304.                 else {
  305.                     echo $lang['link'];
  306.                 }
  307.                 echo "</li>\n";
  308.                 $count++;
  309.             }
  310.             echo "  </ul>\n";
  311.             echo " </div>\n";
  312.         }
  313.  
  314.         echo "\n";
  315.  
  316.         // user notes
  317.         echo " <div class=\"manual-notes\" id=\"user-notes\">\n";
  318.         echo "  <h3>User Notes:</h3>\n";
  319.         echo "  " getComments($id"\n";
  320.         echo " </div>\n";
  321.     }
  322.  
  323.     echo "</div>\n<!-- END MANUAL NAVIGATION -->\n\n";
  324. }
  325.  
  326. /**
  327.  * Extracts the package name from a given manual page id.
  328.  *
  329.  * @param string $id Docbook chunk id (Manual page id)
  330.  *
  331.  * @return string Package name, null if not found
  332.  */
  333. function getPackageNameForId($id)
  334. {
  335.     global $dbh;
  336.     static $package_name = null;  // static variable to avoid multiple queries
  337.     if (is_null($package_name)) {
  338.         $res = preg_match('/^package\.[\w-]+\.([\w-]+).*\.php$/'$id$matches);
  339.         if ($res === 1{
  340.             $package str_replace('-''_'$matches[1]);
  341.             $query 'SELECT name FROM packages WHERE LCASE(name) = LCASE(?)';
  342.             $package_name $dbh->getOne($query$package);
  343.         }
  344.     }
  345.     return $package_name;
  346. }
  347.  
  348. /**
  349.  * Returns the URI to report a bug for the package
  350.  *
  351.  * @param string $package_name Package name, may be NULL for
  352.  *                              documentation bugs
  353.  *
  354.  * @return string URI
  355.  */
  356. function getBugReportLink($package_name)
  357. {
  358.     $bug_report_link '/bugs/report.php?package=Documentation';
  359.     if (!is_null($package_name)) {
  360.         $bug_report_link '/bugs/report.php?package=' $package_name;
  361.     }
  362.     return $bug_report_link;
  363. }
  364.  
  365. /**
  366.  * Generates and returns the notes comments HTML.
  367.  *
  368.  * @param string $uri Manual page id
  369.  *
  370.  * @return string HTML
  371.  */
  372. function getComments($uri)
  373. {
  374.     $output '';
  375.  
  376.     require_once 'notes/ManualNotes.class.php';
  377.     $manualNotes = new Manual_Notes();
  378.     $comments $manualNotes->getPageComments($uriauth_check('pear.dev'));
  379.  
  380.     if (empty($comments)) {
  381.         $output .= 'There are no user contributed notes for this page.';
  382.     }
  383.  
  384.     foreach ($comments as $comment{
  385.         $manualNotes->display($comment);
  386.     }
  387.  
  388.     return $output;
  389. }
  390.  
  391. /**
  392.  * Sends HTTP headers for the manual.
  393.  *
  394.  * @internal
  395.  *  Sets global $LANG and $CHARSET parameters to the values passed
  396.  *  to this function.
  397.  *
  398.  * @param string $charset Charset (encoding) to send
  399.  * @param string $lang    2-letter language code
  400.  *
  401.  * @return void 
  402.  */
  403. function sendManualHeaders($charset$lang)
  404. {
  405.     global $LANG,$CHARSET;
  406.     $LANG $lang;
  407.     $CHARSET $charset;
  408.     Header('Cache-Control: public, max-age=600');
  409.     Header('Vary: Cookie');
  410.     Header('Content-Type: text/html;charset=' $charset);
  411.     Header('Content-Language: ' $lang);
  412. }
  413.  
  414. /**
  415.  * Displays HTML headers suitable to display a manual page.
  416.  *
  417.  * @param string $id           ID of the docbook chunk (manual page id)
  418.  * @param string $title        Manual page title
  419.  * @param string $extraHeaders Additional HTML header tags
  420.  *
  421.  * @return void 
  422.  */
  423. function manualHeader($id$title ''$extraHeaders = null)
  424. {
  425.     global $HTDIG$CHARSET;
  426.  
  427.     header('Content-Type: text/html; charset=' $CHARSET);
  428.     response_header(
  429.         'Manual :: ' $title,
  430.         false,
  431.         $extraHeaders getManualHeaderNavLinks()
  432.     );
  433.     //create links to plain html and other languages
  434.     if (!$HTDIG{
  435.         navigationBar($id$title'top');
  436.     }
  437.  
  438.     // draw manual sidebar
  439.     navigationSidebar($id$title);
  440.  
  441.     // start main manual content
  442.     echo "<div class=\"manual-content\" id=\"manual-content\">\n";
  443. }
  444.  
  445. /**
  446.  * Display html footer and closing html tag
  447.  *
  448.  * @param string $id    ID of docbook chunk (manual page id)
  449.  * @param string $title Manual page title
  450.  *
  451.  * @return void 
  452.  */
  453. function manualFooter($id$title '')
  454. {
  455.     echo "</div>\n";
  456.  
  457.     global $HTDIG;
  458.     if (!$HTDIG{
  459.         navigationBar($id$title'bottom');
  460.     }
  461.  
  462.     response_footer();
  463. }
  464.  
  465. /**
  466.  * Creates HTML <link rel..> tags that are used by user agents
  467.  * that support it.
  468.  *
  469.  * @internal
  470.  *  Utilizes global $NEXT, $PREV, $UP, $HOME variables
  471.  *
  472.  * @return string HTML code that should be included in
  473.  *                 the HTML <head> tag.
  474.  */
  475. {
  476.     global $NEXT$PREV$UP$HOME;
  477.  
  478.     $eh '';
  479.     if (isset($NEXT)) {
  480.         $eh .= ' <link rel="next" href="' $NEXT[0'" title="' $NEXT[1'"/>' "\n";
  481.     }
  482.     if (isset($PREV)) {
  483.         $eh .= ' <link rel="prev" href="' $PREV[0'" title="' $PREV[1'"/>' "\n";
  484.     }
  485.     if (isset($UP)) {
  486.         $eh .= ' <link rel="up" href="' $UP[0'" title="' $UP[1'"/>' "\n";
  487.     }
  488.     if (isset($HOME)) {
  489.         $eh .= ' <link rel="home" href="' $HOME[0'" title="' $HOME[1'"/>' "\n";
  490.     }
  491.     return $eh;
  492. }

Documentation generated on Mon, 11 Mar 2019 16:04:26 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.