function refresh_cache()
 {
     $url = reason_get_page_url($this->get_page());
     $result = get_reason_url_contents($url);
     if ($result) {
         $this->report('Rebuilt the cache by hitting ' . $url);
     }
 }
Example #2
0
 function display_entity()
 {
     $this->start_table();
     // iFrame Preview
     if (!$this->_entity->get_value('url') && $this->_entity->get_value('state') == 'Live') {
         // iFrame Preview
         reason_include_once('function_libraries/URL_History.php');
         $url = reason_get_page_url($this->_entity->id());
         if ($url) {
             //$this->show_item_default( 'Public View of Page' , '<iframe src="'.$url.'" width="100%" height="400"></iframe>' );
             // iframe replacement method
             // http://intranation.com/test-cases/object-vs-iframe/
             //  classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13"
             $this->show_item_default('Public View of Page', '<object type="text/html" data="' . $url . '" class="pageViewer"></object><p><a href="' . $url . '" target="_new">Open page in new window</a></p>');
             //$this->show_item_default( 'Public View of Page' , '<iframe src="'.$url.'" class="pageViewer"></iframe><p><a href="'.$url.'" target="_new">Open page in new window</a></p>');
         }
     }
     //
     $this->show_item_default('Cache Status', $this->get_cache_status());
     // Everything Else
     $this->show_all_values($this->_entity->get_values());
     $this->end_table();
 }
