/**
	 * Returns a reference to an array with data about ordered news items
	 */
	function &build_news_items($publication_unique_name = NULL)
	{
		$pub_id = $this->get_publication_id();
		if ($pub_id)
		{
			// The idea of this entity selector is to select all news items that are related to the publication
			// along with the news item owner and id and publication id(s) other than the named publication ...
			// The result should be news items along with a site entity id and publication id(s) - we'll use that
			// data to help build the link.
			
			$es = new entity_selector(); // try without site_id for now ... allows this to be used anywhere with a unique publication name
			$es->add_type(id_of('news'));
			$es->enable_multivalue_results();
			$es->limit_tables(array('press_release', 'dated', 'status'));
			$es->limit_fields(array('press_release.release_title', 'dated.datetime', 'status.status'));
			$es->add_left_relationship($pub_id, relationship_id_of('news_to_publication'));
			$alias = $es->add_left_relationship_field('news_to_publication', 'entity', 'id', 'pub_id');
			$es->add_relation($alias['pub_id']['table'] . '.' . $alias['pub_id']['field'] . " != " . $pub_id);
			$es->add_right_relationship_field('owns', 'entity', 'id', 'site_id');
			$es->add_relation('status.status = "published"');
			$es->set_order('dated.datetime DESC');
			$result = $es->run_one();
			
			if (!empty($result))
			{
				$result_keys = array_keys($result);
				$rpts =& get_reason_page_types();
				$valid_page_types = $rpts->get_page_type_names_that_use_module($this->publication_modules);
				foreach (array_keys($valid_page_types) as $k) quote_walk($valid_page_types[$k], NULL);
				foreach ($result_keys as $key)
				{
					$success = $this->augment_entity($result[$key], $valid_page_types);
					if ($success)
					{
						$result[$key]->unset_value('pub_id');
						$result[$key]->unset_value('site_id');
					}
					else unset($result[$key]);
				}
			}
			$news_items =& $this->set_order_and_limits($result);
			
		}
		else
		{
			trigger_error('The module needs a publication unique name or a page associated with a publication to select borrowed news items');
			$news_items = array();
		}
		
		
		return $news_items;
	}
