1 | <?php |
---|
2 | if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * give a list of available banners |
---|
6 | * @param: bool delete_orphans (from unachieved cropping process) |
---|
7 | */ |
---|
8 | function list_banners($delete_orphans=false) |
---|
9 | { |
---|
10 | if (!file_exists(HEADER_MANAGER_DIR)) return array(); |
---|
11 | $dir = scandir(HEADER_MANAGER_DIR); |
---|
12 | $banners = array(); |
---|
13 | |
---|
14 | foreach ($dir as $file) |
---|
15 | { |
---|
16 | if ( in_array($file, array('.','..','index.php','.svn')) ) continue; |
---|
17 | if ( !in_array(strtolower(get_extension($file)), array('jpg','jpeg','png','gif')) ) continue; |
---|
18 | if ( strpos($file, '-thumbnail')!==false ) continue; |
---|
19 | |
---|
20 | $banner = get_banner($file); |
---|
21 | |
---|
22 | if ( $delete_orphans and !file_exists($banner['THUMB']) ) |
---|
23 | { |
---|
24 | @unlink($banner['PATH']); |
---|
25 | } |
---|
26 | else |
---|
27 | { |
---|
28 | $banners[ get_filename_wo_extension($banner['NAME']) ] = $banner; |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | return $banners; |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * get full size and thumbnail urls and size for a banner |
---|
37 | * @param: string filename |
---|
38 | */ |
---|
39 | function get_banner($file) |
---|
40 | { |
---|
41 | if (file_exists(HEADER_MANAGER_DIR . $file)) |
---|
42 | { |
---|
43 | return array( |
---|
44 | 'NAME' => $file, |
---|
45 | 'PATH' => get_root_url().HEADER_MANAGER_DIR . $file, |
---|
46 | 'THUMB' => get_root_url().HEADER_MANAGER_DIR . get_filename_wo_extension($file) . '-thumbnail.'. get_extension($file), |
---|
47 | 'SIZE' => getimagesize(HEADER_MANAGER_DIR . $file), |
---|
48 | ); |
---|
49 | } |
---|
50 | else |
---|
51 | { |
---|
52 | return false; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * get properties of the jCrop window |
---|
58 | * @param: array picture(width, height[, coi]) |
---|
59 | * @return: array crop(display_width, display_height, l, r, t, b, coi(x, y)) |
---|
60 | */ |
---|
61 | function hm_get_crop_display($picture) |
---|
62 | { |
---|
63 | global $conf; |
---|
64 | |
---|
65 | // find coi |
---|
66 | if (!empty($picture['coi'])) |
---|
67 | { |
---|
68 | $picture['coi'] = array( |
---|
69 | 'l' => char_to_fraction($picture['coi'][0])*$picture['width'], |
---|
70 | 't' => char_to_fraction($picture['coi'][1])*$picture['height'], |
---|
71 | 'r' => char_to_fraction($picture['coi'][2])*$picture['width'], |
---|
72 | 'b' => char_to_fraction($picture['coi'][3])*$picture['height'], |
---|
73 | ); |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | $picture['coi'] = array( |
---|
78 | 'l' => 0, |
---|
79 | 't' => 0, |
---|
80 | 'r' => $picture['width'], |
---|
81 | 'b' => $picture['height'], |
---|
82 | ); |
---|
83 | } |
---|
84 | $crop['coi']['x'] = ($picture['coi']['r']+$picture['coi']['l'])/2; |
---|
85 | $crop['coi']['y'] = ($picture['coi']['b']+$picture['coi']['t'])/2; |
---|
86 | |
---|
87 | // define default crop frame |
---|
88 | if ($picture['width'] > $conf['header_manager']['width']) |
---|
89 | { |
---|
90 | $crop['display_width'] = $conf['header_manager']['width']; |
---|
91 | $crop['display_height'] = round($picture['height']*$crop['display_width']/$picture['width']); |
---|
92 | |
---|
93 | $crop['coi']['x'] = round($crop['coi']['x']*$crop['display_width']/$picture['width']); |
---|
94 | $crop['coi']['y'] = round($crop['coi']['y']*$crop['display_height']/$picture['height']); |
---|
95 | |
---|
96 | $crop['l'] = 0; |
---|
97 | $crop['r'] = $conf['header_manager']['width']; |
---|
98 | $crop['t'] = max(0, $crop['coi']['y']-$conf['header_manager']['height']/2); |
---|
99 | $crop['b'] = min($crop['display_height'], $crop['t']+$conf['header_manager']['height']); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | $crop['display_width'] = $picture['width']; |
---|
104 | $crop['display_height'] = $picture['height']; |
---|
105 | |
---|
106 | $adapted_crop_height = round($conf['header_manager']['height']*$picture['width']/$conf['header_manager']['width']); |
---|
107 | |
---|
108 | $crop['l'] = 0; |
---|
109 | $crop['r'] = $picture['width']; |
---|
110 | $crop['t'] = max(0, $crop['coi']['y']-$adapted_crop_height/2); |
---|
111 | $crop['b'] = min($crop['display_height'], $crop['t']+$adapted_crop_height); |
---|
112 | } |
---|
113 | |
---|
114 | return $crop; |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * clean table when categroies are delete |
---|
119 | */ |
---|
120 | function header_manager_delete_categories($ids) |
---|
121 | { |
---|
122 | $query = ' |
---|
123 | DELETE FROM '.HEADER_MANAGER_TABLE.' |
---|
124 | WHERE category_id IN('.implode(',', $ids).') |
---|
125 | ;'; |
---|
126 | pwg_query($query); |
---|
127 | } |
---|
128 | |
---|
129 | ?> |
---|