* @copyright Copyright © 2007, Entorn Web S.C.P. */ if(!function_exists('file_put_contents')) { define('FILE_APPEND', 8); /** * Escriu el contingut de l'string $data al fitxer $filename * Extracted from Pear::PHP_Compat */ function file_put_contents($filename, $data, $file_append = false) { $fp = fopen($filename, (!$file_append ? 'w+' : 'a+')); if(!$fp) { trigger_error('file_put_contents cannot write in file.', E_USER_ERROR); return; } fputs($fp, $data); fclose($fp); } } /** * Retrieve directory listing * @author Jason Wong */ if (!function_exists('list_directory')) { function list_directory($dir) { $file_list = ''; $stack[] = $dir; while ($stack) { $current_dir = array_pop($stack); if ($dh = opendir($current_dir)) { while (($file = readdir($dh)) !== false) { if ($file !== '.' AND $file !== '..') { $current_file = "{$current_dir}/{$file}"; if (is_file($current_file)) { $file_list[] = "{$current_dir}/{$file}"; } elseif (is_dir($current_file)) { $stack[] = $current_file; } } } } } return $file_list; } } /** * Filter an array based on a regexp */ if ( !function_exists('array_preg_filter') ) { function array_preg_filter(&$array,$regexp) { if (!is_array($array)) return array(); reset($array); while (list ($key, $val) = each ($array)) { if (!preg_match($regexp,$val,$matches)) unset($array[$key]); else $out[$val] = $matches[1]; } return $out; } } if ( !function_exists('array_trim') ) { function array_trim($ary) { $out = array(); if (!is_array($ary)) return $out; foreach ($ary as $k=>$v) { if (is_array($v)) $out[$k] = array_trim($v); else $out[$k] = trim($v); } return $out; } } if ( !function_exists('mysql_prepare_values')) { function mysql_prepare_values(&$value,$key,$update=false) { if (strtolower($value) == 'null' || $value === null) $value = 'NULL'; else $value = "'" . mysql_real_escape_string($value) . "'"; if ($update) $value = "$key = $value"; } } if ( !function_exists('get_image_path')) { function get_image_path($path,$w=null,$h=null,$id=null,$ext='') { global $setup; global $module; $w = intval($w); $h = intval($h); $m = (empty($ext)?$module->name:$ext); $cached_img = $m . DIRECTORY_SEPARATOR . $w . 'x'. $h . $path; if (!is_file($setup->getConfig('cache_dir') . $cached_img)) { create_cached_image($m,$id,$w,$h); } return $setup->getConfig('cache_url') . $cached_img; } } if ( !function_exists('create_cached_image') ) { function create_cached_image($m,$id,$width,$height) { require_once 'class/file.class.php'; global $setup; if ($width == 0) $width = "*"; if ($height == 0) $height = "*"; $img = new BeWeB_Image(); $img->loadFromDB( $m, $id ); $img->resize( $width, $height ); // Caching stuff $cache_dir = $setup->getConfig('cache_dir') . DIRECTORY_SEPARATOR . $m; if ( is_dir( $cache_dir ) || mkdir( $cache_dir ) ) $img->save( $cache_dir . DIRECTORY_SEPARATOR . intval($width) . 'x' . intval($height) ); } } if ( !function_exists('get_file_mimetype') ) { function get_file_mimetype( $ext ) { include 'mimetypes.inc.php'; return (isset($type[$ext]) ? $type[$ext] : 'app/unknown'); } } if ( !function_exists('BeWeB_Error_handler') ) { function BeWeB_Error_handler($errno, $errstr, $errfile, $errline) { if ( substr($errstr, 0, 16) == 'var: Deprecated.') { return true; } if ( substr($errstr, 0, 23) == 'Non-static method BeWeB') { return true; } if ( substr($errstr, 0, 48) == 'Redefining already defined constructor for class') { return true; } return false; } } ?>