/**
  * Determines whether or not the current user has access to the specified media work.  If no username is provided, this function defaults to the currently-loggin-in username.
  *
  * @param string $username
  * @return boolean user has access
  */
 public function user_has_access_to_media($username = '')
 {
     // First, get the restricted group--if one exists
     $es = new entity_selector();
     $es->add_type(id_of('group_type'));
     $es->add_right_relationship($this->media_work->id(), relationship_id_of('av_restricted_to_group'));
     $group = current($es->run_one());
     if (!empty($group)) {
         $gh = new group_helper();
         $gh->set_group_by_id($group->id());
         if ($gh->requires_login()) {
             if (!$username) {
                 $username = reason_check_authentication();
             }
             if ($username) {
                 if (!$gh->is_username_member_of_group($username)) {
                     return false;
                 }
             } else {
                 return false;
             }
         }
     }
     return true;
     // Return true if the user has access to view media work
 }
 function get_links()
 {
     $links = parent::get_links();
     $es = new entity_selector($this->admin_page->site_id);
     $es->add_type(id_of('event_type'));
     $es->set_order('dated.datetime DESC');
     $values = $es->run_one();
     //should adjust so that can't rearrange slots for events that have only one or no registration slots.
     //also, probably not for past events either.
     if ($values) {
         foreach ($values as $event_id => $event) {
             $es2 = new entity_selector($this->admin_page->site_id);
             $es2->add_type(id_of('registration_slot_type'));
             $es2->add_right_relationship($event_id, relationship_id_of('event_type_to_registration_slot_type'));
             $numSlots = $es2->get_one_count();
             if ($numSlots > 1) {
                 $date = $event->get_value('datetime');
                 $name = 'Sort slots for ' . $event->get_value('name') . ' - ' . prettify_mysql_datetime($date);
                 $link = $this->admin_page->make_link(array('event_id' => $event->id(), 'default_sort' => false), true);
                 $links[$name] = $link;
             }
         }
         $this->links = $links;
         return $this->links;
     }
 }
예제 #3
0
 /**
  * Standard Module init function
  *
  * @return void
  */
 function init()
 {
     parent::init();
     if (!reason_user_has_privs($this->admin_page->user_id, 'delete')) {
         $this->_ok_to_run = false;
         $this->_not_ok_message = 'Sorry; you don\'t have the privileges to delete items on this site.';
     } elseif (empty($this->admin_page->site_id)) {
         $this->_ok_to_run = false;
         $this->_not_ok_message = 'Sorry; you need to specify a site before batch deleting items.';
     } elseif (empty($this->admin_page->type_id)) {
         $this->_ok_to_run = false;
         $this->_not_ok_message = 'Sorry; you need to specify a type before batch deleting items.';
     }
     if ($this->_ok_to_run) {
         $this->_type = new entity($this->admin_page->type_id);
         $this->admin_page->title = 'Batch Delete ' . $this->_type->get_value('plural_name');
         $es = new entity_selector($this->admin_page->site_id);
         $es->add_type($this->admin_page->type_id);
         $es->set_sharing('owns');
         $es->set_order('entity.last_modified DESC');
         // pray($this->admin_page->request);
         if (isset($this->admin_page->request['state']) && $this->admin_page->request['state'] == 'pending') {
             $status = 'Pending';
         } else {
             $status = 'Live';
         }
         $this->_items = $es->run_one('', $status);
         foreach (array_keys($this->_items) as $id) {
             if (!$this->admin_page->is_deletable($id)) {
                 unset($this->_items[$id]);
             }
         }
     }
 }
예제 #4
0
function name_es($name)
{
    $es = new entity_selector();
    $es->add_type(id_of('content_table'));
    $es->add_relation('entity.name = "' . $name . '"');
    $results = $es->run_one();
    return $results;
}
예제 #5
0
 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);
 }
예제 #6
0
 function get_entity_selector()
 {
     $es = new entity_selector($this->admin_page->site_id);
     $es->add_type($this->admin_page->type_id);
     $es->set_order($this->get_table() . '.' . $this->get_field() . ' ASC');
     $es->set_sharing('owns');
     $es = $this->update_es($es);
     return $es;
 }
