function process()
 {
     //prep site
     $this->helper->ensure_type_is_on_site(id_of('publication_type'));
     $this->helper->ensure_type_is_on_site(id_of('group_type'));
     $this->helper->ensure_nobody_group_is_on_site();
     // gather core information
     $pub_type_id = id_of('publication_type');
     $name = trim(strip_tags($this->get_value('pub_name')));
     // populate values array
     $values['new'] = 0;
     $values['description'] = trim(get_safer_html($this->get_value('pub_description')));
     $values['unique_name'] = trim(strip_tags($this->get_value('pub_unique_name')));
     $values['state'] = 'Live';
     $values['hold_comments_for_review'] = 'no';
     $values['posts_per_page'] = turn_into_int($this->get_value('pub_posts_per_page'));
     $values['blog_feed_string'] = trim(strip_tags($this->get_value('pub_rss_feed_url')));
     $values['publication_type'] = 'Newsletter';
     $values['has_issues'] = 'no';
     $values['has_sections'] = 'no';
     $values['date_format'] = $this->get_value('date_format');
     // create the publication
     $pub_id = reason_create_entity($this->site_id, $pub_type_id, $this->user_id, $name, $values);
     // associate with nobody posting and commenting groups
     create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_posting_group'));
     create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_commenting_group'));
 }
예제 #2
0
	function attach_template($template_id)
	{
		if($this->test_mode)
		{
			$this->report .= '<p>Would have attached template id '.$template_id.'</p>';
			return true;
		}
		if(!empty($this->id))
		{
			$old_template_id = $this->get_template_id();
			if($old_template_id != $template_id)
			{
				if($old_template_id)
				{
					delete_relationships(
array( 'entity_a' => $this->id , 'entity_b' => $old_template_id , 'type' => relationship_id_of('theme_to_minisite_template') ) );
				}
				return(create_relationship( $this->id, $template_id, relationship_id_of('theme_to_minisite_template')));
			}
			else
			{
				return true;
			}
		}
		else
		{
			trigger_error('could not add template, as theme does not yet have an id');
			return false;
		}
	}
예제 #3
0
 protected function link_section_to_parent($section)
 {
     //echo round(memory_get_usage()/1024,2)."K at point A\n";
     if ($template = $this->get_section_parent($section->get_value('parent_template_id'))) {
         //	echo round(memory_get_usage()/1024,2)."K at point B\n";
         if (!($parents = $section->get_right_relationship('course_template_to_course_section'))) {
             return create_relationship($template->id(), $section->id(), relationship_id_of('course_template_to_course_section'), false, false);
         } else {
             if (is_array($parents)) {
                 $current_template = reset($parents);
                 //		echo round(memory_get_usage()/1024,2)."K at point C\n";
                 // verify that we have the correct parent, and fix if not.
                 if ($current_template->get_value('sourced_id') == $template->get_value('sourced_id')) {
                     return true;
                 } else {
                     //$this->errors[] = 'Incorrect template attached to '.$section->get_value('name');
                     echo 'Incorrect template attached to ' . $section->get_value('name');
                 }
             } else {
                 //$this->errors[] = 'Non-array '.$parents.' returned from get_right_relationship';
                 echo 'Non-array ' . $parents . ' returned from get_right_relationship';
             }
         }
     } else {
         //$this->errors[] = 'No template found for '.$section->get_value('name');
         echo 'No template found for ' . $section->get_value('name');
         return false;
     }
 }
 function process()
 {
     $pub_id = $this->get_value('publication_id');
     $issues_to_link = $this->get_value('issues');
     foreach ($issues_to_link as $issue_id) {
         create_relationship($issue_id, $pub_id, relationship_id_of('issue_to_publication'));
     }
     // update the publication - set has_issues to "Yes"
     reason_update_entity($pub_id, $this->user_id, array('has_issues' => 'yes'));
 }
예제 #5
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";
     }
 }
 function process()
 {
     $pub_id = $this->get_value('publication_id');
     $sections_to_link = $this->get_value('sections');
     foreach ($sections_to_link as $section_id) {
         create_relationship($section_id, $pub_id, relationship_id_of('news_section_to_publication'));
         // old style news would show as many items per section as existed ... we will set the posts_per_section_on_front_page to 1000
         // to make sure the publication continues to behave the same way ... not exactly pretty but it works for now.
         reason_update_entity($section_id, $this->user_id, array('posts_per_section_on_front_page' => 1000));
     }
     // update the publication - set has_sections to "Yes"
     reason_update_entity($pub_id, $this->user_id, array('has_sections' => 'yes'));
 }
예제 #7
0
 /**
  * Run the upgrader
  * @return string HTML report
  */
 public function run()
 {
     if ($this->_link_in_db()) {
         return 'This script has already run';
     } else {
         if ($id = reason_create_entity(id_of('master_admin'), id_of('admin_link'), $this->user_id(), 'Admin Tools', array('url' => '?cur_module=AdminTools', 'new' => 0))) {
             if (create_relationship(id_of('master_admin'), $id, relationship_id_of('site_to_admin_link'))) {
                 return 'Created the admin tools link and placed on Master Admin sidebar';
             } else {
                 return 'Created the admin tools link but error occurred placing in Master Admin sidebar. You may want to do this manually.';
             }
         } else {
             return 'Error creating the AdminTools link. You may want to add this link manually, by adding an Admin Link in Master Admin to the URL "?cur_module=AdminTools"';
         }
     }
 }
예제 #8
0
 /**
  * Lists the current and available themes (if appropriate to do so) otherwise, changes the theme
  * if the user has selected a new one
  * 
  * @return void
  */
 function run()
 {
     if (!empty($this->admin_page->request['chosen_theme'])) {
         if ($this->self_change) {
             //create a relationship of type site_has_had_theme (if needed)
             $oldies = $this->get_previously_selected_themes();
             $site_type_themes = $this->get_site_type_themes(false);
             $e = $this->get_current_theme();
             if ($e) {
                 if (!entity_in_array($oldies, $e->id()) and !entity_in_array($site_type_themes, $e->id())) {
                     create_relationship($this->admin_page->site_id, $e->id(), relationship_id_of('site_has_had_theme'));
                 }
             }
             //do relationship adding/deleting
             delete_relationships(array('entity_a' => $this->admin_page->site_id, 'type' => relationship_id_of('site_to_theme')));
             create_relationship($this->admin_page->site_id, $this->admin_page->request['chosen_theme'], relationship_id_of('site_to_theme'));
         }
         $link = $this->admin_page->make_link(array('cur_module' => 'ChooseTheme', 'chosen_theme' => ''));
         header('Location: ' . unhtmlentities($link));
     } else {
         $this->list_available_themes();
     }
 }
