JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
progress on webpacking css
[wfpl-cms.git] / admin_header.php
1 <?php
2
3 require_once('inc/wfpl/upload.php');
4
5 $GLOBALS['upload_directory'] = 'image/';
6
7
8 function admin_header_get_fields() {
9     $data = array();
10
11     $data['width'] = (int) format_int_0(_REQUEST_cut('width'));
12     $data['caption'] = format_oneline(_REQUEST_cut('caption'));
13
14     if ($data['width'] < 100 || $data['width'] > WFPL_SITE_WIDTH) {
15         $data['width'] = WFPL_SITE_WIDTH;
16     }
17
18     $old = persistent_get('wfplcms_header_image');
19     if ($_FILES['image'] && $_FILES['image']['error'] == 0) {
20         if ($old) {
21             $data['version'] = 1 + $old['version'];
22         } else {
23             $data['version'] = 1;
24         }
25         $ext = generate_filename($_FILES['image']['name'], $_FILES['image']['type']);
26         $ext = substr($ext, strrpos($ext, '.') + 1);
27         $ext = strtolower($ext);
28         if ($ext !== 'jpg' && $ext !== 'jpeg') {
29             $ext = 'png';
30         }
31         $dest = "{$GLOBALS['upload_directory']}header_v{$data['version']}.$ext";
32         $image = convert_uploaded_image('image', $dest, $data['width'], 2000);
33         # FIXME use autoresizer instead, and call identify to get aspect ratio
34         $image = explode(' ', $image);
35         $data['url'] = $image[0];
36         $data['width'] = $image[1];
37         $data['height'] = $image[2];
38     } else if ($old) {
39         $data['url'] = $old['url'];
40         if ($data['width'] == $old['width']) {
41             $data['height'] = $old['height'];
42         } else {
43             $data['height'] = $old['height'] / $old['width'] * $data['width'];
44         }
45     }
46     unset($_FILES['image']);
47
48     return $data;
49 }
50
51
52 function admin_header_main() {
53     session_auth_must('admin_header');
54
55     if (isset($_REQUEST['width'])) {
56         $data = admin_header_get_fields();
57         if (isset($data['url'])) {
58             persistent_set('wfplcms_header_image', $data);
59             message('Header image updated');
60             return './admin_header';
61         }
62     } else {
63         $data = persistent_get('wfplcms_header_image');
64         if (!$data) {
65             $data = array('width' => '');
66         }
67     }
68
69     tem_set('width_max', WFPL_SITE_WIDTH);
70
71     tem_set('form', $data);
72 }