MetaSubtitle::ReadSubtitles PHP Метод

ReadSubtitles() публичный статический Метод

Reads the subtitles from the given content
public static ReadSubtitles ( string $p_content, $p_fieldName, string $p_firstSubtitle = '', $p_headerFormatStart = null, $p_headerFormatEnd = null ) : array
$p_content string
$p_firstSubtitle string
Результат array of MetaSubtitle
    public static function ReadSubtitles($p_content, $p_fieldName, $p_firstSubtitle = '', $p_headerFormatStart = null, $p_headerFormatEnd = null)
    {
        $result = preg_match_all('/(' . MetaSubtitle::GetFindPattern() . ')/i', $p_content, $subtitlesNames);
        $contentParts = preg_split('/' . MetaSubtitle::GetSplitPattern() . '/i', $p_content);
        $subtitlesContents = array();
        foreach ($contentParts as $index => $contentPart) {
            $name = $index > 0 ? $subtitlesNames[3][$index - 1] : $p_firstSubtitle;
            if (empty($p_headerFormatStart)) {
                $formatStart = $index > 0 ? $subtitlesNames[2][$index - 1] : '';
            } else {
                $formatStart = $p_headerFormatStart;
            }
            if (empty($p_headerFormatEnd)) {
                $formatEnd = $index > 0 ? $subtitlesNames[4][$index - 1] : '';
            } else {
                $formatEnd = $p_headerFormatEnd;
            }
            $subtitles[] = new MetaSubtitle($index, $p_fieldName, count($contentParts), $name, $contentPart, $formatStart, $formatEnd);
        }
        return $subtitles;
    }

Usage Example

 /**
  * Constructor
  *
  * @param string $p_content
  */
 public function __construct($p_content, MetaArticle $p_parent, $p_fieldName, $p_articleName, $p_subtitleNumber = null, $p_headerFormatStart = null, $p_headerFormatEnd = null)
 {
     $this->m_subtitleNumber = $p_subtitleNumber;
     $this->m_subtitles = MetaSubtitle::ReadSubtitles($p_content, $p_fieldName, $p_articleName, $p_headerFormatStart, $p_headerFormatEnd);
     $this->m_sutitlesNames = array();
     foreach ($this->m_subtitles as $subtitle) {
         $this->m_sutitlesNames[] = $subtitle->name;
     }
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKeyArticle = $cacheService->getCacheKey(array('Article', $p_parent->language->number, $p_parent->number), 'article');
     if ($cacheService->contains($cacheKeyArticle)) {
         $this->m_parent_article = $cacheService->fetch($cacheKeyArticle);
     } else {
         $this->m_parent_article = new Article($p_parent->language->number, $p_parent->number);
         $cacheService->save($cacheKeyArticle, $this->m_parent_article);
     }
     $this->m_fieldName = $p_fieldName;
     $cacheKey = $cacheService->getCacheKey(array('ArticleTypeField', $p_parent->type_name, $p_fieldName), 'article_type');
     if ($cacheService->contains($cacheKey)) {
         $this->m_articleTypeField = $cacheService->fetch($cacheKey);
     } else {
         $articleTypeField = new ArticleTypeField($p_parent->type_name, $p_fieldName);
         $cacheService->save($cacheKey, $articleTypeField);
         $this->m_articleTypeField = $articleTypeField;
     }
 }
All Usage Examples Of MetaSubtitle::ReadSubtitles