public function getContent() { if ($this->getField('Content') == '') { $templatePath = SSViewer::getTemplateFileByType($this->Identifier, 'main'); if (file_exists($templatePath)) { $contents = file_get_contents($templatePath); return $contents; } } return $this->getField('Content'); }
/** * Extracts translatables from .ss templates (Self referencing) * * @param string $content The text content of a parsed template-file * @param string $module Module's name or 'themes' * @param string $fileName The name of a template file when method is used in self-referencing mode * @return array $entities An array of entities representing the extracted template function calls * * @todo Why the type juggling for $this->collectFromTemplate()? It always returns an array. */ public function collectFromTemplate($content, $fileName, $module, &$parsedFiles = array()) { $entities = array(); // Search for included templates preg_match_all('/<' . '% include +([A-Za-z0-9_]+) +%' . '>/', $content, $regs, PREG_SET_ORDER); foreach ($regs as $reg) { $includeName = $reg[1]; $includeFileName = "{$includeName}.ss"; $filePath = SSViewer::getTemplateFileByType($includeName, 'Includes'); if (!$filePath) { $filePath = SSViewer::getTemplateFileByType($includeName, 'main'); } if ($filePath && !in_array($filePath, $parsedFiles)) { $parsedFiles[] = $filePath; $includeContent = file_get_contents($filePath); $entities = array_merge($entities, (array) $this->collectFromTemplate($includeContent, $module, $includeFileName, $parsedFiles)); } // @todo Will get massively confused if you include the includer -> infinite loop } // use parser to extract <%t style translatable entities $translatables = i18nTextCollector_Parser::GetTranslatables($content); $entities = array_merge($entities, (array) $translatables); // use the old method of getting _t() style translatable entities // Collect in actual template if (preg_match_all('/(_t\\([^\\)]*?\\))/ms', $content, $matches)) { foreach ($matches[1] as $match) { $entities = array_merge($entities, $this->collectFromCode($match, $module)); } } foreach ($entities as $entity => $spec) { unset($entities[$entity]); $entities[$this->normalizeEntity($entity, $module)] = $spec; } ksort($entities); return $entities; }
public function collectFromTemplate($content, $module, $fileName) { $entitiesArr = array(); // Search for included templates preg_match_all('/<' . '% include +([A-Za-z0-9_]+) +%' . '>/', $content, $regs, PREG_SET_ORDER); foreach ($regs as $reg) { $includeName = $reg[1]; $includeFileName = "{$includeName}.ss"; $filePath = SSViewer::getTemplateFileByType($includeName, 'Includes'); if (!$filePath) { $filePath = SSViewer::getTemplateFileByType($includeName, 'main'); } if ($filePath) { $includeContent = file_get_contents($filePath); $entitiesArr = array_merge($entitiesArr, (array) $this->collectFromTemplate($includeContent, $module, $includeFileName)); } // @todo Will get massively confused if you include the includer -> infinite loop } // @todo respect template tags (< % _t() % > instead of _t()) $regexRule = '_t[[:space:]]*\\(' . '[[:space:]]*("[^"]*"|\\\'[^\']*\\\')[[:space:]]*,' . '[[:space:]]*(("([^"]|\\\\")*"|\'([^\']|\\\\\')*\')' . '([[:space:]]*\\.[[:space:]]*("([^"]|\\\\")*"|\'([^\']|\\\\\')*\'))*)' . '([[:space:]]*,[[:space:]]*[^,)]*)?([[:space:]]*,' . '[[:space:]]*("([^"]|\\\\")*"|\'([^\']|\\\\\')*\'))?[[:space:]]*' . '\\)'; while (ereg($regexRule, $content, $regs)) { $entitiesArr = array_merge($entitiesArr, (array) $this->entitySpecFromRegexMatches($regs, $fileName)); // remove parsed content to continue while() loop $content = str_replace($regs[0], "", $content); } ksort($entitiesArr); return $entitiesArr; }