Exemplo n.º 1
0
/**
 * Smarty function to display the category menu for admin links. This also adds the
 * navtabs.css to the page vars array for stylesheets.
 *
 * Admin
 * {admincategorymenu}
 *
 * @see          function.admincategorymenu.php::smarty_function_admincategorymenu()
 * @param        array       $params      All attributes passed to this function from the template
 * @param        \Zikula_View $view        Reference to the Zikula_View object
 * @return       string      the results of the module function
 */
function smarty_function_admincategorymenu($params, \Zikula_View $view)
{
    PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet('ZikulaAdminModule'));
    $modinfo = ModUtil::getInfoFromName($view->getTplVar('toplevelmodule'));
    $acid = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getmodcategory', array('mid' => $modinfo['id']));
    $path = array('_controller' => 'ZikulaAdminModule:Admin:categorymenu', 'acid' => $acid);
    $subRequest = $view->getRequest()->duplicate(array(), null, $path);
    return $view->getContainer()->get('http_kernel')->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST)->getContent();
}
Exemplo n.º 2
0
/**
 * Smarty function to close the admin container.
 *
 * Admin
 * {adminfooter}
 *
 * @see          function.adminfooter.php::smarty_function_adminfooter()
 * @param        array       $params      All attributes passed to this function from the template
 * @param        \Zikula_View $view        Reference to the Zikula_View object
 * @return       string      the results of the module function
 */
function smarty_function_adminfooter($params, \Zikula_View $view)
{
    // check to make sure adminmodule is available and route is available
    $router = $view->getContainer()->get('router');
    try {
        $router->generate('zikulaadminmodule_admin_adminfooter');
    } catch (\Symfony\Component\Routing\Exception\RouteNotFoundException $e) {
        return '';
    }
    $path = array('_controller' => 'ZikulaAdminModule:Admin:adminfooter');
    $subRequest = $view->getRequest()->duplicate(array(), null, $path);
    return $view->getContainer()->get('http_kernel')->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST)->getContent();
}
Exemplo n.º 3
0
/**
 * Smarty function to close the admin container.
 *
 * Admin
 * {adminfooter}
 *
 * @see          function.adminfooter.php::smarty_function_adminfooter()
 * @param        array       $params      All attributes passed to this function from the template
 * @param        \Zikula_View $view        Reference to the Zikula_View object
 * @return       string      the results of the module function
 */
function smarty_function_adminfooter($params, \Zikula_View $view)
{
    // check to make sure adminmodule is available and route is available
    $router = $view->getContainer()->get('router');
    $routeCollection = $router instanceof \JMS\I18nRoutingBundle\Router\I18nRouter ? $router->getOriginalRouteCollection() : $router->getRouteCollection();
    $route = $routeCollection->get('zikulaadminmodule_admin_adminfooter');
    if (isset($route)) {
        $path = array('_controller' => 'ZikulaAdminModule:Admin:adminfooter');
        $subRequest = $view->getRequest()->duplicate(array(), null, $path);
        return $view->getContainer()->get('http_kernel')->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST)->getContent();
    }
    return '';
}
Exemplo n.º 4
0
/**
 * Smarty function to open the admin container.
 *
 * Admin
 * {adminheader}
 *
 * @see          function.adminheader.php::smarty_function_adminheader()
 * @param        array       $params      All attributes passed to this function from the template
 * @param        \Zikula_View $view        Reference to the Zikula_View object
 * @return       string      the results of the module function
 */
function smarty_function_adminheader($params, $view)
{
    // check to make sure adminmodule is available and route is available
    $router = $view->getContainer()->get('router');
    try {
        $router->generate('zikulaadminmodule_admin_adminheader');
    } catch (\Symfony\Component\Routing\Exception\RouteNotFoundException $e) {
        $url = $view->getContainer()->get('router')->generate('zikularoutesmodule_route_reload', array('lct' => 'admin', 'confirm' => 1));
        return '<div class="alert alert-danger"><i class="fa fa-exclamation-triangle fa-2x"></i> ' . __f('Routes must be reloaded. Click %s to reload all routes.', "<a href='{$url}'>" . __('here') . '</a>') . '</div>';
    }
    $path = array('_controller' => 'ZikulaAdminModule:Admin:adminheader');
    $subRequest = $view->getRequest()->duplicate(array(), null, $path);
    return $view->getContainer()->get('http_kernel')->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST)->getContent();
}
/**
 * Smarty function to delete a session variable
 *
 * This function deletes a session-specific variable from the Zikula system.
 *
 *
 * Available parameters:
 *   - name:    The name of the session variable to delete
 *   - path:    The namespace.
 *   - assign:  If set, the result is assigned to the corresponding variable instead of printed out
 *
 * Example
 *   {sessiondelvar name='foobar'}
 *
 * @param  array       $params All attributes passed to this function from the template
 * @param  Zikula_View $view   Reference to the Smarty object
 * @param  string      $name   The name of the session variable to delete
 *
 * @return mixed
 */
