Ejemplo n.º 1
0
 /**
  * Returns the rendered template
  *
  * @return bool|mixed|string
  */
 public function fetch()
 {
     $this->render();
     return $this->tpl->fetch($this->template);
 }
Ejemplo n.º 2
0
 /**
  * Render a confirmation form to a string
  *
  * @param array   $hiddens  associative array of values used to complete confirmed action
  * @param string  $action   form action (URL)
  * @param string  $msg      message to display
  * @param string  $submit   submit button message
  * @param boolean $addtoken true to add CSRF token
  *
  * @return string rendered confirm message
  */
 public function confirm($hiddens, $action, $msg, $submit = '', $addtoken = true)
 {
     $tpl = new XoopsTpl();
     $submit = $submit != '' ? trim($submit) : XoopsLocale::A_SUBMIT;
     $tpl->assign('msg', $msg);
     $tpl->assign('action', $action);
     $tpl->assign('submit', $submit);
     $str_hiddens = '';
     foreach ($hiddens as $name => $value) {
         if (is_array($value)) {
             foreach ($value as $caption => $newvalue) {
                 $str_hiddens .= '<input type="radio" name="' . $name . '" value="' . htmlspecialchars($newvalue) . '" > ' . $caption . NWLINE;
             }
             $str_hiddens .= '<br />' . NWLINE;
         } else {
             $str_hiddens .= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />' . NWLINE;
         }
     }
     if ($addtoken != false) {
         $tpl->assign('token', $this->security()->getTokenHTML());
     }
     $tpl->assign('hiddens', $str_hiddens);
     return $tpl->fetch('module:system/system_confirm.tpl');
 }
