示例#1
0
/**
 * Image block
 *
 * @param array $params
 * @param string $content
 * @param Smarty_Internal_Template $smarty
 * @param bool $repeat
 * @return void
 */
function smarty_block_image(array $params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        $content = $smarty->getTemplateVars('image') ? $content : '';
        $smarty->assign('image', null);
        return $content;
    }
    if (!array_key_exists('rendition', $params)) {
        throw new \InvalidArgumentException("Rendition not set");
    }
    $renditions = Zend_Registry::get('container')->getService('image.rendition')->getRenditions();
    if (!array_key_exists($params['rendition'], $renditions)) {
        throw new \InvalidArgumentException("Unknown rendition");
    }
    $article = $smarty->getTemplateVars('gimme')->article;
    if (!$article) {
        throw new \RuntimeException("Not in article context.");
    }
    $articleRenditions = $article->getRenditions();
    $articleRendition = $articleRenditions[$renditions[$params['rendition']]];
    if ($articleRendition === null) {
        $smarty->assign('image', false);
        $repeat = false;
        return;
    }
    if (array_key_exists('width', $params) && array_key_exists('height', $params)) {
        $preview = $articleRendition->getRendition()->getPreview($params['width'], $params['height']);
        $thumbnail = $preview->getThumbnail($articleRendition->getImage(), Zend_Registry::get('container')->getService('image'));
    } else {
        $thumbnail = $articleRendition->getRendition()->getThumbnail($articleRendition->getImage(), Zend_Registry::get('container')->getService('image'));
    }
    $smarty->assign('image', (object) array('src' => Zend_Registry::get('view')->url(array('src' => $thumbnail->src), 'image', true, false), 'width' => $thumbnail->width, 'height' => $thumbnail->height, 'caption' => $articleRendition->getImage()->getCaption(), 'photographer' => $articleRendition->getImage()->getPhotographer()));
}
示例#2
0
/**
 * Smarty block plugin, for generating page menu item
 * This block must always be called in pageMenu block context
 *
 * @param array $params
 * @param Smarty $smarty
 * @param $repeat
 *
 * <code>
 *	{pageMenu id="menu"}
 *		{menuItem}
 *			{menuCaption}Click Me{/menuCaption}
 *			{menuAction}http://click.me.com{/menuAction}
 *		{/menuItem}
 *		{menuItem}
 *			{menuCaption}Another menu item{/menuCaption}
 *			{pageAction}alert('Somebody clicked on me too!'){/menuAction}
 *		{/menuItem}
 *  {/pageMenu}
 * </code>
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_block_menuItem($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if ($repeat) {
        $smarty->clear_assign('menuCaption');
        $smarty->clear_assign('menuAction');
        $smarty->clear_assign('menuPageAction');
    } else {
        $item = new HtmlElement('a');
        if ($smarty->getTemplateVars('menuAction')) {
            $href = $smarty->getTemplateVars('menuAction');
        } else {
            if ($smarty->getTemplateVars('menuPageAction')) {
                $onClick = $smarty->getTemplateVars('menuPageAction');
                $href = '#';
                $item->setAttribute('onClick', $onClick . '; return false;');
            }
        }
        $item->setAttribute('href', $href);
        // EXPERIMENTAL - set access key for menu item
        $caption = $smarty->getTemplateVars('menuCaption');
        if (FALSE != strpos($caption, '&&')) {
            $p = strpos($caption, '&&');
            $accessKey = substr($caption, $p + 2, 1);
            $item->setAttribute('accessKey', $accessKey);
            $caption = substr($caption, 0, $p + 3) . '</span>' . substr($caption, $p + 3);
            $caption = substr($caption, 0, $p) . '<span class="accessKey">' . substr($caption, $p + 2);
        }
        $item->setContent($caption);
        $smarty->append('pageMenuItems', $item->render());
    }
}
示例#3
0
function smarty_block_fis_widget($params, $content, Smarty_Internal_Template $template, &$repeat)
{
    if (!$repeat) {
        if (isset($params['extends'])) {
            $path = $params['extends'];
            unset($params['extends']);
            foreach ($params as $key => $v) {
                if ($template->getTemplateVars($key)) {
                    $params[$key] = $template->getTemplateVars($key);
                }
            }
            return $content = $template->getSubTemplate($path, $template->cache_id, $template->compile_id, null, null, $params, Smarty::SCOPE_LOCAL);
        } else {
            return $content;
        }
    } else {
        if (isset($params['extends'])) {
            unset($params['extends']);
        }
        foreach ($params as $key => $v) {
            $value = $template->getTemplateVars($key);
            if ($value === null) {
                $template->assign($key, $v, true);
            }
        }
    }
}
/**
 * PixelManager CMS (Community Edition)
 * Copyright (C) 2016 PixelProduction (http://www.pixelproduction.de)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
function smarty_function_getdatatablerow($params, Smarty_Internal_Template $template)
{
    if (!isset($params['class']) || !isset($params['var']) || !isset($params['row'])) {
        return;
    }
    if (isset($params['page'])) {
        $page_id = $params['page'];
    } else {
        $page_id = $template->getTemplateVars('pageId');
    }
    if (isset($params['language'])) {
        $language_id = $params['language'];
    } else {
        $language_id = $template->getTemplateVars('languageId');
        if ($language_id === null) {
            $language_id = Config::get()->languages->standard;
        }
    }
    $data = array();
    if (isset($params['row'])) {
        $data_table = new $params['class']();
        $data = $data_table->getRowForFrontend($params['row'], $page_id, $language_id);
    }
    if (isset($params['var'])) {
        $template->assign($params['var'], $data);
    }
}
示例#5
0
/**
 * Display page section header and footer only if content is present
 * This helps to avoid using redundant if's
 *
 * @param array $params
 * @param Smarty $smarty
 * @param $repeat
 *
 * <code>
 *	{sect}
 *		{header}
 *			Section header
 *		{/header}
 *		{content}
 *			Section content
 *		{/content}
 *		{footer}
 *			Section footer
 *		{/footer}
 *  {/sect}
 * </code>
 *
 * @return string Section HTML code
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_block_header($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        $counter = $smarty->getTemplateVars('sectCounter');
        $blocks = $smarty->getTemplateVars('sect');
        $blocks[$counter]['header'] = $content;
        $smarty->assign('sect', $blocks);
    }
}
示例#6
0
/**
 * Renders an input in smarty.
 *
 * @param string[] $params
 * @param Smarty_Internal_Template $template
 * @return string
 */
