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); } }
/** * 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 $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; }
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; }
/** * 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); }
function testReportedBug() { // Get now date/time $dtNow = new jDateTime(); $dtNow->setFromString("2008-02-08 00:27:22", jDateTime::DB_DTFORMAT); // Get expiration date $expirationDate = "2008-02-12 00:00:00"; // Create date time object from DB date $dtExpirationDate = new jDateTime(); $dtExpirationDate->setFromString($expirationDate, jDateTime::DB_DTFORMAT); // Compute difference between these dates try { $countdown = $dtNow->durationTo($dtExpirationDate); $dtNow->add($countdown); $this->assertEqual($dtNow, $dtExpirationDate); } catch (Exception $e) { $this->fail("Rejected duration construction"); } }
/** * 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; }
/** * prepare an object with values of all controls * @param object $object the object to fill * @param array $properties array of 'propertyname'=>array('required'=>true/false, * 'defaultValue'=>$value, 'datatype'=>$datatype) * values of datatype = same as dao datatypes = ex: 'string', 'int','integer','double','float','boolean','datetime','date' */ public function prepareObjectFromControls($object, $properties = null) { if ($properties == null) { $properties = get_object_vars($object); foreach ($properties as $n => $v) { if (!is_null($v)) { $r = true; $t = gettype($v); } else { $t = 'string'; $r = false; } $properties[$n] = array('required' => $r, 'defaultValue' => $v, 'datatype' => $t); } } foreach ($this->controls as $name => $ctrl) { if (!isset($properties[$name])) { continue; } if (is_array($this->container->data[$name])) { if (count($this->container->data[$name]) == 1) { $object->{$name} = $this->container->data[$name][0]; } else { // do nothing for arrays ? continue; } } else { $object->{$name} = $this->container->data[$name]; } if ($object->{$name} == '' && !$properties[$name]['required']) { // if no value and if the property is not required, we set null to it $object->{$name} = null; } else { if ($object->{$name} == '' && $properties[$name]['defaultValue'] !== null && in_array($properties[$name]['datatype'], array('int', 'integer', 'double', 'float'))) { $object->{$name} = $properties[$name]['defaultValue']; } else { if ($properties[$name]['datatype'] == 'boolean' && !is_bool($object->{$name})) { $object->{$name} = $object->{$name} == '1' || $object->{$name} == 'true' || $object->{$name} == 't'; } else { if ($ctrl->datatype instanceof jDatatypeLocaleDateTime && $properties[$name]['datatype'] == 'datetime') { $dt = new jDateTime(); $dt->setFromString($object->{$name}, jDateTime::LANG_DTFORMAT); $object->{$name} = $dt->toString(jDateTime::DB_DTFORMAT); } elseif ($ctrl->datatype instanceof jDatatypeLocaleDate && $properties[$name]['datatype'] == 'date') { $dt = new jDateTime(); $dt->setFromString($object->{$name}, jDateTime::LANG_DFORMAT); $object->{$name} = $dt->toString(jDateTime::DB_DFORMAT); } } } } } }
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; }
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); }
public function prepareObjectFromControls($object, $properties = null) { if ($properties == null) { $properties = get_object_vars($object); foreach ($properties as $n => $v) { if (!is_null($v)) { $r = true; $t = gettype($v); } else { $t = 'varchar'; $r = false; } $properties[$n] = array('required' => $r, 'defaultValue' => $v, 'unifiedType' => $t); } } foreach ($this->controls as $name => $ctrl) { if (!isset($properties[$name])) { continue; } if (is_array($this->container->data[$name])) { if (count($this->container->data[$name]) == 1) { $object->{$name} = $this->container->data[$name][0]; } else { continue; } } else { $object->{$name} = $this->container->data[$name]; } if ($object->{$name} == '' && !$properties[$name]['required']) { $object->{$name} = null; } else { if (isset($properties[$name]['unifiedType'])) { $type = $properties[$name]['unifiedType']; } else { $type = $properties[$name]['datatype']; } if ($object->{$name} == '' && $properties[$name]['defaultValue'] !== null && in_array($type, array('int', 'integer', 'double', 'float', 'numeric', 'decimal'))) { $object->{$name} = $properties[$name]['defaultValue']; } else { if ($type == 'boolean' && !is_bool($object->{$name})) { $object->{$name} = intval($object->{$name}) == 1 || strtolower($object->{$name}) === 'true' || $object->{$name} === 't' || $object->{$name} === 'on'; } else { if ($ctrl->datatype instanceof jDatatypeLocaleDateTime && $type == 'datetime') { $dt = new jDateTime(); $dt->setFromString($object->{$name}, jDateTime::LANG_DTFORMAT); $object->{$name} = $dt->toString(jDateTime::DB_DTFORMAT); } elseif ($ctrl->datatype instanceof jDatatypeLocaleDate && $type == 'date') { $dt = new jDateTime(); $dt->setFromString($object->{$name}, jDateTime::LANG_DFORMAT); $object->{$name} = $dt->toString(jDateTime::DB_DFORMAT); } } } } } }