Copyright (c) 2012 Sallar Kaboli http://sallar.me The MIT License (MIT) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 1- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 2- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Original Jalali to Gregorian (and vice versa) convertor: Copyright (C) 2000 Roozbeh Pournader and Mohammad Toossi List of supported timezones can be found here: http://www.php.net/manual/en/timezones.php
See also: DateTime
Author: Sallar Kaboli (sallar.kaboli@gmail.com)
Author: Omid Pilevar (omid.pixel@gmail.com)
Exemple #1
1
 /**
  * @param $format
  * @param $str
  * @return \DateTime
  */
 public static function dateTimeFromFormat($format, $str)
 {
     $jd = new jDate();
     $pd = $jd->parseFromFormat($format, $str);
     $gd = jDateTime::toGregorian($pd['year'], $pd['month'], $pd['day']);
     $date = new \DateTime();
     $date->setDate($gd[0], $gd[1], $gd[2]);
     $date->setTime($pd['hour'], $pd['minute'], $pd['second']);
     return $date;
 }
 /**
  * fill item with the given xml node
  * @param SimpleXMLElement node representing an item
  */
 public function setFromXML(SimpleXMLElement $item)
 {
     $dt = new jDateTime();
     $resultat = explode(" ", (string) $item->author);
     foreach ($resultat as $mot) {
         if (jFilter::isEmail($mot)) {
             $this->authorEmail = $mot;
         } else {
             $this->authorName .= ' ' . $mot;
         }
     }
     $categorie = $item->category;
     foreach ($categorie as $cat) {
         $this->categories[] = (string) $cat;
     }
     $this->content = (string) $item->description;
     $this->id = (string) $item->guid;
     $this->link = (string) $item->link;
     if ((string) $item->pubDate != '') {
         $dt->setFromString((string) $item->pubDate, jDateTime::RFC2822_FORMAT);
         $this->published = $dt->toString(jDateTime::DB_DTFORMAT);
     }
     $this->title = (string) $item->title;
     $this->idIsPermalink = isset($item->guid['isPermaLink']) && $item->guid['isPermaLink'] == 'true' ? true : false;
     $this->sourceTitle = (string) $item->source;
     $this->sourceUrl = isset($item->source['url']) ? (string) $item->source['url'] : '';
     $this->comments = (string) $item->comments;
     if (isset($item->enclosure['url'])) {
         $this->enclosure = array();
         $attrs = array('url', 'length', 'type');
         foreach ($attrs as $a) {
             $this->enclosure[$a] = isset($item->enclosure[$a]) ? (string) $item->enclosure[$a] : '';
         }
     }
 }
 public function setFromXML(SimpleXMLElement $item)
 {
     $dt = new jDateTime();
     $this->authorEmail = (string) $item->author->email;
     $this->authorName = (string) $item->author->name;
     foreach ($item->category as $cat) {
         if ($cat['term'] != null) {
             $this->categories[] = (string) $cat['term'];
         }
     }
     $this->content = (string) $item->content;
     if ($item->content['type']) {
         $this->contentType = (string) $item->content['type'];
     }
     $this->source = (string) $item->source;
     $this->id = (string) $item->id;
     if ((string) $item->published != '') {
         $dt->setFromString((string) $item->published, jDateTime::ISO8601_FORMAT);
         $this->published = $dt->toString(jDateTime::DB_DTFORMAT);
     }
     $this->title = (string) $item->title;
     $this->authorUri = (string) $item->author->uri;
     $this->copyright = (string) $item->rights;
     foreach ($item->contributor as $contrib) {
         $this->contributors[] = array('name' => (string) $contrib->name, 'email' => (string) $contrib->email, 'uri' => (string) $contrib->uri);
     }
     $i = 0;
     foreach ($item->author as $author) {
         if ($i == 0) {
             $this->authorEmail = (string) $author->email;
             $this->authorName = (string) $author->name;
             $this->authorUri = (string) $author->uri;
         } else {
             $this->otherAuthors[] = array('name' => (string) $author->name, 'email' => (string) $author->email, 'uri' => (string) $author->uri);
         }
         $i++;
     }
     $attrs_links = array('href', 'rel', 'type', 'hreflang', 'title', 'length');
     foreach ($item->link as $l) {
         if (($l['rel'] == 'alternate' || $l['rel'] == null) && $l['href'] != null) {
             $this->link = (string) $l['href'];
         } else {
             $link = array();
             foreach ($attrs_links as $a) {
                 if ($l[$a] != null) {
                     $link[$a] = (string) $l[$a];
                 }
             }
             $this->otherLinks[] = $link;
         }
     }
     $this->summary = (string) $item->summary;
     if ($feed->summary['type']) {
         $this->summaryType = (string) $feed->summary['type'];
     }
     if ((string) $item->updated != '') {
         $dt->setFromString((string) $item->updated, jDateTime::ISO8601_FORMAT);
         $this->updated = $dt->toString(jDateTime::DB_DTFORMAT);
     }
 }
 function getDisplayValue($value)
 {
     if ($value != '') {
         $dt = new jDateTime();
         $dt->setFromString($value, jDateTime::DB_DFORMAT);
         $value = $dt->toString(jDateTime::LANG_DFORMAT);
     }
     return $value;
 }
