コード例 #1
0
 private function initRepo()
 {
     //get path to the repo root (by default DokuWiki's savedir)
     if (defined('DOKU_FARM')) {
         $repoPath = $this->getConf('repoPath');
     } else {
         $repoPath = DOKU_INC . $this->getConf('repoPath');
     }
     //set the path to the git binary
     $gitPath = trim($this->getConf('gitPath'));
     if ($gitPath !== '') {
         Git::set_bin($gitPath);
     }
     //init the repo and create a new one if it is not present
     io_mkdir_p($repoPath);
     $repo = new GitRepo($repoPath, true, true);
     //set git working directory (by default DokuWiki's savedir)
     $repoWorkDir = DOKU_INC . $this->getConf('repoWorkDir');
     Git::set_bin(Git::get_bin() . ' --work-tree ' . escapeshellarg($repoWorkDir));
     $params = str_replace(array('%mail%', '%user%'), array($this->getAuthorMail(), $this->getAuthor()), $this->getConf('addParams'));
     if ($params) {
         Git::set_bin(Git::get_bin() . ' ' . $params);
     }
     return $repo;
 }
コード例 #2
0
ファイル: ajax.php プロジェクト: kiwix/dokukiwix
/**
 * Prepare the static dump
 */
function ajax_prepare()
{
    global $conf;
    $today = date('Y-m-d');
    $staticDir = DOKU_INC . $conf['savedir'] . '/static/' . $today . "/";
    // create output directory
    io_mkdir_p($rootStaticPath);
    // acquire a lock
    $lock = $conf['lockdir'] . '/_dokukiwix.lock';
    if (!file_exists($lock) || time() - @filemtime($lock) > 60 * 5) {
        unlink($lock);
        if ($fp = fopen($lock, 'w+')) {
            fwrite($fp, $today);
            fclose($fp);
        }
    } else {
        print 'dokukiwix is locked.';
        exit;
    }
    // create mandatory directories
    io_mkdir_p($staticDir . '/images/');
    io_mkdir_p($staticDir . '/images/extern/');
    io_mkdir_p($staticDir . '/pages/');
    io_mkdir_p($staticDir . '/css/');
    print 'true';
}
コード例 #3
0
 function __construct($pagesize = 'A4', $orientation = 'portrait')
 {
     global $conf;
     io_mkdir_p(_MPDF_TTFONTDATAPATH);
     io_mkdir_p(_MPDF_TEMP_PATH);
     $format = $pagesize;
     if ($orientation == 'landscape') {
         $format .= '-L';
     }
     switch ($conf['lang']) {
         case 'zh':
         case 'zh-tw':
         case 'ja':
         case 'ko':
             $mode = '+aCJK';
             break;
         default:
             $mode = 'UTF-8-s';
     }
     // we're always UTF-8
     parent::__construct($mode, $format);
     $this->autoScriptToLang = true;
     $this->baseScript = 1;
     $this->autoVietnamese = true;
     $this->autoArabic = true;
     $this->autoLangToFont = true;
     $this->ignore_invalid_utf8 = true;
     $this->tabSpaces = 4;
 }
コード例 #4
0
ファイル: DokuPDF.class.php プロジェクト: neutrinog/Door43
 function __construct()
 {
     io_mkdir_p(_MPDF_TTFONTDATAPATH);
     io_mkdir_p(_MPDF_TEMP_PATH);
     // we're always UTF-8
     parent::__construct('UTF-8-s');
     $this->SetAutoFont(AUTOFONT_ALL);
     $this->ignore_invalid_utf8 = true;
 }
コード例 #5
0
ファイル: repo.class.php プロジェクト: lorea/Hydra-dev
 /**
  * Send a zipped theme
  *
  * @author Samuele Tognini <*****@*****.**>
  */
 function send_theme($file)
 {
     require_once DOKU_PLUGIN . 'indexmenu/syntax/indexmenu.php';
     $idxm = new syntax_plugin_indexmenu_indexmenu();
     //clean the file name
     $file = cleanID($file);
     //check config
     if (!$idxm->getConf('be_repo') || empty($file)) {
         return false;
     }
     $repodir = INDEXMENU_IMG_ABSDIR . "/repository";
     $zipfile = $repodir . "/{$file}.zip";
     $localtheme = INDEXMENU_IMG_ABSDIR . "/{$file}/";
     //theme does not exists
     if (!file_exists($localtheme)) {
         return false;
     }
     if (!io_mkdir_p($repodir)) {
         return false;
     }
     $lm = @filemtime($zipfile);
     //no cached zip or older than 1 day
     if ($lm < time() - 60 * 60 * 24) {
         //create the zip
         require_once DOKU_PLUGIN . "indexmenu/inc/pclzip.lib.php";
         @unlink($zipfile);
         $zip = new PclZip($zipfile);
         $status = $zip->add($localtheme, PCLZIP_OPT_REMOVE_ALL_PATH);
         //error
         if ($status == 0) {
             return false;
         }
     }
     $len = (int) filesize($zipfile);
     //don't send large zips
     if ($len > 2 * 1024 * 1024) {
         return false;
     }
     //headers
     header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Content-Type: application/zip');
     header('Content-Disposition: attachment; filename="' . basename($zipfile) . '";');
     header("Content-Transfer-Encoding: binary");
     //send zip
     $fp = @fopen($zipfile, 'rb');
     if ($fp) {
         $ct = @fread($fp, $len);
         print $ct;
     }
     @fclose($fp);
     return true;
 }
