Ejemplo n.º 1
0
 /**
  * sets $asset entity given an asset_id
  */
 function set_asset_id($asset_id)
 {
     $e = new entity($asset_id);
     if (reason_is_entity($e, 'asset')) {
         $this->asset = $e;
     }
 }
Ejemplo n.º 2
0
 function _get_site_page_data()
 {
     if (!isset($this->_site_page_data)) {
         $site_pages = $this->_get_site_pages();
         if ($site_pages) {
             foreach ($site_pages as $k => $v) {
                 $user_entity_lm = $v->get_value('last_edited_by') ? new entity($v->get_value('last_edited_by')) : false;
                 $username_lm = $user_entity_lm && reason_is_entity($user_entity_lm, 'user') ? $user_entity_lm->get_value('name') : '(unknown)';
                 $user_entity_cb = $v->get_value('created_by') ? new entity($v->get_value('created_by')) : false;
                 $username_cb = $user_entity_cb && reason_is_entity($user_entity_cb, 'user') ? $user_entity_cb->get_value('name') : '(unknown)';
                 $pretty_date = prettify_mysql_datetime($v->get_value('last_modified'));
                 $page_url = $v->get_value('page_url');
                 if (!empty($page_url)) {
                     $this->_site_page_data[$k]['page_url'] = $this->_should_provide_html_link() ? '<a href="' . $page_url . '">' . $page_url . '</a>' : $page_url;
                     $this->_site_page_data[$k]['author'] = $v->get_value('author');
                     $this->_site_page_data[$k]['created_by'] = $username_cb;
                     $this->_site_page_data[$k]['last_edited_by'] = $username_lm;
                     $this->_site_page_data[$k]['last_modified'] = $pretty_date;
                 }
             }
         } else {
             $this->_site_page_data = false;
         }
     }
     return $this->_site_page_data;
 }
Ejemplo n.º 3
0
 function run()
 {
     if (($e = new entity($this->admin_page->id)) && reason_is_entity($e, true)) {
         $name = 'Copy of ' . $e->get_value('name');
         if ($new_entity_id = duplicate_entity($this->admin_page->id, false, false, array('name' => $name, 'unique_name' => '', 'last_modified_by' => $this->admin_page->user_id, 'state' => 'Pending', 'new' => '1'))) {
             header('Location: ' . carl_make_redirect(array('cur_module' => 'Editor', 'id' => $new_entity_id)));
         } else {
             echo '<p>Unable to duplicate entity.</p>';
             return false;
         }
     } else {
         echo '<p>Duplicate called with invalid entity ID.</p>';
         return false;
     }
 }
Ejemplo n.º 4
0
 /**
  * This is typically the page the module is running on unless parent_unique_name is set.
  *
  * @return object entity parent page
  */
 function get_parent_page()
 {
     if (!isset($this->_parent_page)) {
         if (!empty($this->params['parent_unique_name'])) {
             if (reason_unique_name_exists($this->params['parent_unique_name'])) {
                 $page = new entity(id_of($this->params['parent_unique_name']));
                 if (reason_is_entity($page, 'minisite_page')) {
                     $this->_parent_page = $page;
                 } else {
                     trigger_error('The unique name specified in parent_unique_name (' . $this->params['parent_unique_name'] . ') was ignored - it needs to refer to a minisite page entity.');
                 }
             } else {
                 trigger_error('The unique name specified in parent_unique_name (' . $this->params['parent_unique_name'] . ') was ignored - it does not exist.');
             }
         }
         if (!isset($this->_parent_page)) {
             $this->_parent_page = new entity($this->page_id);
         }
     }
     return $this->_parent_page;
 }
 /**
  * Returns requested and validated site id or FALSE if it cannot be found or is invalid
  * @return mixed int site id or FALSE
  */
 function get_requested_site_id()
 {
     if (!isset($this->_requested_site_id)) {
         if (array_key_exists('requested_url', $this->request)) {
             $parsed_url = parse_url($this->request['requested_url']);
             $query = $parsed_url['query'];
             $query_array = $this->convert_url_query($query);
             if (array_key_exists('site_id', $query_array)) {
                 if (is_numeric($query_array['site_id'])) {
                     $apparent_site = new entity($query_array['site_id']);
                     if (reason_is_entity($apparent_site, 'site')) {
                         $this->_requested_site_id = $apparent_site->id();
                     }
                 }
             }
         }
         if (!isset($this->_requested_site_id)) {
             $this->_requested_site_id = false;
         }
     }
     return $this->_requested_site_id;
 }
