Ejemplo n.º 1
0
 /**
  * Active or deactivate articles
  * 
  * @return ViewModel
  */
 public function activateAction()
 {
     $id = $this->params('id', '');
     $ids = array_filter(explode(',', $id));
     $status = $this->params('status', 0);
     $from = $this->params('from', '');
     if ($ids) {
         $module = $this->getModule();
         $modelArticle = $this->getModel('article');
         // Activing articles that user has permission to do
         $rules = Rule::getPermission();
         if (1 == count($ids)) {
             $row = $modelArticle->find($ids[0]);
             if (!(isset($rules[$row->category]['active']) and $rules[$row->category]['active'])) {
                 return $this->jumpToDenied();
             }
         } else {
             $rows = $modelArticle->select(array('id' => $ids));
             $ids = array();
             foreach ($rows as $row) {
                 if (isset($rules[$row->category]['active']) and $rules[$row->category]['active']) {
                     $ids[] = $row->id;
                 }
             }
         }
         $modelArticle->setActiveStatus($ids, $status ? 1 : 0);
         // Clear cache
         Pi::service('render')->flushCache($module);
     }
     if ($from) {
         $from = urldecode($from);
         return $this->redirect()->toUrl($from);
     } else {
         // Go to list page
         return $this->redirect()->toRoute('', array('action' => 'published', 'from' => 'all'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Batch approve draft 
  */
 public function batchApproveAction()
 {
     // Denied user viewing if no front-end management permission assigned
     if (!$this->config('enable_front_edit') && 'front' == $this->section) {
         return $this->jumpTo404();
     }
     $id = $this->params('id', '');
     $ids = array_filter(explode(',', $id));
     $from = $this->params('from', '');
     $options = Setup::getFormConfig();
     if ($ids) {
         // To approve articles that user has permission to approve
         $model = $this->getModel('draft');
         $rules = Rule::getPermission();
         if (1 == count($ids)) {
             $row = $model->find($ids[0]);
             if (!(isset($rules[$row->category]['approve']) and $rules[$row->category]['approve'])) {
                 return $this->jumpToDenied();
             }
         } else {
             $rows = $model->select(array('id' => $ids));
             $ids = array();
             foreach ($rows as $row) {
                 if (isset($rules[$row->category]['approve']) and $rules[$row->category]['approve']) {
                     $ids[] = $row->id;
                 }
             }
         }
         // Approve articles
         foreach ($ids as $id) {
             $this->approve($id, $options['elements']);
         }
     }
     if ($from) {
         $from = urldecode($from);
         return $this->redirect()->toUrl($from);
     } else {
         // Go to list page
         return $this->redirect()->toRoute('', array('controller' => 'article', 'action' => 'published'));
     }
 }
Ejemplo n.º 3
0
 /**
  * Preview draft edit page
  * 
  * @return ViewModel 
  */
 public function previewAction()
 {
     // Get elements
     $options = array();
     $mode = $this->params('mode', '');
     if (empty($mode)) {
         return $this->jumpTo404(_a('Invalid mode!'));
     }
     $options['mode'] = $mode;
     if ('custom' == $mode) {
         $elements = $this->params('elements', '');
         $options['elements'] = explode(',', $elements);
     } else {
         $options['elements'] = DraftEditForm::getDefaultElements($mode);
     }
     $form = new DraftEditForm('add', $options);
     // Get allowed categories
     $rules = Rule::getPermission();
     $listCategory = array();
     $approve = array();
     $delete = array();
     foreach ($rules as $key => $rule) {
         if (isset($rule['compose']) and $rule['compose']) {
             $listCategory[$key] = true;
         }
         if (isset($rule['approve']) and $rule['approve']) {
             $approve[] = $key;
         }
         if (isset($rule['approve-delete']) and $rule['approve-delete']) {
             $delete[] = $key;
         }
     }
     $categories = $form->get('category')->getValueOptions();
     $form->get('category')->setValueOptions(array_intersect_key($categories, $listCategory));
     $form->setData(array('category' => $this->config('default_category'), 'source' => $this->config('default_source'), 'fake_id' => uniqid(), 'uid' => Pi::user()->getId()));
     $module = $this->getModule();
     $this->view()->assign(array('form' => $form, 'config' => Pi::config('', $module), 'elements' => $options['elements'], 'rules' => $rules, 'approve' => $approve, 'delete' => $delete, 'status' => \Module\Article\Model\Draft::FIELD_STATUS_DRAFT, 'currentDelete' => true));
     $this->view()->setTemplate('draft-edit', $this->getModule(), 'front');
 }
Ejemplo n.º 4
0
 /**
  * Delete published articles
  * 
  * @return ViewModel 
  */
 public function deleteAction()
 {
     // Denied user viewing if no front-end management permission assigned
     if (!$this->config('enable_front_edit') && 'front' == $this->section) {
         return $this->jumpTo404();
     }
     $id = $this->params('id', '');
     $ids = array_filter(explode(',', $id));
     $from = $this->params('from', '');
     if (empty($ids)) {
         return $this->jumpTo404(__('Invalid article ID'));
     }
     $module = $this->getModule();
     $modelArticle = $this->getModel('article');
     $modelAsset = $this->getModel('asset');
     // Delete articles that user has permission to do
     $rules = Rule::getPermission();
     if (1 == count($ids)) {
         $row = $modelArticle->find($ids[0]);
         $slug = Draft::getStatusSlug($row->status);
         $resource = $slug . '-delete';
         if (!(isset($rules[$row->category][$resource]) and $rules[$row->category][$resource])) {
             return $this->jumpToDenied();
         }
     } else {
         $rows = $modelArticle->select(array('id' => $ids));
         $ids = array();
         foreach ($rows as $row) {
             $slug = Draft::getStatusSlug($row->status);
             $resource = $slug . '-delete';
             if (isset($rules[$row->category][$resource]) and $rules[$row->category][$resource]) {
                 $ids[] = $row->id;
             }
         }
     }
     $resultsetArticle = $modelArticle->select(array('id' => $ids));
     // Step operation
     foreach ($resultsetArticle as $article) {
         // Delete feature image
         if ($article->image) {
             @unlink(Pi::path($article->image));
             @unlink(Pi::path(Media::getThumbFromOriginal($article->image)));
         }
     }
     // Batch operation
     // Deleting extended fields
     $this->getModel('extended')->delete(array('article' => $ids));
     // Deleting statistics
     $this->getModel('stats')->delete(array('article' => $ids));
     // Deleting compiled article
     $this->getModel('compiled')->delete(array('article' => $ids));
     // Delete tag
     if ($this->config('enable_tag')) {
         Pi::service('tag')->delete($module, $ids);
     }
     // Delete related articles
     $this->getModel('related')->delete(array('article' => $ids));
     // Delete visits
     $this->getModel('visit')->delete(array('article' => $ids));
     // Delete assets
     $modelAsset->delete(array('article' => $ids));
     // Delete article directly
     $modelArticle->delete(array('id' => $ids));
     // Clear cache
     Pi::service('render')->flushCache($module);
     if ($from) {
         $from = urldecode($from);
         return $this->redirect()->toUrl($from);
     } else {
         // Go to list page
         return $this->redirect()->toRoute('', array('controller' => 'article', 'action' => 'published', 'from' => 'all'));
     }
 }