/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendBlogModel::exists($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // set category id $this->categoryId = \SpoonFilter::getGetValue('category', null, null, 'int'); if ($this->categoryId == 0) { $this->categoryId = null; } // get data $this->record = (array) BackendBlogModel::get($this->id); // delete item BackendBlogModel::delete($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // delete search indexes BackendSearchModel::removeIndex($this->getModule(), $this->id); // build redirect URL $redirectUrl = BackendModel::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']); // append to redirect URL if ($this->categoryId != null) { $redirectUrl .= '&category=' . $this->categoryId; } // item was deleted, so redirect $this->redirect($redirectUrl); } else { // something went wrong $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing'); } }
/** * Execute the action */ public function execute() { parent::execute(); BackendBlogModel::deleteSpamComments(); // item was deleted, so redirect $this->redirect(BackendModel::createURLForAction('Comments') . '&report=deleted-spam#tabSpam'); }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $categoryTitle = trim(\SpoonFilter::getPostValue('value', null, '', 'string')); // validate if ($categoryTitle === '') { $this->output(self::BAD_REQUEST, null, BL::err('TitleIsRequired')); } else { // get the data // build array $item['title'] = \SpoonFilter::htmlspecialchars($categoryTitle); $item['language'] = BL::getWorkingLanguage(); $meta['keywords'] = $item['title']; $meta['keywords_overwrite'] = 'N'; $meta['description'] = $item['title']; $meta['description_overwrite'] = 'N'; $meta['title'] = $item['title']; $meta['title_overwrite'] = 'N'; $meta['url'] = BackendBlogModel::getURLForCategory(\SpoonFilter::urlise($item['title'])); // update $item['id'] = BackendBlogModel::insertCategory($item, $meta); // output $this->output(self::OK, $item, vsprintf(BL::msg('AddedCategory'), array($item['title']))); } }
/** * Execute the action */ public function execute() { $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendBlogModel::existsCategory($this->id)) { // get data $this->record = (array) BackendBlogModel::getCategory($this->id); // allowed to delete the category? if (BackendBlogModel::deleteCategoryAllowed($this->id)) { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // delete item BackendBlogModel::deleteCategory($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete_category', array('id' => $this->id)); // category was deleted, so redirect $this->redirect(BackendModel::createURLForAction('Categories') . '&report=deleted-category&var=' . rawurlencode($this->record['title'])); } else { $this->redirect(BackendModel::createURLForAction('Categories') . '&error=delete-category-not-allowed&var=' . rawurlencode($this->record['title'])); } } else { // something went wrong $this->redirect(BackendModel::createURLForAction('Categories') . '&error=non-existing'); } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); // validate meta $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { // build item $item['title'] = $this->frm->getField('title')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['meta_id'] = $this->meta->save(); // insert the item $item['id'] = BackendBlogModel::insertCategory($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_category', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('Categories') . '&report=added-category&var=' . rawurlencode($item['title']) . '&highlight=row-' . $item['id']); } } }
/** * Handle the category of a post * * We'll check if the category exists in the fork blog module, and create it if it doesn't. * * @param string $category The post category * @return int */ private function handleCategory($category = '') { // Does a category with this name exist? /* @var \SpoonDatabase $db */ $db = BackendModel::getContainer()->get('database'); $id = (int) $db->getVar('SELECT id FROM blog_categories WHERE title=? AND language=?', array($category, BL::getWorkingLanguage())); // We found an id! if ($id > 0) { return $id; } // Return default if we got an empty string if (trim($category) == '') { return 2; } // We should create a new category $cat = array(); $cat['language'] = BL::getWorkingLanguage(); $cat['title'] = $category; $meta = array(); $meta['keywords'] = $category; $meta['description'] = $category; $meta['title'] = $category; $meta['url'] = $category; return Model::insertCategory($cat, $meta); }
/** * Parse all datagrids */ protected function parse() { parent::parse(); // parse the datagrid for the drafts $this->tpl->assign('dgDrafts', (string) $this->dgDrafts->getContent()); // parse the datagrid for all blogposts $this->tpl->assign('dgPosts', (string) $this->dgPosts->getContent()); // parse the datagrid for the most recent blogposts $this->tpl->assign('dgRecent', is_object($this->dgRecent) ? $this->dgRecent->getContent() : false); // get categories $categories = BackendBlogModel::getCategories(true); $hasMultipleCategories = count($categories) > 1; $this->tpl->assign('hasMultipleCategories', $hasMultipleCategories); // multiple categories? if ($hasMultipleCategories) { // create form $frm = new BackendForm('filter', null, 'get', false); // create element $frm->addDropdown('category', $categories, $this->categoryId); $frm->getField('category')->setDefaultElement(''); // parse the form $frm->parse($this->tpl); } // parse category if (!empty($this->category)) { $this->tpl->assign('filterCategory', $this->category); } }
/** * Load the data */ private function loadData() { $this->comments = BackendBlogModel::getLatestComments('published', 5); $this->numCommentStatus = BackendBlogModel::getCommentStatusCount(); }
/** * Execute the action */ public function execute() { parent::execute(); // current status $from = \SpoonFilter::getGetValue('from', array('published', 'moderation', 'spam'), 'published'); // action to execute $action = \SpoonFilter::getGetValue('action', array('published', 'moderation', 'spam', 'delete'), 'spam'); // no id's provided if (!isset($_GET['id'])) { $this->redirect(BackendModel::createURLForAction('Comments') . '&error=no-comments-selected'); } // redefine id's $ids = (array) $_GET['id']; // delete comment(s) if ($action == 'delete') { BackendBlogModel::deleteComments($ids); } elseif ($action == 'spam') { // is the spamfilter active? if ($this->get('fork.settings')->get($this->URL->getModule(), 'spamfilter', false)) { // get data $comments = BackendBlogModel::getComments($ids); // loop comments foreach ($comments as $row) { // unserialize data $row['data'] = unserialize($row['data']); // check if needed data is available if (!isset($row['data']['server']['REMOTE_ADDR'])) { continue; } if (!isset($row['data']['server']['HTTP_USER_AGENT'])) { continue; } // build vars $userIp = $row['data']['server']['REMOTE_ADDR']; $userAgent = $row['data']['server']['HTTP_USER_AGENT']; $content = $row['text']; $author = $row['author']; $email = $row['email']; $url = isset($row['website']) && $row['website'] != '' ? $row['website'] : null; $referrer = isset($row['data']['server']['HTTP_REFERER']) ? $row['data']['server']['HTTP_REFERER'] : null; $others = $row['data']['server']; // submit as spam BackendModel::submitSpam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others); } } // set new status BackendBlogModel::updateCommentStatuses($ids, $action); } else { // published? if ($action == 'published') { // is the spamfilter active? if ($this->get('fork.settings')->get($this->URL->getModule(), 'spamfilter', false)) { // get data $comments = BackendBlogModel::getComments($ids); // loop comments foreach ($comments as $row) { // previous status is spam if ($row['status'] == 'spam') { // unserialize data $row['data'] = unserialize($row['data']); // check if needed data is available if (!isset($row['data']['server']['REMOTE_ADDR'])) { continue; } if (!isset($row['data']['server']['HTTP_USER_AGENT'])) { continue; } // build vars $userIp = $row['data']['server']['REMOTE_ADDR']; $userAgent = $row['data']['server']['HTTP_USER_AGENT']; $content = $row['text']; $author = $row['author']; $email = $row['email']; $url = isset($row['website']) && $row['website'] != '' ? $row['website'] : null; $referrer = isset($row['data']['server']['HTTP_REFERER']) ? $row['data']['server']['HTTP_REFERER'] : null; $others = $row['data']['server']; // submit as spam BackendModel::submitHam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others); } } } } // set new status BackendBlogModel::updateCommentStatuses($ids, $action); } // define report $report = count($ids) > 1 ? 'comments-' : 'comment-'; // init var if ($action == 'published') { $report .= 'moved-published'; } elseif ($action == 'moderation') { $report .= 'moved-moderation'; } elseif ($action == 'spam') { $report .= 'moved-spam'; } elseif ($action == 'delete') { $report .= 'deleted'; } // redirect $this->redirect(BackendModel::createURLForAction('Comments') . '&report=' . $report . '#tab' . \SpoonFilter::ucfirst($from)); }
/** * 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['meta_id'] = $this->meta->save(); // this is used to let our model know the status (active, archive, draft) of the edited item $item['revision_id'] = $this->record['revision_id']; $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'; // create folders if needed $fs = new Filesystem(); $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128')); // If the image should be deleted, only the database entry is refreshed. // The revision should keep it's file. if ($this->frm->getField('delete_image')->isChecked()) { // reset the name $item['image'] = null; } // new image given? if ($this->frm->getField('image')->isFilled()) { // build the image name // we use the previous revision-id in the filename to make the filename unique between // the different revisions, to prevent that a new file would // overwrite images of previous revisions that have the same title, and thus, the same filename $item['image'] = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $this->frm->getField('image')->getExtension(); // upload the image & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']); } elseif ($item['image'] != null) { // generate the new filename $image = new File($imagePath . '/source/' . $item['image']); $newName = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $image->getExtension(); // extract the filenames excluding …-[language]-[revision-id].jpg // to properly compare them to eachother $regex = '/(.*)-[a-z]{2}-[0-9]+\\.(.*)/'; // only copy if the new name differs from the old filename if (preg_replace($regex, '$1', $newName) != preg_replace($regex, '$1', $item['image'])) { // loop folders foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) { $fs->copy($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $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 ($this->get('fork.settings')->get($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') { // 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); } } }
/** * Validate the form */ private function validateForm() { 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'])); } } }
/** * 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; // insert the item $item['revision_id'] = BackendBlogModel::insert($item); if ($this->imageIsAllowed) { // the image path $imagePath = FRONTEND_FILES_PATH . '/blog/images'; // create folders if needed $fs = new Filesystem(); $fs->mkdir(array($imagePath . '/source', $imagePath . '/128x128')); // image provided? if ($this->frm->getField('image')->isFilled()) { // build the image name $item['image'] = $this->meta->getURL() . '-' . BL::getWorkingLanguage() . '-' . $item['revision_id'] . '.' . $this->frm->getField('image')->getExtension(); // upload the image & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']); // add the image to the database without changing the revision id BackendBlogModel::updateRevision($item['revision_id'], array('image' => $item['image'])); } } // 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 ($this->get('fork.settings')->get($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') { // 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']); } } } }
/** * Update the status for multiple comments at once. * * @param array $id The id/ids of the comment(s) to update. * @param string $status The new status for the comment. Possible values are: published, moderation, spam. */ public static function commentsUpdateStatus($id, $status) { // authorize if (BaseAPI::isAuthorized() && BaseAPI::isValidRequestMethod('POST')) { // redefine if (!is_array($id)) { $id = (array) explode(',', $id); } $status = (string) $status; // update statuses BackendBlogModel::updateCommentStatuses($id, $status); } }