Exemplo n.º 1
0
    function repair()
    {
        global $db;
        $stylelist = filelist(PHPBB_ROOT_PATH . 'styles/', '', 'cfg');
        ksort($stylelist);
        // Loop throught the files and try to find a style we can use.
        // To be usable the directory name in the style.cfg is the same as the directory.
        foreach (array_keys($stylelist) as $styledirname) {
            if (!in_array('style.cfg', $stylelist[$styledirname])) {
                continue;
            }
            // Read the cfg, should always be index 0
            $items = parse_cfg_file(PHPBB_ROOT_PATH . 'styles/' . $styledirname . 'style.cfg');
            // Unify the name in the cfg to something used as a directory
            // Spaces -> '_'
            // All lowercase
            $stylename = utf8_clean_string(str_replace(' ', '_', $items['name']));
            // Clean up the dirname
            $dirname = substr($styledirname, -1) == '/' ? substr($styledirname, 0, -1) : $styledirname;
            // If not the same switch to the next one
            if ($dirname != $stylename) {
                continue;
            }
            // If this style isn't installed we will install the style at this point.
            $sql = 'SELECT style_id
				FROM ' . STYLES_TABLE . "\n\t\t\t\tWHERE style_name = '" . $db->sql_escape($items['name']) . "'";
            $result = $db->sql_query($sql);
            $this->sid = $db->sql_fetchfield('style_id', false, $result);
            $db->sql_freeresult($result);
            if (empty($this->sid)) {
                // Nasty, but the style installer fetches these in the method o_0
                $GLOBALS['_REQUEST']['path'] = $stylename;
                $GLOBALS['_POST']['update'] = true;
                // Call the style installer
                $this->ac->install('style');
                // Fetch the id
                $sql = 'SELECT style_id
					FROM ' . STYLES_TABLE . "\n\t\t\t\t\tWHERE style_name = '" . $db->sql_escape($items['name']) . "'";
                $result = $db->sql_query($sql);
                $this->sid = $db->sql_fetchfield('style_id', false, $result);
                $db->sql_freeresult($result);
            }
            // Set this style as the active style
            set_config('default_style', $this->sid);
            set_config('override_user_style', 1);
            // Overriding the style should enable the board for everyone
            return;
        }
        echo 'The support toolkit couldn\'t find an available style. Please seek further assistance in the support forums on <a href="http://www.phpbb.com/community/viewforum.php?f=46" title="phpBB.com Support forum">phpbb.com</a>';
        garbage_collection();
        exit_handler();
    }
Exemplo n.º 2
0
    public function update_installed_styles()
    {
        // Get all currently available styles
        $styles = $this->find_style_dirs();
        $style_paths = $style_ids = array();
        $sql = 'SELECT style_path, style_id
				FROM ' . $this->table_prefix . 'styles';
        $result = $this->db->sql_query($sql);
        while ($styles_row = $this->db->sql_fetchrow()) {
            if (in_array($styles_row['style_path'], $styles)) {
                $style_paths[] = $styles_row['style_path'];
                $style_ids[] = $styles_row['style_id'];
            }
        }
        $this->db->sql_freeresult($result);
        // Install prosilver if no style is available and prosilver can be installed
        if (empty($style_paths) && in_array('prosilver', $styles)) {
            // Try to parse config file
            $cfg = parse_cfg_file($this->phpbb_root_path . 'styles/prosilver/style.cfg');
            // Stop running this if prosilver cfg file can't be read
            if (empty($cfg)) {
                throw new \RuntimeException('No styles available and could not fall back to prosilver.');
            }
            $style = array('style_name' => 'prosilver', 'style_copyright' => '&copy; phpBB Limited', 'style_active' => 1, 'style_path' => 'prosilver', 'bbcode_bitfield' => 'kNg=', 'style_parent_id' => 0, 'style_parent_tree' => '');
            // Add to database
            $this->db->sql_transaction('begin');
            $sql = 'INSERT INTO ' . $this->table_prefix . 'styles
					' . $this->db->sql_build_array('INSERT', $style);
            $this->db->sql_query($sql);
            $style_id = $this->db->sql_nextid();
            $style_ids[] = $style_id;
            $this->db->sql_transaction('commit');
            // Set prosilver to default style
            $this->config->set('default_style', $style_id);
        } else {
            if (empty($styles) && empty($available_styles)) {
                throw new \RuntimeException('No valid styles available');
            }
        }
        // Make sure default style is available
        if (!in_array($this->config['default_style'], $style_ids)) {
            $this->config->set('default_style', array_pop($style_ids));
        }
        // Reset users to default style if their user_style is nonexistent
        $sql = 'UPDATE ' . $this->table_prefix . "users\n\t\t\tSET user_style = {$this->config['default_style']}\n\t\t\tWHERE " . $this->db->sql_in_set('user_style', $style_ids, true, true);
        $this->db->sql_query($sql);
    }
Exemplo n.º 3
0
 public function version_info($event)
 {
     $sitesplat_themes = array('bboots', 'flatboots');
     foreach ($sitesplat_themes as $sitesplat_theme) {
         if (file_exists($this->root_path . 'styles/' . strtoupper($sitesplat_theme) . '/style.cfg')) {
             $cfg_ary = parse_cfg_file($this->root_path . 'styles/' . strtoupper($sitesplat_theme) . '/style.cfg');
             if ($cfg_ary) {
                 $version = !empty($cfg_ary[$sitesplat_theme]) ? $cfg_ary[$sitesplat_theme] : '0.0.0';
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, 'http://www.sitesplat.com/updatecheck/phpbb31/' . $sitesplat_theme . '.txt');
                 curl_setopt($ch, CURLOPT_HEADER, false);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 $contents = curl_exec($ch);
                 $http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                 curl_close($ch);
                 if ($http >= 400) {
                     $contents = '';
                 }
                 $this->template->assign_block_vars('sitesplat_themes', array('NAME' => strtoupper($sitesplat_theme), 'VERSION' => $version, 'MSG' => $contents));
             }
         }
     }
 }
Exemplo n.º 4
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
				);
			}
		}
Exemplo n.º 5
0
 /**
  * Get style|component name from configuration file.
  *
  * @param string $file		Full path to .cfg file
  * @return bool|string Returns style|component name, or false
  *	on failure
  */
 protected function get_name_from_cfg($file)
 {
     $result = parse_cfg_file($file);
     return empty($result['name']) ? false : $result['name'];
 }
Exemplo n.º 6
0
 function main($id, $mode)
 {
     global $cache, $config, $request, $template, $user;
     global $phpbb_log, $phpbb_root_path, $table_prefix, $phpbb_container;
     $db_tools = $phpbb_container->get('dbal.tools');
     $this->fields_table = $phpbb_container->getParameter('tables.profile_fields');
     $this->pbwow_config_table = $phpbb_container->getParameter('tables.pbwow3_config');
     $this->pbwow_chars_table = $phpbb_container->getParameter('tables.pbwow3_chars');
     $user->add_lang('acp/board');
     $this->tpl_name = 'acp_pbwow3';
     $allow_curl = function_exists('curl_init');
     $legacy_dbtable1 = defined('PBWOW_CONFIG_TABLE') ? PBWOW_CONFIG_TABLE : '';
     $legacy_dbtable2 = defined('PBWOW2_CONFIG_TABLE') ? PBWOW2_CONFIG_TABLE : '';
     $constantsokay = $dbokay = $legacy_constants = $legacy_db_active = $chars_constokay = $chars_dbokay = $new_config = $ext_version = false;
     // Check if constants have been set correctly
     // if yes, check if the config table exists
     // if yes, load the config variables
     if ($this->pbwow_config_table == $table_prefix . 'pbwow3_config') {
         $constantsokay = true;
         if ($db_tools->sql_table_exists($this->pbwow_config_table)) {
             $dbokay = true;
             $this->get_pbwow_config();
             $new_config = $this->pbwow_config;
         }
     }
     if ($this->pbwow_chars_table == $table_prefix . 'pbwow3_chars') {
         $chars_constokay = true;
         if ($db_tools->sql_table_exists($this->pbwow_chars_table)) {
             $chars_dbokay = true;
         }
     }
     // Detect if a game has been enabled/disabled in the overview. This must be done before we retrieve the $cplist
     $cpf_game_toggle = $request->variable('game', '');
     if (!empty($cpf_game_toggle)) {
         $activate = $request->variable('enable', '');
         $this->toggle_game_cpf($cpf_game_toggle, $activate);
     }
     // Detect Battle.net characters table flush
     $charsdb_flush = $request->variable('charsdb_flush', '');
     if ($charsdb_flush && $chars_dbokay) {
         $this->charsdb_flush();
     }
     if ($mode == 'overview') {
         // Get the PBWoW extension version from the composer.json file
         $ext_manager = $phpbb_container->get('ext.manager');
         $ext_meta_manager = $ext_manager->create_extension_metadata_manager('paybas/pbwow', $template);
         $ext_meta_data = $ext_meta_manager->get_metadata('version');
         $ext_version = isset($ext_meta_data['version']) ? $ext_meta_data['version'] : '';
         $cpflist = $this->get_profile_fields_list();
         $style_root = $phpbb_root_path . 'styles/pbwow3/';
         // Get the PBWoW style version from the style.cfg file
         if (file_exists($style_root . 'style.cfg')) {
             $values = parse_cfg_file($style_root . 'style.cfg');
             $style_version = isset($values['style_version']) ? $values['style_version'] : '';
         }
         $versions = $this->obtain_remote_version($request->variable('versioncheck_force', false), true);
         // Check if old constants are still being used
         if (!empty($legacy_dbtable1) || !empty($legacy_dbtable2)) {
             $legacy_constants = true;
         }
         // Check if old table still exists
         if ($db_tools->sql_table_exists($legacy_dbtable1) || $db_tools->sql_table_exists($table_prefix . 'pbwow_config') || $db_tools->sql_table_exists($legacy_dbtable2) || $db_tools->sql_table_exists($table_prefix . 'pbwow2_config')) {
             $legacy_db_active = true;
         }
     }
     /**
      *    Config vars
      */
     switch ($mode) {
         case 'overview':
             $display_vars = array('title' => 'PBWOW_OVERVIEW_TITLE', 'vars' => array());
             break;
         case 'config':
             $display_vars = array('title' => 'PBWOW_CONFIG_TITLE', 'vars' => array('legend1' => 'PBWOW_LOGO', 'logo_size_width' => array('lang' => 'PBWOW_LOGO_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'logo_size_height' => array('lang' => 'PBWOW_LOGO_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'logo_enable' => array('lang' => 'PBWOW_LOGO_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'logo_src' => array('lang' => 'PBWOW_LOGO_SRC', 'validate' => 'string', 'type' => 'text:20:255', 'explain' => true), 'logo_size' => array('lang' => 'PBWOW_LOGO_SIZE', 'validate' => 'int:0', 'type' => 'dimension:0', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), 'logo_margins' => array('lang' => 'PBWOW_LOGO_MARGINS', 'validate' => 'string', 'type' => 'text:20:20', 'explain' => true), 'legend2' => 'PBWOW_TOPBAR', 'topbar_enable' => array('lang' => 'PBWOW_TOPBAR_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'topbar_code' => array('lang' => 'PBWOW_TOPBAR_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'topbar_fixed' => array('lang' => 'PBWOW_TOPBAR_FIXED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend3' => 'PBWOW_HEADERLINKS', 'headerlinks_enable' => array('lang' => 'PBWOW_HEADERLINKS_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'headerlinks_code' => array('lang' => 'PBWOW_HEADERLINKS_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'legend4' => 'PBWOW_VIDEOBG', 'videobg_enable' => array('lang' => 'PBWOW_VIDEOBG_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'videobg_allpages' => array('lang' => 'PBWOW_VIDEOBG_ALLPAGES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'fixedbg' => array('lang' => 'PBWOW_FIXEDBG', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend5' => 'PBWOW_AVATARS', 'avatars_enable' => array('lang' => 'PBWOW_AVATARS_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'avatars_path' => array('lang' => 'PBWOW_AVATARS_PATH', 'validate' => 'string', 'type' => 'text:20:255', 'explain' => true), 'smallranks_enable' => array('lang' => 'PBWOW_SMALLRANKS_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'legend6' => 'PBWOW_BNETCHARS', 'bnetchars_enable' => array('lang' => 'PBWOW_BNETCHARS_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'bnet_apikey' => array('lang' => 'PBWOW_BNET_APIKEY', 'validate' => 'string', 'type' => 'text:32:64', 'explain' => true), 'bnetchars_cachetime' => array('lang' => 'PBWOW_BNETCHARS_CACHETIME', 'validate' => 'int:0', 'type' => 'text:6:6', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']), 'bnetchars_timeout' => array('lang' => 'PBWOW_BNETCHARS_TIMEOUT', 'validate' => 'int:0', 'type' => 'text:1:1', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']), 'legend7' => 'PBWOW_ADS_INDEX', 'ads_index_enable' => array('lang' => 'PBWOW_ADS_INDEX_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'ads_index_code' => array('lang' => 'PBWOW_ADS_INDEX_CODE', 'type' => 'textarea:6:6', 'explain' => true)));
             break;
         default:
             $display_vars = array('title' => 'ACP_PBWOW3_CATEGORY', 'vars' => array());
             break;
     }
     $submit = $request->is_set_post('submit');
     $cfg_array = isset($_REQUEST['config']) ? utf8_normalize_nfc($request->variable('config', array('' => ''), true)) : $new_config;
     $error = array();
     // We validate the complete config if we want
     validate_config_vars($display_vars['vars'], $cfg_array, $error);
     // Do not write values if there is an error
     if (sizeof($error)) {
         $submit = false;
     }
     // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... and then write to config
     foreach ($display_vars['vars'] as $config_name => $null) {
         if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
             continue;
         }
         $new_config[$config_name] = $config_value = $cfg_array[$config_name];
         if ($submit) {
             $this->set_pbwow_config($config_name, $config_value);
             // Enable/disable Battle.net profile fields when the API is enabled/disabled
             if ($config_name == 'bnetchars_enable') {
                 $this->toggle_game_cpf('bnet', $config_value);
             }
         }
     }
     if ($submit) {
         if ($mode != 'overview') {
             $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PBWOW_CONFIG');
             $cache->purge();
             trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
         }
     }
     $this->page_title = $display_vars['title'];
     $title_explain = $user->lang[$display_vars['title'] . '_EXPLAIN'];
     $template->assign_vars(array('L_TITLE' => $user->lang[$display_vars['title']], 'L_TITLE_EXPLAIN' => $title_explain, 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'S_CONSTANTSOKAY' => $constantsokay ? true : false, 'PBWOW_DBTABLE' => $this->pbwow_config_table, 'S_DBOKAY' => $dbokay ? true : false, 'S_CURL_DANGER' => isset($this->pbwow_config['bnetchars_enable']) && $this->pbwow_config['bnetchars_enable'] && !$allow_curl, 'L_PBWOW_DB_GOOD' => sprintf($user->lang['PBWOW_DB_GOOD'], $this->pbwow_config_table), 'L_PBWOW_DB_BAD' => sprintf($user->lang['PBWOW_DB_BAD'], $this->pbwow_config_table), 'L_PBWOW_CHARSDB_GOOD' => sprintf($user->lang['PBWOW_CHARSDB_GOOD'], $this->pbwow_chars_table), 'L_PBWOW_CHARSDB_BAD' => sprintf($user->lang['PBWOW_CHARSDB_BAD'], $this->pbwow_chars_table), 'U_ACTION' => $this->u_action));
     if ($mode == 'overview') {
         $pb_bnet_host = isset($cpflist['pb_bnet_host']) && $cpflist['pb_bnet_host']['field_active'] && !$cpflist['pb_bnet_host']['field_no_view'] ? true : false;
         $pb_bnet_realm = isset($cpflist['pb_bnet_realm']) && $cpflist['pb_bnet_realm']['field_active'] && !$cpflist['pb_bnet_realm']['field_no_view'] ? true : false;
         $pb_bnet_name = isset($cpflist['pb_bnet_name']) && $cpflist['pb_bnet_name']['field_active'] && !$cpflist['pb_bnet_name']['field_no_view'] ? true : false;
         $pb_bnet_url = isset($cpflist['pb_bnet_url']) && $cpflist['pb_bnet_url']['field_active'] && !$cpflist['pb_bnet_url']['field_no_view'] ? true : false;
         $pb_bnet_avatar = isset($cpflist['pb_bnet_avatar']) && $cpflist['pb_bnet_avatar']['field_active'] && !$cpflist['pb_bnet_avatar']['field_no_view'] ? true : false;
         $pb_wow_race = isset($cpflist['pb_wow_race']) && $cpflist['pb_wow_race']['field_active'] && !$cpflist['pb_wow_race']['field_no_view'] ? true : false;
         $pb_wow_gender = isset($cpflist['pb_wow_gender']) && $cpflist['pb_wow_gender']['field_active'] && !$cpflist['pb_wow_gender']['field_no_view'] ? true : false;
         $pb_wow_class = isset($cpflist['pb_wow_class']) && $cpflist['pb_wow_class']['field_active'] && !$cpflist['pb_wow_class']['field_no_view'] ? true : false;
         $pb_wow_level = isset($cpflist['pb_wow_level']) && $cpflist['pb_wow_level']['field_active'] && !$cpflist['pb_wow_level']['field_no_view'] ? true : false;
         $pb_wow_guild = isset($cpflist['pb_wow_guild']) && $cpflist['pb_wow_guild']['field_active'] && !$cpflist['pb_wow_guild']['field_no_view'] ? true : false;
         $pb_diablo_class = isset($cpflist['pb_diablo_class']) && $cpflist['pb_diablo_class']['field_active'] && !$cpflist['pb_diablo_class']['field_no_view'] ? true : false;
         $pb_diablo_gender = isset($cpflist['pb_diablo_gender']) && $cpflist['pb_diablo_gender']['field_active'] && !$cpflist['pb_diablo_gender']['field_no_view'] ? true : false;
         $pb_diablo_follower = isset($cpflist['pb_diablo_follower']) && $cpflist['pb_diablo_follower']['field_active'] && !$cpflist['pb_diablo_follower']['field_no_view'] ? true : false;
         $pb_wildstar_race = isset($cpflist['pb_wildstar_race']) && $cpflist['pb_wildstar_race']['field_active'] && !$cpflist['pb_wildstar_race']['field_no_view'] ? true : false;
         $pb_wildstar_gender = isset($cpflist['pb_wildstar_gender']) && $cpflist['pb_wildstar_gender']['field_active'] && !$cpflist['pb_wildstar_gender']['field_no_view'] ? true : false;
         $pb_wildstar_class = isset($cpflist['pb_wildstar_class']) && $cpflist['pb_wildstar_class']['field_active'] && !$cpflist['pb_wildstar_class']['field_no_view'] ? true : false;
         $pb_wildstar_path = isset($cpflist['pb_wildstar_path']) && $cpflist['pb_wildstar_path']['field_active'] && !$cpflist['pb_wildstar_path']['field_no_view'] ? true : false;
         $pb_wow_enabled = $pb_wow_race && $pb_wow_gender && $pb_wow_class && $pb_wow_level && $pb_wow_guild;
         $pb_diablo_enabled = $pb_diablo_class && $pb_diablo_gender && $pb_diablo_follower;
         $pb_wildstar_enabled = $pb_wildstar_race && $pb_wildstar_gender && $pb_wildstar_class && $pb_wildstar_path;
         $pb_wow_activate_url = $this->u_action . '&game=wow&enable=' . ($pb_wow_enabled ? '0' : '1');
         $pb_diablo_activate_url = $this->u_action . '&game=diablo&enable=' . ($pb_diablo_enabled ? '0' : '1');
         $pb_wildstar_activate_url = $this->u_action . '&game=wildstar&enable=' . ($pb_wildstar_enabled ? '0' : '1');
         $pb_charsdb_flush_url = $this->u_action . '&charsdb_flush=1';
         $template->assign_vars(array('S_INDEX' => true, 'S_CHECK_V' => empty($versions) ? false : true, 'EXT_VERSION' => $ext_version, 'EXT_VERSION_V' => isset($versions['ext_version']['version']) ? $versions['ext_version']['version'] : '', 'STYLE_VERSION' => isset($style_version) ? $style_version : '', 'STYLE_VERSION_V' => isset($versions['style_version']['version']) ? $versions['style_version']['version'] : '', 'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&amp;versioncheck_force=1'), 'S_ALLOW_CURL' => $allow_curl, 'S_CPF_ON_MEMBERLIST' => $config['load_cpf_memberlist'] == 1 ? true : false, 'S_CPF_ON_VIEWPROFILE' => $config['load_cpf_viewprofile'] == 1 ? true : false, 'S_CPF_ON_VIEWTOPIC' => $config['load_cpf_viewtopic'] == 1 ? true : false, 'S_PB_WOW' => $pb_wow_enabled, 'S_PB_DIABLO' => $pb_diablo_enabled, 'S_PB_WILDSTAR' => $pb_wildstar_enabled, 'U_PB_WOW' => $pb_wow_activate_url, 'U_PB_DIABLO' => $pb_diablo_activate_url, 'U_PB_WILDSTAR' => $pb_wildstar_activate_url, 'S_BNETCHARS_ACTIVE' => isset($this->pbwow_config['bnetchars_enable']) && $this->pbwow_config['bnetchars_enable'] ? true : false, 'S_BNETCHARS_CONSTOKAY' => $chars_constokay ? true : false, 'S_BNETCHARS_DBOKAY' => $chars_dbokay ? true : false, 'BNET_APIKEY' => isset($this->pbwow_config['bnet_apikey']) ? $this->pbwow_config['bnet_apikey'] : false, 'U_CHARSDB_FLUSH' => $pb_charsdb_flush_url, 'S_PB_BNET_HOST' => $pb_bnet_host, 'S_PB_BNET_REALM' => $pb_bnet_realm, 'S_PB_BNET_NAME' => $pb_bnet_name, 'S_PB_BNET_URL' => $pb_bnet_url, 'S_PB_BNET_AVATAR' => $pb_bnet_avatar, 'S_PB_WOW_RACE' => $pb_wow_race, 'S_PB_WOW_GENDER' => $pb_wow_gender, 'S_PB_WOW_CLASS' => $pb_wow_class, 'S_PB_WOW_LEVEL' => $pb_wow_level, 'S_PB_WOW_GUILD' => $pb_wow_guild, 'S_PB_DIABLO_CLASS' => $pb_diablo_class, 'S_PB_DIABLO_GENDER' => $pb_diablo_gender, 'S_PB_DIABLO_FOLLOWER' => $pb_diablo_follower, 'S_PB_WILDSTAR_RACE' => $pb_wildstar_race, 'S_PB_WILDSTAR_GENDER' => $pb_wildstar_gender, 'S_PB_WILDSTAR_CLASS' => $pb_wildstar_class, 'S_PB_WILDSTAR_PATH' => $pb_wildstar_path, 'S_LEGACY_CONSTANTS' => $legacy_constants, 'S_LEGACY_DB_ACTIVE' => $legacy_db_active));
     }
     // Output relevant page
     foreach ($display_vars['vars'] as $config_key => $vars) {
         if (!is_array($vars) && strpos($config_key, 'legend') === false) {
             continue;
         }
         if (strpos($config_key, 'legend') !== false) {
             $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars));
             continue;
         }
         $type = explode(':', $vars['type']);
         $l_explain = '';
         if ($vars['explain'] && isset($vars['lang_explain'])) {
             $l_explain = isset($user->lang[$vars['lang_explain']]) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
         } else {
             if ($vars['explain']) {
                 $l_explain = isset($user->lang[$vars['lang'] . '_EXPLAIN']) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
             }
         }
         $content = build_cfg_template($type, $config_key, $new_config, $config_key, $vars);
         if (empty($content)) {
             continue;
         }
         $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => isset($user->lang[$vars['lang']]) ? $user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => $content));
         unset($display_vars['vars'][$config_key]);
     }
 }
