本文整理汇总了PHP中Message::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::validate方法的具体用法?PHP Message::validate怎么用?PHP Message::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message::validate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
public function actionIndex()
{
//未提示客户端
$platform = 'android';
if (isset($_GET['p'])) {
$platform = $_GET['p'];
}
$message = new Message();
$relation = new Relation();
if (isset($_POST['Message'])) {
$message->attributes = $_POST['Message'];
if (!empty($message->plan)) {
$message->type = '3';
}
if ($message->validate()) {
$message->file = $this->upload($message);
if (UserState::model()->findByPk($message->receiver)->type == 0) {
$message->chat('android');
} else {
$message->chat('ios');
}
}
}
$this->render('index', array('message' => $message));
}
示例2: add
public function add()
{
$user = $this->getUser();
if (RequestMethods::post("share")) {
$message = new Message(array("body" => RequestMethods::post("body"), "message" => RequestMethods::post("message"), "user" => $user['id']));
if ($message->validate()) {
$message->save();
$this->redirect('/');
}
}
}
示例3: actionAdd
public function actionAdd()
{
$this->pageTitle = Yii::t('page-title', 'Add new message dialog');
$model = new Message();
if (Yii::app()->request->isPostRequest) {
$model->attributes = $_POST['Message'];
if ($model->validate()) {
$model->create();
$this->redirect('/message/list');
}
}
$this->render('add', ['model' => $model]);
}
示例4: sendPM
public function sendPM($hash)
{
if (Request::isMethod('GET')) {
$user = User::where('public_hash', '=', $hash)->firstOrFail();
return View::make('user.anonpm', ['user' => $user]);
} else {
if (!Input::get('captcha') || !$this->checkCaptcha()) {
return View::make('verif.pm_verif');
}
$input = Input::only('message');
Message::validate($input);
$user = User::where('public_hash', '=', $hash)->firstOrFail();
Message::send($user->user_fp, $input);
return Redirect::to('u/' . $hash);
}
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// Validate input
$v = Message::validate(Input::all());
if ($v !== true) {
return Redirect::route('messages.create')->withErrors($v->errors());
}
$msg = new Message();
// Generate a key
$key = sha1(microtime(true) . mt_rand(10000, 90000));
// Generate an IV
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CFB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
// Encrypt the message
$body = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, Input::get('body'), MCRYPT_MODE_CFB, $iv);
// Save the message to the database
$msg->body = $body;
$msg->url = Message::get_unique_url();
$msg->iv = $iv;
$msg->save();
// Return the view
return View::make('messages.store', ['url' => $msg->url, 'key' => $key]);
}
示例6: actionNewgroup
public function actionNewgroup()
{
$this->module->registerConfig($this->getAction()->getId());
$cs = $this->module->getClientScript();
$cs->registerScriptFile($this->module->getAssetsUrl() . '/js/compose.js');
$cs->registerScriptFile($this->module->getAssetsUrl() . '/js/jquery.combobox.contacts.js');
$js = '$(".mailbox-compose").yiiMailboxCompose(' . $this->module->getOptions() . ");";
$cs->registerScript('mailbox-js', $js, CClientScript::POS_READY);
if (!$this->module->authManager && (!$this->module->sendMsgs || $this->module->readOnly && !$this->module->isAdmin())) {
$this->redirect(array('message/inbox'));
}
if (isset($_POST['Mailbox']['to']) and $_POST['Mailbox']['to'] != NULL) {
$users = AuthAssignment::model()->findAllByAttributes(array('itemname' => $_POST['Mailbox']['to']));
if ($users != NULL) {
foreach ($users as $user) {
$t = time();
$conv = new Mailbox();
$conv->subject = $_POST['Mailbox']['subject'] ? $_POST['Mailbox']['subject'] : $this->module->defaultSubject;
$conv->to = $user->userid;
$conv->initiator_id = $this->module->getUserId();
$conv->interlocutor_id = $user->userid;
if ($conv->interlocutor_id && $conv->initiator_id == $conv->interlocutor_id) {
$conv->addError('to', "Can't send message to self!");
}
if (!$this->module->isAdmin() && $conv->interlocutor_id == $this->module->newsUserId) {
$conv->addError('to', "User not found?");
}
// check user-to-user perms
if (!$conv->hasErrors() && !$this->module->userToUser && !$this->module->isAdmin()) {
if (!$this->module->isAdmin($conv->to)) {
$conv->addError('to', "Invalid user!");
}
}
$conv->modified = $t;
$conv->bm_read = Mailbox::INITIATOR_FLAG;
if ($this->module->isAdmin()) {
$msg = new Message('admin');
} else {
$msg = new Message('user');
}
$msg->text = $_POST['Message']['text'];
$validate = $conv->validate(array('text'), false);
// html purify
$msg->created = $t;
$msg->sender_id = $conv->initiator_id;
$msg->recipient_id = $conv->interlocutor_id;
if ($this->module->checksums) {
$msg->crc64 = Message::crc64($msg->text);
// 64bit INT
} else {
$msg->crc64 = 0;
}
// Validate
$validate = $conv->validate(null, false);
// don't clear errors
$validate = $msg->validate() && $validate;
if ($validate) {
$conv->save();
$msg->conversation_id = $conv->conversation_id;
$msg->save();
}
Yii::app()->user->setFlash('success', "Message has been sent!");
}
$this->redirect(array('message/inbox'));
} else {
Yii::app()->user->setFlash('error', "Error sending message!");
Yii::app()->user->setFlash('success', "Check Sent Mail");
}
} else {
$conv = new Mailbox();
if (isset($_GET['id'])) {
$conv->to = $this->module->getUserName($_GET['id']);
} elseif (isset($_GET['to'])) {
$conv->to = $_GET['to'];
} else {
$conv->to = '';
}
$msg = new Message();
}
$this->render('composetogroup', array('conv' => $conv, 'msg' => $msg));
}
示例7: actionMessages
/**
* Выводит сообщения - список последних с группировкой по пользователю
* отделить вывод сообщений отдельного пользователя
* @param int $id - ID-шник пользователя для переписки
* @throws CHttpException - незарегистрированный пользователь
*/
public function actionMessages($id = 0)
{
// уберется в фильтре
if (Yii::app()->user->isGuest) {
throw new CHttpException(403, 'Чтобы просматривать эту страницу следует зарегистрироваться');
}
if (empty($id)) {
// messages list
$messages = Message::model()->active()->lastMessages();
$users = Anketa::model()->with('mainphotoimage')->findAllByPk(array_keys($messages), array('index' => 'id'));
$this->render('messages', array('messages' => $messages, 'users' => $users));
Yii::app()->end();
}
//$me = $this->loadModel($id);
// сохранить в сессии
$me = Anketa::model()->with('mainphotoimage')->findByPk(Yii::app()->user->id);
$user = Anketa::model()->with('mainphotoimage')->findByPk($id);
$welike = Anketa::isWelike($user->id, Yii::app()->user->id);
$message = new Message('send');
if (isset($_POST['Message'])) {
if (!$welike) {
Yii::app()->user->setFlash('error', 'Отправлять сообщения можно только по взаимной симпатии');
$this->refresh();
}
$message->attributes = $_POST['Message'];
$message->id_from = Yii::app()->user->id;
$message->id_to = $user->id;
if ($message->validate()) {
$message->save();
$this->refresh();
}
}
$messages = Message::model()->active()->fromto($id)->findAll();
if (empty($messages) && !$welike) {
throw new CHttpException('403', 'Переписка возможна только по взаимной симпатии');
}
foreach ($messages as $message1) {
if ($message1->id_to == Yii::app()->user->id) {
$message1->viewed = true;
$message1->saveAttributes(array('viewed'));
}
}
$this->render('messages_one', array('messages' => $messages, 'me' => $me, 'user' => $user, 'posted' => $message, 'hideform' => !$welike));
}
示例8: sendMessage
public function sendMessage($hash)
{
$input = Input::only('message');
Message::validate($input);
$user = User::where('public_hash', '=', $hash)->firstOrFail();
Message::send($user->user_fp, $input);
return Response::jsonOk();
}
示例9: actionReply
public function actionReply()
{
if (!$this->module->authManager && (!$this->module->sendMsgs || $this->module->readOnly && !$this->module->isAdmin())) {
$this->redirect(array('message/inbox'));
}
$this->module->registerConfig($this->getAction()->getId());
if ($this->module->isAdmin()) {
$reply = new Message('admin');
} else {
$reply = new Message('user');
}
$conv = Mailbox::conversation($_GET['id']);
if (isset($_POST['text'])) {
$reply->text = $_POST['text'];
$validate = $conv->validate(array('text'), false);
// html purify
$reply->conversation_id = $conv->conversation_id;
if ($conv->initiator_id != Yii::app()->user->id) {
$reply->recipient_id = $conv->initiator_id;
$conv->bm_read = $conv->bm_read & ~Mailbox::INITIATOR_FLAG;
} else {
$reply->recipient_id = $conv->interlocutor_id;
$conv->bm_read = $conv->bm_read & ~Mailbox::INTERLOCUTOR_FLAG;
}
$reply->sender_id = $this->module->getUserId();
$reply->created = time();
$conv->modified = $reply->created;
$reply->crc64 = Message::crc64($reply->text);
$conv->bm_deleted = 0;
// restore message
$conv->interlocutor_del = 0;
$conv->initiator_del = 0;
$validate = $reply->validate();
$validate = $conv->validate() && $validate;
if ($validate) {
$conv->save();
$reply->save();
Yii::app()->user->setFlash('success', "Message sent!");
$this->redirect(array('message/inbox'));
} else {
Yii::app()->user->setFlash('error', "Error sending message!");
$this->render('message', array('conv' => $conv, 'reply' => $reply));
}
}
}
示例10: actionMessages
/**
* Выводит сообщения - список последних с группировкой по пользователю
* отделить вывод сообщений отдельного пользователя
* @param int $id - ID-шник пользователя для переписки
* @throws CHttpException - незарегистрированный пользователь
*/
public function actionMessages($id = 0, $folder = 0, $mode = 0)
{
if (Yii::app()->user->isGuest) {
$this->actionFakeMessages($id);
}
if (Yii::app()->user->id == $id) {
// нельзя писать самому себе
throw new CHttpException(404, 'Страница не найдена');
}
if (!($currentFolder = MessageFolder::model()->findByPk($folder))) {
throw new CHttpException(404, 'Папка не найдена');
}
if (empty($id)) {
// messages list
$messages = MessageCount::model()->lastMessages(null, $folder);
$users = Anketa::model()->with('mainphotoimage')->findAllByPk(array_keys($messages), array('index' => 'id'));
$newCnt = MessageCount::newMessages(null, array_keys($messages));
$this->render('messages', array('messages' => $messages, 'users' => $users, 'currentFolder' => $currentFolder, 'newCnt' => $newCnt));
Yii::app()->end();
}
// сохранить в сессии не будем, т.к. см ниже
$me = Anketa::model()->with('mainphotoimage')->findByPk(Yii::app()->user->id);
$user = Anketa::model()->with('mainphotoimage')->findByPk($id);
if (!$me || $me->isdeleted) {
Yii::app()->user->logout(false);
Yii::app()->end();
}
// if (!user || $user->isdeleted) {throw new CHttpException(403,'Анкета удалена');}
$welike = 1;
// Anketa::isWelike($user->id,Yii::app()->user->id);
$message = new Message('send');
if (isset($_POST['Message'])) {
if (!$welike) {
Yii::app()->user->setFlash('error', 'Отправлять сообщения можно только по взаимной симпатии');
$this->refresh();
}
if ($me->disallowMessageTo($user)) {
Yii::app()->user->setFlash('error', 'Отправка сообщения запрещена');
$this->refresh();
}
$message->attributes = $_POST['Message'];
$message->id_from = Yii::app()->user->id;
$message->id_to = $user->id;
if ($message->validate()) {
// вычитаем контакт, если диалога раньше не было
if (!$me->wasDialogTo($user)) {
MessageFolder::addDefaultFolder($me->id, $user->id);
$me->updateCounters(array('contact_count' => -1), 'id=' . $me->id);
}
$message->save();
$this->refresh();
}
}
$all = (bool) $mode;
$count = Message::model()->active()->fromto($id)->count();
$all = $count < 25 || $all;
if ($all) {
$messages = Message::model()->active()->fromto($id)->findAll(array('order' => 'id'));
} else {
$messages = Message::model()->active()->fromto($id)->findAll(array('order' => 'id DESC', 'limit' => 10));
$messages = array_reverse($messages);
}
if (empty($messages) && !$welike) {
throw new CHttpException('403', 'Переписка возможна только по взаимной симпатии');
}
foreach ($messages as $message1) {
if ($message1->id_to == Yii::app()->user->id && $message1->viewed == false) {
$message1->viewed = true;
$message1->saveAttributes(array('viewed'));
}
}
$this->render('messages_one', array('messages' => $messages, 'me' => $me, 'user' => $user, 'posted' => $message, 'hideform' => !$welike, 'all' => $all));
}
示例11: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Message();
$model->user_id = Yii::app()->user->id;
$model->modified = date('Y-m-d H:i:s');
//define original and posted grid details
$user_messagePost = array();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Message'])) {
$validToSave = TRUE;
//~~~set the posted in models~~~
$model->attributes = $_POST['Message'];
if (isset($_POST['UserMessage'])) {
foreach ($_POST['UserMessage'] as $index => $submittedDetail) {
$user_message = new UserMessage();
$user_message->attributes = $submittedDetail;
$user_message->message_id = 0;
$user_message->message_read = 0;
$user_message->created = date('Y-m-d H:i:s');
//uncoment condition if need condition.
//if ($user_message->id > 0) {
array_push($user_messagePost, $user_message);
//}
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//~~~validate all~~~~
if (!$model->validate()) {
$validToSave = FALSE;
die(print_r($model->getErrors()));
}
foreach ($user_messagePost as $index => $user_message) {
//add some condition if needed
//$user_message->id > 0 &&
if (!$user_message->validate()) {
$validToSave = FALSE;
die(print_r($user_message->getErrors()));
//break;
}
}
//~~~~~~~~~~~~~~~~~~~~
if ($validToSave) {
if ($model->save()) {
//~~~save details~~~
foreach ($user_messagePost as $index => $user_message) {
$user_message->message_id = $model->id;
if ($user_message->save()) {
//die('saved');
} else {
die('not saved');
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~
} else {
}
if (isset($_POST["saveandedit"])) {
$this->redirect(array('update', 'id' => $model->id));
} elseif (isset($_POST["save"])) {
$this->redirect(array('admin'));
}
} else {
}
//~~~~~~~~~~~~~~~~~~~~~~~
} else {
//not posted
}
$this->render('create', array('model' => $model, 'user_message' => $user_messagePost));
}
示例12: actionReply
public function actionReply()
{
$this->networkheader = 'mailbox';
// Added on 29-01-2013
if (!$this->module->authManager && (!$this->module->sendMsgs || $this->module->readOnly && !$this->module->isAdmin())) {
$this->redirect(array('message/inbox'));
}
$this->module->registerConfig($this->getAction()->getId());
if ($this->module->isAdmin()) {
$reply = new Message('admin');
} else {
$reply = new Message('user');
}
$conv = Mailbox::conversation($_GET['id']);
if (isset($_POST['text'])) {
$reply->text = $_POST['text'];
$validate = $conv->validate(array('text'), false);
// html purify
$reply->conversation_id = $conv->conversation_id;
if ($conv->initiator_id != Yii::app()->session['login']['id']) {
$reply->recipient_id = $conv->initiator_id;
$conv->bm_read = $conv->bm_read & ~Mailbox::INITIATOR_FLAG;
} else {
$reply->recipient_id = $conv->interlocutor_id;
$conv->bm_read = $conv->bm_read & ~Mailbox::INTERLOCUTOR_FLAG;
}
$reply->sender_id = $this->module->getUserId();
$reply->created = time();
$conv->modified = $reply->created;
$reply->crc64 = Message::crc64($reply->text);
$conv->bm_deleted = 0;
// restore message
$conv->interlocutor_del = 0;
$conv->initiator_del = 0;
$validate = $reply->validate();
$validate = $conv->validate() && $validate;
$userRec = User::model()->findByAttributes(array('userid' => $reply->recipient_id));
if ($validate) {
$conv->save();
$reply->save();
$subj = "Parentvalet";
$mesg = "Hi ,You have got new message in your parentvalet messages";
$headers = "From: admin@parentvalet.com";
mail($userRec['email'], $subj, $mesg, $headers);
Yii::app()->user->setFlash('success', "Message sent!");
$this->redirect(array('message/inbox'));
} else {
Yii::app()->user->setFlash('error', "Error sending message!");
$this->render('message', array('conv' => $conv, 'reply' => $reply));
}
}
}