Exemple #1
0
 public function main()
 {
     try {
         $DEFAULT_URL = 'https://ens.firebaseio.com/';
         $DEFAULT_TOKEN = Configure::read('Firebase.token');
         $DEFAULT_PATH = '/sms';
         $firebase = new \Firebase\FirebaseLib($DEFAULT_URL, $DEFAULT_TOKEN);
         if (!isset($this->args[0])) {
             throw new \Exception('Missing queue ID');
         }
         $this->out('Start...');
         $sendQueueTable = TableRegistry::get('SendQueues');
         $numberTable = TableRegistry::get('Numbers');
         $dateTimeUtc = new \DateTimeZone('UTC');
         $now = new \DateTime('now', $dateTimeUtc);
         $sendQueue = $sendQueueTable->find('all', ['conditions' => ['type' => 1, 'send_queue_id' => $this->args[0], 'OR' => ['next_try_datetime IS NULL', 'next_try_datetime <=' => $now]]]);
         if (!$sendQueue->count()) {
             throw new \Exception('No more queue');
         }
         $firstQueue = $sendQueue->first();
         // Mark as being processed...
         $firebase->set($DEFAULT_PATH . '/' . $firstQueue->send_queue_id . '/status', 1);
         $firstQueue->status = 1;
         $firstQueue->start_datetime = $now;
         $sendQueueTable->save($firstQueue);
         // Mark as sending...
         $firebase->set($DEFAULT_PATH . '/' . $firstQueue->send_queue_id . '/status', 2);
         $firstQueue->status = 2;
         $sendQueueTable->save($firstQueue);
         $page = 1;
         while (true) {
             $numbers = $numberTable->find('all', ['fields' => ['number_id', 'number_list_id', 'country_code', 'phone_number'], 'conditions' => ['number_list_id' => $firstQueue->number_list_id], 'limit' => 5000, 'page' => $page]);
             $list = $numbers->toArray();
             if (!count($list)) {
                 break;
             }
             // Format the number for Firebase
             $numberForFb = Hash::combine($list, '{n}.number_id', '{n}');
             $this->out(json_encode($numberForFb));
             $this->out($page);
             // Put the all the number on Firebase
             $firebase->update($DEFAULT_PATH . '/' . $firstQueue->send_queue_id . '/numbers', $numberForFb);
             // Send SMS
             foreach ($numbers as $number) {
                 shell_exec(ROOT . DS . 'bin' . DS . 'cake SendSmsBackground ' . $firstQueue->send_queue_id . ' ' . $number->number_id . ' ' . $number->country_code . ' ' . $number->phone_number . ' "THIS IS A TEST! ' . $firstQueue->message . '" > /dev/null 2>/dev/null &');
                 usleep(10000);
             }
             $page++;
         }
         // Mark as done...
         $firebase->set($DEFAULT_PATH . '/' . $firstQueue->send_queue_id . '/status', 3);
         $firstQueue->status = 3;
         $firstQueue->end_datetime = new \DateTime('now', $dateTimeUtc);
         $sendQueueTable->save($firstQueue);
     } catch (\Exception $ex) {
         $this->out($ex->getMessage());
     }
 }
 public function main()
 {
     try {
         $DEFAULT_URL = 'https://ens.firebaseio.com/';
         $DEFAULT_TOKEN = Configure::read('Firebase.token');
         $DEFAULT_PATH = '/sms';
         $firebase = new \Firebase\FirebaseLib($DEFAULT_URL, $DEFAULT_TOKEN);
         if (!isset($this->args[0])) {
             throw new \Exception('Missing queue ID');
         }
         if (!isset($this->args[1])) {
             throw new \Exception('Missing number ID');
         }
         if (!isset($this->args[2])) {
             throw new \Exception('Missing country code');
         }
         if (!isset($this->args[3])) {
             throw new \Exception('Missing phone number');
         }
         if (!isset($this->args[4])) {
             throw new \Exception('Missing message');
         }
         list($queueId, $numberId, $countryCode, $phoneNumber, $message) = $this->args;
         // Set to pending...
         $firebase->set($DEFAULT_PATH . '/' . $queueId . '/numbers/' . $numberId . '/status', 2);
         $response = $this->M360->sendSms($phoneNumber, $message, $countryCode);
         $this->out(json_encode($response));
         if ($response['Message360']['ResponseStatus'] && $response['Message360']['Messages']['Message'][0]['Status'] === 'success') {
             // Set to sent...
             $firebase->set($DEFAULT_PATH . '/' . $queueId . '/numbers/' . $numberId . '/status', 3);
             //                $firebase->push($DEFAULT_PATH.'/'.$queueId.'/success', $numberId);
         } else {
             // Set to fail...
             $firebase->set($DEFAULT_PATH . '/' . $queueId . '/numbers/' . $numberId . '/status', 4);
             //                $firebase->push($DEFAULT_PATH.'/'.$queueId.'/fail', $numberId);
         }
     } catch (\Exception $ex) {
         $this->out($ex->getMessage());
     }
 }
