<h2>time_verbose('<var>time</var>', <var>[include_seconds]</var>)</h2> <p>Returns the time into a verbose format (e.g. 12hrs 10mins 10secs).</p> <pre class="brush: php"> time_verbose(time(), TRUE); //returns <?php echo time_verbose(time(), TRUE); ?> </pre> <h2>english_to_db_format(<var>date</var>, <var>[hour]</var>, <var>[min]</var>, <var>[sec]</var>, <var>[ampm]</var>, <var>[delimiter]</var>)</h2> <p>Converts a date from english (e.g. mm/dd/yyyy) to db format (e.g yyyy-mm-dd). The default delimiter parameter is <strong>'/'</strong>.</p> <pre class="brush: php"> english_to_db_format('01/01/2010', 12, 10, 0); // returns <?php echo english_to_db_format('01/01/2010', 12, 10, 0); ?> </pre> <h2>format_db_date(<var>[y]</var>, <var>[m]</var>, <var>[d]</var>, <var>[h]</var>, <var>[i]</var>, <var>[s]</var>)</h2> <p>Formats a date for the database in (yyyy-mm-dd hh:mm:ss) format. If a value is left out, it will return the current date/time value for that slot.</p> <pre class="brush: php"> format_db_date(2010, 1, 1, 12, 10, 10); // returns <?php echo format_db_date(2010, 1, 1, 12, 10, 10); ?> </pre> <h2>date_range_string(<var>date1</var>, <var>date2</var>)</h2>
/** * Clean the data before saving * * @access public * @param mixed an array of values to be saved * @return array */ public function clean($values = array()) { if (empty($values)) { $values = $_POST; } $fields = $this->table_info(); $clean = array(); foreach ($fields as $key => $val) { if (isset($values[$key])) { $clean[$key] = $this->auto_trim ? trim($values[$key]) : $values[$key]; } } // get table information to clean against $this->load->helper('date'); $this->load->helper('string'); $this->load->helper('security'); foreach ($fields as $key => $field) { // make it easier for dates if ($field['type'] == 'datetime') { if (isset($values[$key . '_hour'])) { if (empty($values[$key]) or (int) $values[$key] == 0) { $values[$key] = $this->default_date; } $values[$key] = english_to_db_format($values[$key], @$values[$key . '_hour'], @$values[$key . '_min'], @$values[$key . '_sec'], @$values[$key . '_am_pm']); } } else { if ($field['type'] == 'date') { if (empty($values[$key]) or (int) $values[$key] == 0) { $values[$key] = $this->default_date; } if (isset($values[$key]) and !is_db_format($values[$key])) { $values[$key] = english_to_db_format($values[$key]); } } } $date_func = $this->date_use_gmt ? 'gmdate' : 'date'; // create dates for date added and last updated fields automatically if (($field['type'] == 'datetime' or $field['type'] == 'timestamp' or $field['type'] == 'date') and in_array($key, $this->auto_date_add)) { $test_date = isset($values[$key]) ? (int) $values[$key] : 0; // if no key field then we assume it is a new save and so we add the date if it's empty' if (!$this->_has_key_field_value($values) and empty($test_date)) { $values[$key] = $field['type'] == 'date' ? $date_func('Y-m-d') : $date_func('Y-m-d H:i:s'); } } else { if (($field['type'] == 'datetime' or $field['type'] == 'timestamp' or $field['type'] == 'date') and in_array($key, $this->auto_date_update)) { $values[$key] = $field['type'] == 'date' ? $date_func('Y-m-d') : $date_func('Y-m-d H:i:s'); } } if (isset($values[$key])) { // format dates if (!in_array($key, $this->auto_date_add)) { if ($field['type'] == 'datetime' or $field['type'] == 'timestamp' or $field['type'] == 'date') { if (strncmp($values[$key], '0000', 4) !== 0) { if ($field['type'] == 'date') { $values[$key] = $values[$key] != 'invalid' ? $date_func('Y-m-d', strtotime($values[$key])) : $this->default_date; } else { $values[$key] = $values[$key] != 'invalid' ? $date_func('Y-m-d H:i:s', strtotime($values[$key])) : $this->default_date; } } } } // safe_htmlspecialchars is buggy for unserialize so we use the cleanup_ms_word if ($this->auto_encode_entities) { if (is_array($this->auto_encode_entities) and in_array($key, $this->auto_encode_entities) or is_string($this->auto_encode_entities) and $key == $this->auto_encode_entities or $this->auto_encode_entities === TRUE) { $values[$key] = safe_htmlentities($values[$key]); //$values[$key] = cleanup_ms_word(($values[$key])); } } // safe_htmlspecialchars is buggy for unserialize so we use the cleanup_ms_word if ($this->xss_clean) { if (is_array($this->xss_clean) and in_array($key, $this->xss_clean) or is_string($this->xss_clean) and $key == $this->xss_clean or $this->xss_clean === TRUE) { $values[$key] = xss_clean($values[$key]); } } $clean[$key] = $values[$key]; } } $this->cleaned_data = $clean; return $clean; }