/**
  * 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] : '';
         }
     }
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 5
0
/**
 * 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;
 }
Exemplo n.º 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);
 }
Exemplo n.º 8
0
 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);
 }
/**
 * 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;
}
Exemplo n.º 11
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;
         }
     }
 }
Exemplo n.º 12
0
 function testtoString()
 {
     // Time when my guests arrive.
     $dt = new jDateTime(2007, 12, 25, 20, 30, 19);
     $this->assertEqual($dt->toString(jDateTime::DB_DFORMAT), "2007-12-25");
     $this->assertEqual($dt->toString(jDateTime::DB_DTFORMAT), "2007-12-25 20:30:19");
     $this->assertEqual($dt->toString(jDateTime::DB_TFORMAT), "20:30:19");
     $this->assertEqual($dt->toString(jDateTime::ISO8601_FORMAT), "2007-12-25T20:30:19Z");
     $this->assertEqual($dt->toString(jDateTime::TIMESTAMP_FORMAT), "1198611019");
     $this->assertEqual($dt->toString(jDateTime::RFC822_FORMAT), "Tue, 25 Dec 2007 20:30:19 +0100");
 }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
0
 /**
  *
  */
 function save()
 {
     $rep = $this->getResponse('json');
     $receiver_id = $this->intParam('receiver_id', 0, true);
     $content = $this->param('content', '', true);
     //insert
     if (!empty($content) && !empty($receiver_id)) {
         $this->msg = 'Message non envoyé';
         // instanciation de la factory
         $tb = jDao::get("message");
         // creation d'un record correspondant au dao foo
         $record = jDao::createRecord("message");
         // on remplit le record
         $record->receiver_id = $receiver_id;
         $record->sender_id = jAuth::getUserSession()->id;
         $record->content = $content;
         $dt = new jDateTime();
         $dt->now();
         $record->createdate = $dt->toString(jDateTime::DB_DTFORMAT);
         // on le sauvegarde dans la base
         try {
             $tb->insert($record);
             $this->success = true;
             $this->msg = "Message envoyé ";
         } catch (Exception $e) {
             $this->success = false;
             $this->msg = "Message non envoyé ";
         }
     }
     $rep->data = array('success' => $this->success, 'msg' => $this->msg);
     return $rep;
 }