hackedProjectWebDownloader.inc in Hacked! 7.2
File
includes/hackedProjectWebDownloader.inc
View source
<?php
class hackedProjectWebDownloader {
var $project;
function __construct(&$project) {
$this->project = $project;
}
function get_temp_directory($namespace = NULL) {
if (is_null($namespace)) {
$namespace = get_class($this);
}
$segments = array(
file_directory_temp(),
'hacked-cache-' . get_current_user(),
$namespace,
);
$dir = implode('/', array_filter($segments));
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY) && !mkdir($dir, 0775, TRUE)) {
watchdog('hacked', 'Failed to create temp directory: %dir', array(
'%dir' => $dir,
), WATCHDOG_ERROR);
return FALSE;
}
return $dir;
}
function get_destination() {
$type = $this->project->project_type;
$name = $this->project->name;
$version = $this->project->existing_version;
$dir = $this
->get_temp_directory() . "/{$type}/{$name}";
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY) && !mkdir($dir, 0775, TRUE)) {
watchdog('hacked', 'Failed to create temp directory: %dir', array(
'%dir' => $dir,
), WATCHDOG_ERROR);
return FALSE;
}
return "{$dir}/{$version}";
}
function get_final_destination() {
$dir = $this
->get_destination();
$name = $this->project->name;
$version = $this->project->existing_version;
$type = $this->project->project_type;
if ($type != 'core') {
$module_dir = $dir . "/{$name}";
}
else {
$module_dir = $dir . '/' . $name . '-' . $version;
}
return $module_dir;
}
function download() {
}
function remove_dir($path) {
if (is_file($path) || is_link($path)) {
unlink($path);
}
elseif (is_dir($path)) {
$d = dir($path);
while (($entry = $d
->read()) !== FALSE) {
if ($entry == '.' || $entry == '..') {
continue;
}
$entry_path = $path . '/' . $entry;
$this
->remove_dir($entry_path);
}
$d
->close();
rmdir($path);
}
else {
watchdog('hacked', 'Unknown file type(%path) stat: %stat ', array(
'%path' => $path,
'%stat' => print_r(stat($path), 1),
), WATCHDOG_ERROR);
}
}
}