2 // vim: tabstop=2:shiftwidth=2
\r
5 * Parser_PaintBBS.php ($Revision: 1.33 $)
\r
7 * by hsur ( http://blog.cles.jp/np_cles )
\r
8 * $Id: Parser_PaintBBS.php,v 1.33 2010/06/06 11:44:19 hsur Exp $
\r
12 * Copyright (C) 2005-2010 CLES. All rights reserved.
\r
14 * This program is free software; you can redistribute it and/or
\r
15 * modify it under the terms of the GNU General Public License
\r
16 * as published by the Free Software Foundation; either version 2
\r
17 * of the License, or (at your option) any later version.
\r
19 * This program is distributed in the hope that it will be useful,
\r
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
22 * GNU General Public License for more details.
\r
24 * You should have received a copy of the GNU General Public License
\r
25 * along with this program; if not, write to the Free Software
\r
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
28 * In addition, as a special exception, cles( http://blog.cles.jp/np_cles ) gives
\r
29 * permission to link the code of this program with those files in the PEAR
\r
30 * library that are licensed under the PHP License (or with modified versions
\r
31 * of those files that use the same license as those files), and distribute
\r
32 * linked combinations including the two. You must obey the GNU General Public
\r
33 * License in all respects for all of the code used other than those files in
\r
34 * the PEAR library that are licensed under the PHP License. If you modify
\r
35 * this file, you may extend this exception to your version of the file,
\r
36 * but you are not obligated to do so. If you do not wish to do so, delete
\r
37 * this exception statement from your version.
\r
41 class Parser_PaintBBS extends PaintPlugin {
\r
42 function Parser_PaintBBS(){
\r
43 $this->id = '$Id: Parser_PaintBBS.php,v 1.33 2010/06/06 11:44:19 hsur Exp $';
\r
44 $this->name = 'PaintBBS Parser';
\r
45 $this->enable = true;
\r
47 $this->postdata = null;
\r
50 function _read($length, &$err){
\r
51 $data = substr( $this->postdata, $this->offset, $length );
\r
52 $this->offset += strlen($data);
\r
54 if( strlen($data) != $length ) $err = true;
\r
60 $plugin = $manager->getPlugin('NP_Paint');
\r
62 ini_set("always_populate_raw_post_data", "1");
\r
63 global $HTTP_RAW_POST_DATA;
\r
64 $this->postdata = $HTTP_RAW_POST_DATA;;
\r
66 if(! $this->postdata ){
\r
67 $plugin->_info(_PAINT_Parser_useinput);
\r
68 if( $_SERVER['CONTENT_LENGTH'] ) $length = $_SERVER['CONTENT_LENGTH'];
\r
69 if( $_ENV['CONTENT_LENGTH'] ) $length = $_ENV['CONTENT_LENGTH'];
\r
70 $input = fopen("php://input", "rb");
\r
72 $this->postdata = fread($input, $length);
\r
74 $plugin->_warn(_PAINT_Parser_contentLengthNotFound);
\r
75 while (!feof($input)) {
\r
76 $this->postdata .= fread($input, 8192);
\r
84 $test = fopen("/tmp/postdata.dat","wb");
\r
85 fwrite($test, $this->postdata);
\r
87 $plugin->_info('post length: ' . strlen($this->postdata) );
\r
93 'images' => Array(),
\r
99 $data['magic'] = $this->_read(1, $err);
\r
100 if($err) return 'Cannot read magic char';
\r
101 if( $data['magic'] == chr(0x00) ) return 'magic char is INVALID. (maybe poo=true?) ->' . $data['magic'];
\r
102 $plugin->_info('post magic: ' . $data['magic'] );
\r
105 $headerSize = $this->_read(8, $err);
\r
106 if($err) return 'Cannot read header size';
\r
107 if( ! is_numeric($headerSize) ) return 'Header size is INVALID';
\r
109 $data['header'] = $this->_read(intval($headerSize), $err);
\r
110 if($err) return 'Cannot read header';
\r
113 $imageSize = $this->_read(8, $err);
\r
114 if($err) return 'Cannot read image size';
\r
115 if( ! is_numeric($imageSize) ) return 'Image size is INVALID';
\r
117 $pad = $this->_read(2, $err);// '\r\n'
\r
118 if($err) return 'Cannot read padding';
\r
119 if(! $pad === "\r\n" ) return 'Cannot find padding';
\r
121 $imageData = $this->_read(intval($imageSize), $err);
\r
122 if($err) return 'Cannot read image ' . "(expected: $imageSize, actual:" . strlen($imageData) . ")";
\r
123 $plugin->_info("ImageSize (expected: $imageSize, actual:" . strlen($imageData) . ")");
\r
125 $data['images'][] = $imageData;
\r
126 $data['size'][] = strlen($imageData);
\r
130 $thumbSize = $this->_read(8, $err);
\r
132 if( ! is_numeric($thumbSize) ) break;
\r
134 if( $thumbSize != 0 ){
\r
135 $imageData = $this->_read($thumbSize, $err);
\r
137 $data['images'][] = $imageData;
\r
138 $data['size'][] = strlen($imageData);
\r
139 $plugin->_info("AnimeSize (expected: $thumbSize, actual:" . strlen($imageData) . ")");
\r