예제 #9
0
function attach_thumbnail($media_work, $shim)
{
    // create image file in the vimeo temp directory
    $image_url = $shim->get_thumbnail($media_work->get_value('entry_id'));
    if ($image_url) {
        $tmp_path = VimeoShim::get_temp_dir() . 'tmp_thumbnail_' . $media_work->get_value('id');
        $f = fopen($tmp_path, 'w');
        $contents = get_reason_url_contents($image_url);
        fwrite($f, $contents);
        fclose($f);
        $user = new entity($media_work->get_value('created_by'));
        $username = $user->get_value('name');
        // Create a reason entity out of the temp image file
        if (!empty($tmp_path) && file_exists($tmp_path) && $username) {
            if ($id = create_image_entity($media_work, $username)) {
                reason_include_once('content_managers/image.php3');
                $im = new ImageManager();
                $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                $im->load_by_type(id_of('image'), $id, $media_work->get_value('created_by'));
                $im->handle_standard_image($id, $tmp_path);
                $im->create_default_thumbnail($id);
                $values = array();
                foreach ($im->get_element_names() as $element_name) {
                    $values[$element_name] = $im->get_value($element_name);
                }
                reason_update_entity($id, get_user_id($username), $values, false);
                create_relationship($media_work->get_value('id'), $id, relationship_id_of('av_to_primary_image'));
            }
        }
    } else {
        echo date(DATE_RFC822) . ': No thumbnail url found for media work with id ' . $media_work->get_value('entry_id') . "\n";
    }
}
 protected function create_social_account_type()
 {
     $str = '';
     $social_account_type_id = reason_create_entity(id_of('master_admin'), id_of('type'), $this->user_id(), 'Social Account', $this->social_account_type_details);
     $str .= '<p>Create social account type entity</p>';
     create_default_rels_for_new_type($social_account_type_id);
     create_reason_table('social_account', $this->social_account_type_details['unique_name'], $this->user_id());
     $ftet = new FieldToEntityTable('social_account', array('account_type' => array('db_type' => 'tinytext'), 'account_id' => array('db_type' => 'tinytext'), 'account_details' => array('db_type' => 'text')));
     $ftet->update_entity_table();
     ob_start();
     $ftet->report();
     $str .= ob_get_contents();
     ob_end_clean();
     create_allowable_relationship(id_of('site'), id_of('social_account_type'), 'site_to_social_account', $this->site_to_social_account_details);
     $str .= '<p>Created site to social account relationship.</p>';
     create_relationship(id_of('master_admin'), id_of('social_account_type'), relationship_id_of('site_to_type'));
     return $str;
 }
