Beispiel #1
0
 public function testBaseNameWin()
 {
     if (!GitPHP_Util::IsWindows()) {
         $this->markTestSkipped();
     }
     $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file'));
     $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file\\'));
     $this->assertEquals('file', GitPHP_Util::BaseName('some\\path\\to\\file.ext', '.ext'));
     $this->assertEquals('.extfile', GitPHP_Util::BaseName('some\\path\\to\\.extfile.ext', '.ext'));
 }
 /**
  * Gets whether this mimetype strategy is valid
  *
  * @return bool true if valid
  */
 public function Valid()
 {
     return !GitPHP_Util::IsWindows();
 }
Beispiel #3
0
 /**
  * DefaultBinary
  *
  * Gets the default binary for the platform
  *
  * @access public
  * @static
  * @return string binary
  */
 public static function DefaultBinary()
 {
     if (GitPHP_Util::IsWindows()) {
         // windows
         if (GitPHP_Util::Is64Bit()) {
             // match x86_64 and x64 (64 bit)
             // C:\Program Files (x86)\Git\bin\git.exe
             return 'C:\\Progra~2\\Git\\bin\\git.exe';
         } else {
             // 32 bit
             // C:\Program Files\Git\bin\git.exe
             return 'C:\\Progra~1\\Git\\bin\\git.exe';
         }
     } else {
         // *nix, just use PATH
         return 'git';
     }
 }
Beispiel #4
0
 /**
  * Get the base install url (without index)
  *
  * @param boolean $full true to return full url (include protocol and hostname)
  * @return string base url
  */
 public static function BaseUrl($full = false)
 {
     $baseurl = $_SERVER['SCRIPT_NAME'];
     if (substr_compare($baseurl, 'index.php', -9) === 0) {
         $baseurl = dirname($baseurl);
     }
     if ($full) {
         $baseurl = $_SERVER['HTTP_HOST'] . $baseurl;
         if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
             $baseurl = 'https://' . $baseurl;
         } else {
             $baseurl = 'http://' . $baseurl;
         }
     }
     if (GitPHP_Util::IsWindows()) {
         $baseurl = rtrim($baseurl, "\\");
     }
     return rtrim($baseurl, "/");
 }
Beispiel #5
0
 /**
  * FileMime_File
  *
  * Get the file mimetype using file command
  *
  * @access private
  * @return string mimetype
  */
 private function FileMime_File()
 {
     if (GitPHP_Util::IsWindows()) {
         return '';
     }
     if (!$this->dataRead) {
         $this->ReadData();
     }
     if (!$this->data) {
         return '';
     }
     $descspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'));
     $proc = proc_open('file -b --mime -', $descspec, $pipes);
     if (is_resource($proc)) {
         fwrite($pipes[0], $this->data);
         fclose($pipes[0]);
         $mime = stream_get_contents($pipes[1]);
         fclose($pipes[1]);
         proc_close($proc);
         if ($mime && strpos($mime, '/')) {
             if (strpos($mime, ';')) {
                 $mime = strtok($mime, ';');
             }
             return $mime;
         }
     }
     return '';
 }
Beispiel #6
0
 /**
  * SystemTmpDir
  *
  * Gets the system defined temporary directory
  *
  * @access public
  * @static
  * @return string temp dir
  */
 public static function SystemTmpDir()
 {
     $tmpdir = '';
     if (function_exists('sys_get_temp_dir')) {
         $tmpdir = sys_get_temp_dir();
     }
     if (empty($tmpdir)) {
         $tmpdir = getenv('TMP');
     }
     if (empty($tmpdir)) {
         $tmpdir = getenv('TEMP');
     }
     if (empty($tmpdir)) {
         $tmpdir = getenv('TMPDIR');
     }
     if (empty($tmpdir)) {
         $tmpfile = tempnam(__FILE__, '');
         if (file_exists($tmpfile)) {
             unlink($tmpfile);
             $tmpdir = dirname($temp);
         }
     }
     if (empty($tmpdir)) {
         // ultimate default - should never get this far
         if (GitPHP_Util::IsWindows()) {
             $tmpdir = 'C:\\Windows\\Temp';
         } else {
             $tmpdir = '/tmp';
         }
     }
     return GitPHP_Util::AddSlash(realpath($tmpdir));
 }
Beispiel #7
0
 /**
  * BaseName
  *
  * Get the filename of a given path
  *
  * based on Drupal's basename
  *
  * @access public
  * @param string $path path
  * @param string $suffix optionally trim this suffix
  * @static
  * @return string filename
  */
 public static function BaseName($path, $suffix = null)
 {
     $sep = '/';
     if (GitPHP_Util::IsWindows()) {
         $sep .= '\\';
     }
     $path = rtrim($path, $sep);
     if (!preg_match('@[^' . preg_quote($sep) . ']+$@', $path, $matches)) {
         return '';
     }
     $filename = $matches[0];
     if ($suffix) {
         $filename = preg_replace('@' . preg_quote($suffix, '@') . '$@', '', $filename);
     }
     return $filename;
 }