Ejemplo n.º 1
0
 /**
  * Method for handling the declare parser function.
  * 
  * @since 1.5.3
  * 
  * @param Parser $parser
  * @param PPFrame $frame
  * @param array $args
  */
 public static function render(Parser &$parser, PPFrame $frame, array $args)
 {
     if ($frame->isTemplate()) {
         foreach ($args as $arg) {
             if (trim($arg) !== '') {
                 $expanded = trim($frame->expand($arg));
                 $parts = explode('=', $expanded, 2);
                 if (count($parts) == 1) {
                     $propertystring = $expanded;
                     $argumentname = $expanded;
                 } else {
                     $propertystring = $parts[0];
                     $argumentname = $parts[1];
                 }
                 $property = SMWPropertyValue::makeUserProperty($propertystring);
                 $argument = $frame->getArgument($argumentname);
                 $valuestring = $frame->expand($argument);
                 if ($property->isValid()) {
                     $type = $property->getPropertyTypeID();
                     if ($type == '_wpg') {
                         $matches = array();
                         preg_match_all('/\\[\\[([^\\[\\]]*)\\]\\]/u', $valuestring, $matches);
                         $objects = $matches[1];
                         if (count($objects) == 0) {
                             if (trim($valuestring) !== '') {
                                 SMWParseData::addProperty($propertystring, $valuestring, false, $parser, true);
                             }
                         } else {
                             foreach ($objects as $object) {
                                 SMWParseData::addProperty($propertystring, $object, false, $parser, true);
                             }
                         }
                     } elseif (trim($valuestring) !== '') {
                         SMWParseData::addProperty($propertystring, $valuestring, false, $parser, true);
                     }
                     // $value = SMWDataValueFactory::newPropertyObjectValue( $property->getDataItem(), $valuestring );
                     // if (!$value->isValid()) continue;
                 }
             }
         }
     } else {
         // @todo Save as metadata
     }
     global $wgTitle;
     if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return '';
 }
Ejemplo n.º 2
0
 /**
  * Triple brace replacement -- used for template arguments
  * @private
  *
  * @param array $piece
  * @param PPFrame $frame
  *
  * @return array
  */
 public function argSubstitution($piece, $frame)
 {
     $error = false;
     $parts = $piece['parts'];
     $nameWithSpaces = $frame->expand($piece['title']);
     $argName = trim($nameWithSpaces);
     $object = false;
     $text = $frame->getArgument($argName);
     if ($text === false && $parts->getLength() > 0 && ($this->ot['html'] || $this->ot['pre'] || $this->ot['wiki'] && $frame->isTemplate())) {
         # No match in frame, use the supplied default
         $object = $parts->item(0)->getChildren();
     }
     if (!$this->incrementIncludeSize('arg', strlen($text))) {
         $error = '<!-- WARNING: argument omitted, expansion size too large -->';
         $this->limitationWarn('post-expand-template-argument');
     }
     if ($text === false && $object === false) {
         # No match anywhere
         $object = $frame->virtualBracketedImplode('{{{', '|', '}}}', $nameWithSpaces, $parts);
     }
     if ($error !== false) {
         $text .= $error;
     }
     if ($object !== false) {
         $ret = array('object' => $object);
     } else {
         $ret = array('text' => $text);
     }
     return $ret;
 }
