20 public static function cutArray(array $arr, $nb, $presKey =
true) {
22 array_slice($arr, 0, $nb, $presKey),
23 array_slice($arr, $nb, count($arr), $presKey)
35 return html2text($html);
46 public static function htmlTag($tag, array $attributes, $content = null) {
47 $ret =
'<'.$tag.
' '.self::htmlAttribute($attributes);
48 if (!is_null($content))
49 $ret.=
'>'.$content.
'</'.$tag.
'>';
63 public static function mailTo($email, $name = null, array $attributes = array()) {
64 $emailObfs = self::htmlObfuscate($email);
67 $emailObfs = self::htmlObfuscate(
'mailto:').$emailObfs;
68 return self::htmlTag(
'a', array_merge(array(
'href'=>$emailObfs), $attributes), $name);
79 for ($i=0; $i<strlen($text); $i++)
80 $ret.=
'&#'.ord($text[$i]).
';';
92 foreach($prm as $k=>$v)
93 if (!empty($v) || $v === 0 || $v ===
'0')
94 $tmp[] = $k.
'="'.$v.
'"';
95 return implode(
' ', $tmp);
105 public static function htmlOut($val, $key =
false) {
106 if (is_array($val)) {
110 foreach($tmp as $k=>$t)
111 $val[self::htmlOut($k)] = self::htmlOut($t);
113 array_walk_recursive($val, create_function(
'&$v',
'$v = utils::htmlOut($v);'));
115 $tmp = self::htmlChars();
116 $val = str_replace(array_keys($tmp), $tmp, $val);
131 if (is_array($val)) {
135 foreach($tmp as $k=>$t)
136 $val[self::htmlDeOut($k)] = self::htmlDeOut($t);
138 array_walk_recursive($val, create_function(
'&$v',
'$v = utils::htmlDeOut($v);'));
140 $tmp = self::htmlChars();
141 $val = str_replace($tmp, array_keys($tmp), $val);
159 if (is_null(self::$htmlChars)) {
161 foreach(get_html_translation_table(HTML_ENTITIES) as $k=>$v) {
162 $tmp[utf8_encode($k)]= utf8_encode($v);
165 self::$htmlChars = array_merge(array(
190 return self::$htmlChars;
202 array_walk_recursive($val, create_function(
'&$v',
'$v = utf8_decode($v);'));
215 $tmp = explode(
'_', $className);
218 return implode(
'_', $tmp);
230 for($i = 1; $i<count($vars); $i+=2) {
231 $ret[$vars[$i-1]] = $vars[$i];
233 if ($i == count($vars))
234 $ret[$finalName] = $vars[$i-1];
259 'type'=>$cfg[
'default'],
264 if (array_key_exists($prm[
'type'], $cfg[
'icons'])
265 && is_array($cfg[
'icons'][$prm[
'type']])
266 && in_array($prm[
'name'], $cfg[
'icons'][$prm[
'type']])) {
267 $ret =
request::get(
'path').$cfg[
'dir'].
'/'.$prm[
'type'].request::getCfg(
'sepParam').$prm[
'name'].$cfg[
'ext'];
268 }
else if ($prm[
'type'] != $cfg[
'default']) {
269 $ret = self::getIcon(array(
'name'=>$prm[
'name'],
'imgTag'=>
false));
272 if ($ret && $prm[
'imgTag']) {
273 $alt = $prm[
'alt']? $prm[
'alt'] : ucFirst($prm[
'name']);
274 $ret = self::htmlTag(
'img', array_merge(array(
298 public static function formatDate(
$date, $type =
'date', $len =
'short2', $htmlOut =
true) {
299 if (is_null(self::$date)) {
302 self::$date->set(
$date, is_int(
$date) ?
'timestamp' :
'date');
303 if (is_bool($type)) {
304 self::$date->getCfg()->setA(array(
307 return self::$date->formatDirect($len);
309 self::$date->getCfg()->setA(array(
310 'defaultFormat'=>array(
312 'len'=>$type ==
'datetime' && $len ==
'short2' ?
'short' : $len
316 return self::$date->format();
326 public static function img($prm, $absolute =
false) {
328 $prm = array(
'src'=>$prm,
'size'=>
true);
330 if (isset($prm[
'size'])) {
332 if (!isset($prm[
'width']) && !isset($prm[
'height'])) {
333 $size = getimagesize(WEBROOT.
'img/'.$prm[
'src']);
334 if (!isset($prm[
'width']))
335 $prm[
'width'] = $size[0];
336 if (!isset($prm[
'height']))
337 $prm[
'height'] = $size[1];
343 return self::htmlTag(
'img', array_merge(array(
354 public static function render(array $prm) {
367 if (array_key_exists($keys[0], $source)) {
368 if (is_array($source[$keys[0]]) && count($keys) > 1)
369 $ret = self::getValInArray($source[$keys[0]], array_slice($keys, 1));
371 $ret = $source[$keys[0]];
383 public static function urlify($text, $ignore = null) {
385 array(
'ß' ,
'æ',
'Æ',
'Œ',
'œ',
'¼',
'½',
'¾',
'‰',
'™'),
386 array(
'ss',
'ae',
'AE',
'OE',
'oe',
'1/4',
'1/2',
'3/4',
'0/00',
'TM'),
388 $from =
"ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøðÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüŠšÝŸÿÑñÐÞþ()[]~¤$&%*@秶!¡†‡?¿;,.#:/\\^¨€¢£¥{}|¦+÷×±<>«»“”„\"‘’' ˜–—…©®¹²³°";
389 $to =
'AAAAAAaaaaaaOOOOOOoooooooEEEEeeeeCcIIIIiiiiUUUUuuuuSsYYyNnDPp cS --- EcPY __________------CR123-';
390 if (!is_null($ignore)) {
391 $len = strlen($ignore);
392 for($i = 0; $i < $len; $i++) {
393 $pos = strpos($from, $ignore{$i});
394 if ($pos !==
false) {
395 $from = substr($from, 0, $pos).substr($from, $pos+1);
396 $to = substr($to, 0, $pos).substr($to, $pos+1);
400 $ret = trim(str_replace(
401 array(
' ',
'-----',
'----',
'---',
'--'),
403 strtr(utf8_decode($text), utf8_decode($from), utf8_decode($to))), URLSEPARATOR);
405 return URLLOWER ? mb_strtolower($ret) : $ret;
417 $func = self::jsEncodeSearchFunc($vars);
419 $encoded = json_encode($vars);
421 $encoded = str_replace(array_keys($func), $func, $encoded);
435 foreach($vars as $k=>$v) {
436 if (is_string($v) && strpos($v,
'function(') === 0) {
437 $func[
'"'.$startFunc.
'Func"'] = $v;
438 $vars[$k] = $startFunc.
'Func';
440 }
else if (is_array($v)) {
441 $func = array_merge($func, self::jsEncodeSearchFunc($v, $startFunc));
455 public static function randomStr($len = 10, $ignore = null) {
456 $source =
'abcdefghikjlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
457 if (!is_null($ignore)) {
459 for($i=0;$i<strlen($ignore);$i++)
460 $tmp[] = $ignore[$i];
461 $source = str_replace($tmp,
'', $source);
463 $len = abs(intval($len));
464 $n = strlen($source)-1;
466 for($i = 0; $i < $len; $i++)
467 $r.= $source{rand(0, $n)};
479 foreach($checks as $c) {
480 $tmp = array_intersect_key($url, $c);
482 foreach($tmp as $k=>$v)
484 $nbM += (preg_match(
'/'.$c[$k].
'/', $v)? 1 : 0);
486 if ($nbM == count($tmp))
static htmlOut($val, $key=false)
static htmlDeOut($val, $key=false)
static img($prm, $absolute=false)
static initTabNumPair(array &$vars, $finalName='final')
static urlify($text, $ignore=null)
static htmlTag($tag, array $attributes, $content=null)
static formatDate($date, $type='date', $len='short2', $htmlOut=true)
static randomStr($len=10, $ignore=null)
static getHelper($className, array $cfg=array())
static getIcon(array $prm)
static jsEncodeSearchFunc(array &$vars, &$startFunc=1)
static initTab(array &$vars, array $init)
static htmlAttribute(array $prm)
static mailTo($email, $name=null, array $attributes=array())
static cutArray(array $arr, $nb, $presKey=true)
static isContained(array $url, array $checks)
static getModuleName($className)
static loadCfg($className, $searchParent=true)
static render(array $prm)
static getValInArray(array $source, array $keys)
static htmlObfuscate($text)
static get($className, array $cfg=array())