function _produce_borrowing_nav() { $ret = ''; $nes = new entity_selector(); $nes->add_type(id_of('type')); $nes->add_right_relationship($this->admin_page->site_id, relationship_id_of('site_cannot_edit_type')); $nes->add_relation('`entity`.`id` = "' . addslashes($this->admin_page->type_id) . '"'); $nes->set_num(1); $nes->limit_tables(); $nes->limit_fields(); $ns = $nes->run_one(); $show_edit = reason_user_has_privs($this->admin_page->user_id, 'edit') && !$this->admin_page->is_second_level() && empty($ns) ? true : false; /* $type = new entity($this->admin_page->type_id); $name = $type->get_value('plural_name') ? $type->get_value('plural_name') : $type->get_value('name'); if(function_exists('mb_strtolower')) $name = mb_strtolower($name); else $name = strtolower($name); */ $ret .= '<div class="borrowNav">' . "\n"; $ret .= '<ul>'; if ($show_edit) { $ret .= '<li><a href="' . $this->admin_page->get_owned_list_link($this->admin_page->type_id) . '"><img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/bullet_edit.png" alt="" /> Add & edit</a></li>'; } $ret .= '<li class="current"><strong><img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/car.png" alt="" /> Borrow</strong></li>'; $ret .= '</ul>' . "\n"; $ret .= '</div>' . "\n"; // if(reason_user_has_privs($this->admin_page->user_id,'edit')) return $ret; }
protected function _link_in_db() { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('admin_link')); $es->add_relation('`url` = "?cur_module=AdminTools"'); $es->set_num(1); $results = $es->run_one(); return !empty($results); }
/** * @return object loki 1 entity if it exists */ protected function get_loki_1_entity() { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('html_editor_type')); $es->add_relation('entity.name = "Loki 1"'); $es->set_num(1); $result = $es->run_one(); return !empty($result) ? reset($result) : FALSE; }
function get_last_modified_item_selector() { $es = new entity_selector($this->site_id()); $es->add_type($this->type()); $es->limit_tables(); $es->limit_fields('last_modified'); $es->set_num(1); $es->set_order('last_modified DESC'); return $es; }
function do_updates($mode, $reason_user_id) { if ($mode != 'run' && $mode != 'test') { trigger_error('$mode most be either "run" or "test"'); return; } $messages = array(); $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('view_type')); $es->add_relation('url = "sections_and_issues.php"'); $es->set_num(1); $view_types = $es->run_one(); if (empty($view_types)) { if ('test' == $mode) { echo '<p>Would have added the view type sections_and_issues.php and the Sections and Issues view</p>' . "\n"; return; } else { $view_type_id = reason_create_entity(id_of('master_admin'), id_of('view_type'), $reason_user_id, 'News Sections and Issues', array('url' => 'sections_and_issues.php')); $view_type = new entity($view_type_id); echo '<p>Added the view type sections_and_issues.php</p>' . "\n"; } } else { echo '<p>sections_and_issues.php view type already added</p>' . "\n"; $view_type = current($view_types); } $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('view')); $es->add_left_relationship($view_type->id(), relationship_id_of('view_to_view_type')); $es->set_num(1); $views = $es->run_one(); if (empty($views)) { if ('test' == $mode) { echo '<p>Would have added the Sections and Issues view</p>' . "\n"; } else { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('field')); $es->add_relation('entity.name = "status"'); $es->set_num(1); $fields = $es->run_one(); $view_id = reason_create_entity(id_of('master_admin'), id_of('view'), $reason_user_id, 'News Sections and Issues', array('display_name' => 'Sections and Issues')); create_relationship($view_id, $view_type->id(), relationship_id_of('view_to_view_type')); create_relationship($view_id, id_of('news'), relationship_id_of('view_to_type')); if (!empty($fields)) { $field = current($fields); create_relationship($view_id, $field->id(), relationship_id_of('view_columns')); create_relationship($view_id, $field->id(), relationship_id_of('view_searchable_fields')); } echo '<p>Added sections and issue view</p>'; } } else { echo '<p>sections and issues view already added.</p>' . "\n"; } }
function init($args = array()) { $es = new entity_selector($this->parent->site_id); $es->description = 'Selecting blog/publications for this page'; $es->add_type(id_of('publication_type')); $es->add_right_relationship($this->parent->cur_page->id(), relationship_id_of('page_to_publication')); $es->set_num(1); $blogs = $es->run_one(); if (!empty($blogs)) { $this->blog = current($blogs); } }
function run_error_checks() { parent::run_error_checks(); $es = new entity_selector(); $es->add_relation('audience_integration.directory_service_value = "' . reason_sql_string_escape($this->get_value('directory_service_value')) . '"'); $es->add_relation('entity.id != ' . $this->get_value('id')); $es->set_num(1); $conflicts = $es->run_one(id_of('audience_type')); if (!empty($conflicts)) { $this->set_error('directory_service_value', 'The Directory Service Value you entered ("' . $this->get_value('directory_service_value') . '") is already in use. Each audience must have a unique directory service value.'); } }
/** * Check if the current site has the registration slot type. */ function site_has_slot_type() { if (!isset($this->_site_has_slot_type)) { $es = new entity_selector(); $es->add_type(id_of('type')); $es->add_right_relationship($this->admin_page->site_id, relationship_id_of('site_to_type')); $es->add_relation('entity.id = "' . id_of('registration_slot_type') . '"'); $es->set_num(1); $result = $es->run_one(); $this->_site_has_slot_type = !empty($result); } return $this->_site_has_slot_type; }
protected function _dynamic_site_id_option_exists() { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('admin_link')); $es->set_num(1); $result = $es->run_one(); if ($result) { $ret = reset($result); $values = $ret->get_values(); return array_key_exists('add_dynamic_site_id', $values); } return false; }
/** * Determine if a site has access to the image type * @param integer $site_id site to test * @return boolean */ function site_can_manage_images($site_id) { $es = new entity_selector(); $es->add_type(id_of('type')); $es->add_right_relationship($site_id, relationship_id_of('site_to_type')); $es->add_relation('entity.unique_name = "image"'); $es->set_num(1); $types = $es->run_one(); if (empty($types)) { return false; } else { return true; } }
function get_form() { if (!isset($this->_form)) { $this->_form = false; // Get the form entity attached to the current page $es = new entity_selector(); $es->add_type(id_of('form')); $es->add_right_relationship($this->cur_page->id(), relationship_id_of('page_to_form')); $es->set_num(1); $result = $es->run_one(); if ($result) { $this->_form = reset($result); } } return $this->_form; }
function get_feed_relationship_url() { static $cache = array(); if (!array_key_exists($this->parent->cur_page->id(), $cache)) { $es = new entity_selector($this->parent->site_id); $es->add_type(id_of('external_url')); $es->add_right_relationship($this->parent->cur_page->id(), relationship_id_of('page_to_feed_url')); $es->set_num(1); $urls = $es->run_one(); if (!empty($urls)) { $url = current($urls); $cache[$this->parent->cur_page->id()] = $url->get_value('url'); } else { $cache[$this->parent->cur_page->id()] = ''; } } return $cache[$this->parent->cur_page->id()]; }
function init($args = array()) { $es = new entity_selector($this->site_id); $es->description = 'Selecting publications for this page'; $es->add_type(id_of('publication_type')); $es->add_right_relationship($this->page_id, relationship_id_of('page_to_publication')); $es->set_num(1); $publications = $es->run_one(); if (!empty($publications)) { $this->publication = current($publications); if ($this->publication->get_value('has_sections') == 'yes') { $es = new entity_selector($this->site_id); $es->description = 'Selecting news sections for this publication'; $es->add_type(id_of('news_section_type')); $es->add_left_relationship($this->publication->id(), relationship_id_of('news_section_to_publication')); $es->set_order('sortable.sort_order ASC'); $this->sections = $es->run_one(); } } if (!empty($this->sections) && !empty($this->publication) && $this->publication->get_value('has_issues')) { if (!empty($this->request['issue_id'])) { $iss = new entity($this->request['issue_id']); if ($iss->get_values() && $iss->get_value('type') == id_of('issue_type')) { $this->issue = $iss; } } else { $es = new entity_selector($this->site_id); $es->description = 'Selecting issues for this publication'; $es->add_type(id_of('issue_type')); $es->limit_tables(array('dated', 'show_hide')); $es->limit_fields('dated.datetime'); $es->set_order('dated.datetime DESC'); $es->add_relation('show_hide.show_hide = "show"'); $es->add_left_relationship($this->publication->id(), relationship_id_of('issue_to_publication')); $es->set_num(1); $issues = $es->run_one(); if (!empty($issues)) { $this->issue = current($issues); } } } }
function reason_iframe_get_media_file() { if (!empty($_REQUEST['media_file_id'])) { $id = (int) $_REQUEST['media_file_id']; if ($id) { if ($work = reason_iframe_get_media_work()) { $es = new entity_selector(); $es->add_type(id_of('av_file')); $es->add_right_relationship($work->id(), relationship_id_of('av_to_av_file')); $es->add_relation('`entity`.`id` = "' . addslashes($id) . '"'); $es->set_num(1); $results = $es->run_one(); if (!empty($results)) { return current($results); } } } } return false; }
function init($args = array()) { $show = true; if ($this->params['hide_on_item'] && !empty($this->request['story_id'])) { $show = false; } elseif ($this->params['hide_on_archive_pages'] && !empty($this->request['page']) && $this->request['page'] > 1) { $show = false; } if ($show) { $es = new entity_selector($this->site_id); $es->description = 'Selecting publications for this page'; $es->add_type(id_of('publication_type')); $es->add_right_relationship($this->page_id, relationship_id_of('page_to_publication')); $es->set_num(1); $publications = $es->run_one(); if (!empty($publications)) { $this->publication = current($publications); } } }
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(); }
/** * Get the groups that apply to a given page * @param integer $page_id * @return array of group objects */ function get_groups($page_id) { if (!isset($this->_pages_to_groups[$page_id])) { $alrel_id = relationship_id_of('page_to_access_group'); if (!$alrel_id) { trigger_error('page_to_access_group needs to be added. Please upgrade your database at ' . REASON_HTTP_BASE_PATH . 'scripts/upgrade/4.0b6_to_4.0b7/'); return array(); } $chain = $this->_page_tree->get_id_chain($page_id); if (empty($chain)) { trigger_error('Page ' . $page_id . 'does not appear to be in site.'); $this->_pages_to_groups[$page_id] = array(); } else { $es = new entity_selector(); $es->add_type(id_of('group_type')); $es->limit_tables(); $es->limit_fields(); $es->add_right_relationship($chain, $alrel_id); $es->set_num(count($chain)); $this->_pages_to_groups[$page_id] = $es->run_one(); } } return $this->_pages_to_groups[$page_id]; }
if (!$media_file_id || !$media_work_id || !$hash) { http_response_code(404); die; } $media_file = new entity($media_file_id); if (!$media_file->get_values() || $media_file->get_value('type') != id_of('av_file')) { http_response_code(404); die; } # First, grab the media_work associated with the provided media file $es = new entity_selector(); $es->add_type(id_of('av')); $es->add_left_relationship($media_file->id(), relationship_id_of('av_to_av_file')); $es->add_relation('`entity`.`id` = "' . addslashes($media_work_id) . '"'); $es->add_relation('`media_work`.`integration_library` != ""'); $es->set_num(1); $works = $es->run_one(); if (empty($works)) { http_response_code(404); die; } $media_work = current($works); # check to make sure the REQUEST var hash is correct $displayer = MediaWorkFactory::media_work_displayer($media_work); if ($displayer) { $displayer->set_media_work($media_work); } else { http_response_code(404); die; } if ($displayer->get_hash() != $hash) {
/** * Check to see if the file is a duplicate * This currently only checks within the current site * It would be nicer if it checked across all of Reason * but we would need to make sure that the appropriate borrowing setup * was in place, or it would lead to frustration */ function check_if_file_has_been_previously_imported($stream, $user) { $this->checksum = $this->get_checksum($stream); if (!empty($this->checksum)) { $es = new entity_selector($this->manager->get_value('site_id')); $es->add_type(id_of('av_file')); $es->add_relation('media_md5_sum = "' . $this->checksum . '"'); $es->add_relation('entity.id != ' . $this->manager->get_value('id')); $es->set_num(1); $conflicts = $es->run_one(); if (!empty($conflicts)) { $conflict = current($conflicts); $this->manager->set_error('import_file', 'This file has already been imported into Reason as <strong><a href="' . $conflict->get_value('url') . '">' . $conflict->get_value('name') . '</a></strong> (Reason ID: ' . $conflict->id() . ')'); } } }
function get_path_to_link_target_page() { if($this->link_to_a_different_page) { if(!$this->attempted_to_find_target_page) { $relation = '(page_node.custom_page = "'.implode('" OR page_node.custom_page = "',$this->page_types_available_for_linking).'")'; $es = new entity_selector($this->site_id); $es->add_type( id_of( 'minisite_page' ) ); $es->add_relation( $relation ); $es->set_num( 1 ); $pages = $es->run_one(); if(!empty($pages)) { $this->link_target_page = current($pages); $link = $this->parent->pages->get_full_url($this->link_target_page->id()); $this->path_to_link_target_page = $link; } $this->attempted_to_find_target_page = true; } return $this->path_to_link_target_page; } return ''; }
function _get_max_sort_order_value($page_id) { $es = new entity_selector(); $es->add_type(id_of('image')); $es->add_right_relationship($page_id, relationship_id_of('minisite_page_to_image')); $es->add_field('relationship', 'id', 'rel_id'); $es->add_rel_sort_field($page_id); $es->set_order('relationship.rel_sort_order DESC'); $es->set_num(1); $images = $es->run_one(); if (!empty($images)) { $image = current($images); if ($image->get_value('rel_sort_order')) { return $image->get_value('rel_sort_order'); } } return 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(); }
function get_av_files($item, $num = 0) { $avf = new entity_selector(); $avf->add_type(id_of('av_file')); $avf->add_right_relationship($item->id(), relationship_id_of('av_to_av_file')); $avf->set_order('av.media_format ASC, av.av_part_number ASC'); if ($num) { $avf->set_num($num); } return $avf->run_one(); }
/** * Factory function for grabbing and setting up the theme customizer for a given site * * @param mixed $site site entity or ID * @param mixed $theme theme entity or ID; if not provided Reason will determine the current theme * @return mixed object or false if no customizer */ function reason_get_theme_customizer($site, $theme = NULL) { if (is_numeric($site)) { $site = new entity($site); } if (empty($theme)) { $es = new entity_selector(); $es->add_type(id_of('theme_type')); $es->add_right_relationship($site->id(), relationship_id_of('site_to_theme')); $es->set_num(1); $tmp = $es->run_one(); if (!empty($tmp)) { $theme = current($tmp); } else { return false; } } elseif (is_numeric($theme)) { $theme = new entity($theme); } if ($theme->get_value('theme_customizer')) { reason_include_once('theme_customizers/' . $theme->get_value('theme_customizer') . '.php'); if (!empty($GLOBALS['reason_theme_customizers'][$theme->get_value('theme_customizer')])) { if (class_exists($GLOBALS['reason_theme_customizers'][$theme->get_value('theme_customizer')])) { if ($site->get_value('theme_customization')) { $all_customization_data = json_decode($site->get_value('theme_customization')); $theme_id = $theme->id(); if (isset($all_customization_data->{$theme_id})) { $customization_data = $all_customization_data->{$theme_id}; } } if (empty($customization_data)) { $customization_data = new stdClass(); } $customizer = new $GLOBALS['reason_theme_customizers'][$theme->get_value('theme_customizer')](); $customizer->set_customization_data($customization_data); } else { trigger_error('Theme customizer "' . $theme->get_value('theme_customizer') . '" not registered properly.'); $customizer = false; } } else { trigger_error('Theme customizer "' . $theme->get_value('theme_customizer') . '" not found or not registered properly.'); $customizer = false; } } return isset($customizer) ? $customizer : false; }
/** * Change the definition of a field in a Reason entity table * * @param mixed $field integer id, entity object, or tablename.fieldname string * @param string $definition e.g. enum('foo','bar') * @param integer $user_id The Reason ID of the user making the change * * @return boolean success */ function reason_update_field_definition($field, $definition, $user_id) { if(is_numeric($field)) $field_entity = new entity($field); elseif(is_object($field)) $field_entity = $field; if(!empty($field_entity)) { if($field_entity->get_value('type') != id_of('field')) { trigger_error('reason_update_field_definition passed an entity that is not a field'); return false; } $fieldname = $field_entity->get_value('name'); $tables = $field_entity->get_left_relationship('field_to_entity_table'); if(empty($tables)) { trigger_error('Unable to find table for given field.'); return false; } $table = current($tables); $tablename = $table->get_value('name'); } else { list($tablename,$fieldname) = explode('.',$field); if(empty($tablename) || empty($fieldname)) { trigger_error('Unable to update field definition -- must provide field entity, field id, or table.field string.'); return false; } $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('entity.name = "'.addslashes($tablename).'"'); $es->set_num(1); $tables = $es->run_one(); if(empty($tables)) { trigger_error('Unable to find table for given field.'); return false; } $table = current($tables); $fields = $table->get_right_relationship('field_to_entity_table'); foreach($fields as $f) { if($f->get_value('name') == $fieldname) { $field_entity = $f; break; } } if(empty($field_entity)) { trigger_error('Unable for find field entity for given field'); return false; } } // Update database $q = 'ALTER TABLE `'.addslashes($tablename).'` CHANGE `'.addslashes($fieldname).'` '.addslashes($fieldname).' '.$definition; db_query( $q, 'Unable to change column.' ); // Update reason reason_update_entity($field_entity->id(), $user_id, array('db_type'=>$definition)); return true; }
echo '<p>Testing updates...</p>' . "\n"; } $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('entity.name = "site"'); $es->set_num(1); $tables = $es->run_one(); if (empty($tables)) { echo '<p>Unable to find site table. Major problem.</p>'; } else { $table = current($tables); $es = new entity_selector(); $es->add_type(id_of('field')); $es->add_relation('entity.name IN ("use_custom_footer","custom_footer")'); $es->add_left_relationship($table->id(), relationship_id_of('field_to_entity_table')); $es->set_num(2); $fields = $es->run_one(); $fields_to_create = array('use_custom_footer' => 'enum(\'yes\',\'no\')', 'custom_footer' => 'text'); foreach ($fields as $field) { unset($fields_to_create[$field->get_value('name')]); } if (empty($fields_to_create)) { echo '<p>Fields exist; script has already been run.</p>'; } else { if ($_POST['go'] != 'run') { echo '<p>Would have created these fields:</p>'; pray($fields_to_create); } else { $update_fields = array(); foreach ($fields_to_create as $key => $value) { $update_fields[$key] = array('db_type' => $value);
} foreach ($blurbs as $bl_id => $bl) { if ($test_mode) { $out[] = 'Would have deleted: ' . $bl->get_value('name') . ' (id: ' . $bl_id . ')'; } else { delete_entity($bl_id); $out[] = 'Deleted: ' . $bl->get_value('name') . ' (id: ' . $bl_id . ')'; } } $blurbs = array(); $pending_blurbs = array(); $deleted_blurbs = array(); // Delete most users $out[] = '<h2>Started Users</h2>'; $es = new entity_selector(); $es->set_num($limit); $es->add_relation('entity.name NOT IN ("' . implode('","', $minimal_users) . '")'); $users = $es->run_one(id_of('user')); $pending_users = $es->run_one(id_of('user'), 'Pending'); if (!empty($pending_users)) { $users += $pending_users; } $deleted_users = $es->run_one(id_of('user'), 'Deleted'); if (!empty($deleted_users)) { $users += $deleted_users; } foreach ($users as $usr_id => $usr) { if ($test_mode) { $out[] = 'Would have deleted: ' . $usr->get_value('name') . ' (id: ' . $usr_id . ')'; } else { delete_entity($usr_id);
/** * Get the Reason entity that represents the current user, if one exists * * @return mixed Reason entity or false (if no user logged in or if logged-in user does not have Reason entity) */ function reason_get_current_user_entity() { static $user; if(!isset($user)) { if($username = reason_check_authentication()) { $es = new entity_selector(); $es->add_type(id_of('user')); $es->add_relation('entity.name = "'.addslashes($username).'"'); $es->set_num(1); $result = $es->run_one(); if(!empty($result)) { $user = current($result); } } if(empty($user)) { $user = false; } } return $user; }
protected function _add_table($table_name) { $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('entity.name = "' . reason_sql_string_escape($table_name) . '"'); $es->set_num(1); $results = $es->run_one(); if (empty($results)) { create_reason_table($table_name, $this->_type_unique_name(), $this->user_id()); $ret = '<p>Created the ' . $table_name . ' table.</p>'; } else { $table_entity = current($results); create_relationship($this->_type_id(), $table_entity->id(), relationship_id_of('type_to_table')); $ret = '<p>Added the ' . $table_name . ' table to the ' . $this->_type_unique_name() . ' type.</p>' . "\n"; } reason_include_once('classes/amputee_fixer.php'); $fixer = new AmputeeFixer(); $fixer->fix_amputees($this->_type_id()); return $ret; }
function get_field_id($table_name, $field_name) { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('content_table')); $es->add_relation('entity.name = "' . reason_sql_string_escape($table_name) . '"'); $es->set_num(1); $tables = $es->run_one(); if (empty($tables)) { trigger_error('Unable to find table named ' . $table_name); return false; } $table = current($tables); $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('field')); $es->add_left_relationship($table->id(), relationship_id_of('field_to_entity_table')); $es->add_relation('entity.name = "' . reason_sql_string_escape($field_name) . '"'); $es->set_num(1); $fields = $es->run_one(); if (empty($fields)) { trigger_error('Unable to find table named ' . $field_name, ' in table named ' . $table_name); return false; } $field = current($fields); return $field->id(); }