예제 #1
0
 /**
  * Import a module given the zip file path. Importing a module means inserting it in
  * the database and copying its folder to modules folder. If a module with the same
  * name already exists, the function will append a number to the module name. You must 
  * have either php ZipArchive extension or unzip program installed.
  *
  * @param string $zipFilePath the full path of the zip file
  * @param string $moduleName the module name, if this value if false, the function will
  * 							use the zip filename as the module name. The default value is false
  * @return the module id, or false in case of error.
  */
 function Import($zipFilePath, $moduleName = false)
 {
     include_once 'RCCWP_CustomGroup.php';
     include_once 'RCCWP_CustomField.php';
     include_once 'RCCWP_CustomWritePanel.php';
     include_once 'RCCWP_Application.php';
     include_once 'RCCWP_CustomWritePanel.php';
     global $flutter_domain;
     if (!strpos($zipFilePath, ".zip")) {
         return false;
     }
     if (!$moduleName) {
         //use zip filename
         $moduleName = basename($zipFilePath, ".zip");
     }
     if ($moduleName == '') {
         return false;
     }
     // Append a number if the module already exists,
     $i = 1;
     $newModuleName = $moduleName;
     while (file_exists(FLUTTER_MODULES_DIR . $newModuleName)) {
         $newModuleName = $moduleName . "_" . $i++;
     }
     $moduleName = $newModuleName;
     mkdir(FLUTTER_MODULES_DIR . $moduleName);
     chmod(FLUTTER_MODULES_DIR . $moduleName, 0777);
     $destPath = FLUTTER_MODULES_DIR . $moduleName . DIRECTORY_SEPARATOR;
     if (class_exists('ZipArchive')) {
         $zip = new ZipArchive();
         // open archive
         if ($zip->open($zipFilePath) !== TRUE) {
             die(__('Could not open archive', $flutter_domain));
         }
         // extract contents to destination directory
         $zip->extractTo($destPath);
         // close archive
         $zip->close();
     } else {
         if (RCCWP_Application::CheckDecompressionProgramUnzip()) {
             $command = "unzip {$zipFilePath} -d " . $destPath;
         } else {
             die(__('Cannot find unzip program!', $flutter_domain));
         }
         exec($command, $out, $err);
     }
     $moduleInfo_imported_data = unserialize(file_get_contents($destPath . 'module_info.exp'));
     //Import module
     $moduleID = RCCWP_CustomWriteModule::Create($moduleName, $moduleInfo_imported_data['moduleinfo']->description, false);
     //Import any panels
     if ($handle = @opendir($destPath)) {
         while (false !== ($file = readdir($handle))) {
             if (substr($file, 0, 1) == "_") {
                 $panelName = basename(substr($file, 1), ".pnl");
                 RCCWP_CustomWritePanel::Import($destPath . $file, $panelName);
             }
         }
     }
     //Create Duplicates
     foreach ($moduleInfo_imported_data['duplicates'] as $moduleDuplicate) {
         RCCWP_ModuleDuplicate::Create($moduleID, $moduleDuplicate->duplicate_name);
     }
     return $moduleID;
 }