1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | This program is free software; you can redistribute it and/or modify | |
---|
8 | // | it under the terms of the GNU General Public License as published by | |
---|
9 | // | the Free Software Foundation | |
---|
10 | // | | |
---|
11 | // | This program is distributed in the hope that it will be useful, but | |
---|
12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
14 | // | General Public License for more details. | |
---|
15 | // | | |
---|
16 | // | You should have received a copy of the GNU General Public License | |
---|
17 | // | along with this program; if not, write to the Free Software | |
---|
18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
19 | // | USA. | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
23 | { |
---|
24 | die ("Hacking attempt!"); |
---|
25 | } |
---|
26 | |
---|
27 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
28 | include_once(M2P_PATH.'include/functions.inc.php'); |
---|
29 | |
---|
30 | $admin_base_url = get_root_url().'admin.php?page=plugin-menalto2piwigo'; |
---|
31 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
32 | |
---|
33 | // +-----------------------------------------------------------------------+ |
---|
34 | // | Check Access and exit when user status is not ok | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | |
---|
37 | check_status(ACCESS_WEBMASTER); |
---|
38 | |
---|
39 | // +-----------------------------------------------------------------------+ |
---|
40 | // | load database config for Menalto | |
---|
41 | // +-----------------------------------------------------------------------+ |
---|
42 | |
---|
43 | if (isset($conf['menalto2piwigo'])) |
---|
44 | { |
---|
45 | $conf['menalto2piwigo'] = unserialize($conf['menalto2piwigo']); |
---|
46 | } |
---|
47 | else |
---|
48 | { |
---|
49 | $conf['menalto2piwigo'] = array( |
---|
50 | 'db_host' => $conf['db_host'], |
---|
51 | 'db_user' => $conf['db_user'], |
---|
52 | 'db_password' => $conf['db_password'], |
---|
53 | 'db_name' => '', |
---|
54 | 'prefix_table' => 'g2_', |
---|
55 | 'prefix_column' => 'g_', |
---|
56 | ); |
---|
57 | } |
---|
58 | |
---|
59 | // +-----------------------------------------------------------------------+ |
---|
60 | // | import data from Menalto | |
---|
61 | // +-----------------------------------------------------------------------+ |
---|
62 | |
---|
63 | if (isset($_POST['submit'])) |
---|
64 | { |
---|
65 | foreach (array_keys($conf['menalto2piwigo']) as $key) |
---|
66 | { |
---|
67 | $conf['menalto2piwigo'][$key] = $_POST[$key]; |
---|
68 | } |
---|
69 | |
---|
70 | conf_update_param('menalto2piwigo', serialize($conf['menalto2piwigo'])); |
---|
71 | |
---|
72 | $pt = $conf['menalto2piwigo']['prefix_table']; |
---|
73 | $pc = $conf['menalto2piwigo']['prefix_column']; |
---|
74 | |
---|
75 | // build an associative array like |
---|
76 | // |
---|
77 | // $piwigo_paths = array( |
---|
78 | // [album 1] => c2 |
---|
79 | // [album 1/20081220_173438-014.jpg] => i1 |
---|
80 | // [album 1/20081220_173603-017.jpg] => i2 |
---|
81 | // [album 1/sub-album 1.1] => c3 |
---|
82 | // [album 1/sub-album 1.1/1.1.1] => c4 |
---|
83 | // [album 1/sub-album 1_2] => c5 |
---|
84 | // [album 2] => c1 |
---|
85 | // [album 2/20091011_164753-127.jpg] => i3 |
---|
86 | // [album 2/20091102_172719-190.jpg] => i4 |
---|
87 | // ); |
---|
88 | // |
---|
89 | // cN for categories, iN for images |
---|
90 | $piwigo_paths = array(); |
---|
91 | |
---|
92 | $query = ' |
---|
93 | SELECT |
---|
94 | id, |
---|
95 | REPLACE(path, "./galleries/", "") AS filepath |
---|
96 | FROM '.IMAGES_TABLE.' |
---|
97 | WHERE path like "./galleries/%" |
---|
98 | ;'; |
---|
99 | $result = pwg_query($query); |
---|
100 | while ($row = pwg_db_fetch_assoc($result)) |
---|
101 | { |
---|
102 | $piwigo_paths[$row['filepath']] = 'i'.$row['id']; |
---|
103 | } |
---|
104 | |
---|
105 | $query = ' |
---|
106 | SELECT |
---|
107 | id, |
---|
108 | dir, |
---|
109 | uppercats |
---|
110 | FROM '.CATEGORIES_TABLE.' |
---|
111 | WHERE site_id = 1 |
---|
112 | ;'; |
---|
113 | $albums = query2array($query, 'id'); |
---|
114 | |
---|
115 | foreach ($albums as $id => $album) |
---|
116 | { |
---|
117 | $path_tokens = array(); |
---|
118 | foreach (explode(',', $album['uppercats']) as $uppercat_id) |
---|
119 | { |
---|
120 | $path_tokens[] = $albums[$uppercat_id]['dir']; |
---|
121 | } |
---|
122 | |
---|
123 | $albums[$id]['path'] = implode('/', $path_tokens); |
---|
124 | } |
---|
125 | |
---|
126 | foreach ($albums as $id => $album) |
---|
127 | { |
---|
128 | $piwigo_paths[$album['path']] = 'c'.$id; |
---|
129 | } |
---|
130 | unset($albums); |
---|
131 | |
---|
132 | ksort($piwigo_paths); |
---|
133 | // echo '<pre>'; print_r($piwigo_paths); echo '</pre>'; |
---|
134 | |
---|
135 | m2p_db_connect(); |
---|
136 | |
---|
137 | // Gallery2 or Gallery3? |
---|
138 | $menalto_tables = m2p_get_tables($pt); |
---|
139 | |
---|
140 | if (in_array($pt.'FileSystemEntity', $menalto_tables)) |
---|
141 | { |
---|
142 | // Gallery version 2 |
---|
143 | |
---|
144 | // Gallery2 parent Ids (root is always 7!) |
---|
145 | $ids = array(7,0,0,0,0,0); |
---|
146 | // Piwigo uppercats |
---|
147 | $uct = array('NULL',0,0,0,0,0); |
---|
148 | $ranks = array(); |
---|
149 | |
---|
150 | // the following algorithm is a conversion into PHP of the Perl script |
---|
151 | // convertcomments.pl by dschwen, see https://github.com/dschwen/g2piwigo |
---|
152 | // |
---|
153 | // this plugin just makes things "simpler" for users but the hard part |
---|
154 | // comes from dschwen, he deserves all credits! |
---|
155 | |
---|
156 | foreach ($piwigo_paths as $dir => $piwigo_id) |
---|
157 | { |
---|
158 | $path = explode('/', $dir); |
---|
159 | $basename = $path[count($path)-1]; |
---|
160 | $level = count($path); |
---|
161 | |
---|
162 | $parentId = $ids[$level-1]; |
---|
163 | |
---|
164 | // get id and title/summary/description of tail element in path |
---|
165 | $query = " |
---|
166 | SELECT |
---|
167 | f.".$pc."id, |
---|
168 | i.".$pc."title, |
---|
169 | i.".$pc."summary, |
---|
170 | i.".$pc."description, |
---|
171 | i.".$pc."canContainChildren, |
---|
172 | a.".$pc."orderWeight, |
---|
173 | a.".$pc."viewCount, |
---|
174 | FROM_UNIXTIME(e.".$pc."creationTimestamp) |
---|
175 | FROM ".$pt."Item i |
---|
176 | JOIN ".$pt."FileSystemEntity f ON i.".$pc."id = f.".$pc."id |
---|
177 | JOIN ".$pt."ChildEntity c ON f.".$pc."id = c.".$pc."id |
---|
178 | JOIN ".$pt."ItemAttributesMap a ON i.".$pc."id = a.".$pc."itemId |
---|
179 | JOIN ".$pt."Entity e ON e.".$pc."id = i.".$pc."id |
---|
180 | WHERE c.".$pc."parentId = ".$parentId." |
---|
181 | AND f.".$pc."pathComponent='".$basename."' |
---|
182 | ;"; |
---|
183 | // echo '<pre>'.$query."</pre>"; |
---|
184 | $row = pwg_db_fetch_row(pwg_query($query)); |
---|
185 | |
---|
186 | // print "$row[4] - $parentId -> $row[0] : $row[1] $row[2] $row[3]\n"; |
---|
187 | $title = m2p_remove_bbcode($row[1]); |
---|
188 | $summary = m2p_remove_bbcode($row[2]); |
---|
189 | $description = m2p_remove_bbcode($row[3]); |
---|
190 | $weight = $row[5]; |
---|
191 | $views = $row[6]; |
---|
192 | $date_available = $row[7]; |
---|
193 | $ids[$level] = $row[0]; |
---|
194 | $pid[$row[0]] = $dir; |
---|
195 | |
---|
196 | if ($row[4] == 0) |
---|
197 | { |
---|
198 | // Menalto says it's an image |
---|
199 | |
---|
200 | if (strpos($piwigo_id, 'i') === false) |
---|
201 | { |
---|
202 | echo 'Error, '.$piwig_id.' is not an image and Menalto says it is an image'; |
---|
203 | } |
---|
204 | |
---|
205 | $comment = ""; |
---|
206 | if ( $summary != "" and $description != "" ) |
---|
207 | { |
---|
208 | $comment = "<b>$summary</b> - $description"; |
---|
209 | } |
---|
210 | else |
---|
211 | { |
---|
212 | if ($summary != "") |
---|
213 | { |
---|
214 | $comment = $summary; |
---|
215 | } |
---|
216 | else |
---|
217 | { |
---|
218 | $comment = $description; |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | $image_id = substr($piwigo_id, 1); |
---|
223 | |
---|
224 | $image_updates[] = array( |
---|
225 | 'id' => $image_id, |
---|
226 | 'name' => pwg_db_real_escape_string($title), |
---|
227 | 'comment' => pwg_db_real_escape_string($comment), |
---|
228 | 'date_available' => $date_available, |
---|
229 | ); |
---|
230 | |
---|
231 | // build a map from gallery2 ids to piwigo image ids |
---|
232 | $iid[$row[0]] = $image_id; |
---|
233 | } |
---|
234 | else |
---|
235 | { |
---|
236 | // album (folder) |
---|
237 | if (strpos($piwigo_id, 'c') === false) |
---|
238 | { |
---|
239 | echo 'Error, '.$piwig_id.' is not an album and Menalto says it is an album'; |
---|
240 | } |
---|
241 | |
---|
242 | $comment = ""; |
---|
243 | if ( $summary != "" and $description != "" ) |
---|
244 | { |
---|
245 | $comment = "$summary <!--complete--> $description"; |
---|
246 | } |
---|
247 | else |
---|
248 | { |
---|
249 | if ($summary != "") |
---|
250 | { |
---|
251 | $comment = $summary; |
---|
252 | } |
---|
253 | else |
---|
254 | { |
---|
255 | $comment = "<!--complete-->$description"; |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | // get piwigo category id |
---|
260 | $cat_id = substr($piwigo_id, 1); |
---|
261 | $uct[$level] = $cat_id; |
---|
262 | |
---|
263 | $cat_updates[] = array( |
---|
264 | 'id' => $cat_id, |
---|
265 | 'name' => pwg_db_real_escape_string($title), |
---|
266 | 'comment' => pwg_db_real_escape_string($comment), |
---|
267 | 'rank' => $weight, |
---|
268 | ); |
---|
269 | |
---|
270 | // get highlight picture |
---|
271 | $query = " |
---|
272 | SELECT d2.".$pc."derivativeSourceId |
---|
273 | FROM ".$pt."ChildEntity c |
---|
274 | JOIN ".$pt."Derivative d1 ON c.".$pc."id = d1.".$pc."id |
---|
275 | JOIN ".$pt."Derivative d2 ON d1.".$pc."derivativeSourceId=d2.".$pc."id |
---|
276 | WHERE c.".$pc."parentId = ".$ids[$level]; |
---|
277 | $subresult = pwg_query($query); |
---|
278 | $subrow = pwg_db_fetch_row($subresult); |
---|
279 | $hid[$cat_id] = $subrow[0]; |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | // apply highlites as representative images |
---|
284 | foreach ($hid as $cat_id => $menalto_id) |
---|
285 | { |
---|
286 | if (!empty($menalto_id)) |
---|
287 | { |
---|
288 | $album_thumbs[] = array( |
---|
289 | 'id' => $cat_id, |
---|
290 | 'representative_picture_id' => $iid[$menalto_id], |
---|
291 | ); |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | // copy comments |
---|
296 | $query = " |
---|
297 | SELECT |
---|
298 | c.".$pc."parentId AS id, |
---|
299 | t.".$pc."subject AS subject, |
---|
300 | t.".$pc."comment AS comment, |
---|
301 | t.".$pc."author AS author, |
---|
302 | FROM_UNIXTIME(t.".$pc."date) AS date |
---|
303 | FROM ".$pt."ChildEntity c |
---|
304 | JOIN ".$pt."Comment t ON t.".$pc."id = c.".$pc."id |
---|
305 | WHERE t.".$pc."publishStatus=0 |
---|
306 | "; |
---|
307 | $result = pwg_query($query); |
---|
308 | while ($row = pwg_db_fetch_assoc($result)) |
---|
309 | { |
---|
310 | if (isset($iid[ $row['id'] ])) |
---|
311 | { |
---|
312 | $comment = $row['comment']; |
---|
313 | if (!empty($row['subject'])) |
---|
314 | { |
---|
315 | $comment = '[b]'.$row['subject'].'[/b] '.$comment; |
---|
316 | } |
---|
317 | |
---|
318 | $comment_inserts[] = array( |
---|
319 | 'image_id' => $iid[ $row['id'] ], |
---|
320 | 'date' => $row['date'], |
---|
321 | 'author' => pwg_db_real_escape_string($row['author']), |
---|
322 | 'content' => pwg_db_real_escape_string($comment), |
---|
323 | 'validated' => 'true', |
---|
324 | ); |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | m2p_db_disconnect(); |
---|
329 | |
---|
330 | // echo '<pre>'; print_r($image_updates); echo '</pre>'; |
---|
331 | // echo '<pre>'; print_r($cat_updates); echo '</pre>'; |
---|
332 | // echo '<pre>'; print_r($hid); echo '</pre>'; |
---|
333 | // echo '<pre>'; print_r($iid); echo '</pre>'; |
---|
334 | // echo '<pre>'; print_r($album_thumbs); echo '</pre>'; |
---|
335 | // echo '<pre>'; print_r($comment_inserts); echo '</pre>'; |
---|
336 | |
---|
337 | mass_updates( |
---|
338 | IMAGES_TABLE, |
---|
339 | array( |
---|
340 | 'primary' => array('id'), |
---|
341 | 'update' => array('name', 'comment', 'date_available'), |
---|
342 | ), |
---|
343 | $image_updates |
---|
344 | ); |
---|
345 | |
---|
346 | mass_updates( |
---|
347 | CATEGORIES_TABLE, |
---|
348 | array( |
---|
349 | 'primary' => array('id'), |
---|
350 | 'update' => array('name', 'comment', 'rank'), |
---|
351 | ), |
---|
352 | $cat_updates |
---|
353 | ); |
---|
354 | |
---|
355 | mass_updates( |
---|
356 | CATEGORIES_TABLE, |
---|
357 | array( |
---|
358 | 'primary' => array('id'), |
---|
359 | 'update' => array('representative_picture_id'), |
---|
360 | ), |
---|
361 | $album_thumbs |
---|
362 | ); |
---|
363 | |
---|
364 | mass_inserts( |
---|
365 | COMMENTS_TABLE, |
---|
366 | array_keys($comment_inserts[0]), |
---|
367 | $comment_inserts |
---|
368 | ); |
---|
369 | |
---|
370 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
371 | } |
---|
372 | elseif (in_array($pt.'items_tags', $menalto_tables)) |
---|
373 | { |
---|
374 | // Gallery version 3 |
---|
375 | |
---|
376 | $query = ' |
---|
377 | SELECT |
---|
378 | id, |
---|
379 | name, |
---|
380 | parent_id, |
---|
381 | relative_path_cache, |
---|
382 | title, |
---|
383 | description, |
---|
384 | type, |
---|
385 | view_count, |
---|
386 | created, |
---|
387 | weight, |
---|
388 | album_cover_item_id |
---|
389 | FROM '.$pt.'items |
---|
390 | ;'; |
---|
391 | $result = pwg_query($query); |
---|
392 | while ($row = pwg_db_fetch_assoc($result)) |
---|
393 | { |
---|
394 | if (isset($piwigo_paths[ $row['relative_path_cache'] ])) |
---|
395 | { |
---|
396 | $piwigo_id = $piwigo_paths[ $row['relative_path_cache'] ]; |
---|
397 | } |
---|
398 | else |
---|
399 | { |
---|
400 | continue; |
---|
401 | } |
---|
402 | |
---|
403 | if ('photo' == $row['type']) |
---|
404 | { |
---|
405 | $image_id = substr($piwigo_id, 1); |
---|
406 | |
---|
407 | $image_updates[] = array( |
---|
408 | 'id' => $image_id, |
---|
409 | 'name' => pwg_db_real_escape_string($row['title']), |
---|
410 | 'comment' => pwg_db_real_escape_string($row['description']), |
---|
411 | 'date_available' => date('Y-m-d H:i:s', $row['created']), |
---|
412 | 'hit' => $row['view_count'], |
---|
413 | ); |
---|
414 | |
---|
415 | // build a map from menalto ids to piwigo image ids |
---|
416 | $iid[ $row['id'] ] = $image_id; |
---|
417 | } |
---|
418 | elseif ('album' == $row['type']) |
---|
419 | { |
---|
420 | $cat_id = substr($piwigo_id, 1); |
---|
421 | |
---|
422 | $cat_updates[] = array( |
---|
423 | 'id' => $cat_id, |
---|
424 | 'name' => pwg_db_real_escape_string($row['title']), |
---|
425 | 'comment' => pwg_db_real_escape_string($row['description']), |
---|
426 | 'rank' => $row['weight'], |
---|
427 | ); |
---|
428 | |
---|
429 | $cover_id[$cat_id] = $row['album_cover_item_id']; |
---|
430 | } |
---|
431 | } |
---|
432 | |
---|
433 | // album cover id |
---|
434 | foreach ($cover_id as $cat_id => $menalto_id) |
---|
435 | { |
---|
436 | if (!empty($menalto_id) and isset($iid[$menalto_id])) |
---|
437 | { |
---|
438 | $album_thumbs[] = array( |
---|
439 | 'id' => $cat_id, |
---|
440 | 'representative_picture_id' => $iid[$menalto_id], |
---|
441 | ); |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | // user comments; |
---|
446 | $query = ' |
---|
447 | SELECT |
---|
448 | author_id, |
---|
449 | server_remote_addr, |
---|
450 | created, |
---|
451 | name, |
---|
452 | full_name, |
---|
453 | email, |
---|
454 | url, |
---|
455 | guest_email, |
---|
456 | guest_name, |
---|
457 | guest_url, |
---|
458 | item_id, |
---|
459 | state, |
---|
460 | text |
---|
461 | FROM '.$pt.'comments |
---|
462 | JOIN '.$pt.'users AS u ON author_id = u.id |
---|
463 | ;'; |
---|
464 | $result = pwg_query($query); |
---|
465 | while ($row = pwg_db_fetch_assoc($result)) |
---|
466 | { |
---|
467 | if (isset($iid[ $row['item_id'] ])) |
---|
468 | { |
---|
469 | if (!empty($row['guest_name'])) |
---|
470 | { |
---|
471 | $name = $row['guest_name']; |
---|
472 | $email = $row['guest_email']; |
---|
473 | $url = $row['guest_url']; |
---|
474 | } |
---|
475 | else |
---|
476 | { |
---|
477 | $name = $row['full_name'].' ('.$row['name'].')'; |
---|
478 | $email = $row['email']; |
---|
479 | $url = $row['url']; |
---|
480 | } |
---|
481 | |
---|
482 | if (2 == $row['author_id']) // default admin on G3 |
---|
483 | { |
---|
484 | $author_id = 1; // default admin on Piwigo |
---|
485 | } |
---|
486 | else |
---|
487 | { |
---|
488 | $author_id = 2; // guest on Piwigo |
---|
489 | } |
---|
490 | |
---|
491 | $validated = 'true'; |
---|
492 | if ('unpublished' == $row['state']) |
---|
493 | { |
---|
494 | $validated = 'false'; |
---|
495 | } |
---|
496 | |
---|
497 | $anonymous_id = implode('.', array_slice(explode('.', $row['server_remote_addr']), 0, 3)); |
---|
498 | |
---|
499 | $comment_inserts[] = array( |
---|
500 | 'image_id' => $iid[ $row['item_id'] ], |
---|
501 | 'date' => date('Y-m-d H:i:s', $row['created']), |
---|
502 | 'author' => pwg_db_real_escape_string($name), |
---|
503 | 'author_id' => $author_id, |
---|
504 | 'anonymous_id' => $anonymous_id, |
---|
505 | 'email' => pwg_db_real_escape_string($email), |
---|
506 | 'website_url' => pwg_db_real_escape_string($url), |
---|
507 | 'content' => pwg_db_real_escape_string($row['text']), |
---|
508 | 'validated' => $validated, |
---|
509 | ); |
---|
510 | } |
---|
511 | } |
---|
512 | |
---|
513 | // tags |
---|
514 | $query = ' |
---|
515 | SELECT |
---|
516 | id, |
---|
517 | name |
---|
518 | FROM '.$pt.'tags |
---|
519 | ;'; |
---|
520 | $result = pwg_query($query); |
---|
521 | while ($row = pwg_db_fetch_assoc($result)) |
---|
522 | { |
---|
523 | $tag_inserts[] = array( |
---|
524 | 'name' => pwg_db_real_escape_string($row['name']), |
---|
525 | 'url_name' => str2url($row['name']), |
---|
526 | ); |
---|
527 | |
---|
528 | $menalto_tag_ids[ $row['name'] ] = $row['id']; |
---|
529 | } |
---|
530 | |
---|
531 | $query = ' |
---|
532 | SELECT |
---|
533 | item_id, |
---|
534 | tag_id |
---|
535 | FROM '.$pt.'items_tags |
---|
536 | ;'; |
---|
537 | $result = pwg_query($query); |
---|
538 | while ($row = pwg_db_fetch_assoc($result)) |
---|
539 | { |
---|
540 | $items_tags[] = $row; |
---|
541 | } |
---|
542 | |
---|
543 | m2p_db_disconnect(); |
---|
544 | |
---|
545 | mass_updates( |
---|
546 | IMAGES_TABLE, |
---|
547 | array( |
---|
548 | 'primary' => array('id'), |
---|
549 | 'update' => array('name', 'comment', 'date_available', 'hit'), |
---|
550 | ), |
---|
551 | $image_updates |
---|
552 | ); |
---|
553 | |
---|
554 | mass_updates( |
---|
555 | CATEGORIES_TABLE, |
---|
556 | array( |
---|
557 | 'primary' => array('id'), |
---|
558 | 'update' => array('name', 'comment', 'rank'), |
---|
559 | ), |
---|
560 | $cat_updates |
---|
561 | ); |
---|
562 | |
---|
563 | mass_updates( |
---|
564 | CATEGORIES_TABLE, |
---|
565 | array( |
---|
566 | 'primary' => array('id'), |
---|
567 | 'update' => array('representative_picture_id'), |
---|
568 | ), |
---|
569 | $album_thumbs |
---|
570 | ); |
---|
571 | |
---|
572 | mass_inserts( |
---|
573 | COMMENTS_TABLE, |
---|
574 | array_keys($comment_inserts[0]), |
---|
575 | $comment_inserts |
---|
576 | ); |
---|
577 | |
---|
578 | mass_inserts( |
---|
579 | TAGS_TABLE, |
---|
580 | array_keys($tag_inserts[0]), |
---|
581 | $tag_inserts |
---|
582 | ); |
---|
583 | |
---|
584 | // we need to retrieve the mapping of piwigo tag name => piwigo tag id, |
---|
585 | // for image_tag associations |
---|
586 | $query = ' |
---|
587 | SELECT |
---|
588 | id, |
---|
589 | name |
---|
590 | FROM '.TAGS_TABLE.' |
---|
591 | ;'; |
---|
592 | $result = pwg_query($query); |
---|
593 | while ($row = pwg_db_fetch_assoc($result)) |
---|
594 | { |
---|
595 | if (isset($menalto_tag_ids[ $row['name'] ])) |
---|
596 | { |
---|
597 | $tag_id_convert[ $menalto_tag_ids[ $row['name'] ] ] = $row['id']; |
---|
598 | } |
---|
599 | } |
---|
600 | |
---|
601 | foreach ($items_tags as $item_tag) |
---|
602 | { |
---|
603 | if (isset($iid[ $item_tag['item_id'] ]) and isset($tag_id_convert[ $item_tag['tag_id'] ])) |
---|
604 | { |
---|
605 | $image_tag_inserts[] = array( |
---|
606 | 'image_id' => $iid[ $item_tag['item_id'] ], |
---|
607 | 'tag_id' => $tag_id_convert[ $item_tag['tag_id'] ], |
---|
608 | ); |
---|
609 | } |
---|
610 | } |
---|
611 | |
---|
612 | mass_inserts( |
---|
613 | IMAGE_TAG_TABLE, |
---|
614 | array_keys($image_tag_inserts[0]), |
---|
615 | $image_tag_inserts |
---|
616 | ); |
---|
617 | |
---|
618 | array_push($page['infos'], l10n('Information data registered in database')); |
---|
619 | } |
---|
620 | else |
---|
621 | { |
---|
622 | m2p_db_disconnect(); |
---|
623 | array_push($page['errors'], l10n('No Menalto tables found!')); |
---|
624 | } |
---|
625 | } |
---|
626 | |
---|
627 | |
---|
628 | // +-----------------------------------------------------------------------+ |
---|
629 | // | Template & Form | |
---|
630 | // +-----------------------------------------------------------------------+ |
---|
631 | |
---|
632 | $template->set_filenames( |
---|
633 | array( |
---|
634 | 'plugin_admin_content' => dirname(__FILE__).'/admin.tpl' |
---|
635 | ) |
---|
636 | ); |
---|
637 | |
---|
638 | $template->assign('action_url', $admin_base_url); |
---|
639 | $template->assign($conf['menalto2piwigo']); |
---|
640 | |
---|
641 | // +-----------------------------------------------------------------------+ |
---|
642 | // | Sending html | |
---|
643 | // +-----------------------------------------------------------------------+ |
---|
644 | |
---|
645 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
646 | ?> |
---|