/**
  * Make sure that the model is configured with a valid URL.
  *
  * @return string json
  */
 function build()
 {
     if ($user_id = $this->config('user_id')) {
         $url = 'http://gdata.youtube.com/feeds/api/users/' . $user_id . '/uploads';
         $cache = new ReasonObjectCache($url, $this->config('cache_duration'));
         $result = $cache->fetch();
         if (!$result) {
             $xml = carl_util_get_url_contents($url);
             $sxml = simplexml_load_string($xml);
             if ($sxml) {
                 foreach ($sxml->entry as $entry) {
                     $full_id = $entry->id;
                     $id = basename($full_id);
                     $media = $entry->children('media', true);
                     $url = (string) $media->group->player->attributes()->url;
                     $thumbnail_url = (string) $media->group->thumbnail[0]->attributes()->url;
                     $result[$id] = array('url' => $url, 'thumbnail' => $thumbnail_url);
                 }
                 $cache->set($result);
             } else {
                 $cache = new ReasonObjectCache($url, -1);
                 $result = $cache->fetch();
                 if ($result) {
                     trigger_error('Reusing expired version of user videos - the cache could not be refreshed using url ' . $url);
                     $cache->set($result);
                 }
             }
         }
         return $result;
     } else {
         trigger_error('The YouTubeLatestUserVideosFeedModel must be provided with the configuration parameter user_id.', FATAL);
     }
 }
예제 #2
0
 /**
  * Make sure that the model is configured with a valid URL.
  *
  * @return string json
  */
 function build()
 {
     if ($id = $this->config('tweet_id')) {
         $key = (int) $id;
         $omit_script = $this->config('omit_script') ? 'true' : 'false';
         $roc = new ReasonObjectCache('reason_oembed_twitter_id_' . $key . '_omit_' . $omit_script, $this->config('cache_duration'));
         $json = $roc->fetch();
         if ($json === FALSE) {
             $obj = $this->get_oauth_object();
             $result = $obj->request('GET', $obj->url('1.1/statuses/oembed'), array('id' => $key, 'omit_script' => $omit_script));
             if ($result == '200') {
                 $json = $obj->response['response'];
                 $json = !empty($json) ? $json : '';
                 $roc->set($json);
             } else {
                 $roc2 = new ReasonObjectCache('reason_oembed_twitter_id_' . $key . '_omit_' . $omit_script, -1);
                 $json = $roc2->fetch();
                 if ($json !== FALSE) {
                     trigger_error('Using expired tweet for oembed id ' . $key . ' because the twitter API responded with code ' . $result . ' instead of giving us tweets');
                     $roc->set($json);
                 } else {
                     trigger_error('No tweet available for oembed id ' . $key . '. The twitter API returned code ' . $result . ' - we will retry when we have a fresh cache interval.');
                     $json = '';
                     $roc->set($json);
                 }
             }
         }
         return $json;
     } else {
         trigger_error('The ReasonOembedTwitterFeedModel must be provided with the configuration parameter tweet_id.', FATAL);
     }
 }
예제 #3
0
 function init_from_cache()
 {
     $cache_lifespan = $this->get_cache_lifespan();
     if ($cache_lifespan > 0) {
         $cache = new ReasonObjectCache($this->get_cache_id(), $this->get_cache_lifespan());
         $this->quote_pool =& $cache->fetch();
     }
 }
예제 #4
0
 function process()
 {
     $my_xml_id = $this->controller->get_form_data('xml_id');
     $cache = new ReasonObjectCache($my_xml_id);
     $import =& $cache->fetch();
     $import->run_job();
     // lets save the report in a cache
     $result['report'] = $import->get_report();
     $cache = new ReasonObjectCache($my_xml_id . '_result');
     $cache->set($result);
 }
 function init($args = array())
 {
     if ($this->params['cache_lifespan'] > 0) {
         $news_item_cache = new ReasonObjectCache($this->get_cache_id(), $this->params['cache_lifespan']);
         $this->news_items =& $news_item_cache->fetch();
         if (!$this->news_items) {
             $this->news_items =& $this->build_news_items($this->acceptable_params['publication_unique_name']);
             $news_item_cache->set($this->news_items);
         }
     } else {
         $this->news_items =& $this->build_news_items($this->acceptable_params['publication_unique_name']);
     }
 }