function smarty_function_input($params, Smarty_Internal_Template $template)
{
    $name = $params['name'];
    $form = $template->smarty->getForm("Form_" . $template->getTemplateVars("currentForm"));
    $element = $form->get($name);
    $view = $form->createView();
    $renderer = $template->getFormRenderer();
    $c = $renderer->renderInput($element, "Form_" . $template->getTemplateVars("currentForm"), $params);
    return $c;
}
function smarty_function_pageurl($params, Smarty_Internal_Template $template)
{
    $output = '';
    if (isset($params['page'])) {
        if (isset($params['language'])) {
            $language_id = $params['language'];
        } else {
            $language_id = $template->getTemplateVars('languageId');
            if ($language_id === null) {
                $language_id = Config::get()->languages->standard;
            }
        }
        $mixed_id = $params['page'];
        $page_id = false;
        $pages = new Pages();
        if (is_int($mixed_id)) {
            $page_id = $mixed_id;
        } else {
            if (is_numeric($mixed_id)) {
                $page_id = (int) $mixed_id;
            } else {
                if (is_string($mixed_id)) {
                    $page_id = $pages->getPageIdByUniqueId($mixed_id);
                }
            }
        }
        if ($page_id !== false) {
            $output = $pages->getPageUrl($page_id, $language_id);
        }
    }
    return $output;
}
示例#8
0
/**
 *
 * @package application.helper.smarty.form
 * @author Integry Systems
 */
function smarty_function_metricsfield($params, Smarty_Internal_Template $smarty)
{
    if (empty($params['name'])) {
        $params['name'] = $smarty->getTemplateVars('input_name');
    }
    $formParams = $smarty->_tag_stack[0][1];
    $formHandler = $formParams['handle'];
    if (!isset($params['value']) && !$formHandler instanceof Form) {
        throw new HelperException('Element must be placed in {form} block');
    }
    if (!empty($formParams['model'])) {
        $params['ng-model'] = $formParams['model'] . '.' . $params['name'];
    }
    $application = $smarty->getApplication();
    $params['m_sw'] = $application->translate('_switch_to_english_units');
    $params['en_sw'] = $application->translate('_switch_to_metric_units');
    $params['m_hi'] = $application->translate('_units_kg');
    $params['m_lo'] = $application->translate('_units_g');
    $params['en_hi'] = $application->translate('_units_lbs');
    $params['en_lo'] = $application->translate('_units_oz');
    $params['type'] = strtolower($application->getConfig()->get('UNIT_SYSTEM'));
    $content = '<weight-input ' . $smarty->appendParams($content, $params) . '></weight-input>';
    $content = $smarty->formatControl($content, $params);
    return $content;
}
示例#9
0
/**
 * Image block
 *
 * @param array $params
 * @param string $content
 * @param Smarty_Internal_Template $smarty
 * @param bool $repeat
 * @return void
 */
