/** * 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; }