Esempio n. 2
0
 function setup_associated_items()
 {
     // populate associated entity selector from scratch
     $ass_es = new entity_selector();
     $ass_es->add_type($this->type_id);
     if ($this->rel_direction == 'a_to_b') {
         $ass_es->add_right_relationship($this->admin_page->id, $this->admin_page->rel_id);
     } else {
         $ass_es->add_left_relationship($this->admin_page->id, $this->admin_page->rel_id);
     }
     $ass_es->add_right_relationship_field('owns', 'entity', 'id', 'site_owner_id');
     if ($this->rel_direction == 'a_to_b' && $this->check_is_rel_sortable()) {
         $this->columns['rel_sort_order'] = true;
         $ass_es->add_field('relationship', 'id', 'rel_id');
         $ass_es->add_rel_sort_field($this->admin_page->id);
         $ass_es->set_order('relationship.rel_sort_order ASC');
         if ($this->_cur_user_has_edit_privs() && !$this->get_relationship_lock_state()) {
             $this->alter_order_enable = true;
         }
     } else {
         $ass_es->add_field('relationship', 'site', 'rel_site_id');
     }
     if ($this->assoc_viewer_order_by($ass_es)) {
         $this->alter_order_enable = false;
     }
     $this->ass_vals = $ass_es->run_one();
     // check sharing on associated entities
     foreach ($this->ass_vals as $k => $val) {
         // setup sharing value
         if ($this->site_id == $val->get_value('site_owner_id')) {
             $this->ass_vals[$k]->set_value('sharing', 'owns');
         } else {
             $this->ass_vals[$k]->set_value('sharing', $this->check_borrow_status($k));
         }
     }
     // this verifies and updates the associated items rel_sort_order if this is an a to b relationship
     if ($this->rel_direction == 'a_to_b' && $this->check_is_rel_sortable()) {
         if (count($this->ass_vals) == 1 && isset($this->columns['rel_sort_order'])) {
             unset($this->columns['rel_sort_order']);
         }
         if ($ass_es->orderby == 'relationship.rel_sort_order ASC') {
             $rel_update_array = $this->validate_rel_sort_order($this->ass_vals, true);
         } else {
             $rel_update_array = $this->validate_rel_sort_order($this->ass_vals);
         }
         if (count($rel_update_array) > 0) {
             foreach ($rel_update_array as $k => $v) {
                 update_relationship($k, array('rel_sort_order' => $v));
             }
         }
     }
 }
 function get_orphans($max = NULL, $refresh_cache = false)
 {
     if ($refresh_cache || !$this->_orphans_grabbed) {
         $e = new entity_selector();
         $e->limit_tables();
         $e->limit_fields();
         if (empty($this->_types)) {
             $types = $e->run_one(id_of('type'));
         } else {
             $types = $this->_types;
         }
         $sites = $e->run_one(id_of('site'), 'All');
         foreach ($types as $type_id => $type) {
             $e = new entity_selector();
             $e->add_type($type_id);
             $e->limit_tables();
             $e->limit_fields();
             $alias = $e->add_right_relationship_field('owns', 'entity', 'id', 'site_id');
             $field = $alias['site_id']['table'] . '.' . $alias['site_id']['field'];
             $e->add_relation($field . ' IN ("' . implode('","', array_keys($sites)) . '")');
             $non_orphans = $e->run_one('', 'All');
             $e = new entity_selector();
             $e->add_type($type_id);
             $e->limit_tables(array('entity'));
             $e->limit_fields();
             if (!empty($non_orphans)) {
                 $e->add_relation('entity.id NOT IN ("' . implode('","', array_keys($non_orphans)) . '")');
             }
             $orphans = $e->run_one('', 'All');
             if (!empty($orphans)) {
                 $this->_orphans[$type_id] = $orphans;
                 if (!empty($max)) {
                     $total = count($this->_orphans[$type_id]);
                     $max = $max - $total;
                     if ($max < 1) {
                         $length = count($this->_orphans[$type_id]) + $max;
                         $this->_orphans[$type_id] = array_slice($this->_orphans[$type_id], 0, $length, true);
                         $this->maxed_type = array('type' => $type_id, 'total' => $total);
                         break;
                     }
                 }
             }
         }
     }
     return $this->_orphans;
 }
Esempio n. 4
0
 /**
  * If the current site has the publication type, find the feed url for the oldest publication and redirect
  */
 function publication_check($site)
 {
     $es = new entity_selector($site->id());
     $es->add_type(id_of('publication_type'));
     $es->add_right_relationship_field('news_to_publication', 'entity', 'id', 'news_id');
     $es->limit_tables('entity');
     $es->limit_fields('entity.creation_date');
     $es->set_num(1);
     $es->set_order('entity.creation_date ASC');
     $result = $es->run_one();
     if ($result) {
         $id_array = array_keys($result);
         $ph = new publicationHelper(reset($id_array));
         // should I bother with the helper or just do it here?
         $feed_url = $ph->get_feed_url($site->id());
         if ($feed_url) {
             header("Location: " . $feed_url, true, 301);
         }
     }
 }
Esempio n. 5
0
 function _get_active_users_from_ids($ids, $affiliations)
 {
     @array_walk($ids, 'addslashes');
     $es = new entity_selector();
     $es->add_type(id_of('user'));
     $es->enable_multivalue_results();
     $es->add_relation('`entity`.`id` IN ("' . implode('","', $ids) . '")');
     $es->add_right_relationship_field('site_to_user', 'entity', 'id', 'site_membership_id');
     // This is here so we only grab users who have access to a site
     $users = $es->run_one();
     if (!empty($affiliations)) {
         // Construct a directory service ldap filter query to only include the possible users.
         $dir = new directory_service();
         $filter = $this->_get_ldap_filter($affiliations, $users);
         $dir->search_by_filter($filter);
         $dir_results = $dir->get_records();
         $users = $this->_get_users($users, array_keys($dir_results));
     }
     return $users;
 }