예제 #6
0
 /**
  * Make sure that the model is configured with a valid URL.
  *
  * @return mixed model data
  */
 function build()
 {
     if ($this->config('screen_name') || $this->config('search_string')) {
         $roc = new ReasonObjectCache('reason_twitter_feed_model_tweets_for_' . $this->config('screen_name'), $this->config('cache_duration'));
         $tweets = $roc->fetch();
         if ($tweets === FALSE) {
             $obj = $this->get_oauth_object();
             if ($this->config('screen_name')) {
                 $result = $obj->request('GET', $obj->url('1.1/statuses/user_timeline'), array('screen_name' => $this->config('screen_name')));
             } else {
                 if ($this->config('search_string')) {
                     $result = $obj->request('GET', $obj->url('1.1/search/tweets.json'), array('q' => $this->config('search_string'), 'result_type' => 'recent'));
                 }
             }
             if ($result == '200') {
                 $tweets = json_decode($obj->response['response'], true);
                 // make an associative array
                 $this->add_html_version_to_tweets($tweets);
                 $tweets = is_array($tweets) ? $tweets : array();
                 $roc->set($tweets);
             } else {
                 $roc2 = new ReasonObjectCache('reason_twitter_feed_model_tweets_for_' . $this->config('screen_name'), -1);
                 $tweets = $roc2->fetch();
                 if ($tweets !== FALSE) {
                     trigger_error('Using expired tweets for ' . $this->config('screen_name') . ' because the twitter API responded with code ' . $result . ' instead of giving us tweets');
                     $roc->set($tweets);
                 } else {
                     trigger_error('No new or expired tweets available for ' . $this->config('screen_name') . '. The twitter API returned code ' . $result . ' - we will retry when we have a fresh cache interval.');
                     $tweets = array();
                     $roc->set($tweets);
                 }
             }
         }
         return $tweets;
     } else {
         trigger_error('The ReasonTwitterFeedModel must be provided with the configuration parameter screen_name or search_string.', FATAL);
     }
 }
예제 #7
0
 /**
  * Before we build a page tree, try to fetch a cached version which should usually be available.
  *
  * @todo should this build a cache if it wasn't found ... maybe implement later.
  */
 function get_pages()
 {
     if (!isset($this->_pages)) {
         $site_id = $this->config('site_id');
         $cache = new ReasonObjectCache($site_id . '_navigation_cache', -1);
         if (($result = $cache->fetch()) && isset($result['MinisiteNavigation'])) {
             $this->_pages = reset($result);
         } else {
             $site = new entity($site_id);
             $this->_pages = new MinisiteNavigation();
             $this->_pages->site_info = $site;
             $this->_pages->order_by = 'sortable.sort_order';
             $this->_pages->init($site_id, id_of('minisite_page'));
         }
     }
     return $this->_pages;
 }
예제 #8
0
 function &_get_items_from_cache()
 {
     if ($this->get_cache_lifespan() > 0) {
         $item_cache = new ReasonObjectCache($this->get_cache_id(), $this->get_cache_lifespan());
         $items =& $item_cache->fetch();
     } else {
         $items = false;
     }
     return $items;
 }
예제 #9
0
/**
 * We use a 1 hour cache for this super common query. We update the cache in admin_actions.php whenever allowable relationships are added or changed.
 */
function reason_get_relationship_names()
{
    $cache = new ReasonObjectCache('reason_relationship_names', 3600);
    if ($relationship_names =& $cache->fetch()) {
        return $relationship_names;
    } else {
        return reason_refresh_relationship_names();
    }
}
예제 #10
0
 function init_from_cache()
 {
     $cache_lifespan = $this->get_cache_lifespan();
     if ($cache_lifespan > 0) {
         $cache = new ReasonObjectCache($this->get_cache_id(), $this->get_cache_lifespan());
         $this->events =& $cache->fetch();
         $cache = new ReasonObjectCache($this->get_cache_id() . '_cal', $this->get_cache_lifespan());
         $this->calendar =& $cache->fetch();
     }
 }