コード例 #6
0
 private function initRepo()
 {
     //get path to the repo root (by default DokuWiki's savedir)
     $repoPath = DOKU_INC . $this->getConf('repoPath');
     //init the repo and create a new one if it is not present
     io_mkdir_p($repoPath);
     $repo = new GitRepo($repoPath, true, true);
     //set git working directory (by default DokuWiki's savedir)
     $repoWorkDir = DOKU_INC . $this->getConf('repoWorkDir');
     $repo->git_path .= ' --work-tree ' . escapeshellarg($repoWorkDir);
     $params = str_replace(array('%mail%', '%user%'), array($this->getAuthorMail(), $this->getAuthor()), $this->getConf('addParams'));
     if ($params) {
         $repo->git_path .= ' ' . $params;
     }
     return $repo;
 }
コード例 #7
0
 /**
  * 
  *
  * @param Doku_Event $event  Not used
  * @param mixed      $param  Not used
  * @return void
  */
 public function handle(Doku_Event &$event, $param)
 {
     global $conf;
     if ($event->data != 'feedaggregator') {
         return;
     }
     $event->preventDefault();
     // See if we need a token and whether it matches.
     $requiredToken = $this->getConf('token');
     $suppliedToken = isset($_GET['token']) ? $_GET['token'] : false;
     if (!empty($requiredToken) && $suppliedToken !== $requiredToken) {
         msg("Token doesn't match for feedaggregator");
         return true;
     }
     // Get the feed list.
     $feeds = file(fullpath($conf['tmpdir'] . '/feedaggregator.csv'));
     // Set up SimplePie and merge all the feeds together.
     $simplepie = new FeedParser();
     $ua = 'Mozilla/4.0 (compatible; DokuWiki feedaggregator plugin ' . wl('', '', true) . ')';
     $simplepie->set_useragent($ua);
     $simplepie->force_feed($this->getConf('force_feed'));
     $simplepie->force_fsockopen($this->getConf('force_fsockopen'));
     $simplepie->set_feed_url($feeds);
     // Set up caching.
     $cacheDir = fullpath($conf['cachedir'] . '/feedaggregator');
     io_mkdir_p($cacheDir);
     $simplepie->enable_cache();
     $simplepie->set_cache_location($cacheDir);
     // Run the actual feed aggregation.
     $simplepie->init();
     // Check for errors.
     if ($simplepie->error()) {
         header("Content-type:text/plain");
         echo join("\n", $simplepie->error());
     }
     // Create the output HTML and cache it for use by the syntax component.
     $html = '';
     foreach ($simplepie->get_items() as $item) {
         $html .= "<div class='feedaggregator_item'>\n" . "<h2>" . $item->get_title() . "</h2>\n" . $item->get_content() . "\n" . "<p>" . "  <a href='" . $item->get_permalink() . "'>Published " . $item->get_date('j M Y') . "</a> " . "  in <a href='" . $item->get_feed()->get_permalink() . "'>" . $item->get_feed()->get_title() . "</a>" . "</p>\n" . "</div>\n\n";
     }
     io_saveFile($cacheDir . '/output.html', $html);
     // Output nothing, as this should be run from cron and we don't want to
     // flood the logs with success.
     exit(0);
 }
コード例 #8
0
ファイル: helper.php プロジェクト: neutrinog/Door43
    /**
     * Internal function for moving and renaming meta/attic files between namespaces
     *
     * @param string $dir   The root path of the files (e.g. $conf['metadir'] or $conf['olddir']
     * @param array  $opts  Move options (used here: ns, newns, name, newname)
     * @param string $extregex Regular expression for matching the extension of the file that shall be moved
     * @return bool If the files were moved successfully
     */
    private function move_files($dir, $opts, $extregex) {
        $old_path = $dir;
        if ($opts['ns'] != '') $old_path .= '/'.utf8_encodeFN(str_replace(':', '/', $opts['ns']));
        $new_path = $dir;
        if ($opts['newns'] != '') $new_path .= '/'.utf8_encodeFN(str_replace(':', '/', $opts['newns']));
        $regex = '/^'.preg_quote(utf8_encodeFN($opts['name'])).'('.$extregex.')$/u';

        if (!is_dir($old_path)) return true; // no media files found

        $dh = @opendir($old_path);
        if($dh) {
            while(($file = readdir($dh)) !== false) {
                if (substr($file, 0, 1) == '.') continue;
                $match = array();
                if (is_file($old_path.'/'.$file) && preg_match($regex, $file, $match)) {
                    if (!is_dir($new_path)) {
                        if (!io_mkdir_p($new_path)) {
                            msg('Creating directory '.hsc($new_path).' failed.', -1);
                            return false;
                        }
                    }
                    if (!io_rename($old_path.'/'.$file, $new_path.'/'.utf8_encodeFN($opts['newname'].$match[1]))) {
                        msg('Moving '.hsc($old_path.'/'.$file).' to '.hsc($new_path.'/'.utf8_encodeFN($opts['newname'].$match[1])).' failed.', -1);
                        return false;
                    }
                }
            }
            closedir($dh);
        } else {
            msg('Directory '.hsc($old_path).' couldn\'t be opened.', -1);
            return false;
        }
        return true;
    }
