Пример #1
0
 function finish()
 {
     if ($this->chosen_action != 'cancel') {
         $id = $this->get_value('id');
         if ($id) {
             $e = new entity($id);
             if ($e->get_value('state') == 'Live') {
                 reason_update_entity($id, $this->admin_page->user_id, array('state' => 'Deleted'), false);
                 $type = new entity($this->admin_page->type_id);
                 $post_deleter_filename = $type->get_value('custom_post_deleter');
                 if (!empty($post_deleter_filename)) {
                     reason_include_once('content_post_deleters/' . $post_deleter_filename);
                     $post_deleter_class_name = $GLOBALS['_content_post_deleter_classes'][$post_deleter_filename];
                     $pd = new $post_deleter_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);
                     $pd->init($vars, $e);
                     $pd->run();
                 }
             } else {
                 // grab the state of the item before deleting
                 $this->del_entity_state = $e->get_value('state');
                 $this->delete_entity();
             }
         }
     }
 }
Пример #2
0
 function process_registration()
 {
     $dir = new directory_service();
     $dir->search_by_attribute('ds_username', $this->event->get_value('contact_username'), array('ds_email'));
     $to = $dir->get_first_value('ds_email');
     $dates = explode(',', $this->event->get_value('dates'));
     $date_strings = array();
     foreach ($dates as $date) {
         $date_strings[] = prettify_mysql_datetime(trim($date), 'l, d F Y');
     }
     $subject = 'Event Registration: ' . $_POST["name"] . ' for ' . $this->event->get_value('name');
     $body = 'Name: ' . $_POST["name"] . "\n";
     /*$body.="Department: ".$_POST["department"]."\n";
     		$body.="Campus Address: ".$_POST["address"]."\n";
     		$body.="Campus Postal Address: ".$_POST["postal_address"]."\n";
     		$body.="Work Phone: ".$_POST["phone"]."\n";*/
     $body .= "E-mail Address: " . $_POST["email"] . "\n\n";
     $body .= 'Class: ' . $this->event->get_value('name') . "\n\n";
     $body .= 'Dates:' . "\n" . implode("\n", $date_strings) . "\n\n";
     $body .= 'Time: ' . prettify_mysql_datetime($this->event->get_value('datetime'), 'g:i a') . "\n\n";
     $body .= 'Location: ' . $this->event->get_value('location') . "\n\n";
     // separated out so we don't repeat the content twice when we write back into the DB
     $other_info = 'Other Information: ' . "\n" . strip_tags($this->event->get_value('content')) . "\n\n";
     // to person who should get registration
     mail($to, $subject, $body . $other_info, "From: " . strip_tags($_POST["email"]));
     // to person who filled out email
     mail(strip_tags($_POST["email"]), $subject, $body . $other_info, "From: " . strip_tags($to));
     $values = array('registration' => 'full', 'show_hide' => 'hide', 'content' => $this->event->get_value('content') . '<h3>Registration Information</h3>' . nl2br(htmlspecialchars($body, ENT_QUOTES)));
     reason_update_entity($this->event->id(), $this->event->get_value('last_edited_by'), $values, true);
     $this->show_registration_thanks();
 }
 /**
  * Run the upgrader
  *
  * @return string HTML report
  */
 public function run()
 {
     $ret = '';
     $e = new entity(id_of('css'));
     if (!$e->get_value('custom_content_handler')) {
         reason_update_entity($e->id(), $this->user_id(), array('custom_content_handler' => 'css.php'));
         $ret .= '<p>The CSS type has been assigned a content manager.</p>' . "\n";
     }
     $tables = get_entity_tables_by_type(id_of('css'), false);
     $has_meta = in_array('meta', $tables);
     $has_url = in_array('url', $tables);
     if ($has_meta || $has_url) {
         set_time_limit(3600);
         if ($has_meta) {
             $ret .= $this->_move_table_fields('meta');
         }
         if ($has_url) {
             $ret .= $this->_move_table_fields('url');
         }
     }
     if (empty($ret)) {
         $ret .= '<p>This upgrade has already been run. There is nothing to do.</p>';
     }
     return $ret;
 }
 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'));
 }
 /**
  * Run the upgrader
  * @return string HTML report
  */
 public function run()
 {
     if ($this->content_manager_assigned()) {
         return '<p>This script has already run.</p>';
     } else {
         // lets set it and we'll set new to 0 at the same time just in case...
         reason_update_entity(id_of('audience_type'), $this->user_id(), array('custom_content_handler' => 'audience.php', 'new' => 0));
         return '<p>Set the audience type to use the audience content manager.</p>';
     }
 }
 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'));
 }
 /**
  * Run the upgrader
  * @return string HTML report
  */
 public function run()
 {
     $e = $this->get_feature_type_entity();
     $dnh = $e->get_value('display_name_handler');
     if (!empty($dnh)) {
         return '<p>This update has already run.</p>';
     } else {
         if (reason_update_entity($e->id(), $this->user_id(), array('display_name_handler' => 'feature.php'))) {
             return '<p>Added the feature display name handler.</p>';
         } else {
             return '<p>Failed to add the feature display name handler. Try again. If you are not successful, you may wish to try to add this handler manually: In Master Admin, edit the Feature type and select "Feature" as its display name handler.</p>';
         }
     }
 }
 function remove_minisite_page_rewrite_finish_action()
 {
     $minisite_page_type_entity = new entity(id_of('minisite_page'));
     $finish_action = $minisite_page_type_entity->get_value('finish_actions');
     if ($finish_action != 'update_rewrites.php') {
         echo '<p>The minisite_page finish action is not update_rewrites.php - this script has probably been run</p>';
     } elseif ($this->mode == 'test') {
         echo '<p>Would remove the update_rewrites.php finish action from the minisite_page type</p>';
     } elseif ($this->mode == 'run') {
         $updates = array('finish_actions' => '');
         reason_update_entity(id_of('minisite_page'), $this->reason_user_id, $updates);
         echo '<p>Removed the update_rewrites.php finish action from the minisite_page type</p>';
     }
 }
 /**
  * Run the upgrader
  * @return string HTML report
  */
 public function run()
 {
     $e = $this->get_site_type_entity();
     $deleter = $e->get_value('custom_deleter');
     if (!empty($deleter)) {
         return '<p>This update has already run.</p>';
     } else {
         if (reason_update_entity($e->id(), $this->user_id(), array('custom_deleter' => 'site.php'))) {
             return '<p>Added the site deleter.</p>';
         } else {
             return '<p>Failed to add the site deleter. Try again. If you are not successful, you may wish to try to add this handler manually: In Master Admin, edit the Site type and select "Site" as its custom deleter.</p>';
         }
     }
 }
