Esempio n. 1
0
/**
 * quick function to convert a date field into RFC 822, required by RSS 2.0
 */
function mysql_to_rfc_date($date)
{
    if ($date == "0000-00-00 00:00:00") {
        return null;
    }
    return carl_date('r', get_unix_timestamp($date));
}
Esempio n. 2
0
 function &fetch()
 {
     $ret = false;
     $cache_id = $this->get_cache_id();
     $lifespan = $this->get_cache_lifespan();
     $this->_cache_conn(true);
     $qry = 'SELECT * from ' . $this->get_db_table() . ' WHERE id="' . $cache_id . '"';
     $result = db_query($qry, 'Select query failed.', false);
     $this->_cache_conn(false);
     if ($result) {
         $row = mysql_fetch_assoc($result);
         $created = get_unix_timestamp($row['date_created']);
         $ret = $lifespan == -1 || time() - $created < $lifespan ? unserialize($row['content']) : false;
     }
     return $ret;
 }
 $txt .= '<h3>' . $type->get_value('name') . '</h3>' . "\n";
 $txt .= '<table cellpadding="5" cellspacing="0">' . "\n";
 $txt .= '<tr>';
 foreach ($use_fields as $field) {
     $txt .= '<th>' . $field . '</th>';
 }
 $txt .= '<th>Owned By</th>';
 $txt .= '<th>Search Hits</th>';
 $txt .= '<th>Edit</th>';
 $txt .= '</tr>';
 $class = 'odd';
 foreach ($entities as $e) {
     $txt .= '<tr class="' . $class . '">';
     foreach ($use_fields as $field) {
         if ($field == 'last_modified') {
             $txt .= '<td>' . date('j M Y', get_unix_timestamp($e->get_value($field))) . '</td>' . "\n";
         } elseif ($field == 'name') {
             $txt .= '<td>' . $e->get_display_name() . '</td>' . "\n";
         } else {
             $txt .= '<td>' . $e->get_value($field) . '</td>' . "\n";
         }
     }
     $txt .= '<td>';
     // This is the one thing that could make for poor performance if there are a lot of results
     // I'm not savvy enough yet to know how to include the owner info in the original query
     $owner_site_id = get_owner_site_id($e->id());
     if (!empty($owner_site_id)) {
         $owner_site = new entity(get_owner_site_id($e->id()));
         $txt .= '<a href="' . $owner_site->get_value('base_url') . '">';
         $txt .= $owner_site->get_value('name');
         $txt .= '</a>';
Esempio n. 4
0
 /**
  * Determine the end date
  *
  * Returns:
  * a) the already provided end date,
  * b) the end date based on the view provided, or
  * c) a reasonable end date based on $this->ideal_count
  *
  * Calls on get_max_date()
  * 
  * @param mixed $view name of current view or NULL if not provided
  * @return string $end_date mysql-formatted last date in calendar
  */
 public function get_end_date($view = NULL)
 {
     if (!empty($this->end_date)) {
         // end date either given or already determined
         return $this->end_date;
     }
     if (empty($view)) {
         $view = $this->view;
     }
     if (!empty($view)) {
         if ($view == 'daily') {
             return $this->start_date;
         } elseif ($view == 'all') {
             /* trigger_error('get_max_date called');
             			return $this->get_max_date(); */
             return '9999-12-31';
         } else {
             $start_array = explode('-', $this->start_date);
             if ($view == 'weekly') {
                 $end = get_unix_timestamp($start_array[0] . '-' . $start_array[1] . '-' . str_pad($start_array[2] + 6, 2, '0', STR_PAD_LEFT));
             } elseif ($view == 'monthly') {
                 $end = get_unix_timestamp($start_array[0] . '-' . str_pad($start_array[1] + 1, 2, '0', STR_PAD_LEFT) . '-' . str_pad($start_array[2] - 1, 2, '0', STR_PAD_LEFT));
             } elseif ($view == 'yearly') {
                 $end = get_unix_timestamp($start_array[0] + 1 . '-' . $start_array[1] . '-' . str_pad($start_array[2] - 1, 2, '0', STR_PAD_LEFT));
             } else {
                 trigger_error('$view (' . $view . ') not a recognized value');
             }
         }
         return carl_date('Y-m-d', $end);
     } else {
         /* trigger_error('get_max_date called');
         			return $this->get_max_date(); */
         return '9999-12-31';
     }
 }
 /**
  * Specify an end date that limits what you care about for the publication
  *
  * @param string mysql_datetime format
  * @param normalize time to end of the day (11:59 PM) - default true
  */
 function set_end_date($end_date, $normalize = true)
 {
     if (is_mysql_datetime($end_date) || preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $end_date)) {
         if ($normalize) {
             $end_date = carl_date('Y-m-d 11:59:59', get_unix_timestamp($end_date));
         }
         $this->end_date = $end_date;
         $this->date_changed = true;
     } else {
         trigger_error('publication helper method set_end_date given a value that is not in mysql_datetime format - did not set the end date');
     }
 }
Esempio n. 6
0
	/**
	 * Generate the calendar grid markup and assign to $this->calendar_grid_markup
	 *
	 * @return void
	 * @todo Move to a markup class
	 */
	function generate_calendar_grid_markup()
	{
		$grid = new calendar_grid();
		$start_day_on_cal = false;
		if(!empty($this->request['nav_date']))
		{
			$nav_date = $this->request['nav_date'];
			if(substr($nav_date,0,7) == substr($this->calendar->get_start_date(),0,7) )
				$start_day_on_cal = true;
		}
		else
		{
			$nav_date = $this->calendar->get_start_date();
			$start_day_on_cal = true;
		}
		$date_parts = explode('-',$nav_date);
		$grid->set_year($date_parts[0]);
		$grid->set_month($date_parts[1]);
		if($start_day_on_cal)
		{
			$grid->set_day($date_parts[2]);
		}
		$grid->set_linked_dates($this->get_calendar_grid_links($date_parts[0], $date_parts[1]) );
		
		if($this->calendar->contains_any_events_before($date_parts[0].'-'.$date_parts[1].'-01'))
		{
			$prev_u = get_unix_timestamp($date_parts[0].'-'.str_pad($date_parts[1]-1, 2, "0", STR_PAD_LEFT).'-'.$date_parts[2]);
			$prev_date = carl_date('Y-m-d',$prev_u);
			$grid->set_previous_month_query_string($this->construct_link(array('nav_date'=>$prev_date,'no_search'=>'1' ) ) );
		}
		if($this->calendar->contains_any_events_after($date_parts[0].'-'.$date_parts[1].'-31'))
		{
			$next_u = get_unix_timestamp($date_parts[0].'-'.str_pad($date_parts[1]+1, 2, "0", STR_PAD_LEFT).'-'.$date_parts[2]);
			$next_date = carl_date('Y-m-d',$next_u);
			$grid->set_next_month_query_string($this->construct_link(array('nav_date'=>$next_date,'no_search'=>'1' ) ) );
		}
		
		$nav_month = substr($nav_date,0,7);
		
		$start_month = substr($this->calendar->get_start_date(),0,7);
		$start_day = intval(substr($this->calendar->get_start_date(),8,2));
		
		$end_month = substr($this->calendar->get_end_date(),0,7);
		$end_day = intval(substr($this->calendar->get_end_date(),8,2));
		
		if(!($start_month > $nav_month || $end_month < $nav_month))
		{
			if($start_month == $nav_month)
			{
				$first_day_in_view = $start_day;
				$grid->add_class_to_dates('startDate', array($start_day));
			}
			else
			{
				$first_day_in_view = 1;
			}
			if($end_month == $nav_month)
			{
				$last_day_in_view = $end_day;
			}
			else
			{
				$last_day_in_view = 31;
			}
			
			$viewing_days = array();
			for($i = $first_day_in_view; $i <= $last_day_in_view; $i++)
			{
				$viewing_days[] = $i;
			}
			$grid->add_class_to_dates('currentlyViewing', $viewing_days);
			
		}
		$days_with_events = $this->get_days_with_events($date_parts[0], $date_parts[1]);
		if(!empty($days_with_events))
		{
			$grid->add_class_to_dates('hasEvent', array_keys($days_with_events));
		}
		$this->calendar_grid_markup = $grid->get_calendar_markup();
	}
 function get_days_monthly()
 {
     $ucur = $this->ustart;
     while ($ucur <= $this->uend) {
         $this->dates[] = carl_date('Y', $ucur) . '-' . carl_date('m', $ucur) . '-' . carl_date('d', $ucur);
         $ucur = strtotime('+' . $this->frequency . ' months', $ucur);
         if ($this->monthly_repeat == 'semantic') {
             $cur_day = 1 + 7 * ($this->week_of_month - 1);
             $ucur_var = date('Y', $ucur) . '-' . date('m', $ucur) . '-' . str_pad($cur_day, 2, '0', STR_PAD_LEFT);
             $ucur = get_unix_timestamp($ucur_var);
             if ($ucur) {
                 while (date('l', $ucur) != $this->month_day_of_week) {
                     $ucur = strtotime('+1 day', $ucur);
                 }
             } else {
                 trigger_error('Not able to find appropriate repeat date for ' . $ucur_var);
                 break;
             }
         }
     }
 }
Esempio n. 8
0
function parse_mysql_date($date)
{
    // returns an array of year, month, day, timestamp
    $output = array();
    list($idate) = explode(' ', $date);
    list($output['year'], $output['month'], $output['day']) = explode('-', $idate);
    $output['timestamp'] = get_unix_timestamp($output['year'] . '-' . $output['month'] . '-' . $output['day']);
    return $output;
}
Esempio n. 9
0
 function set($value)
 {
     $value = get_unix_timestamp($value . '-01');
     if (!empty($value) && $value != -1) {
         list($this->year, $this->month) = explode('-', carl_date($this->date_format, $value));
     } else {
         $this->year = '';
         $this->month = '';
     }
 }
Esempio n. 10
0
 /**
  * Used by the pagination displayer.
  * Returns an array of distinct dates represented
  * in the whole set of data.
  */
 function get_distinct_date_array()
 {
     $dates_es = carl_clone($this->pre_user_input_es);
     $dates_es->set_order('dated.datetime ASC');
     $dates_es->limit_tables(array('dated'));
     $dates_es->limit_fields(array('entity.id', 'dated.datetime'));
     $dates_es->set_start(0);
     $dates_es->set_num(false);
     $items = $dates_es->run_one();
     foreach ($items as $item) {
         $ts = get_unix_timestamp($item->get_value('datetime'));
         $dt = date('Y-m-d', $ts);
         $ts = get_unix_timestamp($dt);
         if ($ts > 0) {
             $return_array[$dt . '*'] = date('D, M j, Y', $ts);
         }
     }
     if (!empty($return_array)) {
         return $return_array;
     } else {
         return false;
     }
 }
 /**
  * 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);
 }