Esempio n. 6
0
 function display_right_relationships()
 {
     $rels = $this->get_right_relationships();
     if (!empty($rels)) {
         $associated_items = array();
         foreach ($rels as $key => $v) {
             $es = new entity_selector();
             $es->add_type($v['relationship_a']);
             $es->set_env('site', $this->admin_page->site_id);
             $es->add_left_relationship($this->admin_page->id, $v['id']);
             $es->set_env('restrict_site', false);
             $es->add_right_relationship_field('owns', 'entity', 'name', 'owner_name');
             $es->add_right_relationship_field('owns', 'entity', 'id', 'owner_id');
             $ass_items = $es->run_one();
             if (!empty($ass_items)) {
                 $associated_items[$key] = $ass_items;
             }
         }
         if (!empty($associated_items)) {
             echo '<h3>Usage</h3>' . "\n";
             echo '<ul>' . "\n";
             foreach ($rels as $key => $v) {
                 if (!empty($associated_items[$key])) {
                     $is_borrows_rel = !reason_relationship_names_are_unique() ? $v['name'] == 'borrows' : $v['type'] == 'borrows';
                     if ($is_borrows_rel) {
                         $type = new entity($this->_entity->get_value('type'));
                         $title = 'Sites That Are Borrowing This ' . $type->get_value('name');
                         $show_owner_site = false;
                     } else {
                         $show_owner_site = true;
                         $row = $this->get_rel_info($v['name']);
                         if ($row) {
                             $title = !empty($row['description_reverse_direction']) ? $row['description_reverse_direction'] : $row['entity_name'];
                         } else {
                             $title = !empty($v['description_reverse_direction']) ? $v['description_reverse_direction'] : $v['name'];
                         }
                     }
                     echo '<li><h4>';
                     if (!$this->_entity->user_can_edit_relationship($v['id'], $this->_user, 'left')) {
                         echo '<img class="lockIndicator" src="' . REASON_HTTP_BASE_PATH . 'ui_images/lock_12px.png" alt="Locked" width="12" height="12" />';
                     } elseif ($this->_entity->relationship_has_lock($v['id'], 'left') && reason_user_has_privs($this->_user->id(), 'manage_locks')) {
                         echo '<img class="lockIndicator" src="' . REASON_HTTP_BASE_PATH . 'ui_images/lock_12px_grey_trans.png" alt="Locked for some users" title="Locked for some users" width="12" height="12" />';
                     }
                     echo $title . ':</h4>' . "\n";
                     echo '<ul>' . "\n";
                     foreach ($associated_items[$key] as $ent) {
                         echo '<li>' . $this->_get_rel_list_display_name($ent, $v['name'], 'right');
                         if ($show_owner_site && $ent->get_value('owner_id') != $this->admin_page->site_id) {
                             //echo ' <em>(<a href="http://'.REASON_HOST.$ent->get_value('owner_base_url').'">'.$ent->get_value('owner_name').'</a>)</em>';
                             echo ' <em>(' . $ent->get_value('owner_name') . ')</em>';
                         }
                         echo '</li>' . "\n";
                     }
                     echo '</ul>' . "\n";
                     echo '</li>' . "\n";
                 }
             }
             echo '</ul>' . "\n";
         }
     }
 }
