adminaddpostaction.class.php
查看本檔案說明文件.00001 <?php
00002
00003 include_once( PLOG_CLASS_PATH."class/action/admin/adminpostmanagementcommonaction.class.php" );
00004 include_once( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" );
00005 include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00006 include_once( PLOG_CLASS_PATH."class/locale/locale.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/data/stringutils.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
00009 include_once( PLOG_CLASS_PATH."class/view/admin/adminnewpostview.class.php" );
00010 include_once( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" );
00011 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00012 include_once( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" );
00013 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00014 include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00015 include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
00016
00023 class AdminAddPostAction extends AdminPostManagementCommonAction
00024 {
00029 function AdminAddPostAction( $actionInfo, $request )
00030 {
00031 $this->AdminPostManagementCommonAction( $actionInfo, $request );
00032
00033
00034 $this->registerFieldValidator( "postText", new StringValidator());
00035 $this->registerFieldValidator( "postTopic", new StringValidator());
00036 $this->registerFieldValidator( "postCategories", new ArrayValidator());
00037 $view = new AdminNewPostView( $this->_blogInfo );
00038 $view->setErrorMessage( $this->_locale->tr("error_adding_post"));
00039 $this->setValidationErrorView( $view );
00040
00041
00042 $this->registerField( "postExtendedText" );
00043 $this->registerField( "postSlug" );
00044 $this->registerField( "postStatus" );
00045 $this->registerField( "sendNotification" );
00046 $this->registerField( "sendTrackbacks" );
00047 $this->registerField( "sendPings" );
00048 $this->registerField( "postId" );
00049 $this->registerField( "commentsEnabled" );
00050 $this->registerField( "customField" );
00051 $this->registerField( "postDateTime" );
00052 $this->registerField( "trackbackUrls" );
00053 }
00054
00060 function _savePostData( $article )
00061 {
00062 $status = $this->_postStatus;
00063
00064 $articles = new Articles();
00065 $article->setFields( $this->_getArticleCustomFields());
00066
00067
00068 $this->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article ));
00069
00070
00071 if( $this->_postId != "" ) {
00072 $article->setId( $this->_postId );
00073 $artId = $this->_postId;
00074 $postSavedOk = $articles->updateArticle( $article );
00075
00076 if( $postSavedOk )
00077 $artId = $this->_postId;
00078 else
00079 $artId = false;
00080 }
00081 else {
00082 $artId = $articles->addArticle( $article );
00083 }
00084
00085 return $artId;
00086 }
00087
00091 function perform()
00092 {
00093 $this->_fetchCommonData();
00094
00095 $this->_postId = $this->_request->getValue( "postId" );
00096
00097 $this->_previewPost = $this->_request->getValue( "previewPost" );
00098 $this->_addPost = $this->_request->getValue( "addPost" );
00099 $this->_saveDraft = $this->_request->getValue( "isDraft" );
00100
00101
00102
00103 $postText = Textfilter::xhtmlize($this->_postText).POST_EXTENDED_TEXT_MODIFIER.Textfilter::xhtmlize($this->_postExtendedText);
00104
00105 $article = new Article( $this->_postTopic, $postText, $this->_postCategories,
00106 $this->_userInfo->getId(), $this->_blogInfo->getId(), $this->_postStatus, 0, Array(), $this->_postSlug );
00107
00108 $article->setDateObject( $this->_postTimestamp );
00109 $article->setCommentsEnabled( $this->_commentsEnabled );
00110
00111
00112 $artId = $this->_savePostData( $article );
00113
00114
00115 if( $artId ) {
00116
00117 $this->_view = new AdminPostsListView( $this->_blogInfo );
00118
00119 $message = $this->_locale->tr("post_added_ok");
00120
00121
00122 BayesianFilterCore::trainWithArticle( $article );
00123
00124
00125 if( $this->_sendNotification ) {
00126 $artNotifications = new ArticleNotifications();
00127 $artNotifications->addNotification( $artId, $this->_blogInfo->getId(), $this->_userInfo->getId());
00128 $message .= " ".$this->_locale->tr("send_notifications_ok");
00129 }
00130
00131
00132
00133 $article->setId( $artId );
00134 if( $article->getStatus() == POST_STATUS_PUBLISHED) {
00135
00136 if( $this->_sendPings ) {
00137 $pingsOutput = $this->sendXmlRpcPings();
00138 $message .= "<br/><br/>".$pingsOutput;
00139 }
00140
00141
00142 if( $this->_sendTrackbacks ) {
00143
00144 $postLinks = StringUtils::getLinks( stripslashes($article->getText()));
00145
00146
00147 $trackbackLinks = Array();
00148 foreach(explode( "\r\n", $this->_trackbackUrls ) as $host ) {
00149 trim($host);
00150 if( $host != "" && $host != "\r\n" && $host != "\r" && $host != "\n" )
00151 array_push( $trackbackLinks, $host );
00152 }
00153
00154
00155 if( count($postLinks) == 0 && count($trackbackLinks) == 0 ) {
00156 $this->_view = new AdminPostsListView( $this->_blogInfo );
00157 $this->_view->setErrorMessage( $this->_locale->tr("error_no_trackback_links_sent"));
00158 }
00159 else {
00160 $this->_view = new AdminTemplatedView( $this->_blogInfo, "sendtrackbacks" );
00161 $this->_view->setValue( "post", $article );
00162 $this->_view->setValue( "postLinks", $postLinks );
00163 $this->_view->setValue( "trackbackLinks", $trackbackLinks );
00164 }
00165 }
00166 $this->_view->setSuccessMessage( $message );
00167
00168 $this->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article ));
00169
00170
00171 CacheControl::resetBlogCache( $this->_blogInfo->getId());
00172 }
00173 else {
00174 $this->_view = new AdminPostsListView( $this->_blogInfo );
00175 $this->_view->setSuccessMessage( $this->_locale->tr("post_added_not_published") );
00176
00177 $this->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article ));
00178 }
00179 }
00180 else {
00181 $this->_view = new AdminPostsListView( $this->_blogInfo );
00182 $this->_view->setErrorMessage( $this->_locale->tr("error_adding_post") );
00183 }
00184
00185 $this->setCommonData();
00186
00187
00188 return true;
00189 }
00190 }
00191 ?>