コード例 #1
0
	public function testParameterWithEmptyNameShouldBeIgnoredButPreserved()
	{
		$somestring = '{{tempname|name=val1|=val2}}';
		$template = new POMTemplate( $somestring );
		$this->assertEquals( $somestring, $template->asString() );
	}
コード例 #2
0
 /**
  * Does the template mapping
  */
 private function doTemplateMapping(&$wikiText)
 {
     global $maps, $targetName;
     $pomPage = new POMPage($wikiText);
     $mappedAmount = 0;
     $sourceTemplate = '';
     $mappedTemplate = new POMTemplate('{{' . $targetName . '}}');
     // Go through all the template mappings and check if the linked templates are present in the page.
     foreach ($maps as $templateName => $mappings) {
         $templates = array_key_exists($templateName, $pomPage->templates) ? (array) $pomPage->templates[$templateName] : array();
         if (array_key_exists(strtolower($templateName), $pomPage->templates)) {
             $templates = (array) $pomPage->templates[strtolower($templateName)];
         }
         // Go through all instances of this template.
         while (count($templates) > 0) {
             // Go through all parameters of the template and map them to the new template.
             foreach ($templates[0]->parameters as $param) {
                 if (method_exists($param, 'getName')) {
                     $name = $param->getName();
                     $value = $param->getValue();
                     if (strlen(trim($value)) > 0) {
                         if (array_key_exists($name, $mappings)) {
                             $mappedTemplate->setParameter($mappings[$name], $value);
                         } else {
                             if (array_key_exists(strtolower($name), $mappings)) {
                                 $mappedTemplate->setParameter($mappings[strtolower($name)], $value);
                             }
                         }
                     }
                 }
             }
             if ($mappedAmount < 1) {
                 $sourceTemplate = $templates[0]->asString();
             } else {
                 $wikiText = str_replace($templates[0]->asString(), '', $wikiText);
             }
             $mappedAmount++;
             array_shift($templates);
         }
     }
     // Add an empty template call when not mappings have been done.
     if ($mappedAmount < 1) {
         $wikiText = '{{' . $targetName . '}}' . $wikiText;
     } else {
         // Replace the original template by the mapped one.
         $mappedWikiText = str_replace($sourceTemplate, $mappedTemplate->asString(true), $wikiText);
         if ($mappedWikiText != $wikiText) {
             $wikiText = $mappedWikiText;
         }
     }
 }