⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acp_styles.php

📁 这些都是我以前学习是用到的源码
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		$sql_from = '';		$style_count = array();		switch ($mode)		{			case 'style':				$sql_from = STYLES_TABLE;				$sql = 'SELECT user_style, COUNT(user_style) AS style_count					FROM ' . USERS_TABLE . '					GROUP BY user_style';				$result = $db->sql_query($sql);				while ($row = $db->sql_fetchrow($result))				{					$style_count[$row['user_style']] = $row['style_count'];				}				$db->sql_freeresult($result);			break;			case 'template':				$sql_from = STYLES_TEMPLATE_TABLE;			break;			case 'theme':				$sql_from = STYLES_THEME_TABLE;			break;			case 'imageset':				$sql_from = STYLES_IMAGESET_TABLE;			break;		}		$l_prefix = strtoupper($mode);		$this->page_title = 'ACP_' . $l_prefix . 'S';		$template->assign_vars(array(			'S_FRONTEND'		=> true,			'S_STYLE'			=> ($mode == 'style') ? true : false,			'L_TITLE'			=> $user->lang[$this->page_title],			'L_EXPLAIN'			=> $user->lang[$this->page_title . '_EXPLAIN'],			'L_NAME'			=> $user->lang[$l_prefix . '_NAME'],			'L_INSTALLED'		=> $user->lang['INSTALLED_' . $l_prefix],			'L_UNINSTALLED'		=> $user->lang['UNINSTALLED_' . $l_prefix],			'L_NO_UNINSTALLED'	=> $user->lang['NO_UNINSTALLED_' . $l_prefix],			'L_CREATE'			=> $user->lang['CREATE_' . $l_prefix],			'U_ACTION'			=> $this->u_action,			)		);		$sql = "SELECT *			FROM $sql_from";		$result = $db->sql_query($sql);		$installed = array();		$basis_options = '<option class="sep" value="">' . $user->lang['OPTIONAL_BASIS'] . '</option>';		while ($row = $db->sql_fetchrow($result))		{			$installed[] = $row[$mode . '_name'];			$basis_options .= '<option value="' . $row[$mode . '_id'] . '">' . $row[$mode . '_name'] . '</option>';			$stylevis = ($mode == 'style' && !$row['style_active']) ? 'activate' : 'deactivate';			$s_options = array();			foreach ($options as $option)			{				$s_options[] = '<a href="' . $this->u_action . "&amp;action=$option&amp;id=" . $row[$mode . '_id'] . '">' . $user->lang[strtoupper($option)] . '</a>';			}			$s_actions = array();			foreach ($actions as $option)			{				$s_actions[] = '<a href="' . $this->u_action . "&amp;action=$option&amp;id=" . $row[$mode . '_id'] . '">' . $user->lang[strtoupper($option)] . '</a>';			}			$template->assign_block_vars('installed', array(				'S_DEFAULT_STYLE'		=> ($mode == 'style' && $row['style_id'] == $config['default_style']) ? true : false,				'U_EDIT'				=> $this->u_action . '&amp;action=' . (($mode == 'style') ? 'details' : 'edit') . '&amp;id=' . $row[$mode . '_id'],				'U_STYLE_ACT_DEACT'		=> $this->u_action . '&amp;action=' . $stylevis . '&amp;id=' . $row[$mode . '_id'],				'L_STYLE_ACT_DEACT'		=> $user->lang['STYLE_' . strtoupper($stylevis)],				'S_OPTIONS'				=> implode(' | ', $s_options),				'S_ACTIONS'				=> implode(' | ', $s_actions),				'U_PREVIEW'				=> ($mode == 'style') ? append_sid("{$phpbb_root_path}index.$phpEx", "$mode=" . $row[$mode . '_id']) : '',				'NAME'					=> $row[$mode . '_name'],				'STYLE_COUNT'			=> ($mode == 'style' && isset($style_count[$row['style_id']])) ? $style_count[$row['style_id']] : 0,				)			);		}		$db->sql_freeresult($result);		// Grab uninstalled items		$new_ary = $cfg = array();		$dp = opendir("{$phpbb_root_path}styles");		while (($file = readdir($dp)) !== false)		{			$subpath = ($mode != 'style') ? "$mode/" : '';			if ($file[0] != '.' && file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))			{				if ($cfg = file("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))				{					$items = parse_cfg_file('', $cfg);					$name = (isset($items['name'])) ? trim($items['name']) : false;					if ($name && !in_array($name, $installed))					{						$new_ary[] = array(							'path'		=> $file,							'name'		=> $name,							'copyright'	=> $items['copyright'],						);					}				}			}		}		unset($installed);		@closedir($dp);		if (sizeof($new_ary))		{			foreach ($new_ary as $cfg)			{				$template->assign_block_vars('uninstalled', array(					'NAME'			=> $cfg['name'],					'COPYRIGHT'		=> $cfg['copyright'],					'U_INSTALL'		=> $this->u_action . '&amp;action=install&amp;path=' . urlencode($cfg['path']))				);			}		}		unset($new_ary);		$template->assign_vars(array(			'S_BASIS_OPTIONS'		=> $basis_options)		);	}	/**	* Provides a template editor which allows saving changes to template files on the filesystem or in the database.	*	* @param int $template_id specifies which template set is being edited	*/	function edit_template($template_id)	{		global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template, $safe_mode;		$this->page_title = 'EDIT_TEMPLATE';		$filelist = $filelist_cats = array();		// we want newlines no carriage returns!		$_POST['template_data'] = (isset($_POST['template_data']) && !empty($_POST['template_data'])) ? str_replace(array("\r\n", "\r"), array("\n", "\n"), $_POST['template_data']) : '';		$template_data	= (STRIP) ? stripslashes($_POST['template_data']) : $_POST['template_data'];		$template_file	= request_var('template_file', '');		$text_rows		= max(5, min(999, request_var('text_rows', 20)));		$save_changes	= (isset($_POST['save'])) ? true : false;		// make sure template_file path doesn't go upwards		$template_file = str_replace('..', '.', $template_file);				// Retrieve some information about the template		$sql = 'SELECT template_storedb, template_path, template_name			FROM ' . STYLES_TEMPLATE_TABLE . "			WHERE template_id = $template_id";		$result = $db->sql_query($sql);		$template_info = $db->sql_fetchrow($result);		$db->sql_freeresult($result);		if (!$template_info)		{			trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);		}		// save changes to the template if the user submitted any		if ($save_changes && $template_file)		{			// Get the filesystem location of the current file			$file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file";			$additional = '';			// If the template is stored on the filesystem try to write the file else store it in the database			if (!$safe_mode && !$template_info['template_storedb'] && file_exists($file) && is_writeable($file))			{				if (!($fp = fopen($file, 'wb')))				{					trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);				}				fwrite($fp, $template_data);				fclose($fp);			}			else			{				$db->sql_transaction('begin');				// If it's not stored in the db yet, then update the template setting and store all template files in the db				if (!$template_info['template_storedb'])				{					$sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . '						SET template_storedb = 1						WHERE template_id = ' . $template_id;					$db->sql_query($sql);					$filelist = filelist("{$phpbb_root_path}styles/{$template_info['template_path']}/template", '', 'html');					$this->store_templates('insert', $template_id, $template_info['template_path'], $filelist);					add_log('admin', 'LOG_TEMPLATE_EDIT_DETAILS', $template_info['template_name']);					$additional .= '<br />' . $user->lang['EDIT_TEMPLATE_STORED_DB'];				}				// Update the template_data table entry for this template file				$sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . "					SET template_data = '" . $db->sql_escape($template_data) . "', template_mtime = " . time() . "					WHERE template_id = $template_id						AND template_filename = '" . $db->sql_escape($template_file) . "'";				$db->sql_query($sql);				$db->sql_transaction('commit');			}			// destroy the cached version of the template (filename without extension)			$this->clear_template_cache($template_info, array(substr($template_file, 0, -5)));			add_log('admin', 'LOG_TEMPLATE_EDIT', $template_info['template_name'], $template_file);			trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . $additional . adm_back_link($this->u_action . "&amp;action=edit&amp;id=$template_id&amp;text_rows=$text_rows&amp;template_file=$template_file"));		}		// Generate a category array containing template filenames		if (!$template_info['template_storedb'])		{			$template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template";			$filelist = filelist($template_path, '', 'html');			$filelist[''] = array_diff($filelist[''], array('bbcode.html'));			if ($template_file)			{				if (!file_exists($template_path . "/$template_file") || !($template_data = file_get_contents($template_path . "/$template_file")))				{					trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);				}			}		}		else		{			$sql = 'SELECT *				FROM ' . STYLES_TEMPLATE_DATA_TABLE . "				WHERE template_id = $template_id";			$result = $db->sql_query($sql);			$filelist = array('' => array());			while ($row = $db->sql_fetchrow($result))			{				$file_info = pathinfo($row['template_filename']);				if (($file_info['basename'] != 'bbcode') && ($file_info['extension'] == 'html'))				{					if (($file_info['dirname'] == '.') || empty($file_info['dirname']))					{						$filelist[''][] = $row['template_filename'];					}					else					{						$filelist[$file_info['dirname'] . '/'][] = "{$file_info['basename']}.{$file_info['extension']}";					}				}				if ($row['template_filename'] == $template_file)				{					$template_data = $row['template_data'];				}			}			$db->sql_freeresult($result);			unset($file_info);		}		// Now create the categories		$filelist_cats[''] = array();		foreach ($filelist as $pathfile => $file_ary)		{			// Use the directory name as category name			if (!empty($pathfile))			{				$filelist_cats[$pathfile] = array();				foreach ($file_ary as $file)				{					$filelist_cats[$pathfile][$pathfile . $file] = $file;				}			}			// or if it's in the main category use the word before the first underscore to group files			else			{				$cats = array();				foreach ($file_ary as $file)				{					$cats[] = substr($file, 0, strpos($file, '_'));					$filelist_cats[substr($file, 0, strpos($file, '_'))][$file] = $file;				}				$cats = array_values(array_unique($cats));				// we don't need any single element categories so put them into the misc '' category				for ($i = 0, $n = sizeof($cats); $i < $n; $i++)				{					if (sizeof($filelist_cats[$cats[$i]]) == 1)					{						$filelist_cats[''][key($filelist_cats[$cats[$i]])] = current($filelist_cats[$cats[$i]]);						unset($filelist_cats[$cats[$i]]);					}				}				unset($cats);			}		}		unset($filelist);		// Generate list of categorised template files		$tpl_options = '';		ksort($filelist_cats);		foreach ($filelist_cats as $category => $tpl_ary)		{			ksort($tpl_ary);			if (!empty($category))			{				$tpl_options .= '<option class="sep" value="">' . $category . '</option>';			}			foreach ($tpl_ary as $filename => $file)			{				$selected = ($template_file == $filename) ? ' selected="selected"' : '';				$tpl_options .= '<option value="' . $filename . '"' . $selected . '>' . $file . '</option>';			}		}		$template->assign_vars(array(			'S_EDIT_TEMPLATE'	=> true,			'S_HIDDEN_FIELDS'	=> build_hidden_fields(array('template_file' => $template_file)),			'S_TEMPLATES'		=> $tpl_options,			'U_ACTION'			=> $this->u_action . "&amp;action=edit&amp;id=$template_id&amp;text_rows=$text_rows",			'U_BACK'			=> $this->u_action,			'SELECTED_TEMPLATE'	=> $template_info['template_name'],			'TEMPLATE_FILE'		=> $template_file,			'TEMPLATE_DATA'		=> htmlspecialchars($template_data),			'TEXT_ROWS'			=> $text_rows)		);	}	/**	* Allows the admin to view cached versions of template files and clear single template cache files	*	* @param int $template_id specifies which template's cache is shown	*/	function template_cache($template_id)	{		global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template;		$source		= str_replace('/', '.', request_var('source', ''));		$file_ary	= array_diff(request_var('delete', array('')), array(''));		$submit		= isset($_POST['submit']) ? true : false;		$sql = 'SELECT *			FROM ' . STYLES_TEMPLATE_TABLE . "			WHERE template_id = $template_id";		$result = $db->sql_query($sql);		$template_row = $db->sql_fetchrow($result);		$db->sql_freeresult($result);		if (!$template_row)		{			trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);		}		// User wants to delete one or more files ...		if ($submit && $file_ary)		{			$this->clear_template_cache($template_row, $file_ary);			trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action . "&amp;action=cache&amp;id=$template_id"));		}		$cache_prefix = 'tpl_' . $template_row['template_path'];		// Someone wants to see the cached source ... so we'll highlight it,		// add line numbers and indent it appropriately. This could be nasty		// on larger source files ...		if ($source && file_exists("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx"))		{			adm_page_header($user->lang['TEMPLATE_CACHE']);			$template->set_filenames(array(				'body'	=> 'viewsource.html')			);			$template->assign_vars(array(				'FILENAME'	=> str_replace('.', '/', $source) . '.html')			);			$code = str_replace(array("\r\n", "\r"), array("\n", "\n"), file_get_contents("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx"));			$conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string');			foreach ($conf as $ini_var)			{				@ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var));			}			$marker = 'MARKER' . time();			$code = highlight_string(str_replace("\n", $marker, $code), true);			$code = str_replace($marker, "\n", $code);			$str_from = array('<span style="color: ', '<font color="syntax', '</font>', '<code>', '</code>','[', ']', '.', ':');			$str_to = array('<span class="', '<span class="syntax', '</span>', '', '', '&#91;', '&#93;', '&#46;', '&#58;');			$code = str_replace($str_from, $str_to, $code);			$code = preg_replace('#^(<span class="[a-z_]+">)\n?(.*?)\n?(</span>)$#is', '$1$2$3', $code);			$code = explode("\n", $code);			foreach ($code as $key => $line)			{				$template->assign_block_vars('source', array(					'LINENUM'	=> $key + 1,					'LINE'		=> preg_replace('#([^ ;])&nbsp;([^ &])#', '$1 $2', $line))				);				unset($code[$key]);			}			adm_page_footer();		}

⌨️ 快捷键说明

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