You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updatecss.sh 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. +-----------------------------------------------------------------------+
  5. | bin/updatecss.sh |
  6. | |
  7. | This file is part of the Roundcube Webmail client |
  8. | Copyright (C) 2010-2013, The Roundcube Dev Team |
  9. | |
  10. | Licensed under the GNU General Public License version 3 or |
  11. | any later version with exceptions for skins & plugins. |
  12. | See the README file for a full license statement. |
  13. | |
  14. | PURPOSE: |
  15. | Update cache-baster marks for css background images |
  16. +-----------------------------------------------------------------------+
  17. | Author: Aleksander Machniak <alec@alec.pl> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
  21. require_once INSTALL_PATH . 'program/include/clisetup.php';
  22. // get arguments
  23. $opts = rcube_utils::get_opt(array(
  24. 'd' => 'dir',
  25. ));
  26. if (empty($opts['dir'])) {
  27. print "Skin directory not specified (--dir). Using skins/ and plugins/*/skins/.\n";
  28. $dir = INSTALL_PATH . 'skins';
  29. $dir_p = INSTALL_PATH . 'plugins';
  30. $skins = glob("$dir/*", GLOB_ONLYDIR);
  31. $skins_p = glob("$dir_p/*/skins/*", GLOB_ONLYDIR);
  32. $dirs = array_merge($skins, $skins_p);
  33. }
  34. // Check if directory exists
  35. else if (!file_exists($opts['dir'])) {
  36. rcube::raise_error("Specified directory doesn't exist.", false, true);
  37. }
  38. else {
  39. $dirs = array($opts['dir']);
  40. }
  41. foreach ($dirs as $dir) {
  42. $img_dir = $dir . '/images';
  43. if (!file_exists($img_dir)) {
  44. continue;
  45. }
  46. $files = get_files($dir);
  47. $images = get_images($img_dir);
  48. $find = array();
  49. $replace = array();
  50. // build regexps array
  51. foreach ($images as $path => $sum) {
  52. $path_ex = str_replace('.', '\\.', $path);
  53. $find[] = "#url\(['\"]?images/$path_ex(\?v=[a-f0-9-\.]+)?['\"]?\)#";
  54. $replace[] = "url(images/$path?v=$sum)";
  55. }
  56. foreach ($files as $file) {
  57. $file = $dir . '/' . $file;
  58. print "File: $file\n";
  59. $content = file_get_contents($file);
  60. $content = preg_replace($find, $replace, $content, -1, $count);
  61. if ($count) {
  62. file_put_contents($file, $content);
  63. }
  64. }
  65. }
  66. function get_images($dir)
  67. {
  68. $images = array();
  69. $dh = opendir($dir);
  70. while ($file = readdir($dh)) {
  71. if (preg_match('/^(.+)\.(gif|ico|png|jpg|jpeg)$/', $file, $m)) {
  72. $filepath = "$dir/$file";
  73. $images[$file] = substr(md5_file($filepath), 0, 4) . '.' . filesize($filepath);
  74. print "Image: $filepath ({$images[$file]})\n";
  75. }
  76. else if ($file != '.' && $file != '..' && is_dir($dir . '/' . $file)) {
  77. foreach (get_images($dir . '/' . $file) as $img => $sum) {
  78. $images[$file . '/' . $img] = $sum;
  79. }
  80. }
  81. }
  82. closedir($dh);
  83. return $images;
  84. }
  85. function get_files($dir)
  86. {
  87. $files = array();
  88. $dh = opendir($dir);
  89. while ($file = readdir($dh)) {
  90. if (preg_match('/^(.+)\.(css|html)$/', $file, $m)) {
  91. $files[] = $file;
  92. }
  93. else if ($file != '.' && $file != '..' && is_dir($dir . '/' . $file)) {
  94. foreach (get_files($dir . '/' . $file) as $f) {
  95. $files[] = $file . '/' . $f;
  96. }
  97. }
  98. }
  99. closedir($dh);
  100. return $files;
  101. }
  102. ?>