コード例 #1
0
 public function deleteAction()
 {
     if ($app_id = $this->getRequest()->getParam('app_id')) {
         try {
             $application = new Application_Model_Application();
             $application->find($app_id);
             if (!$application->getId()) {
                 throw new Exception($this->_("This application does not exist"));
             }
             $application->delete();
             $html = array('success' => 1, 'app_id' => $app_id);
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }
コード例 #2
0
 public function setaddpageAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             if (empty($data["admin_id"]) or empty($data["app_id"])) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $admin = new Admin_Model_Admin();
             $admin->find($data["admin_id"]);
             $application = new Application_Model_Application();
             $application->find($data["app_id"]);
             if (!$admin->getId() or !$application->getId()) {
                 throw new Exception($this->_("An error occurred while saving. Please try again later."));
             }
             $admin->setIsAllowedToAddPages(!empty($data["can_add_page"]))->save();
             $data = array("success" => 1, "message" => $this->_("Data saved successfully."));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
コード例 #3
0
 public function downloadappAction()
 {
     if ($app_id = $this->getRequest()->getParam('app_id')) {
         $mobile = new Mobile_Detect();
         $application = new Application_Model_Application();
         $application->find($app_id);
         $redirect_to = $application->getUrl();
         if ($mobile->isAndroiddevice()) {
             $store_url = $application->getDevice(2)->getStoreUrl();
             if ($store_url) {
                 $redirect_to = preg_match('/details/', $store_url) ? preg_replace('/(.*\\/)((details).*)/', 'market://$2', $store_url) : $store_url;
             }
         } else {
             if ($mobile->isIosdevice()) {
                 $store_url = $application->getDevice(1)->getStoreUrl();
                 if ($store_url) {
                     $redirect_to = str_replace(array('http:', 'https:'), 'itms-apps:', $store_url);
                 }
             }
         }
         $this->getResponse()->setRedirect($redirect_to)->sendResponse();
         die;
     }
 }
コード例 #4
0
 public function setpermissionstoadminAction()
 {
     if ($data = $this->getRequest()->getPost()) {
         try {
             if (empty($data["admin_id"]) or empty($data["app_id"])) {
                 throw new Exception($this->_("1An error occurred while saving. Please try again later."));
             }
             $admin = new Admin_Model_Admin();
             $admin->find($data["admin_id"]);
             if (($admin->getId() or $admin->getParentId()) and ($admin->getId() != $this->getAdmin()->getId() and $admin->getParentId() != $this->getAdmin()->getId())) {
                 $this->getSession()->addError("This administrator does not exist");
             }
             $application = new Application_Model_Application();
             $application->find($data["app_id"]);
             if (!$application->getId()) {
                 throw new Exception($this->_("2An error occurred while saving. Please try again later."));
             }
             if (!$application->hasAsAdmin($this->getAdmin()->getId())) {
                 throw new Exception($this->_("3An error occurred while saving. Please try again later."));
             }
             $admin->setIsAllowedToAddPages(!empty($data["is_selected"]));
             $application->addAdmin($admin);
             $data = array("success" => 1);
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
コード例 #5
0
 private function __checkKeyAndDomain($data, $application)
 {
     if (isset($data["key"]) and (!$application->getId() or $application->getKey() != $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 application key \"%s\" is not valid.", $data["key"]));
         }
         $app_tester = new Application_Model_Application();
         $app_tester->find($data["key"], "key");
         if ($app_tester->getId() and $app_tester->getId() != $application->getId()) {
             throw new Exception($this->_("The key is already used by another application."));
         }
     }
     if (!empty($data["domain"]) and $application->getDomain() != $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"));
         }
         $app_tester = new Application_Model_Application();
         $app_tester->find($data["domain"], "domain");
         if ($app_tester->getId() and $app_tester->getId() != $application->getId()) {
             throw new Exception("The domain is already used by another application.");
         }
     }
 }
コード例 #6
0
 public function uploadcertificateAction()
 {
     if ($app_id = $this->getRequest()->getParam("app_id")) {
         try {
             if (empty($_FILES) || empty($_FILES['file']['name'])) {
                 throw new Exception("No file has been sent");
             }
             $application = new Application_Model_Application();
             $application->find($app_id);
             $base_path = Core_Model_Directory::getBasePathTo("var/apps/iphone/");
             $path = Core_Model_Directory::getPathTo("var/apps/iphone/");
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination(Core_Model_Directory::getTmpDirectory(true));
             if ($adapter->receive()) {
                 $file = $adapter->getFileInfo();
                 $certificat = new Push_Model_Certificate();
                 $certificat->find(array('type' => 'ios', 'app_id' => $app_id));
                 if (!$certificat->getId()) {
                     $certificat->setType("ios")->setAppId($app_id);
                 }
                 $new_name = uniqid("cert_") . ".pem";
                 if (!rename($file["file"]["tmp_name"], $base_path . $new_name)) {
                     throw new Exception($this->_("An error occurred while saving. Please try again later."));
                 }
                 $certificat->setPath($path . $new_name)->save();
                 $data = array("success" => 1, "message" => $this->_("The file has been successfully uploaded"));
             } else {
                 $messages = $adapter->getMessages();
                 if (!empty($messages)) {
                     $message = implode("\n", $messages);
                 } else {
                     $message = $this->_("An error occurred during the process. Please try again later.");
                 }
                 throw new Exception($message);
             }
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }