Subversion-Projekte lars-tiefland.content-management

Revision

Revision 1 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 1 Revision 2
Zeile 9... Zeile 9...
9
    * Licensed under the MIT license:
9
    * Licensed under the MIT license:
10
    * http://creativecommons.org/licenses/MIT/
10
    * http://creativecommons.org/licenses/MIT/
11
    */
11
    */
12
    require "common.php";
12
    require "common.php";
13
    error_reporting( E_ALL | E_STRICT );
13
    error_reporting( E_ALL | E_STRICT );
-
 
14
    define( "__USE_MDB2__", false );
14
    $GLOBALS["web"] = $webs;
15
    $GLOBALS["web"] = $webs;
-
 
16
    $GLOBALS["web_rechte"] = $web_rechte;
15
    $GLOBALS["site"] = $site;
17
    $GLOBALS["site"] = $site;
16
    if ( preg_match( "/\.local$/", $_SERVER["SERVER_NAME"] ) )
18
    if ( preg_match( "/\.local$/", $_SERVER["SERVER_NAME"] ) )
17
    {
19
    {
18
        $GLOBALS["site"] .= ".local";
20
        $GLOBALS["site"] .= ".local";
19
    }
21
    }
Zeile 27... Zeile 29...
27
        $folder = Weban_Utils::clean_global_input( "folder" );
29
        $folder = Weban_Utils::clean_global_input( "folder" );
28
    } elseif ( isset( $_GET["folder"] ) && $_GET["folder"] )
30
    } elseif ( isset( $_GET["folder"] ) && $_GET["folder"] )
29
    {
31
    {
30
        $folder = Weban_Utils::clean_global_input( "folder", "get" );
32
        $folder = Weban_Utils::clean_global_input( "folder", "get" );
31
    }
33
    }
-
 
34
    $Imagedaten = array_chunk( explode( ";", $GLOBALS["web_rechte"]["admin"]["toolbox"]["bildverwaltung"] ),
-
 
35
        4 );
-
 
36
 
32
    if ( $folder )
37
    if ( $folder )
33
    {
38
    {
34
        $folder=rtrim($folder,"/");
39
        $folder = rtrim( $folder, "/" );
35
        $GLOBALS["folder"] = $folder;
40
        $GLOBALS["folder"] = $folder;
36
        $folder .= "/";
41
        $folder .= "/";
37
        $real_folder .= $folder;
42
        $real_folder .= $folder;
38
        $real_url .= $folder;
43
        $real_url .= $folder;
39
        $options["upload_dir"] = $real_folder;
44
        $options["upload_dir"] = $real_folder;
40
        $options["upload_url"] = $real_url;
45
        $options["upload_url"] = $real_url;
41
        $options["image_versions"]["large"]["upload_dir"] = $real_folder .
46
        foreach ( $Imagedaten as $set )
42
            "gr/";
47
        {
43
        $options["image_versions"]["large"]["upload_url"] = $real_url .
48
            $options["image_versions"][$set[0]] = array( "upload_dir" => $real_folder .
44
            "gr/";
-
 
45
        $options["image_versions"]["thumbnail"]["upload_dir"] = $real_folder .
49
                $set[1] . "/", "upload_url" => $real_url . $set[1] . "/",
46
            "mini/";
-
 
47
        $options["image_versions"]["thumbnail"]["upload_url"] = $real_url .
50
                "max_width" => $set[2], "max_height" => $set[3], );
48
            "mini/";
51
        }
49
    }
52
    }
Zeile 50... Zeile 53...
50
 
53
 
51
    class UploadHandler
54
    class UploadHandler
52
    {
55
    {
Zeile 53... Zeile 56...
53
        private $options;
56
        private $options;
54
 
57
 
-
 
58
        function __construct( $options = null )
-
 
59
        {
55
        function __construct( $options = null )
60
            $Imagedaten = array_chunk( explode( ";", $GLOBALS["web_rechte"]["admin"]["toolbox"]["bildverwaltung"] ),
56
        {
61
                4 );
57
            $this->options = array( 'script_url' => $_SERVER['PHP_SELF'],
62
            $this->options = array( 'script_url' => $_SERVER['PHP_SELF'],
58
                'upload_dir' => $GLOBALS["web"]["verzeichnis"] .
63
                'upload_dir' => $GLOBALS["web"]["verzeichnis"] .
59
                '/images/upload/', 'upload_url' => "http://www." . $GLOBALS["site"] .
64
                '/images/upload/', 'upload_url' => "http://www." . $GLOBALS["site"] .
60
                '/images/upload/', 'param_name' => 'files',
65
                '/images/upload/', 'param_name' => 'files',
61
                // The php.ini settings upload_max_filesize and post_max_size
66
                // The php.ini settings upload_max_filesize and post_max_size
62
                // take precedence over the following max_file_size setting:
67
                // take precedence over the following max_file_size setting:
63
            'max_file_size' => null, 'min_file_size' => 1,
68
            'max_file_size' => null, 'min_file_size' => 1, 'accept_file_types' =>
64
                'accept_file_types' => '/.+$/i', 'max_number_of_files' => null,
69
                '/(\.|\/)(gif|jpe?g|png)$/i', 'max_number_of_files' => null,
65
                'discard_aborted_uploads' => true, 'image_versions' => array
70
                'discard_aborted_uploads' => true,
66
                ( // Uncomment the following version to restrict the size of
71
                /*'image_versions' => array( // Uncomment the following version to restrict the size of
67
                // uploaded images. You can also add additional versions with
-
 
68
            // their own upload directories:
72
                // uploaded images. You can also add additional versions with
69
 
73
                // their own upload directories:
70
            'large' => array( 'upload_dir' => $GLOBALS["web"]["verzeichnis"] .
74
                'large' => array( 'upload_dir' => $GLOBALS["web"]["verzeichnis"] .
71
                '/images/upload/gr/', 'upload_url' => "http://www." . $GLOBALS["site"] .
75
                '/images/upload/gr/', 'upload_url' => "http://www." . $GLOBALS["site"] .
72
                '/images/upload/gr/', 'max_width' => 1920, 'max_height' =>
76
                '/images/upload/gr/', 'max_width' => 1920, 'max_height' => 1920 ),
73
                1920 ), 'thumbnail' => array( 'upload_dir' => $GLOBALS["web"]["verzeichnis"] .
77
                'thumbnail' => array( 'upload_dir' => $GLOBALS["web"]["verzeichnis"] .
-
 
78
                '/images/upload/mini/', 'upload_url' => "http://www." . $GLOBALS["site"] .
-
 
79
                '/images/upload/mini/', 'max_width' => 80, 'max_height' => 80, ), ),*/ );
-
 
80
            foreach ( $Imagedaten as $set )
-
 
81
            {
-
 
82
                $this->options["image_versions"][$set[0]] = array( "upload_dir" =>
-
 
83
                    $GLOBALS["web"]["verzeichnis"] . '/images/upload/' . $set[1] .
-
 
84
                    "/", "upload_url" => "http://www." . $GLOBALS["site"] .
74
                '/images/upload/mini/', 'upload_url' => "http://www." . $GLOBALS["site"] .
85
                    '/images/upload/' . $set[1] . "/", "max_width" => $set[2],
75
                '/images/upload/mini/', 'max_width' => 80, 'max_height' =>
86
                    "max_height" => $set[3], );
76
                80 ) ) );
87
            }
77
            if ( $options )
88
            if ( $options )
78
            {
89
            {
79
                foreach ( $options as $o_id => $option )
90
                foreach ( $options as $o_id => $option )
Zeile 93... Zeile 104...
93
                        }
104
                        }
94
                    }
105
                    }
95
                }
106
                }
96
                //$this->options = array_merge( $this->options, $options );
107
                //$this->options = array_merge( $this->options, $options );
97
            }
108
            }
-
 
109
            //var_dump( $this->options );
-
 
110
            //exit;
98
        }
111
        }
Zeile 99... Zeile 112...
99
 
112
 
100
        private function get_file_object( $file_name )
113
        private function get_file_object( $file_name )
101
        {
114
        {
Zeile 114... Zeile 127...
114
                        $file->{$version . '_url'} = $options['upload_url'] .
127
                        $file->{$version . '_url'} = $options['upload_url'] .
115
                            rawurlencode( $file->name );
128
                            rawurlencode( $file->name );
116
                    }
129
                    }
117
                }
130
                }
118
                $file->delete_url = $this->options['script_url'] . '?file=' .
131
                $file->delete_url = $this->options['script_url'] . '?file=' .
