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; } }
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); } }