private static function removeMarkedSectionHelper($strPluginName, $strFileName)
 {
     $oldContents = QFile::readFile($strFileName);
     $search = str_replace("\r\n", "", self::getBeginMarker($strPluginName) . ".*" . self::getEndMarker($strPluginName));
     $intReplacementCount = 0;
     $newContents = preg_replace('|' . $search . '|s', '', $oldContents, -1, $intReplacementCount);
     $newContents = self::stripExtraNewlines($newContents);
     QFile::writeFile($strFileName, $newContents);
     return $intReplacementCount;
 }
Exemplo n.º 2
0
 /**
  * Extract a ZIP compressed file to a given path
  * @param       string  $archive        Path to ZIP archive to extract
  * @param       string  $destination    Path to extract archive into
  * @return      boolean True if successful
  */
 public static function extractZip($archive, $destination)
 {
     if (!function_exists('zip_open')) {
         throw new Exception("ZIP extension is not enabled on this installation of PHP. Recompile your installation of PHP with --enable-zip parameter.");
     }
     //		echo "Extracting archive " . $archive . " to " . $destination. "<br>";
     $zip = zip_open($archive);
     if (is_resource($zip)) {
         // Create the destination folder
         if (!mkdir($destination)) {
             self::$strLastError = "Unable to create extraction destination folder " . $destination;
             return false;
         }
         // Read files in the archive
         $createdFolders = array();
         while ($file = zip_read($zip)) {
             if (is_resource($file)) {
                 if (zip_entry_open($zip, $file, "r")) {
                     if (substr(zip_entry_name($file), strlen(zip_entry_name($file)) - 1) != "/") {
                         //							echo zip_entry_name($file) . "<br>";
                         $folderStack = explode("/", zip_entry_name($file));
                         if (sizeof($folderStack) > 1) {
                             for ($i = 0; $i < sizeof($folderStack) - 1; $i++) {
                                 $arraySubsection = array_slice($folderStack, 0, $i + 1);
                                 $item = implode("/", $arraySubsection);
                                 if (!in_array($item, $createdFolders)) {
                                     //										echo "- Creating folder: " . $destination . $item . "<br>";
                                     $createdFolders[] = $item;
                                     mkdir($destination . $item);
                                 }
                             }
                         }
                         $strSectionToAppend = zip_entry_read($file, zip_entry_filesize($file));
                         $strSavePath = $destination . zip_entry_name($file);
                         QFile::writeFile($strSavePath, $strSectionToAppend);
                         zip_entry_close($file);
                     }
                 } else {
                     self::$strLastError = "Unable to read zip entry";
                     return false;
                 }
             } else {
                 self::$strLastError = self::zipFileErrMsg($file);
                 return false;
             }
         }
         zip_close($zip);
     } else {
         self::$strLastError = self::zipFileErrMsg($zip);
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 public function install()
 {
     if (!$this->validate()) {
         throw new QCallerException("The plugin doesn't validate: \r\n" . $this->validationError);
     }
     $pluginConfigXml = $this->toXml();
     $savePath = $this->strTemporaryExpandedPath . QPluginInstaller::PLUGIN_CONFIG_FILE;
     QFile::writeFile($savePath, $pluginConfigXml);
 }
 protected static function replaceFileSection($strFilePath, $strSearch, $strReplace)
 {
     $contents = QFile::readFile($strFilePath);
     $contents = str_replace($strSearch, $strReplace, $contents);
     QFile::writeFile($strFilePath, self::stripExtraNewlines($contents));
 }