Пример #10
0
 function change_news_custom_feed()
 {
     $news_type = new entity(id_of('news', false));
     $custom_feed = $news_type->get_value('custom_feed');
     if ($custom_feed == 'news.php') {
         if ($this->mode == 'run') {
             $values['custom_feed'] = 'sitewide_news.php';
             reason_update_entity($news_type->id(), $this->reason_user_id, $values);
             $link = REASON_HTTP_BASE_PATH . '/scripts/urls/update_urls.php';
             echo '<p>Changed the news type custom_feed from news to sitewide news.</p>';
         } else {
             echo '<p>Would change the news type custom_feed from news to sitewide news.</p>';
         }
     } else {
         echo '<p>The news type custom feed has been changed from news.php - this script has probably already been run.</p>';
     }
 }
 /**
  * Run the upgrader
  * @return string HTML report
  */
 public function run()
 {
     if ($image_type = $this->get_image_type_entity()) {
         if ($image_type->get_value('custom_deleter')) {
             $ret = 'Your image type already has a deleter.';
             if ('image.php' == $image_type->get_value('custom_deleter')) {
                 $ret .= ' This upgrader has already been run.';
             }
             return '<p>' . $ret . '</p>';
         } else {
             reason_update_entity($image_type->id(), $this->_user_id, array('custom_deleter' => 'image.php'));
             return '<p>Added the image deleter.</p><p>NOTE: If you want Reason to move deleted image files instead of simply deleting them, specify a directory in a REASON_IMAGE_GRAVEYARD setting.</p>';
         }
     } else {
         return '<p>Your instance doesn\'t have the image type. There is nothing to do.</p>';
     }
 }
 function change_blurb_page_types()
 {
     $to_change = $this->get_pages_needing_change();
     if (!$to_change) {
         echo '<p>There are no pages with the blurb page type that contain blurbs with headers</p>';
     } elseif ($this->mode == 'test') {
         echo '<p>Would change these pages:</p>';
         pray($to_change);
     } elseif ($this->mode == 'run') {
         if (!isset($this->new_blurb_page_type)) {
             trigger_error('The variable new_blurb_page_type must be defined in this class for this script to actually function.');
         } else {
             foreach ($to_change as $entity_id) {
                 $values = array('custom_page' => $this->new_blurb_page_type);
                 reason_update_entity($entity_id, $this->reason_user_id, $values);
             }
         }
     }
 }
