1 | <?php |
---|
2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | class Back2Front_maintain extends PluginMaintain |
---|
5 | { |
---|
6 | private $table; |
---|
7 | |
---|
8 | private $default_conf = array( |
---|
9 | 'versos_cat' => 0, |
---|
10 | 'switch_mode' => 'click', |
---|
11 | 'transition' => 'none', |
---|
12 | 'position' => 'top', |
---|
13 | 'link_name' => array('default'=>null), |
---|
14 | 'show_thumbnail' => true, |
---|
15 | ); |
---|
16 | |
---|
17 | function __construct($id) |
---|
18 | { |
---|
19 | global $prefixeTable; |
---|
20 | |
---|
21 | parent::__construct($id); |
---|
22 | $this->table = $prefixeTable . 'image_verso'; |
---|
23 | } |
---|
24 | |
---|
25 | function install($plugin_version, &$errors=array()) |
---|
26 | { |
---|
27 | global $conf; |
---|
28 | |
---|
29 | if (empty($conf['back2front'])) |
---|
30 | { |
---|
31 | // create virtual private cat for storage |
---|
32 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.inc.php'); |
---|
33 | $cat = create_virtual_category('Back2Front private album'); |
---|
34 | $info = array( |
---|
35 | 'comment' => 'Used by Back2Front to store backsides.', |
---|
36 | 'status' => 'private', |
---|
37 | 'visible' => 'false', |
---|
38 | 'commentable' => 'false', |
---|
39 | ); |
---|
40 | |
---|
41 | single_update( |
---|
42 | CATEGORIES_TABLE, |
---|
43 | $info, |
---|
44 | array('id' => $cat['id']) |
---|
45 | ); |
---|
46 | |
---|
47 | $this->default_conf['versos_cat'] = $cat['id']; |
---|
48 | |
---|
49 | conf_update_param('back2front', $this->default_conf, true); |
---|
50 | } |
---|
51 | |
---|
52 | // create tables |
---|
53 | $query = ' |
---|
54 | CREATE TABLE IF NOT EXISTS `' . $this->table . '` ( |
---|
55 | `image_id` mediumint(8) unsigned NOT NULL DEFAULT 0, |
---|
56 | `verso_id` mediumint(8) unsigned NOT NULL DEFAULT 0, |
---|
57 | `categories` varchar(128) NULL, |
---|
58 | PRIMARY KEY (`image_id`), |
---|
59 | UNIQUE KEY (`verso_id`) |
---|
60 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
---|
61 | ;'; |
---|
62 | pwg_query($query); |
---|
63 | } |
---|
64 | |
---|
65 | function update($old_version, $new_version, &$errors=array()) |
---|
66 | { |
---|
67 | $this->install($new_version, $errors); |
---|
68 | } |
---|
69 | |
---|
70 | function uninstall() |
---|
71 | { |
---|
72 | global $conf; |
---|
73 | |
---|
74 | include_once(PHPWG_PLUGINS_PATH . 'Back2Front/include/functions.inc.php'); |
---|
75 | $conf['back2front'] = safe_unserialize($conf['back2front']); |
---|
76 | |
---|
77 | $images_versos = pwg_query("SELECT * FROM `" . $this->table . "`;"); |
---|
78 | while ($item = pwg_db_fetch_assoc($images_versos)) |
---|
79 | { |
---|
80 | back2front_restaure_categories($item); |
---|
81 | } |
---|
82 | |
---|
83 | pwg_query("DROP TABLE `" . $this->table . "`;"); |
---|
84 | pwg_query("DELETE FROM `" . CATEGORIES_TABLE ."`WHERE id = ".$conf['back2front']['versos_cat'].";"); |
---|
85 | |
---|
86 | // rebuild categories cache |
---|
87 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
88 | invalidate_user_cache(true); |
---|
89 | |
---|
90 | conf_delete_param('back2front'); |
---|
91 | } |
---|
92 | } |
---|