You are here

nodewords_basic.module in Nodewords: D6 Meta Tags 6

Define basic meta tags for Drupal pages.

File

nodewords_basic/nodewords_basic.module
View source
<?php

/**
 * @file
 * Define basic meta tags for Drupal pages.
 */

/**
 * Implements hook_nodewords_api().
 */
function nodewords_basic_nodewords_api() {
  return array(
    'version' => '1.14',
  );
}

/**
 * Implements hook_nodewords_tags_info().
 */
function nodewords_basic_nodewords_tags_info() {
  $tags = array(
    'logo' => array(
      'attributes' => array(
        'logo' => array(
          'type' => 'image/svg',
        ),
      ),
      'callback' => 'nodewords_basic_logo',
      'context' => array(
        'allowed' => array(
          NODEWORDS_TYPE_DEFAULT,
        ),
      ),
      'label' => t('Logo'),
      'permission' => 'edit meta tag LOGO',
      'templates' => array(
        'head' => array(
          'logo' => NODEWORDS_LINK_REL,
        ),
      ),
      'weight' => array(
        'logo' => -206,
      ),
    ),
    'page_title' => array(
      'callback' => 'nodewords_basic_title',
      'context' => array(
        'denied' => array(
          NODEWORDS_TYPE_DEFAULT,
        ),
      ),
      'label' => t('Page title'),
      'permission' => 'edit meta tag PAGE TITLE',
      'weight' => array(
        'page_title' => -199,
      ),
    ),
    'description' => array(
      'callback' => 'nodewords_basic_description',
      'label' => t('Description'),
      'permission' => 'edit meta tag DESCRIPTION',
      'templates' => array(
        'head' => array(
          'description' => NODEWORDS_META,
        ),
        'search index' => array(
          'description' => '<h3>%content</h3>',
        ),
      ),
      'weight' => array(
        'description' => -179,
      ),
    ),
    'author' => array(
      'callback' => 'nodewords_basic_author',
      'label' => t('Author'),
      'permission' => 'edit meta tag AUTHOR',
      'templates' => array(
        'head' => array(
          'author' => NODEWORDS_LINK_REL,
        ),
      ),
      'weight' => array(
        'author' => -186,
      ),
    ),
    'abstract' => array(
      'callback' => 'nodewords_basic_abstract',
      'label' => t('Abstract'),
      'permission' => 'edit meta tag ABSTRACT',
      'templates' => array(
        'head' => array(
          'abstract' => NODEWORDS_META,
        ),
      ),
      'weight' => array(
        'abstract' => -186,
      ),
    ),
    'keywords' => array(
      'callback' => 'nodewords_basic_keywords',
      'label' => t('Keywords'),
      'permission' => 'edit meta tag KEYWORDS',
      'templates' => array(
        'head' => array(
          'keywords' => NODEWORDS_META,
        ),
        'search index' => array(
          'keywords' => '<h2>%content</h2>',
        ),
      ),
      'weight' => array(
        'keywords' => -185,
      ),
    ),
    'rights' => array(
      'callback' => 'nodewords_basic_rights',
      'label' => t('Rights'),
      'permission' => 'edit meta tag RIGHTS',
      'templates' => array(
        'head' => array(
          'rights' => NODEWORDS_META,
        ),
        'search index' => array(
          'rights' => '<h3>%content</h3>',
        ),
      ),
      'weight' => array(
        'rights' => -169,
      ),
    ),
    'canonical' => array(
      'callback' => 'nodewords_basic_canonical',
      'context' => array(
        'denied' => array(
          NODEWORDS_TYPE_DEFAULT,
          NODEWORDS_TYPE_ERRORPAGE,
          NODEWORDS_TYPE_OFFLINE,
          NODEWORDS_TYPE_TRACKER,
        ),
      ),
      'label' => t('Canonical URL'),
      'permission' => 'edit canonical URL meta tag',
      'templates' => array(
        'head' => array(
          'canonical' => NODEWORDS_LINK_REL,
        ),
      ),
      'weight' => array(
        'canonical' => -139,
      ),
    ),
    'revisit-after' => array(
      'callback' => 'nodewords_basic_revisit_after',
      'label' => t('Revisit after'),
      'permission' => 'edit meta tag REVISIT-AFTER',
      'templates' => array(
        'head' => array(
          'revisit-after' => NODEWORDS_META,
        ),
      ),
      'weight' => array(
        'revisit-after' => -136,
      ),
    ),
    'standout' => array(
      'callback' => 'nodewords_basic_standout',
      'context' => array(
        'allowed' => array(
          NODEWORDS_TYPE_NODE,
        ),
      ),
      'label' => t('Standout'),
      'multiple' => TRUE,
      'permission' => 'edit meta tag STANDOUT',
      'templates' => array(
        'head' => array(
          'standout' => NODEWORDS_LINK_REL,
        ),
      ),
      'weight' => array(
        'standout' => -135,
      ),
    ),
    'original-source' => array(
      'callback' => 'nodewords_basic_original_source',
      'context' => array(
        'allowed' => array(
          NODEWORDS_TYPE_NODE,
        ),
      ),
      'label' => t('Original Source'),
      'multiple' => TRUE,
      'permission' => 'edit meta tag ORIGINAL-SOURCE',
      'templates' => array(
        'head' => array(
          'original-source' => NODEWORDS_LINK_REL,
        ),
      ),
      'weight' => array(
        'original-source' => -134,
      ),
    ),
    'robots' => array(
      'callback' => 'nodewords_basic_robots',
      'context' => array(
        'denied' => array(
          NODEWORDS_TYPE_NONE,
        ),
      ),
      'label' => t('Robots'),
      'permission' => 'edit meta tag ROBOTS',
      'templates' => array(
        'head' => array(
          'robots' => NODEWORDS_META,
        ),
      ),
      'weight' => array(
        'robots' => -119,
      ),
    ),
  );
  return $tags;
}