Example #3
0
 function display_entity()
 {
     $this->start_table();
     // iFrame Preview
     if ($this->_entity->get_value('bug_state') != 'Done') {
         // iFrame Preview
         reason_include_once('function_libraries/URL_History.php');
         $site = $this->_entity->get_owner();
         $es = new entity_selector($site->id());
         $es->add_type(id_of('minisite_page'));
         $es->add_relation('page_node.custom_page = "projects"');
         $es->set_num(1);
         $pages = $es->run_one();
         if (!empty($pages)) {
             $page = current($pages);
             $url = reason_get_page_url($page->id()) . '?item_id=' . $this->_entity->id();
             $this->show_item_default('Public View of Project', '<iframe src="' . $url . '" width="100%" height="400"></iframe>');
             $this->show_item_default('Link to Public View of Project', '<a href="' . $url . '">' . $url . '</a>');
         }
     }
     // Everything Else
     $this->show_all_values($this->_entity->get_values());
     $this->end_table();
 }
 function get_item_url($k, &$page)
 {
     return reason_get_page_url($page) . '?story_id=' . $k;
 }
 /**
  * Return information about new settings
  * @return string HTML report
  */
 public function run()
 {
     $str = '';
     $str .= '<h4>Page Types That Should Be Changed or Deleted</h4>';
     if ($deprecated = $this->get_page_types_using_deprecated_news_modules()) {
         $str .= '<p>The following pages types (and reason pages) look to be using deleted news modules and should be updated or removed.</p>';
         $str .= '<ul>';
         foreach ($deprecated as $page_type_name => $pages) {
             $str .= '<li>' . $page_type_name;
             if (!empty($pages)) {
                 $str .= '<ul>';
                 foreach ($pages as $id => $page) {
                     $url = @reason_get_page_url($id);
                     $str .= '<li>';
                     if ($url) {
                         $str .= '<a href="' . $url . '">' . $page->get_value('name') . '</a> (Page ID ' . $id . ')';
                     } else {
                         $str .= $page->get_value('name') . ' (Page ID ' . $id . ' - URL not available)';
                     }
                     $str .= '</li>';
                 }
                 $str .= '</ul>';
             }
             $str .= '</li>';
         }
         $str .= '</ul>';
     } else {
         $str .= '<p>None found.</p>';
     }
     $str .= '<h4>Pages Using Deleted News Page Types</h4>';
     if ($pages_using_missing_page_types = $this->get_pages_using_now_missing_page_types()) {
         $str .= '<ul>';
         foreach ($pages_using_missing_page_types as $id => $page) {
             $url = @reason_get_page_url($id);
             $name = $page->get_value('name');
             $str .= '<li><a href="' . $url . '">' . $name . '</a></li>';
         }
         $str .= '</ul>';
     } else {
         $str .= '<p>None found.</p>';
     }
     return $str;
 }
 function set_page_link(&$e)
 {
     $owner_site = $e->get_owner();
     if ($owner_site) {
         $ps = new entity_selector($owner_site->id());
         $ps->add_type(id_of('minisite_page'));
         $rels = array();
         foreach ($this->get_events_page_types() as $page_type) {
             $rels[] = 'page_node.custom_page = "' . $page_type . '"';
         }
         $ps->add_relation('( ' . implode(' OR ', $rels) . ' )');
         $page_array = $ps->run_one();
         reset($page_array);
         $events_page = current($page_array);
         if (!empty($events_page)) {
             $ret = reason_get_page_url($events_page->id());
         }
         if (!empty($ret)) {
             $e->set_value('url', sprintf('%s?event_id=%d&date=%s', $ret, $e->id(), $e->get_value('date')));
         }
     } else {
         trigger_error('set_page_link called on an event (id ' . $e->id() . ') that does not have an owner site id - a url could not be set');
     }
 }
 function init($args = array())
 {
     parent::init($args);
     if ($this->controller->get_current_step() != 'SelectItems') {
         return;
     }
     if ($this->controller->get_form_data('selected_publications') != '' || $this->controller->get_form_data('events_start_date') != '') {
         $this->add_element('select_instructions', 'comment', array('text' => '<p>Items from the publications and calendar dates which you picked are displayed below. Select the posts and events that you would like to include in your newsletter from the lists below.</p>'));
     }
     if ($this->controller->get_form_data('selected_publications') != '') {
         $pubs = $this->controller->get_form_data('selected_publications');
         $this->add_element('pub_items_header', 'comment', array('text' => '<h2 class="region">Posts</h2>'));
         foreach ($pubs as $pub) {
             $post_options = array();
             $ph_new = new PublicationHelper($pub);
             if ($startDate = $this->controller->get_form_data('publication_start_date')) {
                 $ph_new->set_start_date($startDate);
             }
             if ($endDate = $this->controller->get_form_data('publication_end_date')) {
                 $ph_new->set_end_date($endDate);
             }
             $pub_posts = $ph_new->get_published_items();
             $page_of_publication = $ph_new->get_right_relationship('page_to_publication');
             if ($pub_posts) {
                 foreach ($pub_posts as $pub_post) {
                     $available_posts[$pub][$pub_post->get_value('id')] = array('id' => $pub_post->get_value('id'), 'name' => $pub_post->get_value('name'), 'date_released' => $pub_post->get_value('datetime'), 'created_by' => $pub_post->get_value('created_by'), 'url' => reason_get_page_url($page_of_publication[0]->get_value('id')) . "?story_id=" . $pub_post->get_value('id'));
                 }
             }
             if (!empty($available_posts)) {
                 if (empty($available_posts[$pub])) {
                     $this->add_element("pub_items_number_{$pub}", 'comment', array('text' => '<p>No live posts were found for the publication "' . $ph_new->get_value('name') . '".</p>'));
                 } else {
                     $count = count($available_posts[$pub]);
                     $text = "{$count}" . ($count > 1 ? ' posts were' : ' post was');
                     $text .= ' found for the publication "' . $ph_new->get_value('name') . '"';
                     foreach ($available_posts[$pub] as $post) {
                         $post_options[$post['id'] . '_post'] = $post['name'] . ' (<a target="_blank" href="' . $post['url'] . '">link</a>)';
                         //						$this->add_element($item['id'].'_info', 'comment', array('text' => '<p>Date released: '.$item['date_released'].'</p>'));
                     }
                     $this->add_element("pub_posts_group_{$pub}", 'checkboxgroup', array('options' => $post_options));
                     $this->set_display_name("pub_posts_group_{$pub}", $text);
                 }
             } else {
                 $this->add_element("pub_items_none_{$pub}", 'comment', array('text' => '<p>No posts were found for "' . $ph_new->get_value('name') . '" during the selected timeframe.</p>'));
             }
         }
     }
     if ($this->controller->get_form_data('events_start_date') != '') {
         $site_id = (int) $_REQUEST['site_id'];
         $site = new entity($site_id);
         $start_date = $this->controller->get_form_data('events_start_date');
         $end_date = $this->controller->get_form_data('events_end_date');
         $end_date = !empty($end_date) ? $end_date : date('Y-m-d');
         $cal = new reasonCalendar(array('site' => $site, 'start_date' => $start_date, 'end_date' => $end_date));
         $cal->run();
         $events = $cal->get_all_events();
         $days = $cal->get_all_days();
         $this->add_element('events_header', 'comment', array('text' => '<h2 class="region">Calendar events</h2>'));
         if ($days) {
             // This is a bit of a hack. We want to know the number of deepest-level elements
             // _before_ we've  iterated through the array, creating elements for each deepest-level
             // element... hence the double foreach.
             $count = 0;
             foreach ($days as $day => $event_ID_array) {
                 foreach ($event_ID_array as $event_item) {
                     $count++;
                 }
             }
             $text = "<p>{$count}" . ($count > 1 ? ' calendar events were found.</p>' : ' calendar event was found.</p>');
             $this->add_element('events_number', 'comment', array('text' => $text));
             foreach ($days as $day => $event_ID_array) {
                 $event_options = array();
                 $events_from_today = array();
                 foreach ($event_ID_array as $event_ID) {
                     $events_from_today[$event_ID] = $events[$event_ID];
                 }
                 uasort($events_from_today, "sort_events");
                 foreach ($events_from_today as $event_id => $event_item) {
                     $prettyDate = date("g:i a", strtotime($event_item->get_value('datetime')));
                     $eHelper = new EventHelper();
                     @$eHelper->set_page_link($event_item);
                     $eventURL = $event_item->get_value('url') . date("Y-m-d", strtotime($event_item->get_value('datetime')));
                     $event_options[$event_id . '_event'] = '<strong>' . $prettyDate . '</strong> ' . $event_item->get_value('name') . ' (<a target="_blank" href="' . $eventURL . '">link</a>)';
                 }
                 $this->add_element('events_group_day_' . $day, 'checkboxgroup_no_sort', array('options' => $event_options));
                 $rows[] = date("D, M j Y", strtotime($day));
                 $elements_to_add_to_group['events_group_day_' . $day] = 'events_group_day_' . $day;
             }
             $args = array('rows' => $rows, 'use_element_labels' => false, 'use_group_display_name' => false, 'wrapper_class' => 'events_wrapper');
             $this->add_element_group('wrappertable', 'events_group', $elements_to_add_to_group, $args);
         } else {
             $this->add_element('events_number', 'comment', array('text' => '<p>No events were found.</p>'));
         }
     }
 }
