summaryrefslogtreecommitdiffstats
path: root/print.install
blob: 79f793fc8ccc815ffcb5e709e9dab35135589a61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
// $Id$

/**
 * @file
 * Install file of the print module
 */

/**
 * Implementation of hook_install().
 */
function print_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {print_node_conf} (
        nid int(10) unsigned NOT NULL,
        link tinyint(3) unsigned NOT NULL default '1',
        comments tinyint(3) unsigned NOT NULL default '1',
        url_list tinyint(3) unsigned NOT NULL default '1',
        PRIMARY KEY  (nid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {print_page_counter} (
        path varchar(128) NOT NULL,
        totalcount bigint(20) unsigned NOT NULL default '0',
        timestamp int(10) unsigned NOT NULL default '0',
        PRIMARY KEY  (path)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {print_node_conf} (
        nid int_unsigned NOT NULL,
        link smallint NOT NULL default '1',
        comments smallint_unsigned NOT NULL default '1',
        url_list smallint_unsigned NOT NULL default '1',
        PRIMARY KEY  (nid)
      )");
      db_query("CREATE TABLE {print_page_counter} (
        path varchar(128) NOT NULL,
        totalcount bigint NOT NULL default '0',
        timestamp int_unsigned NOT NULL default '0',
        PRIMARY KEY  (path)
      )");
      break;
  }

  $t = get_t();
  drupal_set_message($t('Printer-friendly Page settings are available under !link',
    array( '!link' => l($t('Administer > Site configuration > Printer-friendly Pages'),  'admin/settings/print' ) )
  ));
}

/**
 * Implementation of hook_uninstall().
 */
function print_uninstall() {
  db_query('DROP TABLE {print_node_conf}');
  db_query('DROP TABLE {print_page_counter}');

  variable_del('print_settings');
  variable_del('print_display_comment');
  variable_del('print_sourceurl_settings');
  variable_del('print_robot_settings');
  variable_del('print_logo_url');
  variable_del('print_logo_options');
  variable_del('print_css');
  variable_del('print_urls');
  variable_del('print_comments');
  variable_del('print_newwindow');
  variable_del('print_sourceurl_enabled');
  variable_del('print_sourceurl_date');
  variable_del('print_sourceurl_forcenode');
  variable_del('print_html_show_link');
  variable_del('print_html_link_pos');
  variable_del('print_html_node_link_visibility');
  variable_del('print_html_node_link_pages');
  variable_del('print_html_link_class');
  variable_del('print_html_sys_link_visibility');
  variable_del('print_html_sys_link_pages');
  variable_del('print_html_book_link');
  variable_del('print_html_new_window');
  variable_del('print_html_sendtoprinter');
  variable_del('print_robots_noindex');
  variable_del('print_robots_nofollow');
  variable_del('print_robots_noarchive');
  variable_del('print_footer_options');
  variable_del('print_footer_user');
  variable_del('print_html_link_text');
  variable_del('print_html_link_use_alias');
  variable_del('print_text_by');
  variable_del('print_text_created');
  variable_del('print_text_links');
  variable_del('print_text_published');
  variable_del('print_text_retrieved');
  variable_del('print_text_source_url');
  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_display\_%'");
  while ($variable = db_fetch_object($settings)) {
    variable_del($variable->name);
  }
}

/**
 * Update to version 5.x-3.6
 */
function print_update_5300() {
  global $conf;

  $ret = array();
  if (isset($conf['print_settings'])) {
    $print_settings = variable_get('print_settings', '');
    $print_settings['node_link_visibility'] = 0;
    $print_settings['node_link_pages'] = '';
    $print_settings['link_class'] = 'print-page';
    $print_settings['sys_link_visibility'] = ($print_settings['show_sys_link']) ? 0 : 1;
    $print_settings['sys_link_pages'] = '';
    $oldwindow = $print_settings['newwindow'];
    $print_settings['newwindow'] = 1;
    $print_settings['new_window'] = 0;
    switch ($oldwindow) {
      case 1: // Use HTML target
        $print_settings['newwindow'] = 0;
        // no break on purpose
      case 2: // Use Javascript
        $print_settings['new_window'] = 1;
        break;
      case 3: // Use Greybox Redux
        $print_settings['link_class'] .= ' '. variable_get('greybox_class_text', 'greybox');
        break;
      case 4: // Use Thickbox
        $print_settings['link_class'] .= ' thickbox';
        break;
    }
    unset($print_settings['show_sys_link']);
    variable_set('print_settings', $print_settings);
  }
  if (isset($conf['print_robot_settings'])) {
    $robots_settings = variable_get('print_robot_settings', '');
    unset($robots_settings['nocache']);
    variable_set('print_robot_settings', $robots_settings);
  }
  return $ret;
}

/**
 * Update to version 5.x-3.7
 */
function print_update_5301() {
  global $conf;

  $ret = array();
  if (isset($conf['print_settings'])) {
    $print_settings = variable_get('print_settings', '');
    variable_set('print_logo_options', ($print_settings['logo_url'] ? 2 : 1));
    variable_set('print_logo_url', $print_settings['logo_url']);
    variable_set('print_css', $print_settings['css']);
    variable_set('print_urls', $print_settings['urls']);
    variable_set('print_comments', $print_settings['comments']);
    variable_set('print_newwindow', $print_settings['newwindow']);
    variable_set('print_html_link_pos', array('link' => ($print_settings['show_link'] ? 'link' : 0) ));
    variable_set('print_html_show_link', max(1, $print_settings['show_link']));
    variable_set('print_html_node_link_visibility', $print_settings['node_link_visibility']);
    variable_set('print_html_node_link_pages', $print_settings['node_link_pages']);
    variable_set('print_html_link_class', $print_settings['link_class']);
    variable_set('print_html_sys_link_visibility', $print_settings['sys_link_visibility']);
    variable_set('print_html_sys_link_pages', $print_settings['sys_link_pages']);
    variable_set('print_html_book_link', $print_settings['book_link']);
    variable_set('print_html_new_window', $print_settings['new_window']);
    variable_set('print_html_sendtoprinter', $print_settings['sendtoprinter']);
    variable_del('print_settings');
  }
  if (isset($conf['print_sourceurl_settings'])) {
    $print_sourceurl_settings = variable_get('print_sourceurl_settings', '');
    variable_set('print_sourceurl_enabled', $print_sourceurl_settings['enabled']);
    variable_set('print_sourceurl_date', $print_sourceurl_settings['date']);
    variable_set('print_sourceurl_forcenode', $print_sourceurl_settings['forcenode']);
    variable_del('print_sourceurl_settings');
  }
  if (isset($conf['print_robot_settings'])) {
    $print_robot_settings = variable_get('print_robot_settings', '');
    variable_set('print_robots_noindex', $print_robot_settings['noindex']);
    variable_set('print_robots_nofollow', $print_robot_settings['nofollow']);
    variable_set('print_robots_noarchive', $print_robot_settings['noarchive']);
    variable_del('print_robot_settings');
  }
  return $ret;
}

/**
 * Update to version 5.x-4.1
 */
function print_update_5302() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {print_node_conf} (
        nid int(10) unsigned NOT NULL,
        link tinyint(3) unsigned NOT NULL default '1',
        comments tinyint(3) unsigned NOT NULL default '1',
        url_list tinyint(3) unsigned NOT NULL default '1',
        PRIMARY KEY  (nid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {print_page_counter} (
        path varchar(128) NOT NULL,
        totalcount bigint(20) unsigned NOT NULL default '0',
        timestamp int(10) unsigned NOT NULL default '0',
        PRIMARY KEY  (path)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {print_node_conf} (
        nid int_unsigned NOT NULL,
        link smallint NOT NULL default '1',
        comments smallint_unsigned NOT NULL default '1',
        url_list smallint_unsigned NOT NULL default '1',
        PRIMARY KEY  (nid)
      )");
      db_query("CREATE TABLE {print_page_counter} (
        path varchar(128) NOT NULL,
        totalcount bigint NOT NULL default '0',
        timestamp int_unsigned NOT NULL default '0',
        PRIMARY KEY  (path)
      )");
      break;
  }
  return $ret;
}

/**
 * Update to version 5.x-4.2
 */
function print_update_5303() {
  // Delete custom text strings set to the default
  $ret = array();
  $vars = array(
    'print_html_link_text' => 'Printer-friendly version',
    'print_text_published' => 'Published on %site_name',
    'print_text_by' => 'By %author',
    'print_text_created' => 'Created %date',
    'print_text_source_url' => 'Source URL',
    'print_text_retrieved' => 'retrieved on %date',
    'print_text_links' => 'Links',
  );

  $t = get_t();

  foreach ($vars as $name => $default) {
    if (variable_get($name, '') == $t($default)) {
      variable_del($name);
    }
  }

  menu_rebuild();
  return $ret;
}