You are here

function metatags_quick_page_build in Meta tags quick 7.2

Same name and namespace in other branches
  1. 8.3 metatags_quick.module \metatags_quick_page_build()
  2. 7 metatags_quick.module \metatags_quick_page_build()

Implements hook_page_build

File

./metatags_quick.module, line 184
Quick and dirty implementation of meta tags for drupal 7 Module defines new field type 'meta'. Fields of this type are not displayed in HTML. Instead, they add html meta to the head section.

Code

function metatags_quick_page_build(&$page) {
  global $language;
  if (variable_get('metatags_quick_use_path_based', 1) && _metatags_quick_path_based_page()) {

    // Try to load path-based meta tags
    $path_based_id = db_select('metatags_quick_path_based', 'pv')
      ->condition('lang', $language->language)
      ->condition('path', $_GET['q'])
      ->fields('pv', array(
      'id',
    ))
      ->execute()
      ->fetchField();

    // if no excact match found - do wildcard search
    if ($path_based_id == 0 && strstr($_GET['q'], "/")) {
      $parts = explode("/", $_GET['q']);

      // iterate through parts
      for ($i = count($parts) - 1; $i > 0; $i--) {

        // create path
        $path = "";
        for ($j = 0; $j < $i; $j++) {
          $path .= $parts[$j] . "/";
        }

        // do wildcard query
        $path_based_id = db_select('metatags_quick_path_based', 'pv')
          ->condition('lang', $language->language)
          ->condition('path', $path . "*")
          ->fields('pv', array(
          'id',
        ))
          ->execute()
          ->fetchField();

        // check for results
        if ($path_based_id > 0) {
          break;
        }
      }
    }
    if ($path_based_id > 0) {
      $controller = new DrupalDefaultEntityController('metatags_path_based');
      $path_entities = $controller
        ->load(array(
        $path_based_id,
      ));
      foreach ($path_entities as $entity) {
        field_attach_view('metatags_path_based', $entity, 'default', LANGUAGE_NONE);
      }
    }
  }
}