echo.install 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * @file
  4. * Installation for Echo module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. *
  9. * Since the Echo module relies on a working cache implementation, check whether
  10. * a cache_set() followed immediately by a cache_get() retrieves what it stored.
  11. */
  12. function echo_requirements($phase) {
  13. $title = 'Echo test';
  14. $uniqid = uniqid();
  15. $content = "<div id='$uniqid'>Hello, world!</div>";
  16. $theme = 'bartik';
  17. if ($phase == 'runtime') {
  18. // The echo_themed_page() function should be available at this point.
  19. $document = new DomDocument();
  20. $document->loadHTML(echo_themed_page($title, $content, $theme));
  21. $xpath = new DOMXpath($document);
  22. $pass = $xpath->query("//div[@id='$uniqid']");
  23. }
  24. else {
  25. $key = sha1($title . $content . $theme);
  26. // Thirty seconds ought to be enough for anyone.
  27. $expiration = REQUEST_TIME + max(ini_get('max_execution_time'), 30);
  28. cache_set($key, $key, 'cache', $expiration);
  29. sleep(1);
  30. $cached = cache_get($key);
  31. $pass = ($cached->data === $key);
  32. }
  33. return array(
  34. 'echo' => array(
  35. 'title' => t('Cache system'),
  36. 'description' => t('The <a href="!echo">%echo</a> module requires a working cache system.', array('!echo' => 'http://drupal.org/project/echo', '%echo' => 'Echo')),
  37. 'value' => $pass ? t('Working') : t('Not working'),
  38. 'severity' => $pass ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  39. ),
  40. );
  41. }