momo            Sun May  2 02:49:31 2004 EDT

  Added files:                 
    /livedocs/langs     en.style_mapping.php he.style_mapping.php 
  Log:
  rtl support step one (harmless one).
  the second that activate the changes goes to the newgroup with explanations as patch.
  
http://cvs.php.net/co.php/livedocs/langs/en.style_mapping.php?r=1.1&p=1
Index: livedocs/langs/en.style_mapping.php
+++ livedocs/langs/en.style_mapping.php
<?php
/* vim: set tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.php.net/license/3_0.txt.                                  |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Wez Furlong, Derick Rethans, Ilia Alshanetsky               |
// +----------------------------------------------------------------------+
// | Helper functions for formatting elements                             |
// +----------------------------------------------------------------------+
//
// $Id: en.style_mapping.php,v 1.1 2004/05/02 06:49:31 momo Exp $

// almost XPATH.. ;-)
$map = array(
        'acronym'               => 'acronym',
        'appendix/title'        => 'h1',
        'author'                => 'format_name',
        'authorgroup'           => 'format_authorgroup',
        'bookinfo/title'        => 'h1',
        'chapter/title'         => 'h1',
        'classname'             => 'span',
        'classsynopsis'         => 'format_class_synopsis',
        'code'                  => 'code',
        'collab'                => 'span',
        'collabname'            => 'span',
        'command'               => 'span',
        'computeroutput'        => 'span',
        'constant'              => 'span',
        'copyright'             => 'format_copyright',
        'copyright/year'        => 'span',
        'copyright/holder'      => 'span',
        'editor'                => 'format_name',
        'emphasis'              => 'em',
        'enumname'              => 'span',
        'envar'                 => 'span',
        'filename'              => 'span',
        'funcsynopsis'          => 'format_funcsynopsis',
        'function'              => 'format_function',
        'glossterm'             => 'span',
        'htmlcode'              => 'format_htmlcode',
        'informaltable'         => 'table',
        'informaltable/title'   => 'caption',
        'itemizedlist'          => 'ul',
        'itemizedlist/listitem' => 'li',
        'legalnotice/title'     => 'h3',
        'link'                  => 'format_link',
        'literal'               => 'span',
        'literallayout'         => 'format_listing',
        'methodparam'           => 'span',
        'methodsynopsis'        => 'format_params',
        'option'                => 'span',    
        'orderedlist'           => 'ol',
        'orderedlist/listitem'  => 'li',
        'parameter'             => 'span',
        'phpdoc_include'        => 'handle_include',
        'preface/title'         => 'h1',
        'productname'           => 'span',
        'programlisting'        => 'format_listing',
        'propname'              => 'span',
        'proptype'              => 'span',
        'pubdate'               => 'format_pubdate',
        'reference/title'       => 'h1',
        'refnamediv/refname'    => 'h1',
        'refnamediv/refpurpose' => 'format_refpurpose',
        'refsect1/title'        => 'h3',
        'refsect2/title'        => 'h4',
        'replaceable'           => 'span',
        'screen'                => 'format_listing',
        'section/title'         => 'h1',
        'sect1/title'           => 'h2',
        'sect2/title'           => 'h3',
        'sect3/title'           => 'h4',
        'sect4/title'           => 'h5',
        'sect5/title'           => 'h6',
        'signalname'            => 'span',
        'simpara'               => 'p',
        'simplelist'            => 'ul',
        'simplelist/member'     => 'li',
        'subscript'             => 'span',
        'systemitem'            => 'span',
        'table'                 => 'table',
        'table/title'           => 'caption',
        'tbody'                 => 'tbody',
        'tbody/row'             => 'tr',
        'tbody/row/entry'       => 'td',
        'tgroup'                => '',
        'thead'                 => 'thead',
        'thead/row'             => 'tr',
        'thead/row/entry'       => 'th',    
        'titleabbrev'           => '',
        'type'                  => 'span',
        'ulink'                 => 'format_ulink',
        'userinput'             => 'span',
        'varname'               => 'span',
        'warning/title'         => 'format_warning_title',
        'xref'                  => 'format_link',    
);


function format_authorgroup($node) 
{
        $l = '';
        $cl = array();

        foreach ($node->children as $child) {
                if ($child->tagname == "author" || $child->tagname == "editor") {
                        $l .= format_name($child);
                }
                if ($child->tagname == "collab") {
                        $cl[] = $child->children[0]->content;
                }
        }
        switch ($node->attributes['id']) {
                case "authors":
                        $prefix = "Authors:<br />";
                        break;
                case "editors":
                        $prefix = "Edited by:<br />";
                        break;
                case "translators";
                        $prefix = $cl[0]."<br />";
                        unset($cl[0]);
                        break;
                default:
                        $prefix = $node->attributes['id'];
        }

        return sprintf('<div class="group%s"><b>%s</b>%s %s%s</div>', 
$node->attributes['id'], $prefix, $node->content, $l, implode(", ", $cl));
}

function format_copyright($node) 
{
        $y = array();

        foreach ($node->children as $child) {
                if ($child->tagname == "year") {
                        $y[] = $child->content;
                } else if ($child->tagname == "holder") {
                        $holder = $child->content;
                }
        }

        return sprintf('<div class="copyright">Copyright &copy; %s by %s</div>', 
implode(", ", $y), $holder);
}

function format_refpurpose($node) 
{
        global $current_page, $idx, $print_version;

        $vers = '';

        if (substr($current_page, 0, 9) == 'function.') {
                $func_name = sqlite_escape_string(strtr(substr($current_page, 9), '-', 
'_'));
                $q = sqlite_query($idx, "SELECT versinfo FROM funcs where 
funcname='$func_name'");
                if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) {
                        $vers = sprintf('<div class="versinfo">%s</div>', $r[0]);
                } else {
                        $vers = '<div class="versinfo">no version information, might 
be only in CVS</div>';
                }
        }

        return sprintf('%s<h2 class="refpurpose">%s</h2>', $vers, $node->content);
}

function format_name($node) 
{
        $class = $node->parent->attributes['id'];
        foreach ($node->children as $child) {
                if ($child->tagname == 'firstname') {
                        $firstname = $child->content;
                }
                if ($child->tagname == 'surname') {
                        $surname = $child->content;
                }
        }
        switch ($class) {
                case 'authors':
                case 'editors':
                        $tag = 'div';
                        break;
                case 'translators':
                        $tag = 'span';
                        break;
                default:
                        $tag = 'span';
        }
        return sprintf('<%s class="%s">%s %s</%s>', $tag, $class, $firstname, 
$surname, $tag);
}

function format_parameter($node) 
{
        return sprintf('<span class="%s">$%s</span>', $node->tagname, $node->content);
}

function format_pubdate($node) 
{
        return sprintf('<div class="%s">Published on: %s</div>', $node->tagname, 
$node->content);
}

function format_ulink($node) 
{
        return sprintf('<a target="_blank" class="ulink" href="%s">%s</a>',
                $node->attributes['url'],
                $node->content
                );
}

function format_warning_title($node) 
{
        return sprintf('<span class="warning_title">%s</span>', $node->content);
}

function format_link($node) 
{
        global $lang;

        $caption = $node->content;
        if (strlen($caption) == 0) {
                $caption = lookup_title($node->attributes['linkend']);
        }
        if (strlen($caption) == 0) {
                $caption = $node->attributes['linkend'];
        }
        $url = generate_url_for_id($lang, $node->attributes['linkend']);
        return sprintf('<a class="%s" href="%s">%s</a>',
                $node->tagname,
                $url,
                $caption
                );
}

function format_function($node) 
{
        global $current_page, $lang;

        $replace = array('_' => '-',
                        '::' => '-',
                        '->' => '-');

        $itemid = strtr($node->content, $replace);
        $itemid = strtr($itemid, array('---' => '-'));

        $class = 'function';
        if (isset($node->attributes['class'])) {
                $class = 'method';
                $dest = $node->attributes['class'] . '.method.' . $itemid;
        } else {
                $dest = 'function.' . $itemid;
        }

        if ($current_page == $dest) {
                return sprintf('<span class="%s">%s()</span>', $class, $node->content);
        }

        $url = generate_url_for_id($lang, $dest);
        return sprintf('<a class="%s" href="%s">%s()</a>',
                $class,
                $url,
                $node->content
                );
}

function format_listing($node) 
{
        $content = trim($node->content);

        if (substr($content, 0, 5) == '<?php') {
                $node->attributes['role'] = 'php';
        }
        if (!isset($node->attributes['role'])) {
                $node->attributes['role'] = '';
        }

        switch ($node->attributes['role']) {
                case 'php':

// Small hack because highlight_string has changed its behaviour in PHP 5 RC1
                        if (version_compare(phpversion(), '5.0.0RC1') == -1){
                                $content = preg_replace(array(
                                        '@<br />@',
                                        '@<font color="([^"]+)">@',
                                        '@</font>@',
                                        ),
                                        array(
                                        "<br />\n",
                                        '<span class="\\1">',
                                        '</span>',
                                        ),
                                        highlight_string($content, 1));
                        } else {
                                $content = preg_replace(array(
                                        '@<br />@',
                                        '@<span style="color: ([^"]+)">@',
                                        '@</span>@',
                                        ),
                                        array(
                                        "<br />\n",
                                        '<span class="\\1">',
                                        '</span>',
                                        ),
                                        highlight_string($content, 1));
                        }
                        break;
                case 'shell':
                case 'html':
                case 'xml':
                case 'c':
                        $content = '<pre>' . htmlentities($content) . '</pre>';
                        break;
                default:
                        $content = htmlspecialchars($content);
        }

        return sprintf('<div class="%scode">%s</div>', $node->attributes['role'], 
$content);
}

function format_params($node) 
{
        $node->parent = null;

        /* Check role */
        if (isset($node->attributes['role'])) {
                $role = $node->attributes['role'];
        } else {
                $role = 'php';
        }

        /* build up prototype */
        $type = $node->children[0]->content;
        $fname = $node->children[1]->content;
        if (!strlen(trim($fname))) { // it's a class
                $fname = $node->children[3]->content;
        }
        $params = "";
        $optclose = "";
        
        for ($i = 2; $i < count($node->children); $i++) {
                $k = $node->children[$i];
        
                if (strlen($k->tagname) == 0 || $k->tagname == 'void') {
                        continue;
                }
        
                $p = '';
                if (strlen(trim(strip_tags($params)))) {
                        $p .= ',';
                }
                
                if (isset($k->attributes['choice']) && $k->attributes['choice'] == 
'opt') {
                        $p = '[' . $p ;
                        $optclose .= ']';
                        if (strlen($params)) {
                                $p = ' ' . $p;
                        }
                }

                if (strlen($p)) {
                        $p .= ' ';
                }

                if (isset($k->children[0])) {
                        $p .= '<span class="methodparam"><span class="type">' . 
$k->children[0]->content . '</span>';
                }

                if (isset($k->children[1])) {
                        $name = $k->children[1]->content;
                } else {
                        $name = '';
                }
                switch ($role) {
                        case 'c':
                                break;
                        default:
                                if ($name && $name{0} == '&') {
                                        $name = '&$' . substr($name, 1);
                                } elseif(trim($name) != '') {
                                        $name = '$' . $name;
                                } else {
                                        $name = '';
                                }
                }

                $p .= ' <span class="varname">' . $name . '</span></span>';

                $params .= $p;
        }


        return "<div class=\"methodsynopsis\"><span class=\"type\">$type</span> <span 
