1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : admin_batchmanager.php |
---|
4 | * Project : piwigo-videojs |
---|
5 | * Descr : handle batch manager |
---|
6 | * |
---|
7 | * Created : 4.06.2013 |
---|
8 | * |
---|
9 | * Copyright 2012-2013 <xbgmsharp@gmail.com> |
---|
10 | * |
---|
11 | * |
---|
12 | * This program is free software: you can redistribute it and/or modify |
---|
13 | * it under the terms of the GNU General Public License as published by |
---|
14 | * the Free Software Foundation, either version 3 of the License, or |
---|
15 | * (at your option) any later version. |
---|
16 | * |
---|
17 | * This program is distributed in the hope that it will be useful, |
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | * GNU General Public License for more details. |
---|
21 | * |
---|
22 | * You should have received a copy of the GNU General Public License |
---|
23 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
24 | * |
---|
25 | ************************************************/ |
---|
26 | |
---|
27 | // Check whether we are indeed included by Piwigo. |
---|
28 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
29 | |
---|
30 | // Hook to add a new filter in the batch mode |
---|
31 | add_event_handler('get_batch_manager_prefilters', 'vjs_get_batch_manager_prefilters'); |
---|
32 | function vjs_get_batch_manager_prefilters($prefilters) |
---|
33 | { |
---|
34 | $prefilters[] = array('ID' => 'videojs0', 'NAME' => l10n('All videos')); |
---|
35 | $prefilters[] = array('ID' => 'videojs1', 'NAME' => l10n('All videos with poster')); |
---|
36 | $prefilters[] = array('ID' => 'videojs2', 'NAME' => l10n('All videos without poster')); |
---|
37 | return $prefilters; |
---|
38 | } |
---|
39 | |
---|
40 | // Hook to perfom the filter in the batch mode |
---|
41 | add_event_handler('perform_batch_manager_prefilters', 'vjs_perform_batch_manager_prefilters', 50, 2); |
---|
42 | function vjs_perform_batch_manager_prefilters($filter_sets, $prefilter) |
---|
43 | { |
---|
44 | if ($prefilter==="videojs0") |
---|
45 | $filter = ""; |
---|
46 | else if ($prefilter==="videojs1") |
---|
47 | $filter = "AND `representative_ext` IS NOT NULL"; |
---|
48 | else if ($prefilter==="videojs2") |
---|
49 | $filter = "AND `representative_ext` IS NULL"; |
---|
50 | |
---|
51 | if ( isset($filter) ) |
---|
52 | { |
---|
53 | $query = "SELECT id FROM ".IMAGES_TABLE." WHERE ".SQL_VIDEOS." ".$filter; |
---|
54 | $filter_sets[] = array_from_query($query, 'id'); |
---|
55 | } |
---|
56 | return $filter_sets; |
---|
57 | } |
---|
58 | |
---|
59 | // Hook to show action when selected |
---|
60 | add_event_handler('loc_end_element_set_global', 'vjs_loc_end_element_set_global'); |
---|
61 | function vjs_loc_end_element_set_global() |
---|
62 | { |
---|
63 | global $template; |
---|
64 | $template->append('element_set_global_plugins_actions', |
---|
65 | array('ID' => 'videojs', 'NAME'=>l10n('Videos'), 'CONTENT' => ' |
---|
66 | <ul> |
---|
67 | <li> |
---|
68 | <label><input type="checkbox" name="vjs_metadata" value="1" checked="checked" /> filesize, width, height, latitude, longitude</label> |
---|
69 | <br/><small>Will overwrite the information in the database with the metadata from the video.</small> |
---|
70 | <br/><small><strong>Support of latitude, longitude required <a href="http://piwigo.org/ext/extension_view.php?eid=701" target="_blanck">\'OpenStreetMap\'</a> or \'RV Maps & Earth\' plugin.</strong></small> |
---|
71 | </li> |
---|
72 | <li> |
---|
73 | <label><input type="checkbox" name="vjs_thumb" value="1" checked="checked" /> Create thumbnail at position in second:</label> |
---|
74 | <!-- <input type="range" name="vjs_thumbsec" value="4" min="0" max="60" step="1"/> --> |
---|
75 | <input type="text" name="vjs_thumbsec" value="4" size="2" required/> |
---|
76 | <br/><small>Create a thumbnail from the video at specify position, it will overwrite any existing poster.</small> |
---|
77 | </li> |
---|
78 | <li> |
---|
79 | <label><span class="property">Output format : </span></label> |
---|
80 | <label><input type="radio" name="vjs_thumbouput" value="jpg" checked="checked"/> JPG</label> |
---|
81 | <label><input type="radio" name="vjs_thumbouput" value="png" /> PNG</label> |
---|
82 | <br/><small>Select the output format for the thumbnail</small> |
---|
83 | </li> |
---|
84 | <li> |
---|
85 | <label><input type="checkbox" name="vjs_thumboverlay" value="1" > Add film effect</label> |
---|
86 | <br/><small>Apply an overlay on the poster creation.</small> |
---|
87 | </li> |
---|
88 | </ul> |
---|
89 | ')); |
---|
90 | } |
---|
91 | |
---|
92 | // Hook to perform the action on in global mode |
---|
93 | add_event_handler('element_set_global_action', 'vjs_element_set_global_action', 50, 2); |
---|
94 | function vjs_element_set_global_action($action, $collection) |
---|
95 | { |
---|
96 | if ($action!=="videojs") |
---|
97 | return; |
---|
98 | |
---|
99 | global $page; |
---|
100 | |
---|
101 | $query = "SELECT `id`, `file`, `path` |
---|
102 | FROM ".IMAGES_TABLE." |
---|
103 | WHERE id IN (".implode(',',$collection).")"; |
---|
104 | |
---|
105 | // Override default value from the form |
---|
106 | $sync_options = array( |
---|
107 | 'metadata' => isset($_POST['vjs_metadata']), |
---|
108 | 'thumb' => isset($_POST['vjs_thumb']), |
---|
109 | 'thumbsec' => $_POST['vjs_thumbsec'], |
---|
110 | 'thumbouput' => $_POST['vjs_thumbouput'], |
---|
111 | 'thumboverlay' => isset($_POST['vjs_thumboverlay']), |
---|
112 | 'simulate' => false, |
---|
113 | 'sync_gps' => true, |
---|
114 | ); |
---|
115 | |
---|
116 | // Do the work, share with batch manager |
---|
117 | require_once(dirname(__FILE__).'/../include/function_sync.php'); |
---|
118 | |
---|
119 | $page['errors'] = $errors; |
---|
120 | $page['infos'] = $infos; |
---|
121 | } |
---|
122 | |
---|
123 | // Hook to perform the action on in single mode |
---|
124 | add_event_handler('loc_begin_element_set_unit', 'vjs_loc_begin_element_set_unit'); |
---|
125 | function vjs_loc_begin_element_set_unit() |
---|
126 | { |
---|
127 | global $page; |
---|
128 | |
---|
129 | if (!isset($_POST['submit'])) |
---|
130 | return; |
---|
131 | |
---|
132 | $collection = explode(',', $_POST['element_ids']); |
---|
133 | foreach ($collection as $id) |
---|
134 | { |
---|
135 | if (!isset($_POST['vjs_thumbsec-'.$id])) |
---|
136 | return; |
---|
137 | |
---|
138 | // Override default value from the form |
---|
139 | $sync_options = array( |
---|
140 | 'metadata' => isset($_POST['vjs_metadata-'.$id]), |
---|
141 | 'thumb' => isset($_POST['vjs_thumb-'.$id]), |
---|
142 | 'thumbsec' => $_POST['vjs_thumbsec-'.$id], |
---|
143 | 'thumbouput' => $_POST['vjs_thumbouput-'.$id], |
---|
144 | 'thumboverlay' => isset($_POST['vjs_thumboverlay-'.$id]), |
---|
145 | 'simulate' => false, |
---|
146 | 'sync_gps' => true, |
---|
147 | ); |
---|
148 | |
---|
149 | $query = "SELECT `id`, `file`, `path` |
---|
150 | FROM ".IMAGES_TABLE." |
---|
151 | WHERE `id`='".$id."';"; |
---|
152 | |
---|
153 | // Do the work, share with batch manager |
---|
154 | include(dirname(__FILE__).'/../include/function_sync.php'); |
---|
155 | |
---|
156 | $page['errors'] = array_merge($page['errors'], $errors); |
---|
157 | $page['infos'] = array_merge($page['infos'], $infos); |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | // Hoook for batch manager in single mode |
---|
162 | add_event_handler('loc_end_element_set_unit', 'vjs_loc_end_element_set_unit'); |
---|
163 | function vjs_loc_end_element_set_unit() |
---|
164 | { |
---|
165 | global $template, $conf, $page, $is_category, $category_info; |
---|
166 | $template->set_prefilter('batch_manager_unit', 'vjs_prefilter_batch_manager_unit'); |
---|
167 | } |
---|
168 | |
---|
169 | function vjs_prefilter_batch_manager_unit($content) |
---|
170 | { |
---|
171 | $needle = '</table>'; |
---|
172 | $pos = strpos($content, $needle); |
---|
173 | if ($pos!==false) |
---|
174 | { |
---|
175 | $add = '<tr><td><strong>{\'VideoJS\'|@translate}</strong></td> |
---|
176 | <td> |
---|
177 | <label><input type="checkbox" name="vjs_metadata-{$element.id}" value="1" checked="checked" /> filesize, width, height, latitude, longitude</label> |
---|
178 | <br/><small>Will overwrite the information in the database with the metadata from the video.</small> |
---|
179 | <br/><small><strong>Support of latitude, longitude required <a href="http://piwigo.org/ext/extension_view.php?eid=701" target="_blanck">\'OpenStreetMap\'</a> or \'RV Maps & Earth\' plugin.</strong></small> |
---|
180 | <br/> |
---|
181 | <label><input type="checkbox" name="vjs_thumb-{$element.id}" value="1" checked="checked" /> Create thumbnail at position in second:</label> |
---|
182 | <!-- <input type="range" name="vjs_thumbsec" value="4" min="0" max="60" step="1"/> --> |
---|
183 | <input type="text" name="vjs_thumbsec-{$element.id}" value="4" size="2" required/> |
---|
184 | <br/><small>Create a thumbnail from the video at specify position, it will overwrite any existing poster.</small> |
---|
185 | <br/> |
---|
186 | <label><span class="property">Output format : </span></label> |
---|
187 | <label><input type="radio" name="vjs_thumbouput-{$element.id}" value="jpg" checked="checked"/> JPG</label> |
---|
188 | <label><input type="radio" name="vjs_thumbouput-{$element.id}" value="png" /> PNG</label> |
---|
189 | <br/><small>Select the output format for the thumbnail</small> |
---|
190 | <br/> |
---|
191 | <label><input type="checkbox" name="vjs_thumboverlay-{$element.id}" value="1" > Add film effect</label> |
---|
192 | <br/><small>Apply an overlay on the poster creation.</small> |
---|
193 | <br/> |
---|
194 | </td> |
---|
195 | </tr>'; |
---|
196 | $content = substr_replace($content, $add, $pos, 0); |
---|
197 | } |
---|
198 | return $content; |
---|
199 | } |
---|
200 | |
---|
201 | ?> |
---|