public function searchAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             // Déclaration des variables
             $categories = array();
             // Test s'il y a un value_id
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving'));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             // Appelle le Wordpress et récupère la réponse
             $wordpress = $option_value->getObject();
             $root_category = $wordpress->getRemoteRootCategory($datas['url']);
             // Test si les données sont OK
             if ($root_category->getChildren()) {
                 // Sauvegarde le Wordpress
                 if (!$wordpress->getId()) {
                     $wordpress->setValueId($datas['value_id']);
                 }
                 $wordpress->setUrl($datas['url'])->save();
                 $html = $this->getLayout()->addPartial('categories_html', 'admin_view_default', 'wordpress/application/edit/categories.phtml')->setCategory($root_category)->setCheckAllCategories(true)->toHtml();
                 $html = array('success' => 1, 'categories_html' => $html);
             } else {
                 throw new Exception($this->_("We are sorry but our Wordpress plugin hasn\\'t been detected on your website. Please be sure it is correctly installed and activated."));
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $isNew = false;
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_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($datas['value_id']);
             // Récupère l'objet
             $facebook = $option_value->getObject();
             if (!empty($datas['id'])) {
                 $facebook->find($datas['id']);
             } else {
                 $datas['value_id'] = $option_value->getId();
             }
             if ($facebook->getId() and $facebook->getValueId() != $option_value->getId()) {
                 throw new Exception("Une erreur est survenue lors de la sauvegarde de votre galerie vidéos. Merci de réessayer ultérieurement.");
             }
             $facebook->setData($datas)->save();
             $html = array('success' => '1', 'success_message' => $this->_('Info 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 editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $isNew = false;
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_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($datas['value_id']);
             $html = array('success' => '1', 'success_message' => $this->_('Link has been successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             // Prépare la weblink
             $weblink = $option_value->getObject();
             if (!$weblink->getId()) {
                 $weblink->setValueId($datas['value_id']);
             }
             // S'il y a une cover image
             if (!empty($datas['file'])) {
                 if (!empty($datas['file'])) {
                     $relative_path = '/weblink/cover/';
                     $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $path = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $datas['file'];
                     if (!is_dir($path)) {
                         mkdir($path, 0777, true);
                     }
                     if (!copy($file, $folder . $datas['file'])) {
                         throw new exception($this->_('An error occurred while saving your picture. Please try againg later.'));
                     } else {
                         $weblink->setCover($relative_path . $datas['file']);
                     }
                     if (empty($datas['link'])) {
                         $html['success_message'] = $this->_("The image has been successfully saved");
                     }
                 }
             } else {
                 if (!empty($datas['remove_cover'])) {
                     $weblink->setCover(null);
                     if (empty($datas['link'])) {
                         $html['success_message'] = $this->_("The image has been successfully deleted");
                     }
                 }
             }
             // Sauvegarde le weblink
             $weblink->save();
             if (!empty($datas['link'])) {
                 $link_datas = $datas['link'];
                 if (empty($link_datas['url']) or !Zend_Uri::check($link_datas['url'])) {
                     throw new Exception($this->_('Please enter a valid url'));
                 }
                 // Prépare le link
                 $link = new Weblink_Model_Weblink_Link();
                 if (!empty($link_datas['link_id'])) {
                     $link->find($link_datas['link_id']);
                 }
                 $isNew = !$link->getId();
                 $link_datas['weblink_id'] = $weblink->getId();
                 // Test s'il y a un picto
                 if (!empty($link_datas['picto']) and file_exists(Core_Model_Directory::getTmpDirectory(true) . '/' . $link_datas['picto'])) {
                     $relative_path = '/pictos/';
                     $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $path = Application_Model_Application::getBaseImagePath() . $relative_path;
                     $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $link_datas['picto'];
                     if (!is_dir($path)) {
                         mkdir($path, 0777, true);
                     }
                     if (!copy($file, $folder . $link_datas['picto'])) {
                         throw new exception($this->_("An error occurred while saving your picto. Please try againg later."));
                     } else {
                         $link_datas['picto'] = $relative_path . $link_datas['picto'];
                     }
                 }
                 // Sauvegarde le link
                 $link->addData($link_datas)->save();
                 if ($link->getIsDeleted()) {
                     $html['success_message'] = $this->_('Link has been successfully deleted');
                     $html['is_deleted'] = 1;
                 }
             }
             if ($isNew) {
                 $html['row_html'] = $this->getLayout()->addPartial('row_', 'admin_view_default', 'weblink/application/multi/edit/row.phtml')->setCurrentLink($link)->setCurrentOptionValue($option_value)->toHtml();
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             $application = $this->getApplication();
             // Test s'il y a un value_id
             if (empty($datas['value_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($datas['value_id']);
             // Test s'il y a embrouille entre la value_id en cours de modification et l'application en session
             if (!$option_value->getId() or $option_value->getAppId() != $this->getApplication()->getId()) {
                 throw new Exception($this->_('An error occurred while saving. Please try again later.'));
             }
             // Prépare le weblink
             $html = array();
             $padlock = $option_value->getObject();
             if (!$padlock->getId()) {
                 $padlock->setValueId($datas['value_id']);
             }
             $value_ids = array();
             if (!empty($datas['app_is_locked'])) {
                 $application->setRequireToBeLoggedIn(1);
             } else {
                 $value_ids = !empty($datas['value_ids']) ? $datas['value_ids'] : array();
                 $application->setRequireToBeLoggedIn(0);
             }
             $unlock_by = null;
             if (!empty($datas['type_ids'])) {
                 sort($datas['type_ids']);
                 $unlock_by = join("|", $datas['type_ids']);
             }
             $unlock_code = null;
             if (isset($datas["qrcode_unlock_code"])) {
                 $unlock_code = $datas["qrcode_unlock_code"];
                 $dir_image = Core_Model_Directory::getBasePathTo("/images/application/" . $this->getApplication()->getId());
                 if (!is_dir($dir_image)) {
                     mkdir($dir_image, 0775, true);
                 }
                 if (!is_dir($dir_image . "/application")) {
                     mkdir($dir_image . "/application", 0775, true);
                 }
                 if (!is_dir($dir_image . "/application/padlock")) {
                     mkdir($dir_image . "/application/padlock", 0775, true);
                 }
                 $dir_image .= "/application/padlock/";
                 $image_name = "padlock_qrcode.png";
                 copy('http://api.qrserver.com/v1/create-qr-code/?color=000000&bgcolor=FFFFFF&data=sendback%3A' . $datas["qrcode_unlock_code"] . '&qzone=1&margin=0&size=200x200&ecc=L', $dir_image . $image_name);
             }
             $this->getApplication()->setUnlockBy($unlock_by)->setUnlockCode($unlock_code)->save();
             $allow_everyone = (int) (!empty($datas['allow_all_customers_to_access_locked_features']));
             $application->setData('allow_all_customers_to_access_locked_features', $allow_everyone)->save();
             $padlock->setAppId($application->getId())->setValueIds($value_ids)->save();
             $html = array('success' => '1', 'success_message' => $this->_('Info 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->getResponse()->setBody(Zend_Json::encode($html))->sendResponse();
         die;
     }
 }