/**
  * Parse an addon's README file.
  *
  * @param string $Path The base path to search from.
  * @return string
  */
 protected function parseReadme($Path)
 {
     $ReadmePaths = array('/readme', '/README', '/readme.md', '/README.md', '/readme.txt', '/README.txt');
     $Description = '';
     // Get the list of potential files to analyze.
     $Entries = UpdateModel::findFiles($Path, $ReadmePaths);
     if ($Entries === false) {
         return '';
     }
     foreach ($Entries as $Entry) {
         $ReadMeContents = file_get_contents($Entry['Path']);
         $Description = Gdn_Format::markdown($ReadMeContents);
     }
     $FolderPath = substr($Path, 0, -4);
     Gdn_FileSystem::removeFolder($FolderPath);
     return $Description;
 }
Exemple #2
0
 /**
  * Open a zip archive and inspect its contents for the requested paths.
  *
  * @param $Path
  * @param $InfoPaths
  * @param bool $TmpPath
  * @param bool $ThrowError
  * @return array|bool
  * @throws Exception
  */
 protected static function _getInfoZip($Path, $InfoPaths, $TmpPath = false, $ThrowError = true)
 {
     // Extract the zip file so we can make sure it has appropriate information.
     $Zip = null;
     if (class_exists('ZipArchive', false)) {
         $Zip = new ZipArchive();
         $ZipOpened = $Zip->open($Path);
         if ($ZipOpened !== true) {
             $Zip = null;
         }
     }
     if (!$Zip) {
         require_once PATH_LIBRARY . "/vendors/pclzip/class.pclzipadapter.php";
         $Zip = new PclZipAdapter();
         $ZipOpened = $Zip->open($Path);
     }
     if ($ZipOpened !== true) {
         if ($ThrowError) {
             $Errors = array(ZIPARCHIVE::ER_EXISTS => 'ER_EXISTS', ZIPARCHIVE::ER_INCONS => 'ER_INCONS', ZIPARCHIVE::ER_INVAL => 'ER_INVAL', ZIPARCHIVE::ER_MEMORY => 'ER_MEMORY', ZIPARCHIVE::ER_NOENT => 'ER_NOENT', ZIPARCHIVE::ER_NOZIP => 'ER_NOZIP', ZIPARCHIVE::ER_OPEN => 'ER_OPEN', ZIPARCHIVE::ER_READ => 'ER_READ', ZIPARCHIVE::ER_SEEK => 'ER_SEEK');
             throw new Exception(t('Could not open addon file. Addons must be zip files.') . ' (' . $Path . ' ' . val($ZipOpened, $Errors, 'Unknown Error') . ')', 400);
         }
         return false;
     }
     if ($TmpPath === false) {
         $TmpPath = dirname($Path) . '/' . basename($Path, '.zip') . '/';
     }
     if (file_exists($TmpPath)) {
         Gdn_FileSystem::removeFolder($TmpPath);
     }
     $Result = [];
     for ($i = 0; $i < $Zip->numFiles; $i++) {
         $Entry = $Zip->statIndex($i);
         if (preg_match('#(\\.\\.[\\/])#', $Entry['name'])) {
             throw new Gdn_UserException("Invalid path in zip file: " . htmlspecialchars($Entry['name']));
         }
         $Name = '/' . ltrim($Entry['name'], '/');
         foreach ($InfoPaths as $InfoPath) {
             $Preg = '`(' . str_replace(array('.', '*'), array('\\.', '.*'), $InfoPath) . ')$`';
             if (preg_match($Preg, $Name, $Matches)) {
                 $Base = trim(substr($Name, 0, -strlen($Matches[1])), '/');
                 if (strpos($Base, '/') !== false) {
                     continue;
                     // file nested too deep.
                 }
                 if (!file_exists($TmpPath)) {
                     mkdir($TmpPath, 0777, true);
                 }
                 $Zip->extractTo($TmpPath, $Entry['name']);
                 $Result[] = array('Name' => $Matches[1], 'Path' => $TmpPath . rtrim($Entry['name'], '/'), 'Base' => $Base);
             }
         }
     }
     return $Result;
 }
Exemple #3
0
 /**
  *
  */
 public function flush()
 {
     foreach ($this->containers as &$Container) {
         $CacheLocation = $Container[Gdn_Filecache::CONTAINER_LOCATION];
         if (is_dir($CacheLocation)) {
             Gdn_FileSystem::removeFolder($CacheLocation);
             @mkdir($CacheLocation, 0755, true);
         }
     }
 }