drg_elfinder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +8 -0
  5. data/app/assets/config/drg_elfinder_manifest.js +1 -0
  6. data/app/assets/javascripts/drg_elfinder.js +15 -0
  7. data/app/assets/javascripts/elfinder/Changelog +1283 -0
  8. data/app/assets/javascripts/elfinder/LICENSE.md +15 -0
  9. data/app/assets/javascripts/elfinder/README.md +216 -0
  10. data/app/assets/javascripts/elfinder/bower.json +28 -0
  11. data/app/assets/javascripts/elfinder/composer.json +39 -0
  12. data/app/assets/javascripts/elfinder/css/elfinder.full.css +5350 -0
  13. data/app/assets/javascripts/elfinder/css/elfinder.min.css +9 -0
  14. data/app/assets/javascripts/elfinder/css/theme.css +430 -0
  15. data/app/assets/javascripts/elfinder/elfinder.html +74 -0
  16. data/app/assets/javascripts/elfinder/elfinder.legacy.html +94 -0
  17. data/app/assets/javascripts/elfinder/img/arrows-active.png +0 -0
  18. data/app/assets/javascripts/elfinder/img/arrows-normal.png +0 -0
  19. data/app/assets/javascripts/elfinder/img/crop.gif +0 -0
  20. data/app/assets/javascripts/elfinder/img/dialogs.png +0 -0
  21. data/app/assets/javascripts/elfinder/img/edit_aceeditor.png +0 -0
  22. data/app/assets/javascripts/elfinder/img/edit_ckeditor.png +0 -0
  23. data/app/assets/javascripts/elfinder/img/edit_ckeditor5.png +0 -0
  24. data/app/assets/javascripts/elfinder/img/edit_codemirror.png +0 -0
  25. data/app/assets/javascripts/elfinder/img/edit_creativecloud.png +0 -0
  26. data/app/assets/javascripts/elfinder/img/edit_onlineconvert.png +0 -0
  27. data/app/assets/javascripts/elfinder/img/edit_pixlreditor.png +0 -0
  28. data/app/assets/javascripts/elfinder/img/edit_pixlrexpress.png +0 -0
  29. data/app/assets/javascripts/elfinder/img/edit_simplemde.png +0 -0
  30. data/app/assets/javascripts/elfinder/img/edit_tinymce.png +0 -0
  31. data/app/assets/javascripts/elfinder/img/edit_tuiimgedit.png +0 -0
  32. data/app/assets/javascripts/elfinder/img/edit_zohooffice.png +0 -0
  33. data/app/assets/javascripts/elfinder/img/editor-icons.png +0 -0
  34. data/app/assets/javascripts/elfinder/img/icons-big.png +0 -0
  35. data/app/assets/javascripts/elfinder/img/icons-big.svg +1 -0
  36. data/app/assets/javascripts/elfinder/img/icons-small.png +0 -0
  37. data/app/assets/javascripts/elfinder/img/logo.png +0 -0
  38. data/app/assets/javascripts/elfinder/img/progress.gif +0 -0
  39. data/app/assets/javascripts/elfinder/img/quicklook-bg.png +0 -0
  40. data/app/assets/javascripts/elfinder/img/quicklook-icons.png +0 -0
  41. data/app/assets/javascripts/elfinder/img/resize.png +0 -0
  42. data/app/assets/javascripts/elfinder/img/spinner-mini.gif +0 -0
  43. data/app/assets/javascripts/elfinder/img/toolbar.png +0 -0
  44. data/app/assets/javascripts/elfinder/img/trashmesh.png +0 -0
  45. data/app/assets/javascripts/elfinder/img/tui-icon-a.svg +235 -0
  46. data/app/assets/javascripts/elfinder/img/tui-icon-b.svg +224 -0
  47. data/app/assets/javascripts/elfinder/img/tui-icon-c.svg +224 -0
  48. data/app/assets/javascripts/elfinder/img/tui-icon-d.svg +224 -0
  49. data/app/assets/javascripts/elfinder/img/ui-icons_ffffff_256x240.png +0 -0
  50. data/app/assets/javascripts/elfinder/img/volume_icon_box.png +0 -0
  51. data/app/assets/javascripts/elfinder/img/volume_icon_box.svg +1 -0
  52. data/app/assets/javascripts/elfinder/img/volume_icon_dropbox.png +0 -0
  53. data/app/assets/javascripts/elfinder/img/volume_icon_dropbox.svg +1 -0
  54. data/app/assets/javascripts/elfinder/img/volume_icon_ftp.png +0 -0
  55. data/app/assets/javascripts/elfinder/img/volume_icon_ftp.svg +1 -0
  56. data/app/assets/javascripts/elfinder/img/volume_icon_googledrive.png +0 -0
  57. data/app/assets/javascripts/elfinder/img/volume_icon_googledrive.svg +1 -0
  58. data/app/assets/javascripts/elfinder/img/volume_icon_local.png +0 -0
  59. data/app/assets/javascripts/elfinder/img/volume_icon_local.svg +1 -0
  60. data/app/assets/javascripts/elfinder/img/volume_icon_network.png +0 -0
  61. data/app/assets/javascripts/elfinder/img/volume_icon_network.svg +1 -0
  62. data/app/assets/javascripts/elfinder/img/volume_icon_onedrive.png +0 -0
  63. data/app/assets/javascripts/elfinder/img/volume_icon_onedrive.svg +1 -0
  64. data/app/assets/javascripts/elfinder/img/volume_icon_sql.png +0 -0
  65. data/app/assets/javascripts/elfinder/img/volume_icon_sql.svg +1 -0
  66. data/app/assets/javascripts/elfinder/img/volume_icon_trash.png +0 -0
  67. data/app/assets/javascripts/elfinder/img/volume_icon_trash.svg +1 -0
  68. data/app/assets/javascripts/elfinder/img/volume_icon_zip.png +0 -0
  69. data/app/assets/javascripts/elfinder/img/volume_icon_zip.svg +1 -0
  70. data/app/assets/javascripts/elfinder/js/elfinder.full.js +36019 -0
  71. data/app/assets/javascripts/elfinder/js/elfinder.min.js +25 -0
  72. data/app/assets/javascripts/elfinder/js/extras/editors.default.js +2643 -0
  73. data/app/assets/javascripts/elfinder/js/extras/editors.default.min.js +2 -0
  74. data/app/assets/javascripts/elfinder/js/extras/quicklook.googledocs.js +75 -0
  75. data/app/assets/javascripts/elfinder/js/extras/quicklook.googledocs.min.js +1 -0
  76. data/app/assets/javascripts/elfinder/js/i18n/elfinder.LANG.js +587 -0
  77. data/app/assets/javascripts/elfinder/js/i18n/elfinder.ar.js +580 -0
  78. data/app/assets/javascripts/elfinder/js/i18n/elfinder.bg.js +559 -0
  79. data/app/assets/javascripts/elfinder/js/i18n/elfinder.ca.js +375 -0
  80. data/app/assets/javascripts/elfinder/js/i18n/elfinder.cs.js +581 -0
  81. data/app/assets/javascripts/elfinder/js/i18n/elfinder.da.js +580 -0
  82. data/app/assets/javascripts/elfinder/js/i18n/elfinder.de.js +582 -0
  83. data/app/assets/javascripts/elfinder/js/i18n/elfinder.el.js +374 -0
  84. data/app/assets/javascripts/elfinder/js/i18n/elfinder.es.js +546 -0
  85. data/app/assets/javascripts/elfinder/js/i18n/elfinder.fa.js +580 -0
  86. data/app/assets/javascripts/elfinder/js/i18n/elfinder.fallback.js +11 -0
  87. data/app/assets/javascripts/elfinder/js/i18n/elfinder.fo.js +419 -0
  88. data/app/assets/javascripts/elfinder/js/i18n/elfinder.fr.js +578 -0
  89. data/app/assets/javascripts/elfinder/js/i18n/elfinder.fr_CA.js +580 -0
  90. data/app/assets/javascripts/elfinder/js/i18n/elfinder.he.js +375 -0
  91. data/app/assets/javascripts/elfinder/js/i18n/elfinder.hr.js +434 -0
  92. data/app/assets/javascripts/elfinder/js/i18n/elfinder.hu.js +580 -0
  93. data/app/assets/javascripts/elfinder/js/i18n/elfinder.id.js +498 -0
  94. data/app/assets/javascripts/elfinder/js/i18n/elfinder.it.js +552 -0
  95. data/app/assets/javascripts/elfinder/js/i18n/elfinder.ja.js +581 -0
  96. data/app/assets/javascripts/elfinder/js/i18n/elfinder.ko.js +582 -0
  97. data/app/assets/javascripts/elfinder/js/i18n/elfinder.nl.js +581 -0
  98. data/app/assets/javascripts/elfinder/js/i18n/elfinder.no.js +374 -0
  99. data/app/assets/javascripts/elfinder/js/i18n/elfinder.pl.js +580 -0
  100. data/app/assets/javascripts/elfinder/js/i18n/elfinder.pt_BR.js +580 -0
  101. data/app/assets/javascripts/elfinder/js/i18n/elfinder.ro.js +417 -0
  102. data/app/assets/javascripts/elfinder/js/i18n/elfinder.ru.js +582 -0
  103. data/app/assets/javascripts/elfinder/js/i18n/elfinder.si.js +537 -0
  104. data/app/assets/javascripts/elfinder/js/i18n/elfinder.sk.js +581 -0
  105. data/app/assets/javascripts/elfinder/js/i18n/elfinder.sl.js +374 -0
  106. data/app/assets/javascripts/elfinder/js/i18n/elfinder.sr.js +374 -0
  107. data/app/assets/javascripts/elfinder/js/i18n/elfinder.sv.js +375 -0
  108. data/app/assets/javascripts/elfinder/js/i18n/elfinder.tr.js +583 -0
  109. data/app/assets/javascripts/elfinder/js/i18n/elfinder.ug_CN.js +374 -0
  110. data/app/assets/javascripts/elfinder/js/i18n/elfinder.uk.js +580 -0
  111. data/app/assets/javascripts/elfinder/js/i18n/elfinder.vi.js +579 -0
  112. data/app/assets/javascripts/elfinder/js/i18n/elfinder.zh_CN.js +585 -0
  113. data/app/assets/javascripts/elfinder/js/i18n/elfinder.zh_TW.js +582 -0
  114. data/app/assets/javascripts/elfinder/js/i18n/help/cs.html.js +10 -0
  115. data/app/assets/javascripts/elfinder/js/i18n/help/de.html.js +15 -0
  116. data/app/assets/javascripts/elfinder/js/i18n/help/en.html.js +10 -0
  117. data/app/assets/javascripts/elfinder/js/i18n/help/es.html.js +10 -0
  118. data/app/assets/javascripts/elfinder/js/i18n/help/ja.html.js +10 -0
  119. data/app/assets/javascripts/elfinder/js/i18n/help/ko.html.js +10 -0
  120. data/app/assets/javascripts/elfinder/js/i18n/help/pl.html.js +10 -0
  121. data/app/assets/javascripts/elfinder/js/i18n/help/ru.html.js +10 -0
  122. data/app/assets/javascripts/elfinder/js/i18n/help/sk.html.js +10 -0
  123. data/app/assets/javascripts/elfinder/js/i18n/help/tr.html.js +10 -0
  124. data/app/assets/javascripts/elfinder/js/proxy/elFinderSupportVer1.js +408 -0
  125. data/app/assets/javascripts/elfinder/js/worker/calcfilehash.js +20 -0
  126. data/app/assets/javascripts/elfinder/js/worker/quicklook.tiff.js +7 -0
  127. data/app/assets/javascripts/elfinder/js/worker/quicklook.unzip.js +55 -0
  128. data/app/assets/javascripts/elfinder/main.default.js +175 -0
  129. data/app/assets/javascripts/elfinder/package.json +13 -0
  130. data/app/assets/javascripts/elfinder/php/MySQLStorage.sql +47 -0
  131. data/app/assets/javascripts/elfinder/php/autoload.php +56 -0
  132. data/app/assets/javascripts/elfinder/php/connector.maximal.php-dist +449 -0
  133. data/app/assets/javascripts/elfinder/php/connector.minimal.php-dist +180 -0
  134. data/app/assets/javascripts/elfinder/php/editors/OnlineConvert/editor.php +113 -0
  135. data/app/assets/javascripts/elfinder/php/editors/ZipArchive/editor.php +12 -0
  136. data/app/assets/javascripts/elfinder/php/editors/ZohoOffice/editor.php +206 -0
  137. data/app/assets/javascripts/elfinder/php/editors/editor.php +79 -0
  138. data/app/assets/javascripts/elfinder/php/elFinder.class.php +5401 -0
  139. data/app/assets/javascripts/elfinder/php/elFinderConnector.class.php +380 -0
  140. data/app/assets/javascripts/elfinder/php/elFinderFlysystemGoogleDriveNetmount.php +380 -0
  141. data/app/assets/javascripts/elfinder/php/elFinderPlugin.php +113 -0
  142. data/app/assets/javascripts/elfinder/php/elFinderSession.php +335 -0
  143. data/app/assets/javascripts/elfinder/php/elFinderSessionInterface.php +57 -0
  144. data/app/assets/javascripts/elfinder/php/elFinderVolumeBox.class.php +1972 -0
  145. data/app/assets/javascripts/elfinder/php/elFinderVolumeDriver.class.php +7651 -0
  146. data/app/assets/javascripts/elfinder/php/elFinderVolumeDropbox.class.php +1464 -0
  147. data/app/assets/javascripts/elfinder/php/elFinderVolumeDropbox2.class.php +1516 -0
  148. data/app/assets/javascripts/elfinder/php/elFinderVolumeFTP.class.php +1810 -0
  149. data/app/assets/javascripts/elfinder/php/elFinderVolumeGoogleDrive.class.php +2163 -0
  150. data/app/assets/javascripts/elfinder/php/elFinderVolumeGroup.class.php +315 -0
  151. data/app/assets/javascripts/elfinder/php/elFinderVolumeLocalFileSystem.class.php +1477 -0
  152. data/app/assets/javascripts/elfinder/php/elFinderVolumeMySQL.class.php +1022 -0
  153. data/app/assets/javascripts/elfinder/php/elFinderVolumeOneDrive.class.php +2131 -0
  154. data/app/assets/javascripts/elfinder/php/elFinderVolumeSFTPphpseclib.class.php +838 -0
  155. data/app/assets/javascripts/elfinder/php/elFinderVolumeTrash.class.php +51 -0
  156. data/app/assets/javascripts/elfinder/php/elFinderVolumeTrashMySQL.class.php +51 -0
  157. data/app/assets/javascripts/elfinder/php/libs/GdBmp.php +473 -0
  158. data/app/assets/javascripts/elfinder/php/mime.types +781 -0
  159. data/app/assets/javascripts/elfinder/php/plugins/AutoResize/plugin.php +151 -0
  160. data/app/assets/javascripts/elfinder/php/plugins/AutoRotate/plugin.php +148 -0
  161. data/app/assets/javascripts/elfinder/php/plugins/Normalizer/plugin.php +204 -0
  162. data/app/assets/javascripts/elfinder/php/plugins/Sanitizer/plugin.php +157 -0
  163. data/app/assets/javascripts/elfinder/php/plugins/Watermark/logo.png +0 -0
  164. data/app/assets/javascripts/elfinder/php/plugins/Watermark/plugin.php +432 -0
  165. data/app/assets/javascripts/elfinder/php/plugins/WinRemoveTailDots/plugin.php +114 -0
  166. data/app/assets/javascripts/elfinder/php/resources/image.png +0 -0
  167. data/app/assets/javascripts/elfinder/php/resources/video.png +0 -0
  168. data/app/assets/javascripts/elfinder/sounds/rm.wav +0 -0
  169. data/app/controllers/dc_elfinder_controller.rb +63 -0
  170. data/app/models/drgcms_form_fields/elfinder.rb +85 -0
  171. data/changelog.md +0 -0
  172. data/lib/drg_elfinder/engine.rb +5 -0
  173. data/lib/drg_elfinder/version.rb +3 -0
  174. data/lib/drg_elfinder.rb +9 -0
  175. data/lib/el_finder/action.rb +19 -0
  176. data/lib/el_finder/base64.rb +24 -0
  177. data/lib/el_finder/connector.rb +625 -0
  178. data/lib/el_finder/image.rb +33 -0
  179. data/lib/el_finder/mime_type.rb +86 -0
  180. data/lib/el_finder/pathname.rb +185 -0
  181. data/lib/el_finder/version.rb +5 -0
  182. data/lib/el_finder.rb +8 -0
  183. data/lib/patches/patch_for_elfinder.rb +115 -0
  184. data/lib/tasks/drg_elfinder_tasks.rake +10 -0
  185. metadata +245 -0
