/**
  * Return Content
  *
  * @return string
  */
 public function output($echo = false)
 {
     // parse php code
     ob_start();
     eval("?> " . $this->get('document') . " <?php ");
     $this->set('document', ob_get_clean());
     // run output declared in parent
     parent::output($echo);
 }
Exemple #2
0
    /**
     * Generate Group Page Preview
     *
     * @param    $page   Group page object
     * @return   void
     */
    public static function generatePreview($page, $version = 0, $contentOnly = false)
    {
        // get groups
        $gidNumber = $page->get('gidNumber');
        $group = \Hubzero\User\Group::getInstance($gidNumber);
        //get config
        $config = Component::params('com_groups');
        // load page version
        $content = $page->version($version)->content('parsed');
        // create new group document helper
        $groupDocument = new Document();
        // strip out scripts & php tags if not super group
        if (!$group->isSuperGroup()) {
            $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content);
            $content = preg_replace('/<\\?[\\s\\S]*?\\?>/', '', $content);
        }
        // are we allowed to display group modules
        if (!$group->isSuperGroup() && !$config->get('page_modules', 0)) {
            $groupDocument->set('allowed_tags', array());
        }
        // set group doc needed props
        // parse and render content
        $groupDocument->set('group', $group)->set('page', $page)->set('document', $content)->parse()->render();
        // get doc content
        $content = $groupDocument->output();
        // only parse php if Super Group
        if ($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();
        }
        // do we want to retun only content?
        if ($contentOnly) {
            return $content;
        }
        // get group css
        $pageCss = View::getPageCss($group);
        $css = '';
        foreach ($pageCss as $p) {
            $p = rtrim(Request::root(), '/') . '/' . ltrim($p, '/');
            $css .= '<link rel="stylesheet" href="' . $p . '" />';
        }
        // output html
        $html = '<!DOCTYPE html>
				<html>
					<head>
						<title>' . $group->get('description') . '</title>
						' . $css . '
						<style>#system-debug { display: none !important; }</style>
					</head>
					<body class="group-page-preview">
						' . $content . '
					</body>
				</html>';
        // return html
        return $html;
    }
Exemple #3
0
    /**
     * 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;
    }
Exemple #4
0
 /**
  * Display Super Group Pages
  *
  * @return     array
  */
 public static function superGroupPhpPages($group)
 {
     // var to hold content
     $phpPageContent = null;
     // make sure this is a super group
     if (!$group->isSuperGroup()) {
         return $phpPageContent;
     }
     // get URI path
     $path = Request::path();
     $path = trim(str_replace('groups' . DS . $group->get('cn'), '', $path), DS);
     // make sure we have a path. if no path means were attempting to access the home page
     if ($path == '') {
         $path = 'overview';
     }
     // get group upload path
     $uploadPath = Component::params('com_groups')->get('uploadpath');
     // build path to php page in template
     $templatePhpPagePath = PATH_APP . DS . trim($uploadPath, DS) . DS . $group->get('gidNumber') . DS . 'pages' . DS . $path . '.php';
     // if the file is not a valid path
     if (!is_file($templatePhpPagePath)) {
         return $phpPageContent;
     }
     // include & render php file
     ob_start();
     include $templatePhpPagePath;
     $phpPageContent = ob_get_contents();
     ob_end_clean();
     //create new group document helper
     $groupDocument = new Document();
     // set group doc needed props
     // parse and render content
     $groupDocument->set('group', $group)->set('page', null)->set('document', $phpPageContent)->parse()->render();
     // get doc content
     $phpPageContent = $groupDocument->output();
     // run as closure to ensure no $this scope
     $eval = function () use($phpPageContent) {
         ob_start();
         eval("?>{$phpPageContent}<?php ");
         $document = ob_get_clean();
         return $document;
     };
     $phpPageContent = $eval();
     // create view object
     $view = new \Hubzero\Component\View(array('name' => 'pages', 'layout' => '_view_php'));
     // if super group add super group folder
     // to available paths
     if ($group->isSuperGroup()) {
         $base = $group->getBasePath();
         $view->addTemplatePath(PATH_APP . $base . DS . 'template');
     }
     $view->content = $phpPageContent;
     return $view->loadTemplate();
 }