Ejemplo n.º 6
0
	/**
	 * Creates the ownership, borrowing, and archive relationships that are necessary for each Reason type
	 *
	 * @param integer $type_id
	 * @return boolean (success)
	 */
	function create_default_rels_for_new_type($type_id)
	{
		if(empty($type_id))
		{
			trigger_error('Unable to create default relationships for type id '.$type_id.'; no type_id provided', HIGH);
			return false;
		}
		else $type = new entity($type_id);
		$values = $type->get_values();
		if (!reason_is_entity($type, 'type'))
		{
			trigger_error('Unable to create default relationships for type id '.$type_id.'; id does not correspond to a reason type entity.', HIGH);
			return false;
		}
		else $type_unique_name = $type->get_value('unique_name');
		if (func_num_args() > 1)
		{
			trigger_error('The unique name parameter of create_default_rels_for_new_type is deprecated - the type unique name is determined from the type entity itself');
		}
		if (reason_relationship_names_are_unique())
		{
			$owns_id = create_allowable_relationship(id_of('site'),$type_id,'site_owns_'.$type_unique_name,array('connections'=>'many_to_one','directionality'=>'unidirectional','required'=>'yes','is_sortable'=>'no','type'=>'owns'));
			$borrows_id = create_allowable_relationship(id_of('site'),$type_id,'site_borrows_'.$type_unique_name,array('connections'=>'many_to_many','directionality'=>'bidirectional','required'=>'no','is_sortable'=>'no','type'=>'borrows'));
			$archive_id = create_allowable_relationship($type_id,$type_id,$type_unique_name.'_archive',array('connections'=>'many_to_one','directionality'=>'unidirectional','required'=>'no','is_sortable'=>'no','type'=>'archive'));
		}
		else
		{
			$owns_id = create_allowable_relationship(id_of('site'),$type_id,'owns',array('connections'=>'many_to_one','directionality'=>'unidirectional','required'=>'yes','is_sortable'=>'no'));
			$borrows_id = create_allowable_relationship(id_of('site'),$type_id,'borrows',array('connections'=>'many_to_many','directionality'=>'bidirectional','required'=>'no','is_sortable'=>'no'));
			$archive_id = create_allowable_relationship($type_id,$type_id,$type_unique_name.'_archive',array('connections'=>'many_to_one','directionality'=>'unidirectional','required'=>'no','is_sortable'=>'no'));
		}
		if($owns_id && $borrows_id && $archive_id)
			return true;
		else
			return false;
	}
Ejemplo n.º 7
0
		/**
		* Checks to see if the user's id matches the auther of the current item.
		*/ 
		function user_is_author()
		{
			if (isset($this->current_item_id) && ($netid = reason_check_authentication()))
			{
				$item = new entity($this->current_item_id);
				if (reason_is_entity($item, 'news'))
				{
					if ($item->get_value('created_by') == get_user_id($netid))
					{
						return true;
					}
				}
			}
			return false;
		}
Ejemplo n.º 8
0
 /**
  * If the user_id is a valid reason user entity, we load our plugins.
  *
  * @return boolean
  */
 function reason_plugins_available($user_id)
 {
     if (!isset($this->_reason_plugins_available)) {
         if (!empty($user_id)) {
             $user = new entity($user_id);
             $this->_reason_plugins_available = reason_is_entity($user, 'user');
         } else {
             $this->_reason_plugins_available = false;
         }
     }
     return $this->_reason_plugins_available;
 }
