function get() { $tweets = $this->data(); if (!empty($tweets)) { $title = !is_null($this->config('title')) ? $this->config('title') : $this->get_title(); $description = !is_null($this->config('description')) ? $this->config('description') : $this->get_description(); $str = !empty($title) ? $title : ''; $str .= !empty($description) ? $description : ''; if ($this->config('randomize')) { shuffle($tweets); } $str .= '<ul>'; foreach ($tweets as $tweet) { $num = !isset($num) ? 1 : $num + 1; $str .= '<li>' . $tweet['html'] . ' <span class="date">' . carl_date('j M', strtotime($tweet['created_at'])) . '</li>'; if ($num == $this->config('num_to_show')) { break; } } $str .= '</ul>'; } else { $str = ''; } return $str; }
/** * 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)); }
/** * 'past','current','future' */ public function temporal_status() { if ($this->_event->get_value('datetime') <= carl_date('Y-m-d h:i:s')) { if ($this->_event->get_value('last_occurence') < carl_date('Y-m-d')) { return 'past'; } return 'current'; } return 'future'; }
/** * Run the module */ function run() { $sites = $this->_get_sites(); if (empty($sites)) { echo '<p>You must have editing access to at least one live Reason site for this module to work</p>' . "\n"; return; } $users = $this->_get_users(); if (empty($users)) { echo '<p>No users available.</p>' . "\n"; return; } echo '<div id="reviewChangesModule">' . "\n"; $d = new disco(); $d->add_element('start_date', 'textdate', array('prepopulate' => true, 'year_max' => carl_date('Y'), 'year_min' => '1000')); $d->add_required('start_date'); $d->add_element('end_date', 'textdate', array('year_max' => carl_date('Y'), 'year_min' => '1000')); $d->add_comments('end_date', form_comment('If no end date given, changes will be shown for just the start date')); $d->add_element('type', 'select', array('options' => $this->_prep_for_disco($this->_get_types()))); if (!empty($this->admin_page->request['type_id'])) { $d->set_value('type', $this->admin_page->request['type_id']); } $d->add_element('site', 'select', array('options' => $this->_prep_for_disco($sites))); if (!empty($this->admin_page->request['site_id'])) { $d->set_value('site', $this->admin_page->request['site_id']); } $d->add_element('user', 'select', array('options' => $this->_prep_for_disco($users))); if (!empty($this->admin_page->request['user'])) { $d->set_value('user', $this->admin_page->request['user']); } $d->add_element('sort', 'select', array('options' => array('DESC' => 'Descending', 'ASC' => 'Ascending'))); $d->set_actions(array('review' => 'Review')); $d->run(); if ($d->successfully_submitted()) { $end_date = $d->get_value('end_date') ? $d->get_value('end_date') : $d->get_value('start_date'); if ($end_date < $d->get_value('start_date')) { echo 'Please pick a end date on or after the start date.'; } else { echo $this->_get_changes_markup($d->get_value('start_date'), $end_date, $d->get_value('type'), $d->get_value('site'), $d->get_value('user'), $d->get_value('sort')); } } echo '</div>' . "\n"; }
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 ); }
public function contains_any_events_before($date) { if (!$this->contains_any_events()) { return false; } if (!empty($this->known_lower_limit) && $this->known_lower_limit < $date) { //echo '<strong>contains_any_events_before</strong>: req.date ('.$date.') after kll ('.$this->known_lower_limit.'); ret true<br />'; return true; } elseif (!empty($this->known_closest_date_before) && $this->known_closest_date_before > $date) { //echo '<strong>contains_any_events_before</strong>: req.date ('.$date.') before kcdb ('.$this->known_closest_date_before.'); ret false<br />'; return false; } $test_es = carl_clone($this->base_es); $test_es->set_num(1); $test_es->add_relation(table_of('datetime', id_of('event_type')) . ' < "' . reason_sql_string_escape($date) . '"'); $test_es->limit_fields(); $test_es->exclude_tables_dynamically(); $test_es->set_cache_lifespan($this->_get_cache_lifespan_meta()); $test_results = $test_es->run_one(); if (!empty($test_results)) { $result = current($test_results); //echo '<strong>contains_any_events_before</strong>: found event before req.date '.$date.'. id: '.$result->id().'; datetime: '.$result->get_value('datetime').'; ret true<br />'; $date = prettify_mysql_datetime($result->get_value('datetime'), 'Y-m-d'); $this->known_lower_limit = carl_date('Y-m-d', strtotime($date . ' -1 day')); return true; } else { //echo '<strong>contains_any_events_before</strong>: no events found before req.date ('.$date.'); ret false<br />'; $this->known_closest_date_before = $date; return false; } }
protected function _populate_author($disco) { $person_info = $this->_get_user_info(); if (!empty($person_info)) { if (isset($person_info['ds_fullname'][0])) { $disco->set_value('name', $person_info['ds_fullname'][0]); } if (!empty($person_info['carlcohortyear'][0]) && $person_info['carlcohortyear'][0] >= carl_date('Y') && $person_info['carlcohortyear'][0] < carl_date('Y') + 4) { $disco->set_value('class_year', $person_info['carlcohortyear'][0]); } if (!empty($person_info['mail'][0])) { $disco->set_value('email', $person_info['mail'][0]); } } }
/** * 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'); } }
/** * Get earliest year that has events in the calendar * @return integer year */ function get_min_year() { if(!empty($this->min_year)) { return $this->min_year; } $year = carl_date('Y'); //echo 'start: '.$year.'<br />'; $min_year = NULL; $min_found_so_far = $year; for( $i=2; $i < 65; $i = $i*2 ) { //echo 'testing: '. ( $year - $i ) .'<br />'; if($this->calendar->contains_any_events_before(($year-$i).'-01-01')) { $min_found_so_far = $year - $i; continue; } else { $min_year = $this->refine_get_min_year($year-$i, $min_found_so_far); break; } } if(empty($min_year)) $min_year = $year - $i; $this->min_year = $min_year; return $min_year; }
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 = ''; } }
/** * Log the amount of time it took to generate the current page/process * * @param integer $milliseconds The number of milliseconds that it took to generate the page * @return boolean success */ function reason_log_page_generation_time($milliseconds) { if (defined('REASON_PERFORMANCE_PROFILE_LOG') && REASON_PERFORMANCE_PROFILE_LOG) { $pieces = array(carl_date('r'), get_current_url(), $milliseconds); array_walk($pieces, 'quote_walk'); $msg = implode(',', $pieces); return dlog($msg, REASON_PERFORMANCE_PROFILE_LOG); } return false; }
function get_days_yearly() { for ($ucur = $this->ustart; $ucur < $this->uend; $ucur = strtotime('+' . $this->frequency . ' years', $ucur)) { $this->dates[] = carl_date('Y', $ucur) . '-' . carl_date('m', $ucur) . '-' . carl_date('d', $ucur); } }
function _create_icalendar_event($event) { $icalendar_event = ""; $icalendar_event .= 'BEGIN:VEVENT' . "\r\n"; $icalendar_event .= 'UID:' . $this->_fold_text(str_replace(array('-', ' ', ':'), '', $event->get_value('creation_date')) . '-' . $event->id() . '@' . REASON_ICALENDAR_UID_DOMAIN) . "\r\n"; //SUMMARY if (strlen($event->get_value('name')) != 0) { $icalendar_event .= 'SUMMARY:' . $this->_fold_text($event->get_value('name')) . "\r\n"; } //DESCRIPTION // if "brief description of event" (field: description) was specified, use that. Otherwise, use the "full event information" (field: content) if (strlen($event->get_value('description')) != 0) { $icalendar_event .= 'DESCRIPTION:' . $this->_fold_text($event->get_value('description')) . "\r\n"; } else { if (strlen($event->get_value('content')) != 0) { $icalendar_event .= 'DESCRIPTION:' . $this->_fold_text($event->get_value('content')) . "\r\n"; } } //LOCATION if (strlen($event->get_value('location')) != 0) { $icalendar_event .= 'LOCATION:' . $this->_fold_text($event->get_value('location')) . "\r\n"; } //URL if (strlen($event->get_value('url')) != 0) { $icalendar_event .= 'URL:' . $this->_fold_text($event->get_value('url')) . "\r\n"; } //LAST-MODIFIED if (strlen($event->get_value('last_modified')) != 0) { $icalendar_event .= 'LAST-MODIFIED:' . $this->_create_datetime(carl_date("Y-m-d H:i:s", strtotime($event->get_value('last_modified'))), false) . "\r\n"; } //CREATED if (strlen($event->get_value('creation_date')) != 0) { $icalendar_event .= 'CREATED:' . $this->_create_datetime(carl_date("Y-m-d H:i:s", strtotime($event->get_value('creation_date'))), false) . "\r\n"; } //DTSTART if (strlen($event->get_value('datetime')) != 0) { $timestamp = $this->_create_datetime(carl_date("Y-m-d H:i:s", strtotime($event->get_value('datetime'))), false); if (strstr($event->get_value('datetime'), '00:00:00')) { preg_match("/[\\d]*/", $timestamp, $matches); $icalendar_event .= 'DTSTART;VALUE=DATE:' . $matches[0] . "\r\n"; //DREND (for all day events) $icalendar_event .= 'DTEND;VALUE=DATE:' . $matches[0] . "\r\n"; } else { $icalendar_event .= 'DTSTART:' . $timestamp . "\r\n"; //DURATION if (strlen($event->get_value('hours')) != 0 || strlen($event->get_value('minutes')) != 0) { if ($event->get_value('hours') != 0 || $event->get_value('minutes') != 0) { $icalendar_event .= $this->_create_duration($event->get_value('hours'), $event->get_value('minutes')); } else { $icalendar_event .= $this->_create_duration('0', '0'); } } } } //Recurrence Rule if ($event->get_value('recurrence') != 'none') { $icalendar_event .= $this->_create_rrule($event->get_value('recurrence'), $event->get_value('frequency'), $event->get_value('week_of_month'), $event->get_value('month_day_of_week'), $event->get_value('monthly_repeat'), $event->get_value('sunday'), $event->get_value('monday'), $event->get_value('tuesday'), $event->get_value('wednesday'), $event->get_value('thursday'), $event->get_value('friday'), $event->get_value('saturday'), $event->get_value('end_date'), $event->get_value('datetime'), false); } $icalendar_event .= 'END:VEVENT' . "\r\n"; return $icalendar_event; }
function get_options_for_email_submitter_view() { if ($this->should_email_link()) { $email_link = $this->get_link_for_email_submitter_view(); if (!empty($email_link)) { $options['access_link'] = $email_link; } else { $options['origin_link'] = carl_construct_link(array('')); // we use the origin if no link to edit is available } } $options['email_empty_fields'] = $this->should_email_empty_fields(); $options['subject'] = 'Form Submission Confirmation: ' . $this->get_form_name(); // should i include form name $options['header'] = $this->get_form_name() . " - " . "Successfully Submitted " . carl_date('l, F jS Y \\a\t h:i:s A'); $options['to'] = $this->get_email_of_submitter(); $options['disclaimer'] = false; $view =& $this->get_view(); if (method_exists($view, 'get_custom_options_for_email_submitter_view')) { $view_options = $view->get_custom_options_for_email_submitter_view(); if (is_array($view_options)) { $options = array_merge($options, $view_options); } else trigger_error('The method get_custom_options_for_email_submitter_view, if defined in the view, needs to return an array.'); } return $options; }
/** * Make a good looking date from a mysql datetime * @param string $dt format of mysql datetime * @param string $format the format string according to {@link http://us2.php.net/manual/en/function.date.php php's date function} * @return string The formatted date or the empty string on conversion failure */ function prettify_mysql_datetime($dt, $format = 'M jS, Y') { return false !== ($time = mysql_datetime_to_unix($dt)) ? carl_date($format, $time) : ''; }
/** * Returns a timestamp in mysql datetime format - returns current mysql datetime if no parameter is given * @param int timestamp optional * @return string mysql datetime */ function get_mysql_datetime($timestamp = false) { return carl_date("Y-m-d H:i:s", $timestamp); }
function find_errors($values = array()) { if (empty($values) && !empty($this->disco_form)) { $values = $this->disco_form->get_values(); } if (empty($values)) { $values = $this->get_event_values(); } if (empty($values)) { trigger_error('Programmer error: no event values available for reasonEvent::find_errors()'); } static $required_fields = array('name', 'datetime', 'recurrence', 'show_hide'); $errors = array(); foreach ($required_fields as $field) { if (empty($values[$field])) { $errors[$field][] = 'The ' . $field . ' field is required.'; } } if (empty($errors)) { if ($values['recurrence'] != 'none') { if (empty($values['frequency'])) { static $repeat_vals = array('daily' => 'day', 'weekly' => 'week', 'monthly' => 'month', 'yearly' => 'year'); $errors['frequency'][] = 'How often should this event repeat? If it repeats every ' . $repeat_vals[$values['recurrence']] . ', enter a 1.'; } if (empty($values['term_only'])) { $errors['term_only'][] = 'Please indicate whether this event should occur only while classes are in session.'; } } $d = parse_mysql_date($values['datetime']); if ($values['recurrence'] == 'weekly') { // there must be at least 1 day of the week the event recurs on static $days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); foreach ($days as $day) { if (!empty($values[$day])) { $day_set = true; break; } } if (empty($day_set)) { $errors['sunday'][] = 'Please enter which day(s) of the week this event will occur.'; } // the date of the event must be on one of those days of the week $day_o_week = carl_date('l', $d['timestamp']); if (empty($values[strtolower($day_o_week)])) { $errors['sunday'][] = 'This event starts on a ' . $day_o_week . ', which is not one of the repeating days of week provided.'; } } elseif ($values['recurrence'] == 'monthly') { // don't allow repetition on days that don't occur in every month if ($d['day'] > 28) { $errors['datetime'][] = 'Dates after the 28th do not occur in all months, so they are not available for monthly repeats.'; } } elseif ($values['recurrence'] == 'yearly') { if ($d['month'] == 2 and $d['day'] == 29) { $errors['datetime'][] = 'February 29th only occurs on leap-years, so it is not an acceptable date for yearly repeating events.'; } } } if (!empty($this->disco_form)) { foreach ($errors as $field => $errs) { foreach ($errs as $err_txt) { $this->disco_form->set_error($field, $err_txt); } } } return $errors; }
/** @access private */ function _carl_util_log_error($level, $message, $file, $line, $context) { $referrer = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $error = array('type' => strtoupper(error_level_name($level)), 'time' => carl_date('r'), 'msg' => $message, 'line' => $line, 'file' => $file, 'uri' => $uri, 'ip' => $ip, 'ua' => $ua, 'errno' => $level, 'referrer' => $referrer); $error = implode(',', array_map('_carl_util_escape_error_part', $error)); dlog($error, PHP_ERROR_LOG_FILE); }
function _get_maintainer_info($maintainer) { // Check to see if it's before or after 7 am, and set the last colleague->ldap sync time appropriately. if (carl_date('G') < 7) { $ldap_last_sync_time = strtotime('7 am yesterday'); } else { $ldap_last_sync_time = strtotime('7 am today'); } /* Either of the following conditions will fire the ldap->reason sync: 1: the cached info predates the last colleague->ldap sync (presumed to be daily by 7 am.) 2: the primary maintainer has been changed since the last ldap->reason sync. */ if ($this->parent->site_info->get_value('cache_last_updated') <= date('Y-m-d', $ldap_last_sync_time) || $this->parent->site_info->get_value('username_cache') != $this->parent->site_info->get_value('primary_maintainer')) { $dir = new directory_service(); if ($dir->search_by_attribute('ds_username', $maintainer, array('ds_email', 'ds_fullname'))) { $email = $dir->get_first_value('ds_email'); $full_name = $dir->get_first_value('ds_fullname'); // lets fall back to the maintainer username if a valid full name is not found for the user $full_name = !carl_empty_html($full_name) ? $full_name : trim(strip_tags($maintainer)); $values = array('email_cache' => $email, 'name_cache' => $full_name, 'cache_last_updated' => date('Y-m-d H:i:s'), 'username_cache' => $maintainer); $update_vals = array('ldap_cache' => $values); reason_include_once('function_libraries/admin_actions.php'); /* I know this is nonstandard, but it's the only way right now to update the entity without creating an archive and changing the last_updated field on all the sites every day... */ $sqler = new SQLER(); foreach ($update_vals as $table => $fields) { $sqler->update_one($table, $fields, $this->parent->site_info->id()); } } } else { $email = $this->parent->site_info->get_value('email_cache'); $full_name = $this->parent->site_info->get_value('name_cache'); } return array('email' => $email, 'full_name' => $full_name); }
function get_display_value_datetime($value, &$item, $summary_mode) { $value = empty($value) ? carl_date('Y-m-d') : $value; return prettify_mysql_datetime($value); }
function _process_policy_reviewed_date(&$disco) { $chosenAction = $disco->get_chosen_action(); if (self::ACTION_CANCEL == $chosenAction) { // user cancelled; no need to do anything, the where_to callback will just bounce them back to the back with inline editing disabled } else { if (self::ACTION_DEBUG == $chosenAction) { $saveVals['last_reviewed_date'] = "0000-00-00"; reason_update_entity($this->request['policy_id'], $this->get_update_entity_user_id(), $saveVals, false); } else { if (self::ACTION_MARK_POLICY_REVIEWED == $chosenAction) { $saveVals['last_reviewed_date'] = carl_date('Y-m-d'); reason_update_entity($this->request['policy_id'], $this->get_update_entity_user_id(), $saveVals, true); } } } }