public function actionAdmin() { // delete comment request if (Rays::isPost()) { if (isset($_POST['checked_comments'])) { $commentIds = $_POST['checked_comments']; foreach ($commentIds as $id) { if (!is_numeric($id)) { return; } else { $comment = new Comment(); $comment->id = $id; $comment->delete(); } } } } $curPage = $this->getPage("page"); $pageSize = $this->getPageSize('pagesize', 10); $count = Comment::find()->count(); $comments = Comment::find()->join("user")->join("topic")->order_desc("id")->range(($curPage - 1) * $pageSize, $pageSize); $pager = new RPager('page', $count, $pageSize, RHtml::siteUrl('comment/admin'), $curPage); $this->layout = 'admin'; $this->setHeaderTitle("Comments administration"); $data = array('count' => $count, 'comments' => $comments, 'pager' => $pager->showPager()); $this->render('admin', $data, false); }
public function actionSend($type = 'private', $toUserId = null) { $types = array('system', 'user', 'private', 'group'); RAssert::is_true(in_array($type, $types)); $data = array('type' => $type); if ($toUserId != null) { $data['toUser'] = User::get($toUserId); } if (Rays::isPost()) { if (isset($_POST['new'])) { if (isset($_POST['receiverName'])) { $data['sendForm'] = array('receiver' => $_POST['receiverName']); } $this->render('send', $data, false); return; } $form = $_POST; $config = array(array('field' => 'title', 'label' => 'Title', 'rules' => 'trim|required'), array('field' => 'msg-content', 'label' => 'Content', 'rules' => 'trim|required'), array('field' => 'receiver', 'label' => 'Receiver', 'rules' => 'required'), array('field' => 'type', 'label' => 'Message type', 'rules' => 'trim|required')); $validation = new RValidation($config); if ($validation->run()) { $receiver = User::find("name", $_POST['receiver'])->first(); if ($receiver == null) { $this->flash("error", "No such user."); } else { $senderId = 0; if (isset($_POST['sender'])) { //mainly for group and system message $senderId = $_POST['sender']; } else { $senderId = Rays::user()->id; } $title = isset($_POST['title']) ? trim($_POST['title']) : ""; $msgContent = RHtml::encode($_POST['msg-content']); $message = Message::sendMessage($_POST['type'], $senderId, $receiver->id, $title, $msgContent, null, 1); if (isset($message->id) && $message->id != '') { $this->flash("message", "Send message successfully."); $this->redirectAction('message', 'view'); return; } else { $this->flash("message", "Send message failed."); } } } $data['sendForm'] = $form; if ($validation->getErrors() != '') { $data['validation_errors'] = $validation->getErrors(); } } $this->render('send', $data, false); }
/** * Category administration */ public function actionAdmin() { $data = array(); if (Rays::isPost()) { if (isset($_POST['sub_items'])) { $items = $_POST['sub_items']; if (is_array($items)) { foreach ($items as $item) { if (!is_numeric($item)) { return; } else { $cat = Category::get($item); if ($cat->pid == 0) { continue; } $cat->delete(); } } } } if (isset($_POST['cat-name']) && isset($_POST['parent-id'])) { $name = trim($_POST['cat-name']); $pid = $_POST['parent-id']; if (is_numeric($pid)) { if ($name == '') { $this->flash('error', 'Category name cannot be blank.'); } else { $result = Category::get($pid); if ($result != null) { $newCat = new Category(); $newCat->name = RHtml::encode(trim($name)); $newCat->pid = $pid; $newCat->save(); $this->flash('message', 'Category ' . $name . " was created successfully."); } else { $this->flash('error', 'Parent category not exists.'); } } } } } $data['categories'] = Category::find()->all(); $this->layout = 'admin'; $this->setHeaderTitle('Category administration'); $this->render('admin', $data, false); }
public function run() { $params = $this->getParams(); $groupId = $params[0]; if (!is_numeric($groupId)) { $this->getController()->page404(); return; } if (($group = Group::get($groupId)) !== null) { if (Rays::isPost()) { // remove members request if (isset($_POST['selected_members'])) { $ids = $_POST['selected_members']; if (is_array($ids)) { $flag = true; foreach ($ids as $id) { if (!is_numeric($id) || $id == $group->creator) { $flag = false; break; } } if ($flag) { GroupUser::removeUsers($groupId, $ids); } } } } $group->category = Category::get($group->categoryId); $members = Group::getMembers($group->id); $this->getController()->setHeaderTitle("Members in " . $group->name); $this->getController()->render('members', array('members' => $members, 'manager' => User::get($group->creator), 'group' => $group, 'memberCount' => count($members), 'topicCount' => Group::countTopics($groupId)), false); } else { $this->getController()->page404(); return; } }
public function actionAdmin() { $this->setHeaderTitle('Advertisement'); $this->layout = 'admin'; if (Rays::isPost()) { if (isset($_POST['checked_ads'])) { $selected = $_POST['checked_ads']; if (is_array($selected)) { $operation = $_POST['operation_type']; foreach ($selected as $id) { $ad = Ads::get($id); if ($ad == null) { break; } switch ($operation) { case "block": $ad->status = Ads::BLOCKED; $ad->save(); break; case "active": $ad->status = Ads::APPROVED; $ad->save(); break; } } } } } $curPage = $this->getPage('page'); $pageSize = $this->getPageSize("pagesize", 10); $filterStr = Rays::getParam('search', null); $query = Ads::find()->join("publisher"); if ($name = trim($filterStr)) { $names = preg_split("/[\\s]+/", $name); foreach ($names as $key) { $query = $query->like("name", $key); } } $count = $query->count(); $ads = $query->order_desc("id")->range($pageSize * ($curPage - 1), $pageSize); $data = ['ads' => $ads, 'count' => $count]; $url = RHtml::siteUrl('ads/admin'); if ($filterStr != null) { $url .= '?search=' . urlencode(trim($filterStr)); } $pager = new RPager('page', $count, $pageSize, $url, $curPage); $data['pager'] = $pager->showPager(); $this->render('admin', $data, false); }
/** * Recommend groups to users * @access: administrator */ public function actionRecommend() { if (Rays::isAjax()) { $action = Rays::getParam('action', null); if ($action) { $name = Rays::getParam('name', null); $query = Group::find(); $queryUser = User::find(); $like = array(); if (isset($name) && $name != '') { $names = explode(' ', $name); foreach ($names as $val) { $query = $query->like("name", $val); $queryUser = $queryUser->like("name", $val); } } switch ($action) { case "search_groups": $groups = $query->range(0, 20); $results = array(); foreach ($groups as $item) { $result['id'] = $item->id; $result['name'] = $item->name; $result['link'] = RHtml::siteUrl('group/detail/' . $item->id); $result['picture'] = $item->picture; $results[] = $result; } echo json_encode($results); exit; break; case "search_users": $users = $queryUser->range(0, 20); $results = array(); foreach ($users as $item) { $result['id'] = $item->id; $result['name'] = $item->name; $result['link'] = RHtml::siteUrl('user/view/' . $item->id); $result['picture'] = $item->picture; $results[] = $result; } echo json_encode($results); exit; break; default: } } } if (Rays::isPost()) { if (isset($_POST['selected_recommend_groups']) && isset($_POST['selected_recommend_users'])) { $groups = $_POST['selected_recommend_groups']; $users = $_POST['selected_recommend_users']; $words = $_POST['recommend-words']; Group::recommendGroups($groups, $users, $words); $this->flash('message', 'Send group recommendations successfully.'); } } $this->layout = 'admin'; $data = array(); $this->setHeaderTitle("Groups recommendation"); $this->render('recommend', $data, false); }
public function actionFind() { $this->layout = 'user'; $page = $this->getPage("page"); $pageSize = $this->getPageSize("pagesize", 24); $searchStr = ''; if (Rays::isPost()) { $searchStr = $_POST['searchstr']; } else { if (isset($_GET['search'])) { $searchStr = $_GET['search']; } } $query = User::find(); if ($name = trim($searchStr)) { $names = preg_split("/[\\s]+/", $name); foreach ($names as $key) { $query = $query->like("name", $key); } } $count = $query->count(); $users = $query->range(($page - 1) * $pageSize, $pageSize); $url = RHtml::siteUrl('user/find' . ($searchStr != '') ? '?search=' . urlencode($searchStr) : ""); $pager = new RPager('page', $count, $pageSize, $url, $page); $this->setHeaderTitle("Find User"); $this->render("find", ['users' => $users, 'searchstr' => $searchStr, 'pager' => $pager->showPager()], false); }
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); }