Subversion Repositories SmartDukaan

Rev

Rev 13565 | Rev 13579 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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());
27
/*
28
        App::import('Vendor','NewEpiCurl',array('file' =>'NewEpiCurl.php'));
29
		App::import('Vendor','NewEpiOAuth',array('file' =>'NewEpiOAuth.php'));
30
		App::import('Vendor','NewEpiTwitter',array('file' =>'NewEpiTwitter.php'));
31
*/		
32
		//Set api keys according to domain
33
		// get host name from URL
34
		preg_match('@^(?:http://)?([^/]+)@i',$_SERVER['HTTP_HOST'], $matches);
35
		$host = $matches[1];
36
		switch($host){			
13567 anikendra 37
			case 'localdtr':
13532 anikendra 38
				Configure::load('dev');
39
				break;
40
			default:
13567 anikendra 41
			case 'www.profittill.com':
42
			case 'profittill.com':
13532 anikendra 43
				Configure::load('live');
44
				break;
45
		}
13567 anikendra 46
		// Configure::load('live');
47
		$facebookConfig = Configure::read("Facebook");				
13532 anikendra 48
		//Facebook configuration
49
		$this->set('fbappid', $facebookConfig['fbappid']);
50
	   	$sessionState = $this->Session->read('state');
51
		if(!isset($sessionState)){
52
			$this->Session->write('state' , md5(uniqid(rand(), TRUE))); // CSRF protection
53
		}
54
	 	$dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
55
		   . $facebookConfig['fbappid'] . "&redirect_uri=" . urlencode($facebookConfig['base_url'].'/users/checkfbuser/') . "&state="
56
		   . $this->Session->read('state').'&scope=publish_stream,email,user_birthday,publish_actions,user_location';
57
	   	$this->set('dialog_url', $dialog_url);
58
		$this->set('description','Why spend money when you can get something for free');
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() {
73
	$result['ucadcode'] = $this->ucadcode;
74
    }
75
 
76
    function beforeRender() {    	
13565 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
}
81
 
82
if (!function_exists('getallheaders')) 
83
{ 
84
    function getallheaders() 
85
    { 
86
           $headers = ''; 
87
       foreach ($_SERVER as $name => $value) 
88
       { 
89
           if (substr($name, 0, 5) == 'HTTP_') 
90
           { 
91
               $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; 
92
           } 
93
       } 
94
       return $headers; 
95
    } 
96
}