class=\"function\">$fname(</span>$params$optclose<span 
class=\"function\">)</span></div>";
}

function format_class_synopsis($node) 
{
        $classname = $node->children[0]->children[0]->content;


        $head = "<div class=\"classsynopsis\">class <span 
class=\"classname\">$classname</span> {\n<div class=\"classcontents\">";
        $foot = "</div>}\n</div>";
        $body = "";

        for ($i = 1; $i < count($node->children); $i++) {
                $k = $node->children[$i];

                switch ($k->tagname) {
                        case 'constructorsynopsis':
                        case 'methodsynopsis':
                                $body .= format_params($k);
                                break;
                        case 'fieldsynopsis':
                                $body .= "<div class=\"fieldsynopsis\"><span 
class=\"type\">" .
                                        $k->children[0]->content . "</span> <span 
class=\"varname\">" .
                                        $k->children[1]->content . "</span></div>\n";
                                break;
                }
        }


        return $head . $body . $foot;
}

function format_funcsynopsis($node) 
{
        $html = "<div class=\"funcsynopsis\">";

        /* for each prototype in the synopsis */
        for ($proto = 0; $proto < count($node->children); $proto++) {
                $p = $node->children[$proto];

                if ($p->tagname != 'funcprototype')
                        continue;

                if (isset($p->attributes['role'])) {
                        $role = $node->attributes['role'];
                } else {
                        $role = 'php';
                }

                $funcdef = $p->children[0];
                $rettype = "";
                $funcname = "";

                for ($i = 0; $i < count($funcdef->children); $i++) {
                        $k = $funcdef->children[$i];
                        switch($k->tagname) {
                                case '':
                                        $rettype = $k->content;
                                        break;
                                case 'function':
                                        $funcname = $k->content;
                                        break;
                        }
                }

                if ($rettype == '') {
                        $rettype = 'void';
                }


                $html .= "<div class=\"funcprototype\"><span 
class=\"type\">$rettype</span> <span class=\"function\">$funcname</span>";

                $params = "";
                $optclose = "";

                for ($i = 1; $i < count($p->children); $i++) {
                        $def = $p->children[$i];
                        if ($def->tagname != 'paramdef') {
                                continue;
                        }
                        $paramhtml = "";
                        $paramtype = "";
                        $param = null;

                        for ($j = 0; $j < count($def->children); $j++) {
                                $k = $def->children[$j];
                                switch($k->tagname) {
                                        case 'parameter':
                                                $param = $k;
                                                break;
                                        case 'enumname':
                                                $paramtype = "<span 
class=\"enumname\">{$k->content}</enumname>";
                                                break;
                                        case '':
                                                if (strlen($paramtype) == 0)
                                                        $paramtype = $k->content;
                                                break;
                                }
                        }
                        if ($paramtype == '') {
                                $paramtype = 'void';
                        }

                        if (count($param->children) > 1) {
                                $param = $param->children[1];
                                $optional = true;
                        } else {
                                $optional = false;
                        }
                        $paramname = trim($param->content);

                        if (strlen($params)) {
                                $paramhtml .= ',';
                        }
                        if ($optional) {
                                $paramhtml = '[' . $paramhtml;
                                $optclose .= ']';
                                if (strlen($params)) {
                                        $paramhtml = ' ' . $paramhtml;
                                }
                        }

                        if (strlen($paramhtml)) {
                                $paramhtml .= ' ';
                        }

                        $paramhtml .= '<span class=\"paramdef\"><span class=\"type\">' 
. $paramtype . '</span>';

                        switch ($role) {
                                case 'c':
                                        break;
                                default:
                                        if ($paramname && $paramname{0} == '&') {
                                                $paramname = '&$' . substr($paramname, 
1);
                                        } else {
                                                $paramname = '$' . $paramname;
                                        }
                        }

                        $paramhtml .= ' <span class=\"parameter\">' . $paramname . 
'</span></span>';

                        $params .= $paramhtml;
                }

                $html .= '(' . $params . $optclose . ")</div>";
        }

        return $html . "</div>";
}
?>