예제 #11
0
     $items = $es->run_one();
     $pending_items = $es->run_one($type->id(), 'Pending');
     $deleted_items = $es->run_one($type->id(), 'Deleted');
     if (!empty($pending_items)) {
         $items += $pending_items;
     }
     if (!empty($deleted_items)) {
         $items += $deleted_items;
     }
     // go through all the entities of those types and create relationships to duplicate the data in the audience fields
     foreach ($items as $item) {
         $out[] = 'inspecting ' . $item->get_value('name');
         if (!$item->has_relation_of_type($rel_name)) {
             foreach ($audiences as $audience => $audience_data) {
                 if ($item->get_value($audience) == 'true') {
                     create_relationship($item->id(), $audience_ids[$audience], $alrel_id);
                     $out[] = 'Created rel between ' . $item->get_value('name') . ' and ' . $audience;
                     $did_creation = true;
                 }
             }
         }
     }
 }
 pray($out);
 if (isset($did_creation) && $did_creation == true) {
     echo '<p>The script needs to run step one again. Please click submit to continue.</p>';
     echo '<form>';
     echo 'Number to run: <input type="text" name="num" value="100"/><br />';
     echo '<input type="submit" name="do_it" value="Do it" />';
     echo '</form>';
 } else {
예제 #12
0
	function process()
	{	
		$description = trim(tidy($this->get_value('description')));
		$content = trim(get_safer_html(tidy($this->get_value('post_content'))));
		if(carl_empty_html($description))
		{
			$words = explode(' ', $content, 31);
			unset($words[count($words)-1]);
			$description = implode(' ', $words).'…';
			$description = trim(tidy($description)); // we're tidying it twice so that if we chop off a closing tag tidy will stitch it back up again
		}
		
		if(!empty($this->user_netID))
		{
			$user_id = make_sure_username_is_user($this->user_netID, $this->site_info->id());
		}
		else
		{
			$user_id = $this->site_info->id();
		}
		
		if($this->hold_posts_for_review)
		{
			$status = 'pending';
		}
		else
		{
			$status = 'published';
		}

		$values = array (
			'status' => $status,
			'release_title' => trim(strip_tags($this->get_value('title'))),
			'author' => trim(strip_tags($this->get_value('author'))),
			'content' => $content,
			'description' => $description,
			'datetime' => date('Y-m-d H:i:s', time()),
			'keywords' => implode(', ', array(strip_tags($this->get_value('title')), date('Y'), date('F'))),
			'show_hide' => 'show',
			'new' => 0
		);
				
		$this->new_post_id = reason_create_entity( 
			$this->site_info->id(), 
			id_of('news'), 
			$user_id, 
			$values['release_title'], 
			$values
		);
		
		create_relationship(
			$this->new_post_id,
			$this->publication->id(),
			relationship_id_of('news_to_publication')
		);

		if ($this->successfully_submitted())
		{
			
			if($this->hold_posts_for_review)
			{
				echo '<p>Posts are being held for review on this publication. Please check back later to see if your post has been published.</p>';
				echo '<a href="?">Back to main page</a>';
			
			}
			else
			{
				echo '<p>Your post has been published.</p>';
				echo '<a href="'.carl_construct_redirect(array('story_id'=>$this->new_post_id)).'">View it.</a>';
			}
		}
		
		if($this->get_value('issue'))
		{
			create_relationship($this->new_post_id, $this->get_value('issue'), relationship_id_of('news_to_issue'));
		}
		
		if($this->get_value('section'))
		{
			create_relationship($this->new_post_id, $this->get_value('section'), relationship_id_of('news_to_news_section'));
		}
		
		if($this->get_value('categories'))
		{
			foreach($this->get_value('categories') as $category_id)
			{
				// Check to make sure ids posted actually belong to categories in the site
				if(array_key_exists($category_id, $this->categories))
				{
					create_relationship(
						$this->new_post_id,
						$category_id,
						relationship_id_of('news_to_category')
					);
				}
			}
		}
		
		$this->show_form = false;

		$this->do_notifications();
	}
 /**
  * This callback generates the thumbnail image for the video.  It also updates some metadata 
  * such as duration for the entity.
  */
 public function _process_callback()
 {
     $username = reason_check_authentication();
     reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_publication_datetime' => date('Y-m-d H:i:s')), false);
     if ($this->manager->get_value('vimeo_url') && $this->manager->get_value('entry_id') != $this->original_entry_id) {
         // create image file in the vimeo temp directory
         $tmp_path = VimeoShim::get_temp_dir() . 'tmp_thumbnail_' . $this->manager->get_value('id');
         $f = fopen($tmp_path, 'w');
         $image_url = $this->shim->get_thumbnail($this->manager->get_value('entry_id'));
         $contents = get_reason_url_contents($image_url);
         fwrite($f, $contents);
         fclose($f);
         // Create a reason entity out of the temp image file
         if (!empty($tmp_path) and file_exists($tmp_path) && $username) {
             if ($id = $this->create_image_entity($username)) {
                 $im = new ImageManager();
                 $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                 $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                 $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                 $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                 $im->load_by_type(id_of('image'), $id, get_user_id($username));
                 $im->handle_standard_image($id, $tmp_path);
                 $im->create_default_thumbnail($id);
                 $values = array();
                 foreach ($im->get_element_names() as $element_name) {
                     $values[$element_name] = $im->get_value($element_name);
                 }
                 reason_update_entity($id, get_user_id($username), $values, false);
                 // Remove any existing association with an image and replace it with this new one
                 delete_relationships(array('entity_a' => $this->manager->get_value('id'), 'type' => relationship_id_of('av_to_primary_image')));
                 create_relationship($this->manager->get_value('id'), $id, relationship_id_of('av_to_primary_image'));
             }
         }
         // update the duration field of the media work.
         $data_obj = $this->shim->get_video_data($this->manager->get_value('entry_id'));
         if ($data_obj) {
             reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_duration' => format_seconds_as_human_readable(intval($data_obj->duration))), false);
         }
     }
 }
예제 #14
0
 function add_relationship_second_level()
 {
     if (empty($this->admin_page->request['unborrow'])) {
         create_relationship($this->admin_page->request[CM_VAR_PREFIX . 'id'], $this->admin_page->id, $this->admin_page->request[CM_VAR_PREFIX . 'rel_id']);
     }
 }
예제 #15
0
 function move_into_site($orphan_id, $types, $owner_site_id)
 {
     if (empty($this->_user_id)) {
         trigger_error('Must set user id before calling move_into_site()');
         return false;
     }
     if (!get_owner_site_id($orphan_id)) {
         $owns_rel_id = get_owns_relationship_id($types);
         // If there is an existing entry in the relationship table, delete it
         $q = 'DELETE FROM `relationship` WHERE `entity_b` = "' . reason_sql_string_escape($orphan_id) . '" AND `type` = "' . reason_sql_string_escape($owns_rel_id) . '"';
         $r = db_query($q, 'Unable to delete old owns relationship');
         // create new ownership entry
         create_relationship($owner_site_id, $orphan_id, $owns_rel_id);
     } else {
         trigger_error($orphan_id . ' not actually an orphan');
         return false;
     }
 }
예제 #16
0
		function _process_policy_metadata(&$disco)
		{
			$values['approvals'] = tidy($disco->get_value('approvals'));
			$values['last_revised_date'] = tidy($disco->get_value('last_revised_date'));
			$values['last_reviewed_date'] = carl_date('Y-m-d');
			$values['keywords'] = tidy($disco->get_value('keywords'));

			foreach ($this->all_audiences as $audience)
			{	
				// if the audience is checked
				if (in_array($this->audience_opts[$audience->get_value('name')], $disco->get_value('audiences')))
				{
					if (!in_array($audience, $this->related_audiences))
					{
						create_relationship($this->edit_policy->id(), $audience->id(), relationship_id_of('policy_to_relevant_audience'));
					}
				}
				// if the audience was unchecked by the user
				elseif (in_array($audience, $this->related_audiences))
				{
					$conditions = array(
						'entity_a'=> $this->edit_policy->id(),
						'entity_b'=> $audience->id(),
						'type'=> relationship_id_of('policy_to_relevant_audience'),
					);
					delete_relationships($conditions);
				}
			}
			$archive = ($disco->get_chosen_action() == 'save_and_finish') ? true : false;
			$succes = reason_update_entity( $this->request['policy_id'], $this->get_update_entity_user_id(), $values, $archive );
		}
예제 #17
0
 function do_course_toggle($id)
 {
     $this->build_course_list();
     if (isset($this->courses[$id])) {
         if ($this->courses[$id]->include_source == 'page_courses') {
             $course = new entity($id);
             $rels = $course->get_left_relationships_info();
             foreach ($rels['course_template_to_page'] as $rel) {
                 if ($rel['entity_b'] == $this->get_source_page_id()) {
                     delete_relationship($rel['id']);
                     return true;
                     break;
                 }
             }
         } else {
             if ($this->courses[$id]->include_source == 'categories') {
                 $course = new entity($id);
                 $rels = $course->get_left_relationships_info();
                 $cats = $this->get_page_categories();
                 foreach ($rels['course_template_to_category'] as $rel) {
                     if (isset($cats[$rel['entity_b']])) {
                         delete_relationship($rel['id']);
                         return true;
                         break;
                     }
                 }
             }
         }
     } else {
         if ($this->params['get_page_courses']) {
             return create_relationship($id, $this->get_source_page_id(), relationship_id_of('course_template_to_page'), false, false);
         } else {
             if ($this->params['get_courses_by_page_categories']) {
                 if ($cats = $this->get_page_categories()) {
                     // For now we're just attaching the first page category we find to the course;
                     // a better, future interface would allow the user to pick the category.
                     $cat_id = key($cats);
                     return create_relationship($id, $cat_id, relationship_id_of('course_template_to_category'), false, false);
                 }
             }
         }
     }
     return false;
 }
예제 #18
0
 function update_default_issue_view()
 {
     $es = new entity_selector(id_of('master_admin'));
     $es->add_type(id_of('view'));
     $es->add_right_relationship(id_of('issue_type'), relationship_id_of('type_to_default_view'));
     $es->set_num(1);
     $views = $es->run_one();
     if (!empty($views)) {
         echo '<p>Default issue view already exists. No need to create a default issue view.</p>' . "\n";
         return;
     }
     if ($this->mode == 'run') {
         echo '<p>Creating default issue view...</p>' . "\n";
         echo '<ul>' . "\n";
         $id = reason_create_entity(id_of('master_admin'), id_of('view'), $this->reason_user_id, 'Default Issue View', array('display_name' => 'List', 'column_order' => 'id, name, datetime, show_hide, last_modified', 'default_sort' => 'datetime, desc'));
         if (empty($id)) {
             echo '<li>Unable to create default issue view. This is not a critical update, but you may want to look into why this did not work. Aborting default issue creation.</li></ul>' . "\n";
             return;
         }
         echo '<li>Created default issue view</li>' . "\n";
         $success = create_relationship($id, id_of('generic_lister'), relationship_id_of('view_to_view_type'));
         if ($success) {
             echo '<li>Associated default issue view with the List view type.</li>' . "\n";
         } else {
             echo '<li>Did not successfully associate default issue view with the List view type.</li>' . "\n";
         }
         $show_hide_field_id = $this->get_field_id('show_hide', 'show_hide');
         if (!empty($show_hide_field_id)) {
             $success = create_relationship($id, $show_hide_field_id, relationship_id_of('view_columns'));
             if ($success) {
                 echo '<li>Added the show_hide field to the view.</li>' . "\n";
             } else {
                 echo '<li>Did not successfully add the show_hide field to the view.</li>' . "\n";
             }
             $success = create_relationship($id, $show_hide_field_id, relationship_id_of('view_searchable_fields'));
             if ($success) {
                 echo '<li>Added the show_hide field to the searchable fields.</li>' . "\n";
             } else {
                 echo '<li>Did not successfully add the show_hide field to the searchable fields.</li>' . "\n";
             }
         }
         $datetime_field_id = $this->get_field_id('dated', 'datetime');
         if (!empty($datetime_field_id)) {
             $success = create_relationship($id, $datetime_field_id, relationship_id_of('view_columns'));
             if ($success) {
                 echo '<li>Added the datetime field to the view.</li>' . "\n";
             } else {
                 echo '<li>Did not successfully add the datetime field to the view.</li>' . "\n";
             }
             $success = create_relationship($id, $datetime_field_id, relationship_id_of('view_searchable_fields'));
             if ($success) {
                 echo '<li>Added the datetime field to the searchable fields.</li>' . "\n";
             } else {
                 echo '<li>Did not successfully add the datetime field to the searchable fields.</li>' . "\n";
             }
         }
         $success = create_relationship(id_of('issue_type'), $id, relationship_id_of('type_to_default_view'));
         if ($success) {
             echo '<li>Set up new view as the default view for issues.</li>' . "\n";
         } else {
             echo '<li>Did not successfully set up new view as the default view for issues.</li>' . "\n";
         }
         echo '</ul>' . "\n";
     } else {
         echo '<p>Would have created the default issue view.</p>' . "\n";
     }
 }
예제 #19
0
 function associate_with_nobody_group($reln_unique_name)
 {
     //disassociate any current groups
     if ($this->entity->has_left_relation_of_type($reln_unique_name)) {
         $this->delete_associations_of_type($reln_unique_name);
     }
     //create a relationship with the nobody group
     create_relationship($this->entity->id(), id_of('nobody_group'), relationship_id_of($reln_unique_name));
 }
 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;
 }
