Fix #763810: Configure module weights to ensure that the core module is always called...
[project/print.git] / print.install
CommitLineData
9d395e7c
JV
1<?php
2// $Id$
3
4/**
95076d9f
JV
5 * @file
6 * Install file of the print module
64ad3057
JV
7 *
8 * @ingroup print
95076d9f
JV
9 */
10
11/**
623692c4
JV
12 * Implementation of hook_install().
13 */
14function print_install() {
6ea54f45
JV
15 switch ($GLOBALS['db_type']) {
16 case 'mysql':
17 case 'mysqli':
18 db_query("CREATE TABLE {print_node_conf} (
19 nid int(10) unsigned NOT NULL,
20 link tinyint(3) unsigned NOT NULL default '1',
21 comments tinyint(3) unsigned NOT NULL default '1',
22 url_list tinyint(3) unsigned NOT NULL default '1',
23 PRIMARY KEY (nid)
24 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
25 db_query("CREATE TABLE {print_page_counter} (
26 path varchar(128) NOT NULL,
27 totalcount bigint(20) unsigned NOT NULL default '0',
28 timestamp int(10) unsigned NOT NULL default '0',
29 PRIMARY KEY (path)
30 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
31 break;
32 case 'pgsql':
33 db_query("CREATE TABLE {print_node_conf} (
34 nid int_unsigned NOT NULL,
35 link smallint NOT NULL default '1',
782f98ee
JV
36 comments smallint_unsigned NOT NULL default '1',
37 url_list smallint_unsigned NOT NULL default '1',
6ea54f45
JV
38 PRIMARY KEY (nid)
39 )");
40 db_query("CREATE TABLE {print_page_counter} (
41 path varchar(128) NOT NULL,
42 totalcount bigint NOT NULL default '0',
43 timestamp int_unsigned NOT NULL default '0',
44 PRIMARY KEY (path)
45 )");
46 break;
47 }
48
dde462ce
JV
49 // Module weight
50 update_sql("UPDATE {system} SET weight = 0 WHERE name = 'print'");
51
9383096e
JV
52 $t = get_t();
53 drupal_set_message($t('Printer-friendly Page settings are available under !link',
149e2ffa 54 array( '!link' => l($t('Administer > Site configuration > Printer-friendly Pages'), 'admin/settings/print' ) )
623692c4
JV
55 ));
56}
57
58/**
9d395e7c
JV
59 * Implementation of hook_uninstall().
60 */
61function print_uninstall() {
6ea54f45
JV
62 db_query('DROP TABLE {print_node_conf}');
63 db_query('DROP TABLE {print_page_counter}');
64
9d395e7c
JV
65 variable_del('print_settings');
66 variable_del('print_display_comment');
67 variable_del('print_sourceurl_settings');
68 variable_del('print_robot_settings');
a64f645a
JV
69 variable_del('print_logo_url');
70 variable_del('print_logo_options');
71 variable_del('print_css');
72 variable_del('print_urls');
b54ad9f8 73 variable_del('print_urls_anchors');
a64f645a
JV
74 variable_del('print_comments');
75 variable_del('print_newwindow');
76 variable_del('print_sourceurl_enabled');
77 variable_del('print_sourceurl_date');
78 variable_del('print_sourceurl_forcenode');
79 variable_del('print_html_show_link');
80 variable_del('print_html_link_pos');
7b050ea9 81 variable_del('print_html_link_teaser');
a64f645a
JV
82 variable_del('print_html_node_link_visibility');
83 variable_del('print_html_node_link_pages');
84 variable_del('print_html_link_class');
85 variable_del('print_html_sys_link_visibility');
86 variable_del('print_html_sys_link_pages');
87 variable_del('print_html_book_link');
88 variable_del('print_html_new_window');
89 variable_del('print_html_sendtoprinter');
413d30ed 90 variable_del('print_html_windowclose');
a64f645a
JV
91 variable_del('print_robots_noindex');
92 variable_del('print_robots_nofollow');
93 variable_del('print_robots_noarchive');
568392c9
JV
94 variable_del('print_footer_options');
95 variable_del('print_footer_user');
96 variable_del('print_html_link_text');
97 variable_del('print_html_link_use_alias');
98 variable_del('print_text_by');
99 variable_del('print_text_created');
100 variable_del('print_text_links');
101 variable_del('print_text_published');
102 variable_del('print_text_retrieved');
103 variable_del('print_text_source_url');
950ba25d
JV
104 $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_display\_%'");
105 while ($variable = db_fetch_object($settings)) {
106 variable_del($variable->name);
107 }
9d395e7c 108}
6ee36e8a
JV
109
110/**
111 * Update to version 5.x-3.6
112 */
113function print_update_5300() {
114 global $conf;
115
116 $ret = array();
117 if (isset($conf['print_settings'])) {
118 $print_settings = variable_get('print_settings', '');
119 $print_settings['node_link_visibility'] = 0;
120 $print_settings['node_link_pages'] = '';
121 $print_settings['link_class'] = 'print-page';
122 $print_settings['sys_link_visibility'] = ($print_settings['show_sys_link']) ? 0 : 1;
123 $print_settings['sys_link_pages'] = '';
124 $oldwindow = $print_settings['newwindow'];
125 $print_settings['newwindow'] = 1;
126 $print_settings['new_window'] = 0;
127 switch ($oldwindow) {
128 case 1: // Use HTML target
129 $print_settings['newwindow'] = 0;
130 // no break on purpose
131 case 2: // Use Javascript
132 $print_settings['new_window'] = 1;
133 break;
134 case 3: // Use Greybox Redux
135 $print_settings['link_class'] .= ' '. variable_get('greybox_class_text', 'greybox');
136 break;
137 case 4: // Use Thickbox
138 $print_settings['link_class'] .= ' thickbox';
139 break;
140 }
141 unset($print_settings['show_sys_link']);
142 variable_set('print_settings', $print_settings);
143 }
144 if (isset($conf['print_robot_settings'])) {
145 $robots_settings = variable_get('print_robot_settings', '');
146 unset($robots_settings['nocache']);
147 variable_set('print_robot_settings', $robots_settings);
148 }
149 return $ret;
150}
a64f645a
JV
151
152/**
153 * Update to version 5.x-3.7
154 */
155function print_update_5301() {
156 global $conf;
157
158 $ret = array();
159 if (isset($conf['print_settings'])) {
160 $print_settings = variable_get('print_settings', '');
161 variable_set('print_logo_options', ($print_settings['logo_url'] ? 2 : 1));
162 variable_set('print_logo_url', $print_settings['logo_url']);
163 variable_set('print_css', $print_settings['css']);
164 variable_set('print_urls', $print_settings['urls']);
165 variable_set('print_comments', $print_settings['comments']);
166 variable_set('print_newwindow', $print_settings['newwindow']);
167 variable_set('print_html_link_pos', array('link' => ($print_settings['show_link'] ? 'link' : 0) ));
168 variable_set('print_html_show_link', max(1, $print_settings['show_link']));
169 variable_set('print_html_node_link_visibility', $print_settings['node_link_visibility']);
170 variable_set('print_html_node_link_pages', $print_settings['node_link_pages']);
171 variable_set('print_html_link_class', $print_settings['link_class']);
172 variable_set('print_html_sys_link_visibility', $print_settings['sys_link_visibility']);
173 variable_set('print_html_sys_link_pages', $print_settings['sys_link_pages']);
174 variable_set('print_html_book_link', $print_settings['book_link']);
175 variable_set('print_html_new_window', $print_settings['new_window']);
176 variable_set('print_html_sendtoprinter', $print_settings['sendtoprinter']);
177 variable_del('print_settings');
178 }
179 if (isset($conf['print_sourceurl_settings'])) {
180 $print_sourceurl_settings = variable_get('print_sourceurl_settings', '');
181 variable_set('print_sourceurl_enabled', $print_sourceurl_settings['enabled']);
182 variable_set('print_sourceurl_date', $print_sourceurl_settings['date']);
183 variable_set('print_sourceurl_forcenode', $print_sourceurl_settings['forcenode']);
184 variable_del('print_sourceurl_settings');
185 }
186 if (isset($conf['print_robot_settings'])) {
187 $print_robot_settings = variable_get('print_robot_settings', '');
188 variable_set('print_robots_noindex', $print_robot_settings['noindex']);
189 variable_set('print_robots_nofollow', $print_robot_settings['nofollow']);
190 variable_set('print_robots_noarchive', $print_robot_settings['noarchive']);
191 variable_del('print_robot_settings');
192 }
193 return $ret;
194}
6ea54f45
JV
195
196/**
197 * Update to version 5.x-4.1
198 */
199function print_update_5302() {
200 $ret = array();
201 switch ($GLOBALS['db_type']) {
202 case 'mysql':
203 case 'mysqli':
204 db_query("CREATE TABLE {print_node_conf} (
205 nid int(10) unsigned NOT NULL,
206 link tinyint(3) unsigned NOT NULL default '1',
207 comments tinyint(3) unsigned NOT NULL default '1',
208 url_list tinyint(3) unsigned NOT NULL default '1',
209 PRIMARY KEY (nid)
210 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
211 db_query("CREATE TABLE {print_page_counter} (
212 path varchar(128) NOT NULL,
213 totalcount bigint(20) unsigned NOT NULL default '0',
214 timestamp int(10) unsigned NOT NULL default '0',
215 PRIMARY KEY (path)
216 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
217 break;
218 case 'pgsql':
219 db_query("CREATE TABLE {print_node_conf} (
220 nid int_unsigned NOT NULL,
221 link smallint NOT NULL default '1',
782f98ee
JV
222 comments smallint_unsigned NOT NULL default '1',
223 url_list smallint_unsigned NOT NULL default '1',
6ea54f45
JV
224 PRIMARY KEY (nid)
225 )");
226 db_query("CREATE TABLE {print_page_counter} (
227 path varchar(128) NOT NULL,
228 totalcount bigint NOT NULL default '0',
229 timestamp int_unsigned NOT NULL default '0',
230 PRIMARY KEY (path)
231 )");
232 break;
233 }
234 return $ret;
235}
6f0c09ff
JV
236
237/**
238 * Update to version 5.x-4.2
239 */
240function print_update_5303() {
241 // Delete custom text strings set to the default
242 $ret = array();
243 $vars = array(
244 'print_html_link_text' => 'Printer-friendly version',
245 'print_text_published' => 'Published on %site_name',
246 'print_text_by' => 'By %author',
247 'print_text_created' => 'Created %date',
248 'print_text_source_url' => 'Source URL',
249 'print_text_retrieved' => 'retrieved on %date',
250 'print_text_links' => 'Links',
251 );
252
253 $t = get_t();
254
255 foreach ($vars as $name => $default) {
efd9c2ba 256 if (variable_get($name, '') == $t($default)) {
6f0c09ff
JV
257 variable_del($name);
258 }
259 }
260
261 menu_rebuild();
262 return $ret;
263}
dde462ce
JV
264
265/**
266 * Update to version 5.x-4.10
267 */
268function print_update_5304() {
269 $ret = array();
270 // Module weight
271 $ret[] = update_sql("UPDATE {system} SET weight = 0 WHERE name = 'print'");
272 return $ret;
273}