Esempio n. 1
0
/**
 * Get the most recent entry for the page_id - if its URL does not match the URL of the page now, create a new entry and update
 * the timestamp of the last location (if it exists).
 *
 * @todo consider whether or not there is any utility in checking children if we are not creating an entry for the current
 *       location the page
 *
 * @param integer $page_id
 * @param boolean $check_children
 * @return boolean
 */
function update_URL_history( $page_id, $check_children = true )
{
	$page = new entity($page_id);
	if (reason_is_entity($page, 'minisite_page') && !$page->get_value('url'))
	{
		$builder = new reasonPageURL();
		$builder->disable_static_cache(); // force a refresh for this instance of the builder in case the URL just changed
		$builder->set_id($page->id());
		$url = $builder->get_relative_url();
		
		if (!empty($url)) // we only bother if we can get a url
		{
			// lets grab the most recent entry for this page_id
		
			$d = new DBselector();
			$d->add_table( 'history', 'URL_history' );
			$d->add_field( 'history', 'id', 'id' );
			$d->add_field( 'history', 'url', 'url' );
			$d->add_field( 'history', 'page_id', 'page_id' );
			$d->add_field( 'history', 'timestamp', 'timestamp' );
			$d->add_relation( 'history.page_id = ' . $page_id );
			$d->set_num(1);
			$d->set_order( 'history.timestamp DESC, history.id DESC' ); // get highest id of highest timestamp
			$result = db_query( $d->get_query() , 'Error getting most recent URL_history entry for page '.$page_id );
			if( $row = mysql_fetch_assoc($result))
			{
				$create_new = ($row['url'] == $url) ? false : true;
				$update_old = $create_new; // if we create new in this case we want to update the old as well
			}
			else
			{
				$create_new = true;
				$update_old = false;
			}
			if ($create_new) // lets use the SQLer to do this
			{
				$sqler = new SQLER();
				$cur_time = time();
				$values = array('url' => $url, 'page_id' => $page_id, 'timestamp' => $cur_time);
				$sqler->insert('URL_history', $values);
				if ($update_old) // the old row is the one we already grabbed - lets update its timestamp to be just before what we just created
				{
					$sqler->update_one('URL_history', array('timestamp' => ($cur_time - 1)), $row['id']);
				}
			}
			if( $check_children ) update_children( $page_id );
			return true;
		}
	}
	trigger_error('update_URL_history called on entity id ' . $page_id . ' which does not appear to be a valid minisite_page entity with a url (is it an external URL?)');
	return false;
}
Esempio n. 2
0
if (!reason_user_has_privs(get_user_id($current_user), 'view_sensitive_data')) {
    die('<h1>Sorry.</h1><p>You do not have permission to view modules.</p>');
}
$pages = array();
$modules_by_page_type = array();
$es = new entity_selector();
$es->add_type(id_of('minisite_page'));
$es->limit_tables(array('page_node', 'url'));
$es->limit_fields('entity.name, page_node.custom_page, page_node.url_fragment, url.url');
$es->add_right_relationship_field('owns', 'entity', 'id', 'owner_id');
$es->add_right_relationship_field('owns', 'entity', 'name', 'site_name');
$es->add_left_relationship_field('minisite_page_parent', 'entity', 'id', 'parent_id');
// we add some relations so that we grab only valid pages with names that are not custom url pages
$es->add_relation('(entity.name != "") AND ((url.url = "") OR (url.url IS NULL))');
$result = $es->run_one();
$builder = new reasonPageURL();
$builder->provide_page_entities($result);
$request = carl_get_request();
$detail_mode = isset($request['detail']) ? $request['detail'] == 'true' : false;
$module_limiter = isset($request['limit']) ? conditional_stripslashes(turn_into_string($request['limit'])) : '';
$detail_limiter = isset($request['detail_limit']) ? conditional_stripslashes(turn_into_string($request['detail_limit'])) : '';
$core_local_limiter = isset($request['core_local_limit']) ? check_against_array($request['core_local_limit'], array('core', 'local')) : '';
$num = isset($request['num']) ? turn_into_int($request['num']) : 'All';
if (isset($request['reset'])) {
    header("Location: " . carl_make_redirect(array('limit' => '', 'core_local_limit' => '')));
    exit;
}
// Make an array with first dimension of page type name, second dimension of every page
// ID using the pt, third dimension 'true' for every page type returned by the query.
foreach ($result as $k => $mypage) {
    $page_type_value = $mypage->get_value('custom_page');
Esempio n. 3
0
 /**
  * We'll get our site URLs using the url_builder to save some time.
  *
  * We also will cache the urls for url_cache_lifespan so that only the first load has the overhead of URL building.
  */
 function get_site_urls()
 {
     $roc = new ReasonObjectCache($this->admin_page->site_id . '_google_analytics_site_url_info', $this->url_cache_lifespan);
     $urls = $roc->fetch();
     if (!$urls) {
         $es = new entity_selector($this->admin_page->site_id);
         $es->limit_fields(array('url', 'url_fragment'));
         $es->add_type(id_of('minisite_page'));
         $es->add_left_relationship_field('minisite_page_parent', 'entity', 'id', 'parent_id');
         $es->add_relation('(entity.name != "") AND ((url.url = "") OR (url.url IS NULL))');
         // only pages, not custom urls
         $this->pages = $es->run_one();
         $url_builder = new reasonPageURL();
         $url_builder->provide_page_entities($pages);
         foreach ($this->pages as $id => $page) {
             $url_builder->set_id($id);
             $url = $url_builder->get_relative_url();
             $urls[$id] = $url;
         }
         $roc->set($urls);
     }
     return $urls;
 }