/** * @Request({"filter": "array", "page":"int"}) * @Response("extension://page/views/admin/pages/index.razr") */ public function indexAction($filter = null, $page = 0) { if ($filter) { $this['session']->set('page.filter', $filter); } else { $filter = $this['session']->get('page.filter', []); } $query = $this->pages->query(); if (isset($filter['status']) && is_numeric($filter['status'])) { $query->where(['status' => intval($filter['status'])]); } if (isset($filter['search']) && strlen($filter['search'])) { $query->where(function ($query) use($filter) { $query->orWhere('title LIKE :search', ['search' => "%{$filter['search']}%"]); }); } $limit = self::PAGES_PER_PAGE; $count = $query->count(); $total = ceil($count / $limit); $page = max(0, min($total - 1, $page)); $query->offset($page * $limit)->limit($limit)->orderBy('title'); if ($this['request']->isXmlHttpRequest()) { return $this['response']->json(['table' => $this['view']->render('extension://page/views/admin/pages/table.razr', ['count' => $count, 'pages' => $query->get(), 'roles' => $this->roles->findAll()]), 'total' => $total]); } return ['head.title' => __('Pages'), 'pages' => $query->get(), 'statuses' => Page::getStatuses(), 'filter' => $filter, 'total' => $total, 'count' => $count]; }
/** * @Request({"id": "int"}) * @Response("extension://system/views/admin/menu/index.razr") */ public function indexAction($id = null) { $menus = $this->menus->query()->orderBy('name')->get(); if ($menu = $id === null && count($menus) ? current($menus) : (isset($menus[$id]) ? $menus[$id] : false)) { $menu->setItems($this->items->findByMenu($menu)); } return ['head.title' => __('Menus'), 'menu' => $menu, 'menus' => $menus]; }
/** * @Response("extension://system/views/admin/widgets/index.razr") */ public function indexAction() { $this->positions[''] = ['name' => __('Unassigned Widgets')]; $widgets = []; foreach ($this->widgets->query()->orderBy('priority', 'ASC')->get() as $widget) { $position = $widget->getPosition(); $widgets[isset($this->positions[$position]) ? $position : ''][] = $widget; } return ['head.title' => __('Widgets'), 'widgets' => $widgets, 'positions' => $this->positions, 'types' => TypesTrait::getWidgetTypes()]; }
/** * @Request({"filter": "array"}) * @Response("extension://system/views/admin/aliases/index.razr") */ public function indexAction($filter = null) { if ($filter) { $this['session']->set('alias.filter', $filter); } else { $filter = $this['session']->get('alias.filter', []); } $query = $this->aliases->query(); if (isset($filter['search']) && strlen($filter['search'])) { $query->where('alias LIKE ?', ["%{$filter['search']}%"]); } return ['head.title' => __('URL Aliases'), 'aliases' => $query->get(), 'filter' => $filter]; }
/** * @Request({"id": "int"}) * @Response("extension://system/views/admin/user/role.razr") */ public function indexAction($id = null) { $roles = $this->roles->query()->orderBy('priority')->get(); if ($id === null && count($roles)) { $role = current($roles); } elseif ($id && isset($roles[$id])) { $role = $roles[$id]; } else { $role = new Role(); $role->setId(0); } $authrole = $this->roles->find(Role::ROLE_AUTHENTICATED); return ['head.title' => __('Roles'), 'role' => $role, 'roles' => $roles, 'authrole' => $authrole, 'permissions' => $this['permissions']]; }
/** * @Request({"filter": "array", "post":"int", "page":"int"}) * @Response("extension://blog/views/admin/comment/index.razr") */ public function indexAction($filter = [], $post_id = 0, $page = 0) { if ($filter) { $this['session']->set('blog.comments.filter', $filter); } else { $filter = $this['session']->get('blog.comments.filter', []); } $query = $this->comments->query()->related(['post']); $post = null; if ($post_id) { $query->where(['post_id = ?'], [$post_id]); $post = $this->posts->find($post_id); } if (isset($filter['status']) && is_numeric($status = $filter['status'])) { $query->where(['status = ?'], [intval($filter['status'])]); } else { $query->where(function ($query) use($filter) { $query->orWhere(['status = ?', 'status = ?'], [CommentInterface::STATUS_APPROVED, CommentInterface::STATUS_PENDING]); }); } if (isset($filter['search']) && strlen($filter['search'])) { $query->where(function ($query) use($filter) { $query->orWhere(['author LIKE :search', 'email LIKE :search', 'url LIKE :search', 'ip LIKE :search', 'content LIKE :search'], ['search' => "%{$filter['search']}%"]); }); } $limit = $this->extension->getParams('comments.comments_per_page'); $count = $query->count(); $total = ceil($count / $limit); $page = max(0, min($total - 1, $page)); $comments = $query->offset($page * $limit)->limit($limit)->orderBy('created', 'DESC')->get(); if ($comments) { $pending = $this['db']->createQueryBuilder()->from('@blog_comment')->where(['status' => CommentInterface::STATUS_PENDING])->whereIn('post_id', array_unique(array_map(function ($comment) { return $comment->getPostId(); }, $comments)))->groupBy('post_id')->execute('post_id, count(id)')->fetchAll(\PDO::FETCH_KEY_PAIR); } else { $pending = []; } foreach ($comments as $comment) { $comment->setContent($this['content']->applyPlugins($comment->getContent(), ['comment' => true])); } if ($this['request']->isXmlHttpRequest()) { return $this['response']->json(['table' => $this['view']->render('extension://blog/views/admin/comment/table.razr', ['count' => $count, 'comments' => $comments, 'post' => $post, 'pending' => $pending]), 'total' => $total]); } $title = $post ? __('Comments on %title%', ['%title%' => $post->getTitle()]) : __('Comments'); return ['head.title' => $title, 'comments' => $comments, 'post' => $post, 'statuses' => Comment::getStatuses(), 'filter' => $filter, 'total' => $total, 'count' => $count, 'pending' => $pending]; }
/** * @Request({"id": "int", "user": "******", "password", "roles": "array"}, csrf=true) * @Response("json") */ public function saveAction($id, $data, $password, $roles = null) { try { // is new ? if (!($user = $this->users->find($id))) { if ($id) { throw new Exception(__('User not found.')); } if (empty($password)) { throw new Exception(__('Password required.')); } $user = new User(); $user->setRegistered(new \DateTime()); } $self = $this->user->getId() == $user->getId(); if ($self && $user->isBlocked()) { throw new Exception(__('Unable to block yourself.')); } $name = trim(@$data['username']); $email = trim(@$data['email']); if (strlen($name) < 3 || !preg_match('/^[a-zA-Z0-9_\\-]+$/', $name)) { throw new Exception(__('Username is invalid.')); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new Exception(__('Email is invalid.')); } if ($this->users->where(['id <> :id'], compact('id'))->where(function ($query) use($name) { $query->orWhere(['username = :username', 'email = :username'], ['username' => $name]); })->first()) { throw new Exception(__('Username not available.')); } if ($this->users->where(['id <> :id'], compact('id'))->where(function ($query) use($email) { $query->orWhere(['username = :email', 'email = :email'], ['email' => $email]); })->first()) { throw new Exception(__('Email not available.')); } $data['username'] = $name; $data['email'] = $email; if ($email != $user->getEmail()) { $user->set('verified', false); } if (!empty($password)) { $user->setPassword($this['auth.password']->hash($password)); } if ($this->user->hasAccess('system: manage user permissions')) { if ($self && $user->hasRole(RoleInterface::ROLE_ADMINISTRATOR) && (!$roles || !in_array(RoleInterface::ROLE_ADMINISTRATOR, $roles))) { $roles[] = RoleInterface::ROLE_ADMINISTRATOR; } $user->setRoles($roles ? $this->roles->query()->whereIn('id', $roles)->get() : []); } $this->users->save($user, $data); return ['message' => $id ? __('User saved.') : __('User created.'), 'user' => $this->getInfo($user)]; } catch (Exception $e) { return ['error' => $e->getMessage()]; } }
/** * @Route("/feed") * @Route("/feed/{type}") */ public function feedAction($type = '') { $feed = $this['feed']->create($type ?: $this->extension->getParams('feed.type'), ['title' => $this['option']->get('system:app.site_title'), 'link' => $this['url']->route('@blog/site', [], true), 'description' => $this['option']->get('system:app.site_description'), 'element' => ['language', $this['option']->get('system:app.locale')], 'selfLink' => $this['url']->route('@blog/site/feed', [], true)]); if ($last = $this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->limit(1)->orderBy('modified', 'DESC')->first()) { $feed->setDate($last->getModified()); } foreach ($this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->related('user')->limit($this->extension->getParams('feed.limit'))->orderBy('date', 'DESC')->get() as $post) { $feed->addItem($feed->createItem(['title' => $post->getTitle(), 'link' => $this['url']->route('@blog/id', ['id' => $post->getId()], true), 'description' => $this['content']->applyPlugins($post->getContent(), ['post' => $post, 'markdown' => $post->get('markdown'), 'readmore' => true]), 'date' => $post->getDate(), 'author' => [$post->getUser()->getName(), $post->getUser()->getEmail()], 'id' => $this['url']->route('@blog/id', ['id' => $post->getId()], true)])); } return $this['response']->create($feed->generate(), Response::HTTP_OK, ['Content-Type' => $feed->getMIMEType()]); }
/** * @Request({"id": "int"}) * @Response("extension://blog/views/admin/post/edit.razr") */ public function editAction($id) { try { if (!($post = $this->posts->query()->where(compact('id'))->related('user')->first())) { throw new Exception(__('Invalid post id.')); } } catch (Exception $e) { $this['message']->error($e->getMessage()); return $this->redirect('@blog/post'); } return ['head.title' => __('Edit Post'), 'post' => $post, 'statuses' => Post::getStatuses(), 'roles' => $this->roles->findAll(), 'users' => $this->users->findAll()]; }
/** * @Route("/feed") * @Route("/feed/{type}") */ public function feedAction($type = '') { $feed = $this->getFeed($type); $feed->setTitle($this['option']->get('system:app.site_title')); $feed->setLink($this['url']->route('@blog/site/index', [], true)); $feed->setDescription($this['option']->get('system:app.site_description')); $feed->setChannelElement('language', $this['option']->get('system:app.locale')); if ($last = $this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->limit(1)->orderBy('modified', 'DESC')->first()) { $feed->setDate($last->getModified()->format(DATE_RSS)); } $feed->setSelfLink($this['url']->route('@blog/site/feed', [], true)); foreach ($this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->related('user')->limit($this->extension->getParams('feed.limit'))->orderBy('date', 'DESC')->get() as $post) { $item = $feed->createNewItem(); $item->setTitle($post->getTitle()); $item->setLink($this['url']->route('@blog/id', ['id' => $post->getId()], true)); $item->setDescription($this['content']->applyPlugins($post->getContent(), ['post' => $post, 'markdown' => $post->get('markdown'), 'readmore' => true])); $item->setDate($post->getDate()->format(DATE_RSS)); $item->setAuthor($post->getUser()->getName(), $post->getUser()->getEmail()); $item->setId($this['url']->route('@blog/id', ['id' => $post->getId()], true), true); $feed->addItem($item); } return $this['response']->create($feed->generateFeed(), Response::HTTP_OK, array('Content-Type' => $feed->getMIMEType())); }
/** * @Response("extension://system/views/admin/user/permission.razr") */ public function indexAction() { $roles = $this->roles->query()->orderBy('priority')->get(); return ['head.title' => __('Permissions'), 'roles' => $roles, 'permissions' => $this['permissions']]; }