diff options
| author | lsces <lester@lsces.co.uk> | 2025-08-27 15:38:07 +0100 |
|---|---|---|
| committer | lsces <lester@lsces.co.uk> | 2025-08-27 15:38:07 +0100 |
| commit | 38ee27b2f03d5126766df77ceeac4d8d4e153564 (patch) | |
| tree | 5f2e11dcdd38b43dd00aa20fe9e63f66c6a60c72 | |
| parent | c7151e5754fab3aa6ccd3f5f9ee15e29f0793c00 (diff) | |
| download | themes-38ee27b2f03d5126766df77ceeac4d8d4e153564.tar.gz themes-38ee27b2f03d5126766df77ceeac4d8d4e153564.tar.bz2 themes-38ee27b2f03d5126766df77ceeac4d8d4e153564.zip | |
smarty plugins massaged for Smarty5
87 files changed, 1407 insertions, 704 deletions
diff --git a/smartyplugins/PreTr.php b/smartyplugins/PreTr.php new file mode 100755 index 0000000..1ed16e5 --- /dev/null +++ b/smartyplugins/PreTr.php @@ -0,0 +1,98 @@ +<?php +/** + * Smarty plugin + * @package Smarty + * @subpackage plugins + */ + +/** + * smarty_pre_tr + * + * @param array $source + * @access public + * @return full source with partially treated sections + */ + +namespace Bitweaver\Plugins; +use Smarty\Compile\Modifier\ModifierCompilerInterface; +use Smarty\Compiler\Template; + +class PreTr implements ModifierCompilerInterface { + public function __construct() { + // Initialization code + } + + public function compile($code, Template $template) { + $source = $code[0]; + // Now replace the matched language strings with the entry in the file + // $return = preg_replace_callback( '#\{tr[^\{]*\}([^\{]+)\{/tr\}#', '_translate_lang', $source ); + // + // correction: in order to match when a variable is inside tags. + // Example: The newsletter was sent to {$sent} email addresses, + // and where there are parameters with take away the smarty comments + // {* *} in case they have tr tags + $ret = preg_replace_callback( '#(?s)(\{tr[^\}]*\})(.+?)\{/tr\}#', [ $this, 'translate_lang' ], preg_replace ( '#(?s)\{\*.*?\*\}#', '', $source ) ); + return $ret; + } + + /** + * _translate_lang + * + * @param array $pKey Hash passed in by smarty_prefilter_tr() above + * @param array $pKey[0] starting tag + * @param array $pKey[1] string that needs to be translated + * @param array $pKey[2] flosing tag + * @access protected + * @return string translated string + * + * Note: If you want to have a block interpreted AFTER variable substitution, add a parameter to + * e.g.: {tr post=1}text {$that} needs to be {$evaluated} + */ + private function translate_lang( $pKey ) { + global $gBitLanguage, $lang; + + // this is the original codeblock: + // if (strstr($pKey[2], "{\$")) { + // // We have a variable - keep the tags to be perhaps translated in block.tr.php + // return $pKey[1].$pKey[2].""; + // } elseif ($pKey[1] == "") { + // // no more possible translation in block.tr.php + // return $trans; + // } else { + // // perhaps variable substitution to do in block.tr.php + // return $pKey[1].$trans.""; + // } + // Explanation why this doesn't work: + // - case 1 + // returning stuff like waiting for {$number} ratings + // will get translated by block.tr.php but only after the {$number} has + // been interpreted and we will end up with master strings like: + // waiting for 4 ratings + // waiting for 5 ratings + // waiting for 6 ratings + // + // - case 2 + // this should be fine since it has been translated and the blocks + // have been removed i.e. block.tr.php won't be called anymore + // + // - case 3 + // this will leave everything as is. this will work as well, but only if + // there is no {$var} in the string - see case 1 + // --- xing + + + // if the entire string in is a variable, we pass it on to block.tr.php + // e.g. {$menu.menu_title} in top_bar.tpl + // if you change this regexp, please modify the one in languages/BitLanguage.php as well (approx line 256) + if( preg_match( '!^(\{\$[^\}]*\})+$!', $pKey[2] ) ) { + return $pKey[1].$pKey[2].""; + } elseif( $pKey[1] == "" ) { + // no parameters set for block.tr.php + $trans = $gBitLanguage->translate( $pKey[2] ); + return $trans; + } else { + // perhaps there are parameters set for block.tr.php + return $pKey[1].$pKey[2].""; + } + } +}
\ No newline at end of file diff --git a/smartyplugins/ResourceBitpackage.php b/smartyplugins/ResourceBitpackage.php new file mode 100755 index 0000000..1ac2337 --- /dev/null +++ b/smartyplugins/ResourceBitpackage.php @@ -0,0 +1,140 @@ +<?php +/** + * Smarty plugin + * ------------------------------------------------------------- + * File: resource.bitpackage.php + * Type: resource + * Name: bitpackage + * Purpose: Fetches templates from the correct package + * ------------------------------------------------------------- + * @package Smarty + * @subpackage plugins + */ + + +namespace Bitweaver\Plugins; +use Smarty\Resource\CustomPlugin; +use Smarty\Template\Source; +use Smarty\Template; + +class ResourceBitpackage extends CustomPlugin { + + protected function fetch ( $pTplName, &$pTplSource, &$pTplTime ) { + $resources = $this->getTplLocations( $pTplName ); + foreach( $resources as $location => $resource ) { + if( file_exists( $resource )) { + $pTplSource = file_get_contents( $resource ); + $pTplTime = filemtime( $resource ); + return; + } + } + } + + /** + * THE method to invoke if you want to be sure a tpl's sibling php file gets included if it exists. This + * should not need to be invoked from anywhere except within this class + * + * @param string $pFile file to be included, should be of the form "bitpackage:<packagename>/<templatename>" + * @return void + */ + public function populate(Source $source, ?Template $_template = null) { + global $gBitThemes; + $ret = FALSE; + + if( $siblingPhpFile = static::getSiblingPhpFile( $source->name ) ) { + global $gBitSmarty, $gBitSystem, $gBitUser, $gQueryUserId, $moduleParams; + $moduleParams = []; + if( !empty( $gBitSmarty->tpl_vars[ 'moduleParams'] ) ) { + // Module Params were passed in from the template, like kernel/dynamic.tpl + $moduleParams = $gBitSmarty->tpl_vars[ 'moduleParams' ]; + } +// if( !empty( $moduleParams->module_params ) ) { +// // module_params were passed through via the {include}, +// // e.g. {include file="bitpackage:foobar/mod_list_foo.tpl" module_params="user_id=`$gBitUser->mUserId`&sort_mode=created_desc"} +// $moduleParams['module_params'] = $gBitThemes->parseString( $gBitSmarty->tpl_vars[ 'module_params' ] ?? '' ); +// } + //$_template->templateId = md5(serialize( $moduleParams )); + include $siblingPhpFile; + } + + parent::populate( $source, $_template ); + } + + public static function getSiblingPhpFile( $pTplName ) { + $ret = NULL; + if( preg_match('/mod_/', $pTplName ) || preg_match( '/center_/', $pTplName ) ) { + if( strpos( $pTplName, '/' )) { + list( $package, $modFile ) = explode( '/', $pTplName ); + $subdir = preg_match( '/mod_/', $modFile ) ? 'modules' : 'templates'; + global $gBitSmarty, $gBitSystem, $gBitUser, $gQueryUserId, $moduleParams; + // the PHP sibling file needs to be included here, before the fetch so caching works properly + $modFile = str_replace( '.tpl', '.php', $modFile ); + + $path = constant( strtoupper( $package )."_PKG_PATH" ); + $includeFile = "$path$subdir/$modFile"; + + if( file_exists( $includeFile )) { + $ret = $includeFile; + } + } + } + return $ret; + } + + + protected function fetchTimestamp( $pTplName ) { + $ret = FALSE; + $locations = $this->getTplLocations( $pTplName ); + foreach( $locations as $resource ) { + if( file_exists( $resource )) { + $ret = filemtime( $resource ); + break; + } + } + return $ret; + } + + private function getTplLocations( $pTplName ) { + global $gBitThemes, $gNoForceStyle; + + $path = explode( '/', $pTplName ); + $package = array_shift( $path ); + $template = array_pop( $path ); + $subdir = ''; + foreach( $path as $p ) { + $subdir .= $p.'/'; + } + + // files found in temp are special - these are stored in temp/<pkg>/(templates|modules)/<template.tpl> + if( $package == 'temp' ) { + // if it's a module, we need to look in the correct place + $subdir .= preg_match( '/\b(help_)?mod_/', $template ) ? 'modules' : 'templates'; + // we can't override these templates - they only exist in temp + $ret['package_template'] = constant( strtoupper( $package ).'_PKG_PATH' )."$subdir/$template"; + } else { + if( empty( $gNoForceStyle )) { + // look in config/themes/force/ + $ret['force'] = CONFIG_PKG_PATH."themes/force/$package/$subdir$template"; + $ret['force_simple'] = CONFIG_PKG_PATH."themes/force/$subdir$template"; + } + + // look in themes/style/<stylename>/ + $ret['override'] = $gBitThemes->getStylePath()."$package/$subdir$template"; + $ret['override_simple'] = $gBitThemes->getStylePath().$subdir.$template; + + // if it's a module, we need to look in the correct place + $subdir = ( preg_match( '/\b(help_)?mod_/', $template ) ? 'modules' : 'templates' )."/".$subdir; + + // look for default package template +// if ( $package <> 'downloads' ) { + $ret['package_template'] = constant( strtoupper( $package ).'_PKG_PATH' )."$subdir$template"; +// } + } + + return $ret; + } + + public function getContent(Source $source) { + return parent::getContent($source); + } +}
\ No newline at end of file diff --git a/smartyplugins/compiler.set.php b/smartyplugins/compiler.set.php index 16c4f76..617a616 100644..100755 --- a/smartyplugins/compiler.set.php +++ b/smartyplugins/compiler.set.php @@ -1,8 +1,11 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty {set} compiler function plugin * - * File: compiler.set.php + * File: compiler.set.<?php + * Type: compiler function * Name: set * Purpose: Set a value to a variable (also arrays). @@ -13,7 +16,7 @@ * @link http://www.dav-muz.net/ * @version 1.0 * @copyright Copyright 2006 by Muzzarelli Davide - * @author Davide Muzzarelli <info@dav-muz.net> + * @author Davide Muzzarelli <info@dav-muz.ne * * @package kernel * @subpackage plugins @@ -67,5 +70,3 @@ function smarty_compiler_set($params, &$smarty) { return "{$params['var']} = {$params['value']};"; } } -?> - diff --git a/smartyplugins/function.adsense.php b/smartyplugins/function.adsense.php index 83eee91..e4e31ed 100644..100755 --- a/smartyplugins/function.adsense.php +++ b/smartyplugins/function.adsense.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -16,4 +18,3 @@ function smarty_function_adsense( $params, &$gBitSmarty ) { echo "You need to activate the adsense liberty plugin to use this."; } } -?> diff --git a/smartyplugins/function.alphabar.php b/smartyplugins/function.alphabar.php index b4fce89..cdf4daa 100644..100755 --- a/smartyplugins/function.alphabar.php +++ b/smartyplugins/function.alphabar.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -24,21 +26,13 @@ function smarty_function_alphabar( $params, &$gBitSmarty ) { extract( $params ); // work out what the url is - if( isset( $ifile ) ) { - if( isset( $ipackage ) ) { - if( $ipackage == 'root' ) { - $url = BIT_ROOT_URL.$ifile; - } else { - $url = constant( strtoupper( $ipackage ).'_PKG_URL' ).$ifile; - } - } else { - $url = constant( strtoupper( $gBitSystem->getActivePackage() ).'_PKG_URL' ).$ifile; - } - } else { - $url = $_SERVER['SCRIPT_NAME']; - } + $url = isset( $ifile ) + ? ( isset( $ipackage ) + ? ( $ipackage == 'root' ? BIT_ROOT_URL.$ifile : constant( strtoupper( $ipackage ).'_PKG_URL' ).$ifile ) + : constant( strtoupper( $gBitSystem->getActivePackage() ).'_PKG_URL' ).$ifile ) + : $_SERVER['SCRIPT_NAME']; - $alphabar_params = array( 'ifile', 'ipackage', 'iall' ); + $alphabar_params = [ 'ifile', 'ipackage', 'iall' ]; // append any other paramters that were passed in $url_params = ''; foreach( $params as $key => $val ) { @@ -48,7 +42,7 @@ function smarty_function_alphabar( $params, &$gBitSmarty ) { } $ret = '<div class="pagination alphabar">'; - $alpha = 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','0-9','+' ); + $alpha = [ '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','0-9','+' ]; foreach( $alpha as $char ) { if( empty( $iskip ) || !in_array( $char, $iskip )) { $wrap = array( 'open' => '', 'close' => '' ); @@ -66,4 +60,3 @@ function smarty_function_alphabar( $params, &$gBitSmarty ) { return $ret; } -?> diff --git a/smartyplugins/function.attachhelp.php b/smartyplugins/function.attachhelp.php index 73524ae..a9cdc89 100644..100755 --- a/smartyplugins/function.attachhelp.php +++ b/smartyplugins/function.attachhelp.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -8,8 +10,8 @@ /** * smarty_function_attachmenthelp */ -function smarty_function_attachhelp( $pParams, &$gBitSmarty ) { - global $gBitSystem; +function smarty_function_attachhelp( $pParams, &$gSmartyTemplate ) { + global $gBitSystem, $gBitSmarty; // print legend if desired if( !empty( $pParams['legend'] )) { @@ -40,4 +42,3 @@ function smarty_function_attachhelp( $pParams, &$gBitSmarty ) { $gBitSmarty->assign( 'attachhelp', $attachhelp ); return $gBitSmarty->fetch( 'bitpackage:liberty/attachhelp.tpl' ); } -?> diff --git a/smartyplugins/function.banner.php b/smartyplugins/function.banner.php index c80d73c..efe196c 100644..100755 --- a/smartyplugins/function.banner.php +++ b/smartyplugins/function.banner.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -11,9 +13,9 @@ function smarty_function_banner($params, &$gBitSmarty) { global $gBitSystem; - include_once( BANNERS_PKG_PATH.'banner_lib.php' ); + include_once BANNERS_PKG_PATH.'banner_lib.php'; if(!isset($bannerlib)) { - $bannerlib = new BannerLib(); + $bannerlib = new \Bitweaver\BannerLib(); } extract($params); @@ -24,9 +26,6 @@ function smarty_function_banner($params, &$gBitSmarty) return; } $banner = $bannerlib->select_banner($zone); - print($banner); + print $banner; } -/* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.bit_html_options.php b/smartyplugins/function.bit_html_options.php new file mode 100755 index 0000000..d53ad82 --- /dev/null +++ b/smartyplugins/function.bit_html_options.php @@ -0,0 +1,216 @@ +<?php +namespace Bitweaver\Plugins; + +/** + * Smarty {html_options} function plugin + * Type: function + * Name: html_options + * Purpose: Prints the list of <option> tags generated from + * the passed parameters + * Params: + * + * - name (optional) - string default "select" + * - values (required) - if no options supplied) - array + * - options (required) - if no values supplied) - associative array + * - selected (optional) - string default not set + * - output (required) - if not options supplied) - array + * - id (optional) - string default not set + * - class (optional) - string default not set + * + * @author Monte Ohrt <monte at ohrt dot com> + * @author Ralf Strehle (minor optimization) <ralf dot strehle at yahoo dot de> + * + * @param array $params parameters + * + * @return string + * @uses smarty_function_escape_special_chars() + * @throws \Smarty\Exception + */ +function smarty_function_bit_html_options($params) { + $name = null; + $values = null; + $options = null; + $selected = null; + $output = null; + $id = null; + $class = null; + $extra = ''; + foreach ($params as $_key => $_val) { + switch ($_key) { + case 'name': + case 'class': + case 'id': + $$_key = (string)$_val; + break; + case 'options': + $options = (array)$_val; + break; + case 'values': + case 'output': + $$_key = array_values((array)$_val); + break; + case 'selected': + if (is_array($_val)) { + $selected = []; + foreach ($_val as $_sel) { + if (is_object($_sel)) { + if (method_exists($_sel, '__toString')) { + $_sel = smarty_function_escape_special_chars((string)$_sel->__toString()); + } else { + trigger_error( + 'html_options: selected attribute contains an object of class \'' . + get_class($_sel) . '\' without __toString() method', + E_USER_NOTICE + ); + continue; + } + } else { + $_sel = smarty_function_escape_special_chars((string)$_sel); + } + $selected[$_sel] = true; + } + } elseif (is_object($_val)) { + if (method_exists($_val, '__toString')) { + $selected = smarty_function_escape_special_chars((string)$_val->__toString()); + } else { + trigger_error( + 'html_options: selected attribute is an object of class \'' . get_class($_val) . + '\' without __toString() method', + E_USER_NOTICE + ); + } + } else { + $selected = smarty_function_escape_special_chars((string)$_val); + } + break; + case 'strict': + break; + case 'disabled': + case 'readonly': + if (!empty($params['strict'])) { + if (!is_scalar($_val)) { + trigger_error( + "html_options: {$_key} attribute must be a scalar, only boolean true or string '{$_key}' will actually add the attribute", + E_USER_NOTICE + ); + } + if ($_val === true || $_val === $_key) { + $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; + } + break; + } + // omit break; to fall through! + // no break + default: + if (!is_array($_val)) { + $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; + } else { + trigger_error("html_options: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); + } + break; + } + } + if (!isset($options) && !isset($values)) { + /* raise error here? */ + return ''; + } + $_html_result = ''; + $_idx = 0; + if (isset($options)) { + foreach ($options as $_key => $_val) { + $_html_result .= \Bitweaver\Plugins\getHtmlOutput($_key, $_val, $selected, $id, $class, $_idx); + } + } else { + foreach ($values as $_i => $_key) { + $_val = $output[$_i] ?? ''; + $_html_result .= \Bitweaver\Plugins\getHtmlOutput($_key, $_val, $selected, $id, $class, $_idx); + } + } + if (!empty($name)) { + $_html_class = !empty($class) ? ' class="' . $class . '"' : ''; + $_html_id = !empty($id) ? ' id="' . $id . '"' : ''; + $_html_result = + '<select name="' . $name . '"' . $_html_class . $_html_id . $extra . '>' . "\n" . $_html_result . + '</select>' . "\n"; + } + return $_html_result; + } + + + /** + * @param $key + * @param $value + * @param $selected + * @param $id + * @param $class + * @param $idx + * + * @return string + */ + function getHtmlOutput($key, $value, $selected, $id, $class, &$idx) + { + if (!is_array($value)) { + $_key = smarty_function_escape_special_chars($key); + $_html_result = '<option value="' . $_key . '"'; + if (is_array($selected)) { + if (isset($selected[ $_key ])) { + $_html_result .= ' selected="selected"'; + } + } elseif ($_key === $selected) { + $_html_result .= ' selected="selected"'; + } + $_html_class = !empty($class) ? ' class="' . $class . ' option"' : ''; + $_html_id = !empty($id) ? ' id="' . $id . '-' . $idx . '"' : ''; + if (is_object($value)) { + if (method_exists($value, '__toString')) { + $value = smarty_function_escape_special_chars((string)$value->__toString()); + } else { + trigger_error( + 'html_options: value is an object of class \'' . get_class($value) . + '\' without __toString() method', + E_USER_NOTICE + ); + return ''; + } + } else { + $value = smarty_function_escape_special_chars((string)$value); + } + $_html_result .= $_html_class . $_html_id . '>' . $value . '</option>' . "\n"; + $idx++; + } else { + $_idx = 0; + $_html_result = + \Bitweaver\Plugins\getHtmlForOptGroup( + $key, + $value, + $selected, + !empty($id) ? ($id . '-' . $idx) : null, + $class, + $_idx + ); + $idx++; + } + return $_html_result; + } + + /** + * @param $key + * @param $values + * @param $selected + * @param $id + * @param $class + * @param $idx + * + * @return string + */ + function getHtmlForOptGroup($key, $values, $selected, $id, $class, &$idx) + { + $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n"; + foreach ($values as $key => $value) { + $optgroup_html .= \Bitweaver\Plugins\getHtmlOutput($key, $value, $selected, $id, $class, $idx); + } + $optgroup_html .= "</optgroup>\n"; + return $optgroup_html; + } + + diff --git a/smartyplugins/function.bit_select_datetime.php b/smartyplugins/function.bit_select_datetime.php index f1337db..2260cad 100644..100755 --- a/smartyplugins/function.bit_select_datetime.php +++ b/smartyplugins/function.bit_select_datetime.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @@ -58,22 +60,22 @@ function smarty_function_bit_select_datetime( $pParams, &$gBitSmarty ) { //It is the readonly input field that will be evaluated back on the server //unsupported $format = preg_replace( "/%Z/", "", $format ); // JSCalendar does not know about time zones - $html_result = "<input type=\"text\" name=\"$name\" id=\"${nname}_id\" value=\"$time\" readonly />\n"; - $html_result = $html_result . "<button type=\"reset\" id=\"${nname}_button\">...</button>\n"; - $html_result = $html_result . "<script type=\"text/javascript\">\n"; - $html_result = $html_result . " Calendar.setup({\n"; - $html_result = $html_result . " date : \"$time\",\n"; - $html_result = $html_result . " inputField : \"${nname}_id\", // id of the input field\n"; - $html_result = $html_result . " ifFormat : \"%Y-%m-%d %H:%M\", // format of the input field\n"; - $html_result = $html_result . " showsTime : $showtime, // will display a time selector\n"; - $html_result = $html_result . " button : \"${nname}_button\", // trigger for the calendar (button ID)\n"; - $html_result = $html_result . " singleClick : true, // double-click mode\n"; - $html_result = $html_result . " step : 1 // show all years in drop-down boxes (instead of every other year as default)\n"; - $html_result = $html_result . " });\n"; - $html_result = $html_result . "</script>\n"; + $html_result = "<input type=\"text\" name=\"$name\" id=\"{$nname}_id\" value=\"$time\" readonly />\n"; + $html_result .= "<button type=\"reset\" id=\"{$nname}_button\">...</button>\n"; + $html_result .= "<script type=\"text/javascript\">\n"; + $html_result .= " Calendar.setup({\n"; + $html_result .= " date : \"$time\",\n"; + $html_result .= " inputField : \"{$nname}_id\", // id of the input field\n"; + $html_result .= " ifFormat : \"%Y-%m-%d %H:%M\", // format of the input field\n"; + $html_result .= " showsTime : $showtime, // will display a time selector\n"; + $html_result .= " button : \"{$nname}_button\", // trigger for the calendar (button ID)\n"; + $html_result .= " singleClick : true, // double-click mode\n"; + $html_result .= " step : 1 // show all years in drop-down boxes (instead of every other year as default)\n"; + $html_result .= " });\n"; + $html_result .= "</script>\n"; } else { - $gBitSmarty->loadPlugin( 'smarty_modifier_html_select_date' ); - $gBitSmarty->loadPlugin( 'smarty_modifier_html_select_time' ); + // $gBitSmarty->loadPlugin( 'smarty_modifier_html_select_date' ); + // $gBitSmarty->loadPlugin( 'smarty_modifier_html_select_time' ); // we use html_select_date and html_select_time to pick a date, which generate a number of select fields. //On every change a hidden field will be updated via javascript. @@ -81,32 +83,32 @@ function smarty_function_bit_select_datetime( $pParams, &$gBitSmarty ) { $pDate = array ( 'prefix' => $nname, - 'all_extra' => "onchange=\"bit_select_datetime_${nname}()\"", + 'all_extra' => "onchange=\"bit_select_datetime_{$nname}()\"", 'time' => $time ); $pTime = array ( 'prefix' => $nname, - 'all_extra' => "onchange=\"bit_select_datetime_${nname}()\"", + 'all_extra' => "onchange=\"bit_select_datetime_{$nname}()\"", 'display_seconds' => false, 'time' => $time ); - $html_result = "<input type=\"hidden\" name=\"$name\" value=\"${time}\">"; + $html_result = "<input type=\"hidden\" name=\"$name\" value=\"{$time}\">"; $html_result .= smarty_function_html_select_date( $pDate, $gBitSmarty ); if( $showtime == 'true' ) { $html_result .= smarty_function_html_select_time( $pTime, $gBitSmarty ); $html_result .= "<script type=\"text/javascript\"> \n"; - $html_result .= " function bit_select_datetime_${nname} () {\n"; - $html_result .= " var date = new Date(); \n date.setHours ( document.getElementsByName(\"${nname}Hour\")[0].value);\ndate.setMinutes( document.getElementsByName(\"${nname}Minute\")[0].value); \n date.setFullYear(document.getElementsByName(\"${nname}Year\")[0].value,document.getElementsByName(\"${nname}Month\")[0].value-1,document.getElementsByName(\"${nname}Day\")[0].value); \n "; - $html_result .= "document.getElementsByName(\"${name}\")[0].value = Math.floor(date.getTime() / 1000);"; + $html_result .= " function bit_select_datetime_{$nname} () {\n"; + $html_result .= " var date = new Date(); \n date.setHours ( document.getElementsByName(\"{$nname}Hour\")[0].value);\ndate.setMinutes( document.getElementsByName(\"{$nname}Minute\")[0].value); \n date.setFullYear(document.getElementsByName(\"{$nname}Year\")[0].value,document.getElementsByName(\"{$nname}Month\")[0].value-1,document.getElementsByName(\"{$nname}Day\")[0].value); \n "; + $html_result .= "document.getElementsByName(\"{$name}\")[0].value = Math.floor(date.getTime() / 1000);"; $html_result .= "}\n"; $html_result .= "</script>\n"; } else { $html_result .= "<script type=\"text/javascript\">\n"; - $html_result .= " function bit_select_datetime_${name} () {\n"; - $html_result .= " var date = new Date(); \n date.setDate( document.getElementsByName(\"${nname}Day\")[0].value ); \n date.setMonth(document.getElementsByName(\"${nname}Month\")[0].value-1); \n date.setFullYear(document.getElementsByName(\"${nname}Year\")[0].value); \n "; - $html_result .= " document.getElementsByName(\"${name}\")[0].value = Math.floor(date.getTime() / 1000);"; + $html_result .= " function bit_select_datetime_{$name} () {\n"; + $html_result .= " var date = new Date(); \n date.setDate( document.getElementsByName(\"{$nname}Day\")[0].value ); \n date.setMonth(document.getElementsByName(\"{$nname}Month\")[0].value-1); \n date.setFullYear(document.getElementsByName(\"{$nname}Year\")[0].value); \n "; + $html_result .= " document.getElementsByName(\"{$name}\")[0].value = Math.floor(date.getTime() / 1000);"; $html_result .= "}\n"; $html_result .= "</script>\n"; } @@ -114,4 +116,3 @@ function smarty_function_bit_select_datetime( $pParams, &$gBitSmarty ) { return $html_result."(".$gBitUser->getPreference('site_display_utc').")\n"; } -?> diff --git a/smartyplugins/function.bithelp.php b/smartyplugins/function.bithelp.php index b64c241..b0628a6 100644..100755 --- a/smartyplugins/function.bithelp.php +++ b/smartyplugins/function.bithelp.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -8,7 +10,7 @@ /** * source elements */ -require_once('function.booticon.php'); + /** * smarty_function_bithelp */ @@ -17,10 +19,10 @@ function smarty_function_bithelp($params, &$gBitSmarty) { $outstr = ""; if( $gBitSystem->isFeatureActive('site_online_help') ){ if($gBitUser->hasPermission( 'p_admin' )){ - $outstr .= "<a href=\"".KERNEL_PKG_URL."admin/index.php\">".smarty_function_booticon(array('iname'=>'fa-gears', 'iexplain'=>'Administration Menu'),$gBitSmarty)."</a> "; + $outstr .= "<a href=\"".KERNEL_PKG_URL."admin/index.php\">".smarty_function_booticon(array('ipackage'=>'icons', 'iname'=>'icon-cogs', 'iexplain'=>'Administration Menu') )."</a> "; } if( $helpInfo = $gBitSmarty->getTemplateVars('TikiHelpInfo') ) { - $outstr .= "<a href=\"".$helpInfo["URL"]."\" >".smarty_function_booticon(array('iname'=>'fa-circle-question', 'iexplain'=>(empty($helpInfo["Desc"])?"help":$helpInfo["Desc"])),$gBitSmarty)."</a>"; + $outstr .= "<a href=\"".$helpInfo["URL"]."\" >".smarty_function_booticon(array('ipackage'=>'icons', 'iname'=>'icon-question-sign', 'iexplain'=>(empty($helpInfo["Desc"])?"help":$helpInfo["Desc"])) )."</a>"; } } return $outstr; diff --git a/smartyplugins/function.biticon.php b/smartyplugins/function.biticon.php index d902e84..038a467 100644..100755 --- a/smartyplugins/function.biticon.php +++ b/smartyplugins/function.biticon.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; + /** * Smarty plugin * @package Smarty @@ -10,20 +13,15 @@ * biticon_first_match * * @param string $pDir Directory in which we want to search for the icon - * @param array $pFilename Icon name without the extension + * @param string $pFilename Icon name without the extension * @access public - * @return Icon name with extension on success, FALSE on failure + * @return string|bool Icon name with extension on success, false on failure */ function biticon_first_match( $pDir, $pFilename ) { if( is_dir( $pDir )) { global $gSniffer; - // if this is MSIE < 7, we try png last. - if( $gSniffer->_browser_info['browser'] == 'ie' && $gSniffer->_browser_info['maj_ver'] < 7 ) { - $extensions = array( 'gif', 'jpg', 'png' ); - } else { - $extensions = array( 'png', 'gif', 'jpg' ); - } + $extensions = [ 'png', 'gif', 'jpg' ]; foreach( $extensions as $ext ) { if( is_file( $pDir.$pFilename.'.'.$ext ) ) { @@ -31,26 +29,26 @@ function biticon_first_match( $pDir, $pFilename ) { } } } - return FALSE; + return false; } /** * Turn collected information into an html image * - * @param boolean $pParams['url'] set to TRUE if you only want the url and nothing else - * @param string $pParams['iexplain'] Explanation of what the icon represents - * @param string $pParams['iforce'] takes following optins: icon, icon_text, text - will override system settings - * @param string $pFile Path to icon file - * @param string iforce override site-wide setting how to display icons (can be set to 'icon', 'text' or 'icon_text') - * @access public - * @return Full <img> on success + * @param array $pParams + * @var boolean ['url'] set to true if you only want the url and nothing else + * @var string ['iexplain'] Explanation of what the icon represents + * @var string ['iclass'] + * @var string ['iforce'] override site-wide setting how to display icons (can be set to 'icon', 'text' or 'icon_text') + * @var string $pFile Path to icon file + * @return string Full <img> on success */ function biticon_output( $pParams, $pFile ) { global $gBitSystem; - $iexplain = isset( $pParams["iexplain"] ) ? tra( $pParams["iexplain"] ) : 'please set iexplain'; + $iexplain = isset( $pParams["iexplain"] ) ? KernelTools::tra( $pParams["iexplain"] ) : 'please set iexplain'; if( empty( $pParams['iforce'] )) { - $pParams['iforce'] = NULL; + $pParams['iforce'] = 'none'; } if( isset( $pParams["url"] )) { @@ -61,12 +59,12 @@ function biticon_output( $pParams, $pFile ) { } else { $outstr='<img src="'.$pFile.'"'; if( isset( $pParams["iexplain"] ) ) { - $outstr .= ' alt="'.tra( $pParams["iexplain"] ).'" title="'.tra( $pParams["iexplain"] ).'"'; + $outstr .= ' alt="'.KernelTools::tra( $pParams["iexplain"] ).'" title="'.KernelTools::tra( $pParams["iexplain"] ).'"'; } else { $outstr .= ' alt=""'; } - $ommit = array( 'ilocation', 'ipackage', 'ipath', 'iname', 'iexplain', 'iforce', 'istyle', 'iclass' ); + $ommit = [ 'ilocation', 'ipackage', 'ipath', 'iname', 'iexplain', 'iforce', 'istyle', 'iclass' ]; foreach( $pParams as $name => $val ) { if( !in_array( $name, $ommit ) ) { $outstr .= ' '.$name.'="'.$val.'"'; @@ -93,7 +91,7 @@ function biticon_output( $pParams, $pFile ) { if( !preg_match( "#^broken\.#", $pFile )) { if( !biticon_write_cache( $pParams, $outstr )) { - echo tra( 'There was a problem writing the icon cache file' ); + echo KernelTools::tra( 'There was a problem writing the icon cache file' ); } } @@ -103,25 +101,23 @@ function biticon_output( $pParams, $pFile ) { /** * smarty_function_biticon * - * @param array $pParams['ipath'] subdirectory within icon directory - * @param array $pParams['iname'] name of the icon without extension - * @param array $pParams['ipackage'] package the icon should be searched for - if it's part of an icon theme, this should be set to 'icons' - * @param array $pCheckSmall look for a small render of the image + * @param array $pParams + * @var boolean ['url'] set to true if you only want the url and nothing else + * @var string ['iexplain'] Explanation of what the icon represents + * @var string ['iclass'] + * @var string ['iforce'] override site-wide setting how to display icons (can be set to 'icon', 'text' or 'icon_text') + * @param bool $pCheckSmall look for a small render of the image * @access public - * @return final <img> + * @return string final <img> */ -function smarty_function_biticon( $pParams, $pSmall=NULL ) { +function smarty_function_biticon( $pParams, $pSmall = false ) { global $gBitSystem, $gBitThemes, $gSniffer; // this is needed in case everything goes horribly wrong $copyParams = $pParams; // ensure that ipath has a leading and trailing slash - if( !empty( $pParams['ipath'] )) { - $pParams['ipath'] = str_replace( "//", "/", "/".$pParams['ipath']."/" ); - } else { - $pParams['ipath'] = '/'; - } + $pParams['ipath'] = !empty( $pParams['ipath'] ) ? str_replace( "//", "/", "/".$pParams['ipath']."/" ) : '/'; // try to separate iname from ipath if we've been given some sloppy naming if( strstr( $pParams['iname'], '/' )) { @@ -158,11 +154,7 @@ function smarty_function_biticon( $pParams, $pSmall=NULL ) { } // make sure ipackage is set correctly - if( !empty( $pParams['ipackage'] )) { - $pParams['ipackage'] = strtolower( $pParams['ipackage'] ); - } else { - $pParams['ipackage'] = 'icons'; - } + $pParams['ipackage'] = !empty( $pParams['ipackage'] ) ? strtolower( $pParams['ipackage'] ?? '' ) :'icons'; // if the user is using a text-browser we force text instead of icons if( $gSniffer->_browser_info['browser'] == 'lx' || $gSniffer->_browser_info['browser'] == 'li' ) { @@ -170,7 +162,7 @@ function smarty_function_biticon( $pParams, $pSmall=NULL ) { } // get out of here as quickly as possible if we've already cached the icon information before - if(( $ret = biticon_read_cache( $pParams )) && !( defined( 'TEMPLATE_DEBUG' ) && TEMPLATE_DEBUG == TRUE )) { + if(( $ret = biticon_read_cache( $pParams )) && !( defined( 'TEMPLATE_DEBUG' ) && TEMPLATE_DEBUG == true )) { return $ret; } @@ -181,11 +173,11 @@ function smarty_function_biticon( $pParams, $pSmall=NULL ) { // violators will be poked with soft cushions by the Cardinal himself!!! $icon_style = !empty( $pParams['istyle'] ) ? $pParams['istyle'] : $gBitSystem->getConfig( 'site_icon_style', DEFAULT_ICON_STYLE ); - if( FALSE !== ( $matchFile = biticon_first_match( CONFIG_PKG_PATH."iconsets/$icon_style".$pParams['ipath'], $pParams['iname'] ))) { + if( false !== ( $matchFile = biticon_first_match( CONFIG_PKG_PATH."iconsets/$icon_style".$pParams['ipath'], $pParams['iname'] ))) { return biticon_output( $pParams, CONFIG_PKG_URL."iconsets/$icon_style".$pParams['ipath'].$matchFile ); } - if( $icon_style != DEFAULT_ICON_STYLE && FALSE !== ( $matchFile = biticon_first_match( CONFIG_PKG_PATH."iconsets/".DEFAULT_ICON_STYLE.$pParams['ipath'], $pParams['iname'] ))) { + if( $icon_style != DEFAULT_ICON_STYLE && false !== ( $matchFile = biticon_first_match( CONFIG_PKG_PATH."iconsets/".DEFAULT_ICON_STYLE.$pParams['ipath'], $pParams['iname'] ))) { return biticon_output( $pParams, CONFIG_PKG_URL."iconsets/".DEFAULT_ICON_STYLE.$pParams['ipath'].$matchFile ); } @@ -197,34 +189,34 @@ function smarty_function_biticon( $pParams, $pSmall=NULL ) { // since package icons reside in <pkg>/icons/ we don't need the small/ subdir if( strstr( "/small/", $pParams['ipath'] )) { $pParams['ipath'] = str_replace( "small/", "", $pParams['ipath'] ); - $small = TRUE; + $small = true; } // first check themes/force - if( FALSE !== ( $matchFile = biticon_first_match( THEMES_PKG_PATH."force/icons/".$pParams['ipackage'].$pParams['ipath'], $pParams['iname'] ))) { + if( false !== ( $matchFile = biticon_first_match( THEMES_PKG_PATH."force/icons/".$pParams['ipackage'].$pParams['ipath'], $pParams['iname'] ))) { return biticon_output( $pParams, BIT_ROOT_URL."themes/force/icons/".$pParams['ipackage'].$pParams['ipath'].$matchFile ); } //if we have site styles, look there - if( FALSE !== ( $matchFile = biticon_first_match( $gBitThemes->getStylePath().'/icons/'.$pParams['ipackage'].$pParams['ipath'], $pParams['iname'] ))) { - return biticon_output( $pParams, $gBitThemes->getStyleUrl().'/icons/'.$pParams['ipackage'].$pParams['ipath'].$matchFile ); + if( false !== ( $matchFile = biticon_first_match( $gBitThemes->getStylePath().'icons/'.$pParams['ipackage'].$pParams['ipath'], $pParams['iname'] ))) { + return biticon_output( $pParams, $gBitThemes->getStyleUrl().'icons/'.$pParams['ipackage'].$pParams['ipath'].$matchFile ); } //Well, then lets look in the package location - if( FALSE !== ( $matchFile = biticon_first_match( constant( strtoupper( $pParams['ipackage'] ).'_PKG_PATH' )."icons".$pParams['ipath'], $pParams['iname'] ))) { + if( false !== ( $matchFile = biticon_first_match( constant( strtoupper( $pParams['ipackage'] ).'_PKG_PATH' )."icons".$pParams['ipath'], $pParams['iname'] ))) { return biticon_output( $pParams, constant( strtoupper( $pParams['ipackage'] ).'_PKG_URL' )."icons".$pParams['ipath'].$matchFile ); } - // Still didn't find it! Well lets output something (return FALSE if only the url is requested) + // Still didn't find it! Well lets output something (return empty string if only the url is requested) if( isset( $pParams['url'] )) { - return FALSE; + return ''; } else { if( empty( $pSmall ) ) { // if we were looking for the large icon, we'll try the whole kaboodle again, looking for the small icon - $copyParams['ipath'] = preg_replace( "!/.*?/$!", "/small/", $copyParams['ipath'] ); - return smarty_function_biticon( $copyParams, TRUE ); + $copyParams['ipath'] = preg_replace( "!/.*?/$!", "/small/", $pParams['ipath'] ); + return smarty_function_biticon( $copyParams, true ); } else { - return biticon_output( $pParams, NULL ); + return biticon_output( $pParams, '' ); } } } @@ -234,10 +226,10 @@ function smarty_function_biticon( $pParams, $pSmall=NULL ) { * * @param array $pParams * @access public - * @return cached icon string on sucess, FALSE on failure + * @return string cached icon string on sucess, false on failure */ function biticon_read_cache( $pParams ) { - $ret = FALSE; + $ret = false; $cacheFile = biticon_get_cache_file( $pParams ); if( is_readable( $cacheFile )) { if( $h = fopen( $cacheFile, 'r' )) { @@ -254,10 +246,10 @@ function biticon_read_cache( $pParams ) { * * @param array $pParams * @access public - * @return TRUE on success, FALSE on failure + * @return bool true on success, false on failure */ function biticon_write_cache( $pParams, $pCacheString ) { - $ret = FALSE; + $ret = false; if( $cacheFile = biticon_get_cache_file( $pParams )) { if( $h = fopen( $cacheFile, 'w' )) { $ret = fwrite( $h, $pCacheString ); @@ -265,7 +257,7 @@ function biticon_write_cache( $pParams, $pCacheString ) { } } - return( $ret != 0 ); + return $ret; } /** @@ -273,17 +265,17 @@ function biticon_write_cache( $pParams, $pCacheString ) { * * @param array $pParams * @access public - * @return full path to cachefile + * @return string full path to cachefile */ function biticon_get_cache_file( $pParams ) { global $gBitThemes, $gBitSystem; // create a hash filename based on the parameters given $hashstring = ''; - $ihash = array( 'iforce', 'ipath', 'iname', 'iexplain', 'ipackage', 'url', 'istyle', 'id', 'style', 'onclick' ); + $ihash = [ 'iforce', 'ipath', 'iname', 'iexplain', 'ipackage', 'url', 'istyle', 'id', 'style', 'onclick' ]; foreach( $pParams as $param => $value ) { - if( in_array( $param, $ihash ) && is_string( $value ) ) { - $hashstring .= strtolower( $value ); + if( in_array( $param, $ihash )) { + $hashstring .= strtolower( $value ?? '' ); } } diff --git a/smartyplugins/function.booticon.php b/smartyplugins/function.booticon.php index 330c44e..5260ea2 100644..100755 --- a/smartyplugins/function.booticon.php +++ b/smartyplugins/function.booticon.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,19 +11,20 @@ /** * Turn collected information into an html image * - * @param boolean $pParams['url'] set to TRUE if you only want the url and nothing else - * @param string $pParams['iexplain'] Explanation of what the icon represents - * @param string $pParams['iforce'] takes following optins: icon, icon_text, text - will override system settings - * @param string $pFile Path to icon file - * @param string iforce override site-wide setting how to display icons (can be set to 'icon', 'text' or 'icon_text') + * @param array $pParams parameter hash + * @var boolean $pParams['url'] set to TRUE if you only want the url and nothing else + * @var string $pParams['iexplain'] Explanation of what the icon represents + * @var string $pParams['iforce'] takes following optins: icon, icon_text, text - will override system settings + * @var string $pFile Path to icon file + * @var string iforce override site-wide setting how to display icons (can be set to 'icon', 'text' or 'icon_text') * @access public - * @return Full <img> on success + * @return string Full <img> on success */ function smarty_function_booticon( $pParams ) { global $gBitSystem; if( empty( $pParams['iforce'] )) { - $pParams['iforce'] = NULL; + $pParams['iforce'] = ''; } $outstr = ''; @@ -33,34 +36,18 @@ function smarty_function_booticon( $pParams ) { $outstr .= '>'; } - $outstr .= '<span class="fa fal '; -if( empty( $pParams["iname"] ) ) { - bit_error_log( 'missing iname', $pParams ); -} - if( strpos( $pParams["iname"], 'icon-' ) === 0 ) { - $pParams['iname'] = str_replace( 'icon-', 'fa-', $pParams['iname'] ); + $outstr .= '<span class="'; + if( isset( $pParams["iname"] ) ) { + $outstr .= $pParams['iname']; } -if( strpos( $pParams["iname"], 'fa-' ) !== 0 ) { - bit_error_log( 'missing fa '.$pParams["iname"] ); -} - - $outstr .= str_replace( 'icon-', '', $pParams['iname'] ); - if( isset( $pParams["iclass"] ) ) { $outstr .= ' '.$pParams["iclass"].''; } if( isset( $pParams["class"] ) ) { $outstr .= ' '.$pParams["class"].''; } - if( isset( $pParams["igroup"] ) ) { - $outstr .= ' '.$pParams["igroup"].''; - } $outstr .= '"'; - if( isset( $pParams["style"] ) ) { - $outstr .= ' style="'.$pParams["style"].'"'; - } - if( isset( $pParams["id"] ) ) { $outstr .= ' id="'.$pParams['id'].'"'; } @@ -88,4 +75,3 @@ if( strpos( $pParams["iname"], 'fa-' ) !== 0 ) { return $outstr; } - diff --git a/smartyplugins/function.content.php b/smartyplugins/function.content.php index 92db47b..5399739 100644..100755 --- a/smartyplugins/function.content.php +++ b/smartyplugins/function.content.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -23,5 +25,3 @@ function smarty_function_content($params, &$gBitSmarty) $data = $dcslib->get_actual_content($id); print($data); } - -?> diff --git a/smartyplugins/function.cookie.php b/smartyplugins/function.cookie.php index 8c076f8..e23041c 100644..100755 --- a/smartyplugins/function.cookie.php +++ b/smartyplugins/function.cookie.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -10,7 +12,6 @@ */ function smarty_function_cookie($params, &$gBitSmarty) { global $taglinelib; - include_once( TIDBITS_PKG_PATH.'BitFortuneCookies.php' ); + include_once TIDBITS_PKG_PATH.'BitFortuneCookies.php'; print( $taglinelib->pick_cookie() ); } -?> diff --git a/smartyplugins/function.displaycomment.php b/smartyplugins/function.displaycomment.php index 0ae4618..a1ea210 100644..100755 --- a/smartyplugins/function.displaycomment.php +++ b/smartyplugins/function.displaycomment.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,18 +11,15 @@ * smarty_function_displaycomment */ function smarty_function_displaycomment( $pParams, &$pSmarty ) { + global $gBitSmarty; if (!empty($pParams['comment'])) { $comment = $pParams['comment']; - $pSmarty->assign('comment', $comment); - if (empty($pParams['template'])) { - $ret = $pSmarty->fetch('bitpackage:liberty/display_comment.tpl'); - } else { - $ret = $pSmarty->fetch($pParams['template']); - } + $gBitSmarty->assign('comment', $comment); + $ret = ( empty( $pParams['template'] ) ) + ? $gBitSmarty->fetch( 'bitpackage:liberty/display_comment.tpl' ) + : $gBitSmarty->fetch( $pParams['template'] ); } return $ret; } - -?> diff --git a/smartyplugins/function.displayname.php b/smartyplugins/function.displayname.php index d10e71b..f77b0ba 100644..100755 --- a/smartyplugins/function.displayname.php +++ b/smartyplugins/function.displayname.php @@ -1,4 +1,8 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\BitBase; +use Bitweaver\Users\RoleUser; + /** * Smarty plugin * @package Smarty @@ -19,13 +23,13 @@ function smarty_function_displayname( $pParams, &$gBitSmarty ) { $hash = array_merge( $pParams, $pParams['hash'] ); unset( $hash['hash'] ); // if the hash only has a user_id, we need to look up the user - if( @BitBase::verifyId( $hash['user_id'] ) && empty( $hash['user'] ) && empty( $hash['email'] ) && empty( $hash['login'] )) { + if( BitBase::verifyId( $hash['user_id'] ) && empty( $hash['user'] ) && empty( $hash['email'] ) && empty( $hash['login'] )) { $lookupHash['user_id'] = $hash['user_id']; } } else { // We were probably just passed the 'login' due to legacy code which has yet to be converted if( strpos( '@', $pParams['hash'] ) ) { - $lookupHash['email'] = $hash; + $lookupHash['email'] = $pParams['hash']; } elseif( is_numeric( $pParams['hash'] ) ) { $lookupHash['user_id'] = $pParams['hash']; } else { @@ -49,13 +53,10 @@ function smarty_function_displayname( $pParams, &$gBitSmarty ) { $hash = $gBitUser->getUserInfo( $lookupHash ); } - if( !empty( $hash ) ) { - $displayName = BitUser::getDisplayNameFromHash( $hash, empty( $pParams['nolink'] ) ); - } else { + $displayName = !empty( $hash ) + ? RoleUser::getDisplayNameFromHash( $hash, empty( $pParams['nolink'] ) ) // Now we're really in trouble. We don't even have a user_id to work with - $displayName = "Unknown"; - } + : "Unknown"; - return( $displayName ); + return $displayName; } -?> diff --git a/smartyplugins/function.ed.php b/smartyplugins/function.ed.php index c1a5912..d48f783 100644..100755 --- a/smartyplugins/function.ed.php +++ b/smartyplugins/function.ed.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -23,5 +25,3 @@ function smarty_function_ed($params, &$gBitSmarty) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.elapsed.php b/smartyplugins/function.elapsed.php index 69bb602..3cfbd39 100644..100755 --- a/smartyplugins/function.elapsed.php +++ b/smartyplugins/function.elapsed.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -17,5 +19,3 @@ function smarty_function_elapsed($params, &$gBitSmarty) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.form_id.php b/smartyplugins/function.form_id.php index 486a5a8..1b8a305 100644..100755 --- a/smartyplugins/function.form_id.php +++ b/smartyplugins/function.form_id.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -18,4 +20,3 @@ function smarty_function_form_id(){ } return $ret; } -?> diff --git a/smartyplugins/function.formfeedback.php b/smartyplugins/function.formfeedback.php index 1e8117d..810e822 100644..100755 --- a/smartyplugins/function.formfeedback.php +++ b/smartyplugins/function.formfeedback.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -13,10 +15,6 @@ * Input: * - warning, error or success are defined css styles, but you can feed it anything */ -function smarty_function_formfeedback( $params, &$gBitSmarty ) { - if( !empty( $params['pagekey'] ) ) { - $params = BitFeedback::get( $params['pagekey'] ); - } - return themes_feedback_to_html( $params ); +function smarty_function_formfeedback( $params, &$gSmartyTemplate ) { + return \Bitweaver\Themes\themes_feedback_to_html( $params ); } - diff --git a/smartyplugins/function.formhelp.php b/smartyplugins/function.formhelp.php index a52d1ab..f6eccd9 100644..100755 --- a/smartyplugins/function.formhelp.php +++ b/smartyplugins/function.formhelp.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; + /** * Smarty plugin * @package Smarty @@ -35,6 +38,7 @@ function smarty_function_formhelp( $pParams, &$pSmarty=NULL ) { // maybe params were passed in separately $hash = &$pParams; } + $force = 'n'; // we need to do some hash modification if we're in the installer if( !empty( $hash['is_installer'] )) { @@ -44,8 +48,6 @@ function smarty_function_formhelp( $pParams, &$pSmarty=NULL ) { } } - $class = ''; - foreach( $hash as $key => $val ) { switch( $key ) { case 'note': @@ -58,7 +60,6 @@ function smarty_function_formhelp( $pParams, &$pSmarty=NULL ) { case 'package': case 'install': case 'force': - case 'class': $$key = $val; break; default: @@ -87,15 +88,15 @@ function smarty_function_formhelp( $pParams, &$pSmarty=NULL ) { if( $gBitSystem->isFeatureActive( 'site_online_help' ) || $gBitSystem->isFeatureActive( 'site_form_help' ) || $force == 'y' ) { if( !empty( $rawHash ) ) { if( !empty( $rawHash['page'] ) && ( $gBitSystem->isFeatureActive('site_online_help') || $force == 'y' ) ) { - $ret_page = '<strong>'.tra( 'Online help' ).'</strong>: <a class=\'external\' href=\'http://doc.bitweaver.org/wiki/index.php?page='.$rawHash['page'].'\'>'.$rawHash['page'].'</a><br />'; + $ret_page = '<strong>'.KernelTools::tra( 'Online help' ).'</strong>: <a class=\'external\' href=\'http://doc.bitweaver.org/wiki/index.php?page='.$rawHash['page'].'\'>'.$rawHash['page'].'</a><br />'; } if( !empty( $rawHash['link'] ) && ( $gBitSystem->isFeatureActive('site_online_help') || $force == 'y' ) ) { if( is_array( $rawHash['link'] ) ) { - $ret_link = '<strong>'.tra( 'IntraLink' ).'</strong>: '; + $ret_link = '<strong>'.KernelTools::tra( 'IntraLink' ).'</strong>: '; $ret_link .= '<a href=\''; $ret_link .= constant( strtoupper( $rawHash['link']['package'] ).'_PKG_URL' ).$rawHash['link']['file']; - $ret_link .= '\'>'.tra( $rawHash['link']['title'] ).'</a>'; + $ret_link .= '\'>'.KernelTools::tra( $rawHash['link']['title'] ).'</a>'; } } @@ -103,21 +104,21 @@ function smarty_function_formhelp( $pParams, &$pSmarty=NULL ) { if( is_array( $rawHash['note'] ) ) { foreach( $rawHash['note'] as $name => $value ) { if( $name == 'install' ) { - $ret_install = '<strong>'.tra( 'Install' ).'</strong>: '.tra( 'To use this package, you will first have to run the package specific installer' ).': '; + $ret_install = '<strong>'.KernelTools::tra( 'Install' ).'</strong>: '.KernelTools::tra( 'To use this package, you will first have to run the package specific installer' ).': '; $ret_install .= '<a href=\''; $ret_install .= constant( strtoupper( $value['package'] ).'_PKG_URL' ).$value['file']; $ret_install .= '\'>'.ucfirst( $value['package'] ).'</a>'; } else { - $ret_note .= '<strong>'.ucfirst( tra( $name ) ).'</strong>: '.tra( $value ).'<br />'; + $ret_note .= '<strong>'.ucfirst( KernelTools::tra( $name ) ).'</strong>: '.KernelTools::tra( $value ).'<br />'; } } } else { - $ret_note .= tra( $rawHash['note'] ).'<br />'; + $ret_note .= KernelTools::tra( $rawHash['note'] ).'<br />'; } } if( !empty( $rawHash['warning'] ) ) { - $ret_note .= '<span class="warning">'.tra( $rawHash['warning'] ).'</span><br />'; + $ret_note .= '<span class="warning">'.KernelTools::tra( $rawHash['warning'] ).'</span><br />'; } // join all the output content into one string @@ -128,38 +129,38 @@ function smarty_function_formhelp( $pParams, &$pSmarty=NULL ) { if( !empty( $content ) ) { if( $gBitSystem->isFeatureActive('site_help_popup') ) { global $gBitSmarty; - $gBitSmarty->loadPlugin( 'smarty_modifier_popup' ); - $gBitSmarty->loadPlugin( 'smarty_function_biticon' ); +// $gBitSmarty->loadPlugin( 'smarty_modifier_popup' ); +// $gBitSmarty->loadPlugin( 'smarty_function_biticon' ); - $gBitSmarty->assign( 'title',tra('Extended Help') ); + $gBitSmarty->assign( 'title',KernelTools::tra('Extended Help') ); $gBitSmarty->assign( 'content', $content ); $gBitSmarty->assign( 'closebutton', TRUE ); $text = $gBitSmarty->fetch('bitpackage:kernel/popup_box.tpl'); $text = preg_replace( '/"/',"'",$text ); - $popup = array( + $popup = [ 'trigger' => 'onclick', 'text' => $text, 'fullhtml' => '1', 'sticky' => '1', 'timeout' => '8000', - ); + ]; - $biticon = array( + $biticon = [ 'ipackage' => 'icons', 'iname' => 'dialog-information', 'iforce' => 'icon', 'iexplain' => 'Extended Help', - ); + ]; - $html .= ' <span class="formhelppopup '.$class.'" '.$atts.'> '; - $html .= '<a '.smarty_function_popup( $popup ).'>'; + $html .= ' <span class="formhelppopup" '.$atts.'> '; + $html .= '<a '.smarty_function_popup( $popup, $pSmarty ).'>'; $html .= smarty_function_biticon( $biticon ); $html .= '</a>'; $html .= '</span>'; } else { - $html .= '<span class="help-block '.$class.'" '.$atts.'>'.$content.'</span>'; + $html .= '<span class="help-block" '.$atts.'>'.$content.'</span>'; } } @@ -167,4 +168,3 @@ function smarty_function_formhelp( $pParams, &$pSmarty=NULL ) { } } } -?> diff --git a/smartyplugins/function.formlabel.php b/smartyplugins/function.formlabel.php index 63a43d3..b2961f8 100644..100755 --- a/smartyplugins/function.formlabel.php +++ b/smartyplugins/function.formlabel.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; + /** * Smarty plugin * @package Smarty @@ -49,11 +52,10 @@ function smarty_function_formlabel( $params,&$gBitSmarty ) { } $html .= '>'; if( empty( $params['no_translate'] ) ) { - $html .= tra( $name ); + $html .= KernelTools::tra( $name ); } else { $html .= $name; } $html .= '</label>'; return $html; } -?> diff --git a/smartyplugins/function.gallery.php b/smartyplugins/function.gallery.php index eeff227..6b9c066 100644..100755 --- a/smartyplugins/function.gallery.php +++ b/smartyplugins/function.gallery.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -11,7 +13,7 @@ function smarty_function_gallery($params, &$gBitSmarty) { global $gBitSystem; - include_once( IMAGEGALS_PKG_PATH.'imagegal_lib.php' ); + include_once IMAGEGALS_PKG_PATH.'imagegal_lib.php'; extract($params); // Param = id @@ -20,28 +22,14 @@ function smarty_function_gallery($params, &$gBitSmarty) return; } $img = $gBitSystem->get_random_image($id); - print('<center>'); - print('<table border="0" cellpadding="0" cellspacing="0">'); - print('<tr>'); - print('<td align=center>'); - print('<a href="'.IMAGEGALS_PKG_URL.'browse_image.php?gallery_id='.$img['gallery_id'].'&image_id='.$img['image_id'].'"><img alt="thumbnail" class="athumb" src="show_image.php?id='.$img['image_id'].'&thumb=1" /></a><br/>'); - print('<b>'.$img['name'].'</b><br>'); + print '<center>'; + print '<table border="0" cellpadding="0" cellspacing="0">'; + print '<tr>'; + print '<td align=center>'; + print '<a href="'.IMAGEGALS_PKG_URL.'browse_image.php?gallery_id='.$img['gallery_id'].'&image_id='.$img['image_id'].'"><img alt="thumbnail" class="athumb" src="show_image.php?id='.$img['image_id'].'&thumb=1" /></a><br/>'; + print '<b>'.$img['name'].'</b><br>'; if ($showgalleryname == 1) { - print('<small>From <a href="'.IMAGEGALS_PKG_URL.'browse_gallery.php?gallery_id='.$img['gallery_id'].'">'.$img['gallery'].'</a></small>'); + print '<small>From <a href="'.IMAGEGALS_PKG_URL.'browse_gallery.php?gallery_id='.$img['gallery_id'].'">'.$img['gallery'].'</a></small>'; } - print('</td></tr></table></center>'); + print '</td></tr></table></center>'; } -?> -<!-- -<center> -<table border="0" cellpadding="0" cellspacing="0"> -<tr> -<td align=center> -<a href="'.IMAGEGALS_PKG_URL.'browse_image.php?gallery_id=<?php echo $img['gallery_id']; ?>&image_id=<?php echo $img['image_id']; ?>"><img alt="thumbnail" class="athumb" src="show_image.php?id=<?php echo $img['image_id']; ?>&thumb=1" /></a><br/> -<b><?php echo $img['name']; ?></b><br> -<?php if ($showgalleryname == 1) { ?><small>From <a href="'.IMAGEGALS_PKG_URL.'browse_gallery.php?gallery_id=<?php echo $img['gallery_id']; ?>"><?php echo $img['gallery']; ?></a></small><?php } ?> -</td> -</tr> -</table> -</center> ---> diff --git a/smartyplugins/function.helplink.php b/smartyplugins/function.helplink.php index ce900b0..4fb24fe 100644..100755 --- a/smartyplugins/function.helplink.php +++ b/smartyplugins/function.helplink.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -20,5 +22,3 @@ function smarty_function_helplink($params, &$gBitSmarty) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.html_select_date.php b/smartyplugins/function.html_select_date.php index 0d8315f..6d28f8a 100644..100755 --- a/smartyplugins/function.html_select_date.php +++ b/smartyplugins/function.html_select_date.php @@ -1,4 +1,8 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; +use Bitweaver\BitDate; + /** * Smarty plugin * @package Smarty @@ -27,226 +31,351 @@ * @version 1.3 * @author Andrei Zmievski * @param array - * @param Smarty + * @param \Bitweaver\Themes\BitSmarty * @return string */ -function smarty_function_html_select_date($params, &$pSmarty) -{ - global $gBitSystem; - $pSmarty->loadPlugin( 'smarty_shared_make_timestamp' ); - $pSmarty->loadPlugin( 'smarty_function_html_options' ); - /* Default values. */ - $prefix = "Date_"; - $start_year = strftime("%Y"); - $end_year = $start_year; - $display_days = true; - $display_months = true; - $display_years = true; - $month_format = "%B"; - /* Write months as numbers by default GL */ - $month_value_format = "%m"; - $day_format = "%02d"; - /* Write day values using this format MB */ - $day_value_format = "%d"; - $year_as_text = false; - /* Display years in reverse order? Ie. 2000,1999,.... */ - $reverse_years = false; - /* Should the select boxes be part of an array when returned from PHP? - e.g. setting it to "birthday", would create "birthday[Day]", - "birthday[Month]" & "birthday[Year]". Can be combined with prefix */ - $field_array = null; - /* <select size>'s of the different <select> tags. - If not set, uses default dropdown. */ - $day_size = null; - $month_size = null; - $year_size = null; - /* Unparsed attributes common to *ALL* the <select>/<input> tags. - An example might be in the template: all_extra ='class ="foo"'. */ - $all_extra = null; - /* Separate attributes for the tags. */ - $day_extra = null; - $month_extra = null; - $year_extra = null; - /* Order in which to display the fields. - "D" -> day, "M" -> month, "Y" -> year. */ - $field_order = 'MDY'; - /* String printed between the different fields. */ - $field_separator = "\n"; - $time = time(); +function smarty_function_html_select_date($params, &$pSmarty) { + // generate timestamps used for month names only + $_month_timestamps = null; + $_current_year = null; + if ($_month_timestamps === null) { + $_current_year = date('Y'); + $_month_timestamps = []; + for ($i = 1; $i <= 12; $i++) { + $_month_timestamps[$i] = mktime(0, 0, 0, $i, 1, 2000); + } + } + /* Default values. */ + $prefix = 'Date_'; + $start_year = null; + $end_year = null; + $display_days = true; + $display_months = true; + $display_years = true; + $month_format = '%B'; + /* Write months as numbers by default GL */ + $month_value_format = '%m'; + $day_format = '%02d'; + /* Write day values using this format MB */ + $day_value_format = '%d'; + $year_as_text = false; + /* Display years in reverse order? Ie. 2000,1999,.... */ + $reverse_years = false; + /* Should the select boxes be part of an array when returned from PHP? + e.g. setting it to "birthday", would create "birthday[Day]", + "birthday[Month]" & "birthday[Year]". Can be combined with prefix */ + $field_array = ''; + /* <select size>'s of the different <select> tags. + If not set, uses default dropdown. */ + $day_size = null; + $month_size = null; + $year_size = null; + /* Unparsed attributes common to *ALL* the <select>/<input> tags. + An example might be in the template: all_extra ='class ="foo"'. */ + $all_extra = null; + /* Separate attributes for the tags. */ + $day_extra = null; + $month_extra = null; + $year_extra = null; + /* Order in which to display the fields. + "D" -> day, "M" -> month, "Y" -> year. */ + $field_order = 'MDY'; + /* String printed between the different fields. */ + $field_separator = "\n"; + $option_separator = "\n"; + $time = null; - extract($params); - // If $time is not in format yyyy-mm-dd - if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $time)) { - // then $time is empty or unix timestamp or mysql timestamp - // strftime to make yyyy-mm-dd - // Just in case the offset moves us into another day. - $date = new BitDate(0); - // sets the offset for the user - necessary because BitDate is a bitwack - $offset = $date->get_display_offset(); - $time = $date->getDisplayDateFromUTC( $time ); - $time = $gBitSystem->mServerTimestamp->strftime('%Y-%m-%d', $time, TRUE); + // $all_empty = null; + // $day_empty = null; + // $month_empty = null; + // $year_empty = null; + $extra_attrs = ''; + $all_id = null; + $day_id = null; + $month_id = null; + $year_id = null; + foreach ($params as $_key => $_value) { + switch ($_key) { + case 'time': + $$_key = $_value; // we'll handle conversion below + break; + case 'month_names': + if (is_array($_value) && count($_value) === 12) { + $$_key = $_value; + } else { + trigger_error('html_select_date: month_names must be an array of 12 strings', E_USER_NOTICE); + } + break; + case 'prefix': + case 'field_array': + case 'start_year': + case 'end_year': + case 'day_format': + case 'day_value_format': + case 'month_format': + case 'month_value_format': + case 'day_size': + case 'month_size': + case 'year_size': + case 'all_extra': + case 'day_extra': + case 'month_extra': + case 'year_extra': + case 'field_order': + case 'field_separator': + case 'option_separator': + case 'all_empty': + case 'month_empty': + case 'day_empty': + case 'year_empty': + case 'all_id': + case 'month_id': + case 'day_id': + case 'year_id': + $$_key = (string)$_value; + break; + case 'display_days': + case 'display_months': + case 'display_years': + case 'year_as_text': + case 'reverse_years': + $$_key = (bool)$_value; + break; + default: + if (!is_array($_value)) { + $extra_attrs .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_value) . '"'; + } else { + trigger_error("html_select_date: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); + } + break; + } } - // Now split this in pieces, which later can be used to set the select - $time = explode("-", $time); + // Note: date() is faster than strftime() + // Note: explode(date()) is faster than date() date() date() - // make syntax "+N" or "-N" work with start_year and end_year - if (preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match)) { - if ($match[1] == '+') { - $end_year = strftime('%Y') + $match[2]; + if (isset($time) && is_array($time)) { + if (isset($time[$prefix . 'Year'])) { + // $_REQUEST[$field_array] given + foreach ([ + 'Y' => 'Year', + 'm' => 'Month', + 'd' => 'Day' + ] as $_elementKey => $_elementName) { + $_variableName = '_' . strtolower($_elementName); + $$_variableName = + $time[$prefix . $_elementName] ?? date($_elementKey); + } + } elseif (isset($time[$field_array][$prefix . 'Year'])) { + // $_REQUEST given + foreach ([ + 'Y' => 'Year', + 'm' => 'Month', + 'd' => 'Day' + ] as $_elementKey => $_elementName) { + $_variableName = '_' . strtolower($_elementName); + $$_variableName = $time[$field_array][$prefix . $_elementName] ?? date($_elementKey); + } } else { - $end_year = strftime('%Y') - $match[2]; + // no date found, use NOW + [$_year, $_month, $_day] = explode('-', date('Y-m-d')); } - } - if (preg_match('!^(\+|\-)\s*(\d+)$!', $start_year, $match)) { - if ($match[1] == '+') { - $start_year = strftime('%Y') + $match[2]; + } elseif (isset($time) && preg_match("/(\d*)-(\d*)-(\d*)/", $time, $matches)) { + $_year = $_month = $_day = null; + if ($matches[1] > '') { + $_year = (int)$matches[1]; + } + if ($matches[2] > '') { + $_month = (int)$matches[2]; + } + if ($matches[3] > '') { + $_day = (int)$matches[3]; + } + } elseif ($time === null) { + if (array_key_exists('time', $params)) { + $_year = $_month = $_day = null; } else { - $start_year = strftime('%Y') - $match[2]; + [$_year, $_month, $_day] = explode('-', date('Y-m-d')); } + } else { + $time = smarty_make_timestamp($time); + [$_year, $_month, $_day] = explode('-', date('Y-m-d', $time)); } - $field_order = strtoupper($field_order); - - $html_result = $month_result = $day_result = $year_result = ""; - - if ($display_months) { - $month_names = array(); - $month_values = array(); - - for ($i = 1; $i <= 12; $i++) { - - // date: 2003/03/20 22:54:34; author: ohertel; state: Exp; lines: +1 -1 - // added many missing translation blocks and german translations for user admin page, newsreader, notepad and bookmarks, month from html_select_date is being translated now - // - $month_names[] = strftime($month_format, mktime(0, 0, 0, $i, 1, 2000)); - // + $month_names[] = tra(strftime($month_format, mktime(0, 0, 0, $i, 1, 2000))); - - $month_names[] = tra(strftime($month_format, mktime(0, 0, 0, $i, 1, 2000))); - $month_values[] = strftime($month_value_format, mktime(0, 0, 0, $i, 1, 2000)); - } - - $month_result .= '<select name='; - if (null !== $field_array){ - $month_result .= '"' . $field_array . '[' . $prefix . 'Month]"'; - } else { - $month_result .= '"' . $prefix . 'Month"'; - } - if (null !== $month_size){ - $month_result .= ' size="' . $month_size . '"'; - } - if (null !== $month_extra){ - $month_result .= ' ' . $month_extra; - } - if (null !== $all_extra){ - $month_result .= ' ' . $all_extra; - } - $month_result .= '>'."\n"; - - $month_result .= smarty_function_html_options(array('output' => $month_names, - 'values' => $month_values, - 'selected' => $month_values[$time[1]-1], - 'print_result' => false), - $pSmarty); - - $month_result .= '</select>'; - } - - if ($display_days) { - $days = array(); - for ($i = 1; $i <= 31; $i++) { - $days[] = sprintf($day_format, $i); - $day_values[] = sprintf($day_value_format, $i); - } - - $day_result .= '<select name='; - if (null !== $field_array){ - $day_result .= '"' . $field_array . '[' . $prefix . 'Day]"'; - } else { - $day_result .= '"' . $prefix . 'Day"'; - } - if (null !== $day_size){ - $day_result .= ' size="' . $day_size . '"'; - } - if (null !== $all_extra){ - $day_result .= ' ' . $all_extra; - } - if (null !== $day_extra){ - $day_result .= ' ' . $day_extra; - } - $day_result .= '>'."\n"; - $day_result .= smarty_function_html_options(array('output' => $days, - 'values' => $day_values, - 'selected' => $time[2], - 'print_result' => false), - $pSmarty); - $day_result .= '</select>'; - } - - if ($display_years) { - if (null !== $field_array){ - $year_name = $field_array . '[' . $prefix . 'Year]'; - } else { - $year_name = $prefix . 'Year'; - } - if ($year_as_text) { - $year_result .= '<input type="text" name="' . $year_name . '" value="' . $time[0] . '" size="4" maxlength="4"'; - if (null !== $all_extra){ - $year_result .= ' ' . $all_extra; - } - if (null !== $year_extra){ - $year_result .= ' ' . $year_extra; - } - $year_result .= '>'; - } else { - $years = range((int)$start_year, (int)$end_year); - if ($reverse_years) { - rsort($years, SORT_NUMERIC); - } - - $year_result .= '<select name="' . $year_name . '"'; - if (null !== $year_size){ - $year_result .= ' size="' . $year_size . '"'; - } - if (null !== $all_extra){ - $year_result .= ' ' . $all_extra; - } - if (null !== $year_extra){ - $year_result .= ' ' . $year_extra; - } - $year_result .= '>'."\n"; - $year_result .= smarty_function_html_options(array('output' => $years, - 'values' => $years, - 'selected' => $time[0], - 'print_result' => false), - $pSmarty); - $year_result .= '</select>'; - } - } - - // Loop thru the field_order field - for ($i = 0; $i <= 2; $i++){ - $c = substr($field_order, $i, 1); - switch ($c){ - case 'D': - $html_result .= $day_result; - break; - - case 'M': - $html_result .= $month_result; - break; - - case 'Y': - $html_result .= $year_result; - break; - } - // Add the field seperator - if($i != 2) { - $html_result .= $field_separator; - } - } - - return $html_result; + // make syntax "+N" or "-N" work with $start_year and $end_year + // Note preg_match('!^(\+|\-)\s*(\d+)$!', $end_year, $match) is slower than trim+substr + foreach ([ + 'start', + 'end' + ] as $key) { + $key .= '_year'; + $t = $$key; + if ($t === null) { + $$key = (int)$_current_year; + } elseif ($t[0] === '+') { + $$key = (int)($_current_year + (int)trim(substr($t, 1))); + } elseif ($t[0] === '-') { + $$key = (int)($_current_year - (int)trim(substr($t, 1))); + } else { + $$key = (int)$$key; + } + } + // flip for ascending or descending + if (($start_year > $end_year && !$reverse_years) || ($start_year < $end_year && $reverse_years)) { + $t = $end_year; + $end_year = $start_year; + $start_year = $t; + } + // generate year <select> or <input> + if ($display_years) { + $_extra = ''; + $_name = $field_array ? ($field_array . '[' . $prefix . 'Year]') : ($prefix . 'Year'); + if ($all_extra) { + $_extra .= ' ' . $all_extra; + } + if ($year_extra) { + $_extra .= ' ' . $year_extra; + } + if ($year_as_text) { + $_html_years = + '<input type="text" name="' . $_name . '" value="' . $_year . '" size="4" maxlength="4"' . $_extra . + $extra_attrs . ' />'; + } else { + $_html_years = '<select name="' . $_name . '"'; + if ($year_id !== null || $all_id !== null) { + $_html_years .= ' id="' . smarty_function_escape_special_chars( + $year_id !== null ? + ($year_id ? $year_id : $_name) : + ($all_id ? ($all_id . $_name) : + $_name) + ) . '"'; + } + if ($year_size) { + $_html_years .= ' size="' . $year_size . '"'; + } + $_html_years .= $_extra . $extra_attrs . '>' . $option_separator; + if (isset($year_empty) || isset($all_empty)) { + $_html_years .= '<option value="">' . (isset($year_empty) ? $year_empty : $all_empty) . '</option>' . + $option_separator; + } + $op = $start_year > $end_year ? -1 : 1; + for ($i = $start_year; $op > 0 ? $i <= $end_year : $i >= $end_year; $i += $op) { + $_html_years .= '<option value="' . $i . '"' . ($_year == $i ? ' selected="selected"' : '') . '>' . $i . + '</option>' . $option_separator; + } + $_html_years .= '</select>'; + } + } + // generate month <select> or <input> + if ($display_months) { + $dateFormatter = new \IntlDateFormatter('en_GB', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE); + $_extra = ''; + $_name = $field_array ? ($field_array . '[' . $prefix . 'Month]') : ($prefix . 'Month'); + if ($all_extra) { + $_extra .= ' ' . $all_extra; + } + if ($month_extra) { + $_extra .= ' ' . $month_extra; + } + $_html_months = '<select name="' . $_name . '"'; + if ($month_id !== null || $all_id !== null) { + $_html_months .= ' id="' . smarty_function_escape_special_chars( + $month_id !== null ? + ($month_id ? $month_id : $_name) : + ($all_id ? ($all_id . $_name) : + $_name) + ) . '"'; + } + if ($month_size) { + $_html_months .= ' size="' . $month_size . '"'; + } + $_html_months .= $_extra . $extra_attrs . '>' . $option_separator; + if (isset($month_empty) || isset($all_empty)) { + $_html_months .= '<option value="">' . ( $month_empty ?? $all_empty) . '</option>' . + $option_separator; + } + for ($i = 1; $i <= 12; $i++) { + $_val = sprintf('%02d', $i); + $_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[$i]) : + ($month_format === '%m' ? $_val : $dateFormatter->format($_month_timestamps[$i])); + $pattern = '/\d{1,2}\s+([a-zA-ZáéíóúüñÁÉÍÓÚÜÑ]+)\s+\d{4}/u'; + // Match the pattern + if (preg_match($pattern, $_text, $matches)) { + // The month part is in the first capturing group + $_text = $matches[1] ?? $_val; + } + $_value = $month_value_format === '%m' ? $_val : $dateFormatter->format($_month_timestamps[$i]); + $_html_months .= '<option value="' . $_value . '"' . ($_val == $_month ? ' selected="selected"' : '') . + '>' . $_text . '</option>' . $option_separator; + } + $_html_months .= '</select>'; + } + // generate day <select> or <input> + if ($display_days) { + $_extra = ''; + $_name = $field_array ? ($field_array . '[' . $prefix . 'Day]') : ($prefix . 'Day'); + if ($all_extra) { + $_extra .= ' ' . $all_extra; + } + if ($day_extra) { + $_extra .= ' ' . $day_extra; + } + $_html_days = '<select name="' . $_name . '"'; + if ($day_id !== null || $all_id !== null) { + $_html_days .= ' id="' . + smarty_function_escape_special_chars( + $day_id !== null ? ($day_id ? $day_id : $_name) : + ($all_id ? ($all_id . $_name) : $_name) + ) . '"'; + } + if ($day_size) { + $_html_days .= ' size="' . $day_size . '"'; + } + $_html_days .= $_extra . $extra_attrs . '>' . $option_separator; + if (isset($day_empty) || isset($all_empty)) { + $_html_days .= '<option value="">' . (isset($day_empty) ? $day_empty : $all_empty) . '</option>' . + $option_separator; + } + for ($i = 1; $i <= 31; $i++) { + $_val = sprintf('%02d', $i); + $_text = $day_format === '%02d' ? $_val : sprintf($day_format, $i); + $_value = $day_value_format === '%02d' ? $_val : sprintf($day_value_format, $i); + $_html_days .= '<option value="' . $_value . '"' . ($_val == $_day ? ' selected="selected"' : '') . '>' . + $_text . '</option>' . $option_separator; + } + $_html_days .= '</select>'; + } + // order the fields for output + $_html = ''; + for ($i = 0; $i <= 2; $i++) { + switch ($field_order[$i]) { + case 'Y': + case 'y': + if (isset($_html_years)) { + if ($_html) { + $_html .= $field_separator; + } + $_html .= $_html_years; + } + break; + case 'm': + case 'M': + if (isset($_html_months)) { + if ($_html) { + $_html .= $field_separator; + } + $_html .= $_html_months; + } + break; + case 'd': + case 'D': + if (isset($_html_days)) { + if ($_html) { + $_html .= $field_separator; + } + $_html .= $_html_days; + } + break; + } + } + return $_html; } - -/* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.html_select_time.php b/smartyplugins/function.html_select_time.php index e235f26..693a5ea 100644..100755 --- a/smartyplugins/function.html_select_time.php +++ b/smartyplugins/function.html_select_time.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use \Bitweaver\BitDate; + /** * Smarty plugin * @package Smarty @@ -21,8 +24,8 @@ function smarty_function_html_select_time($params, &$gBitSmarty) { global $gBitSystem; - $gBitSmarty->loadPlugin( 'smarty_shared_make_timestamp' ); - $gBitSmarty->loadPlugin( 'smarty_function_html_options' ); +// $gBitSmarty->loadPlugin( 'smarty_shared_make_timestamp' ); +// $gBitSmarty->loadPlugin( 'smarty_function_bit_html_options' ); /* Default values. */ $prefix = "Time_"; $time = time(); @@ -71,10 +74,10 @@ function smarty_function_html_select_time($params, &$gBitSmarty) $html_result .= ' ' . $all_extra; } $html_result .= '>'."\n"; - $html_result .= smarty_function_html_options(array('output' => $hours, - 'values' => $hours, - 'selected' => $selected, - 'print_result' => false), + $html_result .= smarty_function_bit_html_options( [ 'output' => $hours, + 'values' => $hours, + 'selected' => $selected, + 'print_result' => false ], $gBitSmarty); $html_result .= "</select>\n"; } @@ -98,7 +101,7 @@ function smarty_function_html_select_time($params, &$gBitSmarty) } $html_result .= '>'."\n"; - $html_result .= smarty_function_html_options(array('output' => $minutes, + $html_result .= smarty_function_bit_html_options(array('output' => $minutes, 'values' => $minutes, 'selected' => $selected, 'print_result' => false), @@ -126,7 +129,7 @@ function smarty_function_html_select_time($params, &$gBitSmarty) } $html_result .= '>'."\n"; - $html_result .= smarty_function_html_options(array('output' => $seconds, + $html_result .= smarty_function_bit_html_options(array('output' => $seconds, 'values' => $seconds, 'selected' => $selected, 'print_result' => false), @@ -151,7 +154,7 @@ function smarty_function_html_select_time($params, &$gBitSmarty) } $html_result .= '>'."\n"; - $html_result .= smarty_function_html_options(array('output' => array('AM', 'PM'), + $html_result .= smarty_function_bit_html_options(array('output' => array('AM', 'PM'), 'values' => array('am', 'pm'), 'selected' => $selected, 'print_result' => false), @@ -170,5 +173,3 @@ function smarty_function_html_select_time($params, &$gBitSmarty) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.include_js.php b/smartyplugins/function.include_js.php index 60b6508..e309ad0 100644..100755 --- a/smartyplugins/function.include_js.php +++ b/smartyplugins/function.include_js.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use \Bitweaver\BitCache; + /** * Smarty plugin * @package Smarty diff --git a/smartyplugins/function.include_wiki_page_content.php b/smartyplugins/function.include_wiki_page_content.php index d216588..dd136e4 100644..100755 --- a/smartyplugins/function.include_wiki_page_content.php +++ b/smartyplugins/function.include_wiki_page_content.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use \Bitweaver\Wiki\BitPage; + /** * Smarty plugin * @package Smarty @@ -50,7 +53,7 @@ # # Step 3: Include the following line in the wiki/edit_page.tpl file at the point where you want the notice displayed: # -#{include_wiki_page_content page="`$pageInfo.original_title` - edit notice" page_default="default edit notice"} +#{include_wiki_page_content page="`$gContent->mInfo.original_title` - edit notice" page_default="default edit notice"} # # Now whenever "ABC" is edited the custom notice will be displayed on the edit page. # Editing any other page will display the default edit notice. @@ -62,7 +65,7 @@ function smarty_function_include_wiki_page_content($params, &$gBitSmarty) $parsed = ''; // if( ($pageName = !empty( $params['page'] ) ? $params['page'] : (!empty( $params['page_default'] ) ? $params['page_default'] : NULL )) ) { - include_once( WIKI_PKG_CLASS_PATH.'BitPage.php' ); + include_once WIKI_PKG_CLASS_PATH.'BitPage.php'; if( $includePage = BitPage::lookupObject( array( 'page' => $pageName ) ) ) { $parsed = $includePage->getParsedData(); } @@ -70,5 +73,3 @@ function smarty_function_include_wiki_page_content($params, &$gBitSmarty) return $parsed; } - -?> diff --git a/smartyplugins/function.inlinemodule.php b/smartyplugins/function.inlinemodule.php index 3be9001..cfdba21 100644..100755 --- a/smartyplugins/function.inlinemodule.php +++ b/smartyplugins/function.inlinemodule.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -18,4 +20,3 @@ function smarty_function_inlinemodule($params, &$gBitSmarty) { $module_params = ( !empty( $params ) ? $params : NULL ); print $gBitSmarty->fetch( $params['file'] ); } -?> diff --git a/smartyplugins/function.jscalendar.php b/smartyplugins/function.jscalendar.php index 6941195..7d37ecd 100644..100755 --- a/smartyplugins/function.jscalendar.php +++ b/smartyplugins/function.jscalendar.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\BitDate; + /** * Smarty plugin * @package Smarty @@ -16,8 +19,8 @@ * - 1.0 initial release * @version 1.0 * @author Stephan Borg - * @param array - * @param Smarty + * @param array + * @param array Smarty * @return string */ function smarty_function_jscalendar($params, &$gBitSmarty) { @@ -37,13 +40,10 @@ function smarty_function_jscalendar($params, &$gBitSmarty) { extract( $params ); $time = $gBitSystem->mServerTimestamp->getDisplayDateFromUTC( $time ); - $time = strftime( "%m/%d/%Y %H:%M", $time ); + $time = BitDate::strftime( "%m/%d/%Y %H:%M", $time ); - if( $readonly ) { - $html_result = $time; - } else { - $html_result = - "<script type=\"text/javascript\">//<![CDATA[ + $html_result = $readonly ? $time + : "<script type=\"text/javascript\">//<![CDATA[ Calendar.setup({ date : \"$time\", inputField : \"$inputField\", @@ -53,13 +53,10 @@ function smarty_function_jscalendar($params, &$gBitSmarty) { electric : $electric, onUpdate : $onUpdate }); - //]]></script>" - ; - } + //]]></script>"; return $html_result; } else { return ''; } } -?> diff --git a/smartyplugins/function.jspack.php b/smartyplugins/function.jspack.php index c11459f..3002cc1 100644..100755 --- a/smartyplugins/function.jspack.php +++ b/smartyplugins/function.jspack.php @@ -1,4 +1,8 @@ <?php +namespace Bitweaver\Plugins; + +use Bitweaver\BitCache; + /** * Smarty plugin * @package Smarty @@ -33,7 +37,6 @@ function smarty_function_jspack( $pParams, &$gBitSmarty ) { // get a name for the cache file we're going to store $cachefile = $pParams['ipackage'].'_'.str_replace( '/', '_', $pParams['ifile'] ); - require_once( KERNEL_PKG_PATH.'BitCache.php' ); $bitCache = new BitCache( 'javascript', TRUE ); // if the file hasn't been packed and cached yet, we do that now. @@ -56,9 +59,8 @@ function smarty_function_jspack( $pParams, &$gBitSmarty ) { } $defer = !empty( $pParams['defer'] ) ? " defer='".$pParams['defer']."'" : ""; - return '<script'.$defer.' type="text/javascript" src="'.$bitCache->getCacheUrl( $cachefile ).'"></script>'; + return '<script'.$defer.' src="'.$bitCache->getCacheUrl( $cachefile ).'"></script>'; } else { return "<!-- ".tra( 'not a valid file: ' ).$pParams['ifile']." -->"; } } -?> diff --git a/smartyplugins/function.jspopup.php b/smartyplugins/function.jspopup.php index e53a339..e91c875 100644..100755 --- a/smartyplugins/function.jspopup.php +++ b/smartyplugins/function.jspopup.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; + /** * Smarty plugin * @package Smarty @@ -13,33 +16,30 @@ * smarty_function_jspopup * * @param array $pParams hash of options - * @param string $pParams[href] link the popup should open - * @param string $pParams[title] title of the link - * @param string $pParams[img] source of an image that is to be displayed instead of the title - * @param string $pParams[href] - * @param string $pParams[href] + * @var string $pParams[href] link the popup should open + * @var string $pParams[title] title of the link + * @var string $pParams[img] source of an image that is to be displayed instead of the title + * @var string $pParams[href] + * @var string $pParams[href] * @param array $pSmarty - * @access public - * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure + * @return string */ function smarty_function_jspopup( $pParams, &$pSmarty=NULL ) { global $gBitThemes, $gBitSmarty; $ret = ''; if( empty( $pParams['href'] ) ) { - return( 'assign: missing "href" parameter' ); + return 'assign: missing "href" parameter'; } - if( empty( $pParams['title'] ) ) { - $title = basename( $pParams['href'] ); - } else { - $title = empty( $pParams['notra'] ) ? $pParams['title'] : tra( $pParams['title'] ); - } + $title = empty( $pParams['title'] ) + ? basename( $pParams['href'] ) + : ( empty( $pParams['notra'] ) ? $pParams['title'] : KernelTools::tra( $pParams['title'] ) ); if( empty( $pParams['text'] )){ $text = $title; } else { - $text = empty( $pParams['notra'] ) ? $pParams['text'] : tra( $pParams['text'] ); + $text = empty( $pParams['notra'] ) ? $pParams['text'] : KernelTools::tra( $pParams['text'] ); // remove it from the hash since later the params are looped over for to formulate the a tag unset( $pParams['text'] ); } @@ -50,7 +50,7 @@ function smarty_function_jspopup( $pParams, &$pSmarty=NULL ) { foreach( $pParams as $param => $val ) { if( !in_array( $param, $optionHash ) ) { if( $param == 'title' ) { - $guts .= ' '.$param.'="'.tra( 'This will open a new window: ' ).$title.'"'; + $guts .= ' '.$param.'="'.KernelTools::tra( 'This will open a new window: ' ).$title.'"'; }elseif( $param == 'href' && $gBitThemes->isJavascriptEnabled()){ $guts .= ' '.$param.'="javascript:void(0)"'; } else { @@ -60,14 +60,14 @@ function smarty_function_jspopup( $pParams, &$pSmarty=NULL ) { } if( !empty( $pParams['ibiticon'] ) ) { - $gBitSmarty->loadPlugin( 'smarty_function_biticon' ); +// $gBitSmarty->loadPlugin( 'smarty_function_biticon' ); $tmp = explode( '/', $pParams['ibiticon'] ); - $ibiticon = array( + $ibiticon = [ 'ipackage' => $tmp[0], 'iname' => $tmp[1], 'iexplain' => $title, - ); + ]; if( !empty( $pParams['iforce'] ) ) { $ibiticon['iforce'] = $pParams['iforce']; @@ -86,11 +86,11 @@ function smarty_function_jspopup( $pParams, &$pSmarty=NULL ) { $img = '<img src="'.$pParams['img'].'" alt="'.$title.'" title="'.$title.'" '.$img_size.' />'; } - if( !empty( $pParams['type'] ) && $pParams['type'] == 'fullscreen' ) { - $js = 'BitBase.popUpWin(\''.$pParams['href'].'\',\'fullScreen\');'; - } else { - $js = 'BitBase.popUpWin(\''.$pParams['href'].'\',\'standard\','.( !empty( $pParams['width'] ) ? $pParams['width'] : 600 ).','.( !empty( $pParams['height'] ) ? $pParams['height'] : 400 ).');'; - } + $js = !empty( $pParams['type'] ) && $pParams['type'] == 'fullscreen' + ? 'BitBase.popUpWin( \''.$pParams['href'].'\',\'fullScreen\');' + : ( 'BitBase.popUpWin( \''.$pParams['href'].'\',\'standard\',' . + ( !empty( $pParams['width'] ) ? $pParams['width'] : 600 ) . + ',' . ( !empty( $pParams['height'] ) ? $pParams['height'] : 400 ) . ');' ); // deprecated slated for removal - onkeypress causes focus problems with browsers - if this is an ada issue get in touch -wjames5. // $guts .= ' onkeypress="'.$js.'" onclick="'.$js.'return false;"'; @@ -99,6 +99,6 @@ function smarty_function_jspopup( $pParams, &$pSmarty=NULL ) { if( !empty( $pParams['gutsonly'] ) ) { return $guts; } else { - return( '<a '.$guts.'>'.( !empty( $img ) ? $img : $text ).'</a>' ); + return '<a '.$guts.'>'.( !empty( $img ) ? $img : $text ).'</a>'; } } diff --git a/smartyplugins/function.libertypagination.php b/smartyplugins/function.libertypagination.php index 9add003..71d4975 100644..100755 --- a/smartyplugins/function.libertypagination.php +++ b/smartyplugins/function.libertypagination.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty {libertypagination} function plugin * @@ -24,7 +26,9 @@ /** * Smarty {libertypagination} function plugin */ -function smarty_function_libertypagination($params, &$gBitSmarty) { +function smarty_function_libertypagination($params, &$gSmartyTemplate) { + global $gBitSmarty; + if( isset( $params['ihash'] ) && is_array( $params['ihash'] ) ) { $params = array_merge( $params['ihash'], $params ); $params['ihash'] = NULL; @@ -45,19 +49,15 @@ function smarty_function_libertypagination($params, &$gBitSmarty) { $pgnHidden[$form_param] = $form_val; } } - $pgnVars .= ( !empty( $params['ianchor'] ) ? '#'.$params['ianchor'] : '' ); + $pgnVars .= !empty( $params['ianchor'] ) ? '#'.$params['ianchor'] : ''; if( !empty( $params['numPages'] ) ) { for( $pageCount = 1; $pageCount < $params['numPages']+1; $pageCount++ ) { - if( $pageCount != $params[$pgnName] ) { - if( !empty( $params['ajaxId'] ) ) { - $pages[] = '<a href="javascript:void(0);" onclick="BitAjax.updater(\''.$params['ajaxId']."','".$_SERVER['REQUEST_URI']."','".$pgnName.'='.$pageCount.$pgnVars.'\')'.'">'.( $pageCount ).'</a>'; - } else { - $pages[] = '<a href="'.$_SERVER['SCRIPT_NAME'].'?'.$pgnName.'='.$pageCount.$pgnVars.'">'.( $pageCount ).'</a>'; - } - } else { - $pages[] = '<strong>'.$pageCount.'</strong>'; - } + $pages[] = $pageCount != $params[$pgnName] + ? ( !empty( $params['ajaxId'] ) + ? '<a href="javascript:void(0);" onclick="BitAjax.updater(\''.$params['ajaxId']."','".$_SERVER['REQUEST_URI']."','".$pgnName.'='.$pageCount.$pgnVars.'\')'.'">'. $pageCount .'</a>' + : '<a href="'.$_SERVER['SCRIPT_NAME'].'?'.$pgnName.'='.$pageCount.$pgnVars.'">'. $pageCount .'</a>') + : '<strong>'.$pageCount.'</strong>'; } $gBitSmarty->assign( 'pgnPage', $params[$pgnName] ); @@ -69,7 +69,6 @@ function smarty_function_libertypagination($params, &$gBitSmarty) { if( !empty( $params['ajaxId'] ) ) { $gBitSmarty->assign( 'ajaxId', $params['ajaxId'] ); } - $gBitSmarty->display( 'bitpackage:liberty/libertypagination.tpl' ); + return $gBitSmarty->fetch( 'bitpackage:liberty/libertypagination.tpl' ); } } -?> diff --git a/smartyplugins/function.memusage.php b/smartyplugins/function.memusage.php index 1e0158f..74e204e 100644..100755 --- a/smartyplugins/function.memusage.php +++ b/smartyplugins/function.memusage.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -18,7 +20,7 @@ function smarty_function_memusage($params, &$gBitSmarty) { // If you need it to work for 2000 look at http://us2.php.net/manual/en/function.memory-get-usage.php#54642 if( substr( PHP_OS, 0, 3 ) == 'WIN' ) { if( substr( PHP_OS, 0, 3 ) == 'WIN' ) { - $output = array(); + $output = []; } exec( 'tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $output ); $memusage = preg_replace( '/[\D]/', '', $output[5] ) * 1024; @@ -51,5 +53,3 @@ function smarty_function_memusage($params, &$gBitSmarty) { print( number_format( $memusage, 2 ).$memunit ); } } - -?> diff --git a/smartyplugins/function.menu.php b/smartyplugins/function.menu.php index f22d012..7461c76 100644..100755 --- a/smartyplugins/function.menu.php +++ b/smartyplugins/function.menu.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -13,4 +15,3 @@ function smarty_function_menu($params, &$gBitSmarty) { // Dummy } -?> diff --git a/smartyplugins/function.minifind.php b/smartyplugins/function.minifind.php index 4ab90c6..a915d64 100644..100755 --- a/smartyplugins/function.minifind.php +++ b/smartyplugins/function.minifind.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; + /** * Smarty plugin * @package Smarty @@ -13,7 +16,8 @@ * Input: all parameters (except legend) that are passed in will be added as <input type="hidden" name=$name value=$value>. The 'legend' parameter will be used as the form legend, a string is expected. * Output: a small form that allows you to search your table using $_REQUEST['find'] as search value */ -function smarty_function_minifind($params, &$gBitSmarty) { +function smarty_function_minifind($params, &$gSmartyTemplate) { + global $gBitSmarty; if(isset($params['legend'])) { $legend = $params['legend']; @@ -23,15 +27,14 @@ function smarty_function_minifind($params, &$gBitSmarty) { } if( !empty( $params['find_name'] ) ) { - $gBitSmarty->assign( 'find_name', tra( $params['name'] ) ); + $gBitSmarty->assign( 'find_name', KernelTools::tra( $params['name'] ) ); } if( !empty( $params['prompt'] ) ) { - $gBitSmarty->assign( 'prompt', tra( $params['prompt'] ).'...' ); + $gBitSmarty->assign( 'prompt', KernelTools::tra( $params['prompt'] ).'...' ); } $gBitSmarty->assign( 'legend',$legend ); $gBitSmarty->assign( 'hidden',$params ); - $gBitSmarty->display( 'bitpackage:kernel/minifind.tpl' ); + return $gBitSmarty->fetch( 'bitpackage:kernel/minifind.tpl' ); } -?> diff --git a/smartyplugins/function.moduleinc.php b/smartyplugins/function.moduleinc.php index 9950c5b..4e2073b 100644..100755 --- a/smartyplugins/function.moduleinc.php +++ b/smartyplugins/function.moduleinc.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -19,7 +21,7 @@ * @param integer $pParams['cache_time'] seconds the template will be cached */ function smarty_function_moduleinc($pParams, &$gBitSmarty) { - global $gBitSystem, $gBitThemes; + global $gBitSystem, $gBitThemes, $gBitSmarty; // go through some hassle here in consideration of a future day when this handles any module list( $package, $template ) = split( '/', $pParams['module_rsrc'] ); @@ -40,11 +42,11 @@ function smarty_function_moduleinc($pParams, &$gBitSmarty) { $fp = fopen( $cachefile, "r" ); $data = fread( $fp, filesize( $cachefile )); fclose( $fp ); - print( $data ); + print $data; } else { if( $moduleParams = $gBitThemes->getCustomModule( $template )) { $moduleParams = array_merge( $pParams, $moduleParams ); - $gBitSmarty->assignByRef( 'moduleParams', $moduleParams ); + $gBitSmarty->assign( 'moduleParams', $moduleParams ); $data = $gBitSmarty->fetch( 'bitpackage:themes/custom_module.tpl' ); if( !empty( $pParams["cache_time"] ) ) { @@ -53,7 +55,7 @@ function smarty_function_moduleinc($pParams, &$gBitSmarty) { fwrite( $fp, $data, strlen( $data )); fclose( $fp ); } - print( $data ); + print $data; } } unset( $data ); diff --git a/smartyplugins/function.nexus.php b/smartyplugins/function.nexus.php index 9c54c32..f85eb1b 100644..100755 --- a/smartyplugins/function.nexus.php +++ b/smartyplugins/function.nexus.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -20,12 +22,10 @@ function smarty_function_nexus( $params, &$gBitSmarty ) { return; } - require_once( NEXUS_PKG_PATH.'Nexus.php' ); - $tmpNexus = new Nexus( $id ); + $tmpNexus = new \Bitweaver\Nexus\Nexus( $id ); $nexusMenu = $tmpNexus->mInfo; $gBitSmarty->assign( 'nexusMenu', $nexusMenu ); $gBitSmarty->assign( 'nexusId', $id ); $gBitSmarty->display('bitpackage:nexus/nexus_module.tpl'); } -?>
\ No newline at end of file diff --git a/smartyplugins/function.pageurl.php b/smartyplugins/function.pageurl.php index 7a708d9..8414d49 100644..100755 --- a/smartyplugins/function.pageurl.php +++ b/smartyplugins/function.pageurl.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty {pageurl} function plugin * @package Smarty diff --git a/smartyplugins/function.pagination.php b/smartyplugins/function.pagination.php index 2025808..1bdf50b 100644..100755 --- a/smartyplugins/function.pagination.php +++ b/smartyplugins/function.pagination.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /*** Handle jQuery plugin naming conflict between jQuery UI and Bootstrap ***/ /** * Smarty {pagination} function plugin @@ -16,7 +18,9 @@ * - <attribute>=<value> (optional) - pass in any attributes and they will be added to the pagination string<br> * Output: url of the form: $_SERVER[SCRIPT_NAME]?attribute1=value1&attribute2=value2 */ -function smarty_function_pagination( $params, &$gBitSmarty ) { +function smarty_function_pagination( $params, &$gSmartyTemplate ) { + global $gBitSmarty; + $pgnUrl = $gBitSmarty->getTemplateVars('returnURL'); if ( isset( $params['url'] ) ) { $pgnUrl = $params['url']; @@ -29,13 +33,15 @@ function smarty_function_pagination( $params, &$gBitSmarty ) { $gBitSmarty->assign( 'pgnUrl', $pgnUrl ); $pgnVars = ''; - $pgnHidden = array(); + $pgnHidden = []; foreach( $params as $form_param => $form_val ) { - $pgnVars .= "&".$form_param."=".$form_val; - $pgnHidden[$form_param] = $form_val; + if ( !is_array($form_val)) { + $pgnVars .= "&$form_param=$form_val"; + $pgnHidden[$form_param] = $form_val; + } } + $gBitSmarty->assign( 'pgnVars', $pgnVars ); $gBitSmarty->assign( 'pgnHidden', $pgnHidden ); - $gBitSmarty->display('bitpackage:kernel/pagination.tpl'); + return $gBitSmarty->fetch('bitpackage:kernel/pagination.tpl'); } -?> diff --git a/smartyplugins/function.poll.php b/smartyplugins/function.poll.php index f675370..ad7b96e 100644..100755 --- a/smartyplugins/function.poll.php +++ b/smartyplugins/function.poll.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -8,7 +10,7 @@ /** * smarty_function_base */ -require_once( KERNEL_PKG_CLASS_PATH.'BitBase.php' ); +use Bitweaver\BitBase; /** * smarty_function_poll @@ -18,8 +20,7 @@ function smarty_function_poll($params, &$gBitSmarty) { extract($params); // Param = zone - include_once( POLLS_PKG_INCLUDE_PATH.'poll_lib.php' ); - include_once( LIBERTY_PKG_CLASS_PATH.'LibertyComment.php' ); + include_once( POLLS_PKG_PATH.'poll_lib.php' ); if (empty($id)) { $id = $polllib->get_random_active_poll(); @@ -39,6 +40,3 @@ function smarty_function_poll($params, &$gBitSmarty) { } } -/* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.popup.php b/smartyplugins/function.popup.php index 1ea5976..26ac6b3 100644..100755 --- a/smartyplugins/function.popup.php +++ b/smartyplugins/function.popup.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -18,7 +20,6 @@ * @param Smarty * @return string */ -require_once(LIBERTY_PKG_CLASS_PATH.'LibertyContent.php'); function smarty_function_popup($params, &$gBitSmarty) { $append = ''; @@ -131,4 +132,3 @@ function smarty_function_popup($params, &$gBitSmarty) { return $retval; } -?> diff --git a/smartyplugins/function.querytable.php b/smartyplugins/function.querytable.php index 2a29372..1321f0f 100644..100755 --- a/smartyplugins/function.querytable.php +++ b/smartyplugins/function.querytable.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -71,7 +73,3 @@ function smarty_function_querytable($params, &$gBitSmarty) { return $output; } - - - -?> diff --git a/smartyplugins/function.rcontent.php b/smartyplugins/function.rcontent.php index 90b5d2c..3a39294 100644..100755 --- a/smartyplugins/function.rcontent.php +++ b/smartyplugins/function.rcontent.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -24,5 +26,3 @@ function smarty_function_rcontent($params, &$gBitSmarty) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.required.php b/smartyplugins/function.required.php index cf0cf27..247f3b6 100644..100755 --- a/smartyplugins/function.required.php +++ b/smartyplugins/function.required.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -10,17 +12,16 @@ */ function smarty_function_required( $pParams, &$pSmarty=NULL ) { global $gBitSmarty; - $gBitSmarty->loadPlugin( 'smarty_function_biticon' ); +// $gBitSmarty->loadPlugin( 'smarty_function_biticon' ); $biticon = array( 'ipackage' => 'icons', 'iname' => 'emblem-important', 'iexplain' => 'Required', ); - $ret = smarty_function_biticon( $biticon ); + $ret = \Bitweaver\Plugins\smarty_function_biticon( $biticon ); if( !empty( $pParams['legend'] )) { $ret = "<p>$ret ".tra( "Elements marked with this symbol are required." )."</p>"; } return $ret; } -?> diff --git a/smartyplugins/function.rss.php b/smartyplugins/function.rss.php index 4ec93ff..5f92f2d 100644..100755 --- a/smartyplugins/function.rss.php +++ b/smartyplugins/function.rss.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -14,4 +16,3 @@ function smarty_function_rss($params, &$gBitSmarty) { $feed = rss_parse_data("", $params); print $feed; } -?> diff --git a/smartyplugins/function.sameurl.php b/smartyplugins/function.sameurl.php index d4f581a..ff0de72 100644..100755 --- a/smartyplugins/function.sameurl.php +++ b/smartyplugins/function.sameurl.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -58,5 +60,3 @@ function smarty_function_sameurl($params, &$gBitSmarty) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.showdate.php b/smartyplugins/function.showdate.php index e11c7af..a0a05d9 100644..100755 --- a/smartyplugins/function.showdate.php +++ b/smartyplugins/function.showdate.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -22,5 +24,3 @@ function smarty_function_showdate($params, &$gBitSmarty) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/function.smartlink.php b/smartyplugins/function.smartlink.php index cdb0515..ae9c809 100644..100755 --- a/smartyplugins/function.smartlink.php +++ b/smartyplugins/function.smartlink.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; + /** * Smarty plugin * @package Smarty @@ -64,18 +67,11 @@ function smarty_function_smartlink( $pParams, &$pSmarty=NULL ) { if( !empty( $hash['iurl'] ) ) { $url = $hash['iurl']; } elseif( !empty( $hash['ifile'] ) ) { - if( !empty( $hash['ipackage'] ) ) { - if( $hash['ipackage'] == 'root' ) { - $url = BIT_ROOT_URL.$hash['ifile']; - } else { - $pkgConst = strtoupper( $hash['ipackage'] ).'_PKG_URL'; - if( defined( $pkgConst ) ) { - $url = constant( strtoupper( $hash['ipackage'] ).'_PKG_URL' ).$hash['ifile']; - } - } - } else { - $url = constant( strtoupper( $gBitSystem->getActivePackage() ).'_PKG_URL' ).$hash['ifile']; - } + $url = !empty( $hash['ipackage'] ) + ? ( $hash['ipackage'] == 'root' + ? $url = BIT_ROOT_URL.$hash['ifile'] + : constant( strtoupper( $hash['ipackage'] ).'_PKG_URL' ).$hash['ifile'] ) + : constant( strtoupper( $gBitSystem->getActivePackage() ).'_PKG_URL' ).$hash['ifile']; } else { $url = $_SERVER['SCRIPT_NAME']; } @@ -86,8 +82,8 @@ function smarty_function_smartlink( $pParams, &$pSmarty=NULL ) { $ititle = $hash['ititle']; $iatitle = empty( $hash['iatitle'] ) ? $ititle : $hash['iatitle']; } else { - $ititle = tra( $hash['ititle'] ); - $iatitle = empty( $hash['iatitle'] ) ? $ititle : tra ( $hash['iatitle'] ); + $ititle = KernelTools::tra( $hash['ititle'] ); + $iatitle = empty( $hash['iatitle'] ) ? $ititle : KernelTools::tra( $hash['iatitle'] ); } $atitle = 'title="'.$iatitle.'"'; @@ -98,7 +94,7 @@ function smarty_function_smartlink( $pParams, &$pSmarty=NULL ) { $sort_asc = $hash['isort'].'_asc'; $sort_desc = $hash['isort'].'_desc'; - $atitle = 'title="'.tra( 'Sort by' ).": ".$iatitle.'"'; + $atitle = 'title="'.KernelTools::tra( 'Sort by' ).": ".$iatitle.'"'; $url .= '?'; $url_params .= 'sort_mode='; @@ -109,27 +105,27 @@ function smarty_function_smartlink( $pParams, &$pSmarty=NULL ) { // check if sort_mode has anything to do with our link if( $sort_asc == $isort_mode ) { - $sorticon = array( + $sorticon = [ 'ipackage' => 'icons', - 'iname' => 'fa-sort-up', + 'iname' => 'icon-sort-up', 'iexplain' => 'ascending', 'iforce' => 'icon', - ); + ]; $url_params .= $sort_desc; } elseif( $sort_desc == $isort_mode ) { - $sorticon = array( + $sorticon = [ 'ipackage' => 'icons', - 'iname' => 'fa-sort-down', + 'iname' => 'icon-sort-down', 'iexplain' => 'descending', 'iforce' => 'icon', - ); + ]; $url_params .= $sort_asc; } else { $url_params .= $hash['isort'].'_'.( isset( $hash['iorder'] ) ? $hash['iorder'] : 'asc' ); } } - $ignore = array( 'iatitle', 'icontrol', 'isort', 'ianchor', 'isort_mode', 'iorder', 'ititle', 'idefault', 'ifile', 'ipackage', 'itype', 'iurl', 'ionclick', 'ibiticon', 'iforce', 'itra', 'booticon' ); + $ignore = [ 'iatitle', 'icontrol', 'isort', 'ianchor', 'isort_mode', 'iorder', 'ititle', 'idefault', 'ifile', 'ipackage', 'itype', 'iurl', 'ionclick', 'ibiticon', 'booticon', 'iforce', 'itra' ]; // append any other paramters that were passed in foreach( $hash as $key => $val ) { if( !empty( $val ) && !in_array( $key, $ignore ) ) { @@ -163,7 +159,7 @@ function smarty_function_smartlink( $pParams, &$pSmarty=NULL ) { } // encode quote marks so we not break href="" construction - $url_params = preg_replace('/"/', '%22', $url_params); + $url_params = preg_replace('/"/', '%22', $url_params ?? ''); if( isset( $hash['itype'] ) && $hash['itype'] == 'url' ) { $ret = $url.$url_params; @@ -172,13 +168,13 @@ function smarty_function_smartlink( $pParams, &$pSmarty=NULL ) { // if we want to display an icon instead of text, do that if( isset( $hash['booticon'] ) ) { - if( !empty( $tmp[2] )) { - $tmp[1] .= "/".$tmp[2]; - } - $booticon = array( + // if( !empty( $tmp[2] )) { + // $tmp[1] .= "/".$tmp[2]; + // } + $booticon = [ 'iname' => $hash['booticon'], 'iexplain' => $hash['ititle'], // use untranslated ititle - booticon has a tra() - ); + ]; if( !empty( $hash['iforce'] ) ) { $booticon['iforce'] = $hash['iforce']; } @@ -188,11 +184,11 @@ function smarty_function_smartlink( $pParams, &$pSmarty=NULL ) { if( !empty( $tmp[2] )) { $tmp[1] .= "/".$tmp[2]; } - $ibiticon = array( + $ibiticon = [ 'ipackage' => $tmp[0], 'iname' => $tmp[1], 'iexplain' => $hash['ititle'], // use untranslated ititle - biticon has a tra() - ); + ]; if( !empty( $hash['iforce'] ) ) { $ibiticon['iforce'] = $hash['iforce']; } @@ -211,4 +207,3 @@ function smarty_function_smartlink( $pParams, &$pSmarty=NULL ) { } return $ret; } -?> diff --git a/smartyplugins/function.spellchecker.php b/smartyplugins/function.spellchecker.php index 92dbb0d..52f730c 100644..100755 --- a/smartyplugins/function.spellchecker.php +++ b/smartyplugins/function.spellchecker.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -19,4 +21,3 @@ function smarty_function_spellchecker( $params, &$gBitSmarty ) { echo 'title="spellcheck_icons" accesskey="'.BNSPELL_PKG_URL.'spell_checker.php"'; } } -?> diff --git a/smartyplugins/function.textarea.php b/smartyplugins/function.textarea.php index 218169e..c1990f7 100644..100755 --- a/smartyplugins/function.textarea.php +++ b/smartyplugins/function.textarea.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -14,7 +16,7 @@ * Name: textarea * ------------------------------------------------------------- */ -function smarty_function_textarea( $pParams, &$pSmarty ) { +function smarty_function_textarea( $pParams, &$pSmartyTemplate ) { global $gBitSystem, $gContent, $gLibertySystem, $gBitSmarty; $attributes = ''; @@ -28,10 +30,10 @@ function smarty_function_textarea( $pParams, &$pSmarty ) { $class .= 'wysiwyg'; } if (empty($pParams['rows'])) { - $pParams['rows'] = (empty($_COOKIE['rows']) ? $gBitSystem->getConfig('liberty_textarea_height', 20) : $_COOKIE['rows']); + $pParams['rows'] = empty($_COOKIE['rows']) ? $gBitSystem->getConfig('liberty_textarea_height', 20) : $_COOKIE['rows']; } if (empty($pParams['cols'])) { - $pParams['cols'] = (empty($_COOKIE['cols']) ? $gBitSystem->getConfig('liberty_textarea_width', 35) : $_COOKIE['rows']); + $pParams['cols'] = empty($_COOKIE['cols']) ? $gBitSystem->getConfig('liberty_textarea_width', 35) : $_COOKIE['rows']; } if (empty($pParams['id'])) { $pParams['id'] = LIBERTY_TEXT_AREA; @@ -54,7 +56,7 @@ function smarty_function_textarea( $pParams, &$pSmarty ) { case 'error': case 'required': case 'maxchars': - $pSmarty->assign("textarea_".$_key, $_value); + $gBitSmarty->assign("textarea_".$_key, $_value); break; case 'class': $class .= ' '.$_key; @@ -63,16 +65,16 @@ function smarty_function_textarea( $pParams, &$pSmarty ) { $style .= $_key; break; case 'formatguid': - $pSmarty->assign('formatGuid', $_value); + $gBitSmarty->assign('formatGuid', $_value); break; case 'langcode': - $pSmarty->assign('langCode', $_value); + $gBitSmarty->assign('langCode', $_value); break; case 'gContent': // Trick out gContent $oldContent = $gContent; $gContent = $_value; - $pSmarty->assign('gContent', $_value); + $gBitSmarty->assign('gContent', $_value); break; default: $attributes .= $_key.'="'.$_value.'" '; @@ -84,31 +86,30 @@ function smarty_function_textarea( $pParams, &$pSmarty ) { if ($gBitSystem->isPackageActive('bnspell')) { $style .= (empty($style) ? '' : ';').'height:'.$pParams['rows'].'em;'; } - $pSmarty->assign('textarea_attributes', $attributes); + $gBitSmarty->assign('textarea_attributes', $attributes); if (!empty($style)) { - $pSmarty->assign('textarea_style', 'style="'.$style.'"'); + $gBitSmarty->assign('textarea_style', 'style="'.$style.'"'); } - $pSmarty->assign('textarea_class', 'class="form-control '.$class.'"'); - $ret = $pSmarty->fetch("bitpackage:liberty/edit_textarea.tpl"); + $gBitSmarty->assign('textarea_class', 'class="form-control '.$class.'"'); + $ret = $gBitSmarty->fetch("bitpackage:liberty/edit_textarea.tpl"); if( is_object( $gContent ) ) { if( $formatGuid = $gContent->getField( 'format_guid' ) ) { - $pSmarty->assign('formatGuid', $formatGuid); + $gBitSmarty->assign('formatGuid', $formatGuid); } if( $langCode = $gContent->getField( 'lang_code' ) ) { - $pSmarty->assign( 'langCode', $langCode ); + $gBitSmarty->assign( 'langCode', $langCode ); } } // Restore gContent if (isset($oldContent)) { $gContent = $oldContent; - $pSmarty->assign('gContent', $oldContent); + $gBitSmarty->assign('gContent', $oldContent); } // since we have the funky {textarea} in play, we'll display the edit help tab - $pSmarty->assign( 'display_help_tab', TRUE ); + $gBitSmarty->assign( 'display_help_tab', TRUE ); return $ret; } -?> diff --git a/smartyplugins/function.tk.php b/smartyplugins/function.tk.php index ace72df..3a15b85 100644..100755 --- a/smartyplugins/function.tk.php +++ b/smartyplugins/function.tk.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -12,4 +14,3 @@ function smarty_function_tk($params, &$gBitSmarty) { global $gBitUser; print 'tk='.$gBitUser->mTicket; } -?> diff --git a/smartyplugins/function.var_dump.php b/smartyplugins/function.var_dump.php index 28ae24a..35e9244 100644..100755 --- a/smartyplugins/function.var_dump.php +++ b/smartyplugins/function.var_dump.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -34,5 +36,3 @@ function smarty_function_var_dump($params, &$gBitSmarty) $debugger->msg("Smarty var_dump: Parameter 'var' not specified"); return '<!-- var_dump('.$v.') -->'; } - -?> diff --git a/smartyplugins/modifier.act_icon.php b/smartyplugins/modifier.act_icon.php index 72d2d2d..c9373e3 100644..100755 --- a/smartyplugins/modifier.act_icon.php +++ b/smartyplugins/modifier.act_icon.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -37,5 +39,3 @@ function smarty_modifier_act_icon($type,$isInter='n') $img="<img src='".GALAXIA_PKG_URL."icons/$ic' alt='$type' title='$type' />"; return $img; } - -?> diff --git a/smartyplugins/modifier.adjust.php b/smartyplugins/modifier.adjust.php index b6b2078..d2cb5de 100644..100755 --- a/smartyplugins/modifier.adjust.php +++ b/smartyplugins/modifier.adjust.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -39,5 +41,3 @@ function smarty_modifier_adjust($string, $length = 80, } } - -?> diff --git a/smartyplugins/modifier.append_url.php b/smartyplugins/modifier.append_url.php index dd66911..b6da128 100644..100755 --- a/smartyplugins/modifier.append_url.php +++ b/smartyplugins/modifier.append_url.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty diff --git a/smartyplugins/modifier.avatarize.php b/smartyplugins/modifier.avatarize.php index 029ed6b..4476ad0 100644..100755 --- a/smartyplugins/modifier.avatarize.php +++ b/smartyplugins/modifier.avatarize.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -15,12 +17,10 @@ */ function smarty_modifier_avatarize($user) { - global $gBitSystem; + global $gBitSystem, $gBitUser; $avatar = $gBitSystem->get_user_avatar($user); - if($gBitUser->userNameExists($user)&&$gBitSystem->getConfig('users_information','public',$user)=='public') { + if( $gBitUser->userNameExists($user) && $gBitSystem->getConfig('users_information','public',$user)=='public') { $avatar = '<a title="'.$user.'" href="'.USERS_PKG_URL.'index.php?home='.$user.'">'.$avatar.'</a>'; } return $avatar; } - -?> diff --git a/smartyplugins/modifier.bit_date_format.php b/smartyplugins/modifier.bit_date_format.php index c996aba..6fd5e92 100644..100755 --- a/smartyplugins/modifier.bit_date_format.php +++ b/smartyplugins/modifier.bit_date_format.php @@ -1,4 +1,8 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; +use Bitweaver\BitDate; + /** * Smarty plugin * @package Smarty @@ -9,7 +13,7 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin('smarty_shared_make_timestamp'); +// $gBitSmarty->loadPlugin('smarty_shared_make_timestamp'); /** * Smarty plugin @@ -30,26 +34,21 @@ function smarty_modifier_bit_date_format( $pString, $format = "%b %e, %Y", $pTra // we translate the entire date format string for total control if( $gBitSystem->getConfig( "bitlanguage", "en" ) != $gBitLanguage->mLanguage ) { - $format = tra( $pTraFormat ); + $format = KernelTools::tra( $pTraFormat ); } if( $gBitUser->getPreference( 'site_display_utc' ) == 'Fixed' && class_exists( 'DateTime' ) ) { date_default_timezone_set( $gBitUser->getPreference( 'site_display_timezone', 'UTC' ) ); - if ( is_numeric( $pString )) { - $dateTimeUser = new DateTime( '@'.(int)$pString ); - } else { - $dateTimeUser = new DateTime( $pString ); - } + $dateTimeUser = is_numeric( $pString ) + ? new \DateTime( '@'.(int)$pString ) + : new \DateTime( $pString ); $disptime = strtotime($dateTimeUser->format(DATE_W3C)); return $gBitSystem->mServerTimestamp->strftime( $format, $disptime ); } else { - if( $gBitSystem->get_display_offset() ) { - $format = preg_replace( "/ ?%Z/",'', $format ); - } else { - $format = preg_replace( "/%Z/", "UTC", $format ); - } + $format = $gBitSystem->get_display_offset() + ? preg_replace( "/ ?%Z/",'', $format ) + : $format = preg_replace( "/%Z/", "UTC", $format ); $disptime = $gBitSystem->mServerTimestamp->getDisplayDateFromUTC( $pString ); } return $gBitSystem->mServerTimestamp->strftime( $format, $disptime, TRUE ); } -?> diff --git a/smartyplugins/modifier.bit_date_nls.php b/smartyplugins/modifier.bit_date_nls.php index 1c47468..c4931fb 100644..100755 --- a/smartyplugins/modifier.bit_date_nls.php +++ b/smartyplugins/modifier.bit_date_nls.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,13 +11,12 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); +// $gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); /** * smarty_modifier_bit_long_datetime */ function smarty_modifier_bit_date_nls( $pString ) { global $gBitSystem; - return smarty_modifier_bit_date_format( $pString, '%Y-%m-%d %H:%M', '%Y%m%d %H%M' ); + return \Bitweaver\Plugins\smarty_modifier_bit_date_format( $pString, '%Y-%m-%d %H:%M', '%Y%m%d %H%M' ); } -?> diff --git a/smartyplugins/modifier.bit_long_date.php b/smartyplugins/modifier.bit_long_date.php index 26b0d72..98ab3c9 100644..100755 --- a/smartyplugins/modifier.bit_long_date.php +++ b/smartyplugins/modifier.bit_long_date.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,13 +11,12 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); +// $gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); /** * smarty_modifier_bit_long_date */ function smarty_modifier_bit_long_date( $pString ) { global $gBitSystem; - return smarty_modifier_bit_date_format( $pString, $gBitSystem->get_long_date_format(), '%A, %B %d, %Y' ); + return \Bitweaver\Plugins\smarty_modifier_bit_date_format( $pString, $gBitSystem->get_long_date_format(), '%A, %B %d, %Y' ); } -?> diff --git a/smartyplugins/modifier.bit_long_datetime.php b/smartyplugins/modifier.bit_long_datetime.php index 3c52a92..9351e9c 100644..100755 --- a/smartyplugins/modifier.bit_long_datetime.php +++ b/smartyplugins/modifier.bit_long_datetime.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,13 +11,12 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); +// $gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); /** * smarty_modifier_bit_long_datetime */ function smarty_modifier_bit_long_datetime( $pString ) { global $gBitSystem; - return smarty_modifier_bit_date_format( $pString, $gBitSystem->get_long_datetime_format(), '%A %d of %B, %Y (%H:%M:%S %Z)' ); + return \Bitweaver\Plugins\smarty_modifier_bit_date_format( $pString, $gBitSystem->get_long_datetime_format(), '%A %d of %B, %Y (%H:%M:%S %Z)' ); } -?> diff --git a/smartyplugins/modifier.bit_long_time.php b/smartyplugins/modifier.bit_long_time.php index e5cab35..b284883 100644..100755 --- a/smartyplugins/modifier.bit_long_time.php +++ b/smartyplugins/modifier.bit_long_time.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,13 +11,12 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); +// $gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); /** * smarty_modifier_bit_long_time */ function smarty_modifier_bit_long_time( $pString ) { global $gBitSystem; - return smarty_modifier_bit_date_format( $pString, $gBitSystem->get_long_time_format(), '%H:%M:%S %Z' ); + return \Bitweaver\Plugins\smarty_modifier_bit_date_format( $pString, $gBitSystem->get_long_time_format(), '%H:%M:%S %Z' ); } -?> diff --git a/smartyplugins/modifier.bit_short_date.php b/smartyplugins/modifier.bit_short_date.php index 6df05af..867b180 100644..100755 --- a/smartyplugins/modifier.bit_short_date.php +++ b/smartyplugins/modifier.bit_short_date.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,13 +11,12 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin('smarty_modifier_bit_date_format'); +// $gBitSmarty->loadPlugin('smarty_modifier_bit_date_format'); /** * smarty_modifier_bit_short_date */ function smarty_modifier_bit_short_date( $pString ) { global $gBitSystem; - return smarty_modifier_bit_date_format( $pString, $gBitSystem->get_short_date_format(), '%d %b %Y' ); + return \Bitweaver\Plugins\smarty_modifier_bit_date_format( $pString, $gBitSystem->get_short_date_format(), '%d %b %Y' ); } -?> diff --git a/smartyplugins/modifier.bit_short_datetime.php b/smartyplugins/modifier.bit_short_datetime.php index 5fcaec2..a97cd3d 100644..100755 --- a/smartyplugins/modifier.bit_short_datetime.php +++ b/smartyplugins/modifier.bit_short_datetime.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,7 +11,7 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); +// $gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); /** * smarty_modifier_bit_short_datetime @@ -17,9 +19,8 @@ $gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); function smarty_modifier_bit_short_datetime( $pString, $time='' ) { global $gBitSystem; if( !empty( $time ) && date( 'Ymd' ) == date( 'Ymd', $pString )) { - return smarty_modifier_bit_date_format( $pString, $gBitSystem->get_short_time_format(), '%H:%M %Z' ); + return \Bitweaver\Plugins\smarty_modifier_bit_date_format( $pString, $gBitSystem->get_short_time_format(), '%H:%M %Z' ); } else { - return smarty_modifier_bit_date_format( $pString, $gBitSystem->get_short_datetime_format(), '%d %b %Y (%H:%M %Z)' ); + return \Bitweaver\Plugins\smarty_modifier_bit_date_format( $pString, $gBitSystem->get_short_datetime_format(), '%d %b %Y (%H:%M %Z)' ); } } -?> diff --git a/smartyplugins/modifier.bit_short_time.php b/smartyplugins/modifier.bit_short_time.php index e7928f2..7f3fd43 100644..100755 --- a/smartyplugins/modifier.bit_short_time.php +++ b/smartyplugins/modifier.bit_short_time.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -9,13 +11,12 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); +// $gBitSmarty->loadPlugin( 'smarty_modifier_bit_date_format' ); /** * smarty_modifier_bit_short_time */ function smarty_modifier_bit_short_time( $pString ) { global $gBitSystem; - return smarty_modifier_bit_date_format( $pString, $gBitSystem->get_short_time_format(), '%H:%M %Z' ); + return \Bitweaver\Plugins\smarty_modifier_bit_date_format( $pString, $gBitSystem->get_short_time_format(), '%H:%M %Z' ); } -?> diff --git a/smartyplugins/modifier.cal_date_format.php b/smartyplugins/modifier.cal_date_format.php index 228d193..b33381f 100644..100755 --- a/smartyplugins/modifier.cal_date_format.php +++ b/smartyplugins/modifier.cal_date_format.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\BitDate; + /** * Smarty plugin * @package Smarty @@ -9,7 +12,7 @@ * required setup */ global $gBitSmarty; -$gBitSmarty->loadPlugin('smarty_shared_make_timestamp'); +// $gBitSmarty->loadPlugin('smarty_shared_make_timestamp'); /** * Smarty plugin @@ -24,23 +27,18 @@ $gBitSmarty->loadPlugin('smarty_shared_make_timestamp'); */ function smarty_modifier_cal_date_format($string, $format = "%b %e, %Y", $default_date=null, $tra_format=null) { - $mDate = new BitDate(); - if ( $mDate->get_display_offset()) { - $format = preg_replace("/ ?%Z/","",$format); - } else { - $format = preg_replace("/%Z/","UTC",$format); - } + $mDate = new BitDate(0); + $format = $mDate->get_display_offset() + ? preg_replace("/ ?%Z/","",$format) + : preg_replace("/%Z/","UTC",$format); - $disptime = strtotime( $string ); // Let PHP handle all conversion, TZ or not... + $disptime = $mDate->getTimestampFromISO($string); global $gBitSystem, $gBitLanguage; //$gBitLanguage->mLanguage= $gBitSystem->getConfig("language", "en"); if ($gBitSystem->getConfig("language", "en") != $gBitLanguage->mLanguage && $tra_format) { $format = $tra_format; } - return $mDate->strftime($format, $disptime, true); } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/modifier.countryflag.php b/smartyplugins/modifier.countryflag.php index 094c027..7e19091 100644..100755 --- a/smartyplugins/modifier.countryflag.php +++ b/smartyplugins/modifier.countryflag.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -19,5 +21,3 @@ function smarty_modifier_countryflag($user) $flag = $gBitSystem->getConfig('users_country','Other',$user); return "<img alt='flag' src='".IMG_PKG_URL."flags/".$flag.".gif' />"; } - -?> diff --git a/smartyplugins/modifier.dbg.php b/smartyplugins/modifier.dbg.php index 0fd8e7c..134555b 100644..100755 --- a/smartyplugins/modifier.dbg.php +++ b/smartyplugins/modifier.dbg.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -25,5 +27,3 @@ function smarty_modifier_dbg($string, $label = '') return $string; } } - -?> diff --git a/smartyplugins/modifier.displayUrl.php b/smartyplugins/modifier.displayUrl.php index 6f92884..e5f424f 100644..100755 --- a/smartyplugins/modifier.displayUrl.php +++ b/smartyplugins/modifier.displayUrl.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -81,7 +83,7 @@ function smarty_modifier_displayUrl($pMixed, $lib='') { return $pMixed['display_url']; } if (!empty($pMixed['content_type_guid'])) { - $type =$gLibertySystem->mContentTypes[$pContentType]; + $type =$gLibertySystem->mContentTypes[$pMixed['content_type_guid']]; if (!empty($type)) { $lib = $type['handler_class']; smarty_modifier_displayUrl_loadLib($type); @@ -99,4 +101,3 @@ function smarty_modifier_displayUrl($pMixed, $lib='') { } return LibertyContent::getDisplayUrlFromHash( $pMixed ); } -?> diff --git a/smartyplugins/modifier.display_bytes.php b/smartyplugins/modifier.display_bytes.php index aed6c99..284b793 100644..100755 --- a/smartyplugins/modifier.display_bytes.php +++ b/smartyplugins/modifier.display_bytes.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -23,4 +25,3 @@ function smarty_modifier_display_bytes( $pSize, $pDecimalPlaces = 1 ) { } return round( $pSize, $pDecimalPlaces )." ".$iec[$i]; } -?> diff --git a/smartyplugins/modifier.display_duration.php b/smartyplugins/modifier.display_duration.php index 7d2fe19..1b68722 100644..100755 --- a/smartyplugins/modifier.display_duration.php +++ b/smartyplugins/modifier.display_duration.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * @package Smarty * @subpackage plugins @@ -35,4 +37,3 @@ function smarty_modifier_display_duration( $pDuration ) { $ret .= str_pad( $duration['hour'], 2, 0, STR_PAD_LEFT ).':'.str_pad( $duration['min'], 2, 0, STR_PAD_LEFT ).':'.str_pad( $duration['sec'], 2, 0, STR_PAD_LEFT ); return $ret; } -?> diff --git a/smartyplugins/modifier.div.php b/smartyplugins/modifier.div.php index 7431b1f..27e5404 100644..100755 --- a/smartyplugins/modifier.div.php +++ b/smartyplugins/modifier.div.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -21,5 +23,3 @@ function smarty_modifier_div($string,$num,$max=10) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/modifier.duration.php b/smartyplugins/modifier.duration.php index ee7cb8f..0d2fcc9 100644..100755 --- a/smartyplugins/modifier.duration.php +++ b/smartyplugins/modifier.duration.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin modifier duration * @@ -18,21 +20,21 @@ */ function smarty_modifier_duration($string) { - $result=Array(); + $result=[]; if($string > 60*60*24) { $days = floor($string/(60*60*24)); $result[]="$days days"; - $string = $string % (60*60*24); + $string %= 60*60*24; } if($string > 60*60) { $hours = floor($string/(60*60)); $result[]="$hours hours"; - $string = $string % (60*60); + $string %= 60*60; } if($string > 60) { - $mins = floor($string/(60)); + $mins = floor($string/60); $result[]="$mins minutes"; - $string = $string % (60); + $string %= 60; } if($string > 0) { $result[]="$string seconds"; @@ -40,5 +42,3 @@ function smarty_modifier_duration($string) return implode(' ',$result); } - -?> diff --git a/smartyplugins/modifier.htmlToText.php b/smartyplugins/modifier.htmlToText.php index c1c4107..eedea7e 100644..100755 --- a/smartyplugins/modifier.htmlToText.php +++ b/smartyplugins/modifier.htmlToText.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -17,4 +19,3 @@ function smarty_modifier_htmlToText( $string ) { return preg_replace('/<.*>/U', '', $string); } -?> diff --git a/smartyplugins/modifier.iconify.php b/smartyplugins/modifier.iconify.php index 31eb528..571e246 100644..100755 --- a/smartyplugins/modifier.iconify.php +++ b/smartyplugins/modifier.iconify.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -18,11 +20,9 @@ function smarty_modifier_iconify($string) // XINGICON what are we going to do with this function? is this needed? $string=substr($string,strlen($string)-3); if(file_exists(IMG_PKG_PATH."icn/$string".".gif")) { - return "<img border='0' src='".IMG_PKG_URL."icn/${string}.gif' alt='icon' class='icon' />"; + return "<img border='0' src='".IMG_PKG_URL."icn/{$string}.gif' alt='icon' class='icon' />"; } else { return "<img border='0' src='".IMG_PKG_URL."icn/else.gif' alt='icon' class='icon' />"; } } - -?> diff --git a/smartyplugins/modifier.nlbr.php b/smartyplugins/modifier.nlbr.php index 03f9d96..86dae2a 100644..100755 --- a/smartyplugins/modifier.nlbr.php +++ b/smartyplugins/modifier.nlbr.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -18,5 +20,3 @@ function smarty_modifier_nlbr($string) return nl2br($string); } - -?> diff --git a/smartyplugins/modifier.ordinal_suffix.php b/smartyplugins/modifier.ordinal_suffix.php index ac94175..088a40a 100644..100755 --- a/smartyplugins/modifier.ordinal_suffix.php +++ b/smartyplugins/modifier.ordinal_suffix.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -69,4 +71,3 @@ function smarty_modifier_ordinal_suffix( $pNum ) { return $pNum.tra( $suffix ); } -?> diff --git a/smartyplugins/modifier.plural.php b/smartyplugins/modifier.plural.php index 9c535b0..4e0f552 100644..100755 --- a/smartyplugins/modifier.plural.php +++ b/smartyplugins/modifier.plural.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * @package Plugins * @author Bimal Poudel @@ -48,5 +50,3 @@ function smarty_modifier_plural($word = '', $counter = 0) return $plural; } - -?> diff --git a/smartyplugins/modifier.quoted.php b/smartyplugins/modifier.quoted.php index f529375..c5dc911 100644..100755 --- a/smartyplugins/modifier.quoted.php +++ b/smartyplugins/modifier.quoted.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -20,5 +22,3 @@ function smarty_modifier_quoted($string) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/modifier.reltime.php b/smartyplugins/modifier.reltime.php index 4fad97a..57548ea 100644..100755 --- a/smartyplugins/modifier.reltime.php +++ b/smartyplugins/modifier.reltime.php @@ -1,4 +1,7 @@ <?php +namespace Bitweaver\Plugins; +use Bitweaver\KernelTools; + /** * Smarty plugin * @package Smarty @@ -13,8 +16,8 @@ function smarty_modifier_reltime( $pTimeStamp, $pMode = 'long', $pFallback = 'bi // if this feature is not desired, we simply don't use it. if( !$gBitSystem->isFeatureActive( 'site_display_reltime' ) ) { - $gBitSmarty->loadPlugin( "smarty_modifier_$pFallback" ); - $pFallback = "smarty_modifier_$pFallback"; +// $gBitSmarty->loadPlugin( "smarty_modifier_$pFallback" ); + $pFallback = "Bitweaver\\Plugins\\smarty_modifier_$pFallback"; return $pFallback( $pTimeStamp ); } @@ -33,28 +36,28 @@ function smarty_modifier_reltime( $pTimeStamp, $pMode = 'long', $pFallback = 'bi if( $delta < 0 ) { $delta = -$delta; - return tra( "In the future" ).": "; + return KernelTools::tra( "In the future" ).": "; } if( $delta < 1 ) { // seconds - return tra( "within the last second" ); + return KernelTools::tra( "within the last second" ); } elseif( $delta < $min ) { // minutes - return tra( "within the last minute" ); + return KernelTools::tra( "within the last minute" ); } elseif( $delta < $hour ) { // hours if( $delta < $min * 2 ) { - return tra( "one minute ago" ); + return KernelTools::tra( "one minute ago" ); } else { - return round( $delta / $min )." ".tra( "minutes ago" ); + return round( $delta / $min )." ".KernelTools::tra( "minutes ago" ); } } elseif( $delta < $day ) { // up to a day if( $delta < $hour * 1.1 ) { - return tra( "one hour ago" ); + return KernelTools::tra( "one hour ago" ); } elseif( $delta < $day ) { - $delta_hours = floor( ( $delta - ( floor( $delta / $hour ) * $hour ) ) / $min ); + $delta_hours = floor( ( $delta - floor( $delta / $hour ) * $hour ) / $min ); if( $pMode == 'short' ) { return floor( $delta / $hour )."h {$delta_hours}m ago"; } @@ -74,23 +77,22 @@ function smarty_modifier_reltime( $pTimeStamp, $pMode = 'long', $pFallback = 'bi } else { - return round( $delta / $hour )." ".tra( "hour(s) ago" ); + return round( $delta / $hour )." ".KernelTools::tra( "hour(s) ago" ); } } elseif( $delta < $week ) { // up to a week if( $delta < $day * 2 ) { - return tra( "Yesterday" )." ".date( $strf, $pTimeStamp ); + return KernelTools::tra( "Yesterday" )." ".date( $strf, $pTimeStamp ); } else { if( $pMode == 'short' ) { return date( 'D '.$strf, $pTimeStamp ); } - return tra( date( 'l', $pTimeStamp ) )." ".date( $strf, $pTimeStamp ); + return KernelTools::tra( date( 'l', $pTimeStamp ) )." ".date( $strf, $pTimeStamp ); } } else { // anything longer than a week - $gBitSmarty->loadPlugin( "smarty_modifier_$pFallback" ); - $pFallback = "smarty_modifier_$pFallback"; +// $gBitSmarty->loadPlugin( "smarty_modifier_$pFallback" ); + $pFallback = "Bitweaver\\Plugins\\smarty_modifier_$pFallback"; return $pFallback( $pTimeStamp ); } } -?> diff --git a/smartyplugins/modifier.replace_limit.php b/smartyplugins/modifier.replace_limit.php index d278562..af60d0f 100644..100755 --- a/smartyplugins/modifier.replace_limit.php +++ b/smartyplugins/modifier.replace_limit.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty diff --git a/smartyplugins/modifier.times.php b/smartyplugins/modifier.times.php index 385d134..6a8fcda 100644..100755 --- a/smartyplugins/modifier.times.php +++ b/smartyplugins/modifier.times.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -14,5 +16,3 @@ function smarty_modifier_times($n1,$n2) } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/modifier.truncate.php b/smartyplugins/modifier.truncate.php index 0ef73c6..2789e9f 100644..100755 --- a/smartyplugins/modifier.truncate.php +++ b/smartyplugins/modifier.truncate.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -45,5 +47,3 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/modifier.userlink.php b/smartyplugins/modifier.userlink.php index b7d2f36..49b0aa0 100644..100755 --- a/smartyplugins/modifier.userlink.php +++ b/smartyplugins/modifier.userlink.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -13,5 +15,3 @@ function smarty_modifier_userlink($user,$class='username') { } /* vim: set expandtab: */ - -?> diff --git a/smartyplugins/outputfilter.groupslayout.php b/smartyplugins/outputfilter.groupslayout.php index c1b53cf..059048b 100644..100755 --- a/smartyplugins/outputfilter.groupslayout.php +++ b/smartyplugins/outputfilter.groupslayout.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -56,7 +58,7 @@ function smarty_outputfilter_groupslayout( $source, &$gBitSmarty ) { preg_match_all( $extractor, $source, $match ); $contents = $match[0]; - $ret = array(); + $ret = []; foreach( $contents as $key => $content ) { // if we picked something up, we rip it out and modify if( !empty( $content ) ) { @@ -99,4 +101,3 @@ function smarty_outputfilter_groupslayout( $source, &$gBitSmarty ) { return $source; } -?> diff --git a/smartyplugins/outputfilter.highlight.php b/smartyplugins/outputfilter.highlight.php new file mode 100755 index 0000000..ce29642 --- /dev/null +++ b/smartyplugins/outputfilter.highlight.php @@ -0,0 +1,123 @@ +<?php +/** + * Smarty plugin + * @package Smarty + * @subpackage plugins + */ + +/** + * Smarty plugin + * ------------------------------------------------------------- + * File: outputfilter.highlight.php + * Type: outputfilter + * Name: highlight + * Version: 1.1 + * Date: Sep 18, 2003 + * Version: 1.0 + * Date: Aug 10, 2003 + * Purpose: Adds Google-cache-like highlighting for terms in a + * template after its rendered. This can be used + * easily integrated with the wiki search functionality + * to provide highlighted search terms. + * Install: Drop into the plugin directory, call + * $gBitSmarty->loadFilter('output','highlight'); + * from application. + * Author: Greg Hinkle <ghinkl@users.sourceforge.net> + * patched by mose <mose@feu.org> + * ------------------------------------------------------------- + */ +function smarty_output_highlight( $source, $gBitSmarty ) { + global $gBitSystem; + if( $gBitSystem->isFeatureActive( 'themes_output_highlighting' ) ) { + // This array is used to choose colours for supplied highlight terms + $colorArr = [ '#ffffcc', '#ffcccc', '#a0ffff', '#ffccff', '#ccffcc' ]; + + // don't highlight characters that are used as replacements + $find = [ + "!(\s|^)%(\s|$)!", + "!(\s|^)#(\s|$)!", + "!(\s|^)@(\s|$)!", + "!(\s|^):(\s|$)!", + "!(\s|^)&(\s|$)!", + ]; + $words = trim( preg_replace( $find, "$1$2", urldecode( $_REQUEST['highlight'] ))); + if( empty( $words )) { + return $source; + } + + // get all text that needs to be highlighted + $extractor = "#<div\s+class=.?body[^>]*>.*?<!--\s*end\s*\.?body\s*-->#is"; + preg_match_all( $extractor, $source, $match ); + $highlights = $match[0]; + + $ret = []; + foreach( $highlights as $key => $highlight ) { + // if we picked something up, we highlight the contents + if( !empty( $highlight ) ) { + // highlighted words + $source = preg_replace( $extractor, "@@@##########:#########%:##########@@@", $source ); + + // extraction patterns and their replacements + $patterns = [ + // scripts + "!<script[^>]+>.*?</script>!is" => "@@@##########:#########%:#########&@@@", + // maketoc + "!<div class=.?maketoc[^>]*>.*?</div>!si" => "@@@##########:#########%:#########@@@@", + // html tags + "'<[\/\!]*?[^<>]*?>'si" => "@@@##########:#########%:#########:@@@", + ]; + + ksort( $patterns ); + + foreach( $patterns as $pattern => $replace ) { + preg_match_all( $pattern, $highlight, $match ); + $matches[$replace] = $match[0]; + $highlight = preg_replace( $pattern, $replace, $highlight ); + } + + // Wrap all the highlight words with a colourful span + $wordArr = array(); + $pattern = '#"([^"]*)"#'; + if( preg_match_all( $pattern, $words, $ms ) ) { + $wordArr = $ms[1]; + // remove the words we've just dealt with + $words = preg_replace( $pattern, "", $words ); + } + + $words = preg_replace( "!\s+!", " ", $words ); + if( !empty( $words ) ) { + $wordArr = array_merge( $wordArr, explode( ' ', strip_tags($words) ) ); + } + + //$wordArr = split( " ", urldecode( $words ) ); + //vd($wordArr); + $i = 0; + $wordList = tra( "Highlighted words" ).': '; + foreach( $wordArr as $word ) { + $wordList .= '<span style="font-weight:bold;padding:0 0.3em;color:black;background-color:'.$colorArr[$i].';">'.$word.'</span> '; + $highlight = preg_replace( "/(".preg_quote( $word, '/' ).")/si", '<span style="font-weight:bold;color:black;background-color:'.$colorArr[$i++].';">$1</span>', $highlight ); + } + + krsort( $patterns ); + + foreach( $patterns as $pattern ) { + foreach( $matches[$pattern] as $insert ) { + $highlight = preg_replace( "!{$pattern}!", $insert, $highlight, 1 ); + } + } + + $highlight = '<div class="wordlist">'.$wordList.'</div>'.$highlight; + $ret[] = $highlight; + } + } + + // insert the highlighted code back into the source + foreach( $ret as $highlight ) { + // Escape dollars in highlight so they don't back reference + $highlight = preg_replace('!\$!','\\\$', $highlight); + $source = preg_replace( "!@@@##########:#########%:##########@@@!", $highlight, $source, 1 ); + } + } + + return $source; +}
\ No newline at end of file diff --git a/smartyplugins/prefilter.tr.php b/smartyplugins/prefilter.tr.php index 5311626..01031fb 100644..100755 --- a/smartyplugins/prefilter.tr.php +++ b/smartyplugins/prefilter.tr.php @@ -1,4 +1,6 @@ <?php +namespace Bitweaver\Plugins; + /** * Smarty plugin * @package Smarty @@ -83,4 +85,3 @@ function _translate_lang( $pKey ) { return $pKey[1].$pKey[2]."{/tr}"; } } -?> |
