예제 #1
0
 /**
  * Identify the images that should be displayed
  */
 function select_images()
 {
     // Initialize the images with appropriate entity selector properties
     $page_id = $this->page_id;
     if (!empty($this->params['alternate_source_page_id'])) {
         $page_id = $this->params['alternate_source_page_id'];
         if (!($site_id = get_owner_site_id($page_id))) {
             $site_id = $this->site_id;
         }
     } else {
         $page_id = $this->cur_page->id();
         $site_id = $this->site_id;
     }
     $es = new entity_selector();
     $es->add_type(id_of('image'));
     $es->set_env('site', $site_id);
     $es->add_right_relationship($page_id, relationship_id_of('minisite_page_to_image'));
     if ($this->params['rand_flag']) {
         $es->set_order('rand()');
     } elseif (!empty($this->params['order_by'])) {
         $es->set_order($this->params['order_by']);
     } else {
         $es->add_rel_sort_field($page_id, relationship_id_of('minisite_page_to_image'));
         $es->set_order('rel_sort_order');
     }
     if (!empty($this->params['num_to_display'])) {
         $es->set_num($this->params['num_to_display']);
     }
     $this->images = $es->run_one();
 }
예제 #2
0
function reason_iframe_get_media_work()
{
    static $media_work;
    if (isset($media_work)) {
        return $media_work;
    }
    if (!empty($_REQUEST['media_work_id'])) {
        $id = (int) $_REQUEST['media_work_id'];
        if ($id) {
            $media_work = new entity($id);
            if ($media_work->get_value('type') == id_of('av') && ($media_work->get_value('state') == 'Live' || user_can_edit_site(get_user_id(reason_check_authentication()), get_owner_site_id($id)))) {
                return $media_work;
            }
        }
    }
    $media_work = false;
    return $media_work;
}
예제 #3
0
 function _ok_to_run_module()
 {
     if ($this->_ok_to_run !== true && $this->_ok_to_run !== false) {
         $this->_ok_to_run = false;
         if (!$this->admin_page->id) {
             return $this->_ok_to_run;
         }
         $owner_site = get_owner_site_id($this->admin_page->id);
         $entity = new entity($this->admin_page->id);
         if ($owner_site == $this->admin_page->site_id) {
             $this->_ok_to_run = true;
             return $this->_ok_to_run;
         }
         if (site_borrows_entity($this->admin_page->site_id, $entity->id())) {
             $this->_ok_to_run = true;
             return $this->_ok_to_run;
         }
         if (site_shares_type($owner_site, $entity->get_value('type')) && $entity->get_value('no_share') == 0) {
             $this->_ok_to_run = true;
             return $this->_ok_to_run;
         }
     }
     return $this->_ok_to_run;
 }
예제 #4
0
 function delete_orphan($orphan_id)
 {
     if (empty($this->_user_id)) {
         trigger_error('Must set user id before calling delete_orphan()');
         return false;
     }
     if (!get_owner_site_id($orphan_id)) {
         return reason_expunge_entity($orphan_id, $this->_user_id);
     } else {
         trigger_error($orphan_id . ' not actually an orphan');
         return false;
     }
 }
예제 #5
0
		/**
		 * Determines whether or not the user can inline edit.
		 *
		 * Returns true in two cases:
		 *
		 * 1. User is a site administrator of the page the story belongs to.
		 * 2. User is the author of the post.
		 *
		 * @return boolean;
		 */
		function user_can_inline_edit()
		{
			if (!isset($this->_user_can_inline_edit))
			{
				if (!empty($this->current_item_id))
				{
					$story_id = $this->current_item_id;
					$story = new entity($story_id);
					if (reason_is_entity($story, 'news'))
					{
						$owner = get_owner_site_id($story_id);
						$this->_user_can_inline_edit = (!empty($owner) && reason_check_authentication() && ((reason_check_access_to_site($owner) || $this->user_is_author())));
					}
					else $this->_user_can_inline_edit = false;
				}
				else
				{
					$this->_user_can_inline_edit = false;
				}
			}
			return $this->_user_can_inline_edit;
		}