function smarty_function_sessiondelvar($params, Zikula_View $view)
{
    $assign = isset($params['assign']) ? $params['assign'] : null;
    $name = isset($params['name']) ? $params['name'] : null;
    $path = isset($params['path']) ? $params['path'] : '/';
    if (!$name) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('sessiondelvar', 'name')));
        return false;
    }
    $result = $view->getRequest()->getSession()->del($name, $path);
    if ($assign) {
        $view->assign($assign, $result);
    } else {
        return $result;
    }
}
Exemplo n.º 6
0
/**
 * Zikula_View block to implement group checks in a template.
 *
 * Available attributes:
 *  - gid (numeric) The ID number of the group to be tested.
 *
 * Example:
 * <pre>
 * {checkgroup gid='1'}
 *   do some stuff now we have permission
 * {/checkgroup}
 * </pre>.
 *
 * @param array       $params  All attributes passed to this function from the template.
 * @param string      $content The content between the block tags.
 * @param Zikula_View $view    Reference to the {@link Zikula_View} object.
 *
 * @return string|boolean|void The content of the matching case.
 *                             If the user is a member of the group specified by the gid,
 *                             then the content contained in the block, otherwise null,
 *                             false on error.
 */
function smarty_block_checkgroup($params, $content, Zikula_View $view)
{
    // check if there is something between the tags
    if (is_null($content)) {
        return;
    }
    // check our input
    if (!isset($params['gid'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_block_checkgroup', 'component')));
        return false;
    }
    $uid = $view->getRequest()->getSession()->get('uid');
    if (empty($uid)) {
        return;
    }
    if (!ModUtil::apiFunc('GroupsModule', 'user', 'isgroupmember', array('uid' => $uid, 'gid' => $params['gid']))) {
        return;
    }
    return $content;
}
/**
 * FormUtil::getPassedValue().
 *
 * Available parameters:
 *   assign    The smarty variable to assign the retrieved value to.
 *   html      Wether or not to DataUtil::formatForDisplayHTML'ize the ML value.
 *   key       The key to retrieve from the input vector.
 *   name      Alias for key.
 *   default   The default value to return if the key is not set.
 *   source    The input source to retrieve the key from .
 *   noprocess If set, no processing is applied to the constant value.
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return string
 *
 */
function smarty_function_formutil_getpassedvalue($params, Zikula_View $view)
{
    if ((!isset($params['key']) || !$params['key']) && (!isset($params['name']) || !$params['name'])) {
        // use name as an alias for key for programmer convenience
        $view->trigger_error('formutil_getpassedvalue: attribute key (or name) required');
        return false;
    }
    $assign = isset($params['assign']) ? $params['assign'] : null;
    $key = isset($params['key']) ? $params['key'] : null;
    $default = isset($params['default']) ? $params['default'] : null;
    $html = isset($params['html']) ? $params['html'] : null;
    $source = isset($params['source']) ? $params['source'] : null;
    $noprocess = isset($params['noprocess']) ? $params['noprocess'] : null;
    if (!$key) {
        $key = isset($params['name']) ? $params['name'] : null;
    }
    $source = isset($source) ? $source : null;
    switch ($source) {
        case 'GET':
            $val = $view->getRequest()->query->get($key, $default);
            break;
        case 'POST':
            $val = $view->getRequest()->request->get($key, $default);
            break;
        case 'SERVER':
            $val = $view->getRequest()->server->get($key, $default);
            break;
        case 'FILES':
            $val = $view->getRequest()->files->get($key, $default);
            break;
        default:
            $val = $view->getRequest()->query->get($key, $view->getRequest()->request->get($key, $default));
            break;
    }
    if ($noprocess) {
        $val = $val;
    } elseif ($html) {
        $val = DataUtil::formatForDisplayHTML($val);
    } else {
        $val = DataUtil::formatForDisplay($val);
    }
    if ($assign) {
        $view->assign($assign, $val);
    } else {
        return $val;
    }
}
Exemplo n.º 8
0
/**
 * Zikula_View pager plugin
 *
 * Examples (see also the demo page)
 *   {pager rowcount="400" limit="50"}
 *   {pager rowcount="400" limit="35" template="pageritems.tpl"}
 *   {pager rowcount="480" limit="90" template="pagerintervals.tpl" posvar="myposvar"}
 *   {pager rowcount="500" limit="47" template="pagerimage.tpl"}
 *   {pager rowcount="432" limit="25" template="pagercss.tpl"}
 *   {pager rowcount="1200" limit="40" maxpages="10"}
 *   {pager rowcount="1200" limit="40" template="pagercss.tpl" maxpages="7"}
 *   {pager rowcount="1200" limit="40" template="pagerjs.tpl" maxpages="10"}
 *   {pager rowcount="1200" limit="40" template="pagercss2.tpl" maxpages="20"}
 *   {pager rowcount="1200" limit="40" template="pagercss2.tpl" maxpages="20" optimize=true}
 *
 * Available parameters:
 *  modname            Fixed name of the module to page (optional)
 *  type               Fixed value of the type url parameter (optional)
 *  func               Fixed value of the function url parameter (optional)
 *  route              Name of a fixed route to use (optional, replaces modname / type / func)
 *  rowcount           Total number of items to page in between
 *                       (if an array is assigned, it's count will be used)
 *  limit              Number of items on a page (if <0 unlimited)
 *  posvar             Name of the variable that contains the position data, eg "offset"
 *  owner              If set uses it as the module owner of the Zikula_View instance. Default owner is the Theme module
 *  template           Optional name of a template file
 *  includeStylesheet  Use predefined stylesheet file? Default is yes.
 *  anchorText         Optional text for hyperlink anchor (e.g. 'comments' for the anchor #comments) (default: '')
 *  maxpages           Optional maximum number of displayed pages, others will be hidden / suppressed
 *                       (default: 15 = show only 15 pages)
 *  display            Optional choice between 'page' or 'startnum'. Show links using page number or starting item number (default is startnum)
 *  class              Optional class to apply to the pager container (default : z-pager)
 *  processDetailLinks Should the single page links be processed? (default: false if using pagerimage.tpl, otherwise true)
 *  processUrls        Should urls be processed or assign the arguments? (default: true)
 *  optimize           Only deliver page links which are actually displayed to the template (default: true)
 *  includePostVars    Whether or not to include the POST variables as GET variables in the pager URLs (default: true)
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return string
 */
function smarty_function_pager($params, Zikula_View $view)
{
    if (!isset($params['rowcount'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('pager', 'rowcount')));
    }
    if (!isset($params['limit'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('pager', 'limit')));
    }
    if (is_array($params['rowcount'])) {
        $params['rowcount'] = count($params['rowcount']);
    } elseif ($params['rowcount'] == 0) {
        return '';
    }
    if ($params['limit'] == 0) {
        $params['limit'] = 5;
    }
    if (!isset($params['display'])) {
        $params['display'] = 'startnum';
    }
    if (!isset($params['class'])) {
        $params['class'] = 'z-pager';
    }
    if (!isset($params['optimize'])) {
        $params['optimize'] = true;
    }
    if (!isset($params['owner'])) {
        $params['owner'] = false;
    }
    if (!isset($params['includePostVars'])) {
        $params['includePostVars'] = true;
    }
    if (!isset($params['route'])) {
        $params['route'] = false;
    }
    $pager = array();
    $pager['total'] = $params['rowcount'];
    $pager['perpage'] = $params['limit'];
    $pager['class'] = $params['class'];
    $pager['optimize'] = $params['optimize'];
    unset($params['rowcount']);
    unset($params['limit']);
    unset($params['class']);
    unset($params['optimize']);
    // current position
    $pager['posvar'] = isset($params['posvar']) ? $params['posvar'] : 'pos';
    $routeParams = array();
    if ($view->getRequest()->attributes->has('_route_params')) {
        $routeParams = $view->getRequest()->attributes->get('_route_params');
        if (isset($routeParams[$pager['posvar']])) {
            $pager['pos'] = (int) $routeParams[$pager['posvar']];
        } else {
            $pager['pos'] = (int) $view->getRequest()->query->get($pager['posvar'], '');
        }
    } else {
        $pager['pos'] = (int) $view->getRequest()->query->get($pager['posvar'], '');
    }
    if ($params['display'] == 'page') {
        $pager['pos'] = $pager['pos'] * $pager['perpage'];
        $pager['increment'] = 1;
    } else {
        $pager['increment'] = $pager['perpage'];
    }
    if ($pager['pos'] < 1) {
        $pager['pos'] = 1;
    }
    if ($pager['pos'] > $pager['total']) {
        $pager['pos'] = $pager['total'];
    }
    unset($params['posvar']);
    // number of pages
    $pager['countPages'] = isset($pager['total']) && $pager['total'] > 0 ? ceil($pager['total'] / $pager['perpage']) : 1;
    if ($pager['countPages'] < 2) {
        return '';
    }
    // current page
    $pager['currentPage'] = ceil($pager['pos'] / $pager['perpage']);
    if ($pager['currentPage'] > $pager['countPages']) {
        $pager['currentPage'] = $pager['countPages'];
    }
    $template = isset($params['template']) ? $params['template'] : 'pagercss.tpl';
    $pager['includeStylesheet'] = isset($params['includeStylesheet']) ? $params['includeStylesheet'] : true;
    $anchorText = isset($params['anchorText']) ? '#' . $params['anchorText'] : '';
    $pager['maxPages'] = isset($params['maxpages']) ? $params['maxpages'] : 15;
    unset($params['template']);
    unset($params['anchorText']);
    unset($params['maxpages']);
    if (isset($params['modname'])) {
        $pager['module'] = $params['modname'];
    } else {
        $module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
        $name = FormUtil::getPassedValue('name', null, 'GETPOST', FILTER_SANITIZE_STRING);
        $pager['module'] = !empty($module) ? $module : $name;
    }
    $pager['func'] = isset($params['func']) ? $params['func'] : FormUtil::getPassedValue('func', 'index', 'GETPOST', FILTER_SANITIZE_STRING);
    $pager['type'] = isset($params['type']) ? $params['type'] : FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
    $pager['route'] = $params['route'];
    $pager['args'] = array();
    if (empty($pager['module'])) {
        $pager['module'] = System::getVar('startpage');
        $starttype = System::getVar('starttype');
        $pager['type'] = !empty($starttype) ? $starttype : 'user';
        $startfunc = System::getVar('startfunc');
        $pager['func'] = !empty($startfunc) ? $startfunc : 'index';
        $startargs = explode(',', System::getVar('startargs'));
        foreach ($startargs as $arg) {
            if (!empty($arg)) {
                $argument = explode('=', $arg);
                $pager['args'][$argument[0]] = $argument[1];
            }
        }
    }
    //also $_POST vars have to be considered, i.e. for search results
    $allVars = $params['includePostVars'] ? array_merge($_POST, $_GET, $routeParams) : array_merge($_GET, $routeParams);
    foreach ($allVars as $k => $v) {
        if ($k != $pager['posvar'] && !is_null($v)) {
            switch ($k) {
                case 'module':
                    if (!isset($params['modname'])) {
                        $pager['module'] = $v;
                    }
                    break;
                case 'func':
                    if (!isset($params['func'])) {
                        $pager['func'] = $v;
                    }
                    break;
                case 'type':
                    if (!isset($params['type'])) {
                        $pager['type'] = $v;
                    }
                    break;
                case 'lang':
                    $addcurrentlang2url = System::getVar('languageurl');
                    if ($addcurrentlang2url == 0) {
                        $pager['args'][$k] = $v;
                    }
                    break;
                default:
                    if (is_array($v)) {
                        foreach ($v as $kk => $vv) {
                            if (is_array($vv)) {
                                foreach ($vv as $kkk => $vvv) {
                                    if (is_array($vvv)) {
                                        foreach ($vvv as $kkkk => $vvvv) {
                                            if (strlen($vvvv)) {
                                                $tkey = $k . '[' . $kk . '][' . $kkk . '][' . $kkkk . ']';
                                                $pager['args'][$tkey] = $vvvv;
                                            }
                                        }
                                    } elseif (strlen($vvv)) {
                                        $tkey = $k . '[' . $kk . '][' . $kkk . ']';
                                        $pager['args'][$tkey] = $vvv;
                                    }
                                }
                            } elseif (strlen($vv)) {
                                $tkey = $k . '[' . $kk . ']';
                                $pager['args'][$tkey] = $vv;
                            }
                        }
                    } else {
                        if (strlen($v)) {
                            $pager['args'][$k] = $v;
                        }
                    }
            }
        }
    }
    unset($params['modname']);
    unset($params['type']);
    unset($params['func']);
    unset($params['route']);
    $pagerUrl = function ($pager) use($view) {
        if (!$pager['route']) {
            return ModUtil::url($pager['module'], $pager['type'], $pager['func'], $pager['args']);
        }
        return $view->getContainer()->get('router')->generate($pager['route'], $pager['args']);
    };
    // build links to items / pages
    // entries are marked as current or displayed / hidden
    $pager['pages'] = array();
    if ($pager['maxPages'] > 0) {
        $pageInterval = floor($pager['maxPages'] / 2);
        $leftMargin = $pager['currentPage'] - $pageInterval;
        $rightMargin = $pager['currentPage'] + $pageInterval;
        if ($leftMargin < 1) {
            $rightMargin += abs($leftMargin) + 1;
            $leftMargin = 1;
        }
        if ($rightMargin > $pager['countPages']) {
            $leftMargin -= $rightMargin - $pager['countPages'];
            $rightMargin = $pager['countPages'];
        }
    }
    $params['processUrls'] = isset($params['processUrls']) ? (bool) $params['processUrls'] : true;
    $params['processDetailLinks'] = isset($params['processDetailLinks']) ? (bool) $params['processDetailLinks'] : $template != 'pagerimage.tpl';
    if ($params['processDetailLinks']) {
        for ($currItem = 1; $currItem <= $pager['countPages']; $currItem++) {
            $currItemVisible = true;
            if ($pager['maxPages'] > 0 && ($currItem < $leftMargin || $currItem > $rightMargin)) {
                if ($pager['optimize']) {
                    continue;
                } else {
                    $currItemVisible = false;
                }
            }
            if ($params['display'] == 'page') {
                $pager['args'][$pager['posvar']] = $currItem;
            } else {
                $pager['args'][$pager['posvar']] = ($currItem - 1) * $pager['perpage'] + 1;
            }
            $pager['pages'][$currItem]['pagenr'] = $currItem;
            $pager['pages'][$currItem]['isCurrentPage'] = $pager['pages'][$currItem]['pagenr'] == $pager['currentPage'];
            $pager['pages'][$currItem]['isVisible'] = $currItemVisible;
            if ($params['processUrls']) {
                $pager['pages'][$currItem]['url'] = DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText);
            } else {
                $pager['pages'][$currItem]['url'] = array('module' => $pager['module'], 'type' => $pager['type'], 'func' => $pager['func'], 'args' => $pager['args'], 'fragment' => $anchorText);
            }
        }
        unset($pager['args'][$pager['posvar']]);
    }
    // link to first & prev page
    $pager['args'][$pager['posvar']] = $pager['first'] = '1';
    if ($params['processUrls']) {
        $pager['firstUrl'] = DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText);
    } else {
        $pager['firstUrl'] = array('module' => $pager['module'], 'type' => $pager['type'], 'func' => $pager['func'], 'args' => $pager['args'], 'fragment' => $anchorText);
    }
    if ($params['display'] == 'page') {
        $pager['prev'] = $pager['currentPage'] - 1;
    } else {
        $pager['prev'] = ($leftMargin - 1) * $pager['perpage'] - $pager['perpage'] + $pager['first'];
    }
    $pager['args'][$pager['posvar']] = $pager['prev'] > 1 ? $pager['prev'] : 1;
    if ($params['processUrls']) {
        $pager['prevUrl'] = DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText);
    } else {
        $pager['prevUrl'] = array('module' => $pager['module'], 'type' => $pager['type'], 'func' => $pager['func'], 'args' => $pager['args'], 'fragment' => $anchorText);
    }
    // link to next & last page
    if ($params['display'] == 'page') {
        $pager['next'] = $pager['currentPage'] + 1;
    } else {
        $pager['next'] = $rightMargin * $pager['perpage'] + 1;
    }
    $pager['args'][$pager['posvar']] = $pager['next'] < $pager['total'] ? $pager['next'] : $pager['next'] - $pager['perpage'];
    if ($params['processUrls']) {
        $pager['nextUrl'] = DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText);
    } else {
        $pager['nextUrl'] = array('module' => $pager['module'], 'type' => $pager['type'], 'func' => $pager['func'], 'args' => $pager['args'], 'fragment' => $anchorText);
    }
    if ($params['display'] == 'page') {
        $pager['last'] = $pager['countPages'];
    } else {
        $pager['last'] = $pager['countPages'] * $pager['perpage'] - $pager['perpage'] + 1;
    }
    $pager['args'][$pager['posvar']] = $pager['last'];
    if ($params['processUrls']) {
        $pager['lastUrl'] = DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText);
    } else {
        $pager['lastUrl'] = array('module' => $pager['module'], 'type' => $pager['type'], 'func' => $pager['func'], 'args' => $pager['args'], 'fragment' => $anchorText);
    }
    $pager['itemStart'] = $pager['currentPage'] * $pager['perpage'] - $pager['perpage'] + 1;
    $pager['itemEnd'] = $pager['itemStart'] + $pager['perpage'] - 1;
    if ($pager['itemEnd'] > $pager['total']) {
        $pager['itemEnd'] = $pager['total'];
    }
    $modview = $params['owner'] && ModUtil::available($params['owner']) ? $params['owner'] : 'ZikulaThemeModule';
    $renderer = Zikula_View::getInstance($modview);
    $renderer->setCaching(Zikula_View::CACHE_DISABLED);
    $renderer->assign('pagerPluginArray', $pager);
    $renderer->assign('hiddenPageBoxOpened', 0);
    $renderer->assign('hiddenPageBoxClosed', 0);
    return $renderer->fetch($template);
}
Exemplo n.º 9
0
/**
 * Inserts a hidden admin panel controlled by permissions.
 *
 * Inserts required javascript and css files for a hidden admin panel that is triggered by a rendered link.
 * Builds and renders an unordered list of admin-capable modules and their adminLinks using the
 * jQuery.mmenu library <@see http://mmenu.frebsite.nl>
 *
 * This plugin currently has NO configuration options.
 *
 * Examples:
 *
 * <samp>{adminpanelmenu}</samp>
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the {@link Zikula_View} object.
 *
 * @return string
 */
