original_string: public function metadata($var = null)
      {
          if ($var !== null) {
              $this->metadata = (array)$var;
          }
  
          // if not metadata yet, process it.
          if (null === $this->metadata) {
              $header_tag_http_equivs = ['content-type', 'default-style', 'refresh', 'x-ua-compatible'];
  
              $this->metadata = [];
  
              $metadata = [];
              // Set the Generator tag
              $metadata['generator'] = 'GravCMS';
  
              // Get initial metadata for the page
              $metadata = array_merge($metadata, Grav::instance()['config']->get('site.metadata'));
  
              if (isset($this->header->metadata)) {
                  // Merge any site.metadata settings in with page metadata
                  $metadata = array_merge($metadata, $this->header->metadata);
              }
  
              // Build an array of meta objects..
              foreach ((array)$metadata as $key => $value) {
                  // Lowercase the key
                  $key = strtolower($key);
                  // If this is a property type metadata: "og", "twitter", "facebook" etc
                  // Backward compatibility for nested arrays in metas
                  if (is_array($value)) {
                      foreach ($value as $property => $prop_value) {
                          $prop_key = $key . ':' . $property;
                          $this->metadata[$prop_key] = [
                              'name' => $prop_key,
                              'property' => $prop_key,
                              'content' => htmlspecialchars($prop_value, ENT_QUOTES, 'UTF-8')
                          ];
                      }
                  } else {
                      // If it this is a standard meta data type
                      if ($value) {
                          if (\in_array($key, $header_tag_http_equivs, true)) {
                              $this->metadata[$key] = [
                                  'http_equiv' => $key,
                                  'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
                              ];
                          } elseif ($key === 'charset') {
                              $this->metadata[$key] = ['charset' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')];
                          } else {
                              // if it's a social metadata with separator, render as property
                              $separator = strpos($key, ':');
                              $hasSeparator = $separator && $separator < strlen($key) - 1;
                              $entry = [
                                  'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
                              ];
  
                              if ($hasSeparator && !Utils::startsWith($key, 'twitter')) {
                                  $entry['property'] = $key;
                              } else {
                                  $entry['name'] = $key;
                              }
  
                              $this->metadata[$key] = $entry;
                          }
                      }
                  }
              }
          }
  
          return $this->metadata;
      }
code: public function metadata($var = null)
      {
          if ($var !== null) {
              $this->metadata = (array)$var;
          }
  
          // if not metadata yet, process it.
          if (null === $this->metadata) {
              $header_tag_http_equivs = ['content-type', 'default-style', 'refresh', 'x-ua-compatible'];
  
              $this->metadata = [];
  
              $metadata = [];
              // Set the Generator tag
              $metadata['generator'] = 'GravCMS';
  
              // Get initial metadata for the page
              $metadata = array_merge($metadata, Grav::instance()['config']->get('site.metadata'));
  
              if (isset($this->header->metadata)) {
                  // Merge any site.metadata settings in with page metadata
                  $metadata = array_merge($metadata, $this->header->metadata);
              }
  
              // Build an array of meta objects..
              foreach ((array)$metadata as $key => $value) {
                  // Lowercase the key
                  $key = strtolower($key);
                  // If this is a property type metadata: "og", "twitter", "facebook" etc
                  // Backward compatibility for nested arrays in metas
                  if (is_array($value)) {
                      foreach ($value as $property => $prop_value) {
                          $prop_key = $key . ':' . $property;
                          $this->metadata[$prop_key] = [
                              'name' => $prop_key,
                              'property' => $prop_key,
                              'content' => htmlspecialchars($prop_value, ENT_QUOTES, 'UTF-8')
                          ];
                      }
                  } else {
                      // If it this is a standard meta data type
                      if ($value) {
                          if (\in_array($key, $header_tag_http_equivs, true)) {
                              $this->metadata[$key] = [
                                  'http_equiv' => $key,
                                  'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
                              ];
                          } elseif ($key === 'charset') {
                              $this->metadata[$key] = ['charset' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')];
                          } else {
                              // if it's a social metadata with separator, render as property
                              $separator = strpos($key, ':');
                              $hasSeparator = $separator && $separator < strlen($key) - 1;
                              $entry = [
                                  'content' => htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
                              ];
  
                              if ($hasSeparator && !Utils::startsWith($key, 'twitter')) {
                                  $entry['property'] = $key;
                              } else {
                                  $entry['name'] = $key;
                              }
  
                              $this->metadata[$key] = $entry;
                          }
                      }
                  }
              }
          }
  
          return $this->metadata;
      }
code_tokens: public function metadata ( $ var = null ) { if ( $ var !== null ) { $ this -> metadata = ( array ) $ var ; } // if not metadata yet, process it. if ( null === $ this -> metadata ) { $ header_tag_http_equivs = [ 'content-type' , 'default-style' , 'refresh' , 'x-ua-compatible' ] ; $ this -> metadata = [ ] ; $ metadata = [ ] ; // Set the Generator tag $ metadata [ 'generator' ] = 'GravCMS' ; // Get initial metadata for the page $ metadata = array_merge ( $ metadata , Grav :: instance ( ) [ 'config' ] -> get ( 'site.metadata' ) ) ; if ( isset ( $ this -> header -> metadata ) ) { // Merge any site.metadata settings in with page metadata $ metadata = array_merge ( $ metadata , $ this -> header -> metadata ) ; } // Build an array of meta objects.. foreach ( ( array ) $ metadata as $ key => $ value ) { // Lowercase the key $ key = strtolower ( $ key ) ; // If this is a property type metadata: "og", "twitter", "facebook" etc // Backward compatibility for nested arrays in metas if ( is_array ( $ value ) ) { foreach ( $ value as $ property => $ prop_value ) { $ prop_key = $ key . ':' . $ property ; $ this -> metadata [ $ prop_key ] = [ 'name' => $ prop_key , 'property' => $ prop_key , 'content' => htmlspecialchars ( $ prop_value , ENT_QUOTES , 'UTF-8' ) ] ; } } else { // If it this is a standard meta data type if ( $ value ) { if ( \ in_array ( $ key , $ header_tag_http_equivs , true ) ) { $ this -> metadata [ $ key ] = [ 'http_equiv' => $ key , 'content' => htmlspecialchars ( $ value , ENT_QUOTES , 'UTF-8' ) ] ; } elseif ( $ key === 'charset' ) { $ this -> metadata [ $ key ] = [ 'charset' => htmlspecialchars ( $ value , ENT_QUOTES , 'UTF-8' ) ] ; } else { // if it's a social metadata with separator, render as property $ separator = strpos ( $ key , ':' ) ; $ hasSeparator = $ separator && $ separator < strlen ( $ key ) - 1 ; $ entry = [ 'content' => htmlspecialchars ( $ value , ENT_QUOTES , 'UTF-8' ) ] ; if ( $ hasSeparator && ! Utils :: startsWith ( $ key , 'twitter' ) ) { $ entry [ 'property' ] = $ key ; } else { $ entry [ 'name' ] = $ key ; } $ this -> metadata [ $ key ] = $ entry ; } } } } } return $ this -> metadata ; }
docstring: Function to merge page metadata tags and build an array of Metadata objects
  that can then be rendered in the page.
  
  @param  array $var an Array of metadata values to set
  
  @return array      an Array of metadata values for the page
docstring_tokens: Function to merge page metadata tags and build an array of Metadata objects that can then be rendered in the page .