Exemple #1
0
 /**
  * Process trackback when saving blog post
  * - check if there un-ping URLs
  * - mark as sent if necessary
  *
  * @param	Integer		Blog ID
  * @param	Array		Trackbacks from user input
  * @param	Object		User object
  */
 public static function processTrackbacks($blogId, $trackbacks, $user)
 {
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'trackback.php';
     require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'router.php';
     $trackbackTbl = EasyBlogHelper::getTable('TrackbackSent', 'Table');
     $author = EasyBlogHelper::getTable('Profile', 'Table');
     $author->setUser($user);
     for ($x = 0; $x < count($trackbacks); $x++) {
         // check if the URL has been added to our record
         $exists = $trackbackTbl->load($trackbacks[$x], true, $blogId);
         // if not exists, we need to store them
         if (!$exists) {
             $trackbackTbl->post_id = $blog->id;
             $trackbackTbl->url = $url;
             $trackbackTbl->sent = 0;
             $trackbackTbl->store();
         }
     }
     // now load trackback model
     $trackbackModel = self::getModel('TrackbackSent');
     // get lists of trackback URLs based on blog ID
     $tbacks = $trackbackModel->getSentTrackbacks($blogId, true);
     // loop each URL, ping if necessary
     for ($x = 0; $x < count($tbacks); $x++) {
         $tb = new EasyBlogTrackBack($author->getName(), $author->getName(), 'UTF-8');
         $text = empty($blog->intro) ? $blog->content : $blog->intro;
         if ($tb->ping($tbacks->url, EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true), $blog->title, $text)) {
             //@task: Since the trackback was successful, store the trackback into the table.
             $trackbackTbl->load($tbacks->id);
             $new_trackbacks = array();
             $new_trackbacks['url'] = $tback->url;
             $new_trackbacks['post_id'] = $tback->post_id;
             $new_trackbacks['sent'] = 1;
             $trackbackTbl->bind($new_trackbacks);
             $trackbackTbl->store();
         }
     }
 }
Exemple #2
0
 public static function addTrackback($trackback, $blogObj, $my)
 {
     // JTable::addIncludePath( JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'tables' );
     // JModel::addIncludePath( JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'models' );
     require_once JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'trackback.php';
     $author = EasyBlogHelper::getTable('Profile', 'Table');
     $author->setUser($my);
     if (!empty($trackback) && is_string($trackback)) {
         $trackbacks = explode(' ', $trackback);
         for ($x = 0; $x < count($trackbacks); $x++) {
             $tbl = EasyBlogHelper::getTable('TrackbackSent', 'Table');
             // check if the URL has been added to our record
             $exists = $tbl->load($trackbacks[$x], true, $blogObj->id);
             // if not exists, we need to store them
             if (!$exists) {
                 $tbl = EasyBlogHelper::getTable('TrackbackSent', 'Table');
                 $tbl->post_id = $blogObj->id;
                 $tbl->url = $trackbacks[$x];
                 $tbl->sent = 0;
                 $tbl->store();
             }
         }
     }
     // only process this part when publish blog
     if ($blogObj->published == '1') {
         // now load trackback model
         jimport('joomla.application.component.model');
         $trackbackModel = EasyBlogHelper::getModel('TrackbackSent');
         // get lists of trackback URLs based on blog ID
         $tbacks = $trackbackModel->getSentTrackbacks($blogObj->id, true);
         if (count($tbacks) > 0) {
             // loop each URL, ping if necessary
             foreach ($tbacks as $tback) {
                 $tb = new EasyBlogTrackBack($author->getName(), $author->getName(), 'UTF-8');
                 $text = empty($blogObj->intro) ? $blogObj->content : $blogObj->intro;
                 if (@$tb->ping($tback->url, EasyBlogRouter::getEntryRoute($blogObj->id), $blogObj->title, $text)) {
                     $tbl = EasyBlogHelper::getTable('TrackbackSent', 'Table');
                     $tbl->load($tback->id);
                     $new_trackbacks = array();
                     $new_trackbacks['url'] = $tback->url;
                     $new_trackbacks['post_id'] = $tback->post_id;
                     $new_trackbacks['sent'] = 1;
                     $tbl->bind($new_trackbacks);
                     $tbl->store();
                 }
             }
             //enf foreach
         }
         //end if
     }
 }
Exemple #3
0
 public function processTrackbacks()
 {
     JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT);
     if (!class_exists('EasyBlogModelTrackbackSent')) {
         JLoader::import('trackbacksent', EBLOG_ROOT . DIRECTORY_SEPARATOR . 'models');
     }
     $model = JModel::getInstance('TrackbackSent', 'EasyBlogModel');
     // get lists of trackback URLs based on blog ID
     $trackbacks = $model->getSentTrackbacks($this->id, true);
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'trackback.php';
     require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'router.php';
     if (!$trackbacks) {
         return false;
     }
     foreach ($trackbacks as $trackback) {
         $author = EasyBlogHelper::getTable('Profile');
         $author->load($this->created_by);
         $tb = new EasyBlogTrackBack($author->getName(), $author->getName(), 'UTF-8');
         $text = empty($this->intro) ? $this->content : $this->intro;
         $url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $this->id, false, true);
         if ($tb->ping($trackback->url, $url, $this->title, $text)) {
             $table = EasyBlogHelper::getTable('TrackbackSent');
             $table->load($trackback->id);
             $table->markSent();
         }
     }
     return true;
 }