function smarty_block_image(array $params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        $content = $smarty->getTemplateVars('image') ? $content : '';
        $smarty->assign('image', null);
        return $content;
    }
    if (!array_key_exists('rendition', $params)) {
        throw new \InvalidArgumentException("Rendition not set");
    }
    $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
    $renditionService = \Zend_Registry::get('container')->getService('image.rendition');
    $cacheKey = $cacheService->getCacheKey(array('theme_renditions'), 'theme');
    if ($cacheService->contains($cacheKey)) {
        $renditions = $cacheService->fetch($cacheKey);
    } else {
        $renditions = $renditionService->getRenditions();
        $cacheService->save($cacheKey, $renditions);
    }
    if (!array_key_exists($params['rendition'], $renditions)) {
        throw new \InvalidArgumentException("Unknown rendition");
    }
    $article = $smarty->getTemplateVars('gimme')->article;
    if (!$article) {
        throw new \RuntimeException("Not in article context.");
    }
    $articleRenditions = $article->getRenditions();
    $articleRendition = $articleRenditions[$renditions[$params['rendition']]];
    if ($articleRendition === null) {
        $smarty->assign('image', false);
        $repeat = false;
        return;
    }
    $image = null;
    if (array_key_exists('width', $params) && array_key_exists('height', $params)) {
        $image = $renditionService->getArticleRenditionImage($article->number, $params['rendition'], $params['width'], $params['height']);
    } else {
        $image = $renditionService->getArticleRenditionImage($article->number, $params['rendition']);
    }
    $imageService = \Zend_Registry::get('container')->getService('image');
    $preferencesService = \Zend_Registry::get('container')->getService('preferences');
    $caption = $imageService->getCaption($articleRendition->getImage(), $article->number, $article->language->number);
    if ($preferencesService->get('MediaRichTextCaptions', 'N') == 'N') {
        $caption = MetaDbObject::htmlFilter($caption);
    }
    $smarty->assign('image', (object) array('src' => \Zend_Registry::get('view')->url(array('src' => $image['src']), 'image', true, false), 'width' => $image['width'], 'height' => $image['height'], 'caption' => $caption, 'description' => $articleRendition->getImage()->getDescription(), 'photographer' => $articleRendition->getImage()->getPhotographer(), 'original' => $image['original']));
}
示例#10
0
/**
 * Display page section header and footer only if content is present
 * This helps to avoid using redundant if's
 *
 * @param array $params
 * @param Smarty $smarty
 * @param $repeat
 *
 * <code>
 *	{sect}
 *		{header}
 *			Section header
 *		{/header}
 *		{content}
 *			Section content
 *		{/content}
 *		{footer}
 *			Section footer
 *		{/footer}
 *  {/sect}
 * </code>
 *
 * @return string Section HTML code
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_block_sect($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    $counter = $smarty->getTemplateVars('sectCounter');
    if ($repeat) {
        $counter++;
        $smarty->assign('sectCounter', $counter);
        $sections = $smarty->getTemplateVars('sect');
        $sections[$counter] = array('header' => '', 'content' => '', 'footer' => '');
        $smarty->assign('sect', $sections);
    } else {
        $blocks = $smarty->getTemplateVars('sect');
        $blocks = $blocks[$counter];
        $counter--;
        $smarty->assign('sectCounter', $counter);
        if (trim($blocks['content'])) {
            return $blocks['header'] . $blocks['content'] . $blocks['footer'];
        }
    }
}
示例#11
0
function smarty_function_numberDecimal(array $params, Smarty_Internal_Template $template)
{
    $value = $params['value'];
    if (!is_numeric($value)) {
        throw new CM_Exception_Invalid('Invalid non-numeric value');
    }
    /** @var CM_Frontend_Render $render */
    $render = $template->getTemplateVars('render');
    $formatter = new NumberFormatter($render->getLocale(), NumberFormatter::DECIMAL);
    return $formatter->format($value);
}
示例#12
0
/**
 * Form field row
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_label($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        $class = $smarty->getTemplateVars('last_fieldType') . ' ' . $params['class'];
        if (strpos($class, 'checkbox') === false) {
            $class = 'control-label col-lg-2 ' . $class;
        }
        $for = empty($params['for']) ? '' : ' for="' . $params['for'] . '"';
        $content = '<label class="' . $class . '"' . $for . '>' . $content . '</label>';
        return $content;
    }
}
示例#13
0
function smarty_function_chess_fugure($params, Smarty_Internal_Template &$template)
{
    // Постановка фигуры на доску
    $x = $params['x'];
    $y = $params['y'];
    $value = '';
    $figure = '';
    $data = array();
    $class = array();
    if ($y == 0 || $y == 9) {
        switch ($x) {
            case 1:
                $value = 'A';
                break;
            case 2:
                $value = 'B';
                break;
            case 3:
                $value = 'C';
                break;
            case 4:
                $value = 'D';
                break;
            case 5:
                $value = 'E';
                break;
            case 6:
                $value = 'F';
                break;
            case 7:
                $value = 'G';
                break;
            case 8:
                $value = 'H';
                break;
        }
    } else {
        if ($x == 0 || $x == 9) {
            $value = $y;
        } else {
            $class[] = ($x + $y) % 2 == 0 ? 'even' : 'odd';
            $figs = $template->getTemplateVars('figures');
            $pos = $x . $y;
            //Позиция фигуры, например a6
            if (is_array($figs) && array_key_exists($pos, $figs)) {
                $figure = $figs[$pos];
                $value = "<span class=\"{$figure}\"></span>";
            }
        }
    }
    return PsHtml::html2('td', array('class' => $class), $value);
}
示例#14
0
/**
 * Smarty block plugin, for generating page menus
 *
 * @param array $params
 * @param Smarty $smarty
 * @param $repeat
 *
 * <code>
 *	{pageMenu id="menu"}
 *		{menuItem}
 *			{menuCaption}Click Me{/menuCaption}
 *			{menuAction}http://click.me.com{/menuAction}
 *		{/menuItem}
 *		{menuItem}
 *			{menuCaption}Another menu item{/menuCaption}
 *			{pageAction}alert('Somebody clicked on me too!'){/menuAction}
 *		{/menuItem}
 *  {/pageMenu}
 * </code>
 *
 * @return string Menu HTML code
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_block_pageMenu($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if ($repeat) {
        $smarty->clear_assign('pageMenuItems');
    } else {
        $items = $smarty->getTemplateVars('pageMenuItems');
        $menuDiv = new HtmlElement('div');
        $menuDiv->setAttribute('id', $params['id']);
        $menuDiv->setAttribute('tabIndex', 1);
        $menuDiv->setContent(implode(' | ', $items));
        return $menuDiv->render();
    }
}
/**
 * PixelManager CMS (Community Edition)
 * Copyright (C) 2016 PixelProduction (http://www.pixelproduction.de)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
function smarty_function_getdatatablesomerows($params, Smarty_Internal_Template $template)
{
    if (!isset($params['class']) || !isset($params['var']) || !isset($params['rows'])) {
        return;
    }
    if (isset($params['page'])) {
        $page_id = $params['page'];
    } else {
        $page_id = $template->getTemplateVars('pageId');
    }
    if (isset($params['language'])) {
        $language_id = $params['language'];
    } else {
        $language_id = $template->getTemplateVars('languageId');
        if ($language_id === null) {
            $language_id = Config::get()->languages->standard;
        }
    }
    // Sicherstellen, dass $id_list auch wirklich ein Array ist
    // es ist auch möglich, einen kommaseparierten String zu übergeben
    $id_list = $params['rows'];
    if (!is_array($id_list)) {
        if (is_numeric($id_list)) {
            $id_list = array(intval($id_list));
        } else {
            $id_list = strval($id_list);
            $id_list = explode(',', $id_list);
            if (count($id_list) > 0) {
                foreach ($id_list as &$row_id) {
                    $row_id = intval(trim($row_id));
                }
            }
        }
    }
    $data_table = new $params['class']();
    $data = $data_table->getSomeRowsForFrontend($id_list, $page_id, $language_id);
    $template->assign($params['var'], $data);
}
示例#16
0
function smarty_function_load(array $params, Smarty_Internal_Template $template)
{
    /** @var CM_Frontend_Render $render */
    $render = $template->smarty->getTemplateVars('render');
    $namespace = isset($params['namespace']) ? $params['namespace'] : null;
    $parse = isset($params['parse']) ? (bool) $params['parse'] : true;
    if ($parse) {
        $tplPath = $render->getLayoutPath($params['file'], $namespace);
        $params = array_merge($template->getTemplateVars(), $params);
        return $render->fetchTemplate($tplPath, $params);
    } else {
        $tplPath = $render->getLayoutPath($params['file'], $namespace, null, true);
        $file = new CM_File($tplPath);
        return $file->read();
    }
}
示例#17
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_uniqid($params, Smarty_Internal_Template $smarty)
{
    if (isset($params['last'])) {
        return $smarty->getTemplateVars('lastUniqId');
    } else {
        // start with a letter for XHTML id attribute value compatibility
        $id = 'a' . uniqid();
        $smarty->assign('lastUniqId', $id);
        if (isset($params['assign'])) {
            $smarty->assign($params['assign'], $id);
            if (!empty($params['noecho'])) {
                return '';
            }
        }
        return $id;
    }
}
/**
 * @param $sSource
 * @param Smarty_Internal_Template $oTemplate
 * @return mixed
 */
