/** * builds and adds the common stuff to the CBaseElement that * is being generated: an icon, a label and the extraHTML * * @param CBaseElement $DOMitem the target CBaseElement * @param array $item the source generating item * * @access private */ private function buildCommon($DOMitem, $item) { // add the icon if (!is_null($item['icon'])) { $DOMitem->addChild($this->buildItemIcon($item)); } // add the label inside a span if (!is_null($item['label'])) { if (strpos($item['label'], 'template_field') === false) { // translate label directly if it's not a template field $label = translateFN($item['label']); } else { /** * label has some template field in it, let's translate word by word. * The preg_split will take a string like: * * edit <template_field class="template_field" name="what">what</template_field>some text <template_field class="template_field" name="whatxxx">whatxxx</template_field> some other text * * and produce an array like: * * array (size=8) * 0 => string 'edit' (length=4) * 1 => string '<template_field class="template_field" name="what">what</template_field>' (length=72) * 2 => string 'some' (length=4) * 3 => string 'text' (length=4) * 4 => string '<template_field class="template_field" name="whatxxx">whatxxx</template_field>' (length=78) * 5 => string 'some' (length=4) * 6 => string 'other' (length=5) * 7 => string 'text' (length=4) * * so that it's easy to translate word by word and then glue the * pieces together while keeping the template_field tags unmodified */ $splitted = preg_split('/(<template_field[^>]*>\\w*<\\/template_field>)|\\s+/', $item['label'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); // if splitted has only one element, it's the template field itself if (is_array($splitted) && count($splitted) > 1) { foreach ($splitted as $count => $word) { // if $word is a not template field, translate it if (strpos($item['label'], 'template_field') !== false) { $splitted[$count] = translateFN($word); } } } // glue splitted array and we're done $label = implode(' ', $splitted); } $span = CDOMElement::create('span', 'class:menulabel'); $span->addChild(new CText($label)); $DOMitem->addChild($span); } }