/** * Load and parse a plugin manifest from a plugin XML file. * * @example plugins/manifest.xml Example 1.8-style manifest file. * * @deprecated 1.8 Use ElggPlugin->getManifest() * * @param string $plugin Plugin name. * @return array of values */ function load_plugin_manifest($plugin) { elgg_deprecated_notice('load_plugin_manifest() is deprecated by ElggPlugin->getManifest()', 1.8); $xml_file = elgg_get_plugins_path() . "{$plugin}/manifest.xml"; try { $manifest = new ElggPluginManifest($xml_file, $plugin); } catch (Exception $e) { return false; } return $manifest->getManifest(); }
function guessName($release, &$type) { $filestorePath = $release->getFilenameOnFilestore(); $filename = $release->originalfilename; // var_dump($filename, $filestorePath); $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if ($extension == 'gz') { if (strtolower(pathinfo(substr($filename, 0, strlen($filename) - 3), PATHINFO_EXTENSION)) == 'tar') { $extension = 'tar.gz'; } } if (!in_array($extension, array('zip', 'tar.gz'))) { // var_dump('BAD ext: ' . $extension); return false; } $resultId = false; $resultDir = false; /* * guess package name */ if ($extension == 'zip') { $type = 'zip'; $zip = new ZipArchive(); if ($errorCode = $zip->open($filestorePath)) { $manifestsCnt = 0; $dirname = null; for ($i = 0; $i < $zip->numFiles; $i++) { $stat = $zip->statIndex($i); if (basename($stat['name']) == 'manifest.xml') { $dirname = trim(pathinfo($stat['name'], PATHINFO_DIRNAME), '/\\'); if (!empty($dirname) && $dirname !== '.' && strpos($dirname, '/') === false && strpos($dirname, '\\') === false) { $resultDir = $dirname; if (preg_match('#^([^\\-]+)\\-(.+)\\-([0-9a-fA-F]{7}|master)$#', $resultDir, $matches)) { $resultDir = $matches[2]; } elseif (strpos($resultDir, '-' . $release->version) === strlen($resultDir) - strlen('-' . $release->version)) { // cut away version appended by git $resultDir = substr($resultDir, 0, strlen($resultDir) - strlen('-' . $release->version)); } $manifestsCnt++; $stream = $zip->getStream($stat['name']); if (is_resource($stream)) { $content = stream_get_contents($stream); try { $manifest = new ElggPluginManifest($content); $manifestArr = $manifest->getManifest(); if (isset($manifestArr['id'])) { $resultId = $manifestArr['id']; } } catch (Exception $e) { } } } } } if ($manifestsCnt == 1) { if ($resultId) { return $resultId; } else { return $resultDir; } } else { return false; //no manifests or too many manifests in proper nesting } } else { var_dump('ERROR:', $errorCode); return false; // cant open archive } } else { // tar.gz $type = 'tar'; try { $tar = new PharData($filestorePath); } catch (UnexpectedValueException $e) { return false; } $tarIterator = new RecursiveIteratorIterator($tar); $prefix = 'phar://' . $filestorePath . '/'; $manifestsCnt = 0; $dirname = null; $tarIterator->rewind(); /** * @var $file PharFileInfo */ // foreach ($tarIterator as $key => $file) { while ($tarIterator->valid()) { try { $file = $tarIterator->current(); } catch (RuntimeException $e) { $tarIterator->next(); continue; } $path = substr($file->getPathname(), strlen($prefix)); if ($file->getFilename() == 'manifest.xml') { $dirname = trim(pathinfo($path, PATHINFO_DIRNAME), '/\\'); if (!empty($dirname) && $dirname !== '.' && strpos($dirname, '/') === false && strpos($dirname, '\\') === false) { $resultDir = $dirname; if (preg_match('#^([^\\-]+)\\-(.+)\\-([0-9a-fA-F]{7}|master)$#', $resultDir, $matches)) { $resultDir = $matches[2]; } elseif (strpos($resultDir, '-' . $release->version) === strlen($resultDir) - strlen('-' . $release->version)) { // cut away version appended by git $resultDir = substr($resultDir, 0, strlen($resultDir) - strlen('-' . $release->version)); } $manifestsCnt++; $content = $file->getContent(); try { $manifest = new ElggPluginManifest($content); $manifestArr = $manifest->getManifest(); if (isset($manifestArr['id'])) { $resultId = $manifestArr['id']; } } catch (Exception $e) { } } } $tarIterator->next(); } if ($manifestsCnt == 1) { if ($resultId) { return $resultId; } else { return $resultDir; } } else { return false; //no manifests or too many manifests in proper nesting } return false; } }