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.

legacy_browser.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Plugin which adds support for legacy browsers (IE 7/8, Firefox < 4)
  4. *
  5. * @author Aleksander Machniak <alec@alec.pl>
  6. * @license GNU GPLv3+
  7. */
  8. class legacy_browser extends rcube_plugin
  9. {
  10. public $noajax = true;
  11. private $rc;
  12. public function init()
  13. {
  14. $this->rc = $rcube = rcube::get_instance();
  15. if (
  16. // IE < 9
  17. ($rcube->output->browser->ie && $rcube->output->browser->ver < 9)
  18. // Firefox < 4 (Firefox 4 is recognized as 2.0)
  19. || ($rcube->output->browser->mz && $rcube->output->browser->ver < 2)
  20. ) {
  21. $this->add_hook('send_page', array($this, 'send_page'));
  22. $this->add_hook('render_page', array($this, 'render_page'));
  23. }
  24. }
  25. function send_page($args)
  26. {
  27. $p1 = $this->rc->output->asset_url('program/js');
  28. $p2 = $this->rc->output->asset_url('plugins/legacy_browser/js');
  29. $assets_dir = $this->rc->config->get('assets_dir');
  30. $ts1 = filemtime($this->home . '/js/jquery.min.js');
  31. $ts2 = filemtime($this->home . '/js/iehacks.js');
  32. if (!$ts1 && $assets_dir) {
  33. $ts1 = filemtime($assets_dir . '/plugins/legacy_browser/js/jquery.min.js');
  34. }
  35. if (!$ts2 && $assets_dir) {
  36. $ts2 = filemtime($assets_dir . '/plugins/legacy_browser/js/iehacks.js');
  37. }
  38. // put iehacks.js after app.js
  39. if ($this->rc->output->browser->ie) {
  40. $args['content'] = preg_replace(
  41. '|(<script src="' . preg_quote($p1, '|') . '/app(\.min)?\.js(\?s=[0-9]+)?" type="text/javascript"></script>)|',
  42. '\\1<script src="' . $p2 . '/iehacks.js?s=' . $ts2 . '" type="text/javascript"></script>',
  43. $args['content'], 1, $count);
  44. }
  45. else {
  46. $count = 1;
  47. }
  48. // replace jQuery 2.x with 1.x
  49. $args['content'] = preg_replace(
  50. '|<script src="' . preg_quote($p1, '|') . '/jquery\.min\.js(\?s=[0-9]+)?" type="text/javascript"></script>|',
  51. '<script src="' . $p2 . '/jquery.min.js?s=' . $ts1 . '" type="text/javascript"></script>'
  52. // add iehacks.js if it is IE and it wasn't added yet
  53. . ($count ? '' : "\n".'<script src="' . $p2 . '/iehacks.js?s=' . $ts2 . '" type="text/javascript"></script>'),
  54. $args['content'], 1);
  55. return $args;
  56. }
  57. function render_page($args)
  58. {
  59. if (!$this->rc->output->browser->ie) {
  60. return $args;
  61. }
  62. $skin = $this->skin();
  63. if ($skin == 'classic') {
  64. $minified = file_exists(INSTALL_PATH . '/plugins/legacy_browser/skins/classic/iehacks.min.css') ? '.min' : '';
  65. $this->rc->output->add_header(
  66. '<link rel="stylesheet" type="text/css" href="plugins/legacy_browser/skins/classic/iehacks' . $minified . '.css" />'
  67. );
  68. }
  69. else if ($skin == 'larry') {
  70. $minified = file_exists(INSTALL_PATH . '/plugins/legacy_browser/skins/larry/iehacks.min.css') ? '.min' : '';
  71. $this->rc->output->add_header(
  72. '<link rel="stylesheet" type="text/css" href="plugins/legacy_browser/skins/larry/iehacks' . $minified . '.css" />'
  73. );
  74. if ($this->rc->output->browser->ver < 8) {
  75. $this->rc->output->add_header(
  76. '<link rel="stylesheet" type="text/css" href="plugins/legacy_browser/skins/larry/ie7hacks' . $minified . '.css" />'
  77. );
  78. }
  79. }
  80. }
  81. private function skin()
  82. {
  83. $skin = $this->rc->config->get('skin');
  84. // external skin, find if it inherits from other skin
  85. if ($skin != 'larry' && $skin != 'classic') {
  86. $json = @file_get_contents(INSTALL_PATH . "/skins/$skin/meta.json");
  87. $json = @json_decode($json, true);
  88. if (!empty($json['extends'])) {
  89. return $json['extends'];
  90. }
  91. }
  92. return $skin;
  93. }
  94. }