/** * loop through twitter messages, put them to database and send them to qaul app */ function twitter_process_messages($data, $type) { foreach ($data as $item) { // check if message already exists $msg = MsgQuery::create()->filterByTwitterid($item->id_str)->findOne(); if (!$msg) { // save message in data base $msg = new Msg(); $msg->setType($type); $msg->setName($item->user->screen_name); $msg->setMsg($item->text); $msg->setIp(get_qaul_setting('ip')); $msg->setTime($item->created_at); $msg->setStatus(0); $msg->setTwitterid($item->id_str); $msg->save(); // send message to qaul app twitter_send2qaul($msg); } } }
$data = json_decode($json, false); // loop through messages foreach ($data->messages as $message) { // check if message is connection if ($message->type == 13 || $message->type == 3) { // don't do anything } elseif ($message->type == 11 || $message->type == 12) { // don't do anything // message was already added before sending it to the qaul app } elseif (file_check_msg($message->msg)) { // schedule file file_schedule($message); } elseif ($message->type == 1) { // don't do anything } elseif ($message->type == 2) { // put message into data base $msg = new Msg(); $msg->setType($message->type); $msg->setName($message->name); $msg->setMsg($message->msg); $msg->setIp($message->ip); $msg->setTime($message->time); $msg->setStatus(0); $msg->save(); // send message via twitter $txt = twitter_message_string_utf8($msg->getMsg(), $msg->getName()); twitter_send2twitter($txt); // wait before sending the next message sleep(1); } }