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 untrashPost($postId) { $post = get_post($postId); if ($post->post_type !== 'poll') { return; } $secret = get_field('agreable_poll_plugin_settings_firebase_secret', 'options'); $firebase = new \Firebase\FirebaseLib('https://senti.firebaseio.com/', $secret); $path = $this->getPath($postId); $firebase->update($path, array('trashed' => false)); }
public function postCashExchange(Request $request) { $firebase = new \Firebase\FirebaseLib(env('FIREBASE_URL'), env('FIREBASE_SECRET')); $commissions = json_decode($firebase->get('users/' . Auth::user()->id)); //dd($commissions); $total_earned = (double) $commissions->total_own_time * 0.013888889; if ($total_earned < 250000) { return view('product.sorry'); } $new_own_time = ($total_earned - 250000) / 0.013888889; $dollars = ["total_own_time" => $new_own_time]; $firebase->update('users/' . Auth::user()->id, $dollars); $cashout = Cashout::create(['user_id' => Auth::user()->id]); return view('product.cashout-thanks'); }
case 'update': 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->update($path, $data); // updates data in Firebase break; case 'push': 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'];
//determine "total-time" if (isset($formatted_recipe['prepTime']) && isset($formatted_recipe['cookTime']) && $formatted_recipe['prepTime'] !== "" && $formatted_recipe['cookTime'] !== "") { $formatted_recipe['totalTime'] = $formatted_recipe['prepTime'] + $formatted_recipe['cookTime']; } else { if (isset($formatted_recipe['prepTime']) && !isset($formatted_recipe['cookTime'])) { $formatted_recipe['totalTime'] = $formatted_recipe['prepTime']; } else { if (!isset($formatted_recipe['prepTime']) && isset($formatted_recipe['cookTime'])) { $formatted_recipe['totalTime'] = $formatted_recipe['cookTime']; } else { $formatted_recipe['totalTime'] = ""; } } } //$var_is_greater_than_two = ($var > 2 ? true : false); //$message = 'Hello '.($user->get('first_name') ?: 'Guest'); $formatted_recipe['nutrition'] = $recipe['recipe']['serving_sizes']['serving']; echo '<br>Formatted recipe<pre>'; print_r($formatted_recipe); echo "<br/><br/>"; $taste = determine_taste($formatted_recipe); $formatted_recipe['taste'] = $taste; echo $taste; //save recipe to firebase if (!isset($recipe['error'])) { $token = FB_TOKEN; $url = 'https://phoodbuddy.firebaseio.com'; $firebase = new \Firebase\FirebaseLib($url, $token); $firebase->update("/recipe-directory/{$selected_recipe_id}", $formatted_recipe); } }
public function updateDollars(Request $request, $id) { $firebase = new \Firebase\FirebaseLib(env('FIREBASE_URL'), env('FIREBASE_SECRET')); $commissions = json_decode($firebase->get('users/' . $id)); $total_all_time = number_format((double) $commissions->total_all_time * 0.013888889, 2); $new_own_time = $request->dollars / 0.013888889; $new_total_all_time = $total_all_time + $new_own_time; $dollars = ["total_own_time" => $new_own_time, "total_all_time" => $new_total_all_time]; $firebase->update('users/' . $id, $dollars); return redirect('/cms/user/' . $id . '/edit')->withSuccess('User Successfully Updated'); }
public function purchaseProduct($slug) { $product = Product::where('slug', $slug)->firstOrFail(); $firebase = new \Firebase\FirebaseLib(env('FIREBASE_URL'), env('FIREBASE_SECRET')); $commissions = json_decode($firebase->get('users/' . Auth::user()->id)); //dd($commissions); $total_earned = number_format((double) $commissions->total_own_time * 0.013888889, 2); if ($total_earned < $product->price) { return view('product.sorry'); } $purchase = Purchase::create(['user_id' => Auth::user()->id, 'product_id' => $product->id]); $new_own_time = ($total_earned - $product->price) / 0.013888889; $dollars = ["total_own_time" => $new_own_time]; $firebase->update('users/' . Auth::user()->id, $dollars); return view('product.thanks', compact('product')); }
public function save_post($post_id) { $post = get_post($post_id); if ($post_id == 'options' || !isset($post->post_type) || $post->post_type !== 'poll' || isset($_POST['acf']) === false) { return; } //Both user and secret set in the WP settings. $userId = get_field('agreable_poll_plugin_settings_senti_user_id', 'options'); $secret = get_field('agreable_poll_plugin_settings_firebase_secret', 'options'); if (empty($secret) || empty($userId)) { return false; } $firebase = new \Firebase\FirebaseLib('https://senti.firebaseio.com/', $secret); $path = 'polls'; $acf = $_POST['acf']; // Empty poll obj. $poll = array('question' => html_entity_decode(get_the_title($post_id), ENT_QUOTES, 'UTF-8'), 'userId' => $userId, 'answers' => array()); $answers = get_field('agreable_poll_definition_answers', $post_id); // Loop through answers in ACF. foreach ($answers as $answer) { array_push($poll['answers'], array('text' => $answer['answer_text'], 'votes' => $answer['answer_votes'])); } $firebasePollId = get_field('agreable_poll_definition_firebase_id', $post_id); // Update or insert based on presence of firebase_id. if (empty($firebasePollId) === false) { // Update. $return = $firebase->update($path . '/' . $userId . '/' . $firebasePollId, $poll); } else { // Insert. $poll['entries'] = 0; $poll['created_at'] = round(microtime(true) * 1000); $return = $firebase->push($path . '/' . $userId, $poll); // Insert object contains firebase id. $returnJSON = json_decode($return); update_field('agreable_poll_definition_firebase_id', $returnJSON->name, $post_id); $post_answers = $_POST['acf']['agreable_poll_definition_answers']; for ($i = 0; $i < count($post_answers); $i++) { update_post_meta($post_id, "poll_answers_{$i}_answer_index", $i); } } }