Пример #1
0
 function set(&$object)
 {
     $cache_id = $this->get_cache_id();
     $content = mysql_real_escape_string(serialize($object));
     $qry = 'INSERT INTO ' . $this->get_db_table() . ' (id, content) VALUES ("' . $cache_id . '", "' . $content . '") ON DUPLICATE KEY UPDATE content="' . $content . '", date_created="' . get_mysql_datetime() . '";';
     $this->_cache_conn(true);
     $result = db_query($qry, 'Insert failed.', false);
     $this->_cache_conn(false);
     return $result;
 }
Пример #2
0
	/**
	 * Updates entity with id = $id with the values of the array $values
	 *
	 * reason_update_entity() provides an easier-to-use interface 
	 * where the updates do not need to be organized by table.
	 *
	 * @todo figure out how to refresh the entity data cache on update
	 *
	 * @param integer $id ID of entity to update
	 * @param integer $user_id Reason ID of user making changes
	 * @param array $updates array of tables with values being array of key-val pairs
	 * @param boolean $archive boolean that determines whether this update will be archived
	 * @return boolean true => entity has changed,  false => entity has not changed
	 */
	function update_entity( $id, $user_id, $raw_updates = array(), $archive = true )
	{
		$original = new entity($id, false);
		if (reason_is_entity($original, true)) // must be an entity of some type.
		{
			if (isset($raw_updates['entity']['type']) && ($raw_updates['entity']['type'] != $original->get_value('type')))
			{
				trigger_error('update_entity cannot be used to change the type of an entity.');
			}
			foreach( $raw_updates AS $table => $raw_fields )
			{
				$updates[$table] = reason_sanitize_values($original->get_value('type'), $raw_fields);
				if (empty($changed))
				{
					foreach ($updates[$table] as $k => $v) // see if this represents a change.
					{
						if ($v != $original->get_value($k))
						{
							$changed = true;
							break;
						}
					}
				}
			}
			if (!empty($changed)) // some change took place
			{
				if (!isset($updates['entity']['last_edited_by'])) $updates['entity']['last_edited_by'] = $user_id;
				if (!isset($updates['entity']['last_modified'])) $updates['entity']['last_modified'] = get_mysql_datetime();
				foreach  ($updates as $table => $fields)
				{
					$GLOBALS['sqler']->update_one( $table, $fields, $id );
				}
				if (!empty($archive))
				{
					$archived_id = duplicate_entity( $original, false, true, array( 'state' => 'Archived' ) );
					$rel_id = reason_get_archive_relationship_id($original->get_value('type'));
					create_relationship( $id, $archived_id, $rel_id );
				}
				$updated_entity = new entity($id, false);
				$updated_entity->get_values();
				// If the unique_name changes on the updated entity, or a uniquely named entity is deleted or undeleted, lets update the unique name cache
				if ($updated_entity->get_value('unique_name') != $original->get_value('unique_name') ||
					($original->get_value('state') != 'Deleted' && $updated_entity->get_value('state') == 'Deleted' && $original->get_value('unique_name')) ||
					($original->get_value('state') == 'Deleted' && $updated_entity->get_value('state') != 'Deleted' && $updated_entity->get_value('unique_name')))
				{
					reason_refresh_unique_names();
				}
				return true;
			}
		}
		else
		{
			trigger_error('update_entity requires a valid entity id (was given ' . $id . ').');
		}
		return false;
	}
