/** * Restore Page Version * * @return void */ public function restoreTask() { // get reqest vars $pageid = Request::getInt('pageid', 0, 'get'); $version = Request::getInt('version', null, 'get'); // page object $page = new Page($pageid); // make sure page belongs to this group if (!$page->belongsToGroup($this->group)) { App::abort(403, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_AUTH')); } // load page version $pageVersion = $page->version($version); // do we have a page version if ($pageVersion === null) { App::abort(404, Lang::txt('COM_GROUPS_PAGES_PAGE_VERSION_NOT_FOUND')); } // get the current version for this page $currentVersionNumber = $page->version('current')->get('version'); // duplicate page version unsetting the id & updating version # $newVersion = clone $pageVersion; $newVersion->set('id', null); $newVersion->set('version', $currentVersionNumber + 1); // attempt to save new version if (!$newVersion->store(false, $this->group->isSuperGroup())) { $this->setNotification($newVersion->getError(), 'error'); $this->versionsTask(); return; } // redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages&task=versions&pageid=' . $page->get('id')), Lang::txt('COM_GROUPS_PAGES_PAGE_VERSION_RESTORED', $page->get('title'), $version, Date::of($pageVersion->get('created'))->format('M d, Y @ g:ia')), 'passed'); }
/** * Preview Group Module * * @return void */ public function previewTask() { // make sure we are approvers if (!Helpers\Pages::isPageApprover()) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_MODULES_AUTHORIZED_APPROVERS_ONLY'), 'error'); return; } // get reqest vars $moduleid = Request::getInt('moduleid', 0, 'get'); // page object $module = new Module($moduleid); // make sure page belongs to this group if (!$module->belongsToGroup($this->group)) { App::abort(403, Lang::txt('COM_GROUPS_MODULES_NOT_AUTHORIZED')); } // get first module menu's page id $pageid = $module->menu()->first()->get('pageid'); // check if pageid 0 if ($pageid == 0) { // get a list of all pages $pageArchive = Page\Archive::getInstance(); $pages = $pageArchive->pages('list', array('gidNumber' => $this->group->get('gidNumber'), 'state' => array(1), 'orderby' => 'ordering')); // get first page $pageid = $pages->first()->get('id'); } // load page $page = new Page($pageid); // load page version $content = $page->version()->content('parsed'); // create new group document helper $groupDocument = new Helpers\Document(); // strip out scripts & php tags if not super group if (!$this->group->isSuperGroup()) { $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content); $content = preg_replace('/<\\?[\\s\\S]*?\\?>/', '', $content); } // are we allowed to display group modules if (!$this->group->isSuperGroup() && !$this->config->get('page_modules', 0)) { $groupDocument->set('allowed_tags', array()); } // set group doc needed props // parse and render content $groupDocument->set('group', $this->group)->set('page', $page)->set('document', $content)->set('allMods', true)->parse()->render(); // get doc content $content = $groupDocument->output(); // only parse php if Super Group if ($this->group->isSuperGroup()) { // run as closure to ensure no $this scope $eval = function () use($content) { ob_start(); unset($this); eval("?> {$content} <?php "); $content = ob_get_clean(); return $content; }; $content = $eval(); } // get group css $pageCss = Helpers\View::getPageCss($this->group); $css = ''; foreach ($pageCss as $p) { $css .= '<link rel="stylesheet" href="' . $p . '" />'; } // output html $html = '<!DOCTYPE html> <html> <head> <title>' . $this->group->get('description') . '</title> ' . $css . ' </head> <body> ' . $content . ' </body> </html>'; //echo content and exit echo $html; exit; }
/** * Output raw content * * @param $escape Escape outputted content * @return string HTML content */ public function rawTask($escape = true) { // make sure we are approvers if (!Helpers\Pages::isPageApprover()) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_MUST_BE_AUTHORIZED'), 'error'); return; } // get reqest vars $pageid = Request::getInt('pageid', 0, 'get'); $version = Request::getInt('version', null, 'get'); // page object $page = new Page($pageid); // make sure page belongs to this group if (!$page->belongsToGroup($this->group)) { App::abort(403, Lang::txt('COM_GROUPS_PAGES_NOT_AUTH')); } // load page version $pageVersion = $page->version($version); // do we have a page version if ($pageVersion === null) { App::abort(404, Lang::txt('COM_GROUPS_PAGES_VERSION_NOT_FOUND')); } // output page version if ($escape) { echo highlight_string($pageVersion->content('raw'), true); } else { echo $pageVersion->content('raw'); } exit; }
/** * Restore Page Version * * @return void */ public function restoreTask() { // get reqest vars $pageid = Request::getInt('pageid', 0, 'get'); $version = Request::getInt('version', null, 'get'); // page object $page = new Page($pageid); // make sure page belongs to this group if (!$page->belongsToGroup($this->group)) { App::abort(403, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_AUTH')); } // load page version $pageVersion = $page->version($version); // do we have a page version if ($pageVersion === null) { App::abort(404, Lang::txt('COM_GROUPS_PAGES_PAGE_VERSION_NOT_FOUND')); } // get the current version for this page $currentVersionNumber = $page->version('current')->get('version'); // duplicate page version unsetting the id & updating version # $newVersion = clone $pageVersion; $newVersion->set('id', null); $newVersion->set('version', $currentVersionNumber + 1); // attempt to save new version if (!$newVersion->store(false, $this->group->isSuperGroup())) { $this->setNotification($newVersion->getError(), 'error'); return $this->versionsTask(); } // Log activity $recipients = array(['group', $this->group->get('gidNumber')], ['user', User::get('id')]); foreach ($this->group->get('managers') as $recipient) { $recipients[] = ['user', $recipient]; } Event::trigger('system.logActivity', ['activity' => ['action' => 'updated', 'scope' => 'group.page', 'scope_id' => $page->get('id'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_PAGE_RESTORED', $page->get('title'), $version, '<a href="' . $url . '">' . $this->group->get('description') . '</a>'), 'details' => array('title' => $page->get('title'), 'url' => $url, 'gidNumber' => $this->group->get('gidNumber'))], 'recipients' => $recipients]); // redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages&task=versions&pageid=' . $page->get('id')), Lang::txt('COM_GROUPS_PAGES_PAGE_VERSION_RESTORED', $page->get('title'), $version, Date::of($pageVersion->get('created'))->format('M d, Y @ g:ia')), 'passed'); }