Example #8
0
		function get_events_page_url()
		{
			if(!$this->queried_for_events_page_url)
			{
				reason_include_once('classes/module_sets.php');
				$ms =& reason_get_module_sets();
				$modules = $ms->get('event_display');
				$rpts =& get_reason_page_types();
				$events_page_types = $rpts->get_page_type_names_that_use_module($modules);
				$ps = new entity_selector($this->site_id );
				$ps->add_type( id_of('minisite_page') );
				$ps->set_num(1);
				$rels = array();
				foreach($events_page_types as $page_type)
				{
					$rels[] = 'page_node.custom_page = "'.$page_type.'"';
				}
				$ps->add_relation('( '.implode(' OR ', $rels).' )');
				$page_array = $ps->run_one();
				if (!empty($page_array))
				{
					$events_page = current($page_array);
					$this->events_page_url = reason_get_page_url($events_page->id());
				}
			}
			return $this->events_page_url;
		}
Example #9
0
		/**
		 * A function to get the page link when the parent_unique_name param has been specified.
		 *
		 * - if the page is on the same site we use the page tree directly.
		 * - If not, we just use reason_get_page_url() since it is faster than building the whole tree.
		 *
		 * @return string href attribute
		 */
		function get_page_link_other_parent($page)
		{
			if ($this->parent_page_is_on_current_site() && ($pages = $this->get_page_nav())) // we can use the page tree
			{
				return $pages->get_url_from_base($page->id()); // relative to our site
			}
			else
			{
				return reason_get_page_url($page->id()); // absolute to some other site or page tree is not available
			}
		}
    die;
}
$rpt =& get_reason_page_types();
// lets parse the entities and build our data set
foreach ($result as $page) {
    $page_type = trim($page->get_value('custom_page')) ? trim($page->get_value('custom_page')) : 'default';
    // no page type is considered default by reason
    if (!isset($data_pages[$page_type]['page_type'])) {
        $data_pages[$page_type]['page_type'] = $page_type;
    }
    if (!isset($data_pages[$page_type]['location'])) {
        $pt = @$rpt->get_page_type($page_type);
        $data_pages[$page_type]['location'] = is_object($pt) ? $pt->get_location() : "";
    }
    if (!isset($data_pages[$page_type]['url'])) {
        $data_pages[$page_type]['url'] = '<a href="' . reason_get_page_url($page) . '">' . reason_get_page_url($page) . '</a>';
    }
    if (!isset($data_pages[$page_type]['count'])) {
        $data_pages[$page_type]['count'] = 1;
    } else {
        $data_pages[$page_type]['count']++;
    }
}
// lets add page_types that do not exist
$page_types_no_pages = array_diff(array_values($rpt->get_page_type_names()), array_keys($data_pages));
foreach ($page_types_no_pages as $page_type_no_page) {
    $data_pages[$page_type_no_page]['page_type'] = $page_type_no_page;
    $pt = @$rpt->get_page_type($page_type_no_page);
    $data_pages[$page_type_no_page]['location'] = is_object($pt) ? $pt->get_location() : "";
    $data_pages[$page_type_no_page]['url'] = '';
    $data_pages[$page_type_no_page]['count'] = 0;
     }
     while ($i <= $count && $equal) {
         $i++;
         $old = current($old_order_images);
         next($old_order_images);
         $new = current($new_order_images);
         next($new_order_images);
         //echo gettype($old);
         //echo gettype($new);
         if ($old->id() != $new->id()) {
             $equal = false;
         }
     }
     if (!$equal) {
         $num++;
         echo '<li><a href="' . reason_get_page_url($id) . '" target="_new">' . $id . ': ' . $page->get_value('name') . '</a>';
         if ($_POST['go'] == 'run') {
             //
             if ($updater->update_image_relationships($new_order_images, array_keys($old_order_images))) {
                 echo '...Updated';
             } else {
                 echo '...Not updated!';
             }
         }
         echo '</li>' . "\n";
     }
 }
 if ($num == 0) {
     echo '<li>None</li>' . "\n";
 }
 echo '</ul>' . "\n";
