本文整理汇总了PHP中Valid::date方法的典型用法代码示例。如果您正苦于以下问题:PHP Valid::date方法的具体用法?PHP Valid::date怎么用?PHP Valid::date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Valid
的用法示例。
在下文中一共展示了Valid::date方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: default_value
/**
* return string
*/
public function default_value()
{
if (Valid::date($this->default)) {
return date($this->_format, strtotime($this->default));
} else {
return FALSE;
}
}
示例2: filter
public function filter()
{
$request = Request::initial();
$levels = (array) $request->query('level');
if (!empty($levels)) {
$this->where('level', 'in', $levels);
}
$date_range = $request->query('created_on');
if (empty($date_range)) {
$request->query('created_on', array(date('Y-m-d', strtotime("-1 month")), date('Y-m-d')));
}
if (is_array($date_range)) {
$this->where(DB::expr('DATE(created_on)'), 'between', $date_range);
} else {
if (Valid::date($date_range)) {
$this->where(DB::expr('DATE(created_on)'), '=', $date_range);
}
}
return $this;
}
示例3: test_date
/**
* Tests Valid::date()
*
* @test
* @dataProvider provider_date
* @param string $date The date to validate
* @param integer $expected
*/
public function test_date($date, $expected)
{
$this->assertSame($expected, Valid::date($date, $expected));
}
示例4: regenerateCli
public function regenerateCli()
{
$db = $this->db;
$newPaths = array();
$fields = array();
// Default fields and value
foreach ($this->dbFields as $field => $options) {
if (!$options['inFile']) {
$fields[$field] = $options['value'];
}
}
//$tmpPaths = glob(PATH_PAGES.'*', GLOB_ONLYDIR);
$tmpPaths = Filesystem::listDirectories(PATH_PAGES);
foreach ($tmpPaths as $directory) {
$key = basename($directory);
if (file_exists($directory . DS . 'index.txt')) {
// The key is the directory name
$newPaths[$key] = true;
}
// Recovery pages from subdirectories
//$subPaths = glob($directory.DS.'*', GLOB_ONLYDIR);
$subPaths = Filesystem::listDirectories($directory . DS);
foreach ($subPaths as $subDirectory) {
$subKey = basename($subDirectory);
if (file_exists($subDirectory . DS . 'index.txt')) {
// The key is composed by the directory/subdirectory
$newPaths[$key . '/' . $subKey] = true;
}
}
}
foreach ($newPaths as $key => $value) {
if (!isset($this->db[$key])) {
// Default values for the new pages.
$fields['status'] = CLI_STATUS;
$fields['date'] = Date::current(DB_DATE_FORMAT);
$fields['username'] = 'admin';
// Create the entry for the new page.
$this->db[$key] = $fields;
}
$Page = new Page($key);
// Update all fields from FILE to DATABASE.
foreach ($fields as $f => $v) {
// If the field exists on the FILE, update it.
if ($Page->getField($f)) {
$valueFromFile = $Page->getField($f);
if ($f == 'tags') {
// Generate tags array.
$this->db[$key]['tags'] = $this->generateTags($valueFromFile);
} elseif ($f == 'date') {
// Validate Date from file
if (Valid::date($valueFromFile, DB_DATE_FORMAT)) {
$this->db[$key]['date'] = $valueFromFile;
}
} else {
// Sanitize the values from file.
$this->db[$key][$f] = Sanitize::html($valueFromFile);
}
}
}
}
// Remove old pages from db
foreach (array_diff_key($db, $newPaths) as $key => $data) {
unset($this->db[$key]);
}
// Save the database.
if ($this->save() === false) {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
return false;
}
return $this->db != $db;
}
示例5: regenerateCli
public function regenerateCli()
{
$db = $this->db;
$allPosts = array();
$fields = array();
$currentDate = Date::current(DB_DATE_FORMAT);
// Generate default fields and values.
foreach ($this->dbFields as $field => $options) {
if (!$options['inFile']) {
$fields[$field] = $options['value'];
}
}
$fields['status'] = CLI_STATUS;
$fields['date'] = $currentDate;
$fields['username'] = 'admin';
// Recovery posts from the first level of directories
$tmpPaths = Filesystem::listDirectories(PATH_POSTS);
foreach ($tmpPaths as $directory) {
if (file_exists($directory . DS . 'index.txt')) {
// The key is the directory name.
$key = basename($directory);
// All keys posts
$allPosts[$key] = true;
// Create the new entry if not exists on DATABASE.
if (!isset($this->db[$key])) {
// New entry on database
$this->db[$key] = $fields;
}
// Create the post from FILE.
$Post = new Post($key);
// Update all fields from FILE to DATABASE.
foreach ($fields as $f => $v) {
// If the field exists on the FILE, update it.
if ($Post->getField($f)) {
$valueFromFile = $Post->getField($f);
if ($f == 'tags') {
// Generate tags array.
$this->db[$key]['tags'] = $this->generateTags($valueFromFile);
} elseif ($f == 'date') {
// Validate Date from file
if (Valid::date($valueFromFile, DB_DATE_FORMAT)) {
$this->db[$key]['date'] = $valueFromFile;
if ($valueFromFile > $currentDate) {
$this->db[$key]['status'] = 'scheduled';
}
}
} else {
// Sanitize the values from file.
$this->db[$key][$f] = Sanitize::html($valueFromFile);
}
}
}
}
}
// Remove orphan posts from db, the orphan posts are posts deleted by hand (directory deleted).
foreach (array_diff_key($db, $allPosts) as $key => $data) {
unset($this->db[$key]);
}
// Sort posts before save.
$this->sortByDate();
// Save the database.
if ($this->save() === false) {
Log::set(__METHOD__ . LOG_SEP . 'Error occurred when trying to save the database file.');
return false;
}
return $this->db != $db;
}
示例6: set_update_date
/**
*
* @param array $ids
* @param type $date
*/
public function set_update_date(array $ids, $date = NULL)
{
if (empty($ids)) {
return FALSE;
}
if ($date === NULL or !Valid::date($date)) {
$date = date('Y-m-d H:i:s');
}
DB::update($this->table_name())->set(array('updated_on' => $date))->where('id', 'in', $ids)->execute($this->_db);
if (Kohana::$caching === TRUE) {
Cache::instance()->delete_tag('pages');
}
return TRUE;
}
示例7: validate
protected function validate($value)
{
if (!Valid::date($value)) {
return 'date';
}
}
示例8: main
/**
* Pages admin function
*/
public static function main()
{
$current_theme = Option::get('theme_site_name');
$site_url = Option::get('siteurl');
$templates_path = THEMES_SITE;
$errors = array();
$pages = new Table('pages');
PagesAdmin::$pages = $pages;
$users = new Table('users');
$user = $users->select('[id=' . Session::get('user_id') . ']', null);
// Page author
if (!empty($user['firstname'])) {
$author = empty($user['lastname']) ? $user['firstname'] : $user['firstname'] . ' ' . $user['lastname'];
} else {
$author = Session::get('user_login');
}
$author = Html::toText($author);
// Status array
$status_array = array('published' => __('Published', 'pages'), 'draft' => __('Draft', 'pages'));
// Access array
$access_array = array('public' => __('Public', 'pages'), 'registered' => __('Registered', 'pages'));
// Check for get actions
// ---------------------------------------------
if (Request::get('action')) {
// Switch actions
// -----------------------------------------
switch (Request::get('action')) {
// Clone page
// -------------------------------------
case "clone_page":
if (Security::check(Request::get('token'))) {
// Generate rand page name
$rand_page_name = Request::get('name') . '_clone_' . date("Ymd_His");
// Get original page
$orig_page = $pages->select('[slug="' . Request::get('name') . '"]', null);
// Generate rand page title
$rand_page_title = $orig_page['title'] . ' [copy]';
// Clone page
if ($pages->insert(array('slug' => $rand_page_name, 'template' => $orig_page['template'], 'parent' => $orig_page['parent'], 'robots_index' => $orig_page['robots_index'], 'robots_follow' => $orig_page['robots_follow'], 'status' => $orig_page['status'], 'access' => isset($orig_page['access']) ? $orig_page['access'] : 'public', 'expand' => isset($orig_page['expand']) ? $orig_page['expand'] : '0', 'title' => $rand_page_title, 'meta_title' => $orig_page['meta_title'], 'description' => $orig_page['description'], 'keywords' => $orig_page['keywords'], 'tags' => $orig_page['tags'], 'date' => $orig_page['date'], 'author' => $orig_page['author']))) {
// Get cloned page ID
$last_id = $pages->lastId();
// Save cloned page content
File::setContent(STORAGE . DS . 'pages' . DS . $last_id . '.page.txt', File::getContent(STORAGE . DS . 'pages' . DS . $orig_page['id'] . '.page.txt'));
// Send notification
Notification::set('success', __('The page <i>:page</i> cloned.', 'pages', array(':page' => Security::safeName(Request::get('name'), '-', true))));
}
// Run add extra actions
Action::run('admin_pages_action_clone');
// Redirect
Request::redirect('index.php?id=pages');
} else {
die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
}
break;
// Add page
// -------------------------------------
// Add page
// -------------------------------------
case "add_page":
// Add page
if (Request::post('add_page') || Request::post('add_page_and_exit')) {
if (Security::check(Request::post('csrf'))) {
// Get parent page
if (Request::post('pages') == '0') {
$parent_page = '';
} else {
$parent_page = Request::post('pages');
}
// Validate
//--------------
if (trim(Request::post('page_name')) == '') {
$errors['pages_empty_name'] = __('Required field', 'pages');
}
if (trim(Request::post('page_title')) == '') {
$errors['pages_empty_title'] = __('Required field', 'pages');
}
if (count($pages->select('[slug="' . Security::safeName(Request::post('page_name'), '-', true) . '"]')) != 0) {
$errors['pages_exists'] = __('This page already exists', 'pages');
}
// Prepare date
if (Valid::date(Request::post('page_date'))) {
$date = strtotime(Request::post('page_date'));
} else {
$date = time();
}
if (Request::post('robots_index')) {
$robots_index = 'noindex';
} else {
$robots_index = 'index';
}
if (Request::post('robots_follow')) {
$robots_follow = 'nofollow';
} else {
$robots_follow = 'follow';
}
// If no errors then try to save
if (count($errors) == 0) {
//.........这里部分代码省略.........