コード例 #9
0
ファイル: action.php プロジェクト: nextghost/Dokutranslate
 public function handle_action_act_preprocess(Doku_Event &$event, $param)
 {
     global $ID;
     global $TEXT;
     global $ACT;
     global $SUM;
     global $RANGE;
     global $REV;
     $act = $event->data;
     if ($act != 'dokutranslate_review') {
         $act = act_clean($act);
         $act = act_permcheck($act);
     }
     # Ignore drafts if the page is being translated
     # FIXME: Find a way to save $_REQUEST['parid'] into the draft
     if (@file_exists(metaFN($ID, '.translate')) && in_array($act, array('draft', 'recover'))) {
         act_draftdel('draftdel');
         $ACT = $act = 'edit';
     }
     if ($act == 'save') {
         # Take over save action if translation is in progress
         # or we're starting it
         if (!@file_exists(metaFN($ID, '.translate')) && empty($_REQUEST['translate'])) {
             return;
         }
         if (!checkSecurityToken()) {
             return;
         }
         # We're starting a translation
         if (!@file_exists(metaFN($ID, '.translate')) && !empty($_REQUEST['translate'])) {
             # Check if the user has permission to start
             # translation in this namespace
             if (!isModerator($ID)) {
                 return;
             }
             # Take the event over
             $event->stopPropagation();
             $event->preventDefault();
             # Save the data but exit if it fails
             $ACT = act_save($act);
             if ($ACT != 'show') {
                 return;
             }
             # Page was deleted, exit
             if (!@file_exists(wikiFN($ID))) {
                 return;
             }
             # Prepare data path
             $datapath = dataPath($ID);
             io_mkdir_p($datapath, 0755, true);
             # Backup the original page
             io_rename(wikiFN($ID), $datapath . '/orig.txt');
             # Backup old revisions
             $revisions = allRevisions($ID);
             foreach ($revisions as $rev) {
                 $tmp = wikiFN($ID, $rev);
                 io_rename($tmp, $datapath . '/' . basename($tmp));
             }
             # Backup meta files
             $metas = metaFiles($ID);
             foreach ($metas as $f) {
                 io_rename($f, $datapath . '/' . basename($f));
             }
             # Generate empty page to hold translated text
             $data = getCleanInstructions($datapath . '/orig.txt');
             saveWikiText($ID, genTranslateFile($data), $SUM, $_REQUEST['minor']);
             $translateMeta = genMeta(count($data));
             # create meta file for current translation state
             io_saveFile(metaFN($ID, '.translate'), serialize($translateMeta));
             # create separate meta file for translation history
             io_saveFile(metaFN($ID, '.translateHistory'), serialize(array('current' => $translateMeta)));
         } else {
             # Translation in progress, take the event over
             $event->preventDefault();
             # Save the data but exit if it fails
             $ACT = act_save($act);
             # Save failed, exit
             if ($ACT != 'show') {
                 return;
             }
             # Save successful, update translation metadata
             $lastrev = getRevisions($ID, 0, 1, 1024);
             updateMeta($ID, getParID(), $lastrev[0]);
         }
     } else {
         if ($act == 'revert') {
             # Take over save action if translation is in progress
             if (!@file_exists(metaFN($ID, '.translate'))) {
                 return;
             }
             if (!checkSecurityToken()) {
                 return;
             }
             # Translation in progress, take the event over
             $event->preventDefault();
             # Save the data but exit if it fails
             $revert = $REV;
             $ACT = act_revert($act);
             # Revert failed, exit
             if ($ACT != 'show') {
                 return;
             }
             # Revert successful, update translation metadata
             $lastrev = getRevisions($ID, 0, 1, 1024);
             updateMeta($ID, getParID(), $lastrev[0], $revert);
         } else {
             if (in_array($act, array('edit', 'preview'))) {
                 if (!@file_exists(metaFN($ID, '.translate')) || isset($TEXT)) {
                     return;
                 }
                 $parid = getParID();
                 $instructions = p_cached_instructions(wikiFN($ID));
                 $separators = array();
                 # Build array of paragraph separators
                 foreach ($instructions as $ins) {
                     if ($ins[0] == 'plugin' && $ins[1][0] == 'dokutranslate' && in_array($ins[1][1][0], array(DOKU_LEXER_ENTER, DOKU_LEXER_SPECIAL, DOKU_LEXER_EXIT))) {
                         $separators[] = $ins[1][1];
                     }
                 }
                 # Validate paragraph ID
                 if ($parid >= count($separators) - 1) {
                     $parid = 0;
                 }
                 # Build range for paragraph
                 $RANGE = strval($separators[$parid][2] + 1) . '-' . strval($separators[$parid + 1][1] - 1);
             } else {
                 if ($act == 'dokutranslate_review') {
                     # This action is mine
                     $event->stopPropagation();
                     $event->preventDefault();
                     # Show the page when done
                     $ACT = 'show';
                     # Load data
                     $meta = unserialize(io_readFile(metaFN($ID, '.translateHistory'), false));
                     $parid = getParID();
                     $writeRev = empty($REV) ? 'current' : intval($REV);
                     $writeRev = empty($meta[$writeRev][$parid]['changed']) ? $writeRev : $meta[$writeRev][$parid]['changed'];
                     $user = $_SERVER['REMOTE_USER'];
                     # Check for permission to write reviews
                     if (!canReview($ID, $meta[$writeRev], $parid)) {
                         return;
                     }
                     # Add review to meta array
                     $data['message'] = $_REQUEST['review'];
                     $data['quality'] = intval($_REQUEST['quality']);
                     $data['incomplete'] = !empty($_REQUEST['incomplete']);
                     $meta[$writeRev][$parid]['reviews'][$user] = $data;
                     # Review applies to latest revision as well
                     if (empty($REV) || $meta['current'][$parid]['changed'] == $writeRev) {
                         $meta['current'][$parid]['reviews'][$user] = $data;
                         io_saveFile(metaFN($ID, '.translate'), serialize($meta['current']));
                     }
                     # Save metadata
                     io_saveFile(metaFN($ID, '.translateHistory'), serialize($meta));
                 }
             }
         }
     }
 }