Exemplo n.º 7
0
    function repair()
    {
        global $db, $table_prefix;
        $sql = 'SELECT s.style_id
			FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i\n\t\t\tWHERE t.template_id = s.template_id\n\t\t\t\tAND c.theme_id = s.theme_id\n\t\t\t\tAND i.imageset_id = s.imageset_id";
        $result2 = $db->sql_query_limit($sql, 1);
        $row = $db->sql_fetchrow($result2);
        if ($row) {
            // There is a style in the database, so we are lucky
            set_config('default_style', $row['style_id']);
        } else {
            // Not so lucky...need to add a style into the database to access the Support Toolkit (can not guarentee this style will work for the board however).
            $template_id = $theme_id = $imageset_id = $style_id = $style_name = false;
            foreach (array('template', 'theme', 'imageset') as $mode) {
                $var = $mode . '_id';
                $subpath = $mode != 'style' ? "{$mode}/" : '';
                $result = $db->sql_query('SELECT * FROM ' . $table_prefix . 'styles_' . $mode);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if ($row && file_exists(PHPBB_ROOT_PATH . "styles/{$mode}_path/{$subpath}{$mode}.cfg")) {
                    // There already is one of this item in the database, so no need to add it.
                    ${$var} = $row[$var];
                    if ($mode == 'template') {
                        $style_name = $row['template_name'];
                    }
                    continue;
                }
                $dp = @opendir(PHPBB_ROOT_PATH . 'styles');
                if ($dp) {
                    while (($file = readdir($dp)) !== false) {
                        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;
                                $sql_ary = array($mode . '_name' => $name, $mode . '_copyright' => $items['copyright'], $mode . '_path' => $file);
                                if ($mode == 'theme') {
                                    $sql_ary['theme_data'] = '';
                                }
                                $db->sql_query('INSERT INTO ' . $table_prefix . 'styles_' . $mode . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                                ${$var} = $db->sql_nextid();
                                if ($mode == 'template') {
                                    $style_name = $name;
                                }
                                break;
                            }
                        }
                    }
                    closedir($dp);
                }
            }
            if ($template_id && $theme_id && $imageset_id) {
                // We've got one of each, so we can add a new style and repair this.
                $sql_ary = array('style_name' => $style_name, 'style_copyright' => '', 'style_active' => 1, 'template_id' => $template_id, 'theme_id' => $theme_id, 'imageset_id' => $imageset_id);
                $db->sql_query('INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                $style_id = $db->sql_nextid();
                // That should be everything, only reset the board style and purge the cache yet
                set_config('default_style', $style_id);
            } else {
                // Can't use trigger_error
                echo 'We could not automatically add a new style.  Please install at least one style on your phpBB3 forum and try again.';
                garbage_collection();
                exit_handler();
            }
        }
        $db->sql_freeresult($result2);
    }
Exemplo n.º 8
0
    public function __construct()
    {
        global $db, $user, $auth, $cache;
        global $quickinstall_path, $phpbb_root_path, $phpEx, $config, $qi_config, $msg_title;
        // include installation functions
        include $quickinstall_path . 'includes/functions_install.' . $phpEx;
        //		include($quickinstall_path . 'includes/qi_functions.' . $phpEx);
        $config = array_merge($config, array('rand_seed' => md5(mt_rand()), 'rand_seed_last_update' => time()));
        // load installer lang
        qi::add_lang('phpbb');
        // phpbb's install uses $lang instead of $user->lang
        // need to use $GLOBALS here
        $GLOBALS['lang'] =& $user->lang;
        global $lang;
        // request variables
        $dbname = htmlspecialchars_decode(request_var('dbname', '', true));
        $redirect = request_var('redirect', false);
        $drop_db = request_var('drop_db', false);
        $delete_files = request_var('delete_files', false);
        $automod = request_var('automod', false);
        $make_writable = request_var('make_writable', false);
        $populate = request_var('populate', false);
        $subsilver = request_var('subsilver', 0);
        $alt_env = request_var('alt_env', '');
        $pop_data = request_var('pop_data', array('' => ''));
        // Some populate checking
        if ($populate) {
            if (empty($pop_data['num_users']) && empty($pop_data['num_cats']) && empty($pop_data['num_forums']) && empty($pop_data['num_topics']) && empty($pop_data['num_replies'])) {
                // populate with nothing?
                $populate = false;
            } else {
                $pop_data['email_domain'] = trim($pop_data['email_domain']);
                if (!empty($pop_data['num_users']) && empty($pop_data['email_domain'])) {
                    trigger_error($user->lang['NEED_EMAIL_DOMAIN'], E_USER_ERROR);
                }
            }
        }
        foreach (array('site_name', 'site_desc', 'table_prefix', 'admin_name', 'admin_pass') as $r) {
            if ($_r = request_var($r, '', true)) {
                $qi_config[$r] = $_r;
            }
        }
        if ($alt_env !== '' && !file_exists($quickinstall_path . 'sources/phpBB3_alt/' . $alt_env)) {
            trigger_error('NO_ALT_ENV');
        }
        // Set up our basic founder.
        $user->data['user_id'] = 2;
        //
        $user->data['username'] = $qi_config['admin_name'];
        $user->data['user_colour'] = 'AA0000';
        // overwrite some of them ;)
        $user->lang = array_merge($user->lang, array('CONFIG_SITE_DESC' => $qi_config['site_desc'], 'CONFIG_SITENAME' => $qi_config['site_name']));
        // smaller ^^
        list($dbms, $table_prefix) = array(&$qi_config['dbms'], &$qi_config['table_prefix']);
        // check if we have a board db (and folder) name
        if (!$dbname) {
            trigger_error('NO_DB');
        }
        // Set the new board as root path.
        $board_dir = $quickinstall_path . 'boards/' . $dbname . '/';
        $phpbb_root_path = $board_dir;
        if (!defined('PHPBB_ROOT_PATH')) {
            define('PHPBB_ROOT_PATH', $board_dir);
        }
        if (file_exists($board_dir)) {
            if ($delete_files) {
                file_functions::delete_dir($board_dir);
            } else {
                trigger_error(sprintf($user->lang['DIR_EXISTS'], $board_dir));
            }
        }
        // copy all of our files
        file_functions::copy_dir($quickinstall_path . 'sources/' . ($alt_env === '' ? 'phpBB3/' : "phpBB3_alt/{$alt_env}/"), $board_dir);
        if ($make_writable) {
            chmod($board_dir, 0777);
        }
        // Now make sure we have a valid db-name and prefix
        $qi_config['db_prefix'] = validate_dbname($qi_config['db_prefix'], true);
        $dbname = validate_dbname($dbname);
        // copy qi's lang file for the log
        if (file_exists("{$quickinstall_path}language/{$qi_config['qi_lang']}/info_acp_qi.{$phpEx}") && file_exists($board_dir . 'language/' . $qi_config['qi_lang'])) {
            copy("{$quickinstall_path}language/{$qi_config['qi_lang']}/info_acp_qi.{$phpEx}", "{$board_dir}language/{$qi_config['qi_lang']}/mods/info_acp_qi.{$phpEx}");
        } else {
            copy("{$quickinstall_path}language/en/info_acp_qi.{$phpEx}", "{$board_dir}language/en/mods/info_acp_qi.{$phpEx}");
        }
        if ($dbms == 'sqlite' || $dbms == 'firebird') {
            $qi_config['dbhost'] = $qi_config['db_prefix'] . $dbname;
            // temp remove some
            list($qi_config['db_prefix'], $dbname, $temp1, $temp2) = array('', '', &$qi_config['db_prefix'], &$dbname);
        }
        // Set the new board as language path to get language files from outside phpBB
        $user->set_custom_lang_path($phpbb_root_path . 'language/');
        // Write to config.php ;)
        $config_data = "<?php\n";
        $config_data .= "// phpBB 3.0.x auto-generated configuration file\n// Do not change anything in this file!\n";
        $config_data_array = array('dbms' => $dbms, 'dbhost' => $qi_config['dbhost'], 'dbport' => $qi_config['dbport'], 'dbname' => $qi_config['db_prefix'] . $dbname, 'dbuser' => $qi_config['dbuser'], 'dbpasswd' => htmlspecialchars_decode($qi_config['dbpasswd']), 'table_prefix' => $table_prefix, 'acm_type' => 'file', 'load_extensions' => '');
        foreach ($config_data_array as $key => $value) {
            $config_data .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n";
        }
        unset($config_data_array);
        $config_data .= "\n@define('PHPBB_INSTALLED', true);\n";
        $config_data .= "@define('DEBUG', true);\n";
        $config_data .= "@define('DEBUG_EXTRA', true);\n";
        $config_data .= '?' . '>';
        // Done this to prevent highlighting editors getting confused!
        file_put_contents($board_dir . 'config.' . $phpEx, $config_data);
        if ($dbms == 'sqlite' || $dbms == 'firebird') {
            // and now restore
            list($qi_config['db_prefix'], $dbname) = array(&$temp1, &$temp2);
        }
        // update phpbb_root_path
        $phpbb_root_path = $board_dir;
        if ($drop_db) {
            $db->sql_query('DROP DATABASE IF EXISTS ' . $qi_config['db_prefix'] . $dbname);
        } else {
            // Check if the database exists.
            if ($dbms == 'sqlite' || $dbms == 'firebird') {
                $db_check = $db->sql_select_db($quickinstall_path . 'cache/' . $qi_config['db_prefix'] . $dbname);
            } else {
                $db_check = $db->sql_select_db($qi_config['db_prefix'] . $dbname);
            }
            if ($db_check) {
                trigger_error(sprintf($user->lang['DB_EXISTS'], $qi_config['db_prefix'] . $dbname));
            }
        }
        if ($dbms == 'sqlite' || $dbms == 'firebird') {
            $db->sql_query('CREATE DATABASE ' . $quickinstall_path . 'cache/' . $qi_config['db_prefix'] . $dbname);
            $db->sql_select_db($quickinstall_path . 'cache/' . $qi_config['db_prefix'] . $dbname);
        } else {
            $db->sql_query('CREATE DATABASE ' . $qi_config['db_prefix'] . $dbname);
            $db->sql_select_db($qi_config['db_prefix'] . $dbname);
        }
        // include install lang fom phpbb
        qi::add_lang('install', $phpbb_root_path . 'language/' . $qi_config['default_lang'] . '/');
        // perform sql
        load_schema($phpbb_root_path . 'install/schemas/', $dbms);
        $current_time = time();
        $user_ip = !empty($_SERVER['REMOTE_ADDR']) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : '';
        $script_path = !empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
        if (!$script_path) {
            $script_path = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI');
        }
        // Replace backslashes and doubled slashes (could happen on some proxy setups)
        $script_path = str_replace(array('\\', '//'), '/', $script_path);
        $script_path = trim(dirname($script_path));
        // add the dbname to script path
        $script_path .= '/boards/' . $dbname;
        $config_ary = array('board_startdate' => $current_time, 'default_lang' => $qi_config['default_lang'], 'server_name' => $qi_config['server_name'], 'server_port' => $qi_config['server_port'], 'board_email' => $qi_config['board_email'], 'board_contact' => $qi_config['board_email'], 'cookie_domain' => $qi_config['cookie_domain'], 'default_dateformat' => $user->lang['default_dateformat'], 'email_enable' => $qi_config['email_enable'], 'smtp_delivery' => $qi_config['smtp_delivery'], 'smtp_host' => $qi_config['smtp_host'], 'smtp_auth_method' => $qi_config['smtp_auth'], 'smtp_username' => $qi_config['smtp_user'], 'smtp_password' => $qi_config['smtp_pass'], 'cookie_secure' => $qi_config['cookie_secure'], 'script_path' => $script_path, 'server_protocol' => !empty($qi_config['server_protocol']) ? $qi_config['server_protocol'] : 'http://', 'newest_username' => $qi_config['admin_name'], 'avatar_salt' => md5(mt_rand()), 'cookie_name' => 'phpbb3_' . strtolower(gen_rand_string(5)));
        if (@extension_loaded('gd') || can_load_dll('gd')) {
            $config_ary['captcha_gd'] = 1;
        }
        foreach ($config_ary as $config_name => $config_value) {
            set_config($config_name, $config_value);
        }
        // Set default config and post data, this applies to all DB's
        $sql_ary = array("UPDATE {$table_prefix}users\n\t\t\t\tSET username = '******'admin_name']) . "', user_password='******'admin_pass'])) . "', user_ip = '" . $db->sql_escape($user_ip) . "', user_lang = '" . $db->sql_escape($qi_config['default_lang']) . "', user_email='" . $db->sql_escape($qi_config['board_email']) . "', user_dateformat='" . $db->sql_escape($user->lang['default_dateformat']) . "', user_email_hash = " . (crc32($qi_config['board_email']) . strlen($qi_config['board_email'])) . ", username_clean = '" . $db->sql_escape(utf8_clean_string($qi_config['admin_name'])) . "'\n\t\t\t\tWHERE username = '******'", "UPDATE {$table_prefix}moderator_cache\n\t\t\t\tSET username = '******'admin_name']) . "'\n\t\t\t\tWHERE username = '******'", "UPDATE {$table_prefix}forums\n\t\t\t\tSET forum_last_poster_name = '" . $db->sql_escape($qi_config['admin_name']) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", "UPDATE {$table_prefix}topics\n\t\t\t\tSET topic_first_poster_name = '" . $db->sql_escape($qi_config['admin_name']) . "', topic_last_poster_name = '" . $db->sql_escape($qi_config['admin_name']) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", "UPDATE {$table_prefix}users\n\t\t\t\tSET user_regdate = {$current_time}", "UPDATE {$table_prefix}posts\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $db->sql_escape($user_ip) . "'", "UPDATE {$table_prefix}topics\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", "UPDATE {$table_prefix}forums\n\t\t\t\tSET forum_last_post_time = {$current_time}", "UPDATE {$table_prefix}config\n\t\t\t\tSET config_value = '" . $db->sql_escape($qi_config['site_name']) . "'\n\t\t\t\tWHERE config_name = 'sitename'", "UPDATE {$table_prefix}config\n\t\t\t\tSET config_value = '" . $db->sql_escape($qi_config['site_desc']) . "'\n\t\t\t\tWHERE config_name = 'site_desc'", "UPDATE {$table_prefix}config\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'load_tplcompile'");
        foreach ($sql_ary as $sql) {
            if (!$db->sql_query($sql)) {
                $error = $db->sql_error();
                trigger_error($error['message']);
            }
        }
        // main sql is done, let's get a fresh $config array
        $sql = 'SELECT *
			FROM ' . CONFIG_TABLE;
        $result = $db->sql_query($sql);
        $config = array();
        while ($row = $db->sql_fetchrow($result)) {
            $config[$row['config_name']] = $row['config_value'];
        }
        $db->sql_freeresult($result);
        // no templates though :P
        $config['load_tplcompile'] = '1';
        // build search index
        include_once $phpbb_root_path . 'includes/search/fulltext_native.' . $phpEx;
        $search = new fulltext_native($error = false);
        $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
			FROM ' . POSTS_TABLE;
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
        }
        $db->sql_freeresult($result);
        // extended phpbb install script
        include $phpbb_root_path . 'install/install_install.' . $phpEx;
        include $quickinstall_path . 'includes/install_install_qi.' . $phpEx;
        $install = new install_install_qi($p_master = new p_master_dummy());
        $install->set_data(array('dbms' => $dbms, 'dbhost' => $qi_config['dbhost'], 'dbport' => $qi_config['dbport'], 'dbuser' => $qi_config['dbuser'], 'dbpasswd' => $qi_config['dbpasswd'], 'dbname' => $dbname, 'table_prefix' => $table_prefix, 'default_lang' => $qi_config['default_lang'], 'admin_name' => $qi_config['admin_name'], 'admin_pass1' => $qi_config['admin_pass'], 'admin_pass2' => $qi_config['admin_pass'], 'board_email1' => $qi_config['board_email'], 'board_email2' => $qi_config['board_email'], 'email_enable' => $qi_config['email_enable'], 'smtp_delivery' => $qi_config['smtp_delivery'], 'smtp_host' => $qi_config['smtp_host'], 'smtp_auth' => $qi_config['smtp_auth'], 'smtp_user' => $qi_config['smtp_user'], 'smtp_pass' => $qi_config['smtp_pass'], 'cookie_secure' => $qi_config['cookie_secure'], 'server_protocol' => !empty($qi_config['server_protocol']) ? $qi_config['server_protocol'] : 'http://', 'server_name' => $qi_config['server_name'], 'server_port' => $qi_config['server_port'], 'script_path' => $script_path));
        $install->add_modules(false, false);
        $install->add_language(false, false);
        $install->add_bots(false, false);
        // login
        $user->session_begin();
        $auth->login($qi_config['admin_name'], $qi_config['admin_pass'], false, true, true);
        // now automod (easymod)
        if ($automod) {
            include $quickinstall_path . 'includes/functions_install_automod.' . $phpEx;
            automod_installer::install_automod($board_dir, $make_writable);
        }
        if ($dbms == 'sqlite' || $dbms == 'firebird') {
            // copy the temp db over
            file_functions::copy_file($quickinstall_path . 'cache/' . $qi_config['db_prefix'] . $dbname, $board_dir . $qi_config['db_prefix'] . $dbname);
            $db->sql_select_db($board_dir . $qi_config['db_prefix'] . $dbname);
        }
        // clean up
        file_functions::delete_files($board_dir, array('Thumbs.db', 'DS_Store', 'CVS', '.svn', '.git'));
        // remove install dir, develop and umil
        file_functions::delete_dir($board_dir . 'install/');
        file_functions::delete_dir($board_dir . 'develop/');
        file_functions::delete_dir($board_dir . 'umil/');
        // copy extra user added files
        file_functions::copy_dir($quickinstall_path . 'sources/extra/', $board_dir);
        // Install Subsilver2
        if ($subsilver) {
            if (!class_exists('bitfield')) {
                include $phpbb_root_path . 'includes/functions_content.' . $phpEx;
            }
            include $phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx;
            $acp_styles = new acp_styles();
            $acp_styles->main(0, '');
            // Mostly copied from includes/acp/acp_styles.php
            $reqd_template = $reqd_theme = $reqd_imageset = false;
            $error = $installcfg = $style_row = array();
            $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE);
            $install_path = 'subsilver2';
            $root_path = $phpbb_root_path . 'styles/subsilver2/';
            $cfg_file = $root_path . 'style.cfg';
            $installcfg = parse_cfg_file($cfg_file);
            if (!sizeof($installcfg)) {
                continue;
            }
            $name = $installcfg['name'];
            $copyright = $installcfg['copyright'];
            $version = $installcfg['version'];
            $style_row = array('style_id' => 0, 'template_id' => 0, 'theme_id' => 0, 'imageset_id' => 0, 'style_name' => $installcfg['name'], 'template_name' => $installcfg['name'], 'theme_name' => $installcfg['name'], 'imageset_name' => $installcfg['name'], 'template_copyright' => $installcfg['copyright'], 'theme_copyright' => $installcfg['copyright'], 'imageset_copyright' => $installcfg['copyright'], 'style_copyright' => $installcfg['copyright'], 'store_db' => 0, 'style_active' => 1, 'style_default' => $subsilver == 2 ? 1 : 0);
            $acp_styles->install_style($error, 'install', $root_path, $style_row['style_id'], $style_row['style_name'], $install_path, $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row);
            unset($error);
        }
        // Add some random users and posts.
        if ($populate) {
            include $quickinstall_path . 'includes/functions_populate.' . $phpEx;
            new populate($pop_data);
        }
        // add log entry :D
        $user->ip =& $user_ip;
        add_log('admin', 'LOG_INSTALL_INSTALLED_QI', $qi_config['qi_version']);
        // purge cache
        $cache->purge();
        // Make all files world writable.
        if ($make_writable) {
            file_functions::make_writable($board_dir);
        }
        // if he wants to be redirected, redirect him
        if ($redirect) {
            qi::redirect($board_dir);
        }
        // On succces just return to main page.
        qi::redirect('index.' . $phpEx);
    }
    /**
     * Setup basic user-specific items (style, language, ...)
     */
    function setup($lang_set = false, $style = false)
    {
        global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache;
        if ($this->data['user_id'] != ANONYMOUS) {
            $this->lang_name = file_exists($this->lang_path . $this->data['user_lang'] . "/common.{$phpEx}") ? $this->data['user_lang'] : basename($config['default_lang']);
            $this->date_format = $this->data['user_dateformat'];
            $this->timezone = $this->data['user_timezone'] * 3600;
            $this->dst = $this->data['user_dst'] * 3600;
        } else {
            $this->lang_name = basename($config['default_lang']);
            $this->date_format = $config['default_dateformat'];
            $this->timezone = $config['board_timezone'] * 3600;
            $this->dst = $config['board_dst'] * 3600;
            /**
            * If a guest user is surfing, we try to guess his/her language first by obtaining the browser language
            * If re-enabled we need to make sure only those languages installed are checked
            * Commented out so we do not loose the code.
            
            if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
            {
            	$accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
            
            	foreach ($accept_lang_ary as $accept_lang)
            	{
            		// Set correct format ... guess full xx_YY form
            		$accept_lang = substr($accept_lang, 0, 2) . '_' . strtoupper(substr($accept_lang, 3, 2));
            		$accept_lang = basename($accept_lang);
            
            		if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
            		{
            			$this->lang_name = $config['default_lang'] = $accept_lang;
            			break;
            		}
            		else
            		{
            			// No match on xx_YY so try xx
            			$accept_lang = substr($accept_lang, 0, 2);
            			$accept_lang = basename($accept_lang);
            
            			if (file_exists($this->lang_path . $accept_lang . "/common.$phpEx"))
            			{
            				$this->lang_name = $config['default_lang'] = $accept_lang;
            				break;
            			}
            		}
            	}
            }
            */
        }
        // We include common language file here to not load it every time a custom language file is included
        $lang =& $this->lang;
        // Do not suppress error if in DEBUG_EXTRA mode
        $include_result = defined('DEBUG_EXTRA') ? include $this->lang_path . $this->lang_name . "/common.{$phpEx}" : @(include $this->lang_path . $this->lang_name . "/common.{$phpEx}");
        if ($include_result === false) {
            die('Language file ' . $this->lang_path . $this->lang_name . "/common.{$phpEx}" . " couldn't be opened.");
        }
        $this->add_lang($lang_set);
        unset($lang_set);
        if (!empty($_GET['style']) && $auth->acl_get('a_styles') && !defined('ADMIN_START')) {
            global $SID, $_EXTRA_URL;
            $style = request_var('style', 0);
            $SID .= '&amp;style=' . $style;
            $_EXTRA_URL = array('style=' . $style);
        } else {
            // Set up style
            $style = $style ? $style : (!$config['override_user_style'] ? $this->data['user_style'] : $config['default_style']);
        }
        $sql = 'SELECT s.style_id, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name
			FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i\n\t\t\tWHERE s.style_id = {$style}\n\t\t\t\tAND t.template_id = s.template_id\n\t\t\t\tAND c.theme_id = s.theme_id\n\t\t\t\tAND i.imageset_id = s.imageset_id";
        $result = $db->sql_query($sql, 3600);
        $this->theme = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        // User has wrong style
        if (!$this->theme && $style == $this->data['user_style']) {
            $style = $this->data['user_style'] = $config['default_style'];
            $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\tSET user_style = {$style}\n\t\t\t\tWHERE user_id = {$this->data['user_id']}";
            $db->sql_query($sql);
            $sql = 'SELECT s.style_id, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name
				FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i\n\t\t\t\tWHERE s.style_id = {$style}\n\t\t\t\t\tAND t.template_id = s.template_id\n\t\t\t\t\tAND c.theme_id = s.theme_id\n\t\t\t\t\tAND i.imageset_id = s.imageset_id";
            $result = $db->sql_query($sql, 3600);
            $this->theme = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
        }
        if (!$this->theme) {
            trigger_error('Could not get style data', E_USER_ERROR);
        }
        // Now parse the cfg file and cache it
        $parsed_items = $cache->obtain_cfg_items($this->theme);
        // We are only interested in the theme configuration for now
        $parsed_items = $parsed_items['theme'];
        $check_for = array('parse_css_file' => (int) 0, 'pagination_sep' => (string) ', ');
        foreach ($check_for as $key => $default_value) {
            $this->theme[$key] = isset($parsed_items[$key]) ? $parsed_items[$key] : $default_value;
            settype($this->theme[$key], gettype($default_value));
            if (is_string($default_value)) {
                $this->theme[$key] = htmlspecialchars($this->theme[$key]);
            }
        }
        // If the style author specified the theme needs to be cached
        // (because of the used paths and variables) than make sure it is the case.
        // For example, if the theme uses language-specific images it needs to be stored in db.
        if (!$this->theme['theme_storedb'] && $this->theme['parse_css_file']) {
            $this->theme['theme_storedb'] = 1;
            $stylesheet = file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/stylesheet.css");
            // Match CSS imports
            $matches = array();
            preg_match_all('/@import url\\(["\'](.*)["\']\\);/i', $stylesheet, $matches);
            if (sizeof($matches)) {
                $content = '';
                foreach ($matches[0] as $idx => $match) {
                    if ($content = @file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/" . $matches[1][$idx])) {
                        $content = trim($content);
                    } else {
                        $content = '';
                    }
                    $stylesheet = str_replace($match, $content, $stylesheet);
                }
                unset($content);
            }
            $stylesheet = str_replace('./', 'styles/' . $this->theme['theme_path'] . '/theme/', $stylesheet);
            $sql_ary = array('theme_data' => $stylesheet, 'theme_mtime' => time(), 'theme_storedb' => 1);
            $sql = 'UPDATE ' . STYLES_THEME_TABLE . '
				SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
				WHERE theme_id = ' . $this->theme['theme_id'];
            $db->sql_query($sql);
            unset($sql_ary);
        }
        $template->set_template();
        $this->img_lang = file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . $this->lang_name) ? $this->lang_name : $config['default_lang'];
        // Same query in style.php
        $sql = 'SELECT *
			FROM ' . STYLES_IMAGESET_DATA_TABLE . '
			WHERE imageset_id = ' . $this->theme['imageset_id'] . "\n\t\t\tAND image_filename <> ''\n\t\t\tAND image_lang IN ('" . $db->sql_escape($this->img_lang) . "', '')";
        $result = $db->sql_query($sql, 3600);
        $localised_images = false;
        while ($row = $db->sql_fetchrow($result)) {
            if ($row['image_lang']) {
                $localised_images = true;
            }
            $row['image_filename'] = rawurlencode($row['image_filename']);
            $this->img_array[$row['image_name']] = $row;
        }
        $db->sql_freeresult($result);
        // there were no localised images, try to refresh the localised imageset for the user's language
        if (!$localised_images) {
            // Attention: this code ignores the image definition list from acp_styles and just takes everything
            // that the config file contains
            $sql_ary = array();
            $db->sql_transaction('begin');
            $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
				WHERE imageset_id = ' . $this->theme['imageset_id'] . '
					AND image_lang = \'' . $db->sql_escape($this->img_lang) . '\'';
            $result = $db->sql_query($sql);
            if (@file_exists("{$phpbb_root_path}styles/{$this->theme['imageset_path']}/imageset/{$this->img_lang}/imageset.cfg")) {
                $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$this->theme['imageset_path']}/imageset/{$this->img_lang}/imageset.cfg");
                foreach ($cfg_data_imageset_data as $image_name => $value) {
                    if (strpos($value, '*') !== false) {
                        if (substr($value, -1, 1) === '*') {
                            list($image_filename, $image_height) = explode('*', $value);
                            $image_width = 0;
                        } else {
                            list($image_filename, $image_height, $image_width) = explode('*', $value);
                        }
                    } else {
                        $image_filename = $value;
                        $image_height = $image_width = 0;
                    }
                    if (strpos($image_name, 'img_') === 0 && $image_filename) {
                        $image_name = substr($image_name, 4);
                        $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $this->theme['imageset_id'], 'image_lang' => (string) $this->img_lang);
                    }
                }
            }
            if (sizeof($sql_ary)) {
                $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
                $db->sql_transaction('commit');
                $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
                add_log('admin', 'LOG_IMAGESET_LANG_REFRESHED', $this->theme['imageset_name'], $this->img_lang);
            } else {
                $db->sql_transaction('commit');
                add_log('admin', 'LOG_IMAGESET_LANG_MISSING', $this->theme['imageset_name'], $this->img_lang);
            }
        }
        // Call phpbb_user_session_handler() in case external application want to "bend" some variables or replace classes...
        // After calling it we continue script execution...
        phpbb_user_session_handler();
        // If this function got called from the error handler we are finished here.
        if (defined('IN_ERROR_HANDLER')) {
            return;
        }
        // Disable board if the install/ directory is still present
        // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally
        if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) {
            // Adjust the message slightly according to the permissions
            if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) {
                $message = 'REMOVE_INSTALL';
            } else {
                $message = !empty($config['board_disable_msg']) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
            }
            trigger_error($message);
        }
        // Is board disabled and user not an admin or moderator?
        if ($config['board_disable'] && !defined('IN_LOGIN') && !$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) {
            if ($this->data['is_bot']) {
                send_status_line(503, 'Service Unavailable');
            }
            $message = !empty($config['board_disable_msg']) ? $config['board_disable_msg'] : 'BOARD_DISABLE';
            trigger_error($message);
        }
        // Is load exceeded?
        if ($config['limit_load'] && $this->load !== false) {
            if ($this->load > floatval($config['limit_load']) && !defined('IN_LOGIN') && !defined('IN_ADMIN')) {
                // Set board disabled to true to let the admins/mods get the proper notification
                $config['board_disable'] = '1';
                if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) {
                    if ($this->data['is_bot']) {
                        send_status_line(503, 'Service Unavailable');
                    }
                    trigger_error('BOARD_UNAVAILABLE');
                }
            }
        }
        if (isset($this->data['session_viewonline'])) {
            // Make sure the user is able to hide his session
            if (!$this->data['session_viewonline']) {
                // Reset online status if not allowed to hide the session...
                if (!$auth->acl_get('u_hideonline')) {
                    $sql = 'UPDATE ' . SESSIONS_TABLE . '
						SET session_viewonline = 1
						WHERE session_user_id = ' . $this->data['user_id'];
                    $db->sql_query($sql);
                    $this->data['session_viewonline'] = 1;
                }
            } else {
                if (!$this->data['user_allow_viewonline']) {
                    // the user wants to hide and is allowed to  -> cloaking device on.
                    if ($auth->acl_get('u_hideonline')) {
                        $sql = 'UPDATE ' . SESSIONS_TABLE . '
						SET session_viewonline = 0
						WHERE session_user_id = ' . $this->data['user_id'];
                        $db->sql_query($sql);
                        $this->data['session_viewonline'] = 0;
                    }
                }
            }
        }
        // Does the user need to change their password? If so, redirect to the
        // ucp profile reg_details page ... of course do not redirect if we're already in the ucp
        if (!defined('IN_ADMIN') && !defined('ADMIN_START') && $config['chg_passforce'] && !empty($this->data['is_registered']) && $auth->acl_get('u_chgpasswd') && $this->data['user_passchg'] < time() - $config['chg_passforce'] * 86400) {
            if (strpos($this->page['query_string'], 'mode=reg_details') === false && $this->page['page_name'] != "ucp.{$phpEx}") {
                redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=profile&amp;mode=reg_details'));
            }
        }
        // [+] Karma MOD
        if (!class_exists('karmamod')) {
            require $phpbb_root_path . 'includes/functions_karma.' . $phpEx;
        }
        global $karmamod;
        $karmamod = new karmamod();
        // [-] Karma MOD
        return;
    }
