Merge branch 'ticket/10380' into develop

* ticket/10380:
  [ticket/10380] BIDI support for imageset
This commit is contained in:
Igor Wiedler 2012-02-17 14:04:13 +01:00
commit 5e0b4e63d0
4 changed files with 199 additions and 32 deletions

View file

@ -52,6 +52,9 @@ $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))
@ -70,8 +73,16 @@ else for($i=0; $i<count($files); $i++)
if (strpos($data, $not_compatible[$j]) !== false)
{
echo 'Error: ', $file, ' contains ', $not_compatible[$j], '. That variable cannot be converted.<br />';
continue;
}
}
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:<br />';
}
if (md5($data) == $hash)
{
echo 'Nothing to replace in ', $file, '<br />';
@ -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<count($list); $i++)
{
$lang = $list[$i];
$images = get_imageset($imageset_path . '/' . $lang);
if(!count($images)) continue;
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');
@ -135,15 +154,24 @@ return;
function get_imageset($path, $lang = '')
{
$cfg = $path . ($lang ? '/' . $lang : '') . '/imageset.cfg';
if(!@file_exists($cfg)) return false;
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;
if (substr($str, 0, 4) != 'img_')
{
continue;
}
$list = explode('=', $data[$i]);
if(count($list) != 2) continue;
if (count($list) != 2)
{
continue;
}
$key = trim($list[0]);
$row = explode('*', trim($list[1]));
$file = trim($row[0]);
@ -201,7 +229,10 @@ 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)
{
@ -218,11 +249,17 @@ 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)
{
if(substr($file, 0, 1) == '.') continue;
if (substr($file, 0, 1) == '.')
{
continue;
}
$filename = $dir . '/' . $file;
if (is_dir($filename) && file_exists($filename . '/imageset.cfg'))
{
@ -256,19 +293,82 @@ function dump_code($code, $filename = 'file.txt')
echo '<textarea id="code-', $hash, '" onfocus="this.select();" style="width: 98%; height: 200px;">', htmlspecialchars($code), '</textarea><br />';
}
function css($list, $path = './')
function css($list, $path = './', $bidi = false)
{
$code = '';
// Change value to true if you want images to be grouped up by size
$group = $bidi;
if ($group)
{
// group up images by size
$groups = array();
foreach ($list as $key => $row)
{
if(!strlen($row['file'])) continue;
$code .= '.imageset.' . substr($key, 4) . ' {
if (!strlen($row['file']))
{
continue;
}
$groups[$row['width'] . '*' . $row['height']][] = $key;
}
foreach ($groups as $size => $keys)
{
$extra = '';
for ($i=0; $i<count($keys); $i++)
{
$code .= ($i == 0 ? '' : ', ') . ($bidi ? '.rtl ' : '') . '.imageset.' . substr($keys[$i], 4);
if (!$bidi)
{
$extra .= '.imageset.' . substr($keys[$i], 4) . ' { background-image: url("' . $path . $list[$keys[$i]]['file'] . "\"); }\n";
}
}
$row = $list[$keys[0]];
$code .= ' {';
if ($bidi)
{
$code .= '
padding-right: ' . $row['width'] . 'px;
padding-left: 0;
}
';
}
else
{
$code .= '
padding-left: ' . $row['width'] . 'px;
padding-top: ' . $row['height'] . 'px;
}
' . $extra;
}
}
}
else
{
foreach ($list as $key => $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;
}

View file

@ -755,3 +755,33 @@
.rtl #wrap, .rtl .headerbar, .rtl #site-description, .rtl .navbar {
position: relative;
}
/* Former imageset */
.rtl .imageset.site_logo {
padding-right: 139px;
padding-left: 0;
}
.rtl .imageset.forum_link, .rtl .imageset.forum_read, .rtl .imageset.forum_read_locked, .rtl .imageset.forum_read_subforum, .rtl .imageset.forum_unread, .rtl .imageset.forum_unread_locked, .rtl .imageset.forum_unread_subforum, .rtl .imageset.topic_moved, .rtl .imageset.topic_read, .rtl .imageset.topic_read_mine, .rtl .imageset.topic_read_hot, .rtl .imageset.topic_read_hot_mine, .rtl .imageset.topic_read_locked, .rtl .imageset.topic_read_locked_mine, .rtl .imageset.topic_unread, .rtl .imageset.topic_unread_mine, .rtl .imageset.topic_unread_hot, .rtl .imageset.topic_unread_hot_mine, .rtl .imageset.topic_unread_locked, .rtl .imageset.topic_unread_locked_mine, .rtl .imageset.sticky_read, .rtl .imageset.sticky_read_mine, .rtl .imageset.sticky_read_locked, .rtl .imageset.sticky_read_locked_mine, .rtl .imageset.sticky_unread, .rtl .imageset.sticky_unread_mine, .rtl .imageset.sticky_unread_locked, .rtl .imageset.sticky_unread_locked_mine, .rtl .imageset.announce_read, .rtl .imageset.announce_read_mine, .rtl .imageset.announce_read_locked, .rtl .imageset.announce_read_locked_mine, .rtl .imageset.announce_unread, .rtl .imageset.announce_unread_mine, .rtl .imageset.announce_unread_locked, .rtl .imageset.announce_unread_locked_mine, .rtl .imageset.global_read, .rtl .imageset.global_read_mine, .rtl .imageset.global_read_locked, .rtl .imageset.global_read_locked_mine, .rtl .imageset.global_unread, .rtl .imageset.global_unread_mine, .rtl .imageset.global_unread_locked, .rtl .imageset.global_unread_locked_mine, .rtl .imageset.pm_read, .rtl .imageset.pm_unread {
padding-right: 27px;
padding-left: 0;
}
.rtl .imageset.subforum_read, .rtl .imageset.subforum_unread, .rtl .imageset.icon_post_target, .rtl .imageset.icon_post_target_unread, .rtl .imageset.icon_topic_latest, .rtl .imageset.icon_topic_newest {
padding-right: 11px;
padding-left: 0;
}
.rtl .imageset.icon_back_top {
padding-right: 11px;
padding-left: 0;
}
.rtl .imageset.icon_contact_aim, .rtl .imageset.icon_contact_email, .rtl .imageset.icon_contact_icq, .rtl .imageset.icon_contact_jabber, .rtl .imageset.icon_contact_msnm, .rtl .imageset.icon_contact_www, .rtl .imageset.icon_contact_yahoo, .rtl .imageset.icon_post_delete, .rtl .imageset.icon_post_info, .rtl .imageset.icon_post_report, .rtl .imageset.icon_user_warn {
padding-right: 20px;
padding-left: 0;
}
.rtl .imageset.icon_topic_attach {
padding-right: 7px;
padding-left: 0;
}
.rtl .imageset.icon_topic_reported, .rtl .imageset.icon_topic_unapproved {
padding-right: 16px;
padding-left: 0;
}

View file

@ -4,7 +4,6 @@ span.imageset {
background: transparent none 0 0 no-repeat;
margin: 0;
padding: 0;
padding-right: 0 !important;
width: 0;
height: 0;
overflow: hidden;

View file

@ -1094,3 +1094,41 @@ a.imageset {
padding-left: 97px;
padding-top: 27px;
}
/* RTL imageset entries */
.rtl .imageset.site_logo {
padding-right: 170px;
padding-left: 0;
}
.rtl .imageset.upload_bar {
padding-right: 280px;
padding-left: 0;
}
.rtl .imageset.poll_left, .rtl .imageset.poll_right {
padding-right: 4px;
padding-left: 0;
}
.rtl .imageset.poll_center {
padding-right: 1px;
padding-left: 0;
}
.rtl .imageset.forum_link, .rtl .imageset.forum_read, .rtl .imageset.forum_read_locked, .rtl .imageset.forum_read_subforum, .rtl .imageset.forum_unread, .rtl .imageset.forum_unread_locked, .rtl .imageset.forum_unread_subforum {
padding-right: 46px;
padding-left: 0;
}
.rtl .imageset.topic_moved, .rtl .imageset.topic_read, .rtl .imageset.topic_read_mine, .rtl .imageset.topic_read_hot, .rtl .imageset.topic_read_hot_mine, .rtl .imageset.topic_read_locked, .rtl .imageset.topic_read_locked_mine, .rtl .imageset.topic_unread, .rtl .imageset.topic_unread_mine, .rtl .imageset.topic_unread_hot, .rtl .imageset.topic_unread_hot_mine, .rtl .imageset.topic_unread_locked, .rtl .imageset.topic_unread_locked_mine, .rtl .imageset.sticky_read, .rtl .imageset.sticky_read_mine, .rtl .imageset.sticky_read_locked, .rtl .imageset.sticky_read_locked_mine, .rtl .imageset.sticky_unread, .rtl .imageset.sticky_unread_mine, .rtl .imageset.sticky_unread_locked, .rtl .imageset.sticky_unread_locked_mine, .rtl .imageset.announce_read, .rtl .imageset.announce_read_mine, .rtl .imageset.announce_read_locked, .rtl .imageset.announce_read_locked_mine, .rtl .imageset.announce_unread, .rtl .imageset.announce_unread_mine, .rtl .imageset.announce_unread_locked, .rtl .imageset.announce_unread_locked_mine, .rtl .imageset.global_read, .rtl .imageset.global_read_mine, .rtl .imageset.global_read_locked, .rtl .imageset.global_read_locked_mine, .rtl .imageset.global_unread, .rtl .imageset.global_unread_mine, .rtl .imageset.global_unread_locked, .rtl .imageset.global_unread_locked_mine, .rtl .imageset.pm_read, .rtl .imageset.pm_unread, .rtl .imageset.icon_topic_reported, .rtl .imageset.icon_topic_unapproved {
padding-right: 19px;
padding-left: 0;
}
.rtl .imageset.icon_post_target, .rtl .imageset.icon_post_target_unread {
padding-right: 12px;
padding-left: 0;
}
.rtl .imageset.icon_topic_attach {
padding-right: 14px;
padding-left: 0;
}
.rtl .imageset.icon_topic_latest, .rtl .imageset.icon_topic_newest {
padding-right: 18px;
padding-left: 0;
}