You are here

print.install in Printer, email and PDF versions 5.4

Install file of the print module

File

print.install
View source
<?php

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

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

  // Module weight
  db_query("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() {
  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_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_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} (\n        nid int(10) unsigned NOT NULL,\n        link tinyint(3) unsigned NOT NULL default '1',\n        comments tinyint(3) unsigned NOT NULL default '1',\n        url_list tinyint(3) unsigned NOT NULL default '1',\n        PRIMARY KEY  (nid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {print_page_counter} (\n        path varchar(128) NOT NULL,\n        totalcount bigint(20) unsigned NOT NULL default '0',\n        timestamp int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY  (path)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {print_node_conf} (\n        nid int_unsigned NOT NULL,\n        link smallint NOT NULL default '1',\n        comments smallint_unsigned NOT NULL default '1',\n        url_list smallint_unsigned NOT NULL default '1',\n        PRIMARY KEY  (nid)\n      )");
      db_query("CREATE TABLE {print_page_counter} (\n        path varchar(128) NOT NULL,\n        totalcount bigint NOT NULL default '0',\n        timestamp int_unsigned NOT NULL default '0',\n        PRIMARY KEY  (path)\n      )");
      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;
}

/**
 * Update to version 5.x-4.10
 */
function print_update_5304() {
  $ret = array();

  // Module weight
  $ret[] = update_sql("UPDATE {system} SET weight = 0 WHERE name = 'print'");
  return $ret;
}

/**
 * Update to version 5.x-4.10
 */
function print_update_5305() {
  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 5.x-4.10
 */
function print_update_5306() {
  $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;
}

Related topics

Functions

Namesort descending Description
print_install Implementation of hook_install().
print_uninstall Implementation of hook_uninstall().
print_update_5300 Update to version 5.x-3.6
print_update_5301 Update to version 5.x-3.7
print_update_5302 Update to version 5.x-4.1
print_update_5303 Update to version 5.x-4.2
print_update_5304 Update to version 5.x-4.10
print_update_5305 Update to version 5.x-4.10
print_update_5306 Update to version 5.x-4.10