function run_job()
 {
     reason_include_once('minisite_templates/nav_classes/default.php');
     $page_ids = $this->config('page_ids');
     $id = reset($page_ids);
     $page = new entity($id);
     $site = $page->get_owner();
     // lets make and get the page tree
     $page_tree = new MinisiteNavigation();
     $page_tree->order_by = 'sortable.sort_order';
     $page_tree->init($site->id(), id_of('minisite_page'));
     foreach ($page_ids as $page_id) {
         $children = $page_tree->children($page_id);
         $diff = array_diff($children, $page_ids);
         // are we trying to move a page without its children?
         if (!empty($diff)) {
             $problem[] = 'Cannot move page id ' . $page_id . ' without also moving child pages with ids (' . implode(", ", $diff) . ')';
         }
     }
     if (isset($problem)) {
         $report = 'Blocking any further jobs. When moving pages you need to move entire branches';
         $report .= '<ul>';
         $report .= '<li>' . implode("</li><li>", $problem) . '</li>';
         $report .= '</ul>';
         $this->set_report($report);
         $this->block_jobs();
         return false;
     } else {
         $this->set_report('Verified that the page tree integrity is preserved with this move.');
     }
     return true;
 }
示例#2
0
 function checkPermissions()
 {
     // first, make sure user is logged in
     $username = reason_check_authentication();
     if (!$username) {
         $this->error("this page requires authentication");
     } else {
         // next, figure out the form id
         $matches = array();
         $res = preg_match("/form_(\\d*)/", $this->table, $matches);
         if (count($matches) != 2) {
             $this->error("invalid table name");
         } else {
             $formId = $matches[1];
             // now that we've got the form id, find out what site it belongs to
             $form = new entity($formId);
             $site = $form->get_owner();
             // and finally, make sure the logged in user has access to the site, and is an admin
             $hasSiteAccess = reason_username_has_access_to_site($username, $site->id());
             // $isAdmin = user_is_a(get_user_id($username), id_of("admin_role"));
             // return $hasSiteAccess && $isAdmin;
             return $hasSiteAccess;
         }
     }
     return false;
 }
示例#3
0
 function &get_form()
 {
     if (!isset($this->_form)) {
         $form = new entity($this->admin_page->id);
         if ($form->get_values() && $form->get_value('type') == id_of('form')) {
             $owner = $form->get_owner();
             if ($owner->id() == $this->admin_page->site_id) {
                 $this->_form = $form;
             }
         }
         if (!isset($this->_form)) {
             $this->_form = false;
         }
     }
     return $this->_form;
 }
