You are here

function simplemeta_get_page_meta in Simple Meta 7.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. 6.2 simplemeta.module \simplemeta_get_page_meta()
  4. 7 simplemeta.module \simplemeta_get_page_meta()

Get SimpleMeta entity for a page, by path.

Parameters

string $path: Path of the page to get metadata for.

string $language: Language code to get metadata for.

bool $reset: TRUE to reset static cache.

Return value

SimplemetaEntity|FALSE SimpleMeta entity if appropriate found, FALSE otherwise.

2 calls to simplemeta_get_page_meta()
simplemeta_page_alter in ./simplemeta.module
Implements hook_page_alter().
simplemeta_preprocess_html in ./simplemeta.module
Implements $module_preprocess_$hook().

File

./simplemeta.module, line 218
SimpleMeta module.

Code

function simplemeta_get_page_meta($path = NULL, $language = '', $reset = FALSE) {
  static $meta = array();
  if (!isset($path)) {
    $path = current_path();
  }
  if (!isset($meta[$path]) || $reset) {
    $meta[$path] = FALSE;
    $cid = $path . ':' . $language;
    if ($cache = cache_get($cid, 'cache_simplemeta')) {
      $meta[$path] = $cache->data;
    }
    else {
      $original_map = arg(NULL, $path);
      $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
      $ancestors = simplemeta_path_get_ancestors($parts);
      $entity = simplemeta_meta_load_by_path($ancestors, $language);

      // If there is no language-specific meta, try to load language-neutral.
      if (!$entity && $language) {
        $entity = simplemeta_meta_load_by_path($ancestors);
      }
      if ($entity) {

        // @todo Content should probably be added to the entity outside of there.
        $content = $entity
          ->view('meta');
        $entity->content = $content['simplemeta'][$entity->sid];
        cache_set($cid, $entity, 'cache_simplemeta');
        $meta[$path] = $entity;
      }
    }
  }
  return $meta[$path];
}