You are here

function simplemeta_get_page_meta in Simple Meta 6.2

Same name and namespace in other branches
  1. 8.2 simplemeta.module \simplemeta_get_page_meta()
  2. 8 simplemeta.module \simplemeta_get_page_meta()
  3. 7.2 simplemeta.module \simplemeta_get_page_meta()
  4. 7 simplemeta.module \simplemeta_get_page_meta()
1 call to simplemeta_get_page_meta()
simplemeta_preprocess_page in ./simplemeta.module
Implements $module_preprocess_$hook()

File

./simplemeta.module, line 244

Code

function simplemeta_get_page_meta($path = NULL, $language = '', $reset = FALSE) {
  static $meta = array();
  if (!isset($path)) {
    $path = $_GET['q'];
  }
  if (!isset($meta[$path]) || $reset) {
    $meta[$path] = FALSE;
    $cid = $path . ':' . $language;
    if ($cache = cache_get($cid, 'cache_simplemeta')) {
      $meta[$path] = $cache->data;
    }
    else {
      $row = NULL;
      $original_map = arg(NULL, $path);
      $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
      list($ancestors, $placeholders) = menu_get_ancestors($parts);
      $row = db_fetch_object(db_query_range("SELECT * FROM {simplemeta} WHERE path IN (" . implode(',', $placeholders) . ") AND language = '%s' ORDER BY fit DESC", array_merge($ancestors, array(
        $language,
      )), 0, 1));

      // if there is no language-specific meta, try to load language-neutral
      if (!$row && $language) {
        $row = db_fetch_object(db_query_range("SELECT * FROM {simplemeta} WHERE path IN (" . implode(',', $placeholders) . ") AND language = '%s' ORDER BY fit DESC", array_merge($ancestors, array(
          '',
        )), 0, 1));
      }
      if ($row) {
        $row->data = unserialize($row->data);
        $row->view = array();
        $info = simplemeta_get_info();
        foreach ($info as $key => $definition) {
          $themed = theme($definition['theme'], $row);
          if ($themed) {
            $row->view[$key] = $themed;
          }
        }
        cache_set($cid, $row, 'cache_simplemeta');
        $meta[$path] = $row;
      }
    }
  }
  return $meta[$path];
}