function smarty_function_adminpanelmenu($params, Zikula_View $view)
{
    if (!SecurityUtil::checkPermission('ZikulaAdminModule::', "::", ACCESS_EDIT)) {
        return '';
        // Since no permission, return empty
    }
    // add required scritps and stylesheets to page
    PageUtil::addVar('javascript', '@ZikulaAdminModule/Resources/public/js/jQuery.mmenu-5.5.1/dist/core/js/jquery.mmenu.min.all.js');
    PageUtil::addVar('stylesheet', '@ZikulaAdminModule/Resources/public/js/jQuery.mmenu-5.5.1/dist/core/css/jquery.mmenu.all.css');
    // add override for panel width created from .scss file
    PageUtil::addVar('stylesheet', '@ZikulaAdminModule/Resources/public/css/mmenu-hiddenpanel-customwidth.css');
    $router = $view->getContainer()->get('router');
    $modules = ModUtil::getModulesCapableOf('admin');
    // sort modules by displayname
    $moduleNames = array();
    foreach ($modules as $key => $module) {
        $moduleNames[$key] = $module['displayname'];
    }
    array_multisort($moduleNames, SORT_ASC, $modules);
    // create unordered list of admin-capable module links
    $htmlContent = '<nav id="zikula-admin-hiddenpanel-menu">';
    $htmlContent .= '<div class="text-left">';
    $htmlContent .= '<h1><img src="images/logo.gif" alt="Logo" style="height: 32px"> ' . __('Administration') . '</h1>';
    $htmlContent .= '<ul>';
    foreach ($modules as $module) {
        if (SecurityUtil::checkPermission("module[name]::", '::', ACCESS_EDIT)) {
            // first-level list - list modules with general 'index' link
            $img = ModUtil::getModuleImagePath($module['name']);
            $url = isset($module['capabilities']['admin']['url']) ? $module['capabilities']['admin']['url'] : $router->generate($module['capabilities']['admin']['route']);
            $moduleSelected = empty($moduleSelected) && strpos($view->getRequest()->getUri(), $module['url']) ? " class='Selected'" : "";
            $htmlContent .= "<li{$moduleSelected}><a href=\"" . DataUtil::formatForDisplay($url) . "\"><img src=\"{$img}\" alt=\"\" style=\"height: 18px\" /> " . $module['displayname'] . "</a>";
            $links = $view->getContainer()->get('zikula.link_container_collector')->getLinks($module['name'], 'admin');
            if (empty($links)) {
                $links = (array) ModUtil::apiFunc($module['name'], 'admin', 'getLinks');
            }
            if (count($links) > 0 && $links[0] != false) {
                // create second-level list from module adminLinks
                $htmlContent .= '<ul class="text-left">';
                foreach ($links as $link) {
                    if (isset($link['icon'])) {
                        $img = '<i class="fa fa-' . $link['icon'] . '"></i>';
                    } elseif (isset($link['class'])) {
                        $img = '<span class="' . $link['class'] . '"></span>';
                    } else {
                        $img = '';
                    }
                    $linkSelected = empty($linkSelected) && strpos($view->getRequest()->getUri(), $link['url']) ? " class='Selected'" : "";
                    $htmlContent .= "<li{$linkSelected}><a href=\"" . DataUtil::formatForDisplay($link['url']) . "\">{$img} " . $link['text'] . '</a>';
                    // create third-level list from adminLinks subLinks
                    if (isset($link['links']) && count($link['links']) > 0) {
                        $htmlContent .= '<ul class="text-left">';
                        foreach ($link['links'] as $sublink) {
                            $htmlContent .= '<li><a href="' . DataUtil::formatForDisplay($sublink['url']) . '">' . $sublink['text'] . '</a></li>';
                        }
                        $htmlContent .= '</ul>';
                    }
                    $htmlContent .= '</li>';
                }
                $htmlContent .= '</ul>';
            }
            $htmlContent .= '</li>';
        }
    }
    $htmlContent .= '</ul>';
    $htmlContent .= '</div>';
    $htmlContent .= '</nav>';
    $htmlContent .= '
            <script type="text/javascript">
                jQuery(document).ready(function( $ ){
                    $("#zikula-admin-hiddenpanel-menu").mmenu({
                        extensions: ["hiddenpanel-customwidth"],
                        "header": {
                           "title": "' . __('Zikula Administration') . '",
                           "add": true,
                           "update": true
                        },
                        "searchfield": true
                    });
                });
            </script>';
    // the the html content before </body>
    PageUtil::addVar('footer', $htmlContent);
    // display the control link
    return '<a href="#zikula-admin-hiddenpanel-menu"><i class="fa fa-bars"></i></a>';
}
Exemplo n.º 10
0
/**
 * Zikula_View plugin.
 *
 * Author:   Peter Dudas <duda at bigfish dot hu>
 *
 *  Examples:
 *    code:
 *    {pagerabc posvar='letter' class='abcpager' class_num='abclink' class_numon='abclink_on' separator=' - ' names='A,B;C,D;E,F;G,H;I,J;K,L;M,N,O;P,Q,R;S,T;U,V,W,X,Y,Z'}
 *
 *    result
 * <span class="abcpager">
 * <a class="abclink_on" href="index.php?module=Example&amp;letter=A,B">&nbspA,B</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=C,D">&nbspC,D</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=E,F">&nbspE,F</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=G,H">&nbspG,H</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=I,J">&nbspI,J</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=K,L">&nbspK,L</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=M,N,O">&nbspM,N,O</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=P,Q,R">&nbspP,Q,R</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=S,T">&nbspS,T</a>
 *  - <a class="abclink" href="index.php?module=Example&amp;letter=U,V,W,X,Y,Z">&nbspU,V,W,X,Y,Z</a>
 * </span>
 *
 *
 * Parameters:
 *  posvar         Name of the variable that contains the position data, eg "letter"
 *  forwardvars    Comma- semicolon- or space-delimited list of POST and GET variables to forward in the pager links. If unset, all vars are forwarded.
 *  additionalvars Comma- semicolon- or space-delimited list of additional variable and value pairs to forward in the links. eg "foo=2,bar=4"
 *  route          Name of a fixed route to use (optional, replaces modname / type / func)
 *  modname        Fixed name of the module to page (optional)
 *  type           Fixed value of the type url parameter (optional)
 *  func           Fixed value of the function url parameter (optional)
 *  class          Class for the pager
 *  class_num      Class for the pager links (<a> tags)
 *  class_numon    Class for the active page
 *  printempty     Print empty sel ('-')
 *  lang           Language
 *  names          String or array of names to select from (array or csv)
 *  values         Optional parameter for the previous names (array or cvs)
 *  skin           Use predefined values (hu - hungarian ABC)
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return string
 */
