Esempio n. 1
0
 public function add()
 {
     $this->setupForm();
     if ($this->isPost()) {
         $this->validate();
         if (!$this->error->has()) {
             $date = Loader::helper('form/date_time')->translate('blogDate');
             $parent = ProblogPost::getParentByID($this->post('cParentID'));
             $canonical = Loader::helper('blogify')->getOrCreateCanonical($date, $parent);
             $ct = CollectionType::getByHandle('pb_post');
             $data = array('cName' => $this->post('blogTitle'), 'cDescription' => $this->post('blogDescription'), 'cDatePublic' => $date);
             $p = $canonical->add($ct, $data);
             $p = ProblogPost::getByID($p->getCollectionID());
             $p->update(array('pTemplateID' => $this->post('ptID')));
             if ($this->post('draft') == 1 || $this->post('draft') == 2) {
                 $p->deactivate();
                 if ($this->post('draft') == 2) {
                     Loader::helper('blog_actions')->send_publish_request($p);
                 }
             }
             ProblogPost::saveData($p);
             if (!$this->post('save_post')) {
                 $this->redirect('/dashboard/problog/blog_list/', 'blogadded');
             } else {
                 $this->redirect('/dashboard/problog/add_blog/edit/' . $p->getCollectionID());
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * render Add Blog dialog
  */
 public function save()
 {
     $blogify = Loader::helper('blogify');
     $error = Loader::helper('validation/error');
     $error = $this->validate($error);
     if (!$error->has()) {
         $date = Loader::helper('form/date_time')->translate('blogDate');
         $parent = ProblogPost::getParentByID($_REQUEST['cParentID']);
         $canonical = $blogify->getOrCreateCanonical($date, $parent);
         $ct = CollectionType::GetByHandle('pb_post');
         $data = array('cName' => $_REQUEST['blogTitle'], 'cDescription' => $_REQUEST['blogDescription'], 'cDatePublic' => $date, 'pTemplateID' => $this->post('ptID'));
         if ($_REQUEST['blogID']) {
             $p = ProblogPost::getByID($_REQUEST['blogID']);
             $old_parent_id = $blogify->getCanonicalParent($date, $p);
             $olddate = $p->getCollectionDatePublic();
             $p->update($data);
             $p->setPageType($ct);
             if ($old_parent_id != $canonical->getCollectionID() || $date != $olddate) {
                 $p->move($canonical);
             }
         } else {
             $p = $canonical->add($ct, $data);
         }
         if ($_REQUEST['draft'] == 1 || $_REQUEST['draft'] == 2) {
             $p->deactivate();
             if ($_REQUEST['draft'] == 2) {
                 Loader::helper('blog_actions')->send_publish_request($p);
             }
         }
         ProblogPost::saveData($p);
         print Loader::helper('json')->encode(array('success'));
     } else {
         $errors = $error->getList();
         print Loader::helper('json')->encode($errors);
     }
 }