Exemplo n.º 10
0
    /**
     * Install a style on the demo board.
     *
     * @param string $phpbb_root_path
     * @param mixed contrib object
     */
    public function install_demo_style($phpbb_root_path, $contrib)
    {
        phpbb::$user->add_lang('acp/styles');
        if ($phpbb_root_path[strlen($phpbb_root_path) - 1] != '/') {
            $phpbb_root_path .= '/';
        }
        if (!is_dir($phpbb_root_path) || !file_exists($phpbb_root_path . 'config.' . PHP_EXT)) {
            $this->error[] = 'PATH_INVALID';
            return false;
        }
        include $phpbb_root_path . 'config.' . PHP_EXT;
        $sql_db = !empty($dbms) ? 'dbal_' . basename($dbms) : 'dbal';
        // Is this DBAL loaded?
        phpbb::_include('db/' . $dbms, false, $sql_db);
        // Instantiate DBAL class
        $db = new $sql_db();
        // Connect to demo board DB
        $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport);
        // We do not need this any longer, unset for safety purposes
        unset($dbpasswd);
        if (empty($this->unzip_dir)) {
            // Extract zip.
            $this->unzip_dir = titania::$config->contrib_temp_path . basename($this->original_zip, 'zip') . '/';
            // Clear out old stuff if there is anything here...
            $this->rmdir_recursive($this->unzip_dir);
            // Unzip to our temp directory
            $this->extract($this->original_zip, $this->unzip_dir);
        }
        $package_root = $this->find_root(false, 'style.cfg');
        $stylecfg = parse_cfg_file($this->unzip_dir . $package_root . '/style.cfg');
        $style_root = $phpbb_root_path . 'styles/' . $contrib->contrib_id . '/';
        $this->mvdir_recursive($this->unzip_dir . $package_root, $style_root, false);
        $this->rmdir_recursive($this->unzip_dir);
        $variables = array('db', 'phpbb_root_path');
        // Let's get lazy.
        foreach ($variables as $variable) {
            ${'_' . $variable} = $GLOBALS[$variable];
            $GLOBALS[$variable] = ${$variable};
        }
        // Get the acp_styles class.
        phpbb::_include('acp/acp_styles', false, 'acp_styles');
        if (!defined('TEMPLATE_BITFIELD')) {
            // Hardcoded template bitfield to add for new templates
            $bitfield = new bitfield();
            $bitfield->set(0);
            $bitfield->set(1);
            $bitfield->set(2);
            $bitfield->set(3);
            $bitfield->set(4);
            $bitfield->set(8);
            $bitfield->set(9);
            $bitfield->set(11);
            $bitfield->set(12);
            define('TEMPLATE_BITFIELD', $bitfield->get_base64());
            unset($bitfield);
        }
        $styles = new acp_styles();
        // Fill the configuration variables
        $styles->style_cfg = $styles->template_cfg = $styles->theme_cfg = $styles->imageset_cfg = '
#
# phpBB {MODE} configuration file
#
# @package phpBB3
# @copyright (c) 2005 phpBB Group
# @license http://opensource.org/licenses/gpl-license.php GNU Public License
#
#
# At the left is the name, please do not change this
# At the right the value is entered
# For on/off options the valid values are on, off, 1, 0, true and false
#
# Values get trimmed, if you want to add a space in front or at the end of
# the value, then enclose the value with single or double quotes.
# Single and double quotes do not need to be escaped.
#
#

# General Information about this {MODE}
name = {NAME}
copyright = {COPYRIGHT}
version = {VERSION}
';
        $styles->theme_cfg .= '
# Some configuration options

#
# You have to turn this option on if you want to use the
# path template variables ({T_IMAGESET_PATH} for example) within
# your css file.
# This is mostly the case if you want to use language specific
# images within your css file.
#
parse_css_file = {PARSE_CSS_FILE}
';
        $styles->template_cfg .= '
# Some configuration options

#
# You can use this function to inherit templates from another template.
# The template of the given name has to be installed.
# Templates cannot inherit from inheriting templates.
#';
        $styles->imageset_keys = array('logos' => array('site_logo'), 'buttons' => array('icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply'), 'icons' => array('icon_post_target', 'icon_post_target_unread', 'icon_topic_attach', 'icon_topic_latest', 'icon_topic_newest', 'icon_topic_reported', 'icon_topic_unapproved', 'icon_friend', 'icon_foe'), 'forums' => array('forum_link', 'forum_read', 'forum_read_locked', 'forum_read_subforum', 'forum_unread', 'forum_unread_locked', 'forum_unread_subforum', 'subforum_read', 'subforum_unread'), 'folders' => array('topic_moved', 'topic_read', 'topic_read_mine', 'topic_read_hot', 'topic_read_hot_mine', 'topic_read_locked', 'topic_read_locked_mine', 'topic_unread', 'topic_unread_mine', 'topic_unread_hot', 'topic_unread_hot_mine', 'topic_unread_locked', 'topic_unread_locked_mine', 'sticky_read', 'sticky_read_mine', 'sticky_read_locked', 'sticky_read_locked_mine', 'sticky_unread', 'sticky_unread_mine', 'sticky_unread_locked', 'sticky_unread_locked_mine', 'announce_read', 'announce_read_mine', 'announce_read_locked', 'announce_read_locked_mine', 'announce_unread', 'announce_unread_mine', 'announce_unread_locked', 'announce_unread_locked_mine', 'global_read', 'global_read_mine', 'global_read_locked', 'global_read_locked_mine', 'global_unread', 'global_unread_mine', 'global_unread_locked', 'global_unread_locked_mine', 'pm_read', 'pm_unread'), 'polls' => array('poll_left', 'poll_center', 'poll_right'), 'ui' => array('upload_bar'), 'user' => array('user_icon1', 'user_icon2', 'user_icon3', 'user_icon4', 'user_icon5', 'user_icon6', 'user_icon7', 'user_icon8', 'user_icon9', 'user_icon10'));
        // Define references.
        $error = array();
        $style_id = 0;
        $style_row = array('install_name' => $stylecfg['name'], 'install_copyright' => $stylecfg['copyright'], 'template_id' => 0, 'template_name' => $stylecfg['name'], 'template_copyright' => $stylecfg['copyright'], 'theme_id' => 0, 'theme_name' => $stylecfg['name'], 'theme_copyright' => $stylecfg['copyright'], 'imageset_id' => 0, 'imageset_name' => $stylecfg['name'], 'imageset_copyright' => $stylecfg['copyright'], 'store_db' => 0, 'style_active' => 1, 'style_default' => 0);
        // Install the style.
        // (&$error, $action, $root_path, &$id, $name, $path, $copyright, $active, $default, &$style_row, $template_root_path = false, $template_path = false, $theme_root_path = false, $theme_path = false, $imageset_root_path = false, $imageset_path = false)
        if (!$styles->install_style($error, 'install', $style_root, $style_id, $stylecfg['name'], $contrib->contrib_id, $stylecfg['copyright'], true, false, $style_row)) {
            if ($error != array(phpbb::$user->lang['STYLE_ERR_NAME_EXIST'])) {
                $this->error = array_merge($this->error, $error);
            } else {
                $sql = 'SELECT style_id
					FROM ' . STYLES_TABLE . "\n\t\t\t\t\tWHERE style_name = '" . $db->sql_escape(basename($stylecfg['name'])) . "'";
                $db->sql_query($sql);
                $style_id = $db->sql_fetchfield('style_id');
                $db->sql_freeresult();
            }
        }
        // Have UMIL refresh the template, theme, imageset
        phpbb::_include('../umil/umil', false, 'umil');
        $umil = new umil(true, $db);
        $umil->cache_purge('template', $style_id);
        $umil->cache_purge('theme', $style_id);
        $umil->cache_purge('imageset', $style_id);
        foreach ($variables as $variable) {
            $GLOBALS[$variable] = ${'_' . $variable};
        }
        return $style_id;
    }
