+function format_filename($str, $allow_uppercase = false) {
+ if(!$allow_uppercase) {
+ $str = strtolower($str);
+ }
+ $str = ereg_replace('[^a-zA-Z0-9_.-]', '_', $str);
+ return ereg_replace('^[.-]', '_', $str);
+}
+
+function format_path($str, $allow_uppercase = false) {
+ if(!$allow_uppercase) {
+ $str = strtolower($str);
+ }
+ $str = ereg_replace('[^a-zA-Z0-9_./-]', '_', $str);
+ return ereg_replace('^[.-]', '_', $str);
+}
+
+function client_path_to_filename($path) {
+ $filename = ereg_replace(".*[:/\\]", '', $path);
+ return format_filename($filename, true);
+}
+
+
+function format_image_w_h($str) {
+ $fields = explode(' ', $str);
+ if(count($fields) != 3) {
+ return '';
+ }
+
+ list($filename, $width, $height) = $fields;
+ $filename = format_path($filename);
+ $width = format_int_0($width);
+ $height = format_int_0($height);
+
+ return "$filename $width $height";
+}
+
+function format_image_w_h_thumb_w_h($str) {
+ $fields = explode(' ', $str);
+ if(count($fields) != 6) {
+ return '';
+ }
+
+ list($filename, $width, $height, $thumb_filename, $thumb_width, $thumb_height) = $fields;
+ $filename = format_path($filename);
+ $width = format_int_0($width);
+ $height = format_int_0($height);
+ $thumb_filename = format_path($thumb_filename);
+ $thumb_width = format_int_0($thumb_width);
+ $thumb_height = format_int_0($thumb_height);
+
+ return "$filename $width $height $thumb_filename $thumb_width $thumb_height";