コード例 #1
0
ファイル: Message.php プロジェクト: bklein01/siberian_cms_2
 public function setMessage($message)
 {
     $this->_message = $message;
     if ($certificate = Push_Model_Certificate::getiOSCertificat($message->getAppId())) {
         $this->__certificate = Core_Model_Directory::getBasePathTo($certificate);
     }
     return $this;
 }
コード例 #2
0
 public static function getAndroidSenderId()
 {
     if (is_null(self::$_android_sender_id)) {
         $certificat = new self();
         $certificat->find('android_sender_id', 'type');
         self::$_android_sender_id = $certificat->getPath();
     }
     return self::$_android_sender_id;
 }
コード例 #3
0
 public function saveAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             foreach ($data as $key) {
                 $certificate = new Push_Model_Certificate();
                 $certificate->find($key["name"], "type");
                 if (!$certificate->getId()) {
                     $certificate->setType($key["name"]);
                 }
                 $certificate->setPath($key["value"])->save();
             }
             $data = array("success" => 1, "message" => $this->_("Keys successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
コード例 #4
0
 public function saveAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (empty($datas['type'])) {
                 throw new Exception('An error occurred during process. Please try again later.');
             }
             if (empty($datas['path'])) {
                 $datas['path'] = null;
             }
             $certificat = new Push_Model_Certificate();
             $certificat->find($datas['type'], 'type');
             if (!$certificat->getId()) {
                 $certificat->setType($datas['type']);
             }
             $certificat->setPath($datas['path'])->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));
     }
 }
コード例 #5
0
 public function uploadAction()
 {
     if (!empty($_FILES)) {
         try {
             $path = '/var/apps/iphone/certificates/';
             $base_path = Core_Model_Directory::getBasePathTo($path);
             $filename = uniqid() . '.pem';
             $app_id = $this->getRequest()->getParam('app_id');
             if (!is_dir($base_path)) {
                 mkdir($base_path, 0775, true);
             }
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination($base_path);
             $adapter->setValidators(array('Extension' => array('pem', 'case' => false)));
             $adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, \\'%s\\' only", '%extension%')));
             $files = $adapter->getFileInfo();
             foreach ($files as $file => $info) {
                 if (!$adapter->isUploaded($file)) {
                     throw new Exception($this->_('An error occurred during process. Please try again later.'));
                 } else {
                     if (!$adapter->isValid($file)) {
                         if (count($adapter->getMessages()) == 1) {
                             $erreur_message = $this->_('Error : <br/>');
                         } else {
                             $erreur_message = $this->_('Errors : <br/>');
                         }
                         foreach ($adapter->getMessages() as $message) {
                             $erreur_message .= '- ' . $message . '<br/>';
                         }
                         throw new Exception($erreur_message);
                     } else {
                         $adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $base_path . $filename, 'overwrite' => true)));
                         $adapter->receive($file);
                     }
                 }
             }
             $certificat = new Push_Model_Certificate();
             $certificat->find(array('type' => 'ios', 'app_id' => $app_id));
             if (!$certificat->getId()) {
                 $certificat->setType('ios')->setAppId($app_id);
             }
             $certificat->setPath($path . $filename)->save();
             $datas = array('success' => 1, 'files' => 'eeeee', 'message_success' => $this->_('Info successfully saved'), 'message_button' => 0, 'message_timeout' => 2);
         } catch (Exception $e) {
             $datas = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($datas));
     }
 }
