예제 #1
0
 /**
  * Process the downloaded file
  */
 function download($url, $overwrite = false)
 {
     global $lang;
     // check the url
     $matches = array();
     if (!preg_match("/[^\\/]*\$/", $url, $matches) || !$matches[0]) {
         $this->manager->error = $this->lang['error_badurl'] . "\n";
         return false;
     }
     $file = $matches[0];
     if (!($tmp = io_mktmpdir())) {
         $this->manager->error = $this->lang['error_dircreate'] . "\n";
         return false;
     }
     if (!($file = io_download($url, "{$tmp}/", true, $file, 0))) {
         $this->manager->error = sprintf($this->lang['error_download'], $url) . "\n";
     }
     if (!$this->manager->error && !$this->decompress("{$tmp}/{$file}", $tmp)) {
         $this->manager->error = sprintf($this->lang['error_decompress'], $file) . "\n";
     }
     // search $tmp for the folder(s) that has been created
     // move the folder(s) to lib/plugins/
     if (!$this->manager->error) {
         $result = array('old' => array(), 'new' => array());
         if ($this->find_folders($result, $tmp)) {
             // choose correct result array
             if (count($result['new'])) {
                 $install = $result['new'];
             } else {
                 $install = $result['old'];
             }
             // now install all found items
             foreach ($install as $item) {
                 // where to install?
                 if ($item['type'] == 'template') {
                     $target = DOKU_INC . 'lib/tpl/' . $item['base'];
                 } else {
                     $target = DOKU_INC . 'lib/plugins/' . $item['base'];
                 }
                 // check to make sure we aren't overwriting anything
                 if (!$overwrite && @file_exists($target)) {
                     // remember our settings, ask the user to confirm overwrite, FIXME
                     continue;
                 }
                 $instruction = @file_exists($target) ? 'update' : 'install';
                 // copy action
                 if ($this->dircopy($item['tmp'], $target)) {
                     $this->downloaded[] = $item['base'];
                     $this->plugin_writelog($target, $instruction, array($url));
                 } else {
                     $this->manager->error .= sprintf($this->lang['error_copy'] . "\n", $item['base']);
                 }
             }
         } else {
             $this->manager->error = $this->lang['error'] . "\n";
         }
     }
     // cleanup
     if ($tmp) {
         $this->dir_delete($tmp);
     }
     if (!$this->manager->error) {
         msg(sprintf($this->lang['packageinstalled'], count($this->downloaded), join(',', $this->downloaded)), 1);
         $this->refresh();
         return true;
     }
     return false;
 }
예제 #2
0
 /**
  * Returns a temporary directory
  *
  * The directory is registered for cleanup when the class is destroyed
  *
  * @return false|string
  */
 protected function mkTmpDir()
 {
     $dir = io_mktmpdir();
     if (!$dir) {
         return false;
     }
     $this->temporary[] = $dir;
     return $dir;
 }
예제 #3
0
파일: media.php 프로젝트: yjliugit/dokuwiki
/**
 * Handle file uploads via XMLHttpRequest
 *
 * @param string $ns target namespace
 * @param int $auth current auth check result
 * @return mixed false on error, id of the new file on success
 */
function media_upload_xhr($ns, $auth)
{
    if (!checkSecurityToken()) {
        return false;
    }
    global $INPUT;
    $id = $INPUT->get->str('qqfile');
    list($ext, $mime) = mimetype($id);
    $input = fopen("php://input", "r");
    if (!($tmp = io_mktmpdir())) {
        return false;
    }
    $path = $tmp . '/' . md5($id);
    $target = fopen($path, "w");
    $realSize = stream_copy_to_stream($input, $target);
    fclose($target);
    fclose($input);
    if (isset($_SERVER["CONTENT_LENGTH"]) && $realSize != (int) $_SERVER["CONTENT_LENGTH"]) {
        unlink($path);
        return false;
    }
    $res = media_save(array('name' => $path, 'mime' => $mime, 'ext' => $ext), $ns . ':' . $id, $INPUT->get->str('ow') == 'checked' ? true : false, $auth, 'copy');
    unlink($path);
    if ($tmp) {
        io_rmdir($tmp, true);
    }
    if (is_array($res)) {
        msg($res[0], $res[1]);
        return false;
    }
    return $res;
}
예제 #4
0
 /**
  * Create a temporary file from the given data
  *
  * exits if an error occurs
  *
  * @param $data
  * @return string
  */
 private function storetemp($data)
 {
     // store in temporary file
     $this->tempdir = io_mktmpdir();
     if (!$this->tempdir) {
         $this->fail(500);
     }
     $this->tempfile = $this->tempdir . '/' . md5($data);
     if (!io_saveFile($this->tempfile, $data)) {
         $this->fail(500);
     }
     return $this->tempfile;
 }
예제 #5
0
파일: media.php 프로젝트: hlxlplxl/dokuwiki
/**
 * Handle file uploads via XMLHttpRequest
 *
 * @return mixed false on error, id of the new file on success
 */
