diff -r e3d7322305bf -r 5e1f1e916419 punbb/admin/extensions.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/punbb/admin/extensions.php Sat Apr 05 23:56:45 2008 -0400 @@ -0,0 +1,738 @@ + $_ ) +{ + $$key =& $GLOBALS[$key]; +} +require_once PUN_ROOT.'include/xml.php'; + +($hook = get_hook('aex_start')) ? eval($hook) : null; + +if ($session->user_level < USER_LEVEL_ADMIN) + message($lang_common['No permission']); + +// Load the admin.php language file +require PUN_ROOT.'lang/'.$pun_user['language'].'/admin.php'; +$GLOBALS['lang_admin'] = $lang_admin; + +// Make sure we have XML support +if (!function_exists('xml_parser_create')) + message($lang_admin['No XML support']); + +$section = isset($_GET['section']) ? $_GET['section'] : null; + + +// Install an extension +if (isset($_GET['install']) || isset($_GET['install_hotfix'])) +{ + ($hook = get_hook('aex_install_selected')) ? eval($hook) : null; + + // User pressed the cancel button + if (isset($_POST['install_cancel'])) + pun_redirect(pun_link($pun_url['admin_extensions_install']), $lang_admin['Cancel redirect']); + + $id = preg_replace('/[^0-9a-z_]/', '', isset($_GET['install']) ? $_GET['install'] : $_GET['install_hotfix']); + + // Load manifest (either locally or from punbb.org updates service) + if (isset($_GET['install'])) + $manifest = @file_get_contents(PUN_ROOT.'extensions/'.$id.'/manifest.xml'); + else + $manifest = @end(get_remote_file('http://punbb.org/update/manifest/'.$id.'.xml', 16)); + + // Parse manifest.xml into an array and validate it + $ext_data = xml_to_array($manifest); + $errors = validate_manifest($ext_data, $id); + + if (!empty($errors)) + message(isset($_GET['install']) ? $lang_common['Bad request'] : $lang_admin['Hotfix download failed']); + + // Setup breadcrumbs + $pun_page['crumbs'] = array( + array($pun_config['o_board_title'], pun_link($pun_url['index'])), + array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), + array($lang_admin['Install extensions'], pun_link($pun_url['admin_extensions_install'])), + $lang_admin['Install extension'] + ); + + if (isset($_POST['install_comply'])) + { + ($hook = get_hook('aex_install_comply_form_submitted')) ? eval($hook) : null; + + // Is there some uninstall code to store in the db? + $uninstall_code = (isset($ext_data['extension']['uninstall']) && trim($ext_data['extension']['uninstall']) != '') ? '\''.$pun_db->escape(trim($ext_data['extension']['uninstall'])).'\'' : 'NULL'; + + // Is there an uninstall note to store in the db? + $uninstall_note = 'NULL'; + foreach ($ext_data['extension']['note'] as $cur_note) + { + if ($cur_note['attributes']['type'] == 'uninstall' && trim($cur_note['content']) != '') + $uninstall_note = '\''.$pun_db->escape(trim($cur_note['content'])).'\''; + } + + $notices = array(); + + // Is this a fresh install or an upgrade? + $query = array( + 'SELECT' => 'e.version', + 'FROM' => 'extensions AS e', + 'WHERE' => 'e.id=\''.$pun_db->escape($id).'\'' + ); + + ($hook = get_hook('aex_qr_get_current_ext_version')) ? eval($hook) : null; + $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + if ($pun_db->num_rows($result)) + { + // EXT_CUR_VERSION will be available to the extension install routine (to facilitate extension upgrades) + define('EXT_CUR_VERSION', $pun_db->result($result)); + + // Run the author supplied install code + if (isset($ext_data['extension']['install']) && trim($ext_data['extension']['install']) != '') + eval($ext_data['extension']['install']); + + // Update the existing extension + $query = array( + 'UPDATE' => 'extensions', + 'SET' => 'title=\''.$pun_db->escape($ext_data['extension']['title']).'\', version=\''.$pun_db->escape($ext_data['extension']['version']).'\', description=\''.$pun_db->escape($ext_data['extension']['description']).'\', author=\''.$pun_db->escape($ext_data['extension']['author']).'\', uninstall='.$uninstall_code.', uninstall_note='.$uninstall_note, + 'WHERE' => 'id=\''.$pun_db->escape($id).'\'' + ); + + ($hook = get_hook('aex_qr_update_ext')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + + // Delete the old hooks + $query = array( + 'DELETE' => 'extension_hooks', + 'WHERE' => 'extension_id=\''.$pun_db->escape($id).'\'' + ); + + ($hook = get_hook('aex_qr_delete_hooks')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + } + else + { + // Run the author supplied install code + if (isset($ext_data['extension']['install']) && trim($ext_data['extension']['install']) != '') + eval($ext_data['extension']['install']); + + // Add the new extension + $query = array( + 'INSERT' => 'id, title, version, description, author, uninstall, uninstall_note', + 'INTO' => 'extensions', + 'VALUES' => '\''.$pun_db->escape($ext_data['extension']['id']).'\', \''.$pun_db->escape($ext_data['extension']['title']).'\', \''.$pun_db->escape($ext_data['extension']['version']).'\', \''.$pun_db->escape($ext_data['extension']['description']).'\', \''.$pun_db->escape($ext_data['extension']['author']).'\', '.$uninstall_code.', '.$uninstall_note + ); + + ($hook = get_hook('aex_qr_add_ext')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + } + + // Now insert the hooks + foreach ($ext_data['extension']['hooks']['hook'] as $hook) + { + $query = array( + 'INSERT' => 'id, extension_id, code, installed', + 'INTO' => 'extension_hooks', + 'VALUES' => '\''.$pun_db->escape(trim($hook['attributes']['id'])).'\', \''.$pun_db->escape($id).'\', \''.$pun_db->escape(trim($hook['content'])).'\', '.time() + ); + + ($hook = get_hook('aex_qr_add_hook')) ? eval($hook) : null; + $pun_db->query_build($query) or error(__FILE__, __LINE__); + } + + // Empty the PHP cache + $d = dir(PUN_CACHE_DIR); + while (($entry = $d->read()) !== false) + { + if (substr($entry, strlen($entry)-4) == '.php') + @unlink(PUN_CACHE_DIR.$entry); + } + $d->close(); + + // Regenerate the hooks cache + require_once PUN_ROOT.'include/cache.php'; + generate_hooks_cache(); + + // Display notices if there are any + if (!empty($notices)) + { + ($hook = get_hook('aex_install_notices_pre_header_load')) ? eval($hook) : null; + + define('PUN_PAGE_SECTION', 'extensions'); + define('PUN_PAGE', 'admin-extensions-install'); + require PUN_ROOT.'header.php'; + +?> +
+ +'.sprintf($lang_admin['Extension by'], 'PunBB').'
'.$lang_admin['Hotfix description'].'
'.$lang_admin['Illegal ID'].'
'."\n\t\t\t".''.$lang_admin['Missing manifest'].'
'."\n\t\t\t".''.$lang_admin['Failed parse manifest'].'
'."\n\t\t\t".''.implode(' ', $errors).'
'."\n\t\t\t".''.sprintf($lang_admin['Extension by'], htmlspecialchars($ext_data['extension']['author'])).''.(($ext_data['extension']['description'] != '') ? '
'.htmlspecialchars($ext_data['extension']['description']).'' : '').'