/**
 * modifier plugin : change the format of a date
 *
 * It uses jDateTime to convert a date. It takes two optionnal arguments. 
 * The first one is the format identifier of the given date (by default, it is db_datetime). 
 * The second one is the format identifier of the output date (by default, it is lang_date).
 *
 * Availabled format identifiers are (with the equivalent constant of jDateTime)  :
 * <ul>
 * <li>'lang_date' (jDateTime::LANG_DFORMAT)</li>
 * <li>'lang_datetime' => jDateTime::LANG_DTFORMAT)</li>
 * <li>'lang_time' => jDateTime::LANG_TFORMAT)</li>
 * <li>'db_date' => jDateTime::DB_DFORMAT)</li>
 * <li>'db_datetime' => jDateTime::DB_DTFORMAT)</li>
 * <li>'db_time' => jDateTime::DB_TFORMAT)</li>
 * <li>'iso8601' => jDateTime::ISO8601_FORMAT)</li>
 * <li>'timestamp' => jDateTime::TIMESTAMP_FORMAT)</li>
 * <li>'rfc822'=> jDateTime::RFC822_FORMAT)</li></ul>
 * 
 * examples :
 *  {$mydate|jdatetime}
 *  {$mydate|jdatetime:'db_time':'lang_time'}
 *
 * @param string $date the date
 * @param string $format_in  the format identifier of the given date
 * @param string $format_out the format identifier of the output date
 * @return string the converted date
 * @see jDateTime
 */
function jtpl_modifier_common_jdatetime($date, $format_in = 'db_datetime', $format_out = 'lang_date')
{
    $formats = array('lang_date' => jDateTime::LANG_DFORMAT, 'lang_datetime' => jDateTime::LANG_DTFORMAT, 'lang_time' => jDateTime::LANG_TFORMAT, 'db_date' => jDateTime::DB_DFORMAT, 'db_datetime' => jDateTime::DB_DTFORMAT, 'db_time' => jDateTime::DB_TFORMAT, 'iso8601' => jDateTime::ISO8601_FORMAT, 'timestamp' => jDateTime::TIMESTAMP_FORMAT, 'rfc822' => jDateTime::RFC822_FORMAT);
    if (!isset($formats[$format_in]) | !isset($formats[$format_out])) {
        throw new jException("jelix~errors.tpl.tag.modifier.invalid", array('', 'jdatetime', ''));
    }
    $dt = new jDateTime();
    $dt->setFromString($date, $formats[$format_in]);
    return $dt->toString($formats[$format_out]);
}
 function getDisplayValue($value)
 {
     if ($value != '') {
         $dt = new jDateTime();
         $dt->setFromString($value, jDateTime::DB_DFORMAT);
         $value = $dt->toString(jDateTime::LANG_DFORMAT);
     } else {
         if ($this->emptyValueLabel !== null) {
             return $this->emptyValueLabel;
         }
     }
     return $value;
 }
