Exemplo n.º 1
0
 protected function _rel_is_sortable()
 {
     if ($info = reason_get_allowable_relationship_info(relationship_id_of('event_to_image'))) {
         return $info['is_sortable'] == 'yes' ? true : false;
     }
     trigger_error('unable to find event_to_image allowable relationship');
 }
 protected function updated_allowable_relationship($rel_name, $field, $val)
 {
     $rel = reason_get_allowable_relationship_info(relationship_id_of($rel_name));
     if ($rel[$field] == $val) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 3
0
 function _relationship_check($relationship, $user = null, $direction, $entity_on_other_side = null, $context_site = null)
 {
     if (null === $user) {
         $user = $this->_get_current_user();
     }
     if (empty($user)) {
         return false;
     }
     $this_entity_state = $this->_entity->get_value('state');
     $other_entity_state = $entity_on_other_side ? $entity_on_other_side->get_value('state') : null;
     // If one of the entities is deleted or archived, return false
     if ('Deleted' == $this_entity_state || 'Deleted' == $other_entity_state || 'Archived' == $this_entity_state || 'Archived' == $other_entity_state) {
         // relationships not changeable on archived or deleted entities
         return false;
     } elseif ('Live' == $this_entity_state && (empty($other_entity_state) || 'Live' == $other_entity_state)) {
         if (!reason_user_has_privs($user->id(), 'edit_live')) {
             return false;
         }
     } elseif ('Pending' == $this_entity_state || 'Pending' == $other_entity_state) {
         if (!reason_user_has_privs($user->id(), 'edit_pending')) {
             return false;
         }
     } else {
         trigger_error('Uncaught state combination: ' . $this_entity_state . ' and ' . $other_entity_state . '. Check logic.');
         return false;
     }
     if (!$context_site) {
         $context_site_given = false;
         $context_site = $this->_find_context_site($entity_a, $entity_b, $user);
         $context_site_valid = !empty($context_site);
     } else {
         $context_site_given = true;
         $context_site_valid = $entity_a->is_owned_or_borrowed_by($context_site->id()) && $entity_b->is_owned_or_borrowed_by($context_site->id());
     }
     // if context site that the user has admin rights to that contains both entities
     if ($context_site_valid) {
         // if rel is bidirectional or user is admin of A side owner site return true
         $alrel = reason_get_allowable_relationship_info($alrel_id);
         if ('bidirectional' == $alrel['directionality']) {
             return true;
         } else {
             if ('right' == $direction) {
                 $a_side_owner_site = $this->_entity->get_owner();
             } elseif ($entity_on_other_side) {
                 $a_side_owner_site = $entity_on_other_side->get_owner();
             } else {
                 return false;
             }
             return user_can_edit_site($user->id(), $a_side_owner_site->id());
         }
     } else {
         if ($context_site_given) {
             $context_sites = array($context_site->id() => $context_site);
         } else {
             $context_sites = reason_user_sites($user);
         }
         $rels = $this->_get_rels_between_entities($entity_a, $entity_b, $allowable_relationship_id, $context_sites);
         if (!empty($rels)) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 4
0
 function init()
 {
     if (!$this->admin_page->id) {
         return false;
     }
     //these next few lines check the entity to make sure it has everything it needs
     $this->load_content_manager();
     $this->check_entity_values();
     $this->get_required_relationships();
     if (!empty($this->req_rels)) {
         $this->check_required_relationships();
     }
     /* the new finish stuff */
     // new_entity stuff
     // figure out if the entity is new and store that so we can change the data in the database but still know what's going on
     $temp = new entity($this->admin_page->id, false);
     if ($temp->get_value('new')) {
         $this->new_entity = true;
     } else {
         $this->new_entity = false;
     }
     // when finishing an entity, we want to ensure that it is live and not new (unless it is a page)
     if ($this->admin_page->type_id != id_of('minisite_page') && $temp->get_value('state') == 'Pending' && reason_user_has_privs($this->admin_page->user_id, 'publish')) {
         $update_values['state'] = 'Live';
         if (!empty($this->disco_item)) {
             $this->disco_item->set_value('state', "Live");
         }
     }
     if ($temp->get_value('new') != '0') {
         $update_values['new'] = 0;
         if (!empty($this->disco_item)) {
             $this->disco_item->set_value('new_entity', 0);
         }
     }
     if (!empty($update_values)) {
         reason_update_entity($this->admin_page->id, $this->admin_page->user_id, $update_values, false);
         // archive, yes?
     }
     $original = new entity($this->admin_page->id, false);
     $original->get_values();
     // get archive relationship id
     $q = 'SELECT id FROM allowable_relationship WHERE name LIKE "%archive%" AND relationship_a = ' . $this->admin_page->type_id . ' AND relationship_b = ' . $this->admin_page->type_id;
     $r = db_query($q, 'Unable to get archive relationship.');
     $row = mysql_fetch_array($r, MYSQL_ASSOC);
     $this->rel_id = $row['id'];
     // get archives
     $es = new entity_selector($this->admin_page->site_id);
     $es->add_type($this->admin_page->type_id);
     $es->add_right_relationship($this->admin_page->id, $this->rel_id);
     $es->add_relation('last_modified = "' . $original->get_value('last_modified') . '"');
     $es->set_num(1);
     $similar_archived = $es->run_one('', 'Archived');
     // if the entity has in fact been changed, actually create the relationship
     if (empty($similar_archived)) {
         $archived_id = duplicate_entity($original, false, true, array('state' => 'Archived'));
         create_relationship($this->admin_page->id, $archived_id, $this->rel_id);
     }
     // DETERMINE WHERE TO GO
     if (!empty($this->admin_page->request[CM_VAR_PREFIX . 'type_id'])) {
         // this code block is intended to associate a new entity with the context entity upon finish - it once created backwards relationships IF we reached an
         // entity with get_value('new') = 1 from the reverse associator. This needs fixin. We do so by running this section of code only in the case where
         // the "old" module was the associator (the only module that allows the creation of new entities than need a relationship back to the a side entity
         // whose context is relevant.
         if ($this->new_entity && $this->admin_page->request[CM_VAR_PREFIX . 'cur_module'] == 'Associator') {
             $rel_info = reason_get_allowable_relationship_info($this->admin_page->request[CM_VAR_PREFIX . 'rel_id']);
             $entity_a = new entity($this->admin_page->request[CM_VAR_PREFIX . 'id']);
             $entity_b = new entity($this->admin_page->request['id']);
             // lets do a bit of additional sanity checking.
             if ($rel_info['relationship_a'] == $entity_a->get_value('type') && $rel_info['relationship_b'] == $entity_b->get_value('type')) {
                 if ($rel_info['connections'] == 'one_to_many') {
                     $this->delete_existing_relationships();
                 }
                 create_relationship($entity_a->id(), $entity_b->id(), $rel_info['id']);
             }
         }
         $old_vars = array();
         foreach ($this->admin_page->request as $key => $val) {
             if (substr($key, 0, strlen(CM_VAR_PREFIX)) == CM_VAR_PREFIX) {
                 $old_vars[substr($key, strlen(CM_VAR_PREFIX))] = $val;
                 $old_vars[$key] = '';
             }
         }
         foreach ($this->admin_page->default_args as $arg) {
             if (!isset($old_vars[$arg])) {
                 $old_vars[$arg] = '';
             }
         }
         $link = $this->admin_page->make_link($old_vars);
     } elseif (!empty($this->admin_page->request['next_entity'])) {
         $link = $this->admin_page->make_link(array('cur_module' => 'Editor', 'id' => $this->admin_page->request['next_entity']));
     } else {
         $link = $this->admin_page->make_link(array('id' => '', 'site_id' => $this->admin_page->site_id, 'type_id' => $this->admin_page->type_id, 'cur_module' => 'Lister'));
     }
     // before redirecting, check to see if there are any custom finish actions associated with this type.
     // the entity_type variable is declared earlier in the check_entity_values method.
     //Run any custom finish actions specified in the content manager
     if (!empty($this->disco_item)) {
         $this->disco_item->run_custom_finish_actions($this->new_entity);
     }
     if ($this->entity_type->get_value('finish_actions')) {
         $finish_actions_filename = $this->entity_type->get_value('finish_actions');
     } else {
         $finish_actions_filename = 'default.php';
     }
     reason_include_once('finish_actions/' . $finish_actions_filename);
     $finish_action_class_name = $GLOBALS['_finish_action_classes'][$finish_actions_filename];
     $fac = new $finish_action_class_name();
     $vars = array('site_id' => $this->admin_page->site_id, 'type_id' => $this->admin_page->type_id, 'id' => $this->admin_page->id, 'user_id' => $this->admin_page->user_id);
     $fac->init($vars);
     $fac->run();
     header('Location: ' . unhtmlentities($link));
     die;
 }