예제 #11
0
	/**
	 * Set up the template
	 *
	 * @var integer $site_id
	 * @var integer $page_id
	 * @todo page_id should not have a default value -- this makes it seem like you could initialize
	 *       the template without providing a page_id, but that would result in a 404.
	 */
	function initialize( $site_id, $page_id = '' ) // {{{
	{
		$this->sess =& get_reason_session();
		if( $this->sess->exists() )
		{
			// if a session exists and the server supports https, pop over to the secure
			// site so we have access to the secure session information
			force_secure_if_available();
			if(!$this->sess->has_started())
				$this->sess->start();
		}
	
		$this->site_id = $site_id;
		$this->page_id = $page_id;
		$this->site_info = new entity( $site_id );
		$this->page_info = new entity( $page_id );
		$this->head_items = new HeadItems();

		// make sure that the page exists or that the page's state is Live
		// if not, redirect to the 404
		if( !$this->page_info->get_values() OR $this->page_info->get_value( 'state' ) != 'Live' )
		{
			//trigger_error( 'page does not exist', WARNING );
			$this->display_404_page();
			die();
		}
		
		if ($this->use_navigation_cache)
		{
			$cache = new ReasonObjectCache($this->site_id . '_navigation_cache', 3600); // lifetime of 1 hour
			$page_object_cache =& $cache->fetch();
			if ($page_object_cache && is_array($page_object_cache) && isset($page_object_cache[$this->nav_class]))
			{
				$this->pages = $page_object_cache[$this->nav_class];
			}
			elseif ($page_object_cache && is_object($page_object_cache)) // old format
			{
				// lets use our cache and also update it
				$this->pages = $page_object_cache;
				$new_page_object_cache[$this->nav_class] = $this->pages;
				$cache->set($new_page_object_cache); // replace with our array keyed cache
			}
		}
		// lets check the persistent cache
		
		if (empty($this->pages) || !isset($this->pages->values[$this->page_info->id()]))
		{
			// lets setup $this->pages and place in the persistent cache
			$this->pages = new $this->nav_class;
			// small kludge - just give the tree view access to the site info.  used in the show_item function to show the root node of the navigation
			$this->pages->site_info =& $this->site_info;
			$this->pages->order_by = 'sortable.sort_order';
			$this->pages->init( $this->site_id, id_of('minisite_page') );
			if ($this->use_navigation_cache) 
			{
				$page_object_cache[$this->nav_class] = $this->pages;
				$cache->set($page_object_cache);
			}
		}
		else // if pages came from cache refresh the request variables and set site_info and order_by
		{
			$this->pages->grab_request();
			$this->pages->site_info =& $this->site_info;
			$this->pages->order_by = 'sortable.sort_order'; // in case it was changed in the request
		}
		
		$this->_handle_access_auth_check();
		
		$this->textonly = '';
		
		if( $this->pages->values  )
		{
			if( !$this->page_id )
				$this->page_id = $this->pages->root_node();

			$this->pages->cur_page_id = $this->page_id;

			$this->pages->force_open( $this->page_id );

			$this->cur_page = new entity($this->page_id);
			
			$this->title = $this->cur_page->get_value('name');
			
			$this->get_css_files();

			$this->get_meta_information();
			
			if( $this->sess->exists() )
			{
				if (USE_JS_LOGOUT_TIMER)
				{
					$this->head_items->add_stylesheet(REASON_HTTP_BASE_PATH.'css/timer.css');
					$this->head_items->add_javascript(JQUERY_URL, true);
					$this->head_items->add_javascript(WEB_JAVASCRIPT_PATH . 'timer/timer.js');
				}
				
				// we know that someone is logged in if the session exists
				$this->logged_in = true;
			}

			// hook for any actions to take prior to loading modules
			$this->pre_load_modules();

			// load the modules
			$this->load_modules();
		}
		else
		{
			trigger_error('Page requested not able to be displayed... no pages on site');
			$this->_display_403_page();
			die();
		}
	} // }}}
예제 #12
0
 function get_excluded()
 {
     $id = $this->_get_cache_id();
     $cache = new ReasonObjectCache($id);
     return $cache->fetch();
 }
예제 #13
0
 final function cache($obj = NULL)
 {
     if ($obj === NULL && isset($this->_cache)) {
         return $this->_cache;
     }
     $cache_key = $this->get_cache_key();
     $cache = new ReasonObjectCache($cache_key);
     if ($obj !== NULL) {
         $cache->set($obj);
     }
     $this->_cache = $cache->fetch($cache_key);
     return $this->_cache;
 }
예제 #14
0
$reason_user_id = get_user_id($netid);
if (empty($reason_user_id)) {
    die('valid Reason user required');
} elseif (!reason_user_has_privs($reason_user_id, 'upgrade')) {
    die('You must have upgrade privileges to run this script');
} else {
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n";
    echo '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n";
    echo '<head>' . "\n";
    echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
    echo '</head>' . "\n";
    echo '<body>' . "\n";
    if (isset($_GET['report'])) {
        $link = carl_make_link(array('report' => ''));
        $cache = new ReasonObjectCache($_GET['report']);
        $report =& $cache->fetch();
        if (isset($report['report'])) {
            echo '<h2>Full Report</h2>';
            echo $report['report'];
        } else {
            echo '<p>Nothing to Report</p>';
        }
        $link = carl_make_link(array('report' => ''));
        echo '<p><a href="' . $link . '">Do another Wordpress Import</a></p>';
    } else {
        // Initialize the controller and set a few options.
        $controller = new FormController();
        $controller->set_session_class('Session_PHP');
        $controller->set_session_name('REASON_SESSION');
        $controller->set_data_context('wordpress_import');
        $controller->show_back_button = false;
예제 #15
0
	/**
	 * If the form submission was just completed - we should have a valid submission_key passed in the request
	 */
	function form_submission_is_complete()
	{
		if (!isset($this->_form_submission_is_complete))
		{
			$submission_key = $this->get_form_submission_key();
			$sk_cache = new ReasonObjectCache($submission_key);
			$this->_form_submission_is_complete = ($sk_cache->fetch());
			if ($sk_cache->fetch()) $sk_cache->clear();
		}
		return $this->_form_submission_is_complete;
	}
예제 #16
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;
 }