function media_upload_xhr($ns, $auth)
{
    if (!checkSecurityToken()) {
        return false;
    }
    $id = $_GET['qqfile'];
    list($ext, $mime, $dl) = mimetype($id);
    $input = fopen("php://input", "r");
    $temp = tmpfile();
    $realSize = stream_copy_to_stream($input, $temp);
    fclose($input);
    if ($realSize != (int) $_SERVER["CONTENT_LENGTH"]) {
        return false;
    }
    if (!($tmp = io_mktmpdir())) {
        return false;
    }
    $path = $tmp . '/' . md5($id);
    $target = fopen($path, "w");
    fseek($temp, 0, SEEK_SET);
    stream_copy_to_stream($temp, $target);
    fclose($target);
    $res = media_save(array('name' => $path, 'mime' => $mime, 'ext' => $ext), $ns . ':' . $id, $_REQUEST['ow'] == 'checked' ? true : false, $auth, 'copy');
    unlink($path);
    if ($tmp) {
        dir_delete($tmp);
    }
    if (is_array($res)) {
        msg($res[0], $res[1]);
        return false;
    }
    return $res;
}
예제 #6
0
 function download($url, $overwrite = false)
 {
     global $lang;
     // check the url
     $matches = array();
     if (!preg_match("/[^\\/]*\$/", $url, $matches) || !$matches[0]) {
         $this->manager->error = $this->lang['error_badurl'] . "\n";
         return false;
     }
     $file = $matches[0];
     if (!($tmp = io_mktmpdir())) {
         $this->manager->error = $this->lang['error_dircreate'] . "\n";
         return false;
     }
     if (!($file = io_download($url, "{$tmp}/", true, $file))) {
         $this->manager->error = sprintf($this->lang['error_download'], $url) . "\n";
     }
     if (!$this->manager->error && !ap_decompress("{$tmp}/{$file}", $tmp)) {
         $this->manager->error = sprintf($this->lang['error_decompress'], $file) . "\n";
     }
     // search $tmp for the folder(s) that has been created
     // move the folder(s) to lib/plugins/
     if (!$this->manager->error) {
         if ($dh = @opendir("{$tmp}/")) {
             while (false !== ($f = readdir($dh))) {
                 if ($f == '.' || $f == '..' || $f == 'tmp') {
                     continue;
                 }
                 if (!is_dir("{$tmp}/{$f}")) {
                     continue;
                 }
                 // check to make sure we aren't overwriting anything
                 if (!$overwrite && @file_exists(DOKU_PLUGIN . $f)) {
                     // remember our settings, ask the user to confirm overwrite, FIXME
                     continue;
                 }
                 $instruction = @file_exists(DOKU_PLUGIN . $f) ? 'update' : 'install';
                 if (ap_copy("{$tmp}/{$f}", DOKU_PLUGIN . $f)) {
                     $this->downloaded[] = $f;
                     $this->plugin_writelog($f, $instruction, array($url));
                 } else {
                     $this->manager->error .= sprintf($this->lang['error_copy'] . "\n", $f);
                 }
             }
             closedir($dh);
         } else {
             $this->manager->error = $this->lang['error'] . "\n";
         }
     }
     // cleanup
     if ($tmp) {
         ap_delete($tmp);
     }
     if (!$this->manager->error) {
         msg('Plugin package (' . count($this->downloaded) . ' plugin' . (count($this->downloaded) != 1 ? 's' : '') . ': ' . join(',', $this->downloaded) . ') successfully installed.', 1);
         $this->refresh();
         return true;
     }
     return false;
 }
예제 #7
0
 function test_full_hierarchy()
 {
     // setup hierachy and test it exists
     $dir = io_mktmpdir();
     $top = dirname($dir);
     $this->assertTrue($dir !== false);
     $this->assertTrue(is_dir($dir));
     $this->assertTrue(io_mkdir_p("{$dir}/foo/bar/baz"));
     $this->assertTrue(is_dir("{$dir}/foo/bar/baz"));
     $this->assertTrue(io_mkdir_p("{$dir}/foobar/bar/baz"));
     $this->assertTrue(is_dir("{$dir}/foobar/bar/baz"));
     // put files
     $this->assertTrue(io_saveFile("{$dir}/testfile.txt", 'foobar'));
     $this->assertFileExists("{$dir}/testfile.txt");
     $this->assertTrue(io_saveFile("{$dir}/foo/testfile.txt", 'foobar'));
     $this->assertFileExists("{$dir}/foo/testfile.txt");
     $this->assertTrue(io_saveFile("{$dir}/foo/bar/baz/testfile.txt", 'foobar'));
     $this->assertFileExists("{$dir}/foo/bar/baz/testfile.txt");
     // delete unsuccessfully
     $this->assertFalse(io_rmdir($dir, false));
     // check result
     clearstatcache();
     $this->assertFileExists("{$dir}/testfile.txt");
     $this->assertFileExists("{$dir}/foo/testfile.txt");
     $this->assertFileExists("{$dir}/foo/bar/baz/testfile.txt");
     $this->assertTrue(is_dir("{$dir}/foo/bar/baz"));
     $this->assertTrue(is_dir("{$dir}/foobar/bar/baz"));
     $this->assertTrue(is_dir($dir));
     $this->assertTrue(is_dir($top));
     // delete successfully
     $this->assertTrue(io_rmdir($dir, true));
     // check result
     clearstatcache();
     $this->assertFileNotExists("{$dir}/testfile.txt");
     $this->assertFileNotExists("{$dir}/foo/testfile.txt");
     $this->assertFileNotExists("{$dir}/foo/bar/baz/testfile.txt");
     $this->assertFalse(is_dir("{$dir}/foo/bar/baz"));
     $this->assertFalse(is_dir("{$dir}/foobar/bar/baz"));
     $this->assertFalse(is_dir($dir));
     $this->assertTrue(is_dir($top));
 }