| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('Controller', 'Controller');
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
* Application Controller
|
|
|
6 |
*
|
|
|
7 |
* Add your application-wide methods in the class below, your controllers
|
|
|
8 |
* will inherit them.
|
|
|
9 |
*
|
|
|
10 |
* @package app.Controller
|
|
|
11 |
* @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
|
|
|
12 |
*/
|
|
|
13 |
class AppController extends Controller {
|
| 13808 |
anikendra |
14 |
|
|
|
15 |
public $limit;
|
|
|
16 |
public $apihost;
|
| 15311 |
anikendra |
17 |
public $acls;
|
| 13808 |
anikendra |
18 |
|
| 13532 |
anikendra |
19 |
public $components = array(
|
| 14970 |
anikendra |
20 |
'Session','Resize','Cookie',
|
| 13532 |
anikendra |
21 |
'Auth' => array(
|
|
|
22 |
'loginAction' => array('controller' => 'users', 'action' => 'login'),
|
|
|
23 |
'allowedActions' => array('index', 'view', 'display')
|
|
|
24 |
)
|
|
|
25 |
);
|
| 13808 |
anikendra |
26 |
|
| 13532 |
anikendra |
27 |
var $helpers = array('Session', 'Form', 'Html');
|
|
|
28 |
var $keywords = array('instagram followers','instagram button','instagram follow back','instagram tool','instagram automation','free istagram followers','instagram stats','instagram follow button');
|
|
|
29 |
|
|
|
30 |
function beforeFilter() {
|
| 13659 |
anikendra |
31 |
$this->Auth->autoRedirect = false;
|
| 13579 |
anikendra |
32 |
|
|
|
33 |
//Set config settings according to domain
|
| 13532 |
anikendra |
34 |
// get host name from URL
|
|
|
35 |
preg_match('@^(?:http://)?([^/]+)@i',$_SERVER['HTTP_HOST'], $matches);
|
|
|
36 |
$host = $matches[1];
|
|
|
37 |
switch($host){
|
| 13567 |
anikendra |
38 |
case 'localdtr':
|
| 13532 |
anikendra |
39 |
Configure::load('dev');
|
|
|
40 |
break;
|
| 13946 |
anikendra |
41 |
case 'staging.profittill.com':
|
|
|
42 |
case 'www.staging.profittill.com':
|
| 13944 |
anikendra |
43 |
Configure::load('staging');
|
|
|
44 |
break;
|
| 13532 |
anikendra |
45 |
default:
|
| 13567 |
anikendra |
46 |
case 'www.profittill.com':
|
|
|
47 |
case 'profittill.com':
|
| 13633 |
anikendra |
48 |
case 'api.profittill.com':
|
| 13532 |
anikendra |
49 |
Configure::load('live');
|
|
|
50 |
break;
|
|
|
51 |
}
|
| 13579 |
anikendra |
52 |
$facebookConfig = Configure::read("Facebook");
|
|
|
53 |
$categories = Configure::read('Categories');
|
| 16989 |
anikendra |
54 |
if($this->params->params['controller'] == 'categories' || $this->params->params['controller'] == 'orders' || $this->params->params['controller'] == 'store_products' || $this->params->params['controller'] == 'brands'){
|
| 16724 |
anikendra |
55 |
//Check access for apps tab
|
|
|
56 |
$userId = $this->request->query('user_id');
|
| 16729 |
anikendra |
57 |
if($this->isAuthorized()) {
|
|
|
58 |
$userId = $this->Auth->user('id');
|
|
|
59 |
}
|
| 16724 |
anikendra |
60 |
$cachekey = 'appacls-'.$userId;
|
|
|
61 |
$access = Cache::read($cachekey,'day');
|
|
|
62 |
if(empty($access)) {
|
|
|
63 |
$this->loadModel('Appacl');
|
|
|
64 |
$this->Appacl->recursive = -1;
|
|
|
65 |
$conditions = array('user_id'=>$userId);
|
|
|
66 |
$access = $this->Appacl->find('first',array('conditions'=>$conditions));
|
|
|
67 |
if(empty($access) || $access['Appacl']['access']==0){
|
|
|
68 |
unset($categories[2]);
|
|
|
69 |
$this->set('noappcashback',true);
|
|
|
70 |
}
|
|
|
71 |
Cache::write($cachekey,$access,'day');
|
|
|
72 |
}
|
| 16679 |
anikendra |
73 |
}
|
| 13532 |
anikendra |
74 |
//Facebook configuration
|
|
|
75 |
$this->set('fbappid', $facebookConfig['fbappid']);
|
| 13579 |
anikendra |
76 |
$this->set('apihost', Configure::read('apihost'));
|
|
|
77 |
|
| 13532 |
anikendra |
78 |
$sessionState = $this->Session->read('state');
|
|
|
79 |
if(!isset($sessionState)){
|
|
|
80 |
$this->Session->write('state' , md5(uniqid(rand(), TRUE))); // CSRF protection
|
|
|
81 |
}
|
|
|
82 |
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
|
|
|
83 |
. $facebookConfig['fbappid'] . "&redirect_uri=" . urlencode($facebookConfig['base_url'].'/users/checkfbuser/') . "&state="
|
|
|
84 |
. $this->Session->read('state').'&scope=publish_stream,email,user_birthday,publish_actions,user_location';
|
|
|
85 |
$this->set('dialog_url', $dialog_url);
|
|
|
86 |
$this->set('description','Why spend money when you can get something for free');
|
| 13579 |
anikendra |
87 |
$this->set('categories',$categories);
|
| 13532 |
anikendra |
88 |
if(isset($this->params['admin'])) {
|
| 13739 |
anikendra |
89 |
$this->layout = 'admin';
|
| 13808 |
anikendra |
90 |
}
|
|
|
91 |
$this->apihost = Configure::read('pythonapihost');
|
|
|
92 |
$this->limit = Configure::read('dealsperpage');
|
| 13685 |
anikendra |
93 |
$staticVersion = Configure::read('staticversion');
|
|
|
94 |
$this->set('staticversion',$staticVersion);
|
| 14929 |
anikendra |
95 |
$this->set('requiremobileverification',Configure::read('requiremobileverification'));
|
| 14970 |
anikendra |
96 |
$debugusers = Configure::read('debugusers');
|
|
|
97 |
if($id = $this->isAuthorized()){
|
|
|
98 |
if(in_array($id, $debugusers)){
|
|
|
99 |
$this->Cookie->write('debuguser',1);
|
|
|
100 |
}else{
|
|
|
101 |
$this->Cookie->delete('debuguser');
|
|
|
102 |
}
|
|
|
103 |
}
|
| 15188 |
anikendra |
104 |
//acl
|
|
|
105 |
$cachekey = 'acls';
|
|
|
106 |
$acls = Cache::read($cachekey,'month');
|
|
|
107 |
if(empty($acls)) {
|
|
|
108 |
$acls = array();
|
|
|
109 |
$this->loadModel('Acl');
|
|
|
110 |
$result = $this->Acl->find('all');
|
|
|
111 |
foreach ($result as $key => $value) {
|
|
|
112 |
if($value['Acl']['access']) {
|
|
|
113 |
$acls[$value['Acl']['group_id']]['allowed'][] = $value['Acl']['action'];
|
|
|
114 |
}else{
|
|
|
115 |
$acls[$value['Acl']['group_id']]['disallowed'][] = $value['Acl']['action'];
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
Cache::write($cachekey,$acls,'month');
|
|
|
119 |
}
|
| 15311 |
anikendra |
120 |
$this->acls = $acls;
|
| 15188 |
anikendra |
121 |
$this->set('acls',$acls);
|
| 13532 |
anikendra |
122 |
}
|
|
|
123 |
|
| 15311 |
anikendra |
124 |
function checkAcl() {
|
|
|
125 |
if(!in_array($this->here,$this->acls[$this->Session->read('Auth.User.group_id')]['allowed'])){
|
| 15227 |
anikendra |
126 |
$this->Session->setFlash(__('You are not authorized to access this page.'));
|
|
|
127 |
return $this->redirect(array('controller'=>'administration','action' => 'dashboard','admin'=>false));
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
|
| 13532 |
anikendra |
131 |
function isAuthorized() {
|
|
|
132 |
return $this->Auth->user('id');
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
function isFbAuthorized() {
|
|
|
136 |
return $this->Session->read('facebook_id');
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
function afterFilter() {
|
| 13579 |
anikendra |
140 |
$result['ucadcode'] = $this->ucadcode;
|
| 13532 |
anikendra |
141 |
}
|
|
|
142 |
|
| 13659 |
anikendra |
143 |
function beforeRender() {
|
| 13736 |
anikendra |
144 |
$logged_user = $this->Auth->user();
|
|
|
145 |
$this->set('logged_user', $logged_user);
|
| 13579 |
anikendra |
146 |
$this->set('base_url', 'http://' . $_SERVER['SERVER_NAME'] . Router::url('/'));
|
| 13532 |
anikendra |
147 |
}
|
|
|
148 |
|
| 13736 |
anikendra |
149 |
function checkMobileNumber() {
|
|
|
150 |
$logged_user = $this->Auth->user();
|
|
|
151 |
if(empty($logged_user['mobile_verified']) && $this->params['controller'] !='users') {
|
|
|
152 |
$skipmobileverification = $this->Session->read('skipmobileverification');
|
|
|
153 |
if(!isset($skipmobileverification) || empty($skipmobileverification)) {
|
|
|
154 |
$this->redirect('/users/verifymobile');
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
|
| 15335 |
anikendra |
159 |
function checkToken($userId = null) {
|
|
|
160 |
$headers = $this->getallheaders();
|
| 14890 |
anikendra |
161 |
$this->log(print_r($headers,1),'headers');
|
| 14897 |
anikendra |
162 |
$token = $_COOKIE['token'];
|
| 15188 |
anikendra |
163 |
$checkToken = $_COOKIE['walletAuthentication'];
|
| 14894 |
anikendra |
164 |
$this->log("Token : $token",'headers');
|
| 15188 |
anikendra |
165 |
$this->log("CheckToken : $checkToken",'headers');
|
|
|
166 |
if(isset($checkToken) && !empty($checkToken) && isset($token) && !empty($token)) {
|
| 15335 |
anikendra |
167 |
$this->loadModel('SocialProfile');
|
|
|
168 |
$options = array('conditions'=>array('access_token'=>$token),'fields'=>array('user_id'),'recursive'=>-1);
|
|
|
169 |
$user = $this->SocialProfile->find('first',$options);
|
| 15767 |
anikendra |
170 |
$this->log($userId." ".print_r($user['SocialProfile'],1),'headers');
|
| 15380 |
anikendra |
171 |
/*if(!$userId){
|
| 15335 |
anikendra |
172 |
$userId = $this->request->query('user_id');
|
| 15767 |
anikendra |
173 |
} */
|
| 15335 |
anikendra |
174 |
if(isset($userId) && !empty($userId)){
|
|
|
175 |
if($userId == $user['SocialProfile']['user_id']){
|
| 15380 |
anikendra |
176 |
$this->log("User authenticated",'headers');
|
| 15651 |
anikendra |
177 |
return 1;//success
|
| 15335 |
anikendra |
178 |
} else{
|
|
|
179 |
// token mismatch, so maybe hack attempt
|
| 15380 |
anikendra |
180 |
$this->log("Mismatch hence user not authenticated",'headers');
|
| 15651 |
anikendra |
181 |
return 0;//fail
|
| 15335 |
anikendra |
182 |
}
|
|
|
183 |
} else {
|
|
|
184 |
// userId is not sent so maybe hack attempt
|
| 15380 |
anikendra |
185 |
$this->log("Id not sent hence user not authenticated",'headers');
|
| 15651 |
anikendra |
186 |
return 0;//fail
|
| 15335 |
anikendra |
187 |
}
|
| 15380 |
anikendra |
188 |
} else {
|
|
|
189 |
$this->log("Old User hence pass",'headers');
|
| 16308 |
anikendra |
190 |
return -1;//token not set in cookie
|
| 14890 |
anikendra |
191 |
}
|
|
|
192 |
}
|
|
|
193 |
|
| 13659 |
anikendra |
194 |
function getallheaders() {
|
|
|
195 |
$headers = '';
|
|
|
196 |
foreach ($_SERVER as $name => $value)
|
|
|
197 |
{
|
|
|
198 |
if (substr($name, 0, 5) == 'HTTP_')
|
|
|
199 |
{
|
|
|
200 |
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
return $headers;
|
|
|
204 |
}
|
| 13633 |
anikendra |
205 |
|
| 15015 |
anikendra |
206 |
public function getDealsApiUrl($page=1,$userId = null,$categoryId=0,$sort=null,$direction=null,$filter=null,$brands=null){
|
| 13808 |
anikendra |
207 |
$this->log('categoryId '.$categoryId,'api');
|
|
|
208 |
$this->log('page '.$page,'api');
|
|
|
209 |
$offset = ($page - 1) * $this->limit;
|
|
|
210 |
if(isset($sort) && !empty($sort) && $sort!=-1){
|
|
|
211 |
$url = $this->apihost.'deals/'.$userId.'?categoryId='.$categoryId.'&sort='.$sort.'&direction='.$direction.'&limit='.$this->limit.'&offset='.$offset;
|
|
|
212 |
}else{
|
|
|
213 |
$url = $this->apihost.'deals/'.$userId.'?categoryId='.$categoryId.'&limit='.$this->limit.'&offset='.$offset;
|
|
|
214 |
}
|
| 15015 |
anikendra |
215 |
if(isset($filter) && !empty($filter)){
|
|
|
216 |
$url .= "&filterData=brandFilter:".$brands;
|
|
|
217 |
}
|
| 13808 |
anikendra |
218 |
return $url;
|
|
|
219 |
}
|
|
|
220 |
|
| 13633 |
anikendra |
221 |
function make_request($url,$fields,$format='json'){
|
| 13683 |
anikendra |
222 |
$this->log("[url] $url",'api');
|
|
|
223 |
$this->log("[fields] ".print_r($fields,1),'api');
|
| 13633 |
anikendra |
224 |
$fields_string = '';
|
|
|
225 |
//open connection
|
|
|
226 |
$ch = curl_init();
|
|
|
227 |
//set the url, number of POST vars, POST data
|
|
|
228 |
curl_setopt($ch,CURLOPT_URL, $url);
|
|
|
229 |
curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
|
|
|
230 |
if(!empty($fields)) {
|
|
|
231 |
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
|
|
|
232 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
233 |
'Content-Type: application/json',
|
| 13994 |
anikendra |
234 |
// 'Content-Length: ' . sizeof($fields))
|
|
|
235 |
'Content-Length: ' . strlen($fields))
|
| 13633 |
anikendra |
236 |
);
|
|
|
237 |
}
|
|
|
238 |
//execute post
|
|
|
239 |
$result = curl_exec($ch);
|
| 15335 |
anikendra |
240 |
$this->log("[response] ".print_r($result,1),'api');
|
| 13633 |
anikendra |
241 |
//close connection
|
|
|
242 |
curl_close($ch);
|
|
|
243 |
switch($format){
|
|
|
244 |
case 'json':
|
|
|
245 |
$response = json_decode($result,1);
|
|
|
246 |
break;
|
|
|
247 |
}
|
|
|
248 |
return $response;
|
|
|
249 |
}
|
| 13901 |
anikendra |
250 |
|
| 14016 |
anikendra |
251 |
function post_request($url,$fields,$format='json'){
|
|
|
252 |
$this->log("[url] $url",'api');
|
|
|
253 |
$this->log("[fields] ".print_r($fields,1),'api');
|
|
|
254 |
$fields_string = '';
|
|
|
255 |
//open connection
|
|
|
256 |
$ch = curl_init();
|
|
|
257 |
//execute post
|
|
|
258 |
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
|
|
|
259 |
rtrim($fields_string, '&');
|
|
|
260 |
//set the url, number of POST vars, POST data
|
|
|
261 |
curl_setopt($ch,CURLOPT_URL, $url);
|
|
|
262 |
curl_setopt($ch,CURLOPT_POST, count($fields));
|
|
|
263 |
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
|
|
|
264 |
$result = curl_exec($ch);
|
|
|
265 |
$this->log("[response] ".print_r($result,1),'api');
|
|
|
266 |
//close connection
|
|
|
267 |
curl_close($ch);
|
|
|
268 |
switch($format){
|
|
|
269 |
case 'json':
|
|
|
270 |
$response = json_decode($result,1);
|
|
|
271 |
break;
|
|
|
272 |
}
|
|
|
273 |
return $response;
|
|
|
274 |
}
|
| 14215 |
anikendra |
275 |
|
| 13901 |
anikendra |
276 |
public function get_solr_result($q,$page) {
|
| 16363 |
anikendra |
277 |
$dealsperpage = Configure::read('searchresultsperpage');
|
| 13901 |
anikendra |
278 |
$offset = ($page - 1)*$dealsperpage;
|
| 13993 |
anikendra |
279 |
$cond = "$q";
|
| 13901 |
anikendra |
280 |
$sort = "store desc";
|
|
|
281 |
|
|
|
282 |
$params = array(
|
|
|
283 |
'conditions' =>array(
|
|
|
284 |
'solr_query' => $cond
|
|
|
285 |
),
|
|
|
286 |
//'order' => $sort,
|
|
|
287 |
'offset' => $offset,
|
|
|
288 |
'limit' => $dealsperpage
|
|
|
289 |
);
|
| 14215 |
anikendra |
290 |
$this->loadModel('Solr');
|
| 13901 |
anikendra |
291 |
$solroutput = $this->Solr->find('all', $params);
|
|
|
292 |
$result = array();
|
| 14215 |
anikendra |
293 |
if(sizeof($solroutput)<$dealsperpage){
|
|
|
294 |
$hasMore = false;
|
|
|
295 |
}else{
|
|
|
296 |
$hasMore = true;
|
|
|
297 |
}
|
| 13901 |
anikendra |
298 |
if(!empty($solroutput['Solr'])) {
|
|
|
299 |
$skuMap = array();
|
| 14215 |
anikendra |
300 |
foreach ($solroutput['Solr'] as $key => $value) {
|
| 14432 |
anikendra |
301 |
// if(!$value['in_stock'])continue;
|
| 13901 |
anikendra |
302 |
$skuMap[$value['id']] = $value;
|
|
|
303 |
$result[$value['skuBundleId']][$value['id']] = $value['available_price'];
|
| 14215 |
anikendra |
304 |
}
|
|
|
305 |
if(!empty($result)) {
|
|
|
306 |
foreach ($result as $key => $value) {
|
|
|
307 |
asort($value);
|
|
|
308 |
$lowestPriceSku = key($value);
|
|
|
309 |
$result[$key] = $skuMap[$lowestPriceSku];
|
|
|
310 |
}
|
| 13901 |
anikendra |
311 |
}
|
| 14215 |
anikendra |
312 |
}
|
|
|
313 |
$result['hasMore'] = $hasMore;
|
| 13901 |
anikendra |
314 |
return $result;
|
|
|
315 |
}
|
| 14098 |
anikendra |
316 |
|
|
|
317 |
public function admin_update(){
|
|
|
318 |
$this->response->type('json');
|
|
|
319 |
$this->layout = 'ajax';
|
|
|
320 |
$data[$this->request->data['id']] = $this->request->data['value'];
|
|
|
321 |
$data['oid'] = $this->request->data['oid'];
|
| 14584 |
anikendra |
322 |
$id = $this->request->data['id'];
|
|
|
323 |
$multi = $this->request->data['multi'];
|
| 14098 |
anikendra |
324 |
if($this->modelClass == 'Exceptionalskudiscount') {
|
|
|
325 |
$data['class'] = 'SkuDiscountInfo';
|
|
|
326 |
}elseif($this->modelClass == 'Skuscheme'){
|
| 16234 |
anikendra |
327 |
if($id == 'dp' || $id == 'showDp'){
|
| 14584 |
anikendra |
328 |
$data['class'] = 'SkuDealerPrices';
|
|
|
329 |
}else{
|
|
|
330 |
$data['class'] = 'SkuSchemeDetails';
|
|
|
331 |
}
|
| 14426 |
anikendra |
332 |
}elseif($this->modelClass == 'Exceptionalnlc'){
|
|
|
333 |
$data['class'] = 'ExceptionalNlc';
|
| 16494 |
anikendra |
334 |
}elseif($this->modelClass == 'ManualDeal' && ($id == 'dealPoints' || $id == 'dealThresholdPrice')){
|
|
|
335 |
$data['class'] = 'DealPoints';
|
| 14426 |
anikendra |
336 |
}
|
|
|
337 |
else{
|
| 14098 |
anikendra |
338 |
$data['class'] = $this->modelClass;
|
|
|
339 |
}
|
| 14584 |
anikendra |
340 |
$data_string = json_encode($data,JSON_NUMERIC_CHECK);
|
| 14098 |
anikendra |
341 |
$ch = curl_init();
|
|
|
342 |
$url = $this->apihost.'Catalog/updateCollection';
|
| 14584 |
anikendra |
343 |
if(isset($multi) && $multi==1){
|
|
|
344 |
$url .= "/?multi=1";
|
|
|
345 |
}
|
| 14098 |
anikendra |
346 |
$this->log("[url] $url",'api');
|
|
|
347 |
$this->log("[fields] ".print_r($data_string,1),'api');
|
|
|
348 |
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
349 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
350 |
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
351 |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // note the PUT here
|
|
|
352 |
|
|
|
353 |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
|
|
354 |
curl_setopt($ch, CURLOPT_HEADER, true);
|
|
|
355 |
|
|
|
356 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
357 |
'Content-Type: application/json',
|
|
|
358 |
'Content-Length: ' . strlen($data_string)
|
|
|
359 |
));
|
|
|
360 |
|
|
|
361 |
// execute the request
|
|
|
362 |
|
|
|
363 |
$output = curl_exec($ch);
|
|
|
364 |
$result = $this->request->data['value'];
|
|
|
365 |
$this->log("[response] ".print_r($output,1),'api');
|
|
|
366 |
curl_close($ch);
|
|
|
367 |
$this->set(array(
|
|
|
368 |
'result' => $result,
|
|
|
369 |
'_serialize' => array('result')
|
|
|
370 |
));
|
|
|
371 |
$this->render('/Elements/json');
|
|
|
372 |
}
|
| 14150 |
anikendra |
373 |
|
| 14509 |
anikendra |
374 |
public function remove($id,$class){
|
|
|
375 |
$data['oid'] = $id;
|
|
|
376 |
$data['class'] = $class;
|
|
|
377 |
|
|
|
378 |
$data_string = json_encode($data,JSON_NUMERIC_CHECK);
|
|
|
379 |
$ch = curl_init();
|
|
|
380 |
$url = $this->apihost.'Catalog/deleteDocument';
|
|
|
381 |
$this->log("[url] $url",'api');
|
|
|
382 |
$this->log("[fields] ".print_r($data_string,1),'api');
|
|
|
383 |
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
384 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
385 |
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
386 |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // note the PUT here
|
|
|
387 |
|
|
|
388 |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
| 15848 |
anikendra |
389 |
// curl_setopt($ch, CURLOPT_HEADER, true);
|
| 14509 |
anikendra |
390 |
|
|
|
391 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
392 |
'Content-Type: application/json',
|
|
|
393 |
'Content-Length: ' . strlen($data_string)
|
|
|
394 |
));
|
|
|
395 |
|
|
|
396 |
// execute the request
|
|
|
397 |
|
|
|
398 |
$output = curl_exec($ch);
|
| 15848 |
anikendra |
399 |
// $result = $this->request->data['value'];
|
| 14509 |
anikendra |
400 |
$this->log("[response] ".print_r($output,1),'api');
|
|
|
401 |
curl_close($ch);
|
|
|
402 |
// $this->set(array(
|
|
|
403 |
// 'result' => $result,
|
|
|
404 |
// '_serialize' => array('result')
|
|
|
405 |
// ));
|
|
|
406 |
// $this->render('/Elements/json');
|
| 15848 |
anikendra |
407 |
$result = json_decode($output,1);
|
| 14509 |
anikendra |
408 |
return $result;
|
|
|
409 |
}
|
|
|
410 |
|
| 14150 |
anikendra |
411 |
function getAutoLoginUrl($userId,$next) {
|
| 14996 |
anikendra |
412 |
$saholicoffline = Configure::read('saholicoffline');
|
|
|
413 |
if($saholicoffline) {
|
|
|
414 |
$url = "/abouts/saholicoffline";
|
|
|
415 |
return $url;
|
|
|
416 |
}
|
| 14150 |
anikendra |
417 |
$this->loadModel('User');
|
|
|
418 |
$this->User->Behaviors->attach('Containable');
|
| 14166 |
anikendra |
419 |
$options = array('contain'=>array('UserAccount'), 'conditions'=>array('User.id'=>$userId),'fields'=>array('username','email'),'recursive'=>-1);
|
| 14150 |
anikendra |
420 |
$user = $this->User->find('first',$options);
|
| 15380 |
anikendra |
421 |
$this->log("user_accounts ".print_r($user,1),'headers');
|
| 14441 |
anikendra |
422 |
$data = array('email'=>$user['User']['email'],'Id'=>$user['UserAccount'][0]['account_key'],'cartId' => $user['UserAccount'][1]['account_key'],'isPrivateDealUser'=>1,'next'=>$next);
|
| 14150 |
anikendra |
423 |
$data = '?data='.base64_encode(serialize($data));
|
|
|
424 |
$token = '&token='.md5(Configure::read('saholicapikey').'|'.$user['UserAccount'][0]['account_key']);
|
| 15335 |
anikendra |
425 |
$url = Configure::read('saholicapihost')."login!authorizeProfitMandiUser?userId=".$user['UserAccount'][0]['account_key']."&source=ProfitMandi";
|
| 15380 |
anikendra |
426 |
$result = $this->make_request($url,null);
|
|
|
427 |
$this->log(print_r($result,1),'headers');
|
| 15335 |
anikendra |
428 |
if(!empty($result['tokenString'])){
|
|
|
429 |
$token = '&token='.$result['tokenString'];
|
|
|
430 |
return Configure::read('saholicauthurl').$data.$token.'&v=2';
|
|
|
431 |
}
|
| 14441 |
anikendra |
432 |
return Configure::read('saholicauthurl').$data.$token;
|
| 14150 |
anikendra |
433 |
}
|
| 14509 |
anikendra |
434 |
|
|
|
435 |
function createUploadDirectory($modelClass) {
|
|
|
436 |
//Create directory
|
|
|
437 |
if (!is_dir(WWW_ROOT.'uploads'.DS.$modelClass)) {
|
|
|
438 |
$this->log("making directory for $modelClass". WWW_ROOT.DS.'uploads'.DS.$modelClass);
|
|
|
439 |
mkdir(WWW_ROOT.'uploads'.DS.$modelClass,0777);
|
|
|
440 |
}
|
|
|
441 |
if (!is_dir(WWW_ROOT.'uploads'.DS.$modelClass)) {
|
|
|
442 |
$this->log("failed to create directory for $modelClass");
|
|
|
443 |
return false;
|
|
|
444 |
} else {
|
|
|
445 |
return true;
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
public function upload() {
|
|
|
450 |
$result['status'] = 0;
|
|
|
451 |
$result['success'] = false;
|
|
|
452 |
$result['message'] = __('Unable to upload');
|
|
|
453 |
|
|
|
454 |
App::import('Vendor','qqFileUploader',array('file' =>'qqFileUploader.php'));
|
|
|
455 |
|
|
|
456 |
$uploader = new qqFileUploader();
|
|
|
457 |
|
|
|
458 |
// Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp")
|
|
|
459 |
$uploader->allowedExtensions = array('jpeg','png','jpg','gif','bmp');
|
|
|
460 |
|
|
|
461 |
// Specify max file size in bytes.
|
|
|
462 |
$uploader->sizeLimit = 10 * 1024 * 1024;
|
|
|
463 |
|
|
|
464 |
// Specify the input name set in the javascript.
|
|
|
465 |
$uploader->inputName = 'qqfile';
|
|
|
466 |
|
|
|
467 |
// If you want to use resume feature for uploader, specify the folder to save parts.
|
|
|
468 |
$uploader->chunksFolder = 'chunks';
|
|
|
469 |
|
|
|
470 |
// $min_width = isset($this->request->data['minwidth']) ? $this->request->data['minwidth'] : 0;
|
|
|
471 |
// $min_height = isset($this->request->data['minheight']) ? $this->request->data['minheight'] : 0;
|
|
|
472 |
$modelClass = $this->modelClass;
|
|
|
473 |
|
|
|
474 |
$this->log($this->request);
|
|
|
475 |
$folderName = Inflector::pluralize(strtolower($modelClass));
|
|
|
476 |
|
|
|
477 |
if (!$this->createUploadDirectory($folderName)) {
|
|
|
478 |
$result['message'] = 'Failed to create directory :'.$modelClass.
|
|
|
479 |
'. Sorry we are having trouble. Please try again, or email help@profittill.com';
|
|
|
480 |
} else {
|
|
|
481 |
// To save the upload with a specified name, set the second parameter
|
|
|
482 |
$result = $uploader->handleUpload('uploads'.DS.$folderName.DS, $uploader->getName());
|
|
|
483 |
if($result){
|
|
|
484 |
//Resize and create thumbnail
|
|
|
485 |
$inFile = WWW_ROOT.'uploads'.DS.$folderName.DS. $uploader->getName();
|
|
|
486 |
|
|
|
487 |
$largeOutFile = WWW_ROOT.'uploads'.DS.$folderName.DS.'large-'.basename($inFile);
|
|
|
488 |
$this->resizeImage($inFile,$largeOutFile,800,800);
|
|
|
489 |
|
|
|
490 |
$outFile = WWW_ROOT.'uploads'.DS.$folderName.DS.'small-'.basename($inFile);
|
|
|
491 |
$this->resizeImage($inFile,$outFile,200,200);
|
|
|
492 |
|
|
|
493 |
$newUrl = '/uploads/'.$folderName.'/'.basename($inFile);
|
|
|
494 |
// To return a name used for uploaded file you can use the following line.
|
|
|
495 |
$result['uploadName'] = $newUrl;
|
|
|
496 |
|
|
|
497 |
$result['status'] = 1;
|
|
|
498 |
$result['success'] = true;
|
|
|
499 |
// $result['filesize'] = $filesize;
|
|
|
500 |
$result['message'] = __('Uploaded');
|
|
|
501 |
}
|
|
|
502 |
}
|
|
|
503 |
$this->log($result);
|
|
|
504 |
return new CakeResponse(array('body' => json_encode($result)));
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
function cropImage ($url, $height, $width, $x1, $x2, $y1, $y2) {
|
|
|
508 |
ini_set('memory_limit', '2G');
|
|
|
509 |
$result['status'] = 0;
|
|
|
510 |
$result['message'] = __('Unable to crop');
|
|
|
511 |
|
|
|
512 |
$image_type = substr($url, strrpos($url, '.', -1));
|
|
|
513 |
$filepath = WWW_ROOT.substr($url, strlen(FULL_BASE_URL)+1);
|
|
|
514 |
$croppedfile = substr($filepath, 0, strrpos($filepath, '/', -1)).
|
|
|
515 |
'/C_'.substr($filepath, strrpos($filepath, '/', -1)+1);
|
|
|
516 |
|
|
|
517 |
// Create image instances
|
|
|
518 |
$dest = imagecreatetruecolor($x2,$y2);
|
|
|
519 |
|
|
|
520 |
switch ($image_type) {
|
|
|
521 |
case '.jpg':
|
|
|
522 |
case '.jpeg':
|
|
|
523 |
case '.JPEG':
|
|
|
524 |
case '.JPG':
|
|
|
525 |
$src = imagecreatefromjpeg($filepath);
|
|
|
526 |
imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
|
|
|
527 |
imagejpeg($dest, $croppedfile);
|
|
|
528 |
$ext = '.jpg';
|
|
|
529 |
break;
|
|
|
530 |
case '.gif':
|
|
|
531 |
$src = imagecreatefromgif($filepath);
|
|
|
532 |
imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
|
|
|
533 |
imagegif($dest, $croppedfile);
|
|
|
534 |
$ext = '.gif';
|
|
|
535 |
break;
|
|
|
536 |
case '.png':
|
|
|
537 |
$src = imagecreatefrompng($filepath);
|
|
|
538 |
imagecopyresampled($dest,$src,0,0,$x1,$y1,$x2,$y2,$width,$height);
|
|
|
539 |
imagepng($dest, $croppedfile);
|
|
|
540 |
$ext = '.png';
|
|
|
541 |
break;
|
|
|
542 |
default:
|
|
|
543 |
$result['message'] = __('Unsupported image format.');
|
|
|
544 |
return $result;
|
|
|
545 |
}
|
|
|
546 |
$result['status'] = 1;
|
|
|
547 |
$result['message'] = __('Cropped');
|
|
|
548 |
$result['data'] = substr($url, 0, strrpos($url, '/', -1)).'/C_'.substr($url, strrpos($url, '/', -1)+1);
|
|
|
549 |
return $result;
|
|
|
550 |
}
|
|
|
551 |
|
|
|
552 |
function resizeImage ($inFile, $outFile, $w, $h) {
|
|
|
553 |
$image = $this->Resize;
|
|
|
554 |
$image->load($inFile);
|
|
|
555 |
$image->crop($w,$h);
|
|
|
556 |
$image->save($outFile);
|
|
|
557 |
}
|
|
|
558 |
|
|
|
559 |
public function crop() {
|
|
|
560 |
$url = $this->request->data['file_url'];
|
|
|
561 |
$height = $this->request->data['h'];
|
|
|
562 |
$width = $this->request->data['w'];
|
|
|
563 |
$x1 = $this->request->data['x'];
|
|
|
564 |
$x2 = $this->request->data['x2'];
|
|
|
565 |
$y1 = $this->request->data['y'];
|
|
|
566 |
$y2 = $this->request->data['y2'];
|
|
|
567 |
|
|
|
568 |
$result = $this->cropImage($url, $height, $width, $x1, $x2, $y1, $y2);
|
|
|
569 |
|
|
|
570 |
$this->set('result', $result);
|
|
|
571 |
$this->set('_serialize', array('result'));
|
|
|
572 |
}
|
| 14561 |
anikendra |
573 |
|
|
|
574 |
public function generateMultiUrl($url,&$data){
|
|
|
575 |
if(!empty($data['multi']) && $data['multi']==1){
|
|
|
576 |
$url .= '/?multi=1';
|
|
|
577 |
}
|
|
|
578 |
unset($data['multi']);
|
|
|
579 |
return $url;
|
|
|
580 |
}
|
| 15378 |
anikendra |
581 |
|
|
|
582 |
public function markUserActivated($id){
|
| 15383 |
anikendra |
583 |
$url = Configure::read('pythonapihost').'retailerActivated/'.$id;
|
| 15378 |
anikendra |
584 |
$this->make_request($url,null);
|
|
|
585 |
$this->loadModel('User');
|
| 17044 |
anikendra |
586 |
$sql = "UPDATE users SET activation_time = NOW() WHERE id = $id AND activation_time IS NULL";
|
| 15383 |
anikendra |
587 |
$this->User->query($sql);
|
| 16966 |
anikendra |
588 |
$this->loadModel('Appacl');
|
|
|
589 |
$data = array('user_id'=>$id,'access'=>1);
|
|
|
590 |
$count = $this->Appacl->find('count',array('conditions'=> $data));
|
|
|
591 |
if($count==0){
|
|
|
592 |
$this->Appacl->create();
|
|
|
593 |
$this->Appacl->save($data);
|
|
|
594 |
}
|
| 15378 |
anikendra |
595 |
}
|
| 15767 |
anikendra |
596 |
}
|