| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- /**
- * @file
- * Ensures JavaScript callback handler has been setup properly.
- */
- /**
- * Implements hook_requirements().
- */
- function js_requirements($phase) {
- $requirements = array();
- $t = get_t();
- switch ($phase) {
- case 'runtime':
- $title = $t('JavaScript callback handler');
- // Warn about missing js.php in root directory.
- if (!file_exists('js.php')) {
- $requirements['js'] = array(
- 'title' => $title,
- 'description' => $t('In order for JavaScript callbacks to work correctly, please copy the js.php file to the root of your Drupal installation.'),
- 'severity' => REQUIREMENT_ERROR,
- 'value' => $t('Please copy js.php'),
- );
- }
- // Warn about missing RewriteRule in .htaccess.
- elseif (variable_get('js_server_software', 'apache') == 'apache' && strpos(file_get_contents('.htaccess'), 'js.php') === FALSE) {
- $requirements['js'] = array(
- 'title' => $title,
- 'description' => t('Please add the <a href="!url">RewriteRules</a> to the .htaccess file.', array('!url' => url('admin/config/system/js'))),
- 'severity' => REQUIREMENT_ERROR,
- 'value' => $t('Add Apache RewriteRule to .htaccess'),
- );
- }
- // Return positive status message.
- else {
- $requirements['js'] = array(
- 'title' => $title,
- 'description' => t('The JavaScript callback handler has been installed correctly.',
- array('%core' => 'js.php')
- ),
- 'severity' => REQUIREMENT_OK,
- 'value' => $t('Installed correctly'),
- );
- }
- }
- return $requirements;
- }
- /**
- * Implements hook_install().
- */
- function js_install() {
- // Move js.php to the root of Drupal.
- $js_dir = realpath(dirname(__FILE__));
- $destination = DRUPAL_ROOT . DIRECTORY_SEPARATOR . 'js.php';
- $source = $js_dir . DIRECTORY_SEPARATOR . 'js.php';
- if (!file_exists($destination) && file_exists($source)) {
- if (!copy($source, $destination)) {
- drupal_set_message(t('Can not copied js.php to installation root folder.'), 'error');
- }
- else {
- drupal_set_message(t('Copied js.php to installation root folder successfully.'));
- }
- }
- // Notify the user that they should add the rewrite rules to their .htaccess
- // file.
- drupal_set_message(t('To complete the installation: please add the <a href="!url">RewriteRules</a> to the .htaccess file.', array('!url' => url('admin/config/system/js'))));
- }
- /**
- * Implements hook_uninstall().
- */
- function js_uninstall() {
- // Delete js.php to remove any leftovers from the js module.
- $file = DRUPAL_ROOT . DIRECTORY_SEPARATOR . 'js.php';
- if (file_exists($file)) {
- if (!unlink($file)) {
- drupal_set_message(t('Can not delete js.php'), 'warning');
- }
- else {
- drupal_set_message(t('Deleted js.php successfully'));
- }
- }
- // If the .htaccess contains references to js.php, notify the user they should
- // clean it up.
- if (variable_get('js_server_software', 'apache') == 'apache' && strpos(file_get_contents(DRUPAL_ROOT . DIRECTORY_SEPARATOR . '.htaccess'), 'js.php') !== FALSE) {
- drupal_set_message(t('The js.php file is still referenced in the .htaccess file. Please make sure to remove the .htaccess handling for js.php for a full uninstall.'));
- }
- // Delete used variables.
- variable_del('js_server_software');
- }
|