Пример #13
0
 function init()
 {
     $this->admin_page->set_show('leftbar', false);
     if (empty($this->admin_page->id)) {
         $this->_not_undeletable_reason = 'no_id_provided';
         return false;
     }
     if (!reason_user_has_privs($this->admin_page->user_id, 'publish')) {
         $this->_not_undeletable_reason = 'insufficient_privileges';
         return false;
     }
     $item = new entity($this->admin_page->id);
     $user = new entity($this->admin_page->user_id);
     if (!$item->user_can_edit_field('state', $user)) {
         $this->_not_undeletable_reason = 'state_field_locked';
         return false;
     }
     if ($item->get_value('state') != 'Deleted') {
         $this->_not_undeletable_reason = 'not_deleted_yet';
         return false;
     }
     reason_update_entity($this->admin_page->id, $this->admin_page->user_id, array('state' => 'Live'), false);
     if ($this->admin_page->type_id == id_of('minisite_page')) {
         // zap nav cache so it reappears.
         reason_include_once('classes/object_cache.php');
         $cache = new ReasonObjectCache($this->admin_page->site_id . '_navigation_cache');
         $cache->clear();
     }
     $manager_site_id = $this->admin_page->site_id;
     if ($item->get_value('type') == id_of('site')) {
         $manager_site_id = $item->id();
     }
     //Updates the rewrites to prevent infinite redirection loop.
     reason_include_once('classes/url_manager.php');
     $urlm = new url_manager($manager_site_id);
     $urlm->update_rewrites();
     $link = unhtmlentities($this->admin_page->make_link(array('cur_module' => 'Lister', 'id' => '', 'state' => 'deleted')));
     header('Location: ' . $link);
     die;
 }
Пример #14
0
 /**
  * Run the upgrader
  * @return string HTML report
  */
 public function run()
 {
     if ($assets_needing_fixing = $this->get_assets_needing_fixing()) {
         $count = count(array_keys($assets_needing_fixing));
         foreach ($assets_needing_fixing as $k => $asset) {
             $new_values['last_edited_by'] = $asset->get_value('last_edited_by');
             $new_values['last_modified'] = $asset->get_value('last_modified');
             $new_values['mime_type'] = $this->new_mime_type;
             reason_update_entity($k, $new_values['last_edited_by'], $new_values, false);
         }
         return '<p>Fixed ' . $count . ' assets needing fixing.</p>';
     } else {
         return '<p>There are no assets needing fixing.</p>';
     }
 }
Пример #15
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;
			
	}
Пример #16
0
 protected function build_course_section_entities($data)
 {
     echo "Building section entities\n";
     foreach ($data as $key => $row) {
         //echo round(memory_get_usage()/1024,2)."K at point E\n";
         $es = new entity_selector();
         $es->add_type(id_of('course_section_type'));
         $name = sprintf('%s %s %s', $row['course_number'], $row['academic_session'], $row['title']);
         $es->relations = array();
         $es->add_relation('sourced_id = "' . $row['sourced_id'] . '"');
         if ($result = $es->run_one()) {
             $section = reset($result);
             // Find all the values that correspond to the data we're importing
             $values = array_intersect_key($section->get_values(), $row);
             if ($values != $row) {
                 echo 'Updating: ' . $name . "\n";
                 reason_update_entity($section->id(), get_user_id('causal_agent'), $row, false);
             } else {
                 echo 'Unchanged: ' . $name . "\n";
             }
         } else {
             if ($this->get_section_parent($row['parent_template_id'])) {
                 echo 'Adding: ' . $name . "\n";
                 $id = reason_create_entity(id_of('academic_catalog_site'), id_of('course_section_type'), get_user_id('causal_agent'), $name, $row);
                 $section = new entity($id);
             } else {
                 echo 'No course template found; skipping ' . $name . "\n";
                 continue;
             }
         }
         if (!empty($section)) {
             $this->link_section_to_parent($section);
         }
         //echo round(memory_get_usage()/1024,2)."K at point D\n";
     }
 }