function smarty_prefilter_tplhook($sSource, Smarty_Internal_Template $oTemplate)
{
    $aTplHooks = $oTemplate->getTemplateVars('aTplHooks');
    foreach ($aTplHooks as $oTplHook) {
        if ($oTplHook->isCurrentTemplate($oTemplate->smarty->_current_file) and $sSelector = $oTplHook->GetSelector()) {
            $sTplCode = $oTplHook->Call();
            $doc = new DomFrag($sSource);
            $oElements = $doc->find($sSelector);
            if ($oElements->count()) {
                switch ($oTplHook->GetAction()) {
                    case 'prepend':
                        $oElements->prepend($sTplCode);
                        break;
                    case 'append':
                        $oElements->append($sTplCode);
                        break;
                    case 'before':
                        $oElements->before($sTplCode);
                        break;
                    case 'after':
                        $oElements->after($sTplCode);
                        break;
                    case 'wrap':
                        $oElements->wrap($sTplCode);
                        break;
                    case 'html':
                        $oElements->html($sTplCode);
                        break;
                    case 'text':
                        $oElements->text($sTplCode);
                        break;
                    default:
                        $oElements->replaceWith($sTplCode);
                }
            }
            $sSource = $doc->html();
            $doc->clear();
            unset($doc);
        }
    }
    if (Config::Get('plugin.aceadminpanel.smarty.options.mark_template')) {
        $sSource = _smarty_prefilter_tplhook_mark($sSource, $oTemplate);
    }
    return $sSource;
}
示例#19
0
/**
 * Smarty function to get a localized file type
 *
 * @author Christopher Han <*****@*****.**>
 * @copyright Copyright (c) 2012 Christopher Han
 * @package GitPHP
 * @subpackage Smarty
 *
 * @param array $params param array
 * @param Smarty_Internal_Template $template smarty template
 */