Esempio n. 7
0
		/**
		 * Grab featured items from related publications and populate $featured_items[$pub_id]
		 *
		 * - We optimize and sort differently depending on how many related publications we are picking from.
		 * - If just one, we use relationship_sort_order, otherwise we do datetime DESC.
		 */
		function get_related_featured_items()
		{
			$featured_items = array();
			$related_pub_ids = implode(",", array_keys($this->related_publications));
			if ($this->show_featured_items && !empty($related_pub_ids))
			{
				if (count($this->related_publications) > 1) // we use dated.datetime DESC for sort order
				{
					$es = new entity_selector( $this->site_id );
					$es->description = 'Selecting featured news items from related publications';
					$es->add_type( id_of('news') );
					$es->set_env('site', $this->site_id);
					$alias['rel_pub_id'] = current($es->add_right_relationship_field( 'publication_to_featured_post', 'entity', 'id', 'related_publication_id' ));
					$alias['pub_id'] = current($es->add_left_relationship_field( 'news_to_publication', 'entity', 'id', 'publication_id' ));
					$es->add_relation($alias['rel_pub_id']['table'] . '.id IN ('.$related_pub_ids.')');
					$es->add_relation($alias['rel_pub_id']['table'] . '.id = '.$alias['pub_id']['table'] . '.id');
					$es->add_relation('status.status = "published"');
					$es->set_order('dated.datetime DESC');
					$fi = $es->run_one();
					if (!empty($fi))
					{
						foreach($fi as $k=>$v)
						{
							$featured_items[$k] = $v;
						}
					}
				}
				else // lets use relationship sort order since we have only 1 related publication.
				{
					$related_pub_id = $related_pub_ids;
					$es = new entity_selector( $this->site_id );
					$es->description = 'Selecting featured news items from a single related publication';
					$es->add_type( id_of('news') );
					$es->set_env('site', $this->site_id);
					$es->add_right_relationship( $related_pub_id, relationship_id_of('publication_to_featured_post') );
					$es->add_left_relationship( $related_pub_id, relationship_id_of('news_to_publication') );
					$es->add_rel_sort_field($related_pub_id, relationship_id_of('publication_to_featured_post'), 'featured_sort_order');
					$es->set_order('featured_sort_order ASC');
					
					$fi = $es->run_one();
					if (!empty($fi))
					{
						foreach($fi as $k=>$v)
						{
							$featured_items[$k] = $v;
							$featured_items[$k]->set_value('publication_id', $related_pub_id);
							$featured_items[$k]->set_value('related_publication_id', $related_pub_id);
						}
					}
				}
			}
			return $featured_items;
		}
Esempio n. 8
0
 function update_es()
 {
     // lets find the sites that share the type (except the current site) and limit our query to those sites
     $prep_es = new entity_selector();
     $prep_es->add_type(id_of('site'));
     $prep_es->add_left_relationship($this->admin_page->type_id, relationship_id_of('site_shares_type'));
     if ($this->site_is_live()) {
         $prep_es->limit_tables('site');
         $prep_es->limit_fields('site.site_state');
         $prep_es->add_relation('site.site_state = "Live"');
         $prep_es->add_relation('entity.id != "' . $this->admin_page->site_id . '"');
     } else {
         $prep_es->limit_tables();
         $prep_es->limit_fields();
     }
     $this->sites_that_borrow_type = $prep_es->run_one();
     $es = new entity_selector();
     $es->add_type($this->admin_page->type_id);
     $limiter = !empty($this->admin_page->request['search_site']) ? $this->admin_page->request['search_site'] : array_keys($this->sites_that_borrow_type);
     if (empty($limiter)) {
         $limiter = array("-1");
     }
     // no sites share type lets limit to site_id = -1, which will be no sites - this avoids a crash.
     $es->add_right_relationship_field('owns', 'entity', 'id', 'site_id', $limiter);
     $es->add_right_relationship_field('owns', 'entity', 'name', 'site');
     $this->apply_order_and_limits($es);
     $es->add_relation('(entity.no_share IS NULL OR entity.no_share = 0)');
     // entity is shared
     $this->es = $es;
 }