예제 #21
0
	/**
	 * Move all the fields of one table into another table for a specific type
	 *
	 * This method is for denormalizing Reason tables. For example, a type may use a common table
	 * like meta, datetime, or chunk. For performance reasons, it can be desirable to collapse
	 * these tables into a single table just for that type. This method will do that.
	 * 
	 * @param integer $type The ID of the type whose fields we are moving
	 * @param string $source_table The name of the table we are moving fields FROM
	 * @param string $destination_table The name of the table we are moving fields TO
	 * @param integer $user_id The Reason ID of the user who is doing this move
	 * @return boolean Success
	 *
	 * @todo Add limit to ensure fields are only created that don't already exist
	 */
	function reason_move_table_fields($type, $source_table, $destination_table, $user_id)
	{
		// Sanity checks
		
		if(empty($type))
		{
			trigger_error('No type provided in reason_move_table_fields()');
			return false;
		}
		
		if(empty($source_table))
		{
			trigger_error('No source table provided in reason_move_table_fields()');
			return false;
		}
		
		if(!is_string($source_table))
		{
			trigger_error('Source table provided not a string in reason_move_table_fields()');
			return false;
		}
		
		if(empty($destination_table))
		{
			trigger_error('No destination table provided in reason_move_table_fields()');
			return false;
		}
		
		if(!is_string($destination_table))
		{
			trigger_error('Destination table provided not a string in reason_move_table_fields()');
			return false;
		}
		
		if('entity' == $source_table || 'entity' == $destination_table)
		{
			trigger_error('reason_move_table_fields() cannot move fields into or out of the entity table.');
			return false;
		}
		
		if(is_object($type))
		{
			$type_id = $type->id();
		}
		elseif(is_numeric($type))
		{
			$type_id = (integer) $type;
		}
		else
		{
			$type_id = id_of($type);
		}
		
		if(empty($type_id))
		{
			trigger_error('Invalid type specified in reason_move_table_fields().');
			return false;
		}
		
		if(is_object($type))
			$type_entity = $type;
		else
			$type_entity = new entity($type_id);
		
		$type_vals = $type_entity->get_values();
		if(empty($type_vals))
		{
			trigger_error('Type specified (id '.$type_id.') is not a Reason entity in reason_move_table_fields().');
			return false;
		}
		if($type_entity->get_value('type') != id_of('type'))
		{
			trigger_error('Type specified (id '.$type_id.') is not a Type entity in reason_move_table_fields().');
			return false;
		}
		if($type_entity->get_value('state') != 'Live')
		{
			trigger_error('Type specified (id '.$type_id.') is not a live entity in reason_move_table_fields().');
			return false;
		}
		
		if(empty($user_id))
		{
			trigger_error('No user id specified in reason_move_table_fields().');
			return false;
		}
		$user = new entity($user_id);
		if(!$user->get_values() || $user->get_value('type') != id_of('user'))
		{
			trigger_error('Invalid user ID specified in reason_move_table_fields().');
			return false;
		}
		
		// check for table existence
		$es = new entity_selector();
		$es->add_type(id_of('content_table'));
		$es->add_relation('`name` = "'.addslashes($source_table).'"');
		$source_table_result = $es->run_one();
		if(empty($source_table_result))
		{
			trigger_error('Source table "'.$source_table.'" does not exist in reason_move_table_fields()');
			return false;
		}
		
		$es = new entity_selector();
		$es->add_type(id_of('content_table'));
		$es->add_relation('`name` = "'.addslashes($destination_table).'"');
		$destination_table_result = $es->run_one();
		if(empty($destination_table_result))
		{
			trigger_error('Destination table "'.$destination_table.'" does not exist in reason_move_table_fields()');
			return false;
		}
		
		$source_table_entity = current($source_table_result);
		$destination_table_entity = current($destination_table_result);
		
		// ensure type uses both tables
		
		$type_tables = get_entity_tables_by_type( $type_id );
		
		if(!in_array($source_table, $type_tables))
		{
			trigger_error('Source table "'.$source_table.'" not part of the type in reason_move_table_fields()');
			return false;
		}
		
		if(!in_array($destination_table, $type_tables))
		{
			trigger_error('Destination table "'.$destination_table.'" not part of the type in reason_move_table_fields()');
			return false;
		}
		
		$es = new entity_selector();
		$es->add_type(id_of('type'));
		$es->add_left_relationship($destination_table_entity->id(),relationship_id_of('type_to_table'));
		$es->add_relation('`entity`.`id` != "'.addslashes($type_id).'"');
		$other_types = $es->run_one();
		
		if(!empty($other_types))
		{
			trigger_error(count($other_types).' other type(s) share the destination table with the type specified in reason_move_table_fields(). reason_move_table_fields() can only move fields into single-type tables.');
			return false;
		}
		
		// get the fields in the old table
		$es = new entity_selector();
		$es->add_type(id_of('field'));
		$es->add_left_relationship($source_table_entity->id(), relationship_id_of('field_to_entity_table'));
		$source_table_fields = $es->run_one();
		
		if(empty($source_table_fields))
		{
			trigger_error('Source table '.$source_table.' does not appear to have any fields associated with it in Reason. Unable to move its content in reason_move_table_fields()');
		}
		
		$q = 'DESCRIBE `'.addslashes($destination_table).'`';
		$handle = db_query( $q, 'Unable to describe destination table in reason_move_table_fields()' );
		$raw_dest_cols = array();
		while($row = mysql_fetch_assoc($handle))
		{
			$raw_dest_cols[] = $row['Field'];
		}
		
		
		foreach($source_table_fields as $k=>$field)
		{
			if(in_array($field->get_value('name'),$raw_dest_cols))
			{
				trigger_error($field->get_value('name').' field is already in destination table. Unable to accomplish reason_move_table_fields().');
				return false;
			}
			$tmp_field_name = $field->get_value('name').'_move_tmp';
			if(in_array($tmp_field_name,$raw_dest_cols))
			{
				trigger_error($tmp_field_name.' field already in destination table. There appears to have been an error in a previous attempt to run reason_move_table_fields(). Please drop this column in MySQL and try again.');
				return false;
			}
			$source_table_fields[$k]->set_value('_field_move_temp_name',$field->get_value('name').'_move_tmp');
		}
		
		// Done with sanity checks
		
		
		// map old to temp field names & create new fields
		$query_parts = array();
		foreach($source_table_fields as $k=>$field)
		{
			$source_table_fields[$k]->set_value('_field_move_temp_name',$field->get_value('name').'_move_tmp');
			$q = 'ALTER TABLE `'.addslashes($destination_table).'` ADD '.addslashes( $field->get_value('_field_move_temp_name') ).' '. $field->get_value('db_type');
			db_query( $q, 'Unable to create new field '.$field->get_value('_field_move_temp_name').' in reason_move_table_fields()' );
			$values = array();
			foreach($field->get_values() as $f=>$v)
			{
				if($f != 'name' && $f != 'id' && strpos($f,'_') !== 0)
				{
					$values[$f] = $v;
				}
			}
			$id = reason_create_entity( id_of('master_admin'), id_of('field'), $user_id, $field->get_value('_field_move_temp_name'), $values);
			$source_table_fields[$k]->set_value('_new_field_id',$id);
			$query_parts[] = '`'.addslashes($destination_table).'`.`'.addslashes($field->get_value('_field_move_temp_name')).'` = `'.addslashes($source_table).'`.`'.addslashes($field->get_value('name')).'`';
		}
		
		// copy content of old fields to new fields
		
		
		$q = 'UPDATE `'.addslashes($destination_table).'`, `'.addslashes($source_table).'`, `entity` SET '.implode(' , ',$query_parts).' WHERE `'.addslashes($destination_table).'`.`id` = `'.addslashes($source_table).'`.`id` AND `'.addslashes($destination_table).'`.`id` = `entity`.`id` AND `entity`.`type` = "'.addslashes($type_id).'";';
		
		db_query($q,'Attempt to move data between fields');
		
		
		// zap source table's type-to-table relationship for this type
		
		$conditions = array(
			'entity_a' => $type_id,
			'entity_b' => $source_table_entity->id(),
			'type' => relationship_id_of('type_to_table'),
		);
		
		delete_relationships( $conditions );
		
		// create new field-to-table relationship for new fields and update field names in new table -- remove temp flag
		
		foreach($source_table_fields as $field)
		{
			create_relationship( $field->get_value('_new_field_id'), $destination_table_entity->id(), relationship_id_of(	'field_to_entity_table' ) );
			$q = 'ALTER TABLE `'.addslashes($destination_table).'` CHANGE '.addslashes($field->get_value('_field_move_temp_name')).' '.addslashes( $field->get_value('name') ).' '.$field->get_value('db_type') ;
			db_query( $q, 'Unable to change field name of '.$field->get_value('_field_move_temp_name').' in reason_move_table_fields()' );
			reason_update_entity( $field->get_value('_new_field_id'), $user_id, array('name' => $field->get_value('name') ), false );
		}
		
		// delete the rows from the source table
		
		$q = 'DELETE `'.addslashes($source_table).'` FROM `'.addslashes($source_table).'`, `entity` WHERE `'.addslashes($source_table).'`.`id` = `entity`.`id` AND `entity`.`type` = "'.addslashes($type_id).'"';
		
		db_query($q,'Attempt to delete rows from '.$source_table.' in reason_move_table_fields()');
		
		get_entity_tables_by_id( $type_id, false );
		
		return true;
			
	}
