Esempio n. 1
0
 public function save()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     $mainframe = JFactory::getApplication();
     $task = $this->getTask();
     $message = '';
     $type = 'success';
     if (JRequest::getMethod() == 'POST') {
         $post = JRequest::get('post');
         if (empty($post['title'])) {
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CATEGORIES_INVALID_CATEGORY'), DISCUSS_QUEUE_ERROR);
             $url = 'index.php?option=com_easydiscuss&view=categories';
             $mainframe->redirect(JRoute::_($url, false));
             return;
         }
         $category = JTable::getInstance('Category', 'Discuss');
         $user = JFactory::getUser();
         $post['created_by'] = $user->id;
         $catId = JRequest::getVar('catid', '');
         $isNew = empty($catId) ? true : false;
         $alterOrdering = true;
         if (!empty($catId)) {
             $category->load($catId);
             $newParentId = $post['parent_id'];
             if ($category->parent_id != $newParentId) {
                 $alterOrdering = true;
             } else {
                 $alterOrdering = false;
             }
             $post['id'] = $catId;
         }
         $category->bind($post);
         // Description might contain html codes
         $description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW);
         $category->description = $description;
         // Bind params
         $params = DiscussHelper::getRegistry('');
         $params->set('show_description', $post['show_description']);
         $params->set('maxlength', $post['maxlength']);
         $params->set('maxlength_size', $post['maxlength_size']);
         $params->set('cat_notify_custom', $post['cat_notify_custom']);
         $params->set('cat_email_parser', $post['cat_email_parser']);
         $params->set('cat_email_parser_password', $post['cat_email_parser_password']);
         $params->set('cat_email_parser_switch', $post['cat_email_parser_switch']);
         $category->params = $params->toString();
         if (!$category->store($alterOrdering)) {
             JError::raiseError(500, $category->getError());
             exit;
         }
         //save the category acl
         $category->deleteACL();
         $category->saveACL($post);
         $file = JRequest::getVar('Filedata', '', 'files', 'array');
         if (!empty($file['name'])) {
             $newAvatar = DiscussHelper::uploadCategoryAvatar($category, true);
             $category->avatar = $newAvatar;
             $category->store();
             //now update the avatar.
         }
         // now we need to rerun the category ordering incase admin assign the correct category tree as a child of another category.
         $category->rebuildOrdering();
         $message = JText::_('COM_EASYDISCUSS_CATEGORIES_SAVED_SUCCESS');
     } else {
         $message = JText::_('COM_EASYDISCUSS_INVALID_REQUEST');
         $type = 'error';
     }
     DiscussHelper::setMessageQueue($message, $type);
     if ($task == 'savePublishNew') {
         $mainframe->redirect('index.php?option=com_easydiscuss&view=category');
         $mainframe->close();
     }
     if ($task == 'apply') {
         $mainframe->redirect('index.php?option=com_easydiscuss&view=category&catid=' . $category->id);
         $mainframe->close();
     }
     $mainframe->redirect('index.php?option=com_easydiscuss&view=categories');
     $mainframe->close();
 }