Beispiel #1
0
/**
 * 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 void The results must be 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_ModUrl) {
        return trigger_error(__f('Error! "%1$s" must be an instance of %2$s', array('urlobject', 'Zikula_ModUrl')));
    }
    $assign  = isset($params['assign']) ? $params['assign'] : false;

    // create event and notify
    $hook = new Zikula_DisplayHook($eventname, $id, $urlObject);
    $view->getServiceManager()->getService('zikula.hookmanager')->notify($hook);
    $responses = $hook->getResponses();

    // assign results, this plugin does not return any display
    if ($assign) {
        $view->assign($assign, $responses);
        return;
    }

    $output = '';
    foreach ($responses as $result) {
        $output .= "$result\n";
    }

    return $output;
}
Beispiel #2
0
/**
 * Available params:
 *  - image         (string)        Path to source image (required)
 *  - width         (int)           Thumbnail width in pixels (optional, default value based on 'default' preset)
 *  - height        (int)           Thumbnail width in pixels (optional, default value based on 'default' preset)
 *  - mode          (string)        Thumbnail mode; 'inset' or 'outset' (optional, default 'inset')
 *  - extension     (string)        File extension for thumbnails: jpg, png, gif; null for original file type
 *                                  (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'}
 *
 * 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->getServiceManager()->getService('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'] : null;
        $preset['height'] = isset($params['height']) ? $params['height'] : null;
        $preset['mode'] = isset($params['mode']) ? $params['mode'] : null;
        $preset['extension'] = isset($params['extension']) ? $params['extension'] : null;
        $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;
    }
}
/**
 * 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->getServiceManager()->getArgument('debug.display_pagerendertime')) {
        // calcultate time to render
        $dbg_totaltime = $view->getServiceManager()->getService('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;
        }
    }
}
/**
 * Zikula_View function to get the meta keywords
 *
 * This function will take the contents of the page and transfer it
 * into a keyword list. If stopwords are defined, they are filtered out.
 * The keywords are sorted by count.
 * As a default, the whole page contents are taken as a base for keyword
 * generation. If set, the contents of "contents" are taken.
 * Beware that the function always returns the site keywords if "generate
 * meta keywords" is turned off.
 *
 * available parameters:
 *  - contents    if set, this wil be taken as a base for the keywords
 *  - dynamic     if set, the keywords will be created from the content / mainconent
 *                oterwise we use the page vars. The rules are:
 *                1) If dynamic keywords disabled in admin settings then use static keywords
 *                2) if parameter "dynamic" not set or empty then always use main content (default),
 *                3) if parameter "dynamic" set and not empty then use page vars if any set - otherwise use content.
 *  - assign      if set, the keywords will be assigned to this variable
 *
 * Example
 * <meta name="KEYWORDS" content="{keywords}">
 *
 * @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 keywords.
 */
function smarty_function_keywords($params, $view)
{
    LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('keywords')), E_USER_DEPRECATED);
    $metatags = $view->getServiceManager()->getArgument('zikula_view.metatags');
    if (isset($params['assign'])) {
        $view->assign($params['assign'], $metatags['keywords']);
    } else {
        return $metatags['keywords'];
    }
}
/**
 * The reviewsModerationObjects plugin determines the amount of unapproved objects.
 * It uses the same logic as the moderation block and the pending content listener.
 *
 * @param  array       $params All attributes passed to this function from the template.
 * @param  Zikula_View $view   Reference to the view object.
 */
function smarty_function_reviewsModerationObjects($params, $view)
{
    if (!isset($params['assign']) || empty($params['assign'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('reviewsModerationObjects', 'assign')));
        return false;
    }
    $serviceManager = $view->getServiceManager();
    $workflowHelper = new Reviews_Util_Workflow($serviceManager);
    $result = $workflowHelper->collectAmountOfModerationItems();
    $view->assign($params['assign'], $result);
}
Beispiel #6
0
/**
 * Zikula_View function to obtain status 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.
 *
 * Note that you must not cache the outputs from this function, as its results
 * change aech time it is called. The Zikula developers are looking for ways to
 * automise this.
 *
 *
 * 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
 *   {getstatusmsg}
 *   {getstatusmsg style='color:red;'}
 *   {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.
 *
 * @todo prevent this function from being cached
 * @deprecated
 *
 * @return string|void The value of the last status message posted, or void if no status message exists.
 */
function smarty_function_getstatusmsg($params, Zikula_View $view)
{
    LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('getstatusmsg', 'insert name="getstatusmsg"')), E_USER_DEPRECATED);

    $assign = isset($params['assign'])  ? $params['assign']  : null;
    $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->getServiceManager()->getService('session');
    $msgStatus = $session->getMessages(Zikula_Session::MESSAGE_STATUS);
    $msgtype   = ($class ? $class : 'z-statusmsg');
    $session->clearMessages(Zikula_Session::MESSAGE_STATUS);
    $msgError = $session->getMessages(Zikula_Session::MESSAGE_ERROR);
    $session->clearMessages(Zikula_Session::MESSAGE_ERROR);

    // Error message overrides status message
    if (!empty($msgError)) {
        $msgStatus = $msgError;
        $msgtype   = ($class ? $class : 'z-errormsg');
    }

    if ($assign) {
        $view->assign($assign, $msgStatus);
        return;
    }

    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;
}
/**
 * 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->getServiceManager();
    $sm['zikula_view.metatags'][$name] = DataUtil::formatForDisplay($value);
}
Beispiel #8
0
/**
 * 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->getServiceManager()->getService('session');
    $msgStatus = $session->getMessages(Zikula_Session::MESSAGE_STATUS);
    $msgtype   = ($class ? $class : 'z-statusmsg');
    $session->clearMessages(Zikula_Session::MESSAGE_STATUS);
    $msgError = $session->getMessages(Zikula_Session::MESSAGE_ERROR);
    $session->clearMessages(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;
}
/**
 * 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->getServiceManager());
}