コード例 #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));
 }
コード例 #11
0
 function _dircopy($srcdir, $dstdir)
 {
     io_mkdir_p($dstdir);
     $num = 0;
     if ($curdir = opendir($srcdir)) {
         while ($file = readdir($curdir)) {
             if ($file != '.' && $file != '..') {
                 $srcfile = $srcdir . DIRECTORY_SEPARATOR . $file;
                 $dstfile = $dstdir . DIRECTORY_SEPARATOR . $file;
                 if (is_file($srcfile)) {
                     if (!$this->_copy($srcfile, $dstfile)) {
                         msg(sprintf($this->getLang('error_copying'), $srcfile), -1);
                     } else {
                         $num++;
                     }
                 } else {
                     if (is_dir($srcfile)) {
                         $num += $this->_dircopy($srcfile, $dstfile);
                     }
                 }
             }
         }
         closedir($curdir);
     }
     return $num;
 }
コード例 #12
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);
 }
コード例 #13
0
function epub_setup_book_skel($user_title = false)
{
    $dir = epub_get_metadirectory();
    $meta = $dir . 'META-INF';
    $oebps = epub_get_oebps();
    $media_dir = epub_get_data_media() . 'epub';
    io_mkdir_p($meta);
    io_mkdir_p($oebps);
    io_mkdir_p($oebps . 'Images/');
    io_mkdir_p($oebps . 'Text/');
    io_mkdir_p($media_dir);
    io_mkdir_p($oebps . 'Styles/');
    if (isset($_POST['client'])) {
        $user = cleanID(rawurldecode($_POST['client'])) . '/';
        io_mkdir_p($media_dir . '/' . $user);
    }
    $book_id = cleanID(rawurldecode($_POST['book_page']));
    copy(EPUB_DIR . 'scripts/package/my-book.epub', $dir . 'my-book.epub');
    copy(EPUB_DIR . 'scripts/package/container.xml', $dir . 'META-INF/container.xml');
    if (!$user_title) {
        copy(EPUB_DIR . 'scripts/package/title.html', $oebps . 'Text/title.html');
        copy(EPUB_DIR . 'scripts/package/cover.png', $oebps . 'Images/cover.png');
    }
    $zip = epub_zip_handle($dir . 'my-book.epub');
    if ($zip) {
        $zip->addFile(EPUB_DIR . 'scripts/package/container.xml', 'META-INF/container.xml');
        if (!$user_title) {
            $zip->addFile(EPUB_DIR . 'scripts/package/title.html', 'OEBPS/Text/title.html');
            $zip->addFile(EPUB_DIR . 'scripts/package/cover.png', 'OEBPS/Images/cover.png');
        }
    }
}
コード例 #14
0
 /**
  * Traverse over the given dir and compare it to the DokuWiki dir
  *
  * Checks what files need an update, tests for writability and copies
  *
  * @param string $dir
  * @param bool   $dryrun do not copy but only check permissions
  * @return bool
  */
 private function _traverse($dir, $dryrun)
 {
     $base = $this->tgzdir;
     $ok = true;
     $dh = @opendir($base . '/' . $dir);
     if (!$dh) {
         return false;
     }
     while (($file = readdir($dh)) !== false) {
         if ($file == '.' || $file == '..') {
             continue;
         }
         $from = "{$base}/{$dir}/{$file}";
         $to = DOKU_INC . "{$dir}/{$file}";
         if (is_dir($from)) {
             if ($dryrun) {
                 // just check for writability
                 if (!is_dir($to)) {
                     if (is_dir(dirname($to)) && !is_writable(dirname($to))) {
                         $this->_warn('<b>' . $this->getLang('tv_noperm') . '</b>', hsc("{$dir}/{$file}"));
                         $ok = false;
                     }
                 }
             }
             // recursion
             if (!$this->_traverse("{$dir}/{$file}", $dryrun)) {
                 $ok = false;
             }
         } else {
             $fmd5 = md5(@file_get_contents($from));
             $tmd5 = md5(@file_get_contents($to));
             if ($fmd5 != $tmd5 || !file_exists($to)) {
                 if ($dryrun) {
                     // just check for writability
                     if (file_exists($to) && !is_writable($to) || !file_exists($to) && is_dir(dirname($to)) && !is_writable(dirname($to))) {
                         $this->_warn('<b>' . $this->getLang('tv_noperm') . '</b>', hsc("{$dir}/{$file}"));
                         $ok = false;
                     } else {
                         $this->_say($this->getLang('tv_upd'), hsc("{$dir}/{$file}"));
                     }
                 } else {
                     // check dir
                     if (io_mkdir_p(dirname($to))) {
                         // copy
                         if (!copy($from, $to)) {
                             $this->_warn('<b>' . $this->getLang('tv_nocopy') . '</b>', hsc("{$dir}/{$file}"));
                             $ok = false;
                         } else {
                             $this->_say($this->getLang('tv_done'), hsc("{$dir}/{$file}"));
                         }
                     } else {
                         $this->_warn('<b>' . $this->getLang('tv_nodir') . '</b>', hsc("{$dir}"));
                         $ok = false;
                     }
                 }
             }
         }
     }
     closedir($dh);
     return $ok;
 }
