jquery_colorpicker.install 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Implementation of hook_requirements()
  4. */
  5. function jquery_colorpicker_requirements($phase)
  6. {
  7. $errors = array();
  8. // Set the base path for the module, and use this to check the existence of files
  9. $path = drupal_get_path('module', 'jquery_colorpicker') . '/';
  10. if($phase == 'runtime')
  11. {
  12. // If IE6 is to be supported, check if the required files exist. First we check to see if IE6 support has been enabled
  13. if(variable_get('jquery_colorpicker_ie6_support', 0))
  14. {
  15. // Next set a new folder path where the IE6 support files will be located
  16. $path .= 'twin_helix/';
  17. // Check for the existence of the file blank.gif
  18. if(!is_file($path . 'blank.gif'))
  19. {
  20. $errors['missing_blank_gif'] = array
  21. (
  22. 'title' => t('Missing blank.gif'),
  23. 'description' => t
  24. (
  25. 'You have enabled IE6 support for Jquery Colorpicker, but are missing the required file !blank.gif. This file can be downloaded from !twin_helix and should saved in !path',
  26. array
  27. (
  28. '!twin_helix' => l
  29. (
  30. 'Twin Helix',
  31. 'http://www.twinhelix.com/css/iepngfix/',
  32. array
  33. (
  34. 'html' => TRUE,
  35. )
  36. ),
  37. '!path' => '<strong>' . $path . '</strong>',
  38. '!blank.gif' => '<strong>blank.gif</strong>',
  39. )
  40. ),
  41. 'severity' => REQUIREMENT_ERROR,
  42. );
  43. }
  44. // Next, check the file iepngfix.htc
  45. if(!is_file($path . 'iepngfix.htc'))
  46. {
  47. $errors['missing_iepngfix.htc'] = array
  48. (
  49. 'title' => t('Missing iepngfix.htc'),
  50. 'description' => t
  51. (
  52. 'You have enabled IE6 support for Jquery Colorpicker, but are missing the required file !iepngfix.htc. This file can be downloaded from !twin_helix and should saved in !path',
  53. array
  54. (
  55. '!twin_helix' => l
  56. (
  57. 'Twin Helix',
  58. 'http://www.twinhelix.com/css/iepngfix/',
  59. array
  60. (
  61. 'html' => TRUE,
  62. )
  63. ),
  64. '!path' => '<strong>' . $path . '</strong>',
  65. '!iepngfix.htc' => '<strong>iepngfix.htc</strong>',
  66. )
  67. ),
  68. 'severity' => REQUIREMENT_ERROR,
  69. );
  70. }
  71. // Finally check the existence of file iepngfix_tilebg.js
  72. if(!is_file($path . 'iepngfix_tilebg.js'))
  73. {
  74. $errors['missing_iepngfix_tilebg_js'] = array
  75. (
  76. 'title' => t('Missing iepngfix_tilebg.js'),
  77. 'description' => t
  78. (
  79. 'You have enabled IE6 support for Jquery Colorpicker, but are missing the required file !iepngfix_tilebg.js. This file can be downloaded from !twin_helix and should saved in !path',
  80. array
  81. (
  82. '!twin_helix' => l
  83. (
  84. 'Twin Helix',
  85. 'http://www.twinhelix.com/css/iepngfix/',
  86. array
  87. (
  88. 'html' => TRUE,
  89. )
  90. ),
  91. '!path' => '<strong>' . $path . '</strong>',
  92. '!iepngfix_tilebg.js' => '<strong>iepngfix_tilebg.js</strong>',
  93. )
  94. ),
  95. 'severity' => REQUIREMENT_ERROR,
  96. );
  97. }
  98. }
  99. }
  100. elseif($phase == 'install')
  101. {
  102. $path = module_exists('libraries') && in_array('colorpicker', array_keys(libraries_get_libraries()))
  103. ? libraries_get_path('colorpicker')
  104. : drupal_get_path('module', 'jquery_colorpicker') . '/colorpicker';
  105. // The first file we check is the 3rd party integration. Without this file, the module will not work. Other
  106. // files are also required, but the assumption is made that if they got this file, they will have gotten all the other files.
  107. // This is done to keep code relatively streamlined.
  108. if(!is_file($path . '/js/colorpicker.js'))
  109. {
  110. $t = get_t();
  111. $errors['jquery_colorpicker_missing_files'] = array
  112. (
  113. 'title' => $t('Required files missing'),
  114. 'description' => $t
  115. (
  116. '<h2>jQuery Colorpicker not installed</h2>You are missing the required files for the Jquery Colorpicker. Please download the colorpicker.zip from !eyecon and unzip the CSS, JS and IMAGES folders to !colorpicker_path. After doing this, confirm that the following path exists: !colorpicker_js_path.',
  117. array
  118. (
  119. '!eyecon' => l
  120. (
  121. 'http://www.eyecon.ro/colorpicker/',
  122. 'http://www.eyecon.ro/colorpicker/',
  123. array
  124. (
  125. 'external' => TRUE,
  126. )
  127. ),
  128. '!colorpicker_path' => '<strong>' . $path . '</strong>',
  129. '!colorpicker_js_path' => '<strong>' . $path . '/js/colorpicker.js</strong>',
  130. )
  131. ),
  132. 'severity' => REQUIREMENT_ERROR,
  133. );
  134. }
  135. }
  136. if(count($errors))
  137. {
  138. return $errors;
  139. }
  140. }
  141. /**
  142. * Implementation of hook_field_schema()
  143. */
  144. function jquery_colorpicker_field_schema($field)
  145. {
  146. $columns = array
  147. (
  148. 'jquery_colorpicker' => array
  149. (
  150. 'type' => 'varchar',
  151. 'length' => 6,
  152. 'not null' => FALSE,
  153. ),
  154. );
  155. return array
  156. (
  157. 'columns' => $columns,
  158. );
  159. }