Пример #1
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 '';
 }
Пример #2
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;
 }
 /**
  * Function ensures that arrays are used for merging
  *
  * @param PPFrame $frame
  *
  * @return array
  */
 protected function getFrameParams(PPFrame $frame)
 {
     //we use both getNamedArguments and getArguments to ensure we acquire variables no matter what frame is used
     $namedArgs = $frame->getNamedArguments();
     $namedArgs = isset($namedArgs) ? is_array($namedArgs) ? $namedArgs : [$namedArgs] : [];
     $args = $frame->getArguments();
     $args = isset($args) ? is_array($args) ? $args : [$args] : [];
     return array_merge($namedArgs, $args);
 }