예제 #22
0
 protected function _create_media_entity($disco)
 {
     // put together the values for the entity
     $name = htmlspecialchars($disco->get_value('media_title'));
     $values = $this->params['default_values'];
     $values['name'] = $name;
     $values['new'] = "0";
     $values['author'] = htmlspecialchars($disco->get_value('name'));
     if ($disco->get_value('class_year')) {
         switch (strlen($disco->get_value('class_year'))) {
             case 4:
                 $values['author'] .= ' \'' . htmlspecialchars(mb_substr($disco->get_value('class_year'), -2));
                 break;
             case 3:
                 $values['author'] .= htmlspecialchars($disco->get_value('class_year'));
                 break;
             case 2:
                 $values['author'] .= ' \'' . htmlspecialchars($disco->get_value('class_year'));
         }
     }
     $values['description'] = htmlspecialchars($disco->get_value('description'));
     $values['keywords'] = $name . ', ' . $values['author'];
     $values['entry_id'] = $this->_entry->id;
     $values['av_type'] = $disco->get_value('av_type');
     $values['transcoding_status'] = 'converting';
     $values['integration_library'] = 'kaltura';
     $values['tmp_file_name'] = $this->_filename;
     // create the entity
     $this->_media_work_id = $id = reason_create_entity($this->site_id, id_of('av'), $this->_user_id, $name, $values);
     //$this->set_form_id($id);
     $page_id = $this->page_id;
     if (!empty($this->params['entries_gallery_page'])) {
         if (reason_unique_name_exists($this->params['entries_gallery_page'])) {
             $page_id = id_of($this->params['entries_gallery_page']);
         } else {
             trigger_error('Unable to find uniquely named page ' . $this->params['entries_gallery_page'] . '. Attaching photos to form page.');
         }
     }
     create_relationship($page_id, $id, relationship_id_of('minisite_page_to_av'));
     // access restriction
     $da = reason_get_default_access();
     if ($this->params['default_group_uname'] && reason_unique_name_exists($this->params['default_group_uname'])) {
         $group_id = id_of($this->params['default_group_uname']);
         create_relationship($id, $group_id, relationship_id_of('av_restricted_to_group'));
     } elseif ($group_id = $da->get($this->site_id, 'av', 'av_restricted_to_group')) {
         create_relationship($id, $group_id, relationship_id_of('av_restricted_to_group'));
     }
     return $id;
 }
 function process()
 {
     foreach ($this->pages_using_news_modules as $k => $page) {
         $npt_name = 'npt_page' . $k;
         $ar_name = $this->helper->get_allowable_relationship_for_page_type($this->get_value($npt_name));
         $pubs_for_page = $this->get_value('pubs_for_page' . $k);
         reason_update_entity($k, $this->user_id, array('custom_page' => $this->get_value($npt_name)));
         foreach ($pubs_for_page as $pub_id) {
             create_relationship($k, $pub_id, relationship_id_of($ar_name));
         }
     }
 }
