| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/action.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/view/trackbackview.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" ); 9 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 10 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" ); 11 lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" ); 12 lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" ); 13 lt_include( PLOG_CLASS_PATH."class/net/client.class.php" ); 14 lt_include( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" ); 15 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" ); 16 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 17 lt_include( PLOG_CLASS_PATH."class/security/pipeline.class.php" ); 18 19 /** 20 * Class that takes care of adding trackbacks 21 * 22 * \ingroup Action 23 * @private 24 */ 25 class AddTrackbackAction extends Action 26 { 27 28 function AddTrackbackAction( $actionInfo, $request ) 29 { 30 $this->Action( $actionInfo, $request ); 31 32 // we need certain data 33 $this->registerFieldValidator( "id", new IntegerValidator()); 34 $this->registerFieldValidator( "url", new StringValidator()); 35 $this->setValidationErrorView( new TrackbackView( "Error incorrect parameters", 36 true )); 37 } 38 39 /** 40 * @private 41 * @static 42 */ 43 function tblog( $message ) 44 { 45 lt_include( PLOG_CLASS_PATH . "class/logger/loggermanager.class.php" ); 46 47 $logger =& LoggerManager::getLogger( "trackback" ); 48 $logger->debug( $message ); 49 } 50 51 function perform() 52 { 53 // check if we should be receiving trackbacks at all 54 $config =& Config::getConfig(); 55 if( !$config->getValue( "trackback_server_enabled", false )) { 56 $this->tblog( "ERROR: Trackbacks are not enabled in this site" ); 57 $this->_view = new TrackbackView( "Trackbacks are not enabled in this site", true ); 58 return( false ); 59 } 60 61 // for security, we will strip _ANY_ html tag from the tags 62 $tf = new TextFilter(); 63 $blogName = $tf->filterAllHTML( $this->_request->getValue( "blog_name" )); 64 $excerpt = $tf->filterAllHTML( $this->_request->getValue( "excerpt" )); 65 $title = $tf->filterAllHTML( $this->_request->getValue( "title" )); 66 $articleId = $this->_request->getValue( "id" ); 67 $url = $tf->filterAllHTML( $this->_request->getValue( "url" )); 68 69 $this->tblog( "** Incoming request **" ); 70 $this->tblog( "Blog name = ".$blogName ); 71 $this->tblog( "Excerpt = ".$excerpt ); 72 $this->tblog( "Title = ".$title ); 73 $this->tblog( "Article ID = ".$articleId ); 74 $this->tblog( "url = ".$url ); 75 76 // try to see if the article is correct 77 $articles = new Articles(); 78 $article = $articles->getBlogArticle( $articleId ); 79 if( !$article ) { 80 $this->tblog( "ERROR: Incorrect error identifier" ); 81 $this->_view = new TrackbackView( "Incorrect article identifier", true ); 82 return( false ); 83 } 84 85 // try to load the blog info too, as we are going to need it 86 $blogs = new Blogs(); 87 $blogInfo = $blogs->getBlogInfo( $article->getBlog()); 88 89 // a bit of protection... 90 if( !$blogInfo ) { 91 $this->tblog( "ERROR: Article id ".$article->getId()." points to blog ".$article->getBlog()." that doesn't exist!" ); 92 $this->_view = new TrackbackView( "The blog does not exist", true ); 93 return( false ); 94 } 95 96 // if the blog is disabled, then we shoulnd't take trackbacks... 97 if( $blogInfo->getStatus() != BLOG_STATUS_ACTIVE ) { 98 $this->tblog( "ERROR: The blog ".$blogInfo->getBlog()." is set as disabled and cannot receive trackbacks!" ); 99 $this->_view = new TrackbackView( "The blog is not active", true ); 100 return( false ); 101 } 102 103 // if everything went fine, load the plugins so that we can throw some events... 104 $pm =& PluginManager::getPluginManager(); 105 $pm->loadPlugins(); 106 // and also configure the BlogInfo and UserInfo objects so that they know 107 // who threw the events... 108 $pm->setBlogInfo( $blogInfo ); 109 $userInfo = $blogInfo->getOwnerInfo(); 110 $pm->setUserInfo( $userInfo ); 111 112 // let's take a look at the security stuff, once we've made sure that the 113 // blog and the article are both valid 114 $pipeline = new Pipeline( $this->_request, $blogInfo ); 115 $result = $pipeline->process(); 116 // let the sender of the trackback know that something went wrong 117 if( !$result->isValid()) { 118 // use the default view 119 $this->tblog( "The trackback was blocked by a filter" ); 120 $this->_view = new TrackbackView( $result->getErrorMessage(), true ); 121 print($this->_view->render()); 122 die(); 123 } 124 125 // receives the request and adds it to the database 126 $trackbacks = new TrackBacks(); 127 // create teh trackback object 128 $now = new Timestamp(); 129 $ip = Client::getIp(); 130 $trackback = new Trackback( $url, 131 $title, 132 $articleId, 133 $blogInfo->getId(), 134 $excerpt, 135 $blogName, 136 $now->getTimestamp(), 137 $ip ); 138 139 // this code probably needs some explanation... 140 // Basically, if the bayesian filter is configured to save spam to the database marked as spam, 141 // we would end up with two identical trackbacks: one marked as spam and the other one not marked 142 // as spam. The first one would be created by the spam filter and the second one would be created 143 // by us here, so we need to know if the trackback is already there and if not, don't add it. 144 // This also works as an additional protection feature agains repeating trackback spammers. 145 if( !$trackbacks->getIdenticalTrackback( $trackback )) { 146 // throw the event in case somebody is listening to it! 147 $pm->notifyEvent( EVENT_PRE_TRACKBACK_ADD, Array( "trackback" => &$trackback )); 148 $result = $trackbacks->addTrackBack( $trackback ); 149 if( !$result ) { 150 $this->tblog( "There was an error saving the trackback!" ); 151 } 152 } 153 154 // throw the post event too... 155 $pm->notifyEvent( EVENT_POST_TRACKBACK_ADD, Array( "trackback" => &$trackback )); 156 157 // everything went fine so let's create a normal view, without a message 158 // (the message is not needed if there is no error) 159 $this->_view = new TrackbackView( "", false ); 160 161 // notify the user that a new trackback has been received, if the article was 162 // configured to receive notifications 163 // but first make sure, the trackback was not removed by some plugins like validatetrackback... 164 if( $trackbacks->getTrackBack( $trackback->getId() ) ) { 165 $notifier = new ArticleNotifications(); 166 $notifier->notifyUsers( $article->getId(), $blogInfo); 167 } 168 // clear the blog cache 169 CacheControl::resetBlogCache( $article->getBlog()); 170 171 $this->tblog( "** End **" ); 172 } 173 } 174 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
|