Ejemplo n.º 9
0
/** @access private */
function _reason_upload_handle_entity(&$element, $expected_type, $filesystem_translator, $web_translator)
{
    if (!$element->existing_entity) {
        return;
    }
    if (is_numeric($element->existing_entity)) {
        $id = (int) $element->existing_entity;
        $entity = new entity($id);
    } else {
        if (is_object($element->existing_entity)) {
            $entity = $element->existing_entity;
        } else {
            trigger_error("a {$expected_type} entity object or ID must be passed " . "as the existing entity to a Reason upload type; got " . var_export($element->existing_entity, true) . " instead", WARNING);
            return;
        }
    }
    if (!reason_is_entity($entity, $expected_type)) {
        trigger_error("an invalid existing entity was passed to a Reason " . "upload type", WARNING);
        return;
    }
    $element->existing_file = call_user_func($filesystem_translator, $entity);
    $element->existing_file_web = call_user_func($web_translator, $entity);
}
Ejemplo n.º 10
0
 function check_errors($user)
 {
     $error_messages = array('site_is_site' => 'You have requested an invalid site.', 'site_to_type' => 'This site does not have access to this type.', 'type_to_id' => 'The entity you have chosen does not match the type.', 'site_owns_id' => 'This site does not own this entity.');
     $message = '';
     $site = new entity($this->site_id);
     if (!reason_is_entity($site, 'site')) {
         $message = $error_messages['site_is_site'];
     } elseif (!$this->verify_user($user)) {
         header('Location: ' . securest_available_protocol() . '://' . REASON_WEB_ADMIN_PATH . '?cur_module=SiteAccessDenied&user_id=' . $user->id() . '&requested_url=' . urlencode(get_current_url()));
     } elseif (!$this->site_to_type()) {
         $message = $error_messages['site_to_type'];
     } elseif (!$this->type_to_id()) {
         $message = $error_messages['type_to_id'];
     } elseif (!$this->site_owns_id()) {
         $message = $error_messages['site_owns_id'];
     }
     if ($message) {
         ob_flush();
         $link = 'index.php';
         if ($this->user_id) {
             $link .= '?user_id=' . $this->user_id;
         }
         die($message . '  <a href="' . $link . '">Reason Home</a>.');
     }
 }
Ejemplo n.º 11
0
 /**
  * Delete the registrant_data for checked slots.
  */
 function delete_slot_data_process($disco)
 {
     $slots = $disco->get_value('slots_with_data');
     foreach ($slots as $id) {
         $e = new entity($id);
         if (reason_is_entity($e, 'registration_slot_type')) {
             $values['registrant_data'] = '';
             reason_update_entity($e->id(), $this->admin_page->user_id, $values, false);
         }
     }
 }
Ejemplo n.º 12
0
 function clean_expunged()
 {
     $es = new entity_selector();
     $es->add_type(id_of('minisite_page'));
     $es->limit_tables();
     $es->limit_fields();
     $result = $es->run_one('', 'All');
     $page_ids = array_keys($result);
     $dbs = new DBSelector();
     $dbs->add_table('URL_history', 'URL_history');
     $dbs->add_field('URL_history', 'id');
     $dbs->add_field('URL_history', 'page_id');
     $dbs->add_field('URL_history', 'timestamp');
     $dbs->add_field('URL_history', 'url');
     $dbs->add_relation('URL_history.page_id NOT IN ("' . implode('","', $page_ids) . '")');
     $rows = $dbs->run();
     foreach ($rows as $row) {
         $e = new entity($row['page_id']);
         if (!reason_is_entity($e, 'minisite_page')) {
             $needs_deletion[] = $row['id'];
         }
     }
     if (isset($needs_deletion)) {
         $deleter_sql = 'DELETE FROM URL_history WHERE id IN ("' . implode('","', $needs_deletion) . '")';
         if ($this->mode == 'test') {
             echo '<p>Would delete ' . count($needs_deletion) . ' rows that reference expunged entities with this query:</p>';
             echo $deleter_sql;
         }
         if ($this->mode == 'run') {
             db_query($deleter_sql, 'Could not delete rows from URL_history');
             echo '<p>Deleted ' . count($needs_deletion) . ' rows that reference expunged entities with this query:</p>';
             echo $deleter_sql;
         }
     } else {
         echo '<p>There are no rows that reference expunged entities in the URL_history table - you may have already run this script</p>';
         return true;
     }
 }
