From 3e76f7468864f5e5d8c3f805745c44e422ae817c Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 4 Sep 2011 11:05:30 +0300 Subject: [feature/remove-imagesets] Script for converting imageset to css Removing imagesets. Script for converting imageset to css PHPBB3-10336 --- phpBB/develop/imageset_to_css.php | 274 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 phpBB/develop/imageset_to_css.php (limited to 'phpBB/develop/imageset_to_css.php') 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 @@ + $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.
'; +} +else for($i=0; $i'; + } + } + if(md5($data) == $hash) + { + echo 'Nothing to replace in ', $file, '
'; + } + 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'; + $skip = true; + } + else + { + $size = @getimagesize($filename); + if($size === false) + { + echo 'Error: file ', $filename, ' is not a valid image
'; + $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 ' [ download expand ]
'; + echo '
'; +} + +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; +} + -- cgit v1.2.1 From 7295e5824aed6f5ec32cfab0ad17cfa2c24855ac Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 16 Jan 2012 14:35:29 +0200 Subject: [ticket/10380] BIDI support for imageset BIDI support for imageset conversion script, added RTL imageset entries to prosilver and subsilver2, fixed small bug in imageset.css, changed spacing in code to match phpbb coding guidelines PHPBB3-10380 --- phpBB/develop/imageset_to_css.php | 160 +++++++++++++++++++++++++++++++------- 1 file changed, 130 insertions(+), 30 deletions(-) (limited to 'phpBB/develop/imageset_to_css.php') diff --git a/phpBB/develop/imageset_to_css.php b/phpBB/develop/imageset_to_css.php index 3d55808319..3db005a054 100644 --- a/phpBB/develop/imageset_to_css.php +++ b/phpBB/develop/imageset_to_css.php @@ -17,14 +17,14 @@ ob_start(); // Get global and English images $images_global = get_imageset($imageset_path); -if($images_global === false) +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) +if ($images_en === false) { echo 'English imageset.cfg was not found.'; echo ob_get_clean(); @@ -32,7 +32,7 @@ if($images_en === false) } // Remove duplicate images -foreach($images_en as $key => $row) +foreach ($images_en as $key => $row) { unset($images_global[$key]); } @@ -52,13 +52,16 @@ $replace = array( // $replace = array_merge($replace, get_replacements($images_global)); $replace = array_merge($replace, get_replacements($images_global), get_replacements($images_en)); +// BIDI code +$bidi_code = css($images_global, './images/', true); + // Get all CSS files, parse them $files = list_files($theme_path, 'css'); -if($files === false || !count($files)) +if ($files === false || !count($files)) { echo 'No CSS files found in theme directory.
'; } -else for($i=0; $i'; + continue; } } - if(md5($data) == $hash) + if (basename($file) == 'bidi.css' && strpos($data, '/* Former imageset */') === false && strlen($bidi_code)) + { + // Add bidi data + $data .= "\n/* Former imageset */\n" . $bidi_code; + $bidi_code = ''; + echo 'Note: RTL imageset entries were added at the end of file below:
'; + } + if (md5($data) == $hash) { echo 'Nothing to replace in ', $file, '
'; } @@ -84,9 +95,9 @@ else for($i=0; $i $row) +foreach ($list as $key => $row) { - if($row['skip']) + 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(); @@ -112,14 +123,22 @@ span.imageset { /* English images for fallback */ ' . css($images_en, './en/'); +if (strlen($bidi_code)) +{ + $code .= "\n/* RTL imageset entries */\n" . $bidi_code; +} echo 'Code to add to CSS file:', dump_code($code, 'imageset.css'); + $list = list_languages($imageset_path); -for($i=0; $i'; $skip = true; @@ -162,7 +190,7 @@ function get_imageset($path, $lang = '') else { $size = @getimagesize($filename); - if($size === false) + if ($size === false) { echo 'Error: file ', $filename, ' is not a valid image
'; $skip = true; @@ -188,7 +216,7 @@ function get_imageset($path, $lang = '') function get_replacements($list) { $result = array(); - foreach($list as $key => $row) + foreach ($list as $key => $row) { $key = '{' . strtoupper($key); $result[$key . '_SRC}'] = strlen($row['file']) ? ($row['lang'] ? './' . $row['lang'] : './images') . '/' . $row['file'] : ''; @@ -201,9 +229,12 @@ function get_replacements($list) function list_files($dir, $ext) { $res = @opendir($dir); - if($res === false) return false; + if ($res === false) + { + return false; + } $files = array(); - while(($file = readdir($res)) !== false) + while (($file = readdir($res)) !== false) { $list = explode('.', $file); if(count($list) > 1 && strtolower($list[count($list) - 1]) == $ext) @@ -218,13 +249,19 @@ function list_files($dir, $ext) function list_languages($dir) { $res = @opendir($dir); - if($res === false) return array(); + if ($res === false) + { + return array(); + } $files = array(); - while(($file = readdir($res)) !== false) + while (($file = readdir($res)) !== false) { - if(substr($file, 0, 1) == '.') continue; + if (substr($file, 0, 1) == '.') + { + continue; + } $filename = $dir . '/' . $file; - if(is_dir($filename) && file_exists($filename . '/imageset.cfg')) + if (is_dir($filename) && file_exists($filename . '/imageset.cfg')) { $files[] = $file; } @@ -236,7 +273,7 @@ function list_languages($dir) function dump_code($code, $filename = 'file.txt') { $hash = md5($code); - if(isset($_GET['download']) && $_GET['download'] === $hash) + if (isset($_GET['download']) && $_GET['download'] === $hash) { // Download file ob_end_clean(); @@ -256,18 +293,81 @@ function dump_code($code, $filename = 'file.txt') echo '
'; } -function css($list, $path = './') +function css($list, $path = './', $bidi = false) { $code = ''; - foreach($list as $key => $row) + // Change value to true if you want images to be grouped up by size + $group = $bidi; + if ($group) { - if(!strlen($row['file'])) continue; - $code .= '.imageset.' . substr($key, 4) . ' { + // group up images by size + $groups = array(); + foreach ($list as $key => $row) + { + if (!strlen($row['file'])) + { + continue; + } + $groups[$row['width'] . '*' . $row['height']][] = $key; + } + foreach ($groups as $size => $keys) + { + $extra = ''; + for ($i=0; $i $row) + { + if (!strlen($row['file'])) + { + continue; + } + $code .= ($bidi ? '.rtl ' : '') . '.imageset.' . substr($key, 4) . ' {'; + if ($bidi) + { + $code .= ' + padding-right: ' . $row['width'] . 'px; + padding-left: 0; +} +'; + } + else + { + $code .= ' background-image: url("' . $path . $row['file'] . '"); padding-left: ' . $row['width'] . 'px; padding-top: ' . $row['height'] . 'px; } '; + } + } } return $code; } -- cgit v1.2.1 From d4c3d4b21d4951b6cd3d4038988278a3667f2827 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Fri, 20 Jan 2012 12:41:00 +0200 Subject: [ticket/10378] Imageset to css convertor typo Imageset to css convertor typo PHPBB3-10378 --- phpBB/develop/imageset_to_css.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/develop/imageset_to_css.php') diff --git a/phpBB/develop/imageset_to_css.php b/phpBB/develop/imageset_to_css.php index 3d55808319..9983a85202 100644 --- a/phpBB/develop/imageset_to_css.php +++ b/phpBB/develop/imageset_to_css.php @@ -10,7 +10,7 @@ $phpbb_root_path = '../'; $style = 'subsilver2'; $imageset_path = $phpbb_root_path . 'styles/' . $style . '/imageset'; -$theme_path = $phpbb_root_path . 'styles/' . $style . '/theme2'; +$theme_path = $phpbb_root_path . 'styles/' . $style . '/theme'; // Start output buffering ob_start(); -- cgit v1.2.1