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 delete($assignment = [])
 {
     $table = Rays::app()->getDBPrefix() . GroupUser::$table;
     if (is_numeric($this->groupId) && is_numeric($this->userId)) {
         $sql = "DELETE FROM " . $table . " WHERE {$table}." . GroupUser::$mapping['groupId'] . "={$this->groupId} AND {$table}." . GroupUser::$mapping['userId'] . " = {$this->userId}";
         Data::executeSQL($sql);
     }
 }
Example #3
0
 public static function getConnection()
 {
     if (self::$connection == null) {
         $dbConfig = Rays::app()->getDbConfig();
         self::$connection = mysql_connect($dbConfig['host'], $dbConfig['user'], $dbConfig['password']) or die(mysql_error());
         mysql_select_db($dbConfig['db_name']) or die(mysql_error());
         mysql_query("set names " . $dbConfig['charset']) or die(mysql_error());
     }
     return self::$connection;
 }
Example #4
0
 public function actionException(Exception $e)
 {
     if (Rays::isAjax()) {
         print $e;
         exit;
     }
     $this->layout = 'error';
     switch ($e->getCode()) {
         case 404:
             $this->render('404', ['message' => $e->getMessage()]);
             Rays::log('Page not found! (' . $e->getMessage() . ')', "warning", "system");
             break;
         default:
             if (Rays::app()->isDebug()) {
                 print $e;
             } else {
                 $this->render("exception", ['code' => $e->getCode(), 'message' => $e->getMessage()]);
             }
     }
     Rays::logger()->flush();
 }
Example #5
0
 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;
 }
Example #6
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 #7
0
    ?>
            <a href="<?php 
    echo RHtml::siteUrl('message/view');
    ?>
"><span class="glyphicon glyphicon-envelope"></span> &nbsp; Messages</a>
            <?php 
    echo "</li>";
} else {
    echo '<li ' . ($isMessageUrl ? 'class="active"' : "") . '><a href="' . RHtml::siteUrl('message/view') . '">';
    echo '<span class="glyphicon glyphicon-envelope"></span> &nbsp; ';
    echo 'Messages <span class="badge">' . $count . '</span></a></li>';
}
if ($user->roleId == Role::VIP_ID) {
    ?>
            <li <?php 
    echo Rays::app()->request()->urlMatch(array('ads/view', 'ads/view/*'), $currentUrl) ? 'class="active"' : "";
    ?>
>
                <a href="<?php 
    echo RHtml::siteUrl('ads/view');
    ?>
">
                    <span class="glyphicon glyphicon-euro"></span> &nbsp;
                    Advertisement <span class="badge badge-vip">VIP</span>
                </a>
            </li>
        <?php 
}
?>
    </ul>
</div>
Example #8
0
        <div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation"> -->

            <?php 
// $self->module("new_users",array('id'=>'new_users','name'=>"New Users"));
?>

       <!-- </div>--><!--/span-->


    </div>

    <hr>

    <footer>
        <p><?php 
echo "© Copyright " . Rays::app()->getName() . " 2013, All Rights Reserved.";
?>
</p>
    </footer>

</div>
<!--/.container-->

<!-- Placed at the end of the document so the pages load faster -->
<?php 
// link custom script files
echo RHtml::linkScriptArray(Rays::app()->client()->script);
?>
</body>

</html>
Example #9
0
 /**
  * Delete group
  * This action will delete all content related to the group, including topics, comments
  * that belong the group
  * @access group creator | administrator
  * @param $groupId
  */
 public function actionDelete($groupId)
 {
     $group = Group::get($groupId);
     RAssert::not_null($group);
     $userId = Rays::user()->id;
     if (Rays::user()->isAdmin() || $group->creator == $userId) {
         // Execute delete group transaction
         Group::deleteGroup($group);
         // Delete group's picture from local file system
         if (isset($group->picture) && $group->picture != '') {
             $picture = Rays::app()->getBaseDir() . "/../" . $group->picture;
             if (file_exists($picture)) {
                 unlink($picture);
             }
         }
         $this->flash("message", "Group " . $group->name . " was deleted.");
         $this->redirectAction("group", "mygroups");
     } else {
         $this->flash("error", "Sorry. You don't have the right to delete the group!");
         $this->redirectAction('group', 'detail', $group->id);
     }
 }
Example #10
0
                <a id="logo" href="<?php 
echo Rays::baseUrl();
?>
" class="navbar-brand">
                    <?php 
echo RHtml::image("public/images/logo.png");
?>
                </a>
            </div>
            <div class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <?php 
if (Rays::isLogin()) {
    ?>
                        <li <?php 
    echo Rays::app()->request()->urlMatch(array('user/home', 'user', 'user/'), $curUrl) ? 'class="active"' : "";
    ?>
>
                            <?php 
    echo RHtml::linkAction("user", "Home", "home");
    ?>
                        </li>
                    <?php 
}
?>
                    <li <?php 
echo $curUrl == 'group/find' ? 'class="active"' : '';
?>
>
                        <?php 