コード例 #15
0
ファイル: TarLib.class.php プロジェクト: stretchyboy/dokuwiki
 function _dirApp($d)
 {
     //  map to dokuwiki function (its more robust)
     return io_mkdir_p($d);
 }
コード例 #16
0
 function externalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL)
 {
     global $conf;
     global $ID;
     list($ext, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         $tmp_dir = $conf['tmpdir'] . "/odt";
         $tmp_name = $tmp_dir . "/" . md5($src) . '.' . $ext;
         $final_name = 'Pictures/' . md5($tmp_name) . '.' . $ext;
         if (!isset($this->manifest[$final_name])) {
             $client = new DokuHTTPClient();
             $img = $client->get($src);
             if ($img === FALSE) {
                 $tmp_name = $src;
                 // fallback to a simple link
             } else {
                 if (!is_dir($tmp_dir)) {
                     io_mkdir_p($tmp_dir);
                 }
                 $tmp_img = fopen($tmp_name, "w") or die("Can't create temp file {$tmp_img}");
                 fwrite($tmp_img, $img);
                 fclose($tmp_img);
             }
         }
         $this->_odtAddImage($tmp_name, $width, $height, $align, $title);
         if (file_exists($tmp_name)) {
             unlink($tmp_name);
         }
     } else {
         $this->externallink($src, $title);
     }
 }
コード例 #17
0
ファイル: config.php プロジェクト: omusico/isle-web-framework
 function _create_dir($path)
 {
     global $conf;
     $res = init_path($path);
     if (empty($res)) {
         // let's create it, recursively
         $res = io_mkdir_p($path);
         //$res = mkdir($path, $conf['dmode'], true);
         if (!$res) {
             die("Unable to create directory {$path}, please create it.");
         }
     }
 }
