function IncludeText($pagename, $inclspec) { global $MaxIncludes, $IncludeOpt, $InclCount; SDV($MaxIncludes, 50); SDVA($IncludeOpt, array('self' => 1)); $npat = '[[:alpha:]][-\\w]*'; if ($InclCount++ >= $MaxIncludes) { return Keep($inclspec); } $args = array_merge($IncludeOpt, ParseArgs($inclspec)); while (count($args['#']) > 0) { $k = array_shift($args['#']); $v = array_shift($args['#']); if ($k == '') { if ($v[0] != '#') { if (isset($itext)) { continue; } $iname = MakePageName($pagename, $v); if (!$args['self'] && $iname == $pagename) { continue; } $ipage = RetrieveAuthPage($iname, 'read', false, READPAGE_CURRENT); $itext = @$ipage['text']; } $itext = TextSection($itext, $v, array('anchors' => 1)); continue; } if (preg_match('/^(?:line|para)s?$/', $k)) { preg_match('/^(\\d*)(\\.\\.(\\d*))?$/', $v, $match); @(list($x, $a, $dots, $b) = $match); $upat = $k[0] == 'p' ? ".*?(\n\\s*\n|\$)" : "[^\n]*(?:\n|\$)"; if (!$dots) { $b = $a; $a = 0; } if ($a > 0) { $a--; } $itext = preg_replace("/^(({$upat}){0,{$b}}).*\$/s", '$1', $itext, 1); $itext = preg_replace("/^({$upat}){0,{$a}}/s", '', $itext, 1); continue; } } $basepage = isset($args['basepage']) ? MakePageName($pagename, $args['basepage']) : $iname; if ($basepage) { $itext = Qualify(@$basepage, @$itext); } return FmtTemplateVars(PVSE($itext), $args); }
function IncludeText($pagename, $inclspec) { global $MaxIncludes, $IncludeOpt, $InclCount, $PCache; SDV($MaxIncludes,50); SDVA($IncludeOpt, array('self'=>1)); if ($InclCount++>=$MaxIncludes) return Keep($inclspec); $args = array_merge($IncludeOpt, ParseArgs($inclspec)); while (count($args['#'])>0) { $k = array_shift($args['#']); $v = array_shift($args['#']); if ($k=='') { if ($v{0} != '#') { if (isset($itext)) continue; $iname = MakePageName($pagename, $v); if (!$args['self'] && $iname == $pagename) continue; $ipage = RetrieveAuthPage($iname, 'read', false, READPAGE_CURRENT); $itext = IsEnabled($PCache[$iname]['=preview'], @$ipage['text']); } $itext = TextSection($itext, $v, array('anchors' => 1)); continue; } if (preg_match('/^(?:line|para)s?$/', $k)) { preg_match('/^(\\d*)(\\.\\.(\\d*))?$/', $v, $match); @list($x, $a, $dots, $b) = $match; $upat = ($k{0} == 'p') ? ".*?(\n\\s*\n|$)" : "[^\n]*(?:\n|$)"; if (!$dots) { $b=$a; $a=0; } if ($a>0) $a--; $itext=preg_replace("/^(($upat){0,$b}).*$/s",'$1',$itext,1); $itext=preg_replace("/^($upat){0,$a}/s",'',$itext,1); continue; } } $basepage = isset($args['basepage']) ? MakePageName($pagename, $args['basepage']) : $iname; if ($basepage) $itext = Qualify(@$basepage, @$itext); return FmtTemplateVars(PVSE($itext), $args); }
function TETextRows($pagename, $source, $opt, &$par) { if ($source == $pagename) { return ''; } $page = ReadPage($source); if (!$page) { return ''; } $text = $page['text']; //use pagename#section if present if ($opt['section']) { $text = TextSection($text, $source . $opt['section']); } //skip page if it has an exclude match if ($opt['pat']['-'] != '') { foreach ($opt['-'] as $pat) { if (preg_match("({$pat})" . $par['qi'], $text)) { return; } } } //skip page if it has no match; all inclusive elements need to match (AND condition) foreach ($opt[''] as $pat) { if (!preg_match("({$pat})" . $par['qi'], $text)) { return; } } $text = Qualify($source, $text); $rows = explode("\n", rtrim($text)); //use range of lines if ($opt['lines'] != '') { $cnt = count($rows); if (strstr($opt['lines'], '..')) { preg_match_all("/\\d*/", $lines, $k); $a = $k[0][0]; $b = $k[0][3]; $c = $k[0][2]; if ($a && $b) { $rows = array_slice($rows, $a - 1, $b - $a + 1); } else { if ($a) { $rows = array_slice($rows, $a - 1); } else { if ($c) { $rows = array_slice($rows, 0, $c); } } } } else { if ($opt['lines'][0] == '-') { $rows = array_slice($rows, $opt['lines']); } else { $rows = array_slice($rows, 0, $opt['lines']); } } } //unit=para: combine rows to paragraph rows if ($opt['unit'] == 'para') { $paras = array(); $j = 0; foreach ($rows as $i => $row) { $row = rtrim($row); if ($row == '') { $j++; continue; } $paras[$j] .= $row . "\n"; } $rows = $paras; } //unit=page: combine rows to one row if ($opt['unit'] == 'page') { $part = implode("\n", $rows); $rows[0] = $part; } return $rows; }