예제 #1
0
 /**
  * Parse the form
  *
  * @return	void
  */
 protected function parse()
 {
     // call parent
     parent::parse();
     // parse additional variables
     $this->tpl->assign('commentsRSSURL', SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'comments_rss'));
 }
예제 #2
0
 /**
  * Add postdata into the comment
  *
  * @return	string
  * @param 	string $text	The comment.
  * @param	string $title	The title for the blogarticle.
  * @param	string $URL		The URL for the blogarticle.
  * @param	int $id			The id of the comment.
  */
 public static function addPostData($text, $title, $URL, $id)
 {
     // reset URL
     $URL = BackendModel::getURLForBlock('blog', 'detail') . '/' . $URL . '#comment-' . $id;
     // build HTML
     return '<p><em>' . sprintf(BL::msg('CommentOnWithURL'), $URL, $title) . '</em></p>' . "\n" . (string) $text;
 }
예제 #3
0
 /**
  * Parse the page
  */
 protected function parse()
 {
     parent::parse();
     // get url
     $url = BackendModel::getURLForBlock($this->URL->getModule(), 'detail');
     $url404 = BackendModel::getURL(404);
     // parse additional variables
     if ($url404 != $url) {
         $this->tpl->assign('detailURL', SITE_URL . $url);
     }
 }
예제 #4
0
 /**
  * Load the form
  *
  * @return	void
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('editComment');
     // create elements
     $this->frm->addText('author', $this->record['author']);
     $this->frm->addText('email', $this->record['email']);
     $this->frm->addText('website', $this->record['website'], null);
     $this->frm->addTextarea('text', $this->record['text']);
     // assign URL
     $this->tpl->assign('itemURL', BackendModel::getURLForBlock($this->getModule(), 'detail') . '/' . $this->record['post_url'] . '#comment-' . $this->record['post_id']);
     $this->tpl->assign('itemTitle', $this->record['post_title']);
 }
예제 #5
0
파일: edit.php 프로젝트: richsage/forkcms
 /**
  * Parse the form
  */
 protected function parse()
 {
     parent::parse();
     // get url
     $url = BackendModel::getURLForBlock($this->URL->getModule(), 'detail');
     $url404 = BackendModel::getURL(404);
     if ($url404 != $url) {
         $this->tpl->assign('detailURL', SITE_URL . $url);
     }
     // assign the active record and additional variables
     $this->tpl->assign('item', $this->record);
     $this->tpl->assign('feedback', $this->feedback);
 }
