public function parse()
{
// gets all the tags from the original template file
$pattern = '/<!\\*\\*\\s*([^>]+)>/';
$this->m_oldTags = $this->getAllTagsFromTemplate($pattern);
if ($this->m_oldTags == false || sizeof($this->m_oldTags) == 0) {
return false;
}
// sets the tags content (without delimeters)
$oldTagsContent = $this->m_oldTags[1];
// inits patterns and replacements arrays
$patternsArray = array();
$replacementsArray = array();
foreach ($oldTagsContent as $oldTagContent) {
// gets single words from tag content (options string)
$optArray = $this->parseOptionsString($oldTagContent);
// finds out new tag syntax based on given tag content
$newTagContent = $this->getNewTagContent($optArray, $oldTagContent);
if (is_null($newTagContent)) {
continue;
}
// sets pattern and replacement strings
$pattern = '/<!\\*\\*\\s*' . @preg_quote($oldTagContent) . '\\s*>/';
if ($newTagContent == 'DISCARD_SENTENCE') {
$replacement = '';
} else {
$replacement = CS_OPEN_TAG . ' ' . $newTagContent . ' ' . CS_CLOSE_TAG;
}
$patternsArray[] = $pattern;
$replacementsArray[] = $replacement;
}
// sets pattern and replacement for get_img script
$patternsArray[] = "/cgi-bin\\/get_img/";
$replacementsArray[] = "get_img.php";
// replaces all patterns with corresponding replacements
$this->m_templateContent = @preg_replace($patternsArray, $replacementsArray, $this->m_templateOriginalContent);
// replaces templates path properly
$pattern = '/\\/look\\/(.*?)[^"\']+/';
$oldTplTags = $this->getAllTagsFromTemplate($pattern);
if ($oldTplTags == false || sizeof($oldTplTags) == 0) {
return false;
}
foreach ($oldTplTags[0] as $oldTplTag) {
if (!empty($oldTplTag)) {
//$pattern = '/(.*?)[^\.tpl]$/';
$pattern = '/\\.tpl/';
preg_match($pattern, $oldTplTag, $m);
if (is_array($m) && !empty($m[0])) {
$replacement = '/tpl/';
} else {
$replacement = '/templates/';
}
$pattern = '/\\/look\\//';
$this->m_templateContent = @preg_replace($pattern, $replacement, $this->m_templateContent, 1);
}
}
return true;
}