コード例 #1
0
 public function findallAction()
 {
     $offset = $this->getRequest()->getParam("offset") ? $this->getRequest()->getParam("offset") : null;
     $limit = Application_Model_Application::BO_DISPLAYED_PER_PAGE;
     $params = array("offset" => $offset, "limit" => $limit);
     $application = new Application_Model_Application();
     $applications = $application->findAll(null, null, $params);
     $app_ids = $application->findAllToPublish();
     $data = array("display_per_page" => $limit, "collection" => array());
     foreach ($applications as $application) {
         $data["collection"][] = array("id" => $application->getId(), "can_be_published" => in_array($application->getId(), $app_ids), "name" => mb_convert_encoding($application->getName(), 'UTF-8', 'UTF-8'), "bundle_id" => $application->getBundleId(), "icon" => $application->getIcon(128));
     }
     $this->_sendHtml($data);
 }
コード例 #2
0
 public function saveAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data["app_id"])) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $application = new Application_Model_Application();
             $application->find($data["app_id"]);
             if (!$application->getId()) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             if (!empty($data["key"])) {
                 $module_names = array_map('strtolower', Zend_Controller_Front::getInstance()->getDispatcher()->getSortedModuleDirectories());
                 if (in_array($data["key"], $module_names)) {
                     throw new Exception($this->_("Your domain key \"%s\" is not valid.", $data["key"]));
                 }
                 $dummy = new Application_Model_Application();
                 $dummy->find($data["key"], "key");
                 if ($dummy->getId() and $dummy->getId() != $application->getId()) {
                     throw new Exception($this->_("The key is already used by another application."));
                 }
             } else {
                 throw new Exception($this->_("The key cannot be empty."));
             }
             if (!empty($data["domain"])) {
                 $data["domain"] = str_replace(array("http://", "https://"), "", $data["domain"]);
                 $tmp_url = str_replace(array("http://", "https://"), "", $this->getRequest()->getBaseUrl());
                 $tmp_url = current(explode("/", $tmp_url));
                 $tmp_domain = explode("/", $data["domain"]);
                 $domain = current($tmp_domain);
                 if (preg_match('/^(www.)?(' . $domain . ')/', $tmp_url)) {
                     throw new Exception($this->_("You can't use this domain."));
                 } else {
                     $domain_folder = next($tmp_domain);
                     $module_names = array_map('strtolower', Zend_Controller_Front::getInstance()->getDispatcher()->getSortedModuleDirectories());
                     if (in_array($domain_folder, $module_names)) {
                         throw new Exception($this->_("Your domain key \"%s\" is not valid.", $domain_folder));
                     }
                 }
                 if (!Zend_Uri::check("http://" . $data["domain"])) {
                     throw new Exception($this->_("Please enter a valid URL"));
                 }
                 $dummy = new Application_Model_Application();
                 $dummy->find($data["domain"], "domain");
                 if ($dummy->getId() and $dummy->getId() != $application->getId()) {
                     throw new Exception("The domain is already used by another application.");
                 }
             }
             if (empty($data["free_until"])) {
                 $data["free_until"] = null;
             } else {
                 $data["free_until"] = new Zend_Date($data["free_until"], "MM/dd/yyyy");
                 $data["free_until"] = $data["free_until"]->toString('yyyy-MM-dd HH:mm:ss');
             }
             $application->addData($data)->save();
             $data = array("success" => 1, "message" => $this->_("Info successfully saved"), "bundle_id" => $application->getBundleId(), "url" => $application->getUrl());
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }