diff options
author | Igor Wiedler <igor@wiedler.ch> | 2011-09-21 18:12:07 +0200 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2011-09-21 18:12:07 +0200 |
commit | e41f9c932970c81908f28735e0478510f6d1215b (patch) | |
tree | 35c9939fd5c1b24cb949580874eb181df249f97f /phpBB/develop | |
parent | 47bb42e2f034cdb82e8f8e97b90639af9ed85b74 (diff) | |
parent | fab0ec64b383c672e91db8524a225671795d4805 (diff) | |
download | forums-e41f9c932970c81908f28735e0478510f6d1215b.tar forums-e41f9c932970c81908f28735e0478510f6d1215b.tar.gz forums-e41f9c932970c81908f28735e0478510f6d1215b.tar.bz2 forums-e41f9c932970c81908f28735e0478510f6d1215b.tar.xz forums-e41f9c932970c81908f28735e0478510f6d1215b.zip |
Merge branch 'develop' of github.com:phpbb/phpbb3 into develop
* 'develop' of github.com:phpbb/phpbb3: (44 commits)
[ticket/10374] Remove 'custom template' cache prefix.
[feature/remove-db-styles] Remove forgotten template variables.
[feature/remove-db-styles] Removed style.php!
[feature/remove-db-styles] Rework filesystem permission checks from 6d24a71.
[feature/remove-db-styles] Update language to reflect removal of db storage.
[feature/remove-db-styles] Mark log entrys as deprecated.
[feature/remove-db-styles] Add error if template/theme file is unwritable.
[feature/remove-db-styles] Add schema changes sinces 3.0.x.
[feature/remove-db-styles] Readd table constant for upgrades etc.
[feature/remove-db-styles] Update database schemas.
[feature/remove-db-styles] Remove style.php DB storage.
[feature/remove-db-styles] Remove parse_css_file option from themes.
[feature/remove-db-styles] Remove DB theme handling code from session.
[feature/remove-db-styles] ACP has forgotten how to store themes in the DB.
[feature/remove-db-styles] Missed a few template DB bits in acp_styles.
[feature/remove-db-styles] Removing unused methods from acp_style.
[feature/remove-db-styles] Removed database storage of style components.
[ticket/10371] Removing last mentions of imageset
[ticket/10370] Add function documentation for get_stacktrace().
[ticket/10370] Explain that we are not the ones hiding backtrace pieces.
...
Diffstat (limited to 'phpBB/develop')
-rw-r--r-- | phpBB/develop/create_schema_files.php | 18 | ||||
-rw-r--r-- | phpBB/develop/imageset_to_css.php | 274 | ||||
-rw-r--r-- | phpBB/develop/mysql_upgrader.php | 31 |
3 files changed, 274 insertions, 49 deletions
diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 213354fcb9..2057d292b7 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1657,7 +1657,6 @@ function get_schema_struct() 'template_copyright' => array('VCHAR_UNI', ''), 'template_path' => array('VCHAR:100', ''), 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'template_storedb' => array('BOOL', 0), 'template_inherits_id' => array('UINT:4', 0), 'template_inherit_path' => array('VCHAR', ''), ), @@ -1667,29 +1666,12 @@ function get_schema_struct() ), ); - $schema_data['phpbb_styles_template_data'] = array( - 'COLUMNS' => array( - 'template_id' => array('UINT', 0), - 'template_filename' => array('VCHAR:100', ''), - 'template_included' => array('TEXT', ''), - 'template_mtime' => array('TIMESTAMP', 0), - 'template_data' => array('MTEXT_UNI', ''), - ), - 'KEYS' => array( - 'tid' => array('INDEX', 'template_id'), - 'tfn' => array('INDEX', 'template_filename'), - ), - ); - $schema_data['phpbb_styles_theme'] = array( 'COLUMNS' => array( 'theme_id' => array('UINT', NULL, 'auto_increment'), 'theme_name' => array('VCHAR_UNI:255', ''), 'theme_copyright' => array('VCHAR_UNI', ''), 'theme_path' => array('VCHAR:100', ''), - 'theme_storedb' => array('BOOL', 0), - 'theme_mtime' => array('TIMESTAMP', 0), - 'theme_data' => array('MTEXT_UNI', ''), ), 'PRIMARY_KEY' => 'theme_id', 'KEYS' => array( diff --git a/phpBB/develop/imageset_to_css.php b/phpBB/develop/imageset_to_css.php new file mode 100644 index 0000000000..3d55808319 --- /dev/null +++ b/phpBB/develop/imageset_to_css.php @@ -0,0 +1,274 @@ +<?php + +/* + Converts imageset to CSS code + + Change style name and path below, open in browser. +*/ + +$phpbb_root_path = '../'; +$style = 'subsilver2'; + +$imageset_path = $phpbb_root_path . 'styles/' . $style . '/imageset'; +$theme_path = $phpbb_root_path . 'styles/' . $style . '/theme2'; + +// Start output buffering +ob_start(); + +// Get global and English images +$images_global = get_imageset($imageset_path); +if($images_global === false) +{ + echo 'imageset.cfg was not found.'; + echo ob_get_clean(); + return; +} +$images_en = get_imageset($imageset_path, 'en'); +if($images_en === false) +{ + echo 'English imageset.cfg was not found.'; + echo ob_get_clean(); + return; +} + +// Remove duplicate images +foreach($images_en as $key => $row) +{ + unset($images_global[$key]); +} + +// CSS replacements +$not_compatible = array( + '{T_TEMPLATE_PATH}', + '{T_IMAGESET_PATH}', + '{T_IMAGESET_LANG_PATH}', + '{T_STYLESHEET_NAME}', + '{S_USER_LANG}' +); +$replace = array( + '{T_THEME_PATH}' => '.', +); +// Enable/disable one of lines below to enable/disable replacement of English buttons +// $replace = array_merge($replace, get_replacements($images_global)); +$replace = array_merge($replace, get_replacements($images_global), get_replacements($images_en)); + +// Get all CSS files, parse them +$files = list_files($theme_path, 'css'); +if($files === false || !count($files)) +{ + echo 'No CSS files found in theme directory.<br />'; +} +else for($i=0; $i<count($files); $i++) +{ + $file = $theme_path . '/' . $files[$i]; + $data = file_get_contents($file); + $hash = md5($data); + $data = strtr($data, $replace); + $errors = false; + for($j=0; $j<count($not_compatible); $j++) + { + if(strpos($data, $not_compatible[$j]) !== false) + { + echo 'Error: ', $file, ' contains ', $not_compatible[$j], '. That variable cannot be converted.<br />'; + } + } + if(md5($data) == $hash) + { + echo 'Nothing to replace in ', $file, '<br />'; + } + else + { + echo 'Updated ', $file, ':', dump_code($data, $files[$i]); + } +} + +// Check if there are invalid images in imageset +$list = array_merge($images_global, $images_en); +foreach($list as $key => $row) +{ + if($row['skip']) + { + echo 'Unable to generate code to add to CSS files because some images are missing or invalid. See errors above.'; + echo ob_get_clean(); + return; + } +} + +// Code to add to CSS files +$code = ' +/* Former imageset */ +span.imageset { + display: inline-block; + background: transparent none 0 0 no-repeat; + margin: 0; + padding: 0; + width: 0; + height: 0; + overflow: hidden; +} + +/* Global imageset items */ +' . css($images_global, './images/') . ' + +/* English images for fallback */ +' . css($images_en, './en/'); +echo 'Code to add to CSS file:', dump_code($code, 'imageset.css'); + +$list = list_languages($imageset_path); +for($i=0; $i<count($list); $i++) +{ + $lang = $list[$i]; + $images = get_imageset($imageset_path . '/' . $lang); + if(!count($images)) continue; + $code = '/* ' . strtoupper($lang) . ' Language Pack */ +' . css($images, './'); + echo 'New CSS file: ', $theme_path, '/', $lang, '/stylesheet.css', dump_code($code, 'stylesheet_' . $lang . '.css'); +} + +echo ob_get_clean(); +return; + + +/* + Functions +*/ +function get_imageset($path, $lang = '') +{ + $cfg = $path . ($lang ? '/' . $lang : '') . '/imageset.cfg'; + if(!@file_exists($cfg)) return false; + $data = file($cfg); + $result = array(); + for($i=0; $i<count($data); $i++) + { + $str = trim($data[$i]); + if(substr($str, 0, 4) != 'img_') continue; + $list = explode('=', $data[$i]); + if(count($list) != 2) continue; + $key = trim($list[0]); + $row = explode('*', trim($list[1])); + $file = trim($row[0]); + $height = isset($row[1]) && intval($row[1]) ? intval($row[1]) : false; + $width = isset($row[2]) && intval($row[2]) ? intval($row[2]) : false; + $skip = false; + if(strlen($file) && (!$width || !$height)) + { + // Try to detect width/height + $filename = $path . ($lang ? '/' . $lang : '') . '/' . $file; + if(!@file_exists($filename)) + { + echo 'Error: file ', $filename, ' does not exist and its dimensions are not available in imageset.cfg<br />'; + $skip = true; + } + else + { + $size = @getimagesize($filename); + if($size === false) + { + echo 'Error: file ', $filename, ' is not a valid image<br />'; + $skip = true; + } + else + { + if(!$width) $width = intval($size[0]); + if(!$height) $height = intval($size[1]); + } + } + } + $result[$key] = array( + 'lang' => $lang, + 'file' => $file, + 'height' => $height, + 'width' => $width, + 'skip' => $skip + ); + } + return $result; +} + +function get_replacements($list) +{ + $result = array(); + foreach($list as $key => $row) + { + $key = '{' . strtoupper($key); + $result[$key . '_SRC}'] = strlen($row['file']) ? ($row['lang'] ? './' . $row['lang'] : './images') . '/' . $row['file'] : ''; + $result[$key . '_WIDTH}'] = intval($row['width']); + $result[$key . '_HEIGHT}'] = intval($row['height']); + } + return $result; +} + +function list_files($dir, $ext) +{ + $res = @opendir($dir); + if($res === false) return false; + $files = array(); + while(($file = readdir($res)) !== false) + { + $list = explode('.', $file); + if(count($list) > 1 && strtolower($list[count($list) - 1]) == $ext) + { + $files[] = $file; + } + } + closedir($res); + return $files; +} + +function list_languages($dir) +{ + $res = @opendir($dir); + if($res === false) return array(); + $files = array(); + while(($file = readdir($res)) !== false) + { + if(substr($file, 0, 1) == '.') continue; + $filename = $dir . '/' . $file; + if(is_dir($filename) && file_exists($filename . '/imageset.cfg')) + { + $files[] = $file; + } + } + closedir($res); + return $files; +} + +function dump_code($code, $filename = 'file.txt') +{ + $hash = md5($code); + if(isset($_GET['download']) && $_GET['download'] === $hash) + { + // Download file + ob_end_clean(); + header('Pragma: public'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Content-Type: application/force-download'); + header('Content-Disposition: attachment; filename="' . $filename . '";'); + header('Content-Transfer-Encoding: binary'); + header('Content-Length: ' . strlen($code)); + echo $code; + exit; + } + $list = explode("\n", $code); + $height = 15 * count($list); + echo ' [ <a href="?download=', $hash, '">download</a> <a href="javascript:void(0);" onclick="document.getElementById(\'code-', $hash, '\').style.height = \'', $height, 'px\'; this.style.display = \'none\'; return false;">expand</a> ]<br />'; + echo '<textarea id="code-', $hash, '" onfocus="this.select();" style="width: 98%; height: 200px;">', htmlspecialchars($code), '</textarea><br />'; +} + +function css($list, $path = './') +{ + $code = ''; + foreach($list as $key => $row) + { + if(!strlen($row['file'])) continue; + $code .= '.imageset.' . substr($key, 4) . ' { + background-image: url("' . $path . $row['file'] . '"); + padding-left: ' . $row['width'] . 'px; + padding-top: ' . $row['height'] . 'px; +} +'; + } + return $code; +} + diff --git a/phpBB/develop/mysql_upgrader.php b/phpBB/develop/mysql_upgrader.php index ca3e87dcc6..c54a7155c2 100644 --- a/phpBB/develop/mysql_upgrader.php +++ b/phpBB/develop/mysql_upgrader.php @@ -1094,14 +1094,12 @@ function get_schema_struct() 'style_active' => array('BOOL', 1), 'template_id' => array('UINT', 0), 'theme_id' => array('UINT', 0), - 'imageset_id' => array('UINT', 0), ), 'PRIMARY_KEY' => 'style_id', 'KEYS' => array( 'style_name' => array('UNIQUE', 'style_name'), 'template_id' => array('INDEX', 'template_id'), 'theme_id' => array('INDEX', 'theme_id'), - 'imageset_id' => array('INDEX', 'imageset_id'), ), ); @@ -1152,35 +1150,6 @@ function get_schema_struct() ), ); - $schema_data['phpbb_styles_imageset'] = array( - 'COLUMNS' => array( - 'imageset_id' => array('UINT', NULL, 'auto_increment'), - 'imageset_name' => array('VCHAR_UNI:255', ''), - 'imageset_copyright' => array('VCHAR_UNI', ''), - 'imageset_path' => array('VCHAR:100', ''), - ), - 'PRIMARY_KEY' => 'imageset_id', - 'KEYS' => array( - 'imgset_nm' => array('UNIQUE', 'imageset_name'), - ), - ); - - $schema_data['phpbb_styles_imageset_data'] = array( - 'COLUMNS' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'image_name' => array('VCHAR:200', ''), - 'image_filename' => array('VCHAR:200', ''), - 'image_lang' => array('VCHAR:30', ''), - 'image_height' => array('USINT', 0), - 'image_width' => array('USINT', 0), - 'imageset_id' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'image_id', - 'KEYS' => array( - 'i_d' => array('INDEX', 'imageset_id'), - ), - ); - $schema_data['phpbb_topics'] = array( 'COLUMNS' => array( 'topic_id' => array('UINT', NULL, 'auto_increment'), |