Example #1
0
 /**
  * Undo tokens of wikitex-templates. Normalize parametric templates.
  * @param $sortParams booleam to sort template-parameters, or array with initial params.
  */
 function wikitextTpl_untokenize($sortParams = TRUE, $close = TRUE, $VPARAM_SEP = ' | ')
 {
     $tpls =& $this->wikitext_tpls;
     $this->wikitext = preg_replace_callback('~#_tpl_#([a-z][\\w\\d_\\-]+)#(\\d+)##~is', function ($m) use(&$tpls, $sortParams, $VPARAM_SEP) {
         $idx = $m[2];
         if (isset($tpls[$idx])) {
             return MediawikiNavigor::wikitextTpl_untokenize1Tpl($tpls[$idx], $m[1], $sortParams, $VPARAM_SEP);
         } else {
             return '';
         }
     }, $this->wikitext);
     if ($close) {
         $this->wikitext_tpls = NULL;
     }
     // see
 }
// // END:ANALYSIS
// // // // // // //
// BEGIN:GENERATE NEW TPLs
print "\n----BEGIN:GENERATE NEW TPLs----\n";
foreach ($csv_rows as $pk => $v) {
    if ($pk != '#header' && !isset($wikitext_pk[$pk])) {
        $params = csv_rows_header2params($v, array('Ementa' => 'ementa', 'Ano' => 'kx_ano', 'Norma' => '#1', 'Tags' => 'tags', 'cod' => 'kx_cod', 'tipo' => 'kx_tipo'));
        if (isset($params['kx_ano'])) {
            if (!isset($params['#2'])) {
                $params['#2'] = $params['kx_ano'];
            }
            $tplName = 'norma';
            if (isset($params['prj']) && $params['prj'] || strpos($pk, 'PROJETO') !== FALSE) {
                $tplName = 'prjnorma';
            }
            print "\n\n" . $mn->wikitextTpl_untokenize1Tpl($params, $tplName, $MAIN_PARAMS);
        }
    }
}
print "\n----END:GENERATE NEW TPLs----\n";
// END:GENERATE NEW TPLs
$mn->wikitextTpl_untokenize($MAIN_PARAMS);
print $mn->wikitext;
if ($DEBUG) {
    print "\n---- de fora do wikitext ---\n";
    foreach ($csv_rows as $k => $v) {
        if ($k != '#header' && !isset($wikitext_pk[$k])) {
            print "\n* {$k} ";
        }
    }
}