예제 #24
0
 function sync_with_old_catalog($year)
 {
     $courses = array();
     $es = new entity_selector();
     $es->description = 'Selecting courses';
     $factory = new CourseTemplateEntityFactory();
     $es->set_entity_factory($factory);
     $es->add_type(id_of('course_template_type'));
     $es->set_order('course_number');
     $results = $es->run_one();
     connectdb('reg_catalog_new');
     foreach ($results as $id => $entity) {
         $query = 'SELECT id FROM course' . $year . ' WHERE visible = 1 AND course_id = "' . $entity->get_value('sourced_id') . '"';
         if ($result = mysql_query($query)) {
             if (mysql_num_rows($result)) {
                 connectdb(REASON_DB);
                 create_relationship($this->site_id, $entity->id(), get_borrows_relationship_id(id_of('course_template_type')));
                 connectdb('reg_catalog_new');
             }
         }
     }
     connectdb(REASON_DB);
 }
예제 #25
0
 function _process_relationship_element($name, $info)
 {
     $values = $this->get_value($name);
     if (!is_array($values)) {
         $values = array($values);
     }
     foreach ($info['options'] as $id) {
         if (in_array($id, $values)) {
             if (!in_array($id, $info['related_at_prep'])) {
                 // this neeeds a little more mojo to be site context aware
                 if ($info['direction'] == 'right') {
                     create_relationship($this->get_value('id'), $id, $info['rel_id']);
                 } else {
                     // if $id is not owned by current site, add site id to relationship
                     create_relationship($id, $this->get_value('id'), $info['rel_id'], array('site' => $this->_get_rel_site_value($id)));
                 }
             }
         } else {
             if (in_array($id, $info['related_at_prep'])) {
                 if ($info['direction'] == 'right') {
                     $conditions = array('entity_a' => $this->get_value('id'), 'entity_b' => $id, 'type' => $info['rel_id'], 'site' => 0);
                 } else {
                     $conditions = array('entity_a' => $id, 'entity_b' => $this->get_value('id'), 'type' => $info['rel_id'], 'site' => $this->_get_rel_site_value($id));
                 }
                 delete_relationships($conditions);
             }
         }
     }
 }
/**
 * Attempt to attach a thumbnail to the media work.
 *
 * @param $obj object
 * @param $media_work entity
 * @param $netid string
 */
