Example #1
0
/**
 * Alter the default value for a date argument.
 *
 * @param object $argument
 *   The argument object.
 * @param string $value
 *   The default value created by the argument handler.
 */
function hook_date_default_argument_alter(&$argument, &$value)
{
    $style_options = $style_options = $argument->view->display_handler->get_option('style_options');
    if (!empty($style_options['track_date'])) {
        $default_date = date_now();
        $value = $default_date->format($argument->arg_format);
    }
}
 /**
  * Parse the duration of the event.
  * Example:
  *  DURATION:PT1H30M
  *  DURATION:P1Y2M
  *
  *  @param $subgroup
  *   array of other values in the vevent so we can check for DTSTART
  */
 public static function date_ical_parse_duration(&$subgroup, $field = 'DURATION')
 {
     $items = $subgroup[$field];
     $data = $items['DATA'];
     preg_match('/^P(\\d{1,4}[Y])?(\\d{1,2}[M])?(\\d{1,2}[W])?(\\d{1,2}[D])?([T]{0,1})?(\\d{1,2}[H])?(\\d{1,2}[M])?(\\d{1,2}[S])?/', $data, $duration);
     $items['year'] = isset($duration[1]) ? str_replace('Y', '', $duration[1]) : '';
     $items['month'] = isset($duration[2]) ? str_replace('M', '', $duration[2]) : '';
     $items['week'] = isset($duration[3]) ? str_replace('W', '', $duration[3]) : '';
     $items['day'] = isset($duration[4]) ? str_replace('D', '', $duration[4]) : '';
     $items['hour'] = isset($duration[6]) ? str_replace('H', '', $duration[6]) : '';
     $items['minute'] = isset($duration[7]) ? str_replace('M', '', $duration[7]) : '';
     $items['second'] = isset($duration[8]) ? str_replace('S', '', $duration[8]) : '';
     $start_date = array_key_exists('DTSTART', $subgroup) ? $subgroup['DTSTART']['datetime'] : date_format(date_now(), DATE_FORMAT_ISO);
     $timezone = array_key_exists('DTSTART', $subgroup) ? $subgroup['DTSTART']['tz'] : variable_get('date_default_timezone');
     if (empty($timezone)) {
         $timezone = 'UTC';
     }
     $date = new DateObject($start_date, $timezone);
     $date2 = clone $date;
     foreach ($items as $item => $count) {
         if ($count > 0) {
             date_modify($date2, '+' . $count . ' ' . $item);
         }
     }
     $format = isset($subgroup['DTSTART']['type']) && $subgroup['DTSTART']['type'] == 'DATE' ? 'Y-m-d' : 'Y-m-d H:i:s';
     $subgroup['DTEND'] = array('datetime' => date_format($date2, DATE_FORMAT_DATETIME), 'all_day' => isset($subgroup['DTSTART']['all_day']) ? $subgroup['DTSTART']['all_day'] : 0, 'tz' => $timezone);
     $duration = date_format($date2, 'U') - date_format($date, 'U');
     $subgroup['DURATION'] = array('DATA' => $data, 'DURATION' => $duration);
 }
         }
         if ('float' == $types[$k]) {
             if (!strlen($val)) {
                 $val = null;
             }
             $val = str_replace(',', '.', $val);
             if (!(is_numeric($val) || is_null($val))) {
                 error('%s: invalid value', $k);
             }
         }
         if ('time' == $types[$k]) {
             if (!strlen($val)) {
                 $val = null;
             }
             if ('now' == $val) {
                 $val = date_now();
             }
         }
         $post[$k] = $val;
     } else {
         error('Missing key: %s in POST', $k);
     }
 }
 if ('update' == $edit_action) {
     if ($post[$get['pk']] != $row[$get['pk']]) {
         if (count($row) != 1) {
             // Case: more than 1 column
             error('%s: cannot change pk on UPDATE', $get['pk']);
         }
     }
 }
Example #4
0
 function refresh_session($uid = "")
 {
     if ($uid == "") {
         $uid = $this->user;
     }
     global $db;
     $db->set($this->users_table, array($this->last_session_key => date_now()), $this->primary_key . " = '{$uid}'", FALSE);
 }