119
                    rawurlencode( $file->name ).'&folder='.$GLOBALS["folder"];
132
                    rawurlencode( $file->name ) . '&folder=' . $GLOBALS["folder"];
120
                $file->delete_type = 'DELETE';
133
                $file->delete_type = 'DELETE';
121
                return $file;
134
                return $file;
122
            }
135
            }
123
            return null;
136
            return null;
124
        }
137
        }
Zeile 169... Zeile 182...
169
                    $write_image = 'imagepng';
182
                    $write_image = 'imagepng';
170
                    break;
183
                    break;
171
                default:
184
                default:
172
                    $src_img = $image_method = null;
185
                    $src_img = $image_method = null;
173
            }
186
            }
174
            $success = $src_img && @imagecopyresampled( $new_img, $src_img,
187
            $success = $src_img && @imagecopyresampled( $new_img, $src_img, 0, 0,
175
                0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height ) &&
188
                0, 0, $new_width, $new_height, $img_width, $img_height ) && $write_image( $new_img,
176
                $write_image( $new_img, $new_file_path );
189
                $new_file_path );
177
            // Free up memory (imagedestroy does not delete files):
190
            // Free up memory (imagedestroy does not delete files):
178
            @imagedestroy( $src_img );
191
            @imagedestroy( $src_img );
179
            @imagedestroy( $new_img );
192
            @imagedestroy( $new_img );
180
            return $success;
193
            return $success;
181
        }
194
        }
