本文整理汇总了PHP中read_tgz_file函数的典型用法代码示例。如果您正苦于以下问题:PHP read_tgz_file函数的具体用法?PHP read_tgz_file怎么用?PHP read_tgz_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_tgz_file函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: InstallSmileySet
function InstallSmileySet()
{
global $sourcedir, $boarddir, $modSettings;
isAllowedTo('manage_smileys');
checkSession('request');
require_once $sourcedir . '/Subs-Package.php';
$name = strtok(basename(isset($_FILES['set_gz']) ? $_FILES['set_gz']['name'] : $_REQUEST['set_gz']), '.');
$name = preg_replace(array('/\\s/', '/\\.[\\.]+/', '/[^\\w_\\.\\-]/'), array('_', '.', ''), $name);
// !!! Decide: overwrite or not?
if (isset($_FILES['set_gz']) && is_uploaded_file($_FILES['set_gz']['tmp_name']) && (@ini_get('open_basedir') != '' || file_exists($_FILES['set_gz']['tmp_name']))) {
$extracted = read_tgz_file($_FILES['set_gz']['tmp_name'], $boarddir . '/Smileys/' . $name);
} elseif (isset($_REQUEST['set_gz'])) {
checkSession('request');
// Check that the theme is from simplemachines.org, for now... maybe add mirroring later.
if (preg_match('~^http://[\\w_\\-]+\\.simplemachines\\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) {
fatal_lang_error('not_on_simplemachines');
}
$extracted = read_tgz_file($_REQUEST['set_gz'], $boarddir . '/Smileys/' . $name);
} else {
redirectexit('action=smileys');
}
updateSettings(array('smiley_sets_known' => addslashes($modSettings['smiley_sets_known'] . ',' . $name), 'smiley_sets_names' => addslashes($modSettings['smiley_sets_names'] . "\n" . strtok(basename(isset($_FILES['set_gz']) ? $_FILES['set_gz']['name'] : $_REQUEST['set_gz']), '.'))));
cache_put_data('parsing_smileys', null, 480);
cache_put_data('posting_smileys', null, 480);
// !!! Add some confirmation?
redirectexit('action=smileys');
}
示例2: DownloadLanguage
function DownloadLanguage()
{
global $context, $sourcedir, $forum_version, $boarddir, $txt, $smcFunc, $scripturl, $modSettings;
loadLanguage('ManageSettings');
require_once $sourcedir . '/Subs-Package.php';
// Clearly we need to know what to request.
if (!isset($_GET['did'])) {
fatal_lang_error('no_access', false);
}
// Some lovely context.
$context['download_id'] = $_GET['did'];
$context['sub_template'] = 'download_language';
$context['menu_data_' . $context['admin_menu_id']]['current_subsection'] = 'add';
// Can we actually do the installation - and do they want to?
if (!empty($_POST['do_install']) && !empty($_POST['copy_file'])) {
checkSession('get');
$chmod_files = array();
$install_files = array();
// Check writable status.
foreach ($_POST['copy_file'] as $file) {
// Check it's not very bad.
if (strpos($file, '..') !== false || substr($file, 0, 6) != 'Themes' && !preg_match('~agreement\\.[A-Za-z-_0-9]+\\.txt$~', $file)) {
fatal_error($txt['languages_download_illegal_paths']);
}
$chmod_files[] = $boarddir . '/' . $file;
$install_files[] = $file;
}
// Call this in case we have work to do.
$file_status = create_chmod_control($chmod_files);
$files_left = $file_status['files']['notwritable'];
// Something not writable?
if (!empty($files_left)) {
$context['error_message'] = $txt['languages_download_not_chmod'];
} elseif (!empty($install_files)) {
$archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), $boarddir, false, true, $install_files);
// Make sure the files aren't stuck in the cache.
package_flush_cache();
$context['install_complete'] = sprintf($txt['languages_download_complete_desc'], $scripturl . '?action=admin;area=languages');
return;
}
}
// Open up the old china.
if (!isset($archive_content)) {
$archive_content = read_tgz_file('http://download.simplemachines.org/fetch_language.php?version=' . urlencode(strtr($forum_version, array('SMF ' => ''))) . ';fetch=' . urlencode($_GET['did']), null);
}
if (empty($archive_content)) {
fatal_error($txt['add_language_error_no_response']);
}
// Now for each of the files, let's do some *stuff*
$context['files'] = array('lang' => array(), 'other' => array());
$context['make_writable'] = array();
foreach ($archive_content as $file) {
$dirname = dirname($file['filename']);
$filename = basename($file['filename']);
$extension = substr($filename, strrpos($filename, '.') + 1);
// Don't do anything with files we don't understand.
if (!in_array($extension, array('php', 'jpg', 'gif', 'jpeg', 'png', 'txt'))) {
continue;
}
// Basic data.
$context_data = array('name' => $filename, 'destination' => $boarddir . '/' . $file['filename'], 'generaldest' => $file['filename'], 'size' => $file['size'], 'writable' => false, 'default_copy' => true, 'exists' => false);
// Does the file exist, is it different and can we overwrite?
if (file_exists($boarddir . '/' . $file['filename'])) {
if (is_writable($boarddir . '/' . $file['filename'])) {
$context_data['writable'] = true;
}
// Finally, do we actually think the content has changed?
if ($file['size'] == filesize($boarddir . '/' . $file['filename']) && $file['md5'] == md5_file($boarddir . '/' . $file['filename'])) {
$context_data['exists'] = 'same';
$context_data['default_copy'] = false;
} elseif ($file['md5'] == md5(preg_replace("~[\r]?\n~", "\r\n", file_get_contents($boarddir . '/' . $file['filename'])))) {
$context_data['exists'] = 'same';
$context_data['default_copy'] = false;
} else {
$context_data['exists'] = 'different';
}
} else {
// Can we at least stick it in the directory...
if (is_writable($boarddir . '/' . $dirname)) {
$context_data['writable'] = true;
}
}
// I love PHP files, that's why I'm a developer and not an artistic type spending my time drinking absinth and living a life of sin...
if ($extension == 'php' && preg_match('~\\w+\\.\\w+(?:-utf8)?\\.php~', $filename)) {
$context_data += array('version' => '??', 'cur_version' => false, 'version_compare' => 'newer');
list($name, $language) = explode('.', $filename);
// Let's get the new version, I like versions, they tell me that I'm up to date.
if (preg_match('~\\s*Version:\\s+(.+?);\\s*' . preg_quote($name, '~') . '~i', $file['preview'], $match) == 1) {
$context_data['version'] = $match[1];
}
// Now does the old file exist - if so what is it's version?
if (file_exists($boarddir . '/' . $file['filename'])) {
// OK - what is the current version?
$fp = fopen($boarddir . '/' . $file['filename'], 'rb');
$header = fread($fp, 768);
fclose($fp);
// Find the version.
if (preg_match('~(?://|/\\*)\\s*Version:\\s+(.+?);\\s*' . preg_quote($name, '~') . '(?:[\\s]{2}|\\*/)~i', $header, $match) == 1) {
$context_data['cur_version'] = $match[1];
// How does this compare?
//.........这里部分代码省略.........
示例3: getPackageInfo
function getPackageInfo($gzfilename)
{
global $boarddir;
// Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.)
if (strpos($gzfilename, 'http://') !== false) {
$packageInfo = read_tgz_data(fetch_web_data($gzfilename, '', true), '*/package-info.xml', true);
} else {
if (!file_exists($boarddir . '/Packages/' . $gzfilename)) {
return 'package_get_error_not_found';
}
if (is_file($boarddir . '/Packages/' . $gzfilename)) {
$packageInfo = read_tgz_file($boarddir . '/Packages/' . $gzfilename, '*/package-info.xml', true);
} elseif (file_exists($boarddir . '/Packages/' . $gzfilename . '/package-info.xml')) {
$packageInfo = file_get_contents($boarddir . '/Packages/' . $gzfilename . '/package-info.xml');
} else {
return 'package_get_error_missing_xml';
}
}
// Nothing?
if (empty($packageInfo)) {
return 'package_get_error_is_zero';
}
// Parse package-info.xml into an xmlArray.
loadClassFile('Class-Package.php');
$packageInfo = new xmlArray($packageInfo);
// !!! Error message of some sort?
if (!$packageInfo->exists('package-info[0]')) {
return 'package_get_error_packageinfo_corrupt';
}
$packageInfo = $packageInfo->path('package-info[0]');
$package = $packageInfo->to_array();
$package['xml'] = $packageInfo;
$package['filename'] = $gzfilename;
if (!isset($package['type'])) {
$package['type'] = 'modification';
}
return $package;
}
示例4: ThemeInstall
//.........这里部分代码省略.........
<author name="Simple Machines">info@simplemachines.org</author>
<!-- Website... where to get updates and more information. -->
<website>http://www.simplemachines.org/</website>
<!-- Template layers to use, defaults to "html,body". -->
<layers>' . (empty($theme_layers) ? 'html,body' : $theme_layers) . '</layers>
<!-- Templates to load on startup. Default is "index". -->
<templates>' . (empty($theme_templates) ? 'index' : $theme_templates) . '</templates>
<!-- Base this theme off another? Default is blank, or no. It could be "default". -->
<based-on></based-on>
</theme-info>';
// Now write it.
$fp = @fopen($theme_dir . '/theme_info.xml', 'w+');
if ($fp) {
fwrite($fp, $xml_info);
fclose($fp);
}
} elseif (isset($_REQUEST['theme_dir']) && $method == 'path') {
if (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
fatal_lang_error('theme_install_error', false);
}
$theme_name = basename($_REQUEST['theme_dir']);
$theme_dir = $_REQUEST['theme_dir'];
} elseif ($method = 'upload') {
// Hopefully the themes directory is writable, or we might have a problem.
if (!is_writable($boarddir . '/Themes')) {
fatal_lang_error('theme_install_write_error', 'critical');
}
require_once $sourcedir . '/Subs-Package.php';
// Set the default settings...
$theme_name = strtok(basename(isset($_FILES['theme_gz']) ? $_FILES['theme_gz']['name'] : $_REQUEST['theme_gz']), '.');
$theme_name = preg_replace(array('/\\s/', '/\\.[\\.]+/', '/[^\\w_\\.\\-]/'), array('_', '.', ''), $theme_name);
$theme_dir = $boarddir . '/Themes/' . $theme_name;
if (isset($_FILES['theme_gz']) && is_uploaded_file($_FILES['theme_gz']['tmp_name']) && (@ini_get('open_basedir') != '' || file_exists($_FILES['theme_gz']['tmp_name']))) {
$extracted = read_tgz_file($_FILES['theme_gz']['tmp_name'], $boarddir . '/Themes/' . $theme_name, false, true);
} elseif (isset($_REQUEST['theme_gz'])) {
// Check that the theme is from simplemachines.org, for now... maybe add mirroring later.
if (preg_match('~^http://[\\w_\\-]+\\.simplemachines\\.org/~', $_REQUEST['theme_gz']) == 0 || strpos($_REQUEST['theme_gz'], 'dlattach') !== false) {
fatal_lang_error('not_on_simplemachines');
}
$extracted = read_tgz_file($_REQUEST['theme_gz'], $boarddir . '/Themes/' . $theme_name, false, true);
} else {
redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
}
}
// Something go wrong?
if ($theme_dir != '' && basename($theme_dir) != 'Themes') {
// Defaults.
$install_info = array('theme_url' => $boardurl . '/Themes/' . basename($theme_dir), 'images_url' => isset($images_url) ? $images_url : $boardurl . '/Themes/' . basename($theme_dir) . '/images', 'theme_dir' => $theme_dir, 'name' => $theme_name);
if (file_exists($theme_dir . '/theme_info.xml')) {
$theme_info = file_get_contents($theme_dir . '/theme_info.xml');
$xml_elements = array('name' => 'name', 'theme_layers' => 'layers', 'theme_templates' => 'templates', 'based_on' => 'based-on');
foreach ($xml_elements as $var => $name) {
if (preg_match('~<' . $name . '>(?:<!\\[CDATA\\[)?(.+?)(?:\\]\\]>)?</' . $name . '>~', $theme_info, $match) == 1) {
$install_info[$var] = $match[1];
}
}
if (preg_match('~<images>(?:<!\\[CDATA\\[)?(.+?)(?:\\]\\]>)?</images>~', $theme_info, $match) == 1) {
$install_info['images_url'] = $install_info['theme_url'] . '/' . $match[1];
$explicit_images = true;
}
if (preg_match('~<extra>(?:<!\\[CDATA\\[)?(.+?)(?:\\]\\]>)?</extra>~', $theme_info, $match) == 1) {
$install_info += unserialize($match[1]);
}
}
if (isset($install_info['based_on'])) {
if ($install_info['based_on'] == 'default') {
示例5: action_showoperations
/**
* List operations
*/
public function action_showoperations()
{
global $context, $txt;
// Can't be in here buddy.
isAllowedTo('admin_forum');
// We need to know the operation key for the search and replace, mod file looking at, is it a board mod?
if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) {
fatal_lang_error('operation_invalid', 'general');
}
// Load the required file.
require_once SUBSDIR . '/Package.subs.php';
require_once SUBSDIR . '/Themes.subs.php';
// Uninstalling the mod?
$reverse = isset($_REQUEST['reverse']) ? true : false;
// Get the base name.
$context['filename'] = preg_replace('~[\\.]+~', '.', $_REQUEST['package']);
// We need to extract this again.
if (is_file(BOARDDIR . '/packages/' . $context['filename'])) {
$context['extracted_files'] = read_tgz_file(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp');
if ($context['extracted_files'] && !file_exists(BOARDDIR . '/packages/temp/package-info.xml')) {
foreach ($context['extracted_files'] as $file) {
if (basename($file['filename']) == 'package-info.xml') {
$context['base_path'] = dirname($file['filename']) . '/';
break;
}
}
}
if (!isset($context['base_path'])) {
$context['base_path'] = '';
}
} elseif (is_dir(BOARDDIR . '/packages/' . $context['filename'])) {
copytree(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp');
$context['extracted_files'] = listtree(BOARDDIR . '/packages/temp');
$context['base_path'] = '';
}
// Load up any custom themes we may want to install into...
$theme_paths = getThemesPathbyID();
// For uninstall operations we only consider the themes in which the package is installed.
if (isset($_REQUEST['reverse']) && !empty($_REQUEST['install_id'])) {
$install_id = (int) $_REQUEST['install_id'];
if ($install_id > 0) {
$old_themes = loadThemesAffected($install_id);
foreach ($theme_paths as $id => $data) {
if ($id != 1 && !in_array($id, $old_themes)) {
unset($theme_paths[$id]);
}
}
}
}
// Boardmod?
if (isset($_REQUEST['boardmod'])) {
$mod_actions = parseBoardMod(@file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
} else {
$mod_actions = parseModification(@file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
}
// Ok lets get the content of the file.
$context['operations'] = array('search' => strtr(htmlspecialchars($mod_actions[$_REQUEST['operation_key']]['search_original'], ENT_COMPAT, 'UTF-8'), array('[' => '[', ']' => ']')), 'replace' => strtr(htmlspecialchars($mod_actions[$_REQUEST['operation_key']]['replace_original'], ENT_COMPAT, 'UTF-8'), array('[' => '[', ']' => ']')), 'position' => $mod_actions[$_REQUEST['operation_key']]['position']);
// Let's do some formatting...
$operation_text = $context['operations']['position'] == 'replace' ? 'operation_replace' : ($context['operations']['position'] == 'before' ? 'operation_after' : 'operation_before');
$context['operations']['search'] = parse_bbc('[code=' . $txt['operation_find'] . ']' . ($context['operations']['position'] == 'end' ? '?>' : $context['operations']['search']) . '[/code]');
$context['operations']['replace'] = parse_bbc('[code=' . $txt[$operation_text] . ']' . $context['operations']['replace'] . '[/code]');
// No layers
Template_Layers::getInstance()->removeAll();
$context['sub_template'] = 'view_operations';
}
示例6: ExamineFile
function ExamineFile()
{
global $txt, $scripturl, $boarddir, $context, $sourcedir;
checkSession('get');
require_once $sourcedir . '/Subs-Package.php';
// No package? Show him or her the door.
if (empty($_REQUEST['package']) || preg_match('~[^\\w0-9.\\-_]~', $_REQUEST['package']) === 1 || strpos($_REQUEST['package'], '..') !== false) {
redirectexit('action=packages');
}
// No file? Show him or her the door.
if (!isset($_REQUEST['file']) || $_REQUEST['file'] == '') {
redirectexit('action=packages');
}
$_REQUEST['package'] = preg_replace('~[\\.]+~', '.', $_REQUEST['package']);
$_REQUEST['file'] = preg_replace('~[\\.]+~', '.', $_REQUEST['file']);
if (isset($_REQUEST['raw'])) {
if (is_file($boarddir . '/Packages/' . $_REQUEST['package'])) {
echo read_tgz_file($boarddir . '/Packages/' . $_REQUEST['package'], $_REQUEST['file'], true);
} elseif (is_dir($boarddir . '/Packages/' . $_REQUEST['package'])) {
echo file_get_contents($boarddir . '/Packages/' . $_REQUEST['package'] . '/' . $_REQUEST['file']);
}
obExit(false);
}
$context['linktree'][] = array('url' => $scripturl . '?action=packages;sa=list;package=' . $_REQUEST['package'], 'name' => &$txt['package_examine_file']);
$context['page_title'] .= ' - ' . $txt['package_examine_file'];
$context['sub_template'] = 'examine';
// The filename...
$context['package'] = $_REQUEST['package'];
$context['filename'] = $_REQUEST['file'];
// Let the unpacker do the work.... but make sure we handle images properly.
if (in_array(strtolower(strrchr($_REQUEST['file'], '.')), array('.bmp', '.gif', '.jpeg', '.jpg', '.png'))) {
$context['filedata'] = '<img src="' . $scripturl . '?action=packages;sa=examine;package=' . $_REQUEST['package'] . ';file=' . $_REQUEST['file'] . ';raw;sesc=' . $context['session_id'] . '" alt="' . $_REQUEST['file'] . '" />';
} else {
if (is_file($boarddir . '/Packages/' . $_REQUEST['package'])) {
$context['filedata'] = htmlspecialchars(read_tgz_file($boarddir . '/Packages/' . $_REQUEST['package'], $_REQUEST['file'], true));
} elseif (is_dir($boarddir . '/Packages/' . $_REQUEST['package'])) {
$context['filedata'] = htmlspecialchars(file_get_contents($boarddir . '/Packages/' . $_REQUEST['package'] . '/' . $_REQUEST['file']));
}
if (strtolower(strrchr($_REQUEST['file'], '.')) == '.php') {
$context['filedata'] = highlight_php_code($context['filedata']);
}
}
}
示例7: ViewOperations
function ViewOperations()
{
global $context, $txt, $boarddir, $sourcedir, $modSettings;
// Can't be in here buddy.
isAllowedTo('admin_forum');
// We need to know the operation key for the search and replace, mod file looking at, is it a board mod?
if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) {
fatal_lang_error('operation_invalid', 'general');
}
// Load the required file.
require_once $sourcedir . '/lib/Subs-Package.php';
// Uninstalling the mod?
$reverse = isset($_REQUEST['reverse']) ? true : false;
// Get the base name.
$context['filename'] = preg_replace('~[\\.]+~', '.', $_REQUEST['package']);
// We need to extract this again.
if (is_file($boarddir . '/Packages/' . $context['filename'])) {
$context['extracted_files'] = read_tgz_file($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp');
if ($context['extracted_files'] && !file_exists($boarddir . '/Packages/temp/package-info.xml')) {
foreach ($context['extracted_files'] as $file) {
if (basename($file['filename']) == 'package-info.xml') {
$context['base_path'] = dirname($file['filename']) . '/';
break;
}
}
}
if (!isset($context['base_path'])) {
$context['base_path'] = '';
}
} elseif (is_dir($boarddir . '/Packages/' . $context['filename'])) {
copytree($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp');
$context['extracted_files'] = listtree($boarddir . '/Packages/temp');
$context['base_path'] = '';
}
// Load up any custom themes we may want to install into...
$request = smf_db_query('
SELECT id_theme, variable, value
FROM {db_prefix}themes
WHERE (id_theme = {int:default_theme} OR id_theme IN ({array_int:known_theme_list}))
AND variable IN ({string:name}, {string:theme_dir})', array('known_theme_list' => explode(',', $modSettings['knownThemes']), 'default_theme' => 1, 'name' => 'name', 'theme_dir' => 'theme_dir'));
$theme_paths = array();
while ($row = mysql_fetch_assoc($request)) {
$theme_paths[$row['id_theme']][$row['variable']] = $row['value'];
}
mysql_free_result($request);
// Boardmod?
if (isset($_REQUEST['boardmod'])) {
$mod_actions = parseBoardMod(@file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
} else {
$mod_actions = parseModification(@file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths);
}
// Ok lets get the content of the file.
$context['operations'] = array('search' => strtr(htmlspecialchars($mod_actions[$_REQUEST['operation_key']]['search_original']), array('[' => '[', ']' => ']')), 'replace' => strtr(htmlspecialchars($mod_actions[$_REQUEST['operation_key']]['replace_original']), array('[' => '[', ']' => ']')), 'position' => $mod_actions[$_REQUEST['operation_key']]['position']);
// Let's do some formatting...
$operation_text = $context['operations']['position'] == 'replace' ? 'operation_replace' : ($context['operations']['position'] == 'before' ? 'operation_after' : 'operation_before');
$context['operations']['search'] = parse_bbc('[code=' . $txt['operation_find'] . ']' . ($context['operations']['position'] == 'end' ? '?>' : $context['operations']['search']) . '[/code]');
$context['operations']['replace'] = parse_bbc('[code=' . $txt[$operation_text] . ']' . $context['operations']['replace'] . '[/code]');
// No layers
$context['template_layers'] = array();
$context['sub_template'] = 'view_operations';
}
示例8: getPackageInfo
/**
* Loads a package's information and returns a representative array.
*
* - Expects the file to be a package in packages/.
* - Returns a error string if the package-info is invalid.
* - Otherwise returns a basic array of id, version, filename, and similar information.
* - An Xml_Array is available in 'xml'.
*
* @package Packages
* @param string $gzfilename
*/
function getPackageInfo($gzfilename)
{
$gzfilename = trim($gzfilename);
// Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.)
if (preg_match('~^https?://~i', $gzfilename) === 1) {
$packageInfo = read_tgz_data(fetch_web_data($gzfilename, '', true), '*/package-info.xml', true);
} else {
// It must be in the package directory then
if (!file_exists(BOARDDIR . '/packages/' . $gzfilename)) {
return 'package_get_error_not_found';
}
// Make sure an package.xml file is available
if (is_file(BOARDDIR . '/packages/' . $gzfilename)) {
$packageInfo = read_tgz_file(BOARDDIR . '/packages/' . $gzfilename, '*/package-info.xml', true);
} elseif (file_exists(BOARDDIR . '/packages/' . $gzfilename . '/package-info.xml')) {
$packageInfo = file_get_contents(BOARDDIR . '/packages/' . $gzfilename . '/package-info.xml');
} else {
return 'package_get_error_missing_xml';
}
}
// Nothing?
if (empty($packageInfo)) {
// Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function
$packageInfo = read_tgz_file(BOARDDIR . '/packages/' . $gzfilename, '*/theme_info.xml', true);
if (!empty($packageInfo)) {
return 'package_get_error_is_theme';
} else {
return 'package_get_error_is_zero';
}
}
// Parse package-info.xml into an Xml_Array.
require_once SUBSDIR . '/XmlArray.class.php';
$packageInfo = new Xml_Array($packageInfo);
// @todo Error message of some sort?
if (!$packageInfo->exists('package-info[0]')) {
return 'package_get_error_packageinfo_corrupt';
}
$packageInfo = $packageInfo->path('package-info[0]');
// Convert packageInfo to an array for use
$package = htmlspecialchars__recursive($packageInfo->to_array());
$package['xml'] = $packageInfo;
$package['filename'] = $gzfilename;
// Set a default type if none was supplied in the package
if (!isset($package['type'])) {
$package['type'] = 'modification';
}
return $package;
}
示例9: CleanupMods
//.........这里部分代码省略.........
}
// Anything which reinstalled should not have its entry removed.
$reinstall_worked = array();
// We're gonna be doing some removin'
$test = isset($_POST['cleandone']) ? false : true;
foreach ($upcontext['packages'] as $id => $package) {
// Can't do anything about this....
if ($package['missing_file']) {
continue;
}
// Not testing *and* this wasn't checked?
if (!$test && (!isset($_POST['remove']) || !isset($_POST['remove'][$id]))) {
continue;
}
// What are the themes this was installed into?
$cur_theme_paths = array();
foreach ($theme_paths as $tid => $data) {
if ($tid != 1 && in_array($tid, $package['themes'])) {
$cur_theme_paths[$tid] = $data;
}
}
// Get the modifications data if applicable.
$filename = $package['filename'];
$packageInfo = getPackageInfo($filename);
if (!is_array($packageInfo)) {
continue;
}
$info = parsePackageInfo($packageInfo['xml'], $test, 'uninstall');
// Also get the reinstall details...
if (isset($_POST['remove'])) {
$infoInstall = parsePackageInfo($packageInfo['xml'], true);
}
if (is_file($boarddir . '/Packages/' . $filename)) {
read_tgz_file($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
} else {
copytree($boarddir . '/Packages/' . $filename, $boarddir . '/Packages/temp');
}
// Work out how we uninstall...
$files = array();
foreach ($info as $change) {
// Work out two things:
// 1) Whether it's installed at the moment - and if so whether its fully installed, and:
// 2) Whether it could be installed on the new version.
if ($change['type'] == 'modification') {
$contents = @file_get_contents($boarddir . '/Packages/temp/' . $upcontext['base_path'] . $change['filename']);
if ($change['boardmod']) {
$results = parseBoardMod($contents, $test, $change['reverse'], $cur_theme_paths);
} else {
$results = parseModification($contents, $test, $change['reverse'], $cur_theme_paths);
}
foreach ($results as $action) {
// Something we can remove? Probably means it existed!
if (($action['type'] == 'replace' || $action['type'] == 'append' || !empty($action['filename']) && $action['type'] == 'failure') && !in_array($action['filename'], $files)) {
$files[] = $action['filename'];
}
if ($action['type'] == 'failure') {
$upcontext['packages'][$id]['needs_removing'] = true;
$upcontext['packages'][$id]['status'] = 'Reinstall Required';
$upcontext['packages'][$id]['color'] = '#FD6435';
}
}
}
}
// Store this info for the template as appropriate.
$upcontext['packages'][$id]['files'] = $files;
$upcontext['packages'][$id]['file_count'] = count($files);
示例10: unpackGames
function unpackGames($games, $move_games = false)
{
global $scripturl, $txt, $db_prefix, $modSettings, $context, $sourcedir, $smcFunc, $boarddir;
if (!is_writable($modSettings['gamesDirectory']) && !chmod($modSettings['gamesDirectory'], 0777)) {
fatal_lang_error('arcade_not_writable', false, array($modSettings['gamesDirectory']));
}
require_once $sourcedir . '/Subs-Package.php';
$request = $smcFunc['db_query']('', '
SELECT f.id_file, f.game_file, f.game_directory
FROM {db_prefix}arcade_files AS f
WHERE id_file IN ({array_int:games})
AND (f.status = 10)', array('games' => $games));
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$from = $modSettings['gamesDirectory'] . '/' . $row['game_directory'] . '/' . $row['game_file'];
$target = substr($row['game_file'], 0, strpos($row['game_file'], '.'));
$targetb = $target;
if (substr($target, 0, 5) == 'game_') {
$target = substr($target, 5);
$target = trim($target);
if ($target == '') {
continue;
}
}
$fromb = str_replace('game_', '', $from);
$i = 1;
while (@file_exists($modSettings['gamesDirectory'] . '/' . $target)) {
@unlink($from);
continue 2;
}
while (file_exists($modSettings['gamesDirectory'] . '/' . $fromb)) {
@unlink($from);
continue 2;
}
if (substr($row['game_file'], -3) == 'zip') {
$files = read_tgz_file($from, $modSettings['gamesDirectory'] . '/' . $target);
$data = gameCacheInsertGames(getAvailableGames($target, 'unpack'), true);
}
if (substr($row['game_file'], -3) == 'tar') {
@(require_once $sourcedir . '/Tar.php');
$path = $modSettings['gamesDirectory'];
$tar = new Archive_Tar($path . '/' . $row['game_file']);
$data = $tar->listContent();
if ($data === false) {
fatal_lang_error('arcade_file_non_read', false);
} else {
$folder = $modSettings['gamesDirectory'] . '/' . $target;
if (!@is_dir($folder)) {
@mkdir($folder, 0777);
}
$tar = new Archive_Tar($path . '/' . $row['game_file']);
$tar->extract($folder);
}
}
if (unlink($from)) {
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}arcade_files
WHERE id_file = {int:file}', array('file' => $row['id_file']));
}
}
$smcFunc['db_free_result']($request);
return true;
}
示例11: action_install
/**
* Installs new themes, either from a gzip or copy of the default.
*
* What it does:
* - Puts themes in $boardurl/themes.
* - Assumes the gzip has a root directory in it. (ie default.)
* - Requires admin_forum.
* - Accessed with ?action=admin;area=theme;sa=install.
*
* @uses ManageThemes template
*/
public function action_install()
{
global $boardurl, $txt, $context, $settings, $modSettings;
checkSession('request');
require_once SUBSDIR . '/Themes.subs.php';
require_once SUBSDIR . '/Package.subs.php';
loadTemplate('ManageThemes');
// Passed an ID, then the install is complete, lets redirect and show them
if (isset($_GET['theme_id'])) {
$_GET['theme_id'] = (int) $_GET['theme_id'];
$context['sub_template'] = 'installed';
$context['page_title'] = $txt['theme_installed'];
$context['installed_theme'] = array('id' => $_GET['theme_id'], 'name' => getThemeName($_GET['theme_id']));
return;
}
// How are we going to install this theme, from a dir, zip, copy of default?
if (!empty($_FILES['theme_gz']) && (!isset($_FILES['theme_gz']['error']) || $_FILES['theme_gz']['error'] != 4) || !empty($_REQUEST['theme_gz'])) {
$method = 'upload';
} elseif (isset($_REQUEST['theme_dir']) && rtrim(realpath($_REQUEST['theme_dir']), '/\\') != realpath(BOARDDIR . '/themes') && file_exists($_REQUEST['theme_dir'])) {
$method = 'path';
} else {
$method = 'copy';
}
// Copy the default theme?
if (!empty($_REQUEST['copy']) && $method == 'copy') {
// Hopefully the themes directory is writable, or we might have a problem.
if (!is_writable(BOARDDIR . '/themes')) {
fatal_lang_error('theme_install_write_error', 'critical');
}
// Make the new directory, standard characters only
$theme_dir = BOARDDIR . '/themes/' . preg_replace('~[^A-Za-z0-9_\\- ]~', '', $_REQUEST['copy']);
umask(0);
mkdir($theme_dir, 0777);
// Get some more time if we can
@set_time_limit(600);
if (function_exists('apache_reset_timeout')) {
@apache_reset_timeout();
}
// Create the subdirectories for css, javascript and font files.
mkdir($theme_dir . '/css', 0777);
mkdir($theme_dir . '/scripts', 0777);
mkdir($theme_dir . '/webfonts', 0777);
// Copy over the default non-theme files.
$to_copy = array('/index.php', '/index.template.php', '/scripts/theme.js');
foreach ($to_copy as $file) {
copy($settings['default_theme_dir'] . $file, $theme_dir . $file);
@chmod($theme_dir . $file, 0777);
}
// And now the entire css, images and webfonts directories!
copytree($settings['default_theme_dir'] . '/css', $theme_dir . '/css');
copytree($settings['default_theme_dir'] . '/images', $theme_dir . '/images');
copytree($settings['default_theme_dir'] . '/webfonts', $theme_dir . '/webfonts');
package_flush_cache();
$theme_name = $_REQUEST['copy'];
$images_url = $boardurl . '/themes/' . basename($theme_dir) . '/images';
$theme_dir = realpath($theme_dir);
// Lets get some data for the new theme (default theme (1), default settings (0)).
$theme_values = loadThemeOptionsInto(1, 0, array(), array('theme_templates', 'theme_layers'));
// Lets add a theme_info.xml to this theme.
write_theme_info($_REQUEST['copy'], $modSettings['elkVersion'], $theme_dir, $theme_values);
} elseif (isset($_REQUEST['theme_dir']) && $method == 'path') {
if (!is_dir($_REQUEST['theme_dir']) || !file_exists($_REQUEST['theme_dir'] . '/theme_info.xml')) {
fatal_lang_error('theme_install_error', false);
}
$theme_name = basename($_REQUEST['theme_dir']);
$theme_dir = $_REQUEST['theme_dir'];
} elseif ($method == 'upload') {
// Hopefully the themes directory is writable, or we might have a problem.
if (!is_writable(BOARDDIR . '/themes')) {
fatal_lang_error('theme_install_write_error', 'critical');
}
// This happens when the admin session is gone and the user has to login again
if (empty($_FILES['theme_gz']) && empty($_REQUEST['theme_gz'])) {
redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
}
// Set the default settings...
$theme_name = strtok(basename(isset($_FILES['theme_gz']) ? $_FILES['theme_gz']['name'] : $_REQUEST['theme_gz']), '.');
$theme_name = preg_replace(array('/\\s/', '/\\.[\\.]+/', '/[^\\w_\\.\\-]/'), array('_', '.', ''), $theme_name);
$theme_dir = BOARDDIR . '/themes/' . $theme_name;
if (isset($_FILES['theme_gz']) && is_uploaded_file($_FILES['theme_gz']['tmp_name']) && (ini_get('open_basedir') != '' || file_exists($_FILES['theme_gz']['tmp_name']))) {
read_tgz_file($_FILES['theme_gz']['tmp_name'], BOARDDIR . '/themes/' . $theme_name, false, true);
} elseif (isset($_REQUEST['theme_gz'])) {
if (!isAuthorizedServer($_REQUEST['theme_gz'])) {
fatal_lang_error('not_valid_server');
}
read_tgz_file($_REQUEST['theme_gz'], BOARDDIR . '/themes/' . $theme_name, false, true);
} else {
redirectexit('action=admin;area=theme;sa=admin;' . $context['session_var'] . '=' . $context['session_id']);
}
//.........这里部分代码省略.........
示例12: action_install
/**
* Install a smiley set.
*/
public function action_install()
{
global $modSettings, $scripturl, $context, $txt, $user_info;
isAllowedTo('manage_smileys');
checkSession('request');
// One of these two may be necessary
loadLanguage('Errors');
loadLanguage('Packages');
require_once SUBSDIR . '/Smileys.subs.php';
require_once SUBSDIR . '/Package.subs.php';
// Installing unless proven otherwise
$testing = false;
$destination = '';
$name = '';
if (isset($_REQUEST['set_gz'])) {
$base_name = strtr(basename($_REQUEST['set_gz']), ':/', '-_');
$name = Util::htmlspecialchars(strtok(basename($_REQUEST['set_gz']), '.'));
$name_pr = preg_replace(array('/\\s/', '/\\.[\\.]+/', '/[^\\w_\\.\\-]/'), array('_', '.', ''), $name);
$context['filename'] = $base_name;
// Check that the smiley is from simplemachines.org, for now... maybe add mirroring later.
if (!isAuthorizedServer($_REQUEST['set_gz']) == 0) {
fatal_lang_error('not_valid_server');
}
$destination = BOARDDIR . '/packages/' . $base_name;
if (file_exists($destination)) {
fatal_lang_error('package_upload_error_exists');
}
// Let's copy it to the packages directory
file_put_contents($destination, fetch_web_data($_REQUEST['set_gz']));
$testing = true;
} elseif (isset($_REQUEST['package'])) {
$base_name = basename($_REQUEST['package']);
$name = Util::htmlspecialchars(strtok(basename($_REQUEST['package']), '.'));
$name_pr = preg_replace(array('/\\s/', '/\\.[\\.]+/', '/[^\\w_\\.\\-]/'), array('_', '.', ''), $name);
$context['filename'] = $base_name;
$destination = BOARDDIR . '/packages/' . basename($_REQUEST['package']);
}
if (!file_exists($destination)) {
fatal_lang_error('package_no_file', false);
}
// Make sure temp directory exists and is empty.
if (file_exists(BOARDDIR . '/packages/temp')) {
deltree(BOARDDIR . '/packages/temp', false);
}
if (!mktree(BOARDDIR . '/packages/temp', 0755)) {
deltree(BOARDDIR . '/packages/temp', false);
if (!mktree(BOARDDIR . '/packages/temp', 0777)) {
deltree(BOARDDIR . '/packages/temp', false);
// @todo not sure about url in destination_url
create_chmod_control(array(BOARDDIR . '/packages/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true));
deltree(BOARDDIR . '/packages/temp', false);
if (!mktree(BOARDDIR . '/packages/temp', 0777)) {
fatal_lang_error('package_cant_download', false);
}
}
}
$extracted = read_tgz_file($destination, BOARDDIR . '/packages/temp');
// @todo needs to change the URL in the next line ;)
if (!$extracted) {
fatal_lang_error('packageget_unable', false, array('http://custom.elkarte.net/index.php?action=search;type=12;basic_search=' . $name));
}
if ($extracted && !file_exists(BOARDDIR . '/packages/temp/package-info.xml')) {
foreach ($extracted as $file) {
if (basename($file['filename']) == 'package-info.xml') {
$base_path = dirname($file['filename']) . '/';
break;
}
}
}
if (!isset($base_path)) {
$base_path = '';
}
if (!file_exists(BOARDDIR . '/packages/temp/' . $base_path . 'package-info.xml')) {
fatal_lang_error('package_get_error_missing_xml', false);
}
$smileyInfo = getPackageInfo($context['filename']);
if (!is_array($smileyInfo)) {
fatal_lang_error($smileyInfo);
}
// See if it is installed?
if (isSmileySetInstalled($smileyInfo['id'])) {
fata_lang_error('package_installed_warning1');
}
// Everything is fine, now it's time to do something, first we test
$actions = parsePackageInfo($smileyInfo['xml'], true, 'install');
$context['post_url'] = $scripturl . '?action=admin;area=smileys;sa=install;package=' . $base_name;
$context['has_failure'] = false;
$context['actions'] = array();
$context['ftp_needed'] = false;
foreach ($actions as $action) {
if ($action['type'] == 'readme' || $action['type'] == 'license') {
$type = 'package_' . $action['type'];
if (file_exists(BOARDDIR . '/packages/temp/' . $base_path . $action['filename'])) {
$context[$type] = htmlspecialchars(trim(file_get_contents(BOARDDIR . '/packages/temp/' . $base_path . $action['filename']), "\n\r"), ENT_COMPAT, 'UTF-8');
} elseif (file_exists($action['filename'])) {
$context[$type] = htmlspecialchars(trim(file_get_contents($action['filename']), "\n\r"), ENT_COMPAT, 'UTF-8');
}
//.........这里部分代码省略.........
示例13: ThemeInstall
function ThemeInstall()
{
global $sourcedir, $boarddir, $boardurl, $db_prefix, $txt, $context, $settings, $modSettings;
checkSession('request');
isAllowedTo('admin_forum');
checkSession('request');
require_once $sourcedir . '/Subs-Package.php';
loadTemplate('Themes');
if (isset($_GET['theme_id'])) {
adminIndex('manage_themes');
$result = db_query("\n\t\t\tSELECT value\n\t\t\tFROM {$db_prefix}themes\n\t\t\tWHERE ID_THEME = " . (int) $_GET['theme_id'] . "\n\t\t\t\tAND ID_MEMBER = 0\n\t\t\t\tAND variable = 'name'\n\t\t\tLIMIT 1", __FILE__, __LINE__);
list($theme_name) = mysql_fetch_row($result);
mysql_free_result($result);
$context['sub_template'] = 'installed';
$context['page_title'] = $txt['theme_installed'];
$context['installed_theme'] = array('id' => (int) $_GET['theme_id'], 'name' => $theme_name);
return;
}
if (!empty($_FILES['theme_gz']) && (!isset($_FILES['theme_gz']['error']) || $_FILES['theme_gz']['error'] != 4) || !empty($_REQUEST['theme_gz'])) {
$method = 'upload';
} elseif (isset($_REQUEST['theme_dir']) && realpath(stripslashes($_REQUEST['theme_dir'])) != realpath($boarddir . '/Themes') && file_exists(stripslashes($_REQUEST['theme_dir']))) {
$method = 'path';
} else {
$method = 'copy';
}
if (!empty($_REQUEST['copy']) && $method == 'copy') {
// Hopefully the themes directory is writable, or we might have a problem.
if (!is_writable($boarddir . '/Themes')) {
fatal_lang_error('theme_install_write_error');
}
$theme_dir = $boarddir . '/Themes/' . preg_replace('~[^A-Za-z0-9_\\- ]~', '', $_REQUEST['copy']);
umask(0);
mkdir($theme_dir, 0777);
// Copy over the default non-theme files.
$to_copy = array('/style.css', '/index.php', '/index.template.php');
foreach ($to_copy as $file) {
copy($settings['default_theme_dir'] . $file, $theme_dir . $file);
@chmod($theme_dir . $file, 0777);
}
// And now the entire images directory!
copytree($settings['default_theme_dir'] . '/images', $theme_dir . '/images');
package_flush_cache();
$theme_name = $_REQUEST['copy'];
$images_url = $boardurl . '/Themes/' . basename($theme_dir) . '/images';
$theme_dir = realpath($theme_dir);
} elseif (isset($_REQUEST['theme_dir']) && $method == 'path') {
if (!is_dir(stripslashes($_REQUEST['theme_dir'])) || !file_exists(stripslashes($_REQUEST['theme_dir']) . '/theme_info.xml')) {
fatal_lang_error('theme_install_error', false);
}
$theme_name = basename($_REQUEST['theme_dir']);
$theme_dir = stripslashes($_REQUEST['theme_dir']);
} elseif ($method = 'upload') {
// Hopefully the themes directory is writable, or we might have a problem.
if (!is_writable($boarddir . '/Themes')) {
fatal_lang_error('theme_install_write_error');
}
require_once $sourcedir . '/Subs-Package.php';
// Set the default settings...
$theme_name = strtok(basename(isset($_FILES['theme_gz']) ? $_FILES['theme_gz']['name'] : $_REQUEST['theme_gz']), '.');
$theme_name = preg_replace(array('/\\s/', '/\\.[\\.]+/', '/[^\\w_\\.\\-]/'), array('_', '.', ''), $theme_name);
$theme_dir = $boarddir . '/Themes/' . $theme_name;
if (isset($_FILES['theme_gz']) && is_uploaded_file($_FILES['theme_gz']['tmp_name']) && (@ini_get('open_basedir') != '' || file_exists($_FILES['theme_gz']['tmp_name']))) {
$extracted = read_tgz_file($_FILES['theme_gz']['tmp_name'], $boarddir . '/Themes/' . $theme_name, false, true);
} elseif (isset($_REQUEST['theme_gz'])) {
// Check that the theme is from simplemachines.org, for now... maybe add mirroring later.
if (preg_match('~^http://[\\w_\\-]+\\.simplemachines\\.org/~', $_REQUEST['theme_gz']) == 0 || strpos($_REQUEST['theme_gz'], 'dlattach') !== false) {
fatal_lang_error('not_on_simplemachines');
}
$extracted = read_tgz_file($_REQUEST['theme_gz'], $boarddir . '/Themes/' . $theme_name, false, true);
} else {
redirectexit('action=theme;sa=admin;sesc=' . $context['session_id']);
}
}
// Something go wrong?
if ($theme_dir != '' && basename($theme_dir) != 'Themes') {
// Defaults.
$install_info = array('theme_url' => $boardurl . '/Themes/' . basename($theme_dir), 'images_url' => isset($images_url) ? $images_url : $boardurl . '/Themes/' . basename($theme_dir) . '/images', 'theme_dir' => $theme_dir, 'name' => $theme_name);
if (file_exists($theme_dir . '/theme_info.xml')) {
$theme_info = file_get_contents($theme_dir . '/theme_info.xml');
$xml_elements = array('name' => 'name', 'theme_layers' => 'layers', 'theme_templates' => 'templates', 'based_on' => 'based-on');
foreach ($xml_elements as $var => $name) {
if (preg_match('~<' . $name . '>(?:<!\\[CDATA\\[)?(.+?)(?:\\]\\]>)?</' . $name . '>~', $theme_info, $match) == 1) {
$install_info[$var] = $match[1];
}
}
if (preg_match('~<images>(?:<!\\[CDATA\\[)?(.+?)(?:\\]\\]>)?</images>~', $theme_info, $match) == 1) {
$install_info['images_url'] = $install_info['theme_url'] . '/' . $match[1];
$explicit_images = true;
}
if (preg_match('~<extra>(?:<!\\[CDATA\\[)?(.+?)(?:\\]\\]>)?</extra>~', $theme_info, $match) == 1) {
$install_info += unserialize($match[1]);
}
}
if (isset($install_info['based_on'])) {
if ($install_info['based_on'] == 'default') {
$install_info['theme_url'] = $settings['default_theme_url'];
$install_info['images_url'] = $settings['default_images_url'];
} elseif ($install_info['based_on'] != '') {
$install_info['based_on'] = preg_replace('~[^A-Za-z0-9\\-_ ]~', '', $install_info['based_on']);
$request = db_query("\n\t\t\t\t\tSELECT th.value AS base_theme_dir, th2.value AS base_theme_url" . (!empty($explicit_images) ? '' : ", th3.value AS images_url") . "\n\t\t\t\t\tFROM ({$db_prefix}themes AS th, {$db_prefix}themes AS th2" . (!empty($explicit_images) ? '' : ", {$db_prefix}themes AS th3") . ")\n\t\t\t\t\tWHERE th.ID_MEMBER = 0\n\t\t\t\t\t\tAND (th.value LIKE '%/{$install_info['based_on']}' OR th.value LIKE '%\\{$install_info['based_on']}')\n\t\t\t\t\t\tAND th.variable = 'theme_dir'\n\t\t\t\t\t\tAND th.ID_THEME = th2.ID_THEME\n\t\t\t\t\t\tAND th2.ID_MEMBER = 0\n\t\t\t\t\t\tAND th2.variable = 'theme_url'" . (!empty($explicit_images) ? '' : "\n\t\t\t\t\t\tAND th.ID_THEME = th3.ID_THEME\n\t\t\t\t\t\tAND th3.ID_MEMBER = 0\n\t\t\t\t\t\tAND th3.variable = 'images_url'") . "\n\t\t\t\t\tLIMIT 1", __FILE__, __LINE__);
//.........这里部分代码省略.........
示例14: getPackageInfo
/**
* Loads a package's information and returns a representative array.
* - expects the file to be a package in Packages/.
* - returns a error string if the package-info is invalid.
* - otherwise returns a basic array of id, version, filename, and similar information.
* - an xmlArray is available in 'xml'.
*
* @param string $filename
* @return array
*/
function getPackageInfo($gzfilename)
{
global $boarddir, $sourcedir, $smcFunc;
// Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.)
if (strpos($gzfilename, 'http://') !== false) {
$packageInfo = read_tgz_data(fetch_web_data($gzfilename, '', true), '*/package-info.xml', true);
} else {
if (!file_exists($boarddir . '/Packages/' . $gzfilename)) {
return 'package_get_error_not_found';
}
if (is_file($boarddir . '/Packages/' . $gzfilename)) {
$packageInfo = read_tgz_file($boarddir . '/Packages/' . $gzfilename, '*/package-info.xml', true);
} elseif (file_exists($boarddir . '/Packages/' . $gzfilename . '/package-info.xml')) {
$packageInfo = file_get_contents($boarddir . '/Packages/' . $gzfilename . '/package-info.xml');
} else {
return 'package_get_error_missing_xml';
}
}
// Nothing?
if (empty($packageInfo)) {
// Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function
$packageInfo = read_tgz_file($boarddir . '/Packages/' . $gzfilename, '*/theme_info.xml', true);
if (!empty($packageInfo)) {
return 'package_get_error_is_theme';
} else {
return 'package_get_error_is_zero';
}
}
// Parse package-info.xml into an xmlArray.
require_once $sourcedir . '/Class-Package.php';
$packageInfo = new xmlArray($packageInfo);
// @todo Error message of some sort?
if (!$packageInfo->exists('package-info[0]')) {
return 'package_get_error_packageinfo_corrupt';
}
$packageInfo = $packageInfo->path('package-info[0]');
$package = $packageInfo->to_array();
$package['xml'] = $packageInfo;
$package['filename'] = $gzfilename;
$package['name'] = $smcFunc['htmlspecialchars']($package['name']);
if (!isset($package['type'])) {
$package['type'] = 'modification';
}
return $package;
}