00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00007 lt_include( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
00008 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00009 lt_include( PLOG_CLASS_PATH."class/data/validator/usernamevalidator.class.php" );
00010 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00011 lt_include( PLOG_CLASS_PATH."class/data/validator/emailvalidator.class.php" );
00012 lt_include( PLOG_CLASS_PATH."class/data/validator/httpurlvalidator.class.php" );
00013 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00014 lt_include( PLOG_CLASS_PATH."class/data/filter/htmlfilter.class.php" );
00015 lt_include( PLOG_CLASS_PATH."class/data/filter/javascriptfilter.class.php" );
00016 lt_include( PLOG_CLASS_PATH."class/data/filter/urlconverter.class.php" );
00017 lt_include( PLOG_CLASS_PATH."class/data/filter/allowedhtmlfilter.class.php" );
00018 lt_include( PLOG_CLASS_PATH."class/data/filter/xhtmlizefilter.class.php" );
00019 lt_include( PLOG_CLASS_PATH."class/view/errorview.class.php" );
00020 lt_include( PLOG_CLASS_PATH."class/view/redirectview.class.php" );
00021 lt_include( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
00022 lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
00023
00030 class AddCommentAction extends BlogAction
00031 {
00032
00033 var $_articleId;
00034 var $_blogId;
00035 var $_userName;
00036 var $_userEmail;
00037 var $_userUrl;
00038 var $_commentText;
00039 var $_commentTopic;
00040 var $_parentId;
00041
00045 function AddCommentAction( $blogInfo, $request )
00046 {
00047 $this->BlogAction( $blogInfo, $request );
00048
00049
00050 $f = new HtmlFilter();
00051 $this->_request->registerFilter( "userEmail", $f );
00052 $this->_request->registerFilter( "userName", $f );
00053 $this->_request->registerFilter( "commentTopic", $f );
00054
00055
00056
00057 $f = new HtmlFilter();
00058 $f->addFilter( new UrlConverter());
00059 $this->_request->registerFilter( "userUrl", $f );
00060
00061 $f = new AllowedHtmlFilter();
00062 $f->addFilter( new JavascriptFilter());
00063 $f->addFilter( new XhtmlizeFilter());
00064 $this->_request->registerFilter( "commentText", $f );
00065
00066
00067 $this->registerFieldValidator( "articleId", new IntegerValidator());
00068 $this->_form->setFieldErrorMessage( "articleId", $this->_locale->tr("error_incorrect_article_id" ));
00069 $this->registerFieldValidator( "blogId", new IntegerValidator());
00070 $this->_form->setFieldErrorMessage( "blogId", $this->_locale->tr("error_incorrect_blog_id" ));
00071 $this->registerFieldValidator( "parentId", new IntegerValidator(), true );
00072 $this->_form->setFieldErrorMessage( "parentId", $this->_locale->tr("error_incorrect_article_id" ));
00073 $this->registerFieldValidator( "userEmail", new EmailValidator(), true );
00074 $this->_form->setFieldErrorMessage( "userEmail", $this->_locale->tr("error_incorrect_email_address" ));
00075 $this->registerFieldValidator( "userName", new StringValidator());
00076 $this->_form->setFieldErrorMessage( "userName", $this->_locale->tr("error_comment_without_name" ));
00077 $this->registerFieldValidator( "commentText", new StringValidator( true ));
00078 $this->_form->setFieldErrorMessage( "commentText", $this->_locale->tr("error_comment_without_text"));
00079 $this->registerFieldValidator( "userUrl", new HttpUrlValidator(), true );
00080 $this->_form->setFieldErrorMessage( "userUrl", $this->_locale->tr("invalid_url" ));
00081 $view = new ErrorView( $this->_blogInfo );
00082 $view->setErrorMessage( "There has been an error validating the data!" );
00083 $this->setValidationErrorView( $view );
00084
00085 $this->_fetchFields();
00086 }
00087
00088 function _fetchFields()
00089 {
00090 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00091
00092 $f = new HtmlFilter( true );
00093
00094 $this->_articleId = $this->_request->getValue( "articleId" );
00095 $this->_blogId = $this->_request->getValue( "blogId" );
00096 $this->_parentId = $this->_request->getValue( "parentId" );
00097 if( $this->_parentId == null || $this->_parentId == "" )
00098 $this->_parentId = 0;
00099 $this->_userEmail = $this->_request->getValue( "userEmail" );
00100 $this->_userUrl = $this->_request->getValue( "userUrl" );
00101 $this->_userName = $this->_request->getValue( "userName" );
00102 $this->_commentText = trim($this->_request->getValue( "commentText" ));
00103 $this->_commentTopic = $this->_request->getValue( "commentTopic" );
00104
00105
00106 if( $this->_config->getValue( "beautify_comments_text" )) {
00107 $tf = new TextFilter();
00108 $this->_commentText = $tf->autop($this->_commentText);
00109 }
00110 }
00111
00118 function validate()
00119 {
00120
00121 $blogSettings = $this->_blogInfo->getSettings();
00122 if( !$blogSettings->getValue( "comments_enabled" )) {
00123 $this->_view = new ErrorView( $this->_blogInfo, "error_comments_not_enabled" );
00124 $this->setCommonData();
00125
00126 return false;
00127 }
00128
00129 return( parent::validate());
00130 }
00131
00138 function validationErrorProcessing()
00139 {
00140 $this->_view = new ErrorView( $this->_blogInfo);
00141
00142
00143
00144 $results = $this->_form->getFormValidationResults();
00145 $errorMessage = "";
00146 foreach( $results as $field => $result ) {
00147 if( !$result ) {
00148 $errorMessage .= $this->_form->getFieldErrorMessage( $field )."<br/><br/>";
00149 }
00150 }
00151
00152 $this->_view->setErrorMessage( $errorMessage );
00153 $this->setCommonData();
00154
00155 return true;
00156 }
00157
00161 function perform()
00162 {
00163 lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
00164 lt_include( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
00165 lt_include( PLOG_CLASS_PATH."class/net/client.class.php" );
00166
00167
00168 $clientIp = Client::getIp();
00169
00170
00171
00172 $articles = new Articles();
00173 $article = $articles->getBlogArticle( $this->_articleId, $this->_blogInfo->getId());
00174 if(!$article) {
00175 $this->_view = new ErrorView( $this->_blogInfo );
00176 $this->_view->setValue( "message", $this->_locale->tr("error_incorrect_article_id"));
00177 $this->setCommonData();
00178 return false;
00179 }
00180
00181 $this->notifyEvent( EVENT_POST_LOADED, Array( "article" => &$article ));
00182
00183
00184
00185 if( $article->getCommentsEnabled() == false ) {
00186 $this->_view = new ErrorView( $this->_blogInfo );
00187 $this->_view->setValue( "message", "Comments have been disabled for this article." );
00188 $this->setCommonData();
00189 return false;
00190 }
00191
00192
00193 $comments = new ArticleComments();
00194
00195 $comment = new UserComment( $this->_articleId,
00196 $this->_blogInfo->getId(),
00197 $this->_parentId,
00198 $this->_commentTopic,
00199 $this->_commentText,
00200 null,
00201 $this->_userName,
00202 $this->_userEmail,
00203 $this->_userUrl,
00204 $clientIp );
00205
00206
00207 if( $this->_userInfo ) {
00208
00209 $comment->setUser( $this->_userInfo );
00210 } else {
00211 $comment->setUserId( 0 );
00212 }
00213
00214
00215
00216
00217 if( $comments->getIdentical( $comment )){
00218 $this->_view = new ErrorView( $this->_blogInfo );
00219 $this->_view->setValue( "message", "error_adding_comment" );
00220 $this->setCommonData();
00221 return false;
00222 }
00223
00224
00225 $this->notifyEvent( EVENT_PRE_COMMENT_ADD, Array( "comment" => &$comment ));
00226
00227 if( !$comments->addComment( $comment )) {
00228
00229 $this->_view = new ErrorView( $this->_blogInfo );
00230 $this->_view->setValue( "message", "error_adding_comment" );
00231 $this->setCommonData();
00232 return false;
00233 }
00234
00235
00236
00237 $notifier = new ArticleNotifications();
00238 $notifier->notifyUsers( $article->getId(), $this->_blogInfo);
00239
00240
00241 $this->notifyEvent( EVENT_POST_COMMENT_ADD, Array( "comment" => &$comment ));
00242
00243
00244
00245
00246
00247
00248
00249 CacheControl::resetBlogCache( $this->_blogInfo->getId());
00250
00251
00252
00253
00254
00255 $request = HttpVars::getRequest();
00256 $request["commentUserName"] = $this->_userName;
00257 $request["userName"] = "";
00258 HttpVars::setRequest( $request );
00259
00260
00261 $rg = $this->_blogInfo->getBlogRequestGenerator();
00262 $rg->setXHTML( false );
00263 $postPermalink = $rg->postPermalink( $article );
00264
00265
00266 $this->_view = new RedirectView( $postPermalink );
00267
00268 return( true );
00269 }
00270 }
00271 ?>