1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | function plugin_install() { |
---|
5 | global $prefixeTable; |
---|
6 | |
---|
7 | /* create table for recto/veros pairs | stores original verso categories */ |
---|
8 | pwg_query("CREATE TABLE IF NOT EXISTS `" . $prefixeTable . "image_verso` ( |
---|
9 | `image_id` mediumint(8) unsigned NOT NULL DEFAULT '0', |
---|
10 | `verso_id` mediumint(8) unsigned NOT NULL DEFAULT '0', |
---|
11 | `categories` varchar(128) NULL, |
---|
12 | PRIMARY KEY (`image_id`), |
---|
13 | UNIQUE KEY (`verso_id`) |
---|
14 | ) DEFAULT CHARSET=utf8;"); |
---|
15 | |
---|
16 | /* create a virtual category to store versos */ |
---|
17 | $versos_cat = create_virtual_category('Back2Front private album'); |
---|
18 | $versos_cat = array( |
---|
19 | 'id' => $versos_cat['id'], |
---|
20 | 'comment' => 'Used by Back2Front to store backsides.', |
---|
21 | 'status' => 'private', |
---|
22 | 'visible' => 'false', |
---|
23 | 'commentable' => 'false', |
---|
24 | ); |
---|
25 | mass_updates( |
---|
26 | CATEGORIES_TABLE, |
---|
27 | array( |
---|
28 | 'primary' => array('id'), |
---|
29 | 'update' => array_diff(array_keys($versos_cat), array('id')) |
---|
30 | ), |
---|
31 | array($versos_cat) |
---|
32 | ); |
---|
33 | |
---|
34 | /* config parameter */ |
---|
35 | pwg_query("INSERT INTO `" . CONFIG_TABLE . "` |
---|
36 | VALUES ('back2front', '".$versos_cat['id']."', 'Configuration for Back2Front plugin');"); |
---|
37 | } |
---|
38 | |
---|
39 | function plugin_uninstall() { |
---|
40 | global $conf, $prefixeTable; |
---|
41 | |
---|
42 | $conf['back2front'] = explode(',',$conf['back2front']); |
---|
43 | |
---|
44 | /* versos must be restored to their original categories |
---|
45 | criterias : |
---|
46 | - verso 'versos' cat only => restore verso to original categories |
---|
47 | - otherwise nothing is changed |
---|
48 | */ |
---|
49 | |
---|
50 | $query = "SELECT * FROM `" . $prefixeTable . "image_verso`;"; |
---|
51 | $images_versos = pwg_query($query); |
---|
52 | |
---|
53 | while ($item = pwg_db_fetch_assoc($images_versos)) |
---|
54 | { |
---|
55 | /* catch current verso categories */ |
---|
56 | $versos_infos = pwg_query("SELECT category_id FROM ".IMAGE_CATEGORY_TABLE." WHERE image_id = ".$item['verso_id'].";"); |
---|
57 | while (list($verso_cat) = pwg_db_fetch_row($versos_infos)) |
---|
58 | { |
---|
59 | $item['current_verso_cats'][] = $verso_cat; |
---|
60 | } |
---|
61 | |
---|
62 | /* if verso 'versos' cat only */ |
---|
63 | if (count($item['current_verso_cats']) == 1 AND $item['current_verso_cats'][0] == $conf['back2front'][0]) |
---|
64 | { |
---|
65 | foreach (explode(',',$item['categories']) as $cat) |
---|
66 | { |
---|
67 | $datas[] = array( |
---|
68 | 'image_id' => $item['verso_id'], |
---|
69 | 'category_id' => $cat, |
---|
70 | ); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE." |
---|
75 | WHERE image_id = ".$item['verso_id']." AND category_id = ".$conf['back2front'][0].";"); |
---|
76 | } |
---|
77 | |
---|
78 | if (isset($datas)) |
---|
79 | { |
---|
80 | mass_inserts( |
---|
81 | IMAGE_CATEGORY_TABLE, |
---|
82 | array('image_id', 'category_id'), |
---|
83 | $datas |
---|
84 | ); |
---|
85 | } |
---|
86 | |
---|
87 | pwg_query("DROP TABLE `" . $prefixeTable . "image_verso`;"); |
---|
88 | pwg_query("DELETE FROM `" . CONFIG_TABLE . "` WHERE param = 'back2front';"); |
---|
89 | pwg_query("DELETE FROM `" . CATEGORIES_TABLE ."`WHERE id = ".$conf['back2front'][0].";"); |
---|
90 | |
---|
91 | /* rebuild categories cache */ |
---|
92 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
93 | invalidate_user_cache(true); |
---|
94 | } |
---|
95 | ?> |
---|