/** * 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(); }
/** * 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 ''; }
/** * 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(); }
/** * Zikula_View function notify display hooks. * * This function notify display hooks. * * Available parameters: * - 'eventname' The name of the hook event [required]. * - 'id' The ID if the subject. * - 'urlobject' Zikula_ModUrl instance or null. * - 'assign' If set, the results array is assigned to the named variable instead display [optional]. * - all remaining parameters are passed to the hook via the args param in the event. * * Example: * {notifydisplayhooks eventname='news.ui_hooks.item.display_view' id=$id urlobject=$urlObject} * {notifydisplayhooks eventname='news.ui_hooks.item.display_view' id=$id urlobject=$urlObject assign='displayhooks'} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see smarty_function_notifydisplayhooks() * * @return string|void if the results are assigned to variable in assigned. */ function smarty_function_notifydisplayhooks($params, Zikula_View $view) { if (!isset($params['eventname'])) { return trigger_error(__f('Error! "%1$s" must be set in %2$s', array('eventname', 'notifydisplayhooks'))); } $eventname = $params['eventname']; $id = isset($params['id']) ? $params['id'] : null; $urlObject = isset($params['urlobject']) ? $params['urlobject'] : null; if ($urlObject && !$urlObject instanceof \Zikula\Core\UrlInterface) { return trigger_error(__f('Error! "%1$s" must be an instance of %2$s', array('urlobject', '\\Zikula\\Core\\UrlInterface'))); } $assign = isset($params['assign']) ? $params['assign'] : false; // create event and notify $hook = new Zikula_DisplayHook($eventname, $id, $urlObject); // @todo Zikula_DisplayHook maintains BC. IN 1.5.0 change to \Zikula\Core\Hook\DisplayHook($id, $urlObject); $view->getContainer()->get('hook_dispatcher')->dispatch($eventname, $hook); $responses = $hook->getResponses(); // assign results, this plugin does not return any display if ($assign) { $view->assign($assign, $responses); return null; } $output = ''; foreach ($responses as $result) { $output .= "<div class=\"z-displayhook\">{$result}</div>\n"; } return $output; }
/** * Zikula_View function to get the site's page render time * * Available parameters: * - assign if set, the message will be assigned to this variable * - round if the, the time will be rounded to this number of decimal places * (optional: default 2) * * Example * {pagerendertime} outputs 'Page created in 0.18122792243958 seconds.' * * {pagerendertime round=2} outputs 'Page created in 0.18 seconds.' * * @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 page render time in seconds. */ function smarty_function_pagerendertime($params, Zikula_View $view) { // show time to render if ($view->getContainer()->getParameter('debug.display_pagerendertime')) { // calcultate time to render $dbg_totaltime = $view->getContainer()->get('zikula')->getUptime(); $round = isset($params['round']) ? $params['round'] : 7; $dbg_totaltime = round($dbg_totaltime, $round); if (isset($params['assign'])) { $view->assign('rendertime', $dbg_totaltime); } else { // load language files $message = '<div class="z-pagerendertime" style="text-align:center;">' . __f('Page generated in %s seconds.', $dbg_totaltime) . '</div>'; return $message; } } }
/** * 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(); }
/** * Available params: * - image (string) Path to source image (required) * - width (int) Thumbnail width in pixels or 'auto' (optional, default value based on 'default' preset) * - height (int) Thumbnail width in pixels or 'auto' (optional, default value based on 'default' preset) * - mode (string) Thumbnail mode; 'inset' or 'outbound' (optional, default 'inset') * In outbound mode auto width or height gives the same effect as inset * - extension (string) File extension for thumbnails: jpg, png, gif; null for original file type * (optional, default value based on 'default' preset) * - options (array) Options array given to the thumbnail Imagine method call. * - options[jpeg_quality] * (int) Thumbnail jpeg quality in % [0-100], where 100% is best quality (optional, default value based on 'default' preset) * - options[png_compression_level] * (int) Thumbnail png compression level [0-9], where 0 is no compression (optional, default value based on 'default' preset) * - objectid (string) Unique signature for object, which owns this thumbnail (optional) * - preset (string|object) Name of preset defined in Imagine or custom preset passed as instance of * SystemPlugin_Imagine_Preset; if given inline options ('width', 'heigth', 'mode' * and 'extension') are ignored (optional) * - manager (object) Instance of SystemPlugin_Imagine_Manager; if given inline options ('width', * 'heigth', 'mode' and 'extension') are ignored (optional) * - fqurl (boolean) If set the thumb path is absolute, if not relative * - tag (boolean) If set to true - full <img> tag will be generated. Tag attributes should be * passed with "img_" prefix (for example: "img_class"). Getttext prefix may be * used for translations (for example: "__img_alt") * * Examples * * Basic usage with inline options: * {thumb image='path/to/image.png' width='100' height='100' mode='inset' extension='jpg'} * {thumb image='path/to/image.png' width='150' height='auto' mode='inset' extension='png'} * {thumb image='path/to/image.jpg' width='150' 'jpeg_quality'=50} * * Using preset define in Imagine plugin * {thumb image='path/to/image.png' objectid='123' preset='my_preset'} * * Using custom preset, defined in module and passed to template * {thumb image='path/to/image.png' objectid='123' preset=$preset} * * Using custom SystemPlugin_Imagine_Manager instance, defined in module and passed to template * {thumb image='path/to/image.png' objectid='123' manager=$manager} * * Generating full img tag * {thumb image='path/to/image.png' objectid='123' preset=$preset tag=true __img_alt='Alt text, gettext prefix may be used' img_class='image-class'} * This will generate: * <img src="thumb/path" widht="100" height="100" alt="Alt text, gettext prefix may be used" class="image-class" /> * * @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 thumb path */ function smarty_function_thumb($params, Zikula_View $view) { if (!isset($params['image']) || empty($params['image'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_thumb', 'image'))); return false; } $image = $params['image']; $objectId = isset($params['objectid']) ? $params['objectid'] : null; if (isset($params['manager']) && $params['manager'] instanceof SystemPlugin_Imagine_Manager) { $manager = $params['manager']; } else { $manager = $view->getContainer()->get('systemplugin.imagine.manager'); } if (isset($params['preset']) && $params['preset'] instanceof SystemPlugin_Imagine_Preset) { $preset = $params['preset']; } elseif (isset($params['preset']) && $manager->getPlugin()->hasPreset($params['preset'])) { $preset = $manager->getPlugin()->getPreset($params['preset']); } else { $preset = array(); $preset['width'] = isset($params['width']) ? $params['width'] : 'auto'; $preset['height'] = isset($params['height']) ? $params['height'] : 'auto'; $preset['mode'] = isset($params['mode']) ? $params['mode'] : null; $preset['extension'] = isset($params['extension']) ? $params['extension'] : null; $preset['options'] = isset($params['options']) ? $params['options'] : array(); $preset = array_filter($preset); } $manager->setPreset($preset); $thumb = $manager->getThumb($image, $objectId); $basePath = isset($params['fqurl']) && $params['fqurl'] ? System::getBaseUrl() : System::getBaseUri(); $result = "{$basePath}/{$thumb}"; if (isset($params['tag']) && $params['tag']) { $thumbSize = @getimagesize($thumb); $attributes = array(); $attributes[] = "src=\"{$basePath}/{$thumb}\""; $attributes[] = $thumbSize[3]; // width and height // get tag params foreach ($params as $key => $value) { if (strpos($key, 'img_') === 0) { $key = str_replace('img_', '', $key); $attributes[$key] = "{$key}=\"{$value}\""; } } if (!isset($attributes['alt'])) { $attributes[] = 'alt=""'; } $attributes = implode(' ', $attributes); $result = "<img {$attributes} />"; } if (isset($params['assign'])) { $view->assign($params['assign'], $result); } else { return $result; } }
/** * Set key in $metatags array. * * Available attributes: * - name (string) The name of the configuration variable to obtain * - value (string) Value. * * Examples: * * <samp><p>Welcome to {setmetatag name='description' value='Description goes here}!</p></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 void */ function smarty_function_setmetatag($params, Zikula_View $view) { $name = isset($params['name']) ? $params['name'] : null; $value = isset($params['value']) ? $params['value'] : null; if (!$name) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('setmetatag', 'name'))); return false; } $sm = $view->getContainer(); $sm['zikula_view.metatags'][$name] = DataUtil::formatForDisplay($value); }
/** * Zikula_View function to the module lists header links * * This function returns the sort link for one of the columns of a list. * * * Available parameters: * - linktext: Text of the link * - currentsort: Current column being sorted on the list * - sort: Column to sort with this link * - sortdir: Sort direction of the link (default: ASC) * - assign: If set, the results are assigned to the corresponding * variable instead of printed out * - modname: Module name for the link * - type: Function type for the link (default: user) * - func: Function name for the link (default: main) * - route: the routename * * Additional parameters will be passed to ModUtil::url directly. * * Example * {sortlink __linktext='Column name' sort='colname' currentsort=$sort sortdir=$sortdir modname='ModName' type='admin' func='view'} * * @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 link output. */ function smarty_function_sortlink($params, Zikula_View $view) { if (!isset($params['currentsort'])) { trigger_error(__f('Error! "%1$s" must be set in %2$s', array('currentsort', 'sortlink'))); } if (!isset($params['sort'])) { trigger_error(__f('Error! "%1$s" must be set in %2$s', array('sort', 'sortlink'))); } $modname = isset($params['modname']) ? $params['modname'] : $view->getTopLevelModule(); $type = isset($params['type']) ? $params['type'] : 'user'; $func = isset($params['func']) ? $params['func'] : 'index'; $route = isset($params['route']) ? $params['route'] : null; $text = isset($params['linktext']) ? $params['linktext'] : ' '; $sortdir = isset($params['sortdir']) ? strtoupper($params['sortdir']) : 'ASC'; $assign = isset($params['assign']) ? $params['assign'] : null; // defines the CSS class and revert the order for current field if ($params['currentsort'] == $params['sort']) { $cssclass = 'z-order-' . strtolower($sortdir); // reverse the direction $params['sortdir'] = $sortdir == 'ASC' ? 'DESC' : 'ASC'; } else { $cssclass = 'z-order-unsorted'; // defaults the direction to ASC $params['sortdir'] = 'ASC'; } // unset non link parameters $unsets = array('linktext', 'currentsort', 'assign', 'modname', 'type', 'func', 'route'); foreach ($unsets as $unset) { unset($params[$unset]); } // build the link output if (!empty($route)) { $link = $view->getContainer()->get('router')->generate($route, $params); } else { $link = ModUtil::url($modname, $type, $func, $params); } $output = '<a class="' . DataUtil::formatForDisplay($cssclass) . '" href="' . DataUtil::formatForDisplay($link) . '">' . DataUtil::formatForDisplay($text) . '</a>'; if ($assign) { $view->assign($assign, $output); } else { return $output; } }
/** * Zikula_View function to create a compatible route for a specific module function. * * NOTE: This function only works for modules using the Core 1.4.0+ routing specification * * This function returns a module route string if successful. This is already sanitized to display, * so it should not be passed to the safetext modifier. * * Available parameters: * - name: the route name e.g. `acmewidgetmakermodule_user_construct` * - absolute: whether to generate an absolute URL * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - all remaining parameters are passed to the generator as route parameters * * Example * Create a route to the News 'view' function with parameters 'sid' set to 3 * <a href="{route name='zikulanewsmodule_user_display' sid='3'}">Link</a> * * @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 route or empty. */ function smarty_function_route($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; unset($params['assign']); $name = isset($params['name']) ? $params['name'] : false; unset($params['name']); $absolute = isset($params['absolute']) ? $params['absolute'] : false; unset($params['absolute']); /** @var $router \JMS\I18nRoutingBundle\Router\I18nRouter */ $router = $view->getContainer()->get('router'); try { $route = $router->generate($name, $params, $absolute); } catch (Symfony\Component\Routing\Exception\RouteNotFoundException $e) { $route = ''; // route does not exist } if ($assign) { $view->assign($assign, $route); } else { return DataUtil::formatForDisplay($route); } }
/** * Zikula_View function to create a compatible route for a specific module function. * * NOTE: This function only works for modules using the Core 1.4.0+ routing specification * * This function returns a module route string if successful. This is already sanitized to display, * so it should not be passed to the safetext modifier. * * Available parameters: * - name: the route name e.g. `acmewidgetmakermodule_user_construct` * - absolute: whether to generate an absolute URL * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - all remaining parameters are passed to the generator as route parameters * * Example * Create a route to the News 'view' function with parameters 'sid' set to 3 * <a href="{route name='zikulanewsmodule_user_display' sid='3'}">Link</a> * * @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 route or empty. */ function smarty_function_route($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; unset($params['assign']); $name = isset($params['name']) ? $params['name'] : false; unset($params['name']); $absolute = isset($params['absolute']) ? $params['absolute'] : false; unset($params['absolute']); /** @var $router \JMS\I18nRoutingBundle\Router\I18nRouter */ $router = $view->getContainer()->get('router'); $originalRouteCollection = $router->getOriginalRouteCollection()->all(); if (array_key_exists($name, $originalRouteCollection)) { $route = $router->generate($name, $params, $absolute); } else { $route = ''; // route does not exist } if ($assign) { $view->assign($assign, $route); } else { return DataUtil::formatForDisplay($route); } }
/** * Zikula_View insert function to dynamically get current status/error message * * This function obtains the last status message posted for this session. * The status message exists in one of two session variables: '_ZStatusMsg' for a * status message, or '_ZErrorMsg' for an error message. If both a status and an * error message exists then the error message is returned. * * This is is a destructive function - it deletes the two session variables * '_ZStatusMsg' and 'erorrmsg' during its operation. * * Available parameters: * - assign: If set, the status message is assigned to the corresponding variable instead of printed out * - style, class: If set, the status message is being put in a div tag with the respective attributes * - tag: You can specify if you would like a span or a div tag * * Example * {insert name='getstatusmsg'} * {insert name="getstatusmsg" style="color:red;"} * {insert name="getstatusmsg" class="statusmessage" tag="span"} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string|void */ function smarty_insert_getstatusmsg($params, $view) { // NOTE: assign parameter is handled by the smarty_core_run_insert_handler(...) function in lib/vendor/Smarty/internals/core.run_insert_handler.php $class = isset($params['class']) ? $params['class'] : null; $style = isset($params['style']) ? $params['style'] : null; $tag = isset($params['tag']) ? $params['tag'] : null; //prepare output var $output = ''; // $msgStatus = LogUtil::getStatusMessages(); // we do not use LogUtil::getStatusMessages() because we need to know if we have to // show a status or an error $session = $view->getContainer()->get('session'); $msgStatus = $session->getFlashBag()->get(Zikula_Session::MESSAGE_STATUS); $msgtype = $class ? $class : 'z-statusmsg'; $msgError = $session->getFlashBag()->get(Zikula_Session::MESSAGE_ERROR); // Error message overrides status message if (!empty($msgError)) { $msgStatus = $msgError; $msgtype = $class ? $class : 'z-errormsg'; } if (empty($msgStatus) || count($msgStatus) == 0) { return $output; } // some parameters have been set, so we build the complete tag if (!$tag || $tag != 'span') { $tag = 'div'; } // need to build a proper error message from message array $output = '<' . $tag . ' class="' . $msgtype . '"'; if ($style) { $output .= ' style="' . $style . '"'; } $output .= '>'; $output .= implode('<hr />', $msgStatus); $output .= '</' . $tag . '>'; return $output; }
/** * 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); }
/** * Zikula_View function to display menulinks in an unordered list * * Example * {modulelinks data=$links id='listid' class='navbar navbar-default' itemclass='z-ml-item' first='z-ml-first' last='z-ml-last'} * * Available parameters: * links Array with menulinks (text, url, title, id, class, disabled) (optional) * modname Module name to display links for (optional) * type Function type where the getLinks-function is located (optional) * menuid ID for the unordered list (optional) * menuclass Class for the unordered list (optional) * itemclass Array with menulinks (text, url, title, class, disabled) (optional) * first Class for the first element (optional) * last Class for the last element (optional) * seperator Link seperator (optional) * class CSS class (optional). * returnAsArray return results as array, not as formatted html - MUST set assign * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string A formatted string containing navigation for the module admin panel. */ function smarty_function_modulelinks($params, Zikula_View $view) { $menuLinks = isset($params['links']) ? $params['links'] : ''; $menuId = isset($params['menuid']) ? $params['menuid'] : ''; $menuClass = isset($params['menuclass']) ? $params['menuclass'] : 'navbar navbar-default navbar-modulelinks navbar-modulelinks-main'; $menuItemClass = isset($params['itemclass']) ? $params['itemclass'] : ''; $menuItemFirst = isset($params['first']) ? $params['first'] : ''; $menuItemLast = isset($params['last']) ? $params['last'] : ''; $returnAsArray = isset($params['returnAsArray']) ? (bool) $params['returnAsArray'] : false; if (empty($menuLinks)) { if (!isset($params['modname']) || !ModUtil::available($params['modname'])) { $params['modname'] = ModUtil::getName(); } // check our module name if (!ModUtil::available($params['modname'])) { $view->trigger_error('modulelinks: ' . __f("Error! The '%s' module is not available.", DataUtil::formatForDisplay($params['modname']))); return false; } $params['type'] = isset($params['type']) ? $params['type'] : 'admin'; // get the menu links // try the Core-2.0 way first, then try the legacy way. $menuLinks = $view->getContainer()->get('zikula.link_container_collector')->getLinks($params['modname'], $params['type']); if (empty($menuLinks)) { $menuLinks = ModUtil::apiFunc($params['modname'], $params['type'], 'getLinks', $params); } } // return if there are no links to print or template has requested to returnAsArray if (!$menuLinks || $returnAsArray && isset($params['assign'])) { if (isset($params['assign'])) { $view->assign($params['assign'], $menuLinks); } return ''; } $html = ''; if (!empty($menuLinks)) { $html = '<ul'; $html .= !empty($menuId) ? ' id="' . $menuId . '"' : ''; $html .= !empty($menuClass) ? ' class="' . $menuClass . '"' : ''; $html .= '>'; $i = 1; $size = count($menuLinks); foreach ($menuLinks as $menuitem) { $class = array(); $class[] = $size == 1 ? 'z-ml-single' : ''; $class[] = $i == 1 && $size > 1 ? $menuItemFirst : ''; $class[] = $i == $size && $size > 1 ? $menuItemLast : ''; $class[] = !empty($menuItemClass) ? $menuItemClass : ''; $class[] = isset($menuitem['disabled']) && $menuitem['disabled'] == true ? 'z-ml-disabled' : ''; $class = trim(implode(' ', $class)); $i++; if (System::isLegacyMode() && !empty($class) && isset($menuitem['class'])) { if ($menuitem['class'] == 'z-icon-es-add') { $menuitem['class'] = null; $menuitem['icon'] = 'plus'; } elseif ($menuitem['class'] == 'z-icon-es-back') { $menuitem['class'] = null; $menuitem['icon'] = 'arrow-left'; } elseif ($menuitem['class'] == 'z-icon-es-cancel') { $menuitem['class'] = null; $menuitem['icon'] = 'times'; } elseif ($menuitem['class'] == 'z-icon-es-config') { $menuitem['class'] = null; $menuitem['icon'] = 'wrench'; } elseif ($menuitem['class'] == 'z-icon-es-copy') { $menuitem['class'] = null; $menuitem['icon'] = 'files-o'; } elseif ($menuitem['class'] == 'z-icon-es-cubes') { $menuitem['class'] = null; $menuitem['icon'] = 'th'; } elseif ($menuitem['class'] == 'z-icon-es-cut') { $menuitem['class'] = null; $menuitem['icon'] = 'scissors'; } elseif ($menuitem['class'] == 'z-icon-es-delete') { $menuitem['class'] = null; $menuitem['icon'] = 'trash-o'; } elseif ($menuitem['class'] == 'z-icon-es-display') { $menuitem['class'] = null; $menuitem['icon'] = 'eye'; } elseif ($menuitem['class'] == 'z-icon-es-edit') { $menuitem['class'] = null; $menuitem['icon'] = 'pencil-square-o'; } elseif ($menuitem['class'] == 'z-icon-es-error') { $menuitem['class'] = null; $menuitem['icon'] = 'exclamation-triangle'; } elseif ($menuitem['class'] == 'z-icon-es-export') { $menuitem['class'] = null; $menuitem['icon'] = 'upload'; } elseif ($menuitem['class'] == 'z-icon-es-gears') { $menuitem['class'] = null; $menuitem['icon'] = 'gears'; } elseif ($menuitem['class'] == 'z-icon-es-filter') { $menuitem['class'] = null; $menuitem['icon'] = 'filter'; } elseif ($menuitem['class'] == 'z-icon-es-group') { $menuitem['class'] = null; $menuitem['icon'] = 'users'; } elseif ($menuitem['class'] == 'z-icon-es-help') { $menuitem['class'] = null; $menuitem['icon'] = 'info'; } elseif ($menuitem['class'] == 'z-icon-es-home') { $menuitem['class'] = null; $menuitem['icon'] = 'home'; } elseif ($menuitem['class'] == 'z-icon-es-hook') { $menuitem['class'] = null; $menuitem['icon'] = 'paperclip'; } elseif ($menuitem['class'] == 'z-icon-es-import') { $menuitem['class'] = null; $menuitem['icon'] = 'download'; } elseif ($menuitem['class'] == 'z-icon-es-info') { $menuitem['class'] = null; $menuitem['icon'] = 'info'; } elseif ($menuitem['class'] == 'z-icon-es-locale') { $menuitem['class'] = null; $menuitem['icon'] = 'globe'; } elseif ($menuitem['class'] == 'z-icon-es-locked') { $menuitem['class'] = null; $menuitem['icon'] = 'lock'; } elseif ($menuitem['class'] == 'z-icon-es-log') { $menuitem['class'] = null; $menuitem['icon'] = 'archive'; } elseif ($menuitem['class'] == 'z-icon-es-mail') { $menuitem['class'] = null; $menuitem['icon'] = 'inbox'; } elseif ($menuitem['class'] == 'z-icon-es-new') { $menuitem['class'] = null; $menuitem['icon'] = 'file-o'; } elseif ($menuitem['class'] == 'z-icon-es-ok') { $menuitem['class'] = null; $menuitem['icon'] = 'check'; } elseif ($menuitem['class'] == 'z-icon-es-options') { $menuitem['class'] = null; $menuitem['icon'] = 'th-list'; } elseif ($menuitem['class'] == 'z-icon-es-preview') { $menuitem['class'] = null; $menuitem['icon'] = 'cog'; } elseif ($menuitem['class'] == 'z-icon-es-print') { $menuitem['class'] = null; $menuitem['icon'] = 'print'; } elseif ($menuitem['class'] == 'z-icon-es-profile') { $menuitem['class'] = null; $menuitem['icon'] = 'user'; } elseif ($menuitem['class'] == 'z-icon-es-regenerate') { $menuitem['class'] = null; $menuitem['icon'] = 'refresh'; } elseif ($menuitem['class'] == 'z-icon-es-remove') { $menuitem['class'] = null; $menuitem['icon'] = 'times'; } elseif ($menuitem['class'] == 'z-icon-es-save') { $menuitem['class'] = null; $menuitem['icon'] = 'floppy-o'; } elseif ($menuitem['class'] == 'z-icon-es-saveas') { $menuitem['class'] = null; $menuitem['icon'] = 'floppy-o'; } elseif ($menuitem['class'] == 'z-icon-es-search') { $menuitem['class'] = null; $menuitem['icon'] = 'search'; } elseif ($menuitem['class'] == 'z-icon-es-url') { $menuitem['class'] = null; $menuitem['icon'] = 'globe'; } elseif ($menuitem['class'] == 'z-icon-es-user') { $menuitem['class'] = null; $menuitem['icon'] = 'user'; } elseif ($menuitem['class'] == 'z-icon-es-view') { $menuitem['class'] = null; $menuitem['icon'] = 'eye'; } elseif ($menuitem['class'] == 'z-icon-es-warning') { $menuitem['class'] = null; $menuitem['icon'] = 'exclamation-triangle'; } elseif ($menuitem['class'] == 'z-icon-es-rss') { $menuitem['class'] = null; $menuitem['icon'] = 'rss-square'; } } $active = ''; if (!empty($menuitem['url']) && System::getBaseUrl() . $menuitem['url'] === System::getCurrentUrl()) { $active = 'active '; } $dropdown = ''; if (isset($menuitem['links'])) { $dropdown = 'dropdown'; } $html .= '<li'; $html .= !empty($menuitem['id']) ? ' id="' . $menuitem['id'] . '"' : ''; $html .= ' class="' . $active . $dropdown; $html .= !empty($class) ? $class : ''; $html .= '">'; $attr = !empty($menuitem['title']) ? ' title="' . $menuitem['title'] . '"' : ''; $attr .= !empty($menuitem['class']) ? ' class="' . $menuitem['class'] . '"' : ''; if (isset($menuitem['disabled']) && $menuitem['disabled'] == true) { $html .= '<a ' . $attr . '>' . $menuitem['text'] . '</a>'; } elseif (!empty($menuitem['url'])) { $icon = ''; if (!empty($menuitem['icon'])) { $icon = '<span class="fa fa-' . $menuitem['icon'] . '"></span> '; } $html .= '<a href="' . DataUtil::formatForDisplay($menuitem['url']) . '"' . $attr . ' style="display: inline-block;">' . $icon . $menuitem['text'] . '</a>'; if (isset($menuitem['links'])) { $html .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown" style="text-decoration: none;"> <b class="caret"></b></a>'; } } else { $html .= '<span' . $attr . '>' . $menuitem['text'] . '</span>'; } if (isset($menuitem['links'])) { $html .= '<ul class="dropdown-menu">'; foreach ($menuitem['links'] as $submenuitem) { $html .= '<li>'; if (isset($submenuitem['url'])) { $html .= '<a href="' . DataUtil::formatForDisplay($submenuitem['url']) . '">' . $submenuitem['text'] . '</a>'; } else { $html .= $submenuitem['text']; } $html .= '</li>'; } $html .= '</ul>'; } $html .= '</li>'; } $html .= '</ul>'; } if (isset($params['assign'])) { $view->assign($params['assign'], $html); } else { return $html; } }
/** * Insert a CSRF protection nonce. * * Available parameters: * - assign: Assign rather the output. * * Example: * <input type="hidden" name="csrftoken" value="{insert name='csrftoken'}" /> * * @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_insert_csrftoken($params, $view) { // NOTE: assign parameter is handled by the smarty_core_run_insert_handler(...) function in lib/vendor/Smarty/internals/core.run_insert_handler.php return SecurityUtil::generateCsrfToken($view->getContainer()); }
/** * 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&letter=A,B"> A,B</a> * - <a class="abclink" href="index.php?module=Example&letter=C,D"> C,D</a> * - <a class="abclink" href="index.php?module=Example&letter=E,F"> E,F</a> * - <a class="abclink" href="index.php?module=Example&letter=G,H"> G,H</a> * - <a class="abclink" href="index.php?module=Example&letter=I,J"> I,J</a> * - <a class="abclink" href="index.php?module=Example&letter=K,L"> K,L</a> * - <a class="abclink" href="index.php?module=Example&letter=M,N,O"> M,N,O</a> * - <a class="abclink" href="index.php?module=Example&letter=P,Q,R"> P,Q,R</a> * - <a class="abclink" href="index.php?module=Example&letter=S,T"> S,T</a> * - <a class="abclink" href="index.php?module=Example&letter=U,V,W,X,Y,Z"> U,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; }
/** * Zikula_View insert function to dynamically get current status/error message * * This function obtains the last status message posted for this session. * The status message exists in one of two session variables: '_ZStatusMsg' for a * status message, or '_ZErrorMsg' for an error message. If both a status and an * error message exists then the error message is returned. * * This is is a destructive function - it deletes the two session variables * '_ZStatusMsg' and 'erorrmsg' during its operation. * * Available parameters: * - assign: If set, the status message is assigned to the corresponding variable instead of printed out * - style, class: If set, the status message is being put in a div tag with the respective attributes * - tag: You can specify if you would like a span or a div tag * * Example * {insert name='getstatusmsg'} * {insert name="getstatusmsg" style="color:red;"} * {insert name="getstatusmsg" class="statusmessage" tag="span"} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string|void */ function smarty_insert_getstatusmsg($params, $view) { /** * Note: The "assign" parameter is handled by the smarty_core_run_insert_handler() * function in lib/vendor/Smarty/internals/core.run_insert_handler.php. */ $params['class'] = isset($params['class']) ? $params['class'] : null; $params['style'] = isset($params['style']) ? $params['style'] : null; $params['tag'] = isset($params['tag']) ? $params['tag'] : null; /** * Prepare output. */ $result = ''; $total_messages = array(); /** * Get session. */ $session = $view->getContainer()->get('session'); /** * Get error messages. */ $messages = $session->getFlashBag()->get(Zikula_Session::MESSAGE_ERROR); if (count($messages) > 0) { /** * Set class for the messages. */ $class = !is_null($params['class']) ? $params['class'] : 'alert alert-danger'; $total_messages = $total_messages + $messages; /** * Build output of the messages. */ if (!$params['tag'] || $params['tag'] != 'span') { $params['tag'] = 'div'; } $result .= '<' . $params['tag'] . ' class="' . $class . '"'; if (!is_null($params['style'])) { $result .= ' style="' . $params['style'] . '"'; } $result .= '>'; $result .= implode('<hr />', $messages); $result .= '</' . $params['tag'] . '>'; } /** * Get warning messages. */ $messages = $session->getFlashBag()->get(Zikula_Session::MESSAGE_WARNING); if (count($messages) > 0) { /** * Set class for the messages. */ $class = !is_null($params['class']) ? $params['class'] : 'alert alert-warning'; $total_messages = $total_messages + $messages; /** * Build output of the messages. */ if (!$params['tag'] || $params['tag'] != 'span') { $params['tag'] = 'div'; } $result .= '<' . $params['tag'] . ' class="' . $class . '"'; if ($params['style']) { $result .= ' style="' . $params['style'] . '"'; } $result .= '>'; $result .= implode('<hr />', $messages); $result .= '</' . $params['tag'] . '>'; } /** * Get status messages. */ $messages = $session->getFlashBag()->get(Zikula_Session::MESSAGE_STATUS); if (count($messages) > 0) { /** * Set class for the messages. */ $class = !is_null($params['class']) ? $params['class'] : 'alert alert-success'; $total_messages = $total_messages + $messages; /** * Build output of the messages. */ if (!$params['tag'] || $params['tag'] != 'span') { $params['tag'] = 'div'; } $result .= '<' . $params['tag'] . ' class="' . $class . '"'; if ($params['style']) { $result .= ' style="' . $params['style'] . '"'; } $result .= '>'; $result .= implode('<hr />', $messages); $result .= '</' . $params['tag'] . '>'; } if (empty($total_messages)) { return; } return $result; }
/** * 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>'; }