예제 #1
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, LiveCartSmarty $smarty, &$repeat)
{
    if ($repeat) {
        $smarty->clear_assign('menuCaption');
        $smarty->clear_assign('menuAction');
        $smarty->clear_assign('menuPageAction');
    } else {
        $item = new HtmlElement('a');
        if ($smarty->get_template_vars('menuAction')) {
            $href = $smarty->get_template_vars('menuAction');
        } else {
            if ($smarty->get_template_vars('menuPageAction')) {
                $onClick = $smarty->get_template_vars('menuPageAction');
                $href = '#';
                $item->setAttribute('onClick', $onClick . '; return false;');
            }
        }
        $item->setAttribute('href', $href);
        // EXPERIMENTAL - set access key for menu item
        $caption = $smarty->get_template_vars('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());
    }
}
예제 #2
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_content($params, $content, LiveCartSmarty $smarty, &$repeat)
{
    if (!$repeat) {
        $counter = $smarty->get_template_vars('sectCounter');
        $blocks = $smarty->get_template_vars('sect');
        $blocks[$counter]['content'] = $content;
        $smarty->assign('sect', $blocks);
    }
}
예제 #3
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, LiveCartSmarty $smarty, &$repeat)
{
    $counter = $smarty->get_template_vars('sectCounter');
    if ($repeat) {
        $counter++;
        $smarty->assign('sectCounter', $counter);
        $sections = $smarty->get_template_vars('sect');
        $sections[$counter] = array('header' => '', 'content' => '', 'footer' => '');
        $smarty->assign('sect', $sections);
    } else {
        $blocks = $smarty->get_template_vars('sect');
        $blocks = $blocks[$counter];
        $counter--;
        $smarty->assign('sectCounter', $counter);
        if (trim($blocks['content'])) {
            return $blocks['header'] . $blocks['content'] . $blocks['footer'];
        }
    }
}
예제 #4
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, LiveCartSmarty $smarty, &$repeat)
{
    if ($repeat) {
        $smarty->clear_assign('pageMenuItems');
    } else {
        $items = $smarty->get_template_vars('pageMenuItems');
        $menuDiv = new HtmlElement('div');
        $menuDiv->setAttribute('id', $params['id']);
        $menuDiv->setAttribute('tabIndex', 1);
        $menuDiv->setContent(implode(' | ', $items));
        return $menuDiv->render();
    }
}
예제 #5
0
/**
 * ...
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_uniqid($params, LiveCartSmarty $smarty)
{
    if (isset($params['last'])) {
        return $smarty->get_template_vars('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;
    }
}
예제 #6
0
/**
 * Language forms
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_language($params, $content, LiveCartSmarty $smarty, &$repeat)
{
    if (!$smarty->getApplication()->getLanguageSetArray()) {
        return false;
    }
    if ($repeat) {
        $smarty->languageBlock = $smarty->getApplication()->getLanguageSetArray();
        $smarty->assign('languageBlock', $smarty->languageBlock);
        $smarty->assign('lang', array_shift($smarty->languageBlock));
        $smarty->langHeadDisplayed = false;
        $user = SessionUser::getUser();
        foreach ($smarty->getApplication()->getLanguageSetArray() as $lang) {
            $userPref = $user->getPreference('tab_lang_' . $lang['ID']);
            $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false';
            $classNames[$lang['ID']] = $isHidden ? 'hidden' : '';
        }
        $smarty->langClassNames = $classNames;
    } else {
        if (!trim($content)) {
            $repeat = false;
            return false;
        }
        if ($smarty->languageBlock) {
            $repeat = true;
        }
        $contentLang = $smarty->get_template_vars('lang');
        $content = '<div class="languageFormContainer languageFormContainer_' . $contentLang['ID'] . ' ' . $smarty->langClassNames[$contentLang['ID']] . '">' . $content . '</div>';
        if (!$smarty->langHeadDisplayed) {
            $smarty->assign('langFormId', 'langForm_' . uniqid());
            $smarty->assign('classNames', $smarty->langClassNames);
            $content = $smarty->fetch('block/backend/langFormHead.tpl') . $content;
            $smarty->langHeadDisplayed = true;
        }
        $smarty->assign('lang', array_shift($smarty->languageBlock));
        // form footer
        if (!$repeat) {
            $content .= $smarty->fetch('block/backend/langFormFoot.tpl');
        }
        return $content;
    }
}