Пример #17
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;
 }
Пример #18
0
function update_theme_content_manager($test_mode = true)
{
    echo '<h3>Theme Content Manager Update</h3>';
    $theme_type = new entity(id_of('theme_type'));
    if ($theme_type->get_values()) {
        if (!$theme_type->get_value('custom_content_handler')) {
            if ($test_mode) {
                echo '<p>Would have updated the theme type to use the new content manager</p>';
            } else {
                if (reason_update_entity(id_of('theme_type'), $GLOBALS['__cur_user_id_hack__'], array('custom_content_handler' => 'theme.php'))) {
                    echo '<p>Updated the theme type to use the new content manager</p>';
                } else {
                    echo '<p>Some sort of problem has occurred with updating the theme type to use the new content manager</p>';
                }
            }
        } else {
            echo '<p>Theme type appears to be using the file ' . $theme_type->get_value('custom_content_handler') . ' as a content manager. No database changes are needed.</p>';
        }
    } else {
        echo '<p>Theme type not found; unable to update</p>';
    }
}
 /**
  * Actions which happen based on the validated data from the form.
  * @access public
  */
 function process()
 {
     // lets make sure the event_agent user exists
     $user = new User();
     if (!$user->get_user('event_agent')) {
         $user->create_user('event_agent');
     }
     $name = str_replace(array($this->delimiter1, $this->delimiter2), '_', $this->get_value('name'));
     $new_data = implode($this->delimiter2, array(strip_tags($this->request_array['date']), strip_tags($name), strip_tags($this->get_value('email')), time()));
     $slot_values = get_entity_by_id($this->request_array['slot_id']);
     $old_data = $slot_values['registrant_data'];
     if (!empty($old_data)) {
         $registrant_data = $old_data . $this->delimiter1 . $new_data;
     } else {
         $registrant_data = $new_data;
     }
     $values = array('registrant_data' => $registrant_data);
     $successful_update = reason_update_entity($this->request_array['slot_id'], get_user_id('event_agent'), $values);
     if ($successful_update) {
         $this->show_form = false;
         $this->send_confirmation_emails();
         $this->show_registration_thanks();
     } else {
         $this->show_registration_error_message();
     }
 }
Пример #20
0
 function process()
 {
     if ($this->get_value('chosen_action') == '0') {
         $items = array();
         foreach ($this->get_element_names() as $name) {
             if (preg_match("/^sortOrder_/i", $name)) {
                 $order = $this->get_value($name);
                 $name = preg_replace("/^sortOrder_/i", "", $name);
                 $items[$name] = $order;
             }
         }
         asort($items);
         $sort_order = 1;
         foreach ($items as $k => $v) {
             $items[$k] = $sort_order;
             $sort_order++;
         }
         $changed_something = false;
         if (!empty($items)) {
             foreach ($items as $id => $order) {
                 $result = reason_update_entity($id, $this->user_id, array($this->sorter->get_field() => $order), false);
                 if ($result) {
                     $changed_something = true;
                 }
             }
         }
         // if we have changed sort order of pages, lets try to drop the nav cache for the active site.
         if ($changed_something && $this->type_id == id_of('minisite_page')) {
             reason_include_once('classes/object_cache.php');
             $cache = new ReasonObjectCache($this->site_id . '_navigation_cache');
             $cache->clear();
         }
     }
 }
