| [ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/admin/adminpostmanagementcommonaction.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/view/admin/adminpostslistview.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/view/admin/adminnewpostview.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php" ); 9 lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" ); 10 11 /** 12 * \ingroup Action 13 * @private 14 * 15 * Action that adds a new post to the database. 16 */ 17 class AdminAddPostAction extends AdminPostManagementCommonAction 18 { 19 /** 20 * Constructor. If nothing else, it also has to call the constructor of the parent 21 * class, BlogAction with the same parameters 22 */ 23 function AdminAddPostAction( $actionInfo, $request ) 24 { 25 $this->AdminPostManagementCommonAction( $actionInfo, $request ); 26 27 // for data validation purposes, posts must have at least a topic, an intro text, and a category 28 $this->registerFieldValidator( "postText", new StringValidator()); 29 $this->registerFieldValidator( "postTopic", new StringValidator()); 30 $this->registerFieldValidator( "postCategories", new ArrayValidator()); 31 $this->registerFieldValidator( "globalArticleCategoryId", new IntegerValidator(), true ); 32 $view = new AdminNewPostView( $this->_blogInfo ); 33 $view->setErrorMessage( $this->_locale->tr("error_adding_post")); 34 $this->setValidationErrorView( $view ); 35 36 // these fields do not need to be validated but should be there when we show the view once again 37 $this->registerField( "postSlug" ); 38 $this->registerField( "postStatus" ); 39 $this->registerField( "sendNotification" ); 40 $this->registerField( "sendTrackbacks" ); 41 $this->registerField( "sendPings" ); 42 $this->registerField( "postId" ); 43 $this->registerField( "commentsEnabled" ); 44 $this->registerField( "customField" ); 45 $this->registerField( "postDateTime" ); 46 $this->registerField( "trackbackUrls" ); 47 $this->registerField( "postUser" ); 48 49 // security checks 50 $this->requirePermission( "add_post" ); 51 } 52 53 /** 54 * @private 55 * 56 * If the form is not validate, we need to clean the autosave cookie 57 */ 58 function validate() 59 { 60 $validateOk = parent::validate(); 61 if( !$validateOk ) 62 $this->clearAutoSaveCookie(); 63 64 return $validateOk; 65 } 66 67 /** 68 * @private 69 * 70 * returns the id of the post or 'false' if it couldn't be saved 71 */ 72 function _savePostData( $article ) 73 { 74 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 75 76 $status = $this->_postStatus; 77 78 $articles = new Articles(); 79 $article->setFields( $this->_getArticleCustomFields()); 80 //print_r($article->_customFields); 81 82 // notifiy about this event 83 $this->notifyEvent( EVENT_PRE_POST_ADD, Array( "article" => &$article )); 84 85 // in case the post is already in the db 86 if( $this->_postId != "" ) { 87 $article->setId( $this->_postId ); 88 $artId = $this->_postId; 89 $postSavedOk = $articles->updateArticle( $article ); 90 91 if( $postSavedOk ) 92 $artId = $this->_postId; 93 else 94 $artId = false; 95 } 96 else { 97 $artId = $articles->addArticle( $article ); 98 } 99 100 return $artId; 101 } 102 103 /** 104 * Carries out the specified action 105 */ 106 function perform() 107 { 108 lt_include( PLOG_CLASS_PATH."class/dao/article.class.php" ); 109 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" ); 110 111 $this->_fetchCommonData(); 112 113 $this->_postId = $this->_request->getValue( "postId" ); 114 115 $this->_previewPost = $this->_request->getValue( "previewPost" ); 116 $this->_addPost = $this->_request->getValue( "addPost" ); 117 $this->_saveDraft = $this->_request->getValue( "isDraft" ); 118 119 // we know for sure that the information is correct so we can now add 120 // the post to the database 121 $postText = Textfilter::xhtmlize($this->_postText); 122 123 $article = new Article( $this->_postTopic, 124 $postText, 125 $this->_postCategories, 126 $this->_posterId, 127 $this->_blogInfo->getId(), 128 $this->_postStatus, 129 0, 130 Array(), 131 $this->_postSlug ); 132 // set also the date before it's too late 133 $article->setDateObject( $this->_postTimestamp ); 134 $article->setCommentsEnabled( $this->_commentsEnabled ); 135 $article->setGlobalCategoryId( $this->_globalArticleCategoryId ); 136 137 // save the article to the db 138 $artId = $this->_savePostData( $article ); 139 140 // depending on the permission that the user has, we'll show one view or another 141 if( !$this->userHasPermission( "view_posts" )) 142 $view = "AdminNewPostView"; 143 else 144 $view = "AdminPostsListView"; 145 146 // once we have built the object, we can add it to the database 147 if( $artId ) { 148 // clear autosave cookie 149 $this->clearAutoSaveCookie(); 150 151 $this->_view = new $view( $this->_blogInfo ); 152 //$article->setId( $artId ); 153 $message = $this->_locale->tr("post_added_ok"); 154 155 // train the filter, but only if enabled 156 if( $this->_config->getValue( "bayesian_filter_enabled" ) == true ) { 157 lt_include( PLOG_CLASS_PATH."class/bayesian/bayesianfiltercore.class.php" ); 158 BayesianFilterCore::trainWithArticle( $article ); 159 } 160 161 // add the article notification if requested to do so 162 if( $this->_sendNotification ) { 163 lt_include( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" ); 164 165 $artNotifications = new ArticleNotifications(); 166 $artNotifications->addNotification( $artId, $this->_blogInfo->getId(), $this->_userInfo->getId()); 167 $message .= " ".$this->_locale->tr("send_notifications_ok"); 168 } 169 170 // we only have to send trackback pings if the article was published 171 // otherwise there is no need to... 172 $article->setId( $artId ); 173 if( $article->getStatus() == POST_STATUS_PUBLISHED) { 174 // get the output from the xmlrpc pings but only if the user decided to do so! 175 176 if( $this->_sendPings) { 177 $t = new Timestamp(); 178 $today = $t->getTimestamp(); 179 if($today > $article->getDate()){ 180 $pingsOutput = $this->sendXmlRpcPings(); 181 $message .= "<br/><br/>".$pingsOutput; 182 } 183 } 184 185 // and now check what to do with the trackbacks 186 if( $this->_sendTrackbacks ) { 187 lt_include( PLOG_CLASS_PATH."class/data/stringutils.class.php" ); 188 189 // get the links from the text of the post 190 $postLinks = StringUtils::getLinks( stripslashes($article->getText())); 191 192 // get the real trackback links from trackbackUrls 193 $trackbackLinks = Array(); 194 foreach(explode( "\r\n", $this->_trackbackUrls ) as $host ) { 195 trim($host); 196 if( $host != "" && $host != "\r\n" && $host != "\r" && $host != "\n" ) 197 array_push( $trackbackLinks, $host ); 198 } 199 200 // if no links, there is nothing to do 201 if( count($postLinks) == 0 && count($trackbackLinks) == 0 ) { 202 $this->_view = new $view( $this->_blogInfo ); 203 $this->_view->setErrorMessage( $this->_locale->tr("error_no_trackback_links_sent")); 204 } 205 else { 206 $this->_view = new AdminTemplatedView( $this->_blogInfo, "sendtrackbacks" ); 207 $this->_view->setValue( "post", $article ); 208 $this->_view->setValue( "postLinks", $postLinks ); 209 $this->_view->setValue( "trackbackLinks", $trackbackLinks ); 210 } 211 } 212 $this->_view->setSuccessMessage( $message ); 213 214 $this->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article )); 215 216 // empty the cache used by this blog 217 lt_include( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" ); 218 219 CacheControl::resetBlogCache( $this->_blogInfo->getId()); 220 } 221 else { 222 $this->_view = new $view( $this->_blogInfo ); 223 $this->_view->setSuccessMessage( $this->_locale->tr("post_added_not_published") ); 224 225 $this->notifyEvent( EVENT_POST_POST_ADD, Array( "article" => &$article )); 226 } 227 } 228 else { 229 $this->_view = new $view( $this->_blogInfo ); 230 $this->_view->setErrorMessage( $this->_locale->tr("error_adding_post") ); 231 } 232 233 $this->setCommonData(); 234 235 // better to return true if everything fine 236 return true; 237 } 238 239 function clearAutoSaveCookie() 240 { 241 $rg = $this->_blogInfo->getBlogRequestGenerator(); 242 $plogBaseUrl = $rg->getBaseUrl(false); 243 $cookieBaseName = "LT" . preg_replace("/[^a-zA-Z0-9]/", "", $plogBaseUrl).$this->_blogInfo->getId(); 244 245 // set the auto save cookie as false 246 setcookie( $cookieBaseName.'postNotSaved', '0', -1, '/' ); 247 setcookie( $cookieBaseName.'postTopic', '', -1, '/' ); 248 setcookie( $cookieBaseName.'postText', '', -1, '/' ); 249 } 250 } 251 ?>
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 |
|