Ejemplo n.º 3
0
$item_page_id = Request::getInt('page', -1);
if ($itemid == 0) {
    $xoops->redirect("javascript:history.go(-1)", 1, _MD_PUBLISHER_NOITEMSELECTED);
}
// Creating the item object for the selected item
/* @var $itemObj PublisherItem */
$itemObj = $publisher->getItemHandler()->get($itemid);
// if the selected item was not found, exit
if (!$itemObj) {
    $xoops->redirect("javascript:history.go(-1)", 1, _MD_PUBLISHER_NOITEMSELECTED);
}
// Creating the category object that holds the selected item
$categoryObj = $publisher->getCategoryHandler()->get($itemObj->getVar('categoryid'));
// Check user permissions to access that category of the selected item
if (!$itemObj->accessGranted()) {
    $xoops->redirect("javascript:history.go(-1)", 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
}
$publisher->loadLanguage('main');
$tpl = new XoopsTpl();
$tpl->assign('item', $itemObj->toArray('all'));
$tpl->assign('display_whowhen_link', $publisher->getConfig('item_disp_whowhen_link'));
$content = $tpl->fetch('module:publisher/pdf.tpl');
$xoops->service('htmltopdf')->startPdf();
$xoops->service('htmltopdf')->setAuthor($itemObj->posterName());
$xoops->service('htmltopdf')->setTitle($itemObj->getVar('title'));
$xoops->service('htmltopdf')->setKeywords($itemObj->getVar('meta_keywords'));
$xoops->service('htmltopdf')->setSubject($categoryObj->getVar('name'));
$xoops->service('htmltopdf')->addHtml($content);
$name = $itemObj->getVar('short_url') . '.pdf';
$xoops->service('htmltopdf')->outputPdfInline($name);
exit;
Ejemplo n.º 4
0
*/
use Xoops\Core\Request;
use Xoops\Core\XoopsTpl;
/**
 * @copyright       XOOPS Project (http://xoops.org)
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
 * @author          trabis <*****@*****.**>
 * @version         $Id$
 */
include dirname(dirname(__DIR__)) . '/mainfile.php';
$xoops = Xoops::getInstance();
if (Request::getBool('pdf', false)) {
    $content = \Xoops\Utils::dumpVar($xoops->getConfigs(), false);
    $tpl = new XoopsTpl();
    $tpl->assign('dummy_content', $content);
    $content2 = $tpl->fetch('module:system/system_dummy.tpl');
    if ($xoops->service('htmltopdf')->isAvailable()) {
        $xoops->service('htmltopdf')->addHtml($content2);
        $xoops->service('htmltopdf')->outputPdfInline('codex_example.pdf');
    } else {
        $xoops->header();
        echo 'Please install an HtmlToPdf provider!';
        \Xoops\Utils::dumpFile(__FILE__);
        $xoops->footer();
    }
} else {
    $xoops->header();
    echo '<a href="?pdf=1">Make Pdf</a>';
    \Xoops\Utils::dumpFile(__FILE__);
    $xoops->footer();
}
Ejemplo n.º 5
0
if (!$perm_view) {
    $xoops->redirect('javascript:history.go(-1)', 2, XoopsLocale::E_NO_ACCESS_PERMISSION);
    exit;
}
// Get content
$view_content = $content_Handler->get($content_id);
// Test if the page exist
if (count($view_content) == 0 || $view_content->getVar('content_status') == 0) {
    $xoops->redirect('index.php', 3, PageLocale::E_NOT_EXIST);
    exit;
}
$tpl = new XoopsTpl();
// content
$content = $view_content->getValues();
foreach ($content as $k => $v) {
    $tpl->assign($k, $v);
}
// related
$tpl->assign('related', $link_Handler->menu_related($content_id));
$tpl->assign('xoops_sitename', $xoops->getConfig('sitename'));
// Meta
$tpl->assign('xoops_pagetitle', strip_tags($view_content->getVar('content_title') . ' - ' . XoopsLocale::A_PRINT . ' - ' . $xoopsModule->name()));
$content = $tpl->fetch('module:page/page_pdf.tpl');
if ($xoops->service('htmltopdf')->isAvailable()) {
    $xoops->service('htmltopdf')->addHtml($content);
    $xoops->service('htmltopdf')->outputPdfInline('example.pdf');
} else {
    $xoops->header();
    echo $content;
    $xoops->footer();
}
Ejemplo n.º 6
0
function menus_mainmenu_show()
{
    $block = array();
    $xoops = Xoops::getInstance();
    $helper = Xoops::getModuleHelper('menus');
    $module_handler = $xoops->getHandlerModule();
    $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
    $criteria->add(new Criteria('isactive', 1));
    $criteria->add(new Criteria('weight', 0, '>'));
    $modules = $module_handler->getObjectsArray($criteria, true);
    $moduleperm_handler = $xoops->getHandlerGroupPermission();
    $groups = $xoops->getUserGroups();
    $read_allowed = $moduleperm_handler->getItemIds('module_read', $groups);
    $menus = array();
    $menu = $helper->getHandlerMenu()->create();
    $menu->setVar('id', 1);
    $menu->setVar('pid', 0);
    $menu->setVar('alt_title', _MB_MENUS_HOME);
    $menu->setVar('title', _MB_MENUS_HOME);
    $menu->setVar('link', \XoopsBaseConfig::get('url'));
    $menu->setVar('image', 'icon-home');
    $menus[] = $menu->getValues();
    foreach (array_keys($modules) as $i) {
        if (in_array($i, $read_allowed)) {
            /* @var $plugin MenusPluginInterface */
            $menu = $helper->getHandlerMenu()->create();
            $menu->setVar('id', $i);
            $menu->setVar('pid', 0);
            $menu->setVar('title', $modules[$i]->getVar('name'));
            $menu->setVar('alt_title', $modules[$i]->getVar('name'));
            $menu->setVar('link', \XoopsBaseConfig::get('url') . '/modules/' . $modules[$i]->getVar('dirname'));
            $menu->setVar('image', 'icon-tags');
            $menus[] = $menu->getValues();
            if ($xoops->isModule() && $xoops->module->getVar('dirname') == $modules[$i]->getVar('dirname') && ($plugin = \Xoops\Module\Plugin::getPlugin($modules[$i]->getVar('dirname'), 'menus'))) {
                $sublinks = $plugin->subMenus();
                $j = -1;
                foreach ($sublinks as $sublink) {
                    $menu = $helper->getHandlerMenu()->create();
                    $menu->setVar('id', $j);
                    $menu->setVar('pid', $i);
                    $menu->setVar('title', $sublink['name']);
                    $menu->setVar('alt_title', $sublink['name']);
                    $menu->setVar('link', \XoopsBaseConfig::get('url') . '/modules/' . $modules[$i]->getVar('dirname') . '/' . $sublink['url']);
                    $menus[] = $menu->getValues();
                    $j--;
                }
            }
        }
    }
    $builder = new MenusBuilder($menus);
    $block = $builder->render();
    $skin_info = $helper->getSkinInfo('mainmenu', false);
    $blockTpl = new XoopsTpl();
    $blockTpl->assign('block', $block);
    $blockTpl->assign('config', $skin_info['config']);
    $blockTpl->assign('skinurl', $skin_info['url']);
    $blockTpl->assign('skinpath', $skin_info['path']);
    $block['content'] = $blockTpl->fetch($skin_info['template']);
    return $block;
}
Ejemplo n.º 7
0
 /**
  * Blocks::buildBlock()
  *
  * @param XoopsBlock $xobject  block to render
  * @param XoopsTpl   $template template engine
  *
  * @return array|bool
  */
 public function buildBlock(XoopsBlock $xobject, XoopsTpl $template)
 {
     $xoops = \Xoops::getInstance();
     // The lame type workaround will change
     // bid is added temporarily as workaround for specific block manipulation
     $dirname = $xobject->getVar('dirname');
     $block = array('id' => $xobject->getVar('bid'), 'module' => $dirname, 'title' => $xobject->getVar('title'), 'weight' => $xobject->getVar('weight'), 'lastmod' => $xobject->getVar('last_modified'));
     $bcachetime = (int) $xobject->getVar('bcachetime');
     if (empty($bcachetime)) {
         $template->caching = 0;
     } else {
         $template->caching = 2;
         $template->cache_lifetime = $bcachetime;
     }
     $template->setCompileId($dirname);
     $tplName = ($tplName = $xobject->getVar('template')) ? "block:{$dirname}/{$tplName}" : "module:system/system_block_dummy.tpl";
     //$tplName = str_replace('.html', '.tpl', $tplName);
     $cacheid = $this->generateCacheId('blk_' . $xobject->getVar('bid'));
     $xoops->preload()->triggerEvent('core.themeblocks.buildblock.start', array($xobject, $template->isCached($tplName, $cacheid)));
     if (!$bcachetime || !$template->isCached($tplName, $cacheid)) {
         //Get theme metas
         $old = array();
         if ($this->theme && $bcachetime) {
             foreach ($this->theme->metas as $type => $value) {
                 $old[$type] = $this->theme->metas[$type];
             }
         }
         //build block
         if ($bresult = $xobject->buildBlock()) {
             $template->assign('block', $bresult);
             $block['content'] = $template->fetch($tplName, $cacheid);
         } else {
             $block = false;
         }
         //check if theme added new metas
         if ($this->theme && $bcachetime) {
             $metas = array();
             foreach ($this->theme->metas as $type => $value) {
                 $dif = \Xoops\Utils::arrayRecursiveDiff($this->theme->metas[$type], $old[$type]);
                 if (count($dif)) {
                     $metas[$type] = $dif;
                 }
             }
             if (count($metas)) {
                 \Xoops\Cache::write($cacheid, $metas);
             }
         }
     } else {
         $block['content'] = $template->fetch($tplName, $cacheid);
     }
     //add block cached metas
     if ($this->theme && $bcachetime) {
         if ($metas = \Xoops\Cache::read($cacheid)) {
             foreach ($metas as $type => $value) {
                 $this->theme->metas[$type] = array_merge($this->theme->metas[$type], $metas[$type]);
             }
         }
     }
     $template->setCompileId();
     return $block;
 }
Ejemplo n.º 8
0
 /**
  * Render the page
  * The theme engine builds pages from 2 templates: canvas and content.
  * A module can call this method directly and specify what templates the theme engine must use.
  * If render() hasn't been called before, the theme defaults will be used for the canvas and
  * page template (and xoopsOption['template_main'] for the content).
  *
  * @param string $canvasTpl  The canvas template, if different from the theme default
  * @param string $pageTpl    The page template, if different from the theme default (unsupported, 2.3+ only)
  * @param string $contentTpl The content template
  * @param array  $vars       Template variables to send to the template engine
  *
  * @return bool
  */
 public function render($canvasTpl = null, $pageTpl = null, $contentTpl = null, $vars = array())
 {
     if ($this->renderCount) {
         return false;
     }
     $xoops = \Xoops::getInstance();
     $xoops->events()->triggerEvent('core.theme.render.start', array($this));
     $cache = $xoops->cache($this->headersCacheEngine);
     //Get meta information for cached pages
     if ($this->contentCacheLifetime && $this->contentCacheId && ($content = $cache->read($this->contentCacheId))) {
         //we need to merge metas set by blocks with the module cached meta
         $this->htmlHeadStrings = array_merge($this->htmlHeadStrings, $content['htmlHeadStrings']);
         foreach ($content['metas'] as $type => $value) {
             $this->metas[$type] = array_merge($this->metas[$type], $content['metas'][$type]);
         }
         $xoops->setOption('xoops_pagetitle', $content['xoops_pagetitle']);
         $xoops->setOption('xoops_module_header', $content['header']);
     }
     if ($xoops->getOption('xoops_pagetitle')) {
         $this->template->assign('xoops_pagetitle', $xoops->getOption('xoops_pagetitle'));
     }
     $header = !$xoops->getOption('xoops_module_header') ? $this->template->getTemplateVars('xoops_module_header') : $xoops->getOption('xoops_module_header');
     //save meta information of cached pages
     if ($this->contentCacheLifetime && $this->contentCacheId && !$contentTpl) {
         $content['htmlHeadStrings'] = (array) $this->htmlHeadStrings;
         $content['metas'] = (array) $this->metas;
         $content['xoops_pagetitle'] = $this->template->getTemplateVars('xoops_pagetitle');
         $content['header'] = $header;
         $cache->write($this->contentCacheId, $content);
     }
     //  @internal : Lame fix to ensure the metas specified in the xoops config page don't appear twice
     $old = array('robots', 'keywords', 'description', 'rating', 'author', 'copyright');
     foreach ($this->metas['meta'] as $name => $value) {
         if (in_array($name, $old)) {
             $this->template->assign("xoops_meta_{$name}", htmlspecialchars($value, ENT_QUOTES));
             unset($this->metas['meta'][$name]);
         }
     }
     // We assume no overlap between $GLOBALS['xoopsOption']['xoops_module_header'] and
     // $this->template->getTemplateVars( 'xoops_module_header' ) ?
     $this->template->assign('xoops_module_header', $this->renderMetas(true) . "\n" . $header);
     if ($canvasTpl) {
         $this->canvasTemplate = $canvasTpl;
     }
     if ($contentTpl) {
         $this->contentTemplate = $contentTpl;
     }
     if (!empty($vars)) {
         $this->template->assign($vars);
     }
     if ($this->contentTemplate) {
         $this->content = $this->template->fetch($this->contentTemplate, $this->contentCacheId);
     }
     if ($this->bufferOutput) {
         $this->content .= ob_get_contents();
         ob_end_clean();
     }
     $this->template->assignByRef('xoops_contents', $this->content);
     // Do not cache the main (theme.html) template output
     $this->template->caching = 0;
     if (false === (bool) $xoops->getConfig('disable_theme_shortcodes')) {
         $this->template->loadFilter('output', 'shortcodes');
     }
     $this->template->display($this->path . '/' . $this->canvasTemplate);
     $this->renderCount++;
     $xoops->events()->triggerEvent('core.theme.render.end', array($this));
     return true;
 }