Frontend\Core\Engine\Header::addMetaData PHP Method

addMetaData() public method

Add meta data
public addMetaData ( array $attributes, boolean $overwrite = false, mixed $uniqueKeys = null, mixed $additionalKey = null )
$attributes array The attributes to parse.
$overwrite boolean Should we overwrite the current value?
$uniqueKeys mixed Which keys can we use to decide if an item is unique.
$additionalKey mixed This additional key helps you to create your own custom unique keys if required.
    public function addMetaData(array $attributes, $overwrite = false, $uniqueKeys = null, $additionalKey = null)
    {
        $overwrite = (bool) $overwrite;
        $uniqueKeys = (array) $uniqueKeys;
        if ($uniqueKeys == null) {
            $uniqueKeys = array('name');
        }
        // stop if the content is empty
        if (isset($attributes['content']) && $attributes['content'] == '') {
            return;
        }
        ksort($uniqueKeys);
        $uniqueKey = '';
        foreach ($uniqueKeys as $key) {
            if (isset($attributes[$key])) {
                $uniqueKey .= $attributes[$key] . '|';
            }
        }
        // Sometimes we want to add an extra key, because the uniqueKeys are not enough,
        // f.e.: when using multiple og:image:width meta elements
        if ($additionalKey !== null) {
            $uniqueKey .= $additionalKey;
        }
        // is the metadata already available?
        if (isset($this->meta[$uniqueKey])) {
            // should we overwrite the key?
            if ($overwrite) {
                $this->meta[$uniqueKey] = $attributes;
            } else {
                // some keys should be appended instead of ignored.
                if (in_array($uniqueKey, array('description|', 'keywords|', 'robots|'))) {
                    foreach ($attributes as $key => $value) {
                        if (isset($this->meta[$uniqueKey][$key]) && $key == 'content') {
                            $this->meta[$uniqueKey][$key] .= ', ' . $value;
                        } else {
                            $this->meta[$uniqueKey][$key] = $value;
                        }
                    }
                }
            }
        } else {
            $this->meta[$uniqueKey] = $attributes;
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Processes the page
  */
 protected function processPage()
 {
     // set pageTitle
     $this->header->setPageTitle($this->record['meta_title'], (bool) ($this->record['meta_title_overwrite'] == 'Y'));
     // set meta-data
     $this->header->addMetaDescription($this->record['meta_description'], (bool) ($this->record['meta_description_overwrite'] == 'Y'));
     $this->header->addMetaKeywords($this->record['meta_keywords'], $this->record['meta_keywords_overwrite'] == 'Y');
     $this->header->setMetaCustom($this->record['meta_custom']);
     // advanced SEO-attributes
     if (isset($this->record['meta_data']['seo_index'])) {
         $this->header->addMetaData(array('name' => 'robots', 'content' => $this->record['meta_data']['seo_index']));
     }
     if (isset($this->record['meta_data']['seo_follow'])) {
         $this->header->addMetaData(array('name' => 'robots', 'content' => $this->record['meta_data']['seo_follow']));
     }
     // create navigation instance
     new Navigation($this->getKernel());
     // assign content
     $pageInfo = Navigation::getPageInfo($this->record['id']);
     $this->record['has_children'] = $pageInfo['has_children'];
     $this->tpl->assign('page', $this->record);
     // set template path
     $this->templatePath = FRONTEND_PATH . '/' . $this->record['template_path'];
     // loop blocks
     foreach ($this->record['positions'] as $position => &$blocks) {
         // position not known in template = skip it
         if (!in_array($position, $this->record['template_data']['names'])) {
             continue;
         }
         // loop blocks in position
         foreach ($blocks as $index => &$block) {
             // an extra
             if ($block['extra_id'] !== null) {
                 // block
                 if ($block['extra_type'] == 'block') {
                     // create new instance
                     $extra = new FrontendBlockExtra($this->getKernel(), $block['extra_module'], $block['extra_action'], $block['extra_data']);
                     if (extension_loaded('newrelic')) {
                         newrelic_name_transaction($block['extra_module'] . '::' . $block['extra_action']);
                     }
                 } else {
                     // widget
                     $extra = new FrontendBlockWidget($this->getKernel(), $block['extra_module'], $block['extra_action'], $block['extra_data']);
                 }
                 // add to list of extras
                 $block = array('extra' => $extra);
                 // add to list of extras to parse
                 $this->extras[] = $extra;
             } else {
                 // the block only contains HTML
                 $block = array('blockIsEditor' => true, 'blockContent' => $block['html']);
                 // Maintain backwards compatibility
                 $block['blockIsHTML'] = $block['blockIsEditor'];
             }
         }
     }
 }
All Usage Examples Of Frontend\Core\Engine\Header::addMetaData