settings.php

来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 494 行

PHP
494
字号
<?php/*+--------------------------------------------------------------------------|   Invision Power Board v2.1.5|   =============================================|   by Matthew Mecham|   (c) 2001 - 2005 Invision Power Services, Inc.|   |   =============================================|   Web: |   Time: Wed, 01 Mar 2006 19:11:27 GMT|   Release: |   Licence Info: +---------------------------------------------------------------------------|   > $Date: 2006-3-6|   > $Revision: 137 $|   > $Author: bfarber $+---------------------------------------------------------------------------||   > Admin Setting functions|   > Module written by Matt Mecham|   > Date started: 20th March 2002||	> Module Version Number: 1.0.0|   > DBA Checked: Tue 25th May 2004+--------------------------------------------------------------------------*/if ( ! defined( 'IN_ACP' ) ){	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'admin.php'.";	exit();}class ad_settings {	var $base_url;	var $in_group  = array();	var $key_array = array();		/**	* Section title name	*	* @var	string	*/	var $perm_main = "tools";		/**	* Section title name	*	* @var	string	*/	var $perm_child = "op";		function auto_run() 	{		//-----------------------------------------		// Kill globals - globals bad, Homer good.		//-----------------------------------------				$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );				foreach ( $tmp_in as $k => $v )		{			unset($$k);		}				//-----------------------------------------				$this->ipsclass->DB->sql_get_version();				$this->true_version  = $this->ipsclass->DB->true_version;		$this->mysql_version = $this->ipsclass->DB->mysql_version;		switch($this->ipsclass->input['code'])		{			case 'settinggroup_resync':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );				$this->settinggroup_resync();				break;							case 'settinggroup_delete':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );				$this->settinggroup_delete();				break;							case 'settinggroup_new':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );				$this->settinggroup_form('add');				break;							case 'settinggroup_showedit':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );				$this->settinggroup_form('edit');				break;							case 'settinggroup_add':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );				$this->settinggroup_save('add');				break;							case 'settinggroup_edit':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );				$this->settinggroup_save('edit');				break;							case 'settingnew':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );				$this->setting_form('add');				break;							case 'setting_showedit':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );				$this->setting_form('edit');				break;							case 'setting_add':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':add' );				$this->setting_save('add');				break;							case 'setting_edit':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );				$this->setting_save('edit');				break;							case 'setting_view':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );				$this->setting_view();				break;							case 'setting_delete':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':remove' );				$this->setting_delete();				break;						case 'setting_revert':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );				$this->setting_revert();				break;							case 'setting_update':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':edit' );				$this->setting_update();				break;						case 'setting_allexport':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':export' );				$this->setting_allexport();				break;							case 'findsetting':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':search' );				$this->setting_findgroup();				break;							case 'setting_someexport_start':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':export' );				$this->setting_someexport_start();				break;							case 'setting_someexport_complete':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':export' );				$this->setting_someexport_complete();				break;						case 'settings_do_import':				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':import' );				$this->settings_do_import();				break;							//-----------------------------------------			// Full text			//-----------------------------------------							case 'dofulltext':				$this->do_fulltext();				break;							case 'phpinfo':				phpinfo();				exit;			//-----------------------------------------			default:				$this->ipsclass->admin->cp_permission_check( $this->perm_main.'|'.$this->perm_child.':' );				$this->setting_start();				break;		}			}		//-----------------------------------------	//	// IMPORT PARTIAL SETTINGS	//	//-----------------------------------------		function settings_do_import( $noreturn=0 )	{		//-----------------------------------------		// INIT		//-----------------------------------------				$updated      = 0;		$inserted     = 0;		$need_update  = array();		$cur_settings = array();		$new_titles   = array();		$new_settings = array();				$this->setting_titles_check();				//-----------------------------------------		// Get file		//-----------------------------------------				if ( $_FILES['FILE_UPLOAD']['name'] == "" or ! $_FILES['FILE_UPLOAD']['name'] or ($_FILES['FILE_UPLOAD']['name'] == "none") )		{			//-----------------------------------------			// check and load from server			//-----------------------------------------						if ( ! $this->ipsclass->input['file_location'] )			{				$this->ipsclass->main_msg = "No upload file was found and no filename was specified.";				$this->setting_start();			}						if ( ! file_exists( ROOT_PATH . $this->ipsclass->input['file_location'] ) )			{				$this->ipsclass->main_msg = "Could not find the file to open at: " . ROOT_PATH . $this->ipsclass->input['file_location'];				$this->setting_start();			}						if ( preg_match( "#\.gz$#", $this->ipsclass->input['file_location'] ) )			{				if ( $FH = @gzopen( ROOT_PATH.$this->ipsclass->input['file_location'], 'rb' ) )				{					while ( ! @gzeof( $FH ) )					{						$content .= @gzread( $FH, 1024 );					}										@gzclose( $FH );				}			}			else			{				if ( $FH = @fopen( ROOT_PATH.$this->ipsclass->input['file_location'], 'rb' ) )				{					$content = @fread( $FH, filesize(ROOT_PATH.$this->ipsclass->input['file_location']) );					@fclose( $FH );				}			}		}		else		{			//-----------------------------------------			// Get uploaded schtuff			//-----------------------------------------						$tmp_name = $_FILES['FILE_UPLOAD']['name'];			$tmp_name = preg_replace( "#\.gz$#", "", $tmp_name );						$content  = $this->ipsclass->admin->import_xml( $tmp_name );		}				//-----------------------------------------		// Get current settings.		//-----------------------------------------				$this->ipsclass->DB->simple_construct( array( 'select' => 'conf_id, conf_key',													  'from'   => 'conf_settings',													  'order'  => 'conf_id' ) );				$this->ipsclass->DB->simple_exec();				while ( $r = $this->ipsclass->DB->fetch_row() )		{			$cur_settings[ $r['conf_key'] ] = $r['conf_id'];		}				//-----------------------------------------		// Get current titles		//-----------------------------------------				$this->setting_get_groups();				//-----------------------------------------		// Get xml mah-do-dah		//-----------------------------------------				require_once( KERNEL_PATH.'class_xml.php' );		$xml = new class_xml();				//-----------------------------------------		// Unpack the datafile		//-----------------------------------------				$xml->xml_parse_document( $content );				//-----------------------------------------		// pArse		//-----------------------------------------				$fields = array( 'conf_title'   , 'conf_description', 'conf_group'    , 'conf_type'    , 'conf_key'        , 'conf_default',						 'conf_extra'   , 'conf_evalphp'    , 'conf_protected', 'conf_position', 'conf_start_group', 'conf_end_group',						 'conf_help_key', 'conf_add_cache'  , 'conf_title_keyword' );				$setting_fields = array( 'conf_title_keyword', 'conf_title_title', 'conf_title_desc', 'conf_title_noshow' );				//-----------------------------------------		// Fix up...		//-----------------------------------------				if ( ! is_array( $xml->xml_array['settingexport']['settinggroup']['setting'][0]  ) )		{			//-----------------------------------------			// Ensure [0] is populated			//-----------------------------------------						$tmp = $xml->xml_array['settingexport']['settinggroup']['setting'];						unset($xml->xml_array['settingexport']['settinggroup']['setting']);						$xml->xml_array['settingexport']['settinggroup']['setting'][0] = $tmp;		}				//-----------------------------------------		// Loop through and sort out settings...		//-----------------------------------------				foreach( $xml->xml_array['settingexport']['settinggroup']['setting'] as $id => $entry )		{			$newrow = array();						//-----------------------------------------			// Is setting?			//-----------------------------------------						if ( ! $entry['conf_is_title']['VALUE'] )			{				foreach( $fields as $f )				{					$newrow[$f] = $entry[ $f ]['VALUE'];				}								$new_settings[] = $newrow;			}						//-----------------------------------------			// Is title?			//-----------------------------------------						else			{				foreach( $setting_fields as $f )				{					$newrow[$f] = $entry[ $f ]['VALUE'];				}								$new_titles[] = $newrow;			}		}				//-----------------------------------------		// Sort out titles...		//-----------------------------------------				if ( is_array( $new_titles ) and count( $new_titles ) )		{			foreach( $new_titles as $idx => $data )			{				if ( $data['conf_title_title'] AND $data['conf_title_keyword'] )				{					//-----------------------------------------					// Get ID based on key					//-----------------------------------------										$conf_id = $this->setting_groups_by_key[ $data['conf_title_keyword'] ]['conf_title_id'];										$save = array( 'conf_title_title'   => $data['conf_title_title'],								   'conf_title_desc'    => $data['conf_title_desc'],								   'conf_title_keyword' => $data['conf_title_keyword'],								   'conf_title_noshow'  => $data['conf_title_noshow']  );										//-----------------------------------------					// Not got a row, insert first!					//-----------------------------------------										if ( ! $conf_id )					{						$this->ipsclass->DB->do_insert( 'conf_settings_titles', $save );						$conf_id = $this->ipsclass->DB->get_insert_id();											}					else					{						//-----------------------------------------						// Update...						//-----------------------------------------												$this->ipsclass->DB->do_update( 'conf_settings_titles', $save, 'conf_title_id='.$conf_id );					}										//-----------------------------------------					// Update settings cache					//-----------------------------------------										$save['conf_title_id']                                      = $conf_id;					$this->setting_groups_by_key[ $save['conf_title_keyword'] ] = $save;					$this->setting_groups[ $save['conf_title_id'] ]             = $save;											//-----------------------------------------					// Remove need update...					//-----------------------------------------										$need_update[] = $conf_id;				}			}		}				//-----------------------------------------		// Sort out settings		//-----------------------------------------				if ( is_array( $new_settings ) and count( $new_settings ) )		{			foreach( $new_settings as $idx => $data )			{				//-----------------------------------------				// Make PHP slashes safe				// Not needed 2.1.0 'cos mysql_escape_slashes does a good job				//-----------------------------------------								//$data['conf_evalphp'] = str_replace( '\\', '\\\\', $data['conf_evalphp'] );								//-----------------------------------------				// Now assign to the correct ID based on				// our title keyword...				//-----------------------------------------								$data['conf_group'] = $this->setting_groups_by_key[ $data['conf_title_keyword'] ]['conf_title_id'];								//-----------------------------------------				// Remove from array				//-----------------------------------------								unset( $data['conf_title_keyword'] );								if ( $cur_settings[ $data['conf_key'] ] )				{					//-----------------------------------------					// Update					//-----------------------------------------										$this->ipsclass->DB->do_update( 'conf_settings', $data, 'conf_id='.$cur_settings[ $data['conf_key'] ] );					$updated++;				}				else				{					//-----------------------------------------					// INSERT					//-----------------------------------------										$this->ipsclass->DB->do_insert( 'conf_settings', $data );					$inserted++;				}			}		}				//-----------------------------------------		// Update group counts...		//-----------------------------------------				if ( count( $need_update ) )		{			foreach( $need_update as $i => $idx )			{				$conf = $this->ipsclass->DB->simple_exec_query( array( 'select' => 'count(*) as count', 'from' => 'conf_settings', 'where' => 'conf_group='.$idx ) );							$count = intval($conf['count']);								$this->ipsclass->DB->do_update( 'conf_settings_titles', array( 'conf_title_count' => $count ), 'conf_title_id='.$idx );			}		}				//-----------------------------------------		// Resync		//-----------------------------------------				$this->ipsclass->main_msg = "鏇存柊浜

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?