예제 #7
0
 /**
  * Standard Module init function
  *
  * Sets up page variables and runs the entity selctor that grabs the users
  * 
  * @return void
  */
 function init()
 {
     parent::init();
     $this->site = new entity($this->admin_page->site_id);
     $this->admin_page->title = 'Users with administrative access to ' . $this->site->get_value('name');
     $es = new entity_selector();
     $es->add_right_relationship($this->admin_page->site_id, relationship_id_of('site_to_user'));
     $this->users = $es->run_one(id_of('user'));
 }
예제 #8
0
 /**
  * @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;
 }
예제 #9
0
function get_minisite_template($theme_id)
{
    $template = false;
    $es = new entity_selector();
    $es->add_type(id_of('minisite_template'));
    $es->add_right_relationship($theme_id, relationship_id_of('theme_to_minisite_template'));
    $tmp = $es->run_one();
    return current($tmp);
}
예제 #10
0
 function get_images_in_new_order($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_rel_sort_field($page_id, relationship_id_of('minisite_page_to_image'), 'rel_sort_order');
     $es->add_field('relationship', 'id', 'rel_id');
     $es->set_order('rel_sort_order ASC, dated.datetime ASC, meta.description ASC, entity.id ASC');
     return $es->run_one();
 }
예제 #11
0
 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();
 }
예제 #12
0
 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.');
     }
 }
예제 #13
0
 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";
     }
 }
예제 #14
0
 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_job()
 {
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('news'));
     $result = $es->run_one();
     if ($result) {
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             reason_expunge_entity($id, $this->user_id);
         }
     }
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('publication_type'));
     $result = $es->run_one();
     if ($result) {
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             reason_expunge_entity($id, $this->user_id);
         }
     }
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('category_type'));
     $result = $es->run_one();
     if ($result) {
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             reason_expunge_entity($id, $this->user_id);
         }
     }
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('comment_type'));
     $result = $es->run_one();
     if ($result) {
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             reason_expunge_entity($id, $this->user_id);
         }
     }
     $es = new entity_selector($this->site_id);
     $es->add_type(id_of('minisite_page'));
     $result = $es->run_one();
     if ($result) {
         $root_page = root_finder($this->site_id);
         $ids = array_keys($result);
         foreach ($result as $id => $item) {
             if ($id != $root_page) {
                 reason_expunge_entity($id, $this->user_id);
             }
         }
     }
     $this->set_report('Zapped all the news, publications, categories, comments, and pages from the site');
 }
 function get_children($child)
 {
     $es = new entity_selector();
     $es->description = 'Selecting children of the page id ' . $child->id();
     // find all the children of this page
     $es->add_type(id_of('minisite_page'));
     $es->add_left_relationship($child->id(), relationship_id_of('minisite_page_parent'));
     if ($this->params['show_only_pages_in_nav']) {
         $this->es->add_relation('nav_display = "Yes"');
     }
     $es->set_order('sortable.sort_order ASC');
     return $es->run_one();
 }
 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;
 }
예제 #18
0
 /**
  * Make sure that the model is configured with a valid URL.
  *
  * @return string json
  */
 function build()
 {
     if ($site_id = $this->config('site_id')) {
         $s = get_microtime();
         $es = new entity_selector();
         $es->add_type(id_of('social_account_type'));
         $es->add_right_relationship($site_id, relationship_id_of('site_to_social_account'));
         $es->add_rel_sort_field($site_id, relationship_id_of('site_to_social_account'));
         $es->set_order('rel_sort_order ASC');
         $es->limit_tables();
         $es->limit_fields();
         if ($results = $es->run_one()) {
             $result_keys = array_keys($results);
             $sih = reason_get_social_integration_helper();
             foreach ($result_keys as $id) {
                 // get the integrator if it supports the SocialAccountProfileLinks interface
                 if ($integrator = $sih->get_social_account_integrator($id, 'SocialAccountProfileLinks')) {
                     $profile_links[$id]['icon'] = $integrator->get_profile_link_icon($id);
                     $profile_links[$id]['text'] = $integrator->get_profile_link_text($id);
                     $profile_links[$id]['href'] = $integrator->get_profile_link_href($id);
                 }
             }
             if (!empty($profile_links)) {
                 return $profile_links;
             }
         }
         return false;
     } else {
         trigger_error('The ReasonSocialProfileLinksModel must be provided with the configuration parameter site_id.', FATAL);
     }
 }
