1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Batch Manager Prefilters ratio |
---|
4 | Version: 1.0 |
---|
5 | Description: Add ration image prefilters in Batch Manager. |
---|
6 | Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=734 |
---|
7 | Author: Miklfe |
---|
8 | Author URI: http://www.piwitheme.fr |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | |
---|
13 | add_event_handler('get_batch_manager_prefilters', 'mps_add_batch_manager_prefilters'); |
---|
14 | add_event_handler('perform_batch_manager_prefilters', 'mps_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
15 | |
---|
16 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
17 | |
---|
18 | |
---|
19 | /** |
---|
20 | * add a prefilter to the Batch Downloader |
---|
21 | */ |
---|
22 | function mps_add_batch_manager_prefilters($prefilters) |
---|
23 | { |
---|
24 | array_push($prefilters, array( |
---|
25 | 'ID' => 'mps3.2', |
---|
26 | 'NAME' => l10n('ratio of the image 3/2'), |
---|
27 | )); |
---|
28 | array_push($prefilters, array( |
---|
29 | 'ID' => 'mps4.3', |
---|
30 | 'NAME' => l10n('ratio of the image 4/3'), |
---|
31 | )); |
---|
32 | array_push($prefilters, array( |
---|
33 | 'ID' => 'mps16.9', |
---|
34 | 'NAME' => l10n('ratio of the image 16/9'), |
---|
35 | )); |
---|
36 | array_push($prefilters, array( |
---|
37 | 'ID' => 'mpssquare', |
---|
38 | 'NAME' => l10n('ratio of the image square'), |
---|
39 | )); |
---|
40 | |
---|
41 | return $prefilters; |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * perform added prefilter |
---|
46 | */ |
---|
47 | function mps_perform_batch_manager_prefilters($filter_sets, $prefilter) |
---|
48 | { |
---|
49 | if ($prefilter == 'mps3.2') |
---|
50 | { |
---|
51 | $ratios = array( |
---|
52 | 1.47, |
---|
53 | 1.53, |
---|
54 | 0.63, |
---|
55 | 0.69 |
---|
56 | ); |
---|
57 | $res= filter_sets_image_format($ratios); |
---|
58 | $filter_sets[] = $res; |
---|
59 | } |
---|
60 | |
---|
61 | if ($prefilter == 'mps4.3') |
---|
62 | { |
---|
63 | $ratios = array( |
---|
64 | 1.3, |
---|
65 | 1.4, |
---|
66 | 0.72, |
---|
67 | 0.78 |
---|
68 | ); |
---|
69 | $res= filter_sets_image_format($ratios); |
---|
70 | $filter_sets[] = $res; |
---|
71 | } |
---|
72 | |
---|
73 | if ($prefilter == 'mps16.9') |
---|
74 | { |
---|
75 | $ratios = array( |
---|
76 | 1.74, |
---|
77 | 1.80, |
---|
78 | 0.53, |
---|
79 | 0.59 |
---|
80 | ); |
---|
81 | $res= filter_sets_image_format($ratios); |
---|
82 | $filter_sets[] = $res; |
---|
83 | } |
---|
84 | |
---|
85 | if ($prefilter == 'mpssquare') |
---|
86 | { |
---|
87 | $ratios = array( |
---|
88 | 0.97, |
---|
89 | 1.03, |
---|
90 | 0.97, |
---|
91 | 1.03 |
---|
92 | ); |
---|
93 | $res= filter_sets_image_format($ratios); |
---|
94 | $filter_sets[] = $res; |
---|
95 | } |
---|
96 | |
---|
97 | return $filter_sets; |
---|
98 | } |
---|
99 | |
---|
100 | function filter_sets_image_format($ratios) |
---|
101 | { |
---|
102 | $res = array(); |
---|
103 | |
---|
104 | $query = ' |
---|
105 | SELECT id, width, height |
---|
106 | FROM '.IMAGES_TABLE.' |
---|
107 | ;'; |
---|
108 | |
---|
109 | $result = pwg_query($query); |
---|
110 | if (pwg_db_num_rows($result)) |
---|
111 | { |
---|
112 | while ($row = pwg_db_fetch_assoc($result)) |
---|
113 | { |
---|
114 | if ($row['width']>0 && $row['height']>0) |
---|
115 | { |
---|
116 | $ratio = floor($row['width'] / $row['height'] * 100) / 100; |
---|
117 | |
---|
118 | if(($ratio > $ratios[0] && $ratio < $ratios[1]) || ($ratio > $ratios[2] && $ratio < $ratios[3])) |
---|
119 | { |
---|
120 | $res[] = $row['id']; |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | } |
---|
125 | return $res; |
---|
126 | } |
---|
127 | |
---|
128 | ?> |
---|