Ejemplo n.º 3
0
 /**
  * print an array.
  * foreach element of the array, print 'subject' where  all occurrences of 'search' is replaced with the element,
  * and each element print-out is deliminated by 'delimiter'
  * The subject can embed parser functions; wiki links; and templates.
  * usage:
  *      {{#arrayprint:arrayid|delimiter|search|subject|options}}
  * examples:
  *    {{#arrayprint:b}}    -- simple
  *    {{#arrayprint:b|<br/>}}    -- add change line
  *    {{#arrayprint:b|<br/>|@@@|[[@@@]]}}    -- embed wiki links
  *    {{#arrayprint:b|<br/>|@@@|{{#set:prop=@@@}} }}   -- embed parser function
  *    {{#arrayprint:b|<br/>|@@@|{{f.tag{{f.print.vbar}}prop{{f.print.vbar}}@@@}} }}   -- embed template function
  *    {{#arrayprint:b|<br/>|@@@|[[name::@@@]]}}   -- make SMW links
  */
 static function pfObj_arrayprint(Parser &$parser, PPFrame $frame, $args)
 {
     global $egArraysCompatibilityMode, $egArraysExpansionEscapeTemplates;
     // Get Parameters
     $arrayId = isset($args[0]) ? trim($frame->expand($args[0])) : '';
     $delimiter = isset($args[1]) ? trim($frame->expand($args[1])) : self::$mDefaultSep;
     /*
      * PPFrame::NO_ARGS and PPFrame::NO_TEMPLATES for expansion make a lot of sense here since the patterns getting replaced
      * in $subject before $subject is being parsed. So any template or argument influence in the patterns wouldn't make any
      * sense in any sane scenario.
      */
     $search = isset($args[2]) ? trim($frame->expand($args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES)) : null;
     $subject = isset($args[3]) ? trim($frame->expand($args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES)) : null;
     // options array:
     $options = isset($args[4]) ? self::parse_options($frame->expand($args[4])) : array();
     // get array, null if non-existant:
     $array = self::get($parser)->getArray($arrayId);
     if ($array === null) {
         // array we want to print doesn't exist!
         if (!$egArraysCompatibilityMode) {
             return '';
         } else {
             // COMPATIBILITY-MODE
             return "undefined array: {$arrayId}";
         }
     }
     // if there is no subject, there is no point in expanding. Faster!
     if ($subject === null) {
         if (!$egArraysCompatibilityMode && $egArraysExpansionEscapeTemplates !== null) {
             // we can ignore options here, since if subject is null, options won't be set as well!
             return trim(implode($delimiter, $array));
         } else {
             // COMPATIBILITY-MODE
             // set search and subject so the old routine can be done
             $search = $subject = '@@@@';
         }
     }
     $rendered_values = array();
     foreach ($array as $val) {
         if (!$egArraysCompatibilityMode) {
             // NO COMPATIBILITY-MODE
             /**
              * escape the array value so it won't destroy the users wiki markup expression.
              */
             $val = self::escapeForExpansion($val);
         }
         // replace place holder with current value:
         $rawResult = str_replace($search, $val, $subject);
         /*
          * $subjectd still is un-expanded (this allows to use some parser functions like
          * {{FULLPAGENAME:@@@@}} directly without getting parsed before @@@@ is replaced.
          * Expand it so we replace templates like {{!}} which we need for the final parse.
          */
         $rawResult = $parser->preprocessToDom($rawResult, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0);
         $rawResult = trim($frame->expand($rawResult));
         $rendered_values[] = $rawResult;
     }
     // follow special print options:
     switch (self::array_value($options, 'print')) {
         case 'pretty':
             // pretty list print with ' and ' connecting the last two items
             if ($delimiter === '') {
                 // '' as delimiter isn't pretty, so in this case we take the (languages) default
                 $output = self::arrayToText($rendered_values);
             } else {
                 $output = self::arrayToText($rendered_values, $delimiter);
             }
             break;
         default:
             // normal print with one delimiter, might be the languages default
             $output = implode($delimiter, $rendered_values);
             break;
     }
     if ($egArraysCompatibilityMode || $egArraysExpansionEscapeTemplates === null) {
         // COMPATIBLITY-MODE:
         /*
          * don't leave the final parse to Parser::braceSubstitution() since there are some special cases where it
          * would produce unexpected output (it uses a new child frame and ignores whether the frame is a template!)
          */
         $output = $parser->preprocessToDom($output, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0);
         $output = $frame->expand($output);
     }
     return trim($output);
 }
Ejemplo n.º 4
0
 /**
  * Generic function handling '#forargs' and '#fornumargs' as one
  */
 protected static function perform_forargs(Parser &$parser, PPFrame $frame, array $funcArgs, array $templateArgs, $prefix = '')
 {
     // if not called within template instance:
     if (!$frame->isTemplate()) {
         return '';
     }
     // name of the variable to store the argument name:
     $keyVar = array_shift($funcArgs);
     $keyVar = $keyVar !== null ? trim($frame->expand($keyVar)) : '';
     // name of the variable to store the argument value:
     $valVar = array_shift($funcArgs);
     $valVar = $valVar !== null ? trim($frame->expand($valVar)) : '';
     // unexpanded code:
     $rawCode = array_shift($funcArgs);
     $rawCode = $rawCode !== null ? $rawCode : '';
     $output = '';
     // if prefix contains numbers only or isn't set, get all arguments, otherwise just non-numeric
     $tArgs = preg_match('/^([1-9][0-9]*)?$/', $prefix) > 0 ? $frame->getArguments() : $frame->getNamedArguments();
     foreach ($templateArgs as $argName => $argVal) {
         // if no filter or prefix in argument name:
         if ($prefix !== '' && strpos($argName, $prefix) !== 0) {
             continue;
         }
         if ($keyVar !== $valVar) {
             // variable with the argument name without prefix as value:
             self::setVariable($parser, $keyVar, substr($argName, strlen($prefix)));
         }
         // variable with the arguments value:
         self::setVariable($parser, $valVar, $argVal);
         // expand current run:
         $output .= trim($frame->expand($rawCode));
     }
     return $output;
 }
Ejemplo n.º 5
0
 /**
  * Define an hash filled with all given parameters of the current template.
  * In case there are no parameters, the hash will be void.
  */
 static function pfObj_parameterstohash(&$parser, PPFrame $frame, $args)
 {
     if (!isset($args[0])) {
         return '';
     }
     $store = self::get($parser);
     $hashId = trim($frame->expand($args[0]));
     $store->setHash($hashId);
     // create empty hash table
     // in case the page is not used as template i.e. when displayed on its own
     if (!$frame->isTemplate()) {
         return '';
     }
     $templateArgs = $frame->getArguments();
     foreach ($templateArgs as $argName => $argVal) {
         // one hash value for each parameter
         $store->setHashValue($hashId, $argName, $argVal);
     }
     return '';
 }