1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | function plugin_install() |
---|
6 | { |
---|
7 | global $prefixeTable, $conf; |
---|
8 | |
---|
9 | $query = 'SHOW TABLES LIKE "' . $prefixeTable . 'stuffs"'; |
---|
10 | $result = pwg_query($query); |
---|
11 | if (!mysql_fetch_row($result)) |
---|
12 | { |
---|
13 | $q = 'CREATE TABLE `' . $prefixeTable . 'stuffs` ( |
---|
14 | `id` smallint(5) NOT NULL, |
---|
15 | `pos` smallint(5) NOT NULL, |
---|
16 | `name` text NOT NULL, |
---|
17 | `descr` varchar(255) default NULL, |
---|
18 | `type` varchar(255) NOT NULL, |
---|
19 | `datas` longtext default NULL, |
---|
20 | `users` varchar(255) default NULL, |
---|
21 | `groups` varchar(255) default NULL, |
---|
22 | `show_title` enum(\'true\',\'false\') NOT NULL, |
---|
23 | `on_home` enum(\'true\',\'false\') NOT NULL, |
---|
24 | `on_cats` enum(\'true\',\'false\') NOT NULL, |
---|
25 | `on_picture` enum(\'true\',\'false\') NOT NULL, |
---|
26 | `id_line` varchar(1) default NULL, |
---|
27 | `width` smallint(9) default NULL, |
---|
28 | PRIMARY KEY (`id`), |
---|
29 | KEY `on_home` (`on_home`), |
---|
30 | KEY `on_cats` (`on_cats`), |
---|
31 | KEY `on_picture` (`on_picture`) |
---|
32 | ) DEFAULT CHARSET=utf8;'; |
---|
33 | pwg_query($q); |
---|
34 | |
---|
35 | $q = "INSERT INTO `" . $prefixeTable . "stuffs` (`id`, `pos`, `name`, `descr`, `type`, `datas`, `users`, `groups`, `show_title`, `on_home`, `on_cats`, `on_picture`, `id_line`, `width`) |
---|
36 | VALUES (0, 1, 'MainBlock', NULL, 'MainBlock', NULL, 'guest,generic,normal,admin,webmaster', NULL, 'true', 'true', 'true', 'true', NULL, NULL);"; |
---|
37 | pwg_query($q); |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | function plugin_activate() |
---|
42 | { |
---|
43 | global $prefixeTable; |
---|
44 | |
---|
45 | // Check if upgrade is needed |
---|
46 | $query = 'SHOW FULL COLUMNS FROM ' . $prefixeTable . 'stuffs;'; |
---|
47 | $result = array_from_query($query, 'Field'); |
---|
48 | if ($result[5] == 'params') |
---|
49 | { |
---|
50 | upgrade_stuffs_from_17(); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | function plugin_uninstall() |
---|
55 | { |
---|
56 | global $prefixeTable; |
---|
57 | |
---|
58 | $q = 'DROP TABLE ' . $prefixeTable . 'stuffs;'; |
---|
59 | pwg_query($q); |
---|
60 | } |
---|
61 | |
---|
62 | function upgrade_stuffs_from_17() |
---|
63 | { |
---|
64 | global $prefixeTable, $conf; |
---|
65 | |
---|
66 | $query = 'ALTER TABLE ' . $prefixeTable . 'stuffs |
---|
67 | MODIFY COLUMN name TEXT CHARACTER SET utf8 NOT NULL, |
---|
68 | MODIFY COLUMN descr VARCHAR(255) CHARACTER SET utf8 default NULL, |
---|
69 | MODIFY COLUMN type VARCHAR(255) CHARACTER SET utf8 NOT NULL, |
---|
70 | MODIFY COLUMN params VARCHAR(255) CHARACTER SET utf8 default NULL, |
---|
71 | MODIFY COLUMN datas LONGTEXT CHARACTER SET utf8 default NULL, |
---|
72 | MODIFY COLUMN users VARCHAR(255) CHARACTER SET utf8 default NULL, |
---|
73 | MODIFY COLUMN groups VARCHAR(255) CHARACTER SET utf8 default NULL, |
---|
74 | DEFAULT CHARACTER SET utf8, |
---|
75 | ADD show_title ENUM(\'true\',\'false\') NOT NULL, |
---|
76 | ADD on_home ENUM(\'true\',\'false\') NOT NULL, |
---|
77 | ADD on_cats ENUM(\'true\',\'false\') NOT NULL, |
---|
78 | ADD on_picture ENUM(\'true\',\'false\') NOT NULL, |
---|
79 | ADD id_line VARCHAR(1) default NULL, |
---|
80 | ADD width SMALLINT(9) default NULL, |
---|
81 | ADD INDEX (on_home), |
---|
82 | ADD INDEX (on_cats), |
---|
83 | ADD INDEX (on_picture);'; |
---|
84 | |
---|
85 | pwg_query($query); |
---|
86 | |
---|
87 | $query = 'SELECT id, name, type, params, datas FROM ' . $prefixeTable . 'stuffs;'; |
---|
88 | $result = pwg_query($query); |
---|
89 | |
---|
90 | $modules = array(); |
---|
91 | while ($row = mysql_fetch_assoc($result)) |
---|
92 | { |
---|
93 | if ($row['name'] != 'MainBlock') |
---|
94 | { |
---|
95 | $array = array(); |
---|
96 | foreach (explode('///', $row['name']) as $name) |
---|
97 | { |
---|
98 | $a = explode(':', $name); |
---|
99 | array_push($array, '[lang='.substr($a[0],0,2).']'.$a[1].'[/lang]'); |
---|
100 | } |
---|
101 | $new_name = implode("\r\n", $array); |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | $new_name = 'MainBlock'; |
---|
106 | } |
---|
107 | |
---|
108 | if ($row['type'] == 'LastComs') |
---|
109 | { |
---|
110 | $datas = unserialize($row['datas']); |
---|
111 | $row['datas'] = serialize(array($datas[0], $datas[1], $datas[6], $datas[2], $datas[3])); |
---|
112 | } |
---|
113 | |
---|
114 | $params = explode(',', $row['params']); |
---|
115 | $params[4] = !empty($params[4]) ? '"'.$params[4].'"' : 'NULL'; |
---|
116 | $params[5] = !empty($params[5]) ? $params[5] : 'NULL'; |
---|
117 | |
---|
118 | $query = 'UPDATE ' . $prefixeTable . 'stuffs |
---|
119 | SET |
---|
120 | name = "'. $new_name . '", |
---|
121 | datas = "' . addslashes($row['datas']) . '", |
---|
122 | show_title = "'. ($params[0] ? 'true' : 'false') .'", |
---|
123 | on_home = "'. ($params[1] ? 'true' : 'false') .'", |
---|
124 | on_cats = "'. ($params[2] ? 'true' : 'false') .'", |
---|
125 | on_picture = "'. ($params[3] ? 'true' : 'false') .'", |
---|
126 | id_line = '. $params[4] .', |
---|
127 | width = '. $params[5] .' |
---|
128 | WHERE id = '.$row['id'].';'; |
---|
129 | |
---|
130 | pwg_query($query); |
---|
131 | } |
---|
132 | |
---|
133 | $query = 'ALTER TABLE ' . $prefixeTable . 'stuffs DROP params;'; |
---|
134 | pwg_query($query); |
---|
135 | |
---|
136 | if (isset($conf['Stuffs'])) |
---|
137 | { |
---|
138 | $q = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param="Stuffs" LIMIT 1;'; |
---|
139 | pwg_query($q); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | ?> |
---|