コード例 #1
0
ファイル: api.php プロジェクト: netconstructor/forkcms
 /**
  * Update a comment
  *
  * @return	void
  * @param	int $id								The id of the comment.
  * @param	string[optional] $status			The new status for the comment. Possible values are: published, moderation, spam.
  * @param	string[optional] $text				The new text for the comment.
  * @param	string[optional] $authorName		The new author for the comment.
  * @param	string[optional] $authorEmail		The new email for the comment.
  * @param	string[optional] $authorWebsite		The new website for the comment.
  */
 public static function commentsUpdate($id, $status = null, $text = null, $authorName = null, $authorEmail = null, $authorWebsite = null)
 {
     // authorize
     if (API::authorize()) {
         // redefine
         $id = (int) $id;
         if ($status !== null) {
             $status = (string) $status;
         }
         if ($text !== null) {
             $text = (string) $text;
         }
         if ($authorName !== null) {
             $authorName = (string) $authorName;
         }
         if ($authorEmail !== null) {
             $authorEmail = (string) $authorEmail;
         }
         if ($authorWebsite !== null) {
             $authorWebsite = (string) $authorWebsite;
         }
         // validate
         if ($status === null && $text === null && $authorName === null && $authorEmail === null && $authorWebsite === null) {
             API::output(API::ERROR, array('message' => 'No data provided.'));
         }
         // update
         if ($text !== null || $authorName !== null || $authorEmail != null || $authorWebsite !== null) {
             if ($text !== null) {
                 $item['text'] = $text;
             }
             if ($authorName !== null) {
                 $item['author'] = $authorName;
             }
             if ($authorEmail !== null) {
                 $item['email'] = $authorEmail;
             }
             if ($authorWebsite !== null) {
                 $item['website'] = $authorWebsite;
             }
             // update the comment
             BackendBlogModel::updateComment($id, $item);
         }
         // change the status if needed
         if ($status !== null) {
             BackendBlogModel::updateCommentStatuses(array($id), $status);
         }
     }
 }
コード例 #2
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('author')->isFilled(BL::err('AuthorIsRequired'));
         $this->frm->getField('email')->isEmail(BL::err('EmailIsInvalid'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->getField('website')->isFilled()) {
             $this->frm->getField('website')->isURL(BL::err('InvalidURL'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['status'] = $this->record['status'];
             $item['author'] = $this->frm->getField('author')->getValue();
             $item['email'] = $this->frm->getField('email')->getValue();
             $item['website'] = $this->frm->getField('website')->isFilled() ? $this->frm->getField('website')->getValue() : null;
             $item['text'] = $this->frm->getField('text')->getValue();
             // insert the item
             BackendBlogModel::updateComment($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_comment', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('comments') . '&report=edited-comment&id=' . $item['id'] . '&highlight=row-' . $item['id'] . '#tab' . SpoonFilter::toCamelCase($item['status']));
         }
     }
 }