public function findallAction()
 {
     if ($value_id = $this->getRequest()->getParam('value_id')) {
         $option = $this->getCurrentOptionValue();
         $page = new Cms_Model_Application_Page();
         $page->find($option->getId(), 'value_id');
         $blocks = $page->getBlocks();
         $data = array("blocks" => array());
         foreach ($blocks as $block) {
             $data["blocks"][] = $this->_toJson($block);
         }
         $data["page_title"] = $option->getTabbarName();
         $data["social_sharing_active"] = $option->getSocialSharingIsActive();
         $this->_sendHtml($data);
     }
 }
Example #2
0
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving your page.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $page = new Cms_Model_Application_Page();
             $page->find($option_value->getId(), 'value_id');
             // Traitement des images des blocks
             $blocks = !empty($datas['block']) && is_array($datas['block']) ? $datas['block'] : array();
             $image_path = '/cms/block/';
             $base_image_path = $this->getApplication()->getBaseImagePath() . $image_path;
             if (!is_dir($base_image_path)) {
                 mkdir($base_image_path, 0777, true);
             }
             foreach ($blocks as $k => $block) {
                 if ($block["type"] == "image" && !empty($block['image_url'])) {
                     foreach ($block['image_url'] as $index => $image_url) {
                         //déjà enregistrée
                         if (substr($image_url, 0, 1) != '/') {
                             if (!empty($image_url) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $image_url)) {
                                 rename(Core_Model_Directory::getTmpDirectory(true) . '/' . $image_url, $base_image_path . $image_url);
                                 $blocks[$k]['image_url'][$index] = $image_path . $image_url;
                             }
                         } else {
                             //                                $img = explode('/', $image_url);
                             //                                $img = $img[count($img) - 1];
                             //                                $blocks[$k]['image_url'][$index] = $image_path . $img;
                             $blocks[$k]['image_url'][$index] = $image_url;
                         }
                     }
                     foreach ($block['image_fullsize_url'] as $index => $image_url) {
                         //déjà enregistrée
                         if (substr($image_url, 0, 1) != '/') {
                             if (!empty($image_url) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $image_url)) {
                                 rename(Core_Model_Directory::getTmpDirectory(true) . '/' . $image_url, $base_image_path . $image_url);
                                 $blocks[$k]['image_fullsize_url'][$index] = $image_path . $image_url;
                             }
                         } else {
                             //                                $img = explode('/', $image_url);
                             //                                $img = $img[count($img) - 1];
                             //                                $blocks[$k]['image_fullsize_url'][$index] = $image_path . $img;
                             $blocks[$k]['image_fullsize_url'][$index] = $image_url;
                         }
                     }
                 }
                 if (($block["type"] == "text" || $block["type"] == "video") && !empty($block['image'])) {
                     //déjà enregistrée
                     if (substr($block['image'], 0, 1) != '/') {
                         if (!empty($block['image']) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $block['image'])) {
                             rename(Core_Model_Directory::getTmpDirectory(true) . '/' . $block['image'], $base_image_path . $block['image']);
                             $blocks[$k]['image'] = $image_path . $block['image'];
                         }
                     } else {
                         //                            $img = explode('/', $block['image']);
                         //                            $img = $img[count($img) - 1];
                         //                            $blocks[$k]['image'] = $image_path . $img;
                         $blocks[$k]['image'] = $block['image'];
                     }
                 }
             }
             $datas['block'] = $blocks;
             // Sauvegarde
             $page->setData($datas)->save();
             $html = array('success' => 1, 'success_message' => $this->_('Page successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function deleteAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         $html = array();
         try {
             // Test s'il y a un value_id
             if (empty($data['option_value_id']) or empty($data['id'])) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($data['option_value_id']);
             if (!$option_value->getId()) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             $page = new Cms_Model_Application_Page();
             $page->find($data["id"]);
             if (!$page->getId() or $page->getValueId() != $option_value->getId() or $option_value->getAppId() != $this->getApplication()->getId()) {
                 throw new Exception($this->_('An error occurred while saving your page.'));
             }
             $page->delete();
             $html = array('success' => 1, 'success_message' => $this->_('Page successfully deleted'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }