1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : admin_sync.php |
---|
4 | * Project : piwigo-videojs |
---|
5 | * Descr : Generate the admin panel |
---|
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 | // Geneate default value |
---|
31 | $sync_options = array( |
---|
32 | 'metadata' => true, |
---|
33 | 'thumb' => true, |
---|
34 | 'thumbsec' => 1, |
---|
35 | 'thumbouput' => 'jpg', |
---|
36 | 'thumboverlay' => false, |
---|
37 | 'simulate' => true, |
---|
38 | 'cat_id' => 0, |
---|
39 | 'subcats_included' => true, |
---|
40 | 'sync_gps' => true, |
---|
41 | ); |
---|
42 | |
---|
43 | if ( isset($_POST['submit']) and isset($_POST['thumbsec']) ) |
---|
44 | { |
---|
45 | // Override default value from the form |
---|
46 | $sync_options = array( |
---|
47 | 'metadata' => isset($_POST['metadata']), |
---|
48 | 'thumb' => isset($_POST['thumb']), |
---|
49 | 'thumbsec' => $_POST['thumbsec'], |
---|
50 | 'thumbouput' => $_POST['thumbouput'], |
---|
51 | 'thumboverlay' => isset($_POST['thumboverlay']), |
---|
52 | 'thumboverwrite' => isset($_POST['thumboverwrite']), |
---|
53 | 'simulate' => isset($_POST['simulate']), |
---|
54 | 'cat_id' => isset($_POST['cat_id']) ? (int)$_POST['cat_id'] : 0, |
---|
55 | 'subcats_included' => isset($_POST['subcats_included']), |
---|
56 | 'sync_gps' => true, |
---|
57 | ); |
---|
58 | |
---|
59 | // Filter on existing thumbnail |
---|
60 | $OVERWRITE = ""; |
---|
61 | if (!$sync_options['thumboverwrite']) |
---|
62 | { |
---|
63 | $OVERWRITE = " AND `representative_ext` IS NULL "; |
---|
64 | } |
---|
65 | |
---|
66 | // Filter on selected ablum |
---|
67 | if ( $sync_options['cat_id'] != 0 ) |
---|
68 | { |
---|
69 | $query=' |
---|
70 | SELECT id FROM '.CATEGORIES_TABLE.' |
---|
71 | WHERE '; |
---|
72 | if ( $sync_options['subcats_included']) |
---|
73 | $query .= 'uppercats REGEXP \'(^|,)'.$sync_options['cat_id'].'(,|$)\''; |
---|
74 | else |
---|
75 | $query .= 'id='.$sync_options['cat_id']; |
---|
76 | $cat_ids = array_from_query($query, 'id'); |
---|
77 | $query=" |
---|
78 | SELECT `id`, `file`, `path` |
---|
79 | FROM ".IMAGES_TABLE." INNER JOIN ".IMAGE_CATEGORY_TABLE." ON id=image_id |
---|
80 | WHERE ". SQL_VIDEOS ." ". $OVERWRITE ." |
---|
81 | AND category_id IN (".implode(',', $cat_ids).") |
---|
82 | GROUP BY id"; |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | $query = "SELECT `id`, `file`, `path` |
---|
87 | FROM ".IMAGES_TABLE." |
---|
88 | WHERE ". SQL_VIDEOS ." ". $OVERWRITE .";"; |
---|
89 | } |
---|
90 | |
---|
91 | // Do the work, share with batch manager |
---|
92 | require_once(dirname(__FILE__).'/../include/function_sync.php'); |
---|
93 | |
---|
94 | // Send sync result to template |
---|
95 | $template->assign('sync_errors', $errors ); |
---|
96 | $template->assign('sync_infos', $infos ); |
---|
97 | |
---|
98 | // Send result to templates |
---|
99 | $template->assign( |
---|
100 | 'update_result', |
---|
101 | array( |
---|
102 | 'NB_ELEMENTS_THUMB' => $thumbs, |
---|
103 | 'NB_ELEMENTS_EXIF' => $metadata, |
---|
104 | 'NB_ELEMENTS_CANDIDATES' => $videos, |
---|
105 | 'NB_ERRORS' => count($errors), |
---|
106 | )); |
---|
107 | } |
---|
108 | |
---|
109 | // Check the presence of the DB schema |
---|
110 | $sync_options['sync_gps'] = true; |
---|
111 | $q = 'SELECT COUNT(*) as nb FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "'.IMAGES_TABLE.'" AND COLUMN_NAME = "lat" OR COLUMN_NAME = "lon"'; |
---|
112 | $result = pwg_db_fetch_array( pwg_query($q) ); |
---|
113 | if($result['nb'] != 2) |
---|
114 | { |
---|
115 | $sync_options['sync_gps'] = false; |
---|
116 | } |
---|
117 | |
---|
118 | /* Get statistics */ |
---|
119 | // All videos with supported extensions by VideoJS |
---|
120 | $query = "SELECT COUNT(*) FROM ".IMAGES_TABLE." WHERE ".SQL_VIDEOS.";"; |
---|
121 | list($nb_videos) = pwg_db_fetch_array( pwg_query($query) ); |
---|
122 | |
---|
123 | // All videos with supported extensions by VideoJS and thumb |
---|
124 | $query = "SELECT COUNT(*) FROM ".IMAGES_TABLE." WHERE `representative_ext` IS NOT NULL AND ".SQL_VIDEOS.";"; |
---|
125 | list($nb_videos_thumb) = pwg_db_fetch_array( pwg_query($query) ); |
---|
126 | |
---|
127 | // All videos with supported extensions by VideoJS and with GPS data |
---|
128 | if ($sync_options['sync_gps']) |
---|
129 | { |
---|
130 | $query = "SELECT COUNT(*) FROM ".IMAGES_TABLE." WHERE `lat` IS NOT NULL and `lon` IS NOT NULL AND ".SQL_VIDEOS.";"; |
---|
131 | list($nb_videos_geotagged) = pwg_db_fetch_array( pwg_query($query) ); |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | $nb_videos_geotagged = 0; |
---|
136 | } |
---|
137 | |
---|
138 | $query = 'SELECT id, CONCAT(name, IF(dir IS NULL, " (V)", "") ) AS name, uppercats, global_rank FROM '.CATEGORIES_TABLE; |
---|
139 | display_select_cat_wrapper($query, |
---|
140 | array( $sync_options['cat_id'] ), |
---|
141 | 'categories', |
---|
142 | false); |
---|
143 | |
---|
144 | // Send value to templates |
---|
145 | $template->assign( |
---|
146 | array( |
---|
147 | 'SUBCATS_INCLUDED_CHECKED' => $sync_options['subcats_included'] ? 'checked="checked"' : '', |
---|
148 | 'NB_VIDEOS' => $nb_videos, |
---|
149 | 'NB_VIDEOS_GEOTAGGED' => $nb_videos_geotagged, |
---|
150 | 'NB_VIDEOS_THUMB' => $nb_videos_thumb, |
---|
151 | 'VIDEOJS_PATH' => VIDEOJS_PATH, |
---|
152 | ) |
---|
153 | ); |
---|
154 | |
---|
155 | ?> |
---|