| 13532 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* UserUrls Controller
|
|
|
5 |
*
|
|
|
6 |
* @property UserUrl $UserUrl
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class UserUrlsController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
|
|
17 |
|
| 13591 |
anikendra |
18 |
public function beforeFilter() {
|
|
|
19 |
parent::beforeFilter();
|
|
|
20 |
$this->Auth->allow('add');
|
|
|
21 |
}
|
| 13532 |
anikendra |
22 |
/**
|
|
|
23 |
* index method
|
|
|
24 |
*
|
|
|
25 |
* @return void
|
|
|
26 |
*/
|
|
|
27 |
public function index() {
|
| 13591 |
anikendra |
28 |
throw new NotFoundException(__('Access Denied'));
|
| 13532 |
anikendra |
29 |
$this->UserUrl->recursive = 0;
|
|
|
30 |
$this->set('userUrls', $this->Paginator->paginate());
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* view method
|
|
|
35 |
*
|
|
|
36 |
* @throws NotFoundException
|
|
|
37 |
* @param string $id
|
|
|
38 |
* @return void
|
|
|
39 |
*/
|
|
|
40 |
public function view($id = null) {
|
| 13591 |
anikendra |
41 |
throw new NotFoundException(__('Access Denied'));
|
| 13532 |
anikendra |
42 |
if (!$this->UserUrl->exists($id)) {
|
|
|
43 |
throw new NotFoundException(__('Invalid user url'));
|
|
|
44 |
}
|
|
|
45 |
$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
|
|
|
46 |
$this->set('userUrl', $this->UserUrl->find('first', $options));
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* add method
|
|
|
51 |
*
|
|
|
52 |
* @return void
|
|
|
53 |
*/
|
|
|
54 |
public function add() {
|
|
|
55 |
if ($this->request->is('post')) {
|
| 13595 |
anikendra |
56 |
if(isset($this->request->data['pushdata']) && !empty($this->request->data['pushdata'])) {
|
|
|
57 |
$pushdata = json_decode($this->request->data['pushdata'],1);
|
| 14661 |
anikendra |
58 |
$pushdata['pushdata'][0]['ip'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
| 17091 |
anikendra |
59 |
/*
|
| 13595 |
anikendra |
60 |
$this->UserUrl->create();
|
|
|
61 |
if ($this->UserUrl->saveAll($pushdata['pushdata'])) {
|
|
|
62 |
$result = array('success' => true,'message'=>__('The url has been saved.'));
|
|
|
63 |
} else {
|
|
|
64 |
$result = array('success' => false,'message'=>__('The url could not be saved. Please, try again.'));
|
|
|
65 |
}
|
| 17101 |
anikendra |
66 |
*/
|
| 14934 |
anikendra |
67 |
if(isset($pushdata['pushdata'][0]['httpstatus']) && !empty($pushdata['pushdata'][0]['httpstatus'])) {
|
|
|
68 |
$this->loadModel('SaholicLog');
|
|
|
69 |
$this->SaholicLog->create();
|
|
|
70 |
$this->SaholicLog->saveAll($pushdata['pushdata']);
|
| 17101 |
anikendra |
71 |
}
|
| 17091 |
anikendra |
72 |
//Nodejs api call
|
| 17101 |
anikendra |
73 |
$url = Configure::read('nodeurl') . '/addBrowsingHistory/?pushed_by=php';
|
|
|
74 |
$this->make_request($url,json_encode($pushdata));
|
| 17091 |
anikendra |
75 |
$result = array('success' => true,'message'=>__('The url has been saved.'));
|
| 13595 |
anikendra |
76 |
$this->response->type('json');
|
|
|
77 |
$this->layout = 'ajax';
|
|
|
78 |
$this->set(array(
|
|
|
79 |
'result' => $result,
|
|
|
80 |
// 'callback' => $callback,
|
|
|
81 |
'_serialize' => array('result')
|
|
|
82 |
));
|
|
|
83 |
$this->render('/Elements/json');
|
|
|
84 |
}
|
| 13591 |
anikendra |
85 |
}
|
| 13532 |
anikendra |
86 |
}
|
|
|
87 |
|
|
|
88 |
/**
|
|
|
89 |
* edit method
|
|
|
90 |
*
|
|
|
91 |
* @throws NotFoundException
|
|
|
92 |
* @param string $id
|
|
|
93 |
* @return void
|
|
|
94 |
*/
|
|
|
95 |
public function edit($id = null) {
|
| 13591 |
anikendra |
96 |
throw new NotFoundException(__('Access Denied'));
|
| 13532 |
anikendra |
97 |
if (!$this->UserUrl->exists($id)) {
|
|
|
98 |
throw new NotFoundException(__('Invalid user url'));
|
|
|
99 |
}
|
|
|
100 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
101 |
if ($this->UserUrl->save($this->request->data)) {
|
|
|
102 |
$this->Session->setFlash(__('The user url has been saved.'));
|
|
|
103 |
return $this->redirect(array('action' => 'index'));
|
|
|
104 |
} else {
|
|
|
105 |
$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
|
|
|
106 |
}
|
|
|
107 |
} else {
|
|
|
108 |
$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
|
|
|
109 |
$this->request->data = $this->UserUrl->find('first', $options);
|
|
|
110 |
}
|
|
|
111 |
$users = $this->UserUrl->User->find('list');
|
|
|
112 |
$this->set(compact('users'));
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
/**
|
|
|
116 |
* delete method
|
|
|
117 |
*
|
|
|
118 |
* @throws NotFoundException
|
|
|
119 |
* @param string $id
|
|
|
120 |
* @return void
|
|
|
121 |
*/
|
|
|
122 |
public function delete($id = null) {
|
| 13591 |
anikendra |
123 |
throw new NotFoundException(__('Access Denied'));
|
| 13532 |
anikendra |
124 |
$this->UserUrl->id = $id;
|
|
|
125 |
if (!$this->UserUrl->exists()) {
|
|
|
126 |
throw new NotFoundException(__('Invalid user url'));
|
|
|
127 |
}
|
|
|
128 |
$this->request->onlyAllow('post', 'delete');
|
|
|
129 |
if ($this->UserUrl->delete()) {
|
|
|
130 |
$this->Session->setFlash(__('The user url has been deleted.'));
|
|
|
131 |
} else {
|
|
|
132 |
$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
|
|
|
133 |
}
|
|
|
134 |
return $this->redirect(array('action' => 'index'));
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* admin_index method
|
|
|
139 |
*
|
|
|
140 |
* @return void
|
|
|
141 |
*/
|
| 17113 |
anikendra |
142 |
public function admin_index() {
|
| 14434 |
anikendra |
143 |
$q = $this->request->query('q');
|
|
|
144 |
if(isset($q) && !empty($q)){
|
| 17113 |
anikendra |
145 |
// $this->Paginator->settings = array('conditions' => array('UserUrl.url LIKE'=>'%'.$q.'%'),'order' => array('id'=>'desc'));
|
|
|
146 |
$url = Configure::read('nodeurl') . "/searchBrowsingHistory/?search_term=$q&posted_by=php";
|
| 14654 |
anikendra |
147 |
$this->set(compact('q'));
|
|
|
148 |
} else {
|
| 17113 |
anikendra |
149 |
// $this->Paginator->settings = array('order' => array('id'=>'desc'));
|
|
|
150 |
$url = Configure::read('nodeurl') . '/getBrowsingHistory/?posted_by=php';
|
| 14654 |
anikendra |
151 |
}
|
| 17113 |
anikendra |
152 |
// $this->set('userUrls', $this->Paginator->paginate());
|
| 17101 |
anikendra |
153 |
$page = $this->request->query('page');
|
|
|
154 |
if(!isset($page)){
|
|
|
155 |
$page = 1;
|
| 17113 |
anikendra |
156 |
}
|
| 17101 |
anikendra |
157 |
$url = $this->UserUrl->getNodeUrl($url,$page);
|
|
|
158 |
$userUrls = $this->make_request($url,null);
|
|
|
159 |
$this->set(compact('userUrls', 'page'));
|
| 13532 |
anikendra |
160 |
}
|
|
|
161 |
|
|
|
162 |
/**
|
|
|
163 |
* admin_view method
|
|
|
164 |
*
|
|
|
165 |
* @throws NotFoundException
|
|
|
166 |
* @param string $id
|
|
|
167 |
* @return void
|
|
|
168 |
*/
|
|
|
169 |
public function admin_view($id = null) {
|
|
|
170 |
if (!$this->UserUrl->exists($id)) {
|
|
|
171 |
throw new NotFoundException(__('Invalid user url'));
|
|
|
172 |
}
|
|
|
173 |
$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
|
|
|
174 |
$this->set('userUrl', $this->UserUrl->find('first', $options));
|
|
|
175 |
}
|
|
|
176 |
|
| 14401 |
anikendra |
177 |
public function admin_by($userId = null) {
|
| 17101 |
anikendra |
178 |
/*$options = array('conditions' => array('UserUrl.user_id' => $userId),'order'=>array('id'=>'desc'),'limit' => 100);
|
| 14401 |
anikendra |
179 |
$this->Paginator->settings = $options;
|
|
|
180 |
$userUrls = $this->Paginator->paginate();
|
| 17101 |
anikendra |
181 |
$this->set(compact('userUrls'));*/
|
|
|
182 |
$page = $this->request->query('page');
|
|
|
183 |
if(!isset($page)){
|
|
|
184 |
$page = 1;
|
|
|
185 |
}
|
|
|
186 |
$url = Configure::read('nodeurl') . '/getBrowsingHistoryByUserId/?posted_by=php&user_id='.$userId;
|
|
|
187 |
$url = $this->UserUrl->getNodeUrl($url,$page);
|
|
|
188 |
$userUrls = $this->make_request($url,null);
|
|
|
189 |
$userInfoApiUrl = Configure::read('nodeurl') . '/getUserById/?user_id='.$userId;
|
|
|
190 |
$user = $this->make_request($userInfoApiUrl,null);
|
|
|
191 |
$this->set(compact('userUrls', 'page','user','userId'));
|
| 14401 |
anikendra |
192 |
}
|
| 13532 |
anikendra |
193 |
/**
|
|
|
194 |
* admin_add method
|
|
|
195 |
*
|
|
|
196 |
* @return void
|
|
|
197 |
*/
|
|
|
198 |
public function admin_add() {
|
|
|
199 |
if ($this->request->is('post')) {
|
|
|
200 |
$this->UserUrl->create();
|
|
|
201 |
if ($this->UserUrl->save($this->request->data)) {
|
|
|
202 |
$this->Session->setFlash(__('The user url has been saved.'));
|
|
|
203 |
return $this->redirect(array('action' => 'index'));
|
|
|
204 |
} else {
|
|
|
205 |
$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
$users = $this->UserUrl->User->find('list');
|
|
|
209 |
$this->set(compact('users'));
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
/**
|
|
|
213 |
* admin_edit method
|
|
|
214 |
*
|
|
|
215 |
* @throws NotFoundException
|
|
|
216 |
* @param string $id
|
|
|
217 |
* @return void
|
|
|
218 |
*/
|
|
|
219 |
public function admin_edit($id = null) {
|
|
|
220 |
if (!$this->UserUrl->exists($id)) {
|
|
|
221 |
throw new NotFoundException(__('Invalid user url'));
|
|
|
222 |
}
|
|
|
223 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
224 |
if ($this->UserUrl->save($this->request->data)) {
|
|
|
225 |
$this->Session->setFlash(__('The user url has been saved.'));
|
|
|
226 |
return $this->redirect(array('action' => 'index'));
|
|
|
227 |
} else {
|
|
|
228 |
$this->Session->setFlash(__('The user url could not be saved. Please, try again.'));
|
|
|
229 |
}
|
|
|
230 |
} else {
|
|
|
231 |
$options = array('conditions' => array('UserUrl.' . $this->UserUrl->primaryKey => $id));
|
|
|
232 |
$this->request->data = $this->UserUrl->find('first', $options);
|
|
|
233 |
}
|
|
|
234 |
$users = $this->UserUrl->User->find('list');
|
|
|
235 |
$this->set(compact('users'));
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
/**
|
|
|
239 |
* admin_delete method
|
|
|
240 |
*
|
|
|
241 |
* @throws NotFoundException
|
|
|
242 |
* @param string $id
|
|
|
243 |
* @return void
|
|
|
244 |
*/
|
|
|
245 |
public function admin_delete($id = null) {
|
|
|
246 |
$this->UserUrl->id = $id;
|
|
|
247 |
if (!$this->UserUrl->exists()) {
|
|
|
248 |
throw new NotFoundException(__('Invalid user url'));
|
|
|
249 |
}
|
|
|
250 |
$this->request->onlyAllow('post', 'delete');
|
|
|
251 |
if ($this->UserUrl->delete()) {
|
|
|
252 |
$this->Session->setFlash(__('The user url has been deleted.'));
|
|
|
253 |
} else {
|
|
|
254 |
$this->Session->setFlash(__('The user url could not be deleted. Please, try again.'));
|
|
|
255 |
}
|
|
|
256 |
return $this->redirect(array('action' => 'index'));
|
|
|
257 |
}}
|