summaryrefslogtreecommitdiffstats
path: root/print.install
blob: 4122ef8831f330b89635ff4720335e658b2a54de (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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php

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

/**
 * Implementation of hook_install().
 */
function print_install() {
  drupal_install_schema('print');

  // Module weight
  update_sql("UPDATE {system} SET weight = 0 WHERE name = 'print'");

  $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() {
  drupal_uninstall_schema('print');

  variable_del('print_settings');
  variable_del('print_sourceurl_settings');
  variable_del('print_html_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_urls_anchors');
  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_link_teaser');
  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_html_windowclose');
  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_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);
  }
}

/**
 * Implementation of hook_schema().
 */
function print_schema() {
  $schema['print_node_conf'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'link' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
        'size' => 'tiny',
      ),
      'comments' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
        'size' => 'tiny',
      ),
      'url_list' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
        'size' => 'tiny',
      ),
    ),
    'primary key' => array('nid'),
  );

  $schema['print_page_counter'] = array(
    'fields' => array(
      'path' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'totalcount' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ),
      'timestamp' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('path'),
  );

  return $schema;
}


/**
 * Update to version 6.x-1.0
 */
function print_update_6000() {
  global $conf;
  $ret = array();

  $lastversion = drupal_get_installed_schema_version('print');
  if (($lastversion >= 5300) && ($lastversion < 6000)) {
    return $ret;
  }

  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_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_html_settings'])) {
    $print_html_settings = variable_get('print_html_settings', '');
    variable_set('print_html_link_pos', array('link' => ($print_html_settings['show_link'] ? 'link' : 0) ));
    variable_set('print_html_show_link', max(1, $print_html_settings['show_link']));
    variable_set('print_html_node_link_visibility', $print_html_settings['node_link_visibility']);
    variable_set('print_html_node_link_pages', $print_html_settings['node_link_pages']);
    variable_set('print_html_link_class', $print_html_settings['link_class']);
    variable_set('print_html_sys_link_visibility', $print_html_settings['sys_link_visibility']);
    variable_set('print_html_sys_link_pages', $print_html_settings['sys_link_pages']);
    variable_set('print_html_book_link', $print_html_settings['book_link']);
    variable_set('print_html_new_window', $print_html_settings['new_window']);
    variable_set('print_html_sendtoprinter', $print_html_settings['sendtoprinter']);
    variable_del('print_html_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 6.x-1.0
 */
function print_update_6001() {
  $ret = array();
  $lastversion = drupal_get_installed_schema_version('print');
  if (($lastversion >= 5301) && ($lastversion < 6000)) {
    return $ret;
  }

  menu_rebuild();
  return $ret;
}

/**
 * Update to version 6.x-1.1
 */
function print_update_6002() {
  $ret = array();
  $lastversion = drupal_get_installed_schema_version('print');
  if (($lastversion >= 5302) && ($lastversion < 6000)) {
    return $ret;
  }

  $schema['print_node_conf'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'link' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => '1',
        'size' => 'tiny',
      ),
      'comments' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => '1',
        'size' => 'tiny',
      ),
      'url_list' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => '1',
        'size' => 'tiny',
      ),
    ),
    'primary key' => array('nid'),
  );

  $schema['print_page_counter'] = array(
    'fields' => array(
      'path' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'totalcount' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'big',
      ),
      'timestamp' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('path'),
  );

  db_create_table($ret, 'print_node_conf', $schema['print_node_conf']);
  db_create_table($ret, 'print_page_counter', $schema['print_page_counter']);
  return $ret;
}

/**
 * Update to version 6.x-1.2
 */
function print_update_6003() {
  $ret = array();

  $lastversion = drupal_get_installed_schema_version('print');
  if (($lastversion >= 5303) && ($lastversion < 6000)) {
    return $ret;
  }

  // Delete custom text strings set to the default
  $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;
}

/**
 * Update to version 6.x-1.11
 */
function print_update_6004() {
  $ret = array();
  // BLOCK_CACHE_PER_PAGE -> 4
  $ret[] = update_sql("UPDATE {blocks} SET cache = 4 WHERE module = 'print' AND delta = '0'");
  // BLOCK_CACHE_GLOBAL -> 8
  $ret[] = update_sql("UPDATE {blocks} SET cache = 8 WHERE module = 'print' AND delta = '1'");
  return $ret;
}

/**
 * Update to version 6.x-1.11
 */
function print_update_6005() {
  $ret = array();
  // Module weight
  $ret[] = update_sql("UPDATE {system} SET weight = 0 WHERE name = 'print'");
  return $ret;
}

/**
 * Update to version 6.x-1.11
 */
function print_update_6006() {
  global $base_root, $base_path;

  $ret = array();
  $t = get_t();

  $print_css = variable_get('print_css', '');
  $pattern = "!(?:${base_root})?${base_path}(.*)!is";
  if (preg_match($pattern, strtr($print_css, array('%b' => base_path())), $matches)) {
    variable_set('print_css', $matches[1]);
  }
  elseif (!empty($print_css)) {
    drupal_set_message($t('Please review your custom stylesheet path in the <a href="!url">print module settings</a>, as the path must now be relative to the base path of the site.', array('!url' => url('admin/settings/print/common'))));
  }

  return $ret;
}

/**
 * Update to version 6.x-1.11
 */
function print_update_6007() {
  $ret = array();

  foreach (node_get_types() as $key => $value) {
    $print_display = variable_get('print_display_'. $value->type, 1);
    $print_display_comment = variable_get('print_display_comment_'. $value->type, 0);
    $print_display_urllist = variable_get('print_display_urllist_'. $value->type, 1);

    if (!$print_display || $print_display_comment || !$print_display_urllist) {
      $result = db_query("SELECT n.nid, link, comments, url_list from {node} AS n LEFT JOIN {print_node_conf} AS pnc ON n.nid = pnc.nid WHERE type = '%s'", $value->type);
      while ($conf = db_fetch_object($result)) {
        if (($conf->link != NULL) && ($conf->comments != NULL) && ($conf->url_list != NULL)) {
          $conf->link = !$print_display ? 0 : $conf->link;
          $conf->comments = $print_display_comment ? 1 : $conf->comments;
          $conf->url_list = !$print_display_urllist ? 0 : $conf->url_list;
          $ret[] = update_sql("UPDATE {print_node_conf} SET link = $conf->link, comments = $conf->comments, url_list = $conf->url_list WHERE nid = $conf->nid");
        }
        else {
          $ret[] = update_sql("INSERT INTO {print_node_conf} (nid, link, comments, url_list) VALUES ($conf->nid, $print_display, $print_display_comment, $print_display_urllist)");
        }
      }
    }
  }
  return $ret;
}

/**
 * Update to version 6.x-1.13
 */
function print_update_6008() {
  variable_del('print_text_by');
  variable_del('print_text_created');
}