示例#1
0
 public function actionNewmsg()
 {
     $model = new Msg();
     if (isset($_POST['Msg'])) {
         $model->uid = Yii::app()->user->id;
         $model->time = time();
         $model->state = 1;
         $model->attributes = $_POST['Msg'];
         if ($model->save()) {
             $this->redirect_message('私信发送成功!', 'success', '3', $this->createUrl('msg/inbox'));
         }
     }
     $fans = Follow::model()->findAll('touid = ' . Yii::app()->user->id);
     $data = array('model' => $model, 'fans' => $fans);
     $this->render('newmsg', $data);
 }
示例#2
0
 function save()
 {
     $this->success = false;
     $this->POD->tolog("alert->save()");
     if (!$this->POD->isAuthenticated()) {
         $this->throwError("No current user! Can't save alert!");
         return null;
     }
     if (!$this->targetUserId) {
         $this->throwError("Missing required field 'targetUserId'! Can't save alert!");
     }
     if (!$this->message) {
         $this->throwError("Missing required field 'message'! Can't save alert!");
     }
     if (!$this->saved()) {
         $this->set('date', 'now()');
     }
     parent::save();
 }
示例#3
0
/**
 * 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);
        }
    }
}
示例#4
0
 public function actionWrite()
 {
     $this->setPageTitle('写短消息');
     $model = new Msg();
     $this->performAjaxValidation($model);
     $uid = Yii::app()->request->getQuery('uid');
     if ($uid) {
         $user = new User();
         $toUserFace = $user->getUserFace($uid);
         $toUserName = $user->getUserName($uid);
         $model->toUserId = $uid;
     }
     $replyMsgId = Yii::app()->request->getQuery('replyMsgId');
     if ($replyMsgId) {
         $model->replyMsgId = $replyMsgId;
     }
     $mid = Yii::app()->user->id;
     if (!empty($_POST['Msg'])) {
         $attributes = $_POST['Msg'];
         $model->attributes = $attributes;
         $model->save();
         if (empty($model->errors)) {
             $this->redirect(array('show', 'msg_id' => $model->primaryKey));
         }
         //$model->validate();
     }
     if (isset($_POST['Msg'])) {
         $friend_ids = $_POST['friend_ids'];
         if (!empty($friend_ids)) {
             //先对某个用户发送问候
             foreach ($friend_ids as $toUserid) {
                 $model = new Msg();
                 $model->attributes = $_POST['Msg'];
                 $model->toUserId = $toUserid;
                 $model->fromUserId = $mid;
                 $result = $model->save();
             }
             if ($result == true) {
                 $this->redirectMessage('发送短信息成功!', array('outbox'), 20);
             }
             //请选择好友
             //throw new CHttpException(404,'请选择好友.');
         }
     }
     $data = array('toUserFace' => $toUserFace, 'toUserName' => $toUserName, 'toUserId' => $uid, 'model' => $model);
     $this->render('write', $data);
 }
示例#5
0
 /**
  * @reply 在当前消息下回复对方
  */
 public function actionReply()
 {
     $arr = array();
     if (Yii::$app->request->isAjax) {
         $msg = Yii::$app->request->post("Msg");
         $obj = new Msg();
         $obj->fid = $msg['fid'];
         $obj->tid = $msg['tid'];
         $obj->title = $msg['title'];
         $obj->content = $msg['content'];
         $obj->reply = $msg['reply'];
         $obj->send_time = time();
         $obj->save();
         $arr['status'] = 1;
     } else {
         $arr['status'] = 0;
     }
     echo json_encode($arr);
 }
示例#6
0
	function doDel() {
		try {
			$this->lookup = LookupDao::byId($this->id);
			DB::delete("lookups", $this->lookup);
			Apu::redirect("lookup");
		} catch (Exception $e) {
			$this->addMsgString($e->getMessage());
			Msg::save($this->messages);
			Apu::redirect("lookup");
		}
	}
示例#7
0
 function save($ok_to_send_email = true)
 {
     $this->success = false;
     if (!$this->POD->isAuthenticated()) {
         $this->throwError("Access Denied");
         $this->error_code = 401;
         return null;
     }
     if ($this->get('message') == "" || $this->get('targetUserId') == "") {
         $this->throwError("Fields missing!");
         $this->error_code = 500;
         return null;
     }
     //		$this->set('message',strip_tags($this->get('message')));
     if (!$this->saved()) {
         $this->set('fromId', $this->POD->currentUser()->get('id'));
         $from = $this->get('fromId');
         $to = $this->get('targetUserId');
         // for messages, we need to insert two near duplicate rows,
         // one for the sender and one for the recipient
         // we can do this by just swapping the values.
         // first create the recipient
         $this->set('userId', $to);
         $this->set('targetUserId', $from);
         $this->set('status', 'new');
         $this->set('date', 'now()');
         parent::save();
         // now create the sender version
         $this->set('userId', $from);
         $this->set('targetUserId', $to);
         $this->set('status', 'read');
         $this->set('id', null);
         parent::save();
         if ($ok_to_send_email === true && $this->POD->libOptions('contactEmail')) {
             $this->from()->sendEmail("contact", array('to' => $this->to()->get('email'), 'message' => $this->get('message')));
         }
     } else {
         parent::save();
     }
     return $this;
 }
示例#8
0
	function doLogout() {
		$this->addMsgMessage("message.alreadyLogout");
		Session::destroy();
		Msg::save($this->messages);
		Apu::redirect("login");
	}
示例#9
0
$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);
    }
}