예제 #6
0
 function get_email_message()
 {
     $message = 'FYI, there are currently no recent posts on the Reason publication "' . $this->pub->get_value('name') . '."' . "\n\n";
     $message .= 'You are signed up to receive notices when this publication has not been updated in the last ' . $this->days . ' days.' . "\n\n";
     $message .= 'It may be time to add a new post! ';
     $message .= 'Click here to add posts to this publication: http://' . REASON_WEB_ADMIN_PATH . '?site_id=' . get_owner_site_id($this->pub->id()) . '&type_id=' . id_of('news') . "\n\n";
     $message .= 'If you are no longer responsible for this publication, please contact a Reason administrator to have this email sent to someone else.' . "\n\n";
     $message .= 'Thank you!' . "\n\n";
     return $message;
 }
 function get_display()
 {
     $i = 0;
     foreach ($this->options as $k => $val) {
         if (!isset($this->option_info[$k])) {
             trigger_error('Please set option_info for each option!');
             continue;
         }
         // build our checkbox
         //$store_key[$key] = "ture";
         $val = $this->option_info[$k]['values'];
         $id = $this->option_info[$k]['id'];
         $checkbox = '<input type="checkbox" id="' . $this->name . $i . '" name="' . $this->name . '[]" value="' . htmlspecialchars($k, ENT_QUOTES) . '"';
         if (in_array($k, $this->value)) {
             $checkbox .= ' checked="checked"';
         }
         //if ( $this->_is_current_value($k) ) $checkbox .= ' checked="checked"';
         //if ( $this->_is_disabled_option($k) ) $checkbox .= ' disabled="disabled"';
         $checkbox .= ' /> ' . $id;
         $e = new entity($id);
         $checkbox .= '<p class="name">Name: ' . $e->get_value('name') . '</p>';
         $owner = get_owner_site_id($id);
         if ($owner) {
             $site = new entity($owner);
             $checkbox .= '<p class="site">Site: ' . $site->get_value('name') . '</p>';
         } else {
             $checkbox .= '<p class="site">(No owner site)</p>';
         }
         $data[] = array('Find and Replace?' => $checkbox) + $val;
         $i++;
     }
     // data now contains the raw data needed for our table admin work;
     $entity_convert_fields = array_keys(reset($this->option_info));
     $ta = new TableAdmin();
     $ta->init_from_array($data);
     $ta->set_fields_that_allow_sorting(array());
     $ta->set_fields_to_entity_convert(array());
     // we are using html in our fields
     ob_start();
     $ta->run();
     $str = ob_get_contents();
     ob_end_clean();
     return $str;
 }
예제 #8
0
		/**
		 * We determine whether the parent_page is on the current site using the page tree if available or a direct query.
		 *
		 * @return boolean
		 */
		function parent_page_is_on_current_site()
		{
			if (!isset($this->_parent_page_is_on_current_site))
			{
				$page = $this->get_parent_page();
				if ( $pages = $this->get_page_nav() )
				{
					$this->_parent_page_is_on_current_site = isset($pages->values[$page->id()]);
				}
				else
				{
					$this->_parent_page_is_on_current_site = (get_owner_site_id($page->id()) == $this->site_id);
				}
			}
			return $this->_parent_page_is_on_current_site;
		}