Example #5
0
 function add_log($type, $table, $affected_id, $data, $query = "", $error = "")
 {
     if (!$this->log) {
         return;
     }
     global $main;
     $date = "'" . date_now() . "'";
     $user_type = "'" . $main->userdata->user_type . "'";
     $user_id = $main->userdata->user_id;
     $type = "'" . $type . "'";
     $ip = "'" . get_ip() . "'";
     $dns = "'" . get_dns() . "'";
     $table = "'" . $table . "'";
     if ($user_type == "''") {
         return;
     }
     if ($data == '') {
         $data = 'NULL';
     } else {
         $data = "'" . addslashes($data) . "'";
     }
     if ($query == '') {
         $query = 'NULL';
     } else {
         $query = "'" . addslashes($query) . "'";
     }
     if ($error == '') {
         $error = 'NULL';
     } else {
         $error = "'" . addslashes($error) . "'";
     }
     $log_query = "INSERT INTO " . $this->logs_table . " (date, user_type, user_id, type, ip, dns, tablename, affected_id, data, query, error) VALUES ({$date}, {$user_type}, {$user_id}, {$type}, {$ip}, {$dns}, {$table}, {$affected_id}, {$data}, {$query}, {$error})";
     $insert_id_return = $this->insert_id;
     $last_query_return = $this->last_query;
     $this->query_data($log_query);
     $this->log_insert_id = $this->insert_id;
     $this->log_last_query = $this->last_query;
     $this->insert_id = $insert_id_return;
     $this->last_query = $last_query_return;
 }
 *   $event['end'] - the formatted end date of the event.
 *   $event['all_day'] - whether the item is an all day event.
 *   $event['rrule'] - the RRULE of the event, if any.
 *   $event['timezone'] - the formatted timezone name of the event, if any.
 *   $event['url'] - the url for the event.
 *   $event['location'] - the name of the event location.
 *   $event['description'] - a description of the event.
 *
 *   Note that there are empty spaces after RRULE, URL, LOCATION, etc
 *   that are needed to make sure we get the required line break.
 *
 * If you are editing this file, remember that all output lines generated by it
 * must end with DOS-style \r\n line endings, and not Unix-style \n, in order to
 * be compliant with the iCal spec (see http://tools.ietf.org/html/rfc5545#section-3.1)
 */
$date = date_now('UTC');
$current_date = !empty($event['current_date']) ? $event['current_date'] : $date->format(DATE_FORMAT_ICAL);
print "BEGIN:VEVENT\r\n";
print "UID:" . $event['uid'] . "\r\n";
print "SUMMARY:" . $event['summary'] . "\r\n";
print "DTSTAMP:" . $current_date . "Z\r\n";
if ($event['all_day']) {
    print "DTSTART;VALUE=DATE:" . $event['start'] . "\r\n";
} else {
    print "DTSTART:" . $event['start'] . "Z\r\n";
}
if (!empty($event['end'])) {
    if (!empty($event['all_day'])) {
        print "DTEND;VALUE=DATE:" . $event['end'] . "\r\n";
    } else {
        print "DTEND:" . $event['end'] . "Z\r\n";
 public function arrayErrors($arr)
 {
     $errors = array();
     $now = date_now();
     $default_month = !empty($arr['month']) ? $arr['month'] : $now->format('n');
     $default_year = !empty($arr['year']) ? $arr['year'] : $now->format('Y');
     foreach ($arr as $part => $value) {
         // Avoid false errors when a numeric value is input as a string by forcing it numeric.
         $value = intval($value);
         if (!empty($value) && $this->forceValid($part, $value, 'now', $default_month, $default_year) != $value) {
             // Use a switchcase to make translation easier by providing a different message for each part.
             switch ($part) {
                 case 'year':
                     $errors['year'] = t('The year is invalid.');
                     break;
                 case 'month':
                     $errors['month'] = t('The month is invalid.');
                     break;
                 case 'day':
                     $errors['day'] = t('The day is invalid.');
                     break;
                 case 'hour':
                     $errors['hour'] = t('The hour is invalid.');
                     break;
                 case 'minute':
                     $errors['minute'] = t('The minute is invalid.');
                     break;
                 case 'second':
                     $errors['second'] = t('The second is invalid.');
                     break;
             }
         }
     }
     return $errors;
 }
Example #8
0
 public function dofind()
 {
     $email = trim($this->input->post_get('email'));
     if (!preg_match('/^([a-zA-Z0-9\\._-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$/', $email)) {
         echo '邮件地址不正确';
         return;
     }
     $user = $this->signup->get_user_by_email($email);
     $guid = strtolower(create_guid());
     if (!$user) {
         echo '用户不存在';
         return;
     }
     $find_password = array('user_id' => $user['id'], 'link' => $guid, 'used' => FALSE, 'create_at' => date_now(), 'expired_at' => date("Y-m-d H:i:s", strtotime("+1 day")));
     $this->signup->find_password($find_password);
     $link = base_url('index.php/password/findpassword/' . $guid);
     $this->send_email($email, $user['nick'], $link);
     $this->load->view('password/find', array('step2' => TRUE));
 }
Example #9
0
 public function dodelete()
 {
     if (!$this->is_admin()) {
         $this->json_result(401, '非法请求', NULL);
         return;
     }
     $link = trim($this->input->post_get('link', TRUE));
     if ($link && preg_match('/^[a-zA-Z0-9]+$/', $link)) {
         $result = $this->model->delete_article($link, $this->user_id, date_now());
         $this->json_result(200, '请求成功', $result >= 1);
     } else {
         $this->json_result(400, '缺少参数或参数格式不正确', NULL);
     }
 }
Example #10
0
 /**
  * Seed the database table
  */
 public function __construct()
 {
     User::insert(['firstname' => 'John', 'lastname' => 'Doe', 'username' => 'username', 'password' => Hash::encode('password'), 'email' => '*****@*****.**', 'number' => 010000040120, 'avatar' => 'default.jpg', 'role' => 'superadmin', 'active' => 'yes', 'date_added' => date_now(), 'time_added' => time_now()]);
 }
Example #11
0
 /**
  * 上传文件
  */
 public function upload_img()
 {
     if (!$this->is_login()) {
         $this->json_result(401, '请先登录');
         return;
     }
     $upload_dir = $this->upload_dir;
     if (!is_dir($upload_dir)) {
         mkdir($upload_dir, 0644, TRUE);
     }
     $namelink = generate_name_link();
     $config['upload_path'] = $upload_dir;
     $config['allowed_types'] = 'gif|jpg|jpeg|png';
     $config['max_size'] = 1024 * 5;
     $config['file_name'] = $namelink['name'];
     $func_num = $this->input->post_get('CKEditorFuncNum');
     $this->load->library('upload', $config);
     if (!$this->upload->do_upload('upload')) {
         $error = $this->upload->display_errors();
         ob_clean();
         echo '<script type="text/javascript">';
         echo 'window.parent.CKEDITOR.tools.callFunction(' . $func_num . ',"",' . '"' . strip_tags($error) . '");';
         echo '</script>';
     } else {
         $upload_data = $this->upload->data();
         $filename = $upload_data['file_name'];
         $full_url = base_url($this->upload_dir . $filename);
         $link = $namelink['link'];
         $image = array('link' => $link, 'user_id' => $this->user_id, 'article_id' => NULL, 'size' => $upload_data['file_size'], 'width' => $upload_data['image_width'], 'height' => $upload_data['image_height'], 'upload_at' => date_now(), 'client_name' => $upload_data['client_name'], 'file_name' => $filename, 'ext' => strtolower($upload_data['file_ext']), 'local_path' => $upload_data['full_path'], 'local_url' => $full_url, 'transfered' => FALSE);
         //            $rel_link = base_url().'article/image/'.$link;
         $this->model->upload_image($image);
         echo '<script type="text/javascript">';
         echo 'window.parent.CKEDITOR.tools.callFunction(' . $func_num . ',"' . $full_url . '","")';
         echo '</script>';
     }
 }