コード例 #1
0
 /**
  * @coversNothing
  */
 public function tearDown()
 {
     /** @var helper_plugin_move_plan $plan  */
     $plan = plugin_load('helper', 'move_plan');
     $plan->abort();
     io_rmdir(DOKU_TMP_DATA . "pages/newns", true);
     io_rmdir(DOKU_TMP_DATA . "media/newns", true);
     io_rmdir(DOKU_TMP_DATA . "meta/newns", true);
     parent::tearDown();
 }
コード例 #2
0
 /**
  * @coversNothing
  */
 public function tearDown()
 {
     global $conf;
     $dirs = array('indexdir', 'datadir', 'metadir', 'mediadir');
     foreach ($dirs as $dir) {
         io_rmdir($conf[$dir], true);
         mkdir($conf[$dir]);
     }
     $this->plan->abort();
     parent::tearDown();
 }
コード例 #3
0
ファイル: striplangs.php プロジェクト: yjliugit/dokuwiki
 /**
  * Strip languages from path
  *
  * @param string $path       path to lang dir
  * @param array  $keep_langs languages to keep
  */
 protected function stripDirLangs($path, $keep_langs)
 {
     $dir = dir($path);
     while (($cur_dir = $dir->read()) !== false) {
         if ($cur_dir != '.' and $cur_dir != '..' and is_dir($path . '/' . $cur_dir)) {
             if (!in_array($cur_dir, $keep_langs, true)) {
                 io_rmdir($path . '/' . $cur_dir, true);
             }
         }
     }
     $dir->close();
 }
コード例 #4
0
 /**
  * Cleanup temp dir
  */
 function __destruct()
 {
     io_rmdir(_MPDF_TEMP_PATH, true);
 }
