Fix #554940: escape mysql query string
[project/print.git] / print_mail / print_mail.install
CommitLineData
7e0ab8cc
JV
1<?php
2// $Id$
3
4/**
5 * @file
6 * Install file of the print_mail module
64ad3057
JV
7 *
8 * @ingroup print
7e0ab8cc
JV
9 */
10
11/**
6ea54f45
JV
12 * Implementation of hook_install().
13 */
14function print_mail_install() {
15 switch ($GLOBALS['db_type']) {
16 case 'mysql':
17 case 'mysqli':
18 db_query("CREATE TABLE {print_mail_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_mail_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 sentcount bigint(20) unsigned NOT NULL default '0',
30 sent_timestamp int(10) unsigned NOT NULL default '0',
31 PRIMARY KEY (path)
32 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
33 break;
34 case 'pgsql':
35 db_query("CREATE TABLE {print_mail_node_conf} (
36 nid int_unsigned NOT NULL,
37 link smallint NOT NULL default '1',
782f98ee
JV
38 comments smallint_unsigned NOT NULL default '1',
39 url_list smallint_unsigned NOT NULL default '1',
6ea54f45
JV
40 PRIMARY KEY (nid)
41 )");
42 db_query("CREATE TABLE {print_mail_page_counter} (
43 path varchar(128) NOT NULL,
44 totalcount bigint NOT NULL default '0',
45 timestamp int_unsigned NOT NULL default '0',
46 sentcount bigint NOT NULL default '0',
47 sent_timestamp int_unsigned NOT NULL default '0',
48 PRIMARY KEY (path)
49 )");
50 break;
51 }
52}
53
54/**
7e0ab8cc
JV
55 * Implementation of hook_uninstall().
56 */
57function print_mail_uninstall() {
6ea54f45
JV
58 db_query('DROP TABLE {print_mail_node_conf}');
59 db_query('DROP TABLE {print_mail_page_counter}');
60
7e0ab8cc
JV
61 variable_del('print_mail_settings');
62 variable_del('print_mail_show_link');
63 variable_del('print_mail_link_pos');
64 variable_del('print_mail_node_link_visibility');
65 variable_del('print_mail_node_link_pages');
66 variable_del('print_mail_link_class');
67 variable_del('print_mail_sys_link_visibility');
68 variable_del('print_mail_sys_link_pages');
69 variable_del('print_mail_book_link');
70 variable_del('print_mail_hourly_threshold');
71 variable_del('print_mail_teaser_default');
72 variable_del('print_mail_teaser_choice');
568392c9
JV
73 variable_del('print_mail_link_text');
74 variable_del('print_mail_link_use_alias');
75 variable_del('print_mail_text_confirmation');
76 variable_del('print_mail_text_message');
77 variable_del('print_mail_text_subject');
bcfedb9d 78 variable_del('print_mail_job_queue');
7e0ab8cc
JV
79 $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_mail\_display\_%'");
80 while ($variable = db_fetch_object($settings)) {
81 variable_del($variable->name);
82 }
83}
84
85/**
6ea54f45 86 * Update to version 5.x-4.0
7e0ab8cc
JV
87 */
88function print_mail_update_6000() {
89 global $conf;
90
91 $ret = array();
92 if (isset($conf['print_mail_settings'])) {
93 $print_mail_settings = variable_get('print_mail_settings', '');
94 variable_set('print_mail_link_pos', array('link' => ($print_html_settings['show_link'] ? 'link' : 0) ));
95 variable_set('print_mail_show_link', max(1, $print_mail_settings['show_link']));
96 variable_set('print_mail_node_link_visibility', $print_mail_settings['node_link_visibility']);
97 variable_set('print_mail_node_link_pages', $print_mail_settings['node_link_pages']);
98 variable_set('print_mail_link_class', $print_mail_settings['link_class']);
99 variable_set('print_mail_sys_link_visibility', $print_mail_settings['sys_link_visibility']);
100 variable_set('print_mail_sys_link_pages', $print_mail_settings['sys_link_pages']);
101 variable_set('print_mail_book_link', $print_mail_settings['book_link']);
102 variable_set('print_mail_teaser_default', $print_mail_settings['teaser_default']);
103 variable_set('print_mail_teaser_choice', $print_mail_settings['teaser_choice']);
104 variable_del('print_mail_settings');
105 }
106 return $ret;
107}
6ea54f45
JV
108
109/**
110 * Update to version 5.x-4.1
111 */
112function print_mail_update_6001() {
113 $ret = array();
114 switch ($GLOBALS['db_type']) {
115 case 'mysql':
116 case 'mysqli':
117 db_query("CREATE TABLE {print_mail_node_conf} (
118 nid int(10) unsigned NOT NULL,
119 link tinyint(3) unsigned NOT NULL default '1',
120 comments tinyint(3) unsigned NOT NULL default '1',
121 url_list tinyint(3) unsigned NOT NULL default '1',
122 PRIMARY KEY (nid)
123 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
124 db_query("CREATE TABLE {print_mail_page_counter} (
125 path varchar(128) NOT NULL,
126 totalcount bigint(20) unsigned NOT NULL default '0',
127 timestamp int(10) unsigned NOT NULL default '0',
128 sentcount bigint(20) unsigned NOT NULL default '0',
129 sent_timestamp int(10) unsigned NOT NULL default '0',
130 PRIMARY KEY (path)
131 ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
132 break;
133 case 'pgsql':
134 db_query("CREATE TABLE {print_mail_node_conf} (
135 nid int_unsigned NOT NULL,
136 link smallint NOT NULL default '1',
782f98ee
JV
137 comments smallint_unsigned NOT NULL default '1',
138 url_list smallint_unsigned NOT NULL default '1',
6ea54f45
JV
139 PRIMARY KEY (nid)
140 )");
141 db_query("CREATE TABLE {print_mail_page_counter} (
142 path varchar(128) NOT NULL,
143 totalcount bigint NOT NULL default '0',
144 timestamp int_unsigned NOT NULL default '0',
145 sentcount bigint NOT NULL default '0',
146 sent_timestamp int_unsigned NOT NULL default '0',
147 PRIMARY KEY (path)
148 )");
149 break;
150 }
151 return $ret;
152}
6f0c09ff
JV
153
154/**
155 * Update to version 5.x-4.2
156 */
157function print_mail_update_6003() {
158 // Delete custom text strings set to the default
159 $ret = array();
160 $vars = array(
161 'print_mail_link_text' => 'Send to friend',
162 'print_mail_text_subject' => '!user has sent you a message from !site',
163 'print_mail_text_message' => 'Message from sender',
164 'print_mail_text_content' => '',
165 'print_mail_text_confirmation' => 'Thank you for spreading the word about !site.',
166 );
167
168 $t = get_t();
169
170 foreach ($vars as $name => $default) {
efd9c2ba 171 if (variable_get($name, '') == $t($default)) {
6f0c09ff
JV
172 variable_del($name);
173 }
174 }
175
176 menu_rebuild();
177 return $ret;
178}
082c691e
JV
179
180/**
181 * Update to version 5.x-4.8
182 */
183function print_mail_update_6004() {
184 // add new 'access send to friend' permission to any role which has 'access print'
185 $ret = array();
186 $dbret = db_query('SELECT * FROM {permission}');
187 while ($role = db_fetch_object($dbret)) {
188 if ((strpos($role->perm, 'access print') !== FALSE)) {
b776fe78 189 $role->perm = db_escape_string('access send to friend, '. $role->perm);
082c691e
JV
190 $ret[] = update_sql("UPDATE {permission} SET perm = '$role->perm' WHERE rid = $role->rid");
191 }
192 }
193 return $ret;
194}