| 18135 |
manas |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* A Controller
|
|
|
5 |
*
|
|
|
6 |
* @property A $A
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class AController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
| 18208 |
manas |
16 |
|
| 18135 |
manas |
17 |
public $components = array('Paginator');
|
| 18208 |
manas |
18 |
public function beforeFilter() {
|
|
|
19 |
parent::beforeFilter();
|
|
|
20 |
$this->Auth->allow('index','mobile','error');
|
|
|
21 |
}
|
| 18135 |
manas |
22 |
|
|
|
23 |
public function index() {
|
| 18208 |
manas |
24 |
$encryptUrl = 'http://104.200.25.40:8057/message/encrypt?type=encrypt&data=';
|
| 18135 |
manas |
25 |
$expiryFlag=false;
|
|
|
26 |
$redirectFlag=false;
|
| 18148 |
manas |
27 |
$this->layout = 'ajax';
|
| 18135 |
manas |
28 |
$serverHost= $_SERVER['HTTP_HOST'];
|
|
|
29 |
$serverURI = $_SERVER['REQUEST_URI'];
|
|
|
30 |
$requestURL ="http://".$serverHost.$serverURI;
|
|
|
31 |
$intentToSend = '';
|
| 18208 |
manas |
32 |
$params = explode($serverHost.'/A', $requestURL);
|
| 18192 |
manas |
33 |
$ua = $_SERVER['HTTP_USER_AGENT'];
|
|
|
34 |
|
|
|
35 |
if($this->isMobileDevice($ua)){
|
|
|
36 |
if(empty($params[1])){
|
| 18135 |
manas |
37 |
$redirectFlag=true;
|
|
|
38 |
}else{
|
| 18192 |
manas |
39 |
$fetchParams = explode('/', $params[1]);
|
|
|
40 |
if(empty($fetchParams[0]) && empty($fetchParams[1])){
|
| 18135 |
manas |
41 |
$redirectFlag=true;
|
|
|
42 |
}else{
|
| 18192 |
manas |
43 |
if(sizeof($fetchParams) == 2 || empty($fetchParams[2])){
|
|
|
44 |
$redirectFlag=true;
|
|
|
45 |
}else if(sizeof($fetchParams)>4){
|
|
|
46 |
$redirectFlag=true;
|
|
|
47 |
}else{
|
|
|
48 |
$campaignId = $fetchParams[1];
|
| 19257 |
manas |
49 |
$userId = $fetchParams[2];;
|
| 18192 |
manas |
50 |
$campaignId = $this->num_decode($campaignId);
|
|
|
51 |
$userId = $this->num_decode($userId);
|
|
|
52 |
$notificationUrl='';
|
|
|
53 |
$encryptedData=array();
|
| 19257 |
manas |
54 |
$url = Configure::read('nodeurl')."/getNotificationCampaignById?id=".$campaignId;
|
|
|
55 |
$notificationData = $this->make_request($url,null);
|
|
|
56 |
/*debug($notificationData);*/
|
|
|
57 |
if($notificationData!=null){
|
|
|
58 |
if(!empty($notificationData)){
|
|
|
59 |
$notificationUrl = $notificationData['url'];
|
|
|
60 |
$notificationType = $notificationData['type'];
|
|
|
61 |
$notificationExpires = $notificationData['expiresat'];
|
|
|
62 |
$notificationStatus = $notificationData['status'];
|
|
|
63 |
$currentTime = time();
|
|
|
64 |
if($notificationExpires < ($currentTime*1000) || $notificationStatus=='inactive'){
|
|
|
65 |
$expiryFlag=true;
|
|
|
66 |
}
|
|
|
67 |
if($notificationType=='native'){
|
|
|
68 |
if(strtolower($notificationUrl)=='contact' || strtolower($notificationUrl)=='profile' ||strtolower($notificationUrl)=='tutorial'){
|
|
|
69 |
$encryptUrl = $encryptUrl.base64_encode(strtolower($notificationUrl));
|
|
|
70 |
$encryptedData = $this->make_request($encryptUrl,null);
|
|
|
71 |
}else{
|
|
|
72 |
$encryptedData = $this->defaultEncryptedMessage($userId);
|
|
|
73 |
}
|
|
|
74 |
}else if ($notificationType=='update'){
|
|
|
75 |
$encryptUrl = $encryptUrl.base64_encode('https://play.google.com/store/apps/details?id=com.saholic.profittill');
|
|
|
76 |
$encryptedData = $this->make_request($encryptUrl,null);
|
|
|
77 |
}else{
|
|
|
78 |
if(empty($notificationUrl)){
|
|
|
79 |
$encryptedData = $this->defaultEncryptedMessage($userId);
|
|
|
80 |
}else if(strpos($notificationUrl,'?user_id=') !== false){
|
|
|
81 |
$encryptUrl = $encryptUrl.base64_encode($notificationUrl);
|
|
|
82 |
$encryptedData = $this->make_request($encryptUrl,null);
|
|
|
83 |
}else{
|
|
|
84 |
$notificationUrl = $notificationUrl.'?user_id='.$userId;
|
|
|
85 |
$encryptUrl = $encryptUrl.base64_encode($notificationUrl);
|
|
|
86 |
$encryptedData = $this->make_request($encryptUrl,null);
|
| 18192 |
manas |
87 |
}
|
| 19257 |
manas |
88 |
}
|
|
|
89 |
}
|
|
|
90 |
else{
|
|
|
91 |
$encryptedData = $this->defaultEncryptedMessage($userId);
|
|
|
92 |
}
|
| 18135 |
manas |
93 |
}else{
|
| 19257 |
manas |
94 |
$redirectFlag=true;
|
|
|
95 |
}
|
| 18192 |
manas |
96 |
}
|
|
|
97 |
}
|
| 18135 |
manas |
98 |
}
|
| 18192 |
manas |
99 |
if($redirectFlag){
|
| 20871 |
amit.gupta |
100 |
$this->redirect('http://www.profitmandi.com');
|
| 18148 |
manas |
101 |
}else{
|
| 18208 |
manas |
102 |
$intentToSend = 'intent://pm1.in?key='.urlencode($encryptedData['result']['value']).'&campaign='.$campaignId.'&intent_type='.$notificationType.'#Intent;scheme=profitmandiapp;package=com.saholic.profittill;end';
|
| 18192 |
manas |
103 |
if($expiryFlag){
|
|
|
104 |
$this->set(compact('intentToSend','expiryFlag'));
|
|
|
105 |
}else{
|
|
|
106 |
header('Location: '.$intentToSend);
|
|
|
107 |
exit;
|
|
|
108 |
}
|
|
|
109 |
}
|
| 18135 |
manas |
110 |
}
|
| 18192 |
manas |
111 |
else{
|
|
|
112 |
$this->redirect(array('action'=>'mobile'));
|
|
|
113 |
}
|
| 18135 |
manas |
114 |
}
|
|
|
115 |
|
|
|
116 |
function defaultEncryptedMessage($userId){
|
| 18208 |
manas |
117 |
$encryptUrl = 'http://104.200.25.40:8057/message/encrypt?type=encrypt&data=';
|
| 18135 |
manas |
118 |
$defaultEncryptedData =array();
|
|
|
119 |
$defaultUrl = 'http://api.profittill.com/deals';
|
|
|
120 |
$notificationUrl = $defaultUrl.'?user_id='.$userId;
|
|
|
121 |
$encryptUrl = $encryptUrl.base64_encode($notificationUrl);
|
|
|
122 |
$defaultEncryptedData = $this->make_request($encryptUrl,null);
|
|
|
123 |
return $defaultEncryptedData;
|
|
|
124 |
}
|
|
|
125 |
function decrypt($encryptData){
|
| 18208 |
manas |
126 |
$encryptUrl = 'http://104.200.25.40:8057/message/encrypt?type=decrypt&data=';
|
| 18135 |
manas |
127 |
$encryptUrl = $encryptUrl.$encryptData;
|
|
|
128 |
$encryptedData = $this->make_request($encryptUrl,null);
|
|
|
129 |
return($encryptedData);
|
|
|
130 |
}
|
|
|
131 |
function num_decode($value){
|
|
|
132 |
$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
|
133 |
$number=0;
|
|
|
134 |
foreach(str_split($value) as $letter) {
|
|
|
135 |
$number=($number*64) + strpos($alphabet,$letter);
|
|
|
136 |
}
|
|
|
137 |
return $number;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
function num_encode($id){
|
|
|
141 |
$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
|
142 |
$shortenedId = '';
|
|
|
143 |
while($id>0) {
|
|
|
144 |
$remainder = $id % 64;
|
|
|
145 |
$id = ($id-$remainder) / 64;
|
|
|
146 |
$shortenedId = $alphabet{$remainder} . $shortenedId;
|
|
|
147 |
}
|
|
|
148 |
return $shortenedId;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
function getDatabaseConnection(){
|
| 18208 |
manas |
152 |
$servername = "localhost";
|
| 18135 |
manas |
153 |
$username = "root";
|
|
|
154 |
$password = "shop2020";
|
|
|
155 |
$databaseName="dtr";
|
|
|
156 |
$conn = mysql_connect($servername,$username,$password);
|
|
|
157 |
if(!$conn){
|
|
|
158 |
return false;
|
|
|
159 |
}else{
|
|
|
160 |
$databaseConnection = mysql_select_db($databaseName, $conn);
|
|
|
161 |
if(!$databaseConnection){
|
|
|
162 |
return false;
|
|
|
163 |
}else{
|
|
|
164 |
return $conn;
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|
| 18148 |
manas |
168 |
function error(){
|
|
|
169 |
$this->layout='ajax';
|
|
|
170 |
$name='Sorry';
|
|
|
171 |
$this->set(compact('name'));
|
|
|
172 |
}
|
| 18192 |
manas |
173 |
|
|
|
174 |
public function mobile() {
|
|
|
175 |
$this->layout='ajax';
|
|
|
176 |
}
|
|
|
177 |
function isMobileDevice($userAgent){
|
|
|
178 |
$aMobileUA = array(
|
|
|
179 |
// '/iphone/i' => 'iPhone',
|
|
|
180 |
// '/ipod/i' => 'iPod',
|
|
|
181 |
// '/ipad/i' => 'iPad',
|
|
|
182 |
'/android/i' => 'Android',
|
|
|
183 |
// '/blackberry/i' => 'BlackBerry',
|
|
|
184 |
// '/webos/i' => 'Mobile'
|
|
|
185 |
);
|
|
|
186 |
|
|
|
187 |
foreach($aMobileUA as $sMobileKey => $sMobileOS){
|
|
|
188 |
if(preg_match($sMobileKey,$userAgent)){
|
|
|
189 |
return true;
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
return false;
|
|
|
193 |
}
|
| 18208 |
manas |
194 |
}
|