예제 #6
0
    /**
     * Get the latest comments for a given type
     *
     * @return	array
     * @param	string $status			The status for the comments to retrieve.
     * @param	int[optional] $limit	The maximum number of items to retrieve.
     */
    public static function getLatestComments($status, $limit = 10)
    {
        // get the comments (order by id, this is faster then on date, the higher the id, the more recent
        $comments = (array) BackendModel::getDB()->getRecords('SELECT i.id, i.author, i.text, UNIX_TIMESTAMP(i.created_on) AS created_in,
																	p.title, p.language, m.url
																FROM blog_comments AS i
																INNER JOIN blog_posts AS p ON i.post_id = p.id AND i.language = p.language
																INNER JOIN meta AS m ON p.meta_id = m.id
																WHERE i.status = ? AND p.status = ? AND i.language = ?
																ORDER BY i.created_on DESC
																LIMIT ?', array((string) $status, 'active', BL::getWorkingLanguage(), (int) $limit));
        // loop entries
        foreach ($comments as &$row) {
            // add full url
            $row['full_url'] = BackendModel::getURLForBlock('blog', 'detail', $row['language']) . '/' . $row['url'];
        }
        // return
        return $comments;
    }
예제 #7
0
 /**
  * Get a single comment
  *
  * @return	array	   An array with the comment.
  * @param	int $id	 The id of the comment.
  */
 public static function commentsGetById($id)
 {
     // authorize
     if (API::authorize()) {
         // get comment
         $comment = (array) BackendBlogModel::getComment($id);
         // init var
         $return = array('comments' => null);
         // any comment found?
         if (empty($comment)) {
             return $return;
         }
         // create array
         $item['comment'] = array();
         // article meta data
         $item['comment']['article']['@attributes']['id'] = $comment['post_id'];
         $item['comment']['article']['@attributes']['lang'] = $comment['language'];
         $item['comment']['article']['title'] = $comment['post_title'];
         $item['comment']['article']['url'] = SITE_URL . BackendModel::getURLForBlock('blog', 'detail', $comment['language']) . '/' . $comment['post_url'];
         // set attributes
         $item['comment']['@attributes']['id'] = $comment['id'];
         $item['comment']['@attributes']['created_on'] = date('c', $comment['created_on']);
         $item['comment']['@attributes']['status'] = $comment['status'];
         // set content
         $item['comment']['text'] = $comment['text'];
         $item['comment']['url'] = $item['comment']['article']['url'] . '#comment-' . $comment['id'];
         // author data
         $item['comment']['author']['@attributes']['email'] = $comment['email'];
         $item['comment']['author']['name'] = $comment['author'];
         $item['comment']['author']['website'] = $comment['website'];
         // add
         $return['comments'][] = $item;
         // return
         return $return;
     }
 }
예제 #8
0
 /**
  * Get a preview URL to the specific mailing
  *
  * @param int $id The id of the mailing.
  * @param string[optional] $contentType The content-type, possible values are: html, plain.
  * @param bool[optional] $forCM Is the URL intended for Campaign Monitor.
  * @return string
  */
 public static function getMailingPreviewURL($id, $contentType = 'html', $forCM = false)
 {
     $contentType = SpoonFilter::getValue($contentType, array('html', 'plain'), 'html');
     $forCM = SpoonFilter::getValue($forCM, array(false, true), false, 'int');
     // return the URL
     return SITE_URL . BackendModel::getURLForBlock('mailmotor', 'detail') . '/' . $id . '?type=' . $contentType . '&cm=' . $forCM;
 }
예제 #9
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // get the status
         $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid'));
         $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid'));
         $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['revision_id'] = $this->record['revision_id'];
             // this is used to let our model know the status (active, archive, draft) of the edited item
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = (int) $this->frm->getField('category_id')->getValue();
             $item['user_id'] = $this->frm->getField('user_id')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['introduction'] = $this->frm->getField('introduction')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time')));
             $item['edited_on'] = BackendModel::getUTCDate();
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['status'] = $status;
             if ($this->imageIsAllowed) {
                 $item['image'] = $this->record['image'];
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/blog/images';
                 // if the image should be deleted
                 if ($this->frm->getField('delete_image')->isChecked()) {
                     // delete the image
                     SpoonFile::delete($imagePath . '/source/' . $item['image']);
                     // reset the name
                     $item['image'] = null;
                 }
                 // new image given?
                 if ($this->frm->getField('image')->isFilled()) {
                     // delete the old image
                     SpoonFile::delete($imagePath . '/source/' . $this->record['image']);
                     // build the image name
                     $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                     // upload the image
                     $this->frm->getField('image')->moveFile($imagePath . '/source/' . $item['image']);
                 } elseif ($item['image'] != null) {
                     // get the old file extension
                     $imageExtension = SpoonFile::getExtension($imagePath . '/source/' . $item['image']);
                     // get the new image name
                     $newName = $this->meta->getURL() . '.' . $imageExtension;
                     // only change the name if there is a difference
                     if ($newName != $item['image']) {
                         // move the old file to the new name
                         SpoonFile::move($imagePath . '/source/' . $item['image'], $imagePath . '/source/' . $newName);
                         // assign the new name to the database
                         $item['image'] = $newName;
                     }
                 }
             } else {
                 $item['image'] = null;
             }
             // update the item
             $item['revision_id'] = BackendBlogModel::update($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // recalculate comment count so the new revision has the correct count
             BackendBlogModel::reCalculateCommentCount(array($this->id));
             // save the tags
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // active
             if ($item['status'] == 'active') {
                 // edit search index
                 BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 // ping
                 if (BackendModel::getModuleSetting($this->URL->getModule(), 'ping_services', false)) {
                     BackendModel::ping(SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'detail') . '/' . $this->meta->getURL());
                 }
                 // build URL
                 $redirectUrl = BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($item['title']) . '&id=' . $this->id . '&highlight=row-' . $item['revision_id'];
             } elseif ($item['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $redirectUrl = BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id'];
             }
             // append to redirect URL
             if ($this->categoryId != null) {
                 $redirectUrl .= '&category=' . $this->categoryId;
             }
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
예제 #10
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // get the status
         $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid'));
         $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid'));
         $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->getField('category_id')->getValue() == 'new_category') {
             $this->frm->getField('category_id')->addError(BL::err('FieldIsRequired'));
         }
         if ($this->imageIsAllowed) {
             // validate the image
             if ($this->frm->getField('image')->isFilled()) {
                 // image extension and mime type
                 $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
                 $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
             }
         }
         // validate meta
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = (int) BackendBlogModel::getMaximumId() + 1;
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = (int) $this->frm->getField('category_id')->getValue();
             $item['user_id'] = $this->frm->getField('user_id')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['introduction'] = $this->frm->getField('introduction')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time')));
             $item['created_on'] = BackendModel::getUTCDate();
             $item['edited_on'] = $item['created_on'];
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['num_comments'] = 0;
             $item['status'] = $status;
             if ($this->imageIsAllowed) {
                 // the image path
                 $imagePath = FRONTEND_FILES_PATH . '/blog/images';
                 // validate the image
                 if ($this->frm->getField('image')->isFilled()) {
                     // build the image name
                     $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension();
                     // upload the image
                     $this->frm->getField('image')->moveFile($imagePath . '/source/' . $item['image']);
                 }
             }
             // insert the item
             $item['revision_id'] = BackendBlogModel::insert($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // save the tags
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // active
             if ($item['status'] == 'active') {
                 // add search index
                 BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 // ping
                 if (BackendModel::getModuleSetting($this->getModule(), 'ping_services', false)) {
                     BackendModel::ping(SITE_URL . BackendModel::getURLForBlock('blog', 'detail') . '/' . $this->meta->getURL());
                 }
                 // everything is saved, so redirect to the overview
                 $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['revision_id']);
             } elseif ($item['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $this->redirect(BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id']);
             }
         }
     }
 }