Zeile 184... Zeile 197...
184
        {
197
        {
185
            if ( $error )
198
            if ( $error )
186
            {
199
            {
187
                return $error;
200
                return $error;
188
            }
201
            }
189
            if ( !preg_match( $this->options['accept_file_types'], $file->
202
            if ( !preg_match( $this->options['accept_file_types'], $file->name ) )
190
                name ) )
-
 
191
            {
203
            {
192
                return 'acceptFileTypes';
204
                return 'acceptFileTypes';
193
            }
205
            }
194
            if ( $uploaded_file && is_uploaded_file( $uploaded_file ) )
206
            if ( $uploaded_file && is_uploaded_file( $uploaded_file ) )
195
            {
207
            {
Zeile 202... Zeile 214...
202
            if ( $this->options['max_file_size'] && ( $file_size > $this->
214
            if ( $this->options['max_file_size'] && ( $file_size > $this->
203
                options['max_file_size'] || $file->size > $this->options['max_file_size'] ) )
215
                options['max_file_size'] || $file->size > $this->options['max_file_size'] ) )
204
            {
216
            {
205
                return 'maxFileSize';
217
                return 'maxFileSize';
206
            }
218
            }
207
            if ( $this->options['min_file_size'] && $file_size < $this->
219
            if ( $this->options['min_file_size'] && $file_size < $this->options['min_file_size'] )
208
                options['min_file_size'] )
-
 
209
            {
220
            {
210
                return 'minFileSize';
221
                return 'minFileSize';
211
            }
222
            }
212
            if ( is_int( $this->options['max_number_of_files'] ) && ( count
223
            if ( is_int( $this->options['max_number_of_files'] ) && ( count( $this->
213
                ( $this->get_file_objects() ) >= $this->options['max_number_of_files'] ) )
224
                get_file_objects() ) >= $this->options['max_number_of_files'] ) )
214
            {
225
            {
215
                return 'maxNumberOfFiles';
226
                return 'maxNumberOfFiles';
216
            }
227
            }
217
            return $error;
228
            return $error;
218
        }
229
        }
Zeile 256... Zeile 267...
256
                $file_size = filesize( $file_path );
267
                $file_size = filesize( $file_path );
257
                if ( $file_size === $file->size )
268
                if ( $file_size === $file->size )
258
                {
269
                {
259
                    $file->url = $this->options['upload_url'] . rawurlencode( $file->
270
                    $file->url = $this->options['upload_url'] . rawurlencode( $file->
260
                        name );
271
                        name );
261
                    foreach ( $this->options['image_versions'] as $version =>
272
                    foreach ( $this->options['image_versions'] as $version => $options )
262
                        $options )
-
 
263
                    {
273
                    {
264
                        if ( $this->create_scaled_image( $file->name, $options ) )
274
                        if ( $this->create_scaled_image( $file->name, $options ) )
265
                        {
275
                        {
266
                            $file->{$version . '_url'} = $options['upload_url'] .
276
                            $file->{$version . '_url'} = $options['upload_url'] .
267
                                rawurlencode( $file->name );
277
                                rawurlencode( $file->name );
Zeile 295... Zeile 305...
295
            return $file;
305
            return $file;
296
        }
306
        }
Zeile 297... Zeile 307...
297
 
307
 
298
        public function get()
308
        public function get()
299
        {
309
        {
300
            $file_name = isset( $_REQUEST['file'] ) ? basename( stripslashes
-
 
301
                ( $_REQUEST['file'] ) ) : null;
310
            $file_name = isset( $_REQUEST['file'] ) ? basename( stripslashes( $_REQUEST['file'] ) ) : null;
302
            if ( $file_name )
311
            if ( $file_name )
303
            {
312
            {
304
                $info = $this->get_file_object( $file_name );
313
                $info = $this->get_file_object( $file_name );
305
            }
314
            }
Zeile 329... Zeile 338...
329
                        $upload['type'][$index], $upload['error'][$index] );
338
                        $upload['type'][$index], $upload['error'][$index] );
330
                }
339
                }
331
            }
340
            }
332
            else
341
            else
333
            {
342
            {
334
                $info[] = $this->handle_file_upload( $upload['tmp_name'],
343
                $info[] = $this->handle_file_upload( $upload['tmp_name'], isset
335
                    isset( $_SERVER['HTTP_X_FILE_NAME'] ) ? $_SERVER['HTTP_X_FILE_NAME'] :
344
                    ( $_SERVER['HTTP_X_FILE_NAME'] ) ? $_SERVER['HTTP_X_FILE_NAME'] :
336
                    $upload['name'], isset( $_SERVER['HTTP_X_FILE_SIZE'] ) ?
345
                    $upload['name'], isset( $_SERVER['HTTP_X_FILE_SIZE'] ) ? $_SERVER['HTTP_X_FILE_SIZE'] :
337
                    $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'], isset( $_SERVER['HTTP_X_FILE_TYPE'] ) ?
346
                    $upload['size'], isset( $_SERVER['HTTP_X_FILE_TYPE'] ) ? $_SERVER['HTTP_X_FILE_TYPE'] :
338
                    $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'], $upload['error'] );
347
                    $upload['type'], $upload['error'] );
339
            }
348
            }
340
            header( 'Vary: Accept' );
349
            header( 'Vary: Accept' );
341
            if ( isset( $_SERVER['HTTP_ACCEPT'] ) && ( strpos( $_SERVER['HTTP_ACCEPT'],
350
            if ( isset( $_SERVER['HTTP_ACCEPT'] ) && ( strpos( $_SERVER['HTTP_ACCEPT'],
342
                'application/json' ) !== false ) )
351
                'application/json' ) !== false ) )
343
            {
352
            {
Zeile 350... Zeile 359...
350
            echo json_encode( $info );
359
            echo json_encode( $info );
351
        }
360
        }
Zeile 352... Zeile 361...
352
 
361
 
353
        public function delete()
362
        public function delete()
354
        {
363
        {
355
            $file_name = isset( $_REQUEST['file'] ) ? basename( stripslashes
-
 
356
                ( $_REQUEST['file'] ) ) : null;
364
            $file_name = isset( $_REQUEST['file'] ) ? basename( stripslashes( $_REQUEST['file'] ) ) : null;
357
            $file_path = $this->options['upload_dir'] . $file_name;
365
            $file_path = $this->options['upload_dir'] . $file_name;
358
            $success = is_file( $file_path ) && $file_name[0] !== '.' &&
-
 
359
                unlink( $file_path );
366
            $success = is_file( $file_path ) && $file_name[0] !== '.' && unlink( $file_path );
360
            if ( $success )
367
            if ( $success )
361
            {
368
            {
362
                foreach ( $this->options['image_versions'] as $version => $options )
369
                foreach ( $this->options['image_versions'] as $version => $options )
363
                {
370
                {
Zeile 403... Zeile 410...
403
        case 'OPTIONS':
410
        case 'OPTIONS':
404
            break;
411
            break;
405
        default:
412
        default:
406
            header( 'HTTP/1.0 405 Method Not Allowed' );
413
            header( 'HTTP/1.0 405 Method Not Allowed' );
407
    }
414
    }
408
?>
-
 
409
415
?>
-
 
416