Пример #21
0
 function process()
 {
     // ignoring last_edited_by avoids the problem of updating entities by just viewing them.
     // i believe entities will only be updated when some of the actual CONTENT of the entity is changed.
     // phew.
     $this->_process_ignore[] = 'id';
     $this->_process_ignore[] = 'last_edited_by';
     $this->_process_ignore[] = 'last_modified';
     // collect values of entity
     $values = array();
     foreach ($this->get_element_names() as $element_name) {
         if (!in_array($element_name, $this->_process_ignore)) {
             $values[$element_name] = $this->get_value($element_name);
         }
     }
     /*foreach( $this->_elements AS $key => $element )
     		if( !in_array( $key, $this->_process_ignore ) )
     			$values[ $key ] = $element->get(); */
     foreach ($values as $key => $el) {
         if (!in_array($key, $this->_no_tidy)) {
             $values[$key] = tidy($el);
         }
     }
     // always reason_update_entity since we created when user clicks "Add"
     $this->has_changed = reason_update_entity($this->_id, $this->admin_page->user_id, $values, false);
     // the last argument determines whether or not to archive the entity.  if it's new, don't worry about it.  otherwise, archive
     // the $changed var grabs the result, true if changed, false if not
     // commented out nwhite 11-02-07
     // if a site is borrowing an item and the tiems sharing goes to private, the item is still borrowed by sites that had it ...
     // the owner will need to contact those sites and get them to manually remove the item from the list of those that are available.
     //
     //delete borrow relationships if no_share is true
     //if( $this->_elements[ 'no_share' ] )
     //if($this->_is_element('no_share'))
     //{
     //	if( $this->get_value( 'no_share' ) )
     //	{
     //		$d = new DBSelector;
     //		$d->add_table( 'ar' , 'allowable_relationship' );
     //		$d->add_table( 'r' , 'relationship' );
     //		$d->add_field( 'r' , 'id' , 'id' );
     //		$d->add_relation( 'r.type = ar.id' );
     //		$d->add_relation( 'ar.name = "borrows"' );
     //		$d->add_relation( 'ar.relationship_a = ' . id_of( 'site' ) );
     //		$d->add_relation( 'ar.relationship_b = ' . $this->admin_page->type_id );
     //		$d->add_relation( 'r.entity_b = ' . $this->admin_page->id );
     //		$x = $d->run();
     //		foreach( $x AS $rel )
     //			db_query( 'DELETE FROM relationship WHERE id = ' . $rel[ 'id' ] , 'Error deleting borrowed relationship' );
     //	}
     //}
     $this->_process_relationship_elements();
 }
if (empty($repeat_fields)) {
    echo '<p>This upgrade script has already been run -- you do not need to run it again.</p>';
    echo '<p><a href="index.php">Return to upgrade scripts</a></p>';
    die;
} elseif (empty($_POST['run'])) {
    echo '<p>This script will change the name of the event.repeat field to event.recurrence so that Reason can be run under MySQL 5.x</p>';
    echo '<form method="POST" target="?">';
    echo '<input type="submit" name="run" value="Run the Script" />';
    echo '</form>';
} else {
    echo '<p>Changing event.repeat to event.recurrence</p>';
    $repeat_field = current($repeat_fields);
    $q = 'ALTER TABLE `event` CHANGE `repeat` `recurrence` ' . $repeat_field->get_value('db_type');
    $success = db_query($q, 'Unable to change column.');
    if (!$success) {
        $msg = 'Unable to rename repeat field; aborting process';
        echo $msg;
        trigger_error($msg, EMERGENCY);
        die;
    }
    echo '<p>Successfully changed the database table; will now change the Reason entity that references the table (id #' . $repeat_field->id() . ')</p>';
    $success = reason_update_entity($repeat_field->id(), $cur_user_id, array('name' => 'recurrence'));
    if (!$success) {
        $msg = 'Unable to update repeat field entity';
        echo $msg;
        trigger_error($msg, EMERGENCY);
        die;
    }
    echo '<p>Successfully updated the repeat field entity.</p>';
    echo '<p><a href="index.php">Return to upgrade scripts</a></p>';
}
force_secure_if_available();
$user_netID = reason_require_authentication();
$reason_user_id = get_user_id($user_netID);
if (empty($reason_user_id)) {
    die('valid Reason user required');
}
if (!reason_user_has_privs($reason_user_id, 'upgrade')) {
    die('You must have upgrade privileges to run this script');
}
$stt = new entity(id_of('site_type_type'));
if ($stt->get_value('custom_content_handler')) {
    echo '<p>Site Types already have a content manager. There is no need to run this script!</p>';
} else {
    echo '<p>This script will add the site type content manager to this Reason instance. This content manager makes creating site types easier by adding useful comments.</p>';
    if (empty($_POST['run'])) {
        echo '<form action="?" method="post"><input type="submit" name="run" value="Run It" /></form>';
    } else {
        $success = reason_update_entity($stt->id(), $reason_user_id, array('custom_content_handler' => 'site_type.php'));
        if ($success) {
            echo '<p>Successfully updated site types to use new content manager</p>';
        } else {
            echo '<p>Unable to update site type to use new content manager. Please see the errors triggered (or the Reason error log) to identify why it did not work. Alternately, you can manually update this Reason instance. Here\'s how:</p>';
            echo '<ol><li>Log in to Reason</li><li>Go into the Master Admin</li><li>Choose "Types"</li><li>Find the type "Site Type" and click Edit</li><li>Choose "Site Type" on the Content Manager field</li><li>Save and finish</li></ol>';
        }
    }
}
echo '<p><a href="index.php">Back to 4.0b4 to 4.0b5 upgrades</a></p>';
?>
</body>
</html>
 protected function add_module($unique_name, $module, $name)
 {
     $es = new entity_selector();
     $es->add_type(id_of('type'));
     $es->add_relation('entity.unique_name = "' . addslashes($unique_name) . '"');
     $media_work_type = current($es->run_one());
     reason_update_entity($media_work_type->id(), $this->_user_id, array($module => $name));
 }