function smarty_function_localfiletype($params, Smarty_Internal_Template $template)
{
    if (empty($params['type'])) {
        trigger_error("localfiletype: missing 'type' parameter");
        return;
    }
    $type = $params['type'];
    $resource = $template->getTemplateVars('resource');
    $output = null;
    switch ($type) {
        case GitPHP_FilesystemObject::FileType:
            if ($resource) {
                $output = $resource->translate('file');
            } else {
                $output = 'file';
            }
            break;
        case GitPHP_FilesystemObject::SymlinkType:
            if ($resource) {
                $output = $resource->translate('symlink');
            } else {
                $output = 'symlink';
            }
            break;
        case GitPHP_FilesystemObject::DirectoryType:
            if ($resource) {
                $output = $resource->translate('directory');
            } else {
                $output = 'directory';
            }
            break;
        default:
            if ($resource) {
                $output = $resource->translate('unknown');
            } else {
                $output = 'unknown';
            }
            break;
    }
    if (!empty($params['assign'])) {
        $template->assign($params['assign'], $output);
    } else {
        return $output;
    }
}
示例#20
0
function smarty_function_viewTemplate(array $params, Smarty_Internal_Template $template)
{
    /** @var CM_Frontend_Render $render */
    $render = $template->smarty->getTemplateVars('render');
    $viewClassName = 'CM_View_Abstract';
    if (isset($params['view'])) {
        $viewClassName = $params['view'];
        unset($params['view']);
    }
    $viewResponse = $render->getGlobalResponse()->getClosestViewResponse($viewClassName);
    if (null === $viewResponse) {
        throw new CM_Exception_Invalid('Cannot find parent `CM_View_Abstract` view response.');
    }
    $tplName = (string) $params['name'];
    unset($params['name']);
    $variables = array_merge($template->getTemplateVars(), $params);
    return $render->fetchViewTemplate($viewResponse->getView(), $tplName, $variables);
}
 /**
  * Render and output the template (without using the compiler)
  *
  * @param  Smarty_Template_Source   $source    source object
  * @param  Smarty_Internal_Template $_template template object
  *
  * @return void
  * @throws SmartyException          if template cannot be loaded or allow_php_templates is disabled
  */
 public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
 {
     if (!$source->smarty->allow_php_templates) {
         throw new SmartyException("PHP templates are disabled");
     }
     if (!$source->exists) {
         throw new SmartyException("Unable to load template {$source->type} '{$source->name}'" . ($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : ''));
     }
     // prepare variables
     extract($_template->getTemplateVars());
     // include PHP template with short open tags enabled
     ini_set('short_open_tag', '1');
     /** @var Smarty_Internal_Template $_smarty_template
      * used in included file
      */
     $_smarty_template = $_template;
     include $source->filepath;
     ini_set('short_open_tag', $this->short_open_tag);
 }
 public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
 {
     $_smarty_template = $_template;
     if (!$source->smarty->allow_php_templates) {
         throw new SmartyException("PHP templates are disabled");
     }
     if (!$source->exists) {
         if ($_template->parent instanceof Smarty_Internal_Template) {
             $parent_resource = " in '{$_template->parent->template_resource}'";
         } else {
             $parent_resource = '';
         }
         throw new SmartyException("Unable to load template {$source->type} '{$source->name}'{$parent_resource}");
     }
     extract($_template->getTemplateVars());
     ini_set('short_open_tag', '1');
     include $source->filepath;
     ini_set('short_open_tag', $this->short_open_tag);
 }
示例#23
0
/**
 * Form field row
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_input($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    $formParams = $smarty->_tag_stack[0][1];
    if (!$repeat) {
        $formHandler = $formParams['handle'];
        $isRequired = $formHandler ? $formHandler->isRequired($params['name']) : false;
        $fieldType = $smarty->getTemplateVars('last_fieldType');
        if ($formHandler && $formHandler->getValidator()) {
            $err = $formHandler->getValidator()->getErrorList();
            $msg = empty($err[$params['name']]) ? '' : $err[$params['name']];
        } else {
            $msg = '';
        }
        if ('checkbox' == $fieldType) {
            preg_match('/<input(.*) \\/\\>(.*)\\<label(.*)\\>(.*)\\<\\/label\\>/msU', $content, $matches);
            if ($matches) {
                $content = '<label ' . $matches[3] . '><input ' . $matches[1] . ' /> ' . $matches[4] . '</label>';
            }
        }
        $name = $params['name'];
        $class = !empty($params['class']) ? ' ' . $params['class'] : ' ';
        unset($params['name'], $params['class']);
        $c = $content;
        $content = '<div class="row ' . ($msg ? 'has-error' : '') . ' name_' . $name . ' type_' . $fieldType . ' ' . ($isRequired ? ' required' : '') . $class . '"';
        foreach ($params as $n => $param) {
            $content .= ' ' . $n . '="' . $param . '"';
        }
        $content .= '>' . $c;
        foreach ($smarty->getFieldValidation($name, $formHandler) as $val) {
            $content .= '<div ng-show="isSubmitted && form.' . $name . '.$error.' . substr($val[0], 3) . '" class="text-danger">' . $val[1] . '</div>';
        }
        if ($msg) {
            $content .= '<div class="text-danger">' . $msg . '</div>';
        }
        $content .= '</div>';
        $smarty->assign('last_fieldType', '');
        $smarty->assign('input_name', '');
        return $content;
    } else {
        $smarty->assign('last_fieldType', '');
        $smarty->assign('input_name', $params['name']);
    }
}
示例#24
0
/**
 * Language forms
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_language($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    //$smarty = $smarty->smarty;
    $app = $smarty->smarty->getApplication();
    if (!$app->getLanguageSetArray()) {
        return false;
    }
    if ($repeat) {
        $app->languageBlock = $app->getLanguageSetArray();
        $smarty->assign('languageBlock', $app->languageBlock);
        $smarty->assign('lang', array_shift($app->languageBlock));
        $app->langHeadDisplayed = false;
        $user = SessionUser::getUser();
        foreach ($app->getLanguageSetArray() as $lang) {
            $userPref = $user->getPreference('tab_lang_' . $lang['ID']);
            $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false';
            $classNames[$lang['ID']] = $isHidden ? 'hidden' : '';
        }
        $app->langClassNames = $classNames;
    } else {
        if (!trim($content)) {
            $repeat = false;
            return false;
        }
        if ($app->languageBlock) {
            $repeat = true;
        }
        $contentLang = $smarty->getTemplateVars('lang');
        $content = '<tab class="lang_' . $contentLang['ID'] . '" heading="' . $contentLang['originalName'] . '">' . $content . '</tab>';
        if (!$app->langHeadDisplayed) {
            $smarty->assign('classNames', $app->langClassNames);
            $content = $smarty->fetch('block/backend/langFormHead.tpl') . $content;
            $app->langHeadDisplayed = true;
        }
        $smarty->assign('lang', array_shift($app->languageBlock));
        // form footer
        if (!$repeat) {
            $content .= $smarty->fetch('block/backend/langFormFoot.tpl');
        }
        return $content;
    }
}
示例#25
0
/**
 * Smarty function to wrap url builder
 *
 * @author Christopher Han <*****@*****.**>
 * @copyright Copyright (c) 2012 Christopher Han
 * @package GitPHP
 * @subpackage Smarty
 *
 * @param array $params parameter array
 * @param Smarty_Internal_Template $template smarty template
 * @return string url
 */
