function mediashare_source_browserapi_addMediaItem($args) { $dom = ZLanguage::getModuleDomain('mediashare'); if (!isset($args['albumId'])) { return LogUtil::registerError(__f('Missing [%1$s] in \'%2$s\'', array('albumId', 'source_browserapi.addMediaItem'), $dom)); } $uploadFilename = $args['uploadFilename']; // FIXME Required because the globals?? //pnModAPILoad('mediashare', 'edit'); // For OPEN_BASEDIR reasons we move the uploaded file as fast as possible to an accessible place // MUST remember to remove it afterwards!!! // Create and check tmpfilename $tmpDir = pnModGetVar('mediashare', 'tmpDirName'); if (($tmpFilename = tempnam($tmpDir, 'Upload_')) === false) { return LogUtil::registerError(__f("Unable to create a temporary file in '%s'", $tmpDir, $dom) . ' - ' . __('(uploading image)', $dom)); } if (is_uploaded_file($uploadFilename)) { if (move_uploaded_file($uploadFilename, $tmpFilename) === false) { unlink($tmpFilename); return LogUtil::registerError(__f('Unable to move uploaded file from \'%1$s\' to \'%2$s\'', array($uploadFilename, $tmpFilename), $dom) . ' - ' . __('(uploading image)', $dom)); } } else { if (!copy($uploadFilename, $tmpFilename)) { unlink($tmpFilename); return LogUtil::registerError(__f('Unable to copy the file from \'%1$s\' to \'%2$s\'', array($uploadFilename, $tmpFilename), $dom) . ' - ' . __('(adding image)', $dom)); } } $args['mediaFilename'] = $tmpFilename; $result = pnModAPIFunc('mediashare', 'edit', 'addMediaItem', $args); unlink($tmpFilename); return $result; }
/** * Zikula_View function to use the _dgettext() function * * This function takes a identifier and returns the corresponding language constant. * * Available parameters: * - text: (required) string to translate * - tagN: (optional) replace for sprintf() e.g. %s or %1$s * - domain: (optional) textdomain to be used (not required, the system will fill this out automatically * - comment: (optional) comment to the translator (this is not processed by this code) * - assign: If set, the results are assigned to the corresponding variable instead of printed out * * Examples * {gettext}Hello world{/gettext} * {gettext tag1=$name}Hello %s{/gettext} * {gettext tag1=$city tag2=$country comment="%1 is a name %2 is the place"}Hello %1$s, welcome to %2$s{/gettext} * * String replacement follows the rules at http://php.net/sprintf but please note Smarty seems to pass * all variables as strings so %s and %n$s are mostly used. * * @param array $params All attributes passed to this function from the template. * @param string $content The block content. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string Translation if it was available. */ function smarty_block_gettext($params, $content, Zikula_View $view) { if ($content) { if (isset($params['domain'])) { $domain = strtolower($params['domain']) == 'zikula' ? null : $params['domain']; } else { $domain = $view->getDomain(); // default domain } // build array for tags (for %s, %1$s etc) if applicable ksort($params); $tags = array(); foreach ($params as $key => $value) { if (preg_match('#^tag([0-9]{1,2})$#', $key)) { $tags[] = $value; } } $tags = count($tags) == 0 ? null : $tags; // perform gettext $output = isset($tags) ? __f($content, $tags, $domain) : __($content, $domain); if (isset($params['assign'])) { $render->assign($params['assign'], $output); } else { return $output; } } }
/** * Example: * {secauthaction comp="Stories::" inst=".*" level="ACCESS_ADMIN" assign="auth"} * * true/false will be returned. * * This file is a plugin for Zikula_View, the Zikula implementation of Smarty * @param array $params All attributes passed to this function from the template * @param object &$smarty Reference to the Smarty object * @return boolean authorized? */ function smarty_function_secauthaction($params, &$smarty) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('secauthaction', 'checkpermission')), E_USER_DEPRECATED); $assign = isset($params['assign']) ? $params['assign'] : null; $comp = isset($params['comp']) ? $params['comp'] : null; $inst = isset($params['inst']) ? $params['inst'] : null; $level = isset($params['level']) ? $params['level'] : null; if (!$comp) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_secauthaction', 'comp'))); return false; } if (!$inst) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_secauthaction', 'inst'))); return false; } if (!$level) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_function_secauthaction', 'level'))); return false; } $result = SecurityUtil::checkPermission($comp, $inst, constant($level)); if ($assign) { $smarty->assign($assign, $result); } else { return $result; } }
/** * Zikula_View function to display a drop down list of languages * * Available parameters: * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - name: Name for the control * - id: ID for the control * - selected: Selected value * - installed: if set only show languages existing in languages folder * - all: show dummy entry '_ALL' on top of the list with empty value * * Example * {html_select_languages name=language selected=en} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @deprecated smarty_function_html_select_locales() * @return string The value of the last status message posted, or void if no status message exists. */ function smarty_function_html_select_languages($params, Zikula_View $view) { if (!isset($params['name']) || empty($params['name'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('html_select_languages', 'name'))); return false; } require_once $view->_get_plugin_filepath('function', 'html_options'); $params['output'] = array(); $params['values'] = array(); if (isset($params['all']) && $params['all']) { $params['values'][] = ''; $params['output'][] = DataUtil::formatForDisplay(__('All')); unset($params['all']); } if (isset($params['installed']) && $params['installed']) { $languagelist = ZLanguage::getInstalledLanguageNames(); unset($params['installed']); } else { $languagelist = ZLanguage::languageMap(); } $params['output'] = array_merge($params['output'], DataUtil::formatForDisplay(array_values($languagelist))); $params['values'] = array_merge($params['values'], DataUtil::formatForDisplay(array_keys($languagelist))); $assign = isset($params['assign']) ? $params['assign'] : null; unset($params['assign']); $html_result = smarty_function_html_options($params, $view); if (!empty($assign)) { $view->assign($assign, $html_result); } else { return $html_result; } }
/** * Check if an array element (subscript) is set. * * Available attributes: * - array (array) an array template variable * - field (string) the value of a key in the array specified above * - returnValue (bool|int) if set, then the contents of the array element * $array[$field] is returned if it is set, otherwise false is returned * - assign (string) (optional) if provided, a template variable with * the specified name is set with the return value, * instead of returning the value to the template * * Examples: * * Return true to the template if the template variable $myarray['arraykey'] * is set, otherwise return false to the template: * * <samp>{array_field_isset array=$myarray field='arraykey'}</samp> * * Return the value of the template variable $myarray['arraykey'] to the * template if it is set, otherwise return false to the template: * * <samp>{array_field_isset array=$myarray field='arraykey' returnValue=1}</samp> * * Assign true to the template variable $myValue if the template variable * $myarray['arraykey'] is set, otherwise set $myValue to false: * * <samp>{array_field_isset array=$myarray field='arraykey' assign='myValue'}</samp> * * Assign the value of the template variable $myarray['arraykey'] to the * template variable $myValue if it is set, otherwise assign false to $myValue: * * <samp>{array_field_isset array=$myarray field='arraykey' returnValue=1 assign='myValue'}</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 boolean|mixed if returnValue is not set, then returns true if the array * element is set, otherwise false; if returnValue is set, * then returns the value of the array element if it is set, * otherwise false. */ function smarty_function_array_field_isset($params, Zikula_View $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('array_field_isset returnValue=1 ...', 'array_field ...')), E_USER_DEPRECATED); $array = isset($params['array']) ? $params['array'] : null; $field = isset($params['field']) ? $params['field'] : null; $returnValue = isset($params['returnValue']) ? $params['returnValue'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; if ($array === null) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('array_field_isset', 'array'))); return false; } if ($field === null) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('array_field_isset', 'field'))); return false; } $result = isset($array[$field]); if ($result && $returnValue) { $result = $array[$field]; } if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * Zikula_View function to display a preview image from a theme * * Available parameters: * - name name of the theme to display the preview image for * - name if set, the id assigned to the image * - size if set, the size of the image to use from small, medium, large (optional: default 'medium') * - assign if set, the title will be assigned to this variable * * Example * {previewimage name=andreas08 size=large} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.title.php::smarty_function_previewimage() * * @return string The markup to display the theme image. */ function smarty_function_previewimage($params, Zikula_View $view) { if (!isset($params['name'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('previewimage', 'name'))); return false; } if (!isset($params['size']) || !in_array($params['size'], array('large', 'medium', 'small'))) { $params['size'] = 'medium'; } $idstring = ''; if (isset($params['id'])) { $idstring = " id=\"{$params['id']}\""; } $themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($params['name'])); $theme = ThemeUtil::getTheme($themeinfo['name']); $themePath = null === $theme ? "themes/{$themeinfo['directory']}/images" : $theme->getRelativePath() . '/Resources/public/images'; if (file_exists("{$themePath}/preview_{$params['size']}.png")) { $filesrc = "{$themePath}/preview_{$params['size']}.png"; } else { $filesrc = "system/ThemeModule/Resources/public/images/preview_{$params['size']}.png"; } $markup = "<img{$idstring} src=\"{$filesrc}\" alt=\"\" />"; if (isset($params['assign'])) { $view->assign($params['assign'], $markup); } else { return $markup; } }
/** * 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; }
/** * Zikula_View function to check for the availability of a module * * This function calls ModUtil::isHooked to determine if two Zikula modules are * hooked together. True is returned if the modules are hooked, false otherwise. * The result can also be assigned to a template variable. * * Available parameters: * - tmodname: The well-known name of the hook module * - smodname: The well-known name of the calling module * - assign: The name of a variable to which the results are assigned * * Examples * {modishooked tmodname='Ratings' smodname='News'} * * {modishooked tmodname='bar' smodname='foo' assign='barishookedtofoo'} * {if $barishookedtofoo}.....{/if} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.modishooked.php::smarty_function_modishooked() * * @return boolean True if the module is available; false otherwise. */ function smarty_function_modishooked($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('modishooked')), E_USER_DEPRECATED); $assign = isset($params['assign']) ? $params['assign'] : null; $smodname = isset($params['smodname']) ? $params['smodname'] : null; $tmodname = isset($params['tmodname']) ? $params['tmodname'] : null; if (!$tmodname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modishooked', 'tmodname'))); return false; } if (!$smodname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modishooked', 'smodname'))); return false; } $result = ModUtil::isHooked($tmodname, $smodname); if ($assign) { $view->assign($params['assign'], $result); } else { return $result; } }
/** * Performs all validation rules. * * @return mixed either array with error information or true on success */ public function validateAll() { $errorInfo = array('message' => '', 'code' => 0, 'debugArray' => array()); $dom = ZLanguage::getModuleDomain('MUBoard'); if (!$this->isValidInteger('userid')) { $errorInfo['message'] = __f('Error! Field value may only contain digits (%s).', array('userid'), $dom); return $errorInfo; } if (!$this->isNumberNotEmpty('userid')) { $errorInfo['message'] = __f('Error! Field value must not be 0 (%s).', array('userid'), $dom); return $errorInfo; } if (!$this->isNumberNotLongerThan('userid', 11)) { $errorInfo['message'] = __f('Error! Length of field value must not be higher than %2$s (%1$s).', array('userid', 11), $dom); return $errorInfo; } if (!$this->isValidInteger('numberPostings')) { $errorInfo['message'] = __f('Error! Field value may only contain digits (%s).', array('numberPostings'), $dom); return $errorInfo; } /* if (!$this->isNumberNotEmpty('numberPostings')) { $errorInfo['message'] = __f('Error! Field value must not be 0 (%s).', array('numberPostings'), $dom); return $errorInfo; }*/ if (!$this->isNumberNotLongerThan('numberPostings', 11)) { $errorInfo['message'] = __f('Error! Length of field value must not be higher than %2$s (%1$s).', array('numberPostings', 11), $dom); return $errorInfo; } if (!$this->isValidDateTime('lastVisit')) { $errorInfo['message'] = __f('Error! Field value must be a valid datetime (%s).', array('lastVisit'), $dom); return $errorInfo; } return true; }
/** * Obtain and display a configuration variable from the Zikula system. * * Available attributes: * - name (string) The name of the configuration variable to obtain * - html (bool) If set, the output is prepared for display by * DataUtil::formatForDisplayHTML instead of * DataUtil::formatForDisplay * - assign (string) the name of a template variable to assign the * output to, instead of returning it to the template. (optional) * * <i>Note that if the the result is assigned to a template variable, it is not * prepared for display by either DataUtil::formatForDisplayHTML or * DataUtil::formatForDisplay. If it is to be displayed, the safetext * modifier should be used.</i> * * Examples: * * <samp><p>Welcome to {configgetvar name='sitename'}!</p></samp> * * <samp>{configgetvar name='sitename' assign='thename'}</samp><br> * <samp><p>Welcome to {$thename|safetext}!</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 mixed The value of the configuration variable. */ function smarty_function_configgetvar($params, $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('configgetvar')), E_USER_DEPRECATED); $name = isset($params['name']) ? $params['name'] : null; $default = isset($params['default']) ? $params['default'] : null; $html = isset($params['html']) ? $params['html'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; if (!$name) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('configgetvar', 'name'))); return false; } $result = System::getVar($name, $default); if ($assign) { $view->assign($assign, $result); } else { if (is_bool($html) && $html) { return DataUtil::formatForDisplayHTML($result); } else { return DataUtil::formatForDisplay($result); } } }
/** * Performs all validation rules. * * @return mixed either array with error information or true on success */ public function validateAll() { $errorInfo = array('message' => '', 'code' => 0, 'debugArray' => array()); $dom = ZLanguage::getModuleDomain('MUBoard'); if (!$this->isStringNotLongerThan('title', 255)) { $errorInfo['message'] = __f('Error! Length of field value must not be higher than %2$s (%1$s).', array('title', 255), $dom); return $errorInfo; } if (!$this->isStringNotEmpty('title')) { $errorInfo['message'] = __f('Error! Field value must not be empty (%s).', array('title'), $dom); return $errorInfo; } if (!$this->isStringNotLongerThan('description', 2000)) { $errorInfo['message'] = __f('Error! Length of field value must not be higher than %2$s (%1$s).', array('description', 2000), $dom); return $errorInfo; } if (!$this->isStringNotEmpty('description')) { $errorInfo['message'] = __f('Error! Field value must not be empty (%s).', array('description'), $dom); return $errorInfo; } if (!$this->isValidInteger('pos')) { $errorInfo['message'] = __f('Error! Field value may only contain digits (%s).', array('pos'), $dom); return $errorInfo; } /* if (!$this->isNumberNotEmpty('pos')) { $errorInfo['message'] = __f('Error! Field value must not be 0 (%s).', array('pos'), $dom); return $errorInfo; }*/ if (!$this->isNumberNotLongerThan('pos', 3)) { $errorInfo['message'] = __f('Error! Length of field value must not be higher than %2$s (%1$s).', array('pos', 3), $dom); return $errorInfo; } return true; }
/** * Zikula_View function to get module variable * * This function obtains a module-specific variable from the Zikula system. * * Note that the results should be handled by the safetext or the safehtml * modifier before being displayed. * * * Available parameters: * - module: The well-known name of a module from which to obtain the variable * - name: The name of the module variable to obtain * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - html: If true then result will be treated as html content * - default: The default value to return if the config variable is not set * * Example * {modgetvar module='Example' name='foobar' assign='foobarOfExample'} * * @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 module variable. */ function smarty_function_modgetvar($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $default = isset($params['default']) ? $params['default'] : null; $module = isset($params['module']) ? $params['module'] : null; $html = isset($params['html']) ? (bool) $params['html'] : false; $name = isset($params['name']) ? $params['name'] : null; if (!$module) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modgetvar', 'module'))); return false; } if (!$name && !$assign) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modgetvar', 'name'))); return false; } if (!$name) { $result = ModUtil::getVar($module); } else { $result = ModUtil::getVar($module, $name, $default); } if ($assign) { $view->assign($assign, $result); } else { if ($html) { return DataUtil::formatForDisplayHTML($result); } else { return DataUtil::formatForDisplay($result); } } }
/** * Zikula_View function to to execute a module API function * * This function calls a calls a specific module API function. It returns whatever the return * value of the resultant function is if it succeeds. * Note that in contrast to the API function ModUtil::apiFunc you need not to load the * module API with ModUtil::loadApi. * * * Available parameters: * - modname: The well-known name of a module to execute a function from (required) * - type: The type of function to execute; currently one of 'user' or 'admin' (default is 'user') * - func: The name of the module function to execute (default is 'main') * - assign: The name of a variable to which the results are assigned * - all remaining parameters are passed to the module API function * * Examples * {modapifunc modname='News' type='user' func='get' sid='3'} * * {modapifunc modname='foobar' type='user' func='getfoo' id='1' assign='myfoo'} * {$myfoo.title} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @see function.modfunc.php::smarty_function_modfunc() * * @return string The results of the module API function. */ function smarty_function_modapifunc($params, Zikula_View $view) { $assign = isset($params['assign']) ? $params['assign'] : null; $func = isset($params['func']) && $params['func'] ? $params['func'] : 'main'; $modname = isset($params['modname']) ? $params['modname'] : null; $type = isset($params['type']) && $params['type'] ? $params['type'] : 'user'; // avoid passing these to ModUtil::apiFunc unset($params['modname']); unset($params['type']); unset($params['func']); unset($params['assign']); if (!$modname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('modapifunc', 'modname'))); return false; } if (isset($params['modnamefunc'])) { $params['modname'] = $params['modnamefunc']; unset($params['modnamefunc']); } $result = ModUtil::apiFunc($modname, $type, $func, $params); if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * Zikula_View function to display a drop down list of module stylesheets. * * Available parameters: * - modname The module name to show the styles for * - assign: If set, the results are assigned to the corresponding variable instead of printed out * - id: ID for the control * - name: Name for the control * - exclude Comma seperated list of files to exclude (optional) * - selected: Selected 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 The value of the last status message posted, or void if no status message exists. */ function smarty_function_html_select_modulestylesheets($params, Zikula_View $view) { if (!isset($params['modname'])) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('html_select_modulestylesheets', 'modname'))); return false; } if (isset($params['exclude'])) { $exclude = explode(',', trim($params['exclude'])); unset($params['exclude']); } else { $exclude = array(); } $params['values'] = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getmodstyles', array('modname' => $params['modname'], 'exclude' => $exclude)); unset($params['modname']); $params['output'] = $params['values']; $assign = isset($params['assign']) ? $params['assign'] : null; unset($params['assign']); require_once $view->_get_plugin_filepath('function', 'html_options'); $output = smarty_function_html_options($params, $view); if (!empty($assign)) { $view->assign($assign, $output); } else { return $output; } }
/** * 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; }
/** * {@inheritdoc} * * @throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used */ protected function execute(InputInterface $input, OutputInterface $output) { if (version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION, '<')) { $output->writeln(__f('The current installed version of Zikula is reporting (%1$s). You must upgrade to version (%2$s) before you can use this upgrade.', array(ZIKULACORE_CURRENT_INSTALLED_VERSION, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION))); return false; } $output->writeln(array("<info>---------------------------</info>", "| Zikula Upgrader Script |", "<info>---------------------------</info>")); $output->writeln("*** UPGRADING TO ZIKULA CORE v" . \Zikula_Core::VERSION_NUM . " ***"); $env = $this->getContainer()->get('kernel')->getEnvironment(); $output->writeln('Upgrading Zikula in <info>' . $env . '</info> environment.'); $this->bootstrap(false); $output->writeln('Initializing upgrade...'); $initStage = new InitStage($this->getContainer()); $initStage->isNecessary(); // runs init and upgradeUsersModule methods and intentionally returns false $output->writeln('Initialization complete'); $warnings = $this->getContainer()->get('core_installer.controller.util')->initPhp(); if (!empty($warnings)) { $this->printWarnings($output, $warnings); return; } $checks = $this->getContainer()->get('core_installer.controller.util')->requirementsMet($this->getContainer()); if (true !== $checks) { $this->printRequirementsWarnings($output, $checks); return; } // get the settings from user input $formType = new LocaleType(); $settings = $this->getHelper('form')->interactUsingForm($formType, $input, $output); $formType = new LoginType(); $data = $this->getHelper('form')->interactUsingForm($formType, $input, $output); foreach ($data as $k => $v) { $data[$k] = base64_encode($v); // encode so values are 'safe' for json } $settings = array_merge($settings, $data); $formType = new RequestContextType(); $data = $this->getHelper('form')->interactUsingForm($formType, $input, $output); foreach ($data as $k => $v) { $newKey = str_replace(':', '.', $k); $data[$newKey] = $v; unset($data[$k]); } $settings = array_merge($settings, $data); // write the parameters to custom_parameters.yml $yamlManager = new YamlDumper($this->getContainer()->get('kernel')->getRootDir() . '/config', 'custom_parameters.yml'); $params = array_merge($yamlManager->getParameters(), $settings); $yamlManager->setParameters($params); // upgrade! $ajaxInstallerStage = new AjaxUpgraderStage(); $stages = $ajaxInstallerStage->getTemplateParams(); foreach ($stages['stages'] as $key => $stage) { $output->writeln($stage[AjaxInstallerStage::PRE]); $output->writeln("<fg=blue;options=bold>" . $stage[AjaxInstallerStage::DURING] . "</fg=blue;options=bold>"); $status = $this->getContainer()->get('core_installer.controller.ajaxupgrade')->commandLineAction($stage[AjaxInstallerStage::NAME]); $message = $status ? "<info>" . $stage[AjaxInstallerStage::SUCCESS] . "</info>" : "<error>" . $stage[AjaxInstallerStage::FAIL] . "</error>"; $output->writeln($message); } $output->writeln("UPGRADE COMPLETE!"); }
/** * Dispatch a module view request. * * @return mixed */ public function dispatch() { if (!SecurityUtil::checkPermission('Extensions::', '::', ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } // Get input. $moduleName = $this->request->getGet()->filter('_module', null, FILTER_SANITIZE_STRING); $pluginName = $this->request->getGet()->filter('_plugin', null, FILTER_SANITIZE_STRING); $action = $this->request->getGet()->filter('_action', null, FILTER_SANITIZE_STRING); // Load plugins. if (!$moduleName) { $type = 'SystemPlugin'; PluginUtil::loadAllSystemPlugins(); } else { $type = 'ModulePlugin'; PluginUtil::loadAllModulePlugins(); } if ($moduleName) { $serviceId = PluginUtil::getServiceId("{$type}_{$moduleName}_{$pluginName}_Plugin"); } else { $serviceId = PluginUtil::getServiceId("{$type}_{$pluginName}_Plugin"); } $this->throwNotFoundUnless($this->serviceManager->hasService($serviceId)); $this->plugin = $this->serviceManager->getService($serviceId); // Sanity checks. $this->throwNotFoundUnless($this->plugin->isInstalled(), __f('Plugin "%s" is not installed', $this->plugin->getMetaDisplayName())); $this->throwForbiddenUnless($this->plugin instanceof Zikula_Plugin_ConfigurableInterface, __f('Plugin "%s" is not configurable', $this->plugin->getMetaDisplayName())); $this->pluginController = $this->plugin->getConfigurationController(); $this->throwNotFoundUnless($this->pluginController->getReflection()->hasMethod($action)); return $this->pluginController->{$action}(); }
function validate(Zikula_Form_View $view) { parent::validate($view); if (!$this->isValid) { return; } if ($this->text != '') { if (!is_dir($this->text) || !is_readable($this->text)) { $this->setError(__f('The path %s does not exist or is not readable by the webserver.', $this->text)); } elseif ($this->writable == true && !is_writable($this->text)) { $this->setError(__f('The webserver cannot write to %s.', $this->text)); } else { if ($this->removeSlash == true) { do { $hasSlash = false; if (StringUtil::right($this->text, 1) == '/') { $hasSlash = true; $this->text = StringUtil::left($this->text, strlen($this->text) - 1); } } while ($hasSlash == true); } } } else { $this->setError(__('Error! Missing path.')); } }
function delete() { // security check if (!SecurityUtil::checkPermission('AddressBook::', '::', ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } $ot = FormUtil::getPassedValue('ot', 'categories', 'GETPOST'); $id = (int) FormUtil::getPassedValue('id', 0, 'GETPOST'); $url = ModUtil::url('AddressBook', 'admin', 'view', array('ot' => $ot)); $class = 'AddressBook_DBObject_' . ucfirst($ot); if (!class_exists($class)) { return z_exit(__f('Error! Unable to load class [%s]', $ot)); } $object = new $class(); $data = $object->get($id); if (!$data) { LogUtil::registerError(__f('%1$s with ID of %2$s doesn\'\\t seem to exist', array($ot, $id))); return System::redirect($url); } $object->delete(); if ($ot == "customfield") { $sql = "ALTER TABLE addressbook_address DROP adr_custom_" . $id; try { DBUtil::executeSQL($sql, -1, -1, true, true); } catch (Exception $e) { } } LogUtil::registerStatus($this->__('Done! Item deleted.')); return System::redirect($url); }
/** * Constructor. * * @param string $message * @param int $code */ public function __construct($message = '', $code = 0) { if (empty($message)) { $message = __f("The requested extension [%s%] is currently unavailable.", __NAMESPACE__); } parent::__construct($message, $code); }
/** * Load a file from the specified location in the file tree * * @param fileName The name of the file to load * @param path The path prefix to use (optional) (default=null) * @param exitOnError whether or not exit upon error (optional) (default=true) * @param returnVar The variable to return from the sourced file (optional) (default=null) * * @return string The file which was loaded */ public static function loadFile($fileName, $path = null, $exitOnError = true, $returnVar = null) { if (!$fileName) { return z_exit(__f("Error! Invalid file specification '%s'.", $fileName)); } $file = null; if ($path) { $file = "{$path}/{$fileName}"; } else { $file = $fileName; } $file = DataUtil::formatForOS($file); if (is_file($file) && is_readable($file)) { if (include_once $file) { if ($returnVar) { return ${$returnVar}; } else { return $file; } } } if ($exitOnError) { return z_exit(__f("Error! Could not load the file '%s'.", $fileName)); } return false; }
/** * Example: * {securityutil_checkpermission component='Users::' instance='.*' level='ACCESS_ADMIN' assign='auth'} * * true/false will be returned. * * This file is a plugin for Zikula_View, the Zikula implementation of Smarty * @param array $params All attributes passed to this function from the template * @param object $smarty Reference to the Smarty object * @return boolean authorized? */ function smarty_function_securityutil_checkpermission($params, $smarty) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('securityutil_checkpermission', 'checkpermission')), E_USER_DEPRECATED); if (!isset($params['component'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('securityutil_checkpermission', 'component'))); return false; } if (!isset($params['instance'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('securityutil_checkpermission', 'instance'))); return false; } if (!isset($params['level'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('securityutil_checkpermission', 'level'))); return false; } $result = SecurityUtil::checkPermission($params['component'], $params['instance'], constant($params['level'])); if (isset($params['assign'])) { $smarty->assign($params['assign'], $result); } else { return $result; } }
/** * Zikula_View function to to execute a PHP callable. * * This plugin can call any PHP callable using x_class + x_method OR x_function * with a list of argument/value pairs. * * * Available parameters: * - x_class: The well-known name of a module to execute a function from (required) * - x_method: The type of function to execute; currently one of 'user' or 'admin' (default is 'user') * - x_function: The name of the module function to execute (default is 'main') * - x_assign: If set, the results are assigned to the corresponding variable instead of printed out * - all remaining parameters are passed to the callable. * * Based on call_user_func_array() * * Example * {callfunc x_class='Foo' x_method='Bar' name='Jane'} * {callfunc x_method='Something' age=21 name='Jane'} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return mixed The results of the callable. */ function smarty_function_callfunc($params, Zikula_View $view) { $assign = (isset($params['x_assign']) && !empty($params['x_assign'])) ? $params['x_assign'] : ''; if (array_key_exists('x_class', $params)) { $class = $params['x_class']; $method = $params['x_method']; } else if (array_key_exists('x_function', $params)) { $function = $params['x_function']; } else { $view->trigger_error(__f('Error! in %1$s: the "class" and "method" parameter must be specified together or just "function" by itself.', array('calluserfunc', 'modname'))); } $callable = (isset($class)) ? array($class, $method) : $function; unset($params['x_class']); unset($params['x_method']); unset($params['x_function']); unset($params['x_assign']); $result = call_user_func_array($callable, $params); if ($assign) { $view->assign($assign, $result); } else { return $result; } }
/** * Obtain the value of one block variable or all block variables for a specified block. * * Note: If the name of the block variable is not set, then the assign parameter * must be set since an array of block variables will be returned. * * Available attributes: * - bid (numeric) The block id * - name (string) The name of the block variable to get, otherwise the * entire block array is assigned is returned. * (required, if the assign attribute is not specified, * otherwise, optional) * - assign (string) The name of the template variable to which the value * is assigned, instead of being output to the template. * (optional if the name attribute is set, otherwise * required) * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * * @return mixed the value of the block variable specified by the name attribute, * or an array containing the full block information. */ function smarty_function_blockgetinfo($params, Zikula_View $view) { $bid = isset($params['bid']) ? (int) $params['bid'] : 0; $name = isset($params['name']) ? $params['name'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; if (!$bid) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockgetinfo', 'bid'))); } // get the block info array $blockinfo = BlockUtil::getBlockInfo($bid); if ($name) { if ($assign) { $view->assign($assign, $blockinfo[$name]); } else { return $blockinfo[$name]; } } else { // handle the full blockinfo array if ($assign) { $view->assign($assign, $blockinfo); } else { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified to get the full block information.', array('pnblockgetinfo', 'assign'))); } } return; }
/** * Zikula_View function to load Zikula_tree. * * Example: * {tree $menuArray=$your_content imagesDir='yout/path/to/images/'} * * @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_tree($params, Zikula_View $view) { $menuString = isset($params['menustring']) ? $params['menustring'] : null; $menuArray = isset($params['menuarray']) ? $params['menuarray'] : null; $treeArray = isset($params['treearray']) ? $params['treearray'] : null; $config = isset($params['config']) ? $params['config'] : array(); if (!isset($menuString) && !isset($menuArray) && !isset($treeArray)) { $view->trigger_error(__f('Error! in %1$s: %2$s, %3$s or %4$s parameter must be specified.', array('smarty_function_tree', 'menustring', 'menuarray', 'treearray'))); return false; } unset($params['menustring']); unset($params['menuarray']); unset($params['treearray']); unset($params['config']); $config = array_merge($config, (array) $params); $tree = new Zikula_Tree($config); if (isset($treeArray)) { $tree->setTreeData($treeArray); } elseif (isset($menuArray)) { $tree->loadArrayData($menuArray); } else { $tree->loadStringData($menuString); } if (isset($params['assign'])) { $view->assign($params['assign'], $tree->getHTML()); } else { return $tree->getHTML(); } }
/** * Send a notification to the poll admin to notify him about an update. * * @param $poll stdClass The poll * @param $mailService MailService The mail service * @param $name string The name user who triggered the notification * @param $type int cf: Constants on the top of this page */ function sendUpdateNotification($poll, $mailService, $name, $type) { if (!isset($_SESSION['mail_sent'])) { $_SESSION['mail_sent'] = []; } if ($poll->receiveNewVotes) { $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', 'Poll\'s participation: %s', $poll->title); $message = $name . ' '; switch ($type) { case UPDATE_VOTE: $message .= __('Mail', "updated a vote.\nYou can find your poll at the link") . " :\n\n"; break; case ADD_VOTE: $message .= __('Mail', "filled a vote.\nYou can find your poll at the link") . " :\n\n"; break; case ADD_COMMENT: $message .= __('Mail', "wrote a comment.\nYou can find your poll at the link") . " :\n\n"; break; } $urlSondage = Utils::getUrlSondage($poll->admin_id, true); $message .= '<a href="' . $urlSondage . '">' . $urlSondage . '</a>' . "\n\n"; $messageTypeKey = $type . '-' . $poll->id; $mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey); } }
/** * Zikula_View function to create manual link. * * This function creates a manual link from some parameters. * * Available parameters: * - manual: name of manual file, manual.html if not set * - chapter: an anchor in the manual file to jump to * - newwindow: opens the manual in a new window using javascript * - width: width of the window if newwindow is set, default 600 * - height: height of the window if newwindow is set, default 400 * - title: name of the new window if newwindow is set, default is modulename * - class: class for use in the <a> tag * - assign: if set, the results ( array('url', 'link') are assigned to the corresponding variable instead of printed out * * Example * {manuallink newwindow=1 width=400 height=300 title=rtfm } * * @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_function_manuallink($params, Zikula_View $view) { LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated.', array('manuallink')), E_USER_DEPRECATED); $userlang = ZLanguage::transformFS(ZLanguage::getLanguageCode()); $stdlang = System::getVar('language_i18n'); $title = isset($params['title']) ? $params['title'] : 'Manual'; $manual = isset($params['manual']) ? $params['manual'] : 'manual.html'; $chapter = isset($params['chapter']) ? '#' . $params['chapter'] : ''; $class = isset($params['class']) ? 'class="' . $params['class'] . '"' : ''; $width = isset($params['width']) ? $params['width'] : 600; $height = isset($params['height']) ? $params['height'] : 400; $modname = ModUtil::getName(); $possibleplaces = array("modules/{$modname}/docs/{$userlang}/manual/{$manual}", "modules/{$modname}/docs/{$stdlang}/manual/{$manual}", "modules/{$modname}/docs/en/manual/{$manual}", "modules/{$modname}/docs/{$userlang}/{$manual}", "modules/{$modname}/docs/{$stdlang}/{$manual}", "modules/{$modname}/docs/lang/en/{$manual}"); foreach ($possibleplaces as $possibleplace) { if (file_exists($possibleplace)) { $url = $possibleplace . $chapter; break; } } if (isset($params['newwindow'])) { $link = "<a {$class} href='#' onclick=\"window.open( '" . DataUtil::formatForDisplay($url) . "' , '" . DataUtil::formatForDisplay($modname) . "', 'status=yes,scrollbars=yes,resizable=yes,width={$width},height={$height}'); picwin.focus();\">" . DataUtil::formatForDisplayHTML($title) . "</a>"; } else { $link = "<a {$class} href=\"" . DataUtil::formatForDisplay($url) . "\">" . DataUtil::formatForDisplayHTML($title) . "</a>"; } if (isset($params['assign'])) { $ret = array('url' => $url, 'link' => $link); $view->assign($params['assign'], $ret); return; } else { return $link; } }
/** * Renders and displays a single Zikula block by blockinfo array or block id. * * Available attributes: * - module (string) The internal name of the module that defines the block. * - blockname (string) The internal name of the block. * - block (int|array) Either the integer block id (bid) of the block, or * an array containing the blockinfo for the block. * - position (string) The position of the block. * - assign (string) If set, the results are assigned to the corresponding * template variable instead of being returned to the template (optional) * * @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 The rendered output of the specified block. */ function smarty_function_blockshow($params, Zikula_View $view) { $module = isset($params['module']) ? $params['module'] : null; $blockname = isset($params['blockname']) ? $params['blockname'] : null; $block = isset($params['block']) ? $params['block'] : null; $position = isset($params['position']) ? $params['position'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; if (!$module) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'module'))); return; } if (!$blockname) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'blockname'))); return; } if (!$block) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'id/info'))); return; } if (!$position) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'position'))); return; } if (!is_array($block)) { $block = BlockUtil::getBlockInfo($block); } $block['position'] = $position; $output = BlockUtil::show($module, $blockname, $block); if ($assign) { $view->assign($assign, $output); } else { return $output; } }
/** * Implement permissions checks in a template. * * Available attributes: * - component (string) The component to be tested, e.g., 'ModuleName::' * - instance (string) The instance to be tested, e.g., 'name::1' * - level (int) The level of access required, e.g., ACCESS_READ * * Example: * <pre> * {secauthaction_block component='News::' instance='1::' level=ACCESS_COMMENT} * do some stuff now that we have permission * {/secauthaction_block} * </pre>. * * @param array $params All attributes passed to this function from the template. * @param string $content The content between the block tags. * @param Smarty &$smarty Reference to the {@link Zikula_View} object. * * @return mixed The content of the block, if the user has the specified * access level for the component and instance, otherwise null; * false on an error. * * @deprecated See {@link smarty_block_securityutil_checkpermission_block}. */ function smarty_block_secauthaction_block($params, $content, &$smarty) { LogUtil::log(__f('Warning! Template block {%1$s} is deprecated, please use {%2$s} instead.', array('secauthaction_block', 'checkpermissionblock')), E_USER_DEPRECATED); if (is_null($content)) { return; } // check our input if (!isset($params['component'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_block_secauthaction_block', 'component'))); return false; } if (!isset($params['instance'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_block_secauthaction_block', 'instance'))); return false; } if (!isset($params['level'])) { $smarty->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('smarty_block_secauthaction_block', 'level'))); return false; } if (!SecurityUtil::checkPermission($params['component'], $params['instance'], constant($params['level']))) { return; } return $content; }
/** * Pop a field of an array and assign its value to a template variable. * * Available attributes: * - array (string) Name of the template array variable to process * - field (string) Name of the array field to assign then unset * - unset (bool) Flag to specify if the field must be unset or not (default: true) * - assign (string) Name of the assign variable to setup (optional) * * Example: * * Having an $objarray in our template, we want to process its fields in different * sections of the template, so we get the needed fields separately on the desired positions, * clearing the array in the process. * * For instance, the $hooks array resulted of notify the 'display_view' hooks, can be * processed individually using this plugin: * * <samp>{array_pop array='hooks' field='EZComments'}</samp> * <samp>{array_pop array='hooks' field='EZComments' assign='comments'}</samp> * * And display later the remaining ones with a foreach. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the {@link Zikula_View} object. * * @return mixed False on failure, void if the value is assigned, or the value extracted itself. */ function smarty_function_array_pop($params, Zikula_View $view) { if (!isset($params['array']) || !$params['array']) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'var'))); return false; } if (!isset($params['field']) || !$params['field']) { $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'value'))); return false; } $unset = isset($params['unset']) ? (bool) $params['unset'] : true; $value = null; $array = $view->getTplVar($params['array']); if ($array && isset($array[$params['field']])) { $value = $array[$params['field']]; if ($unset) { unset($array[$params['field']]); } $view->assign($params['array'], $array); } if (isset($params['assign']) && $params['assign']) { $view->assign($params['assign'], $value); } else { return $value; } }