global $CFG;
$node = $this->sess->getNode($this->store, $uuid);
$url = $this->get_url($node);
- if (!file_exists($CFG->dataroot.'/repository/download')) {
- mkdir($CFG->dataroot.'/repository/download/', 0777, true);
- }
- if(is_dir($CFG->dataroot.'/repository/download')) {
- $dir = $CFG->dataroot.'/repository/download/';
- }
-
- if (empty($file)) {
- $file = $uuid.'_'.time();
- }
- if (file_exists($dir.$file)) {
- $file = uniqid('al_').$file;
- }
- $fp = fopen($dir.$file, 'w');
+ $path = $this->prepare_file($file);
+ $fp = fopen($path, 'w');
$c = new curl;
$c->download(array(array('url'=>$url, 'file'=>$fp)));
- return $dir.$file;
+ return $path;
}
public function print_search() {
} elseif(!empty($result[2])) {
$url = $result[2]['source'];
}
- if (!file_exists($CFG->dataroot.'/repository/download')) {
- mkdir($CFG->dataroot.'/repository/download/', 0777, true);
- }
- if(is_dir($CFG->dataroot.'/repository/download')) {
- $dir = $CFG->dataroot.'/repository/download/';
- }
-
- if(empty($file)) {
- $file = $photo_id.'_'.time().'.jpg';
- }
- if(file_exists($dir.$file)) {
- $file = uniqid('m').$file;
- }
- $fp = fopen($dir.$file, 'w');
+ $path = $this->prepare_file($file);
+ $fp = fopen($path, 'w');
$c = new curl;
$c->download(array(
array('url'=>$url, 'file'=>$fp)
));
- return $dir.$file;
+ return $path;
}
/**
} elseif(!empty($result[2])) {
$url = $result[2]['source'];
}
- if (!file_exists($CFG->dataroot.'/repository/download')) {
- mkdir($CFG->dataroot.'/repository/download/', 0777, true);
- }
- if(is_dir($CFG->dataroot.'/repository/download')) {
- $dir = $CFG->dataroot.'/repository/download/';
- }
-
- if (empty($file)) {
- $file = $photo_id.'_'.time().'.jpg';
- }
- if (file_exists($dir.$file)) {
- $file = uniqid('m').$file;
- }
- $fp = fopen($dir.$file, 'w');
+ $path = $this->prepare_file($file);
+ $fp = fopen($path, 'w');
$c = new curl;
$c->download(array(array('url'=>$url, 'file'=>$fp)));
- return $dir.$file;
+ return $path;
}
/**
public function get_file($url, $file) {
global $CFG;
+ $path = $this->prepare_file($file);
-
- //FIXME: Why does every repo plugin.. do this mktemp file itself..
-
- if (!file_exists($CFG->dataroot.'/repository/download')) {
- mkdir($CFG->dataroot.'/repository/download/', 0777, true);
- }
-
- if(is_dir($CFG->dataroot.'/repository/download')) {
- $dir = $CFG->dataroot.'/repository/download/';
- }
-
- if (empty($file)){
- $file = time();
- }
-
- $fp = fopen($dir.$file, 'w');
+ $fp = fopen($path, 'w');
$gdocs = new google_docs(new google_authsub($this->subauthtoken));
$gdocs->download_file($url, $fp);
- return $dir.$file;
+ return $path;
}
public function supported_filetypes() {
}
/**
- * Download a file, this function can be overridden by
- * subclass.
- *
- * @global object $CFG
- * @param string $url the url of file
- * @param string $file save location
- * @return string the location of the file
- * @see curl package
+ * Decide where to save the file, can be
+ * reused by sub class
+ * @param string filename
*/
- public function get_file($url, $file = '') {
+ public function prepare_file($file) {
global $CFG;
if (!file_exists($CFG->dataroot.'/temp/download')) {
mkdir($CFG->dataroot.'/temp/download/', 0777, true);
if (file_exists($dir.$file)) {
$file = uniqid('m').$file;
}
- $fp = fopen($dir.$file, 'w');
+ return $dir.$file;
+ }
+
+ /**
+ * Download a file, this function can be overridden by
+ * subclass.
+ *
+ * @global object $CFG
+ * @param string $url the url of file
+ * @param string $file save location
+ * @return string the location of the file
+ * @see curl package
+ */
+ public function get_file($url, $file = '') {
+ global $CFG;
+
+ $path = $this->prepare_file($file);
+ $fp = fopen($path, 'w');
$c = new curl;
$c->download(array(
array('url'=>$url, 'file'=>$fp)
));
- return $dir.$file;
+ return $path;
}
/**
*/
public function get_file($url, $file = '') {
global $CFG;
- if (!file_exists($CFG->dataroot.'/temp/download')) {
- mkdir($CFG->dataroot.'/temp/download/', 0777, true);
- }
- if (is_dir($CFG->dataroot.'/temp/download')) {
- $dir = $CFG->dataroot.'/temp/download/';
- }
- if (empty($file)) {
- $file = uniqid('repo').'_'.time().'.tmp';
- }
- if (file_exists($dir.$file)) {
- $file = uniqid('m').$file;
- }
+ $path = $this->prepare_file($file);
///retrieve the file
$fileparams = unserialize(base64_decode($url));
$fs = get_file_storage();
$sf = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename);
$contents = $sf->get_content();
- $fp = fopen($dir.$file, 'w');
+ $fp = fopen($path, 'w');
fwrite($fp,$contents);
fclose($fp);
- return $dir.$file;
+ return $path;
}
/**
$file = $services[1]; //filename
///create a temporary folder with a file
- if (!file_exists($CFG->dataroot.'/temp/download')) {
- mkdir($CFG->dataroot.'/temp/download/', 0777, true);
- }
- if (is_dir($CFG->dataroot.'/temp/download')) {
- $dir = $CFG->dataroot.'/temp/download/';
- }
- if (empty($file)) {
- $file = uniqid('repo').'_'.time().'.tmp';
- }
- if (file_exists($dir.$file)) {
- $file = uniqid('m').$file;
- }
-
+ $path = $this->prepare_file($file);
///fill the file with the content
- $fp = fopen($dir.$file, 'w');
+ $fp = fopen($path, 'w');
fwrite($fp,$content);
fclose($fp);
- return $dir.$file;
+ return $path;
}
);
$tree[] = $folder;
}
+ echo_fb($tree);
} else {
$contents = $this->s->getBucket($path);
foreach ($contents as $file) {
$arr = explode('/', $filepath);
$bucket = $arr[0];
$filename = $arr[1];
- if (!file_exists($CFG->dataroot.'/repository/download')) {
- mkdir($CFG->dataroot.'/repository/download/', 0777, true);
- }
- if(is_dir($CFG->dataroot.'/repository/download')) {
- $dir = $CFG->dataroot.'/repository/download/';
- }
- $this->s->getObject($bucket, $filename, $dir.$file);
- return $dir.$file;
+ $path = $this->prepare_file($file);
+ $this->s->getObject($bucket, $filename, $path);
+ return $path;
}
// login
public function check_login() {
}
public function get_file($url, $title) {
global $CFG;
- if (!file_exists($CFG->dataroot.'/temp/download')) {
- mkdir($CFG->dataroot.'/temp/download/', 0777, true);
- }
- if (is_dir($CFG->dataroot.'/temp/download')) {
- $dir = $CFG->dataroot.'/temp/download/';
- }
- if (empty($file)) {
- $file = uniqid('repo').'_'.time().'.tmp';
- }
- if (file_exists($dir.$file)) {
- $file = uniqid('m').$file;
- }
-
+ $path = $this->prepare_file($title);
$buffer = '';
$this->wd->open();
$this->wd->get($url, $buffer);
- $fp = fopen($dir.$file, 'wb');
+ $fp = fopen($path, 'wb');
fwrite($fp, $buffer);
- return $dir.$file;
+ return $path;
}
public function global_search() {
return false;