예제 #19
0
/**
 * Root finder:
 * Takes a site id and returns the id of the root page. 
 * @param integer $site_id
 * @return mixed page id integer if found; NULL if not found
 */
function root_finder( $site_id )
{
    $es = new entity_selector( );
    $es->add_type( id_of( 'minisite_page') );
    $es->add_relation( 'entity.state = "Live"' );
    $es->add_right_relationship( $site_id, get_owns_relationship_id(id_of('minisite_page')) );
    $results = $es->run_one();
    foreach( $results as $page )
    {
        $page_id = $page->get_value( 'id' );
        if( is_site_root( $page_id ) )
            return $page_id;
    }
}
 function get_pages_needing_change()
 {
     if (!isset($this->pages_needing_change)) {
         $es = new entity_selector();
         $es->add_type(id_of('minisite_page'));
         $es->enable_multivalue_results();
         $es->limit_tables('page_node');
         $es->limit_fields('custom_page');
         $es->add_relation('page_node.custom_page = "blurb"');
         $es->add_left_relationship_field('minisite_page_to_text_blurb', 'entity', 'id', 'blurb_id');
         $result = $es->run_one();
         foreach ($result as $k => $page) {
             $blurbs = is_array($page->get_value('blurb_id')) ? $page->get_value('blurb_id') : array($page->get_value('blurb_id'));
             foreach ($blurbs as $blurb_id) {
                 $blurb = new entity($blurb_id);
                 $content = $blurb->get_value('content');
                 $demoted_content = demote_headings($content, 1);
                 if ($content == $demoted_content) {
                     $pages_needing_page_type_change[$k] = $k;
                 }
             }
         }
         $this->pages_needing_change = isset($pages_needing_page_type_change) ? array_keys($pages_needing_page_type_change) : false;
     }
     return $this->pages_needing_change;
 }
예제 #21
0
 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 &amp; 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;
 }
예제 #22
0
		function _get_events()
		{
			if(!isset($this->events))
			{
				$es = new entity_selector($this->site_id);
				$es->add_type(id_of('event_type'));
				
				if(!in_array('archived',$this->params['show']))
				{
					$es->add_relation('`last_occurence` >= "'.addslashes(date('Y-m-d')).'"');
				}
				if(!in_array('upcoming',$this->params['show']))
				{
					$es->add_relation('`datetime` < "'.addslashes(date('Y-m-d',time() + (60*60*24))).'"');
				}
				if(!in_array('current',$this->params['show']))
				{
					$es->add_relation('(`last_occurence` < "'.addslashes(date('Y-m-d')).'" OR `datetime` >= "'.addslashes(date('Y-m-d',time() + (60*60*24))).'")');
				}
				$es->add_relation('`show_hide` = "show"');
				$es->set_order($this->params['order']);
				$this->_modify_events_es($es);
				$events = $es->run_one();
				$class = $this->get_model_class($this->params['model']);
				foreach($events as $id => $event)
				{
					$this->events[$id] = new $class($event);
				}
				if(empty($this->events))
					$this->events = array();
			}
			return $this->events;
		}
예제 #23
0
 function init($args = array())
 {
     parent::init($args);
     // find all the sites
     $es = new entity_selector();
     $es->description = "Getting all live sites";
     $es->add_type(id_of('site'));
     $es->add_relation('site.site_state = "Live"');
     $this->sites = $es->run_one();
     // find all non-reason sites
     $es2 = new entity_selector();
     $es2->description = 'Getting all non-reason sites';
     $es2->add_type(id_of('non_reason_site_type'));
     $this->non_reason_sites = $es2->run_one();
 }
 function init()
 {
     parent::init();
     $this->admin_page->title = 'Download Links for Media Work';
     $this->media_work = new entity($this->admin_page->id);
     if ($this->media_work->get_value('integration_library') == 'kaltura') {
         $this->kaltura_shim = new KalturaShim();
         $this->user = new entity($this->admin_page->user_id);
         // Grab the associated media files
         $es = new entity_selector();
         $es->add_type(id_of('av_file'));
         $es->add_right_relationship($this->media_work->id(), relationship_id_of('av_to_av_file'));
         $this->media_files = $es->run_one();
     }
 }
