[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/view/admin/adminxmlview.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/data/timestamp.class.php"); 6 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 7 8 /** 9 * \ingroup Action 10 * @private 11 */ 12 class AdminSaveDraftArticleAjaxAction extends AdminAction 13 { 14 15 var $_postText; 16 var $_postTopic; 17 18 function AdminSaveDraftArticleAjaxAction( $actionInfo, $request ) 19 { 20 $this->AdminAction( $actionInfo, $request ); 21 } 22 23 function validate() 24 { 25 $this->_postText = $this->_request->getValue( "postText" ); 26 $this->_postTopic = $this->_request->getValue( "postTopic" ); 27 28 // if there is no text, extended text or topic there is no point in saving anything 29 if( $this->_postText == "" && $this->_postTopic == "" ) { 30 // nothing to do yet, so let's quit 31 $this->_view = new AdminXmlView( $this->_blogInfo, "response" ); 32 $this->_view->setValue( "method", "saveDraftArticleAjax" ); 33 $this->_view->setValue( "success", "0" ); 34 $this->_view->setValue( "message", $this->_locale->tr( "error_saving_draft" ) ); 35 36 return false; 37 } 38 39 $this->_postCategories = $this->_request->getValue( "postCategories" ); 40 $this->_postStatus = $this->_request->getValue( "postStatus" ); 41 $this->_postSlug = $this->_request->getValue( "postSlug" ); 42 $this->_sendNotification = $this->_request->getValue( "sendNotification" ); 43 $this->_sendTrackbacks = $this->_request->getValue( "sendTrackbacks" ); 44 $this->_sendPings = $this->_request->getValue( "sendPings" ); 45 $this->_postId = $this->_request->getValue( "postId" ); 46 $this->_commentsEnabled = $this->_request->getValue( "commentsEnabled" ); 47 if( $this->_commentsEnabled != 1 ) 48 $this->_commentsEnabled = false; 49 else 50 $this->_commentsEnabled = true; 51 52 // fetch the custom fields 53 $this->_customFields = $this->_request->getValue( "customField" ); 54 55 // fetch the timestamp that the post will have 56 if( $this->_config->getValue( "disable_javascript_calendar")) { 57 $this->_postDay = $this->_request->getValue( "postDay" ); 58 $this->_postMonth = $this->_request->getValue( "postMonth" ); 59 $this->_postHour = $this->_request->getValue( "postHour" ); 60 $this->_postMinutes = $this->_request->getValue( "postMinutes" ); 61 $this->_postYear = $this->_request->getValue( "postYear" ); 62 } 63 else { 64 $postDateTime = $this->_request->getValue( "postDateTime" ); 65 $dateTimeParts = explode(" ", $postDateTime); 66 $dateParts = explode("/", $dateTimeParts[0] ); 67 $timeParts = explode(":",$dateTimeParts[1] ); 68 $this->_postDay = $dateParts[0]; 69 $this->_postMonth = $dateParts[1]; 70 $this->_postYear = $dateParts[2]; 71 $this->_postHour = $timeParts[0]; 72 $this->_postMinutes = $timeParts[1]; 73 } 74 75 $this->_postTimestamp = new Timestamp(); 76 $this->_postTimestamp->setMinutes( $this->_postMinutes ); 77 $this->_postTimestamp->setHour( $this->_postHour ); 78 $this->_postTimestamp->setDay( $this->_postDay ); 79 $this->_postTimestamp->setMonth( $this->_postMonth ); 80 $this->_postTimestamp->setYear( $this->_postYear ); 81 return true; 82 } 83 84 function perform() 85 { 86 $status = POST_STATUS_DRAFT; 87 $articles = new Articles(); 88 $postText = Textfilter::xhtmlize($this->_postText); 89 90 $article = new Article( $this->_postTopic, $postText, $this->_postCategories, $this->_userInfo->getId(), 91 $this->_blogInfo->getId(), $status, 0, Array(), $this->_postSlug ); 92 // set also the date before it's too late 93 $article->setDateObject( $this->_postTimestamp ); 94 $article->setCommentsEnabled( $this->_commentsEnabled ); 95 // prepare the custom fields 96 $fields = Array(); 97 if( is_array($this->_customFields)) { 98 lt_include( PLOG_CLASS_PATH."class/dao/customfields/customfieldvalue.class.php" ); 99 foreach( $this->_customFields as $fieldId => $fieldValue ) { 100 // 3 of those parameters are not really need when creating a new object... it's enough that 101 // we know the field definition id. 102 $customField = new CustomFieldValue( $fieldId, $fieldValue, "", -1, "", -1, $this->_blogInfo->getId(), -1); 103 array_push( $fields, $customField ); 104 } 105 $article->setFields( $fields ); 106 } 107 108 // in case the post is already in the db 109 if( $this->_postId != "" ) { 110 $article->setId( $this->_postId ); 111 $postSavedOk = $articles->updateArticle( $article ); 112 113 if( $postSavedOk ) 114 $artId = $this->_postId; 115 else 116 $artId = false; 117 } 118 else { 119 $artId = $articles->addArticle( $article ); 120 } 121 122 // once we have built the object, we can add it to the database 123 $this->_view = new AdminXmlView( $this->_blogInfo, "response" ); 124 $this->_view->setValue( "method", "saveDraftArticleAjax" ); 125 if( $artId ) 126 { 127 $this->_view->setValue( "success", "1" ); 128 $this->_view->setValue( "message", $this->_locale->pr( "draft_saved_ok", $this->_postTopic ) ); 129 130 $result = '<id>'.$artId.'</id>'; 131 $this->_view->setValue( "result", $result ); 132 } 133 else 134 { 135 $this->_view->setValue( "success", "0" ); 136 $this->_view->setValue( "message", $this->_locale->tr( "error_saving_draft" ) ); 137 } 138 139 return true; 140 } 141 } 142 ?>
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 |
![]() |