Exemplo n.º 11
0
    /**
     * Cache Purge
     *
     * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache.
     *
     * @param string $type The type of cache you want purged.  Available types: auth, imageset, template, theme.  Anything else sent will purge the forum's cache.
     * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section)
     */
    function cache_purge($type = '', $style_id = 0)
    {
        global $auth, $cache, $user, $phpbb_root_path, $phpEx;
        // Multicall
        if (is_array($type)) {
            if (!empty($type)) {
                foreach ($type as $params) {
                    call_user_func_array(array($this, 'cache_purge'), $params);
                }
                return;
            }
        }
        $style_id = (int) $style_id;
        $type = (string) $type;
        // Prevent PHP bug.
        switch ($type) {
            case 'auth':
                $this->umil_start('AUTH_CACHE_PURGE');
                $cache->destroy('_acl_options');
                $auth->acl_clear_prefetch();
                return $this->umil_end();
                break;
            case 'imageset':
                if ($style_id == 0) {
                    $return = array();
                    $sql = 'SELECT imageset_id
						FROM ' . STYLES_IMAGESET_TABLE;
                    $result = $this->db->sql_query($sql);
                    while ($row = $this->db->sql_fetchrow($result)) {
                        $return[] = $this->cache_purge('imageset', $row['imageset_id']);
                    }
                    $this->db->sql_freeresult($result);
                    return implode('<br /><br />', $return);
                } else {
                    $sql = 'SELECT *
						FROM ' . STYLES_IMAGESET_TABLE . "\n\t\t\t\t\t\tWHERE imageset_id = {$style_id}";
                    $result = $this->db->sql_query($sql);
                    $imageset_row = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    if (!$imageset_row) {
                        $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN');
                        return $this->umil_end('FAIL');
                    }
                    $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']);
                    // The following is from includes/acp/acp_styles.php (edited)
                    $sql_ary = array();
                    $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg");
                    $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
						WHERE imageset_id = ' . $style_id;
                    $result = $this->db->sql_query($sql);
                    foreach ($cfg_data_imageset as $image_name => $value) {
                        if (strpos($value, '*') !== false) {
                            if (substr($value, -1, 1) === '*') {
                                list($image_filename, $image_height) = explode('*', $value);
                                $image_width = 0;
                            } else {
                                list($image_filename, $image_height, $image_width) = explode('*', $value);
                            }
                        } else {
                            $image_filename = $value;
                            $image_height = $image_width = 0;
                        }
                        if (strpos($image_name, 'img_') === 0 && $image_filename) {
                            $image_name = substr($image_name, 4);
                            $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $style_id, 'image_lang' => '');
                        }
                    }
                    $sql = 'SELECT lang_dir
						FROM ' . LANG_TABLE;
                    $result = $this->db->sql_query($sql);
                    while ($row = $this->db->sql_fetchrow($result)) {
                        if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) {
                            $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg");
                            foreach ($cfg_data_imageset_data as $image_name => $value) {
                                if (strpos($value, '*') !== false) {
                                    if (substr($value, -1, 1) === '*') {
                                        list($image_filename, $image_height) = explode('*', $value);
                                        $image_width = 0;
                                    } else {
                                        list($image_filename, $image_height, $image_width) = explode('*', $value);
                                    }
                                } else {
                                    $image_filename = $value;
                                    $image_height = $image_width = 0;
                                }
                                if (strpos($image_name, 'img_') === 0 && $image_filename) {
                                    $image_name = substr($image_name, 4);
                                    $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $style_id, 'image_lang' => (string) $row['lang_dir']);
                                }
                            }
                        }
                    }
                    $this->db->sql_freeresult($result);
                    $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
                    $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
                    return $this->umil_end();
                }
                break;
                //case 'imageset' :
            //case 'imageset' :
            case 'template':
                if ($style_id == 0) {
                    $return = array();
                    $sql = 'SELECT template_id
						FROM ' . STYLES_TEMPLATE_TABLE;
                    $result = $this->db->sql_query($sql);
                    while ($row = $this->db->sql_fetchrow($result)) {
                        $return[] = $this->cache_purge('template', $row['template_id']);
                    }
                    $this->db->sql_freeresult($result);
                    return implode('<br /><br />', $return);
                } else {
                    $sql = 'SELECT *
						FROM ' . STYLES_TEMPLATE_TABLE . "\n\t\t\t\t\t\tWHERE template_id = {$style_id}";
                    $result = $this->db->sql_query($sql);
                    $template_row = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    if (!$template_row) {
                        $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN');
                        return $this->umil_end('FAIL');
                    }
                    $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']);
                    // The following is from includes/acp/acp_styles.php
                    if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) {
                        $filelist = array('' => array());
                        $sql = 'SELECT template_filename, template_mtime
							FROM ' . STYLES_TEMPLATE_DATA_TABLE . "\n\t\t\t\t\t\t\tWHERE template_id = {$style_id}";
                        $result = $this->db->sql_query($sql);
                        while ($row = $this->db->sql_fetchrow($result)) {
                            //							if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime'])
                            //							{
                            // get folder info from the filename
                            if (($slash_pos = strrpos($row['template_filename'], '/')) === false) {
                                $filelist[''][] = $row['template_filename'];
                            } else {
                                $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1);
                            }
                            //							}
                        }
                        $this->db->sql_freeresult($result);
                        $includes = array();
                        foreach ($filelist as $pathfile => $file_ary) {
                            foreach ($file_ary as $file) {
                                if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}{$pathfile}{$file}", 'r'))) {
                                    return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}{$pathfile}{$file}");
                                }
                                $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}{$pathfile}{$file}"));
                                fclose($fp);
                                if (preg_match_all('#<!-- INCLUDE (.*?\\.html) -->#is', $template_data, $matches)) {
                                    foreach ($matches[1] as $match) {
                                        $includes[trim($match)][] = $file;
                                    }
                                }
                            }
                        }
                        foreach ($filelist as $pathfile => $file_ary) {
                            foreach ($file_ary as $file) {
                                // Skip index.
                                if (strpos($file, 'index.') === 0) {
                                    continue;
                                }
                                // We could do this using extended inserts ... but that could be one
                                // heck of a lot of data ...
                                $sql_ary = array('template_id' => (int) $style_id, 'template_filename' => "{$pathfile}{$file}", 'template_included' => isset($includes[$file]) ? implode(':', $includes[$file]) . ':' : '', 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}{$pathfile}{$file}"), 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}{$pathfile}{$file}"));
                                $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\t\tWHERE template_id = {$style_id}\n\t\t\t\t\t\t\t\t\t\tAND template_filename = '" . $this->db->sql_escape("{$pathfile}{$file}") . "'";
                                $this->db->sql_query($sql);
                            }
                        }
                        unset($filelist);
                    }
                    return $this->umil_end();
                }
                break;
                //case 'template' :
            //case 'template' :
            case 'theme':
                if ($style_id == 0) {
                    $return = array();
                    $sql = 'SELECT theme_id
						FROM ' . STYLES_THEME_TABLE;
                    $result = $this->db->sql_query($sql);
                    while ($row = $this->db->sql_fetchrow($result)) {
                        $return[] = $this->cache_purge('theme', $row['theme_id']);
                    }
                    $this->db->sql_freeresult($result);
                    return implode('<br /><br />', $return);
                } else {
                    $sql = 'SELECT *
						FROM ' . STYLES_THEME_TABLE . "\n\t\t\t\t\t\tWHERE theme_id = {$style_id}";
                    $result = $this->db->sql_query($sql);
                    $theme_row = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    if (!$theme_row) {
                        $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN');
                        return $this->umil_end('FAIL');
                    }
                    $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']);
                    // The following is from includes/acp/acp_styles.php
                    if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) {
                        $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css');
                        // Match CSS imports
                        $matches = array();
                        preg_match_all('/@import url\\(["\'](.*)["\']\\);/i', $stylesheet, $matches);
                        if (sizeof($matches)) {
                            foreach ($matches[0] as $idx => $match) {
                                $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}"));
                                $stylesheet = str_replace($match, $content, $stylesheet);
                            }
                        }
                        // adjust paths
                        $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet);
                        // Save CSS contents
                        $sql_ary = array('theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), 'theme_data' => $db_theme_data);
                        $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE theme_id = {$style_id}";
                        $this->db->sql_query($sql);
                        $cache->destroy('sql', STYLES_THEME_TABLE);
                    }
                    return $this->umil_end();
                }
                break;
                //case 'theme' :
            //case 'theme' :
            default:
                $this->umil_start('CACHE_PURGE');
                $cache->purge();
                return $this->umil_end();
                break;
        }
    }
Exemplo n.º 12
0
 /**
  * Read style configuration file
  *
  * @param string $dir style directory
  * @return array|bool Style data, false on error
  */
 function read_style_cfg($dir)
 {
     static $required = array('name', 'phpbb_version', 'copyright');
     $cfg = @parse_cfg_file($dir);
     // Check if it is a valid file
     foreach ($required as $key) {
         if (!isset($cfg[$key])) {
             return false;
         }
     }
     // Check data
     if (!isset($cfg['parent']) || !is_string($cfg['parent']) || $cfg['parent'] == $cfg['name']) {
         $cfg['parent'] = '';
     }
     if (!isset($cfg['template_bitfield'])) {
         //			$cfg['template_bitfield'] = $this->default_bitfield();
     }
     return $cfg;
 }
Exemplo n.º 13
0
 /**
  * @dataProvider parse_cfg_file_data
  */
 public function test_parse_cfg_file($file_contents, $expected)
 {
     $this->assertEquals($expected, parse_cfg_file(false, $file_contents));
 }
Exemplo n.º 14
0
 /**
  * Obtain cfg file data
  */
 function obtain_cfg_items($style)
 {
     $parsed_array = $this->driver->get('_cfg_' . $style['style_path']);
     if ($parsed_array === false) {
         $parsed_array = array();
     }
     $filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg';
     if (!file_exists($filename)) {
         return $parsed_array;
     }
     if (!isset($parsed_array['filetime']) || $this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']) {
         // Re-parse cfg file
         $parsed_array = parse_cfg_file($filename);
         $parsed_array['filetime'] = @filemtime($filename);
         $this->driver->put('_cfg_' . $style['style_path'], $parsed_array);
     }
     return $parsed_array;
 }
Exemplo n.º 15
0
 /**
  * Get component configuration from .cfg file.
  *
  * @param string $component		style|imageset|template|theme
  * @return array
  */
 protected function get_component_configuration($component)
 {
     $file = $component == 'style' ? 'style.cfg' : "{$component}/{$component}.cfg";
     $file = $this->root_path . 'styles/' . $this->style_dir . '/' . $file;
     return file_exists($file) ? parse_cfg_file($file) : array();
 }
Exemplo n.º 16
0
/**
 * The current active style doesn't have a directory. Lets look in the styles dir and find a valid style
 * @return unknown_type
 */
