Example #1
0
 /**
  * '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);
         }
     }
 }
Example #2
0
 public function actionIndex($params = null)
 {
     $this->setHeaderTitle("Welcome to FDUGroup");
     if (Rays::isLogin()) {
         $this->redirectAction("user", "home");
     } else {
         $this->redirectAction('group', 'find');
     }
 }
Example #3
0
 /**
  * View group detail
  * @param $groupId
  */
 public function actionDetail($groupId)
 {
     $group = Group::get($groupId);
     RAssert::not_null($group);
     $group->category = Category::get($group->categoryId);
     $group->groupCreator = User::get($group->creator);
     $counter = $group->increaseCounter();
     // get latest 20 posts in the group
     $posts = Topic::find("groupId", $groupId)->join("user")->order_desc("createdTime")->range(0, 20);
     $data = ['group' => $group, 'counter' => $counter->totalCount, 'latestPosts' => $posts];
     $isLogin = Rays::isLogin();
     $data['hasJoined'] = $isLogin && GroupUser::isUserInGroup(Rays::user()->id, $group->id);
     $data['isManager'] = $isLogin && $group->creator == Rays::user()->id;
     $this->setHeaderTitle($group->name);
     $this->addCss("/public/css/post.css");
     $this->render('detail', $data, false);
 }
Example #4
0
 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;
     }
 }
Example #5
0
<?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;
        ?>
Example #6
0
            <div class="action">
                <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 
Example #7
0
 /**
  * Register action
  */
 public function actionRegister()
 {
     if (Rays::isLogin()) {
         $this->redirectAction("user", "home");
     }
     $this->layout = 'user_ui';
     $this->setHeaderTitle("Register");
     $data = [];
     if (Rays::isPost()) {
         // validate the form data
         $rules = array(array('field' => 'username', 'label' => 'User name', 'rules' => 'trim|required|min_length[5]|max_length[20]'), array('field' => 'password', 'label' => 'Password', 'rules' => 'trim|required|min_length[6]|max_length[20]'), array('field' => 'password-confirm', 'label' => 'Password Confirm', 'rules' => 'trim|required|equals[password]'), array('field' => 'email', 'label' => 'Email', 'rules' => 'trim|required|is_email'));
         $validation = new RValidation($rules);
         if ($validation->run()) {
             $user = User::register($_POST['username'], md5($_POST['password']), $_POST['email']);
             if ($user->id) {
                 $user->sendWelcomeMessage();
                 /*
                 Rays::import("extensions.phpmailer.*");
                 $emailResult = MailHelper::sendEmail("Welcome to FDUGroup family","<b>Welcome to FDUGroup family</b><br/>-- FDUGroup team <br/>".date('Y-m-d H:i:s'),$_POST['email']);
                 if($emailResult!==true){
                     var_dump($emailResult);
                     exit;
                 }
                 */
                 $this->flash("message", "Hello," . $user->name . ", please " . RHtml::linkAction('user', 'login', 'login') . " !");
                 $this->redirectAction('user', 'view', $user->id);
             } else {
                 $this->flash("error", "Register failed! User name or email already exists.");
             }
         } else {
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     if (Rays::isPost()) {
         $data['registerForm'] = $_POST;
     }
     $this->render('register', $data, false);
 }
Example #8
0
<?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 '&nbsp;';
    echo RHtml::linkAction('group', "Invite", 'invite', $group->id, array('class' => 'btn btn-xs btn-info'));
    echo '&nbsp;';
}
if (!$hasJoined) {
    echo RHtml::linkAction('group', 'Join', 'join', $group->id, array('class' => 'btn btn-xs btn-success'));
    echo '&nbsp;';
} 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">
Example #9
0
 public function actionView($topicId = null)
 {
     $topic = Topic::find($topicId)->join("group")->join("user")->first();
     if ($topic === null) {
         $this->page404();
         return;
     }
     $counter = $topic->increaseCounter();
     $commentTree = $topic->getComments();
     // TODO use join
     foreach ($commentTree as $commentItem) {
         $commentItem['root']->user = User::get($commentItem['root']->userId);
         foreach ($commentItem['reply'] as $reply) {
             $reply->user = User::get($reply->userId);
         }
     }
     $data = array("topic" => $topic, "commentTree" => $commentTree, 'counter' => $counter);
     $replyTo = Rays::getParam('reply', null);
     if ($replyTo && is_numeric($replyTo)) {
         $comment = Comment::find($replyTo)->join("user")->first();
         $data['parent'] = $comment;
     }
     $data['canEdit'] = Rays::isLogin() && (Rays::user()->id == $topic->user->id || Rays::user()->isAdmin());
     $this->setHeaderTitle($topic->title);
     $this->addCss('/public/css/post.css');
     $this->render("view", $data, false);
 }
Example #10
0
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) {