function smarty_function_geturl($params, Smarty_Internal_Template $template)
{
    $full = false;
    if (!empty($params['fullurl']) && $params['fullurl'] == true) {
        $full = true;
    }
    unset($params['fullurl']);
    $escape = true;
    if (isset($params['escape']) && $params['escape'] == false) {
        $escape = false;
    }
    unset($params['escape']);
    $router = $template->getTemplateVars('router');
    if (!$router) {
        trigger_error("geturl: missing router");
        return;
    }
    $finalurl = $router->GetUrl($params, $full);
    if ($escape) {
        $finalurl = htmlspecialchars($finalurl, ENT_COMPAT, 'UTF-8', false);
    }
    return $finalurl;
}
/**
 * @todo Finish documentation of smarty_function_widgetarea
 * @param array  $params  Associative (and/or indexed) array of smarty parameters passed in from the template
 * @param Smarty_Internal_Template $smarty  Parent Smarty template object
 *
 * @return string|void
 */
function smarty_function_widgetarea($params, $smarty) {
	// Get all widgets set to load in this area.

	$body     = '';
	$baseurl  = PageRequest::GetSystemRequest()->getBaseURL();
	$template = $smarty->template_resource;
	$tmpl     = $smarty->getTemplateVars('__core_template');
	$topview  = ($tmpl instanceof \Core\Templates\TemplateInterface) ? $tmpl->getView() : \Core\view();

	$parameters  = [];
	$name        = null;
	$installable = null;
	$assign      = null;
	foreach($params as $k => $v){
		switch($k){
			case 'name':
				$name = $v;
				break;
			case 'installable':
				$installable = $v;
				break;
			case 'assign':
				$assign = $v;
				break;
			default:
				$parameters[$k] = $v;
				break;
		}
	}

	// I need to resolve the page template down to the base version in order for the lookup to work.
	foreach(Core\Templates\Template::GetPaths() as $base){
		if(strpos($template, $base) === 0){
			$template = substr($template, strlen($base));
			break;
		}
	}

	// Given support for page-level widgets, this logic gets slightly more difficult...
	$factory = new ModelFactory('WidgetInstanceModel');
	$factory->order('weight');
	if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled()){
		$factory->whereGroup('or', ['site = -1', 'site = ' . MultiSiteHelper::GetCurrentSiteID()]);
	}

	$subwhere = new Core\Datamodel\DatasetWhereClause();
	$subwhere->setSeparator('OR');

	// First, the skin-level where clause.
	$skinwhere = new Core\Datamodel\DatasetWhereClause();
	$skinwhere->setSeparator('AND');
	$skinwhere->addWhere('template = ' . $template);
	$skinwhere->addWhere('widgetarea = ' . $name);
	$subwhere->addWhere($skinwhere);

	// And second, the page-level where clause.
	if($baseurl){
		$pagewhere = new Core\Datamodel\DatasetWhereClause();
		$pagewhere->setSeparator('AND');
		$pagewhere->addWhere('page_baseurl = ' . $baseurl);
		$pagewhere->addWhere('widgetarea = ' . $name);
		$subwhere->addWhere($pagewhere);
	}

	$factory->where($subwhere);


	$widgetcount = 0;
	try{
		$widgets = $factory->get();
	}
	catch(Exception $e){
		if(DEVELOPMENT_MODE){
			$body .= '<p class="message-error">Exception while trying to load widget area ' . $name . '!</p>';
			$body .= '<pre class="xdebug-var-dump">' . $e->getMessage() . '</pre>';
		}
		else{
			\Core\ErrorManagement\exception_handler($e, false);
		}
		$widgets = [];
		++$widgetcount;
	}


	foreach ($widgets as $wi) {
		/** @var $wi WidgetInstanceModel */
		// User cannot access this widget? Don't display it...
		if(!\Core\user()){
			continue;
		}
		if (!\Core\user()->checkAccess($wi->get('access'))){
			continue;
		}

		if($installable){
			$wi->set('installable', $installable);
		}
		$view = $wi->execute($parameters);

		// Some widgets may return simply a blank string.  Those should just be ignored.
		if ($view == ''){
			continue;
		}

		// If it's just a string, return that.
		if (is_string($view)) {
			$contents = $view;
		}
		elseif($view->error == View::ERROR_NOERROR){
			// Ensure that the widget's View knows it's linked to a parent!
			$view->parent = $topview;

			$contents = $view->fetch();
		}
		else{
			$contents = 'Error displaying widget [' . $wi->get('baseurl') . '], returned error [' . $view->error . ']';
		}
		++$widgetcount;
		
		// Does this widget have controls attached to it?
		$widget = $wi->getWidget();
		if($widget->controls instanceof ViewControls && $widget->controls->hasLinks()){
			$contents = '<div class="widget-controls-wrapper">' .
				'<menu id="widget-controls-' . $wi->get('id') . '">' . 
				$widget->controls->fetch() . 
				'</menu>' . 
				'</div>' .
				$contents;
		}

		$body .= '<div class="widget">' . $contents . '</div>';
	}

	// Do some sanitizing for the css data
	$class = 'widgetarea-' . strtolower(str_replace(' ', '', $name));

	$html = '<div class="widgetarea ' . $class . '" widgetarea="' . $name . '">' . $body . '</div>';

	// No widgets, no inner content!
	if($widgetcount == 0){
		$html = '';
	}

	if($assign){
		$smarty->assign($assign, $html);
	}
	else{
		return $html;
	}
}
示例#27
0
 /**
  * Process {pageloop rel="loopname"} ... {/pageloop} block
  *
  * @param  array                     $params   loop parameters
  * @param  string                    $content  loop text content
  * @param  \Smarty_Internal_Template $template the Smarty object
  * @param  boolean                   $repeat   repeat indicator (see Smarty doc.)
  * @return string                    the loop output
  * @throws \InvalidArgumentException
  */
 public function theliaPageLoop($params, $content, $template, &$repeat)
 {
     $loopName = $this->getParam($params, 'rel');
     if (null == $loopName) {
         throw new \InvalidArgumentException($this->translator->trans("Missing 'rel' parameter in page loop"));
     }
     // Find pagination
     $pagination = self::getPagination($loopName);
     if ($pagination === null || $pagination->getNbResults() == 0) {
         // No need to paginate
         return '';
     }
     $startPage = intval($this->getParam($params, 'start-page', 1));
     $displayedPageCount = intval($this->getParam($params, 'limit', 10));
     if (intval($displayedPageCount) == 0) {
         $displayedPageCount = PHP_INT_MAX;
     }
     $totalPageCount = $pagination->getLastPage();
     if ($content === null) {
         // The current page
         $currentPage = $pagination->getPage();
         // Get the start page.
         if ($totalPageCount > $displayedPageCount) {
             $startPage = $currentPage - round($displayedPageCount / 2);
             if ($startPage < 0) {
                 $startPage = 1;
             }
         }
         // This is the iterative page number, the one we're going to increment in this loop
         $iterationPage = $startPage;
         // The last displayed page number
         $endPage = $startPage + $displayedPageCount - 1;
         if ($endPage > $totalPageCount) {
             $endPage = $totalPageCount;
         }
         // The first displayed page number
         $template->assign('START', $startPage);
         // The previous page number
         $template->assign('PREV', $currentPage > 1 ? $currentPage - 1 : $currentPage);
         // The next page number
         $template->assign('NEXT', $currentPage < $totalPageCount ? $currentPage + 1 : $totalPageCount);
         // The last displayed page number
         $template->assign('END', $endPage);
         // The overall last page
         $template->assign('LAST', $totalPageCount);
     } else {
         $iterationPage = $template->getTemplateVars('PAGE');
         $iterationPage++;
     }
     if ($iterationPage <= $template->getTemplateVars('END')) {
         // The iterative page number
         $template->assign('PAGE', $iterationPage);
         // The overall current page number
         $template->assign('CURRENT', $pagination->getPage());
         $repeat = true;
     }
     if ($content !== null) {
         return $content;
     }
     return '';
 }