function critical_style_dir_repair()
{
	global $cache, $db, $umil;

	$dh = @opendir(PHPBB_ROOT_PATH . 'styles/');
	while (($fname = readdir($dh)) !== false)
	{
		if (!is_dir(PHPBB_ROOT_PATH . 'styles/' . $fname) || $fname[0] == '.')
		{
			continue;
		}

		if ($cfg = file(PHPBB_ROOT_PATH . "styles/$fname/style.cfg"))
		{
			$items = parse_cfg_file('', $cfg);
		}

		// A style folder *could* be renamed only take the first style of which the name in the style.cfg is the same as the directory.
		if ($items['name'] == $fname)
		{
			// Set this style as the default
			$sql = 'SELECT s.style_id
				FROM (' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . " t)
				WHERE t.template_path = '" . $db->sql_escape($fname) . "'
					AND s.template_id = t.template_id";
			$result = $db->sql_query($sql);
			$sid	= $db->sql_fetchfield('style_id', false, $result);
			$db->sql_freeresult($result);

			// Set default style
			set_config('default_style', $sid);
			closedir($dh);

			$cache->purge();
			$umil->cache_purge(array('template', 'theme', 'imageset'));

			return;
		}
	}
	closedir($dh);

	// Couldn't restore
	echo 'The support toolkit couldn\'t find an available style. Please seek further assistance in the support forums on http://www.phpbb.com';
	garbage_collection();
	exit_handler();
}
Exemplo n.º 17
0
 /**
  * Install/add an element, doing various checks as we go
  */
 function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright, $store_db = 0)
 {
     global $phpbb_root_path, $db, $user;
     switch ($mode) {
         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_type = strtoupper($mode);
     if (!$name) {
         $error[] = $user->lang[$l_type . '_ERR_STYLE_NAME'];
     }
     // Check length settings
     if (strlen($name) > 30) {
         $error[] = $user->lang[$l_type . '_ERR_NAME_LONG'];
     }
     if (strlen($copyright) > 60) {
         $error[] = $user->lang[$l_type . '_ERR_COPY_LONG'];
     }
     // Check if the name already exist
     $sql = "SELECT {$mode}_id\n\t\t\tFROM {$sql_from}\n\t\t\tWHERE {$mode}_name = '" . $db->sql_escape($name) . "'";
     $result = $db->sql_query($sql);
     $row = $db->sql_fetchrow($result);
     $db->sql_freeresult($result);
     if ($row) {
         // If it exist, we just use the stlye on installation
         if ($action == 'install') {
             $id = $row[$mode . '_id'];
             return false;
         }
         $error[] = $user->lang[$l_type . '_ERR_NAME_EXIST'];
     }
     if (sizeof($error)) {
         return false;
     }
     $sql_ary = array($mode . '_name' => $name, $mode . '_copyright' => $copyright, $mode . '_path' => $path);
     if ($mode != 'imageset') {
         switch ($mode) {
             case 'template':
                 // We set a pre-defined bitfield here which we may use further in 3.2
                 $sql_ary += array('bbcode_bitfield' => TEMPLATE_BITFIELD, 'template_storedb' => $store_db);
                 break;
             case 'theme':
                 $sql_ary += array('theme_storedb' => $store_db, 'theme_data' => $store_db ? $root_path ? $this->db_theme_data($sql_ary, false, $root_path) : '' : '', 'theme_mtime' => filemtime("{$phpbb_root_path}styles/{$path}/theme/stylesheet.css"));
                 break;
         }
     } else {
         $cfg_data = parse_cfg_file("{$root_path}{$mode}/imageset.cfg");
         foreach ($cfg_data as $key => $value) {
             if (strpos($key, 'img_') === 0) {
                 $key = substr($key, 4);
                 $sql_ary[$key] = str_replace('{PATH}', "styles/{$path}/imageset/", trim($value));
             }
         }
         unset($cfg_data);
     }
     $db->sql_transaction('begin');
     $sql = "INSERT INTO {$sql_from}\n\t\t\t" . $db->sql_build_array('INSERT', $sql_ary);
     $db->sql_query($sql);
     $id = $db->sql_nextid();
     if ($mode == 'template' && $store_db) {
         $filelist = filelist("{$root_path}template", '', 'html');
         $this->store_templates('insert', $id, $path, $filelist);
     }
     $db->sql_transaction('commit');
     $log = $store_db ? 'LOG_' . $l_type . '_ADD_DB' : 'LOG_' . $l_type . '_ADD_FS';
     add_log('admin', $log, $name);
     // Return store_db in case it had to be altered
     return $store_db;
 }
Exemplo n.º 18
0
 /**
  * Find style name
  * 
  * @param string $style Style directory
  * 
  * @return string Style name. Style directory is returned if function fails to read style name
  */
 protected function find_style_name($style)
 {
     $filename = $this->styles_path . $style . '/style.cfg';
     if (!@file_exists($filename)) {
         return $style;
     }
     $cfg = parse_cfg_file($filename);
     if ($cfg && isset($cfg['name'])) {
         return $cfg['name'];
     }
     return $style;
 }
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
        global $safe_mode, $file_uploads;
        include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        $this->default_variables();
        // Check and set some common vars
        $action = isset($_POST['update_details']) ? 'update_details' : '';
        $action = isset($_POST['download_file']) ? 'download_file' : $action;
        $action = isset($_POST['upload_file']) ? 'upload_file' : $action;
        $action = isset($_POST['upload_data']) ? 'upload_data' : $action;
        $action = isset($_POST['submit_file']) ? 'submit_file' : $action;
        $action = isset($_POST['remove_store']) ? 'details' : $action;
        $submit = empty($action) && !isset($_POST['update']) && !isset($_POST['test_connection']) ? false : true;
        $action = empty($action) ? request_var('action', '') : $action;
        $form_name = 'acp_lang';
        add_form_key('acp_lang');
        $lang_id = request_var('id', 0);
        if (isset($_POST['missing_file'])) {
            $missing_file = request_var('missing_file', array('' => 0));
            list($_REQUEST['language_file'], ) = array_keys($missing_file);
        }
        $selected_lang_file = request_var('language_file', '|common.' . $phpEx);
        list($this->language_directory, $this->language_file) = explode('|', $selected_lang_file);
        $this->language_directory = basename($this->language_directory);
        $this->language_file = basename($this->language_file);
        $user->add_lang('acp/language');
        $this->tpl_name = 'acp_language';
        $this->page_title = 'ACP_LANGUAGE_PACKS';
        if ($submit && $action == 'upload_data' && request_var('test_connection', '')) {
            $test_connection = false;
            $action = 'upload_file';
            $method = request_var('method', '');
            include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx;
            switch ($method) {
                case 'ftp':
                    $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
                    break;
                case 'ftp_fsock':
                    $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
                    break;
                default:
                    trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
                    break;
            }
            $test_connection = $transfer->open_session();
            $transfer->close_session();
        }
        switch ($action) {
            case 'upload_file':
                include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx;
                $method = request_var('method', '');
                if (!class_exists($method)) {
                    trigger_error('Method does not exist.', E_USER_ERROR);
                }
                $requested_data = call_user_func(array($method, 'data'));
                foreach ($requested_data as $data => $default) {
                    $template->assign_block_vars('data', array('DATA' => $data, 'NAME' => $user->lang[strtoupper($method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => !empty($_REQUEST[$data]) ? request_var($data, '') : $default));
                }
                $hidden_data = build_hidden_fields(array('file' => $this->language_file, 'dir' => $this->language_directory, 'language_file' => $selected_lang_file, 'method' => $method));
                $hidden_data .= build_hidden_fields(array('entry' => $_POST['entry']), true, STRIP);
                $template->assign_vars(array('S_UPLOAD' => true, 'NAME' => $method, 'U_ACTION' => $this->u_action . "&amp;id={$lang_id}&amp;action=upload_data", 'U_BACK' => $this->u_action . "&amp;id={$lang_id}&amp;action=details&amp;language_file=" . urlencode($selected_lang_file), 'HIDDEN' => $hidden_data, 'S_CONNECTION_SUCCESS' => request_var('test_connection', '') && $test_connection === true ? true : false, 'S_CONNECTION_FAILED' => request_var('test_connection', '') && $test_connection !== true ? true : false));
                break;
            case 'update_details':
                if (!$submit || !check_form_key($form_name)) {
                    trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if (!$lang_id) {
                    trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $sql = 'SELECT *
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_id = {$lang_id}";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $sql_ary = array('lang_english_name' => request_var('lang_english_name', $row['lang_english_name']), 'lang_local_name' => utf8_normalize_nfc(request_var('lang_local_name', $row['lang_local_name'], true)), 'lang_author' => utf8_normalize_nfc(request_var('lang_author', $row['lang_author'], true)));
                $db->sql_query('UPDATE ' . LANG_TABLE . '
					SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE lang_id = ' . $lang_id);
                add_log('admin', 'LOG_LANGUAGE_PACK_UPDATED', $sql_ary['lang_english_name']);
                trigger_error($user->lang['LANGUAGE_DETAILS_UPDATED'] . adm_back_link($this->u_action));
                break;
            case 'submit_file':
            case 'download_file':
            case 'upload_data':
                if (!$submit || !check_form_key($form_name)) {
                    trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if (!$lang_id || empty($_POST['entry'])) {
                    trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if ($this->language_directory != 'email' && !is_array($_POST['entry'])) {
                    trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if (!$this->language_file || !$this->language_directory && !in_array($this->language_file, $this->main_files)) {
                    trigger_error($user->lang['NO_FILE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $sql = 'SELECT *
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_id = {$lang_id}";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$row) {
                    trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                // Before we attempt to write anything let's check if the admin really chose a correct filename
                switch ($this->language_directory) {
                    case 'email':
                        // Get email templates
                        $email_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
                        $email_files = $email_files['email/'];
                        if (!in_array($this->language_file, $email_files)) {
                            trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
                        }
                        break;
                    case 'acp':
                        // Get acp files
                        $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
                        $acp_files = $acp_files['acp/'];
                        if (!in_array($this->language_file, $acp_files)) {
                            trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
                        }
                        break;
                    case 'mods':
                        // Get mod files
                        $mods_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
                        $mods_files = isset($mods_files['mods/']) ? $mods_files['mods/'] : array();
                        if (!in_array($this->language_file, $mods_files)) {
                            trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
                        }
                        break;
                    default:
                        if (!in_array($this->language_file, $this->main_files)) {
                            trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
                        }
                        break;
                }
                if (!$safe_mode) {
                    $mkdir_ary = array('language', 'language/' . $row['lang_iso']);
                    if ($this->language_directory) {
                        $mkdir_ary[] = 'language/' . $row['lang_iso'] . '/' . $this->language_directory;
                    }
                    foreach ($mkdir_ary as $dir) {
                        $dir = $phpbb_root_path . 'store/' . $dir;
                        if (!is_dir($dir)) {
                            if (!@mkdir($dir, 0777)) {
                                trigger_error("Could not create directory {$dir}", E_USER_ERROR);
                            }
                            @chmod($dir, 0777);
                        }
                    }
                }
                // Get target filename for storage folder
                $filename = $this->get_filename($row['lang_iso'], $this->language_directory, $this->language_file, true, true);
                $fp = @fopen($phpbb_root_path . $filename, 'wb');
                if (!$fp) {
                    trigger_error(sprintf($user->lang['UNABLE_TO_WRITE_FILE'], $filename) . adm_back_link($this->u_action . '&amp;id=' . $lang_id . '&amp;action=details&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
                }
                if ($this->language_directory == 'email') {
                    // Email Template
                    $entry = $this->prepare_lang_entry($_POST['entry'], false);
                    fwrite($fp, $entry);
                } else {
                    $name = ($this->language_directory ? $this->language_directory . '_' : '') . $this->language_file;
                    $header = str_replace(array('{FILENAME}', '{LANG_NAME}', '{CHANGED}', '{AUTHOR}'), array($name, $row['lang_english_name'], date('Y-m-d', time()), $row['lang_author']), $this->language_file_header);
                    if (strpos($this->language_file, 'help_') === 0) {
                        // Help File
                        $header .= '$help = array(' . "\n";
                        fwrite($fp, $header);
                        foreach ($_POST['entry'] as $key => $value) {
                            if (!is_array($value)) {
                                continue;
                            }
                            $entry = "\tarray(\n";
                            foreach ($value as $_key => $_value) {
                                $entry .= "\t\t" . (int) $_key . "\t=> '" . $this->prepare_lang_entry($_value) . "',\n";
                            }
                            $entry .= "\t),\n";
                            fwrite($fp, $entry);
                        }
                        $footer = ");\n\n?>";
                        fwrite($fp, $footer);
                    } else {
                        // Language File
                        $header .= $this->lang_header;
                        fwrite($fp, $header);
                        foreach ($_POST['entry'] as $key => $value) {
                            $entry = $this->format_lang_array($key, $value);
                            fwrite($fp, $entry);
                        }
                        $footer = "));\n\n?>";
                        fwrite($fp, $footer);
                    }
                }
                fclose($fp);
                if ($action == 'download_file') {
                    header('Pragma: no-cache');
                    header('Content-Type: application/octetstream; name="' . $this->language_file . '"');
                    header('Content-disposition: attachment; filename=' . $this->language_file);
                    $fp = @fopen($phpbb_root_path . $filename, 'rb');
                    while ($buffer = fread($fp, 1024)) {
                        echo $buffer;
                    }
                    fclose($fp);
                    add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
                    exit;
                } else {
                    if ($action == 'upload_data') {
                        $sql = 'SELECT lang_iso
						FROM ' . LANG_TABLE . "\n\t\t\t\t\t\tWHERE lang_id = {$lang_id}";
                        $result = $db->sql_query($sql);
                        $row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        $file = request_var('file', '');
                        $dir = request_var('dir', '');
                        $selected_lang_file = $dir . '|' . $file;
                        $old_file = '/' . $this->get_filename($row['lang_iso'], $dir, $file, false, true);
                        $lang_path = 'language/' . $row['lang_iso'] . '/' . ($dir ? $dir . '/' : '');
                        include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx;
                        $method = request_var('method', '');
                        if ($method != 'ftp' && $method != 'ftp_fsock') {
                            trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR);
                        }
                        $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
                        if (($result = $transfer->open_session()) !== true) {
                            trigger_error($user->lang[$result] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
                        }
                        $transfer->rename($lang_path . $file, $lang_path . $file . '.bak');
                        $result = $transfer->copy_file('store/' . $lang_path . $file, $lang_path . $file);
                        if ($result === false) {
                            // If failed, try to rename again and print error out...
                            $transfer->delete_file($lang_path . $file);
                            $transfer->rename($lang_path . $file . '.bak', $lang_path . $file);
                            trigger_error($user->lang['UPLOAD_FAILED'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)), E_USER_WARNING);
                        }
                        $transfer->close_session();
                        // Remove from storage folder
                        if (file_exists($phpbb_root_path . 'store/' . $lang_path . $file)) {
                            @unlink($phpbb_root_path . 'store/' . $lang_path . $file);
                        }
                        add_log('admin', 'LOG_LANGUAGE_FILE_REPLACED', $file);
                        trigger_error($user->lang['UPLOAD_COMPLETED'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id . '&amp;language_file=' . urlencode($selected_lang_file)));
                    }
                }
                add_log('admin', 'LOG_LANGUAGE_FILE_SUBMITTED', $this->language_file);
                $action = 'details';
                // no break;
            // no break;
            case 'details':
                if (!$lang_id) {
                    trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $this->page_title = 'LANGUAGE_PACK_DETAILS';
                $sql = 'SELECT *
					FROM ' . LANG_TABLE . '
					WHERE lang_id = ' . $lang_id;
                $result = $db->sql_query($sql);
                $lang_entries = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $lang_iso = $lang_entries['lang_iso'];
                $missing_vars = $missing_files = array();
                // Get email templates
                $email_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'email', 'txt');
                $email_files = $email_files['email/'];
                // Get acp files
                $acp_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'acp', $phpEx);
                $acp_files = $acp_files['acp/'];
                // Get mod files
                $mods_files = filelist($phpbb_root_path . 'language/' . $config['default_lang'], 'mods', $phpEx);
                $mods_files = isset($mods_files['mods/']) ? $mods_files['mods/'] : array();
                // Check if our current filename matches the files
                switch ($this->language_directory) {
                    case 'email':
                        if (!in_array($this->language_file, $email_files)) {
                            trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
                        }
                        break;
                    case 'acp':
                        if (!in_array($this->language_file, $acp_files)) {
                            trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
                        }
                        break;
                    case 'mods':
                        if (!in_array($this->language_file, $mods_files)) {
                            trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
                        }
                        break;
                    default:
                        if (!in_array($this->language_file, $this->main_files)) {
                            trigger_error($user->lang['WRONG_LANGUAGE_FILE'] . adm_back_link($this->u_action . '&amp;action=details&amp;id=' . $lang_id), E_USER_WARNING);
                        }
                }
                if (isset($_POST['remove_store'])) {
                    $store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true);
                    if (file_exists($phpbb_root_path . $store_filename)) {
                        @unlink($phpbb_root_path . $store_filename);
                    }
                }
                include_once $phpbb_root_path . 'includes/functions_transfer.' . $phpEx;
                $methods = transfer::methods();
                foreach ($methods as $method) {
                    $template->assign_block_vars('buttons', array('VALUE' => $method));
                }
                $template->assign_vars(array('S_DETAILS' => true, 'U_ACTION' => $this->u_action . "&amp;action=details&amp;id={$lang_id}", 'U_BACK' => $this->u_action, 'LANG_LOCAL_NAME' => $lang_entries['lang_local_name'], 'LANG_ENGLISH_NAME' => $lang_entries['lang_english_name'], 'LANG_ISO' => $lang_entries['lang_iso'], 'LANG_AUTHOR' => $lang_entries['lang_author'], 'ALLOW_UPLOAD' => sizeof($methods)));
                // If current lang is different from the default lang, then first try to grab missing/additional vars
                if ($lang_iso != $config['default_lang']) {
                    $is_missing_var = false;
                    foreach ($this->main_files as $file) {
                        if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file))) {
                            $missing_vars[$file] = $this->compare_language_files($config['default_lang'], $lang_iso, '', $file);
                            if (sizeof($missing_vars[$file])) {
                                $is_missing_var = true;
                            }
                        } else {
                            $missing_files[] = $this->get_filename($lang_iso, '', $file);
                        }
                    }
                    // Now go through acp/mods directories
                    foreach ($acp_files as $file) {
                        if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'acp', $file))) {
                            $missing_vars['acp/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'acp', $file);
                            if (sizeof($missing_vars['acp/' . $file])) {
                                $is_missing_var = true;
                            }
                        } else {
                            $missing_files[] = $this->get_filename($lang_iso, 'acp', $file);
                        }
                    }
                    if (sizeof($mods_files)) {
                        foreach ($mods_files as $file) {
                            if (file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'mods', $file))) {
                                $missing_vars['mods/' . $file] = $this->compare_language_files($config['default_lang'], $lang_iso, 'mods', $file);
                                if (sizeof($missing_vars['mods/' . $file])) {
                                    $is_missing_var = true;
                                }
                            } else {
                                $missing_files[] = $this->get_filename($lang_iso, 'mods', $file);
                            }
                        }
                    }
                    // More missing files... for example email templates?
                    foreach ($email_files as $file) {
                        if (!file_exists($phpbb_root_path . $this->get_filename($lang_iso, 'email', $file))) {
                            $missing_files[] = $this->get_filename($lang_iso, 'email', $file);
                        }
                    }
                    if (sizeof($missing_files)) {
                        $template->assign_vars(array('S_MISSING_FILES' => true, 'L_MISSING_FILES' => sprintf($user->lang['THOSE_MISSING_LANG_FILES'], $lang_entries['lang_local_name']), 'MISSING_FILES' => implode('<br />', $missing_files)));
                    }
                    if ($is_missing_var) {
                        $template->assign_vars(array('S_MISSING_VARS' => true, 'L_MISSING_VARS_EXPLAIN' => sprintf($user->lang['THOSE_MISSING_LANG_VARIABLES'], $lang_entries['lang_local_name']), 'U_MISSING_ACTION' => $this->u_action . "&amp;action={$action}&amp;id={$lang_id}"));
                        foreach ($missing_vars as $file => $vars) {
                            if (!sizeof($vars)) {
                                continue;
                            }
                            $template->assign_block_vars('missing', array('FILE' => $file, 'TPL' => $this->print_language_entries($vars, '', false), 'KEY' => strpos($file, '/') === false ? '|' . $file : str_replace('/', '|', $file)));
                        }
                    }
                }
                // Main language files
                $s_lang_options = '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['LANGUAGE_FILES'] . '</option>';
                foreach ($this->main_files as $file) {
                    if (strpos($file, 'help_') === 0) {
                        continue;
                    }
                    $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true)) ? '* ' : '';
                    $selected = !$this->language_directory && $this->language_file == $file ? ' selected="selected"' : '';
                    $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
                }
                // Help Files
                $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang['HELP_FILES'] . '</option>';
                foreach ($this->main_files as $file) {
                    if (strpos($file, 'help_') !== 0) {
                        continue;
                    }
                    $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, '', $file, true, true)) ? '* ' : '';
                    $selected = !$this->language_directory && $this->language_file == $file ? ' selected="selected"' : '';
                    $s_lang_options .= '<option value="|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
                }
                // Now every other language directory
                $check_files = array('email', 'acp', 'mods');
                foreach ($check_files as $check) {
                    if (!sizeof(${$check . '_files'})) {
                        continue;
                    }
                    $s_lang_options .= '<option value="|common.' . $phpEx . '" class="sep">' . $user->lang[strtoupper($check) . '_FILES'] . '</option>';
                    foreach (${$check . '_files'} as $file) {
                        $prefix = file_exists($phpbb_root_path . $this->get_filename($lang_iso, $check, $file, true, true)) ? '* ' : '';
                        $selected = $this->language_directory == $check && $this->language_file == $file ? ' selected="selected"' : '';
                        $s_lang_options .= '<option value="' . $check . '|' . $file . '"' . $selected . '>' . $prefix . $file . '</option>';
                    }
                }
                // Get Language Entries - if saved within store folder, we take this one (with the option to remove it)
                $lang = array();
                $is_email_file = $this->language_directory == 'email' ? true : false;
                $is_help_file = strpos($this->language_file, 'help_') === 0 ? true : false;
                $file_from_store = file_exists($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, true, true)) ? true : false;
                $no_store_filename = $this->get_filename($lang_iso, $this->language_directory, $this->language_file);
                if (!$file_from_store && !file_exists($phpbb_root_path . $no_store_filename)) {
                    $print_message = sprintf($user->lang['MISSING_LANGUAGE_FILE'], $no_store_filename);
                } else {
                    if ($is_email_file) {
                        $lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
                    } else {
                        $help = array();
                        include $phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store);
                        if ($is_help_file) {
                            $lang = $help;
                            unset($help);
                        }
                    }
                    $print_message = ($this->language_directory ? $this->language_directory . '/' : '') . $this->language_file;
                }
                // Normal language pack entries
                $template->assign_vars(array('U_ENTRY_ACTION' => $this->u_action . "&amp;action=details&amp;id={$lang_id}#entries", 'S_EMAIL_FILE' => $is_email_file, 'S_FROM_STORE' => $file_from_store, 'S_LANG_OPTIONS' => $s_lang_options, 'PRINT_MESSAGE' => $print_message));
                if (!$is_email_file) {
                    $tpl = '';
                    $name = ($this->language_directory ? $this->language_directory . '/' : '') . $this->language_file;
                    if (isset($missing_vars[$name]) && sizeof($missing_vars[$name])) {
                        $tpl .= $this->print_language_entries($missing_vars[$name], '* ');
                    }
                    $tpl .= $this->print_language_entries($lang);
                    $template->assign_var('TPL', $tpl);
                    unset($tpl);
                } else {
                    $template->assign_vars(array('LANG' => $lang));
                    unset($lang);
                }
                return;
                break;
            case 'delete':
                if (!$lang_id) {
                    trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $sql = 'SELECT *
					FROM ' . LANG_TABLE . '
					WHERE lang_id = ' . $lang_id;
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if ($row['lang_iso'] == $config['default_lang']) {
                    trigger_error($user->lang['NO_REMOVE_DEFAULT_LANG'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if (confirm_box(true)) {
                    $db->sql_query('DELETE FROM ' . LANG_TABLE . ' WHERE lang_id = ' . $lang_id);
                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_lang = '" . $db->sql_escape($config['default_lang']) . "'\n\t\t\t\t\t\tWHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
                    $db->sql_query($sql);
                    // We also need to remove the translated entries for custom profile fields - we want clean tables, don't we?
                    $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
                    $db->sql_query($sql);
                    $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id;
                    $db->sql_query($sql);
                    $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_lang = '" . $db->sql_escape($row['lang_iso']) . "'";
                    $result = $db->sql_query($sql);
                    $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
                    add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']);
                    trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action));
                } else {
                    $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'action' => $action, 'id' => $lang_id);
                    confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
                }
                break;
            case 'install':
                $lang_iso = request_var('iso', '');
                $lang_iso = basename($lang_iso);
                if (!$lang_iso || !file_exists("{$phpbb_root_path}language/{$lang_iso}/iso.txt")) {
                    trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $file = file("{$phpbb_root_path}language/{$lang_iso}/iso.txt");
                $lang_pack = array('iso' => $lang_iso, 'name' => trim(htmlspecialchars($file[0])), 'local_name' => trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')), 'author' => trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8')));
                unset($file);
                $sql = 'SELECT lang_iso
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if ($row) {
                    trigger_error($user->lang['LANGUAGE_PACK_ALREADY_INSTALLED'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if (!$lang_pack['name'] || !$lang_pack['local_name']) {
                    trigger_error($user->lang['INVALID_LANGUAGE_PACK'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                // Add language pack
                $sql_ary = array('lang_iso' => $lang_pack['iso'], 'lang_dir' => $lang_pack['iso'], 'lang_english_name' => $lang_pack['name'], 'lang_local_name' => $lang_pack['local_name'], 'lang_author' => $lang_pack['author']);
                $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                $lang_id = $db->sql_nextid();
                $valid_localized = array('icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply');
                $sql_ary = array();
                $sql = 'SELECT *
					FROM ' . STYLES_IMAGESET_TABLE;
                $result = $db->sql_query($sql);
                while ($imageset_row = $db->sql_fetchrow($result)) {
                    if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg")) {
                        $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['iso']}/imageset.cfg");
                        foreach ($cfg_data_imageset_data as $image_name => $value) {
                            if (strpos($value, '*') !== false) {
                                if (substr($value, -1, 1) === '*') {
                                    list($image_filename, $image_height) = explode('*', $value);
                                    $image_width = 0;
                                } else {
                                    list($image_filename, $image_height, $image_width) = explode('*', $value);
                                }
                            } else {
                                $image_filename = $value;
                                $image_height = $image_width = 0;
                            }
                            if (strpos($image_name, 'img_') === 0 && $image_filename) {
                                $image_name = substr($image_name, 4);
                                if (in_array($image_name, $valid_localized)) {
                                    $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $imageset_row['imageset_id'], 'image_lang' => (string) $lang_pack['iso']);
                                }
                            }
                        }
                    }
                }
                $db->sql_freeresult($result);
                if (sizeof($sql_ary)) {
                    $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
                    $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
                }
                // Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier.
                $sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
                $result = $db->sql_query($sql);
                $default_lang_id = (int) $db->sql_fetchfield('lang_id');
                $db->sql_freeresult($result);
                // From the mysql documentation:
                // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
                // Due to this we stay on the safe side if we do the insertion "the manual way"
                $sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value
					FROM ' . PROFILE_LANG_TABLE . '
					WHERE lang_id = ' . $default_lang_id;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $row['lang_id'] = $lang_id;
                    $db->sql_query('INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
                }
                $db->sql_freeresult($result);
                $sql = 'SELECT field_id, option_id, field_type, lang_value
					FROM ' . PROFILE_FIELDS_LANG_TABLE . '
					WHERE lang_id = ' . $default_lang_id;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $row['lang_id'] = $lang_id;
                    $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row));
                }
                $db->sql_freeresult($result);
                add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']);
                trigger_error(sprintf($user->lang['LANGUAGE_PACK_INSTALLED'], $lang_pack['name']) . adm_back_link($this->u_action));
                break;
            case 'download':
                if (!$lang_id) {
                    trigger_error($user->lang['NO_LANG_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $sql = 'SELECT *
					FROM ' . LANG_TABLE . '
					WHERE lang_id = ' . $lang_id;
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $use_method = request_var('use_method', '');
                $methods = array('.tar');
                $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
                foreach ($available_methods as $type => $module) {
                    if (!@extension_loaded($module)) {
                        continue;
                    }
                    $methods[] = $type;
                }
                // Let the user decide in which format he wants to have the pack
                if (!$use_method) {
                    $this->page_title = 'SELECT_DOWNLOAD_FORMAT';
                    $radio_buttons = '';
                    foreach ($methods as $method) {
                        $radio_buttons .= '<label><input type="radio"' . (!$radio_buttons ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>';
                    }
                    $template->assign_vars(array('S_SELECT_METHOD' => true, 'U_BACK' => $this->u_action, 'U_ACTION' => $this->u_action . "&amp;action={$action}&amp;id={$lang_id}", 'RADIO_BUTTONS' => $radio_buttons));
                    return;
                }
                if (!in_array($use_method, $methods)) {
                    $use_method = '.tar';
                }
                include_once $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
                if ($use_method == '.zip') {
                    $compress = new compress_zip('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
                } else {
                    $compress = new compress_tar('w', $phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method, $use_method);
                }
                // Get email templates
                $email_templates = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'email', 'txt');
                $email_templates = $email_templates['email/'];
                // Get acp files
                $acp_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'acp', $phpEx);
                $acp_files = $acp_files['acp/'];
                // Get mod files
                $mod_files = filelist($phpbb_root_path . 'language/' . $row['lang_iso'], 'mods', $phpEx);
                $mod_files = isset($mod_files['mods/']) ? $mod_files['mods/'] : array();
                // Add main files
                $this->add_to_archive($compress, $this->main_files, $row['lang_iso']);
                // Add search files if they exist...
                if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_ignore_words.' . $phpEx)) {
                    $this->add_to_archive($compress, array("search_ignore_words.{$phpEx}"), $row['lang_iso']);
                }
                if (file_exists($phpbb_root_path . 'language/' . $row['lang_iso'] . '/search_synonyms.' . $phpEx)) {
                    $this->add_to_archive($compress, array("search_synonyms.{$phpEx}"), $row['lang_iso']);
                }
                // Write files in folders
                $this->add_to_archive($compress, $email_templates, $row['lang_iso'], 'email');
                $this->add_to_archive($compress, $acp_files, $row['lang_iso'], 'acp');
                $this->add_to_archive($compress, $mod_files, $row['lang_iso'], 'mods');
                // Write ISO File
                $iso_src = htmlspecialchars_decode($row['lang_english_name']) . "\n";
                $iso_src .= htmlspecialchars_decode($row['lang_local_name']) . "\n";
                $iso_src .= htmlspecialchars_decode($row['lang_author']);
                $compress->add_data($iso_src, 'language/' . $row['lang_iso'] . '/iso.txt');
                // index.html files
                $compress->add_data('', 'language/' . $row['lang_iso'] . '/index.html');
                $compress->add_data('', 'language/' . $row['lang_iso'] . '/email/index.html');
                $compress->add_data('', 'language/' . $row['lang_iso'] . '/acp/index.html');
                if (sizeof($mod_files)) {
                    $compress->add_data('', 'language/' . $row['lang_iso'] . '/mods/index.html');
                }
                $compress->close();
                $compress->download('lang_' . $row['lang_iso']);
                @unlink($phpbb_root_path . 'store/lang_' . $row['lang_iso'] . $use_method);
                exit;
                break;
        }
        $sql = 'SELECT user_lang, COUNT(user_lang) AS lang_count
			FROM ' . USERS_TABLE . '
			GROUP BY user_lang';
        $result = $db->sql_query($sql);
        $lang_count = array();
        while ($row = $db->sql_fetchrow($result)) {
            $lang_count[$row['user_lang']] = $row['lang_count'];
        }
        $db->sql_freeresult($result);
        $sql = 'SELECT *
			FROM ' . LANG_TABLE . '
			ORDER BY lang_english_name';
        $result = $db->sql_query($sql);
        $installed = array();
        while ($row = $db->sql_fetchrow($result)) {
            $installed[] = $row['lang_iso'];
            $tagstyle = $row['lang_iso'] == $config['default_lang'] ? '*' : '';
            $template->assign_block_vars('lang', array('U_DETAILS' => $this->u_action . "&amp;action=details&amp;id={$row['lang_id']}", 'U_DOWNLOAD' => $this->u_action . "&amp;action=download&amp;id={$row['lang_id']}", 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;id={$row['lang_id']}", 'ENGLISH_NAME' => $row['lang_english_name'], 'TAG' => $tagstyle, 'LOCAL_NAME' => $row['lang_local_name'], 'ISO' => $row['lang_iso'], 'USED_BY' => isset($lang_count[$row['lang_iso']]) ? $lang_count[$row['lang_iso']] : 0));
        }
        $db->sql_freeresult($result);
        $new_ary = $iso = array();
        $dp = @opendir("{$phpbb_root_path}language");
        if ($dp) {
            while (($file = readdir($dp)) !== false) {
                if ($file[0] != '.' && file_exists("{$phpbb_root_path}language/{$file}/iso.txt")) {
                    if (!in_array($file, $installed)) {
                        if ($iso = file("{$phpbb_root_path}language/{$file}/iso.txt")) {
                            if (sizeof($iso) == 3) {
                                $new_ary[$file] = array('iso' => $file, 'name' => trim($iso[0]), 'local_name' => trim($iso[1]), 'author' => trim($iso[2]));
                            }
                        }
                    }
                }
            }
            closedir($dp);
        }
        unset($installed);
        if (sizeof($new_ary)) {
            foreach ($new_ary as $iso => $lang_ary) {
                $template->assign_block_vars('notinst', array('ISO' => htmlspecialchars($lang_ary['iso']), 'LOCAL_NAME' => htmlspecialchars($lang_ary['local_name'], ENT_COMPAT, 'UTF-8'), 'NAME' => htmlspecialchars($lang_ary['name'], ENT_COMPAT, 'UTF-8'), 'U_INSTALL' => $this->u_action . '&amp;action=install&amp;iso=' . urlencode($lang_ary['iso'])));
            }
        }
        unset($new_ary);
    }
Exemplo n.º 20
0
    function main($mode, $sub)
    {
        global $lang, $template, $language, $phpbb_root_path, $phpEx, $config, $db, $table_prefix, $db, $auth, $cache, $user;
        $this->old_location = $phpbb_root_path . 'garage/install/install/old/';
        $this->new_location = $phpbb_root_path . 'garage/install/install/new/';
        // Special options for conflicts/modified files
        define('MERGE_NO_MERGE_NEW', 1);
        define('MERGE_NO_MERGE_MOD', 2);
        define('MERGE_NEW_FILE', 3);
        define('MERGE_MOD_FILE', 4);
        $this->install_info = $this->get_file('install_info');
        // Include renderer and engine
        $this->include_file('includes/diff/diff.' . $phpEx);
        $this->include_file('includes/diff/engine.' . $phpEx);
        $this->include_file('includes/diff/renderer.' . $phpEx);
        // Make sure we stay at the file check if checking the files again
        if (!empty($_POST['check_again'])) {
            $sub = $this->p_master->sub = 'file_check';
        }
        $this->tpl_name = 'garage_install_install';
        switch ($sub) {
            case 'intro':
                $this->page_title = $lang['SUB_INTRO'];
                $template->assign_vars(array('TITLE' => $lang['INSTALL_INTRO'], 'BODY' => $lang['INSTALL_INTRO_BODY'], 'L_SUBMIT' => $lang['NEXT_STEP'], 'U_ACTION' => $this->p_master->module_url . "?mode={$mode}&amp;sub=requirements&amp;language={$language}"));
                break;
            case 'requirements':
                $this->check_server_requirements($mode, $sub);
                break;
            case 'optional':
                $this->obtain_optional_settings($mode, $sub);
                break;
            case 'create_table':
                $this->load_schema($mode, $sub);
                break;
            case 'create_permissions':
                $this->add_permissions($mode, $sub);
                $this->update_group_permissions($mode, $sub);
                $this->update_role_permissions($mode, $sub);
                $submit = $lang['NEXT_STEP'];
                $url = $this->p_master->module_url . "?mode={$mode}&amp;sub=install_modules";
                $template->assign_vars(array('BODY' => $lang['STAGE_CREATE_PERMISSIONS_EXPLAIN'], 'L_SUBMIT' => $submit, 'U_ACTION' => $url));
                break;
            case 'install_modules':
                $this->add_modules($mode, $sub);
                $submit = $lang['NEXT_STEP'];
                $url = $this->p_master->module_url . "?mode={$mode}&amp;sub=file_check";
                $template->assign_vars(array('BODY' => $lang['STAGE_INSTALL_MODULES_EXPLAIN'], 'L_SUBMIT' => $submit, 'U_ACTION' => $url));
                break;
                // Last step is just a re-check of files...
            // Last step is just a re-check of files...
            case 'final':
            case 'file_check':
                $this->tpl_name = 'garage_install_update';
                $this->page_title = 'STAGE_FILE_CHECK';
                // Now make sure our install list is correct if the admin refreshes
                $action = request_var('action', '');
                // We are directly within an update. To make sure our install list is correct we check its status.
                $install_list = !empty($_POST['check_again']) ? false : $cache->get('_install_list');
                $modified = $install_list !== false ? @filemtime($cache->cache_dir . 'data_install_list.' . $phpEx) : 0;
                // Make sure the list is up-to-date
                if ($install_list !== false) {
                    $get_new_list = false;
                    foreach ($this->install_info['files'] as $file) {
                        if (file_exists($phpbb_root_path . $file) && filemtime($phpbb_root_path . $file) > $modified) {
                            $get_new_list = true;
                            break;
                        }
                    }
                } else {
                    $get_new_list = true;
                }
                if ($get_new_list) {
                    $install_list = $this->get_install_structure();
                    $cache->put('_install_list', $install_list);
                }
                if ($action == 'diff') {
                    $this->show_diff($install_list);
                    return;
                }
                // Now assign the list to the template
                foreach ($install_list as $status => $filelist) {
                    if ($status == 'no_update' || !sizeof($filelist)) {
                        continue;
                    }
                    $template->assign_block_vars('files', array('S_STATUS' => true, 'STATUS' => $status, 'L_STATUS' => $user->lang['STATUS_' . strtoupper($status)], 'TITLE' => $user->lang['FILES_' . strtoupper($status)], 'EXPLAIN' => $user->lang['FILES_' . strtoupper($status) . '_EXPLAIN']));
                    foreach ($filelist as $file_struct) {
                        $filename = htmlspecialchars($file_struct['filename']);
                        if (strrpos($filename, '/') !== false) {
                            $dir_part = substr($filename, 0, strrpos($filename, '/') + 1);
                            $file_part = substr($filename, strrpos($filename, '/') + 1);
                        } else {
                            $dir_part = '';
                            $file_part = $filename;
                        }
                        $diff_url = append_sid($this->p_master->module_url, "mode={$mode}&amp;sub=file_check&amp;action=diff&amp;status={$status}&amp;file=" . urlencode($file_struct['filename']));
                        $template->assign_block_vars('files', array('STATUS' => $status, 'FILENAME' => $filename, 'DIR_PART' => $dir_part, 'FILE_PART' => $file_part, 'NUM_CONFLICTS' => isset($file_struct['conflicts']) ? $file_struct['conflicts'] : 0, 'S_CUSTOM' => $file_struct['custom'] ? true : false, 'CUSTOM_ORIGINAL' => $file_struct['custom'] ? $file_struct['original'] : '', 'U_SHOW_DIFF' => $diff_url, 'L_SHOW_DIFF' => $status != 'up_to_date' ? $user->lang['SHOW_DIFF_' . strtoupper($status)] : '', 'U_VIEW_MOD_FILE' => $diff_url . '&amp;op=' . MERGE_MOD_FILE, 'U_VIEW_NEW_FILE' => $diff_url . '&amp;op=' . MERGE_NEW_FILE, 'U_VIEW_NO_MERGE_MOD' => $diff_url . '&amp;op=' . MERGE_NO_MERGE_MOD, 'U_VIEW_NO_MERGE_NEW' => $diff_url . '&amp;op=' . MERGE_NO_MERGE_NEW));
                    }
                }
                $all_up_to_date = true;
                foreach ($install_list as $status => $filelist) {
                    if ($status != 'up_to_date' && $status != 'custom' && sizeof($filelist)) {
                        $all_up_to_date = false;
                        break;
                    }
                }
                $template->assign_vars(array('S_FILE_CHECK' => true, 'S_ALL_UP_TO_DATE' => $all_up_to_date, 'U_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&amp;sub=file_check"), 'U_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&amp;sub=update_files")));
                if ($all_up_to_date and $sub == 'final') {
                    // Remove the lock file
                    @unlink($phpbb_root_path . 'cache/install_lock');
                }
                // Make sure we stay at the final if we checked_again and all is now up to date
                if (!empty($_POST['check_again']) && $all_up_to_date) {
                    $sub = $this->p_master->sub = 'final';
                }
                if ($all_up_to_date) {
                    // Refresh any style css data we updated - this may cause some unhappy users, but
                    $sql = 'SELECT *
						FROM ' . STYLES_THEME_TABLE;
                    $result = $db->sql_query($sql);
                    while ($theme = $db->sql_fetchrow($result)) {
                        //Check For Themes Updated By Installer
                        if (file_exists($phpbb_root_path . "garage/install/install/styles/{$theme['theme_name']}/theme/index." . $phpEx)) {
                            $recache = empty($theme['theme_data']) ? true : false;
                            $update_time = time();
                            // We test for stylesheet.css because it is faster and most likely the only file changed on common themes
                            if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css')) {
                                $recache = true;
                                $update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css');
                            } else {
                                if (!$recache) {
                                    $last_change = $theme['theme_mtime'];
                                    $dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme");
                                    if ($dir) {
                                        while (($entry = readdir($dir)) !== false) {
                                            if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}")) {
                                                $recache = true;
                                                break;
                                            }
                                        }
                                        closedir($dir);
                                    }
                                }
                            }
                            if ($recache) {
                                include_once $phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx;
                                $theme['theme_data'] = acp_styles::db_theme_data($theme);
                                $theme['theme_mtime'] = $update_time;
                                // Save CSS contents
                                $sql_ary = array('theme_mtime' => $theme['theme_mtime'], 'theme_data' => $theme['theme_data']);
                                $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
									WHERE theme_id = ' . $theme['theme_id'];
                                $db->sql_query($sql);
                                $cache->destroy('sql', STYLES_THEME_TABLE);
                            }
                        }
                    }
                    $db->sql_freeresult($result);
                    // Refresh any imageset data we updated - but only for garage images
                    $sql = 'SELECT *
						FROM ' . STYLES_IMAGESET_TABLE;
                    $result = $db->sql_query($sql);
                    while ($imageset = $db->sql_fetchrow($result)) {
                        $sql_ary = array();
                        $db->sql_transaction('begin');
                        if (!class_exists('garage_template')) {
                            include $phpbb_root_path . 'includes/mods/class_garage_template.' . $phpEx;
                            $garage_template = new garage_template();
                        }
                        //We need to build the imageset_keys now only for garage keys
                        $imageset_keys = array();
                        $imageset_keys['buttons'] = array();
                        $imageset_keys = $garage_template->update_imageset_keys($imageset_keys);
                        $imageset_definitions = array();
                        foreach ($imageset_keys as $topic => $key_array) {
                            $imageset_definitions = array_merge($imageset_definitions, $key_array);
                        }
                        //Check For Imageset Updated By Installer
                        if (file_exists($phpbb_root_path . "garage/install/install/new/styles/{$imageset['imageset_path']}/imageset/imageset.cfg")) {
                            $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset['imageset_path']}/imageset/imageset.cfg");
                            $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
								WHERE imageset_id = ' . $imageset['imageset_id'] . '
									AND ' . $db->sql_in_set('image_name', $imageset_keys['garage']);
                            $db->sql_query($sql);
                            foreach ($cfg_data_imageset as $image_name => $value) {
                                //Lets cut to the chase and make sure we only work with garage images
                                $image_wanted = substr($image_name, 4);
                                if (!in_array($image_wanted, $imageset_keys['garage'])) {
                                    continue;
                                }
                                if (strpos($value, '*') !== false) {
                                    if (substr($value, -1, 1) === '*') {
                                        list($image_filename, $image_height) = explode('*', $value);
                                        $image_width = 0;
                                    } else {
                                        list($image_filename, $image_height, $image_width) = explode('*', $value);
                                    }
                                } else {
                                    $image_filename = $value;
                                    $image_height = $image_width = 0;
                                }
                                if (strpos($image_name, 'img_') === 0 && $image_filename) {
                                    $image_name = substr($image_name, 4);
                                    if (in_array($image_name, $imageset_definitions)) {
                                        $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $imageset['imageset_id'], 'image_lang' => '');
                                    }
                                }
                            }
                        }
                        $sql2 = 'SELECT lang_dir
							FROM ' . LANG_TABLE;
                        $result2 = $db->sql_query($sql2);
                        while ($language = $db->sql_fetchrow($result2)) {
                            //Check For Language Imageset Updated By Installer
                            if (file_exists($phpbb_root_path . "garage/install/install/new/styles/{$imageset['imageset_path']}/imageset/{$language['lang_dir']}/imageset.cfg")) {
                                $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset['imageset_path']}/imageset/{$language['lang_dir']}/imageset.cfg");
                                $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . '
									WHERE imageset_id = ' . $imageset['imageset_id'] . '
										AND ' . $db->sql_in_set('image_name', $imageset_keys['buttons']) . "\n\t\t\t\t\t\t\t\t\t\tAND image_lang = '{$language['lang_dir']}'";
                                $db->sql_query($sql);
                                foreach ($cfg_data_imageset_data as $image_name => $value) {
                                    //Lets cut to the chase and make sure we only work with garage images
                                    $image_wanted = substr($image_name, 4);
                                    if (!in_array($image_wanted, $imageset_keys['buttons'])) {
                                        continue;
                                    }
                                    if (strpos($value, '*') !== false) {
                                        if (substr($value, -1, 1) === '*') {
                                            list($image_filename, $image_height) = explode('*', $value);
                                            $image_width = 0;
                                        } else {
                                            list($image_filename, $image_height, $image_width) = explode('*', $value);
                                        }
                                    } else {
                                        $image_filename = $value;
                                        $image_height = $image_width = 0;
                                    }
                                    if (strpos($image_name, 'img_') === 0 && $image_filename) {
                                        $image_name = substr($image_name, 4);
                                        if (in_array($image_name, $imageset_definitions)) {
                                            $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $imageset['imageset_id'], 'image_lang' => (string) $language['lang_dir']);
                                        }
                                    }
                                }
                            }
                        }
                        $db->sql_freeresult($result2);
                        $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);
                        $db->sql_transaction('commit');
                    }
                    $db->sql_freeresult($result);
                    $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);
                    add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset['imageset_name']);
                    $db->sql_return_on_error(true);
                    $db->sql_query('DELETE FROM ' . GARAGE_CONFIG_TABLE . " WHERE config_name = 'version_update_from'");
                    $db->sql_return_on_error(false);
                    $cache->purge();
                }
                break;
            case 'update_files':
                $this->tpl_name = 'garage_install_update';
                $this->page_title = 'STAGE_UPDATE_FILES';
                $s_hidden_fields = '';
                $conflicts = request_var('conflict', array('' => 0));
                $modified = request_var('modified', array('' => 0));
                foreach ($conflicts as $filename => $merge_option) {
                    $s_hidden_fields .= '<input type="hidden" name="conflict[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />';
                }
                foreach ($modified as $filename => $merge_option) {
                    if (!$merge_option) {
                        continue;
                    }
                    $s_hidden_fields .= '<input type="hidden" name="modified[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />';
                }
                $no_update = request_var('no_update', array(0 => ''));
                foreach ($no_update as $index => $filename) {
                    $s_hidden_fields .= '<input type="hidden" name="no_update[]" value="' . htmlspecialchars($filename) . '" />';
                }
                if (!empty($_POST['download'])) {
                    $this->include_file('includes/functions_compress.' . $phpEx);
                    $use_method = request_var('use_method', '');
                    $methods = array('.tar');
                    $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
                    foreach ($available_methods as $type => $module) {
                        if (!@extension_loaded($module)) {
                            continue;
                        }
                        $methods[] = $type;
                    }
                    // Let the user decide in which format he wants to have the pack
                    if (!$use_method) {
                        $this->page_title = 'SELECT_DOWNLOAD_FORMAT';
                        $radio_buttons = '';
                        foreach ($methods as $method) {
                            $radio_buttons .= '<label><input type="radio"' . (!$radio_buttons ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>';
                        }
                        $template->assign_vars(array('S_DOWNLOAD_FILES' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&amp;sub=update_files"), 'RADIO_BUTTONS' => $radio_buttons, 'S_HIDDEN_FIELDS' => $s_hidden_fields));
                        // To ease the update process create a file location map
                        $install_list = $cache->get('_install_list');
                        $script_path = $config['force_server_vars'] ? $config['script_path'] == '/' ? '/' : $config['script_path'] . '/' : $user->page['root_script_path'];
                        foreach ($install_list as $status => $files) {
                            if ($status == 'up_to_date' || $status == 'no_update') {
                                continue;
                            }
                            foreach ($files as $file_struct) {
                                if (in_array($file_struct['filename'], $no_update)) {
                                    continue;
                                }
                                $template->assign_block_vars('location', array('SOURCE' => htmlspecialchars($file_struct['filename']), 'DESTINATION' => $script_path . htmlspecialchars($file_struct['filename'])));
                            }
                        }
                        return;
                    }
                    if (!in_array($use_method, $methods)) {
                        $use_method = '.tar';
                    }
                    $update_mode = 'download';
                } else {
                    $this->include_file('includes/functions_transfer.' . $phpEx);
                    // Choose FTP, if not available use fsock...
                    $method = request_var('method', '');
                    $submit = isset($_POST['submit']) ? true : false;
                    $test_ftp_connection = request_var('test_connection', '');
                    if (!$method) {
                        $method = 'ftp';
                        $methods = transfer::methods();
                        if (!in_array('ftp', $methods)) {
                            $method = $methods[0];
                        }
                    }
                    $test_connection = false;
                    if ($test_ftp_connection || $submit) {
                        $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
                        $test_connection = $transfer->open_session();
                        // Make sure that the directory is correct by checking for the existence of common.php
                        if ($test_connection === true) {
                            // Check for common.php file
                            if (!$transfer->file_exists($phpbb_root_path, 'common.' . $phpEx)) {
                                $test_connection = 'ERR_WRONG_PATH_TO_PHPBB';
                            }
                        }
                        $transfer->close_session();
                        // Make sure the login details are correct before continuing
                        if ($submit && $test_connection !== true) {
                            $submit = false;
                            $test_ftp_connection = true;
                        }
                    }
                    if (!$submit) {
                        $this->page_title = 'SELECT_FTP_SETTINGS';
                        if (!class_exists($method)) {
                            trigger_error('Method does not exist.', E_USER_ERROR);
                        }
                        $requested_data = call_user_func(array($method, 'data'));
                        foreach ($requested_data as $data => $default) {
                            $template->assign_block_vars('data', array('DATA' => $data, 'NAME' => $user->lang[strtoupper($method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => !empty($_REQUEST[$data]) ? request_var($data, '') : $default));
                        }
                        $s_hidden_fields .= build_hidden_fields(array('method' => $method));
                        $template->assign_vars(array('S_CONNECTION_SUCCESS' => $test_ftp_connection && $test_connection === true ? true : false, 'S_CONNECTION_FAILED' => $test_ftp_connection && $test_connection !== true ? true : false, 'ERROR_MSG' => $test_ftp_connection && $test_connection !== true ? $user->lang[$test_connection] : '', 'S_FTP_UPLOAD' => true, 'UPLOAD_METHOD' => $method, 'U_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&amp;sub=update_files"), 'S_HIDDEN_FIELDS' => $s_hidden_fields));
                        return;
                    }
                    $update_mode = 'upload';
                }
                // Now update the installation or download the archive...
                $download_filename = 'install_phpbbgarage_' . $this->install_info['version']['install'];
                $archive_filename = $download_filename . '_' . time() . '_' . unique_id();
                $install_list = $cache->get('_install_list');
                $conflicts = request_var('conflict', array('' => 0));
                $modified = request_var('modified', array('' => 0));
                if ($install_list === false) {
                    trigger_error($user->lang['NO_UPDATE_INFO'], E_USER_ERROR);
                }
                // Check if the conflicts data is valid
                if (sizeof($conflicts)) {
                    $conflict_filenames = array();
                    foreach ($install_list['conflict'] as $files) {
                        $conflict_filenames[] = $files['filename'];
                    }
                    $new_conflicts = array();
                    foreach ($conflicts as $filename => $diff_method) {
                        if (in_array($filename, $conflict_filenames)) {
                            $new_conflicts[$filename] = $diff_method;
                        }
                    }
                    $conflicts = $new_conflicts;
                }
                // Build list for modifications
                if (sizeof($modified)) {
                    $modified_filenames = array();
                    foreach ($install_list['modified'] as $files) {
                        $modified_filenames[] = $files['filename'];
                    }
                    $new_modified = array();
                    foreach ($modified as $filename => $diff_method) {
                        if (in_array($filename, $modified_filenames)) {
                            $new_modified[$filename] = $diff_method;
                        }
                    }
                    $modified = $new_modified;
                }
                // Check number of conflicting files, they need to be equal. For modified files the number can differ
                if (sizeof($install_list['conflict']) != sizeof($conflicts)) {
                    trigger_error($user->lang['MERGE_SELECT_ERROR'], E_USER_ERROR);
                }
                // Now init the connection
                if ($update_mode == 'download') {
                    if ($use_method == '.zip') {
                        $compress = new compress_zip('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method);
                    } else {
                        $compress = new compress_tar('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method, $use_method);
                    }
                } else {
                    $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', ''));
                    $transfer->open_session();
                }
                // Ok, go through the update list and do the operations based on their status
                foreach ($install_list as $status => $files) {
                    foreach ($files as $file_struct) {
                        // Skip this file if the user selected to not update it
                        if (in_array($file_struct['filename'], $no_update)) {
                            continue;
                        }
                        $original_filename = $file_struct['custom'] ? $file_struct['original'] : $file_struct['filename'];
                        switch ($status) {
                            case 'new':
                            case 'new_conflict':
                            case 'not_modified':
                                if ($update_mode == 'download') {
                                    $compress->add_custom_file($this->new_location . $original_filename, $file_struct['filename']);
                                } else {
                                    if ($status != 'new') {
                                        $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
                                    }
                                    $transfer->copy_file($this->new_location . $original_filename, $file_struct['filename']);
                                }
                                break;
                            case 'modified':
                                $option = isset($modified[$file_struct['filename']]) ? $modified[$file_struct['filename']] : 0;
                                switch ($option) {
                                    case MERGE_NO_MERGE_NEW:
                                        $contents = file_get_contents($this->new_location . $original_filename);
                                        break;
                                    case MERGE_NO_MERGE_MOD:
                                        $contents = file_get_contents($phpbb_root_path . $file_struct['filename']);
                                        break;
                                    default:
                                        $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename);
                                        $contents = implode("\n", $diff->merged_output());
                                        unset($diff);
                                        break;
                                }
                                if ($update_mode == 'download') {
                                    $compress->add_data($contents, $file_struct['filename']);
                                } else {
                                    // @todo add option to specify if a backup file should be created?
                                    $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
                                    $transfer->write_file($file_struct['filename'], $contents);
                                }
                                break;
                            case 'conflict':
                                $option = $conflicts[$file_struct['filename']];
                                $contents = '';
                                switch ($option) {
                                    case MERGE_NO_MERGE_NEW:
                                        $contents = file_get_contents($this->new_location . $original_filename);
                                        break;
                                    case MERGE_NO_MERGE_MOD:
                                        $contents = file_get_contents($phpbb_root_path . $file_struct['filename']);
                                        break;
                                    default:
                                        $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename);
                                        if ($option == MERGE_NEW_FILE) {
                                            $contents = implode("\n", $diff->merged_new_output());
                                        } else {
                                            if ($option == MERGE_MOD_FILE) {
                                                $contents = implode("\n", $diff->merged_orig_output());
                                            } else {
                                                unset($diff);
                                                break 2;
                                            }
                                        }
                                        unset($diff);
                                        break;
                                }
                                if ($update_mode == 'download') {
                                    $compress->add_data($contents, $file_struct['filename']);
                                } else {
                                    $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak');
                                    $transfer->write_file($file_struct['filename'], $contents);
                                }
                                break;
                        }
                    }
                }
                if ($update_mode == 'download') {
                    $compress->close();
                    $compress->download($archive_filename, $download_filename);
                    @unlink($phpbb_root_path . 'store/' . $archive_filename . $use_method);
                    exit;
                } else {
                    $transfer->close_session();
                    $template->assign_vars(array('S_UPLOAD_SUCCESS' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&amp;sub=final")));
                    return;
                }
                break;
        }
        switch ($sub) {
            case 'final':
                $this->tpl_name = 'garage_install_install';
                // Remove the lock file
                @unlink($phpbb_root_path . 'cache/install_lock');
                $sql = $db->sql_build_query('SELECT', array('SELECT' => 'c.config_name, c.config_value', 'FROM' => array(GARAGE_CONFIG_TABLE => 'c')));
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $garage_config[$row['config_name']] = $row['config_value'];
                }
                $db->sql_freeresult($result);
                add_log('admin', 'LOG_GARAGE_INSTALL', $garage_config['version']);
                $template->assign_vars(array('S_FILE_CHECK' => false, 'TITLE' => $lang['INSTALL_CONGRATS'], 'BODY' => sprintf($lang['INSTALL_CONGRATS_EXPLAIN'], $garage_config['version'], append_sid($phpbb_root_path . 'garage/install/index.' . $phpEx, 'mode=convert&amp;'), '../docs/README.html')));
                $sql = 'INSERT INTO ' . GARAGE_CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array('config_name' => 'installed', 'config_value' => 1));
                $db->sql_query($sql);
                $cache->purge();
                break;
        }
    }
Exemplo n.º 21
0
    /**
     * Install/add an element, doing various checks as we go
     */
    function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright, $store_db = 0)
    {
        global $phpbb_root_path, $db, $user;
        // we parse the cfg here (again)
        $cfg_data = parse_cfg_file("{$root_path}{$mode}/{$mode}.cfg");
        switch ($mode) {
            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_type = strtoupper($mode);
        if (!$name) {
            $error[] = $user->lang[$l_type . '_ERR_STYLE_NAME'];
        }
        // Check length settings
        if (utf8_strlen($name) > 30) {
            $error[] = $user->lang[$l_type . '_ERR_NAME_LONG'];
        }
        if (utf8_strlen($copyright) > 60) {
            $error[] = $user->lang[$l_type . '_ERR_COPY_LONG'];
        }
        // Check if the name already exist
        $sql = "SELECT {$mode}_id\n\t\t\tFROM {$sql_from}\n\t\t\tWHERE {$mode}_name = '" . $db->sql_escape($name) . "'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if ($row) {
            // If it exist, we just use the style on installation
            if ($action == 'install') {
                $id = $row[$mode . '_id'];
                return false;
            }
            $error[] = $user->lang[$l_type . '_ERR_NAME_EXIST'];
        }
        if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from']) {
            if ($mode === 'template') {
                $select_bf = ', bbcode_bitfield';
            } else {
                $select_bf = '';
            }
            $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, {$mode}_storedb {$select_bf}\n\t\t\t\tFROM {$sql_from}\n\t\t\t\tWHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "'\n\t\t\t\t\tAND {$mode}_inherits_id = 0";
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$row) {
                $error[] = sprintf($user->lang[$l_type . '_ERR_REQUIRED_OR_INCOMPLETE'], $cfg_data['inherit_from']);
            } else {
                $inherit_id = $row["{$mode}_id"];
                $inherit_path = $row["{$mode}_path"];
                $inherit_bf = $mode === 'template' ? $row["bbcode_bitfield"] : false;
                $cfg_data['store_db'] = $row["{$mode}_storedb"];
                $store_db = $row["{$mode}_storedb"];
            }
        } else {
            $inherit_id = 0;
            $inherit_path = '';
            $inherit_bf = false;
        }
        if (sizeof($error)) {
            return false;
        }
        $sql_ary = array($mode . '_name' => $name, $mode . '_copyright' => $copyright, $mode . '_path' => $path);
        switch ($mode) {
            case 'template':
                // We check if the template author defined a different bitfield
                if (!empty($cfg_data['template_bitfield'])) {
                    $sql_ary['bbcode_bitfield'] = $cfg_data['template_bitfield'];
                } else {
                    if ($inherit_bf) {
                        $sql_ary['bbcode_bitfield'] = $inherit_bf;
                    } else {
                        $sql_ary['bbcode_bitfield'] = TEMPLATE_BITFIELD;
                    }
                }
                // We set a pre-defined bitfield here which we may use further in 3.2
                $sql_ary += array('template_storedb' => $store_db);
                if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from']) {
                    $sql_ary += array('template_inherits_id' => $inherit_id, 'template_inherit_path' => $inherit_path);
                }
                break;
            case 'theme':
                // We are only interested in the theme configuration for now
                if (isset($cfg_data['parse_css_file']) && $cfg_data['parse_css_file']) {
                    $store_db = 1;
                }
                $sql_ary += array('theme_storedb' => $store_db, 'theme_data' => $store_db ? $this->db_theme_data($sql_ary, false, $root_path) : '', 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$path}/theme/stylesheet.css"));
                break;
                // all the heavy lifting is done later
            // all the heavy lifting is done later
            case 'imageset':
                break;
        }
        $db->sql_transaction('begin');
        $sql = "INSERT INTO {$sql_from}\n\t\t\t" . $db->sql_build_array('INSERT', $sql_ary);
        $db->sql_query($sql);
        $id = $db->sql_nextid();
        if ($mode == 'template' && $store_db) {
            $filelist = filelist("{$root_path}template", '', 'html');
            $this->store_templates('insert', $id, $path, $filelist);
        } else {
            if ($mode == 'imageset') {
                $cfg_data = parse_cfg_file("{$root_path}{$mode}/imageset.cfg");
                $imageset_definitions = array();
                foreach ($this->imageset_keys as $topic => $key_array) {
                    $imageset_definitions = array_merge($imageset_definitions, $key_array);
                }
                foreach ($cfg_data as $key => $value) {
                    if (strpos($value, '*') !== false) {
                        if (substr($value, -1, 1) === '*') {
                            list($image_filename, $image_height) = explode('*', $value);
                            $image_width = 0;
                        } else {
                            list($image_filename, $image_height, $image_width) = explode('*', $value);
                        }
                    } else {
                        $image_filename = $value;
                        $image_height = $image_width = 0;
                    }
                    if (strpos($key, 'img_') === 0 && $image_filename) {
                        $key = substr($key, 4);
                        if (in_array($key, $imageset_definitions)) {
                            $sql_ary = array('image_name' => $key, 'image_filename' => str_replace('{PATH}', "styles/{$path}/imageset/", trim($image_filename)), 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $id, 'image_lang' => '');
                            $db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                        }
                    }
                }
                unset($cfg_data);
                $sql = 'SELECT lang_dir
				FROM ' . LANG_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    if (@file_exists("{$root_path}{$mode}/{$row['lang_dir']}/imageset.cfg")) {
                        $cfg_data_imageset_data = parse_cfg_file("{$root_path}{$mode}/{$row['lang_dir']}/imageset.cfg");
                        foreach ($cfg_data_imageset_data as $image_name => $value) {
                            if (strpos($value, '*') !== false) {
                                if (substr($value, -1, 1) === '*') {
                                    list($image_filename, $image_height) = explode('*', $value);
                                    $image_width = 0;
                                } else {
                                    list($image_filename, $image_height, $image_width) = explode('*', $value);
                                }
                            } else {
                                $image_filename = $value;
                                $image_height = $image_width = 0;
                            }
                            if (strpos($image_name, 'img_') === 0 && $image_filename) {
                                $image_name = substr($image_name, 4);
                                if (in_array($image_name, $imageset_definitions)) {
                                    $sql_ary = array('image_name' => $image_name, 'image_filename' => $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $id, 'image_lang' => $row['lang_dir']);
                                    $db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                                }
                            }
                        }
                        unset($cfg_data_imageset_data);
                    }
                }
                $db->sql_freeresult($result);
            }
        }
        $db->sql_transaction('commit');
        $log = $store_db ? 'LOG_' . $l_type . '_ADD_DB' : 'LOG_' . $l_type . '_ADD_FS';
        add_log('admin', $log, $name);
        // Return store_db in case it had to be altered
        return $store_db;
    }
