Пример #1
0
/**
 * This method will get a module/action or module template result
 * 
 * @param array $params     
 * @param Smarty $smarty 
 */
function smarty_function_widget($params, &$smarty)
{
    if (!isset($params['module']) || !isset($params['action']) && !isset($params['template']) || isset($params['action']) && isset($params['template'])) {
        throw new SmartyException('{widget} : module and action (or template) parameters must be defined');
    }
    $args = array();
    if (count($params) > 2) {
        foreach ($params as $k => $v) {
            if ($k !== 'module' && $k !== 'action' && $k !== 'template') {
                $args[$k] = $v;
            }
        }
    }
    if (isset($params['action'])) {
        Controller::getInstance()->setModule($params['module'])->setAction($params['action'])->setArgs(array($args))->dispatch();
    } else {
        if ($file = get_module_file($params['module'], 'template/' . $params['template'], true)) {
            $tpl = Template::getInstance($file);
            foreach ($smarty->tpl_vars as $k => $v) {
                if ($k !== 'SCRIPT_NAME' && $k !== 'smarty' && !isset($args[$k])) {
                    $args[$k] = $v->value;
                }
            }
            if (empty($args)) {
                return $tpl->get();
            }
            foreach ($args as $name => $value) {
                $tpl->assign($name, $value);
            }
            return $tpl->get();
        }
    }
}
Пример #2
0
/**
 * This method will translate or create an enter in the module xliff locale file
 * 
 * @param array $params         An array of parameters to give to i18n::translate()
 * @param string $content       The string to translate {t}...content...{/t}
 * @param Smarty $smarty        The current Smarty instance
 * @param boolean $repeat       Are we in the end of {t} tag
 * @return string               The translated string, else the original string
 */
function smarty_block_t($params, $content, &$smarty, &$repeat)
{
    if ($repeat == false) {
        // we get the template locale if setted by {setLocale} tag
        $srcLocale = isset($smarty->tpl_vars['TPL_LOCALE']) ? $smarty->tpl_vars['TPL_LOCALE']->value : i18n::getDefaultLocale();
        // if template locale is equal to current locale we don't need to translate
        if ($srcLocale === i18n::getLocale()) {
            return i18n::replaceArgs($content, $params);
        }
        // we get the template path
        $path = explode(DS, str_replace(APP_DIR . DS, '', $smarty->template_resource));
        // module var has been setted in smarty
        if (isset($smarty->smarty->module)) {
            $isModule = true;
            $module = $smarty->smarty->module;
        } else {
            $isModule = array_search('module', $path);
            if ($isModule !== false) {
                $module = $path[$isModule + 1];
            }
        }
        // we are in a module, we can translate
        if ($isModule !== false) {
            // Get locale file with full locale code (ex : fr_CA) for overloading
            if ($file = get_module_file($module, '/i18n/templates.' . $srcLocale . '.xml')) {
                $str = I18n::t($file, $content, $params, $srcLang, end($path));
                if ($str !== $string) {
                    return $str;
                }
                // There is a specific translation for full locale code, return
            }
            // get the lang code
            preg_match('/^([a-z]{2,3})[_-]([A-Z]{2})$/', $srcLocale, $m);
            $srcLang = $m[0];
            // If default lang is equal to the current lang : return
            if ($srcLang == i18n::getLang()) {
                return i18n::replaceArgs($content, $params);
            }
            // Get locale file with only lang code (ex : fr) or create it
            $file = get_module_file($module, '/i18n/templates.' . I18n::getLang() . '.xml', false);
            return I18n::t($file, $content, $params, $srcLang, end($path));
        }
        return i18n::replaceArgs($content, $params);
    }
}
Пример #3
0
add_apage(array('title' => 'Календарь событий', 'code' => 'calendar_event', 'rule' => 'public', 'priority' => 30, 'category' => 'public', 'function' => function () {
    get_module_template('public.php');
}));
add_action(array('title' => 'Календарь событий', 'code' => 'remote_calendar_event', 'rule' => 'public', 'category' => 'public', 'function' => function ($params) {
    $_GET['month'] = isset($params['month']) ? $params['month'] : $_GET['month'];
    $_GET['year'] = isset($params['year']) ? $params['year'] : $_GET['year'];
    show_apage('calendar_event');
}));
add_apage(array('title' => 'Календарь событий для обмена', 'code' => 'calendar_event_json', 'rule' => 'public', 'priority' => 30, 'category' => 'public', 'skelet' => false, 'function' => function () {
    show_calendar_events(array('links' => false, 'show' => 'json'));
}));
add_apage(array('title' => 'Добавить событие', 'category' => 'admin', 'code' => 'calendar_event_add', 'parent' => 'calendar_event', 'rule' => 'calendar_event_admin', 'priority' => -1, 'function' => function () {
    get_module_template('add.php');
}));
add_script(array('type' => 'script', 'link' => get_module_file('js/jquery.datetimepicker.min.js'), 'priority' => '40', 'auto' => 'calendar_event_add', 'category' => 'admin', 'zone' => 'footer', 'code' => 'datetimepicker_js'));
add_script(array('type' => 'style', 'link' => get_module_file('js/jquery.datetimepicker.min.css'), 'priority' => '35', 'auto' => 'calendar_event_add', 'category' => 'admin', 'zone' => 'footer', 'code' => 'datetimepicker_css'));
add_script(array('type' => 'script', 'priority' => '49', 'auto' => 'calendar_event_add', 'category' => 'admin', 'zone' => 'footer', 'link' => 'http://momentjs.com/downloads/moment.min.js', 'code' => 'moment_js'));
add_script(array('type' => 'script', 'priority' => '50', 'auto' => 'calendar_event_add', 'category' => 'admin', 'zone' => 'footer', 'code' => 'datetimepicker_doit', 'function' => function () {
    $option = get_option('calendar_events_range');
    ?>
        <script>
            $(function(){
                var time_start, time_end, min = null, max = null;
                var ID = ($('[name="event_ID"]:first-of-type').length) ? $('[name="event_ID"]:first-of-type').val() : '';

                function check_calendar_events_near() {
                    $('.datepicker-error').remove();
                    if($('.table_show table').length) {
                        $.detmessage('Данное событие пересекается с другими, будьте внимательны!', 'Внимание!', 'warning datepicker-error');
                    }
                }