コード例 #5
0
 /**
  * Build the document from the template.
  * (code taken from old function 'document_end_scratch')
  *
  * @param string      $doc
  * @param string      $autostyles
  * @param array       $commonstyles
  * @param string      $meta
  * @param string      $userfields
  * @param ODTDefaultStyles $styleset
  * @return mixed
  */
 public function build($doc = null, $meta = null, $userfields = null, $pagestyles = null)
 {
     // for the temp dir
     global $ID;
     // Temp dir
     if (is_dir($this->config->getParam('tmpdir'))) {
         // version > 20070626
         $temp_dir = $this->config->getParam('tmpdir');
     } else {
         // version <= 20070626
         $temp_dir = $this->config->getParam('savedir') . '/cache/tmp';
     }
     $temp_dir = $temp_dir . "/odt/" . str_replace(':', '-', $ID);
     if (is_dir($temp_dir)) {
         io_rmdir($temp_dir, true);
     }
     io_mkdir_p($temp_dir);
     // Extract template
     $template_path = $this->config->getParam('mediadir') . '/' . $this->directory . "/" . $this->template;
     $ok = $this->ZIP->Extract($template_path, $temp_dir);
     if ($ok == -1) {
         throw new Exception(' Error extracting the zip archive:' . $template_path . ' to ' . $temp_dir);
     }
     // Import styles from ODT template
     //$this->styleset->importFromODTFile($temp_dir.'/content.xml', 'office:automatic-styles');
     //$this->styleset->importFromODTFile($temp_dir.'/styles.xml', 'office:styles');
     $autostyles = $this->styleset->export('office:automatic-styles');
     $commonstyles = $this->styleset->export('office:styles');
     // Prepare content
     $missingfonts = $this->styleset->getMissingFonts($temp_dir . '/styles.xml');
     // Insert content
     $old_content = io_readFile($temp_dir . '/content.xml');
     if (strpos($old_content, 'DOKUWIKI-ODT-INSERT') !== FALSE) {
         // Replace the mark
         $this->_odtReplaceInFile('/<text:p[^>]*>DOKUWIKI-ODT-INSERT<\\/text:p>/', $doc, $temp_dir . '/content.xml', true);
     } else {
         // Append to the template
         $this->_odtReplaceInFile('</office:text>', $doc . '</office:text>', $temp_dir . '/content.xml');
     }
     // Cut off unwanted content
     if (strpos($old_content, 'DOKUWIKI-ODT-CUT-START') !== FALSE && strpos($old_content, 'DOKUWIKI-ODT-CUT-STOP') !== FALSE) {
         $this->_odtReplaceInFile('/DOKUWIKI-ODT-CUT-START.*DOKUWIKI-ODT-CUT-STOP/', '', $temp_dir . '/content.xml', true);
     }
     // Insert userfields
     if (strpos($old_content, "text:user-field-decls") === FALSE) {
         // no existing userfields
         $this->_odtReplaceInFile('/<office:text([^>]*)>/U', '<office:text\\1>' . $userfields, $temp_dir . '/content.xml', TRUE);
     } else {
         $this->_odtReplaceInFile('</text:user-field-decls>', substr($userfields, 23), $temp_dir . '/content.xml');
     }
     // Insert styles & fonts
     $value = io_readFile($temp_dir . '/content.xml');
     $original = XMLUtil::getElement('office:automatic-styles', $value);
     $this->_odtReplaceInFile($original, $autostyles, $temp_dir . '/content.xml');
     $value = io_readFile($temp_dir . '/styles.xml');
     $original = XMLUtil::getElement('office:automatic-styles', $value);
     $this->_odtReplaceInFile($original, $autostyles, $temp_dir . '/styles.xml');
     $value = io_readFile($temp_dir . '/styles.xml');
     $original = XMLUtil::getElement('office:styles', $value);
     $this->_odtReplaceInFile($original, $commonstyles, $temp_dir . '/styles.xml');
     $this->_odtReplaceInFile('</office:font-face-decls>', $missingfonts . '</office:font-face-decls>', $temp_dir . '/styles.xml');
     // Insert page styles
     $page = '';
     foreach ($pagestyles as $name => $layout_name) {
         $page .= '<style:master-page style:name="' . $name . '" style:page-layout-name="' . $layout_name . '"/>';
     }
     if (!empty($page)) {
         $this->_odtReplaceInFile('</office:master-styles>', $page . '</office:master-styles>', $temp_dir . '/styles.xml');
     }
     // Add manifest data
     $this->_odtReplaceInFile('</manifest:manifest>', $this->manifest->getExtraContent() . '</manifest:manifest>', $temp_dir . '/META-INF/manifest.xml');
     // Build the Zip
     $this->ZIP->Compress(null, $temp_dir, null);
     io_rmdir($temp_dir, true);
 }
コード例 #6
0
/**
 * Recursively delete a directory
 *
 * @author Andreas Gohr <*****@*****.**>
 * @param string $path
 * @param bool   $removefiles defaults to false which will delete empty directories only
 * @return bool
 */
function io_rmdir($path, $removefiles = false)
{
    if (!is_string($path) || $path == "") {
        return false;
    }
    if (!file_exists($path)) {
        return true;
    }
    // it's already gone or was never there, count as success
    if (is_dir($path) && !is_link($path)) {
        $dirs = array();
        $files = array();
        if (!($dh = @opendir($path))) {
            return false;
        }
        while (false !== ($f = readdir($dh))) {
            if ($f == '..' || $f == '.') {
                continue;
            }
            // collect dirs and files first
            if (is_dir("{$path}/{$f}") && !is_link("{$path}/{$f}")) {
                $dirs[] = "{$path}/{$f}";
            } else {
                if ($removefiles) {
                    $files[] = "{$path}/{$f}";
                } else {
                    return false;
                    // abort when non empty
                }
            }
        }
        closedir($dh);
        // now traverse into  directories first
        foreach ($dirs as $dir) {
            if (!io_rmdir($dir, $removefiles)) {
                return false;
            }
            // abort on any error
        }
        // now delete files
        foreach ($files as $file) {
            if (!@unlink($file)) {
                return false;
            }
            //abort on any error
        }
        // remove self
        return @rmdir($path);
    } else {
        if ($removefiles) {
            return @unlink($path);
        }
    }
    return false;
}
コード例 #7
0
ファイル: extension.php プロジェクト: boycaught/dokuwiki
 /**
  * Delete outdated files from updated plugins
  *
  * @param array $installed
  */
 private function removeDeletedfiles($installed)
 {
     foreach ($installed as $id => $extension) {
         // only on update
         if ($extension['action'] == 'install') {
             continue;
         }
         // get definition file
         if ($extension['type'] == 'template') {
             $extensiondir = DOKU_TPLLIB;
         } else {
             $extensiondir = DOKU_PLUGIN;
         }
         $extensiondir = $extensiondir . $extension['base'] . '/';
         $definitionfile = $extensiondir . 'deleted.files';
         if (!file_exists($definitionfile)) {
             continue;
         }
         // delete the old files
         $list = file($definitionfile);
         foreach ($list as $line) {
             $line = trim(preg_replace('/#.*$/', '', $line));
             if (!$line) {
                 continue;
             }
             $file = $extensiondir . $line;
             if (!file_exists($file)) {
                 continue;
             }
             io_rmdir($file, true);
         }
     }
 }
