/** * Gets a local scalable copy of the SVG with its dimensions * * @param $id * @param int $cachetime * @return bool|array either array($file, $width, $height) or false if no cache available */ public function getAdjustedSVG($id, $cachetime = -1) { $info = $this->getInfo(); $cachefile = getCacheName($id . $info['date'], '.svg'); $cachedate = @filemtime($cachefile); if ($cachedate && $cachetime < time() - $cachedate) { list($width, $height) = $this->readSVGsize($cachefile); return array($cachefile, $width, $height); } // still here, create a new cache file if (preg_match('/^https?:\\/\\//i', $id)) { io_download($id, $cachefile); #FIXME make max size configurable } else { @copy(mediaFN($id), $cachefile); } clearstatcache(false, $cachefile); // adjust the size in the cache file if (file_exists($cachefile)) { list($width, $height) = $this->readSVGsize($cachefile, true); return array($cachefile, $width, $height); } return false; }
/** * Download and install themes * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Samuele Tognini <*****@*****.**> */ function install($n, $name) { $repo = $this->repos['url'][$n]; if (!isset($name)) { return false; } $return = true; if (!($absdir = $this->checktmpsubdir())) { return false; } $tmp = $absdir . "/tmp"; //send theme list request if (!($zipfile = io_download($repo . "/lib/plugins/indexmenu/ajax.php?req=send&t=" . $name, "{$tmp}/", true))) { msg($this->getLang('down_err') . ": {$name}", -1); $return = false; } else { //create zip $zip = new PclZip("{$tmp}/{$zipfile}"); $regexp = "/^" . $name . "\\/(info.txt)|(style.css)|(" . str_replace(",", "|", INDEXMENU_ICOS) . ")\\.(gif|png|jpg)\$/i"; $status = $zip->extract(PCLZIP_OPT_PATH, $absdir . "/", PCLZIP_OPT_BY_PREG, $regexp); //error if ($status == 0) { msg($this->getLang('zip_err') . " {$tmp}/{$zipfile}: " . $zip->errorName(true), -1); $return = false; } else { msg("<strong>{$name}</strong> " . $this->getLang('install_ok'), 1); } } //clean tmp $this->_rm_dir($tmp); return $return; }
/** * Download an archive to a protected path * * @param string $url The url to get the archive from * @throws Exception when something goes wrong * @return string The path where the archive was saved */ public function download($url) { // check the url if (!preg_match('/https?:\\/\\//i', $url)) { throw new Exception($this->getLang('error_badurl')); } // try to get the file from the path (used as plugin name fallback) $file = parse_url($url, PHP_URL_PATH); if (is_null($file)) { $file = md5($url); } else { $file = utf8_basename($file); } // create tmp directory for download if (!($tmp = $this->mkTmpDir())) { throw new Exception($this->getLang('error_dircreate')); } // download if (!($file = io_download($url, $tmp . '/', true, $file, 0))) { io_rmdir($tmp, true); throw new Exception(sprintf($this->getLang('error_download'), '<bdi>' . hsc($url) . '</bdi>')); } return $tmp . '/' . $file; }
/** * 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; }
/** * Download a remote file and return local filename * * returns false if download fails. Uses cached file if available and * wanted * * @author Andreas Gohr <*****@*****.**> * @author Pavel Vitis <*****@*****.**> */ function get_from_URL($url, $ext, $cache) { global $conf; $local = getCacheName(strtolower($url), ".media.{$ext}"); $mtime = @filemtime($local); // 0 if not exists //decide if download needed: if ($cache == 0 || $mtime != 0 && $cache != -1 || $mtime == 0 || $cache != -1 && $mtime < time() - $cache) { if (io_download($url, $local)) { return $local; } else { return false; } } //if cache exists use it else if ($mtime) { return $local; } //else return false return false; }
/** * Returns the local binary to use * * Downloads it if necessary * * @return bool|string */ protected function getLocalBinary() { global $conf; $bin = $this->getBinaryName(); if (!$bin) { return false; } // check distributed files first if (file_exists(__DIR__ . '/ditaa/' . $bin)) { return __DIR__ . '/ditaa/' . $bin; } $info = $this->getInfo(); $cache = getCacheName($info['date'], ".{$bin}"); if (file_exists($cache)) { return $cache; } $url = 'https://github.com/akavel/ditaa/releases/download/g1.0.0/' . $bin; if (io_download($url, $cache, false, '', 0)) { @chmod($cache, $conf['dmode']); return $cache; } return false; }
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; }