Example #12
0
/**
 * Header the browser to the current location of the most recent page
 * that occupied a given URL
 *
 * How it works:
 *
 * 1. Looks for the URL in the URL_history table. 
 *
 * 2. If there is no URL, send a 404 header. 
 *    If there are URLs, send a 301 header and a Location header to the
 *    location of the live page that most recent inhabited that URL.
 *
 * Important: Because it may attempt to header the client to a different URL, 
 * this method must be called before any output is started, or in the context
 * of output buffering. 
 *
 * @param string $request_uri a URL relative to the host root (e.g. /foo/bar/)
 * @return NULL
 *
 * @todo modify to make multidomain safe
 */
function check_URL_history($request_uri)
{
    $url_arr = parse_URL($request_uri);
    // This catches links that might not have had a trailing slash
    // pages always have a trailing slash in the db
    $URL = '/' . trim_slashes($url_arr['path']) . '/';
    $URL = str_replace('//', '/', $URL);
    $query_string = !empty($url_arr['query']) ? '?' . $url_arr['query'] : '';
    $query = 'SELECT * FROM URL_history WHERE url ="' . reason_sql_string_escape($URL) . '" ORDER BY timestamp DESC';
    $results = db_query($query);
    $num_results = mysql_num_rows($results);
    if (mysql_num_rows($results) > 0) {
        while ($row = mysql_fetch_array($results)) {
            $page_id = $row['page_id'];
            $page = new entity($page_id);
            if (reason_is_entity($page, 'minisite_page') && $page->get_value('state') == 'Live' && ($redir = @reason_get_page_url($page))) {
                if ($redir == $request_uri) {
                    //Could potentially update rewrites here, solving most times this happens, perhaps.
                    trigger_error("A page should exist here, but apparently does not at the moment. A web administrator may need to run URL updating on this site.");
                } else {
                    header('Location: ' . $redir . $query_string, true, 301);
                    exit;
                }
            }
        }
    }
    // if we have gotten this far and not found a URL lets send a 404
    http_response_code(404);
}
Example #13
0
 function get_site_link()
 {
     if ($p = $this->_get_page()) {
         $this->site_link = reason_get_page_url($p);
     } else {
         parent::get_site_link();
     }
 }
 /**
  * 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.'));
     }
 }
Example #15
0
 /**
  * Lets set some extra values - specifically ... the URL!
  * 
  * @todo instead of just supressing errors in reason_get_page_url perhaps we should flag these pages somehow?
  */
 function _augment_page_entities(&$entities)
 {
     foreach ($entities as $k => $a_fun_page_entity) {
         $url = @reason_get_page_url($a_fun_page_entity);
         $entities[$k]->set_value('page_url', $url);
     }
 }
Example #16
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>";
		}