Exemplo n.º 22
0
 function main($id, $mode)
 {
     global $db, $user, $template, $cache;
     global $config, $pbwow_config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
     // Some basic includes
     if (!function_exists('db_theme_data')) {
         include $phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx;
     }
     if (!class_exists('phpbb_db_tools')) {
         include $phpbb_root_path . 'includes/db/db_tools.' . $phpEx;
     }
     $db_tool = new phpbb_db_tools($db);
     $user->add_lang('mods/lang_pbwow_acp');
     if (isset($display_vars['lang'])) {
         $user->add_lang($display_vars['lang']);
     }
     $this->tpl_name = 'acp_pbwow2';
     // Some constants
     $module_version = '2.0.9';
     $dbtable = defined('PBWOW2_CONFIG_TABLE') ? PBWOW2_CONFIG_TABLE : '';
     $legacy_dbtable = defined('PBWOW_CONFIG_TABLE') ? PBWOW_CONFIG_TABLE : '';
     $topics_table = TOPICS_TABLE;
     $chars_table = defined('PBWOW2_CHARS_TABLE') ? PBWOW2_CHARS_TABLE : '';
     $allow_fopen = ini_get('allow_url_fopen') ? true : false;
     $constantsokay = $dbokay = $legacy_constants = $legacy_db_active = $legacy_topics_mod = false;
     $style_version = $imageset_version = $template_version = $theme_version = '';
     // Check if constants have been set correctly
     // if yes, check if the config table exists
     // if yes, load the config variables
     if ($dbtable == $table_prefix . 'pbwow2_config') {
         $constantsokay = true;
         if ($db_tool->sql_table_exists($dbtable)) {
             $dbokay = true;
             $pbwow_config = $this->get_pbwow_config();
             $this->new_config = $pbwow_config;
             if (!isset($pbwow_config['pbwow2_version'])) {
                 if (isset($config['pbwow2_version']) && !empty($config['pbwow2_version'])) {
                     $pbwow_config['pbwow2_version'] = $config['pbwow2_version'];
                 }
             }
         }
     }
     if ($chars_table == $table_prefix . 'pbwow2_chars') {
         $chars_constokay = true;
         if ($db_tool->sql_table_exists($chars_table)) {
             $chars_dbokay = true;
         }
     }
     if ($mode == 'overview') {
         $cpflist = $this->get_cpf_list();
         $style_root = $phpbb_root_path . 'styles/pbwow2/';
         if (file_exists($style_root . 'style.cfg')) {
             $values = parse_cfg_file($style_root . 'style.cfg');
             $style_version = isset($values['version']) ? $values['version'] : '';
         }
         if (file_exists($style_root . 'imageset/imageset.cfg')) {
             $values = parse_cfg_file($style_root . 'imageset/imageset.cfg');
             $imageset_version = isset($values['version']) ? $values['version'] : '';
         }
         if (file_exists($style_root . 'template/template.cfg')) {
             $values = parse_cfg_file($style_root . 'template/template.cfg');
             $template_version = isset($values['version']) ? $values['version'] : '';
         }
         if (file_exists($style_root . 'theme/theme.cfg')) {
             $values = parse_cfg_file($style_root . 'theme/theme.cfg');
             $theme_version = isset($values['version']) ? $values['version'] : '';
         }
         $versions = $this->obtain_pbwow_version_info(request_var('versioncheck_force', false), true);
         // Check if old constants are still being used
         if (!empty($legacy_dbtable)) {
             $legacy_constants = true;
         }
         // Check if old table still exists
         if ($db_tool->sql_table_exists($legacy_dbtable) || $db_tool->sql_table_exists($table_prefix . 'pbwow_config')) {
             $legacy_db_active = true;
         }
         // Check if topics table has been modded
         if ($db_tool->sql_column_exists(TOPICS_TABLE, 'topic_first_poster_rank_img') || $db_tool->sql_column_exists(TOPICS_TABLE, 'topic_first_poster_rank_title')) {
             $legacy_topics_mod = true;
         }
     }
     /**
      *	Validation types are:
      *		string, int, bool,
      *		script_path (absolute path in url - beginning with / and no trailing slash),
      *		rpath (relative), rwpath (realtive, writeable), path (relative path, but able to escape the root), wpath (writeable)
      */
     switch ($mode) {
         case 'overview':
             $display_vars = array('title' => 'ACP_PBWOW2_OVERVIEW_TITLE', 'vars' => array());
             break;
         case 'config':
             $display_vars = array('title' => 'ACP_PBWOW_CONFIG_TITLE', 'vars' => array('legend1' => 'ACP_PBWOW_LOGO', 'logo_size_width' => array('lang' => 'PBWOW_LOGO_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'logo_size_height' => array('lang' => 'PBWOW_LOGO_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'logo_enable' => array('lang' => 'PBWOW_LOGO_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'logo_src' => array('lang' => 'PBWOW_LOGO_SRC', 'validate' => 'string', 'type' => 'text:20:255', 'explain' => true), 'logo_size' => array('lang' => 'PBWOW_LOGO_SIZE', 'validate' => 'int:0', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), 'logo_margins' => array('lang' => 'PBWOW_LOGO_MARGINS', 'validate' => 'string', 'type' => 'text:20:20', 'explain' => true), 'legend2' => 'ACP_PBWOW_TOPBAR', 'topbar_enable' => array('lang' => 'PBWOW_TOPBAR_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'topbar_code' => array('lang' => 'PBWOW_TOPBAR_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'topbar_fixed' => array('lang' => 'PBWOW_TOPBAR_FIXED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend3' => 'ACP_PBWOW_HEADERLINKS', 'headerlinks_enable' => array('lang' => 'PBWOW_HEADERLINKS_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'headerlinks_code' => array('lang' => 'PBWOW_HEADERLINKS_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'legend4' => 'ACP_PBWOW_NAVMENU', 'navmenu_enable' => array('lang' => 'PBWOW_NAVMENU_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'legend5' => 'ACP_PBWOW_IE6MESSAGE', 'ie6message_enable' => array('lang' => 'PBWOW_IE6MESSAGE_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'ie6message_code' => array('lang' => 'PBWOW_IE6MESSAGE_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'legend6' => 'ACP_PBWOW_VIDEOBG', 'videobg_enable' => array('lang' => 'PBWOW_VIDEOBG_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'videobg_allpages' => array('lang' => 'PBWOW_VIDEOBG_ALLPAGES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'bg_fixed' => array('lang' => 'PBWOW_BG_FIXED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend7' => 'ACP_PBWOW_BNETCHARS', 'bnetchars_enable' => array('lang' => 'PBWOW_BNETCHARS_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'bnetchars_cachetime' => array('lang' => 'PBWOW_BNETCHARS_CACHETIME', 'validate' => 'int:0', 'type' => 'text:6:6', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']), 'bnetchars_timeout' => array('lang' => 'PBWOW_BNETCHARS_TIMEOUT', 'validate' => 'int:0', 'type' => 'text:1:1', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']), 'legend8' => 'ACP_PBWOW_TOOLTIPS', 'wowtips_script' => array('lang' => 'PBWOW_WOWTIPS_SCRIPT', 'validate' => 'int', 'type' => 'custom', 'explain' => true, 'method' => 'select_single'), 'd3tips_script' => array('lang' => 'PBWOW_D3TIPS_SCRIPT', 'validate' => 'int', 'type' => 'custom', 'explain' => true, 'method' => 'select_single'), 'zamtips_enable' => array('lang' => 'PBWOW_ZAMTIPS_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'tooltips_region' => array('lang' => 'PBWOW_TOOLTIPS_REGION', 'validate' => 'int', 'type' => 'custom', 'explain' => true, 'method' => 'select_single'), 'tooltips_footer' => array('lang' => 'PBWOW_TOOLTIPS_FOOTER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'tooltips_local' => array('lang' => 'PBWOW_TOOLTIPS_LOCAL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true)));
             break;
         case 'poststyling':
             $display_vars = array('title' => 'ACP_PBWOW_POSTSTYLING_TITLE', 'vars' => array('legend1' => 'ACP_PBWOW_BLIZZ', 'blizz_enable' => array('lang' => 'PBWOW_BLIZZ_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'blizz_ranks' => array('lang' => 'PBWOW_BLIZZ_RANKS', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_ranks'), 'blizz_color' => array('lang' => 'PBWOW_BLIZZ_COLOR', 'validate' => 'string', 'type' => 'text:7:7', 'explain' => true), 'legend2' => 'ACP_PBWOW_PROPASS', 'propass_enable' => array('lang' => 'PBWOW_PROPASS_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'propass_ranks' => array('lang' => 'PBWOW_PROPASS_RANKS', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_ranks'), 'propass_color' => array('lang' => 'PBWOW_PROPASS_COLOR', 'validate' => 'string', 'type' => 'text:7:7', 'explain' => true), 'legend3' => 'ACP_PBWOW_RED', 'red_enable' => array('lang' => 'PBWOW_RED_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'red_ranks' => array('lang' => 'PBWOW_RED_RANKS', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_ranks'), 'red_color' => array('lang' => 'PBWOW_RED_COLOR', 'validate' => 'string', 'type' => 'text:7:7', 'explain' => true), 'legend4' => 'ACP_PBWOW_GREEN', 'green_enable' => array('lang' => 'PBWOW_GREEN_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'green_ranks' => array('lang' => 'PBWOW_GREEN_RANKS', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_ranks'), 'green_color' => array('lang' => 'PBWOW_GREEN_COLOR', 'validate' => 'string', 'type' => 'text:7:7', 'explain' => true)));
             break;
         case 'ads':
             $display_vars = array('title' => 'ACP_PBWOW_ADS_TITLE', 'vars' => array('legend1' => 'ACP_PBWOW_ADS_INDEX', 'ads_index_enable' => array('lang' => 'PBWOW_ADS_INDEX_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'ads_index_code' => array('lang' => 'PBWOW_ADS_INDEX_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'legend2' => 'ACP_PBWOW_ADS_TOP', 'ads_top_enable' => array('lang' => 'PBWOW_ADS_TOP_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'ads_top_code' => array('lang' => 'PBWOW_ADS_TOP_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'legend3' => 'ACP_PBWOW_ADS_BOTTOM', 'ads_bottom_enable' => array('lang' => 'PBWOW_ADS_BOTTOM_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'ads_bottom_code' => array('lang' => 'PBWOW_ADS_BOTTOM_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'legend4' => 'ACP_PBWOW_ADS_SIDE', 'ads_side_enable' => array('lang' => 'PBWOW_ADS_SIDE_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'ads_side_code' => array('lang' => 'PBWOW_ADS_SIDE_CODE', 'type' => 'textarea:6:6', 'explain' => true), 'legend5' => 'ACP_PBWOW_TRACKING', 'tracking_enable' => array('lang' => 'PBWOW_TRACKING_ENABLE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'tracking_code' => array('lang' => 'PBWOW_TRACKING_CODE', 'type' => 'textarea:6:6', 'explain' => true)));
             break;
     }
     $action = request_var('action', '');
     $submit = isset($_POST['submit']) ? true : false;
     $cfg_array = isset($_REQUEST['config']) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $this->new_config;
     $error = array();
     // We validate the complete config if we want
     validate_config_vars($display_vars['vars'], $cfg_array, $error);
     // Do not write values if there is an error
     if (sizeof($error)) {
         $submit = false;
     }
     // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... and then write to config
     foreach ($display_vars['vars'] as $config_name => $null) {
         if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
             continue;
         }
         $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
         if ($submit) {
             $this->set_pbwow_config($config_name, $config_value);
         }
     }
     if ($submit) {
         if ($action == 'refresh_topic_ranks' && $legacy_topics_mod == true) {
             $this->refresh_topic_ranks();
             $cache->purge();
         }
         if ($action == 'create_topic_ranks' && $legacy_topics_mod == false) {
             $db_tool->sql_column_add($topics_table, 'topic_first_poster_rank_img', array('VCHAR', ''));
             $db_tool->sql_column_add($topics_table, 'topic_first_poster_rank_title', array('VCHAR', ''));
             add_log('admin', 'Topics MOD installed', $user->lang['ACP_PBWOW2_' . strtoupper($mode)]);
             trigger_error('Topics MOD installed' . adm_back_link($this->u_action));
         }
         if (($action == 'drop_topic_ranks' || $action == 'remove_legacy') && $legacy_topics_mod == true) {
             $db_tool->sql_column_remove($topics_table, 'topic_first_poster_rank_img');
             $db_tool->sql_column_remove($topics_table, 'topic_first_poster_rank_title');
             add_log('admin', 'Topics MOD uninstalled', $user->lang['ACP_PBWOW2_' . strtoupper($mode)]);
             trigger_error('Topics MOD uninstalled' . adm_back_link($this->u_action));
         }
         if ($action == 'refresh_all_themes') {
             $this->refresh_all_themes();
             $cache->purge();
             add_log('admin', 'LOG_THEME_REFRESHED', $user->lang['ACP_PBWOW2_' . strtoupper($mode)]);
             trigger_error('All theme data refreshed' . adm_back_link($this->u_action));
         }
         // Get data from select boxes and store in DB
         if ($mode == 'poststyling') {
             $this->store_select_options('blizz_ranks');
             $this->store_select_options('propass_ranks');
             $this->store_select_options('red_ranks');
             $this->store_select_options('green_ranks');
             add_log('admin', 'LOG_PBWOW_CONFIG', $user->lang['ACP_PBWOW2_' . strtoupper($mode)]);
             $cache->purge();
             trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
         }
         if ($mode == ('config' || 'ads')) {
             $this->store_select_options('wowtips_script');
             $this->store_select_options('d3tips_script');
             $this->store_select_options('tooltips_region');
             add_log('admin', 'LOG_PBWOW_CONFIG', $user->lang['ACP_PBWOW2_' . strtoupper($mode)]);
             $cache->purge();
             trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
         }
     }
     $this->page_title = $display_vars['title'];
     $title_explain = $user->lang[$display_vars['title'] . '_EXPLAIN'];
     $template->assign_vars(array('L_TITLE' => $user->lang[$display_vars['title']], 'L_TITLE_EXPLAIN' => $title_explain, 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'S_CONSTANTSOKAY' => $constantsokay ? true : false, 'PBWOW_DBTABLE' => $dbtable, 'S_DBOKAY' => $dbokay ? true : false, 'L_PBWOW_DB_GOOD' => sprintf($user->lang['PBWOW_DB_GOOD'], $dbtable), 'L_PBWOW_DB_BAD' => sprintf($user->lang['PBWOW_DB_BAD'], $dbtable), 'L_PBWOW_RANKS_CREATE_EXPLAIN' => sprintf($user->lang['PBWOW_RANKS_CREATE_EXPLAIN'], $topics_table, $topics_table), 'L_PBWOW_CHARSDB_GOOD' => sprintf($user->lang['PBWOW_CHARSDB_GOOD'], $chars_table), 'L_PBWOW_CHARSDB_BAD' => sprintf($user->lang['PBWOW_CHARSDB_BAD'], $chars_table), 'TOPICS_TABLE' => $topics_table, 'U_ACTION' => $this->u_action));
     if ($mode == 'overview') {
         $template->assign_vars(array('S_INDEX' => true, 'DB_VERSION' => isset($pbwow_config['pbwow2_version']) ? $pbwow_config['pbwow2_version'] : '', 'MODULE_VERSION' => isset($module_version) ? $module_version : '', 'STYLE_VERSION' => $style_version, 'IMAGESET_VERSION' => $imageset_version, 'TEMPLATE_VERSION' => $template_version, 'THEME_VERSION' => $theme_version, 'S_CHECK_V' => empty($versions) ? false : true, 'DB_VERSION_V' => isset($versions['db_version']['version']) ? $versions['db_version']['version'] : '', 'MODULE_VERSION_V' => isset($versions['module_version']['version']) ? $versions['module_version']['version'] : '', 'ATEMPLATE_VERSION_V' => isset($versions['atemplate_version']['version']) ? $versions['atemplate_version']['version'] : '', 'STYLE_VERSION_V' => isset($versions['style_version']['version']) ? $versions['style_version']['version'] : '', 'IMAGESET_VERSION_V' => isset($versions['imageset_version']['version']) ? $versions['imageset_version']['version'] : '', 'TEMPLATE_VERSION_V' => isset($versions['template_version']['version']) ? $versions['template_version']['version'] : '', 'THEME_VERSION_V' => isset($versions['theme_version']['version']) ? $versions['theme_version']['version'] : '', 'U_VERSIONCHECK_FORCE' => append_sid($this->u_action . '&amp;versioncheck_force=1'), 'S_ALLOW_FOPEN' => $allow_fopen, 'S_CPF_ON_MEMBERLIST' => $config['load_cpf_memberlist'] == 1 ? true : false, 'S_CPF_ON_VIEWPROFILE' => $config['load_cpf_viewprofile'] == 1 ? true : false, 'S_CPF_ON_VIEWTOPIC' => $config['load_cpf_viewtopic'] == 1 ? true : false, 'S_CPF_PBGUILD' => isset($cpflist['pbguild']) && $cpflist['pbguild']['field_no_view'] == 0 ? true : false, 'S_CPF_PBREALM' => isset($cpflist['pbrealm']) && $cpflist['pbrealm']['field_no_view'] == 0 ? true : false, 'S_CPF_PBLEVEL' => isset($cpflist['pblevel']) && $cpflist['pblevel']['field_no_view'] == 0 ? true : false, 'S_CPF_PBRACE' => isset($cpflist['pbrace']) && $cpflist['pbrace']['field_no_view'] == 0 ? true : false, 'S_CPF_PBGENDER' => isset($cpflist['pbgender']) && $cpflist['pbgender']['field_no_view'] == 0 ? true : false, 'S_CPF_PBCLASS' => isset($cpflist['pbclass']) && $cpflist['pbclass']['field_no_view'] == 0 ? true : false, 'S_CPF_PBPVPRANK' => isset($cpflist['pbpvprank']) && $cpflist['pbpvprank']['field_no_view'] == 0 ? true : false, 'S_CPF_PBARMORYCHARLINK' => isset($cpflist['pbarmorycharlink']) && $cpflist['pbarmorycharlink']['field_no_view'] == 0 ? true : false, 'S_CPF_PBARMORYGUILDLINK' => isset($cpflist['pbarmoryguildlink']) && $cpflist['pbarmoryguildlink']['field_no_view'] == 0 ? true : false, 'S_CPF_PBDCLASS' => isset($cpflist['pbdclass']) && $cpflist['pbguild']['pbdclass'] == 0 ? true : false, 'S_CPF_PBDGENDER' => isset($cpflist['pbdgender']) && $cpflist['pbguild']['pbdgender'] == 0 ? true : false, 'S_CPF_PBDFOLLOWER' => isset($cpflist['pbdfollower']) && $cpflist['pbguild']['pbdfollower'] == 0 ? true : false, 'S_BNETCHARS_ACTIVE' => isset($pbwow_config['bnetchars_enable']) && $pbwow_config['bnetchars_enable'] ? true : false, 'S_BNETCHARS_CONSTOKAY' => $chars_constokay ? true : false, 'S_BNETCHARS_DBOKAY' => $chars_dbokay ? true : false, 'S_CPF_PBBNETHOST' => isset($cpflist['pbbnethost']) && $cpflist['pbbnethost']['field_no_view'] == 0 ? true : false, 'S_CPF_PBBNETREALM' => isset($cpflist['pbbnetrealm']) && $cpflist['pbbnetrealm']['field_no_view'] == 0 ? true : false, 'S_CPF_PBBNETNAME' => isset($cpflist['pbbnetname']) && $cpflist['pbbnetname']['field_no_view'] == 0 ? true : false, 'S_CPF_PBNETAVATAR' => isset($cpflist['pbbnetavatar']) && $cpflist['pbbnetavatar']['field_no_view'] == 0 ? true : false, 'S_LEGACY_CONSTANTS' => $legacy_constants, 'S_LEGACY_DB_ACTIVE' => $legacy_db_active, 'S_LEGACY_TOPICS_MOD' => $legacy_topics_mod));
     }
     // Output relevant page
     foreach ($display_vars['vars'] as $config_key => $vars) {
         if (!is_array($vars) && strpos($config_key, 'legend') === false) {
             continue;
         }
         if (strpos($config_key, 'legend') !== false) {
             $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars));
             continue;
         }
         $type = explode(':', $vars['type']);
         $l_explain = '';
         if ($vars['explain'] && isset($vars['lang_explain'])) {
             $l_explain = isset($user->lang[$vars['lang_explain']]) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
         } else {
             if ($vars['explain']) {
                 $l_explain = isset($user->lang[$vars['lang'] . '_EXPLAIN']) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
             }
         }
         $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
         if (empty($content)) {
             continue;
         }
         $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => isset($user->lang[$vars['lang']]) ? $user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => $content));
         unset($display_vars['vars'][$config_key]);
     }
 }
Exemplo n.º 23
0
    public function styles_update()
    {
        // Get list of valid 3.1 styles
        $available_styles = array('prosilver');
        $iterator = new \DirectoryIterator($this->phpbb_root_path . 'styles');
        $skip_dirs = array('.', '..', 'prosilver');
        foreach ($iterator as $fileinfo) {
            if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) {
                $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg');
                if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) {
                    // 3.1 style
                    $available_styles[] = $fileinfo->getFilename();
                }
            }
        }
        // Get all installed styles
        if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset')) {
            $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path
				FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i\n\t\t\t\tWHERE t.template_id = s.template_id\n\t\t\t\t\tAND c.theme_id = s.theme_id\n\t\t\t\t\tAND i.imageset_id = s.imageset_id";
        } else {
            $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id
				FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "styles_theme c\n\t\t\t\tWHERE t.template_id = s.template_id\n\t\t\t\t\tAND c.theme_id = s.theme_id";
        }
        $result = $this->db->sql_query($sql);
        $styles = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $styles[] = $row;
        }
        $this->db->sql_freeresult($result);
        // Decide which styles to keep, all others will be deleted
        $valid_styles = array();
        foreach ($styles as $style_row) {
            if ($style_row['template_inherits_id'] == 0 && $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && in_array($style_row['template_path'], $available_styles)) {
                // Valid style. Keep it
                $sql_ary = array('style_path' => $style_row['template_path'], 'bbcode_bitfield' => $style_row['bbcode_bitfield'], 'style_parent_id' => 0, 'style_parent_tree' => '');
                $this->sql_query('UPDATE ' . STYLES_TABLE . '
					SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE style_id = ' . $style_row['style_id']);
                $valid_styles[] = (int) $style_row['style_id'];
            }
        }
        // Remove old entries from styles table
        if (!sizeof($valid_styles)) {
            // No valid styles: remove everything and add prosilver
            $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary);
            $sql_ary = array('style_name' => 'prosilver', 'style_copyright' => '&copy; phpBB Limited', 'style_active' => 1, 'style_path' => 'prosilver', 'bbcode_bitfield' => 'lNg=', 'style_parent_id' => 0, 'style_parent_tree' => '', 'imageset_id' => 0, 'template_id' => 0, 'theme_id' => 0);
            $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
            $this->sql_query($sql);
            $sql = 'SELECT style_id
				FROM ' . $table . "\n\t\t\t\tWHERE style_name = 'prosilver'";
            $result = $this->sql_query($sql);
            $default_style = $this->db->sql_fetchfield($result);
            $this->db->sql_freeresult($result);
            set_config('default_style', $default_style);
            $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0';
            $this->sql_query($sql);
        } else {
            // There are valid styles in styles table. Remove styles that are outdated
            $this->sql_query('DELETE FROM ' . STYLES_TABLE . '
				WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true));
            // Change default style
            if (!in_array($this->config['default_style'], $valid_styles)) {
                $this->sql_query('UPDATE ' . CONFIG_TABLE . "\n\t\t\t\t\tSET config_value = '" . $valid_styles[0] . "'\n\t\t\t\t\tWHERE config_name = 'default_style'");
            }
            // Reset styles for users
            $this->sql_query('UPDATE ' . USERS_TABLE . '
				SET user_style = 0
				WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true));
        }
    }
