Subversion Repositories SmartDukaan

Rev

Rev 13567 | Rev 13633 | 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());
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':
13532 anikendra 39
				Configure::load('live');
40
				break;
41
		}
13579 anikendra 42
		$facebookConfig = Configure::read("Facebook");		
43
		$categories = Configure::read('Categories');
13532 anikendra 44
		//Facebook configuration
45
		$this->set('fbappid', $facebookConfig['fbappid']);
13579 anikendra 46
		$this->set('apihost', Configure::read('apihost'));
47
 
13532 anikendra 48
	   	$sessionState = $this->Session->read('state');
49
		if(!isset($sessionState)){
50
			$this->Session->write('state' , md5(uniqid(rand(), TRUE))); // CSRF protection
51
		}
52
	 	$dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
53
		   . $facebookConfig['fbappid'] . "&redirect_uri=" . urlencode($facebookConfig['base_url'].'/users/checkfbuser/') . "&state="
54
		   . $this->Session->read('state').'&scope=publish_stream,email,user_birthday,publish_actions,user_location';
55
	   	$this->set('dialog_url', $dialog_url);
56
		$this->set('description','Why spend money when you can get something for free');
13579 anikendra 57
		$this->set('categories',$categories);
13532 anikendra 58
		if(isset($this->params['admin'])) {
59
    		$this->layout = 'admin';
60
    	}		
61
    }
62
 
63
    function isAuthorized() {
64
        return $this->Auth->user('id');
65
    }
66
 
67
    function isFbAuthorized() {
68
        return $this->Session->read('facebook_id');
69
    }
70
 
71
    function afterFilter() {
13579 anikendra 72
		$result['ucadcode'] = $this->ucadcode;
13532 anikendra 73
    }
74
 
75
    function beforeRender() {    	
13579 anikendra 76
        $this->set('base_url', 'http://' . $_SERVER['SERVER_NAME'] . Router::url('/'));
77
        // $this->set('base_url', 'http://api.profittill.com/');
13532 anikendra 78
    }
79
}
80
 
81
if (!function_exists('getallheaders')) 
82
{ 
83
    function getallheaders() 
84
    { 
85
           $headers = ''; 
86
       foreach ($_SERVER as $name => $value) 
87
       { 
88
           if (substr($name, 0, 5) == 'HTTP_') 
89
           { 
90
               $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; 
91
           } 
92
       } 
93
       return $headers; 
94
    } 
95
}