Пример #1
0
 function p_template(&$a, &$xml)
 {
     global $content_provider, $xmlg;
     if ($xmlg["useapi"]) {
         return false;
     }
     # API already resolved templates
     $x = "";
     $b = $a;
     if (!$this->nextis($b, "{{")) {
         return false;
     }
     #		if ( $this->nextis ( $b , "{" , false ) ) return false ; # Template names may not start with "{"
     if (!$this->p_internal_link_target($b, $x, "}}")) {
         return false;
     }
     $target = $x;
     $variables = array();
     $varnames = array();
     $vcount = 1;
     while (1) {
         if ($this->nextis($b, "}}")) {
             break;
         }
         if (!$this->nextis($b, "|")) {
             return false;
         }
         $l1 = strlen($x);
         if (!$this->p_internal_link_text($b, $x, false, "}}")) {
             return false;
         }
         $v = substr($x, $l1);
         $v = explode("=", $v);
         if (count($v) < 2) {
             $vk = $vcount;
         } else {
             $vk = trim(array_shift($v));
             $varnames[$vcount] = $vk;
         }
         $vv = array_shift($v);
         $variables[$vk] = $vv;
         if (!isset($variables[$vcount])) {
             $variables[$vcount] = $vv;
         }
         $vcount++;
     }
     $target = array_pop(@explode(">", $target, 2));
     $target = array_shift(@explode("<", $target, 2));
     if ($this->auto_fill_templates == 'all') {
         $replace_template = true;
     } else {
         if ($this->auto_fill_templates == 'none') {
             $replace_template = false;
         } else {
             $found = in_array(ucfirst($target), $this->template_list);
             if ($found and $this->auto_fill_templates == 'these') {
                 $replace_template = true;
             } else {
                 if (!$found and $this->auto_fill_templates == 'notthese') {
                     $replace_template = true;
                 } else {
                     $replace_template = false;
                 }
             }
         }
     }
     if (substr($target, 0, 1) == '#') {
         # Try template logic
         $between = $this->process_template_logic($target, $variables);
         # Change source (!)
         $w1 = substr($this->w, 0, $a);
         $w2 = substr($this->w, $b);
         $this->w = $w1 . $between . $w2;
         $this->wl = strlen($this->w);
     } else {
         if ($replace_template) {
             # Do not generate <template> sections, but rather replace the template call with the template text
             # Get template text
             $between = trim($content_provider->get_template_text($target));
             add_authors($content_provider->authors);
             # Removing <noinclude> stuff
             $between = preg_replace('?<noinclude>.*</noinclude>?msU', '', $between);
             $between = str_replace("<include>", "", $between);
             $between = str_replace("</include>", "", $between);
             $between = str_replace("<includeonly>", "", $between);
             $between = str_replace("</includeonly>", "", $between);
             # Remove HTML comments
             $between = str_replace("-->\n", "-->", $between);
             $between = preg_replace('?<!--.*-->?msU', '', $between);
             # Replacing template variables.
             # ATTENTION: Template variables within <nowiki> sections of templates will be replaced as well!
             if ($a > 0 && substr($between, 0, 2) == '{|') {
                 $between = "\n" . $between;
             }
             $this->replace_template_variables($between, $variables);
             # Change source (!)
             $w1 = substr($this->w, 0, $a);
             $w2 = substr($this->w, $b);
             $this->w = $w1 . $between . $w2;
             $this->wl = strlen($this->w);
         } else {
             $xml .= "<template><target>{$target}</target>";
             for ($i = 1; $i < $vcount; $i++) {
                 if (isset($varnames[$i])) {
                     $xml .= "<arg name=\"{$varnames[$i]}\">{$variables[$i]}</arg>";
                 } else {
                     $xml .= "<arg>{$variables[$i]}</arg>";
                 }
             }
             $xml .= "</template>";
             $a = $b;
         }
     }
     return true;
 }
Пример #2
0
     # set the first article name as the default title
     if ($xmlg["book_title"] == '') {
         $xmlg["book_title"] = $aArticles[0];
     }
     # as long as we have articles to convert (this might change in between!)
     while ($a = array_shift($aArticles)) {
         $wiki2xml_authors = array();
         # Article page|Article name
         $a = explode('|', $a);
         if (count($a) == 1) {
             $a[] = $a[0];
         }
         $title_page = trim(array_shift($a));
         $title_name = trim(array_pop($a));
         $wikitext = $content_provider->get_wiki_text($title_page);
         add_authors($content_provider->authors);
         append_to_xml($xml, $converter->article2xml($title_name, $wikitext, $xmlg, $aArticles));
         #$xml .= $converter->article2xml ( $title_name , $wikitext , $xmlg, &$aArticles ) ;
     }
 }
 $t = microtime_float() - $t;
 $tt = round($t, 3);
 $lt = round($content_provider->load_time, 3);
 $t = round($t - $lt, 3);
 $xmlg['xml_articles_header'] = "<articles xmlns:xhtml=\" \" loadtime='{$lt} sec' rendertime='{$t} sec' totaltime='{$tt} sec'>";
 # Output format
 if ($format == "xml") {
     header('Content-type: text/xml; charset=utf-8');
     print "<?xml version='1.0' encoding='UTF-8' ?>\n";
     print xml_articles_header();
     while ($x = xml_shift($xml)) {
Пример #3
0
function add_author($author)
{
    add_authors(array($author));
}