Ejemplo n.º 1
0
 function _ok_to_run_module()
 {
     if ($this->_ok_to_run !== true && $this->_ok_to_run !== false) {
         $this->_ok_to_run = false;
         if (!$this->admin_page->id) {
             return $this->_ok_to_run;
         }
         $owner_site = get_owner_site_id($this->admin_page->id);
         $entity = new entity($this->admin_page->id);
         if ($owner_site == $this->admin_page->site_id) {
             $this->_ok_to_run = true;
             return $this->_ok_to_run;
         }
         if (site_borrows_entity($this->admin_page->site_id, $entity->id())) {
             $this->_ok_to_run = true;
             return $this->_ok_to_run;
         }
         if (site_shares_type($owner_site, $entity->get_value('type')) && $entity->get_value('no_share') == 0) {
             $this->_ok_to_run = true;
             return $this->_ok_to_run;
         }
     }
     return $this->_ok_to_run;
 }
Ejemplo n.º 2
0
 function show_borrows_links()
 {
     $links = array();
     $links['Preview'] = $this->make_link(array('cur_module' => 'Preview'));
     $e = new entity($this->id);
     if (!$e->get_value('no_share')) {
         if (site_borrows_entity($this->site_id, $e->id())) {
             $links['Don\'t Borrow'] = $this->make_link(array('cur_module' => 'DoBorrow', 'admin_token' => $this->get_admin_token(), 'unborrow' => 1));
         } else {
             $links['Borrow'] = $this->make_link(array('cur_module' => 'DoBorrow', 'admin_token' => $this->get_admin_token()));
         }
     }
     if (!empty($this->request[CM_VAR_PREFIX . 'id'])) {
         foreach ($this->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] = '';
             }
         }
         $link = $this->make_link($old_vars);
         $links['Back to Associate Page'] = $link;
     } else {
         $links['Back to Sharing Page'] = $this->make_link(array('cur_module' => 'Sharing', 'id' => ''));
     }
     /*
     		$rels = $this->get_rels();
     		foreach( $rels AS $rel )
     			$links[ $rel[ 'entity_name' ] ] = $this->make_link( array( 'cur_module' => 'Associator' , 'rel_id' => $rel[ 'id' ] ) );
     */
     foreach ($links as $key => $value) {
         if ($this->is_selected($key)) {
             echo '<li class="navItem navSelect"><strong>' . $key . '</strong></li>' . "\n";
         } else {
             echo '<li class="navItem"><a href="' . $value . '" class="nav">' . $key . '</a></li>' . "\n";
         }
     }
 }
