public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             $message = new Push_Model_Message();
             $sendNow = false;
             $inputs = array('send_at', 'send_until');
             foreach ($inputs as $input) {
                 if (empty($datas[$input . '_a_specific_datetime'])) {
                     $datas[$input] = null;
                 } else {
                     if (empty($datas[$input])) {
                         throw new Exception($this->_('Please, enter a valid date'));
                     } else {
                         $date = new Zend_Date($datas[$input]);
                         $datas[$input] = $date->toString('y-MM-dd HH:mm:ss');
                     }
                 }
             }
             if (empty($datas['send_at'])) {
                 $sendNow = true;
                 $datas['send_at'] = Zend_Date::now()->toString('y-MM-dd HH:mm:ss');
             }
             if (!empty($datas['send_until']) and $datas['send_at'] > $datas['send_until']) {
                 throw new Exception($this->_("The duration limit must be higher than the sent date"));
             }
             $message->setData($datas)->save();
             if ($sendNow) {
                 $c = curl_init();
                 curl_setopt($c, CURLOPT_URL, $this->getUrl('push/message/send', array('message_id' => $message->getId())));
                 curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
                 // Follow the redirects (needed for mod_rewrite)
                 curl_setopt($c, CURLOPT_HEADER, false);
                 // Don't retrieve headers
                 curl_setopt($c, CURLOPT_NOBODY, true);
                 // Don't retrieve the body
                 curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
                 // Return from curl_exec rather than echoing
                 curl_setopt($c, CURLOPT_FRESH_CONNECT, true);
                 // Always ensure the connection is fresh
                 // Timeout super fast once connected, so it goes into async.
                 curl_setopt($c, CURLOPT_TIMEOUT, 1);
                 curl_exec($c);
                 curl_close($c);
             }
             $html = array('success' => 1, 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             if ($sendNow) {
                 $html['success_message'] = $this->_('Your message has been saved successfully and will be sent in a few minutes');
             } else {
                 $html['success_message'] = $this->_('Your message has been saved successfully and will be sent at the entered date');
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function countAction()
 {
     $nbr = 0;
     if ($device_uid = $this->getRequest()->getParam('device_uid')) {
         $message = new Push_Model_Message();
         $message->setMessageTypeByOptionValue($this->getCurrentOptionValue()->getOptionId());
         $nbr = $message->countByDeviceId($device_uid);
     }
     $data = array('count' => $nbr);
     $this->_sendHtml($data);
 }
 public function deleteAction()
 {
     if ($id = $this->getRequest()->getParam('message_id')) {
         $message = new Push_Model_Message();
         $message->find($id);
         $message->delete();
         $data = array('success' => 1, 'success_message' => $this->_('Push successfully deleted.'), 'message_loader' => 0, 'message_button' => 0, 'message_timeout' => 2);
     } else {
         $datas = array('error' => 1, 'message' => $this->_('An error occurred while deleting the push. Please try again later.'));
     }
     $this->getLayout()->setHtml(Zend_Json::encode($data));
 }
示例#4
0
 public function countAction()
 {
     $html = array();
     $device_uid = $this->_getDeviceUid();
     $nbr = 0;
     if ($device_uid) {
         $message = new Push_Model_Message();
         $nbr = $message->countByDeviceId($device_uid);
     }
     $html = array('count' => $nbr);
     $this->getLayout()->setHtml(Zend_Json::encode($html));
 }
 /**
  * Set this message as displayed
  */
 public function markdisplayedAction()
 {
     if ($params = $this->getRequest()->getParams()) {
         if (empty($params['device_uid']) or empty($params['message_id'])) {
             return;
         }
         $device = new Push_Model_Iphone_Device();
         $device->find($params['device_uid'], 'device_uid');
         $message = new Push_Model_Message();
         $message->markAsDisplayed($device->getId(), $params['message_id']);
     }
     die;
 }
 /**
  * Set this message as displayed
  */
 public function markdisplayedAction()
 {
     if ($params = $this->getRequest()->getParams()) {
         if (empty($params['registration_id']) or empty($params['message_id'])) {
             return;
         }
         $device = new Push_Model_Android_Device();
         $device->findByRegistrationId($params['registration_id']);
         $message = new Push_Model_Message();
         $message->markAsDisplayed($device->getId(), $params['message_id']);
     }
     die;
 }
示例#7
0
 /**
  * Register Device
  *
  */
 public function registerdeviceAction()
 {
     if ($params = $this->getRequest()->getParams()) {
         $fields = array('app_name', 'app_version', 'device_uid', 'device_token', 'device_name', 'device_model', 'device_version', 'push_badge', 'push_alert', 'push_sound');
         foreach ($params as $key => $value) {
             if (!in_array($key, $fields)) {
                 unset($params[$key]);
             }
         }
         $params['status'] = 'active';
         $device = new Push_Model_Iphone_Device();
         $device->find($params['device_uid'], 'device_uid');
         $device->addData($params)->save();
         $message = new Push_Model_Message();
         $this->getLayout()->setHtml($message->countByDeviceId($device->getDeviceUid()));
     }
 }
 public function sendAction()
 {
     $message = new Push_Model_Message();
     $now = Zend_Date::now()->toString('y-MM-dd HH:mm:ss');
     $errors = array();
     if ($id = $this->getRequest()->getParam('message_id')) {
         $message->find($id);
         $messages = array();
         if ($message->getId() and $message->getStatus() == "queued") {
             $messages[] = $message;
         }
     } else {
         $messages = $message->findAll(array('status IN (?)' => array('queued'), 'send_at IS NULL OR send_at <= ?' => $now, 'send_until IS NULL OR send_until >= ?' => $now), 'created_at DESC');
     }
     if (count($messages) > 0) {
         foreach ($messages as $message) {
             try {
                 // Envoi et sauvegarde du message
                 $message->push();
                 if ($message->getErrors()) {
                     $errors[$message->getId()] = $message->getErrors();
                 }
             } catch (Exception $e) {
                 $message->updateStatus('failed');
                 $errors[$message->getId()] = $e;
             }
         }
     }
     Zend_Debug::dump('Erreurs :');
     Zend_Debug::dump($errors);
     die('done');
 }
 public function readinappAction()
 {
     $data = array();
     if ($device_uid = $this->getRequest()->getParam('device_uid') and $device_type = $this->getRequest()->getParam('device_type')) {
         $message = new Push_Model_Message();
         $message->markInAppAsRead($this->getApplication()->getId(), $device_uid, $device_type);
         $data = array("message" => "Success.");
     }
     $this->_sendHtml($data);
 }
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         $html = '';
         try {
             $message = new Push_Model_Message();
             $message->setMessageTypeByOptionValue($this->getCurrentOptionValue()->getOptionId());
             $sendNow = false;
             $inputs = array('send_at', 'send_until');
             foreach ($inputs as $input) {
                 if (empty($datas[$input . '_a_specific_datetime'])) {
                     $datas[$input] = null;
                 } else {
                     if (empty($datas[$input])) {
                         throw new Exception($this->_('Please, enter a valid date'));
                     } else {
                         $date = new Zend_Date($datas[$input]);
                         $datas[$input] = $date->toString('y-MM-dd HH:mm:ss');
                     }
                 }
             }
             if (empty($datas['send_at'])) {
                 $sendNow = true;
                 $datas['send_at'] = Zend_Date::now()->toString('y-MM-dd HH:mm:ss');
             }
             if (!empty($datas['send_until']) and $datas['send_at'] > $datas['send_until']) {
                 throw new Exception($this->_("The duration limit must be higher than the sent date"));
             }
             // Récupère l'option_value en cours
             $option_value = new Application_Model_Option_Value();
             if (!empty($datas['file'])) {
                 $file = pathinfo($datas['file']);
                 $filename = $file['basename'];
                 $relative_path = $option_value->getImagePathTo();
                 $folder = Application_Model_Application::getBaseImagePath() . $relative_path;
                 $img_dst = $folder . $filename;
                 $img_src = Core_Model_Directory::getTmpDirectory(true) . '/' . $filename;
                 if (!is_dir($folder)) {
                     mkdir($folder, 0777, true);
                 }
                 if (!@copy($img_src, $img_dst)) {
                     throw new exception($this->_('An error occurred while saving your picture. Please try again later.'));
                 } else {
                     $datas['cover'] = $relative_path . $filename;
                 }
             } else {
                 if (!empty($data['remove_cover'])) {
                     $data['cover'] = null;
                 }
             }
             if (empty($datas['action_value'])) {
                 $datas['action_value'] = null;
             } else {
                 if (!preg_match('/^[0-9]*$/', $datas['action_value'])) {
                     $url = "http://" . $datas['action_value'];
                     if (stripos($datas['action_value'], "http://") !== false || stripos($datas['action_value'], "https://") !== false) {
                         $url = $datas['action_value'];
                     }
                     $datas['action_value'] = file_get_contents("http://tinyurl.com/api-create.php?url=" . urlencode($url));
                 }
             }
             $datas['type_id'] = $message->getMessageType();
             $datas['app_id'] = $this->getApplication()->getId();
             $datas["send_to_all"] = $datas["topic_receiver"] ? 0 : 1;
             $message->setData($datas)->save();
             //PnTopics
             if ($datas["topic_receiver"]) {
                 $topic_data = explode(";", $datas["topic_receiver"]);
                 foreach ($topic_data as $id_topic) {
                     if ($id_topic != "") {
                         $category_message = new Topic_Model_Category_Message();
                         $category_message_data = array("category_id" => $id_topic, "message_id" => $message->getId());
                         $category_message->setData($category_message_data);
                         $category_message->save();
                     }
                 }
             }
             if ($message->getMessageType() == 1) {
                 if ($sendNow) {
                     $c = curl_init();
                     curl_setopt($c, CURLOPT_URL, $this->getUrl('push/message/send', array('message_id' => $message->getId())));
                     curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
                     // Follow the redirects (needed for mod_rewrite)
                     curl_setopt($c, CURLOPT_HEADER, false);
                     // Don't retrieve headers
                     curl_setopt($c, CURLOPT_NOBODY, true);
                     // Don't retrieve the body
                     curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
                     // Return from curl_exec rather than echoing
                     curl_setopt($c, CURLOPT_FRESH_CONNECT, true);
                     // Always ensure the connection is fresh
                     // Timeout super fast once connected, so it goes into async.
                     curl_setopt($c, CURLOPT_TIMEOUT, 10);
                     curl_exec($c);
                     curl_close($c);
                 }
             } else {
                 $message->updateStatus('delivered');
             }
             $html = array('success' => 1, 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
             if ($sendNow) {
                 $html['success_message'] = $this->_('Your message has been saved successfully and will be sent in a few minutes');
             } else {
                 $html['success_message'] = $this->_('Your message has been saved successfully and will be sent at the entered date');
             }
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
示例#11
0
 public function findNotReceivedMessages($geolocated = null)
 {
     $message_ids = $this->getTable()->findNotReceivedMessages($this->getDeviceUid(), $geolocated);
     $message = new Push_Model_Message();
     return !empty($message_ids) ? $message->findAll(array('message_id IN (?)' => $message_ids)) : new Siberian_Db_Table_Rowset(array());
 }