function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); // @task: Check for acl rules. $this->checkAccess('category'); $mainframe = JFactory::getApplication(); $message = ''; $type = 'message'; if (JRequest::getMethod() == 'POST') { $post = JRequest::get('post'); if (empty($post['title'])) { $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_CATEGORIES_INVALID_CATEGORY'), 'error'); $url = 'index.php?option=com_easyblog&view=category'; $mainframe->redirect(JRoute::_($url, false)); return; } $category = EasyBlogHelper::getTable('Category', 'Table'); $user = JFactory::getUser(); if (!isset($post['created_by']) || empty($post['created_by'])) { $post['created_by'] = $user->id; } $post['description'] = JRequest::getVar('description', '', 'REQUEST', 'none', JREQUEST_ALLOWHTML); $catId = JRequest::getVar('catid', ''); $isNew = empty($catId) ? true : false; if (!empty($catId)) { $category->load($catId); } $category->bind($post); if (!$category->store()) { JError::raiseError(500, $category->getError()); } else { //save the category acl $category->deleteACL(); if ($category->private == CATEGORY_PRIVACY_ACL) { $category->saveACL($post); } // Set the meta for the category $category->createMeta(); // AlphaUserPoints // since 1.2 if ($isNew && EasyBlogHelper::isAUPEnabled()) { AlphaUserPointsHelper::newpoints('plgaup_easyblog_add_category', '', 'easyblog_add_category_' . $category->id, JText::sprintf('AUP NEW CATEGORY CREATED', $post['title'])); } $file = JRequest::getVar('Filedata', '', 'files', 'array'); if (!empty($file['name'])) { $newAvatar = EasyBlogHelper::uploadCategoryAvatar($category, true); $category->avatar = $newAvatar; $category->store(); //now update the avatar. } $message = JText::_('COM_EASYBLOG_CATEGORIES_SAVED_SUCCESS'); } } else { $message = JText::_('COM_EASYBLOG_INVALID_REQUEST'); $type = 'error'; } // Redirect to new form once again if necessary $saveNew = JRequest::getInt('savenew', 0); if ($saveNew) { $mainframe->redirect('index.php?option=com_easyblog&view=category', $message, $type); $mainframe->close(); } $mainframe->redirect('index.php?option=com_easyblog&view=categories', $message, $type); }
function saveCategory() { $id = JRequest::getVar('id', ''); $acl = EasyBlogACLHelper::getRuleSet(); $my = JFactory::getUser(); $redirect = EasyBlogRouter::_('index.php?option=com_easyblog&view=dashboard&layout=categories', false); $mainframe = JFactory::getApplication(); // @rule: Sanity checks if (empty($id)) { EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_DASHBOARD_CATEGORIES_ID_IS_EMPTY_ERROR'), 'error'); $mainframe->redirect($redirect); $mainframe->close(); } // @rule: Check if the user is really allowed to create category. if (!$acl->rules->create_category) { EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_NOT_ALLOWED'), 'error'); $mainframe->redirect($redirect); $mainframe->close(); } // @rule: Check if the user is really allowed to edit this category $category = EasyBlogHelper::getTable('Category', 'Table'); $category->load($id); if ($category->id && $category->created_by != $my->id && !EasyBlogHelper::isSiteAdmin()) { EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_NOT_ALLOWED'), 'error'); $mainframe->redirect($redirect); $mainframe->close(); } $post = JRequest::get('POST'); $post['description'] = JRequest::getVar('description', '', 'REQUEST', 'none', JREQUEST_ALLOWHTML); $category->bind($post); $model = $this->getModel('Category'); if ($model->isExist($category->title, $category->id)) { EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_DASHBOARD_CATEGORIES_ALREADY_EXISTS_ERROR'), 'error'); $mainframe->redirect($redirect); $mainframe->close(); } $avatar = JRequest::getVar('Filedata', '', 'files', 'array'); if (isset($avatar['name']) && !empty($avatar['name'])) { $category->avatar = EasyBlogHelper::uploadCategoryAvatar($category); } $category->store(); //save acl $category->deleteACL(); if ($category->private == CATEGORY_PRIVACY_ACL) { $category->saveACL($post); } EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_DASHBOARD_CATEGORIES_UPDATED_SUCCESSFULLY'), 'success'); $mainframe->redirect($redirect); $mainframe->close(); }