Example #1
0
 /**
  * @todo find events page
  */
 public function get_url()
 {
     if (!isset($this->_url)) {
         if ($this->_event->get_value('url')) {
             return $this->_event->get_value('url');
         } elseif ($owner = $this->_event->get_owner()) {
             static $cache = array();
             if (!isset($cache[$owner->id()])) {
                 reason_include_once('classes/module_sets.php');
                 $ms =& reason_get_module_sets();
                 $modules = $ms->get('event_display');
                 if (!empty($modules)) {
                     $page_types = page_types_that_use_module($modules);
                     if (!empty($page_types)) {
                         array_walk($page_types, 'db_prep_walk');
                         $es = new entity_selector($owner->id());
                         $es->add_type(id_of('minisite_page'));
                         $es->add_relation('`custom_page` IN (' . implode(',', $page_types) . ')');
                         $es->set_num(1);
                         $pages = $es->run_one();
                         if (!empty($pages)) {
                             $page = current($pages);
                             $cache[$owner->id()] = build_URL_from_entity($page);
                         }
                     }
                 }
             }
             if (empty($cache[$owner->id()])) {
                 $cache[$owner->id()] = false;
                 $this->_url = '';
             } else {
                 $this->_url = $cache[$owner->id()] . '?event_id=' . $this->_event->id();
             }
         } else {
             $this->_url = '';
         }
     }
     return $this->_url;
 }
Example #2
0
/**
 * Get the URL for a page
 *
 * Originally developed as part of URL history as a lightweight
 * way to find a page's URL without having to query for all pages
 * in the site
 *
 * @param integer $page_id
 * return mixed string URL if found; else NULL
 */
function build_URL($page_id)
{
    $page_id = (int) $page_id;
    if (empty($page_id)) {
        trigger_error('Bad $page_id');
        return;
    }
    static $cache;
    if (isset($cache[$page_id])) {
        $url = $cache[$page_id];
    } else {
        $es = new entity_selector();
        $es->add_type(id_of('minisite_page'));
        $es->limit_tables('page_node');
        $es->limit_fields('page_node.url_fragment');
        $es->add_relation('entity.id = ' . $page_id);
        $result = $es->run_one();
        $page = !empty($result) ? array_shift($result) : false;
        if ($page) {
            $url = build_URL_from_entity($page);
            $cache[$page_id] = !empty($url) ? $url : false;
        } else {
            $cache[$page_id] = $url = false;
        }
    }
    return $url;
}