| 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 {
|
|
|
14 |
public $components = array(
|
|
|
15 |
'Session',
|
|
|
16 |
'Auth' => array(
|
|
|
17 |
'loginAction' => array('controller' => 'users', 'action' => 'login'),
|
|
|
18 |
'allowedActions' => array('index', 'view', 'display')
|
|
|
19 |
)
|
|
|
20 |
);
|
|
|
21 |
var $helpers = array('Session', 'Form', 'Html');
|
|
|
22 |
var $keywords = array('instagram followers','instagram button','instagram follow back','instagram tool','instagram automation','free istagram followers','instagram stats','instagram follow button');
|
|
|
23 |
|
|
|
24 |
function beforeFilter() {
|
|
|
25 |
$this->Auth->autoRedirect = false;
|
|
|
26 |
$this->set('logged_user', $this->Auth->user());
|
| 13579 |
anikendra |
27 |
|
|
|
28 |
//Set config settings according to domain
|
| 13532 |
anikendra |
29 |
// get host name from URL
|
|
|
30 |
preg_match('@^(?:http://)?([^/]+)@i',$_SERVER['HTTP_HOST'], $matches);
|
|
|
31 |
$host = $matches[1];
|
|
|
32 |
switch($host){
|
| 13567 |
anikendra |
33 |
case 'localdtr':
|
| 13532 |
anikendra |
34 |
Configure::load('dev');
|
|
|
35 |
break;
|
|
|
36 |
default:
|
| 13567 |
anikendra |
37 |
case 'www.profittill.com':
|
|
|
38 |
case 'profittill.com':
|
| 13633 |
anikendra |
39 |
case 'api.profittill.com':
|
| 13532 |
anikendra |
40 |
Configure::load('live');
|
|
|
41 |
break;
|
|
|
42 |
}
|
| 13579 |
anikendra |
43 |
$facebookConfig = Configure::read("Facebook");
|
|
|
44 |
$categories = Configure::read('Categories');
|
| 13532 |
anikendra |
45 |
//Facebook configuration
|
|
|
46 |
$this->set('fbappid', $facebookConfig['fbappid']);
|
| 13579 |
anikendra |
47 |
$this->set('apihost', Configure::read('apihost'));
|
|
|
48 |
|
| 13532 |
anikendra |
49 |
$sessionState = $this->Session->read('state');
|
|
|
50 |
if(!isset($sessionState)){
|
|
|
51 |
$this->Session->write('state' , md5(uniqid(rand(), TRUE))); // CSRF protection
|
|
|
52 |
}
|
|
|
53 |
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
|
|
|
54 |
. $facebookConfig['fbappid'] . "&redirect_uri=" . urlencode($facebookConfig['base_url'].'/users/checkfbuser/') . "&state="
|
|
|
55 |
. $this->Session->read('state').'&scope=publish_stream,email,user_birthday,publish_actions,user_location';
|
|
|
56 |
$this->set('dialog_url', $dialog_url);
|
|
|
57 |
$this->set('description','Why spend money when you can get something for free');
|
| 13579 |
anikendra |
58 |
$this->set('categories',$categories);
|
| 13532 |
anikendra |
59 |
if(isset($this->params['admin'])) {
|
|
|
60 |
$this->layout = 'admin';
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
function isAuthorized() {
|
|
|
65 |
return $this->Auth->user('id');
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
function isFbAuthorized() {
|
|
|
69 |
return $this->Session->read('facebook_id');
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
function afterFilter() {
|
| 13579 |
anikendra |
73 |
$result['ucadcode'] = $this->ucadcode;
|
| 13532 |
anikendra |
74 |
}
|
|
|
75 |
|
|
|
76 |
function beforeRender() {
|
| 13579 |
anikendra |
77 |
$this->set('base_url', 'http://' . $_SERVER['SERVER_NAME'] . Router::url('/'));
|
|
|
78 |
// $this->set('base_url', 'http://api.profittill.com/');
|
| 13532 |
anikendra |
79 |
}
|
|
|
80 |
|
| 13633 |
anikendra |
81 |
function getallheaders() {
|
|
|
82 |
$headers = '';
|
|
|
83 |
foreach ($_SERVER as $name => $value)
|
|
|
84 |
{
|
|
|
85 |
if (substr($name, 0, 5) == 'HTTP_')
|
|
|
86 |
{
|
|
|
87 |
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
return $headers;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
function make_request($url,$fields,$format='json'){
|
|
|
94 |
$this->log($url,'pythonapi');
|
|
|
95 |
$this->log($fields,'pythonapi');
|
|
|
96 |
$fields_string = '';
|
|
|
97 |
//open connection
|
|
|
98 |
$ch = curl_init();
|
|
|
99 |
//set the url, number of POST vars, POST data
|
|
|
100 |
curl_setopt($ch,CURLOPT_URL, $url);
|
|
|
101 |
curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
|
|
|
102 |
if(!empty($fields)) {
|
|
|
103 |
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
|
|
|
104 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
105 |
'Content-Type: application/json',
|
|
|
106 |
'Content-Length: ' . strlen($fields))
|
|
|
107 |
);
|
|
|
108 |
}
|
|
|
109 |
//execute post
|
|
|
110 |
$result = curl_exec($ch);
|
|
|
111 |
//close connection
|
|
|
112 |
curl_close($ch);
|
|
|
113 |
switch($format){
|
|
|
114 |
case 'json':
|
|
|
115 |
$response = json_decode($result,1);
|
|
|
116 |
break;
|
|
|
117 |
}
|
|
|
118 |
return $response;
|
|
|
119 |
}
|
| 13532 |
anikendra |
120 |
}
|