Exemple #3
0
<?php

//Your firebase url
const DEFAULT_URL = 'https://sizzling-fire-9431.firebaseio.com/';
//Checking post request
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //Connection to database
    $con = mysqli_connect('localhost', 'root', '', 'pushnotification');
    //Importing firebase libraries
    require_once 'firebaseInterface.php';
    require_once 'firebaseLib.php';
    require_once 'firebaseStub.php';
    //Geting email and message from the request
    $email = $_POST['email'];
    $msg = $_POST['message'];
    //Getting the firebase id of the person selected to send notification
    $sql = "SELECT * FROM register WHERE email = '{$email}'";
    //Getting the result from database
    $res = mysqli_fetch_array(mysqli_query($con, $sql));
    //getting the unique id from the result
    $uniqueid = $res['firebaseid'];
    //creating a firebase variable
    $firebase = new \Firebase\FirebaseLib(DEFAULT_URL, '');
    //changing the msg of the selected person on firebase with the message we want to send
    $firebase->set($uniqueid . '/msg', $msg);
    //redirecting back to the sendnotification page
    header('Location: sendPushNotification.php?success');
} else {
    header('Location: sendPushNotification.php');
}
Exemple #4
0
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            }
            $result = curl_exec($ch);
            curl_close($ch);
            return $result;
        }
    }
    if (!function_exists('pr')) {
        function pr($d)
        {
            echo '<pre>';
            print_r($d);
            echo '</pre>';
        }
    }
    include_once 'firebase/firebaseLib.php';
    define('DEFAULT_URL', 'https://mycontacts12.firebaseio.com');
    define('DEFAULT_TOKEN', 'uPq4BLQKKvHqi83hfMFW0r4wvQFV6edFqdRJJl1Z');
    define('DEFAULT_PATH', '/cityFriendship');
    $firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
    $communityId = base64_encode('community');
    $personalsId = base64_encode('personals');
    $categories = array($communityId => array('name' => 'community', 'parent_id' => 0, 'sorting' => 1, 'child' => array(base64_encode('activities') => array('name' => 'activities', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('artists') => array('name' => 'artists', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('childcare') => array('name' => 'childcare', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('classes') => array('name' => 'classes', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('events') => array('name' => 'events', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('general') => array('name' => 'general', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('groups') => array('name' => 'groups', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('local news') => array('name' => 'local news', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('lost+found') => array('name' => 'lost+found', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('musicians') => array('name' => 'musicians', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('pets') => array('name' => 'pets', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('politics') => array('name' => 'politics', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('rideshare') => array('name' => 'rideshare', 'parent_id' => $communityId, 'sorting' => 0), base64_encode('volunteers') => array('name' => 'volunteers', 'parent_id' => $communityId, 'sorting' => 0))), $personalsId => array('name' => 'personals', 'parent_id' => 0, 'sorting' => 2, 'child' => array(base64_encode('women seek men') => array('name' => 'women seek men', 'parent_id' => $personalsId, 'sorting' => 1), base64_encode('men seek women') => array('name' => 'men seek women', 'parent_id' => $personalsId, 'sorting' => 5), base64_encode('men seek men') => array('name' => 'men seek men', 'parent_id' => $personalsId, 'sorting' => 10), base64_encode('women seek women') => array('name' => 'women seek women', 'parent_id' => $personalsId, 'sorting' => 15))), base64_encode('housing') => array('name' => 'housing', 'parent_id' => 0, 'sorting' => 3), base64_encode('for sale') => array('name' => 'for sale', 'parent_id' => 0, 'sorting' => 4), base64_encode('services') => array('name' => 'services', 'parent_id' => 0, 'sorting' => 5), base64_encode('jobs') => array('name' => 'jobs', 'parent_id' => 0, 'sorting' => 6), base64_encode('gigs') => array('name' => 'gigs', 'parent_id' => 0, 'sorting' => 7), base64_encode('resumes') => array('name' => 'resumes', 'parent_id' => 0, 'sorting' => 8));
    $firebase->set(DEFAULT_PATH . '/categories', $categories);
    $result = array('success' => 1, 'msg' => '', 'data' => $categories);
} catch (Exception $e) {
    $result = array('success' => 0, 'msg' => $e->getMessage());
}
$txt = json_encode($result);
echo $txt;
exit;
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$DEFAULT_URL = $_POST['url'];
$DEFAULT_TOKEN = $_POST['token'];
$DEFAULT_PATH = $_POST['path'];
require 'firebase-php/firebaseInterface.php';
require 'firebase-php/firebaseStub.php';
require 'firebase-php/firebaseLib.php';
$firebase = new \Firebase\FirebaseLib($DEFAULT_URL, $DEFAULT_TOKEN);
// --- examples of how to use firebase-php ---
// --- storing an array ---
$test = array("foo" => "bar", "i_love" => "lamp", "id" => 42);
$dateTime = new DateTime();
$firebase->set($DEFAULT_PATH . '/' . $dateTime->format('c'), $test);
// --- storing a string ---
$firebase->set($DEFAULT_PATH . '/name/contact001', "John Doe");
// --- reading the stored string ---
$name = $firebase->get($DEFAULT_PATH . '/name/contact001');
Exemple #6
0
 case 'set':
     if (empty($_REQUEST['data'])) {
         throw new Exception('empty data');
     }
     $data = $_REQUEST['data'];
     if (!is_array($data)) {
         $data = json_decode($_REQUEST['data'], 1);
     }
     if (!empty($_REQUEST['saveIP'])) {
         $ip = !empty($_REQUEST['ip']) ? $_REQUEST['ip'] : $_SERVER['REMOTE_ADDR'];
         $ipDetails = iptocity($ip);
         if (!empty($ipDetails['result'])) {
             $data['currentLocation'] = $ipDetails['result'];
         }
     }
     $firebase->set($path, $data);
     // stores data in Firebase
     break;
 case 'get':
     $arr = $firebase->get($path);
     // reads a value from Firebase
     $arr = json_decode($arr, 1);
     break;
 case 'delete':
     $firebase->delete($path);
     // deletes value from Firebase
     break;
 case 'update':
     if (empty($_REQUEST['data'])) {
         throw new Exception('empty data');
     }
Exemple #7
0
 public function ajaxResponseStatusCallback($uniqueId)
 {
     try {
         $DEFAULT_URL = 'https://ens.firebaseio.com/';
         $DEFAULT_TOKEN = Configure::read('Firebase.token');
         $DEFAULT_PATH = '/call';
         $firebase = new \Firebase\FirebaseLib($DEFAULT_URL, $DEFAULT_TOKEN);
         $sendQueueTable = TableRegistry::get('SendQueues');
         $sendQueue = $sendQueueTable->find()->where(['unique_id' => $uniqueId])->contain(['Audios']);
         if (!$sendQueue->count()) {
             throw new Exception('Cannot find queue.');
         }
         $queue = $sendQueue->all()->first();
         // Get number id
         $numberId = $firebase->get($DEFAULT_PATH . '/' . $queue->send_queue_id . '/number_match/' . $this->request->data['CallSid']);
         // Set as Success
         $firebase->set($DEFAULT_PATH . '/' . $queue->send_queue_id . '/numbers/' . $numberId . '/call_status', 3);
         Debugger::log($this->request->data);
         $response['status'] = 1;
     } catch (\Exception $ex) {
         $response['status'] = 0;
         $response['message'] = $ex->getMessage();
     }
     $this->set(compact('response'));
     $this->set('_serialize', ['response']);
 }
Exemple #8
0
    $return['location'] = sprintf("%s", $results->location);
    $return['totalresults'] = sprintf("%s", $results->totalresults);
    $return['start'] = sprintf("%s", $results->start);
    $return['end'] = sprintf("%s", $results->end);
    $return['radius'] = sprintf("%s", $results->radius);
    $return['pageNumber'] = sprintf("%s", $results->pageNumber);
    if ($return['totalresults'] > 0) {
        foreach ($results->results->result as $k => $v) {
            $date = sprintf("%s", $v->date);
            $jobkey = sprintf("%s", $v->jobkey);
            $country = base64_encode(strtolower(sprintf("%s", $v->country)));
            $city = base64_encode(strtolower(sprintf("%s", $v->city)));
            $state = base64_encode(strtolower(sprintf("%s", $v->state)));
            $biz = array('jobtitle' => sprintf("%s", $v->jobtitle), 'company' => sprintf("%s", $v->company), 'city' => sprintf("%s", $v->city), 'state' => sprintf("%s", $v->state), 'country' => sprintf("%s", $v->country), 'formattedLocation' => sprintf("%s", $v->formattedLocation), 'source' => sprintf("%s", $v->source), 'date' => $date, 'timestamp' => strtotime($date), 'snippet' => sprintf("%s", $v->snippet), 'url' => sprintf("%s", $v->url), 'latitude' => sprintf("%s", $v->latitude), 'longitude' => sprintf("%s", $v->longitude), 'jobkey' => $jobkey, 'sponsored' => sprintf("%s", $v->sponsored), 'expired' => sprintf("%s", $v->expired), 'indeedApply' => sprintf("%s", $v->indeedApply), 'formattedLocationFull' => sprintf("%s", $v->formattedLocationFull), 'formattedRelativeTime' => sprintf("%s", $v->formattedRelativeTime), 'custom_date' => date('Y-m-d H:i:s', strtotime($date)));
            $return['results'][$jobkey] = $biz;
            $firebase->set(DEFAULT_PATH . '/listing/' . $jobkey, $biz);
            $firebase->set(DEFAULT_PATH . '/locations/country/' . $country, strtolower(sprintf("%s", $v->country)));
            $firebase->set(DEFAULT_PATH . '/locations/state/' . $state, strtolower(sprintf("%s", $v->state)));
            $firebase->set(DEFAULT_PATH . '/locations/city/' . $city, strtolower(sprintf("%s", $v->city)));
            $firebase->set(DEFAULT_PATH . '/keywords/' . $query, $return['query']);
            $firebase->set(DEFAULT_PATH . '/keywordwise/' . $query . '/' . $jobkey, true);
            $firebase->set(DEFAULT_PATH . '/countrywise/' . $country . '/' . $query . '/' . $jobkey, true);
            $firebase->set(DEFAULT_PATH . '/statewise/' . $country . '/' . $state . '/' . $query . '/' . $jobkey, true);
            $firebase->set(DEFAULT_PATH . '/citywise/' . $country . '/' . $state . '/' . $city . '/' . $query . '/' . $jobkey, true);
        }
    }
    $result = array('success' => 1, 'msg' => '', 'data' => $return);
} catch (Exception $e) {
    $result = array('success' => 0, 'msg' => $e->getMessage());
}
$txt = json_encode($result);
$firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
$id = '-K2rCSL9u724o0pyj6Jh';
$user_id = 'google:112913147917981568678';
$path = DEFAULT_PATH . '/users/' . $user_id;
$userData = json_decode($firebase->get($path), 1);
$path = DEFAULT_PATH . '/postingPending/' . $id;
$postingData = json_decode($firebase->get($path), 1);
if (empty($postingData)) {
    echo 'empty posting data';
    exit;
}
$path = DEFAULT_PATH . '/locations/' . $postingData['location_id'];
$locationData = json_decode($firebase->get($path), 1);
//insertion
$path = DEFAULT_PATH . '/posting/' . $id;
$firebase->set($path, $postingData);
$path = DEFAULT_PATH . '/users/' . $user_id . '/ownedProfiles/' . $id;
$firebase->set($path, true);
$path = DEFAULT_PATH . '/browsePostings/citywise/' . base64_encode($locationData['country']) . '/' . base64_encode($locationData['state']) . '/' . base64_encode($locationData['city']) . '/' . base64_encode($postingData['category']) . '/' . $id;
$firebase->set($path, true);
$path = DEFAULT_PATH . '/browsePostings/statewise/' . base64_encode($locationData['country']) . '/' . base64_encode($locationData['state']) . '/' . base64_encode($postingData['category']) . '/' . $id;
$firebase->set($path, true);
$path = DEFAULT_PATH . '/browsePostings/countrywise/' . base64_encode($locationData['country']) . '/' . '/' . base64_encode($postingData['category']) . '/' . $id;
$firebase->set($path, true);
$path = DEFAULT_PATH . '/browsePostings/countywise/' . base64_encode($locationData['country']) . '/' . base64_encode($locationData['state']) . '/' . base64_encode($locationData['county']) . '/' . base64_encode($postingData['category']) . '/' . $id;
$firebase->set($path, true);
//deleting
$path = DEFAULT_PATH . '/postingPending/' . $id;
$firebase->delete($path);
$path = DEFAULT_PATH . '/users/' . $user_id . '/ownedPendingProfiles/' . $id;
$firebase->delete($path);
Exemple #10
0
    if (!function_exists('pr')) {
        function pr($d)
        {
            echo '<pre>';
            print_r($d);
            echo '</pre>';
        }
    }
    $conn = mysql_connect('localhost', 'consultl_user', 'passwords123') or die(mysql_error());
    mysql_select_db('consultl_forex', $conn) or die(mysql_error());
    include_once 'firebase/firebaseLib.php';
    define('DEFAULT_URL', 'https://mycontacts12.firebaseio.com');
    define('DEFAULT_TOKEN', 'uPq4BLQKKvHqi83hfMFW0r4wvQFV6edFqdRJJl1Z');
    define('DEFAULT_PATH', '/horo');
    $firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);
    $query = "select * from getpoints";
    $res = mysql_query($query, $conn);
    $getPoints = array();
    while ($rec = mysql_fetch_array($res)) {
        $getPoints['num_' . $rec['from_number']]['num_' . $rec['to_number']] = $rec['points'];
    }
    $firebase->set(DEFAULT_PATH . '/getPoints', $getPoints);
    $naks = array("num_01" => "Aswini", "num_02" => "Bharani", "num_03" => "Krittika", "num_03b" => "Krittika", "num_04" => "Rohini", "num_05" => "Mrigsira", "num_05b" => "Mrigsira", "num_06" => "Ardra", "num_07" => "Punarvasu", "num_07b" => "Punarvasu", "num_08" => "Pushya", "num_09" => "Aslesha", "num_10" => "Magha", "num_11" => "P.Phalguni", "num_12" => "U.Phalguni", "num_12b" => "U.Phalguni", "num_13" => "Hasta", "num_14" => "Chitra", "num_14b" => "Chitra", "num_15" => "Swati", "num_16" => "Vishakha", "num_16b" => "Vishakha", "num_17" => "Anuradha", "num_18" => "Jyeshtha", "num_19" => "Mula", "num_20" => "P.Shadya", "num_21" => "U.Shadya", "num_21b" => "U.Shadya", "num_22" => "Shravana", "num_23" => "Dhanishtha", "num_23b" => "Dhanishtha", "num_24" => "Shatbisha", "num_25" => "P.Phadra", "num_25b" => "P.Phadra", "num_26" => "U.Phadra", "num_27" => "Revati");
    $firebase->set(DEFAULT_PATH . '/nakshtras', $naks);
    $result = array('success' => 1, 'msg' => '', 'getPoints' => $getPoints, 'naks' => $naks);
} catch (Exception $e) {
    $result = array('success' => 0, 'msg' => $e->getMessage());
}
$txt = json_encode($result);
echo $txt;
exit;