/**
  * @private
  * Caculate the correct article date period
  */
 function _getArticleCorrectedDatePeriod()
 {
     $blogSettings = $this->_blogInfo->getSettings();
     $serverTimeOffset = $blogSettings->getValue("time_offset");
     if ($serverTimeOffset == 0) {
         $this->_maxDate = -1;
     } else {
         if (strlen($this->_date) == 4) {
             $year = $this->_date;
             $this->_date = Timestamp::getDateWithOffset($year . "0101000000", -$serverTimeOffset);
             $this->_maxDate = Timestamp::getDateWithOffset($year . "1231235959", -$serverTimeOffset);
         } elseif (strlen($this->_date) == 6) {
             $year = substr($this->_date, 0, 4);
             $month = substr($this->_date, 4, 2);
             $dayOfMonth = Date_Calc::daysInMonth($month, $year);
             $this->_date = Timestamp::getDateWithOffset($year . $month . "01000000", -$serverTimeOffset);
             $this->_maxDate = Timestamp::getDateWithOffset($year . $month . $dayOfMonth . "235959", -$serverTimeOffset);
         } elseif (strlen($this->_date) == 8) {
             $year = substr($this->_date, 0, 4);
             $month = substr($this->_date, 4, 2);
             $day = substr($this->_date, 6, 2);
             $this->_date = Timestamp::getDateWithOffset($year . $month . $day . "000000", -$serverTimeOffset);
             $this->_maxDate = Timestamp::getDateWithOffset($year . $month . $day . "235959", -$serverTimeOffset);
         } else {
             $this->_maxDate = -1;
         }
     }
 }
 /**
  * @private
  */
 function _fillArticleHeaderInformation($query_result, $includeHiddenFields = true)
 {
     $id = $query_result['id'];
     if (isset($this->cache[$id])) {
         return $this->cache[$id];
     }
     // this is a little dirty trick or otherwise the old
     // that don't have the 'properties' field will not work
     // as they will appear to have comments disabled
     if ($query_result['properties'] == "") {
         $tmpArray = array('comments_enabled' => true);
         $query_result['properties'] = serialize($tmpArray);
     }
     // ---
     // this, i do not like... but I couldn't find a more
     // "elegant" way to arrange it! This makes this method
     // totally dependant on the blog configuration so it basically
     // means an additional query every time we fetch an article
     // (just in case we didn't have enough!)
     // ---
     //
     // if there's a time difference applied to all dates, then we'd better
     // calculate it here!!
     //
     if ($this->_blogInfo == null) {
         $blogId = $query_result['blog_id'];
         $this->_blogInfo = $this->blogs->getBlogInfo($blogId);
         $this->_blogSettings = $this->_blogInfo->getSettings();
         $this->_timeDiff = $this->_blogSettings->getValue('time_offset');
     }
     // we can use this auxiliary function to help us...
     $date = Timestamp::getDateWithOffset($query_result['date'], $this->_timeDiff);
     // postText does not exist here.. maybe a copy/paste problem?
     // anyway.. it works without postText, so i'll just set this to
     // null. oscar, pls double check.. original code:
     // $article = new Article( $postText['topic'],
     //                         $postText['text'],
     //                         NULL,
     $article = new Article(NULL, NULL, NULL, $query_result['user_id'], $query_result['blog_id'], $query_result['status'], $query_result['num_reads'], unserialize($query_result['properties']), $query_result['slug'], $query_result['id']);
     // and fill in all the fields with the information we just got from the db
     $article->setDate($date);
     $article->setTimeOffset($this->_timeDiff);
     $article->setBlogInfo($this->_blogInfo);
     $article->setUserInfo($this->users->getUserInfoFromId($query_result['user_id']));
     return $article;
 }
 /**
  * code factored out and made to be reused through several functions here...
  */
 function _fillCommentInformation($row)
 {
     // ---
     // this stuff is another disgusting hack to make comments
     // be aware of time differences that may have been set by
     // users in their blogs... actually, it will make the whole
     // thing run a little bit slower because for every article
     // that we fetch, we need to know the time difference
     // and that means, additional accesses to the database :(
     // But hey, users demand these things and we are not in the position
     // to deny anything, are we? :P
     // ---
     // at the same time, we're going to brake some of our "nicely"
     // implemented bussiness logic with the query below, bypassing all
     // our objects and directly fetching info from the database, just for
     // the sake of being able to do things with a single query rather
     // than needing at least two to do the same. We would have to first
     // find to which blog the given article belongs and then use another
     // query to find its settings... If we do it this way, we can still
     // do it in one query and get a nice BlogSettings object with the
     // information that we need. Dirty but works :S
     // ---
     $prefix = $this->getPrefix();
     $date = $row["date"];
     $articleId = $row["article_id"];
     // let's try and keep some kind of cache for this...
     if (empty($this->_blogSettings[$articleId])) {
         $query = "SELECT DISTINCT b.settings AS settings\n                          FROM {$prefix}blogs b, {$prefix}articles a,\n                          {$prefix}articles_comments c\n                          WHERE c.article_id = a.id AND\n                          a.blog_id = b.id\n                          AND a.id = {$articleId}";
         $result = $this->Execute($query);
         if (!$result) {
             return false;
         }
         $tmpRow = $result->FetchRow();
         $blogSettings = Blogs::getBlogSettingsFromField($tmpRow["settings"]);
         $this->_blogSettings[$articleId] = $blogSettings;
         $result->Close();
     } else {
         $blogSettings = $this->_blogSettings[$articleId];
     }
     $timeDiff = $blogSettings->getValue("time_offset");
     // now that we've got the time difference, we can
     // calculate what would the "real" date...
     $date = Timestamp::getDateWithOffset($date, $timeDiff);
     $spam_rate = 0;
     if (array_key_exists("spam_rate", $row)) {
         $spam_rate = $row["spam_rate"];
     }
     $comment = new UserComment($row["article_id"], $row["parent_id"], $row["topic"], $row["text"], $date, $row["user_name"], $row["user_email"], $row["user_url"], $row["client_ip"], $spam_rate, $row["status"], $row["id"]);
     return $comment;
 }
 /**
  * @static
  * returns a Timestamp object with the blog time difference already
  * applied, if needed
  *
  * @param blog either a blog id or a BlogInfo object
  * @param timestamp 
  * @return A Timestamp object with time difference applied, if needed
  * @see BlogInfo
  */
 function getBlogDate($blog, $timestamp = null)
 {
     // check whether time differences are dynamically or statically
     // applied, because in case of the former, we don't have to do
     // anything here!
     $config =& Config::getConfig();
     if ($config->getValue("time_difference_calculation") == TIME_DIFFERENCE_CALCULATION_DYNAMIC) {
         return new Timestamp($timestamp);
     }
     //
     // how's this for function overloading??
     // I know it's quite hackish, but it's a bit of a pain that
     // we need to define two different functions depending on whether
     // we're getting an object or an integer!
     //
     if (is_object($blog)) {
         $blogSettings = $blog->getSettings();
         $timeDifference = $blogSettings->getValue("time_offset");
     } else {
         include_once PLOG_CLASS_PATH . "class/dao/blogs.class.php";
         $blogs = new Blogs();
         $blogInfo = $blogs->getBlogInfoById($blog);
         if (!$blogInfo) {
             $timeDifference = 0;
         } else {
             $blogSettings = $blogInfo->getSettings();
             $timeDifference = $blogSettings->getValue("time_offset");
         }
     }
     // generate the date with the correct time difference applied
     $t = new Timestamp();
     $t->setDate(Timestamp::getDateWithOffset($t->getDate(), $timeDifference), DATE_FORMAT_TIMESTAMP);
     return $t;
 }
 /**
  * function factored out from the above
  *
  * @private
  * @param row The row with the information
  */
 function _fillTrackbackInformation($row)
 {
     // ---
     // there we go again doing dirty things to the poor trackbacks...
     // ---
     $prefix = $this->getPrefix();
     $date = $row["date"];
     $articleId = $row["article_id"];
     // let's try and keep some kind of cache for this...
     if (empty($this->_blogSettings[$articleId])) {
         $query = "SELECT DISTINCT b.settings AS settings\n                          FROM {$prefix}blogs b, {$prefix}articles a,\n                          {$prefix}trackbacks t\n                          WHERE t.article_id = a.id AND\n                          a.blog_id = b.id\n                          AND a.id = {$articleId}";
         $result = $this->Execute($query);
         $tmpRow = $result->FetchRow();
         $blogSettings = Blogs::getBlogSettingsFromField($tmpRow["settings"]);
         $this->_blogSettings[$articleId] = $blogSettings;
     } else {
         $blogSettings = $this->_blogSettings[$articleId];
     }
     $timeDiff = $blogSettings->getValue("time_offset");
     // now that we've got the time difference, we can
     // calculate what would the "real" date...
     $date = Timestamp::getDateWithOffset($date, $timeDiff);
     $trackback = new TrackBack($row["url"], $row["title"], $row["article_id"], $row["excerpt"], $row["blog_name"], $date, $row["id"]);
     return $trackback;
 }