js.install in JS Callback Handler 6
Same filename and directory in other branches
Ensures JavaScript callback handler has been setup properly.
File
js.installView source
<?php
/**
* @file
* Ensures JavaScript callback handler has been setup properly.
*/
/**
* Implementation of hook_requirements().
*/
function js_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
case 'install':
case 'runtime':
$path = drupal_get_path('module', 'js') . '/js.php';
$title = $t('JavaScript callback handler');
// Warn about missing js.php in root directoy.
if (file_exists($path) && file_exists('js.php') && md5_file($path) != md5_file('js.php')) {
$requirements['js'] = array(
'title' => $title,
'description' => $t('In order for JavaScript callbacks to work correctly, please copy the file at %mod and use it to replace %core.', array(
'%core' => 'js.php',
'%mod' => $path,
)),
'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
'value' => $t('Please copy js.php'),
);
}
else {
if (!file_exists($path)) {
$requirements['js'] = array(
'title' => $title,
'description' => $t('You probably <em>moved</em> rather than <em>copied</em> the js.php file from %mod to %core. You should leave a copy of this file in the module directory so that you will not lose this file when you upgrade to another revision of Drupal.', array(
'%core' => 'js.php',
'%mod' => $path,
)),
'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
'value' => $t('js.php no longer exists in the js directory'),
);
}
else {
if ($phase == 'runtime') {
// Warn about disabled clean URLs.
if (!variable_get('clean_url', FALSE)) {
$requirements['js'] = array(
'title' => $title,
'description' => $t('In order for JavaScript callbacks to work correctly, please <a href="!clean-urls">enable clean URLs</a>', array(
'!clean-urls' => url('admin/settings/clean-urls'),
)),
'severity' => REQUIREMENT_ERROR,
'value' => $t('Enable clean URLs'),
);
}
else {
if (strpos(file_get_contents('.htaccess'), 'js.php') === FALSE) {
$requirements['js'] = array(
'title' => $title,
'description' => $t('In order for increasing performance of JavaScript callbacks, please add the required <a href="!readme">RewriteRule</a>', array(
'!readme' => url(drupal_get_path('module', 'js') . '/README.txt'),
)),
'severity' => REQUIREMENT_WARNING,
'value' => $t('Add Apache RewriteRule to .htaccess'),
);
}
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;
}
Functions
Name | Description |
---|---|
js_requirements | Implementation of hook_requirements(). |