/** * 'onFlush' event handling. * This method will be called when the 'flush' method of RLog is called * like: <pre>Rays::logger()->flush();</pre> * @param $event event object */ public function onFlush($event) { $logs = $event->getParams(); if (!empty($logs)) { foreach ($logs as $log) { $sysLog = new SystemLog(array('host' => Rays::app()->request()->getUserHostAddress(), 'path' => Rays::uri(), 'title' => $this->getHeaderTitle(), 'uri' => Rays::referrerUri(), 'timestamp' => date('Y-m-d H:i:s'))); $sysLog->userId = Rays::isLogin() ? Rays::user()->id : 0; $sysLog->message = $log['message']; $level = null; switch ($log['level']) { case RLog::LEVEL_ERROR: $level = 2; break; case RLog::LEVEL_INFO: $level = 0; break; case RLog::LEVEL_WARNING: $level = 1; break; } if ($level === null) { continue; } $sysLog->severity = $level; $sysLog->type = $log['type']; $sysLog->save(); unset($sysLog); } } }
public function actionRemove($adId = null, $type) { $ad = Ads::get($adId); RAssert::not_null($ad); $currentUserId = Rays::user()->id; if ($ad->userId == $currentUserId) { $ad->delete(); $this->flash('message', 'Advertisement removed successfully.'); $redirect = null; switch ($type) { case Ads::APPROVED: $redirect = 'published'; break; case Ads::APPLYING: $redirect = 'applying'; break; case Ads::BLOCKED: $redirect = 'blocked'; break; } $this->redirectAction('ads', 'view', $redirect); return; } else { $this->flash("error", 'Permission denied'); $this->page404(); } }
public function actionUploadImage() { $fileTag = 'upload'; $user = Rays::user(); if (isset($_FILES[$fileTag])) { $path = Rays::app()->getBaseDir() . "/files/userfiles/u_" . $user->id . "/"; if (!file_exists($path)) { mkdir($path); } $file = $path . $_FILES[$fileTag]['name']; $name = $_FILES[$fileTag]['name']; $extension = RUpload::get_extension($_FILES[$fileTag]['name']); if (file_exists($file)) { $count = 0; while (true) { $_name = RUpload::get_name($name) . '_' . $count . $extension; $_file = $path . $_name; if (!file_exists($_file)) { $name = $_name; break; } $count++; } } $upload = new RUpload(array("file_name" => $name, "upload_path" => $path)); $upload->upload($fileTag); if ($upload->error != '') { echo $upload->error; //$this->flash("error", $upload->error); } else { // success $uri = "files/userfiles/u_" . $user->id . "/" . $upload->file_name; echo $uri; } } exit; }
public function actionPlus() { if (Rays::isAjax()) { $result = ["result" => false]; if (isset($_POST['plusId']) && isset($_POST['plusType'])) { if (is_numeric($_POST['plusId'])) { $plusId = $_POST['plusId']; $userId = 0; if (Rays::isLogin()) { $userId = Rays::user()->id; } $host = Rays::app()->request()->getUserHostAddress(); switch ($_POST['plusType']) { case Topic::ENTITY_TYPE: if (Topic::get($plusId) !== null) { $plus = new RatingPlus(Topic::ENTITY_TYPE, $plusId, $userId, $host); if ($plus->rate()) { $result = ["result" => true, "counter" => $plus->getCounter()->value]; } } break; case Group::ENTITY_TYPE: if (Group::get($plusId) !== null) { $plus = new RatingPlus(Group::ENTITY_TYPE, $plusId, $userId, $host); if ($plus->rate()) { $result = ["result" => true, "counter" => $plus->getCounter()->value]; } } break; } } } echo json_encode($result); exit; } }
<a href="javascript:void(0);" title="Members of this group"> <span class="glyphicon glyphicon-user"></span> <?php echo $group->memberCount; ?> </a> </div> <div class="action action-like"> <?php $self->module('rating_plus', array('id' => 'rating_plus', 'entityType' => Group::ENTITY_TYPE, 'entityId' => $group->id)); ?> </div> <?php if (Rays::isLogin()) { if (!GroupUser::isUserInGroup(Rays::user()->id, $group->id)) { ?> <div class="action action-right"> <?php $url = RHtml::siteUrl('group/join'); ?> <a href="javascript: joinGroup('<?php echo $url; ?> ','<?php echo $group->id; ?> ')" title="Join the group"><span class="glyphicon glyphicon-plus"></span></a> </div> <?php }
echo RForm::input(array('id' => 'ads-title', 'name' => 'ads-title', 'class' => 'form-control', 'placeholder' => 'Ads title'), isset($form['ads-title']) ? $form : (isset($edit) ? $ad->title : $form)); ?> <br/> <?php echo RForm::label('Ads content', 'ads-content'); ?> <?php $self->module('ckeditor', array('editorId' => 'ads-content', 'name' => 'ads-content', 'data' => isset($form['ads-content']) ? $form['ads-content'] : (isset($edit) ? $ad->content : ''))); ?> <br/> <?php echo RForm::label('Paid price (' . Rays::user()->getWallet()->money . " " . Wallet::COIN_NAME . " in your wallet)", 'paid-price'); ?> <div class="input-group"> <?php echo RForm::input(array_merge(array('id' => 'paid-price', 'name' => 'paid-price', 'class' => 'form-control'), isset($edit) ? ['readonly' => true] : []), isset($form['paid-price']) ? $form : (isset($edit) ? $ad->paidPrice : $form)); ?> <span class="input-group-addon"><?php echo Wallet::COIN_NAME; ?> </span> </div> <br/> <?php echo RForm::input(array('type' => 'submit', 'class' => 'btn btn-sm btn-primary', 'value' => isset($edit) ? 'Save' : 'Send Ads application'));
<?php /** * Posts list view file. * This view file only render the posts list. It's useful for partial rendering without the layout, * for example: render the result for an Ajax request * * @author: Raysmond */ if (!empty($topics)) { ?> <div class="posts-list"> <?php $currentUserId = Rays::isLogin() ? Rays::user()->id : 0; foreach ($topics as $topic) { ?> <div class="row topic-item"> <!-- User picture --> <div class="col-lg-2 topic-picture"> <?php if ($topic->user->picture == '') { $topic->user->picture = User::$defaults['picture']; } $thumbnail = RImage::styleSrc($topic->user->picture, User::getPicOptions()); ?> <a href="<?php echo RHtml::siteUrl("user/view/" . $topic->user->id); ?> " title="<?php echo $topic->user->name; ?>
</h3> </div> <div class="panel-body"> <?php if ($message->type->name == 'system') { echo "From: 系统消息"; } else { $sender = null; if ($message->type->name == "user" || $message->type->name == "private") { $sender = User::get($message->senderId); echo "From: " . RHtml::linkAction('user', $sender->name, 'view', $sender->id); } else { if ($message->type->name == "group") { $sender = Group::get($message->senderId); echo "From: " . RHtml::linkAction('group', $sender->name, 'detail', $sender->id); } else { echo "From: Unknown"; } } } echo ' Delivery time: ' . $message->sendTime; echo ' Status: ' . ($message->status == 0 ? "unread" : "read"); echo "<br/>"; echo '<p>' . RHtml::decode($message->content) . '</p>'; if ($message->status == Message::STATUS_UNREAD && $message->receiverId == Rays::user()->id) { echo RHtml::linkAction('message', "Mark read", 'read', $message->id, array('class' => 'btn btn-sm btn-success')); } ?> </div> </div> </div>
public function actionComment($topicId) { $topic = Topic::get($topicId); if (Rays::isPost()) { $validation = new RValidation(array(array('field' => 'content', 'label' => 'Content', 'rules' => 'trim|required'))); if (!$validation->run()) { $this->flash("error", "Comment content cannot be empty!"); $this->redirectAction('post', 'view', $topicId); } $form = $_POST; $topic->commentCount++; $topic->lastCommentTime = date('Y-m-d H:i:s'); $topic->save(); $user = Rays::user(); $comment = new Comment(); $comment->topicId = $topicId; $comment->userId = $user->id; $comment->createdTime = date('Y-m-d H:i:s'); $comment->content = $form["content"]; if (isset($form['replyTo'])) { $comment->pid = (int) $form['replyTo']; } else { $comment->pid = 0; } $comment->save(); $cid = $comment->id; if (isset($form['replyTo'])) { $exactComment = Comment::get($form['exactReplyTo']); Message::sendMessage('user', $user->id, $exactComment->userId, 'New reply', $user->name . ' has replied to your comment ' . RHtml::linkAction('post', $topic->title, 'view', $topic->id . '?reply=' . $cid)); } else { if ($topic->userId !== $user->id) { //send message to topic author Message::sendMessage('user', $user->id, $topic->userId, 'New Comment', $user->name . ' has replied to your topic ' . RHtml::linkAction('post', $topic->title, 'view', $topic->id . '?reply=' . $cid)); } } } $this->redirectAction('post', 'view', $topicId); }
*/ if (isset($validation_errors)) { RHtml::showValidationErrors($validation_errors); } $form = array(); if (isset($sendForm)) { $form = $sendForm; } echo RForm::openForm('message/send/' . $type . '/', array('id' => 'messageForm', 'class' => 'form-signin')); echo RForm::label('To user: '******'receiver', array()); echo ' '; $disabled = isset($toUser) ? "disabled" : "enabled"; echo RForm::input(array('id' => 'receiver', 'name' => 'receiver', 'class' => 'form-control', 'placeholder' => 'Receiver'), isset($toUser) ? $toUser->name : $form); echo '<br/>'; echo RForm::label('Title', 'title', array()); echo RForm::input(array('id' => 'title', 'name' => 'title', 'class' => 'form-control', 'placeholder' => 'Title'), $form); echo "<br/>"; echo RForm::label('Content', 'content', array()); echo "<br/>"; if (Rays::user()->roleId == Role::ADMINISTRATOR_ID) { $self->module('ckeditor', array('editorId' => 'msg-content', 'name' => 'msg-content', 'data' => isset($form['content']) ? $form['content'] : '')); } else { echo RForm::textarea(array('id' => 'msg-content', 'name' => 'msg-content', 'class' => 'form-control', 'cols' => 100, 'rows' => 6, 'placeholder' => 'Content'), $form); } echo "<br/>"; echo RForm::input(array('type' => 'hidden', 'value' => $type, 'name' => 'type'), $type); echo RForm::input(array('type' => 'submit', 'value' => 'Send', 'class' => 'btn btn-lg btn-primary')); echo RForm::endForm(); ?> </div> </div>
public function actionMyFriend() { $this->layout = 'user'; $user = Rays::user(); $friends = new Friend(); $curPage = $this->getPage("page"); $pageSize = $this->getPageSize("pagesize", 36); list($friends, $count) = $friends->getFriends($user->id, $pageSize, [], ($curPage - 1) * $pageSize); $data['count'] = $count; $pager = new RPager('page', $count, $pageSize, RHtml::siteUrl('friend/myFriend'), $curPage); $data['friends'] = $friends; if ($count > $pageSize) { $data['pager'] = $pager->showPager(); } $data['friNumber'] = $count; return $this->render('my_friend', $data); }
public function actionDelete($msgId) { $message = Message::get($msgId); if (Rays::isAjax() && $message != null) { if (Rays::user()->id != $message->receiverId) { echo "Sorry. You don't have the right to delete the message."; exit; } $message->delete(); echo 'success'; exit; } RAssert::not_null($message); $user = Rays::user(); if ($message->receiverId == $user->id || $user->isAdmin()) { $message->delete(); } $this->redirect(Rays::referrerUri()); }
public function actionInvite($groupId) { $group = Group::get($groupId); $data = array(); $data['group'] = $group; $user = Rays::user(); $friends = new Friend(); $friends = $friends->getFriendsToInvite($user->id, $groupId); $data['friends'] = $friends; if (Rays::isPost()) { if (isset($_POST['select_friends'])) { Group::inviteFriends($groupId, $user, $_POST['select_friends'], $_POST['invitation']); $this->flash('message', 'Send invitation successfully.'); } else { $this->flash('warning', 'No invitation was send!'); } } $this->render('invite', $data, false); }
> <?php echo RHtml::linkAction("post", "Find posts", "find"); ?> </li> </ul> <ul class="nav navbar-nav navbar-right"> <?php // not login if (!isset($user)) { echo "<li>" . RHtml::linkAction("user", "Login", "login", null) . "</li>"; echo "<li>" . RHtml::linkAction("user", "Register", "register", null) . "</li>"; } else { $countMessages = Rays::user()->countUnreadMsgs(); if ($isAdmin) { echo '<li>' . RHtml::linkAction('admin', 'Admin', null, null, array('style' => 'font-weight: bold;')) . "</li>"; } ?> <li class="dropdown"> <a href="#" id="account-dropdown" class="dropdown-toggle" data-toggle="dropdown" > <?php $pic = isset($user->picture) && $user->picture != '' ? $user->picture : "public/images/default_pic.png"; $pic = RImage::styleSrc($pic, User::getPicOptions()); ?> <?php echo RHtml::image($pic, $user->name, array('class' => 'img-thumbnails')); ?> <span class="username"><?php echo $user->name;
/** * Apply for VIP * by songrenchu */ public function actionApplyVIP() { $this->setHeaderTitle('VIP application'); $this->layout = 'user'; $user = Rays::user(); $data = array('user' => $user); if (Rays::isPost()) { $config = [['field' => 'content', 'label' => 'Statement', 'rules' => 'trim|required|min_length[10]|max_length[1000]']]; $validation = new RValidation($config); if ($validation->run()) { $censor = new Censor(); $censor->applyVIPApplication($user->id, RHtml::encode($_POST['content'])); $this->flash('message', 'VIP application sent.'); $this->redirectAction('user', 'profile'); } else { $errors = $validation->getErrors(); $data['validation_errors'] = $errors; $data['editForm'] = $_POST; $this->render('apply_vip', $data, false); } return; } $censor = new Censor(); if ($censor->applyVIPExist($user->id) != null) { $this->flash('error', 'Your previous VIP application is under review!'); $this->redirectAction('user', 'profile'); return; } $this->render('apply_vip', $data, false); }
<?php /** * Group detail page * @author: Raysmond */ ?> <div class="panel panel-default"> <div class="panel-heading"> <div class="heading-actions" style="float: right;"> <?php if ($isManager || Rays::isLogin() && Rays::user()->isAdmin()) { echo RHtml::linkAction('group', "Edit", 'edit', $group->id, array('class' => 'btn btn-xs btn-success')); echo ' '; echo RHtml::linkAction('group', "Invite", 'invite', $group->id, array('class' => 'btn btn-xs btn-info')); echo ' '; } if (!$hasJoined) { echo RHtml::linkAction('group', 'Join', 'join', $group->id, array('class' => 'btn btn-xs btn-success')); echo ' '; } else { echo RHtml::linkAction('group', 'Quit', 'exit', $group->id, array('class' => 'btn btn-xs btn-danger', 'onclick' => 'return confirm(\'Are you sure to quit the group? This operation cannot be undone!\')')); } ?> </div> <h1 class="panel-title"><?php echo $group->name; ?> </h1> </div> <div class="panel-body">
<?php if (!empty($posts)) { ?> <div class="posts-list"> <div id="latest-topics-list"> <?php $user = Rays::user(); if ($user->picture == '') { $user->picture = User::$defaults['picture']; } foreach ($posts as $post) { ?> <div class="row topic-item"> <div class="col-lg-2 topic-picture"> <?php echo RHtml::image(RImage::styleSrc($user->picture, User::getPicOptions()), $user->name, array('width' => '64px')); ?> </div> <div class="col-lg-10 topic-content"> <span class="arrow"></span> <div class="inner"> <div class="topic-title"> <?php echo RHtml::linkAction('post', $post->title, 'view', $post->id); ?> </div> <div class="topic-meta"> <?php echo RHtml::linkAction('view', $user->name, 'view', $user->id); ?>
<?php } else { foreach ($msgs as $msg) { ?> <div id="message-item-<?php echo $msg->id; ?> " class="message-item panel panel-info <?php echo $msg->status == Message::STATUS_UNREAD ? "message-unread" : ""; ?> "> <div class="panel-heading"> <div style="float:right;margin-top: -2px;"> <?php if ($msg->receiverId == Rays::user()->id) { if (($msg->type->name == "private" || $msg->type->name == "user") && $msg->senderId != Rays::user()->id) { echo RHtml::linkAction("message", "", "send", ['private', $msg->senderId], array('title' => 'Reply', "class" => 'glyphicon glyphicon-send')); echo ' '; } if ($msg->status == Message::STATUS_UNREAD) { $url = RHtml::siteUrl("message/read/" . $msg->id); ?> <a href="javascript:markStatus('<?php echo $url; ?> ',<?php echo $msg->id; ?> )"><span class="glyphicon glyphicon-ok message-read"></span></a> <?php }
echo RHtml::linkAction('category', $group->category->name, 'groups', $group->categoryId); ?> <br/> Members: <?php echo $memberCount; ?> <br/> Topics: <?php echo $topicCount; ?> </div> <?php $isManager = false; if (Rays::isLogin() && Rays::user()->id == $manager->id) { $isManager = true; } ?> <?php if ($isManager) { echo RForm::openForm('group/members/' . $group->id, array('id' => 'removeMembersForm')); } ?> <div class="clearfix"></div> <hr> <div class="group-members panel panel-default"> <div class="panel-heading"> <?php if ($isManager) {