/**
  * Returns the recent trackbacks object of current blog
  */
 function getRecentTrackbacks($maxTrackbacks = 0, $based = 'BLOG')
 {
     $trackbacks = new Trackbacks();
     $blogId = $this->blogInfo->getId();
     if ($based == 'BLOG') {
         $query = "SELECT " . $this->prefix . "trackbacks.* FROM " . $this->prefix . "trackbacks, " . $this->prefix . "articles";
         $query .= " WHERE " . $this->prefix . "trackbacks.article_id = " . $this->prefix . "articles.id AND " . $this->prefix . "articles.blog_id = " . $blogId . " AND " . $this->prefix . "articles.status = 1";
         $query .= " ORDER BY " . $this->prefix . "trackbacks.date DESC";
     } elseif ($based == 'SITE') {
         $query = "SELECT " . $this->prefix . "trackbacks.* FROM " . $this->prefix . "trackbacks, " . $this->prefix . "articles";
         $query .= " WHERE " . $this->prefix . "trackbacks.article_id = " . $this->prefix . "articles.id AND " . $this->prefix . "articles.status = 1";
         $query .= " ORDER BY " . $this->prefix . "trackbacks.date DESC";
     } else {
         return false;
     }
     if ($maxTrackbacks > 0) {
         $query .= " LIMIT " . $maxTrackbacks;
     } else {
         $query .= " LIMIT " . $this->maxTrackbacks;
     }
     $result = $trackbacks->_db->Execute($query);
     if (!$result) {
         return false;
     }
     $recenttrackbacks = array();
     while ($row = $result->FetchRow()) {
         array_push($recenttrackbacks, $trackbacks->_fillTrackbackInformation($row));
     }
     return $recenttrackbacks;
 }
 /**
  * @private
  */
 function _deleteTrackbacks()
 {
     $trackbacks = new Trackbacks();
     $errorMessage = "";
     $successMessage = "";
     $totalOk = 0;
     // check if we can really load the article or not...
     $articles = new Articles();
     $article = $articles->getBlogArticle($this->_articleId, $this->_blogInfo->getId());
     if (!$article) {
         $this->_view = new AdminPostsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_post"));
         $this->setCommonData();
         return false;
     }
     foreach ($this->_trackbackIds as $trackbackId) {
         // fetch the trackback
         $trackback = $trackbacks->getArticleTrackback($trackbackId, $this->_articleId);
         if (!$trackback) {
             $errorMessage .= $this->_locale->pr("error_deleting_trackback2", $trackbackId) . "<br/>";
         } else {
             // fire the pre-event
             $this->notifyEvent(EVENT_PRE_TRACKBACK_DELETE, array("trackback" => &$trackback));
             if (!$trackbacks->deletePostTrackback($trackbackId, $this->_articleId)) {
                 $errorMessage .= $this->_locale->pr("error_deleting_trackback", $trackback->getExcerpt()) . "<br/>";
             } else {
                 $totalOk++;
                 if ($totalOk < 2) {
                     $successMessage .= $this->_locale->pr("trackback_deleted_ok", $trackback->getExcerpt());
                 } else {
                     $successMessage = $this->_locale->pr("trackbacks_deleted_ok", $totalOk);
                 }
                 // fire the post-event
                 $this->notifyEvent(EVENT_POST_TRACKBACK_DELETE, array("trackback" => &$trackback));
             }
         }
     }
     $this->_view = new AdminArticleTrackbacksListView($this->_blogInfo, array("article" => $article));
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
         // clear the cache
         CacheControl::resetBlogCache($this->_blogInfo->getId());
     }
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 /**
  * show the contents of the view
  */
 function render()
 {
     $trackbacks = new Trackbacks();
     // get the trackbacks
     $postTrackbacks = $trackbacks->getArticleTrackbacks($this->_article->getId(), $this->_page, DEFAULT_ITEMS_PER_PAGE);
     $this->notifyEvent(EVENT_TRACKBACKS_LOADED, array("trackbacks" => &$postTrackbacks));
     $this->setValue("trackbacks", $postTrackbacks);
     // and the total number of trackbacks
     $numTrackbacks = $trackbacks->getNumTrackbacksArticle($this->_article->getId());
     // create and export the pager to the view
     $pager = new Pager("?op=editTrackbacks&amp;articleId=" . $this->_article->getId() . "&amp;page=", $this->_page, $numTrackbacks, DEFAULT_ITEMS_PER_PAGE);
     $this->setValue("pager", $pager);
     // pass the common data to the templates
     $this->setValue("post", $this->_article);
     parent::render();
 }
 /**
  * normally views do not meddle with data but in this case moving all
  * this data fetching here is benefitial from a coding point of view, because it
  * allows this code to be reused by several action classes... In the worst case
  * we would have to copy+paste the code or put in a separate class only for this bit
  * of code. By moving it here, the view itself can handle everything
  */
 function _loadViewData()
 {
     // for each blog, load some statistics
     $articles = new Articles();
     $comments = new ArticleComments();
     $trackbacks = new Trackbacks();
     $resources = new GalleryResources();
     $recentPosts = array();
     $recentComments = array();
     $recentResources = array();
     // load some statistics	for each one of the blogs
     foreach ($this->_userBlogs as $userBlog) {
         $recentPosts[$userBlog->getId()] = $articles->getBlogArticles($userBlog->getId(), -1, DASHBOARD_MAX_RECENT_ITEMS, 0, POST_STATUS_PUBLISHED);
         $recentComments[$userBlog->getId()] = $comments->getBlogComments($userBlog->getId(), DASHBOARD_MAX_RECENT_ITEMS);
         $recentTrackbacks[$userBlog->getId()] = $trackbacks->getBlogTrackbacks($userBlog->getId(), DASHBOARD_MAX_RECENT_ITEMS);
     }
     $this->_params->setValue("userblogs", $this->_userBlogs);
     $this->_params->setValue("recentposts", $recentPosts);
     $this->_params->setValue("recentcomments", $recentComments);
     $this->_params->setValue("recenttrackbacks", $recentTrackbacks);
 }
