$name, 'expire' => $expire); debug_event('Core', "Registered $type form $name with SID $sid and expiration $expire ($window seconds from now)", 5); switch ($type) { case 'get': $string = $sid; break; case 'post': default: $string = ''; break; } // end switch on type return $string; } // form_register /** * form_verify * * This takes a form name and then compares it with the posted sid, if * they don't match then it returns false and doesn't let the person * continue */ public static function form_verify($name, $type = 'post') { switch ($type) { case 'post': $sid = $_POST['form_validation']; break; case 'get': $sid = $_GET['form_validation']; break; case 'cookie': $sid = $_COOKIE['form_validation']; break; case 'request': $sid = $_REQUEST['form_validation']; break; default: return false; } if (!isset($_SESSION['forms'][$sid])) { debug_event('Core', "Form $sid not found in session, rejecting request", 2); return false; } $form = $_SESSION['forms'][$sid]; unset($_SESSION['forms'][$sid]); if ($form['name'] == $name) { debug_event('Core', "Verified SID $sid for $type form $name", 5); if ($form['expire'] < time()) { debug_event('Core', "Form $sid is expired, rejecting request", 2); return false; } return true; } // OMG HAX0RZ debug_event('Core', "$type form $sid failed consistency check, rejecting request", 2); return false; } // form_verify /** * image_dimensions * This returns the dimensions of the passed song of the passed type * returns an empty array if PHP-GD is not currently installed, returns * false on error */ public static function image_dimensions($image_data) { if (!function_exists('ImageCreateFromString')) { return false; } $image = ImageCreateFromString($image_data); if (!$image) { return false; } $width = imagesx($image); $height = imagesy($image); if (!$width || !$height) { return false; } return array('width'=>$width,'height'=>$height); } // image_dimensions /* * is_readable * * Replacement function because PHP's is_readable is buggy: * https://bugs.php.net/bug.php?id=49620 */ public static function is_readable($path) { if (is_dir($path)) { $handle = opendir($path); if ($handle === false) { return false; } closedir($handle); return true; } $handle = @fopen($path, 'rb'); if ($handle === false) { return false; } fclose($handle); return true; } /* * conv_lc_file * * Convert site charset filename to local charset filename for file operations */ public static function conv_lc_file($filename) { $lc_filename = $filename; $site_charset = AmpConfig::get('site_charset'); $lc_charset = AmpConfig::get('lc_charset'); if ($lc_charset && $lc_charset != $site_charset) { if (function_exists('iconv')) { $lc_filename = iconv($site_charset, $lc_charset, $filename); } } return $lc_filename; } /* * is_session_started * * Universal function for checking session status. */ public static function is_session_started() { if (php_sapi_name() !== 'cli' ) { if (version_compare(phpversion(), '5.4.0', '>=') ) { return session_status() === PHP_SESSION_ACTIVE ? true : false; } else { return session_id() === '' ? false : true; } } return false; } private static function is_class_typeof($classname, $typeofname) { if (class_exists($classname)) { return in_array($typeofname, array_map('strtolower', class_implements($classname))); } return false; } public static function is_playable_item($classname) { return self::is_class_typeof($classname, 'playable_item'); } public static function is_library_item($classname) { return self::is_class_typeof($classname, 'library_item'); } public static function is_media($classname) { return self::is_class_typeof($classname, 'media'); } } // Core