コード例 #8
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;
}
コード例 #9
0
ファイル: extension.php プロジェクト: krichter722/dokuwiki
 /**
  * @param string $file      The path to the archive that shall be installed
  * @param bool   $overwrite If an already installed plugin should be overwritten
  * @param string $base      The basename of the plugin if it's known
  * @throws Exception        when something went wrong
  * @return array            list of installed extensions
  */
 public function installArchive($file, $overwrite = false, $base = '')
 {
     $installed_extensions = array();
     // create tmp directory for decompression
     if (!($tmp = $this->mkTmpDir())) {
         throw new Exception($this->getLang('error_dircreate'));
     }
     // add default base folder if specified to handle case where zip doesn't contain this
     if ($base && !@mkdir($tmp . '/' . $base)) {
         throw new Exception($this->getLang('error_dircreate'));
     }
     // decompress
     $this->decompress($file, "{$tmp}/" . $base);
     // search $tmp/$base for the folder(s) that has been created
     // move the folder(s) to lib/..
     $result = array('old' => array(), 'new' => array());
     $default = $this->isTemplate() ? 'template' : 'plugin';
     if (!$this->find_folders($result, $tmp . '/' . $base, $default)) {
         throw new Exception($this->getLang('error_findfolder'));
     }
     // choose correct result array
     if (count($result['new'])) {
         $install = $result['new'];
     } else {
         $install = $result['old'];
     }
     if (!count($install)) {
         throw new Exception($this->getLang('error_findfolder'));
     }
     // now install all found items
     foreach ($install as $item) {
         // where to install?
         if ($item['type'] == 'template') {
             $target_base_dir = DOKU_TPLLIB;
         } else {
             $target_base_dir = DOKU_PLUGIN;
         }
         if (!empty($item['base'])) {
             // use base set in info.txt
         } elseif ($base && count($install) == 1) {
             $item['base'] = $base;
         } else {
             // default - use directory as found in zip
             // plugins from github/master without *.info.txt will install in wrong folder
             // but using $info->id will make 'code3' fail (which should install in lib/code/..)
             $item['base'] = basename($item['tmp']);
         }
         // check to make sure we aren't overwriting anything
         $target = $target_base_dir . $item['base'];
         if (!$overwrite && file_exists($target)) {
             // TODO remember our settings, ask the user to confirm overwrite
             continue;
         }
         $action = file_exists($target) ? 'update' : 'install';
         // copy action
         if ($this->dircopy($item['tmp'], $target)) {
             // return info
             $id = $item['base'];
             if ($item['type'] == 'template') {
                 $id = 'template:' . $id;
             }
             $installed_extensions[$id] = array('base' => $item['base'], 'type' => $item['type'], 'action' => $action);
         } else {
             throw new Exception(sprintf($this->getLang('error_copy') . DOKU_LF, '<bdi>' . $item['base'] . '</bdi>'));
         }
     }
     // cleanup
     if ($tmp) {
         io_rmdir($tmp, true);
     }
     return $installed_extensions;
 }
コード例 #10
0
ファイル: io_rmdir.test.php プロジェクト: rsnitsch/dokuwiki
 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));
 }