コード例 #1
0
ファイル: class.dc.modules.php プロジェクト: nikrou/dotclear
 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;
 }
コード例 #2
0
ファイル: langs.php プロジェクト: HackerMajor/root
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;
}
コード例 #3
0
ファイル: class.oktThemes.php プロジェクト: jewelhuq/okatea
 /**
  * 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;
 }
コード例 #4
0
ファイル: add_zip.php プロジェクト: jewelhuq/okatea
 }
 if (pathinfo($_FILES['p_zip_file']['name'], PATHINFO_EXTENSION) != 'zip') {
     throw new Exception(__('m_galleries_zip_error_must_zip_file') . ' (not zip extension)');
 }
 //	if ($_FILES['p_zip_file']['type'] != 'application/zip' && $_FILES['p_zip_file']['type'] != 'application/x-zip-compressed') {
 //	if (strpos($_FILES['p_zip_file']['type'], 'zip') === false) {
 //		throw new Exception(__('m_galleries_zip_error_must_zip_file').' (not zip type : '.$_FILES['p_zip_file']['type'].')');
 //	}
 $sTempDir = $okt->galleries->upload_dir . '/temp/';
 files::makeDir($sTempDir, true);
 $sZipFile = $sTempDir . $_FILES['p_zip_file']['name'];
 if (!move_uploaded_file($_FILES['p_zip_file']['tmp_name'], $sZipFile)) {
     throw new Exception(__('m_galleries_zip_error_unable_move_uploaded_file'));
 }
 $oZip = new fileUnzip($sZipFile);
 foreach ($oZip->getList() as $sFileName => $aFileInfos) {
     $sFileExtension = pathinfo($sFileName, PATHINFO_EXTENSION);
     if ($aFileInfos['is_dir'] || !in_array(strtolower($sFileExtension), array('jpg', 'gif', 'png'))) {
         continue;
     }
     $iItemId = $okt->galleries->items->addItem($okt->galleries->items->openItemCursor(array('gallery_id' => $iGalleryId, 'active' => 1)), $aItemLocalesData);
     $sDestination = $okt->galleries->upload_dir . '/img/items/' . $iItemId . '/1.' . $sFileExtension;
     files::makeDir(dirname($sDestination), true);
     $oZip->unzip($sFileName, $sDestination);
     $aNewImagesInfos = $okt->galleries->items->getImageUploadInstance()->buildImagesInfos($iItemId, array(1 => basename($sDestination)));
     if (isset($aNewImagesInfos[1])) {
         $aNewItemImages = $aNewImagesInfos[1];
         $aNewItemImages['original_name'] = utf8_encode(basename($sFileName));
     } else {
         $aNewItemImages = array();
     }
コード例 #5
0
ファイル: class.dc.media.php プロジェクト: HackerMajor/root
 /**
 Returns zip file content
 
 @param	f		<b>fileRecord</b>	fileRecord object
 @return <b>array</b>
 */
 public function getZipContent($f)
 {
     $zip = new fileUnzip($f->file);
     $list = $zip->getList(false, '#(^|/)(__MACOSX|\\.svn|\\.DS_Store|Thumbs\\.db)(/|$)#');
     $zip->close();
     return $list;
 }
コード例 #6
0
ファイル: display.php プロジェクト: jewelhuq/okatea
     files::deltree($sTempDir);
 }
 $sExtension = pathinfo($sUploadedFile['name'], PATHINFO_EXTENSION);
 # des erreurs d'upload ?
 util::uploadStatus($sUploadedFile);
 # vérification de l'extension
 if ($sExtension != 'zip') {
     throw new Exception(__('c_a_config_display_not_zip_file'));
 }
 # création répertoire temporaire
 files::makeDir($sTempDir);
 if (!move_uploaded_file($sUploadedFile['tmp_name'], $sZipFilename)) {
     throw new Exception(__('c_a_config_display_unable_move_file'));
 }
 $oZip = new fileUnzip($sZipFilename);
 $oZip->getList(false, '#(^|/)(__MACOSX|\\.svn|\\.DS_Store|Thumbs\\.db|development-bundle|js)(/|$)#');
 $zip_root_dir = $oZip->getRootDir();
 if ($zip_root_dir !== false) {
     $sTargetDir = dirname($sZipFilename);
     $sDestinationDir = $sTargetDir . '/' . $zip_root_dir;
     $sCssFilename = $zip_root_dir . '/css/custom-theme/' . basename($sTargetDir) . '.css';
     $hasCssFile = $oZip->hasFile($sCssFilename);
 } else {
     $zip_root_dir = preg_replace('/\\.([^.]+)$/', '', basename($sZipFilename));
     $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();
コード例 #7
0
 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;
 }