示例#28
0
/**
 * Renders text field
 *
 * If you wish to use autocomplete on a text field an additional parameter needs to be passed:
 *
 * <code>
 *	  autocomplete="controller=somecontroller field=fieldname"
 * </code>
 *
 * The controller needs to implement an autoComplete method, which must return the AutoCompleteResponse
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty.form
 * @author Integry Systems
 */
function smarty_function_textfield($params, Smarty_Internal_Template $smarty)
{
    if (empty($params['name'])) {
        $params['name'] = $smarty->getTemplateVars('input_name');
    }
    $smarty->assign('last_fieldType', 'textfield');
    $formParams = $smarty->_tag_stack[0][1];
    $formHandler = $formParams['handle'];
    $fieldName = $params['name'];
    if (!$formHandler instanceof Form) {
        throw new HelperException('Element must be placed in {form} block');
    }
    if (!isset($params['type'])) {
        $params['type'] = 'text';
    }
    if (isset($params['ng_model'])) {
        $params['ng-model'] = $params['ng_model'];
        unset($params['ng_model']);
    } else {
        if (!empty($formParams['model'])) {
            $params['ng-model'] = $formParams['model'] . '.' . $params['name'];
        }
    }
    $params = $smarty->applyFieldValidation($params, $formHandler);
    // Check permissions
    if ($formParams['readonly']) {
        $params['readonly'] = 'readonly';
    }
    $value = array_pop(array_filter(array(isset($params['value']) ? $params['value'] : '', isset($params['default']) ? $params['default'] : '', $formHandler->get($fieldName))));
    unset($params['value'], $params['default']);
    if (isset($params['autocomplete']) && $params['autocomplete'] != 'off' && empty($params['id'])) {
        $params['id'] = uniqid();
    }
    if (!empty($params['placeholder'])) {
        $params['placeholder'] = $smarty->getApplication()->translate($params['placeholder']);
    }
    if (isset($params['autocomplete']) && $params['autocomplete'] != 'off') {
        $autocomplete = $params['autocomplete'];
        $params['autocomplete'] = 'off';
    }
    $content = '<input';
    $content = $smarty->appendParams($content, $params);
    $content .= ' value="' . htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '"';
    $content .= '/>';
    $content = $smarty->formatControl($content, $params);
    if (!empty($autocomplete)) {
        $acparams = array();
        foreach (explode(' ', $params['autocomplete']) as $param) {
            list($p, $v) = explode('=', $param, 2);
            $acparams[$p] = $v;
        }
        $url = $smarty->getApplication()->getRouter()->createURL(array('controller' => $acparams['controller'], 'action' => 'autoComplete', 'query' => 'field=' . $acparams['field']), true);
        if (empty($acparams['field'])) {
            $acparams['field'] = 'query';
        }
        /*
        $content .= '<script type="text/javascript">
        				jQuery("#' . $params['id'] . '").typeahead({
        						source: function (query, process) {
        							return jQuery.get("' . $url . '", { ' . $acparams['field'] . ': query }, function (data) {
        								return process(jQuery.parseJSON(data));
        							});
        						}});
        			</script>';
        */
    }
    return $content;
}
示例#29
0
/**
 * Smarty function to turn an age in seconds into a human-readable string
 *
 * @author Christopher Han <*****@*****.**>
 * @copyright Copyright (c) 2010 Christopher Han
 * @package GitPHP
 * @subpackage Smarty
 *
 * @param array $params parameter array
 * @param Smarty_Internal_Template $template smarty template
 * @return string human readable string
 */
