Exemplo n.º 1
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);
     }
 }
 /**
  * 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);
     }
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
 /**
  * run the rewrite rules
  */
 function run()
 {
     $urlm = new url_manager($this->vars['site_id']);
     $urlm->update_rewrites();
     // if a page was just deleted, lets also clear the nav cache for the site
     if ($this->vars['type_id'] == id_of('minisite_page')) {
         reason_include_once('classes/object_cache.php');
         $cache = new ReasonObjectCache($this->vars['site_id'] . '_navigation_cache');
         $cache->clear();
     }
 }
Exemplo n.º 5
0
 function init()
 {
     $this->admin_page->set_show('leftbar', false);
     if (empty($this->admin_page->id)) {
         $this->_not_undeletable_reason = 'no_id_provided';
         return false;
     }
     if (!reason_user_has_privs($this->admin_page->user_id, 'publish')) {
         $this->_not_undeletable_reason = 'insufficient_privileges';
         return false;
     }
     $item = new entity($this->admin_page->id);
     $user = new entity($this->admin_page->user_id);
     if (!$item->user_can_edit_field('state', $user)) {
         $this->_not_undeletable_reason = 'state_field_locked';
         return false;
     }
     if ($item->get_value('state') != 'Deleted') {
         $this->_not_undeletable_reason = 'not_deleted_yet';
         return false;
     }
     reason_update_entity($this->admin_page->id, $this->admin_page->user_id, array('state' => 'Live'), false);
     if ($this->admin_page->type_id == id_of('minisite_page')) {
         // zap nav cache so it reappears.
         reason_include_once('classes/object_cache.php');
         $cache = new ReasonObjectCache($this->admin_page->site_id . '_navigation_cache');
         $cache->clear();
     }
     $manager_site_id = $this->admin_page->site_id;
     if ($item->get_value('type') == id_of('site')) {
         $manager_site_id = $item->id();
     }
     //Updates the rewrites to prevent infinite redirection loop.
     reason_include_once('classes/url_manager.php');
     $urlm = new url_manager($manager_site_id);
     $urlm->update_rewrites();
     $link = unhtmlentities($this->admin_page->make_link(array('cur_module' => 'Lister', 'id' => '', 'state' => 'deleted')));
     header('Location: ' . $link);
     die;
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 7
0
 function clear_cache()
 {
     $cache = new ReasonObjectCache($this->get_cache_id());
     $cache->clear();
 }
Exemplo n.º 8
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();
		}
	} // }}}
Exemplo n.º 9
0
 function process()
 {
     if ($this->get_value('chosen_action') == '0') {
         $items = array();
         foreach ($this->get_element_names() as $name) {
             if (preg_match("/^sortOrder_/i", $name)) {
                 $order = $this->get_value($name);
                 $name = preg_replace("/^sortOrder_/i", "", $name);
                 $items[$name] = $order;
             }
         }
         asort($items);
         $sort_order = 1;
         foreach ($items as $k => $v) {
             $items[$k] = $sort_order;
             $sort_order++;
         }
         $changed_something = false;
         if (!empty($items)) {
             foreach ($items as $id => $order) {
                 $result = reason_update_entity($id, $this->user_id, array($this->sorter->get_field() => $order), false);
                 if ($result) {
                     $changed_something = true;
                 }
             }
         }
         // if we have changed sort order of pages, lets try to drop the nav cache for the active site.
         if ($changed_something && $this->type_id == id_of('minisite_page')) {
             reason_include_once('classes/object_cache.php');
             $cache = new ReasonObjectCache($this->site_id . '_navigation_cache');
             $cache->clear();
         }
     }
 }