Exemple #7
0
 /**
  * function to manage data before assigning to the template of its zone
  */
 protected function _prepareTpl()
 {
     $daoThreads = jDao::get('havefnubb~threads_alone');
     //posts and thread
     //last posts
     $recForum = jDao::get('havefnubb~forum')->statsForum();
     $msgs = $recForum->nb_msg;
     $threads = $recForum->nb_thread;
     $lastPost = jDao::get('havefnubb~posts')->getLastPost();
     // if lastPost is "false" the forum is empty !
     if ($lastPost === false) {
         $forum = new StdClass();
         $forum->forum_name = '';
         $lastPost = new StdClass();
         $lastPost->thread_id = 0;
         $lastPost->id_post = 0;
         $lastPost->subject = '';
         $lastPost->id_forum = 0;
         $lastPost->date_created = 0;
         $lastPost->date_last_post = 0;
         $lastPost->id_first_msg = 0;
         $lastPost->id_last_msg = 0;
     } else {
         $thread = $daoThreads->get($lastPost->thread_id);
         $dao = jDao::get('havefnubb~forum');
         $forum = $dao->get($lastPost->id_forum);
         if ($thread !== false) {
             $lastPost->id_first_msg = $thread->id_first_msg;
             $lastPost->id_last_msg = $thread->id_last_msg;
         } else {
             $lastPost->id_first_msg = 0;
             $lastPost->id_last_msg = 0;
         }
     }
     $dao = jDao::get('havefnubb~member');
     //members
     $members = $dao->countAllActivatedMember();
     // last registered user that is validate
     $lastMember = $dao->findLastActiveMember();
     // display in the header ; the date of the last known posts
     $dt = new jDateTime();
     $dt->setFromString($lastPost->date_created, jDateTime::TIMESTAMP_FORMAT);
     $meta = '<meta name="dc.date" content="' . $dt->toString(jDateTime::ISO8601_FORMAT) . '" />';
     jApp::coord()->response->addHeadContent($meta);
     $this->_tpl->assign('posts', $msgs);
     $this->_tpl->assign('threads', $threads);
     $this->_tpl->assign('lastPost', $lastPost);
     $this->_tpl->assign('forum', $forum);
     $this->_tpl->assign('members', $members);
     $this->_tpl->assign('lastMember', $lastMember);
 }
 public function setFromXML(SimpleXMLElement $feed)
 {
     $dt = new jDateTime();
     foreach ($feed->category as $cat) {
         if ($cat['term'] != null) {
             $this->categories[] = (string) $cat['term'];
         }
     }
     $this->description = (string) $feed->subtitle;
     if ($feed->subtitle['type']) {
         $this->descriptionType = (string) $feed->subtitle['type'];
     }
     $this->generator = (string) $feed->generator;
     $this->image = (string) $feed->logo;
     $this->title = (string) $feed->title;
     $this->copyright = (string) $feed->rights;
     if ((string) $feed->updated != '') {
         $dt->setFromString((string) $feed->updated, jDateTime::ISO8601_FORMAT);
         $this->updated = $dt->toString(jDateTime::DB_DTFORMAT);
     }
     $attrs_links = array('href', 'rel', 'type', 'hreflang', 'title', 'length');
     foreach ($feed->link as $l) {
         if (($l['rel'] == 'alternate' || $l['rel'] == null) && $l['href'] != null) {
             $this->webSiteUrl = (string) $l['href'];
         } else {
             if ($l['rel'] == 'self' && $l['href'] != null) {
                 $this->selfLink = (string) $l['href'];
             } else {
                 $link = array();
                 foreach ($attrs_links as $a) {
                     if ($l[$a] != null) {
                         $link[$a] = (string) $l[$a];
                     }
                 }
                 $this->otherLinks[] = $link;
             }
         }
     }
     foreach ($feed->author as $author) {
         $this->authors[] = array('name' => (string) $author->name, 'email' => (string) $author->email, 'uri' => (string) $author->uri);
     }
     foreach ($feed->contributor as $contrib) {
         $this->contributors[] = array('name' => (string) $contrib->name, 'email' => (string) $contrib->email, 'uri' => (string) $contrib->uri);
     }
     $this->generatorUrl = (string) $feed->generator['url'];
     $this->generatorVersion = (string) $feed->generator['version'];
     $this->icon = (string) $feed->icon;
     $this->id = (string) $feed->id;
 }
 function setDataFromDao($value, $daoDatatype)
 {
     if ($this->datatype instanceof jDatatypeLocaleDateTime && $daoDatatype == 'datetime') {
         if ($value != '') {
             $dt = new jDateTime();
             $dt->setFromString($value, jDateTime::DB_DTFORMAT);
             $value = $dt->toString(jDateTime::LANG_DTFORMAT);
         }
     } elseif ($this->datatype instanceof jDatatypeLocaleDate && $daoDatatype == 'date') {
         if ($value != '') {
             $dt = new jDateTime();
             $dt->setFromString($value, jDateTime::DB_DFORMAT);
             $value = $dt->toString(jDateTime::LANG_DFORMAT);
         }
     }
     $this->setData($value);
 }
 public function setFromXML(SimpleXMLElement $channel)
 {
     $dt = new jDateTime();
     $this->copyright = (string) $channel->copyright;
     $this->description = (string) $channel->description;
     $this->generator = (string) $channel->generator;
     $this->image = (string) $channel->image->url;
     $this->title = (string) $channel->title;
     if ((string) $channel->lastBuildDate != '') {
         $dt->setFromString((string) $channel->lastBuildDate, jDateTime::RFC2822_FORMAT);
         $this->updated = $dt->toString(jDateTime::DB_DTFORMAT);
     }
     if ((string) $channel->pubDate != '') {
         $dt->setFromString((string) $channel->pubDate, jDateTime::RFC2822_FORMAT);
         $this->published = $dt->toString(jDateTime::DB_DTFORMAT);
     }
     $this->webSiteUrl = (string) $channel->link;
     $this->docs = (string) $channel->docs;
     $this->imageHeight = (string) $channel->image->height;
     $this->imageLink = (string) $channel->image->link;
     $this->imageTitle = (string) $channel->image->title;
     $this->imageWidth = (string) $channel->image->width;
     $this->imageDescription = (string) $channel->image->description;
     $this->language = (string) $channel->language;
     $this->managingEditor = (string) $channel->managingEditor;
     $this->rating = (string) $channel->rating;
     $categories = $channel->category;
     foreach ($categories as $cat) {
         $this->categories[] = (string) $cat;
     }
     $skipDays = $channel->skipDays;
     foreach ($skipDays->day as $day) {
         $this->skipDays[] = (string) $day;
     }
     $skipHours = $channel->skipHours;
     foreach ($skipHours->hour as $hour) {
         $this->skipHours[] = (string) $hour;
     }
     $this->textInput['title'] = (string) $channel->textInput->title;
     $this->textInput['description'] = (string) $channel->textInput->description;
     $this->textInput['name'] = (string) $channel->textInput->name;
     $this->textInput['link'] = (string) $channel->textInput->link;
     $this->ttl = (string) $channel->ttl;
     $this->webMaster = (string) $channel->webMaster;
 }
 public function test_create()
 {
     //        $date = new Date();
     //        echo $date->date("W");
     //        $date = new jDateTime(false, true, 'Asia/Tehran');
     //        echo $date->date("z  W",time());
     //        echo $date->date("Y m d",strtotime("next week"))."<br>";
     //        echo jdate("Y m d",strtotime("next week"))."<br>";
     //        echo $date->strftime("y m d","next week");
     //       echo $date->strftime("next week", time(),true, true, 'America/New_York');
     $this->load->library("date");
     $date1 = new jDateTime(false, true, 'Asia/Tehran');
     $date2 = new jDateTime(false);
     $date1->strftime("now");
     $date2->strftime("tomorrow");
     echo $date1->strftime("%s");
     var_dump($date1->date() == $date2->date());
     var_dump($date1 < $date2);
     var_dump($date1 > $date2);
 }
 /**
  * jDateTime::Constructor
  *
  * Pass these parameteres when creating a new instance
  * of this Class, and they will be used as defaults.
  * e.g $obj = new jDateTime(false, true, 'Asia/Tehran');
  * To use system defaults pass null for each one or just
  * create the object without any parameters.
  *
  * @author Sallar Kaboli
  * @param $convert bool Converts numbers to Farsi
  * @param $jalali bool Converts date to Jalali
  * @param $timezone string Timezone string
  */
 public function __construct($convert = null, $jalali = null, $timezone = null)
 {
     if ($jalali !== null) {
         self::$jalali = $jalali === false ? false : true;
     }
     if ($convert !== null) {
         self::$convert = $convert === false ? false : true;
     }
     if ($timezone !== null) {
         self::$timezone = $timezone != null ? $timezone : null;
     }
 }
 /**
  * jDateTime::Constructor
  *
  * Pass these parameteres when creating a new instance
  * of this Class, and they will be used as defaults.
  * e.g $obj = new jDateTime(false, true, 'Asia/Tehran');
  * To use system defaults pass null for each one or just
  * create the object without any parameters.
  *
  * @author Sallar Kaboli
  * @param $convert bool Converts numbers to Farsi
  * @param $jalali bool Converts date to Jalali
  * @param $timezone string Timezone string
  */
 public function __construct($convert = null, $jalali = null, $timezone = null)
 {
     if ($jalali !== null) {
         self::$jalali = (bool) $jalali;
     }
     if ($convert !== null) {
         self::$convert = (bool) $convert;
     }
     if ($timezone !== null) {
         self::$timezone = $timezone;
     }
 }