コード例 #6
0
ファイル: Android.php プロジェクト: bklein01/siberian_cms_2
 protected function _prepareFiles()
 {
     //        $source = $this->_sources_dst.'/java/com/'.$this->_formatted_bundle_name.'/'.$this->_folder_name;
     $source = $this->_sources_dst . '/java/' . str_replace(".", "/", $this->_package_name);
     $links = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, 4096), RecursiveIteratorIterator::SELF_FIRST);
     $allowed_extensions = array("java", "xml");
     if (!$links) {
         return $this;
     }
     foreach ($links as $link) {
         if (!$link->isDir()) {
             $info = pathinfo($link->getPathName());
             $extension = $info["extension"];
             if (in_array($extension, $allowed_extensions)) {
                 if (strpos($link, 'CommonUtilities.java') !== false) {
                     $this->__replace(array('String SENDER_ID = ""' => 'String SENDER_ID = "' . Push_Model_Certificate::getAndroidSenderId() . '"', 'String APP_ID = ""' => 'String APP_ID = "' . $this->getApplication()->getId() . '"', 'SERVEUR_URL = "http://base.appsmobilecompany.com/";' => 'SERVEUR_URL = "' . $this->getUrl() . '";'), $link);
                 }
             }
         }
     }
     $replacements = array('com.appsmobilecompany.base' => $this->_package_name, '[ENCRYPT_KEY]' => $this->getDevice()->getKeyPass());
     $source = $this->_dst;
     $links = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, 4096), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($links as $link) {
         if ($link->isDir()) {
             continue;
         }
         $this->__replace($replacements, $link->getRealPath());
     }
     $this->__replace($replacements, $this->_sources_dst . '/AndroidManifest.xml');
     $this->__replace($replacements, $this->_sources_dst . '/../../build.gradle');
     $name = str_replace("'", "\\'", $this->getApplication()->getName());
     // Retrieve the available languages
     $languages = Core_Model_Language::getLanguageCodes();
     // Check if all the available languages exist in the Android source
     foreach ($languages as $lang) {
         if ($lang == "en") {
             continue;
         }
         if (stripos($lang, "_") !== false) {
             $lang = explode("_", $lang);
             if (count($lang) == 2) {
                 $lang[1] = "r" . $lang[1];
             }
             $lang = implode("-", $lang);
         }
         // If not, create them out of the English one.
         if (!file_exists($this->_sources_dst . '/res/values-' . $lang . '/strings.xml')) {
             mkdir($this->_sources_dst . '/res/values-' . $lang, 0777);
             copy($this->_sources_dst . '/res/values/strings.xml', $this->_sources_dst . '/res/values-' . $lang . '/strings.xml');
         }
     }
     $replacements = array('http://localhost/overview' => $this->getApplication()->getUrl(null, array(), 'en', false), '<string name="app_name">Apps Mobile Company</string>' => '<string name="app_name"><![CDATA[' . $name . ']]></string>');
     $this->__replace($replacements, $this->_sources_dst . '/res/values/strings.xml');
     if ($fbk_app_id = $this->getApplication()->getFacebookId()) {
         $replacements_sharing = array('<!-- FACEBOOK -->' => '<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>');
         if ($this->getApplication()->getData("facebook_id")) {
             $replacements_sharing['<!-- FACEBOOK PROVIDER -->'] = '<provider android:authorities="com.facebook.app.FacebookContentProvider' . $fbk_app_id . '"
                                         android:name="com.facebook.FacebookContentProvider"
                                         android:exported="true" />';
         }
         $replacements_sharing_ids = array('[FACEBOOK_APP_ID]' => $fbk_app_id);
         $this->__replace($replacements_sharing_ids, $this->_sources_dst . '/res/values/sharings_id.xml');
         $this->__replace($replacements_sharing, $this->_sources_dst . '/AndroidManifest.xml');
     }
     foreach ($languages as $lang) {
         if ($lang == "en") {
             continue;
         }
         if (stripos($lang, "_") !== false) {
             $android_lang = explode("_", $lang);
             if (count($android_lang) == 2) {
                 $android_lang[1] = "r" . $android_lang[1];
             }
             $android_lang = implode("-", $android_lang);
         } else {
             $android_lang = $lang;
         }
         $replacements = array('http://localhost/overview' => $this->getApplication()->getUrl(null, array(), $lang, false), '<string name="app_name">SiberianCMS</string>' => '<string name="app_name"><![CDATA[' . $name . ']]></string>', '<string name="app_name">Apps Mobile Company</string>' => '<string name="app_name"><![CDATA[' . $name . ']]></string>');
         $this->__replace($replacements, $this->_sources_dst . "/res/values-{$android_lang}/strings.xml");
     }
     if (file_exists($this->_sources_dst . '/res/values-fr/strings.xml')) {
         $this->__replace($replacements, $this->_sources_dst . '/res/values-fr/strings.xml');
     }
     $version = explode(".", $this->getDevice()->getVersion());
     $version_code = !empty($version[0]) ? $version[0] : 1;
     $version_name = !empty($version[0]) && !empty($version[1]) ? $version[0] . "." . $version[1] : "1.0";
     if ($version_code != 1 || $version_name != "1.0") {
         $replacements = array("versionCode 1" => "versionCode {$version_code}", 'versionName "1.0"' => 'versionName "' . $version_name . '"');
         $this->__replace($replacements, $this->_sources_dst . "/../../build.gradle");
         $this->__replace($replacements, $this->_sources_dst . "/../../build.gradle.save");
     }
     return $this;
 }
コード例 #7
0
ファイル: Message.php プロジェクト: bklein01/siberian_cms_2
 /**
  * Constructor.
  *
  * @param array $params
  * @access 	public
  */
 function __construct($params = array())
 {
     parent::__construct($params);
     $this->__key = Push_Model_Certificate::getAndroidKey();
 }
コード例 #8
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);
     }
 }