''); /** * This item's weight; used for sorting the output. * * @var float */ protected $weight = 0; /** * Constructor. */ function __construct(array $info, array $data = NULL) { $this->info = $info; if (isset($data)) { $this->data = $data; } } /** * Calculate the weight of this meta tag. * * @return int * Weight. */ function getWeight() { static $counter = 0; // If no weight value is found, stack this meta tag at the end. $weight = 100; if (!empty($this->info['weight'])) { $weight = $this->info['weight']; } return $weight + ($counter++ * 0.1); } /** * Build the form for this meta tag. * * @return array * A standard FormAPI array. */ public function getForm(array $options = array()) { return array(); } /** * Get the string value of this meta tag. * * @return string * The value of this meta tag. */ public function getValue(array $options = array()) { $value = $this->tidyValue($this->data['value']); // Translate the final output string prior to output. Use the // 'output' i18n_string object type, and pass along the meta tag's // options as the context so it can be handled appropriately. $value = metatag_translate_metatag($value, $this->info['name'], $options, NULL, TRUE); return $this->truncate($this->tidyValue($this->data['value'])); } /** * Get the HTML tag for this meta tag. * * @return array * A render array for this meta tag. */ public function getElement(array $options = array()) { $value = $this->getValue($options); if (strlen($value) === 0) { return array(); } // The stack of elements that will be output. $elements = array(); // Dynamically add each option to this setting. $base_element = isset($this->info['element']) ? $this->info['element'] : array(); // Single item. if (empty($this->info['multiple'])) { $values = array($value); } // Multiple items. else { $values = array_filter(explode(',', $value)); } // Loop over each item. if (!empty($values)) { foreach ($values as $ctr => $value) { $value = trim($value); // Some meta tags must be output as secure URLs. if (!empty($this->info['secure'])) { $value = str_replace('http://', 'https://', $value); } // Combine the base configuration for this meta tag with the value. $element = $base_element + array( '#theme' => 'metatag', '#tag' => 'meta', '#id' => 'metatag_' . $this->info['name'] . '_' . $ctr, '#name' => $this->info['name'], '#value' => $value, '#weight' => $this->getWeight(), ); // Add header information if desired. if (!empty($this->info['header'])) { $element['#attached']['drupal_add_http_header'][] = array($this->info['header'], $value); } $elements[] = array($element, $element['#id']); } } if (!empty($elements)) { return array( '#attached' => array('drupal_add_html_head' => $elements), ); } } /** * Remove unwanted formatting from a meta tag. * * @param string $value * The meta tag value to be tidied up. * * @return string * The meta tag value after it has been tidied up. */ public function tidyValue($value) { // This shouldn't happen, but protect against tokens returning arrays. if (!is_string($value)) { return ''; } // Check for Media strings from the WYSIWYG submodule. if (module_exists('media_wysiwyg') && strpos($value, '[[{') !== FALSE) { // In https://www.drupal.org/node/2129273 media_wysiwyg_filter() was // changed to require several additional arguments. $langcode = language_default('language'); $value = media_wysiwyg_filter($value, NULL, NULL, $langcode, NULL, NULL); } // Specifically replace encoded spaces, because some WYSIWYG editors are // silly. Do this before decoding the other HTML entities so that the output // doesn't end up with a bunch of a-circumflex characters. $value = str_replace(' ', ' ', $value); // Decode HTML entities. $value = decode_entities($value); // First off, remove the