/** * Loki 2 link style was not being properly handled by the editor_feed_finder - this function converts links that start with // to http:// * @todo normalize loki link formats, ensure */ function turn_into_normalized_url($string) { $url = turn_into_string($string); if ($url) { $url = substr($url, 0, 2) === '//' ? 'http:' . $url : $url; } return $url; }
/** * We explicitly only look at GET - the API will not respond to POST requests. We do this instead of looking * generically at $_REQUEST because php will urldecode $_GET but not $_POST data. We do not want to have to figure * out whether or not urldecode should be run. */ function setup_api() { if (isset($_GET['geo_source']) && in_array($_GET['geo_source'], $this->geo_sources)) { $this->geo_source = $_GET['geo_source']; } if (isset($_GET['geo_action']) && in_array($_GET['geo_action'], $this->geo_actions)) { $this->geo_action = $_GET['geo_action']; } if (isset($_GET['geo_value'])) { $this->geo_value = turn_into_string($_GET['geo_value']); } // we just make this a string since it could be almost anything }
/** * Set myself up. */ function __construct() { $type = turn_into_string($_GET['type']); $site_id = turn_into_int($_GET['site_id']); $this->type(id_of('image')); $this->site_id($site_id); $last_mod = isset($_GET['lastmod']) ? $_GET['lastmod'] : false; $num = !empty($_REQUEST['num']) ? turn_into_int($_REQUEST['num']) : '500'; $offset = !empty($_REQUEST['offset']) ? turn_into_int($_REQUEST['offset']) : '0'; $this->num($num); $this->offset($offset); $this->last_mod($last_mod); $this->caching(isset($_GET['caching']) ? turn_into_boolean($_GET['caching']) : true); }
/** * Create a new allowable relationship * * Checks to make sure we are not duplicating an existing allowable relationship before creating new one. * * Checks include: * 1. the type ids must be the ids of existing reason types * 2. the name must be a nonempty string containing only numbers, letters, and underscores that does not already exist in the allowable relationship table (exception: borrows and owns) * 3. for borrows or owns relationships, the type must not already have an allowable relationship of that type * * @param integer $a_side_type_id The id of the type on the left side of the relationship * @param integer $b_side_type_id The id of the type on the right side of the relationship * @param string $name The unique name of the allowable relationship (or "owns" or "borrows") * @param array $other_data Additional data to be stored in the allowable_relationship table, keyed by field name * @return mixed id of newly created relationship if successful; false if failure * * @todo update to do verification and handling of new "type" field */ function create_allowable_relationship($a_side_type_id,$b_side_type_id,$name,$other_data = array()) { // validate data $a_side_type_id = turn_into_int($a_side_type_id); $b_side_type_id = turn_into_int($b_side_type_id); $name = turn_into_string($name); if(empty($a_side_type_id)) { trigger_error('$a_side_type_id must be a nonzero integer in create_allowable_relationship()'); return false; } $a_ent = new entity($a_side_type_id); if(!empty($a_ent)) { if($a_ent->get_value('type') != id_of('type')) { trigger_error('$a_side_type_id must be the ID of a Reason type entity'); return false; } } else { trigger_error('$a_side_type_id is not the ID of a Reason entity'); return false; } if(empty($b_side_type_id)) { trigger_error('$b_side_type_id must be a nonzero integer in create_allowable_relationship()'); return false; } $b_ent = new entity($b_side_type_id); if(!empty($b_ent)) { if($b_ent->get_value('type') != id_of('type')) { trigger_error('$b_side_type_id must be the ID of a Reason type entity'); return false; } } else { trigger_error('$b_side_type_id is not the ID of a Reason entity'); return false; } if(empty($name)) { trigger_error('$name must be a string in create_allowable_relationship()'); return false; } if( !preg_match( "|^[0-9a-z_]*$|i" , $name ) ) { trigger_error('$name must only contain numbers, letters, and underscores'); return false; } if (!reason_relationship_names_are_unique()) { $repeatable_names = array('borrows','owns'); if( !in_array($name,$repeatable_names) && reason_relationship_name_exists($name, false) ) { trigger_error('Unable to create allowable relationship named '.$name.' because there is already an allowable relationship with that name in Reason'); return false; } if(in_array($name,$repeatable_names)) { if($a_side_type_id != id_of('site')) { trigger_error('The a_side_type_id of borrows and owns relationships must be the id of the site type'); return false; } // check to see if an owns/borrows relationship already exists for this type if ( (($name == 'owns') && get_owns_relationship_id($b_side_type_id)) || (($name == 'borrows') && get_borrows_relationship_id($b_side_type_id)) ) { trigger_error($name.' relationship already exists between '.$a_side_type_id.' and '.$b_side_type_id.'.'); return false; } } } else { if (reason_relationship_name_exists($name, false)) { trigger_error('Unable to create allowable relationship named '.$name.' because there is already an allowable relationship with that name in Reason'); return false; } if (isset($other_data['type']) && ( ($other_data['type'] == 'owns') || ($other_data['type'] == 'borrows') ) ) { if ($a_side_type_id != id_of('site')) { trigger_error('The a_side_type_id of borrows and owns relationships must be the id of the site type'); return false; } // enforce our naming convention $owns_name_should_be = $a_ent->get_value('unique_name') . '_owns_' . $b_ent->get_value('unique_name'); $borrows_name_should_be = $a_ent->get_value('unique_name') . '_borrows_' . $b_ent->get_value('unique_name'); if ( ($other_data['type'] == 'owns') && ($name != $owns_name_should_be) ) { trigger_error('A new allowable relationship of type owns must follow the naming convention a_side_unique_name_owns_b_side_entity_unique_name'); return false; } elseif ( ($other_data['type'] == 'borrows') && ($name != $borrows_name_should_be) ) { trigger_error('A new allowable relationship of type borrows must follow the naming convention a_side_unique_name_borrows_b_side_entity_unique_name'); return false; } } if (isset($other_data['type']) && ($other_data['type'] == 'archive')) { if ($a_side_type_id != $b_side_type_id) { trigger_error('The a_side_type_id and b_side_type_id of archive relationships must be the same.'); return false; } $archive_name_should_be = $a_ent->get_value('unique_name') . '_archive'; if ($name != $archive_name_should_be) { trigger_error('A new allowable relationship of type archive must follow the naming convention type_unique_name_archive'); return false; } } } // do the creation of the allowable relationship $default_values = array( 'directionality'=>'unidirectional', 'is_sortable'=>'no', 'connections'=>'many_to_many', 'required'=>'no', ); if (reason_relationship_names_are_unique()) $default_values['type'] = 'association'; $values = array_merge($default_values,$other_data); $values['relationship_a'] = $a_side_type_id; $values['relationship_b'] = $b_side_type_id; $values['name'] = $name; $sqler = new SQLER(); if($sqler->insert('allowable_relationship',$values)) { $insert_id = mysql_insert_id(); reason_refresh_relationship_names(); return $insert_id; } else { return false; } }
$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' => ''))); exit; } // Make an array with first dimension of page type name, second dimension of every page // ID using the pt, third dimension 'true' for every page type returned by the query. foreach ($result as $k => $mypage) { $page_type_value = $mypage->get_value('custom_page'); if (empty($page_type_value)) { $page_type_value = 'default'; } $reason_page_types[$page_type_value][$k] = 'true'; }