Пример #25
0
 function update_section_content_manager()
 {
     $type = new entity(id_of('news_section_type'));
     if ($type->get_value('custom_content_handler')) {
         echo '<p>Section type already has a content manager. No need to update.</p>' . "\n";
         return;
     }
     if ($this->mode == 'run') {
         if (reason_update_entity($type->id(), $this->reason_user_id, array('custom_content_handler' => 'news_section.php'))) {
             echo '<p>Section content manager successfully updated</p>' . "\n";
         } else {
             echo '<p>Section content manager not updated. Go to master admin -&gt; Types -&gt; News Section and set the Content Manger field to "News Section."</p>' . "\n";
         }
     } else {
         echo '<p>Would have updated the section type to use the content manager news_section.php</p>' . "\n";
     }
 }
Пример #26
0
 function process()
 {
     $replace_list = $this->helper->get_replace_list();
     $original_list = array_flip(array_unique($this->helper->get_original_list()));
     // all ids
     $search_term = $this->helper->get_search_term();
     $replace_term = $this->helper->get_replace_term();
     $user_id = $this->helper->get_user_id();
     // lets build the replacement arrays per entity
     if (!empty($replace_list)) {
         foreach ($replace_list as $id_and_field) {
             $parsed = explode("|", $id_and_field);
             if (isset($parsed[0]) && isset($parsed[1])) {
                 $entity = new entity($parsed[0]);
                 $replace[$parsed[0]][$parsed[1]] = str_replace($search_term, $replace_term, $entity->get_value($parsed[1]));
             }
         }
     }
     if (isset($replace) && !empty($replace)) {
         foreach ($replace as $eid => $values) {
             reason_update_entity($eid, $user_id, $values, false);
             // we are not archiving ... maybe we should - nah
             if (isset($original_list[$eid])) {
                 unset($original_list[$eid]);
             }
             $this->num_changes++;
         }
     }
     if (!empty($original_list)) {
         $this->helper->add_to_excluded($original_list);
     }
 }
Пример #27
0
 /**
  * After we save the title change we also need to destroy the navigation cache for the site.
  */
 function process_editable(&$disco)
 {
     $page = new entity($this->page_id);
     $values['name'] = trim(strip_tags($disco->get_value('page_title')));
     if ($page->get_value('name') != $values['name']) {
         $user_id = get_user_id(reason_check_authentication());
         reason_update_entity($this->page_id, $user_id, $values, true);
         // clear nav cache
         reason_include_once('classes/object_cache.php');
         $cache = new ReasonObjectCache($this->site_id . '_navigation_cache');
         $cache->clear();
     }
 }