function create_image_entity($media_work, $username)
{
    $name = $media_work->get_value('name') . ' (Generated Thumbnail)';
    $values = array();
    $values['new'] = '0';
    $values['description'] = 'A thumbnail image for Vimeo media work ' . $media_work->get_value('name');
    $values['no_share'] = '0';
    $e = new entity($media_work->get_value('id'));
    $site_id = $e->get_owner()->id();
    if ($username) {
        return reason_create_entity($site_id, id_of('image'), get_user_id($username), $name, $values);
    } else {
        echo date(DATE_RFC822) . ': Empty username. Could not create image entity for Media Work with id ' . $media_work->get_value('id') . '.' . "\n";
    }
    return false;
}
示例#5
0
 function _get_rel_site_value($id)
 {
     $e = new entity($id);
     $owner = $e->get_owner();
     if ($owner->id() == $this->get_value('site_id')) {
         return 0;
     } else {
         return $this->get_value('site_id');
     }
 }
	/** duplicate_entity( $id, $dup_relationships = true, $maintain_dates = false, $overrides = array() ) {{{
	 *	Duplicates entity with id = $id.
	 *
	 *	Specifically, copies all fields of an entity to a new id.  If dup_relationships
	 *	is true, also copies all relationships, replacing the old id with the new inserted one.
	 *
	 *	@param	$id						ID of entity to duplicate
	 *									OR an entity object to duplicate
	 *	@param	$dup_relationships		Bool that determines whether to duplicate relationships or not
	 *	@param	$maintain_dates			Bool that determines whether to 
	 *	@param	$overrides				array of field => value pairs to override any values for the new entity
	 *	@return							the new, duplicated entity id
	 */
	function duplicate_entity( $id, $dup_relationships = true, $maintain_dates = false, $overrides = array() )
	{
		// get all values and structure from existing object
		if( is_object( $id ) AND get_class( $id ) == 'entity' )
			$e = $id;
		else
			$e = new entity( $id );

		// get the site that owns this entity
		$site = $e->get_owner();
		
		// get the tables used by this type/entity
		$tables = get_entity_tables_by_id( $e->id() );

		//! start of new code (see commented note below)

		$ignored_fields = array( 'id', 'name', 'type', 'last_edited_by' );

		if( !$maintain_dates )
		{
			$ignored_fields[] = 'last_modified';
			$ignored_fields[] = 'creation_date';
		}

		// Don't ignore values set as overrides
		foreach ($ignored_fields as $key => $val)
			if (isset($overrides[$val])) unset ($ignored_fields[$key]);
		
		// convert values of entity to tabled-array structure, make sure to ignore proper fields
		$values = values_to_tables( $tables, array_merge( $e->get_values(), $overrides ), $ignored_fields );
		
		// create new entity record
		$new_entity_id = create_entity(
			$site->id(), 
			$e->get_value('type'), 
			$e->get_value('last_edited_by'), 
			$e->get_value('name'), 
			$values
		);

		// copy relationships
		if( $dup_relationships )
		{
			// make new left relationships
			$left_rels = $e->get_left_relationships();
			foreach( $left_rels AS $rel_type => $rel_obj )
			{
				if( is_int( $rel_type ) )
				{
					foreach( $rel_obj AS $r )
						create_relationship( $new_entity_id, $r->id(), $rel_type );
				}
			}
			// make new right relationships
			$right_rels = $e->get_right_relationships();
			foreach( $right_rels AS $rel_type => $rel_obj )
			{
				if( is_int( $rel_type ) )
				{
					foreach( $rel_obj AS $r )
						create_relationship( $r->id(), $new_entity_id, $rel_type );
				}
			}
		}

		// return the new entity
		return $new_entity_id;
	} // }}}
 function create_image_entity($username)
 {
     $name = $this->manager->get_value('name') . ' (Generated Thumbnail)';
     $values = array();
     $values['new'] = '0';
     $values['description'] = 'A thumbnail image for Vimeo media work ' . $this->manager->get_value('name');
     $values['no_share'] = '0';
     $e = new entity($this->manager->get_value('id'));
     $site_id = $e->get_owner()->id();
     if ($username) {
         return reason_create_entity($site_id, id_of('image'), get_user_id($username), $name, $values);
     }
     return false;
 }
 function process_confirm()
 {
     foreach ($this->admin_page->request['orphan'] as $type_id => $orphans) {
         $type_site = htmlspecialchars($this->admin_page->request['type_site_' . $type_id], ENT_QUOTES);
         $sites = $this->omi->get_types_to_sites($type_id);
         foreach ($orphans as $orphan_id => $action) {
             $orphan = new entity($orphan_id);
             if (!$orphan->get_owner()) {
                 if ($action == 'move' && isset($type_site) && array_key_exists($type_site, $sites)) {
                     if ($orphan->get_value('type') == id_of('minisite_page') && $orphan->has_relation_with_entity($orphan_id)) {
                         $this->delete_orphan_page_parent($orphan_id);
                     }
                     $this->omi->move_into_site($orphan_id, $type_id, $type_site);
                     $site = $sites[$type_site];
                     echo 'Moved orphan id ' . $orphan_id . ' into site: ' . $site->get_value('name') . '<br />';
                 } else {
                     if ($action == 'delete') {
                         $this->omi->delete_orphan($orphan_id);
                         echo 'Deleted orphan id ' . $orphan_id . '<br />';
                     }
                 }
             }
         }
     }
 }
