@@ -265,7 +265,7 @@ function check_number($number)
265265 * @param mixed $url
266266 * @param mixes $request_file_depth
267267 * @access public
268- * return void
268+ * @ return array
269269 */
270270function GetRequestVar ($ url , $ request_file_depth = 0 )
271271{
@@ -312,36 +312,7 @@ function GetRequestVar($url, $request_file_depth = 0)
312312 return $ paginas ;
313313}
314314
315- /**
316- * is__writable It can accept files or folders, but folders should end with a trailing slash! The function attempts to actually
317- * write a file, so it will correctly return true when a file/folder can be written to when the user has ACL write access to it
318- *
319- * @param mixed $path
320- * @access public
321- * @return void
322- */
323- /*
324- function is__writable($path) {
325- //will work in despite of Windows ACLs bug
326- //NOTE: use a trailing slash for folders!!!
327- //see http://bugs.php.net/bug.php?id=27609
328- //see http://bugs.php.net/bug.php?id=30931
329-
330- if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
331- return is__writable($path.uniqid(mt_rand()).'.tmp');
332- else if (is_dir($path))
333- return is__writable($path.'/'.uniqid(mt_rand()).'.tmp');
334- // check tmp file for read/write capabilities
335- $rm = file_exists($path);
336- $f = @fopen($path, 'a');
337- if ($f===false)
338- return false;
339- fclose($f);
340- if (!$rm)
341- unlink($path);
342- return true;
343- }
344- */
315+
345316/**
346317 * function to override PHP's is_writable() which can occasionally be unreliable due to O/S and F/S differences
347318 * attempts to open the specified file for writing. Returns true if successful, false if not.
@@ -763,111 +734,6 @@ function reset_config_table_prefix()
763734 // unset($_config['table_prefix']);
764735}
765736
766- /**
767- * resize_image
768- *
769- * @param mixed $img
770- * @access public
771- * @return void
772- */
773- function resize_image ($ img )
774- {
775- global $ _config ;
776- $ obj = new Thumbnail ($ img );
777- $ obj ->size_width ($ _config ['pic-width ' ]);
778- $ obj ->process ();
779- $ obj ->save ($ img );
780- }
781-
782- /**
783- * resize_image_new uses new resize class
784- *
785- * @param mixed $img
786- * @access public
787- * @return void
788- */
789- function resize_image_new ($ img )
790- {
791- global $ _config , $ t ;
792- $ img = $ _config ['app_root ' ] . $ img ;
793-
794- $ handle = new Upload ($ img );
795- $ handle ->file_overwrite = true ;
796- $ handle ->image_resize = true ;
797- $ handle ->image_ratio = true ;
798- $ handle ->image_x = $ _config ['pic-width ' ];
799-
800- $ handle ->Process ($ _config ['app_root ' ] . $ _config ['picpath_web ' ]);
801- if ($ handle ->processed ) {
802- //echo 'image resized';
803- //$handle->clean();
804- } else {
805- echo $ handle ->log ;
806- echo 'error : ' . $ handle ->error ;
807- }
808- $ t ->assign ('resize ' , 1 );
809- $ t ->assign ('img ' , $ img );
810- set_time_limit (30 );
811- }
812- /**
813- * make_thumb generates thumb with the Thumbnail class
814- *
815- * @param mixed $img
816- * @param mixed $thumb
817- * @access public
818- * @return void
819- */
820- function make_thumb ($ img , $ thumb , $ i = 0 )
821- {
822- global $ _config , $ t ;
823- $ obj = new Thumbnail ($ img );
824- $ obj ->size_auto ($ _config ['thumb-width ' ]);
825- $ obj ->process ();
826- $ t ->assign ('resize ' , 1 );
827- $ t ->assign ('img ' , $ img );
828- set_time_limit (30 );
829- $ obj ->save ($ thumb );
830- flush ();
831- // echo "Error". $obj->error_msg;
832- }
833-
834- /**
835- * make_thumb_new generates thumbnail with the class.upload class which is newer
836- *
837- * @param mixed $img
838- * @param mixed $thumb
839- * @param int $i
840- * @access public
841- * @return void
842- */
843- function make_thumb_new ($ img , $ thumb , $ i = 0 )
844- {
845- global $ _config , $ t ;
846- $ img = $ _config ['app_root ' ] . $ img ;
847-
848- $ handle = new Upload ($ img );
849- $ handle ->file_name_body_pre = 'thumb_ ' ;
850- $ handle ->file_overwrite = true ;
851- $ handle ->file_auto_rename = false ;
852- $ handle ->image_resize = true ;
853- $ handle ->image_ratio_fill = true ;
854- $ handle ->image_ratio = true ;
855- $ handle ->image_y = $ _config ['thumb-height ' ];
856- $ handle ->image_x = $ _config ['thumb-width ' ];
857-
858- $ handle ->Process ($ _config ['app_root ' ] . $ _config ['picpath_web ' ]);
859- if ($ handle ->processed ) {
860- //echo 'image resized';
861- //$handle->clean();
862- } else {
863- echo $ handle ->log ;
864- echo 'error : ' . $ handle ->error ;
865- }
866- $ t ->assign ('resize ' , 1 );
867- $ t ->assign ('img ' , $ img );
868- set_time_limit (30 );
869- }
870-
871737
872738/**
873739 * count_all count non-empty elements in an array of any dimension
@@ -891,52 +757,57 @@ function count_all($arg)
891757 }
892758}
893759
894-
895- /**
896- * Rewritten by Nathan Codding - Feb 6, 2001
897- * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
898- * to that URL
899- * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking
900- * to http://www.xxxx.yyyy[/zzzz]
901- * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking
902- * to that email address
903- * - Only matches these 2 patterns either after a space, or at the beginning of a line
904- *
905- * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe
906- * have it require something like xxxx@yyyy.zzzz or such. We'll see
907- */
908- function make_clickable ($ text )
760+ function _make_url_clickable_cb ($ matches )
909761{
910- $ text = preg_replace ('#(script|about|applet|activex|chrome):#is ' , "\\1: " , $ text );
911-
912- // pad it with a space so we can match things at the start of the 1st line.
913- $ ret = ' ' . $ text ;
762+ $ ret = '' ;
763+ $ url = $ matches [2 ];
914764
915- // matches an "xxxx://yyyy" URL at the start of a line, or after a space.
916- // xxxx can only be alpha characters.
917- // yyyy is anything up to the first space, newline, comma, double quote or <
918- $ ret = preg_replace ("#(^|[ \n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is " , "\\1<a href= \"\\2 \" target= \"_blank \" title= \"\"> \\2</a> " , $ ret );
765+ if (empty ($ url ))
766+ return $ matches [0 ];
767+ // removed trailing [.,;:] from URL
768+ if (in_array (substr ($ url , -1 ), array ('. ' , ', ' , '; ' , ': ' )) === true ) {
769+ $ ret = substr ($ url , -1 );
770+ $ url = substr ($ url , 0 , strlen ($ url ) - 1 );
771+ }
772+ return $ matches [1 ] . "<a href= \"$ url \" rel= \"nofollow \"> $ url</a> " . $ ret ;
773+ }
919774
920- // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
921- // Must contain at least 2 dots. xxxx contains either alphanum, or "-"
922- // zzzz is optional.. will contain everything up to the first space, newline,
923- // comma, double quote or <.
924- $ ret = preg_replace ( " #(^|[ \n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is " , "\\ 1<a href= \" http:// \\ 2 \" target= \" _blank \" title= \"\" > \\ 2</a> " , $ ret ) ;
775+ function _make_web_ftp_clickable_cb ( $ matches)
776+ {
777+ $ ret = '' ;
778+ $ dest = $ matches [ 2 ];
779+ $ dest = ' http:// ' . $ dest ;
925780
926- // matches an email@domain type address at the start of a line, or after a space.
927- // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
928- $ ret = preg_replace ("#(^|[ \n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i " , "\\1<a href= \"mailto: \\2@ \\3 \" title= \"\"> \\2@ \\3</a> " , $ ret );
781+ if (empty ($ dest ))
782+ return $ matches [0 ];
783+ // removed trailing [,;:] from URL
784+ if (in_array (substr ($ dest , -1 ), array ('. ' , ', ' , '; ' , ': ' )) === true ) {
785+ $ ret = substr ($ dest , -1 );
786+ $ dest = substr ($ dest , 0 , strlen ($ dest ) - 1 );
787+ }
788+ return $ matches [1 ] . "<a href= \"$ dest \" rel= \"nofollow \"> $ dest</a> " . $ ret ;
789+ }
929790
930- // Remove our padding..
931- $ ret = substr ($ ret , 1 );
791+ function _make_email_clickable_cb ($ matches )
792+ {
793+ $ email = $ matches [2 ] . '@ ' . $ matches [3 ];
794+ return $ matches [1 ] . "<a href= \"mailto: $ email \"> $ email</a> " ;
795+ }
932796
933- // echo '<br>'.$text.'<br>';
934- // echo '<br>'.$ret.'<br>';
797+ function make_clickable ($ ret )
798+ {
799+ $ ret = ' ' . $ ret ;
800+ // in testing, using arrays here was found to be faster
801+ $ ret = preg_replace_callback ('#([\s>])([\w]+?://[\w \\x80- \\xff\#$%&~/.\-;:=,?@\[\]+]*)#is ' , '_make_url_clickable_cb ' , $ ret );
802+ $ ret = preg_replace_callback ('#([\s>])((www|ftp)\.[\w \\x80- \\xff\#$%&~/.\-;:=,?@\[\]+]*)#is ' , '_make_web_ftp_clickable_cb ' , $ ret );
803+ $ ret = preg_replace_callback ('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i ' , '_make_email_clickable_cb ' , $ ret );
935804
936- return ($ ret );
805+ // this one is not in an array because we need it to run last, for cleanup of accidental links within links
806+ $ ret = preg_replace ("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i " , "$1$3</a> " , $ ret );
807+ $ ret = trim ($ ret );
808+ return $ ret ;
937809}
938810
939-
940811/**
941812 * WGS84 Distance Calculation
942813 * Here is a function in PHP that returns the distance between two points on earth
0 commit comments