/**
 * modifier plugin : change the format of a date
 *
 * It uses jDateTime to convert a date. It takes two optionnal arguments.
 * The first one is the format identifier of the given date (by default, it is db_datetime).
 * The second one is the format identifier of the output date (by default, it is lang_date).
 *
 * Availabled format identifiers are (with the equivalent constant of jDateTime)  :
 * <ul>
 * <li>'lang_date' (jDateTime::LANG_DFORMAT)</li>
 * <li>'lang_datetime' => jDateTime::LANG_DTFORMAT)</li>
 * <li>'lang_time' => jDateTime::LANG_TFORMAT)</li>
 * <li>'db_date' => jDateTime::DB_DFORMAT)</li>
 * <li>'db_datetime' => jDateTime::DB_DTFORMAT)</li>
 * <li>'db_time' => jDateTime::DB_TFORMAT)</li>
 * <li>'iso8601' => jDateTime::ISO8601_FORMAT)</li>
 * <li>'timestamp' => jDateTime::TIMESTAMP_FORMAT)</li>
 * <li>'rfc822'=> jDateTime::RFC822_FORMAT)</li>
 * <li>'full_lang_date'=> jDateTime::FULL_LANG_DATE</li></ul>
 *
 * examples :
 *  {$mydate|jdatetime}
 *  {$mydate|jdatetime:'db_time':'lang_time'}
 *
 * @param string $date the date
 * @param string $format_in  the format identifier of the given date
 * @param string $format_out the format identifier of the output date
 * @return string the converted date
 * @see jDateTime
 */
