/** * Tim Hodson: renamed functions to avoid collisions. * * Extract plugin headers and readme.txt data from a plugin's ZIP archive. * * Returns an associative array with these keys: * 'headers' - An array of plugin headers. See get_plugin_data() for details. * 'readme' - An array of metadata extracted from readme.txt. See parsePluginReadme() for details. * 'pluginFile' - The name of the PHP file where the plugin headers were found; relative to the root directory of the ZIP archive. * * The 'readme' key will only be present if the input archive contains a readme.txt file * formatted according to WordPress.org readme standards. * * @uses parsePluginReadme() * @uses get_plugin_data() * * @param string $packageFilename The path to the plugin's ZIP package. * @param bool $applyMarkdown Whether to transform markup used in readme.txt to HTML. Defaults to false. * @return array Associative array containing 'headers', 'readme' and 'pluginFile'. Returns FALSE if the input file is not a valid ZIP archive or doesn't contain a WP plugin. */ function pm_analysePluginPackage($packageFilename, $applyMarkdown = false) { if (!file_exists($packageFilename) || !is_readable($packageFilename)) { return false; } //Open the .zip $zip = new ZipArchive(); if ($zip->open($packageFilename) !== true) { return false; } //Find and parse the plugin file and readme.txt $header = null; $readme = null; $pluginFile = null; for ($fileIndex = 0; $fileIndex < $zip->numFiles && (empty($readme) || empty($header)); $fileIndex++) { $info = $zip->statIndex($fileIndex); $fileName = trim(str_replace('\\', '/', $info['name']), '/'); //Backslashes to slashes, kill leading slashes. //readme.txt? if (empty($readme) && strtolower(basename($fileName)) == 'readme.txt') { //Try to parse the readme $readme = pm_parsePluginReadme($zip->getFromIndex($fileIndex), $applyMarkdown); continue; //Skip the rest of the checks. } //Plugin header? if (empty($header)) { //Skip directories and empty files if ($info['size'] == 0) { continue; } //We're only interested in PHP files $extension = end(explode('.', $fileName)); if (strtolower($extension) != 'php') { continue; } //WordPress only looks for plugin files in the top or second level //of the directory tree, so we do the same. if (substr_count($fileName, '/') > 1) { continue; } //Try to read the header. WP only scans the first 8kiB, so we do the same. $fileContents = substr($zip->getFromIndex($fileIndex), 0, 8 * 1024); $header = pm_getPluginHeader($fileContents); if (!empty($header)) { $pluginFile = $fileName; } } } if (empty($pluginFile)) { return false; } else { return compact('header', 'readme', 'pluginFile'); } }
function bib_get_help() { echo "<h3>Help!</h3>"; $rt = file_get_contents(WP_PLUGIN_DIR . '/blog-in-blog/readme.txt'); $rc = pm_parsePluginReadme($rt, true); if (is_array($rc['sections'])) { foreach ($rc['sections'] as $section) { echo $section; } } }