acp_styles::install_style PHP Метод

install_style() защищенный Метод

Install style
protected install_style ( array $style ) : integer
$style array style data
Результат integer Style id
    protected function install_style($style)
    {
        global $user, $phpbb_log;
        // Generate row
        $sql_ary = array();
        foreach ($style as $key => $value) {
            if ($key != 'style_id' && substr($key, 0, 1) != '_') {
                $sql_ary[$key] = $value;
            }
        }
        // Add to database
        $this->db->sql_transaction('begin');
        $sql = 'INSERT INTO ' . STYLES_TABLE . '
			' . $this->db->sql_build_array('INSERT', $sql_ary);
        $this->db->sql_query($sql);
        $id = $this->db->sql_nextid();
        $this->db->sql_transaction('commit');
        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_STYLE_ADD', false, array($sql_ary['style_name']));
        return $id;
    }

Usage Example

Пример #1
0
		function installStyle($styleName)
		{
			global $config, $db, $user, $auth, $template, $cache;
			global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
			if (preg_match('/([^a-z0-9_]+)/iS',$styleName))
				throw new Exception('Style name is not valid',1001);
				
			$res = $db->sql_query(
				"SELECT * FROM 
					{$table_prefix}styles WHERE style_name = '{$styleName}'"
			);
			
			$styles = new acp_styles();
			
			if ($db->sql_affectedrows()) {
				$row = $db->sql_fetchrow();
	
				$db->sql_query(
					"UPDATE {$table_prefix}styles SET style_active = 0"
				);
				$db->sql_query(
					"UPDATE 
						{$table_prefix}styles 
					SET 
						style_name = '{$styleName}',
						style_active = 1 
					WHERE 
						style_id = {$row['style_id']}"
				);
				$db->sql_query(
					"UPDATE {$table_prefix}users SET user_style = " . $row['style_id']
				);
				set_config('default_style', $row['style_id']);
			} else {
				// getting instalation config
				$installcfg = 
					parse_cfg_file(
						$phpbb_root_path 
						. 'styles' 
						. DIRECTORY_SEPARATOR . $styleName 
						. DIRECTORY_SEPARATOR . 'style.cfg'
					);
				
					
				// prepare data to install
				$error 		= array(); 
				$action		= 'install'; 
				$root_path	= $phpbb_root_path . 'styles/' . $styleName . '/'; 
				$id			= 0; 
				$name		= $styleName;
				$path		= $styleName; 
				$copyright	= $installcfg['copyright']; 
				$active		= 1; 
				$default	= 1; 
				$style_row	= array(); 
				
				if (!is_dir($root_path))
					throw new Exception('Directory not found',1002);
	
				$element_ary = array(
					'template' => STYLES_TEMPLATE_TABLE, 
					'theme' => STYLES_THEME_TABLE, 
					'imageset' => STYLES_IMAGESET_TABLE
				);
				
				
				$style_row = array(
					'style_id'			=> 0,
					'style_name'		=> $installcfg['name'],
					'style_copyright'	=> $installcfg['copyright']
				);
				
				
				$reqd_template = 
					(isset($installcfg['required_template'])) 
					? $installcfg['required_template'] 
					: false;
					
				$reqd_theme = 
					(isset($installcfg['required_theme'])) 
					? $installcfg['required_theme'] 
					: false;
					
				$reqd_imageset = 
					(isset($installcfg['required_imageset'])) 
					? $installcfg['required_imageset'] 
					: false;
				
				// Getting related info				
				foreach ($element_ary as $element => $table)
				{
					$style_row = 
						array_merge(
							$style_row, 
							array(
								$element . '_id'			=> 0,
								$element . '_name'			=> '',
								$element . '_copyright'		=> ''
							)
						);
	
		 			$styles->test_installed(
		 				$element, 
		 				$error, 
		 				
		 				(${'reqd_' . $element}) 
		 					? $phpbb_root_path . 'styles/' . $reqd_template .'/' 
		 					: $root_path, ${'reqd_' . $element}, 
		 					
		 				$style_row[$element . '_id'], 
		 				$style_row[$element . '_name'], 
		 				$style_row[$element . '_copyright']
		 			);
	
					if (!$style_row[$element . '_name'])
						$style_row[$element . '_name'] = $reqd_template;
				}
				
				// Install
				$styles->install_style(
					$error, 
					$action, 
					$root_path,
					$id,
					$name,
					$path,
					$copyright,
					$active,
					$default,
					$style_row
				);
			}
		}
All Usage Examples Of acp_styles::install_style