Exemplo n.º 24
0
 /**
  * Obtain cfg file data
  */
 function obtain_cfg_items($theme)
 {
     global $config, $phpbb_root_path;
     $parsed_items = array('theme' => array(), 'template' => array(), 'imageset' => array());
     foreach ($parsed_items as $key => $parsed_array) {
         $parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
         if ($parsed_array === false) {
             $parsed_array = array();
         }
         $reparse = false;
         $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg';
         if (!file_exists($filename)) {
             continue;
         }
         if (!isset($parsed_array['filetime']) || $config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']) {
             $reparse = true;
         }
         // Re-parse cfg file
         if ($reparse) {
             $parsed_array = parse_cfg_file($filename);
             $parsed_array['filetime'] = @filemtime($filename);
             $this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
         }
         $parsed_items[$key] = $parsed_array;
     }
     return $parsed_items;
 }
Exemplo n.º 25
0
	/**
	* Populate the language tables
	*/
	function add_language($mode, $sub)
	{
		global $db, $lang, $phpbb_root_path, $phpEx;

		$dir = @opendir($phpbb_root_path . 'language');

		if (!$dir)
		{
			$this->error('Unable to access the language directory', __LINE__, __FILE__);
		}

		while (($file = readdir($dir)) !== false)
		{
			$path = $phpbb_root_path . 'language/' . $file;

			if ($file == '.' || $file == '..' || is_link($path) || is_file($path) || $file == 'CVS')
			{
				continue;
			}

			if (is_dir($path) && file_exists($path . '/iso.txt'))
			{
				$lang_file = file("$path/iso.txt");

				$lang_pack = array(
					'lang_iso'			=> basename($path),
					'lang_dir'			=> basename($path),
					'lang_english_name'	=> trim(htmlspecialchars($lang_file[0])),
					'lang_local_name'	=> trim(htmlspecialchars($lang_file[1], ENT_COMPAT, 'UTF-8')),
					'lang_author'		=> trim(htmlspecialchars($lang_file[2], ENT_COMPAT, 'UTF-8')),
				);

				$db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $lang_pack));

				if ($db->sql_error_triggered)
				{
					$error = $db->sql_error($db->sql_error_sql);
					$this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
				}

				$valid_localized = array(
					'icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply',
				);

				$sql_ary = array();

				$sql = 'SELECT *
					FROM ' . STYLES_IMAGESET_TABLE;
				$result = $db->sql_query($sql);

				while ($imageset_row = $db->sql_fetchrow($result))
				{
					if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['lang_iso']}/imageset.cfg"))
					{
						$cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$lang_pack['lang_iso']}/imageset.cfg");
						foreach ($cfg_data_imageset_data as $image_name => $value)
						{
							if (strpos($value, '*') !== false)
							{
								if (substr($value, -1, 1) === '*')
								{
									list($image_filename, $image_height) = explode('*', $value);
									$image_width = 0;
								}
								else
								{
									list($image_filename, $image_height, $image_width) = explode('*', $value);
								}
							}
							else
							{
								$image_filename = $value;
								$image_height = $image_width = 0;
							}

							if (strpos($image_name, 'img_') === 0 && $image_filename)
							{
								$image_name = substr($image_name, 4);
								if (in_array($image_name, $valid_localized))
								{
									$sql_ary[] = array(
										'image_name'		=> (string) $image_name,
										'image_filename'	=> (string) $image_filename,
										'image_height'		=> (int) $image_height,
										'image_width'		=> (int) $image_width,
										'imageset_id'		=> (int) $imageset_row['imageset_id'],
										'image_lang'		=> (string) $lang_pack['lang_iso'],
									);
								}
							}
						}
					}
				}
				$db->sql_freeresult($result);

				if (sizeof($sql_ary))
				{
					$db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary);

					if ($db->sql_error_triggered)
					{
						$error = $db->sql_error($db->sql_error_sql);
						$this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__);
					}
				}
			}
		}
		closedir($dir);
	}