Esempio n. 9
0
		/**
		 * A nice handler for missing av things. Attempts to point the user to another
		 * place to access the item, even if that place is on another site.
		 * 
		 * Takes the ID of a missing item and looks for it on pages that use a page 
		 * type which uses a module defined in the module set 'av_module_derivatives'.
		 * Requires reason_page_types and reason_module_sets.
		 * 
		 * @param $id int The entity ID of the missing item
		 * @return null;
		 * 
		 */
		function handle_missing_item($id)
		{
			// Get the list of modules
			reason_include_once('classes/module_sets.php');
			$ms =& reason_get_module_sets();
			$av_module_derivatives = $ms->get("av_module_derivatives");
			
			// Get the page types that use these modules.
			$rpts =& get_reason_page_types();
			$allowed_page_types = array();
			foreach ($av_module_derivatives as $mod){
				$allowed_page_types = array_merge($allowed_page_types, array_diff($rpts->get_page_type_names_that_use_module($mod), $allowed_page_types));
			}
			
			// Turn this list into a string.
			$serialized = "'" . implode("','", $allowed_page_types) . "'";
			
			// Build the ES
			$es = new entity_selector();
			$es->add_type(id_of('minisite_page'));
			$es->add_left_relationship($id, relationship_id_of('minisite_page_to_av'));
			$es->add_right_relationship_field('owns', 'entity', 'name', 'site_name');
			$es->add_relation("page_node.custom_page IN ($serialized)");
			$result = $es->run_one();

			echo '<div class="notice itemNotAvailable"><h3>Sorry -- this item is not available</h3>';
			// If there are suitable replacements found, display them...
			if (!empty($result))
			{
				$url = parse_url(get_current_url());
				
				if (count($result) == 1)
				{
					$new_page_link = reason_get_page_url(current($result)->id()) . '?' . $url['query'];
					header( 'Location: ' . $new_page_link, true, 301 );
					exit;
				}
				echo "<p>However, you might be able to find it at the following location" . ((count($result)-1) ? "s" : "" ) . ":</p>\n<ul>\n";
				foreach ($result as $key => $entity)
				{
					// Don't forget to pass a nice query string that includes the item of the av as well as the av_file_id if it's in the request.
					echo '<li><a href="' . reason_get_page_url($key) . "?" . $url['query'] . "\">{$entity->get_value("site_name")}: {$entity->get_value("name")}</a></li>";
				}
				echo "</ul>";
			} else {
			// Else just echo the normal 404. 
				echo '<p>This might be because...</p><ul><li>the page you are coming from has a bad link</li><li>there is a typo in the web address</li><li>the item you are requesting has been removed</li></ul>';
			}
			echo "</div>";
		}
Esempio n. 10
0
	/**
	 * Build the feature set
	 */
	function _build_features()
	{
		$es1 = new entity_selector( $this->site_id );
		$es1->add_type( id_of('feature_type') );
		$es1->add_right_relationship( $this->page_id, relationship_id_of('page_to_feature'));
		$es1->add_rel_sort_field( $this->page_id, relationship_id_of('page_to_feature') );
		$es1->set_order('rel_sort_order ASC');
		if($this->params['max'] != 0)
		{
			$es1->set_num($this->params['max']);
		}
		$features = $es1->run_one();
		
		if(empty($features))
		{
			return null;
		}
	
		$es2 = new entity_selector( $this->site_id );
		$es2->add_type( id_of('image') );
		$es2->add_right_relationship_field( 'feature_to_image','entity','id','feature_id', array_keys($features) );
		$es2->enable_multivalue_results();
		$images = $es2->run_one();
		if ($images)
		{
			foreach ($images as $image_id => $image)
			{
				$features_with_image = $image->get_value('feature_id');
				$features_with_image = (!is_array($features_with_image)) ? array($features_with_image) : $features_with_image; // force to array
				foreach ($features_with_image as $feature_id)
				{
					$feature_extra[$feature_id]['image_id'][] = $image_id;
				}
			}
		}

		$es3 = new entity_selector( $this->site_id );
		$es3->add_type( id_of('av') );
		$es3->add_right_relationship_field( 'feature_to_media_work','entity','id','av_id', array_keys($features) );
		$es3->enable_multivalue_results();
		$media_works = $es3->run_one();
		if ($media_works)
		{
			foreach ($media_works as $media_work_id => $media_work)
			{
				$features_with_media_work = $media_work->get_value('av_id');
				$features_with_media_work = (!is_array($features_with_media_work)) ? array($features_with_media_work) : $features_with_media_work; // force to array
				foreach ($features_with_media_work as $feature_id)
				{
					$feature_extra[$feature_id]['av_id'][] = $media_work_id;
				}
			}
		}
		
		// augment our features with images and media works
		foreach($features as $feature_id => $feature)
		{
			if (isset($feature_extra[$feature_id]['image_id']))
			{
				$value = (count($feature_extra[$feature_id]['image_id']) == 1) ? reset($feature_extra[$feature_id]['image_id']) : $feature_extra[$feature_id]['image_id'];
				$features[$feature_id]->set_value('image_id',$value);
			}
			else $features[$feature_id]->set_value('image_id',"none");
			
			if (isset($feature_extra[$feature_id]['av_id']))
			{
				$value = (count($feature_extra[$feature_id]['av_id']) == 1) ? reset($feature_extra[$feature_id]['av_id']) : $feature_extra[$feature_id]['av_id'];
				$features[$feature_id]->set_value('av_id',$value);
			}
			else $features[$feature_id]->set_value('av_id',"none");
		}
		
		//shuffle the features if set to true
		//note that keys are preserved in the new
		//shuffled feature array
		if($this->params['shuffle']==true)
		{
			$shuffled_results=array();
			$temps=array();
			$temps=$features;
			shuffle($temps);
			foreach($temps as $temp)
			{
				$id=$temp->get_value('id');
				$shuffled_results[$id]=$temp;
			}
			$features=$shuffled_results;
		}
		//pick a random media work or image from each features list of images.
		foreach($features as $id=>$r)
		{
			$num_imgs=0;
			$num_mdia=0;
			$i=0;
			if($features[$id]->has_value('image_id'))
			{
				$img_id=$features[$id]->get_value('image_id');
				if($img_id!="none")
				{
					$num_imgs=count($img_id);
				}
			}
			else
			{
				$features[$id]->set_value('image_id','none');
			}
			if($features[$id]->has_value('av_id'))
			{
				$av_id=$features[$id]->get_value('av_id');
				if($av_id !="none")
				{
					$num_mdia=count($av_id);
				}
			}
			else
			{
				$features[$id]->set_value('av_id','none');
			}

			$num_objects=$num_imgs+$num_mdia;

			$i=rand(0, $num_objects-1 );
			if($i<$num_mdia)
			{
				$features[$id]->set_value('current_object_type','av');
				$features[$id]->set_value('current_image_index',$i);
			}
			else
			{
				$features[$id]->set_value('current_object_type','img');
				$features[$id]->set_value('current_image_index',$i-$num_mdia);
			}
		}

		//set default values for items that are not set
		foreach($features as $id=>$r)
		{
			$cp=$features[$id]->get_value('crop_style');
			if($cp==null){ $features[$id]->set_value('crop_style','fill');}
			
		}
		$this->_features=$features;
		
		//if feature id is on this page then display it
		//else redirect to same page but this feature not set
		if(isset($this->request['feature']))
		{
			$feature_id=$this->request['feature'];
			$is_a_feature_on_this_page=false;
			foreach($this->_features as $feat)
			{
				if($feature_id==$feat->get_value('id'))
				{
					$is_a_feature_on_this_page=true;
					break;
				}
			}
			if($is_a_feature_on_this_page)
			{
				$this->current_feature_id=$this->request['feature'];
			}
			else
			{
				$url=carl_make_redirect(array('feature'=>''),'');
				header("Location: ".$url);
			}
		}
		$this->_build_view_data();
	}