echo RHtml::linkAction("group", "Find groups", "find");
Example #11
0
 /**
  * Change user info action
  * @param null $userId
  */
 public function actionEdit($userId = null)
 {
     $userId = null === $userId ? Rays::user()->id : $userId;
     $user = User::get($userId);
     RAssert::not_null($user);
     if (Rays::user()->roleId != Role::ADMINISTRATOR_ID && Rays::user()->id != $userId) {
         $this->flash("error", "You don't have the right to change the user information!");
         $this->redirectAction('user', 'view', $userId);
     }
     $data = array('user' => $user);
     if (Rays::isPost()) {
         $config = array(array('field' => 'username', 'label' => 'User name', 'rules' => 'trim|required|min_length[5]|max_length[20]'));
         // if set password, then go changing password
         if (isset($_POST['password']) && $_POST['password'] != '') {
             array_push($config, array('field' => 'password', 'label' => 'New Password', 'rules' => 'trim|required|min_length[6]|max_length[20]'));
             array_push($config, array('field' => 'password-confirm', 'label' => 'New Password Confirm', 'rules' => 'trim|required|min_length[6]|max_length[20]|equals[password]'));
         }
         $validation = new RValidation($config);
         if ($validation->run()) {
             if (isset($_POST['password']) && $_POST['password'] != '') {
                 // set new password
                 $user->password = md5($_POST['password']);
             }
             $user->name = $_POST['username'];
             foreach (User::$mapping as $objCol => $dbCol) {
                 if (in_array($objCol, ["password", "email", "id", "roleId", "credit", "private"])) {
                     continue;
                 }
                 if (isset($_POST[$objCol])) {
                     $user->{$objCol} = $_POST[$objCol];
                 }
             }
             $user->save();
             $this->flash("message", "Update information successfully.");
             // if picture selected
             if (isset($_FILES['user_picture']) && $_FILES['user_picture']['name'] != '') {
                 $pictureName = "pic_u_" . $user->id . RUpload::get_extension($_FILES['user_picture']['name']);
                 $upload = new RUpload(["file_name" => $pictureName, "upload_path" => Rays::app()->getBaseDir() . "/../" . User::PICTURE_DIR]);
                 $upload->upload('user_picture');
                 if ($upload->error != '') {
                     $this->flash("error", $upload->error);
                 } else {
                     $user->picture = "files/images/users/" . $upload->file_name;
                     $user->save();
                     RImage::updateStyle($user->picture, User::getPicOptions());
                 }
             }
             if (Rays::user()->id == $user->id) {
                 $this->redirectAction("user", "profile");
             } else {
                 $this->redirectAction("user", "view", [$user->id, "profile"]);
             }
         } else {
             $errors = $validation->getErrors();
             $data['validation_errors'] = $errors;
             $data['editForm'] = $_POST;
         }
     }
     $this->layout = 'user';
     $this->setHeaderTitle("Edit profile - " . $user->name);
     $this->render('edit', $data, false);
 }
Example #12
0
 /**
  * Topics administration
  */
 public function actionAdmin()
 {
     $this->layout = 'admin';
     $data = array();
     // delete request
     if (Rays::app()->request()->isPostRequest()) {
         if (isset($_POST['checked_topics'])) {
             $checkedTopics = $_POST['checked_topics'];
             foreach ($checkedTopics as $item) {
                 if (!is_numeric($item)) {
                     return;
                 } else {
                     $topic = new Topic();
                     $topic->id = $item;
                     $topic->delete();
                 }
             }
         }
     }
     $curPage = $this->getPage("page");
     $pageSize = $this->getPageSize("pagesize");
     $count = Topic::find()->count();
     $data['count'] = $count;
     $query = Topic::find()->join("user")->join("group")->join("rating")->join("counter");
     $orderBy = Rays::getParam("orderBy", "id");
     $order = Rays::getParam("order", "desc");
     switch ($orderBy) {
         case "id":
             $query = $query->order($order, "[Topic.id]");
             break;
         case "likes":
             $query = $query->order($order, "[RatingStatistic.value]");
             break;
         case "views":
             $query = $query->order($order, "[Counter.totalCount]");
             break;
         case "createTime":
             $query = $query->order($order, "[Topic.id]");
             break;
         default:
             $query = $query->order_desc("id");
     }
     $posts = $query->range(($curPage - 1) * $pageSize, $pageSize);
     $data['topics'] = $posts;
     $pager = new RPager('page', $count, $pageSize, RHtml::siteUrl("post/admin?orderBy={$orderBy}&&order={$order}"), $curPage);
     $pager = $pager->showPager();
     $data['pager'] = $pager;
     $this->render('admin', $data, false);
 }
Example #13
0
 public function uploadPicture($fileTag)
 {
     $uploadPath = Rays::app()->getBaseDir() . '/../' . self::PICTURE_PATH;
     $picName = 'group_' . $this->id . RUpload::get_extension($_FILES[$fileTag]['name']);
     $upload = new RUpload(array('file_name' => $picName, 'upload_path' => $uploadPath));
     $upload->upload($fileTag);
     if ($upload->error != '') {
         return $upload->error;
     } else {
         $this->picture = "files/images/groups/" . $upload->file_name;
         $this->save();
         RImage::updateStyle($this->picture, static::getPicOptions());
         return true;
     }
 }
Example #14
0
 public function init($options)
 {
     $this->key = $options["key"];
     $this->table = Rays::app()->getDBPrefix() . $options["table"];
     $this->columns = $options["columns"];
 }