예제 #11
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // set callback for generating an unique URL
         $this->meta->setUrlCallback('BackendBlogModel', 'getURL', array($this->record['id']));
         // get the status
         $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active');
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid'));
         $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid'));
         $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['revision_id'] = $this->record['revision_id'];
             // this is used to let our model know the status (active, archive, draft) of the edited item
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = (int) $this->frm->getField('category_id')->getValue();
             $item['user_id'] = $this->frm->getField('user_id')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['introduction'] = $this->frm->getField('introduction')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time')));
             $item['edited_on'] = BackendModel::getUTCDate();
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['status'] = $status;
             // update the item
             $item['revision_id'] = BackendBlogModel::update($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item));
             // recalculate comment count so the new revision has the correct count
             BackendBlogModel::reCalculateCommentCount(array($this->id));
             // save the tags
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             // active
             if ($item['status'] == 'active') {
                 // edit search index
                 if (is_callable(array('BackendSearchModel', 'editIndex'))) {
                     BackendSearchModel::editIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text']));
                 }
                 // ping
                 if (BackendModel::getModuleSetting($this->URL->getModule(), 'ping_services', false)) {
                     BackendModel::ping(SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'detail') . '/' . $this->meta->getURL());
                 }
                 // build URL
                 $redirectUrl = BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($item['title']) . '&id=' . $this->id . '&highlight=row-' . $item['revision_id'];
             } elseif ($item['status'] == 'draft') {
                 // everything is saved, so redirect to the edit action
                 $redirectUrl = BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id'];
             }
             // append to redirect URL
             if ($this->categoryId != null) {
                 $redirectUrl .= '&category=' . $this->categoryId;
             }
             // everything is saved, so redirect to the overview
             $this->redirect($redirectUrl);
         }
     }
 }
예제 #12
0
 /**
  * Load the form for step 4
  *
  * @return	void
  */
 private function loadFormForStep4()
 {
     // check if we have to redirect back to step 3 (HTML content is not set)
     if (empty($this->record['content_html'])) {
         $this->redirect(BackendModel::createURLForAction('edit') . '&amp;id=' . $this->id . '&amp;step=3&amp;error=complete-step-3');
     }
     // get preview URL
     $previewURL = BackendMailmotorModel::getMailingPreviewURL($this->record['id']);
     // check if the mailmotor is linked
     if (BackendModel::getURLForBlock($this->getModule(), 'detail') == BackendModel::getURL(404)) {
         $previewURL = false;
     }
     // parse the preview URL
     $this->tpl->assign('previewURL', $previewURL);
     // create form
     $this->frm = new BackendForm('step4');
     // subject
     $this->frm->addText('email');
     $this->frm->addDate('send_on_date', $this->record['send_on']);
     $this->frm->addTime('send_on_time', SpoonDate::getDate('H:i', $this->record['send_on']));
     // show the form
     $this->tpl->assign('step4', true);
 }
예제 #13
0
 /**
  * Updates a list with campaignmonitor and in the database. Returns the affected rows
  *
  * @param array $item The new data.
  * @return int
  */
 public static function updateGroup($item)
 {
     // build unsubscribe link for this list
     $unsubscribeLink = SITE_URL . BackendModel::getURLForBlock('mailmotor', 'unsubscribe', BL::getWorkingLanguage());
     // update the group with CM
     self::getCM()->updateList($item['name'], $unsubscribeLink . '/?group=' . $item['id'] . '&email=[email]', null, null, self::getCampaignMonitorID('list', $item['id']));
     // check if we have a default group set
     if ($item['is_default'] === 'Y' && $item['language'] != '0') {
         // set all defaults to N
         BackendModel::getDB(true)->update('mailmotor_groups', array('is_default' => 'N', 'language' => null), 'language = ?', array($item['language']));
     }
     // update the group in our database
     return (int) BackendMailmotorModel::updateGroup($item);
 }