function attach_thumbnail($obj, $media_work, $netid)
{
    // check to see if this had thumbnails generated
    if (property_exists($obj, 'thumbnails')) {
        // First, create temp file
        $tmp_path = ZencoderShim::get_temp_dir() . 'temp_media_image_' . $media_work->get_value('entry_id') . '.jpg';
        $f = fopen($tmp_path, 'w');
        $image_url = $obj->thumbnails[0]->images[0]->url;
        $contents = get_reason_url_contents($image_url);
        fwrite($f, $contents);
        fclose($f);
        // Then, create image entity.  Attach it to the media work, too.
        if (!empty($tmp_path) and file_exists($tmp_path)) {
            // Create a new entity for the image
            if ($id = create_image_entity($media_work, $netid)) {
                $im = new ImageManager();
                //$im->convert_non_web_to = $this->convert_non_web_to;
                $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                $im->load_by_type(id_of('image'), $id, get_user_id($netid));
                $im->handle_standard_image($id, $tmp_path);
                //$im->handle_original_image($id, $image);
                $im->create_default_thumbnail($id);
                $dimensions = $obj->thumbnails[0]->images[0]->dimensions;
                $arr = explode('x', $dimensions);
                $thumb_width = intval($arr[0]);
                $thumb_height = intval($arr[1]);
                if ($thumb_width > $im->max_width || $thumb_height > $im->max_height) {
                    $image_path = PHOTOSTOCK . reason_format_image_filename($id, 'jpg');
                    $original_path = add_name_suffix($image_path, '_orig');
                    @copy($image_path, $original_path);
                    resize_image($image_path, $im->max_width, $im->max_height);
                }
                // Pull the values generated in the content manager
                // and save them to the entity
                $values = array();
                foreach ($im->get_element_names() as $element_name) {
                    $values[$element_name] = $im->get_value($element_name);
                }
                reason_update_entity($id, get_user_id($netid), $values, false);
                // Remove any existing association with an image and replace it with this new one
                delete_relationships(array('entity_a' => $media_work->id(), 'type' => relationship_id_of('av_to_primary_image')));
                create_relationship($media_work->id(), $id, relationship_id_of('av_to_primary_image'));
            } else {
                trigger_error('Failed to create image entity.');
            }
        } else {
            trigger_error('No path to image: ' . $tmp_path);
        }
    }
}
예제 #27
0
function add_editor_user_role($test_mode = true)
{
    echo '<h3>Adding editor user role</h3>';
    $editor_user_role_id = id_of('editor_user_role');
    echo '<ul>';
    if (!empty($editor_user_role_id)) {
        echo '<li>Editor user role already exists; no need to create it</li>';
    } else {
        if ($test_mode) {
            echo '<li>Would have created editor user role</li>';
        } else {
            $editor_user_role_id = reason_create_entity(id_of('master_admin'), id_of('user_role'), $GLOBALS['__cur_user_id_hack__'], 'Editor', array('new' => '0', 'unique_name' => 'editor_user_role'));
            if ($editor_user_role_id) {
                echo '<li>Created editor user role (ID: ' . $editor_user_role_id . ')</li>';
            } else {
                echo '<li>Unable to create editor user role! Aborting this step.</li></ul>';
                return false;
            }
        }
    }
    // get users with their user roles
    $es = new entity_selector();
    $es->add_type(id_of('user'));
    $es->add_left_relationship_field('user_to_user_role', 'entity', 'id', 'user_role_id', false);
    $users = $es->run_one();
    if ($test_mode) {
        echo '<li>Would have added editor user role to these users currently without a role:';
    } else {
        echo '<li>Adding editor user role to users currently without a role:';
    }
    echo '<ol>';
    $count = 0;
    foreach ($users as $user) {
        if (!$user->get_value('user_role_id')) {
            $count++;
            if ($test_mode) {
                echo '<li>' . $user->get_value('name') . '</li>';
            } else {
                if (create_relationship($user->id(), $editor_user_role_id, relationship_id_of('user_to_user_role'))) {
                    echo '<li>' . $user->get_value('name') . '</li>';
                } else {
                    echo '<li><strong>Eeep!</strong> Problem assigning editor user role to ' . $user->get_value('name') . '</li>';
                }
            }
        }
    }
    echo '</ol>';
    if (!$count) {
        echo '<strong>No users needed to be updated; all users have roles.</strong>';
    }
    echo '</li>';
    echo '</ul>';
}
예제 #28
0
        if (!empty($templates)) {
            $temp = current($templates);
            $es = new entity_selector();
            $es->add_type(id_of('theme_type'));
            $es->add_relation('entity.unique_name NOT IN ("' . implode('","', $core_themes) . '")');
            $es->add_left_relationship($temp->id(), relationship_id_of('theme_to_template'));
            $themes = $es->run_one();
            if (!empty($themes)) {
                $es->add_left_relationship($css->id(), relationship_id_of('theme_to_external_css_url'));
                $themes_with_css_selector = $es->run_one();
                foreach ($themes_with_css_selector as $twcs) {
                    unset($themes[$twcs->id()]);
                }
                if (!empty($themes)) {
                    foreach ($themes as $theme) {
                        create_relationship($theme->id(), $css->id(), relationship_id_of('theme_to_external_css_url'));
                        echo '<p>Added cssSelector to theme: ' . $theme->get_value('name') . '</p>';
                    }
                } else {
                    echo '<p>All themes associated with the ' . $template . ' template are already using the cssSelector</p>';
                }
            } else {
                echo '<p>No themes associated with the ' . $template . ' template</p>';
            }
        } else {
            echo '<p>strong>Error:</strong> Couldn\'t find the ' . $template . ' template</p>';
        }
    }
} else {
    echo '<p><strong>Error:</strong> Couldn\'t find the cssSelector!</p>';
}
예제 #29
0
 function process()
 {
     $site_id = $this->site_id;
     $counts = array();
     for ($i = 1; $i <= $this->max_upload_number; $i++) {
         $element = $this->get_element('upload_' . $i);
         if (!empty($element->tmp_full_path) and file_exists($element->tmp_full_path)) {
             $filename = $this->get_value('upload_' . $i . '_filename');
             if ($this->verify_image($element->tmp_full_path)) {
                 if (empty($counts[$filename])) {
                     $this->files[$filename] = $element->tmp_full_path;
                     $counts[$filename] = 1;
                 } else {
                     $counts[$filename]++;
                     $this->files[$filename . '.' . $counts[$filename]] = $element->tmp_full_path;
                 }
             } else {
                 $this->invalid_files[$filename] = $element->tmp_full_path;
             }
         }
     }
     if (count($this->files)) {
         $page_id = (int) $this->get_value('attach_to_page');
         $max_sort_order_value = 0;
         if ($page_id) {
             $max_sort_order_value = $this->_get_max_sort_order_value($page_id);
         }
         $sort_order_value = $max_sort_order_value;
         $tables = get_entity_tables_by_type(id_of('image'));
         $valid_file_html = '<ul>' . "\n";
         foreach ($this->files as $entry => $cur_name) {
             $sort_order_value++;
             $valid_file_html .= '<li><strong>' . $entry . ':</strong> processing ';
             $date = '';
             // get suffix
             $type = strtolower(substr($cur_name, strrpos($cur_name, '.') + 1));
             $ok_types = array('jpg');
             // get exif data
             if ($this->get_value('exif_override') && in_array($type, $ok_types) && function_exists('read_exif_data')) {
                 // read_exif_data() does not obey error supression
                 $exif_data = @read_exif_data($cur_name);
                 if ($exif_data) {
                     // some photos may have different fields filled in for dates - look through these until one is found
                     $valid_dt_fields = array('DateTimeOriginal', 'DateTime', 'DateTimeDigitized');
                     foreach ($valid_dt_fields as $field) {
                         // once we've found a valid date field, store that and break out of the loop
                         if (!empty($exif_data[$field])) {
                             $date = $exif_data[$field];
                             break;
                         }
                     }
                 }
             } else {
                 $date = $this->get_value('datetime');
             }
             $keywords = $entry;
             if ($this->get_value('keywords')) {
                 $keywords .= ', ' . $this->get_value('keywords');
             }
             // insert entry into DB with proper info
             $values = array('datetime' => $date, 'image_type' => $type, 'author' => $this->get_value('author'), 'state' => 'Pending', 'keywords' => $keywords, 'description' => $this->get_value('description'), 'name' => $this->get_value('name') ? $this->get_value('name') : $entry, 'content' => $this->get_value('content'), 'original_image_format' => $this->get_value('original_image_format'), 'new' => 0, 'no_share' => $this->get_value('no_share'));
             //tidy values
             $no_tidy = array('state', 'new');
             foreach ($values as $key => $val) {
                 if (!in_array($key, $no_tidy) && !empty($val)) {
                     $values[$key] = trim(get_safer_html(tidy($val)));
                 }
             }
             $id = reason_create_entity($site_id, id_of('image'), $this->user_id, $entry, $values);
             if ($id) {
                 //assign to categories
                 $categories = $this->get_value('assign_to_categories');
                 if (!empty($categories)) {
                     foreach ($categories as $category_id) {
                         create_relationship($id, $category_id, relationship_id_of('image_to_category'));
                     }
                 }
                 //assign to	gallery page
                 if ($page_id) {
                     create_relationship($page_id, $id, relationship_id_of('minisite_page_to_image'), array('rel_sort_order' => $sort_order_value));
                 }
                 // resize and move photos
                 $new_name = PHOTOSTOCK . $id . '.' . $type;
                 $orig_name = PHOTOSTOCK . $id . '_orig.' . $type;
                 $tn_name = PHOTOSTOCK . $id . '_tn.' . $type;
                 // Support for new fields; they should be set null by default, but will be
                 // changed below if a thumbnail/original image is created. This is very messy...
                 $thumbnail_image_type = null;
                 $original_image_type = null;
                 // atomic move the file if possible, copy if necessary
                 if (is_writable($cur_name)) {
                     rename($cur_name, $new_name);
                 } else {
                     copy($cur_name, $new_name);
                 }
                 // create a thumbnail if need be
                 list($width, $height, $type, $attr) = getimagesize($new_name);
                 if ($width > REASON_STANDARD_MAX_IMAGE_WIDTH || $height > REASON_STANDARD_MAX_IMAGE_HEIGHT) {
                     copy($new_name, $orig_name);
                     resize_image($new_name, REASON_STANDARD_MAX_IMAGE_WIDTH, REASON_STANDARD_MAX_IMAGE_HEIGHT);
                     $original_image_type = $this->image_types[$type];
                 }
                 $thumb_dimensions = get_reason_thumbnail_dimensions($site_id);
                 if ($width > $thumb_dimensions['width'] || $height > $thumb_dimensions['height']) {
                     copy($new_name, $tn_name);
                     resize_image($tn_name, $thumb_dimensions['width'], $thumb_dimensions['height']);
                     $thumbnail_image_type = $this->image_types[$type];
                 }
                 // real original
                 $my_orig_name = $this->add_name_suffix($cur_name, '-unscaled');
                 if (file_exists($my_orig_name)) {
                     // move the original image into the photostock directory
                     if (is_writable($my_orig_name)) {
                         rename($my_orig_name, $orig_name);
                     } else {
                         copy($my_orig_name, $orig_name);
                     }
                     $original_image_type = $this->image_types[$type];
                 }
                 $info = getimagesize($new_name);
                 $size = round(filesize($new_name) / 1024);
                 // now we have the size of the resized image.
                 $values = array('width' => $info[0], 'height' => $info[1], 'size' => $size, 'thumbnail_image_type' => $thumbnail_image_type, 'original_image_type' => $original_image_type);
                 // update with new info - don't archive since this is really just an extension of the creation of the item
                 // we needed that ID to do something
                 reason_update_entity($id, $this->user_id, $values, false);
                 $valid_file_html .= 'completed</li>';
             } else {
                 trigger_error('Unable to create image entity');
                 $valid_file_html .= '<li>Unable to import ' . $entry . '</li>';
             }
             sleep(1);
         }
         $valid_file_html .= '</ul>' . "\n";
         $num_image_string = count($this->files) == 1 ? '1 image has ' : count($this->files) . ' images have ';
         $valid_file_html .= '<p>' . $num_image_string . 'been successfully imported into Reason.</p>';
         $valid_file_html .= '<p>They are now pending.</p>';
         $next_steps[] = '<a href="?site_id=' . $site_id . '&amp;type_id=' . id_of('image') . '&amp;user_id=' . $this->user_id . '&amp;cur_module=Lister&amp;state=pending">review & approve imported images</a>';
     }
     if (isset($this->invalid_files)) {
         $invalid_files = array_keys($this->invalid_files);
         $invalid_file_html = '<p>The following could not be validated as image files and were not successfully imported.</p>';
         $invalid_file_html .= '<ul>';
         foreach ($invalid_files as $file) {
             $invalid_file_html .= '<li><strong>' . reason_htmlspecialchars($file) . '</strong></li>';
         }
         $invalid_file_html .= '</ul>';
     }
     $next_steps[] = '<a href="' . get_current_url() . '">Import another set of images</a>';
     if (!isset($this->invalid_files) && !isset($this->files)) {
         echo '<p>You did not select any files for upload</p>';
     }
     if (isset($valid_file_html)) {
         echo $valid_file_html;
     }
     if (isset($invalid_file_html)) {
         echo $invalid_file_html;
     }
     echo '<p>Next Steps:</p><ul><li>' . implode('</li><li>', $next_steps) . '</li></ul>';
     $this->show_form = false;
 }