예제 #25
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();
 }
예제 #26
0
 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;
 }
예제 #27
0
 function init($args = array())
 {
     parent::init($args);
     $es = new entity_selector();
     $es->description = 'Selecting images for the gallery';
     $es->add_type(id_of('image'));
     $es = $this->refine_es($es);
     if (!empty($this->request['search_image'])) {
         $es->add_relation('(entity.name LIKE "%' . reason_sql_string_escape($this->request['search_image']) . '%" OR meta.description LIKE "%' . reason_sql_string_escape($this->request['search_image']) . '%"' . ' OR meta.keywords LIKE "%' . reason_sql_string_escape($this->request['search_image']) . '%"' . ' OR chunk.content LIKE "%' . reason_sql_string_escape($this->request['search_image']) . '%"' . ')');
     }
     $this->num = $es->get_one_count();
     $this->check_bounds();
     $es->set_num($this->num_per_page);
     $es->set_start(($this->request['page'] - 1) * $this->num_per_page);
     $this->images = $es->run_one();
 }
예제 #28
0
 function alter_feed()
 {
     $this->feed->set_item_field_map('title', 'id');
     $this->feed->set_item_field_map('author', 'author');
     $this->feed->set_item_field_map('description', 'description');
     $this->feed->set_item_field_map('pubDate', 'datetime');
     $this->feed->set_item_field_handler('title', 'make_title', true);
     $this->feed->set_item_field_handler('description', 'strip_tags', false);
     $this->feed->es->add_relation('show_hide.show_hide = "show"');
     $this->feed->es->set_order('datetime DESC');
     $this->feed->es->add_relation('status.status != "pending"');
     $this->feed->es->add_relation('dated.datetime <= NOW()');
     $this->feed->es->set_num(10);
     if ($this->site_specific) {
         // grab the most recent issue
         $es = new entity_selector($this->site_id);
         $es->add_type(id_of('issue_type'));
         $es->add_relation('show_hide.show_hide = "show"');
         $es->set_order('dated.datetime DESC');
         $es->set_num(1);
         $issues = $es->run_one();
         // Only grab related news items if there is a most recent issue available
         if (!empty($issues)) {
             $issue = current($issues);
             $this->feed->es->add_left_relationship($issue->id(), relationship_id_of('news_to_issue'));
             $this->feed->es->set_num(10000);
             // show the entiure issue, not just the top 10
         }
         // Otherwise just show the most recent news items
     }
 }
예제 #29
0
 function get_description($site)
 {
     $es = new entity_selector($site->id());
     $es->add_type(id_of('text_blurb'));
     $es->add_relation('entity.name = "Site Description"');
     $es->set_order('entity.last_modified DESC');
     $descriptions = $es->run_one();
     if (!empty($descriptions)) {
         reset($descriptions);
         $desc = current($descriptions);
         return $desc->get_value('content');
     } elseif ($site->get_value('description')) {
         return $site->get_value('description');
     } else {
         return NULL;
     }
 }
예제 #30
0
 /**
  * @return mixed array of slot data OR false.
  */
 function get_site_slots_with_data()
 {
     if (!isset($this->_site_slots_with_data)) {
         $es = new entity_selector($this->admin_page->site_id);
         $es->add_type(id_of('registration_slot_type'));
         $es->add_relation('( (registrant_data <> "") AND (registrant_data IS NOT NULL) )');
         $result = $es->run_one();
         if (!empty($result)) {
             foreach ($result as $k => $v) {
                 $this->_site_slots_with_data[$k] = $v->get_value('name');
             }
         } else {
             $this->_site_slots_with_data = FALSE;
         }
     }
     return $this->_site_slots_with_data;
 }