Ejemplo n.º 1
0
function Qualify($pagename, $text) {
  global $QualifyPatterns, $KeepToken, $KPV, $tmp_qualify;
  if (!@$QualifyPatterns) return $text;
  $text = MarkupEscape($text);
  $group = $tmp_qualify['group'] = PageVar($pagename, '$Group');
  $name  = $tmp_qualify['name']  = PageVar($pagename, '$Name');
  $tmp_qualify['pagename'] = $pagename;
  $text = PPRA((array)$QualifyPatterns, $text);
  return MarkupRestore($text);
}
Ejemplo n.º 2
0
function Qualify($pagename, $text) {
  global $QualifyPatterns, $KeepToken, $KPV;
  if (!@$QualifyPatterns) return $text;
  $text = MarkupEscape($text);
  $group = PageVar($pagename, '$Group');
  $name = PageVar($pagename, '$Name');
  foreach((array)$QualifyPatterns as $pat => $rep) 
    $text = preg_replace($pat, $rep, $text);
  return MarkupRestore($text);
}
Ejemplo n.º 3
0
function FPLTemplate($pagename, &$matches, $opt)
{
    global $Cursor, $FPLTemplatePageFmt, $RASPageName, $PageListArgPattern;
    SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates'));
    StopWatch("FPLTemplate begin");
    $template = @$opt['template'];
    if (!$template) {
        $template = @$opt['fmt'];
    }
    $ttext = RetrieveAuthSection($pagename, $template, $FPLTemplatePageFmt);
    $ttext = PVSE(Qualify($RASPageName, $ttext));
    ##  save any escapes
    $ttext = MarkupEscape($ttext);
    ##  remove any anchor markups to avoid duplications
    $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext);
    ##  extract portions of template
    $tparts = preg_split('/\\(:(template)\\s+(\\w+)\\s*(.*?):\\)/i', $ttext, -1, PREG_SPLIT_DELIM_CAPTURE);
    ##  handle (:template defaults:)
    $i = 0;
    while ($i < count($tparts)) {
        if ($tparts[$i] != 'template') {
            $i++;
            continue;
        }
        if ($tparts[$i + 1] != 'defaults' && $tparts[$i + 1] != 'default') {
            $i += 4;
            continue;
        }
        $opt = array_merge(ParseArgs($tparts[$i + 2], $PageListArgPattern), $opt);
        array_splice($tparts, $i, 3);
    }
    SDVA($opt, array('class' => 'fpltemplate', 'wrap' => 'div'));
    ##  get the list of pages
    $matches = array_values(MakePageList($pagename, $opt, 0));
    ##  extract page subset according to 'count=' parameter
    if (@$opt['count']) {
        list($r0, $r1) = CalcRange($opt['count'], count($matches));
        if ($r1 < $r0) {
            $matches = array_reverse(array_slice($matches, $r1 - 1, $r0 - $r1 + 1));
        } else {
            $matches = array_slice($matches, $r0 - 1, $r1 - $r0 + 1);
        }
    }
    $savecursor = $Cursor;
    $pagecount = 0;
    $groupcount = 0;
    $grouppagecount = 0;
    $pseudovars = array('{$$PageCount}' => &$pagecount, '{$$GroupCount}' => &$groupcount, '{$$GroupPageCount}' => &$grouppagecount);
    foreach (preg_grep('/^[\\w$]/', array_keys($opt)) as $k) {
        if (!is_array($opt[$k])) {
            $pseudovars["{\$\${$k}}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES);
        }
    }
    $vk = array_keys($pseudovars);
    $vv = array_values($pseudovars);
    $lgroup = '';
    $out = '';
    foreach ($matches as $i => $pn) {
        $group = PageVar($pn, '$Group');
        if ($group != $lgroup) {
            $groupcount++;
            $grouppagecount = 0;
            $lgroup = $group;
        }
        $grouppagecount++;
        $pagecount++;
        $t = 0;
        while ($t < count($tparts)) {
            if ($tparts[$t] != 'template') {
                $item = $tparts[$t];
                $t++;
            } else {
                list($when, $control, $item) = array_slice($tparts, $t + 1, 3);
                $t += 4;
                if (!$control) {
                    if ($when == 'first' && $i != 0) {
                        continue;
                    }
                    if ($when == 'last' && $i != count($matches) - 1) {
                        continue;
                    }
                } else {
                    if ($when == 'first' || !isset($last[$t])) {
                        $Cursor['<'] = $Cursor['&lt;'] = (string) @$matches[$i - 1];
                        $Cursor['='] = $pn;
                        $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 1];
                        $curr = str_replace($vk, $vv, $control);
                        $curr = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $curr);
                        if ($when == 'first' && $i > 0 && $last[$t] == $curr) {
                            continue;
                        }
                        $last[$t] = $curr;
                    }
                    if ($when == 'last') {
                        $Cursor['<'] = $Cursor['&lt;'] = $pn;
                        $Cursor['='] = (string) @$matches[$i + 1];
                        $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 2];
                        $next = str_replace($vk, $vv, $control);
                        $next = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $next);
                        if ($next == $last[$t] && $i != count($matches) - 1) {
                            continue;
                        }
                        $last[$t] = $next;
                    }
                }
            }
            $Cursor['<'] = $Cursor['&lt;'] = (string) @$matches[$i - 1];
            $Cursor['='] = $pn;
            $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 1];
            $item = str_replace($vk, $vv, $item);
            $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PVSE(PageVar(\$pn, '\$2', '\$1'))", $item);
            $out .= MarkupRestore($item);
        }
    }
    $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']);
    if ($class) {
        $class = " class='{$class}'";
    }
    $wrap = @$opt['wrap'];
    if ($wrap != 'inline') {
        $out = MarkupToHTML($pagename, $out, array('escape' => 0, 'redirect' => 1));
        if ($wrap != 'none') {
            $out = "<div{$class}>{$out}</div>";
        }
    }
    $Cursor = $savecursor;
    StopWatch("FPLTemplate end");
    return $out;
}
Ejemplo n.º 4
0
function FPLTemplateFormat($pagename, $matches, $opt, $tparts, &$output){
  global $Cursor, $FPLTemplateMarkupFunction;
  SDV($FPLTemplateMarkupFunction, 'MarkupToHTML');
  $savecursor = $Cursor;
  $pagecount = 0; $groupcount = 0; $grouppagecount = 0;
  $pseudovars = array('{$$PageCount}' => &$pagecount, 
                      '{$$GroupCount}' => &$groupcount, 
                      '{$$GroupPageCount}' => &$grouppagecount);

  foreach(preg_grep('/^[\\w$]/', array_keys($opt)) as $k) 
    if (!is_array($opt[$k]))
      $pseudovars["{\$\$$k}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES);

  $vk = array_keys($pseudovars);
  $vv = array_values($pseudovars);

  $lgroup = ''; $out = '';
  if(count($matches)==0 )
  {
    $t = 0;
    while($t < count($tparts))
    {
      if($tparts[$t]=='template' && $tparts[$t+2]=='none')
      {
         $out .= MarkupRestore( FPLExpandItemVars($tparts[$t+4], $matches, 0, $pseudovars));
         $t+=4;
      }
      $t++;
    }
  } # else:
  foreach($matches as $i => $pn) {
    $group = PageVar($pn, '$Group');
    if ($group != $lgroup) { $groupcount++; $grouppagecount = 0; $lgroup = $group; }
    $grouppagecount++; $pagecount++;

    $t = 0;
    while ($t < count($tparts)) {
      if ($tparts[$t] != 'template') { $item = $tparts[$t]; $t++; }
      else {
        list($neg, $when, $control, $item) = array_slice($tparts, $t+1, 4); $t+=5;
        if($when=='none') continue;
        if (!$control) {
          if ($when == 'first' && ($neg xor ($i != 0))) continue;
          if ($when == 'last' && ($neg xor ($i != count($matches) - 1))) continue;
        } else {
          if ($when == 'first' || !isset($last[$t])) {
            $curr = FPLExpandItemVars($control, $matches, $i, $pseudovars);
            if ($when == 'first' && ($neg xor (($i != 0) && ($last[$t] == $curr))))
              { $last[$t] = $curr; continue; }
            $last[$t] = $curr;
          }
          if ($when == 'last') {
            $next = FPLExpandItemVars($control, $matches, $i+1, $pseudovars);
            if ($neg xor ($next == $last[$t] && $i != count($matches) - 1)) continue;
            $last[$t] = $next;
          }
        }
      }
      $item = FPLExpandItemVars($item, $matches, $i, $pseudovars);
      $out .= MarkupRestore($item);
    }
  }

  $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']);
  if ($class) $class = " class='$class'";
  $wrap = @$opt['wrap'];
  if ($wrap != 'inline') {
    $out = $FPLTemplateMarkupFunction($pagename, $out, array('escape' => 0, 'redirect'=>1));
    if ($wrap != 'none') $out = "<div$class>$out</div>";
  }
  $Cursor = $savecursor;
  $output .= $out;
}
Ejemplo n.º 5
0
function FPLTemplateFormat($pagename, $matches, $opt, $tparts, &$output)
{
    global $Cursor, $FPLTemplateMarkupFunction;
    SDV($FPLTemplateMarkupFunction, 'MarkupToHTML');
    $savecursor = $Cursor;
    $pagecount = 0;
    $groupcount = 0;
    $grouppagecount = 0;
    $pseudovars = array('{$$PageCount}' => &$pagecount, '{$$GroupCount}' => &$groupcount, '{$$GroupPageCount}' => &$grouppagecount);
    foreach (preg_grep('/^[\\w$]/', array_keys($opt)) as $k) {
        if (!is_array($opt[$k])) {
            $pseudovars["{\$\${$k}}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES);
        }
    }
    $vk = array_keys($pseudovars);
    $vv = array_values($pseudovars);
    $lgroup = '';
    $out = '';
    if (count($matches) == 0) {
        $t = 0;
        while ($t < count($tparts)) {
            if ($tparts[$t] == 'template' && $tparts[$t + 1] == 'none') {
                $out .= MarkupRestore($tparts[$t + 3]);
                $t += 3;
            }
            $t++;
        }
    }
    # else:
    foreach ($matches as $i => $pn) {
        $group = PageVar($pn, '$Group');
        if ($group != $lgroup) {
            $groupcount++;
            $grouppagecount = 0;
            $lgroup = $group;
        }
        $grouppagecount++;
        $pagecount++;
        $t = 0;
        while ($t < count($tparts)) {
            if ($tparts[$t] != 'template') {
                $item = $tparts[$t];
                $t++;
            } else {
                list($when, $control, $item) = array_slice($tparts, $t + 1, 3);
                $t += 4;
                if ($when == 'none') {
                    continue;
                }
                if (!$control) {
                    if ($when == 'first' && $i != 0) {
                        continue;
                    }
                    if ($when == 'last' && $i != count($matches) - 1) {
                        continue;
                    }
                } else {
                    if ($when == 'first' || !isset($last[$t])) {
                        $Cursor['<'] = $Cursor['&lt;'] = (string) @$matches[$i - 1];
                        $Cursor['='] = $pn;
                        $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 1];
                        $curr = str_replace($vk, $vv, $control);
                        $curr = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $curr);
                        if ($when == 'first' && $i > 0 && $last[$t] == $curr) {
                            continue;
                        }
                        $last[$t] = $curr;
                    }
                    if ($when == 'last') {
                        $Cursor['<'] = $Cursor['&lt;'] = $pn;
                        $Cursor['='] = (string) @$matches[$i + 1];
                        $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 2];
                        $next = str_replace($vk, $vv, $control);
                        $next = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PageVar(\$pn, '\$2', '\$1')", $next);
                        if ($next == $last[$t] && $i != count($matches) - 1) {
                            continue;
                        }
                        $last[$t] = $next;
                    }
                }
            }
            $Cursor['<'] = $Cursor['&lt;'] = (string) @$matches[$i - 1];
            $Cursor['='] = $pn;
            $Cursor['>'] = $Cursor['&gt;'] = (string) @$matches[$i + 1];
            $item = str_replace($vk, $vv, $item);
            $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PVSE(PageVar(\$pn, '\$2', '\$1'))", $item);
            $out .= MarkupRestore($item);
        }
    }
    $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']);
    if ($class) {
        $class = " class='{$class}'";
    }
    $wrap = @$opt['wrap'];
    if ($wrap != 'inline') {
        $out = $FPLTemplateMarkupFunction($pagename, $out, array('escape' => 0, 'redirect' => 1));
        if ($wrap != 'none') {
            $out = "<div{$class}>{$out}</div>";
        }
    }
    $Cursor = $savecursor;
    $output .= $out;
}
Ejemplo n.º 6
0
function FPLTemplate($pagename, &$matches, $opt)
{
    global $Cursor, $FPLFormatOpt, $FPLTemplatePageFmt;
    SDV($FPLTemplatePageFmt, array('{$FullName}', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates'));
    StopWatch("FPLTemplate begin");
    $template = @$opt['template'];
    if (!$template) {
        $template = @$opt['fmt'];
    }
    list($tname, $qf) = explode('#', $template, 2);
    if ($tname) {
        $tname = array(MakePageName($pagename, $tname));
    } else {
        $tname = (array) $FPLTemplatePageFmt;
    }
    foreach ($tname as $t) {
        $t = FmtPageName($t, $pagename);
        if (!PageExists($t)) {
            continue;
        }
        if ($qf) {
            $t .= "#{$qf}";
        }
        $ttext = IncludeText($pagename, $t, true);
        if (!$qf || strpos($ttext, "[[#{$qf}]]") !== false) {
            break;
        }
    }
    ##   remove any anchor markups to avoid duplications
    $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext);
    ##   save any escapes
    $ttext = MarkupEscape($ttext);
    $matches = array_values(MakePageList($pagename, $opt, 0));
    if (@$opt['count']) {
        array_splice($matches, $opt['count']);
    }
    $savecursor = $Cursor;
    $pagecount = 0;
    $groupcount = 0;
    $grouppagecount = 0;
    $pseudovars = array('{$$PageCount}' => &$pagecount, '{$$GroupCount}' => &$groupcount, '{$$GroupPageCount}' => &$grouppagecount);
    foreach (preg_grep('/^[\\w$]/', array_keys($opt)) as $k) {
        if (!is_array($opt[$k])) {
            $pseudovars["{\$\${$k}}"] = htmlspecialchars($opt[$k], ENT_NOQUOTES);
        }
    }
    $vk = array_keys($pseudovars);
    $vv = array_values($pseudovars);
    $lgroup = '';
    $out = '';
    foreach ($matches as $i => $pn) {
        $prev = (string) @$matches[$i - 1];
        $next = (string) @$matches[$i + 1];
        $Cursor['<'] = $Cursor['&lt;'] = $prev;
        $Cursor['='] = $pn;
        $Cursor['>'] = $Cursor['&gt;'] = $next;
        $group = PageVar($pn, '$Group');
        if ($group != $lgroup) {
            $groupcount++;
            $grouppagecount = 0;
        }
        $grouppagecount++;
        $pagecount++;
        $item = str_replace($vk, $vv, $ttext);
        $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e', "PVSE(PageVar(\$pn, '\$2', '\$1'))", $item);
        $out .= MarkupRestore($item);
        $lgroup = $group;
    }
    $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']);
    $div = $class ? "<div class='{$class}'>" : '<div>';
    $out = $div . MarkupToHTML($pagename, $out, array('escape' => 0)) . '</div>';
    StopWatch("FPLTemplate end");
    return $out;
}
Ejemplo n.º 7
0
function InputToHTML($pagename, $type, $args, &$opt) {
  global $InputTags, $InputAttrs, $InputValues, $FmtV, $KeepToken,
    $InputFocusLevel, $InputFocusId, $InputFocusFmt, $HTMLFooterFmt;
  if (!@$InputTags[$type]) return "(:input $type $args:)";
  ##  get input arguments
  if (!is_array($args)) $args = ParseArgs($args);
  ##  convert any positional arguments to named arguments
  $posnames = @$InputTags[$type][':args'];
  if (!$posnames) $posnames = array('name', 'value');
  while (count($posnames) > 0 && count(@$args['']) > 0) {
    $n = array_shift($posnames);
    if (!isset($args[$n])) $args[$n] = array_shift($args['']);
  }
  ##  merge defaults for input type with arguments
  $opt = array_merge($InputTags[$type], $args);
  ## www.w3.org/TR/html4/types
  if(isset($opt['id'])) $opt['id'] = preg_replace('/[^-A-Za-z0-9:_.]+/', '_', $opt['id']);
  ##  convert any remaining positional args to flags
  foreach ((array)@$opt[''] as $a) 
    { $a = strtolower($a); if (!isset($opt[$a])) $opt[$a] = $a; }
  if (isset($opt['name'])) {
    $opt['name'] = preg_replace('/^\\$:/', 'ptv_', @$opt['name']);
    $opt['name'] = preg_replace('/[^-A-Za-z0-9:_.\\[\\]]+/', '_', $opt['name']);
    $name = $opt['name'];
    ##  set control values from $InputValues array
    ##  radio, checkbox, select, etc. require a flag of some sort,
    ##  others just set 'value'
    if (isset($InputValues[$name])) {
      $checked = @$opt[':checked'];
      if ($checked) {
        $opt[$checked] = in_array(@$opt['value'], (array)$InputValues[$name])
                         ? $checked : false;
      } else if (!isset($opt['value'])) $opt['value'] = $InputValues[$name];
    }
  }
  ##  build $InputFormContent
  $FmtV['$InputFormContent'] = '';
  foreach((array)@$opt[':content'] as $a)
    if (isset($opt[$a])) { $FmtV['$InputFormContent'] = $opt[$a]; break; }
  ##  hash and store any "secure" values
  if (@$opt['secure'] == '#') $opt['secure'] = rand();
  if (@$opt['secure'] > '') {
    $md5 = md5($opt['secure'] . $opt['value']);
    @session_start(); 
    $_SESSION['forms'][$md5] = $opt['value'];
    $opt['value'] = $md5;
  }
  ##  handle focus=# option
  $focus = @$opt['focus'];
  if (isset($focus)
      && (!isset($InputFocusLevel) || $focus < $InputFocusLevel)) {
    if (!isset($opt['id'])) $opt['id'] = "wikifocus$focus";
    $InputFocusLevel = $focus;
    $InputFocusId = $opt['id'];
    $HTMLFooterFmt['inputfocus'] = $InputFocusFmt;
  }
  ##  build $InputFormArgs from $opt
  $attrlist = (isset($opt[':attr'])) ? $opt[':attr'] : $InputAttrs;
  $attr = array();
  foreach ($attrlist as $a) {
    if (!isset($opt[$a]) || $opt[$a]===false) continue;
    if(strpos($opt[$a], $KeepToken)!== false) # multiline textarea/hidden fields
      $opt[$a] = Keep(str_replace("'", '&#39;', MarkupRestore($opt[$a]) ));
    $attr[] = "$a='".str_replace("'", '&#39;', $opt[$a])."'";
  }
  $FmtV['$InputFormArgs'] = implode(' ', $attr);
  return FmtPageName($opt[':html'], $pagename);
}
Ejemplo n.º 8
0
function ReplaceOnSave($pagename,&$page,&$new) {
  global $EnablePost, $ROSPatterns, $ROEPatterns, $EnableROSEscape;
  $t = $new['text'];
  if (IsEnabled($EnableROSEscape, 0)) $t = MarkupEscape($t);
  $t = PPRA((array)@$ROEPatterns, $t);
  if ($EnablePost) {
    $t = PPRA((array)@$ROSPatterns, $t);
  }
  if (IsEnabled($EnableROSEscape, 0)) $t = MarkupRestore($t);
  $new['=preview'] = $new['text'] = $t;
  PCache($pagename, $new);
}
Ejemplo n.º 9
0
function FPLTemplate($pagename, &$matches, $opt) {
  global $Cursor, $FPLFormatOpt, $FPLTemplatePageFmt;
  SDV($FPLTemplatePageFmt, array('{$FullName}',
    '{$SiteGroup}.LocalTemplates','{$SiteGroup}.PageListTemplates'));

  $template = @$opt['template'];
  if (!$template) $template = @$opt['fmt'];

  list($tname, $qf) = explode('#', $template, 2);
  if ($tname) $tname = array(MakePageName($pagename, $tname));
  else $tname = (array)$FPLTemplatePageFmt;
  foreach ($tname as $t) {
    $t = FmtPageName($t, $pagename);
    if (!PageExists($t)) continue;
    if ($qf) $t .= "#$qf";
    $ttext = IncludeText($pagename, $t, true);
    if (!$qf || strpos($ttext, "[[#$qf]]") !== false) break;
  }

  ##   remove any anchor markups to avoid duplications
  $ttext = preg_replace('/\\[\\[#[A-Za-z][-.:\\w]*\\]\\]/', '', $ttext);

  if (!@$opt['order'] && !@$opt['trail']) $opt['order'] = 'name';
  $matches = array_values(MakePageList($pagename, $opt, 0));
  if (@$opt['count']) array_splice($matches, $opt['count']);

  $savecursor = $Cursor;
  $pagecount = 0; $groupcount = 0; $grouppagecount = 0;
  $vk = array('{$PageCount}', '{$GroupCount}', '{$GroupPageCount}');
  $vv = array(&$pagecount, &$groupcount, &$grouppagecount);

  $lgroup = ''; $out = '';
  foreach($matches as $i => $pn) {
    $prev = (string)@$matches[$i-1];
    $next = (string)@$matches[$i+1];
    $Cursor['<'] = $Cursor['&lt;'] = $prev;
    $Cursor['='] = $pn;
    $Cursor['>'] = $Cursor['&gt;'] = $next;
    $group = PageVar($pn, '$Group');
    if ($group != $lgroup) { $groupcount++; $grouppagecount = 0; }
    $grouppagecount++; $pagecount++;

    $item = str_replace($vk, $vv, MarkupEscape($ttext));
    $item = preg_replace('/\\{(=|&[lg]t;)(\\$:?\\w+)\\}/e',
                "PageVar(\$pn, '$2', '$1')", $item);
    $out .= MarkupRestore($item);
    $lgroup = $group;
  }
  $class = preg_replace('/[^-a-zA-Z0-9\\x80-\\xff]/', ' ', @$opt['class']);
  $div = ($class) ? "<div class='$class'>" : '<div>';
  return $div.MarkupToHTML($pagename, $out, array('escape' => 0)).'</div>';
}