http://cvs.php.net/co.php/livedocs/langs/he.style_mapping.php?r=1.1&p=1
Index: livedocs/langs/he.style_mapping.php
+++ livedocs/langs/he.style_mapping.php
<?php
/* vim: set tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.php.net/license/3_0.txt.                                  |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Wez Furlong, Derick Rethans, Ilia Alshanetsky               |
// +----------------------------------------------------------------------+
// | Helper functions for formatting elements                             |
// +----------------------------------------------------------------------+
//
// $Id: he.style_mapping.php,v 1.1 2004/05/02 06:49:31 momo Exp $

$direction="rtl";
$charset = "windows-1255";
// almost XPATH.. ;-)
$map = array(
        'acronym'               => 'acronym',
        'appendix/title'        => 'h1',
        'author'                => 'format_name',
        'authorgroup'           => 'format_authorgroup',
        'bookinfo/title'        => 'h1',
        'chapter/title'         => 'h1',
        'classname'             => 'span',
        'classsynopsis'         => 'format_class_synopsis',
        'code'                  => 'code',
        'collab'                => 'span',
        'collabname'            => 'span',
        'command'               => 'span',
        'computeroutput'        => 'span',
        'constant'              => 'span',
        'copyright'             => 'format_copyright',
        'copyright/year'        => 'span',
        'copyright/holder'      => 'span',
        'editor'                => 'format_name',
        'emphasis'              => 'format_emphasis',
        'enumname'              => 'span',
        'envar'                 => 'span',
        'filename'              => 'span',
        'funcsynopsis'          => 'format_funcsynopsis',
        'function'              => 'format_function',
        'glossterm'             => 'span',
        'htmlcode'              => 'format_htmlcode',
        'informaltable'         => 'table',
        'informaltable/title'   => 'caption',
        'itemizedlist'          => 'ul',
        'itemizedlist/listitem' => 'li',
        'legalnotice/title'     => 'h3',
        'link'                  => 'format_link',
        'literal'               => 'format_literal',
        'literallayout'         => 'format_listing',
        'methodparam'           => 'span',
        'methodsynopsis'        => 'format_params',
        'option'                => 'format_option',    
        'orderedlist'           => 'ol',
        'orderedlist/listitem'  => 'li',
        'parameter'             => 'span',
        'phpdoc_include'        => 'handle_include',
        'preface/title'         => 'h1',
        'productname'           => 'span',
        'programlisting'        => 'format_listing',
        'propname'              => 'span',
        'proptype'              => 'span',
        'pubdate'               => 'format_pubdate',
        'reference/title'       => 'h1',
        'refnamediv/refname'    => 'h1',
        'refnamediv/refpurpose' => 'format_refpurpose',
        'refsect1/title'        => 'h3',
        'refsect2/title'        => 'h4',
        'replaceable'           => 'span',
        'screen'                => 'format_listing',
        'section/title'         => 'h1',
        'sect1/title'           => 'h2',
        'sect2/title'           => 'h3',
        'sect3/title'           => 'h4',
        'sect4/title'           => 'h5',
        'sect5/title'           => 'h6',
        'signalname'            => 'span',
        'simpara'               => 'p',
        'simplelist'            => 'ul',
        'simplelist/member'     => 'li',
        'subscript'             => 'span',
        'systemitem'            => 'span',
        'table'                 => 'table',
        'table/title'           => 'caption',
        'tbody'                 => 'tbody',
        'tbody/row'             => 'tr',
        'tbody/row/entry'       => 'td',
        'term'                          => 'format_term',
        'tgroup'                => '',
        'thead'                 => 'thead',
        'thead/row'             => 'tr',
        'thead/row/entry'       => 'th',    
        'titleabbrev'           => '',
        'type'                  => 'span',
        'ulink'                 => 'format_ulink',
        'userinput'             => 'span',
        'varname'               => 'format_varname',
        'warning/title'         => 'format_warning_title',
        'xref'                  => 'format_link',    
);


function format_authorgroup($node) 
{
        $l = '';
        $cl = array();

        foreach ($node->children as $child) {
                if ($child->tagname == "author" || $child->tagname == "editor") {
                        $l .= format_name($child);
                }
                if ($child->tagname == "collab") {
                        $cl[] = $child->children[0]->content;
                }
        }
        switch ($node->attributes['id']) {
                case "authors":
                        $prefix = "??????:<br />";
                        break;
                case "editors":
                        $prefix = "???? ?\"?:<br />";
                        break;
                case "translators";
                        $prefix = $cl[0]."<br />";
                        unset($cl[0]);
                        break;
                default:
                        $prefix = $node->attributes['id'];
        }

        return sprintf('<div class="group%s"><b>%s</b>%s %s%s</div>', 
$node->attributes['id'], $prefix, $node->content, $l, implode(", ", $cl));
}

function format_copyright($node) 
{
        $y = array();

        foreach ($node->children as $child) {
                if ($child->tagname == "year") {
                        $y[] = $child->content;
                } else if ($child->tagname == "holder") {
                        $holder = $child->content;
                }
        }

        return sprintf('<div class="copyright">Copyright &copy; %s by %s</div>', 
implode(", ", $y), $holder);
}

function format_emphasis($node)
{
        return sprintf('<em class="%s" dir=ltr>%s</em> ', $node->tagname, 
htmlspecialchars($node->content, ENT_NOQUOTES));      
}

function format_literal($node)
{
        return sprintf('<span class="%s" dir=ltr>%s</span> ', $node->tagname, 
htmlspecialchars($node->content, ENT_NOQUOTES));  
}

function format_term($node)
{
        return sprintf('<span class="%s" dir=ltr>%s</span> ', $node->tagname, 
htmlspecialchars($node->content, ENT_NOQUOTES));  
}

function format_varname($node)
{
        return sprintf('<span class="%s" dir=ltr>%s</span> ', $node->tagname, 
htmlspecialchars($node->content, ENT_NOQUOTES));  
}

function format_option($node)
{
        return sprintf('<span class="%s" dir=ltr>%s</span> ', $node->tagname, 
htmlspecialchars($node->content, ENT_NOQUOTES));  
}

function format_refpurpose($node) 
{
        global $current_page, $idx, $print_version;

        $vers = '';

        if (substr($current_page, 0, 9) == 'function.') {
                $func_name = sqlite_escape_string(strtr(substr($current_page, 9), '-', 
'_'));
                $q = sqlite_query($idx, "SELECT versinfo FROM funcs where 
funcname='$func_name'");
                if ($q && $r = sqlite_fetch_array($q, SQLITE_NUM)) {
                        $vers = sprintf('<div class="versinfo">%s</div>', $r[0]);
                } else {
                        $vers = '<div class="versinfo">no version information, might 
be only in CVS</div>';
                }
                $print_version = 1;
        }
        
        return sprintf('%s<h2 class="refpurpose">%s</h2>', $vers, $node->content);
}

function format_name($node) 
{
        $class = $node->parent->attributes['id'];
        foreach ($node->children as $child) {
                if ($child->tagname == 'firstname') {
                        $firstname = $child->content;
                }
                if ($child->tagname == 'surname') {
                        $surname = $child->content;
                }
        }
        switch ($class) {
                case 'authors':
                case 'editors':
                        $tag = 'div';
                        break;
                case 'translators':
                        $tag = 'span';
                        break;
                default:
                        $tag = 'span';
        }
        return sprintf('<%s class="%s">%s %s</%s>', $tag, $class, $firstname, 
$surname, $tag);
}

function format_parameter($node) 
{
        return sprintf('<span class="%s">$%s</span>', $node->tagname, 
htmlspecialchars($node->content, ENT_NOQUOTES));
}

function format_pubdate($node) 
{
        return sprintf('<div class="%s">Published on: %s</div>', $node->tagname, 
htmlspecialchars($node->content, ENT_NOQUOTES));
}

function format_ulink($node) 
{
        $dir = ereg("([à-ú]+)",$node->content) ? "rtl":"ltr";
        return sprintf('<a target="_blank" class="ulink" href="%s" 
dir="'.$dir.'">%s</a>',
                $node->attributes['url'],
                htmlspecialchars($node->content, ENT_NOQUOTES)
                );
}

function format_warning_title($node) 
{
        return sprintf('<span class="warning_title">%s</span>', 
htmlspecialchars($node->content, ENT_NOQUOTES));
}

function format_link($node) 
{
        global $lang;

        $caption = $node->content;
        if (strlen($caption) == 0) {
                $caption = lookup_title($node->attributes['linkend']);
        }
        if (strlen($caption) == 0) {
                $caption = $node->attributes['linkend'];
        }
        $url = generate_url_for_id($lang, $node->attributes['linkend']);
        $dir = ereg("([à-ú]+)",$caption) ? "rtl":"ltr";
        return sprintf('<a class="%s" href="%s" dir="'.$dir.'">%s</a>',
                $node->tagname,
                $url,
                $caption
                );
}

function format_function($node) 
{
        global $current_page, $lang;

        $replace = array('_' => '-',
                        '::' => '-',
                        '->' => '-');

        $itemid = strtr($node->content, $replace);
        $itemid = strtr($itemid, array('---' => '-'));

        $class = 'function';
        if (isset($node->attributes['class'])) {
                $class = 'method';
                $dest = $node->attributes['class'] . '.method.' . $itemid;
        } else {
                $dest = 'function.' . $itemid;
        }

        if ($current_page == $dest) {
                return sprintf('<span class="%s" dir="ltr">%s()</span>', $class, 
$node->content);
        }

        $url = generate_url_for_id($lang, $dest);
        return sprintf('<a class="%s" href="%s" dir="ltr">%s()</a>',
                $class,
                $url,
                htmlspecialchars($node->content, ENT_NOQUOTES)
                );
}

function format_listing($node) 
{
        $content = trim($node->content);

        if (substr($content, 0, 5) == '<?php') {
                $node->attributes['role'] = 'php';
        }
        if (!isset($node->attributes['role'])) {
                $node->attributes['role'] = '';
        }

        switch ($node->attributes['role']) {
                case 'php':

// Small hack because highlight_string has changed its behaviour in PHP 5 RC1
                        if (version_compare(phpversion(), '5.0.0RC1') == -1){
                                $content = preg_replace(array(
                                        '@<br />@',
                                        '@<font color="([^"]+)">@',
                                        '@</font>@',
                                        ),
                                        array(
                                        "<br />\n",
                                        '<span class="\\1">',
                                        '</span>',
                                        ),
                                        highlight_string($content, 1));
                        } else {
                                $content = preg_replace(array(
                                        '@<br />@',
                                        '@<span style="color: ([^"]+)">@',
                                        '@</span>@',
                                        ),
                                        array(
                                        "<br />\n",
                                        '<span class="\\1">',
                                        '</span>',
                                        ),
                                        highlight_string($content, 1));
                        }
                        break;
                case 'shell':
                case 'html':
                case 'xml':
                case 'c':
                        $content = '<pre>' . htmlentities($content) . '</pre>';
                        break;
                default:
                        $content = htmlspecialchars($content);
        }

        return sprintf('<div dir=ltr class="%scode">%s</div>', 
$node->attributes['role'], $content);
}

function format_params($node) 
{
        $node->parent = null;

        /* Check role */
        if (isset($node->attributes['role'])) {
                $role = $node->attributes['role'];
        } else {
                $role = 'php';
        }

        /* build up prototype */
        $type = $node->children[0]->content;
        $fname = $node->children[1]->content;
        if (!strlen(trim($fname))) { // it's a class
                $fname = $node->children[3]->content;
        }
        $params = "";
        $optclose = "";
        
        for ($i = 2; $i < count($node->children); $i++) {
                $k = $node->children[$i];
        
                if (strlen($k->tagname) == 0 || $k->tagname == 'void') {
                        continue;
                }
        
                $p = '';
                if (strlen(trim(strip_tags($params)))) {
                        $p .= ',';
                }
                
                if (isset($k->attributes['choice']) && $k->attributes['choice'] == 
'opt') {
                        $p = '[' . $p ;
                        $optclose .= ']';
                        if (strlen($params)) {
                                $p = ' ' . $p;
                        }
                }

                if (strlen($p)) {
                        $p .= ' ';
                }

                if (isset($k->children[0])) {
                        $p .= '<span class="methodparam"><span class="type">' . 
$k->children[0]->content . '</span>';
                }

                if (isset($k->children[1])) {
                        $name = $k->children[1]->content;
                } else {
                        $name = '';
                }
                switch ($role) {
                        case 'c':
                                break;
                        default:
                                if ($name && $name{0} == '&') {
                                        $name = '&$' . substr($name, 1);
                                } elseif(trim($name) != '') {
                                        $name = '$' . $name;
                                } else {
                                        $name = '';
                                }
                }

                $p .= ' <span class="varname">' . $name . '</span></span>';

                $params .= $p;
        }


        return "<div class=\"methodsynopsis\" dir=\"ltr\"><span 
