echo.install in Echo 7
Same filename and directory in other branches
Installation for Echo module.
File
echo.installView source
<?php
/**
* @file
* Installation for Echo module.
*/
/**
* Implements hook_requirements().
*
* Since the Echo module relies on a working cache implementation, check whether
* a cache_set() followed immediately by a cache_get() retrieves what it stored.
*/
function echo_requirements($phase) {
$title = 'Echo test';
$uniqid = uniqid();
$content = "<div id='{$uniqid}'>Hello, world!</div>";
$theme = variable_get('theme_default', 'bartik');
if ($phase == 'runtime') {
// Disable libxml errors.
libxml_use_internal_errors(true);
// The echo_themed_page() function should be available at this point.
$document = new DomDocument();
$document
->loadHTML(echo_themed_page($title, $content, $theme));
$xpath = new DOMXpath($document);
$pass = $xpath
->query("//div[@id='{$uniqid}']");
}
else {
$key = sha1($title . $content . $theme);
// Thirty seconds ought to be enough for anyone.
$expiration = REQUEST_TIME + max(ini_get('max_execution_time'), 30);
cache_set($key, $key, 'cache', $expiration);
sleep(1);
$cached = cache_get($key);
$pass = $cached->data === $key;
}
return array(
'echo' => array(
'title' => t('Cache system'),
'description' => t('The <a href="!echo">%echo</a> module requires a working cache system.', array(
'!echo' => 'http://drupal.org/project/echo',
'%echo' => 'Echo',
)),
'value' => $pass ? t('Working') : t('Not working'),
'severity' => $pass ? REQUIREMENT_OK : REQUIREMENT_ERROR,
),
);
}
/**
* Implements hook_install.
*/
function echo_install() {
$key = sha1(time());
variable_set('echo_key', $key);
}
/**
* Implements hook_uninstall.
*/
function echo_uninstall() {
variable_del('echo_key');
}
Functions
Name | Description |
---|---|
echo_install | Implements hook_install. |
echo_requirements | Implements hook_requirements(). |
echo_uninstall | Implements hook_uninstall. |