/** * 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; }
/** * 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; }