0); } } function patch_erase($patch) { global $patch_dir, $patch_suffix; if (!file_exists($patch_dir)) { return true; } $filename = $patch_dir . '/' . $patch['uniqid'] . $patch_suffix; return @unlink($filename); } /* Detect a github URL or commit ID and fix it up */ function patch_fixup_url($url) { global $git_root_url, $patch_suffix; // If it's a commit id then prepend git url, and add .patch if (is_commit_id($url)) { $url = $git_root_url . $url . $patch_suffix; } elseif (is_URL($url)) { $urlbits = explode("/", $url); if (substr($urlbits[2], -10) == "github.com") { // If it's a github url and does not already end in .patch, add it if (substr($url, -strlen($patch_suffix)) != $patch_suffix) { // Make sure it's really a URL to a commit id before adding .patch if (is_commit_id(array_pop($urlbits))) { $url .= $patch_suffix; } } } } return $url; } function is_commit_id($str) { return preg_match("/^[0-9a-f]{5,40}$/", $str); } function is_github_url($url) { $urlbits = explode("/", $url); return (substr($urlbits[2], -10) == "github.com"); } ?>