Exemplo n.º 26
0
 private function qi_get_styles()
 {
     global $phpbb_root_path, $settings;
     $styles = array();
     $dh = dir($this->styles_path);
     while (($dir = $dh->read()) !== false) {
         // Ignore everything that starts with a dot, is a file or prosilver.
         if ($dir[0] === '.' || is_file($this->styles_path . $dir)) {
             continue;
         }
         $style_name = '';
         $style_ary = array('style_id' => $dir == 'prosilver' ? 1 : 0, 'template_id' => 0, 'theme_id' => 0, 'imageset_id' => 0, 'store_db' => 0, 'style_active' => 1);
         // Read cfg files and fill $style_ary.
         // style.cfg
         $install_path = $this->styles_path . $dir;
         $cfg_file = $install_path . '/style.cfg';
         $rows = parse_cfg_file($cfg_file);
         $style_name = !empty($rows['name']) ? $rows['name'] : '';
         $style_ary['style_name'] = !empty($rows['name']) ? $rows['name'] : '';
         $style_ary['style_copyright'] = !empty($rows['copyright']) ? $rows['copyright'] : '';
         // imageset.cfg
         $cfg_file = $install_path . '/imageset/imageset.cfg';
         $rows = parse_cfg_file($cfg_file);
         $style_ary['imageset_name'] = !empty($rows['name']) ? $rows['name'] : '';
         $style_ary['imageset_copyright'] = !empty($rows['copyright']) ? $rows['copyright'] : '';
         // template.cfg
         $cfg_file = $install_path . '/template/template.cfg';
         $rows = parse_cfg_file($cfg_file);
         $style_ary['template_name'] = !empty($rows['name']) ? $rows['name'] : '';
         $style_ary['template_copyright'] = !empty($rows['copyright']) ? $rows['copyright'] : '';
         $style_ary['bbcode_bitfield'] = !empty($rows['template_bitfield']) ? $rows['template_bitfield'] : '';
         $style_ary['inherit_from'] = !empty($rows['inherit_from']) ? $rows['inherit_from'] : '';
         // theme.cfg
         $cfg_file = $install_path . '/theme/theme.cfg';
         $rows = parse_cfg_file($cfg_file);
         $style_ary['theme_name'] = !empty($rows['name']) ? $rows['name'] : '';
         $style_ary['theme_copyright'] = !empty($rows['copyright']) ? $rows['copyright'] : '';
         // Other stuff
         $style_ary['style_default'] = $this->qi_default_style == $style_name ? 1 : 0;
         $style_ary['install_path'] = $dir;
         $this->qi_styles[$style_name] = $style_ary;
     }
     $dh->close();
 }