Example #17
0
/**
 * Takes get_all_form_data() and turns it into something sensible.
 * 
 * Assemble_data expects an array from get_all_form_data(). Good 
 * luck hacking this, as the format is pretty specific. It expects data from a form that looks like this:
 * 
 * <code>
 * 	var $elements = array(
 *		'newsletter_title' => array(
 *		    'display_name' => 'Newsletter Title',
 *		    'type' => 'text',
 *		),
 *		'newsletter_intro' => array(
 *		    'display_name' => 'Write a message to precede the body of the newsletter',
 *		    'type' => 'textarea',
 *		),
 *	);
 * $publication_checkboxes = array(
 *		id_of_post . '_post' => 'display name of this post',
 *		id_of_another_post . '_post' => 'display name of another post',
 * );
 * $this->add_element('pub_posts_group_' . this_publication_id, 'checkboxgroup', array('options'=>$publication_checkboxes);
 * $events_checkboxes = array(
 * 		id_of_the_event . '_event' => 'display name of some event',
 * 		id_of_another_event . '_event' => 'display name of another event'
 * );
 * $this->add_element('events_group_' . date_of_these_events, 'checkboxgroup', $events_checkboxes);
 * </code>
 * 
 * The output of get_all_form_data() for such a form ends up looking 
 * like this (except it generally has a lot of garbage too):
 * 
 * <code>
 * array
 *   'newsletter_title' => string 'A newsletter title'
 *   'newsletter_intro' => string 'Just do the best you can -- but be sure it's your very best.'
 *   'pub_posts_group_556743' => 
 *        array
 *          0 => string '632296_post'
 *          1 => string '635739_post'
 *          2 => string '628269_post'
 *   'pub_posts_group_642174' => boolean false
 *   'events_header' => null
 *   'events_number' => null
 *   'events_group_day_2010-04-14' => 
 *     array
 *       0 => string '618385_event'
 *       1 => string '618389_event'
 * </code>
 * 
 * The output of assemble_data() then transforms this into something
 * meaningful. The same dump after assemble_data():
 * <code>
 *  array
 *   'info' => 
 *     array
 *       'title' => string 'A newsletter title'
 *       'intro' => string 'Just do the best you can -- but be sure it's your very best.'
 *       'urls' => 
 *         array
 *           'Marlena's Blog' => string 'https://bacon.test.carleton.edu/admissions/blogs/marlena/'
 *   'pubs' => 
 *     array
 *       'Marlena's Blog' => 
 *         array
 *           0 => 
 *             some post entity
 *           1 => 
 *             some post entity
 *           2 => 
 *             some post entity
 *   'events' => 
 *     array
 *       '2010-04-14' => 
 *         array
 *           0 => 
 *             some event entity
 *           1 => 
 *             some event entity
 * </code>
 * Much better, don't you think?
 * 
 * @param array $dump The output of get_all_form_data
 * @return array An array with the format described above.
 */
function assemble_data($dump)
{
    $assembled_data['info'] = array('title' => htmlspecialchars($dump['newsletter_title']), 'intro' => preg_replace("/\n/i", "<br />", htmlspecialchars($dump['newsletter_intro'])));
    foreach ($dump as $item => $value) {
        if (is_array($value)) {
            if (preg_match("/^pub_posts_group_/", $item) != 0) {
                $pub_entity_id = preg_replace("/^pub_posts_group_/", '', $item);
                $ph = new PublicationHelper($pub_entity_id);
                $pub_page = $ph->get_right_relationship('page_to_publication');
                $pub_url = reason_get_page_url($pub_page[0]->get_value('id'));
                $pub_id = $ph->get_value('id');
                $assembled_data['info']['urls'][$pub_id] = $pub_url;
                foreach ($value as $key => $pub_post_id) {
                    $entity_id = preg_replace('/_post$/', '', $pub_post_id);
                    $assembled_data['pubs'][$pub_id][] = new entity($entity_id);
                }
            }
            if (preg_match("/^events_group_day_/", $item) != 0) {
                foreach ($value as $key => $event_option_name) {
                    $entity_id = preg_replace('/_event$/', '', $event_option_name);
                    $date = preg_replace('/^events_group_day_/', '', $item);
                    $date = preg_replace('/_.*/', '', $date);
                    $assembled_data['events'][$date][] = new entity($entity_id);
                }
            }
        }
    }
    if (!empty($assembled_data['pubs'])) {
        foreach ($assembled_data['pubs'] as $pub_id => $posts) {
            usort($posts, "sort_pubs");
            $assembled_data['pubs'][$pub_id] = $posts;
        }
    }
    if (!empty($assembled_data['events'])) {
        foreach ($assembled_data['events'] as $date => $events) {
            usort($events, "sort_events");
            $assembled_data['events'][$date] = $events;
        }
    }
    return $assembled_data;
}