Ejemplo n.º 13
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);
}
show_config($fields);
echo '<h1>"Type" Type File Reference Manager</h1>';
echo '<p>This script examines the types in your reason instance, and discovers references to files on the "local" and/or "core" side of the ';
echo ' file system split. The script allows you to easily change these references, or resolve references to missing files. By default, missing ';
echo ' files and references to "local" files are displayed, and "core" files are shown as available options for new values.</p>';
// we loop through POST and make sure it contains requested changes to type entities and that those are limited to changeable fields.
// once we do this, we actually make the changes.
if (!empty($_POST)) {
    unset($_POST['process']);
    $count = 0;
    foreach ($_POST as $k => $v) {
        $change_values = array();
        // each $k should be an integer that corresponds to a type entity. If not, ignore it.
        if (is_int($k)) {
            $e = new entity($k);
            if (reason_is_entity($e, 'type')) {
                foreach ($v as $field => $value) {
                    if (isset($fields[$field])) {
                        if (reason_file_exists($fields[$field] . '/' . $value)) {
                            $change_values[$field] = $value;
                        }
                    }
                }
                if (!empty($change_values)) {
                    if ($update_attempt = reason_update_entity($k, $user_id, $change_values)) {
                        $count++;
                    }
                }
            }
        }
    }
Ejemplo n.º 15
0
/**
 * Checks whether the given user is a member of the given group.
 * @param string $username the username of the user whose group membership is
 *        in question
 * @param int|object $group a group entity or the ID of a group entity
 * @return boolean true if the user was determined to be a member of the group;
 *         false if otherwise
 * @since Reason 4.0 beta 8
 */
function reason_user_is_in_group($username, $group)
{	
	static $error_prefix = "cannot check if user is a member of a group:";	
	if (!$username)
	{
		return false;
		trigger_error("$error_prefix a username was not provided");
	}
	elseif (!$group || (!is_object($group) && !is_numeric($group)))	
	{
		trigger_error("$error_prefix an integer (group id) or entity was not provided");
		return false;
	}
	else
	{
		$group_entity = is_object($group) ? $group : new entity($group);
		if (reason_is_entity($group_entity, 'group_type'))
		{
			$helper = new group_helper();
			$helper->set_group_by_entity($group_entity);
			return $helper->is_username_member_of_group($username);
		}
		else
		{
			trigger_error("$error_prefix a valid group entity was not provided");
			return false;
		}
	}
}
Ejemplo n.º 16
0
/**
 * In a multidomain reason install the web path for a site might not be the web path for the current domain.
 *
 * This function returns the correct webpath for a given reason site or false if a site with a custom domain setting is not defined in domain_settings.php
 *
 * @author Nathan White
 * @return string absolute file system directory that is the web root for a site
 */
function reason_get_site_web_path($site_id_or_entity)
{
    $site = is_numeric($site_id_or_entity) ? new entity($site_id_or_entity) : $site_id_or_entity;
    if (reason_is_entity($site, 'site')) {
        $domain = $site->get_value('domain');
        if (!empty($domain) && isset($GLOBALS['_reason_domain_settings'][$domain]['WEB_PATH'])) {
            return $GLOBALS['_reason_domain_settings'][$domain]['WEB_PATH'];
        } elseif (!empty($domain)) {
            trigger_error('reason_get_site_web_path called on site id ' . $site->id() . ' with domain value ' . $domain . ' that is not defined in domain_settings.php');
            return false;
        }
        return reason_get_default_web_path();
    } else {
        trigger_error('reason_get_site_web_path passed a value that is not a site_id or site entity');
        return false;
    }
}
Ejemplo n.º 17
0
 /** Setters **/
 function set_id($id)
 {
     $my_id = (int) $id;
     if (empty($id) || $my_id != $id || strlen($my_id) != strlen($id)) {
         trigger_error('ID parameter provided (' . $id . ') is invalid. Please provide the id as a postive integer.');
     } elseif (!reason_is_entity(new entity($my_id), 'image')) {
         trigger_error('ID parameter provided (' . $id . ') does not correspond to a reason image.');
     } elseif ($this->locked) {
         trigger_error('Image ID already defined. Create a new sized image object to use a different image.');
     } else {
         $this->id = $my_id;
     }
 }
Ejemplo n.º 18
0
 function configured()
 {
     if ($site_id = $this->config('site_id')) {
         $site = new entity($site_id);
         if (reason_is_entity($site, 'site')) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 19
0
/**
 * Used to update an asset that is already in the filesystem.
 *
 * @param int asset_id id of asset
 * @param int user_id id of person modifying asset
 * @param file array with keys: path, name
 * @return mixed entity_id of existing asset or FALSE on failure
 */
function reason_update_asset($asset_id, $user_id, $file)
{
    if (!is_null($asset_id)) {
        if (empty($asset_id) || intval($asset_id) != $asset_id) {
            trigger_error('reason_update_asset was provided an invalid asset_id parameter (' . $asset_id . ')');
            return false;
        } else {
            $asset = new entity(intval($asset_id));
            if (!reason_is_entity($asset, 'asset')) {
                trigger_error('reason_update_asset was provided a asset_id that is not a reason asset entity id (' . $asset_id . ')');
                return false;
            }
        }
    }
    if (empty($user_id) || intval($user_id) != $user_id) {
        trigger_error('reason_update_asset was provided an invalid user_id parameter (' . $user_id . ')');
        return false;
    } else {
        $user = new entity(intval($user_id));
        if (!reason_is_entity($user, 'user')) {
            trigger_error('reason_update_asset was provided a user_id that is not a reason user entity id (' . $user_id . ')');
            return false;
        }
    }
    if (empty($file) || !is_array($file)) {
        trigger_error('reason_update_asset requires the file parameter to be an array with keys path, name');
        return false;
    } elseif (empty($file['path']) || !file_exists($file['path'])) {
        if (empty($file['path'])) {
            trigger_error('reason_update_asset requires a file parameter with a key "path" that contains the full path to a file');
        } else {
            trigger_error('reason_update_asset was provided a file path (' . $file['path'] . ') that does not exist');
        }
        return false;
    } elseif (empty($file['name'])) {
        trigger_error('reason_update_asset requires a file parameter with a key "name" that specifies what filename should be used for downloading the file');
        return false;
    }
    $cur_path = reason_get_asset_filesystem_location($asset);
    $cur_name = $asset->get_value('file_name');
    // if our name or path has changed lets update the asset
    if ($file['path'] != $cur_path || $file['name'] != $cur_name) {
        $asset_owner = $asset->get_owner();
        $values['mime_type'] = get_mime_type($file['path'], 'application/octet-stream');
        $values['file_name'] = _reason_get_asset_filename($asset_owner->id(), $file['name'], $asset->id());
        $values['file_type'] = _reason_get_asset_extension($file['path'], $values['mime_type']);
        $values['file_size'] = _reason_get_asset_size($file['path']);
        // if the entity update changed the file name lets do rewrites.
        if (reason_update_entity($asset->id(), $user_id, $values, false)) {
            if ($cur_name != $values['file_name']) {
                $um = new url_manager($asset_owner->id());
                $um->update_rewrites();
            }
        }
        if ($file['path'] != $cur_path) {
            $asset_dest = ASSET_PATH . $asset_id . '.' . $values['file_type'];
            if (server_is_windows() && file_exists($asset_dest)) {
                unlink($asset_dest);
            }
            rename($file['path'], $asset_dest);
        }
        return $asset_id;
    }
    return false;
}