Пример #28
0
		/**
		* Update the Reason entity that the user edited.
		*/
		function process_editable(&$disco)
		{
			$values = array();
			$values['release_title'] = trim(strip_tags($disco->get_value('title_of_story')));
			$values['content'] = trim(tidy($disco->get_value( 'editable_content' )));
			$values['description'] = trim(tidy($disco->get_value('description_of_story')));
			$archive = ($disco->get_chosen_action() == 'save_and_finish') ? true : false;
			reason_update_entity($this->current_item_id, get_user_id($this->get_user_netid()), $values, $archive );
		}
	/**
	 * @param array needed_fixes
	 * @return string description of fixes performed and result of data integrity check
	 */
	function table_update()
	{
		$fix_reason_content = false;	
		$xml_parser =& $this->getXMLParser();
		$fields_to_update =& $this->get_fields_that_need_update();
		if (isset($xml_parser->document->radiogroup))
        foreach ($xml_parser->document->radiogroup as $index => $radiogroup)
        {
        	$field_id = $radiogroup->tagAttrs['id'];
        	if (isset($fields_to_update[$field_id]))
        	{
        		if ($enum_result = $this->populate_enum($radiogroup->tagChildren))
        		{
        			$to_process[$field_id]['depth'] = $index;
        			$to_process[$field_id]['options'] = $enum_result['options'];
        			//if (isset($enum_result['selected'])) $to_process[$field_id]['selected'] = $enum_result['selected'];
        		}
        	}
        }
        if (isset($xml_parser->document->optiongroup))
        foreach ($xml_parser->document->optiongroup as $index => $optiongroup)
        {
        	$field_id = $optiongroup->tagAttrs['id'];
        	if (isset($fields_to_update[$field_id]))
        	{
        		if ($enum_result = $this->populate_enum($optiongroup->tagChildren))
   	     		{
        			$to_process[$field_id]['options'] = $enum_result['options'];
        			if (!isset($optiongroup->tagAttrs['required']))
        			{
        				// we are forcing these to required since it was not null previously, and not required,
        				// but the interface was basically forcing a simulation of the "required" setting
        				$to_process[$field_id]['required'] = 'required'; 
        			}
        			$to_process[$field_id]['label'] = $optiongroup->tagAttrs['label'];
        		}
        	}
        }
        
        //$this->set_report('bones i am updating table id ' . $this->table_id . ' which has name ' . $this->table_name);
		if (isset($to_process)) 
		{
			// build query
			foreach ($to_process as $field_name => $field_data)
			{
				$qry = '';
				$qry = 'ALTER TABLE `'.$this->get_table_name().'` CHANGE `'.$field_name.'` `'.$field_name.'`';
				$qry .= ' ENUM ("'. implode('","', $field_data['options']) . '")';
				$qry .= ' NULL ';
				
				// thor never sets a default value - we will keep this in the xml
				//if (isset($field_data['selected']))
				//{
				//	$qry .= ' DEFAULT "'.$field_data['options'][$field_data['selected']].'"';
				//}
				$update_thor[$field_name] = $qry;
				
				if (isset($field_data['required']))
				{
					$fix_reason_content = true;
					$search[] = 'label="' . $field_data['label'] . '" id="' . $field_name . '">';
					$replace[] = 'required="required" label="' . $field_data['label'] . '" id="' . $field_name . '">';
					$field_to_required[] = $field_name;
				}
			}
			
			if ($fix_reason_content)
			{
				if (!$this->test_mode) 
				{
					$table_entity = new entity($this->get_table_id());
					$table_xml = $table_entity->get_value('thor_content');
					$new_table_xml = str_replace($search, $replace, $table_xml);				
					reason_update_entity( $this->get_table_id(), $this->user_id, array('thor_content' => $new_table_xml), false);
				}
				$output['update_reason'] = 'option groups with ids ' . implode(", ", $field_to_required) . ' marked required';
			}
			
			if (!empty($update_thor))
			{
				if (!$this->test_mode)
				{
					connectDB(THOR_FORM_DB_CONN);
					
					$old_data = $this->get_table_data($this->get_table_name());
					foreach ($update_thor as $qry)
					{
						db_query($qry);
					}
					$new_data = $this->get_table_data($this->get_table_name());
					connectDB(REASON_DB);
					
					// data check makes sure data in table is the same before and after query. If not - dies with a fatal error.
					if (array_diff_assoc_recursive($new_data, $old_data))
					{
						echo '<h2>Original data</h2>';
						pray ($old_data);
						echo '<h2>New data</h2>';
						pray ($new_data);
						echo '<h2>Difference detected in new data</h2>';
						pray (array_diff_assoc_recursive($new_data, $old_data));
						trigger_error('integrity problem - result not the same ... script terminating ... table ' . $this->get_table_name() . ' may be corrupted', FATAL);
					}
				}
				$output['update_thor'] = $update_thor;
			}
			$this->set_report($output);
		}
		return true;
	}
 /**
  * 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);
         }
     }
 }