예제 #9
0
    die('Please provide days as an integer (e.g. 1, 2, 3, or 73)' . "\n");
}
$time = strtotime('-' . $days . ' days');
if (empty($time)) {
    die('Something appears to be amiss -- no time value was able to be resolved from the number of days provided' . "\n");
}
$datetime = date('Y-m-d H:i:s', $time);
$es = new entity_selector();
$es->add_type(id_of('news'));
$es->add_left_relationship($pub->id(), relationship_id_of('news_to_publication'));
$es->add_relation('`datetime` >= "' . $datetime . '"');
$es->set_num(1);
$posts = $es->run_one();
if (empty($posts)) {
    echo 'No new posts on publication id ' . $pub->id() . ' (' . $pub->get_value('name') . ') since ' . $datetime . '.' . "\n";
    if (!empty($args['emails'])) {
        $message = 'FYI, there are currently no recent posts on the Reason publication "' . $pub->get_value('name') . '."' . "\n\n";
        $message .= 'You are signed up to receive notices when this publication has not been updated in the last ' . $days . ' days.' . "\n\n";
        $message .= 'It may be time to add a new post!' . "\n\n";
        $message .= 'Click here to add posts to this publication: http://' . REASON_WEB_ADMIN_PATH . '?site_id=' . get_owner_site_id($pub->id()) . '&type_id=' . id_of('news') . "\n\n";
        $message .= 'If you are no longer responsible for this publication, please contact a Reason administrator to have this email sent to someone else.' . "\n\n";
        $message .= 'Thank you!' . "\n\n";
        mail($args['emails'], 'Reason Publication Reminder', $message, 'From: <*****@*****.**>');
        echo 'Message sent to ' . $args['emails'] . "\n";
    }
} else {
    echo 'New post on publication id ' . $pub->id() . ' (' . $pub->get_value('name') . ') since ' . $datetime . '.' . "\n";
    if (!empty($args['emails'])) {
        echo 'No message sent' . "\n";
    }
}
예제 #10
0
/**
 * Ensures validity of site_id and page_id requested.
 *
 * Because of the expense of this call we skip it for cached pages.
 */