/**
 * Implements hook_perm().
 */
function nodewords_basic_perm() {
  return array(
    'edit meta tag PAGE TITLE',
    'edit meta tag ABSTRACT',
    'edit canonical URL meta tag',
    'edit meta tag RIGHTS',
    'edit meta tag DESCRIPTION',
    'edit meta tag KEYWORDS',
    'edit meta tag REVISIT-AFTER',
    'edit meta tag ROBOTS',
    'edit meta tag AUTHOR',
  );
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_title_form(&$form, $content, $options) {
  $form['page_title'] = array(
    '#tree' => TRUE,
    '#weight' => -199,
  );
  $form['page_title']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Page title'),
    '#description' => t('Provide a description of this node to appear in the &lt;title&gt; tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#maxlength' => variable_get('nodewords_max_size', 350),
  );
  $form['page_title']['append'] = array(
    '#type' => 'checkbox',
    '#title' => t('Append site name'),
    '#description' => t('Automatically append the site name to the page title. If the page title is left blank the site name will not be added. Currently the site name is "@site_name".', array(
      '@site_name' => variable_get('site_name', ''),
    )),
    '#default_value' => isset($content['append']) ? $content['append'] : TRUE,
  );
  $form['page_title']['divider'] = array(
    '#type' => 'textfield',
    '#title' => t('Site name divider'),
    '#description' => t('If the site name is being displayed, this will be displayed between the page title and the site name. If the site name is not being displayed then this will have no effect.'),
    '#default_value' => empty($content['divider']) ? ' | ' : $content['divider'],
    '#maxlength' => variable_get('nodewords_max_size', 350),
  );

  // Show the current default.
  if ($options['type'] != NODEWORDS_TYPE_DEFAULT) {

    // Load the current default.
    if (!empty($options['default']['page_title']['value'])) {
      $default = $options['default']['page_title']['value'];
    }
    else {
      $default = t('Not set.');
    }
    $form['page_title']['value']['#description'] .= '<br />' . t('The default is: %default', array(
      '%default' => $default,
    ));
  }
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_title_prepare(&$tags, $content, $options) {

  // Everything hinges on their being a valid title string.
  if (!empty($content['value'])) {
    $tags['page_title'] = $content['value'];

    // Get the site name, will need this in a moment.
    $site_name = variable_get('site_name', '');

    // See if the site name should be appended.
    if (!empty($content['append']) && !empty($site_name)) {

      // See if there's a divider string first.
      if (!empty($content['divider'])) {
        $tags['page_title'] .= $content['divider'];
      }

      // Append the site name.
      $tags['page_title'] .= $site_name;
    }
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_abstract_form(&$form, $content, $options) {
  $form['abstract'] = array(
    '#tree' => TRUE,
    '#weight' => -186,
  );
  $form['abstract']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Abstract'),
    '#description' => t('Enter a short abstract. Typically it is one sentence, with a maximum of %count characters. It should not contain any HTML tags or other formatting.', array(
      '%count' => variable_get('nodewords_max_size', 350),
    )),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#size' => 60,
    '#maxlength' => variable_get('nodewords_max_size', 350),
  );

  // Show the current default.
  if ($options['type'] != NODEWORDS_TYPE_DEFAULT) {

    // Load the current default.
    if (!empty($options['default']['abstract']['value'])) {
      $default = $options['default']['abstract']['value'];
    }
    else {
      $default = t('Not set.');
    }
    $form['abstract']['value']['#description'] .= '<br />' . t('The default is: %default', array(
      '%default' => $default,
    ));
  }
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_abstract_prepare(&$tags, $content, $options) {
  $tags['abstract'] = empty($content['value']) ? !empty($options['default']['abstract']['value']) ? $options['default']['abstract']['value'] : '' : $content['value'];
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_author_form(&$form, $content, $options) {
  $form['author'] = array(
    '#tree' => TRUE,
    '#weight' => -186,
  );
  $form['author']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Author'),
    '#description' => t("Used by some search engines to confirm authorship of the content on a page. Should be either the full URL for the author's Google+ profile page or a local page with information about the author. Example: https://plus.google.com/113325464728592995596"),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#size' => 60,
    '#maxlength' => variable_get('nodewords_max_size', 350),
  );

  // Show the current default.
  if ($options['type'] != NODEWORDS_TYPE_DEFAULT) {

    // Load the current default.
    if (!empty($options['default']['author']['value'])) {
      $default = $options['default']['author']['value'];
    }
    else {
      $default = t('Not set.');
    }
    $form['author']['value']['#description'] .= '<br />' . t('The default is: %default', array(
      '%default' => $default,
    ));
  }
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_author_prepare(&$tags, $content, $options) {
  if (!empty($content['value'])) {
    $tags['author'] = $content['value'];
  }
  elseif (!empty($options['default']['author']['value'])) {
    $tags['author'] = $options['default']['author']['value'];
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_canonical_form(&$form, $content, $options) {
  $form['canonical'] = array(
    '#tree' => TRUE,
    '#weight' => -139,
  );
  $form['canonical']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Canonical URL'),
    '#description' => t('Canonical URLs are used by search engines to identify the primary location that specific content is available from; this is useful when content is accessible from multiple URLs, either within the same site or across multiple sites that are sharing content. Use a relative URL without the initial slash.'),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#element_validate' => array(
      'nodewords_basic_canonical_form_validate',
    ),
    '#size' => 60,
    '#maxlength' => variable_get('nodewords_max_size', 350),
  );

  // Provide an option on node pages to hide this field.
  if ($options['type'] == NODEWORDS_TYPE_NODE) {
    $form['canonical']['hide'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide the Canonical URL'),
      '#description' => t('If the Syndication Source URL is being used it is recommended to not display this value.'),
      '#default_value' => !empty($content['hide']) ? TRUE : FALSE,
    );
  }

  // Expand the field's description to indicate what the default will be.
  if (variable_get('nodewords_use_path_alias', TRUE)) {
    $form['canonical']['value']['#description'] .= ' ' . t('By default this will automatically use this page\'s URL alias, e.g. "article/how-to-contribute-to-drupal" or "categories/drupal".');
  }
  else {
    $form['canonical']['value']['#description'] .= ' ' . t('By default this will automatically use this page\'s internal system path, e.g. "node/123" or "taxonomy/term/123".');
  }
}
function nodewords_basic_canonical_form_validate($element, &$form_state) {
  if (!empty($element['#value'])) {
    $canonical_url = trim($element['#value'], '/');
    if (!empty($canonical_url) && !valid_url(drupal_urlencode($canonical_url))) {
      form_error($element, t('Canonical URL must be a relative URL.'));
    }
  }
}

/**
 * Use the common function for compiling the current URL.
 */
function nodewords_basic_canonical_prepare(&$tags, $content, $options) {

  // Process the tag if the "hide" option wasn't selected.
  if (empty($content['hide'])) {
    $tags['canonical'] = _nodewords_prepare_path($content, $options);
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_rights_form(&$form, $content, $options) {
  $form['rights'] = array(
    '#tree' => TRUE,
    '#weight' => -169,
  );
  $form['rights']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Rights'),
    '#description' => t("A copyright, trademark, patent, or other information about intellectual property on this page."),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#size' => 60,
    '#maxlength' => variable_get('nodewords_max_size', 350),
  );

  // Show the current default.
  if ($options['type'] != NODEWORDS_TYPE_DEFAULT) {

    // Load the current default.
    if (!empty($options['default']['rights']['value'])) {
      $default = $options['default']['rights']['value'];
    }
    else {
      $default = t('Not set.');
    }
    $form['rights']['value']['#description'] .= '<br />' . t('The default is: %default', array(
      '%default' => $default,
    ));
  }
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_rights_prepare(&$tags, $content, $options) {
  $tags['rights'] = empty($content['value']) ? !empty($options['default']['rights']['value']) ? $options['default']['rights']['value'] : '' : $content['value'];
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_description_form(&$form, $content, $options) {
  $autogenerate = FALSE;
  if ($options['type'] == NODEWORDS_TYPE_NODE && isset($options['node_type'])) {
    $autogenerate = variable_get('nodewords_metatags_generation_method_' . $options['node_type'], NODEWORDS_GENERATION_WHEN_EMPTY);
  }
  $form['description'] = array(
    '#tree' => TRUE,
    '#weight' => -189,
  );
  $form['description']['value'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('Enter a one or two sentence description of your page. Limit the description to about 20 words with a maximum of %count characters. It should not contain any HTML tags or other formatting.', array(
      '%count' => variable_get('nodewords_max_size', 350),
    )),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#cols' => 60,
    '#rows' => 3,
    '#wysiwyg' => FALSE,
  );
  if ($options['type'] == NODEWORDS_TYPE_NODE) {
    if ($autogenerate == NODEWORDS_GENERATION_ALWAYS) {
      $form['description']['value']['#disabled'] = TRUE;
      $form['description']['value']['#rows'] = 1;
      $form['description']['value']['#default_value'] = '';
      $form['description']['value']['#description'] = t('This will be automatically generated from the node.');
    }
    elseif ($autogenerate == NODEWORDS_GENERATION_WHEN_EMPTY) {
      $form['description']['value']['#description'] .= ' ' . t('If this is left empty the value will be automatically generated from the node');
    }
  }

  // Show the current default.
  if ($options['type'] != NODEWORDS_TYPE_DEFAULT) {

    // Load the current default.
    if (!empty($options['default']['description']['value'])) {
      $default = $options['default']['description']['value'];
    }
    else {
      $default = t('Not set.');
    }
    $form['description']['value']['#description'] .= '<br />' . t('The default is: %default', array(
      '%default' => $default,
    ));
  }
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_description_prepare(&$tags, $content, $options) {
  _nodewords_prepare_description($tags, $content, $options, 'description');
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_keywords_form(&$form, $content, $options) {
  $form['keywords'] = array(
    '#tree' => TRUE,
    '#weight' => -185,
  );
  $form['keywords']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Keywords'),
    '#description' => t('Enter a comma separated list of keywords. Avoid duplication of words as this will lower your search engine ranking.'),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#size' => 60,
    '#element_validate' => array(
      'nodewords_basic_keywords_form_validate',
    ),
    '#maxlength' => variable_get('nodewords_max_size', 350),
  );

  // Show the current default.
  if ($options['type'] != NODEWORDS_TYPE_DEFAULT) {

    // Load the current default.
    if (!empty($options['default']['keywords']['value'])) {
      $default = $options['default']['keywords']['value'];
    }
    else {
      $default = t('Not set.');
    }
    $form['keywords']['value']['#description'] .= '<br />' . t('The default is: %default', array(
      '%default' => $default,
    ));
  }
}

/**
 * Validate the values passed as keywords.
 */
function nodewords_basic_keywords_form_validate($element, &$form_state) {
  if (trim($element['#value']) == ',') {
    form_error($element, t('The meta tag KEYWORDS value must be a comma separated list of words.'));
  }
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_keywords_prepare(&$tags, $content, $options) {
  $value = variable_get('nodewords_global_keywords', '');
  if (empty($content['value'])) {
    $value .= ',' . (!empty($options['default']['keywords']['value']) ? $options['default']['keywords']['value'] : '');
  }
  else {
    $value .= ',' . $content['value'];
  }
  if ($options['type'] == NODEWORDS_TYPE_NODE && module_exists('taxonomy')) {
    $node = node_load($options['id']);
    foreach (taxonomy_node_get_terms($node) as $term) {
      if (in_array($term->vid, variable_get('nodewords_keyword_vids', array()))) {
        $value .= ',' . $term->name;
      }
    }
  }
  $tags['keywords'] = nodewords_unique_values($value);
}
function nodewords_basic_keywords_settings_form(&$form, $form_id, $options) {
  if ($form_id == 'nodewords_settings_form') {
    if (module_exists('taxonomy')) {
      $options = array();
      foreach (taxonomy_get_vocabularies() as $vocabulary) {
        $options[$vocabulary->vid] = check_plain($vocabulary->name);
      }
      if ($count = count($options)) {
        $form['metatags_creation']['nodewords_keyword_vids'] = array(
          '#type' => $count > 10 ? 'select' : 'checkboxes',
          '#title' => t('Auto-keywords vocabularies'),
          '#description' => t('Select the vocabularies which contain terms you want to add to the keywords meta tag for nodes. The terms of these vocabularies are added before the global keywords but after the page-specific keywords.'),
          '#default_value' => variable_get('nodewords_keyword_vids', array()),
          '#options' => $options,
          '#multiple' => TRUE,
        );
        if ($count > 10) {
          $form['metatags_creation']['nodewords_keyword_vids']['#multiple'] = TRUE;
        }
        elseif ($count > 2) {

          // Add support for Check All if the checkboxes are more than two.
          $form['metatags_creation']['nodewords_keyword_vids']['#checkall'] = TRUE;
        }
      }
    }
    if (empty($options)) {
      $form['metatags_creation']['nodewords_keyword_vids'] = array(
        '#type' => 'value',
        '#default_value' => variable_get('nodewords_keyword_vids', array()),
      );
      $form['metatags_creation']['taxonomy_message'] = array(
        '#value' => module_exists('taxonomy') ? t('There are no vocabularies currently defined.') : t('The module %module is not enabled; if you want to use taxonomy terms to automatically set the content of the meta tag KEYWORDS, you first need to <a href="@modules-page">enable %module</a>', array(
          '%module' => 'taxonomy.module',
          '@modules-page' => url('admin/build/modules'),
        )),
        '#prefix' => '<div>',
        '#suffix' => '</div>',
      );
    }
    $form['metatags_creation']['nodewords_global_keywords'] = array(
      '#type' => 'textfield',
      '#title' => t('Global keywords'),
      '#description' => t('Enter a comma separated list of keywords. Global keywords will be always added to each page, and before any other keywords.'),
      '#default_value' => variable_get('nodewords_global_keywords', ''),
      '#size' => 60,
      '#element_validate' => array(
        'nodewords_basic_keywords_form_validate',
      ),
      '#maxlength' => variable_get('nodewords_max_size', 350),
    );
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_revisit_after_form(&$form, $content, $options) {
  $form['revisit-after'] = array(
    '#tree' => TRUE,
    '#weight' => -136,
  );
  $form['revisit-after']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Revisit after'),
    '#description' => t('The meta tag REVISIT-AFTER defines how often a search engine or spider should come to your website for re-indexing. This tag is used for websites that change their content on a regular basis.'),
    '#default_value' => empty($content['value']) ? '' : (int) $content['value'],
    '#size' => 3,
    '#element_validate' => array(
      'nodewords_basic_revisit_after_form_validate',
    ),
    '#maxlength' => 3,
    '#field_suffix' => t('day(s)'),
  );

  // Show the current default.
  if ($options['type'] != NODEWORDS_TYPE_DEFAULT) {

    // Load the current default.
    if (!empty($options['default']['revisit-after']['value'])) {
      $default = $options['default']['revisit-after']['value'];
    }
    else {
      $default = t('Not set.');
    }
    $form['revisit-after']['value']['#description'] .= '<br />' . t('The default is: %default', array(
      '%default' => $default,
    ));
  }
}

/**
 * Validate the meta tag value.
 */
function nodewords_basic_revisit_after_form_validate($element, &$form_state) {
  if (!empty($element['#value']) && !preg_match('/^[0-9]*$/', $element['#value'])) {
    form_error($element, t('The meta tag REVISIT-AFTER value must be a positive number.'));
  }
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_revisit_after_prepare(&$tags, $content, $options) {
  $value = 0;
  if (!empty($content['value'])) {
    $value = intval($options['default']['revisit-after']['value']);
  }
  elseif (!empty($options['default']['revisit-after']['value'])) {
    $value = intval($content['value']);
  }
  if (!empty($value)) {
    $tags['revisit-after'] = $value > 1 ? "{$value} days" : '1 day';
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_robots_form(&$form, $content, $options) {
  $field_options = _nodewords_basic_robots_options();
  if (isset($content['value']['noopd'])) {
    $content['value']['noodp'] = is_string($content['value']['noopd']) ? 'noodp' : 0;
    unset($content['value']['noopd']);
  }
  $form['robots'] = array(
    '#tree' => TRUE,
    '#weight' => -119,
  );
  $form['robots']['value'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Robots'),
    '#description' => t('The meta tag ROBOTS offers a simple mechanism to indicate to web robots and crawlers whether the page should be indexed (NOINDEX) and whether links on the page should be followed (NOFOLLOW). Search engines will automatically assume "INDEX" and "FOLLOW" unless these are specifically disabled above.'),
    '#default_value' => empty($content['value']) ? array() : $content['value'],
    '#options' => $field_options,
    '#checkall' => TRUE,
  );
  if ($options['type'] != NODEWORDS_TYPE_DEFAULT) {
    $form['robots']['use_default'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use the default value'),
      '#default_value' => !empty($content['use_default']),
    );
    if (!empty($options['default']['robots']['value'])) {
      $default_values = array_keys(array_filter($options['default']['robots']['value']));
    }
    if (!empty($default_values)) {
      $description = t('The default is: %default_values', array(
        '%default_values' => implode(', ', $default_values),
      ));
    }
    else {
      $description = t('The default is: ') . t('Not set.');
    }
    $form['robots']['use_default']['#description'] = $description;
  }
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_robots_prepare(&$tags, $content, $options) {
  $value = array();
  if ($options['type'] == NODEWORDS_TYPE_PAGER) {
    $value = variable_get('nodewords_list_robots', array());
  }
  elseif (isset($content['use_default']) && empty($content['use_default'])) {
    $value = !empty($content['value']) ? $content['value'] : array();
  }
  elseif (!empty($options['default']['robots']['value'])) {
    $value = $options['default']['robots']['value'];
  }
  if (!empty($value)) {
    $value = array_keys(array_filter($value));
    if (!empty($value)) {
      $tags['robots'] = implode(', ', $value);
    }
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_logo_form(&$form, $content, $options) {
  $form['logo'] = array(
    '#tree' => TRUE,
    '#weight' => -206,
  );
  $form['logo']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Logo'),
    '#description' => t('The absolute URL to an SVG version of the site logo to match the <a href="http://relogo.org/">relogo specification</a>.'),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
  );
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_logo_prepare(&$tags, $content, $options) {
  if (!empty($options['default']['logo']['value'])) {
    $tags['logo'] = $options['default']['logo']['value'];
  }
  if (!empty($content['value'])) {
    $tags['logo'] = $content['value'];
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_robots_settings_form(&$form, $form_id, $options) {
  switch ($form_id) {
    case 'nodewords_settings_form':
      $field_options = _nodewords_basic_robots_options();
      $form['metatags_creation']['nodewords_list_robots'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Meta tag ROBOTS for lists'),
        '#description' => t('The value to use for the meta tag ROBOTS for the pages that use a pager; this setting is not used for the first page of the list, or when the option to repeat the meta tags for all the pages in the same list is selected. Search engines will automatically assume "INDEX" and "FOLLOW" unless these are specifically disabled above; these two options are available for completeness sake but can be ignored.'),
        '#default_value' => variable_get('nodewords_list_robots', array()),
        '#options' => $field_options,
        '#checkall' => TRUE,
      );
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_standout_form(&$form, $content, $options) {
  $form['standout'] = array(
    '#tree' => TRUE,
    '#weight' => -135,
  );
  $form['standout']['value'] = array(
    '#type' => 'textarea',
    '#title' => t('Standout URL'),
    '#description' => t('Used to indicate which URL should be credited with breaking the story through oustanding journalism, and can link to either an internal URL or an external source. Should be only occasionally used to link to your own content as doing so too often (suggested: over seven per week) can penalize the site\'s ranking or have it removed entirely. Multiple items may be added, one URL per line, to a total limit of %count characters.', array(
      '%count' => variable_get('nodewords_max_size', 350),
    )),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#element_validate' => array(
      'nodewords_basic_standout_form_validate',
    ),
    '#cols' => 60,
    '#rows' => 3,
    '#wysiwyg' => FALSE,
  );
}
function nodewords_basic_standout_form_validate($element, &$form_state) {
  if (!empty($element['#value'])) {
    $max_length = variable_get('nodewords_max_size', 350);
    if (strlen($element['#value']) > $max_length) {
      form_error($element, t('The Standout URL field is limited to %count characters', array(
        '%count' => $max_length,
      )));
    }
    else {
      $invalid_url = FALSE;
      foreach (explode("\n", $element['#value']) as $url) {
        if (!empty($url) && !valid_url(trim($url), TRUE)) {
          $invalid_url = TRUE;
        }
      }
      if ($invalid_url) {
        form_error($element, t('The Standout URL must be a valid URL, or multple URLs, starting with "http://" or "https://".'));
      }
    }
  }
}
function nodewords_basic_standout_prepare(&$tags, $content, $options) {

  // There is no default allowed for this, due to search engine policies.
  if (!empty($content['value'])) {
    $tags['standout'] = $content['value'];
  }
}

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_original_source_form(&$form, $content, $options) {
  $form['original-source'] = array(
    '#tree' => TRUE,
    '#weight' => -133,
  );
  $form['original-source']['value'] = array(
    '#type' => 'textarea',
    '#title' => t('Original Source URL'),
    '#description' => t('Used to indicate the URL that broke the story, and can link to either an internal URL or an external source. If the full URL is not known it is acceptable to use a partial URL or just the domain name. Multiple items may be added, one URL per line, to a total limit of %count characters.', array(
      '%count' => variable_get('nodewords_max_size', 350),
    )),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#element_validate' => array(
      'nodewords_basic_original_source_form_validate',
    ),
    '#cols' => 60,
    '#rows' => 3,
    '#wysiwyg' => FALSE,
  );
}
function nodewords_basic_original_source_form_validate($element, &$form_state) {
  if (!empty($element['#value'])) {
    $max_length = variable_get('nodewords_max_size', 350);
    if (strlen($element['#value']) > $max_length) {
      form_error($element, t('The Original Source URL field is limited to %count characters', array(
        '%count' => $max_length,
      )));
    }
    else {
      $invalid_url = FALSE;
      foreach (explode("\n", $element['#value']) as $url) {
        if (!empty($url) && !valid_url(trim($url), TRUE)) {
          $invalid_url = TRUE;
        }
      }
      if ($invalid_url) {
        form_error($element, t('The Original Source URL must be a valid URL, or multple URLs, starting with "http://" or "https://".'));
      }
    }
  }
}
function nodewords_basic_original_source_prepare(&$tags, $content, $options) {

  // There is no default allowed for this, due to search engine policies.
  if (!empty($content['value'])) {
    $tags['original-source'] = $content['value'];
  }
}

/**
 * Internal functions
 */

/**
 * The list of ROBOTS options that are available.
 */
function _nodewords_basic_robots_options() {
  return array(
    'index' => t('INDEX (assumed)'),
    'noindex' => t('NOINDEX'),
    'follow' => t('FOLLOW (assumed)'),
    'nofollow' => t('NOFOLLOW'),
    'noarchive' => t('NOARCHIVE'),
    'noodp' => t('NOODP'),
    'nosnippet' => t('NOSNIPPET'),
    'noydir' => t('NOYDIR'),
  );
}

Functions

Namesort descending Description
nodewords_basic_abstract_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_abstract_prepare Set the meta tag content.
nodewords_basic_author_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_author_prepare Set the meta tag content.
nodewords_basic_canonical_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_canonical_form_validate
nodewords_basic_canonical_prepare Use the common function for compiling the current URL.
nodewords_basic_description_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_description_prepare Set the meta tag content.
nodewords_basic_keywords_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_keywords_form_validate Validate the values passed as keywords.
nodewords_basic_keywords_prepare Set the meta tag content.
nodewords_basic_keywords_settings_form
nodewords_basic_logo_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_logo_prepare Set the meta tag content.
nodewords_basic_nodewords_api Implements hook_nodewords_api().
nodewords_basic_nodewords_tags_info Implements hook_nodewords_tags_info().
nodewords_basic_original_source_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_original_source_form_validate
nodewords_basic_original_source_prepare
nodewords_basic_perm Implements hook_perm().
nodewords_basic_revisit_after_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_revisit_after_form_validate Validate the meta tag value.
nodewords_basic_revisit_after_prepare Set the meta tag content.
nodewords_basic_rights_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_rights_prepare Set the meta tag content.
nodewords_basic_robots_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_robots_prepare Set the meta tag content.
nodewords_basic_robots_settings_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_standout_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_standout_form_validate
nodewords_basic_standout_prepare
nodewords_basic_title_form Set the form fields used to implement the options for the meta tag.
nodewords_basic_title_prepare Set the meta tag content.
_nodewords_basic_robots_options The list of ROBOTS options that are available.