コード例 #18
0
ファイル: renderer.php プロジェクト: lorea/Hydra-dev
 /**
  * Closes the document using a template
  */
 function document_end_template()
 {
     global $conf, $ID;
     // for the temp dir
     // Temp dir
     if (is_dir($conf['tmpdir'])) {
         $temp_dir = $conf['tmpdir'];
         // version > 20070626
     } else {
         $temp_dir = $conf['savedir'] . '/cache/tmp';
         // version <= 20070626
     }
     $this->temp_dir = $temp_dir . "/odt/" . str_replace(':', '-', $ID);
     if (is_dir($this->temp_dir)) {
         $this->io_rm_rf($this->temp_dir);
     }
     io_mkdir_p($this->temp_dir);
     // Extract template
     $template_path = $conf['mediadir'] . '/' . $this->getConf("tpl_dir") . "/" . $this->template;
     $this->ZIP->Extract($template_path, $this->temp_dir);
     // Prepare content
     $autostyles = $this->_odtAutoStyles();
     $missingstyles = $this->_odtStyles();
     $missingfonts = $this->_odtFonts();
     $userfields = $this->_odtUserFields();
     // Insert content
     $old_content = io_readFile($this->temp_dir . '/content.xml');
     if (strpos($old_content, 'DOKUWIKI-ODT-INSERT') !== FALSE) {
         // Replace the mark
         $this->_odtReplaceInFile('/<text:p[^>]*>DOKUWIKI-ODT-INSERT<\\/text:p>/', $this->doc, $this->temp_dir . '/content.xml', true);
     } else {
         // Append to the template
         $this->_odtReplaceInFile('</office:text>', $this->doc . '</office:text>', $this->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/', '', $this->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, $this->temp_dir . '/content.xml', TRUE);
     } else {
         $this->_odtReplaceInFile('</text:user-field-decls>', substr($userfields, 23), $this->temp_dir . '/content.xml');
     }
     // Insert styles & fonts
     $this->_odtReplaceInFile('</office:automatic-styles>', substr($autostyles, 25), $this->temp_dir . '/content.xml');
     $this->_odtReplaceInFile('</office:automatic-styles>', substr($autostyles, 25), $this->temp_dir . '/styles.xml');
     $this->_odtReplaceInFile('</office:styles>', $missingstyles . '</office:styles>', $this->temp_dir . '/styles.xml');
     $this->_odtReplaceInFile('</office:font-face-decls>', $missingfonts . '</office:font-face-decls>', $this->temp_dir . '/styles.xml');
     // Build the Zip
     $this->ZIP->Compress(null, $this->temp_dir, null);
     $this->io_rm_rf($this->temp_dir);
 }
コード例 #19
0
 function _dirApp($d)
 {
     //  map to dokuwiki function (its more robust)
     return io_mkdir_p($d);
     /*
         $d = explode('/', $d);
         $base = '';
     
         foreach($d as $f) {
           if(!is_dir($base.$f)) {
             $ok = @mkdir($base.$f, 0777);
             if(!$ok) return false;
           }
           $base .= "$f/";
         }
     */
 }
コード例 #20
0
ファイル: helper.php プロジェクト: omusico/isle-web-framework
 /**
  * Locks the site manually, must unlock manually
  *
  * @return  integer  2: already locked, 1: success, 0: fail
  */
 function manual_lock()
 {
     if (is_file($this->manual_lock_file)) {
         return 2;
     }
     @io_mkdir_p(dirname($this->manual_lock_file));
     @touch($this->manual_lock_file);
     if (is_file($this->manual_lock_file)) {
         return 1;
     }
     return 0;
 }
コード例 #21
0
ファイル: extension.php プロジェクト: boycaught/dokuwiki
 /**
  * Copy with recursive sub-directory support
  *
  * @param string $src filename path to file
  * @param string $dst filename path to file
  * @return bool|int|string
  */
 private function dircopy($src, $dst)
 {
     global $conf;
     if (is_dir($src)) {
         if (!($dh = @opendir($src))) {
             return false;
         }
         if ($ok = io_mkdir_p($dst)) {
             while ($ok && false !== ($f = readdir($dh))) {
                 if ($f == '..' || $f == '.') {
                     continue;
                 }
                 $ok = $this->dircopy("{$src}/{$f}", "{$dst}/{$f}");
             }
         }
         closedir($dh);
         return $ok;
     } else {
         $exists = file_exists($dst);
         if (!@copy($src, $dst)) {
             return false;
         }
         if (!$exists && !empty($conf['fperm'])) {
             chmod($dst, $conf['fperm']);
         }
         @touch($dst, filemtime($src));
     }
     return true;
 }
コード例 #22
0
/**
 * Creates a directory hierachy.
 *
 * @link http://www.php.net/manual/en/function.mkdir.php
 * @author <*****@*****.**>
 * @author Andreas Gohr <*****@*****.**>
 * @author Tim Kroeger <*****@*****.**>
 */
function io_mkdir_p($target)
{
    global $bmzConf;
    if (is_dir($target) || empty($target)) {
        return 1;
    }
    // best case check first
    if (@file_exists($target) && !is_dir($target)) {
        return 0;
    }
    // recursion
    if (io_mkdir_p(substr($target, 0, strrpos($target, '/')))) {
        return @mkdir($target, 0755);
        // crawl back up & create dir tree
    }
    return 0;
}
コード例 #23
0
ファイル: admin.php プロジェクト: omusico/isle-web-framework
 /**
  * Retrive and create themes tmp directory
  *
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  * @author     Samuele Tognini <*****@*****.**>
  */
 function checktmpsubdir()
 {
     $tmp = INDEXMENU_IMG_ABSDIR . "/tmp";
     if (!io_mkdir_p($tmp)) {
         msg($this->getLang('dir_err') . ": {$tmp}", -1);
         return false;
     }
     return INDEXMENU_IMG_ABSDIR;
 }
コード例 #24
0
 /**
  * Render an external media file
  *
  * @param string $src        full media URL
  * @param string $title      descriptive text
  * @param string $align      left|center|right
  * @param int    $width      width of media in pixel
  * @param int    $height     height of media in pixel
  * @param string $cache      cache|recache|nocache
  * @param string $linking    linkonly|detail|nolink
  * @param bool   $returnonly whether to return odt or write to doc attribute
  */
 function externalmedia($src, $title = NULL, $align = NULL, $width = NULL, $height = NULL, $cache = NULL, $linking = NULL, $returnonly = false)
 {
     list($ext, $mime) = mimetype($src);
     if (substr($mime, 0, 5) == 'image') {
         $tmp_dir = $this->config->getParam('tmpdir') . "/odt";
         $tmp_name = $tmp_dir . "/" . md5($src) . '.' . $ext;
         $final_name = 'Pictures/' . md5($tmp_name) . '.' . $ext;
         if (!$this->docHandler->fileExists($final_name)) {
             $client = new DokuHTTPClient();
             $img = $client->get($src);
             if ($img === FALSE) {
                 $tmp_name = $src;
                 // fallback to a simple link
             } else {
                 if (!is_dir($tmp_dir)) {
                     io_mkdir_p($tmp_dir);
                 }
                 $tmp_img = fopen($tmp_name, "w") or die("Can't create temp file {$tmp_img}");
                 fwrite($tmp_img, $img);
                 fclose($tmp_img);
             }
         }
         if ($returnonly) {
             $ret = $this->_odtAddImage($tmp_name, $width, $height, $align, $title, true);
             if (file_exists($tmp_name)) {
                 unlink($tmp_name);
             }
             return $ret;
         } else {
             $this->_odtAddImage($tmp_name, $width, $height, $align, $title);
             if (file_exists($tmp_name)) {
                 unlink($tmp_name);
             }
         }
     } else {
         if ($returnonly) {
             return $this->externallink($src, $title, true);
         } else {
             $this->externallink($src, $title);
         }
     }
 }
コード例 #25
0
/**
 * Creates a unique temporary directory and returns
 * its path.
 *
 * @author Michael Klier <*****@*****.**>
 */
function io_mktmpdir()
{
    global $conf;
    $base = $conf['tmpdir'];
    $dir = md5(uniqid(mt_rand(), true));
    $tmpdir = $base . '/' . $dir;
    if (io_mkdir_p($tmpdir)) {
        return $tmpdir;
    } else {
        return false;
    }
}
コード例 #26
0
/**
 * Creates a directory hierachy.
 *
 * @link    http://www.php.net/manual/en/function.mkdir.php
 * @author  <*****@*****.**>
 * @author  Andreas Gohr <*****@*****.**>
 * @author  Tim Kroeger <*****@*****.**>
 */
function io_mkdir_p($target)
{
    global $bmzConf;
    if (is_dir($target) || empty($target)) {
        return 1;
    }
    // best case check first
    if (@file_exists($target) && !is_dir($target)) {
        return 0;
    }
    //recursion
    if (io_mkdir_p(substr($target, 0, strrpos($target, '/')))) {
        if ($bmzConf['safemodehack']) {
            $dir = preg_replace('/^' . preg_quote(realpath($bmzConf['ftp']['root']), '/') . '/', '', $target);
            return io_mkdir_ftp($dir);
        } else {
            return @mkdir($target, 0777);
            // crawl back up & create dir tree
        }
    }
    return 0;
}
コード例 #27
0
 function _mkdir($d)
 {
     return io_mkdir_p($d);
 }
コード例 #28
0
 /**
  * Executes the move op
  *
  * @param string $dir      The root path of the files (e.g. $conf['metadir'] or $conf['olddir']
  * @param string $src_ns   The original namespace
  * @param string $src_name The original basename of the moved doc (empty for namespace moves)
  * @param string $dst_ns   The namespace after the move
  * @param string $dst_name The basename after the move (empty for namespace moves)
  * @param string $extregex Regular expression for matching the extension of the file that shall be moved
  * @return bool If the files were moved successfully
  */
 protected function execute($dir, $src_ns, $src_name, $dst_ns, $dst_name, $extregex)
 {
     $old_path = $dir;
     if ($src_ns != '') {
         $old_path .= '/' . utf8_encodeFN(str_replace(':', '/', $src_ns));
     }
     $new_path = $dir;
     if ($dst_ns != '') {
         $new_path .= '/' . utf8_encodeFN(str_replace(':', '/', $dst_ns));
     }
     $regex = '/^' . preg_quote(utf8_encodeFN($src_name)) . '(' . $extregex . ')$/u';
     if (!is_dir($old_path)) {
         return true;
     }
     // no media files found
     $dh = @opendir($old_path);
     if ($dh) {
         while (($file = readdir($dh)) !== false) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             $match = array();
             if (is_file($old_path . '/' . $file) && preg_match($regex, $file, $match)) {
                 if (!is_dir($new_path)) {
                     if (!io_mkdir_p($new_path)) {
                         msg('Creating directory ' . hsc($new_path) . ' failed.', -1);
                         return false;
                     }
                 }
                 if (!io_rename($old_path . '/' . $file, $new_path . '/' . utf8_encodeFN($dst_name . $match[1]))) {
                     msg('Moving ' . hsc($old_path . '/' . $file) . ' to ' . hsc($new_path . '/' . utf8_encodeFN($dst_name . $match[1])) . ' failed.', -1);
                     return false;
                 }
             }
         }
         closedir($dh);
     } else {
         msg('Directory ' . hsc($old_path) . ' couldn\'t be opened.', -1);
         return false;
     }
     return true;
 }