function get_validated_site($site_id, $page_id)
{
    static $validated;
    if (isset($validated[$site_id][$page_id])) {
        return $validated[$site_id][$page_id];
    }
    if ($site_id != $_REQUEST['site_id']) {
        trigger_error('the site id in $_REQUEST[\'site_id\'] - ' . $_REQUEST['site_id'] . ' - does not match the site id in the .htaccess file - ' . $site_id . ' - possible hack attempt.', FATAL);
        die;
    }
    if ($page_id != $_REQUEST['page_id']) {
        trigger_error('the page id in $_REQUEST[\'page_id\'] - ' . $_REQUEST['page_id'] . ' - does not match the page id in the .htaccess file - ' . $page_id . ' - possible hack attempt.', FATAL);
        die;
    }
    $page = new entity($page_id);
    if (!$page->get_values()) {
        trigger_error('generate_page could not generate page id ' . $page_id . ' - the page entity was empty', FATAL);
        die;
    }
    if ($page->get_value('type') != id_of('minisite_page')) {
        trigger_error('generate_page passed page_id ' . $page_id . ' which is not an entity of type page', FATAL);
        die;
    }
    if ($page->get_value('state') != 'Live' && $page->get_value('state') != 'Pending') {
        trigger_error('generate_page called with page_id ' . $page_id . ' which is not a live or pending page', FATAL);
        die;
    }
    $actual_site_id = get_owner_site_id($page_id);
    if (empty($actual_site_id)) {
        trigger_error('page must have an owner site to be displayed', FATAL);
        die;
    }
    if ($actual_site_id != $site_id) {
        trigger_error('generate page called with site_id ' . $site_id . ', but the actual owner of page_id ' . $page_id . ' is ' . $actual_site_id . '. Rewrites may need to be run.', FATAL);
        die;
    }
    $site = new entity($actual_site_id);
    if (!$site->get_values()) {
        trigger_error('generate_page could not generate a page for site id ' . $actual_site_id . ' - the site entity was empty', FATAL);
        die;
    }
    if ($site->get_value('type') != id_of('site')) {
        trigger_error('generate_page called with a page whose owner with id ' . $actual_site_id . ' is not an entity of type site', FATAL);
        die;
    }
    if ($site->get_value('state') != 'Live') {
        trigger_error('generate_page called with site_id ' . $site_id . ', which has the state "' . $site->get_value('state') . '".', FATAL);
        die;
    }
    $validated[$site_id][$page_id] = $site;
    return $site;
}
 $txt .= '<tr class="' . $class . '">';
 foreach ($use_fields as $field) {
     if ($field == 'last_modified') {
         $txt .= '<td>' . date('j M Y', get_unix_timestamp($e->get_value($field))) . '</td>' . "\n";
     } elseif ($field == 'name') {
         $txt .= '<td>' . $e->get_display_name() . '</td>' . "\n";
     } else {
         $txt .= '<td>' . $e->get_value($field) . '</td>' . "\n";
     }
 }
 $txt .= '<td>';
 // This is the one thing that could make for poor performance if there are a lot of results
 // I'm not savvy enough yet to know how to include the owner info in the original query
 $owner_site_id = get_owner_site_id($e->id());
 if (!empty($owner_site_id)) {
     $owner_site = new entity(get_owner_site_id($e->id()));
     $txt .= '<a href="' . $owner_site->get_value('base_url') . '">';
     $txt .= $owner_site->get_value('name');
     $txt .= '</a>';
 } else {
     $txt .= 'Orphan Entity -- does not have an owner site';
 }
 $txt .= '</td>';
 $txt .= '<td>';
 $txt .= '<ul>';
 foreach ($e->get_values() as $key => $value) {
     if (stristr($value, $_REQUEST['search_string'])) {
         $search_str = $_REQUEST['search_string'];
         if ($type->get_value('unique_name') == 'form' && 'thor_content' == $key) {
             $value = htmlspecialchars($value);
             $search_str = htmlspecialchars($search_str);
예제 #12
0
 function _blurb_is_editable($blurb)
 {
     $user = reason_get_current_user_entity();
     if (!empty($user) && get_owner_site_id($blurb->id()) == $this->site_id && $blurb->user_can_edit_field('content', $user)) {
         return true;
     }
     return false;
 }
예제 #13
0
 function _get_max_dimensions($image)
 {
     $orig_path = reason_get_image_path($image, 'original');
     if (!file_exists($orig_path) || $this->admin_page->site_id != get_owner_site_id($this->admin_page->id)) {
         $largest_width = $image->get_value('width');
         $largest_height = $image->get_value('height');
     } else {
         list($largest_width, $largest_height) = getimagesize($orig_path);
     }
     return array('width' => $largest_width, 'height' => $largest_height);
 }
예제 #14
0
 function select_images()
 {
     if ($this->params['alternate_source_page_id']) {
         $page_id = $this->params['alternate_source_page_id'];
         if (!($site_id = get_owner_site_id($page_id))) {
             $site_id = $this->site_id;
         }
     } else {
         $page_id = $this->cur_page->id();
         $site_id = $this->site_id;
     }
     $this->es = new entity_selector();
     $this->es->description = 'Selecting images for sidebar';
     $this->es->add_type(id_of('image'));
     $this->es->set_env('site', $site_id);
     $this->es->add_right_relationship($page_id, relationship_id_of('minisite_page_to_image'));
     if ($this->params['rand_flag']) {
         $this->es->set_order('rand()');
     } elseif (!empty($this->params['order_by'])) {
         $this->es->set_order($this->params['order_by']);
     } else {
         $this->es->add_rel_sort_field($page_id, relationship_id_of('minisite_page_to_image'));
         $this->es->set_order('rel_sort_order');
     }
     if (!empty($this->params['num_to_display'])) {
         $this->es->set_num(!empty($this->params['num_to_skip']) ? $this->params['num_to_display'] + $this->params['num_to_skip'] : $this->params['num_to_display']);
     }
     $this->images = $this->es->run_one();
     if (!empty($this->images) && !empty($this->params['num_to_skip'])) {
         $this->images = array_slice($this->images, $this->params['num_to_skip'], NULL, true);
     }
 }
예제 #15
0
 function show_item_owner_site_info(&$item)
 {
     $owner_site_id = get_owner_site_id($item->id());
     if ($owner_site_id != $this->site_id) {
         $owner_site = new entity($owner_site_id);
         if ($owner_site->get_values()) {
             echo '<div class="owner">From site: <a href="' . $owner_site->get_value('base_url') . '">' . $owner_site->get_value('name') . '</a></div>' . "\n";
         }
     }
 }