/** * 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); } }
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']); } }
/** * 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); } }
/** * * @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); }
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; } }
/** * 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(); }
function set_cache() { if ($this->get_cache_lifespan() > 0) { $cache = new ReasonObjectCache($this->get_cache_id()); $cache->set($this->quote_pool); } }
function set_cache() { if ($this->get_cache_lifespan() > 0) { $cache = new ReasonObjectCache($this->get_cache_id()); $cache->set($this->events); $cache = new ReasonObjectCache($this->get_cache_id() . '_cal'); $cache->set($this->calendar); } }
/** * 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(); } } // }}}
function set_excluded($excluded_array) { $id = $this->_get_cache_id(); $cache = new ReasonObjectCache($id); return $cache->set($excluded_array); }
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; }
/** * Create and return a submission key generated from the current submission * @param object disco_obj */ function create_form_submission_key() { $values = $this->get_values_for_save(); $str = get_mysql_datetime(); foreach ($values as $val) $str = $str . $val; $key = md5($str); $sk = new ReasonObjectCache($key, '60'); // only last for a minute $sk->set(true); return $key; }
/** * 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; }