/** * load one anchor from the database * * You should expand this function to take into account any new module * that may behave as anchors for other information components. * * This function saves on actual SQL requests by caching results locally in static memory. * Use the second parameter to ensure you have a fresh copy of the object. * * @param string a valid anchor (e.g., 'section:12', 'article:34') * @param boolean TRUE to always fetch a fresh instance, FALSE to enable cache * @return object implementing the Anchor interface, or NULL if the anchor is unknown * * @see shared/anchor.php */ public static function get($id, $mutable = FALSE) { global $context; // no anchor yet $anchor = NULL; // find the type $attributes = explode(':', $id); // if no type has been provided, assume we want a section if (!isset($attributes[1]) || !$attributes[1]) { $attributes = array('section', $id); } // switch on type switch ($attributes[0]) { case 'article': include_once $context['path_to_root'] . 'articles/article.php'; $anchor = new Article(); $anchor->load_by_id($attributes[1], $mutable); break; case 'category': include_once $context['path_to_root'] . 'categories/category.php'; $anchor = new Category(); $anchor->load_by_id($attributes[1], $mutable); break; case 'file': include_once $context['path_to_root'] . 'files/file.php'; $anchor = new File(); $anchor->load_by_id($attributes[1], $mutable); break; case 'section': include_once $context['path_to_root'] . 'sections/section.php'; $anchor = new Section(); $anchor->load_by_id($attributes[1], $mutable); break; case 'user': include_once $context['path_to_root'] . 'users/user.php'; $anchor = new User(); $anchor->load_by_id($attributes[1], $mutable); break; default: return $anchor; } // ensure the object actually exists if (!isset($anchor->item['id'])) { $anchor = NULL; } // load overlay if any if (isset($anchor->item['overlay'])) { $anchor->overlay = Overlay::load($anchor); } // return by reference return $anchor; }