Exemplo n.º 1
0
 public function destroy($id)
 {
     if (\Request::ajax()) {
         $db = Outbox::destroy($id);
         return $db;
     }
 }
Exemplo n.º 2
0
 public function store()
 {
     $dst = \Input::get('destination');
     $msg = \Input::get('message');
     $schedule = \Input::has('schedule') ? \Input::get('schedule') : null;
     if (\Input::get('state') == 0) {
         $e = array_map('trim', explode(',', $dst));
         foreach ($e as $key) {
             if ($key) {
                 $contact = Contact::where('Name', '=', $key)->first();
                 $group = Group::where('Name', '=', $key)->first();
                 if ($contact) {
                     return Outbox::create(['DestinationNumber' => $contact['Number'], 'SendingDateTime' => $schedule, 'TextDecoded' => $msg, 'CreatorID' => 'users.' . \Auth::user()->id]);
                 } else {
                     if ($group) {
                         return Outbox::SendToGroup($group->Name, $msg, $schedule);
                     } else {
                         return Outbox::create(['DestinationNumber' => $key, 'SendingDateTime' => $schedule, 'TextDecoded' => $msg, 'CreatorID' => 'users.' . \Auth::user()->id]);
                     }
                 }
             }
         }
     } else {
         return Outbox::create(['DestinationNumber' => $dst, 'TextDecoded' => $msg, 'CreatorID' => 'users.' . \Auth::user()->id]);
     }
 }
Exemplo n.º 3
0
 public function kirimsms()
 {
     $token = \Input::get('token');
     $db = Api::where('token', $token)->first();
     if ($db) {
         if ($db['access_ip'] != '' && \Request::getClientIp() != $db['access_ip']) {
             abort(404);
         }
         $rules = ['message' => 'required', 'number' => 'required|between:10,14'];
         $validator = \Validator::make(\Input::all(), $rules);
         if ($validator->fails()) {
             $return = $validator->messages()->toJson();
             return \Response::json($return);
         } else {
             $message = \Input::get('message');
             $number = trim(\Input::get('number'));
             $send = Outbox::create(['DestinationNumber' => $number, 'TextDecoded' => $message, 'CreatorID' => 'apis.' . $db['id']]);
             return 1;
         }
     } else {
         abort(403);
     }
 }
Exemplo n.º 4
0
 public static function daemon()
 {
     $data = Keyword::where('status', '1')->get();
     foreach ($data as $row) {
         $name = $row['name'];
         $keyword = $row['keyword'];
         $url = $row['url'];
         $joingroup_id = $row['joingroup_id'];
         $text_reply = $row['text_reply'];
         /* Pakai keyword */
         if ($keyword != '') {
             $second_keyword_count = preg_match_all("/\\[([^\\]]*)\\]/", $keyword, $second_keyword_match);
             //[]
             $main_keyword = Keyword::main($keyword);
             $db = Keyword::inbox($main_keyword);
             if ($db) {
                 // Ada inbox yang sesuai keyword
                 foreach ($db as $key) {
                     //set inbox:prosessed to true
                     Inbox::process($key->id);
                     // Action URL request
                     if ($url != '') {
                         unset($query);
                         unset($patterns);
                         unset($replacements);
                         $url_match = Keyword::url($url);
                         $query = ['sender' => urlencode($key->hp), 'message' => urlencode(trim(substr($key->isi, strlen($main_keyword)))), 'content' => urlencode($key->isi), 'time' => urlencode($key->waktu)];
                         foreach ($url_match as $key1) {
                             $patterns[] = '/\\${' . $key1 . '}/';
                             $replacements[] = $query[$key1];
                         }
                         $newurl = preg_replace($patterns, $replacements, $url);
                         //${}
                         /* SECOND KEYWORD [] (belum selesai)*/
                         if ($second_keyword_count > 0) {
                             unset($patterns2);
                             unset($replacements2);
                             $main_keyword_count = strlen($main_keyword);
                             $first = strtok($key->isi, " ");
                             $explode_keyword = explode(']', substr($keyword, strlen($main_keyword)));
                             $delimiter = substr($explode_keyword[1], 0, strpos($explode_keyword[1], '['));
                             foreach ($second_keyword_match[1] as $key2) {
                                 $patterns2[] = '/\\$\\[' . $key2 . '\\]/';
                                 $replacements2[] = $key->isi;
                                 #substr($key->isi, $main_keyword_count);
                             }
                             $newest_url = preg_replace($patterns2, $replacements2, $newurl) . ' (baru)<br>keyword:' . $keyword . '||isi:' . $key->isi . '<br>';
                             $return_url[] = $newest_url;
                         } else {
                             $return_url[] = $newurl;
                         }
                     } else {
                         $return_url[] = '';
                     }
                     // Auto add to contact and group
                     if ($joingroup_id) {
                         $firstname = $keyword ? $keyword : $name;
                         $contactname = $firstname . '-' . substr($key->hp, -3);
                         $cc = new ContactController();
                         $cc->newContact($key->hp, $contactname, $joingroup_id);
                     }
                     // Autoreply
                     if ($text_reply) {
                         Outbox::create(['DestinationNumber' => $key->hp, 'TextDecoded' => $text_reply, 'CreatorID' => 'keywords.' . $row['id']]);
                     }
                 }
             } else {
                 // Inbox tidak ada yang sesuai filter keyword
                 $return_url[] = '';
             }
         } else {
             //maaf keyword salah / tidak sesuai format
             $db = Inbox::where('Processed', 'false')->get();
             // dd($db);
         }
     }
     return $return_url;
 }