@@ -0,0 +1,51 @@
1
+ <?php
2
+
3
+ /**
4
+ * elFinder driver for trash bin at local filesystem.
5
+ *
6
+ * @author NaokiSawada
7
+ **/
8
+ class elFinderVolumeTrash extends elFinderVolumeLocalFileSystem
9
+ {
10
+ /**
11
+ * Driver id
12
+ * Must be started from letter and contains [a-z0-9]
13
+ * Used as part of volume id.
14
+ *
15
+ * @var string
16
+ **/
17
+ protected $driverId = 't';
18
+
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+ // original option of the Trash
23
+ $this->options['lockEverything'] = false; // Lock all items in the trash to disable delete, move, rename.
24
+
25
+ // common options as the volume driver
26
+ $this->options['alias'] = 'Trash';
27
+ $this->options['quarantine'] = '';
28
+ $this->options['rootCssClass'] = 'elfinder-navbar-root-trash';
29
+ $this->options['copyOverwrite'] = false;
30
+ $this->options['uiCmdMap'] = array('paste' => 'hidden', 'mkdir' => 'hidden', 'copy' => 'restore');
31
+ $this->options['disabled'] = array('archive', 'duplicate', 'edit', 'extract', 'mkfile', 'places', 'put', 'rename', 'resize', 'upload');
32
+ }
33
+
34
+ public function mount(array $opts)
35
+ {
36
+ if ($this->options['lockEverything']) {
37
+ if (!is_array($opts['attributes'])) {
38
+ $opts['attributes'] = array();
39
+ }
40
+ $attr = array(
41
+ 'pattern' => '/./',
42
+ 'locked' => true,
43
+ );
44
+ array_unshift($opts['attributes'], $attr);
45
+ }
46
+ // force set `copyJoin` to true
47
+ $opts['copyJoin'] = true;
48
+
49
+ return parent::mount($opts);
50
+ }
51
+ }
@@ -0,0 +1,51 @@
1
+ <?php
2
+
3
+ /**
4
+ * elFinder driver for trash bin at MySQL Database
5
+ *
6
+ * @author NaokiSawada
7
+ **/
8
+ class elFinderVolumeTrashMySQL extends elFinderVolumeMySQL
9
+ {
10
+ /**
11
+ * Driver id
12
+ * Must be started from letter and contains [a-z0-9]
13
+ * Used as part of volume id.
14
+ *
15
+ * @var string
16
+ **/
17
+ protected $driverId = 'tm';
18
+
19
+ public function __construct()
20
+ {
21
+ parent::__construct();
22
+ // original option of the Trash
23
+ $this->options['lockEverything'] = false; // Lock all items in the trash to disable delete, move, rename.
24
+
25
+ // common options as the volume driver
26
+ $this->options['alias'] = 'Trash';
27
+ $this->options['quarantine'] = '';
28
+ $this->options['rootCssClass'] = 'elfinder-navbar-root-trash';
29
+ $this->options['copyOverwrite'] = false;
30
+ $this->options['uiCmdMap'] = array('paste' => 'hidden', 'mkdir' => 'hidden', 'copy' => 'restore');
31
+ $this->options['disabled'] = array('archive', 'duplicate', 'edit', 'extract', 'mkfile', 'places', 'put', 'rename', 'resize', 'upload');
32
+ }
33
+
34
+ public function mount(array $opts)
35
+ {
36
+ if ($this->options['lockEverything']) {
37
+ if (!is_array($opts['attributes'])) {
38
+ $opts['attributes'] = array();
39
+ }
40
+ $attr = array(
41
+ 'pattern' => '/./',
42
+ 'locked' => true,
43
+ );
44
+ array_unshift($opts['attributes'], $attr);
45
+ }
46
+ // force set `copyJoin` to true
47
+ $opts['copyJoin'] = true;
48
+
49
+ return parent::mount($opts);
50
+ }
51
+ }
@@ -0,0 +1,473 @@
1
+ <?php
2
+ /**
3
+ * Copyright (c) 2011, oov. All rights reserved.
4
+ * Redistribution and use in source and binary forms, with or without modification,
5
+ * are permitted provided that the following conditions are met:
6
+ * - Redistributions of source code must retain the above copyright notice,
7
+ * this list of conditions and the following disclaimer.
8
+ * - Redistributions in binary form must reproduce the above copyright notice,
9
+ * this list of conditions and the following disclaimer in the documentation
10
+ * and/or other materials provided with the distribution.
11
+ * - Neither the name of the oov nor the names of its contributors may be used to
12
+ * endorse or promote products derived from this software without specific prior
13
+ * written permission.
14
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23
+ * POSSIBILITY OF SUCH DAMAGE.
24
+ * bmp ファイルを GD で使えるように
25
+ * 使用例:
26
+ * //ファイルから読み込む場合はGDでPNGなどを読み込むのと同じような方法で可
27
+ * $image = imagecreatefrombmp("test.bmp");
28
+ * imagedestroy($image);
29
+ * //文字列から読み込む場合は以下の方法で可
30
+ * $image = GdBmp::loadFromString(file_get_contents("test.bmp"));
31
+ * //自動判定されるので破損ファイルでなければこれでも上手くいく
32
+ * //$image = imagecreatefrombmp(file_get_contents("test.bmp"));
33
+ * imagedestroy($image);
34
+ * //その他任意のストリームからの読み込みも可能
35
+ * $stream = fopen("http://127.0.0.1/test.bmp");
36
+ * $image = GdBmp::loadFromStream($stream);
37
+ * //自動判定されるのでこれでもいい
38
+ * //$image = imagecreatefrombmp($stream);
39
+ * fclose($stream);
40
+ * imagedestroy($image);
41
+ * 対応フォーマット
42
+ * 1bit
43
+ * 4bit
44
+ * 4bitRLE
45
+ * 8bit
46
+ * 8bitRLE
47
+ * 16bit(任意のビットフィールド)
48
+ * 24bit
49
+ * 32bit(任意のビットフィールド)
50
+ * BITMAPINFOHEADER の biCompression が BI_PNG / BI_JPEG の画像
51
+ * すべての形式でトップダウン/ボトムアップの両方をサポート
52
+ * 特殊なビットフィールドでもビットフィールドデータが正常なら読み込み可能
53
+ * 以下のものは非対応
54
+ * BITMAPV4HEADER と BITMAPV5HEADER に含まれる色空間に関する様々な機能
55
+ *
56
+ * @param $filename_or_stream_or_binary
57
+ *
58
+ * @return bool|resource
59
+ */
60
+
61
+ if (!function_exists('imagecreatefrombmp')) {
62
+ function imagecreatefrombmp($filename_or_stream_or_binary)
63
+ {
64
+ return elFinderLibGdBmp::load($filename_or_stream_or_binary);
65
+ }
66
+ }
67
+
68
+ class elFinderLibGdBmp
69
+ {
70
+ public static function load($filename_or_stream_or_binary)
71
+ {
72
+ if (is_resource($filename_or_stream_or_binary)) {
73
+ return self::loadFromStream($filename_or_stream_or_binary);
74
+ } else if (is_string($filename_or_stream_or_binary) && strlen($filename_or_stream_or_binary) >= 26) {
75
+ $bfh = unpack("vtype/Vsize", $filename_or_stream_or_binary);
76
+ if ($bfh["type"] == 0x4d42 && ($bfh["size"] == 0 || $bfh["size"] == strlen($filename_or_stream_or_binary))) {
77
+ return self::loadFromString($filename_or_stream_or_binary);
78
+ }
79
+ }
80
+ return self::loadFromFile($filename_or_stream_or_binary);
81
+ }
82
+
83
+ public static function loadFromFile($filename)
84
+ {
85
+ $fp = fopen($filename, "rb");
86
+ if ($fp === false) {
87
+ return false;
88
+ }
89
+
90
+ $bmp = self::loadFromStream($fp);
91
+
92
+ fclose($fp);
93
+ return $bmp;
94
+ }
95
+
96
+ public static function loadFromString($str)
97
+ {
98
+ //data scheme より古いバージョンから対応しているようなので php://memory を使う
99
+ $fp = fopen("php://memory", "r+b");
100
+ if ($fp === false) {
101
+ return false;
102
+ }
103
+
104
+ if (fwrite($fp, $str) != strlen($str)) {
105
+ fclose($fp);
106
+ return false;
107
+ }
108
+
109
+ if (fseek($fp, 0) === -1) {
110
+ fclose($fp);
111
+ return false;
112
+ }
113
+
114
+ $bmp = self::loadFromStream($fp);
115
+
116
+ fclose($fp);
117
+ return $bmp;
118
+ }
119
+
120
+ public static function loadFromStream($stream)
121
+ {
122
+ $buf = fread($stream, 14); //2+4+2+2+4
123
+ if ($buf === false) {
124
+ return false;
125
+ }
126
+
127
+ //シグネチャチェック
128
+ if ($buf[0] != 'B' || $buf[1] != 'M') {
129
+ return false;
130
+ }
131
+
132
+ $bitmap_file_header = unpack(
133
+ //BITMAPFILEHEADER構造体
134
+ "vtype/" .
135
+ "Vsize/" .
136
+ "vreserved1/" .
137
+ "vreserved2/" .
138
+ "Voffbits", $buf
139
+ );
140
+
141
+ return self::loadFromStreamAndFileHeader($stream, $bitmap_file_header);
142
+ }
143
+
144
+ public static function loadFromStreamAndFileHeader($stream, array $bitmap_file_header)
145
+ {
146
+ if ($bitmap_file_header["type"] != 0x4d42) {
147
+ return false;
148
+ }
149
+
150
+ //情報ヘッダサイズを元に形式を区別して読み込み
151
+ $buf = fread($stream, 4);
152
+ if ($buf === false) {
153
+ return false;
154
+ }
155
+ list(, $header_size) = unpack("V", $buf);
156
+
157
+
158
+ if ($header_size == 12) {
159
+ $buf = fread($stream, $header_size - 4);
160
+ if ($buf === false) {
161
+ return false;
162
+ }
163
+
164
+ extract(unpack(
165
+ //BITMAPCOREHEADER構造体 - OS/2 Bitmap
166
+ "vwidth/" .
167
+ "vheight/" .
168
+ "vplanes/" .
169
+ "vbit_count", $buf
170
+ ));
171
+ //飛んでこない分は 0 で初期化しておく
172
+ $clr_used = $clr_important = $alpha_mask = $compression = 0;
173
+
174
+ //マスク類は初期化されないのでここで割り当てておく
175
+ $red_mask = 0x00ff0000;
176
+ $green_mask = 0x0000ff00;
177
+ $blue_mask = 0x000000ff;
178
+ } else if (124 < $header_size || $header_size < 40) {
179
+ //未知の形式
180
+ return false;
181
+ } else {
182
+ //この時点で36バイト読めることまではわかっている
183
+ $buf = fread($stream, 36); //既に読んだ部分は除外しつつBITMAPINFOHEADERのサイズだけ読む
184
+ if ($buf === false) {
185
+ return false;
186
+ }
187
+
188
+ //BITMAPINFOHEADER構造体 - Windows Bitmap
189
+ extract(unpack(
190
+ "Vwidth/" .
191
+ "Vheight/" .
192
+ "vplanes/" .
193
+ "vbit_count/" .
194
+ "Vcompression/" .
195
+ "Vsize_image/" .
196
+ "Vx_pels_per_meter/" .
197
+ "Vy_pels_per_meter/" .
198
+ "Vclr_used/" .
199
+ "Vclr_important", $buf
200
+ ));
201
+ /**
202
+ * @var integer $width
203
+ * @var integer $height
204
+ * @var integer $planes
205
+ * @var integer $bit_count
206
+ * @var integer $compression
207
+ * @var integer $size_image
208
+ * @var integer $x_pels_per_meter
209
+ * @var integer $y_pels_per_meter
210
+ * @var integer $clr_used
211
+ * @var integer $clr_important
212
+ */
213
+ //負の整数を受け取る可能性があるものは自前で変換する
214
+ if ($width & 0x80000000) {
215
+ $width = -(~$width & 0xffffffff) - 1;
216
+ }
217
+ if ($height & 0x80000000) {
218
+ $height = -(~$height & 0xffffffff) - 1;
219
+ }
220
+ if ($x_pels_per_meter & 0x80000000) {
221
+ $x_pels_per_meter = -(~$x_pels_per_meter & 0xffffffff) - 1;
222
+ }
223
+ if ($y_pels_per_meter & 0x80000000) {
224
+ $y_pels_per_meter = -(~$y_pels_per_meter & 0xffffffff) - 1;
225
+ }
226
+
227
+ //ファイルによっては BITMAPINFOHEADER のサイズがおかしい(書き込み間違い?)ケースがある
228
+ //自分でファイルサイズを元に逆算することで回避できることもあるので再計算できそうなら正当性を調べる
229
+ //シークできないストリームの場合全体のファイルサイズは取得できないので、$bitmap_file_headerにサイズ申告がなければやらない
230
+ if ($bitmap_file_header["size"] != 0) {
231
+ $colorsize = $bit_count == 1 || $bit_count == 4 || $bit_count == 8 ? ($clr_used ? $clr_used : pow(2, $bit_count)) << 2 : 0;
232
+ $bodysize = $size_image ? $size_image : ((($width * $bit_count + 31) >> 3) & ~3) * abs($height);
233
+ $calcsize = $bitmap_file_header["size"] - $bodysize - $colorsize - 14;
234
+
235
+ //本来であれば一致するはずなのに合わない時は、値がおかしくなさそうなら(BITMAPV5HEADERの範囲内なら)計算して求めた値を採用する
236
+ if ($header_size < $calcsize && 40 <= $header_size && $header_size <= 124) {
237
+ $header_size = $calcsize;
238
+ }
239
+ }
240
+
241
+ //BITMAPV4HEADER や BITMAPV5HEADER の場合まだ読むべきデータが残っている可能性がある
242
+ if ($header_size - 40 > 0) {
243
+ $buf = fread($stream, $header_size - 40);
244
+ if ($buf === false) {
245
+ return false;
246
+ }
247
+
248
+ extract(unpack(
249
+ //BITMAPV4HEADER構造体(Windows95以降)
250
+ //BITMAPV5HEADER構造体(Windows98/2000以降)
251
+ "Vred_mask/" .
252
+ "Vgreen_mask/" .
253
+ "Vblue_mask/" .
254
+ "Valpha_mask", $buf . str_repeat("\x00", 120)
255
+ ));
256
+ } else {
257
+ $alpha_mask = $red_mask = $green_mask = $blue_mask = 0;
258
+ }
259
+
260
+ //パレットがないがカラーマスクもない時
261
+ if (
262
+ ($bit_count == 16 || $bit_count == 24 || $bit_count == 32) &&
263
+ $compression == 0 &&
264
+ $red_mask == 0 && $green_mask == 0 && $blue_mask == 0
265
+ ) {
266
+ //もしカラーマスクを所持していない場合は
267
+ //規定のカラーマスクを適用する
268
+ switch ($bit_count) {
269
+ case 16:
270
+ $red_mask = 0x7c00;
271
+ $green_mask = 0x03e0;
272
+ $blue_mask = 0x001f;
273
+ break;
274
+ case 24:
275
+ case 32:
276
+ $red_mask = 0x00ff0000;
277
+ $green_mask = 0x0000ff00;
278
+ $blue_mask = 0x000000ff;
279
+ break;
280
+ }
281
+ }
282
+ }
283
+
284
+ if (
285
+ ($width == 0) ||
286
+ ($height == 0) ||
287
+ ($planes != 1) ||
288
+ (($alpha_mask & $red_mask) != 0) ||
289
+ (($alpha_mask & $green_mask) != 0) ||
290
+ (($alpha_mask & $blue_mask) != 0) ||
291
+ (($red_mask & $green_mask) != 0) ||
292
+ (($red_mask & $blue_mask) != 0) ||
293
+ (($green_mask & $blue_mask) != 0)
294
+ ) {
295
+ //不正な画像
296
+ return false;
297
+ }
298
+
299
+ //BI_JPEG と BI_PNG の場合は jpeg/png がそのまま入ってるだけなのでそのまま取り出してデコードする
300
+ if ($compression == 4 || $compression == 5) {
301
+ $buf = stream_get_contents($stream, $size_image);
302
+ if ($buf === false) {
303
+ return false;
304
+ }
305
+ return imagecreatefromstring($buf);
306
+ }
307
+
308
+ //画像本体の読み出し
309
+ //1行のバイト数
310
+ $line_bytes = (($width * $bit_count + 31) >> 3) & ~3;
311
+ //全体の行数
312
+ $lines = abs($height);
313
+ //y軸進行量(ボトムアップかトップダウンか)
314
+ $y = $height > 0 ? $lines - 1 : 0;
315
+ $line_step = $height > 0 ? -1 : 1;
316
+
317
+ //256色以下の画像か?
318
+ if ($bit_count == 1 || $bit_count == 4 || $bit_count == 8) {
319
+ $img = imagecreate($width, $lines);
320
+
321
+ //画像データの前にパレットデータがあるのでパレットを作成する
322
+ $palette_size = $header_size == 12 ? 3 : 4; //OS/2形式の場合は x に相当する箇所のデータは最初から確保されていない
323
+ $colors = $clr_used ? $clr_used : pow(2, $bit_count); //色数
324
+ $palette = array();
325
+ for ($i = 0; $i < $colors; ++$i) {
326
+ $buf = fread($stream, $palette_size);
327
+ if ($buf === false) {
328
+ imagedestroy($img);
329
+ return false;
330
+ }
331
+ extract(unpack("Cb/Cg/Cr/Cx", $buf . "\x00"));
332
+ /**
333
+ * @var integer $b
334
+ * @var integer $g
335
+ * @var integer $r
336
+ * @var integer $x
337
+ */
338
+ $palette[] = imagecolorallocate($img, $r, $g, $b);
339
+ }
340
+
341
+ $shift_base = 8 - $bit_count;
342
+ $mask = ((1 << $bit_count) - 1) << $shift_base;
343
+
344
+ //圧縮されている場合とされていない場合でデコード処理が大きく変わる
345
+ if ($compression == 1 || $compression == 2) {
346
+ $x = 0;
347
+ $qrt_mod2 = $bit_count >> 2 & 1;
348
+ for (; ;) {
349
+ //もし描写先が範囲外になっている場合デコード処理がおかしくなっているので抜ける
350
+ //変なデータが渡されたとしても最悪なケースで255回程度の無駄なので目を瞑る
351
+ if ($x < -1 || $x > $width || $y < -1 || $y > $height) {
352
+ imagedestroy($img);
353
+ return false;
354
+ }
355
+ $buf = fread($stream, 1);
356
+ if ($buf === false) {
357
+ imagedestroy($img);
358
+ return false;
359
+ }
360
+ switch ($buf) {
361
+ case "\x00":
362
+ $buf = fread($stream, 1);
363
+ if ($buf === false) {
364
+ imagedestroy($img);
365
+ return false;
366
+ }
367
+ switch ($buf) {
368
+ case "\x00": //EOL
369
+ $y += $line_step;
370
+ $x = 0;
371
+ break;
372
+ case "\x01": //EOB
373
+ $y = 0;
374
+ $x = 0;
375
+ break 3;
376
+ case "\x02": //MOV
377
+ $buf = fread($stream, 2);
378
+ if ($buf === false) {
379
+ imagedestroy($img);
380
+ return false;
381
+ }
382
+ list(, $xx, $yy) = unpack("C2", $buf);
383
+ $x += $xx;
384
+ $y += $yy * $line_step;
385
+ break;
386
+ default: //ABS
387
+ list(, $pixels) = unpack("C", $buf);
388
+ $bytes = ($pixels >> $qrt_mod2) + ($pixels & $qrt_mod2);
389
+ $buf = fread($stream, ($bytes + 1) & ~1);
390
+ if ($buf === false) {
391
+ imagedestroy($img);
392
+ return false;
393
+ }
394
+ for ($i = 0, $pos = 0; $i < $pixels; ++$i, ++$x, $pos += $bit_count) {
395
+ list(, $c) = unpack("C", $buf[$pos >> 3]);
396
+ $b = $pos & 0x07;
397
+ imagesetpixel($img, $x, $y, $palette[($c & ($mask >> $b)) >> ($shift_base - $b)]);
398
+ }
399
+ break;
400
+ }
401
+ break;
402
+ default:
403
+ $buf2 = fread($stream, 1);
404
+ if ($buf2 === false) {
405
+ imagedestroy($img);
406
+ return false;
407
+ }
408
+ list(, $size, $c) = unpack("C2", $buf . $buf2);
409
+ for ($i = 0, $pos = 0; $i < $size; ++$i, ++$x, $pos += $bit_count) {
410
+ $b = $pos & 0x07;
411
+ imagesetpixel($img, $x, $y, $palette[($c & ($mask >> $b)) >> ($shift_base - $b)]);
412
+ }
413
+ break;
414
+ }
415
+ }
416
+ } else {
417
+ for ($line = 0; $line < $lines; ++$line, $y += $line_step) {
418
+ $buf = fread($stream, $line_bytes);
419
+ if ($buf === false) {
420
+ imagedestroy($img);
421
+ return false;
422
+ }
423
+
424
+ $pos = 0;
425
+ for ($x = 0; $x < $width; ++$x, $pos += $bit_count) {
426
+ list(, $c) = unpack("C", $buf[$pos >> 3]);
427
+ $b = $pos & 0x7;
428
+ imagesetpixel($img, $x, $y, $palette[($c & ($mask >> $b)) >> ($shift_base - $b)]);
429
+ }
430
+ }
431
+ }
432
+ } else {
433
+ $img = imagecreatetruecolor($width, $lines);
434
+ imagealphablending($img, false);
435
+ if ($alpha_mask) {
436
+ //αデータがあるので透過情報も保存できるように
437
+ imagesavealpha($img, true);
438
+ }
439
+
440
+ //x軸進行量
441
+ $pixel_step = $bit_count >> 3;
442
+ $alpha_max = $alpha_mask ? 0x7f : 0x00;
443
+ $alpha_mask_r = $alpha_mask ? 1 / $alpha_mask : 1;
444
+ $red_mask_r = $red_mask ? 1 / $red_mask : 1;
445
+ $green_mask_r = $green_mask ? 1 / $green_mask : 1;
446
+ $blue_mask_r = $blue_mask ? 1 / $blue_mask : 1;
447
+
448
+ for ($line = 0; $line < $lines; ++$line, $y += $line_step) {
449
+ $buf = fread($stream, $line_bytes);
450
+ if ($buf === false) {
451
+ imagedestroy($img);
452
+ return false;
453
+ }
454
+
455
+ $pos = 0;
456
+ for ($x = 0; $x < $width; ++$x, $pos += $pixel_step) {
457
+ list(, $c) = unpack("V", substr($buf, $pos, $pixel_step) . "\x00\x00");
458
+ $a_masked = $c & $alpha_mask;
459
+ $r_masked = $c & $red_mask;
460
+ $g_masked = $c & $green_mask;
461
+ $b_masked = $c & $blue_mask;
462
+ $a = $alpha_max - ((($a_masked << 7) - $a_masked) * $alpha_mask_r);
463
+ $r = (($r_masked << 8) - $r_masked) * $red_mask_r;
464
+ $g = (($g_masked << 8) - $g_masked) * $green_mask_r;
465
+ $b = (($b_masked << 8) - $b_masked) * $blue_mask_r;
466
+ imagesetpixel($img, $x, $y, ($a << 24) | ($r << 16) | ($g << 8) | $b);
467
+ }
468
+ }
469
+ imagealphablending($img, true); //デフォルト値に戻しておく
470
+ }
471
+ return $img;
472
+ }
473
+ }