Пример #5
0
 /**
  * Returns an array of Trackback objects, with all the trackbacks that have been received for
  * this article.
  *
  * @return An array of Trackback objects.
  * @see Trackback
  */
 function getTrackbacks()
 {
     if ($this->_trackbacks == null) {
         $trackbacks = new Trackbacks();
         $this->_trackbacks = $trackbacks->getArticleTrackbacks($this->getId());
     }
     return $this->_trackbacks;
 }
 function Validate($trackback)
 {
     // Get the page
     $url = TextFilter::htmlDecode($trackback->_url);
     $page = $this->fetchPage($url);
     // Get the trackback client
     $tbClient = new TrackbackClient();
     // get the trackback url
     $tbLinks = $tbClient->getTrackbackLinks($page, $url);
     if (empty($tbLinks)) {
         // there were no trackback links in the page
         //               error_log( "Found no trackback urls" );
         // Delete this trackback
         $trackbacks = new Trackbacks();
         $trackbacks->deletePostTrackback($trackback->_id, $trackback->_articleId);
         //print("Error: trackback unavailable<br/>");
     }
 }
 /**
  * Removes an article from the database
  *
  * If forever == true, the article is physically removed from the database.
  * Otherwise, the 'status' field is set to 'deleted'
  *
  * Problem is, that MySQL will automatically update the 'date' field because he feels
  * like it... even if we explicitely say date = old_date... grrreat :P
  *
  * Valid article identifier, blog identifier and user identifier are required to remove an
  * article. It was done for security reasons and to make perfectly clear that we are removing
  * an article (so that we wouldn't be deleting the wrong one if there was any bug!)
  *
  * @param artId A valid article identifier
  * @param userid A valid user identifier
  * @param blogId A valid blog identifier
  * @param forever A boolean meaning whether the post should be removed forever or simply its status
  * should be set to 'deleted'
  * @return Returns true if successful or false otherwise.
  */
 function deleteArticle($artId, $userId, $blogId, $forever = false)
 {
     if ($forever) {
         $query = "DELETE FROM " . $this->getPrefix() . "articles WHERE id = " . $artId . " AND user_id = " . $userId . " AND blog_id = " . $blogId . ";";
         // -- text --
         $this->deleteArticleText($artId);
         // we also have to remove its comments and trackbacks if the article is being deleted forever
         // -- comments --
         $comments = new ArticleComments();
         $comments->deletePostComments($artId);
         // -- trackbacks --
         $trackbacks = new Trackbacks();
         $trackbacks->deletePostTrackbacks($artId);
         // -- post-to-categories mappings --
         $this->deletePostCategoriesLink($artId);
         // -- custom fields --
         $customFields = new CustomFieldsValues();
         $customFields->removeArticleCustomFields($artId);
     } else {
         $query = "UPDATE " . $this->getPrefix() . "articles SET date = date, status = 3 WHERE id = " . $artId . " AND user_id = " . $userId . " AND blog_id = " . $blogId . ";";
     }
     $result = $this->Execute($query);
     if (!$result) {
         return false;
     }
     if ($this->_db->Affected_Rows() == 0) {
         return false;
     }
     return true;
 }