lifetype-1.1.6/class/action/addtrackbackaction.class.php
Go to the documentation of this file.00001 <?php
00002
00003 include_once( PLOG_CLASS_PATH."class/action/action.class.php" );
00004 include_once( PLOG_CLASS_PATH."class/view/trackbackview.class.php" );
00005 include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
00006 include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/net/http/httpvars.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00011 include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
00012 include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
00013 include_once( PLOG_CLASS_PATH."class/net/client.class.php" );
00014 include_once( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" );
00015 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00016 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00017 include_once( PLOG_CLASS_PATH."class/security/pipeline.class.php" );
00018
00025 class AddTrackbackAction extends Action
00026 {
00027
00028 function AddTrackbackAction( $actionInfo, $request )
00029 {
00030 $this->Action( $actionInfo, $request );
00031
00032
00033 $this->registerFieldValidator( "id", new IntegerValidator());
00034 $this->registerFieldValidator( "url", new StringValidator());
00035 $this->setValidationErrorView( new TrackbackView( "Error incorrect parameters",
00036 true ));
00037 }
00038
00043 function tblog( $message )
00044 {
00045 include_once( PLOG_CLASS_PATH . "class/logger/loggermanager.class.php" );
00046
00047 $logger =& LoggerManager::getLogger( "trackback" );
00048 $logger->debug( $message );
00049 }
00050
00051 function perform()
00052 {
00053
00054 $config =& Config::getConfig();
00055 if( !$config->getValue( "trackback_server_enabled", false )) {
00056 $this->tblog( "ERROR: Trackbacks are not enabled in this site" );
00057 $this->_view = new TrackbackView( "Trackbacks are not enabled in this site", true );
00058 return( false );
00059 }
00060
00061
00062 $tf = new TextFilter();
00063 $blogName = $tf->filterAllHTML( $this->_request->getValue( "blog_name" ));
00064 $excerpt = $tf->filterAllHTML( $this->_request->getValue( "excerpt" ));
00065 $title = $tf->filterAllHTML( $this->_request->getValue( "title" ));
00066 $articleId = $this->_request->getValue( "id" );
00067 $url = $tf->filterAllHTML( $this->_request->getValue( "url" ));
00068
00069 $this->tblog( "** Incoming request **" );
00070 $this->tblog( "Blog name = ".$blogName );
00071 $this->tblog( "Excerpt = ".$excerpt );
00072 $this->tblog( "Title = ".$title );
00073 $this->tblog( "Article ID = ".$articleId );
00074 $this->tblog( "url = ".$url );
00075
00076
00077 $articles = new Articles();
00078 $article = $articles->getBlogArticle( $articleId );
00079 if( !$article ) {
00080 $this->tblog( "ERROR: Incorrect error identifier" );
00081 $this->_view = new TrackbackView( "Incorrect article identifier", true );
00082 return( false );
00083 }
00084
00085
00086 $blogs = new Blogs();
00087 $blogInfo = $blogs->getBlogInfo( $article->getBlog());
00088
00089
00090 if( !$blogInfo ) {
00091 $this->tblog( "ERROR: Article id ".$article->getId()." points to blog ".$article->getBlog()." that doesn't exist!" );
00092 $this->_view = new TrackbackView( "The blog does not exist", true );
00093 return( false );
00094 }
00095
00096
00097 if( $blogInfo->getStatus() != BLOG_STATUS_ACTIVE ) {
00098 $this->tblog( "ERROR: The blog ".$blogInfo->getBlog()." is set as disabled and cannot receive trackbacks!" );
00099 $this->_view = new TrackbackView( "The blog is not active", true );
00100 return( false );
00101 }
00102
00103
00104 $pm =& PluginManager::getPluginManager();
00105 $pm->loadPlugins();
00106
00107
00108 $pm->setBlogInfo( $blogInfo );
00109 $userInfo = $blogInfo->getOwnerInfo();
00110 $pm->setUserInfo( $userInfo );
00111
00112
00113
00114 $pipeline = new Pipeline( $this->_request, $blogInfo );
00115 $result = $pipeline->process();
00116
00117 if( !$result->isValid()) {
00118
00119 $this->tblog( "The trackback was blocked by a filter" );
00120 $this->_view = new TrackbackView( $result->getErrorMessage(), true );
00121 print($this->_view->render());
00122 die();
00123 }
00124
00125
00126 $trackbacks = new TrackBacks();
00127
00128 $now = new Timestamp();
00129 $ip = Client::getIp();
00130 $trackback = new Trackback( $url,
00131 $title,
00132 $articleId,
00133 $blogInfo->getId(),
00134 $excerpt,
00135 $blogName,
00136 $now->getTimestamp(),
00137 $ip );
00138
00139
00140
00141
00142
00143
00144
00145 if( !$trackbacks->getIdenticalTrackback( $trackback )) {
00146
00147 $pm->notifyEvent( EVENT_PRE_TRACKBACK_ADD, Array( "trackback" => &$trackback ));
00148 $result = $trackbacks->addTrackBack( $trackback );
00149 if( !$result ) {
00150 $this->tblog( "There was an error saving the trackback!" );
00151 }
00152 }
00153
00154
00155 $pm->notifyEvent( EVENT_POST_TRACKBACK_ADD, Array( "trackback" => &$trackback ));
00156
00157
00158
00159 $this->_view = new TrackbackView( "", false );
00160
00161
00162
00163
00164 if( $trackbacks->getTrackBack( $trackback->getId() ) ) {
00165 $notifier = new ArticleNotifications();
00166 $notifier->notifyUsers( $article->getId(), $blogInfo);
00167 }
00168
00169 CacheControl::resetBlogCache( $article->getBlog());
00170
00171 $this->tblog( "** End **" );
00172 }
00173 }
00174 ?>