示例#9
0
	/**
	 * Initialize the module
	 */
	function init( $args = array() )
	{
		parent::init( $args );
		
		if(!empty($this->params['list_type']))
		{
			if('verbose' == $this->params['list_type'] && '' == $this->params['list_item_markup'])
			{
				$this->params['list_item_markup'] = 'minisite_templates/modules/events_markup/verbose/verbose_events_list_item.php';
				trigger_error('Events module: list_type parameter is deprecated and will stop working in Reason 4.6. Please specify "list_item_markup" => "'.$this->params['list_item_markup'].'" instead.');
			}
			elseif('schedule' == $this->params['list_type'] && '' == $this->params['list_markup'])
			{
				$this->params['list_markup'] = 'minisite_templates/modules/events_markup/schedule/schedule_events_list.php';
				$this->params['list_item_markup'] = 'minisite_templates/modules/events_markup/schedule/schedule_events_list_item.php';
				trigger_error('Events module: list_type parameter is deprecated and will stop working in Reason 4.6. Please specify "list_markup" => "'.$this->params['list_markup'].'", "list_item_markup" => "'.$this->params['list_item_markup'].'" instead.');
			}
		}
		
		$this->validate_inputs();
		
		$this->register_passables();
		
		$this->handle_jump();
				
		if(empty($this->request['event_id']))
		{
			$this->init_list();
		}
		else
			$this->init_event();		
		$inline_edit =& get_reason_inline_editing($this->page_id);
		$inline_edit->register_module($this, $this->user_can_inline_edit());
		if ($inline_edit->active_for_module($this))
		{
			$user = reason_get_current_user_entity();
			$event_id = $this->request['event_id'];
			/* Event adding is currently not functional
			if( !($event_id = $this->request['event_id'] ) )
			{
				if(reason_user_has_privs($user->id(), 'add' ))
				{
					if ($event_id = create_entity( $this->site_id, id_of('event_type'), $user->id(), '', array( 'entity' => array( 'state' => 'Pending' ) ) ))
					{					
						// We have to do a few things to trick the module into
						// recognizing a new event
						$this->request['event_id'] = $event_id;
						$this->init_event();
						$this->_ok_to_show[$event_id] = true;
					}
				}
			}*/
			
			if ($user && $event = new entity($event_id))
			{
				reason_include_once('classes/admin/admin_page.php');
				reason_include_once('classes/admin/modules/editor.php');
				$site = $event->get_owner();
				
				// Create a new admin page object and set some values to make it
				// think it's running in the admin context.
				$admin_page = new AdminPage();
				$admin_page->id = $event->id();
				$admin_page->site_id = $site->id();
				$admin_page->type_id = id_of('event_type');
				$admin_page->user_id = $user->id(); 
				$admin_page->request = array();
				$admin_page->head_items =& $this->get_head_items();
	
				// Create a new editor with the admin page. This will pick the 
				// appropriate editor class and set up the disco form.
				$this->edit_handler = new EditorModule( $admin_page );
				$this->edit_handler->head_items =& $this->get_head_items();
				$this->edit_handler->init();
				
				$this->edit_handler->disco_item->actions = array('finish' => 'Save');
				$this->edit_handler->disco_item->add_callback(array($this,'editor_where_to'),'where_to');
			}
		}
		if(!empty($this->params['wrapper_id']))
			$this->div_id = $this->params['wrapper_id'];
		
		// get_run_output() should be the very last thing done before the end of init()
		// This is done to allow the markup classes to add head items
		$this->get_run_output();
	}
             echo 'Bad string ';
         }
         if ($multiples) {
             echo 'Multiple Items';
         }
         echo '</h3>';
         if ($multiples) {
             echo '<p>Items:</p>';
         } else {
             echo '<p>Item:</p>';
         }
         echo '<ul>';
         foreach ($items as $id => $name) {
             $ent = new entity($id);
             $type = new entity($ent->get_value('type'));
             $owner = $ent->get_owner();
             echo '<li>';
             echo '<strong>' . $name . '</strong>';
             echo '<ul>';
             echo '<li>ID: ' . $id . '</li>';
             echo '<li>State: ' . $ent->get_value('state') . '</li>';
             echo '<li>Type: ' . $type->get_value('name') . '</li>';
             echo '<li>Site: ' . $owner->get_value('name') . '</li>';
             echo '</ul>';
             echo '</li>';
         }
         echo '</ul>';
     } else {
         unset($uniques[$uname]);
     }
 }
 /**
  * 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.'));
     }
 }
/**
 * Get the URL of a Reason asset
 *
 * Returns a URL relative to the server base.
 *
 * @param entity $asset
 * @param entity $owner_site
 * @return string URL
 */
function reason_get_asset_url($asset, $owner_site = NULL)
{
    if (empty($owner_site)) {
        $owner_site = $asset->get_owner();
    }
    return $owner_site->get_value('base_url') . MINISITE_ASSETS_DIRECTORY_NAME . '/' . $asset->get_value('file_name');
}