/** * @param array $p_optArray */ private function parse($p_optArray) { if (isset($p_optArray[1]) && strtolower($p_optArray[1]) == 'not') { $condType = true; $idx = 2; } else { $condType = false; $idx = 1; } if (!isset($p_optArray[$idx])) { return; } $sentence = array_key_exists(strtolower($p_optArray[$idx]), $this->m_sentences) ? strtolower($p_optArray[$idx]) : ''; $object = array_key_exists(strtolower($p_optArray[$idx]), $this->m_objects) ? strtolower($p_optArray[$idx]) : ''; $ifBlockStr = ''; $openBracket = false; if (strlen($sentence) > 0) { $this->m_ifBlock = $sentence; if ($sentence == 'nextsubtitles' || $sentence == 'prevsubtitles') { if (TemplateConverterHelper::GetWithArticleType() != '') { $this->m_sentences[$sentence]['attribute'] = preg_replace('/#type_name#/', TemplateConverterHelper::GetWithArticleType(), $this->m_sentences[$sentence]['attribute']); } } elseif($sentence == 'currentsubtitle') { if (TemplateConverterHelper::GetWithBodyField() != '') { $this->m_sentences[$sentence]['condition'] = preg_replace('/#field_name#/', TemplateConverterHelper::GetWithBodyField(), $this->m_sentences[$sentence]['condition']); } } $ifBlockStr.= '->'.$this->m_sentences[$sentence]['new_object']; $ifBlockStr.= '->'.$this->m_sentences[$sentence]['attribute']; if (isset($this->m_sentences[$sentence]['condition'])) { $ifBlockStr.= $this->m_sentences[$sentence]['condition']; } $idx++; } if (strlen($object) > 0) { $objectIdx = $idx; $idx++; $attribute = (isset($p_optArray[$idx])) ? strtolower($p_optArray[$idx]) : ''; if ($attribute == 'fromstart') { $ifBlockStr.= '->default_'.$object.' == '.CS_OBJECT.'->'.$object; } else { if (array_key_exists($attribute, $this->m_objects[$object])) { if (is_array($this->m_objects[$object][$attribute])) { $ifBlockStr.= (isset($this->m_objects[$object][$attribute]['new_object'])) ? '->'.$this->m_objects[$object][$attribute]['new_object'] : '->'.$object; $ifBlockStr.= (isset($this->m_objects[$object][$attribute]['attribute'])) ? '->'.$this->m_objects[$object][$attribute]['attribute'] : '->'.$attribute; } else { $ifBlockStr.= '->'.$object.'->'.$attribute; } } else { if ($object == 'image' && is_numeric($attribute)) { $ifBlockStr.= '->article->has_image('.$attribute.')'; } else { $numElements = sizeof($p_optArray); if (isset($p_optArray[$numElements - 2]) && array_key_exists($p_optArray[$numElements - 2], $this->m_operators)) { $operatorIdx = $numElements - 2; if ($operatorIdx > $objectIdx) { $numIdentifiers = $operatorIdx - $objectIdx; if ($numIdentifiers == 3) { $type = $attribute; $attribute = $p_optArray[$idx+1]; $ifBlockStr.= '->'.$object.'->type->'.$type.'->'.$attribute; $idx++; } elseif ($numIdentifiers == 2) { $ifBlockStr.= '->'.$object.'->'.$attribute; } } } else { $ifBlockStr.= '->'.$object.'->'.$attribute; } } } } $idx++; // $operator = (isset($p_optArray[$idx]) && array_key_exists(strtolower($p_optArray[$idx]), $this->m_operators)) ? $this->m_operators[strtolower($p_optArray[$idx])] : ''; if (strlen($operator) > 0) { $ifBlockStr.= ' '.$operator; $idx++; } elseif ($object == 'list' && ($attribute == 'row' || $attribute == 'column' || $attribute == 'index')) { $p_optArray[$idx] = isset($p_optArray[$idx]) ? strtolower($p_optArray[$idx]) : ''; if (isset($p_optArray[$idx]) && ($p_optArray[$idx] == 'odd' || $p_optArray[$idx] == 'even')) { $ifBlockStr.= ' is '.$p_optArray[$idx]; $idx++; } elseif(isset($p_optArray[$idx])) { $ifBlockStr.= ' == '.$p_optArray[$idx++]; for ($i = $idx; $i < sizeof($p_optArray); $i++) { $ifBlockStr.= ' || '.CS_OBJECT.'->current_list->'.$attribute.' == '.$p_optArray[$i]; $idx++; } if ($condType == true) { $ifBlockStr.= ')'; $openBracket = true; } } } // $value = (isset($p_optArray[$idx])) ? $p_optArray[$idx] : null; if (isset($p_optArray[$idx])) { if (!empty($p_optArray[$idx])) { $value = $p_optArray[$idx]; } else { $value = '""'; } } if (!is_null($value)) { if ($value == '""') $value = ''; $value = (is_numeric($value)) ? $value : '"'.$value.'"'; $ifBlockStr.= (strlen($operator) <= 0) ? ' == '.$value : ' '.$value; $idx++; } } for ($x = $idx; $x < sizeof($p_optArray); $x++) { $ifBlockStr.= ' '.$p_optArray[$x]; } if (strlen($ifBlockStr) > 0) { $this->m_ifBlockStr = ($condType == true) ? 'if ! ' : 'if '; if ($openBracket == true) { $this->m_ifBlockStr.= '('; } $this->m_ifBlockStr.= CS_OBJECT . $ifBlockStr; } if (!empty($this->m_ifBlockStr)) { $this->m_endIfBlock = '/if'; } } // fn parse
/** * @param array $p_optArray */ private function getNewTagContent($p_optArray, $p_oldTagContent = null) { if (!is_array($p_optArray) || sizeof($p_optArray) < 1) { return; } $newTag = ''; $p_optArray[0] = strtolower($p_optArray[0]); if ($p_optArray[0] == 'list'|| $p_optArray[0] == 'foremptylist' || strpos($p_optArray[0], 'endlist') !== false) { $newTag = TemplateConverterListObject::GetNewTagContent($p_optArray); } elseif ($p_optArray[0] == 'if' || $p_optArray[0] == 'endif') { $newTag = TemplateConverterIfBlock::GetNewTagContent($p_optArray); } else { if (in_array($p_optArray[0], array('uri','uripath','url','urlparameters'))) { $newTag = TemplateConverterHelper::GetNewTagContent($p_optArray); } else { return TemplateConverterHelper::GetNewTagContent($p_optArray, $this->m_templateDirectory); } } if (strlen($newTag) > 0) { $pattern = '/<!\*\*\s*'.@preg_quote($p_oldTagContent).'\s*>/'; $replacement = CS_OPEN_TAG.' '.$newTag.' '.CS_CLOSE_TAG; $this->m_templateOriginalContent = @preg_replace($pattern, $replacement, $this->m_templateOriginalContent, 1); return null; } return false; } // fn getNewTagContent
/** * @param array $p_optArray * * @return string $newTag */ public static function BuildWithStatement($p_optArray) { if ($p_optArray[0] == 'with') { if (isset($p_optArray[1])) { self::$m_withArticleType = strtolower($p_optArray[1]); } if (isset($p_optArray[2])) { self::$m_withBodyField = strtolower($p_optArray[2]); } } elseif ($p_optArray[0] == 'endwith') { self::$m_withArticleType = ''; self::$m_withBodyField = ''; } $newTag = 'DISCARD_SENTENCE'; return $newTag; }