class=\"type\">$type</span> <span 
class=\"function\">$fname(</span>$params$optclose<span 
class=\"function\">)</span></div>";
}

function format_class_synopsis($node) 
{
        $classname = $node->children[0]->children[0]->content;


        $head = "<div class=\"classsynopsis\">class <span 
class=\"classname\">$classname</span> {\n<div class=\"classcontents\">";
        $foot = "</div>}\n</div>";
        $body = "";

        for ($i = 1; $i < count($node->children); $i++) {
                $k = $node->children[$i];

                switch ($k->tagname) {
                        case 'constructorsynopsis':
                        case 'methodsynopsis':
                                $body .= format_params($k);
                                break;
                        case 'fieldsynopsis':
                                $body .= "<div class=\"fieldsynopsis\"><span 
class=\"type\">" .
                                        $k->children[0]->content . "</span> <span 
class=\"varname\">" .
                                        $k->children[1]->content . "</span></div>\n";
                                break;
                }
        }


        return $head . $body . $foot;
}

function format_funcsynopsis($node) 
{
        $html = "<div class=\"funcsynopsis\">";

        /* for each prototype in the synopsis */
        for ($proto = 0; $proto < count($node->children); $proto++) {
                $p = $node->children[$proto];

                if ($p->tagname != 'funcprototype')
                        continue;

                if (isset($p->attributes['role'])) {
                        $role = $node->attributes['role'];
                } else {
                        $role = 'php';
                }

                $funcdef = $p->children[0];
                $rettype = "";
                $funcname = "";

                for ($i = 0; $i < count($funcdef->children); $i++) {
                        $k = $funcdef->children[$i];
                        switch($k->tagname) {
                                case '':
                                        $rettype = $k->content;
                                        break;
                                case 'function':
                                        $funcname = $k->content;
                                        break;
                        }
                }

                if ($rettype == '') {
                        $rettype = 'void';
                }


                $html .= "<div class=\"funcprototype\"><span 
class=\"type\">$rettype</span> <span class=\"function\">$funcname</span>";

                $params = "";
                $optclose = "";

                for ($i = 1; $i < count($p->children); $i++) {
                        $def = $p->children[$i];
                        if ($def->tagname != 'paramdef') {
                                continue;
                        }
                        $paramhtml = "";
                        $paramtype = "";
                        $param = null;

                        for ($j = 0; $j < count($def->children); $j++) {
                                $k = $def->children[$j];
                                switch($k->tagname) {
                                        case 'parameter':
                                                $param = $k;
                                                break;
                                        case 'enumname':
                                                $paramtype = "<span 
class=\"enumname\">{$k->content}</enumname>";
                                                break;
                                        case '':
                                                if (strlen($paramtype) == 0)
                                                        $paramtype = $k->content;
                                                break;
                                }
                        }
                        if ($paramtype == '') {
                                $paramtype = 'void';
                        }

                        if (count($param->children) > 1) {
                                $param = $param->children[1];
                                $optional = true;
                        } else {
                                $optional = false;
                        }
                        $paramname = trim($param->content);

                        if (strlen($params)) {
                                $paramhtml .= ',';
                        }
                        if ($optional) {
                                $paramhtml = '[' . $paramhtml;
                                $optclose .= ']';
                                if (strlen($params)) {
                                        $paramhtml = ' ' . $paramhtml;
                                }
                        }

                        if (strlen($paramhtml)) {
                                $paramhtml .= ' ';
                        }

                        $paramhtml .= '<span class=\"paramdef\"><span class=\"type\">' 
. $paramtype . '</span>';

                        switch ($role) {
                                case 'c':
                                        break;
                                default:
                                        if ($paramname && $paramname{0} == '&') {
                                                $paramname = '&$' . substr($paramname, 
1);
                                        } else {
                                                $paramname = '$' . $paramname;
                                        }
                        }

                        $paramhtml .= ' <span class=\"parameter\">' . $paramname . 
'</span></span>';

                        $params .= $paramhtml;
                }

                $html .= '(' . $params . $optclose . ")</div>";
        }

        return $html . "</div>";
}

Reply via email to