Exemplo n.º 10
0
 /**
  *
  * @todo populate descriptions intelligently
  */
 function process()
 {
     // lets parse the uploaded file and create a job set - we cache the job set so that if the browser times out we can recover.
     $stack = new ReasonJobStack();
     // kill All
     $kill_all = $this->get_value('kill_all');
     if ($kill_all == "true") {
         $cleanup_job = new WordPressImportCleanup();
         $cleanup_job->site_id = $this->get_value('reason_site');
         $cleanup_job->user_id = $this->controller->reason_user_id;
         $stack->add_job($cleanup_job);
     } else {
         // create a job for alerts that we'll add to the end of the stack.
         $report_preformatted_job = new WordPressRewriteRuleReportPreformattedJob();
         // ensure the news type is on the site
         $job = new WordPressEnsureTypeIsOnSite();
         $job->site_id = $this->get_value('reason_site');
         $job->type_id = id_of('news');
         $stack->add_job($job);
         // ensure publication type is on the site
         $job = new WordPressEnsureTypeIsOnSite();
         $job->site_id = $this->get_value('reason_site');
         $job->type_id = id_of('publication_type');
         $stack->add_job($job);
         // ensure category type is on the site
         $job = new WordPressEnsureTypeIsOnSite();
         $job->site_id = $this->get_value('reason_site');
         $job->type_id = id_of('category_type');
         $stack->add_job($job);
         // create the publication entity
         $job = new WordPressEntityCreationJob();
         $job->site_id = $this->get_value('reason_site');
         $job->type_id = id_of('publication_type');
         $job->user_id = $this->controller->reason_user_id;
         $job->entity_info = array('name' => $this->xml_parser->document->channel[0]->title[0]->tagData, 'description' => $this->xml_parser->document->channel[0]->description[0]->tagData, 'publication_type' => 'blog', 'blog_feed_string' => 'blog', 'hold_posts_for_review' => 'no', 'has_issues' => 'no', 'has_sections' => 'no');
         $pub_import_guid = $stack->add_job($job);
         $nobody_group_job = new WordPressEnsureNobodyGroupIsOnSite();
         $nobody_group_job->site_id = $this->get_value('reason_site');
         $stack->add_job($nobody_group_job);
         // relate publication to nobody group for front end posting and commenting
         $post_group_job = new WordPressRelateItemsJob();
         $post_group_job->rel_id = relationship_id_of('publication_to_authorized_posting_group');
         $post_group_job->left_import_guid = $pub_import_guid;
         $post_group_job->right_id = id_of('nobody_group');
         $stack->add_job($post_group_job);
         $comment_group_job = new WordPressRelateItemsJob();
         $comment_group_job->rel_id = relationship_id_of('publication_to_authorized_commenting_group');
         $comment_group_job->left_import_guid = $pub_import_guid;
         $comment_group_job->right_id = id_of('nobody_group');
         $stack->add_job($comment_group_job);
         $make_pub_page_job = new WordPressMakePublicationPageJob();
         $make_pub_page_job->site_id = $this->get_value('reason_site');
         // if we want a new page - create a publication page.
         if ($new_pub_page = $this->get_value('blog_page_name')) {
             $pub_page_name = trim(strip_tags($new_pub_page));
             $pub_page_url_fragment = strtolower(str_replace(array("-", " "), "_", $pub_page_name));
             $create_pub_page_job = new WordPressEntityCreationJob();
             $create_pub_page_job->type_id = id_of('minisite_page');
             $create_pub_page_job->site_id = $this->get_value('reason_site');
             $create_pub_page_job->user_id = $this->controller->reason_user_id;
             $create_pub_page_job->entity_info = array('name' => $pub_page_name, 'link_name' => $pub_page_name, 'url_fragment' => $pub_page_url_fragment, 'state' => 'Live', 'custom_page' => 'publication', 'content' => '', 'nav_display' => 'Yes');
             $create_pub_page_guid = $stack->add_job($create_pub_page_job);
             // we need to make a parent relationship with the root page_id
             $page_parent_job = new WordPressRelateItemsJob();
             $page_parent_job->rel_id = relationship_id_of('minisite_page_parent');
             $page_parent_job->left_import_guid = $create_pub_page_guid;
             $page_parent_job->right_id = $this->get_site_root($this->get_value('reason_site'));
             $page_parent_job_guid = $stack->add_job($page_parent_job);
             $make_pub_page_job->page_id_guid = $create_pub_page_guid;
         } else {
             $make_pub_page_job->page_id = $this->get_site_root($this->get_value('reason_site'));
         }
         $make_pub_page_job->user_id = $this->controller->reason_user_id;
         $make_pub_page_job->pub_import_guid = $pub_import_guid;
         $pub_page_guid = $stack->add_job($make_pub_page_job);
         // CATEGORIES
         if (!empty($this->xml_parser->document->channel[0]->wp_category)) {
             foreach ($this->xml_parser->document->channel[0]->wp_category as $k => $cat) {
                 $the_category['wp_cat_name'] = $cat->wp_cat_name[0]->tagData;
                 $the_category['wp_category_nicename'] = $cat->wp_category_nicename[0]->tagData;
                 $the_category['wp_category_parent'] = $cat->wp_category_parent[0]->tagData;
                 if (!empty($the_category['wp_category_parent'])) {
                     $parent_cat[$the_category['wp_cat_name']] = $the_category['wp_category_parent'];
                 }
                 // STUFF FOR OUR IMPORT
                 $cat_import_job = new WordPressEntityCreationJob();
                 $cat_import_job->type_id = id_of('category_type');
                 $cat_import_job->site_id = $this->get_value('reason_site');
                 $cat_import_job->user_id = $this->controller->reason_user_id;
                 $cat_import_job->entity_info = array('name' => $the_category['wp_cat_name'], 'slug' => $the_category['wp_category_nicename']);
                 $cat_import_guid[$the_category['wp_cat_name']] = $stack->add_job($cat_import_job);
             }
         }
         // TAGS - we also make these into categories since Reason does not have a meaningful distinction
         if (!empty($this->xml_parser->document->channel[0]->wp_tag)) {
             foreach ($this->xml_parser->document->channel[0]->wp_tag as $k => $cat) {
                 $the_category['wp_tag_name'] = $cat->wp_tag_name[0]->tagData;
                 $the_category['wp_tag_slug'] = $cat->wp_tag_slug[0]->tagData;
                 // STUFF FOR OUR IMPORT
                 $cat_import_job = new WordPressEntityCreationJob();
                 $cat_import_job->type_id = id_of('category_type');
                 $cat_import_job->site_id = $this->get_value('reason_site');
                 $cat_import_job->user_id = $this->controller->reason_user_id;
                 $cat_import_job->entity_info = array('name' => $the_category['wp_tag_name'], 'slug' => $the_category['wp_tag_slug']);
                 $cat_import_guid[$the_category['wp_tag_name']] = $stack->add_job($cat_import_job);
             }
         }
         if (!empty($this->xml_parser->document->channel[0]->item)) {
             foreach ($this->xml_parser->document->channel[0]->item as $k => $item) {
                 $the_item = array();
                 // STRAIGHT OUT OF WORDPRESS
                 $the_item['title'] = $item->title[0]->tagData;
                 $the_item['link'] = $item->link[0]->tagData;
                 $the_item['pubDate'] = $item->pubdate[0]->tagData;
                 $the_item['dc_creator'] = $item->dc_creator[0]->tagData;
                 // categories - how to handle??
                 $the_item['guid'] = $item->guid[0]->tagData;
                 // attribute isPermaLink?? - do we care?
                 $the_item['guid_is_permalink'] = $item->guid[0]->tagAttrs['ispermalink'];
                 $the_item['description'] = tidy(strip_tags($item->description[0]->tagData));
                 $the_item['content_encoded'] = trim(tidy(get_safer_html($this->wpautop($item->content_encoded[0]->tagData))));
                 //$the_item['excerpt_encoded'] = trim(tidy($this->wpautop($item->excerpt_encoded[0]->tagData)));
                 $the_item['wp_post_id'] = $item->wp_post_id[0]->tagData;
                 $the_item['wp_post_date'] = $item->wp_post_date[0]->tagData;
                 $the_item['wp_post_date_gmt'] = $item->wp_post_date_gmt[0]->tagData;
                 $the_item['wp_comment_status'] = $item->wp_comment_status[0]->tagData;
                 $the_item['wp_ping_status'] = $item->wp_ping_status[0]->tagData;
                 $the_item['wp_post_name'] = $item->wp_post_name[0]->tagData;
                 $the_item['wp_status'] = $item->wp_status[0]->tagData;
                 $the_item['wp_post_parent'] = $item->wp_post_parent[0]->tagData;
                 $the_item['wp_menu_order'] = $item->wp_menu_order[0]->tagData;
                 $the_item['wp_post_type'] = $item->wp_post_type[0]->tagData;
                 $the_item['wp_post_password'] = $item->wp_post_password[0]->tagData;
                 $the_item['is_sticky'] = $item->wp_post_password[0]->tagData;
                 $the_item['guid'] = $item->guid[0]->tagData;
                 // IF WE ARE A PAGE
                 if (strtolower($the_item['wp_post_type']) == 'page') {
                     //$the_item['link'] is the old URL
                     //$the_item['guid'] is the non friendly URL
                     // our new url fragment should be the last segment of the old URL - if it is an SEO friendly URL
                     $url = parse_url($the_item['link']);
                     if (!empty($url['query'])) {
                         $new_url_fragment = strtolower(str_replace(" ", "_", $the_item['title']));
                     } else {
                         $new_url_fragment = strtolower(str_replace(" ", "_", $the_item['wp_post_name']));
                         $new_url_fragment = strtolower(str_replace("-", "_", $new_url_fragment));
                     }
                     // should we have a description of some type?
                     $page_import_job = new WordPressEntityCreationJob();
                     $page_import_job->type_id = id_of('minisite_page');
                     $page_import_job->site_id = $this->get_value('reason_site');
                     $page_import_job->user_id = $this->controller->reason_user_id;
                     $page_import_job->entity_info = array('name' => $the_item['title'], 'link_name' => $the_item['title'], 'url_fragment' => $new_url_fragment, 'state' => $the_item['wp_status'] == 'publish' ? 'Live' : 'Pending', 'datetime' => $the_item['wp_post_date'], 'author' => $the_item['dc_creator'], 'sort_order' => $the_item['wp_menu_order'], 'custom_page' => 'default', 'content' => tidy($the_item['content_encoded']), 'nav_display' => 'Yes');
                     $page_import_job->id(md5('page_guid_' . $the_item['wp_post_id']));
                     $stack->add_job($page_import_job);
                     //page_to_category - these rels we need to do
                     if (!empty($item->category)) {
                         foreach ($item->category as $k => $category) {
                             $page_cat = array();
                             $cat_name = $category->tagData;
                             $page_cat[] = $cat_name;
                             while (isset($parent_cat[$cat_name])) {
                                 $cat_name = $parent_cat[$cat_name];
                                 $page_cat[] = $cat_name;
                             }
                             foreach ($page_cat as $cat_name) {
                                 // add a job to relate the post to the category
                                 $page_to_cat_job = new WordPressRelateItemsJob();
                                 $page_to_cat_job->rel_id = relationship_id_of('page_to_category');
                                 $page_to_cat_job->left_import_guid = md5('page_guid_' . $the_item['wp_post_id']);
                                 $page_to_cat_job->right_import_guid = $cat_import_guid[$cat_name];
                                 if (!isset($page_to_cat_keys[$cat_import_guid[$cat_name]])) {
                                     $stack->add_job($page_to_cat_job);
                                     // we don't give this one a guid ... doesn't need one
                                 }
                                 $page_to_cat_keys[$cat_import_guid[$cat_name]] = true;
                             }
                         }
                     }
                     //minisite_page_parent - these rels we need to do
                     $page_parent_job = new WordPressRelateItemsJob();
                     $page_parent_job->rel_id = relationship_id_of('minisite_page_parent');
                     $page_parent_job->left_import_guid = md5('page_guid_' . $the_item['wp_post_id']);
                     if (empty($the_item['wp_post_parent'])) {
                         $page_parent_job->right_id = $this->get_site_root($this->get_value('reason_site'));
                     } else {
                         $page_parent_job->right_import_guid = md5('page_guid_' . $the_item['wp_post_parent']);
                     }
                     $page_parent_job_guid = $stack->add_job($page_parent_job);
                     $url_history_job = new WordPressURLHistoryJob();
                     if ($the_item['guid'] && $the_item['guid_is_permalink'] == "true") {
                         $url_history_job->wp_permalink = $the_item['guid'];
                     }
                     $url_history_job->wp_link = $the_item['link'];
                     $url_history_job->rel_guid = $page_parent_job_guid;
                     $url_history_job->entity_guid = md5('page_guid_' . $the_item['wp_post_id']);
                     $stack->add_job($url_history_job);
                     $this->rewrites_needed = true;
                 } elseif (strtolower($the_item['wp_post_type']) == 'post') {
                     if (!empty($the_item['excerpt_encoded'])) {
                         $reason_description = $the_item['excerpt_encoded'];
                     } elseif (!empty($the_item['description'])) {
                         $reason_description = $the_item['description'];
                     } else {
                         $words = explode(' ', $the_item['content_encoded'], 50);
                         unset($words[count($words) - 1]);
                         $reason_description = implode(' ', $words) . '…';
                         $reason_description = trim(tidy($reason_description));
                     }
                     /**
                      * its not clear to me what the various dates represent but in my sample xml file post_date seems to be the only item consistently populated
                      * and so we are going to use it for the dated.datetime value.
                      */
                     // CREATE THE IMPORT JOB AND SAVE IF IT IS NOT ALREADY CACHED
                     $post_import_job = new WordPressEntityCreationJob();
                     $post_import_job->type_id = id_of('news');
                     $post_import_job->site_id = $this->get_value('reason_site');
                     $post_import_job->user_id = $this->controller->reason_user_id;
                     $post_import_job->entity_info = array('name' => $the_item['title'], 'release_title' => $the_item['title'], 'description' => tidy($reason_description), 'content' => tidy($the_item['content_encoded']), 'status' => $the_item['wp_status'] == 'publish' ? 'published' : 'pending', 'show_hide' => $the_item['wp_status'] == 'publish' ? 'show' : 'hide', 'datetime' => $the_item['wp_post_date'], 'commenting_state' => $the_item['wp_comment_status'] == 'open' ? 'on' : 'off', 'author' => $the_item['dc_creator']);
                     $import_guid = $stack->add_job($post_import_job);
                     // now we want to add a job that relates the post to the publication - we have to do this using our import_guids
                     $relationship_job = new WordPressRelateItemsJob();
                     $relationship_job->rel_id = relationship_id_of('news_to_publication');
                     $relationship_job->left_import_guid = $import_guid;
                     $relationship_job->right_import_guid = $pub_import_guid;
                     $stack->add_job($relationship_job);
                     // we don't give this one a guid ... doesn't need one
                     $news_rewrite_alert_job = new WordPressNewsRewriteAlertJob();
                     $news_rewrite_alert_job->page_id_guid = $pub_page_guid;
                     $news_rewrite_alert_job->story_id_guid = $import_guid;
                     $news_rewrite_alert_job->original_url = $the_item['link'];
                     $news_rewrite_alert_job->report_preformatted_job = $report_preformatted_job;
                     $stack->add_job($news_rewrite_alert_job);
                     // lets do category rels and test the stack mechanism at the same time!
                     if (!empty($item->category)) {
                         foreach ($item->category as $k => $category) {
                             $news_cat = array();
                             $cat_name = $category->tagData;
                             $news_cat[] = $cat_name;
                             while (isset($parent_cat[$cat_name])) {
                                 $cat_name = $parent_cat[$cat_name];
                                 $news_cat[] = $cat_name;
                             }
                             foreach ($news_cat as $cat_name) {
                                 // add a job to relate the post to the category
                                 $news_to_cat_job = new WordPressRelateItemsJob();
                                 $news_to_cat_job->rel_id = relationship_id_of('news_to_category');
                                 $news_to_cat_job->left_import_guid = $import_guid;
                                 // the news item
                                 $news_to_cat_job->right_import_guid = $cat_import_guid[$cat_name];
                                 if (!isset($news_to_cat_keys[$cat_import_guid[$cat_name]])) {
                                     $stack->add_job($news_to_cat_job);
                                     // we don't give this one a guid ... doesn't need one
                                 }
                                 $news_to_cat_keys[$cat_import_guid[$cat_name]] = true;
                             }
                         }
                     }
                     if (!empty($item->wp_comment)) {
                         // ensure comment type is on the site
                         if (!isset($make_sure_comments_are_on_site)) {
                             $job = new WordPressEnsureTypeIsOnSite();
                             $job->site_id = $this->get_value('reason_site');
                             $job->type_id = id_of('comment_type');
                             $stack->add_job($job);
                             $make_sure_comments_are_on_site = true;
                         }
                         foreach ($item->wp_comment as $k => $comment) {
                             $the_comment = array();
                             // STRAIGHT OUT OF WORDPRESS
                             $the_comment['id'] = $comment->wp_comment_id[0]->tagData;
                             $the_comment['author'] = strip_tags($comment->wp_comment_author[0]->tagData);
                             $the_comment['author_email'] = $comment->wp_comment_author_email[0]->tagData;
                             $the_comment['author_url'] = $comment->wp_comment_author_url[0]->tagData;
                             $the_comment['author_IP'] = $comment->wp_comment_author_ip[0]->tagData;
                             $the_comment['date'] = $comment->wp_comment_date[0]->tagData;
                             $the_comment['content'] = trim(tidy($this->wpautop($comment->wp_comment_content[0]->tagData)));
                             $the_comment['approved'] = $comment->wp_comment_approved[0]->tagData;
                             $should_import = !$this->only_import_approved_comments || $the_comment['approved'] == '1';
                             // WE MAKE THIS ONE IF IT HAS CONTENT
                             if (!empty($the_comment['content']) && $should_import) {
                                 $words = explode(' ', strip_tags($the_comment['content']), 10);
                                 unset($words[count($words) - 1]);
                                 $name = trim(implode(' ', $words)) . '…';
                                 $comment_import_guid = md5('comment_id_' . $the_comment['id']);
                                 $comment_import_job = new WordPressEntityCreationJob();
                                 $comment_import_job->type_id = id_of('comment_type');
                                 $comment_import_job->site_id = $this->get_value('reason_site');
                                 $comment_import_job->user_id = $this->controller->reason_user_id;
                                 $comment_import_job->entity_info = array('name' => $name, 'content' => $the_comment['content'], 'author' => strip_tags($the_comment['author']), 'show_hide' => $the_comment['approved'] == '1' ? 'show' : 'hide', 'datetime' => $the_comment['date'], 'new' => 0);
                                 $stack->add_job($comment_import_job, $comment_import_guid);
                                 // now we want to add a job that relates the comment to the post - we use import guids
                                 $comment_relationship_job = new WordPressRelateItemsJob();
                                 $comment_relationship_job->rel_id = relationship_id_of('news_to_comment');
                                 $comment_relationship_job->left_import_guid = $import_guid;
                                 $comment_relationship_job->right_import_guid = $comment_import_guid;
                                 $stack->add_job($comment_relationship_job);
                                 // we don't give this one a guid ... doesn't need one
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($this->rewrites_needed) {
         $rewrite_job = new WordPressSiteRewritesJob();
         $rewrite_job->site_id = $this->get_value('reason_site');
         $stack->add_job($rewrite_job);
     }
     if (isset($report_preformatted_job)) {
         $stack->add_job($report_preformatted_job);
     }
     // lets save the stack in a cache with our $uid
     $cache = new ReasonObjectCache($this->uid);
     $cache->set($stack);
 }
Exemplo n.º 11
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;
	}
Exemplo n.º 12
0
 function show_reinstate()
 {
     if (!isset($this->history[$this->admin_page->request['archive_id']])) {
         echo '<p>This version was not found. <a href="' . $this->admin_page->make_link(array()) . '">Return</a></p>' . "\n";
     } elseif (empty($this->_locks[$this->admin_page->request['archive_id']])) {
         $id = $this->admin_page->request['archive_id'];
         $e = new entity($id);
         $values = $e->get_values();
         $old_id = $this->admin_page->id;
         $old = new entity($old_id);
         $old_values = $old->get_values();
         if (isset($values['id'])) {
             unset($values['id']);
         }
         if (isset($values['last_modified'])) {
             unset($values['last_modified']);
         }
         $values['state'] = 'Live';
         reason_update_entity($this->admin_page->id, $this->admin_page->user_id, $values);
         // if this is a page, lets check a few things - we may have to run rewrites or clear the nav cache
         if ($this->admin_page->type_id == id_of('minisite_page')) {
             // do we need to clear the nav cache?
             if ($values['url_fragment'] != $old_values['url_fragment'] || $values['name'] != $old_values['name'] || $values['link_name'] != $old_values['link_name'] || $values['nav_display'] != $old_values['nav_display'] || $values['sort_order'] != $old_values['sort_order'] || $old_values['state'] != 'Live') {
                 reason_include_once('classes/object_cache.php');
                 $cache = new ReasonObjectCache($this->admin_page->site_id . '_navigation_cache');
                 $cache->clear();
             }
             // if the page was formerly pending or the url_fragment has changed, run rewrites.
             if ($old_values['state'] == 'Pending' || $values['url_fragment'] != $old_values['url_fragment']) {
                 reason_include_once('classes/url_manager.php');
                 $urlm = new url_manager($this->admin_page->site_id);
                 $urlm->update_rewrites();
             }
         }
         header('Location: ' . unhtmlentities($this->admin_page->make_link(array('id' => $this->admin_page->id))));
         die;
     } else {
         echo '<p>This version cannot be reinstated becase doing so would change a locked field. <a href="' . $this->admin_page->make_link(array()) . '">Return</a></p>' . "\n";
     }
 }
	/**
	 * This method will clear the news item cache generated by this module for a site and page
	 * @todo implement something to call this
	 */
	function clear_cache($site_id = '', $page_id = '')
	{
		$site_id = ($site_id) ? $site_id : $this->site_id;
		$page_id = ($page_id) ? $page_id : $this->page_id;
		if ($site_id && $page_id)
		{
			$cache = new ReasonObjectCache($this->get_cache_id($site_id, $page_id));
			$cache->clear();
		}
		else trigger_error('clear_cache needs a site_id and page_id');	
	}	
 function run_job()
 {
     reason_include_once('classes/object_cache.php');
     $site_ids = $this->config('site_ids');
     foreach ($site_ids as $site_id) {
         $cache = new ReasonObjectCache($site_id . '_navigation_cache');
         $cache->clear();
     }
     $this->set_report('Zapped the navigation cache for site id(s) ' . implode(', ', $site_ids) . '.');
     return true;
 }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
0
/**
 * Create/refresh the relationship name cache from the database.
 * 
 * @return array unique names
 */
function reason_refresh_relationship_names()
{
    $cache = new ReasonObjectCache('reason_relationship_names');
    $cache->lock(10);
    $dbq = new DBSelector();
    $dbq->add_table('allowable_relationship');
    $dbq->add_field('allowable_relationship', 'id');
    $dbq->add_field('allowable_relationship', 'name');
    $r = db_query($dbq->get_query(), 'Error getting relationship anmes in reason_refresh_relationship_names');
    while ($row = mysql_fetch_array($r)) {
        $retrieved[$row['name']] = (int) $row['id'];
    }
    mysql_free_result($r);
    if (!empty($retrieved)) {
        if ($result = $cache->set($retrieved)) {
            relationship_id_of('site_to_type', false);
            // refresh the relationship_id_of static cache
        }
        $cache->unlock();
        return $retrieved;
    } else {
        trigger_error('reason_refresh_relationship_names did not update the cache because no relationship names were retrieved');
    }
    return array();
}
Exemplo n.º 17
0
 function _set_item_cache(&$items)
 {
     if ($this->get_cache_lifespan() > 0) {
         $item_cache = new ReasonObjectCache($this->get_cache_id(), $this->get_cache_lifespan());
         $item_cache->set($items);
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 18
0
// force login to a session
$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');
Exemplo n.º 19
0
 /**
  * After we save the title change we also need to destroy the navigation cache for the site.
  */
 function process_editable(&$disco)
 {
     $page = new entity($this->page_id);
     $values['name'] = trim(strip_tags($disco->get_value('page_title')));
     if ($page->get_value('name') != $values['name']) {
         $user_id = get_user_id(reason_check_authentication());
         reason_update_entity($this->page_id, $user_id, $values, true);
         // clear nav cache
         reason_include_once('classes/object_cache.php');
         $cache = new ReasonObjectCache($this->site_id . '_navigation_cache');
         $cache->clear();
     }
 }
Exemplo n.º 20
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;
 }
Exemplo n.º 21
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;
 }
Exemplo n.º 22
0
 function set_excluded($excluded_array)
 {
     $id = $this->_get_cache_id();
     $cache = new ReasonObjectCache($id);
     return $cache->set($excluded_array);
 }