function smarty_function_pagerabc($params, Zikula_View $view)
{
    if (!isset($params['posvar'])) {
        $params['posvar'] = 'letter';
    }
    if (!isset($params['separator'])) {
        $params['separator'] = ' | ';
    }
    if (!isset($params['skin'])) {
        $params['skin'] = '';
    }
    if (!isset($params['printempty']) || !is_bool($params['printempty'])) {
        $params['printempty'] = false;
    }
    // set a default class
    if (!isset($params['class'])) {
        $params['class'] = 'pagination pagination-sm';
    }
    if (!isset($params['class_num'])) {
        $params['class_num'] = '';
    }
    if (!isset($params['class_numon'])) {
        $params['class_numon'] = ' ';
    }
    $pager = array();
    if (!empty($params['names'])) {
        if (!is_array($params['names'])) {
            $pager['names'] = explode(';', $params['names']);
        } else {
            $pager['names'] = $params['names'];
        }
        if (!empty($params['values'])) {
            if (!is_array($params['values'])) {
                $pager['values'] = explode(';', $params['values']);
            } else {
                $pager['values'] = $params['values'];
            }
            if (count($pager['values']) != count($pager['names'])) {
                LogUtil::addErrorPopup('pagerabc: Values length must be the same of the names');
                $pager['values'] = $pager['names'];
            }
        } else {
            $pager['values'] = $pager['names'];
        }
    } else {
        // predefined abc
        if (strtolower($params['skin']) == 'hu') {
            // Hungarian
            $pager['names'] = $pager['values'] = array('A', '?', 'B', 'C', 'D', 'E', '?', 'F', 'G', 'H', 'I', '?', 'J', 'K', 'L', 'M', 'N', 'O', '?', '?', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', '?', '?', 'U', 'V', 'W', 'X', 'Y', 'Z');
            //$params['names']  = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U'    ,'V','W','X','Y','Z');
            //$params['values'] = array('A,?','B','C','D','E,?','F','G','H','I,?','J','K','L','M','N','O,?,?,O','P','Q','R','S','T','U,?,?,U','V','W','X','Y','Z');
        } else {
            $alphabet = defined('_ALPHABET') ? constant('_ALPHABET') : 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
            $pager['names'] = $pager['values'] = explode(',', $alphabet);
        }
    }
    $pager['posvar'] = $params['posvar'];
    unset($params['posvar']);
    unset($params['names']);
    unset($params['values']);
    if (!isset($params['route'])) {
        if (isset($params['modname'])) {
            $pager['module'] = $params['modname'];
        } else {
            $module = FormUtil::getPassedValue('module', null, 'GETPOST', FILTER_SANITIZE_STRING);
            $name = FormUtil::getPassedValue('name', null, 'GETPOST', FILTER_SANITIZE_STRING);
            $pager['module'] = !empty($module) ? $module : $name;
        }
        $pager['func'] = isset($params['func']) ? $params['func'] : FormUtil::getPassedValue('func', 'index', 'GETPOST', FILTER_SANITIZE_STRING);
        $pager['type'] = isset($params['type']) ? $params['type'] : FormUtil::getPassedValue('type', 'user', 'GETPOST', FILTER_SANITIZE_STRING);
    } else {
        $pager['route'] = $params['route'];
        unset($params['route']);
    }
    $pagerUrl = function ($pager) use($view) {
        if (!isset($pager['route'])) {
            return ModUtil::url($pager['module'], $pager['type'], $pager['func'], $pager['args']);
        }
        return $view->getContainer()->get('router')->generate($pager['route'], $pager['args']);
    };
    $allVars = array_merge($view->getRequest()->request->all(), $view->getRequest()->query->all(), $view->getRequest()->attributes->get('_route_params', array()));
    $pager['args'] = array();
    if (empty($pager['module']) && empty($pager['route'])) {
        $pager['module'] = System::getVar('startpage');
        $starttype = System::getVar('starttype');
        $pager['type'] = !empty($starttype) ? $starttype : 'user';
        $startfunc = System::getVar('startfunc');
        $pager['func'] = !empty($startfunc) ? $startfunc : 'index';
        $startargs = explode(',', System::getVar('startargs'));
        foreach ($startargs as $arg) {
            if (!empty($arg)) {
                $argument = explode('=', $arg);
                if ($argument[0] == $pager['posvar']) {
                    $allVars[$argument[0]] = $argument[1];
                }
            }
        }
    }
    // If $forwardvars set, add only listed vars to query string, else add all POST and GET vars
    if (isset($params['forwardvars'])) {
        if (!is_array($params['forwardvars'])) {
            $params['forwardvars'] = preg_split('/[,;\\s]/', $params['forwardvars'], -1, PREG_SPLIT_NO_EMPTY);
        }
        foreach ((array) $params['forwardvars'] as $key => $var) {
            if (!empty($var) && !empty($allVars[$var])) {
                $pager['args'][$var] = $allVars[$var];
            }
        }
    } else {
        $pager['args'] = array_merge($pager['args'], $allVars);
    }
    if (isset($params['additionalvars'])) {
        if (!is_array($params['additionalvars'])) {
            $params['additionalvars'] = preg_split('/[,;\\s]/', $params['additionalvars'], -1, PREG_SPLIT_NO_EMPTY);
        }
        foreach ((array) $params['additionalvars'] as $var) {
            $additionalvar = preg_split('/=/', $var);
            if (!empty($var) && !empty($additionalvar[1])) {
                $pager['args'][$additionalvar[0]] = $additionalvar[1];
            }
        }
    }
    unset($pager['args']['module']);
    unset($pager['args']['func']);
    unset($pager['args']['type']);
    unset($pager['args'][$pager['posvar']]);
    // begin to fill the output
    $output = '<ul class="' . $params['class'] . '">' . "\n";
    $style = '';
    if ($params['printempty']) {
        $active = '';
        if (!empty($params['class_numon'])) {
            if (!isset($allVars[$pager['posvar']])) {
                $style = ' class="' . $params['class_numon'] . '"';
                $active = 'class="active"';
            } elseif (!empty($params['class_num'])) {
                $style = ' class="' . $params['class_num'] . '"';
            } else {
                $style = '';
            }
        }
        $vars[$pager['posvar']] = '';
        $urltemp = DataUtil::formatForDisplay($pagerUrl($pager));
        $output .= '<li ' . $active . '><a ' . $style . ' href="' . $urltemp . '"> -' . "\n</a></li>";
    }
    $style = '';
    foreach (array_keys($pager['names']) as $i) {
        $active = '';
        if (!empty($params['class_numon'])) {
            if (isset($allVars[$pager['posvar']]) && $allVars[$pager['posvar']] == $pager['values'][$i]) {
                $style = ' class="' . $params['class_numon'] . '"';
                $active = 'class="active"';
            } elseif (!empty($params['class_num'])) {
                $style = ' class="' . $params['class_num'] . '"';
            } else {
                $style = '';
            }
        }
        $pager['args'][$pager['posvar']] = $pager['values'][$i];
        $urltemp = DataUtil::formatForDisplay($pagerUrl($pager));
        $output .= '<li ' . $active . '><a ' . $style . ' href="' . $urltemp . '">' . $pager['names'][$i] . "</a></li>\n";
    }
    $output .= "</ul>\n";
    return $output;
}
Exemplo n.º 11
0
/**
 * Zikula_View outputfilter to add page variables and additional header global into page header
 *
 * By default this output filter places page variable output immediately prior to the closing
 * head tag (</head>). The output can, optionally, be placed anywhere in the template by adding
 * the HTML comment <!-- pagevars --> to the page template. Note that this must always be in
 * the header for the output to function correctly.
 *
 * @param string      $source Output source.
 * @param Zikula_View $view   Reference to Zikula_View instance.
 *
 * @return string
 */
function smarty_outputfilter_pagevars($source, $view)
{
    $return = '';
    $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme()));
    $cssjscombine = ModUtil::getVar('ZikulaThemeModule', 'cssjscombine', false);
    $type = $view->getRequest()->get('type');
    $zkType = $view->getRequest()->attributes->get('_zkType');
    $isAdminController = $type == 'admin' || $zkType == 'admin';
    // get list of stylesheets and scripts from JCSSUtil
    $jcss = JCSSUtil::prepareJCSS($cssjscombine, $view->cache_dir, $themeinfo, $isAdminController);
    if (is_array($jcss['stylesheets']) && !empty($jcss['stylesheets'])) {
        foreach ($jcss['stylesheets'] as $stylesheet) {
            if (empty($stylesheet)) {
                continue;
            }
            // check if the stylesheets is in the additional_header array
            if ($themeinfo['xhtml']) {
                $return .= '<link rel="stylesheet" href="' . DataUtil::formatForDisplay($stylesheet) . '" type="text/css" />' . "\n";
            } else {
                $return .= '<link rel="stylesheet" href="' . DataUtil::formatForDisplay($stylesheet) . '" type="text/css">' . "\n";
            }
        }
    }
    // get inline js config and print it just before any script tag
    $jsConfig = JCSSUtil::getJSConfig();
    if (!empty($jsConfig)) {
        $return .= $jsConfig;
    }
    if (is_array($jcss['javascripts']) && !empty($jcss['javascripts'])) {
        foreach ($jcss['javascripts'] as $j => $javascript) {
            if (empty($javascript)) {
                unset($jcss['javascripts'][$j]);
                continue;
            }
            // check if the javascript is in the additional_header array
            $return .= '<script type="text/javascript" src="' . DataUtil::formatForDisplay($javascript) . '"></script>' . "\n";
        }
    }
    $headerContent = PageUtil::getVar('header');
    if (is_array($headerContent) && !empty($headerContent)) {
        $return .= implode("\n", $headerContent) . "\n";
    }
    // if we've got some page vars to add the header wrap the output in
    // suitable identifying comments when in development mode
    $return = trim($return);
    if (!empty($return) && System::getVar('development') != 0) {
        $return = "<!-- zikula pagevars -->\n" . $return . "\n<!-- /zikula pagevars -->";
    }
    // get any body page vars
    $bodyvars = PageUtil::getVar('body');
    if (!empty($bodyvars)) {
        $bodyattribs = '<body ' . @implode(' ', $bodyvars) . '>';
        $source = str_replace('<body>', $bodyattribs, $source);
    }
    // get any footer page vars
    $footervars = PageUtil::getVar('footer');
    if (!empty($footervars)) {
        $footersource = @implode("\n", $footervars) . "\n</body>";
        $source = str_replace('</body>', $footersource, $source);
    }
    // replace the string in the template source
    if (stripos($source, '<!-- pagevars -->')) {
        $source = str_replace('<!-- pagevars -->', $return, $source);
    } else {
        $headPos = stripos($source, '</head>');
        if ($headPos !== false) {
            if ($headPos == strripos($source, '</head>')) {
                // Position of the first </head> matches the last </head> so str_replace is safe
                $source = str_replace('</head>', $return . "\n</head>", $source);
            } else {
                // Position of the first </head> does not match the last </head> so str_replace is NOT safe
                // There was probably a {zdebug} tag opening a _dbgconsole.
                // Need to use preg_replace so we can limit to the first.
                preg_replace('#</head>#i', $return . "\n</head>", $source, 1);
            }
        }
    }
    // return the modified source
    return $source;
}