print_epub.install 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the print_epub module.
  5. *
  6. * @ingroup print
  7. */
  8. /**
  9. * Implements hook_enable().
  10. */
  11. function print_epub_enable() {
  12. // Module weight.
  13. db_update('system')
  14. ->fields(array(
  15. 'weight' => 4,
  16. ))
  17. ->condition('type', 'module')
  18. ->condition('name', 'print_epub')
  19. ->execute();
  20. }
  21. /**
  22. * Implements hook_uninstall().
  23. */
  24. function print_epub_uninstall() {
  25. variable_del('print_epub_display_sys_urllist');
  26. variable_del('print_epub_filename');
  27. variable_del('print_epub_images_via_file');
  28. variable_del('print_epub_link_text');
  29. variable_del('print_epub_link_text_enabled');
  30. variable_del('print_epub_epub_tool');
  31. variable_del('print_epub_book_link');
  32. variable_del('print_epub_link_class');
  33. variable_del('print_epub_link_pos');
  34. variable_del('print_epub_link_teaser');
  35. variable_del('print_epub_link_use_alias');
  36. variable_del('print_epub_show_link');
  37. variable_del('print_epub_sys_link_pages');
  38. variable_del('print_epub_sys_link_visibility');
  39. $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'print\_epub\_display\_%'");
  40. foreach ($settings as $variable) {
  41. variable_del($variable->name);
  42. }
  43. }
  44. /**
  45. * Implements hook_requirements().
  46. */
  47. function print_epub_requirements($phase) {
  48. $requirements = array();
  49. $t = get_t();
  50. switch ($phase) {
  51. // At runtime, make sure that a EPUB generation tool is selected.
  52. case 'runtime':
  53. $print_epub_epub_tool = variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
  54. if (empty($print_epub_epub_tool)) {
  55. $requirements['print_epub_tool'] = array(
  56. 'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
  57. 'value' => $t('No EPUB tool selected'),
  58. 'description' => $t('Please configure it in the !url.', array('!url' => l($t('EPUB settings page'), 'admin/config/user-interface/print/epub'))),
  59. 'severity' => REQUIREMENT_ERROR,
  60. );
  61. }
  62. else {
  63. $tool = explode('|', $print_epub_epub_tool);
  64. if (!is_file($tool[1]) || !is_readable($tool[1])) {
  65. $requirements['print_epub_tool'] = array(
  66. 'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
  67. 'value' => $t('File not found'),
  68. 'description' => $t('The currently selected EPUB generation library (%file) is no longer accessible.', array('%file' => $tool[1])),
  69. 'severity' => REQUIREMENT_ERROR,
  70. );
  71. }
  72. }
  73. break;
  74. }
  75. return $requirements;
  76. }
  77. /**
  78. * Implements hook_schema().
  79. */
  80. function print_epub_schema() {
  81. $schema['print_epub_node_conf'] = array(
  82. 'description' => 'EPUB version node-specific configuration settings',
  83. 'fields' => array(
  84. 'nid' => array(
  85. 'type' => 'int',
  86. 'unsigned' => TRUE,
  87. 'not null' => TRUE,
  88. 'description' => 'The {node}.nid of the node.',
  89. ),
  90. 'link' => array(
  91. 'type' => 'int',
  92. 'unsigned' => TRUE,
  93. 'not null' => TRUE,
  94. 'default' => 1,
  95. 'size' => 'tiny',
  96. 'description' => 'Show link',
  97. ),
  98. 'comments' => array(
  99. 'type' => 'int',
  100. 'unsigned' => TRUE,
  101. 'not null' => TRUE,
  102. 'default' => 1,
  103. 'size' => 'tiny',
  104. 'description' => 'Show link in individual comments',
  105. ),
  106. 'url_list' => array(
  107. 'type' => 'int',
  108. 'unsigned' => TRUE,
  109. 'not null' => TRUE,
  110. 'default' => 1,
  111. 'size' => 'tiny',
  112. 'description' => 'Show Printer-friendly URLs list',
  113. ),
  114. ),
  115. 'primary key' => array('nid'),
  116. );
  117. $schema['print_epub_page_counter'] = array(
  118. 'description' => 'EPUB version access counter',
  119. 'fields' => array(
  120. 'path' => array(
  121. 'type' => 'varchar',
  122. 'length' => 255,
  123. 'not null' => TRUE,
  124. 'description' => 'Page path',
  125. ),
  126. 'totalcount' => array(
  127. 'type' => 'int',
  128. 'unsigned' => TRUE,
  129. 'not null' => TRUE,
  130. 'default' => 0,
  131. 'size' => 'big',
  132. 'description' => 'Number of page accesses',
  133. ),
  134. 'timestamp' => array(
  135. 'type' => 'int',
  136. 'unsigned' => TRUE,
  137. 'not null' => TRUE,
  138. 'default' => 0,
  139. 'description' => 'Last access',
  140. ),
  141. ),
  142. 'primary key' => array('path'),
  143. );
  144. return $schema;
  145. }
  146. /**
  147. * Remove hardcoded numeric deltas from all blocks.
  148. */
  149. function print_epub_update_7000(&$sandbox) {
  150. $renamed_deltas = array(
  151. 'print_epub' => array(
  152. '0' => 'print_epub-top',
  153. ),
  154. );
  155. update_fix_d7_block_deltas($sandbox, $renamed_deltas, array());
  156. if (variable_get('print_epub_filename', '') == '[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]') {
  157. variable_set('print_epub_filename', '[site:name] - [node:title] - [node:changed:custom:Y-m-d]');
  158. }
  159. }
  160. /**
  161. * Enable block and help area links.
  162. */
  163. function print_epub_update_7202(&$sandbox) {
  164. $link_pos = variable_get('print_epub_link_pos', drupal_json_decode('{ "link": "link", "block": "block", "help": "help" }'));
  165. $link_pos['block'] = 'block';
  166. $link_pos['help'] = 'help';
  167. variable_set('print_epub_link_pos', $link_pos);
  168. }
  169. /**
  170. * Increase size of the path field in the print_epub_page_counter table.
  171. */
  172. function print_epub_update_7203(&$sandbox) {
  173. db_drop_primary_key('print_epub_page_counter');
  174. db_change_field('print_epub_page_counter', 'path', 'path',
  175. array(
  176. 'type' => 'varchar',
  177. 'length' => 255,
  178. 'not null' => TRUE,
  179. 'description' => 'Page path',
  180. ),
  181. array('primary key' => array('path')));
  182. }