예제 #30
0
        foreach ($fields as $key => $value) {
            $fields[$key] = array('db_type' => $value);
        }
        $updater = new FieldToEntityTable('classified_table', $fields);
        $updater->update_entity_table();
        $updater->report();
    }
    echo 'Checking for classified category type... ';
    if (reason_unique_name_exists('classified_category_type')) {
        echo 'Classified category type already exists. Proceeding.<br/>';
        $classified_category = id_of('classified_category_type');
    } else {
        echo 'Creating classified category type.<br/>';
        $classified_category = create_type($admin_site, id_of('type'), $user, 'Classified Category', array('new' => 0, 'plural_name' => 'Classified categories', 'unique_name' => 'classified_category_type'));
        echo 'Creating allowable relationship with classifieds<br/>';
        create_allowable_relationship($classified, $classified_category, 'classified_to_classified_category');
    }
    echo 'Putting entity tables on classified type<br/>';
    $rel = relationship_id_of('type_to_table');
    foreach (array('classified_table', 'meta', 'chunk', 'dated') as $t) {
        if (name_exists($t)) {
            create_relationship($classified, id_of_name($t), $rel);
        } else {
            echo "Missing name {$t}!<br/>";
        }
    }
    echo "Install was successful!<br/>";
}
?>
</body></html>