Esempio n. 11
0
reason_include_once('classes/url/page.php');
include_once CARL_UTIL_INC . 'basic/misc.php';
echo '<!DOCTYPE html>' . "\n";
echo '<html><head><title>Reason: Modules</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>';
//if (!carl_is_php5()) xdebug_start_profiling();
$current_user = reason_require_authentication();
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' => '')));
Esempio n. 12
0
 /**
  * Grabs a list of all publications and events attached to the site, offers them to 
  * 
  * The bulk of this form step. 
  * 
  * 
  */
 function init($args = array())
 {
     parent::init($args);
     $site_id = (int) $_REQUEST['site_id'];
     // Only do this init if we're on the step that needs it.
     if ($this->controller->get_current_step() != 'SelectIncludes') {
         return;
     }
     //////////////// PUBLICATIONS /////////////////
     // Select all publications that are attached to this site.
     $pub_factory = new PubHelperFactory();
     $es = new entity_selector($site_id);
     $es->add_type(id_of('publication_type'));
     // Add the page_id to which the pub belongs (so we can get url)
     $es->add_right_relationship_field('page_to_publication', 'entity', 'id', 'page_id');
     $es->enable_multivalue_results();
     $es->set_entity_factory($pub_factory);
     $pub_helper_entities = $es->run_one();
     if ($pub_helper_entities) {
         $this->add_element('pub_posts_header1', 'comment', array('text' => '<h2 class="region">Publications</h2>'));
         foreach ($pub_helper_entities as $ph) {
             $name = $ph->get_value('name');
             $entityID = $ph->get_value('id');
             $page_id = $ph->get_value('page_id');
             if (is_array($page_id)) {
                 $strlength = 0;
                 $page_url = '';
                 foreach ($page_id as $one_id) {
                     $page_entity = new entity($one_id);
                     if ($page_entity->get_value('state') == 'Live') {
                         $owner = $page_entity->get_owner();
                         if ($owner->get_value('state') == 'Live') {
                             $url = reason_get_page_url($one_id);
                             if (strlen($url) > $strlength) {
                                 $strlength = strlen($url);
                                 $page_url = $url;
                             }
                         }
                     }
                 }
                 $box_name = '<a target="_blank" href="' . $page_url . '">' . $name . '</a>';
                 $opts[$entityID] = $box_name;
             } else {
                 $page_entity = new entity($page_id);
                 if ($page_entity->get_value('state') == 'Live') {
                     $owner = $page_entity->get_owner();
                     if ($owner->get_value('state') == 'Live') {
                         $page_url = reason_get_page_url($page_id);
                         $box_name = '<a target="_blank" href="' . $page_url . '">' . $name . '</a>';
                         $opts[$entityID] = $box_name;
                     }
                 }
             }
         }
         $this->add_element('selected_publications', 'checkboxgroup', array('options' => $opts));
         $this->set_value('selected_publications', array_keys($opts));
         $this->set_display_name('selected_publications', 'Select the publications from which you wish to draw posts');
         $this->add_element('publication_start_date', 'textDate');
         $monthAgo = date("Y-m-d", strtotime("-1 month"));
         $today = date("Y-m-d", time());
         $this->set_value('publication_start_date', $monthAgo);
         $this->set_display_name('publication_start_date', 'From this date');
         $this->add_element('publication_end_date', 'textDate');
         $this->set_value('publication_end_date', $today);
         $this->set_display_name('publication_end_date', 'To this date');
     }
     //////////////// EVENTS ///////////////////
     // !todo: Find any page on the site $site_id which uses the module 'events', and list
     // 		  that page title as a 'calendar' (there are apparently no calendar entities,
     //		  only the events module which acts as a calendar.
     //		  The extra information should be found in the page_type def for the page containing
     //		  the events module.
     /* $eh = new reasonCalendar();
     		
     		$site = new entity($site_id);
     		$cal = new reasonCalendar(array('site'=>$site));
     		$cal->run();
     		$events = $cal->get_all_events(); */
     $es = new entity_selector($site_id);
     $es->add_type(id_of('event_type'));
     $es->set_num(1);
     $es->limit_tables();
     $es->limit_fields();
     $events = $es->run_one();
     if ($events) {
         $this->add_element('events_header1', 'comment', array('text' => '<h2 class="region">Calendars</h2>'));
         $this->add_element('events_start_date', 'textDate');
         $monthAhead = date("Y-m-d", strtotime("+1 month"));
         $today = date("Y-m-d", time());
         $this->set_value('events_start_date', $today);
         $this->set_display_name('events_start_date', 'From this date');
         $this->add_element('events_end_date', 'textDate');
         $this->set_value('events_end_date', $monthAhead);
         $this->set_display_name('events_end_date', 'To this date');
     }
     if (!$events && !$pub_helper_entities) {
         $this->add_element('sucks_to_be_you', 'comment', array('text' => '<h3>There are no publications or calendars associated with this site. Press continue if you would like to use the newsletter builder anyway.'));
     }
 }
Esempio n. 13
0
    }
    if (!empty($_REQUEST['theme_id'])) {
        $es->add_left_relationship((int) $_REQUEST['theme_id'], relationship_id_of('site_to_theme'));
    }
    $sites = $es->run_one();
    $site_ids = array_keys($sites);
    if (empty($site_ids)) {
        $site_ids = array(0);
    }
}
// grab all the pages along with their page type
$es = new entity_selector($site_ids);
$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_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();
shuffle($result);
// we lose ids due to the shuffle but we don't care
if (empty($result)) {
    echo '<h3>No results.</h3>';
    echo '</body>';
    echo '</html>';
    die;
}
$rpt =& get_reason_page_types();
// lets parse the entities and build our data set
foreach ($result as $page) {