hooks.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * All plugin hook handlers are bundled here
  4. */
  5. /**
  6. * Sends out a full HTML mail
  7. *
  8. * @param string $hook 'email'
  9. * @param string $type 'system'
  10. * @param array $return_value In the format:
  11. * to => STR|ARR of recipients in RFC-2822 format (http://www.faqs.org/rfcs/rfc2822.html)
  12. * from => STR of senden in RFC-2822 format (http://www.faqs.org/rfcs/rfc2822.html)
  13. * subject => STR with the subject of the message
  14. * body => STR with the message body
  15. * plaintext_message STR with the plaintext version of the message
  16. * html_message => STR with the HTML version of the message
  17. * cc => NULL|STR|ARR of CC recipients in RFC-2822 format (http://www.faqs.org/rfcs/rfc2822.html)
  18. * bcc => NULL|STR|ARR of BCC recipients in RFC-2822 format (http://www.faqs.org/rfcs/rfc2822.html)
  19. * date => NULL|UNIX timestamp with the date the message was created
  20. * attachments => NULL|ARR of array(array('mimetype', 'filename', 'content'))
  21. * @param array $params The unmodified core parameters
  22. *
  23. * @return bool
  24. */
  25. function html_email_handler_email_hook($hook, $type, $return_value, $params) {
  26. static $plugin_setting;
  27. if (!isset($plugin_setting)) {
  28. $plugin_setting = false;
  29. // do we need to handle sending of mails?
  30. if (elgg_get_plugin_setting("notifications", "html_email_handler") == "yes") {
  31. $plugin_setting = true;
  32. }
  33. }
  34. if (!$plugin_setting) {
  35. return $return_value;
  36. }
  37. // if someone else handled sending they should return true|false
  38. if (empty($return_value) || !is_array($return_value)) {
  39. return $return_value;
  40. }
  41. $additional_params = elgg_extract("params", $return_value);
  42. if (is_array($additional_params)) {
  43. $return_value = array_merge($return_value, $additional_params);
  44. }
  45. return html_email_handler_send_email($return_value);
  46. }
  47. /**
  48. * Cleanup the cached inline images
  49. *
  50. * @param string $hook the name of the hook
  51. * @param string $type the type of the hook
  52. * @param mixed $return current return value
  53. * @param array $params supplied params
  54. *
  55. * @return mixed
  56. */
  57. function html_email_handler_daily_cron_hook($hook, $type, $return, $params) {
  58. if (empty($params) || !is_array($params)) {
  59. return $return;
  60. }
  61. $cache_dir = elgg_get_config("dataroot") . "html_email_handler/image_cache/";
  62. if (!is_dir($cache_dir)) {
  63. return $return;
  64. }
  65. $dh = opendir($cache_dir);
  66. if (empty($dh)) {
  67. return $return;
  68. }
  69. $max_lifetime = elgg_extract("time", $params, time()) - (24 * 60 * 60);
  70. while (($filename = readdir($dh)) !== false) {
  71. // make sure we have a file
  72. if (!is_file($cache_dir . $filename)) {
  73. continue;
  74. }
  75. $modified_time = filemtime($cache_dir . $filename);
  76. if ($modified_time > $max_lifetime) {
  77. continue;
  78. }
  79. // file is past lifetime, so cleanup
  80. unlink($cache_dir . $filename);
  81. }
  82. closedir($dh);
  83. return $return;
  84. }