[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\db\migration\data\v31x; 15 16 class style_update extends \phpbb\db\migration\migration 17 { 18 static public function depends_on() 19 { 20 return array('\phpbb\db\migration\data\v310\gold'); 21 } 22 23 public function update_data() 24 { 25 return array( 26 array('custom', array(array($this, 'update_installed_styles'))), 27 ); 28 } 29 30 public function update_installed_styles() 31 { 32 // Get all currently available styles 33 $styles = $this->find_style_dirs(); 34 $style_paths = $style_ids = array(); 35 36 $sql = 'SELECT style_path, style_id 37 FROM ' . $this->table_prefix . 'styles'; 38 $result = $this->db->sql_query($sql); 39 while ($styles_row = $this->db->sql_fetchrow()) 40 { 41 if (in_array($styles_row['style_path'], $styles)) 42 { 43 $style_paths[] = $styles_row['style_path']; 44 $style_ids[] = $styles_row['style_id']; 45 } 46 } 47 $this->db->sql_freeresult($result); 48 49 // Install prosilver if no style is available and prosilver can be installed 50 if (empty($style_paths) && in_array('prosilver', $styles)) 51 { 52 // Try to parse config file 53 $cfg = parse_cfg_file($this->phpbb_root_path . 'styles/prosilver/style.cfg'); 54 55 // Stop running this if prosilver cfg file can't be read 56 if (empty($cfg)) 57 { 58 throw new \RuntimeException('No styles available and could not fall back to prosilver.'); 59 } 60 61 $style = array( 62 'style_name' => 'prosilver', 63 'style_copyright' => '© phpBB Limited', 64 'style_active' => 1, 65 'style_path' => 'prosilver', 66 'bbcode_bitfield' => 'kNg=', 67 'style_parent_id' => 0, 68 'style_parent_tree' => '', 69 ); 70 71 // Add to database 72 $this->db->sql_transaction('begin'); 73 74 $sql = 'INSERT INTO ' . $this->table_prefix . 'styles 75 ' . $this->db->sql_build_array('INSERT', $style); 76 $this->db->sql_query($sql); 77 78 $style_id = $this->db->sql_nextid(); 79 $style_ids[] = $style_id; 80 81 $this->db->sql_transaction('commit'); 82 83 // Set prosilver to default style 84 $this->config->set('default_style', $style_id); 85 } 86 else if (empty($styles) && empty($available_styles)) 87 { 88 throw new \RuntimeException('No valid styles available'); 89 } 90 91 // Make sure default style is available 92 if (!in_array($this->config['default_style'], $style_ids)) 93 { 94 $this->config->set('default_style', array_pop($style_ids)); 95 } 96 97 // Reset users to default style if their user_style is nonexistent 98 $sql = 'UPDATE ' . $this->table_prefix . "users 99 SET user_style = {$this->config['default_style']} 100 WHERE " . $this->db->sql_in_set('user_style', $style_ids, true, true); 101 $this->db->sql_query($sql); 102 } 103 104 /** 105 * Find all directories that have styles 106 * Copied from acp_styles 107 * 108 * @return array Directory names 109 */ 110 protected function find_style_dirs() 111 { 112 $styles = array(); 113 $styles_path = $this->phpbb_root_path . 'styles/'; 114 115 $dp = @opendir($styles_path); 116 if ($dp) 117 { 118 while (($file = readdir($dp)) !== false) 119 { 120 $dir = $styles_path . $file; 121 if ($file[0] == '.' || !is_dir($dir)) 122 { 123 continue; 124 } 125 126 if (file_exists("{$dir}/style.cfg")) 127 { 128 $styles[] = $file; 129 } 130 } 131 closedir($dp); 132 } 133 134 return $styles; 135 } 136 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |