/** * Displays URL Aliases with Pagination, also allows the * user to easily add/edit/remove existing aliases * * @return string */ public function indexSection() { if (!$this->_acl->checkMulti(array('aliases_add', 'aliases_edit', 'aliases_delete'))) { throw new Module_NoPermission(); } $this->setTitle(t('URL aliases')); $this->setOutputType(self::_OT_CONFIG); // Get all the needed aliases to display if ($this->inSector('SC') && $this->_input->has('get', 'page')) { $curPage = abs($this->_input->get('page') - 1); } else { $curPage = 0; } $aliases = $this->_model()->getAll(self::_PER_PAGE, self::_PER_PAGE * $curPage); $aliasCount = $this->_model()->getCount(); if ($aliasCount > 0) { $pagination = new Pagination($aliasCount, self::_PER_PAGE); } // Build and display view $view = $this->loadView('overview.html'); $view->assign(array('ALIASES' => $aliases)); $view->assignHtml(array('PAGINATION' => isset($pagination) ? $pagination->build() : null, 'CSRF' => $this->_input->createToken(true))); // Autocomplete/suggest feature $this->_theme->addJsFile('jquery.autocomplete'); $this->_theme->addCssFile('jquery.autocomplete.css'); $this->addAsset('js/autocomplete.js'); return $view->getOutput(); }
/** * Displays the last X registered users. * * @return string */ public function indexSection() { $this->setTitle(t('User management')); $this->setOutputType(self::_OT_CONFIG); // Check user has correct permission if (!$this->_acl->checkMulti(array('users_add', 'users_edit', 'users_delete'))) { throw new Module_NoPermission(); } try { $curPage = abs($this->_input->get('page') - 1); } catch (Input_KeyNoExist $e) { $curPage = 0; } /** * Configure Pagination, build and output the main view file */ $pagination = new Pagination($this->_ugmanager->userCount() - 1, self::_PER_PAGE); $view = $this->loadView('config/main.html'); $view->assign(array('USERS' => $this->_ugmanager->getAllUsers(null, self::_PER_PAGE, $curPage * self::_PER_PAGE))); $view->assignHtml(array('CSRF' => $this->_input->createToken(true), 'PAGINATION' => $pagination->build())); // Autocomplete/suggest feature $this->_theme->addJsFile('jquery.autocomplete'); $this->_theme->addCssFile('jquery.autocomplete.css'); $this->addAsset('js/autocomplete.js'); return $view->getOutput(); }
/** * Displays an overview of pages for a user to manage. Only the parent * will be shown, non of the children will be. * * @return string */ public function indexSection() { $this->setTitle(t('Manage pages')); $this->setOutputType(self::_OT_CONFIG); if (!$this->_acl->check('page_manage')) { throw new Module_NoPermission(); } // Check what pagination page we are on, and get all pages try { $curPage = abs($this->_input->get('page') - 1); } catch (Input_KeyNoExist $e) { $curPage = 0; } $pages = $this->_model()->getAllPages(self::_PER_PAGE, $curPage * self::_PER_PAGE, 0); $pageCount = $this->_model()->getCount(); if ($pageCount > 0) { $pagination = new Pagination($pageCount, self::_PER_PAGE); } // Build and return view $view = $this->loadView('config/overview.html'); $view->assign(array('PAGES' => $pages)); $view->assignHtml(array('PAGINATION' => isset($pagination) ? $pagination->build() : '', 'CSRF' => $this->_input->createToken(true))); // Autocomplete/suggest feature $this->_theme->addJsFile('jquery.autocomplete'); $this->_theme->addCssFile('jquery.autocomplete.css'); $this->addAsset('js/autocomplete.js'); return $view->getOutput(); }
/** * Displays all of the contact forms, and can also delete the selected * contact forms. * * @return string|bool */ public function indexSection() { $this->setTitle(t('Manage contact forms')); $this->setOutputType(self::_OT_CONFIG); if ($this->_input->checkToken()) { if (!$this->_acl->check('contact_delete')) { throw new Module_NoPermission(); } try { $delCount = 0; foreach ($this->_input->post('contact_ids') as $fid) { try { $form = $this->_model()->getForm($fid); // Check user has permission $resource = 'contact-form-' . $form['id']; if ($this->_acl->resourceExists($resource) && $this->_acl->check($resource)) { $this->_model()->deleteForm($form['id']); ++$delCount; } } catch (Contact_NoExist $e) { } } if ($delCount) { $this->_event->success(t('Deleted selected contact forms')); } } catch (Input_KeyNoExist $e) { $this->_event->error(t('No contact forms selected')); } return zula_redirect($this->_router->makeUrl('contact', 'config')); } else { if ($this->_acl->checkMulti(array('contact_edit', 'contact_add', 'contact_delete'))) { // Find out what page we are on try { $curPage = abs($this->_input->get('page') - 1); } catch (Input_KeyNoExist $e) { $curPage = 0; } $forms = $this->_model()->getAllForms(self::_PER_PAGE, $curPage * self::_PER_PAGE); $formCount = $this->_model()->getCount(); if ($formCount > 0) { $pagination = new Pagination($formCount, self::_PER_PAGE); } $view = $this->loadView('config/overview.html'); $view->assign(array('FORMS' => $forms, 'COUNT' => $formCount)); $view->assignHtml(array('PAGINATION' => isset($pagination) ? $pagination->build() : '', 'CSRF' => $this->_input->createToken(true))); return $view->getOutput(); } else { throw new Module_NoPermission(); } } }
/** * Displays all polls (with pagination), or deletes the selected * * @return string|bool */ public function indexSection() { $this->setTitle(t('Manage polls')); $this->setOutputType(self::_OT_CONFIG); if ($this->_input->checkToken()) { // Attempt to delete all selected polls if (!$this->_acl->check('poll_delete')) { throw new Module_NoPermission(); } try { $pollIds = $this->_input->post('poll_ids'); $count = 0; foreach ($pollIds as $pid) { // check if user has permission to the poll $aclResource = 'poll-' . $pid; if ($this->_acl->resourceExists($aclResource) && $this->_acl->check($aclResource)) { $this->_model()->deletePoll($pid); ++$count; } } if ($count > 0) { $this->_event->success(t('Deleted selected polls')); } } catch (Input_KeyNoExist $e) { $this->_event->error(t('No polls selected')); } return zula_redirect($this->_router->makeUrl('poll', 'config')); } else { if ($this->_acl->checkMulti(array('poll_add', 'poll_edit', 'poll_delete'))) { // Display certain amount of polls try { $curPage = abs($this->_input->get('page') - 1); } catch (Input_KeyNoExist $e) { $curPage = 0; } $polls = $this->_model()->getAllPolls(self::_PER_PAGE, $curPage * self::_PER_PAGE); $pollCount = $this->_model()->getCount(); if ($pollCount > 0) { $pagination = new Pagination($pollCount, self::_PER_PAGE); } $view = $this->loadView('config/overview.html'); $view->assign(array('POLLS' => $polls, 'COUNT' => $pollCount)); $view->assignHtml(array('PAGINATION' => isset($pagination) ? $pagination->build() : '', 'CSRF' => $this->_input->createToken(true))); return $view->getOutput(); } else { throw new Module_NoPermission(); } } }
/** * Shows comments that can be managed (Edited/deleted etc). Also handles * deleting or approving of selected comments. * * @return string */ public function indexSection() { $this->setTitle(t('Manage comments')); $this->setOutputType(self::_OT_CONFIG); if (!$this->_acl->check('comments_manage')) { throw new Module_NoPermission(); } if ($this->_input->checkToken()) { try { $commentIds = $this->_input->post('comments/ids'); if ($this->_input->has('post', 'comments/approve')) { foreach ($commentIds as $cid) { $this->_model()->edit($cid, array('status' => 'accepted')); } $msg = t('Approved selected comments'); } else { $this->_model()->delete($commentIds); $msg = t('Deleted selected comments'); } $this->_event->success($msg); } catch (Input_KeyNoExist $e) { $this->_event->error(t('No comments selected')); } return zula_redirect($this->_router->makeUrl('comments', 'config')); } else { try { $type = $this->_input->get('type'); } catch (Input_KeyNoExist $e) { $type = $this->_config->get('comments/moderate') ? 'moderation' : 'all'; } // Display the correct comments respecting pagination and build form try { $curPage = abs($this->_input->get('page') - 1); } catch (Input_KeyNoExist $e) { $curPage = 0; } $comments = $this->_model()->get(null, $type, self::_PER_PAGE, self::_PER_PAGE * $curPage, 'DESC'); $commentsCount = $this->_model()->getCount(); if ($commentsCount > 0) { $pagination = new Pagination($commentsCount, self::_PER_PAGE); } $view = $this->loadView('config/main.html'); $view->assign(array('count' => $commentsCount, 'type' => $type)); $view->assignHtml(array('pagination' => isset($pagination) ? $pagination->build() : '', 'csrf' => $this->_input->createToken(true), 'comments' => $comments)); return $view->getOutput(); } }
/** * Displays a selective amount of users per page, with details * about that users and links to their Profile. * * @return string */ public function indexSection() { $this->setTitle(t('User list')); // Get correct page/offset if ($this->inSector('SC') && $this->_input->has('get', 'page')) { $curPage = abs($this->_input->get('page') - 1); } else { $curPage = 0; } // Gather all of the users and attach the group name onto the array $pdoSt = $this->_sql->prepare('SELECT u.id, u.group, u.username, u.email, u.hide_email, u.joined, g.name group_name FROM {PREFIX}users u LEFT JOIN {PREFIX}groups g ON g.id = u.group WHERE u.status = "active" AND u.id != ' . Ugmanager::_GUEST_ID . ' LIMIT :limit OFFSET :offset'); $pdoSt->bindValue(':limit', self::_PER_PAGE, PDO::PARAM_INT); $pdoSt->bindValue(':offset', $curPage * self::_PER_PAGE, PDO::PARAM_INT); $pdoSt->execute(); $users = array(); foreach ($pdoSt->fetchAll(PDO::FETCH_ASSOC) as $user) { if (!empty($user['hide_email']) && $user['id'] != $this->_session->getUserId() && !$this->_acl->check('users_edit')) { $user['email'] = t('Hidden'); } $users[] = $user; } // How many users would have been returned without limit/offset? $query = $this->_sql->query('SELECT COUNT(id) FROM {PREFIX}users WHERE status = "active" AND id != ' . Ugmanager::_GUEST_ID); $totalUsers = $query->fetchColumn(); $query->closeCursor(); /** * Display the table with pagination */ $pagination = new Pagination($totalUsers, self::_PER_PAGE); $view = $this->loadView('index/main.html'); $view->assign(array('users' => $users)); $view->assignHtml(array('pagination' => $pagination->build())); return $view->getOutput(); }
/** * Displays published articles for a given category (if any) * * @param string $category * @param bool $catSelector Toggles the category selector * @return string */ protected function displayArticles($category = false, $catSelector = true) { $this->setOutputType(self::_OT_CONTENT_INDEX); if (empty($category)) { $this->setTitle(t('Latest articles')); $categories = $this->_model()->getAllCategories(); $cid = null; } else { /** * Attempt to get the single article category details, and check permission */ try { $category = $this->_model()->getCategory($category, false); $this->setTitle($category['title']); $categories = array($category['id'] => $category); $cid = $category['id']; $resource = 'article-cat-' . $category['id']; if (!$this->_acl->resourceExists($resource) || !$this->_acl->check($resource)) { throw new Module_NoPermission(); } } catch (Article_CatNoExist $e) { throw new Module_ControllerNoExist(); } } /** * Check how many to display per page, and what page we are on */ try { $perPage = abs($this->_config->get('article/per_page')); } catch (Input_KeyNoExist $e) { $perPage = 12; } if ($this->inSector('SC') && $this->_input->has('get', 'page')) { $curPage = abs($this->_input->get('page') - 1); } else { $curPage = 0; } // Get the required articles and parse their first article part body $maxDisplayAge = $this->_config->get('article/max_display_age'); $articles = array(); foreach ($this->_model()->getAllArticles($perPage, $curPage * $perPage, $cid, false, $maxDisplayAge) as $tmpArticle) { if (isset($categories[$tmpArticle['cat_id']])) { $parts = $this->_model()->getArticleParts($tmpArticle['id']); $firstPart = current($parts); $editor = new Editor($firstPart['body']); $editor->setContentUrl($this->_router->makeUrl('article', 'view', $tmpArticle['identifier'])); $tmpArticle['body'] = $editor->parse(true); $tmpArticle['category_title'] = $categories[$tmpArticle['cat_id']]['title']; $tmpArticle['category_identifier'] = $categories[$tmpArticle['cat_id']]['identifier']; $articles[] = $tmpArticle; } } $articleCount = $this->_model()->getCount(); if ($articleCount > 0) { $pagination = new Pagination($articleCount, $perPage); } // Build up the view $view = $this->loadView('index/latest.html'); $view->assign(array('META_FORMAT' => $this->getMetaFormat($this->_config->get('article/meta_format')), 'CAT_DETAILS' => $cid ? $category : null)); $view->assignHtml(array('ARTICLES' => $articles, 'PAGINATION' => isset($pagination) ? $pagination->build() : null)); if ($cid == false && $catSelector) { /** Prepend the category selector */ $catSelectorView = $this->loadView('index/category_selector.html'); $catSelectorView->assign(array('CATEGORIES' => $categories)); return $catSelectorView->getOutput() . $view->getOutput(true); } else { return $view->getOutput(true); } }
/** * Displays all articles with pagination (including unpublished articles). * It will also delete all selected articles. * * @return string|bool */ public function indexSection() { $this->setTitle(t('Manage articles')); $this->setOutputType(self::_OT_CONFIG); if ($this->_input->checkToken()) { // Delete all selected articles if (!$this->_acl->check('article_delete_article')) { throw new Module_NoPermission(); } try { $ids = $this->_input->post('article_ids'); $count = 0; foreach ($ids as $aid) { try { $article = $this->_model()->getArticle($aid); // Check user permission $resource = 'article-cat-' . $article['cat_id']; if ($this->_acl->resourceExists($resource) && $this->_acl->check($resource)) { $this->_model()->deleteArticle($article['id']); ++$count; } } catch (Article_NoExist $e) { } } if ($count) { $this->_event->success(t('Deleted selected articles')); } } catch (Input_KeyNoExist $e) { $this->_event->error(t('No articles selected')); } return zula_redirect($this->_router->makeUrl('article', 'config')); } else { if ($this->_acl->checkMulti(array('article_add_article', 'article_edit_article', 'article_delete_article'))) { /** * Attempt to get details for the category if one was provided */ try { if (($cid = $this->_input->get('cid')) != false) { $category = $this->_model()->getCategory($cid); // Check user has permission to this category $resource = 'article-cat-' . $category['id']; if ($this->_acl->resourceExists($resource) && $this->_acl->check($resource)) { $this->setTitle(sprintf(t('Manage "%s" articles'), $category['title'])); } else { throw new Module_NoPermission(); } } } catch (Input_KeyNoExist $e) { $cid = null; } catch (Article_CatNoExist $e) { $cid = null; } // Get the page which we are on try { $curPage = abs($this->_input->get('page') - 1); } catch (Input_KeyNoExist $e) { $curPage = 0; } $articles = $this->_model()->getAllArticles(self::_PER_PAGE, $curPage * self::_PER_PAGE, $cid, true); $articleCount = $this->_model()->getCount(); if ($articleCount > 0) { $pagination = new Pagination($articleCount, self::_PER_PAGE); } // Build up the main view $view = $this->loadView('config/overview.html'); $view->assign(array('ARTICLES' => $articles, 'COUNT' => $articleCount, 'CATEGORIES' => $this->_model()->getAllCategories(), 'CURRENT_CID' => $cid)); $view->assignHtml(array('PAGINATION' => isset($pagination) ? $pagination->build() : '', 'CSRF' => $this->_input->createToken(true))); $this->_theme->addJsFile('jquery.autocomplete'); $this->_theme->addCssFile('jquery.autocomplete.css'); $this->addAsset('js/autocomplete.js'); return $view->getOutput(); } else { throw new Module_NoPermission(); } } }
public function overview($tpl = null, $pagination = 0, CustomDataFilter $filter = null) { if ($filter === null) { $filter = new CustomDataFilter($this->position); foreach ($this->mainFields as $field) { $filter->field($field); } $filter->orderBy(reset($this->mainFields)); } $pages = ''; if ($pagination > 0) { $pg = new Pagination($pagination, $filter->getAmount()); $pg->setUri($this->baseUri); $pg->parsePage(); $filter->limit($pg->getPerPage(), $pg->getOffset()); $pages = $pg->build(); } $tpl = Response::getObject()->appendTemplate($tpl ? $tpl : "/Cms/fields/data_categories"); $tpl->assign('pages', $pages, false); $tpl->assign('list', $filter->retrieveList(), false); $tpl->assign('baseUri', $this->baseUri); $tpl->output(); }
/** * Builds the view to display latest media items from all * categories, or a specific category. * * @param string $category * @return string */ protected function buildLatest($category = null) { if ($category == null) { $cid = null; } else { try { $category = $this->_model()->getCategory($category, false); $cid = $category['id']; $resource = 'media-cat_view_' . $category['id']; if (!$this->_acl->resourceExists($resource) || !$this->_acl->check($resource)) { throw new Module_NoPermission(); } $this->setTitle($category['name']); // Check if the user can upload/add items to this category if ($this->_acl->check('media-cat_upload_' . $cid)) { $this->setPageLinks(array(t('Upload/add media item') => $this->_router->makeUrl('media', 'add')->queryArgs(array('cid' => $cid)))); } } catch (Media_CategoryNoExist $e) { throw new Module_ControllerNoExist(); } } // Check if details for the items should be displayed try { $showDetails = (bool) $this->_config->get('media/show_item_details'); } catch (Config_KeyNoExist $e) { $showDetails = true; } // Get number of latest media items to display, and which page we are on $perPage = abs($this->_config->get('media/per_page')); if ($this->inSector('SC') && $this->_input->has('get', 'page')) { $curPage = abs($this->_input->get('page') - 1); } else { $curPage = 0; } $items = $this->_model()->getItems($perPage, $perPage * $curPage, $cid); $itemCount = $this->_model()->getItemCount(); if ($itemCount) { $pagination = new Pagination($itemCount, $perPage); } $view = $this->loadView('index/latest.html'); $view->assign(array('ITEMS' => $items, 'CATEGORY' => $category, 'SHOW_DETAILS' => $showDetails)); $view->assignHtml(array('PAGINATION' => isset($pagination) ? $pagination->build() : '')); // Check if lightbox effect needs to be used if ($this->_config->get('media/use_lightbox')) { $this->_theme->addJsFile('jquery.tangobox'); $this->_theme->addCssFile('jquery.tangobox.css'); $view->assign(array('LIGHTBOX' => true)); } else { $view->assign(array('LIGHTBOX' => false)); } return $view->getOutput(); }
/** * Magic method - allows for shorter URL's eg: * /article/view/clean-title * * @param string $name * @param array $args * @return string */ public function __call($name, $args) { $this->setOutputType(self::_OT_CONTENT_DYNAMIC); try { $article = $this->_model()->getArticle(substr($name, 0, -7), false); $this->setTitle($article['title']); $category = $this->_model()->getCategory($article['cat_id']); // Check permission to parent category $resource = 'article-cat-' . $category['id']; if (!$this->_acl->resourceExists($resource) || !$this->_acl->check($resource)) { throw new Module_NoPermission(); } else { if (!$article['published']) { throw new Module_ControllerNoExist(); } } /** * Gather all parts for this article, and check the requested part actually exists */ try { $part = abs($this->_input->get('part')); } catch (Input_KeyNoExist $e) { $part = 0; } $articleParts = array_values($this->_model()->getArticleParts($article['id'], false)); # Done to reindex array try { // Get details for the correct part if (empty($part)) { $partId = $articleParts[0]['id']; } else { if (isset($articleParts[$part - 1]['id'])) { $partId = $articleParts[$part - 1]['id']; } else { throw new Article_PartNoExist($part); } } $requestedPart = $this->_model()->getPart($partId); $editor = new Editor($requestedPart['body']); $body = $editor->parse(); } catch (Article_PartNoExist $e) { throw new Module_ControllerNoExist(); } /** * Build up pagination and the main view file */ try { $curPage = abs($this->_input->get('part') - 1); } catch (Input_KeyNoExist $e) { $curPage = 0; } $pagination = new Pagination(count($articleParts), 1, 'part'); if (count($articleParts) > 1) { $this->addAsset('js/jumpbox.js'); } $view = $this->loadView('view/article.html'); $view->assign(array('META_FORMAT' => $this->getMetaFormat($this->_config->get('article/meta_format')), 'ARTICLE' => $article, 'REQUESTED_PART' => $requestedPart, 'ARTICLE_PARTS' => $articleParts, 'CATEGORY' => $category)); $view->assignHtml(array('BODY' => $body, 'PAGINATION' => $pagination->build())); return $view->getOutput(true); } catch (Article_NoExist $e) { throw new Module_ControllerNoExist(); } }
protected function members() { $db = Database::getObject(); $db->query("SELECT COUNT(*) FROM <p>user"); $pp = Config::get('pagination.admin'); $pg = new Pagination($pp, $db->fetchOne()); $pg->parsePage(); $pg->setUri(Uri::build('/Cms/admin/members')); $offset = $pg->getOffset(); $db->query("SELECT * FROM <p>user ORDER BY surname, forename LIMIT <offset:int>, <pp:int>", compact("offset", "pp")); $data = array(); while ($row = $db->fetchAssoc()) { $row['group'] = UserUtils::getGroupName($row['group_id']); $data[] = $row; } $tpl = Response::getObject()->appendTemplate("Cms/admin/members"); $tpl->assign("pages", $pg->build(), false); $tpl->assign("data", $data); $tpl->output(); }