Skip to content

Instantly share code, notes, and snippets.

@renovatorruler
Created May 4, 2010 17:12
Show Gist options
  • Save renovatorruler/389674 to your computer and use it in GitHub Desktop.
Save renovatorruler/389674 to your computer and use it in GitHub Desktop.
<?php
class Canvas extends Controller {
var $facebook;
var $user;
//API and secret key that you got from your application setup.
var $__fbApiKey = "0d6e273ddc3ec2459a3cab05a39ef393";
var $__fbSecret = "d3aac33fa7f5f42b24c62fb21c7fd972";
function __construct()
{
parent::Controller();
$this->load->helper(array('form','url'));
$this->load->plugin('facebook');
$this->load->library('form_validation');
$this->load->library('session');
$GLOBALS['facebook_config']['debug'] = NULL;
// Create a Facebook client API object.
$this->facebook = new Facebook($this->__fbApiKey, $this->__fbSecret);
$this->user = $this->facebook->require_login();
}
function index()
{
$data['user']=$this->user;
$this->load->view('header');
$this->load->view('canvas_front',$data);
}
function addevent()
{
$this->load->model('facebook_accounts_model');
$data['user']=$this->user;
$preferences=$this->facebook_accounts_model->getUserPreferences($this->user);
if(count($preferences)==0){
$this->session->set_flashdata('message','Please enter your login settings before adding events.');
$data['preferenceredirect']=true;
$this->load->view('header');
$this->load->view('canvas_eventlist',$data);
return;
}
$preferences=$preferences[0];
if(!isset($_POST['form_submit'])){
$temparray = $this->facebook->api_client->events_get(null, null, null, null, null);
log_message('debug','Response: '.$temparray);
foreach($temparray as $temprecord){
if($temprecord['venue']['city']=='New York' && $temprecord['venue']['state']=='New York'){
$data['events'][]=$temprecord;
}
}
$this->load->view('header');
$this->load->view('canvas_eventlist',$data);
}else{
//Perform Event Creation
$data['post']=$_POST;
foreach($_POST as $key=>$value){
if(strpos($key,'event')===0){
$temparr=$this->facebook->api_client->events_get(null,$value,null,null,null);
log_message('debug','Response: '.$temparr);
if(is_array($temparr))
$data['events'][]=$temparr[0];
else
$data['events'][]=$temparr;
}
}
$this->load->model('eventmodel');
if(isset($data['events'])){
foreach($data['events'] as $event){
$this->eventmodel->insert($event);
}
}
$this->load->view('header');
$this->load->view('canvas_event_confirmation',$data);
}
}
function preferences()
{
$this->load->model('facebook_accounts_model');
$data['user']=$this->user;
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
//$this->form_validation->set_message('required','<div class="fberrorbox" style="width: 500px;">The %s field is required.</div>');
$this->form_validation->set_error_delimiters('<div class="fberrorbox" style="width: 500px;">','</div>');
if($this->form_validation->run() == FALSE){
$data['preferences']=$this->facebook_accounts_model->getUserPreferences($this->user);
//$this->session->set_flashdata('message',$this->db->last_query());
$data['saved']=false;
$data['logincorrect']=true;
$this->load->view('header');
$this->load->view('preferences_view',$data);
}else{
$this->load->library('DX_Auth');
if($this->dx_auth->login($_POST['username'],$_POST['password'])){
$this->session->set_flashdata('message','<div class="fbbluebox" style="width: 500px;">Settings updated</div>');
//print('<fb:redirect url="http://apps.facebook.com/____/index.php/canvas" />');
$data['saved']=true;
$data['logincorrect']=true;
$data['preferences'][0]->p_username=$_POST['username'];
$data['preferences'][0]->p_password=$_POST['password'];
$this->facebook_accounts_model->saveLoginInfo($this->user,$_POST['username'],$_POST['password']);
$this->load->view('header');
$this->load->view('preferences_view',$data);
}else{
$data['logincorrect']=false;
$data['saved']=false;
$this->session->set_flashdata('message','<div class="fberrorbox" style="width: 500px;">Login failed, please enter correct .com username and password.</div>');
$data['preferences'][0]->p_username=$_POST['username'];
$data['preferences'][0]->p_password=$_POST['password'];
$this->load->view('header');
$this->load->view('preferences_view',$data);
}
}
//$data[]
}
}
/* End of file canvas.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment