/**
  * Tries to guess the install path to the provided program.
  * @access public
  * @param  string $program The program to check for.
  * @return string
  */
 public static function guess_path($program)
 {
     $os = Revisr_Compatibility::get_os();
     $program = Revisr_Admin::escapeshellarg($program);
     if ($os['code'] !== 'WIN') {
         $path = exec("which {$program}");
     } else {
         $path = exec("where {$program}");
     }
     if ($path) {
         return $path;
     } else {
         return __('Not Found', 'revisr');
     }
 }
Esempio n. 2
0
 /**
  * Runs a Git command and fires the given callback.
  * @access 	public
  * @param 	string 			$command 	The command to use.
  * @param 	array 			$args 		Arguements provided by user.
  * @param 	string 			$callback 	The callback to use.
  * @param 	string|array 	$info 		Additional info to pass to the callback
  */
 public function run($command, $args, $callback = '', $info = '')
 {
     // Setup the command for safe usage.
     $safe_path = Revisr_Admin::escapeshellarg($this->git_path);
     $safe_cmd = Revisr_Admin::escapeshellarg($command);
     $safe_args = join(' ', array_map(array('Revisr_Admin', 'escapeshellarg'), $args));
     // Allow for customizing the git work-tree and git-dir paths.
     $git_dir = Revisr_Admin::escapeshellarg("--git-dir={$this->git_dir}");
     $work_tree = Revisr_Admin::escapeshellarg("--work-tree={$this->work_tree}");
     // Run the command.
     chdir($this->work_tree);
     exec("{$safe_path} {$git_dir} {$work_tree} {$safe_cmd} {$safe_args} 2>&1", $output, $return_code);
     chdir($this->current_dir);
     // Process the response.
     $response = new Revisr_Git_Callback();
     $success_callback = 'success_' . $callback;
     $failure_callback = 'null_' . $callback;
     // Return the callback.
     if (0 !== $return_code) {
         return $response->{$failure_callback}($output, $info);
     } else {
         return $response->{$success_callback}($output, $info);
     }
 }
Esempio n. 3
0
 /**
  * Builds the connection string to use with MySQL.
  * @access protected
  * @param  string $table Optionally pass the table to use.
  * @return string
  */
 protected function build_conn($table = '')
 {
     // Allow using the port or socket from the DB_HOST constant.
     $port_or_socket = $this->check_port_or_socket(DB_HOST);
     $add_port = '';
     $add_socket = '';
     $db_host = DB_HOST;
     if (false !== $port_or_socket) {
         if (null !== $port_or_socket['socket']) {
             $socket = $port_or_socket['socket'];
             $add_socket = " --socket={$socket}";
             $temp = strlen($socket) * -1 - 1;
         } else {
             $port = $port_or_socket['port'];
             $add_port = " --port={$port}";
             $temp = strlen($port) * -1 - 1;
         }
         $db_host = substr(DB_HOST, 0, $temp);
     }
     // Maybe connect to a specific table.
     if ('' !== $table) {
         $table = ' ' . Revisr_Admin::escapeshellarg($table);
     }
     // Workaround for compatibility between UNIX and Windows.
     if ('' !== DB_PASSWORD) {
         $conn = "-u " . Revisr_Admin::escapeshellarg(DB_USER) . " -p" . Revisr_Admin::escapeshellarg(DB_PASSWORD) . " " . DB_NAME . $table . " --host " . $db_host . $add_port . $add_socket;
     } else {
         $conn = "-u " . Revisr_Admin::escapeshellarg(DB_USER) . " " . DB_NAME . $table . " --host " . $db_host . $add_port . $add_socket;
     }
     // Return the connection string.
     return $conn;
 }