function smarty_function_agestring($params, Smarty_Internal_Template $template)
{
    if (empty($params['age'])) {
        trigger_error("agestring: missing 'age' parameter");
        return;
    }
    $age = $params['age'];
    $resource = $template->getTemplateVars('resource');
    $output = null;
    if ($age > 60 * 60 * 24 * 365 * 2) {
        $years = (int) ($age / 60 / 60 / 24 / 365);
        if ($resource) {
            $output = sprintf($resource->ngettext('%1$d year ago', '%1$d years ago', $years), $years);
        } else {
            $output = sprintf($years == 1 ? '%1$d year ago' : '%1$d years ago', $years);
        }
    } else {
        if ($age > 60 * 60 * 24 * (365 / 12) * 2) {
            $months = (int) ($age / 60 / 60 / 24 / (365 / 12));
            if ($resource) {
                $output = sprintf($resource->ngettext('%1$d month ago', '%1$d months ago', $months), $months);
            } else {
                $output = sprintf($months == 1 ? '%1$d month ago' : '%1$d months ago', $months);
            }
        } else {
            if ($age > 60 * 60 * 24 * 7 * 2) {
                $weeks = (int) ($age / 60 / 60 / 24 / 7);
                if ($resource) {
                    $output = sprintf($resource->ngettext('%1$d week ago', '%1$d weeks ago', $weeks), $weeks);
                } else {
                    $output = sprintf($weeks == 1 ? '%1$d week ago' : '%1$d weeks ago', $weeks);
                }
            } else {
                if ($age > 60 * 60 * 24 * 2) {
                    $days = (int) ($age / 60 / 60 / 24);
                    if ($resource) {
                        $output = sprintf($resource->ngettext('%1$d day ago', '%1$d days ago', $days), $days);
                    } else {
                        $output = sprintf($days == 1 ? '%1$d day ago' : '%1$d days ago', $days);
                    }
                } else {
                    if ($age > 60 * 60 * 2) {
                        $hours = (int) ($age / 60 / 60);
                        if ($resource) {
                            $output = sprintf($resource->ngettext('%1$d hour ago', '%1$d hours ago', $hours), $hours);
                        } else {
                            $output = sprintf($hours == 1 ? '%1$d hour ago' : '%1$d hours ago', $hours);
                        }
                    } else {
                        if ($age > 60 * 2) {
                            $min = (int) ($age / 60);
                            if ($resource) {
                                $output = sprintf($resource->ngettext('%1$d min ago', '%1$d min ago', $min), $min);
                            } else {
                                $output = sprintf($min == 1 ? '%1$d min ago' : '%1$d min ago', $min);
                            }
                        } else {
                            if ($age > 2) {
                                $sec = (int) $age;
                                if ($resource) {
                                    $output = sprintf($resource->ngettext('%1$d sec ago', '%1$d sec ago', $sec), $sec);
                                } else {
                                    $output = sprintf($sec == 1 ? '%1$d sec ago' : '%1$d sec ago', $sec);
                                }
                            } else {
                                if ($resource) {
                                    $output = $resource->translate('right now');
                                } else {
                                    $output = 'right now';
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!empty($params['assign'])) {
        $template->assign($params['assign'], $output);
    } else {
        return $output;
    }
}
 /**
  * Render and output the template (without using the compiler)
  *
  * @param Smarty_Template_Source $source source object
  * @param Smarty_Internal_Template $_template template object
  * @return void
  * @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
  */
 public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
 {
     $_smarty_template = $_template;
     if (!$source->smarty->allow_php_templates) {
         throw new SmartyException("PHP templates are disabled");
     }
     if (!$source->exists) {
         throw new SmartyException("Unable to load template \"{$source->type} : {$source->name}\"");
     }
     // prepare variables
     extract($_template->getTemplateVars());
     // include PHP template with short open tags enabled
     ini_set('short_open_tag', '1');
     include $source->filepath;
     ini_set('short_open_tag', $this->short_open_tag);
 }