Пример #3
0
	function set_minimum_date()
	{
		if (isset($this->params['minimum_date_strtotime_format']))
		{
			// minimum_date_strtotime_format should be a string usable to strtotime and also in the past not the future - trigger an error if not.
			$cur_timestamp = time();
			$min_date = strtotime($this->params['minimum_date_strtotime_format']);
			if ($min_date && ($min_date != -1) && ($min_date < $cur_timestamp))
			{
				$this->minimum_date = get_mysql_datetime($min_date);
			}
			elseif (!$min_date || ($min_date == -1))
			{
				trigger_error('A minimum date value was not set as the value of minimum_date_strtime_format 
							  ('.$this->params['minimum_date_strtotime_format'].') is not a valid argument for strtotime.');
			}
			elseif ($min_date > $cur_timestamp)
			{
				trigger_error('A minimum date value was not set. The value of minimum_date_strtime_format 
							  ('.$this->params['minimum_date_strtotime_format'].') must reference a date in the past.');
			}
		}
	}
Пример #4
0
	function process_new() 
	{
		$tc = $this->get_thor_core();
		$values = $tc->get_thor_values_from_form($this);
		$values['submitted_by'] = reason_check_authentication();
		$values['submitter_ip'] = $_SERVER['REMOTE_ADDR'];
		$values['date_created'] = get_mysql_datetime();
		$tc->insert_values($values);
	}
Пример #5
0
	/**
	 * Saves the data in the appropriate way. Assumes should_save_form_data has been checked.
	 *
	 * Considerations include:
	 *
	 * - Is this form one that allows multiple submissions?
	 * - If so, is this an edit or a new submission?
	 * - Is this an edit of an existing submission
	 */
	function save_data(&$data, $options = array())
	{
		$form_id = $this->get_form_id();
		
		if ( $form_id ) // update
		{
			$result = $this->perform_update($form_id, $data);
		}
		else // insert
		{
			$columns = $this->get_database_columns();
			
			if (isset($columns['date_created']) && !isset($data['date_created'])) $data['date_created'] = get_mysql_datetime();
			$result = $this->perform_insert(array_merge($data, $this->get_values_for_save_extra_fields()));
			if ($result) $this->set_form_id($result);
		}
	}
Пример #6
0
 function alter_feed()
 {
     $this->grab_blog();
     $this->feed->set_item_field_map('title', 'release_title');
     $this->feed->set_item_field_map('author', 'author');
     // Set description to the blog post id so it can be passed to a handler
     $this->feed->set_item_field_map('description', 'id');
     $this->feed->set_item_field_map('pubDate', 'datetime');
     // Check for include content toggle
     if ($this->blog->get_value('blog_feed_include_content') == 'yes') {
         $this->feed->set_item_field_handler('description', 'get_blog_content_from_id', false);
     } else {
         $this->feed->set_item_field_handler('description', 'get_blog_description_from_id', false);
     }
     // Don't run this handler because it overwrites the content/description grab handlers
     //$this->feed->set_item_field_handler( 'description', 'expand_all_links_in_html', false );
     $this->feed->set_item_field_handler('title', 'strip_tags', false);
     $this->feed->es->add_relation('show_hide = "show"');
     $this->feed->es->set_order('datetime DESC');
     $this->feed->es->add_relation('status != "pending"');
     // In order to be able to take advantage of query caching so we round up using 5 minute intervals when looking at the datetime.
     $this->feed->es->add_relation('datetime <= "' . get_mysql_datetime(ceil(time() / 300) * 300) . '"');
     // lets add some sensible limits to avoid joining across all the tables (particularly chunk)
     $this->feed->es->limit_tables(array('entity', 'dated', 'status', 'show_hide'));
     $this->feed->es->limit_fields();
     if (!empty($this->request['shared_only'])) {
         $this->feed->es->add_relation('no_share = "0"');
     }
     if ($this->blog->get_value('has_issues') == 'yes') {
         if ($issue_id = $this->_get_latest_published_issue_id($this->blog->id())) {
             $this->feed->es->add_left_relationship($issue_id, relationship_id_of('news_to_issue'));
             $this->feed->es->set_num(999);
             // show all posts in issue up to a reasonable number
         } else {
             $this->feed->es->add_relation('1 = 2');
             // don't show any posts if there are no shown issues
         }
     } else {
         if ($this->blog->get_value('posts_per_page')) {
             $this->feed->es->set_num($this->blog->get_value('posts_per_page'));
         }
     }
     $this->feed->es->add_left_relationship($this->blog->id(), relationship_id_of('news_to_publication'));
 }
Пример #7
0
	/**
	 * Get the potential dates a user can register for for a given event
	 *
	 * @param object $event event entity
	 * @return array mysql-formatted dates
	 */
	function get_possible_registration_dates($event)
	{
		$possible_dates_str = $event->get_value('dates');
		$possible_dates = explode(", ", $possible_dates_str);
		$cur_date = get_mysql_datetime();
		$time_frag = substr($event->get_value('datetime'), 10);
		foreach ($possible_dates as $k=>$v)
		{
			$working_date = $v . $time_frag;
			if ($cur_date > $working_date)
			{
				unset($possible_dates[$k]);
			}
		}
		return $possible_dates;
	}
Пример #8
0
	function get_values_for_email_extra_fields()
	{
		$submitted_by = $this->get_user_netid();
		$submitter_ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : '';
		return array('submitted_by' => $submitted_by, 'submitter_ip' => $submitter_ip, 'submission_time' => get_mysql_datetime());
	}
Пример #9
0
 function alter_data()
 {
     if ($this->entity->get_value('state') == 'Pending') {
         $this->set_value('datetime', get_mysql_datetime());
     }
 }
Пример #10
0
 /**
  * Insert a row - we automatically add the date created timestamp
  *
  * @param $disco_obj reference to the disco object. Added Nov 2014
  * @return id of row inserted
  */
 function insert_values($values, $disco_obj)
 {
     if ($this->get_thor_table() && $values) {
         $this->create_table_if_needed();
         // create the table if it does not exist
         if (!isset($values['date_created'])) {
             $values['date_created'] = get_mysql_datetime();
         }
         if (!get_current_db_connection_name()) {
             connectDB($this->get_db_conn());
         }
         $reconnect_db = get_current_db_connection_name() != $this->get_db_conn() ? get_current_db_connection_name() : false;
         if ($reconnect_db) {
             connectDB($this->get_db_conn());
         }
         $GLOBALS['sqler']->mode = 'get_query';
         $query = $GLOBALS['sqler']->insert($this->get_thor_table(), $values);
         $result = db_query($query);
         $insert_id = mysql_insert_id();
         $this->handle_file_uploads($insert_id, $disco_obj, true);
         $GLOBALS['sqler']->mode = '';
         if ($reconnect_db) {
             connectDB($reconnect_db);
         }
         // reconnect to default DB
         return $insert_id;
     } elseif (!$this->get_thor_table()) {
         trigger_error('insert_values called but no table has been defined via the thorCore set_thor_table method');
         return NULL;
     } elseif (empty($values)) {
         trigger_error('insert_values called but the values array was empty');
         return NULL;
     }
 }
Пример #11
0
 /**
  * Preps values for the database and and creates new entity
  * @todo the cleaning methods should be available to the view as well outside of save so that the view can filter
  *       the values in the same way for preview purposes (trim/strip tags in most cases)
  */
 function save_classified($values)
 {
     if ($user_netid = reason_check_authentication()) {
         $user = get_user_id($user_netid);
     }
     if (!isset($user) || !$user) {
         $user = get_user_id('classified_user');
     }
     $name = trim(strip_tags($values['name']));
     $category = turn_into_int($values['category']);
     $duration_days = $this->get_classified_duration_days();
     $requires_approval = $this->get_classified_requires_approval();
     if (!empty($values['classified_date_available'])) {
         $ts = get_unix_timestamp($values['classified_date_available']);
         if ($ts) {
             $clean_values['classified_date_available'] = get_mysql_datetime($ts);
         }
     }
     if (!empty($duration_days)) {
         $clean_values['classified_duration_days'] = $duration_days;
     }
     if (!empty($values['location'])) {
         $clean_values['location'] = trim(strip_tags($values['location']));
     }
     if (!empty($values['content'])) {
         $clean_values['content'] = trim(strip_tags($values['content']));
     }
     if (!empty($values['author'])) {
         $clean_values['author'] = trim(strip_tags($values['author']));
     }
     if (!empty($values['classified_contact_email'])) {
         $clean_values['classified_contact_email'] = trim(strip_tags($values['classified_contact_email']));
     }
     if (!empty($values['price'])) {
         $clean_values['price'] = turn_into_int($values['price']);
     }
     if (!empty($clean_values['content'])) {
         $clean_values['description'] = $this->string_summary($values['content']);
     }
     $clean_values['display_contact_info'] = turn_into_int($values['display_contact_info']);
     // always either 0 or 1
     $clean_values['datetime'] = get_mysql_datetime();
     $clean_values['state'] = $requires_approval ? 'Pending' : 'Live';
     $clean_values['new'] = 0;
     $entity_id = reason_create_entity($this->get_site_id(), id_of('classified_type'), $user, $name, $clean_values);
     create_relationship($entity_id, $category, relationship_id_of('classified_to_classified_category'));
     $this->set_classified_id($entity_id);
 }