Ejemplo n.º 3
0
 function process()
 {
     $nobody_group = new entity(id_of('nobody_group'));
     //check to see if posting or commenting have been enabled while still being associated with the nobody group
     if ($this->get_value('allow_front_end_posting') && $this->entity->has_left_relation_with_entity($nobody_group, 'publication_to_authorized_posting_group')) {
         $this->delete_associations_of_type('publication_to_authorized_posting_group');
     }
     if ($this->get_value('allow_comments') && $this->entity->has_left_relation_with_entity($nobody_group, 'publication_to_authorized_commenting_group')) {
         $this->delete_associations_of_type('publication_to_authorized_commenting_group');
     }
     //check to see if posting or commenting have been disabled
     if (!$this->get_value('allow_front_end_posting') || !$this->get_value('allow_comments')) {
         //if they are, check to make sure that we've borrowed or own the nobody group.
         if (!(site_borrows_entity($this->get_value('site_id'), id_of('nobody_group')) || site_owns_entity($this->get_value('site_id'), id_of('nobody_group')))) {
             //if not, borrow it.
             create_relationship($this->get_value('site_id'), id_of('nobody_group'), get_borrows_relationship_id(id_of('group_type')));
         }
         //check to see if we've got the appropriate relationship(s) with the nobody group.	If we don't, create the relationship.
         if (!$this->get_value('allow_front_end_posting') && !$this->entity->has_left_relation_with_entity($nobody_group, 'publication_to_authorized_posting_group')) {
             $this->associate_with_nobody_group('publication_to_authorized_posting_group');
         }
         if (!$this->get_value('allow_comments') && !$this->entity->has_left_relation_with_entity($nobody_group, 'publication_to_authorized_commenting_group')) {
             $this->associate_with_nobody_group('publication_to_authorized_commenting_group');
         }
     }
     // make sure the group type is available to the site if commenting or front-end posting are available
     if ($this->get_value('allow_front_end_posting') || $this->get_value('allow_comments')) {
         if (!$this->site_has_type(id_of('group_type'))) {
             $this->add_type_to_site(id_of('group_type'));
         }
     }
     if ($this->get_value('allow_comments')) {
         if (!$this->site_has_type(id_of('comment_type'))) {
             $this->add_type_to_site(id_of('comment_type'));
         }
     }
     if ($this->get_value('has_issues') == 'yes' && !$this->site_has_type(id_of('issue_type'))) {
         $this->add_type_to_site(id_of('issue_type'));
     }
     if ($this->get_value('has_sections') == 'yes' && !$this->site_has_type(id_of('news_section_type'))) {
         $this->add_type_to_site(id_of('news_section_type'));
     }
     if (!$this->site_has_type(id_of('news'))) {
         // publicatons don't make much sense without news
         $this->add_type_to_site(id_of('news'));
     }
     parent::process();
 }
 function ensure_nobody_group_is_on_site()
 {
     $site_id = $this->get_site_id();
     if ($site_id) {
         if (!(site_borrows_entity($site_id, id_of('nobody_group')) || site_owns_entity($site_id, id_of('nobody_group')))) {
             // borrow it
             create_relationship($site_id, id_of('nobody_group'), get_borrows_relationship_id(id_of('group_type')));
         }
         return true;
     }
     return false;
 }
 function run_job()
 {
     $new_site_id = (int) $this->config('new_site_id');
     $b_entities = (array) $this->config('b_entities');
     $b_entities_str = implode(",", $b_entities);
     $q = 'SELECT id, entity_a, site FROM relationship ' . 'WHERE entity_b IN (' . $b_entities_str . ') ' . 'AND site > 0';
     $result = db_query($q, 'Unable to select relationships');
     $count = mysql_num_rows($result);
     if ($count > 0) {
         $q2 = 'UPDATE relationship SET site=' . $this->config('new_site_id') . ' ' . 'WHERE entity_b IN (' . $b_entities_str . ') ' . 'AND site > 0';
         $result2 = db_query($q2, 'Unable to change relationships');
         //using the original result set take care of borrowing and site_to_type changes
         $borrowed_count = $site_has_type_count = 0;
         while ($row = mysql_fetch_assoc($result)) {
             $this->report_item[] = 'Changed site context of rel id ' . $row['id'] . ' from ' . $row['site'] . ' to ' . $this->config('new_site_id') . '.';
             $site_has_type = $borrowed = false;
             // figure out if $row['site'] borrows $row['entity_a']
             if (site_borrows_entity($row['site'], $row['entity_a'])) {
                 $entity_a = new entity($row['entity_a']);
                 $entity_a_type = $entity_a->get_value('type');
                 $borrowed = create_relationship($this->config('new_site_id'), $row['entity_a'], get_borrows_relationship_id($entity_a_type));
                 if (!isset($this->_ensured_site_has_type[$entity_a_type])) {
                     $site_has_type = create_relationship($this->config('new_site_id'), $entity_a_type, relationship_id_of('site_to_type'));
                     $this->_ensured_site_has_type[$entity_a_type] = true;
                 }
             }
             if ($borrowed) {
                 $this->report_item[] = 'New site id ' . $this->config('new_site_id') . ' borrowed entity id ' . $row['entity_a'] . '.';
             }
             if ($site_has_type) {
                 $this->report_item[] = 'New site id ' . $this->config('new_site_id') . ' now has access to type ' . $entity_a_type . '.';
             }
         }
         if (count($this->report_item) > 0) {
             if (count($this->report_item) > 1) {
                 $this->set_report('<p>Job did some work:</p><ul><li>' . implode("</li><li>", $this->report_item) . '</li></ul>');
             } else {
                 $this->set_report(reset($this->report_item));
             }
         }
     }
     return true;
 }