コード例 #29
0
ファイル: Tar.class.php プロジェクト: kevinlovesing/dokuwiki
 /**
  * Extract an existing TAR archive
  *
  * The $strip parameter allows you to strip a certain number of path components from the filenames
  * found in the tar file, similar to the --strip-components feature of GNU tar. This is triggered when
  * an integer is passed as $strip.
  * Alternatively a fixed string prefix may be passed in $strip. If the filename matches this prefix,
  * the prefix will be stripped. It is recommended to give prefixes with a trailing slash.
  *
  * By default this will extract all files found in the archive. You can restrict the output using the $include
  * and $exclude parameter. Both expect a full regular expression (including delimiters and modifiers). If
  * $include is set only files that match this expression will be extracted. Files that match the $exclude
  * expression will never be extracted. Both parameters can be used in combination. Expressions are matched against
  * stripped filenames as described above.
  *
  * The archive is closed afer reading the contents, because rewinding is not possible in bzip2 streams.
  * Reopen the file with open() again if you want to do additional operations
  *
  * @param string     $outdir  the target directory for extracting
  * @param int|string $strip   either the number of path components or a fixed prefix to strip
  * @param string     $exclude a regular expression of files to exclude
  * @param string     $include a regular expression of files to include
  * @throws TarIOException
  * @return array
  */
 function extract($outdir, $strip = '', $exclude = '', $include = '')
 {
     if ($this->closed || !$this->file) {
         throw new TarIOException('Can not read from a closed archive');
     }
     $outdir = rtrim($outdir, '/');
     io_mkdir_p($outdir);
     $striplen = strlen($strip);
     $extracted = array();
     while ($dat = $this->readbytes(512)) {
         // read the file header
         $header = $this->parseHeader($dat);
         if (!is_array($header)) {
             continue;
         }
         if (!$header['filename']) {
             continue;
         }
         // strip prefix
         $filename = $this->cleanPath($header['filename']);
         if (is_int($strip)) {
             // if $strip is an integer we strip this many path components
             $parts = explode('/', $filename);
             if (!$header['typeflag']) {
                 $base = array_pop($parts);
                 // keep filename itself
             } else {
                 $base = '';
             }
             $filename = join('/', array_slice($parts, $strip));
             if ($base) {
                 $filename .= "/{$base}";
             }
         } else {
             // ifstrip is a string, we strip a prefix here
             if (substr($filename, 0, $striplen) == $strip) {
                 $filename = substr($filename, $striplen);
             }
         }
         // check if this should be extracted
         $extract = true;
         if (!$filename) {
             $extract = false;
         } else {
             if ($include) {
                 if (preg_match($include, $filename)) {
                     $extract = true;
                 } else {
                     $extract = false;
                 }
             }
             if ($exclude && preg_match($exclude, $filename)) {
                 $extract = false;
             }
         }
         // Now do the extraction (or not)
         if ($extract) {
             $extracted[] = $header;
             $output = "{$outdir}/{$filename}";
             $directory = $header['typeflag'] ? $output : dirname($output);
             io_mkdir_p($directory);
             // is this a file?
             if (!$header['typeflag']) {
                 $fp = fopen($output, "wb");
                 if (!$fp) {
                     throw new TarIOException('Could not open file for writing: ' . $output);
                 }
                 $size = floor($header['size'] / 512);
                 for ($i = 0; $i < $size; $i++) {
                     fwrite($fp, $this->readbytes(512), 512);
                 }
                 if ($header['size'] % 512 != 0) {
                     fwrite($fp, $this->readbytes(512), $header['size'] % 512);
                 }
                 fclose($fp);
                 touch($output, $header['mtime']);
                 chmod($output, $header['perm']);
             } else {
                 $this->skipbytes(ceil($header['size'] / 512) * 512);
                 // the size is usually 0 for directories
             }
         } else {
             $this->skipbytes(ceil($header['size'] / 512) * 512);
         }
     }
     $this->close();
     return $extracted;
 }
コード例 #30
0
ファイル: action.php プロジェクト: houshuang/folders2web
 function _apply_moves(&$opts)
 {
     foreach ($opts['oldfiles'] as $i => $oldfile) {
         $newfile = $opts['newfiles'][$i];
         $newdir = dirname($newfile);
         if (!io_mkdir_p($newdir)) {
             continue;
         }
         io_rename($oldfile, $newfile);
     }
 }