first commit
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Bko_Controller extends WRB_Controller {
|
||||
|
||||
var $template = array(
|
||||
'table_open' => "<table class='table table-striped table-hover table-bordered table-condensed'>",
|
||||
'thead_open' => '<thead class=\'bg-indigo\'>',
|
||||
'thead_close' => '</thead>',
|
||||
'heading_row_start' => '<tr>',
|
||||
'heading_row_end' => '</tr>',
|
||||
'heading_cell_start' => '<th>',
|
||||
'heading_cell_end' => '</th>',
|
||||
'tbody_open' => '<tbody>',
|
||||
'tbody_close' => '</tbody>',
|
||||
'row_start' => '<tr>',
|
||||
'row_end' => '</tr>',
|
||||
'cell_start' => '<td>',
|
||||
'cell_end' => '</td>',
|
||||
'row_alt_start' => '<tr>',
|
||||
'row_alt_end' => '</tr>',
|
||||
'cell_alt_start' => '<td>',
|
||||
'cell_alt_end' => '</td>',
|
||||
'table_close' => '</table>'
|
||||
);
|
||||
public $data = array();
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
if (!isset($_SESSION['bko_username']) or $_SESSION['bko_username'] == '') {
|
||||
redirect(home);
|
||||
}
|
||||
|
||||
//print_r($_SESSION);
|
||||
}
|
||||
|
||||
// protected
|
||||
|
||||
protected function bkoDashData() {
|
||||
$this->load->model('backend_model');
|
||||
$is_live = $this->backend_model->cfgReadChar("system.live");
|
||||
$data = array();
|
||||
$this->load->library('table');
|
||||
$this->table->set_template($this->template);
|
||||
$mysql = "SELECT '<b>ADDED:</b>'||added::date||'<br><b>EXPIRE:</b>'||expire::date||'<br>'||username||'<br><b>Name:</b>'||firstname||' '||lastname AS signup,"
|
||||
. " (CASE WHEN status=1 THEN '<div id=\"btu'||id||'\"><button id=\"acc'||id||'\" class=\"btn btn-info btn-xs\" onclick=\"return resendLink('''||id||''');\" >Resend</button></div>' ELSE ' ' END) AS action ,"
|
||||
. " (CASE WHEN status=1 THEN '<div id=\"dtu'||id||'\"><button id=\"del'||id||'\" class=\"btn btn-warning btn-xs\" onclick=\"return deleteLink('''||id||''');\" >Del</button></div>' ELSE ' ' END) AS Del "
|
||||
. " FROM members_pending WHERE expire> now() AND status = 1"
|
||||
. " ORDER BY id desc limit 5";
|
||||
$query = $this->db->query($mysql);
|
||||
// $this->table->set_heading('Dates', 'Username', 'Name', 'Action');
|
||||
$this->table->set_heading(array('data' => 'Date/Email/Name', 'style' => 'width:180px'), array('data' => 'RES', 'style' => 'width:20px; cellpadding:0px;'), array('data' => 'Del', 'style' => 'width:20px; cellpadding:0px;'));
|
||||
|
||||
$data['pending_dash_table'] = $this->table->generate($query);
|
||||
|
||||
$this->table->set_template($this->template);
|
||||
$mysql = "SElECT added::date||'<br>'||loc AS dates,email||'<br>'||firstname||' '||lastname AS Name FROM members ORDER BY id DESC LIMIT 7";
|
||||
$query = $this->db->query($mysql);
|
||||
// $this->table->set_heading('Account', 'Created', 'Action');
|
||||
$this->table->set_heading(array('data' => 'Date/LOC', 'style' => 'width:140px'), 'Email/Name');
|
||||
|
||||
$data['signup_dash_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
// PUBIC active JOB table
|
||||
$mysql = "SELECT jo.expire,jo.id AS offer_id, jo.offer_code,mj.title,mj.description,mj.timeline_days,mj.price,jo.job_description FROM members_jobs_offer jo "
|
||||
. " LEFT JOIN members_jobs mj ON mj.id=jo.job_id "
|
||||
. " WHERE mj.status=1 AND jo.status=1 "
|
||||
. " AND jo.expire> now() AND jo.public_view > 0";
|
||||
|
||||
$query = $this->db->query($mysql);
|
||||
// $this->table->set_heading(array('data' => 'Date/LOC', 'style' => 'width:140px'), 'Email/Name');
|
||||
|
||||
$data['active_publicjob_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
|
||||
// Active Jobs
|
||||
$jbx = "";
|
||||
|
||||
$mysql = "SELECT '<b>Project ID:</b>'||mc.contract||'<br><b>Title:</b>'||mc.title AS Project,m.firstname||' '||m.lastname||'<br>'||m.email AS Client,"
|
||||
. " '<b>Timeline:</b> '||mc.timeline_days||' day(s)<br><b>Price:</b>'||mc.price*0.01 AS terms ,mc.description||'<br><b>Delivery Date :</b>'||mc.delivery_date As Description,"
|
||||
. " '<input type=submit onclick=\"return post_nav_find_action($jbx, '||mc.id||')\" name=\"manage\" class=\"btn btn-info btn-xs\" value=\"Manage\">' AS manage,mc.status "
|
||||
. "FROM members_jobs_contract mc LEFT JOIN members m ON m.id=mc.client_id LIMIT 10"; // WHERE mc.member_id = " . $_SESSION['member_id']." OR mc.client_id =". $_SESSION['member_id'];
|
||||
|
||||
$mysql = "SELECT '<b>'||mj.contract||'</b><br>'||mo.title AS thejob,'<b>Owner: </b>'||m1.firstname||' '||m1.lastname||' <br>'|| m1.email||'<br><b>Client: </b>'||m2.firstname||' '||m2.lastname||' <br>'|| m2.email AS Team1 "
|
||||
. "FROM members_jobs_contract mj "
|
||||
. "LEFT JOIN members_jobs mo ON mo.id=mj.job_id "
|
||||
. "LEFT JOIN members m1 ON m1.id=mj.member_id "
|
||||
. "LEFT JOIN members m2 ON m2.id=mj.client_id "
|
||||
. "WHERE mj.status IN (1,2) AND mj.delivery_date > now() ORDER by mj.id DESC LIMIT 5 ";
|
||||
|
||||
$query = $this->db->query($mysql);
|
||||
|
||||
//$this->table->set_heading('Job', 'Client', 'Terms', 'Description', 'Manage', 'Status');
|
||||
$this->table->set_heading(array('data' => 'Task', 'style' => 'width:180px'), 'Members');
|
||||
$data['job_active_dash_table'] = $this->table->generate($query);
|
||||
|
||||
$mysql = "SELECT '<b>'||mj.contract||'</b><br>'||mo.title AS thejob,'<b>Owner: </b>'||m1.firstname||' '||m1.lastname||' <br>'|| m1.email||'<br><b>Client: </b>'||m2.firstname||' '||m2.lastname||' <br>'|| m2.email AS Team1 "
|
||||
. "FROM members_jobs_contract mj "
|
||||
. "LEFT JOIN members_jobs mo ON mo.id=mj.job_id "
|
||||
. "LEFT JOIN members m1 ON m1.id=mj.member_id "
|
||||
. "LEFT JOIN members m2 ON m2.id=mj.client_id "
|
||||
. "WHERE mj.status IN (1,2) AND mj.delivery_date < now() ORDER by mj.id DESC LIMIT 5 ";
|
||||
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading(array('data' => 'Task', 'style' => 'width:180px'), 'Members');
|
||||
$data['job_pastdue_dash_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
$mysql = "SELECT '<b>Added: </b>'||m.added::date ||'<br><b>Amount: </b>'||m.terminatingamount*0.01||'<br><b>Fee: </b>'|| m.fee*0.01 as trans, "
|
||||
. "r.firstname||' '||r.lastname||'<br><b>Acc:</b>'||r.account_no||'-'||b.name||'<br><b>Confirm: </b>'||mp.confirmation AS Recitient,"
|
||||
. "CASE WHEN m.status=1 THEN 'Pending' WHEN m.status=3 THEN 'Cancelled' WHEN m.status=5 THEN 'Completed' ELSE '' END AS Status "
|
||||
. "FROM money_transfer m "
|
||||
. "LEFT JOIN sendmoney_recipient r ON r.id = m.recipientid "
|
||||
. "LEFT JOIN bank_entity_codes b ON b.code = r.bank_code "
|
||||
. "LEFT JOIN members_payments mp ON mp.what_sendmoney = m.id "
|
||||
. "WHERE mp.confirmation IS NOT NULL ORDER BY m.id DESC LIMIT 4";
|
||||
|
||||
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading('Trans', 'Target', 'Status');
|
||||
$data['sendmoney_dash_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
|
||||
$mysql = "SELECT created,'From: <b>'||email||'</b><br>'|| ( CASE WHEN status=1 THEn '<input type=submit id=\"dacc'||id||'\" onclick=\"return replyMessage('||id||')\" name=\"reply\" class=\"btn btn-info btn-xs\" value=\"Reply\">' ELSE '' END )||'<br>'||your_message AS your_message "
|
||||
. " FROM contacts order by id desc lIMIT 6";
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading(array('data' => 'Added', 'style' => 'width:110px'), 'Message');
|
||||
$data['contact_dash_table'] = $this->table->generate($query);
|
||||
|
||||
$data['members_dash_online'] = 0;
|
||||
|
||||
// Jobs Messages
|
||||
$sqlMsg = "SELECT created, (CASE WHEN msg_type='FILE' THEN '<a target=\"_blank\" href=\"/smedia/" . ($is_live ? "LIVE" : "TEST") . "/contract/'||contract||'/'||message||'\">'||message||'</a>' "
|
||||
. "ELSE '<b>'||created||'</b><br>'||message END) as msg FROM jobs_contract_message ORDER BY id DESC LIMIT 10"; // WHERE contract='".$data['contract_id']."'";
|
||||
// Jobs Messages
|
||||
$sqlMsg = "SELECT j.created, (CASE WHEN j.msg_type='FILE' THEN '<a target=\"_blank\" href=\"/smedia/" . ($is_live ? "LIVE" : "TEST") . "/contract/'||j.contract||'/'||j.message||'\">'||j.message||'</a>' "
|
||||
. "ELSE '<b>['||m.firstname||'-'||m.username||']->'||j.created||'</b><br>'||j.message END) as msg FROM jobs_contract_message j LEFT JOIN members m ON m.id=j.member_id ORDER BY j.id DESC LIMIT 10"; // WHERE contract='".$data['contract_id']."'";
|
||||
$query_message = $this->db->query($sqlMsg);
|
||||
//$this->table->set_heading('');
|
||||
$this->table->set_heading(array('data' => 'Added', 'style' => 'width:110px'), 'Activity Message');
|
||||
$data['message_dash_table'] = $this->table->generate($query_message);
|
||||
|
||||
|
||||
$data['total_members'] = 0;
|
||||
$data['total_balance'] = 0;
|
||||
$data['total_active_jobs'] = 0;
|
||||
|
||||
|
||||
|
||||
$mysql = "SELECT count(id) AS total_members FROM members WHERE status =1";
|
||||
$query = $this->db->query($mysql);
|
||||
$row = $query->row_array();
|
||||
$data['total_members'] = $row['total_members'];
|
||||
|
||||
$mysql = "SELECT sum(balance)AS total_balance FROM members WHERE status =1";
|
||||
$query = $this->db->query($mysql);
|
||||
$row = $query->row_array();
|
||||
$data['total_balance'] = $row['total_balance'];
|
||||
|
||||
$mysql = "SELECT count(id) AS total_active_jobs FROM members_jobs_contract WHERE status IN (1,2)";
|
||||
$query = $this->db->query($mysql);
|
||||
$row = $query->row_array();
|
||||
$data['total_active_jobs'] = $row['total_active_jobs'];
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class Mobile_Controller extends WRB_Controller {
|
||||
|
||||
public $data = array();
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
|
||||
//$this->renderMobileExtPage('mobile_index', $data);
|
||||
$this->load->model('mobile_detect');
|
||||
|
||||
$phoneH = $this->mobile_detect->getMobileHeaders();
|
||||
$imb = $this->mobile_detect->isMobile();
|
||||
|
||||
$mob_strict = false;
|
||||
|
||||
if ($mob_strict == true) {
|
||||
if ($img == false) {
|
||||
redirect('/');
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Bkomember_Controller extends Bko_Controller {
|
||||
|
||||
var $template = array(
|
||||
'table_open' => "<table class='table table-striped table-hover table-bordered table-condensed'>",
|
||||
'thead_open' => '<thead class=\'bg-indigo\'>',
|
||||
'thead_close' => '</thead>',
|
||||
'heading_row_start' => '<tr>',
|
||||
'heading_row_end' => '</tr>',
|
||||
'heading_cell_start' => '<th>',
|
||||
'heading_cell_end' => '</th>',
|
||||
'tbody_open' => '<tbody>',
|
||||
'tbody_close' => '</tbody>',
|
||||
'row_start' => '<tr>',
|
||||
'row_end' => '</tr>',
|
||||
'cell_start' => '<td>',
|
||||
'cell_end' => '</td>',
|
||||
'row_alt_start' => '<tr>',
|
||||
'row_alt_end' => '</tr>',
|
||||
'cell_alt_start' => '<td>',
|
||||
'cell_alt_end' => '</td>',
|
||||
'table_close' => '</table>'
|
||||
);
|
||||
|
||||
public $data = array();
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
if (!isset($_SESSION['bko_selected_id']) or $_SESSION['bko_selected_id'] == '' or $_SESSION['bko_selected_id'] <= 0 ) {
|
||||
redirect('/bkouser/locate');
|
||||
}
|
||||
}
|
||||
|
||||
// protected
|
||||
|
||||
|
||||
|
||||
protected function bkoUserDashData($member_id) {
|
||||
$this->load->model('backend_model');
|
||||
$is_live = $this->backend_model->cfgReadChar("system.live");
|
||||
$data = array();
|
||||
$this->load->library('table');
|
||||
$this->table->set_template($this->template);
|
||||
|
||||
|
||||
$short_limit = 10;
|
||||
|
||||
// MY JOBS
|
||||
$mysql = "SELECT created,title FROM members_jobs WHERE member_id = $member_id ORDER BY id DESC limit $short_limit";
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading(array('data' => 'Date', 'style' => 'width:110px'), 'Title');
|
||||
$data['member_job_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
// MY CONTRACTS
|
||||
$mysql = "SELECT created,title,status,client_id FROM members_jobs_contract WHERE member_id = $member_id ORDER BY id DESC LIMIT $short_limit";
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading(array('data' => 'Date', 'style' => 'width:110px'), 'Title', array('data' => 'ST', 'style' => 'width:40px'), 'client');
|
||||
$data['member_contract_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
// Jobs Messages
|
||||
$sqlMsg = " SELECT j.created, (CASE WHEN j.msg_type='FILE' THEN '<a target=\"_blank\" href=\"/smedia/" . ($is_live ? "LIVE" : "TEST") . "/contract/'||j.contract||'/'||j.message||'\">'||j.message||'</a>' "
|
||||
. " ELSE '<b>['||m.firstname||'-'||m.username||']->'||j.created||'</b><br>'||j.message END) as msg "
|
||||
. " FROM jobs_contract_message j LEFT JOIN members m ON m.id=j.member_id "
|
||||
. " WHERE j.member_id = $member_id ORDER BY j.id DESC LIMIT $short_limit";
|
||||
|
||||
$query_message = $this->db->query($sqlMsg);
|
||||
//$this->table->set_heading('');
|
||||
$this->table->set_heading(array('data' => 'Added', 'style' => 'width:110px'), 'Activity Message');
|
||||
$data['message_dash_table'] = $this->table->generate($query_message);
|
||||
|
||||
|
||||
|
||||
// Active Jobs
|
||||
$mysql = "SELECT '<b>'||mj.contract||'</b><br>'||mo.title AS thejob,'<b>Owner: </b>'||m1.firstname||' '||m1.lastname||' <br>'|| m1.email||'<br><b>Client: </b>'||m2.firstname||' '||m2.lastname||' <br>'|| m2.email AS Team1 "
|
||||
. "FROM members_jobs_contract mj "
|
||||
. "LEFT JOIN members_jobs mo ON mo.id=mj.job_id "
|
||||
. "LEFT JOIN members m1 ON m1.id=mj.member_id "
|
||||
. "LEFT JOIN members m2 ON m2.id=mj.client_id "
|
||||
. "WHERE mj.status IN (1,2) AND mj.delivery_date > now() AND mj.member_id = $member_id ORDER by mj.id DESC LIMIT $short_limit ";
|
||||
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading('Task', array('data' => 'Members', 'style' => 'width:150px'));
|
||||
$data['job_active_dash_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
// PAST DUE JOBS
|
||||
$mysql = "SELECT '<b>'||mj.contract||'</b><br>'||mo.title AS thejob,'<b>Owner: </b>'||m1.firstname||' '||m1.lastname||' <br>'|| m1.email||'<br><b>Client: </b>'||m2.firstname||' '||m2.lastname||' <br>'|| m2.email AS Team1 "
|
||||
. "FROM members_jobs_contract mj "
|
||||
. "LEFT JOIN members_jobs mo ON mo.id=mj.job_id "
|
||||
. "LEFT JOIN members m1 ON m1.id=mj.member_id "
|
||||
. "LEFT JOIN members m2 ON m2.id=mj.client_id "
|
||||
. "WHERE mj.status IN (1,2) AND mj.delivery_date < now() AND mj.member_id = $member_id ORDER by mj.id DESC LIMIT $short_limit ";
|
||||
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading('Task', array('data' => 'Members', 'style' => 'width:150px'));
|
||||
$data['job_pastdue_dash_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
|
||||
|
||||
$jbx = "";
|
||||
|
||||
$mysql = "SELECT '<b>ADDED:</b>'||added::date||'<br><b>EXPIRE:</b>'||expire::date As Dates,username||'<br><b>Name:</b>'||firstname||' '||lastname AS signup,"
|
||||
. " (CASE WHEN status=1 THEN '<div id=\"btu'||id||'\"><button id=\"acc'||id||'\" class=\"btn btn-info btn-xs\" onclick=\"return resendLink('''||id||''');\" >Resend</button></div>' ELSE ' ' END) AS action ,"
|
||||
. " (CASE WHEN status=1 THEN '<div id=\"dtu'||id||'\"><button id=\"del'||id||'\" class=\"btn btn-warning btn-xs\" onclick=\"return deleteLink('''||id||''');\" >Del</button></div>' ELSE ' ' END) AS Del "
|
||||
. " FROM members_pending WHERE expire> now() AND status = 1"
|
||||
. " ORDER BY id desc limit 5";
|
||||
$query = $this->db->query($mysql);
|
||||
// $this->table->set_heading('Dates', 'Username', 'Name', 'Action');
|
||||
$this->table->set_heading(array('data' => 'Date', 'style' => 'width:180px'), 'Email/Name', array('data' => 'RES', 'style' => 'width:40px; cellpadding:0px;'), array('data' => 'Del', 'style' => 'width:40px; cellpadding:0px;'));
|
||||
|
||||
$data['pending_dash_table'] = $this->table->generate($query);
|
||||
|
||||
$this->table->set_template($this->template);
|
||||
$mysql = "SElECT added::date||'<br>'||loc AS dates,email||'<br>'||firstname||' '||lastname AS Name FROM members ORDER BY id DESC LIMIT 7";
|
||||
$query = $this->db->query($mysql);
|
||||
// $this->table->set_heading('Account', 'Created', 'Action');
|
||||
$this->table->set_heading(array('data' => 'Date/LOC', 'style' => 'width:140px'), 'Email/Name');
|
||||
|
||||
$data['signup_dash_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$mysql = "SELECT '<b>Added: </b>'||m.added::date ||'<br><b>Amount: </b>'||m.terminatingamount*0.01||'<br><b>Fee: </b>'|| m.fee*0.01 as trans, "
|
||||
. "r.firstname||' '||r.lastname||'<br><b>Acc:</b>'||r.account_no||'-'||b.name||'<br><b>Confirm: </b>'||mp.confirmation AS Recitient,"
|
||||
. "CASE WHEN m.status=1 THEN 'Pending' WHEN m.status=3 THEN 'Cancelled' WHEN m.status=5 THEN 'Completed' ELSE '' END AS Status "
|
||||
. "FROM money_transfer m "
|
||||
. "LEFT JOIN sendmoney_recipient r ON r.id = m.recipientid "
|
||||
. "LEFT JOIN bank_entity_codes b ON b.code = r.bank_code "
|
||||
. "LEFT JOIN members_payments mp ON mp.what_sendmoney = m.id "
|
||||
. "WHERE mp.confirmation IS NOT NULL ORDER BY m.id DESC LIMIT 4";
|
||||
|
||||
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading('Trans', 'Target', 'Status');
|
||||
$data['sendmoney_dash_table'] = $this->table->generate($query);
|
||||
|
||||
|
||||
|
||||
$mysql = "SELECT created,'From: <b>'||email||'</b><br>'|| ( CASE WHEN status=1 THEn '<input type=submit id=\"dacc'||id||'\" onclick=\"return replyMessage('||id||')\" name=\"reply\" class=\"btn btn-info btn-xs\" value=\"Reply\">' ELSE '' END )||'<br>'||your_message AS your_message "
|
||||
. " FROM contacts order by id desc lIMIT 6";
|
||||
$query = $this->db->query($mysql);
|
||||
$this->table->set_heading(array('data' => 'Added', 'style' => 'width:110px'), 'Message');
|
||||
$data['contact_dash_table'] = $this->table->generate($query);
|
||||
|
||||
$data['members_dash_online'] = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
$data['total_members'] = 0;
|
||||
$data['total_balance'] = 0;
|
||||
$data['total_active_jobs'] = 0;
|
||||
|
||||
|
||||
|
||||
$mysql = "SELECT count(id) AS total_members FROM members WHERE status =1";
|
||||
$query = $this->db->query($mysql);
|
||||
$row = $query->row_array();
|
||||
$data['total_members'] = $row['total_members'];
|
||||
|
||||
$mysql = "SELECT sum(balance)AS total_balance FROM members WHERE status =1";
|
||||
$query = $this->db->query($mysql);
|
||||
$row = $query->row_array();
|
||||
$data['total_balance'] = $row['total_balance'];
|
||||
|
||||
$mysql = "SELECT count(id) AS total_active_jobs FROM members_jobs_contract WHERE status IN (1,2)";
|
||||
$query = $this->db->query($mysql);
|
||||
$row = $query->row_array();
|
||||
$data['total_active_jobs'] = $row['total_active_jobs'];
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
require_once 'vendor/facebook/php-sdk-v4/src/Facebook/autoload.php';
|
||||
|
||||
/**
|
||||
* Facebook PHP SDK for CodeIgniter 3
|
||||
*
|
||||
* Library wrapper for Facebook PHP SDK. Check user login status, publish to feed
|
||||
* and more with easy to use CodeIgniter syntax.
|
||||
*
|
||||
* This library requires the Facebook PHP SDK to be installed with Composer, and that CodeIgniter
|
||||
* config is set to autoload the vendor folder. More information in the CodeIgniter user guide at
|
||||
* http://www.codeigniter.com/userguide3/general/autoloader.html?highlight=composer
|
||||
*
|
||||
* It also requires CodeIgniter session library to be correctly configured.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @category Libraries
|
||||
* @author Mattias Hedman
|
||||
* @license MIT
|
||||
* @link https://github.com/darkwhispering/facebook-sdk-codeigniter
|
||||
* @version 3.0.0
|
||||
*/
|
||||
use Facebook\Facebook as FB;
|
||||
use Facebook\Authentication\AccessToken;
|
||||
use Facebook\Exceptions\FacebookResponseException;
|
||||
use Facebook\Exceptions\FacebookSDKException;
|
||||
use Facebook\FacebookBatchResponse;
|
||||
use Facebook\Helpers\FacebookCanvasHelper;
|
||||
use Facebook\Helpers\FacebookJavaScriptHelper;
|
||||
use Facebook\Helpers\FacebookPageTabHelper;
|
||||
use Facebook\Helpers\FacebookRedirectLoginHelper;
|
||||
Class Facebook
|
||||
{
|
||||
const UPLOAD_TYPE_VIDEO = 'video';
|
||||
const UPLOAD_TYPE_IMAGE = 'image';
|
||||
/**
|
||||
* @var FB
|
||||
*/
|
||||
private $fb;
|
||||
/**
|
||||
* @var FacebookRedirectLoginHelper|FacebookCanvasHelper|FacebookJavaScriptHelper|FacebookPageTabHelper
|
||||
*/
|
||||
private $helper;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $batch_request_pool = [];
|
||||
/**
|
||||
* Facebook constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Load config
|
||||
$this->load->config('facebook');
|
||||
// Load required libraries and helpers
|
||||
$this->load->library('session');
|
||||
$this->load->helper('url');
|
||||
if (!isset($this->fb))
|
||||
{
|
||||
$this->fb = new FB([
|
||||
'app_id' => $this->config->item('facebook_app_id'),
|
||||
'app_secret' => $this->config->item('facebook_app_secret'),
|
||||
'default_graph_version' => $this->config->item('facebook_graph_version')
|
||||
]);
|
||||
}
|
||||
// Load correct helper depending on login type
|
||||
// set in the config file
|
||||
switch ($this->config->item('facebook_login_type'))
|
||||
{
|
||||
case 'js':
|
||||
$this->helper = $this->fb->getJavaScriptHelper();
|
||||
break;
|
||||
case 'canvas':
|
||||
$this->helper = $this->fb->getCanvasHelper();
|
||||
break;
|
||||
case 'page_tab':
|
||||
$this->helper = $this->fb->getPageTabHelper();
|
||||
break;
|
||||
case 'web':
|
||||
$this->helper = $this->fb->getRedirectLoginHelper();
|
||||
break;
|
||||
}
|
||||
if ($this->config->item('facebook_auth_on_load') === TRUE)
|
||||
{
|
||||
// Try and authenticate the user right away (aka, get valid access token)
|
||||
$this->authenticate();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return FB
|
||||
*/
|
||||
public function object()
|
||||
{
|
||||
return $this->fb;
|
||||
}
|
||||
/**
|
||||
* Check if user are logged in by checking if we have a Facebook
|
||||
* session active.
|
||||
*
|
||||
* @return mixed|boolean
|
||||
*/
|
||||
public function is_authenticated()
|
||||
{
|
||||
$access_token = $this->authenticate();
|
||||
if (isset($access_token))
|
||||
{
|
||||
return $access_token;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Do Graph request
|
||||
*
|
||||
* @param $method
|
||||
* @param $endpoint
|
||||
* @param array $params
|
||||
* @param null $access_token
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function request($method, $endpoint, $params = [], $access_token = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = $this->fb->{strtolower($method)}($endpoint, $params, $access_token);
|
||||
return $response->getDecodedBody();
|
||||
}
|
||||
catch(FacebookResponseException $e)
|
||||
{
|
||||
return $this->logError($e->getCode(), $e->getMessage());
|
||||
}
|
||||
catch (FacebookSDKException $e)
|
||||
{
|
||||
return $this->logError($e->getCode(), $e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Upload image or video to user profile
|
||||
*
|
||||
* @param $path_to_file
|
||||
* @param array $params
|
||||
* @param string $type
|
||||
* @param null $access_token
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function user_upload_request($path_to_file, $params = [], $type = self::UPLOAD_TYPE_IMAGE, $access_token = null)
|
||||
{
|
||||
if ($type === self::UPLOAD_TYPE_IMAGE)
|
||||
{
|
||||
$data = ['source' => $this->fb->fileToUpload($path_to_file)] + $params;
|
||||
$endpoint = '/me/photos';
|
||||
}
|
||||
elseif ($type === self::UPLOAD_TYPE_VIDEO)
|
||||
{
|
||||
$data = ['source' => $this->fb->videoToUpload($path_to_file)] + $params;
|
||||
$endpoint = '/me/videos';
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->logError(400, 'Invalid upload type');
|
||||
}
|
||||
try
|
||||
{
|
||||
$response = $this->fb->post($endpoint, $data, $access_token);
|
||||
return $response->getDecodedBody();
|
||||
}
|
||||
catch(FacebookSDKException $e)
|
||||
{
|
||||
return $this->logError($e->getCode(), $e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add request to batch
|
||||
*
|
||||
* @param $key
|
||||
* @param $method
|
||||
* @param $endpoint
|
||||
* @param array $params
|
||||
* @param null $access_token
|
||||
*/
|
||||
public function add_to_batch_pool($key, $method, $endpoint, $params = [], $access_token = null)
|
||||
{
|
||||
$this->batch_request_pool = array_merge(
|
||||
$this->batch_request_pool,
|
||||
[$key => $this->fb->request($method, $endpoint, $params, $access_token)]
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Remove request from batch
|
||||
*
|
||||
* @param $key
|
||||
*/
|
||||
public function remove_from_batch_pool($key)
|
||||
{
|
||||
if (isset($this->batch_request_pool[$key]))
|
||||
{
|
||||
unset($this->batch_request_pool[$key]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Send all request in the batch pool
|
||||
*
|
||||
* @return array|FacebookBatchResponse
|
||||
*/
|
||||
public function send_batch_pool()
|
||||
{
|
||||
try
|
||||
{
|
||||
$responses = $this->fb->sendBatchRequest($this->batch_request_pool);
|
||||
$this->batch_request_pool = [];
|
||||
$data = [];
|
||||
foreach ($responses as $key => $response)
|
||||
{
|
||||
$data[$key] = $response->getDecodedBody();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
catch(FacebookResponseException $e)
|
||||
{
|
||||
return $this->logError($e->getCode(), $e->getMessage());
|
||||
}
|
||||
catch(FacebookSDKException $e)
|
||||
{
|
||||
return $this->logError($e->getCode(), $e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generate Facebook login url for Facebook Redirect Login (web)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function login_url()
|
||||
{
|
||||
// Login type must be web, else return empty string
|
||||
if ($this->config->item('facebook_login_type') != 'web')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
return $this->helper->getLoginUrl(
|
||||
base_url() . $this->config->item('facebook_login_redirect_url'),
|
||||
$this->config->item('facebook_permissions')
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Generate Facebook login url for Facebook Redirect Login (web)
|
||||
*
|
||||
* @return string
|
||||
* @throws FacebookSDKException
|
||||
*/
|
||||
public function logout_url()
|
||||
{
|
||||
// Login type must be web, else return empty string
|
||||
if ($this->config->item('facebook_login_type') != 'web')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
// Create logout url
|
||||
return $this->helper->getLogoutUrl(
|
||||
$this->get_access_token(),
|
||||
base_url() . $this->config->item('facebook_logout_redirect_url')
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Destroy our local Facebook session
|
||||
*/
|
||||
public function destroy_session()
|
||||
{
|
||||
$this->session->unset_userdata('fb_access_token');
|
||||
}
|
||||
/**
|
||||
* Get a new access token from Facebook
|
||||
*
|
||||
* @return array|AccessToken|null|object|void
|
||||
*/
|
||||
private function authenticate()
|
||||
{
|
||||
$access_token = $this->get_access_token();
|
||||
if ($access_token && $this->get_expire_time() > (time() + 30) || $access_token && !$this->get_expire_time())
|
||||
{
|
||||
$this->fb->setDefaultAccessToken($access_token);
|
||||
return $access_token;
|
||||
}
|
||||
// If we did not have a stored access token or if it has expired, try get a new access token
|
||||
if (!$access_token)
|
||||
{
|
||||
try
|
||||
{
|
||||
$access_token = $this->helper->getAccessToken();
|
||||
}
|
||||
catch (FacebookSDKException $e)
|
||||
{
|
||||
$this->logError($e->getCode(), $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
// If we got a session we need to exchange it for a long lived session.
|
||||
if (isset($access_token))
|
||||
{
|
||||
$access_token = $this->long_lived_token($access_token);
|
||||
$this->set_expire_time($access_token->getExpiresAt());
|
||||
$this->set_access_token($access_token);
|
||||
$this->fb->setDefaultAccessToken($access_token);
|
||||
return $access_token;
|
||||
}
|
||||
}
|
||||
// Collect errors if any when using web redirect based login
|
||||
if ($this->config->item('facebook_login_type') === 'web')
|
||||
{
|
||||
if ($this->helper->getError())
|
||||
{
|
||||
// Collect error data
|
||||
$error = array(
|
||||
'error' => $this->helper->getError(),
|
||||
'error_code' => $this->helper->getErrorCode(),
|
||||
'error_reason' => $this->helper->getErrorReason(),
|
||||
'error_description' => $this->helper->getErrorDescription()
|
||||
);
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
return $access_token;
|
||||
}
|
||||
/**
|
||||
* Exchange short lived token for a long lived token
|
||||
*
|
||||
* @param AccessToken $access_token
|
||||
*
|
||||
* @return AccessToken|null
|
||||
*/
|
||||
private function long_lived_token(AccessToken $access_token)
|
||||
{
|
||||
if (!$access_token->isLongLived())
|
||||
{
|
||||
$oauth2_client = $this->fb->getOAuth2Client();
|
||||
try
|
||||
{
|
||||
return $oauth2_client->getLongLivedAccessToken($access_token);
|
||||
}
|
||||
catch (FacebookSDKException $e)
|
||||
{
|
||||
$this->logError($e->getCode(), $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return $access_token;
|
||||
}
|
||||
/**
|
||||
* Get stored access token
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function get_access_token()
|
||||
{
|
||||
return $this->session->userdata('fb_access_token');
|
||||
}
|
||||
/**
|
||||
* Store access token
|
||||
*
|
||||
* @param AccessToken $access_token
|
||||
*/
|
||||
private function set_access_token(AccessToken $access_token)
|
||||
{
|
||||
$this->session->set_userdata('fb_access_token', $access_token->getValue());
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function get_expire_time()
|
||||
{
|
||||
return $this->session->userdata('fb_expire');
|
||||
}
|
||||
/**
|
||||
* @param DateTime $time
|
||||
*/
|
||||
private function set_expire_time(DateTime $time = null)
|
||||
{
|
||||
if ($time) {
|
||||
$this->session->set_userdata('fb_expire', $time->getTimestamp());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param $code
|
||||
* @param $message
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function logError($code, $message)
|
||||
{
|
||||
log_message('error', '[FACEBOOK PHP SDK] code: ' . $code.' | message: '.$message);
|
||||
return ['error' => $code, 'message' => $message];
|
||||
}
|
||||
/**
|
||||
* Enables the use of CI super-global without having to define an extra variable.
|
||||
* I can't remember where I first saw this, so thank you if you are the original author.
|
||||
*
|
||||
* Borrowed from the Ion Auth library (http://benedmunds.com/ion_auth/)
|
||||
*
|
||||
* @param $var
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($var)
|
||||
{
|
||||
return get_instance()->$var;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
# Imports the Google Cloud client library
|
||||
use Google\Cloud\Storage\StorageClient;
|
||||
|
||||
class GoogleStorage {
|
||||
|
||||
private $storage;
|
||||
private $projectId;
|
||||
private $authFile;
|
||||
public $prefix = 'adminsavvy';
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function Init($projectId, $authFile) {
|
||||
// Your Google Cloud Platform project ID
|
||||
$this->projectId = $projectId; // 'float-app-224118';
|
||||
// The file path to credentials JSON
|
||||
$this->authFile = $authFile; // './float-app-224118-52ef1783d2c5.json';
|
||||
// Instantiates a client
|
||||
$this->storage = new StorageClient([
|
||||
'projectId' => $projectId,
|
||||
'keyFile' => json_decode(file_get_contents($authFile), true)
|
||||
]);
|
||||
}
|
||||
/*
|
||||
* @type array $keyFile The contents of the service account credentials
|
||||
* .json file retrieved from the Google Developer's Console.
|
||||
* Ex: `json_decode(file_get_contents($path), true)`.
|
||||
* @type string $keyFilePath The full path to your service account
|
||||
* credentials .json file retrieved from the Google Developers
|
||||
* Console.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a Cloud Storage Bucket.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName name of the bucket to create.
|
||||
* @param string $options options for the new bucket.
|
||||
*
|
||||
* @return Google\Cloud\Storage\Bucket the newly created bucket.
|
||||
*/
|
||||
public function CreateBucket($bucketName) {
|
||||
// Creates the new bucket
|
||||
$bucket = $this->storage->createBucket($bucketName);
|
||||
//echo 'Bucket ' . $bucket->name() . ' created.';
|
||||
return $bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a Cloud Storage Bucket.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of the bucket to delete.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function DeleteBucket($bucketName)
|
||||
{
|
||||
$this->storage = new StorageClient();
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$bucket->delete();
|
||||
printf('Bucket deleted: %s' . PHP_EOL, $bucket->name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a file.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Google Cloud bucket.
|
||||
* @param string $objectName the name of the object.
|
||||
* @param string $source the path to the file to upload.
|
||||
*
|
||||
* @return Psr\Http\Message\StreamInterface
|
||||
*/
|
||||
function UploadObject($bucketName, $objectName, $source)
|
||||
{
|
||||
$file = fopen($source, 'r');
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->upload($file, [
|
||||
'name' => $objectName
|
||||
]);
|
||||
printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download an object from Cloud Storage and return it as a BLOB.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Google Cloud bucket.
|
||||
* @param string $objectName the name of your Google Cloud object.
|
||||
*
|
||||
* @return BLOB
|
||||
*/
|
||||
function DownloadObject($bucketName, $objectName)
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$stream = $object->downloadAsStream();
|
||||
return $stream->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an object.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
* @param string $objectName the name of your Cloud Storage object.
|
||||
* @param array $options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function DeleteObject($bucketName, $objectName, $options = [])
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$object->delete();
|
||||
printf('Deleted gs://%s/%s' . PHP_EOL, $bucketName, $objectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an object publically accessible.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
* @param string $objectName the name of your Cloud Storage object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function MakePublic($bucketName, $objectName)
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$object->update(['acl' => []], ['predefinedAcl' => 'PUBLICREAD']);
|
||||
printf('gs://%s/%s is now public' . PHP_EOL, $bucketName, $objectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* List object metadata.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
* @param string $objectName the name of your Cloud Storage object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ObjectMetadata($bucketName, $objectName)
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$info = $object->info();
|
||||
printf('Blob: %s' . PHP_EOL, $info['name']);
|
||||
printf('Bucket: %s' . PHP_EOL, $info['bucket']);
|
||||
printf('Storage class: %s' . PHP_EOL, $info['storageClass']);
|
||||
printf('ID: %s' . PHP_EOL, $info['id']);
|
||||
printf('Size: %s' . PHP_EOL, $info['size']);
|
||||
printf('Updated: %s' . PHP_EOL, $info['updated']);
|
||||
printf('Generation: %s' . PHP_EOL, $info['generation']);
|
||||
printf('Metageneration: %s' . PHP_EOL, $info['metageneration']);
|
||||
printf('Etag: %s' . PHP_EOL, $info['etag']);
|
||||
printf('Crc32c: %s' . PHP_EOL, $info['crc32c']);
|
||||
printf('MD5 Hash: %s' . PHP_EOL, $info['md5Hash']);
|
||||
printf('Content-type: %s' . PHP_EOL, $info['contentType']);
|
||||
printf("Temporary hold: " . (isset($info['temporaryHold']) ? "enabled" : "disabled") . PHP_EOL);
|
||||
printf("Event-based hold: " . (isset($info['eventBasedHold']) ? "enabled" : "disabled") . PHP_EOL);
|
||||
if (isset($info['retentionExpirationTime'])) {
|
||||
printf("retentionExpirationTime: " . $info['retentionExpirationTime'] . PHP_EOL);
|
||||
}
|
||||
if (isset($info['metadata'])) {
|
||||
printf('Metadata: %s', print_r($info['metadata'], true));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all Cloud Storage buckets for the current project.
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @return void
|
||||
*/
|
||||
function ListBuckets()
|
||||
{
|
||||
$buckets = array();
|
||||
foreach ($this->storage->buckets() as $bucket) {
|
||||
//printf('Bucket: %s' . PHP_EOL, $bucket->name());
|
||||
$buckets[$bucket->name()] = $bucket;
|
||||
}
|
||||
return $buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* List Cloud Storage bucket objects.
|
||||
* https://cloud.google.com/storage/docs/listing-objects
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function ListObjects($bucketName)
|
||||
{
|
||||
$objects = array();
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
foreach ($bucket->objects() as $object) {
|
||||
//printf('Object: %s' . PHP_EOL, $object->name());
|
||||
$objects[$object->name()] = $object;
|
||||
}
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* List Cloud Storage bucket objects.
|
||||
* https://cloud.google.com/storage/docs/listing-objects
|
||||
*
|
||||
* @param Google\Cloud\Storage\StorageClient $storage Google storage service client
|
||||
* @param string $bucketName the name of your Cloud Storage bucket.
|
||||
* @param string $objectName the name of your Cloud Storage object.
|
||||
* @param string $responseType Response content-type for the object URL
|
||||
* @param integer $duration Number of seconds before the signature expires
|
||||
* @param string $method Optional HTTP verb for URL
|
||||
*
|
||||
* @return string Signed google storage URL
|
||||
*/
|
||||
function SignedUrl($bucketName, $objectName, $responseType, $duration = 60, $method = 'GET')
|
||||
{
|
||||
$bucket = $this->storage->bucket($bucketName);
|
||||
$object = $bucket->object($objectName);
|
||||
$url = $object->signedUrl(
|
||||
new \DateTime('+ ' . $duration . ' seconds'),
|
||||
array(
|
||||
'method' => $method,
|
||||
'responseType' => $responseType,
|
||||
'allowPost' => $method=='POST'
|
||||
));
|
||||
return $url;
|
||||
}
|
||||
/*
|
||||
'method' => 'GET',
|
||||
'cname' => self::DEFAULT_DOWNLOAD_URL,
|
||||
'contentMd5' => null,
|
||||
'contentType' => null,
|
||||
'headers' => [],
|
||||
'saveAsName' => null,
|
||||
'responseDisposition' => null,
|
||||
'responseType' => null,
|
||||
'keyFile' => null,
|
||||
'keyFilePath' => null,
|
||||
'allowPost' => false,
|
||||
'forceOpenssl' => false
|
||||
*/
|
||||
private function BaseEncode($num, $alphabet) {
|
||||
$base_count = strlen($alphabet);
|
||||
$encoded = '';
|
||||
while ($num >= $base_count) {
|
||||
$div = $num/$base_count;
|
||||
$mod = ($num-($base_count*intval($div)));
|
||||
$encoded = $alphabet[$mod] . $encoded;
|
||||
$num = intval($div);
|
||||
}
|
||||
if ($num) $encoded = $alphabet[$num] . $encoded;
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
private function BaseDecode($num, $alphabet) {
|
||||
$decoded = 0;
|
||||
$multi = 1;
|
||||
while (strlen($num) > 0) {
|
||||
$digit = $num[strlen($num)-1];
|
||||
$decoded += $multi * strpos($alphabet, $digit);
|
||||
$multi = $multi * strlen($alphabet);
|
||||
$num = substr($num, 0, -1);
|
||||
}
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
public function UniqueId() {
|
||||
// 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
|
||||
$alphabet = "pRFsNvKifkJtA5Umy9QSD8PTYcZH23dCeWg6aqVXwnr7jxuGMLhE4zBob1";
|
||||
return $this->BaseEncode(
|
||||
filter_var(microtime(),FILTER_SANITIZE_NUMBER_INT),
|
||||
$alphabet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//*
|
||||
// run with GOOGLE_STORAGE_TEST=1 php -f GoogleStorage.php
|
||||
if (isset($_SERVER['GOOGLE_STORAGE_TEST']) && $_SERVER['GOOGLE_STORAGE_TEST']==1) {
|
||||
// Create bucket 'adminsavvy-card-images' and list buckets
|
||||
//TestGoogleStorage(1,1,0,0,0,0,0,0);
|
||||
// Upload 'singapore.jpg' file to 'adminsavvy-card-images' bucket and make the object public
|
||||
//TestGoogleStorage(0,0,1,1,0,0,0,0);
|
||||
// Download 'singapore.jpg' object from 'adminsavvy-card-images' bucket
|
||||
//TestGoogleStorage(0,0,0,0,0,0,1,0);
|
||||
// List buckets, List objects in 'adminsavvy-card-images' bucket, get 'singapore.jpg' object metadata, get signed URL
|
||||
TestGoogleStorage(0,1,0,0,1,1,0,1);
|
||||
}
|
||||
//*/
|
||||
/*
|
||||
* Run the test suite for above defined function
|
||||
*
|
||||
* @param integer $testCreateBucket 1 to run the create bucket test
|
||||
* @param integer $testListBuckets 1 to run the list buckets test
|
||||
* @param integer $testUploadObject 1 to run the upload object test
|
||||
* @param integer $testMakePublic 1 to run the make public test
|
||||
* @param integer $testListObjects 1 to run the list objects test
|
||||
* @param integer $testObjectMetadata 1 to run the object metadata test
|
||||
* @param integer $testDownloadObject 1 to run the download object test
|
||||
* @param integer $testSignedUrl 1 to run the signed URL test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function TestGoogleStorage(
|
||||
$testCreateBucket,
|
||||
$testListBuckets,
|
||||
$testUploadObject,
|
||||
$testMakePublic,
|
||||
$testListObjects,
|
||||
$testObjectMetadata,
|
||||
$testDownloadObject,
|
||||
$testSignedUrl) {
|
||||
// Your Google Cloud Platform project ID
|
||||
$projectId = 'float-app-224118';
|
||||
// The name for the new bucket
|
||||
$bucketName = 'adminsavvy-card-images';
|
||||
// The file path to upload
|
||||
$filePath = '/home/savvy/savvy/savvyoauth2/public/test/singapore.jpg';
|
||||
// The file path to credentials JSON
|
||||
$authFile = '/home/savvy/savvy/savvyoauth2/public/include/float-app-224118-52ef1783d2c5.json';
|
||||
|
||||
// Instantiates a client
|
||||
$storage = new GoogleStorage($projectId, $authFile);
|
||||
|
||||
if ($testCreateBucket) var_dump($storage->CreateBucket($bucketName));
|
||||
if ($testListBuckets) $storage->ListBuckets();
|
||||
if ($testUploadObject) var_dump($storage->UploadObject($bucketName, basename($filePath), $filePath));
|
||||
if ($testMakePublic) $storage->MakePublic($bucketName, basename($filePath));
|
||||
if ($testListObjects) $storage->ListObjects($bucketName);
|
||||
if ($testObjectMetadata) $storage->ObjectMetadata($bucketName, basename($filePath));
|
||||
if ($testDownloadObject) file_put_contents('test.jpg',$storage->DownloadObject($bucketName, basename($filePath)));
|
||||
if ($testSignedUrl) var_dump($storage->SignedUrl($bucketName, basename($filePath), mime_content_type($filePath), 864000));
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* Name: Facebook Login Library
|
||||
*
|
||||
* Author: appleboy
|
||||
*
|
||||
*/
|
||||
require 'vendor/autoload.php';
|
||||
//require_once 'vendor/facebook/php-sdk-v4/src/Facebook/autoload.php';
|
||||
use Facebook\Facebook;
|
||||
use Facebook\FacebookRequestException;
|
||||
use Facebook\FacebookRedirectLoginHelper;
|
||||
class Lib_login
|
||||
{
|
||||
/**
|
||||
* CodeIgniter global
|
||||
*
|
||||
* @var string
|
||||
**/
|
||||
protected $ci;
|
||||
/**
|
||||
* @var FB
|
||||
*/
|
||||
private $fb;
|
||||
|
||||
private $helper;
|
||||
private $facebook_default_scope;
|
||||
private $facebook_login_url;
|
||||
private $facebook_logout_url;
|
||||
|
||||
/**
|
||||
* __construct
|
||||
*
|
||||
* @return void
|
||||
* @author Ben
|
||||
**/
|
||||
public function __construct()
|
||||
{
|
||||
if (!session_id()) {
|
||||
session_start();
|
||||
}
|
||||
$this->ci =& get_instance();
|
||||
$this->ci->load->library('session');
|
||||
$this->ci->config->load('facebook');
|
||||
$this->ci->load->helper('url');
|
||||
if (! isset($_SESSION)) {
|
||||
session_start();
|
||||
}
|
||||
$this->facebook_default_scope = explode(',', $this->ci->config->item("facebook_default_scope"));
|
||||
$facebook_app_id = $this->ci->config->item("facebook_app_id");
|
||||
$facebook_app_secret = $this->ci->config->item("facebook_app_secret");
|
||||
$this->facebook_login_url = base_url() . $this->ci->config->item("facebook_login_redirect_url").'/';
|
||||
$this->facebook_logout_url = base_url() . $this->ci->config->item("facebook_logout_redirect_url").'/';
|
||||
// init app with app id and secret
|
||||
$this->fb = new Facebook([
|
||||
'app_id' => $facebook_app_id, // Replace {app-id} with your app id
|
||||
'app_secret' => $facebook_app_secret,
|
||||
'default_graph_version' => 'v2.2',
|
||||
]);
|
||||
$this->helper = $this->fb->getRedirectLoginHelper();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FB
|
||||
*/
|
||||
public function object()
|
||||
{
|
||||
return $this->fb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user are logged in by checking if we have a Facebook
|
||||
* session active.
|
||||
*
|
||||
* @return mixed|boolean
|
||||
*/
|
||||
public function is_authenticated()
|
||||
{
|
||||
$access_token = $this->authenticate();
|
||||
if (isset($access_token))
|
||||
{
|
||||
return $access_token;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy our local Facebook session
|
||||
*/
|
||||
public function destroy_session()
|
||||
{
|
||||
$this->session->unset_userdata('fb_access_token');
|
||||
}
|
||||
|
||||
public function getLoginUrl() {
|
||||
return $this->helper->getLoginUrl($this->facebook_login_url, $this->facebook_default_scope);
|
||||
}
|
||||
|
||||
public function getLogoutUrl() {
|
||||
return $this->helper->getLogoutUrl($this->get_access_token(), $this->facebook_logout_url);
|
||||
}
|
||||
|
||||
public function get_access_token() {
|
||||
return $this->session->userdata('fb_access_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function get_expire_time()
|
||||
{
|
||||
return $this->session->userdata('fb_expire');
|
||||
}
|
||||
/**
|
||||
* @param DateTime $time
|
||||
*/
|
||||
private function set_expire_time(DateTime $time = null)
|
||||
{
|
||||
if ($time) {
|
||||
$this->session->set_userdata('fb_expire', $time->getTimestamp());
|
||||
}
|
||||
}
|
||||
|
||||
public function authenticate()
|
||||
{
|
||||
$accessToken = $this->get_access_token();
|
||||
if ($accessToken && $this->get_expire_time() > (time() + 30) || $accessToken && !$this->get_expire_time())
|
||||
{
|
||||
$this->fb->setDefaultAccessToken($accessToken);
|
||||
return $accessToken;
|
||||
}
|
||||
// If we did not have a stored access token or if it has expired, try get a new access token
|
||||
try {
|
||||
$accessToken = $this->helper->getAccessToken($this->facebook_login_url);
|
||||
} catch(Facebook\Exceptions\FacebookResponseException $e) {
|
||||
// When Graph returns an error
|
||||
return $this->constructResult(NULL, 'Graph returned an error: ' . $e->getMessage());
|
||||
} catch(Facebook\Exceptions\FacebookSDKException $e) {
|
||||
// When validation fails or other local issues
|
||||
return $this->constructResult(NULL, 'Facebook SDK returned an error: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (! isset($accessToken)) {
|
||||
if ($this->helper->getError()) {
|
||||
/*header('HTTP/1.0 401 Unauthorized');
|
||||
echo "Error: " . $helper->getError() . "\n";
|
||||
echo "Error Code: " . $helper->getErrorCode() . "\n";
|
||||
echo "Error Reason: " . $helper->getErrorReason() . "\n";
|
||||
echo "Error Description: " . $helper->getErrorDescription() . "\n";
|
||||
*/
|
||||
return $this->constructResult(NULL, 'Unauthorized: '.$this->helper->getErrorDescription());
|
||||
} else {
|
||||
return $this->constructResult(NULL, 'Bad request');
|
||||
}
|
||||
}
|
||||
// The OAuth 2.0 client handler helps us manage access tokens
|
||||
$oAuth2Client = $this->fb->getOAuth2Client();
|
||||
// Get the access token metadata from /debug_token
|
||||
///$tokenMetadata = $oAuth2Client->debugToken($accessToken);
|
||||
|
||||
if (! $accessToken->isLongLived()) {
|
||||
// Exchanges a short-lived access token for a long-lived one
|
||||
try {
|
||||
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
|
||||
$this->set_expire_time($accessToken->getExpiresAt());
|
||||
$this->set_access_token($accessToken);
|
||||
$this->fb->setDefaultAccessToken($accessToken);
|
||||
} catch (Facebook\Exceptions\FacebookSDKException $e) {
|
||||
return $this->constructResult(NULL, "<p>Error getting long-lived access token: " . $this->helper->getMessage() . "</p>\n\n");
|
||||
}
|
||||
//var_dump($accessToken->getValue());
|
||||
}
|
||||
$_SESSION['fb_access_token'] = (string) $accessToken;
|
||||
|
||||
return $accessToken;
|
||||
}
|
||||
|
||||
public function getData($accessToken) {
|
||||
$user = NULL;
|
||||
try {
|
||||
// Returns a `Facebook\FacebookResponse` object
|
||||
if ($accessToken!="") {
|
||||
$response = $this->fb->get('/me?fields=id,name,email', $accessToken);
|
||||
$user = $response->getGraphUser();
|
||||
}
|
||||
} catch(Facebook\Exceptions\FacebookResponseException $e) {
|
||||
return $this->constructResult(NULL,'Graph returned an error: ' . $e->getMessage());
|
||||
} catch(Facebook\Exceptions\FacebookSDKException $e) {
|
||||
return $this->constructResult(NULL,'Facebook SDK returned an error: ' . $e->getMessage());
|
||||
}
|
||||
return $this->constructResult($user, NULL);
|
||||
}
|
||||
|
||||
private function constructResult($me,$error) {
|
||||
$fb_data = array(
|
||||
'me' => $me,
|
||||
'error' => $error
|
||||
);
|
||||
$this->ci->session->set_userdata('fb_data', $fb_data);
|
||||
return $fb_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the use of CI super-global without having to define an extra variable.
|
||||
* I can't remember where I first saw this, so thank you if you are the original author.
|
||||
*
|
||||
* Borrowed from the Ion Auth library (http://benedmunds.com/ion_auth/)
|
||||
*
|
||||
* @param $var
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($var)
|
||||
{
|
||||
return get_instance()->$var;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class Mobile_Controller extends WRB_Controller {
|
||||
|
||||
public $data = array();
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
|
||||
//$this->renderMobileExtPage('mobile_index', $data);
|
||||
$this->load->model('mobile_model');
|
||||
|
||||
// $phoneH = $this->mobile_model->getMobileHeaders();
|
||||
$imb = $this->mobile_model->isMobile();
|
||||
//echo "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh=". $imb;
|
||||
$mob_strict = true;
|
||||
|
||||
if ($mob_strict == true) {
|
||||
if ($imb !=1) {
|
||||
// redirect('/');
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
class Users_Controller extends WRB_Controller {
|
||||
|
||||
|
||||
public $data = array();
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
// you dont have bussines here if you are not in session
|
||||
if (!isset($_SESSION['session_id']) or ! isset($_SESSION['username']) or $_SESSION['username'] == '') {
|
||||
redirect(home);
|
||||
}
|
||||
|
||||
$out = array();
|
||||
$in = array();
|
||||
$this->load->model('backend_model');
|
||||
$in["action"] = WRENCHBOARD_SESSION_VERIFY;
|
||||
$in['sessionid'] = $_SESSION['session_id'];
|
||||
$in['member_id'] = $_SESSION['member_id'];
|
||||
$res = $this->backend_model->wrenchboard_api($in, $out);
|
||||
if ($res != PHP_API_OK) {
|
||||
redirect(home);
|
||||
}
|
||||
$this->data = $this->getSessionArray();
|
||||
}
|
||||
|
||||
public function getSessionArray() {
|
||||
$data["current_date"] = date('l jS \of F Y h:i:s A');
|
||||
$data['username'] = $_SESSION['username']; // = $this->input->post('username');
|
||||
$data['name'] = $_SESSION['name']; // = $this->input->post('username');
|
||||
$data['firstname'] = $_SESSION['firstname']; // = $ret->firstname;
|
||||
$data['lastname'] = $_SESSION['lastname']; // = $ret->lastname;
|
||||
$data['email'] = $_SESSION['email']; // = $ret->email;
|
||||
$data['member_id'] = $_SESSION['member_id'];
|
||||
|
||||
$this->load->model('dash_model');
|
||||
$out = $this->dash_model->getDashData($data);
|
||||
$data['active_task'] = $out['active_task'];
|
||||
$data['active_pass_due'] = $out['active_pass_due'];
|
||||
$data['current_balance'] = $out['current_balance'];
|
||||
$data['new_message'] = $out['new_message'];
|
||||
$data['escrow_balance'] = $out['escrow_balance'];
|
||||
$data['description'] = $out["description"];
|
||||
|
||||
//$data = $_SESSION['secure_data'];
|
||||
$data['member_id'] = $_SESSION['member_id']; // = $ret->email;
|
||||
$_SESSION["active_offers_count"] = $out['active_offers_count'];
|
||||
$_SESSION["offers_interest_count"] = $out["offers_interest_count"];
|
||||
$_SESSION['new_message'] = $out["new_message"];
|
||||
|
||||
$this->refreshAccountDetail($_SESSION['member_id']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function refreshAccountDetail($member_id) {
|
||||
$this->load->model('account_model');
|
||||
$qr = $this->account_model->loadAccountData($member_id);
|
||||
// print_r($qr);
|
||||
$_SESSION['current_balance'] = $qr[0]['balance'];
|
||||
$_SESSION['active_task'] = $this->account_model->loadActiveTaskCount($member_id);
|
||||
$_SESSION['state'] = $qr[0]['state'];
|
||||
$_SESSION['city'] = $qr[0]['city'];
|
||||
$_SESSION['country'] = $qr[0]['country'];
|
||||
$_SESSION['post_jobs'] = $qr[0]['post_jobs'];
|
||||
$_SESSION['refer'] = $qr[0]['refer'];
|
||||
|
||||
$in = array();
|
||||
$in['action'] = WRENCHBOARD_SESSION_VERIFY;
|
||||
$in['sessionid'] = $_SESSION['session_id'];
|
||||
$in['member_id'] = $_SESSION['member_id'];
|
||||
$this->load->model('backend_model');
|
||||
$out = array();
|
||||
$res = $this->backend_model->wrenchboard_api($in, $out);
|
||||
if ($res != PHP_API_OK) {
|
||||
redirect(home);
|
||||
}
|
||||
}
|
||||
|
||||
protected function RenderUserPage($page_name, $data) {
|
||||
$this->load->view('users/view_header_user', $data);
|
||||
$this->load->view($page_name, $data);
|
||||
$this->load->view('users/view_footer_user', $data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user