類別AdminAddPostAction的繼承圖:

公開方法(Public Methods) | |
| AdminAddPostAction ($actionInfo, $request) | |
| perform () | |
私有方法(Private Methods) | |
| _savePostData ($article) | |
定義在 adminaddpostaction.class.php 檔案之第 23 行.
|
||||||||||||
|
Constructor. If nothing else, it also has to call the constructor of the parent class, BlogAction with the same parameters 定義在 adminaddpostaction.class.php 檔案之第 29 行. 參考 $request, AdminPostManagementCommonAction::AdminPostManagementCommonAction(), Action::registerField(), Action::registerFieldValidator(), 及 Action::setValidationErrorView(). 00030 { 00031 $this->AdminPostManagementCommonAction( $actionInfo, $request ); 00032 00033 // for data validation purposes, posts must have at least a topic, an intro text, and a category 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 // these fields do not need to be validated but should be there when we show the view once again 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 }
|
|
|
returns the id of the post or 'false' if it couldn't be saved 定義在 adminaddpostaction.class.php 檔案之第 60 行. 參考 $article, $articles, AdminPostManagementCommonAction::_getArticleCustomFields(), 及 AdminAction::notifyEvent(). 被參考於 perform(). 00061 { 00062 $status = $this->_postStatus; 00063 00064 $articles = new Articles(); 00065 $article->setFields( $this->_getArticleCustomFields()); 00066 00067 // notifiy about this event 00068 $this->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article )); 00069 00070 // in case the post is already in the db 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 }
|
|
|
Carries out the specified action 依據Action重新實作. 定義在 adminaddpostaction.class.php 檔案之第 91 行. 參考 $article, $host, AdminPostManagementCommonAction::_fetchCommonData(), _savePostData(), StringUtils::getLinks(), AdminAction::notifyEvent(), CacheControl::resetBlogCache(), AdminPostManagementCommonAction::sendXmlRpcPings(), AdminAction::setCommonData(), 及 BayesianFilterCore::trainWithArticle(). 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 // we know for sure that the information is correct so we can now add 00102 // the post to the database 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 // set also the date before it's too late 00108 $article->setDateObject( $this->_postTimestamp ); 00109 $article->setCommentsEnabled( $this->_commentsEnabled ); 00110 00111 // save the article to the db 00112 $artId = $this->_savePostData( $article ); 00113 00114 // once we have built the object, we can add it to the database 00115 if( $artId ) { 00116 00117 $this->_view = new AdminPostsListView( $this->_blogInfo ); 00118 //$article->setId( $artId ); 00119 $message = $this->_locale->tr("post_added_ok"); 00120 00121 // train the filter 00122 BayesianFilterCore::trainWithArticle( $article ); 00123 00124 // add the article notification if requested to do so 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 // we only have to send trackback pings if the article was published 00132 // otherwise there is no need to... 00133 $article->setId( $artId ); 00134 if( $article->getStatus() == POST_STATUS_PUBLISHED) { 00135 // get the output from the xmlrpc pings but only if the user decided to do so! 00136 if( $this->_sendPings ) { 00137 $pingsOutput = $this->sendXmlRpcPings(); 00138 $message .= "<br/><br/>".$pingsOutput; 00139 } 00140 00141 // and now check what to do with the trackbacks 00142 if( $this->_sendTrackbacks ) { 00143 // get the links from the text of the post 00144 $postLinks = StringUtils::getLinks( stripslashes($article->getText())); 00145 00146 // get the real trackback links from trackbackUrls 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 // if no links, there is nothing to do 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 // empty the cache used by this blog 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 // better to return true if everything fine 00188 return true; 00189 }
|