Esempio n. 1
0
 /**
  * Display permalink anchor for current post.
  *
  * The permalink mode title will use the post title for the 'a' element 'id'
  * attribute. The id mode uses 'post-' with the post ID for the 'id' attribute.
  *
  * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'.
  */
 function permalinkAnchor($mode = 'id')
 {
     switch (strtolower($mode)) {
         case 'title':
             $title = HuradSanitize::title($this->content[self::$model]['title']) . '-' . $this->content[self::$model]['id'];
             echo $this->Html->link(null, null, array('id' => $title));
             break;
         case 'id':
         default:
             echo $this->Html->link(null, null, array('id' => self::$model . '-' . $this->content[self::$model]['id']));
             break;
     }
 }
Esempio n. 2
0
 /**
  * Edit page
  *
  * @param null|int $id
  */
 public function admin_edit($id = null)
 {
     $this->set('title_for_layout', __d('hurad', 'Edit Page'));
     if (!empty($this->request->data)) {
         if ($this->request->is('post') || $this->request->is('put')) {
             $this->request->data['Page']['created'] = $this->Hurad->dateParse($this->request->data['Page']['created']);
             $this->request->data['Page']['type'] = 'page';
             $this->request->data['Page']['user_id'] = $this->Auth->user('id');
             if (empty($this->request->data['Page']['slug'])) {
                 $this->request->data['Page']['slug'] = HuradSanitize::title($this->request->data['Page']['title'], 'dash');
             } else {
                 $this->request->data['Page']['slug'] = HuradSanitize::title($this->request->data['Page']['slug'], 'dash');
             }
             // save the data
             $this->Page->create();
             if ($this->Page->save($this->request->data)) {
                 $this->Session->setFlash(__d('hurad', 'The Page has been saved.'), 'flash_message', ['class' => 'success']);
                 $this->redirect(['action' => 'index']);
             } else {
                 $this->Session->setFlash(__d('hurad', 'The Page could not be saved. Please, try again.'), 'flash_message', ['class' => 'danger']);
             }
         }
     } elseif (empty($this->request->data)) {
         $this->request->data = $this->Page->read(null, $id);
     }
     $parentPages = $this->Page->generateTreeList(['Page.type' => 'page', 'Page.id !=' => $id], null, null, '_');
     $this->set(compact('parentPages'));
 }
Esempio n. 3
0
 /**
  * Edit post
  *
  * @param null|int $id
  */
 public function admin_edit($id = null)
 {
     $this->set('title_for_layout', __d('hurad', 'Edit Post'));
     $defaults = array('parent_id' => null, 'user_id' => $this->Auth->user('id'), 'title' => '', 'slug' => '', 'content' => '', 'excerpt' => '', 'status' => Post::STATUS_DRAFT, 'comment_status' => Post::COMMENT_STATUS_OPEN, 'comment_count' => 0, 'type' => 'post');
     if (!empty($this->request->data)) {
         if ($this->request->is('post') || $this->request->is('put')) {
             $this->request->data['Post'] = Hash::merge($defaults, $this->request->data['Post']);
             $this->request->data['Post']['created'] = $this->Hurad->dateParse($this->request->data['Post']['created']);
             if (empty($this->request->data['Post']['tags'])) {
                 $this->loadModel('PostsTag');
                 $this->PostsTag->deleteAll(array('post_id' => $id), false);
             }
         }
         $this->_saveTags();
         if (empty($this->request->data['Post']['slug'])) {
             $this->request->data['Post']['slug'] = HuradSanitize::title($this->request->data['Post']['title'], 'dash');
         } else {
             $this->request->data['Post']['slug'] = HuradSanitize::title($this->request->data['Post']['slug'], 'dash');
         }
         // save the data
         $this->Post->create();
         $this->Post->PostMeta->post_id = $id;
         if ($this->Post->save($this->request->data) && $this->Post->PostMeta->saveData($this->request->data)) {
             $this->Session->setFlash(__d('hurad', 'The Post has been saved.'), 'flash_message', array('class' => 'success'));
             $this->redirect(array('action' => 'index'));
         } else {
             $this->Session->setFlash(__d('hurad', 'The Post could not be saved. Please, try again.'), 'flash_message', array('class' => 'danger'));
         }
     }
     if (empty($this->request->data)) {
         $this->request->data = $this->Post->read(null, $id);
         // load the habtm data for the text input.
         $this->_loadTags();
     }
     // get the posts current tags
     $this->Post->PostMeta->post_id = $id;
     $post = Hash::merge($this->Post->read(null, $id), $this->Post->PostMeta->getData());
     $categories = $this->Post->Category->generateTreeList();
     $this->request->data = $post;
     $this->set(compact('post', 'categories'));
 }