@ -16,250 +16,6 @@
* All rights reserved .
*/
// Handy.
function println ( $string )
{
$args = func_get_args ();
echo call_user_func_array ( 'sprintf' , $args ) . PHP_EOL ;
}
function sprintln ( $string )
{
$args = func_get_args ();
return call_user_func_array ( 'sprintf' , $args ) . PHP_EOL ;
}
/**
* Prepare the string ( add the a to the links and show the smileys )
*
* @ param string $string
* @ return string
*/
function prepareString ( $string ) {
$smileys =
array (
// HFR icons
" :' \ ( " => 'cry.gif' ,
':love:' => 'love.gif' ,
'O:\)' => 'ange.gif' ,
'O:-\)' => 'ange.gif' ,
':redface:' => 'redface.gif' ,
':petrus:' => 'petrus75.gif' ,
// famfamfam icons
':\)\)' => 'grin.png' ,
':\)' => 'smiley.png' ,
':-\)' => 'smiley.png' ,
':\(' => 'sad.png' ,
':o' => 'shocked.png' ,
':O' => 'shocked.png' ,
':D' => 'grin.png' ,
':d' => 'grin.png' ,
':p' => 'tongue.png' ,
':P' => 'tongue.png' ,
':-P' => 'tongue.png' ,
';D' => 'wink.png' ,
';d' => 'wink.png' ,
';\)' => 'wink.png' ,
'\^\^' => 'happy.png' ,
'\(k\)' => 'heart.png' ,
'B\)' => 'cool.png' ,
':s' => 'confused.png' ,
':S' => 'confused.png' ,
':\/' => 'wondering.png' ,
':evil:' => 'evil.png' ,
" : \ | " => 'neutral.png' ,
// Meme icons
':okay:' => 'okay.gif' ,
':trolldad:' => 'trolldad.png' ,
':epic:' => 'epic.png' ,
':aloneyeah:' => 'aloneyeah.png' ,
':fapfap:' => 'fapfap.png' ,
':megusta:' => 'gusta.png' ,
':trollface:' => 'trollface.png' ,
':troll:' => 'trollface.png' ,
':lol:' => 'trollol.png' ,
':genius:' => 'genius.png' ,
);
//replace begin by www
$string = preg_replace_callback (
'/(^|\s|>)(www.[^<> \n\r]+)/ix' , function ( $match ) {
//print '<br />preg[1]';\system\Debug::dump($match);
if ( strlen ( $match [ 2 ]) > 0 ) {
return stripslashes ( $match [ 1 ] . '<a href=\"http://' . $match [ 2 ] . '\" target=\"_blank\">' . $match [ 2 ] . '</a>' );
} else {
return $match [ 2 ];
}
}, ' ' . $string
);
//replace begin by http - https (before www)
$string = preg_replace_callback (
'/(?(?=<a[^>]*>.+<\/a>)(?:<a[^>]*>.+<\/a>)|([^="\'])((?:https?):\/\/([^<> \n\r]+)))/ix' , function ( $match ) {
if ( isset ( $match [ 2 ]) && strlen ( $match [ 2 ]) > 0 ) {
return stripslashes ( $match [ 1 ] . '<a href=\"' . $match [ 2 ] . '\" target=\"_blank\">' . $match [ 3 ] . '</a>' );
} else {
return $match [ 0 ];
}
}, ' ' . $string
);
// Twitter hashtags
$string = preg_replace_callback (
" / #[a-zA-Z0-9_-]*/ " , function ( $match ) {
return
' <a class="twitter hastag" href="http://twitter.com/search?q=' .
urlencode ( trim ( $match [ 0 ])) .
'&src=hash" target="_blank">' .
trim ( $match [ 0 ]) .
'</a>' ;
}, ' ' . $string
);
$string = preg_replace_callback (
" / @[a-zA-Z0-9_-]*/ " , function ( $match ) {
return
' <a class="twitter at" href="http://twitter.com/' .
trim ( $match [ 0 ]) .
'" target="_blank">' .
trim ( $match [ 0 ]) .
'</a>' ;
}, ' ' . $string
);
//remove all scripts
$string = preg_replace_callback (
'#<[/]?script[^>]*>#is' , function ( $match ) {
return '' ;
}, ' ' . $string
);
//remove all iframe
$string = preg_replace_callback (
'#<[/]?iframe[^>]*>#is' , function ( $match ) {
return '' ;
}, ' ' . $string
);
// We add some smileys...
$conf = new \system\Conf ();
$theme = $conf -> getServerConfElement ( 'theme' );
$path = BASE_URI . 'themes/' . $theme . '/img/smileys/' ;
foreach ( $smileys as $key => $value ) {
$replace = ' <img class="smiley" alt="smiley" src="' . $path . $value . '">' ;
$string = preg_replace ( '/(^|[ ])(' . $key . ')/' , $replace , $string );
}
return trim ( $string );
}
/**
* Fix self - closing tags
*/
function fixSelfClosing ( $string ) {
return preg_replace_callback ( '/<([^\s<]+)\/>/' ,
function ( $match ) {
return '<' . $match [ 1 ] . '></' . $match [ 1 ] . '>' ;
}
, $string );
}
/**
* Remove the content , body and html tags
*/
function cleanHTMLTags ( $string ) {
return str_replace (
array (
'<content type="html">' ,
'<html xmlns="http://jabber.org/protocol/xhtml-im">' ,
'<body xmlns="http://www.w3.org/1999/xhtml">' ,
'</body>' ,
'</html>' ,
'</content>' ),
'' ,
$string );
}
/**
* Return a human - readable week
* @ return string
*/
function getDays () {
return array (
1 => t ( 'Monday' ),
2 => t ( 'Tuesday' ),
3 => t ( 'Wednesday' ),
4 => t ( 'Thursday' ),
5 => t ( 'Friday' ),
6 => t ( 'Saturday' ),
7 => t ( 'Friday' ));
}
/**
* Return a human - readable year
* @ return string
*/
function getMonths () {
return array (
1 => t ( 'January' ),
2 => t ( 'February' ),
3 => t ( 'March' ),
4 => t ( 'April' ),
5 => t ( 'May' ),
6 => t ( 'June' ),
7 => t ( 'July' ),
8 => t ( 'August' ),
9 => t ( 'September' ),
10 => t ( 'October' ),
11 => t ( 'November' ),
12 => t ( 'December' ));
}
/**
* Return a human - readable date
*
* @ param timestamp $string
* @ return string
*/
function prepareDate ( $time , $hours = true ) {
$dotw = getDays ();
$moty = getMonths ();
$today = strtotime ( date ( 'M j, Y' ));
$reldays = ( $time - $today ) / 86400 ;
if ( $reldays >= 0 && $reldays < 1 ) {
$date = t ( 'Today' );
} else if ( $reldays >= 1 && $reldays < 2 ) {
$date = t ( 'Tomorrow' );
} else if ( $reldays >= - 1 && $reldays < 0 ) {
$date = t ( 'Yesterday' );
} else {
if ( abs ( $reldays ) < 7 ) {
if ( $reldays > 0 ) {
$reldays = floor ( $reldays );
$date = 'In ' . $reldays . ' ' . t ( 'day' ) . ( $reldays != 1 ? 's' : '' );
} else {
$reldays = abs ( floor ( $reldays ));
$date = t ( ' %d days ago' , $reldays );
}
} else {
$date = $dotw [ date ( 'N' , $time ? $time : time ())] . ', ' . date ( 'j' , $time ? $time : time ()) . ' ' . $moty [ date ( 'n' , $time ? $time : time ())] ;
if ( abs ( $reldays ) > 182 )
$date .= date ( ', Y' , $time ? $time : time ());
}
}
if ( $hours )
$date .= ' - ' . date ( 'H:i' , $time );
if ( $time )
return $date ;
}
/**
* Return the list of gender
*/
@ -271,31 +27,6 @@ function getGender() {
);
}
/**
* Return an array of informations from a XMPP uri
*/
function explodeURI ( $uri ) {
$arr = parse_url ( urldecode ( $uri ));
$result = array ();
if ( isset ( $arr [ 'query' ])) {
$query = explode ( ';' , $arr [ 'query' ]);
foreach ( $query as $elt ) {
if ( $elt != '' ) {
list ( $key , $val ) = explode ( '=' , $elt );
$result [ $key ] = $val ;
}
}
$arr = array_merge ( $arr , $result );
}
return $arr ;
}
/**
* Return a list of all the country
*/
@ -622,103 +353,6 @@ function getMood() {
);
}
/*
* Get the timezone list
*/
function getTimezoneList ()
{
return array (
'Etc/GMT+12' => - 12.00 ,
'Etc/GMT+11' => - 11.00 ,
'Etc/GMT+10' => - 10.00 ,
'Etc/GMT+9' => - 9.00 ,
'Etc/GMT+8' => - 8.00 ,
'Etc/GMT+7' => - 7.00 ,
'Etc/GMT+6' => - 6.00 ,
'Etc/GMT+5' => - 5.00 ,
'America/Caracas' => - 4.30 ,
'Etc/GMT+4' => - 4.00 ,
'America/St_Johns' => - 3.30 ,
'Etc/GMT+3' => - 3.00 ,
'Etc/GMT+2' => - 2.00 ,
'Etc/GMT+1' => - 1.00 ,
'Etc/GMT' => 0 ,
'Etc/GMT-1' => 1.00 ,
'Etc/GMT-2' => 2.00 ,
'Etc/GMT-3' => 3.00 ,
'Asia/Tehran' => 3.30 ,
'Etc/GMT-4' => 4.00 ,
'Etc/GMT-5' => 5.00 ,
'Asia/Kolkata' => 5.30 ,
'Asia/Katmandu' => 5.45 ,
'Etc/GMT-6' => 6.00 ,
'Asia/Rangoon' => 6.30 ,
'Etc/GMT-7' => 7.00 ,
'Etc/GMT-8' => 8.00 ,
'Etc/GMT-9' => 9.00 ,
'Australia/Darwin' => 9.30 ,
'Etc/GMT-10' => 10.00 ,
'Etc/GMT-11' => 11.00 ,
'Etc/GMT-12' => 12.00 ,
'Etc/GMT-13' => 13.00 );
}
/*
* Get the user local timezone
*/
function getLocalTimezone ()
{
date_default_timezone_set ( 'UTC' );
$iTime = time ();
$arr = localtime ( $iTime );
$arr [ 5 ] += 1900 ;
$arr [ 4 ] ++ ;
$iTztime = gmmktime ( $arr [ 2 ], $arr [ 1 ], $arr [ 0 ], $arr [ 4 ], $arr [ 3 ], $arr [ 5 ]);
$offset = doubleval (( $iTztime - $iTime ) / ( 60 * 60 ));
$zonelist = getTimezoneList ();
$index = array_keys ( $zonelist , $offset );
if ( sizeof ( $index ) != 1 )
return false ;
return $index [ 0 ];
}
/*
* Echap the JID
*/
function echapJid ( $jid )
{
return str_replace ( ' ' , '\40' , $jid );
}
/**
* Return a URIfied string
* @ param string
* @ return string
*/
function stringToUri ( $url ) {
$url = utf8_decode ( $url );
$url = strtolower ( strtr ( $url , utf8_decode ( 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ()[]\'"~$&%*@ç!?;,:/\^¨€{}<>|+- ' ), 'aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn -- c --- e --' ));
$url = str_replace ( ' ' , '' , $url );
$url = str_replace ( '---' , '-' , $url );
$url = str_replace ( '--' , '-' , $url );
$url = trim ( $url , '-' );
return $url ;
}
/**
* Return a human readable filesize
* @ param string size in bytes
* @ return string
*/
function sizeToCleanSize ( $size )
{
$units = array ( 'B' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' );
$power = $size > 0 ? floor ( log ( $size , 1024 )) : 0 ;
return number_format ( $size / pow ( 1024 , $power ), 2 , '.' , ',' ) . ' ' . $units [ $power ];
}
/*
* Generate a standard UUID
*/