function jtpl_modifier_common_jdatetime($date, $format_in = 'db_datetime', $format_out = 'lang_date')
{
    if (is_null($date)) {
        return '';
    }
    $formats = array('lang_date' => jDateTime::LANG_DFORMAT, 'lang_datetime' => jDateTime::LANG_DTFORMAT, 'lang_time' => jDateTime::LANG_TFORMAT, 'lang_short_datetime' => jDateTime::LANG_SHORT_DTFORMAT, 'db_date' => jDateTime::DB_DFORMAT, 'db_datetime' => jDateTime::DB_DTFORMAT, 'db_time' => jDateTime::DB_TFORMAT, 'iso8601' => jDateTime::ISO8601_FORMAT, 'timestamp' => jDateTime::TIMESTAMP_FORMAT, 'rfc822' => jDateTime::RFC822_FORMAT, 'full_lang_date' => jDateTime::FULL_LANG_DATE);
    if (isset($formats[$format_in])) {
        $format_in = $formats[$format_in];
    }
    if (isset($formats[$format_out])) {
        $format_out = $formats[$format_out];
    }
    $ret = false;
    $dt = new jDateTime();
    if ($dt->setFromString($date, $format_in)) {
        $ret = $dt->toString($format_out);
    }
    if ($ret == false) {
        throw new jException("jelix~errors.tpl.tag.modifier.invalid", array('', 'jdatetime', ''));
    }
    return $ret;
}
Exemple #15
0
 public function format($str, $convert = true)
 {
     // convert alias string
     if (in_array($str, array_keys($this->formats))) {
         $str = $this->formats[$str];
     }
     // if valid unix timestamp...
     if ($this->time !== false) {
         return jDateTime::strftime($str, $this->time, $convert);
     } else {
         return false;
     }
 }
Exemple #16
0
 public static function mktime($hour, $minute, $second, $month, $day, $year, $jalali = null, $timezone = null)
 {
     return jDateTime::mktime($hour, $minute, $second, $month, $day, $year, $jalali, $timezone);
 }
Exemple #17
0
 static function submitNewUser($username, $password, $email, $password2 = null)
 {
     if (!registerUsers()) {
         return 5;
     }
     // admin has disabled registering new users
     $email = filter_var($email, FILTER_SANITIZE_EMAIL);
     $username = validateUserName($username) ? $username : false;
     $password = validatePassword($password) ? $password : false;
     if (!$username || !$password) {
         return 1;
         // username or password does not meet the requirements
     }
     if (isset($password2)) {
         $password2 = validatePassword($password2) ? $password2 : false;
         if ($password2 != false) {
             //$password2 = passwordHash($password2);
             if ($password2 != $password) {
                 return 4;
                 // passwords do not match
             }
         } else {
             return 4;
         }
     }
     $password = passwordHash($password);
     $current_datetime = jDateTime::gdate('Y-m-d H:i:s');
     if (Users::userExists($username)) {
         return 2;
         // username already exist
     }
     $activate = md5($email . time());
     $conn = MySQL::open_conn();
     $query = "INSERT INTO c_users (user_login, user_pass, user_email, user_registered, activate) ";
     $query .= "VALUES ('{$username}', '{$password}', '{$email}', '{$current_datetime}', '{$activate}')";
     $res = $conn->query($query);
     if (!$res) {
         return 3;
     }
     // unknown error while creating new user
     $row = $conn->query("SELECT MAX(ID) AS max FROM c_users")->fetch_array();
     if ($row) {
         $id = $row['max'];
     }
     if (shouldConfMail()) {
         $mail_content = replace_template(getDefaultEmailTemplateContent(), getConfEmailTemplateVars($id));
         Email::sendMail($email, $username, getConfMailSubject(), $mail_content);
     }
     return 0;
 }
