Commit 929d8891 authored by pkdille's avatar pkdille

No changes - code styling only (seen on quality.tiki.org)

parent bf74f0a1
......@@ -7,8 +7,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/*
......@@ -22,28 +22,29 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
* using $pad as filler.
* -------------------------------------------------------------
*/
function smarty_modifier_adjust($string,
$length = 80,
$pad = ' ',
$etc = '...',
$break_words = false
)
function smarty_modifier_adjust(
$string,
$length = 80,
$pad = ' ',
$etc = '...',
$break_words = false
)
{
if ($length == 0)
return '';
if ($length == 0)
return '';
if (strlen($string) > $length) {
$length -= strlen($etc);
$fragment = substr($string, 0, $length+1);
if ($break_words)
$fragment = substr($fragment, 0, -1);
else
$fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
return $fragment . $etc;
} elseif (strlen($string)<$length) {
return $string . str_repeat($pad, $length - strlen($string));
} else {
return $string;
}
if (strlen($string) > $length) {
$length -= strlen($etc);
$fragment = substr($string, 0, $length+1);
if ($break_words)
$fragment = substr($fragment, 0, -1);
else
$fragment = preg_replace('/\s+(\S+)?$/', '', $fragment);
return $fragment . $etc;
} elseif (strlen($string)<$length) {
return $string . str_repeat($pad, $length - strlen($string));
} else {
return $string;
}
}
......@@ -7,8 +7,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/*
......@@ -21,15 +21,15 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
*/
function smarty_modifier_avatarize($user)
{
global $tikilib;
global $userlib;
$avatar = $tikilib->get_user_avatar($user);
if ( $avatar != '' && $tikilib->get_user_preference($user, 'user_information', 'public') == 'public' ) {
$id = $userlib->get_user_id($user);
include_once('tiki-sefurl.php');
$url = "tiki-user_information.php?userId=$id";
$url = filter_out_sefurl($url);
$avatar = "<a title=\"" . htmlspecialchars($user, ENT_QUOTES) . "\" href=\"$url\">".$avatar.'</a>';
}
return $avatar;
global $tikilib;
global $userlib;
$avatar = $tikilib->get_user_avatar($user);
if ( $avatar != '' && $tikilib->get_user_preference($user, 'user_information', 'public') == 'public' ) {
$id = $userlib->get_user_id($user);
include_once('tiki-sefurl.php');
$url = "tiki-user_information.php?userId=$id";
$url = filter_out_sefurl($url);
$avatar = "<a title=\"" . htmlspecialchars($user, ENT_QUOTES) . "\" href=\"$url\">".$avatar.'</a>';
}
return $avatar;
}
......@@ -7,8 +7,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/**
* \brief Smarty modifier plugin to add user's country flag
......@@ -26,10 +26,10 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
function smarty_modifier_countryflag($user)
{
global $tikilib;
$flag = $tikilib->get_user_preference($user, 'country', 'Other');
if ($flag == 'Other' || empty($flag))
return '';
return "<img alt='" . tra(str_replace('_', ' ', $flag)) . "' src='img/flags/" . $flag .
".gif' title='" . tra(str_replace('_', ' ', $flag)) . "' />";
global $tikilib;
$flag = $tikilib->get_user_preference($user, 'country', 'Other');
if ($flag == 'Other' || empty($flag))
return '';
return "<img alt='" . tra(str_replace('_', ' ', $flag)) . "' src='img/flags/" . $flag .
".gif' title='" . tra(str_replace('_', ' ', $flag)) . "' />";
}
......@@ -7,8 +7,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/** \file
......@@ -23,9 +23,9 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
*/
function smarty_modifier_dbg($string, $label = '')
{
global $debugger;
require_once('lib/debug/debugger.php');
//
$debugger->msg('Smarty log'.((strlen($label) > 0) ? ': '.$label : '').': '.$string);
return $string;
global $debugger;
require_once('lib/debug/debugger.php');
//
$debugger->msg('Smarty log' . ((strlen($label) > 0) ? ': ' . $label : '') . ': ' . $string);
return $string;
}
......@@ -7,8 +7,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/*
......@@ -20,7 +20,11 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
*/
function smarty_modifier_div($string, $num, $max=10)
{
if ($num==0) return 0;
if (ceil(strlen($string)/$num)>$max) return $max;
return ceil(strlen($string)/$num);
if ($num == 0)
return 0;
if (ceil(strlen($string) / $num) > $max)
return $max;
return ceil(strlen($string) / $num);
}
......@@ -13,8 +13,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/**
......@@ -32,82 +32,81 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
*/
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'UTF-8')
{
switch ($esc_type) {
case 'html':
$return = htmlspecialchars($string, ENT_QUOTES, $char_set);
// Convert back sanitization tags into real tags to avoid them to be displayed
$return = str_replace('&lt;x&gt;', '<x>', $return);
// Convert back sanitization tags into real tags for no wrap space
$return = str_replace('&amp;nbsp;', '&nbsp;', $return);
return $return;
switch ($esc_type) {
case 'html':
$return = htmlspecialchars($string, ENT_QUOTES, $char_set);
// Convert back sanitization tags into real tags to avoid them to be displayed
$return = str_replace('&lt;x&gt;', '<x>', $return);
// Convert back sanitization tags into real tags for no wrap space
$return = str_replace('&amp;nbsp;', '&nbsp;', $return);
return $return;
case 'htmlall':
$return = htmlentities($string, ENT_QUOTES, $char_set);
if (!strlen($return) && strlen($string)) // Bug php when there is non utf8 characters in the string(http://bugs.php.net/bug.php?id=43549, http://bugs.php.net/bug.php?id=43294)
$return = htmlentities($string, ENT_QUOTES);
// Convert back sanitization tags into real tags to avoid them to be displayed
$return = str_replace('&lt;x&gt;', '<x>', $return);
return $return;
case 'htmlall':
$return = htmlentities($string, ENT_QUOTES, $char_set);
if (!strlen($return) && strlen($string)) // Bug php when there is non utf8 characters in the string(http://bugs.php.net/bug.php?id=43549, http://bugs.php.net/bug.php?id=43294)
$return = htmlentities($string, ENT_QUOTES);
// Convert back sanitization tags into real tags to avoid them to be displayed
$return = str_replace('&lt;x&gt;', '<x>', $return);
return $return;
case 'url':
return rawurlencode($string);
case 'url':
return rawurlencode($string);
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string));
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string));
case 'quotes':
// escape unescaped single quotes
return preg_replace("%(?<!\\\\)'%", "\\'", $string);
case 'quotes':
// escape unescaped single quotes
return preg_replace("%(?<!\\\\)'%", "\\'", $string);
case 'hex':
// escape every character into hex
$return = '';
for ($x=0, $xstrlen_string=strlen($string); $x < $xstrlen_string; $x++) {
$return .= '%' . bin2hex($string[$x]);
}
return $return;
case 'hex':
// escape every character into hex
$return = '';
for ($x=0, $xstrlen_string=strlen($string); $x < $xstrlen_string; $x++) {
$return .= '%' . bin2hex($string[$x]);
}
return $return;
case 'hexentity':
$return = '';
for ($x=0, $x_strlen_string = strlen($string); $x < $x_strlen_string; $x++) {
$return .= '&#x' . bin2hex($string[$x]) . ';';
}
return $return;
case 'hexentity':
$return = '';
for ($x=0, $x_strlen_string = strlen($string); $x < $x_strlen_string; $x++) {
$return .= '&#x' . bin2hex($string[$x]) . ';';
}
return $return;
case 'decentity':
$return = '';
for ($x=0, $x_strlen_string = strlen($string); $x < $x_strlen_string; $x++) {
$return .= '&#' . ord($string[$x]) . ';';
}
return $return;
case 'decentity':
$return = '';
for ($x=0, $x_strlen_string = strlen($string); $x < $x_strlen_string; $x++) {
$return .= '&#' . ord($string[$x]) . ';';
}
return $return;
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return strtr($string, array('\\'=>'\\\\', "'"=>"\\'", '"'=>'\\"', "\r"=>'\\r', "\n"=>'\\n', '</'=>'<\/'));
case 'javascript':
// escape quotes and backslashes, newlines, etc.
return strtr($string, array('\\'=>'\\\\', "'"=>"\\'", '"'=>'\\"', "\r"=>'\\r', "\n"=>'\\n', '</'=>'<\/'));
case 'mail':
// safe way to display e-mail address on a web page
return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
case 'mail':
// safe way to display e-mail address on a web page
return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
case 'nonstd':
// escape non-standard chars, such as ms document quotes
$_res = '';
for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
$_ord = ord(substr($string, $_i, 1));
// non-standard char, escape it
if ($_ord >= 126) {
$_res .= '&#' . $_ord . ';';
}
else {
$_res .= substr($string, $_i, 1);
}
}
return $_res;
case 'nonstd':
// escape non-standard chars, such as ms document quotes
$_res = '';
for ($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
$_ord = ord(substr($string, $_i, 1));
// non-standard char, escape it
if ($_ord >= 126) {
$_res .= '&#' . $_ord . ';';
} else {
$_res .= substr($string, $_i, 1);
}
}
return $_res;
case 'unescape':
return rawurldecode($string);
case 'unescape':
return rawurldecode($string);
default:
return $string;
}
return $string;
}
}
......@@ -7,8 +7,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/*
......@@ -24,14 +24,14 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
function smarty_modifier_how_many_user_inscriptions( $text )
{
$pattern="/\d+\[(\d+)\]/";
$out = preg_match_all($pattern, $text, $match);
$pattern = "/\d+\[(\d+)\]/";
$out = preg_match_all($pattern, $text, $match);
$nb=0;
$nb = 0;
foreach ($match[1] as $n){
$nb += ($n+1);
}
foreach ($match[1] as $n) {
$nb += ($n+1);
}
return $nb;
return $nb;
}
......@@ -21,5 +21,5 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
*/
function smarty_modifier_htmldecode( $s )
{
return TikiLib::htmldecode( $s );
return TikiLib::htmldecode($s);
}
......@@ -7,8 +7,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/**
......@@ -22,16 +22,18 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
function smarty_modifier_iconify($string, $filetype = null)
{
global $smarty;
global $smarty;
$smarty->loadPlugin('smarty_function_icon');
$ext = strtolower(substr($string, strrpos($string, '.') + 1));
$icon = file_exists("pics/icons/mime/$ext.png") ? $ext : 'default';
return smarty_function_icon(array(
'_id' => 'pics/icons/mime/'.$icon.'.png',
'alt' => ( $filetype === null ? $icon : $filetype ),
'class' => ''
), $smarty);
$smarty->loadPlugin('smarty_function_icon');
$ext = strtolower(substr($string, strrpos($string, '.') + 1));
$icon = file_exists("pics/icons/mime/$ext.png") ? $ext : 'default';
return smarty_function_icon(
array(
'_id' => 'pics/icons/mime/'.$icon.'.png',
'alt' => ( $filetype === null ? $icon : $filetype ),
'class' => ''
),
$smarty
);
}
......@@ -7,8 +7,8 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
/*
......@@ -21,33 +21,27 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
*/
function smarty_modifier_kbsize($string, $bytes = false, $nb_decimals = 2, $unit_separator = '&nbsp;')
{
if ( $string == '' ) return '';
if ( $string == '' )
return '';
// 1024 x 1024 x 1024 x 1024 = 1099511627776
if ( $string > 1099511627776 ) {
$string = number_format($string/1099511627776, $nb_decimals);
$kb_string = 'T';
}
// 1024 x 1024 x 1024 = 1073741824
elseif ( $string > 1073741824 ) {
$string = number_format($string/1073741824, $nb_decimals);
$kb_string = 'G';
}
// 1024 x 1024 = 1048576
elseif ( $string > 1048576 ) {
$string = number_format($string/1048576, $nb_decimals);
$kb_string = 'M';
}
elseif ( $string > 1024 ) {
$string = number_format($string/1024, $nb_decimals);
$kb_string = 'K';
}
else {
$string = $string;
$kb_string = '';
};
if ( $string > 1099511627776 ) { // 1024 x 1024 x 1024 x 1024 = 1099511627776
$string = number_format($string/1099511627776, $nb_decimals);
$kb_string = 'T';
} elseif ( $string > 1073741824 ) { // 1024 x 1024 x 1024 = 1073741824
$string = number_format($string/1073741824, $nb_decimals);
$kb_string = 'G';
} elseif ( $string > 1048576 ) { // 1024 x 1024 = 1048576
$string = number_format($string/1048576, $nb_decimals);
$kb_string = 'M';
} elseif ( $string > 1024 ) {
$string = number_format($string/1024, $nb_decimals);
$kb_string = 'K';
} else {
$string = $string;
$kb_string = '';
};
$kb_string = $kb_string . (($bytes) ? 'B' : 'b');
$kb_string = $kb_string . (($bytes) ? 'B' : 'b');
return $string.$unit_separator . tra($kb_string);
return $string . $unit_separator . tra($kb_string);
}
......@@ -7,13 +7,15 @@
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
header("location: index.php");
exit;
header("location: index.php");
exit;
}
function smarty_modifier_langname($lang)
{
if ( empty($lang) ) return '';
include('lang/langmapping.php');
return empty($langmapping[$lang]) ? $lang : tra($langmapping[$lang][0]);
if ( empty($lang) )
return '';
include('lang/langmapping.php');
return empty($langmapping[$lang]) ? $lang : tra($langmapping[$lang][0]);
}
......@@ -21,5 +21,5 @@ if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
*/
function smarty_modifier_lcfirst( $s )
{
return strtolower( $s{0} ). substr( $s, 1 );
return strtolower($s{0}) . substr($s, 1);
}
......@@ -50,7 +50,7 @@ function smarty_modifier_money_format($number, $local, $currency, $format = '%(#
}
//regex for format string
$regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?'.
$regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?'.
'(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/';
preg_match_all($regex, $format, $matches, PREG_SET_ORDER);
foreach ($matches as $fmatch) {
......@@ -72,32 +72,33 @@ function smarty_modifier_money_format($number, $local, $currency, $format = '%(#
$positive = true;
if ($value < 0) {
$positive = false;
$value *= -1;
$value *= -1;
}
$letter = $positive ? 'p' : 'n';
$prefix = $suffix = $cprefix = $csuffix = $signal = '';
$signal = $positive ? $locale['positive_sign'] : $locale['negative_sign'];
switch (true) {
case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+':
$prefix = $signal;
break;
break;
case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+':
$suffix = $signal;
break;
break;
case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+':
$cprefix = $signal;
break;
break;
case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+':
$csuffix = $signal;
break;
break;
case $flags['usesignal'] == '(':
case $locale["{$letter}_sign_posn"] == 0:
if ($positive == false) {
$prefix = '(';
$suffix = ')';
}
break;
break;
}
if (!$flags['nosimbol']) {
......@@ -110,10 +111,14 @@ function smarty_modifier_money_format($number, $local, $currency, $format = '%(#
$currency = '<span style="visibility:hidden">' . $currency . '</span>';
}
$space = $locale["{$letter}_sep_by_space"] && !empty($currency) && $display == 1 ? ' ' : '';
$space = $locale["{$letter}_sep_by_space"] && !empty($currency) && $display == 1 ? ' ' : '';
$value = number_format($value, $right, $locale['mon_decimal_point'],
$flags['nogroup'] ? '' : $locale['mon_thousands_sep']);
$value = number_format(
$value,
$right,
$locale['mon_decimal_point'],
$flags['nogroup'] ? '' : $locale['mon_thousands_sep']
);
$value = @explode($locale['mon_decimal_point'], $value);
$n = strlen($prefix) + strlen($currency) + strlen($value[0]);
......@@ -136,7 +141,7 @@ function smarty_modifier_money_format($number, $local, $currency, $format = '%(#
}
$format = str_replace($fmatch[0], $value, $format);
$format = !empty($rightpad) ? $format .= '<span style="visibility:hidden">' . $rightpad . '</span>' : $format;
$format = !empty($rightpad) ? $format .= '<span style="visibility:hidden">' . $rightpad . '</span>' : $format;
}
return $format;
}
......@@ -39,15 +39,15 @@ function separator($sep)
case 'c':
case ',':
$sep = ',';
break;
break;
case 'd':
case '.':
$sep = '.';
break;
break;
case 's':
case ' ':
$sep = ' ';
break;
break;
}
return $sep;
}
......@@ -20,87 +20,110 @@ function smarty_modifier_sefurl($source, $type='wiki', $with_next = '', $all_lan
$sefurl = $prefs['feature_sefurl'] == 'y';
switch($type){
case 'wiki page':
case 'wikipage':
$type = 'wiki';
case 'wiki':
return $wikilib->sefurl($source, $with_next, $all_langs);
case 'blog':
$href = $sefurl ? "blog$source" : "tiki-view_blog.php?blogId=$source";
break;
case 'blog post':
case 'blogpost':
$href = $sefurl ? "blogpost$source" : "tiki-view_blog_post.php?postId=$source";
break;
case 'gallery':
$href = 'tiki-browse_gallery.php?galleryId='. $source;
break;
case 'videogallery':
$href = 'tiki-browse_video_gallery.php?galleryId='. $source;
break;
case 'article':
$href = $sefurl ? "article$source" : "tiki-read_article.php?articleId=$source";
break;
case 'file':
$href = $sefurl ? "dl$source" : "tiki-download_file.php?fileId=$source";
break;
case 'thumbnail':
$href = $sefurl ? "thumbnail$source" : "tiki-download_file.php?fileId=$source&amp;thumbnail";
break;
case 'display':
$href = $sefurl ? "display$source" : "tiki-download_file.php?fileId=$source&amp;display";
break;
case 'preview':