public static function installPackage($zip_file, dcModules &$modules) { $zip = new fileUnzip($zip_file); $zip->getList(false, '#(^|/)(__MACOSX|\\.svn|\\.hg|\\.git|\\.DS_Store|\\.directory|Thumbs\\.db)(/|$)#'); $zip_root_dir = $zip->getRootDir(); $define = ''; if ($zip_root_dir != false) { $target = dirname($zip_file); $destination = $target . '/' . $zip_root_dir; $define = $zip_root_dir . '/_define.php'; $has_define = $zip->hasFile($define); } else { $target = dirname($zip_file) . '/' . preg_replace('/\\.([^.]+)$/', '', basename($zip_file)); $destination = $target; $define = '_define.php'; $has_define = $zip->hasFile($define); } if ($zip->isEmpty()) { $zip->close(); unlink($zip_file); throw new Exception(__('Empty module zip file.')); } if (!$has_define) { $zip->close(); unlink($zip_file); throw new Exception(__('The zip file does not appear to be a valid Dotclear module.')); } $ret_code = 1; if (!is_dir($destination)) { try { files::makeDir($destination, true); $sandbox = clone $modules; $zip->unzip($define, $target . '/_define.php'); $sandbox->resetModulesList(); $sandbox->requireDefine($target, basename($destination)); unlink($target . '/_define.php'); $new_errors = $sandbox->getErrors(); if (!empty($new_errors)) { $new_errors = is_array($new_errors) ? implode(" \n", $new_errors) : $new_errors; throw new Exception($new_errors); } files::deltree($destination); } catch (Exception $e) { $zip->close(); unlink($zip_file); files::deltree($destination); throw new Exception($e->getMessage()); } } else { # test for update $sandbox = clone $modules; $zip->unzip($define, $target . '/_define.php'); $sandbox->resetModulesList(); $sandbox->requireDefine($target, basename($destination)); unlink($target . '/_define.php'); $new_modules = $sandbox->getModules(); if (!empty($new_modules)) { $tmp = array_keys($new_modules); $id = $tmp[0]; $cur_module = $modules->getModules($id); if (!empty($cur_module) && (defined('DC_DEV') && DC_DEV === true || dcUtils::versionsCompare($new_modules[$id]['version'], $cur_module['version'], '>', true))) { # delete old module if (!files::deltree($destination)) { throw new Exception(__('An error occurred during module deletion.')); } $ret_code = 2; } else { $zip->close(); unlink($zip_file); throw new Exception(sprintf(__('Unable to upgrade "%s". (older or same version)'), basename($destination))); } } else { $zip->close(); unlink($zip_file); throw new Exception(sprintf(__('Unable to read new _define.php file'))); } } $zip->unzipAll($target); $zip->close(); unlink($zip_file); return $ret_code; }
function dc_lang_install($file) { $zip = new fileUnzip($file); $zip->getList(false, '#(^|/)(__MACOSX|\\.svn|\\.DS_Store|Thumbs\\.db)(/|$)#'); if (!preg_match('/^[a-z]{2,3}(-[a-z]{2})?$/', $zip->getRootDir())) { throw new Exception(__('Invalid language zip file.')); } if ($zip->isEmpty() || !$zip->hasFile($zip->getRootDir() . '/main.po')) { throw new Exception(__('The zip file does not appear to be a valid Dotclear language pack.')); } $target = dirname($file); $destination = $target . '/' . $zip->getRootDir(); $res = 1; if (is_dir($destination)) { if (!files::deltree($destination)) { throw new Exception(__('An error occurred during language upgrade.')); } $res = 2; } $zip->unzipAll($target); return $res; }
$archives[] = $v; } } # Revert or delete backup file if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'], $archives)) { $b_file = $_POST['backup_file']; try { if (!empty($_POST['b_del'])) { if (!@unlink(DC_ROOT . '/' . $b_file)) { throw new Exception(sprintf(__('Unable to delete file %s'), html::escapeHTML($b_file))); } http::redirect($p_url); } if (!empty($_POST['b_revert'])) { $zip = new fileUnzip(DC_ROOT . '/' . $b_file); $zip->unzipAll(DC_ROOT . '/'); @unlink(DC_ROOT . '/' . $b_file); http::redirect($p_url); } } catch (Exception $e) { $core->error->add($e->getMessage()); } } # Upgrade process if ($new_v && $step) { try { $updater->setForcedFiles('inc/digests'); switch ($step) { case 'check': $updater->checkIntegrity(DC_ROOT . '/inc/digests', DC_ROOT); http::redirect($p_url . '?step=download');
/** * Install a theme from a zip file * * @param string $zip_file * @param oktThemes $oThemes */ public static function installPackage($zip_file, oktThemes $oThemes) { $zip = new fileUnzip($zip_file); $zip->getList(false, '#(^|/)(__MACOSX|\\.svn|\\.DS_Store|Thumbs\\.db)(/|$)#'); $zip_root_dir = $zip->getRootDir(); if ($zip_root_dir !== false) { $target = dirname($zip_file); $destination = $target . '/' . $zip_root_dir; $define = $zip_root_dir . '/_define.php'; $has_define = $zip->hasFile($define); } else { $target = dirname($zip_file) . '/' . preg_replace('/\\.([^.]+)$/', '', basename($zip_file)); $destination = $target; $define = '_define.php'; $has_define = $zip->hasFile($define); } if ($zip->isEmpty()) { $zip->close(); unlink($zip_file); throw new Exception(__('Empty theme zip file.')); } if (!$has_define) { $zip->close(); unlink($zip_file); throw new Exception(__('The zip file does not appear to be a valid theme.')); } $ret_code = 1; if (is_dir($destination)) { throw new Exception(__('The theme allready exists, you can not update a theme.')); /* copy($target.'/_define.php', $target.'/_define.php.bak'); # test for update $sandbox = clone $oThemes; $zip->unzip($define, $target.'/_define.php'); $sandbox->resetThemesList(); $sandbox->requireDefine($target,basename($destination)); unlink($target.'/_define.php'); $new_themes = $sandbox->getThemesList(); $old_themes = $oThemes->getThemesList(); if (!empty($new_themes)) { $tmp = array_keys($new_themes); $id = $tmp[0]; $cur_theme = $old_themes[$id]; if (!empty($cur_theme) && $new_themes[$id]['version'] != $cur_theme['version']) { # delete old theme if (!files::deltree($destination)) { throw new Exception(__('An error occurred during theme deletion.')); } $ret_code = 2; } else { $zip->close(); unlink($zip_file); if (file_exists($target.'/_define.php.bak')) { rename($target.'/_define.php.bak', $target.'/_define.php'); } throw new Exception(sprintf(__('Unable to upgrade "%s". (same version)'),basename($destination))); } } else { $zip->close(); unlink($zip_file); if (file_exists($target.'/_define.php.bak')) { rename($target.'/_define.php.bak', $target.'/_define.php'); } throw new Exception(sprintf(__('Unable to read new _define.php file'))); } */ } $zip->unzipAll($target); $zip->close(); unlink($zip_file); return $ret_code; }
/** Extract zip file in current location @param f <b>fileRecord</b> fileRecord object */ public function inflateZipFile($f, $create_dir = true) { $zip = new fileUnzip($f->file); $zip->getList(false, '#(^|/)(__MACOSX|\\.svn|\\.DS_Store|Thumbs\\.db)(/|$)#'); if ($create_dir) { $zip_root_dir = $zip->getRootDir(); if ($zip_root_dir != false) { $destination = $zip_root_dir; $target = $f->dir; } else { $destination = preg_replace('/\\.([^.]+)$/', '', $f->basename); $target = $f->dir . '/' . $destination; } if (is_dir($f->dir . '/' . $destination)) { throw new Exception(sprintf(__('Extract destination directory %s already exists.'), dirname($f->relname) . '/' . $destination)); } } else { $target = $f->dir; $destination = ''; } $zip->unzipAll($target); $zip->close(); return dirname($f->relname) . '/' . $destination; }
} else { $default_tab = 'update'; } # Revert or delete backup file if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'], $archives)) { $b_file = $_POST['backup_file']; try { if (!empty($_POST['b_del'])) { if (!@unlink(DC_BACKUP_PATH . '/' . $b_file)) { throw new Exception(sprintf(__('Unable to delete file %s'), html::escapeHTML($b_file))); } http::redirect($p_url . '?tab=files'); } if (!empty($_POST['b_revert'])) { $zip = new fileUnzip(DC_BACKUP_PATH . '/' . $b_file); $zip->unzipAll(DC_BACKUP_PATH . '/'); @unlink(DC_BACKUP_PATH . '/' . $b_file); http::redirect($p_url . '?tab=files'); } } catch (Exception $e) { $core->error->add($e->getMessage()); } } # Upgrade process if ($new_v && $step) { try { $updater->setForcedFiles('inc/digests'); switch ($step) { case 'check': $updater->checkIntegrity(DC_ROOT . '/inc/digests', DC_ROOT); http::redirect($p_url . '?step=download');
private static function installLocalWidget($categoryId, $userId, $uploadedFilePath) { try { $unziper = new fileUnzip($uploadedFilePath); $archiveContent = $unziper->getFilesList(); $tempFolder = './widgets/' . mktime(); $alreadyInstalled = false; if (!self::isFileInArchive($archiveContent, 'config.xml')) { throw new FileException(MwwException::MODEL, 'Unable to find config.xml in the provided archive'); } else { if (!self::isFileInArchive($archiveContent, 'index.html') && !self::isFileInArchive($archiveContent, 'index.xul')) { throw new FileException(MwwException::MODEL, 'Unable to find index.html in the provided archive'); } else { // The mandatory files are in the archive. // We unzip the document in the widget repository under an arbitrary folder. $unziper->unzipAll($tempFolder); $unziper->close(); // parse the manifest. $manifestPath = $tempFolder . '/config.xml'; $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; if (!@$doc->load($manifestPath)) { throw new XMLParsingException(MwwException::MODEL, 'Unable to parse XML file. Document not well formed.'); } // validate the manifest. if (!@$doc->schemaValidate('./schema/manifest.xsd')) { throw new XMLValidationException(MwwException::MODEL, "The XML File isn't valid according to the XML Schema."); } // test if the id is unique (test if the directory exists). $id = $doc->getElementsByTagName('widget')->item(0)->getAttribute('id'); // getting name/title of the widget. if ($doc->getElementsByTagName('name')->length) { $name = $doc->getElementsByTagName('name')->item(0)->nodeValue; } else { if ($doc->getElementsByTagName('title')->length) { $name = $doc->getElementsByTagName('title')->item(0)->nodeValue; } else { throw new XMLValidationException(MwwException::MODEL, "The XML File is not valid. The mandatory title or name element is missing."); } } // getting widget description. $description = null; if ($doc->getElementsByTagName('description')->length) { $description = $doc->getElementsByTagName('description')->item(0)->nodeValue; } // is widget authentication enabled or disabled ? $widgetAuth = false; $authKey = null; if ($doc->getElementsByTagName('widget_authentication')->length) { $authValue = $doc->getElementsByTagName('widget_authentication')->item(0)->nodeValue; if ($authValue == 'enabled') { $widgetAuth = true; // create the key. $crypto = new Rijndael(); $authKey = $crypto->generateKey(); } } $targetFolder = './widgets/' . $id; if (file_exists($targetFolder)) { $alreadyInstalled = true; throw new FileException(MwwException::MODEL, 'A widget with the id \'' . $id . '\' already exists.'); } // create the widget directory (actually we simply rename the temporary directory). if (!@rename($tempFolder, $targetFolder)) { throw new FileException(MwwException::MODEL, 'The widget directory could not be created'); } $nameToReturn = $name; // -- Persistant data access section. $db = DbUtil::accessFactory(); $categoryId = $categoryId != 0 ? $db->escape($categoryId) : 'NULL'; $userId = $db->escape($userId); $name = $db->escape($name); $description = $db->escape($description); $generatedKey = $widgetAuth ? "'{$authKey}'" : 'NULL'; // insert the widget into the database. if (!$db->execute("INSERT INTO `widgets` (`widgetid`, `widgetname`, `visible`, `copname`, `category`, `description`, `authkey`) VALUES ('{$id}', '{$name}', 0, (SELECT `copname` FROM `users` WHERE `id`= {$userId}), {$categoryId}, '{$description}', {$generatedKey})")) { throw new DBException(MwwException::MODEL, "Unable to insert new widget '{$id}' information in persistant data"); } // -- End of Persistant data access section. // End of the installation. Everything was fine. return $nameToReturn; } } } catch (Exception $ex) { if (isset($tempFolder) && is_dir($tempFolder)) { Util::full_rmdir($tempFolder); } if (isset($targetFolder) && is_dir($targetFolder) && !$alreadyInstalled) { Util::full_rmdir($targetFolder); } throw $ex; } }
$sTargetDir = dirname($sZipFilename) . '/' . $zip_root_dir; $sDestinationDir = $sTargetDir; $sCssFilename = $zip_root_dir . '/css/custom-theme/' . basename($sTargetDir) . '.css'; $hasCssFile = $oZip->hasFile($sCssFilename); } if ($oZip->isEmpty()) { $oZip->close(); files::deltree($sTempDir); throw new Exception(__('c_a_config_display_empty_zip_file')); } if (!$hasCssFile) { $oZip->close(); files::deltree($sTempDir); throw new Exception(__('c_a_config_display_not_valid_theme')); } $oZip->unzipAll($sTempDir); $oZip->close(); debug($sTempDir); $sFinalPath = OKT_PUBLIC_PATH . '/ui-themes/custom'; util::rcopy($sTempDir . $zip_root_dir . '/css/custom-theme', $sFinalPath); rename($sFinalPath . '/' . basename($sTargetDir) . '.css', $sFinalPath . '/jquery-ui.css'); rename($sFinalPath . '/' . basename($sTargetDir) . '.min.css', $sFinalPath . '/jquery-ui.min.css'); files::deltree($sTempDir); $_POST['p_admin_theme'] = 'custom'; } catch (Exception $e) { files::deltree($sTempDir); $okt->error->set($e->getMessage()); } } # enregistrement de la configuration $p_public_theme = !empty($_POST['p_public_theme']) ? $_POST['p_public_theme'] : 'base';
public static function installPackage($zip_file, dcModules &$modules) { $zip = new fileUnzip($zip_file); $zip->getList(false, '#(^|/)(__MACOSX|\\.svn|\\.DS_Store|Thumbs\\.db)(/|$)#'); $zip_root_dir = $zip->getRootDir(); $define = ''; if ($zip_root_dir != false) { $target = dirname($zip_file); $destination = $target . '/' . $zip_root_dir; $define = $zip_root_dir . '/_define.php'; $has_define = $zip->hasFile($define); } else { $target = dirname($zip_file) . '/' . preg_replace('/\\.([^.]+)$/', '', basename($zip_file)); $destination = $target; $define = '_define.php'; $has_define = $zip->hasFile($define); } if ($zip->isEmpty()) { unlink($zip_file); throw new Exception(T_('Empty module zip file.')); } if (!$has_define) { unlink($zip_file); throw new Exception(T_('The zip file does not appear to be a valid Bilboplanet module.')); } $ret_code = 1; if (is_dir($destination)) { # test for update $sandbox = clone $modules; $zip->unzip($define, $target . '/_define.php'); $sandbox->resetModulesList(); $sandbox->requireDefine($target, basename($destination)); unlink($target . '/_define.php'); $new_modules = $sandbox->getModules(); if (!empty($new_modules)) { $tmp = array_keys($new_modules); $id = $tmp[0]; $cur_module = $modules->getModules($id); if (!empty($cur_module) && $new_modules[$id]['version'] != $cur_module['version']) { # delete old module if (!files::deltree($destination)) { throw new Exception(T_('An error occurred during module deletion.')); } $ret_code = 2; } else { unlink($zip_file); throw new Exception(sprintf(T_('Unable to upgrade "%s". (same version)'), basename($destination))); } } else { unlink($zip_file); throw new Exception(sprintf(T_('Unable to read new _define.php file'))); } } $zip->unzipAll($target); unlink($zip_file); return $ret_code; }
public function install() { global $core; $zip = new fileUnzip($this->zip_file); if ($zip->isEmpty()) { $zip->close(); unlink($this->zip_file); throw new Exception(__('Empty plugin zip file.')); } $zip_root_dir = $zip->getRootDir(); if (!$zip_root_dir) { // try to find a root anyway if all dirs start with same pattern $dirs = $zip->getDirsList(); $n = 0; $zip_root_dir = substr($dirs[0], 0, strpos($dirs[0], '/')); foreach ($dirs as $dir) { if ($zip_root_dir != substr($dirs[0], 0, strpos($dirs[0], '/'))) { $n++; } } if ($n > 0) { $zip_root_dir = false; } } if ($zip_root_dir != false) { $target = dirname($this->zip_file); $destination = $target . '/' . $zip_root_dir; $plugin_js = $zip_root_dir . '/plugin.js'; $has_plugin_js = $zip->hasFile($plugin_js); } else { $target = dirname($this->zip_file) . '/' . preg_replace('/\\.([^.]+)$/', '', basename($this->zip_file)); $destination = $target; $plugin_js = 'plugin.js'; $has_plugin_js = $zip->hasFile($plugin_js); } if ($core->blog->settings->dcCKEditorAddons->check_validity) { if (!$has_plugin_js) { $zip->close(); unlink($this->zip_file); throw new Exception(__('The zip file does not appear to be a valid CKEditor addon.')); } } if (!is_dir($destination)) { files::makeDir($destination, true); } $zip->unzipAll($target); $zip->close(); unlink($this->zip_file); }
$archives[] = $v; } } # Revert or delete backup file if (!empty($_POST['backup_file']) && in_array($_POST['backup_file'], $archives)) { $b_file = $_POST['backup_file']; try { if (!empty($_POST['b_del'])) { if (!@unlink(OKT_BACKUP_PATH . '/' . $b_file)) { throw new Exception(sprintf(__('c_a_update_unable_delete_file_%s'), html::escapeHTML($b_file))); } http::redirect($p_url); } if (!empty($_POST['b_revert'])) { $zip = new fileUnzip(OKT_BACKUP_PATH . '/' . $b_file); $zip->unzipAll(OKT_BACKUP_PATH . '/'); @unlink(OKT_BACKUP_PATH . '/' . $b_file); http::redirect($p_url); } } catch (Exception $e) { $okt->error->set($e->getMessage()); } } # Upgrade process if ($digest_is_readable && $new_v && $step) { try { $updater->setForcedFiles('oktInc/digests'); # check integrity if (empty($_GET['do_not_check'])) { $updater->checkIntegrity(OKT_ROOT_PATH . '/oktInc/digests', OKT_ROOT_PATH); }