Exemple #18
0
    } else {
        $register_status = 'no';
    }
    $query = "UPDATE c_options SET option_value = '{$register_status}' WHERE option_name = 'register_open'";
    $res = $conn->query($query);
    dbQueryCheck($res, $conn);
    //
    if (isset($_POST['conf_mail'])) {
        $conf_mail = 'yes';
    } else {
        $conf_mail = 'no';
    }
    $query = "UPDATE c_options SET option_value = '{$conf_mail}' WHERE option_name = 'send_conf_mail'";
    $res = $conn->query($query);
    dbQueryCheck($res, $conn);
    $datetime = jDateTime::date('Y-m-d', false, null, false);
    $query = "UPDATE c_options SET option_value = '{$datetime}' WHERE option_name = 'installation_date'";
    $res = $conn->query($query);
    dbQueryCheck($res, $conn);
    ob_end_clean();
    redirectTo('index.php?switch=4&hash=' . $hash);
}
?>
    <?php 
if (!isset($_GET['switch'])) {
    ?>
        <div class="col-xs-12 col-sm-12 col-md-6 co-lg-6 col-md-offset-2 div_white_left">
            <div style="text-align: center; padding: 5%;">
                Welcome to ccms installation script.<br>Just a few steps and your website will be online.
                <br><br>
                Please <strong>do not</strong> refresh any page or use back button on your browser during installation.
 /**
  * Gets a Unix Timestamp from a textual date time string
  * @param string $date
  * @return int
  */
 public static function getTimestampFromString($date)
 {
     $timestamp = strtotime($date);
     // If we are Jalali, then we want to convert from Jalali back to Gregorian. Otherwise assume input is already Gregorian.
     if (Config::GetSetting('CALENDAR_TYPE') == 'Jalali') {
         // Split the time stamp into its component parts and pass it to the conversion.
         $date = trim($date);
         $split = stripos($date, ' ') > 0 ? explode(' ', $date) : array($date, '');
         $dateSplit = explode('-', $split[0]);
         $date = jDateTime::toGregorian($dateSplit[0], $dateSplit[1], $dateSplit[2]);
         //Debug::Audit('Converted to Gregorian from Jalali: ' . var_export($date, true));
         // Convert that back into a date using strtotime - the date is now Gregorian
         $timestamp = strtotime($date[0] . '-' . $date[1] . '-' . $date[2] . ' ' . $split[1]);
     }
     return $timestamp;
 }
Exemple #20
0
 private static function _decodeValue($valuetag)
 {
     $children = $valuetag->children();
     $value = null;
     if (count($children)) {
         if (isset($valuetag->i4)) {
             $value = intval((string) $valuetag->i4);
         } else {
             if (isset($valuetag->int)) {
                 $value = intval((string) $valuetag->int);
             } else {
                 if (isset($valuetag->double)) {
                     $value = doubleval((string) $valuetag->double);
                 } else {
                     if (isset($valuetag->string)) {
                         $value = html_entity_decode((string) $valuetag->string);
                     } else {
                         if (isset($valuetag->boolean)) {
                             $value = intval((string) $valuetag->boolean) ? true : false;
                         } else {
                             if (isset($valuetag->array)) {
                                 $value = array();
                                 if (isset($valuetag->array->data->value)) {
                                     foreach ($valuetag->array->data->value as $val) {
                                         $value[] = self::_decodeValue($val);
                                     }
                                 }
                             } else {
                                 if (isset($valuetag->struct)) {
                                     $value = array();
                                     if (isset($children[0]->member)) {
                                         foreach ($children[0]->member as $val) {
                                             if (isset($val->name) && isset($val->value)) {
                                                 $value[(string) $val->name] = self::_decodeValue($val->value);
                                             }
                                         }
                                     }
                                 } else {
                                     if (isset($valuetag->{'dateTime.iso8601'})) {
                                         $value = new jDateTime();
                                         $value->setFromString((string) $valuetag->{'dateTime.iso8601'}, jDateTime::ISO8601_FORMAT);
                                     } else {
                                         if (isset($valuetag->base64)) {
                                             $value = new jBinaryData();
                                             $value->setFromBase64String((string) $valuetag->base64);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $value = (string) $valuetag;
     }
     return $value;
 }
Exemple #21
0
 /**
  * @param $format
  * @param $date
  * @return array
  */
 public function parseFromFormat($format, $date)
 {
     // reverse engineer date formats
     $keys = array('Y' => array('year', '\\d{4}'), 'y' => array('year', '\\d{2}'), 'm' => array('month', '\\d{2}'), 'n' => array('month', '\\d{1,2}'), 'M' => array('month', '[A-Z][a-z]{3}'), 'F' => array('month', '[A-Z][a-z]{2,8}'), 'd' => array('day', '\\d{2}'), 'j' => array('day', '\\d{1,2}'), 'D' => array('day', '[A-Z][a-z]{2}'), 'l' => array('day', '[A-Z][a-z]{6,9}'), 'u' => array('hour', '\\d{1,6}'), 'h' => array('hour', '\\d{2}'), 'H' => array('hour', '\\d{2}'), 'g' => array('hour', '\\d{1,2}'), 'G' => array('hour', '\\d{1,2}'), 'i' => array('minute', '\\d{2}'), 's' => array('second', '\\d{2}'));
     // convert format string to regex
     $regex = '';
     $chars = str_split($format);
     foreach ($chars as $n => $char) {
         $lastChar = isset($chars[$n - 1]) ? $chars[$n - 1] : '';
         $skipCurrent = '\\' == $lastChar;
         if (!$skipCurrent && isset($keys[$char])) {
             $regex .= '(?P<' . $keys[$char][0] . '>' . $keys[$char][1] . ')';
         } else {
             if ('\\' == $char) {
                 $regex .= $char;
             } else {
                 $regex .= preg_quote($char);
             }
         }
     }
     $dt = array();
     $dt['error_count'] = 0;
     // now try to match it
     if (preg_match('#^' . $regex . '$#', $date, $dt)) {
         foreach ($dt as $k => $v) {
             if (is_int($k)) {
                 unset($dt[$k]);
             }
         }
         if (!jDateTime::checkdate($dt['month'], $dt['day'], $dt['year'], false)) {
             $dt['error_count'] = 1;
         }
     } else {
         $dt['error_count'] = 1;
     }
     $dt['errors'] = array();
     $dt['fraction'] = '';
     $dt['warning_count'] = 0;
     $dt['warnings'] = array();
     $dt['is_localtime'] = 0;
     $dt['zone_type'] = 0;
     $dt['zone'] = 0;
     $dt['is_dst'] = '';
     return $dt;
 }
Exemple #22
0
 public function testConvertFormatToFormat()
 {
     $a = '2016-02-14 14:20:38';
     $date = \jDateTime::convertFormatToFormat('Y-m-d H:i:s', 'Y-m-d H:i:s', $a, 'Asia/Tehran');
     $this->assertEquals($date, '۱۳۹۴-۱۱-۲۵ ۱۴:۲۰:۳۸');
 }
Exemple #23
0
 /**
  * Substract a date with another
  * @param jDateTime $date
  * @return jDateTime
  * @author Hadrien Lanneau <*****@*****.**>
  * @since 1.2
  */
 public function substract($date = null)
 {
     if (!$date) {
         $date = new jDateTime();
         $date->now();
     }
     $newDate = new jDateTime();
     $items = array('second', 'minute', 'hour', 'day', 'month', 'year');
     foreach ($items as $k => $i) {
         $newDate->{$i} = $date->{$i} - $this->{$i};
         if ($newDate->{$i} < 0) {
             switch ($i) {
                 case 'second':
                 case 'minute':
                     $sub = 60;
                     break;
                 case 'hour':
                     $sub = 24;
                     break;
                 case 'day':
                     switch ($this->month) {
                         // Month with 31 days
                         case 1:
                         case 3:
                         case 5:
                         case 7:
                         case 8:
                         case 10:
                         case 12:
                             $sub = 31;
                             break;
                             // Month with 30 days
                         // Month with 30 days
                         case 4:
                         case 6:
                         case 9:
                         case 11:
                             $sub = 30;
                             break;
                             // February
                         // February
                         case 2:
                             if ($this->year % 4 == 0 and !($this->year % 100 == 0 and $this->year % 400 != 0)) {
                                 // Bissextile
                                 $sub = 29;
                             } else {
                                 $sub = 28;
                             }
                             break;
                     }
                     break;
                 case 'month':
                     $sub = 12;
                     break;
                 default:
                     $sub = 0;
             }
             $newDate->{$i} = abs($sub + $newDate->{$i});
             if (isset($items[$k + 1])) {
                 $newDate->{$items[$k + 1]}--;
             }
         }
     }
     return $newDate;
 }
 function testLeap2()
 {
     $dur = new jDuration(array("year" => 7));
     $dt = new jDateTime(2000, 2, 29, 12, 12, 12);
     $dtExpected = new jDateTime(1993, 3, 1, 12, 12, 12);
     $dt->sub($dur);
     $this->assertEqual($dt, $dtExpected);
 }
Exemple #25
0
 public static function date()
 {
     $date = new jDateTime(true, true, 'Asia/Tehran');
     return $date->date("Y-m-d", false, false);
 }
 function testsetFromString()
 {
     // Time when my guests leave.
     $dt = new jDateTime();
     $dt->setFromString("2007-12-26", jDateTime::DB_DFORMAT);
     $this->assertEqual(new jDateTime(2007, 12, 26, 0, 0, 0), $dt);
     $dt->setFromString("2007-12-26 05:17:25", jDateTime::DB_DTFORMAT);
     $this->assertEqual(new jDateTime(2007, 12, 26, 5, 17, 25), $dt);
     $dt->setFromString("05:17:25", jDateTime::DB_TFORMAT);
     $this->assertEqual(new jDateTime(0, 0, 0, 5, 17, 25), $dt);
     $dt->setFromString("2007-12-26T05:17:25Z", jDateTime::ISO8601_FORMAT);
     $this->assertEqual(new jDateTime(2007, 12, 26, 5, 17, 25), $dt);
     $dt->setFromString("2007-12-26T05:17:25+01:30", jDateTime::ISO8601_FORMAT);
     $this->assertEqual(new jDateTime(2007, 12, 26, 6, 47, 25), $dt);
     $dt->setFromString("2007-12-26T05:17:25-01:15", jDateTime::ISO8601_FORMAT);
     $this->assertEqual(new jDateTime(2007, 12, 26, 4, 2, 25), $dt);
     $dt->setFromString("1198642645", jDateTime::TIMESTAMP_FORMAT);
     $this->assertEqual(new jDateTime(2007, 12, 26, 5, 17, 25), $dt);
     // Beware of the time zone
     $dt->setFromString("Wed, 26 Dec 2007 05:17:25 +0100", jDateTime::RFC822_FORMAT);
     $this->assertEqual(new jDateTime(2007, 12, 26, 4, 17, 25), $dt);
 }
Exemple #27
0
 function __construct($convert = null, $jalali = null, $timezone = null)
 {
     // TODO: Implement __construct() method.
     parent::__construct($convert, $jalali, $timezone);
 }
Exemple #28
0
 /**
  * dao handler for session stored in database
  */
 public static function daoGarbageCollector($maxlifetime)
 {
     $date = new jDateTime();
     $date->now();
     $date->sub(0, 0, 0, 0, 0, $maxlifetime);
     self::_getDao()->deleteExpired($date->toString(jDateTime::BD_DTFORMAT));
     return true;
 }
Exemple #29
0
 /**
  * declare a child control to the form. The given control should be a child of an other control
  * @param jFormsControl $control
  */
 public function addChildControl($control)
 {
     $this->controls[$control->ref] = $control;
     if ($control->type == 'submit') {
         $this->submits[$control->ref] = $control;
     } else {
         if ($control->type == 'reset') {
             $this->reset = $control;
         } else {
             if ($control->type == 'upload') {
                 $this->uploads[$control->ref] = $control;
             } else {
                 if ($control->type == 'hidden') {
                     $this->hiddens[$control->ref] = $control;
                 } else {
                     if ($control->type == 'htmleditor') {
                         $this->htmleditors[$control->ref] = $control;
                     }
                 }
             }
         }
     }
     $control->setForm($this);
     if (!isset($this->container->data[$control->ref])) {
         if ($control->datatype instanceof jDatatypeDateTime && $control->defaultValue == 'now') {
             $dt = new jDateTime();
             $dt->now();
             $this->container->data[$control->ref] = $dt->toString($control->datatype->getFormat());
         } else {
             $this->container->data[$control->ref] = $control->defaultValue;
         }
     }
 }
Exemple #30
0
<?php

if (isset($_POST["submit_new_user"])) {
    $username = $_POST['new_user_username'];
    $username = validateUserName($username) ? $_POST['new_user_username'] : false;
    $bh_password = $_POST['new_user_password'];
    $bh_password = validatePassword($bh_password) ? $_POST['new_user_password'] : false;
    $password = passwordHash($bh_password);
    $email = $_POST['new_user_email'];
    //$vip = isset($_POST['new_user_vip']) ? 1 : 0;
    $bp_role = $_POST['new_user_role'];
    $current_datetime = jDateTime::gdate('Y-m-d H:i:s');
    $bp_vip = $_POST['new_user_vip'];
    if ($bp_vip == 0) {
        $vip = 0;
        $vip_start = null;
        $vip_expire = null;
    } elseif ($bp_vip == -1) {
        $vip = -1;
        $vip_start = $current_datetime;
        $vip_expire = null;
    } else {
        $vip = $bp_vip;
        $vip_start = strtotime($current_datetime);
        $vip_expire = strtotime('+' . $vip . ' day', $vip_start);
        $vip_start = $current_datetime;
        $vip_expire = date('Y-m-d H:i:s', $vip_expire);
    }
    if (Users::userExists($username)) {
        goToError('?switch=users#new_user', _e('username_already_exists', '', '', true));
    }