announcements.module

  1. 7.x modules/announcements/announcements.module
  2. 6.x modules/announcements/announcements.module
  3. 4.x modules/announcements/announcements.module
  4. 5.x modules/announcements/announcements.module

File

modules/announcements/announcements.module
View source
  1. <?php
  2. /**
  3. * This module lets administrators create announcements, when then appear can appear in a block.
  4. *
  5. * This module uses the Content module to do all of its work. All it is really for is
  6. * specifying the content type, then handing its output as a block.
  7. */
  8. /**
  9. * Implementatin of content's hook_content_register_content_type
  10. *
  11. * @return unknown
  12. */
  13. function announcements_content_register_content_type() {
  14. $arr = array(
  15. "announcement" => array(
  16. "title" => t("Announcement"),
  17. "description" => t("This is a short announcement to the user, meant to be displayed like news items in a block."),
  18. "settings" => array(),
  19. ),
  20. );
  21. // In the settings region, I want some extra fields which will be used
  22. // when we display.
  23. $arr["announcement"]["settings"]["visibility"] = array(
  24. "type" => "radios",
  25. "label" => t("Visibility:"),
  26. "options" => array("public" => t("Public (all users, incl students)"),
  27. "faculty" => t("Only faculty/staff"), "hidden" => t("Hidden")
  28. ),
  29. "required" => TRUE,
  30. );
  31. return $arr;
  32. }
  33. /**
  34. * Implementation of hook_perm
  35. *
  36. */
  37. function announcements_perm() {
  38. return array(
  39. "view_faculty_announcements" => array(
  40. "title" => t("View faculty announcements"),
  41. ),
  42. );
  43. }
  44. /**
  45. * Return the HTML rendering the announcements we have in the database.
  46. */
  47. function announcements_render_announcements() {
  48. global $user;
  49. $rtn = "";
  50. $res = db_query("SELECT * FROM content WHERE type = 'announcement'
  51. ORDER BY updated DESC");
  52. while ($cur = db_fetch_array($res)) {
  53. $announcement = content_load($cur["cid"]);
  54. $title = $announcement["title"];
  55. if (strstr($title, "[hide]")) {
  56. $title = "";
  57. }
  58. // Visibility?
  59. if ($announcement["settings"]["visibility"] == "hidden") {
  60. continue;
  61. }
  62. if ($announcement["settings"]["visibility"] == "faculty") {
  63. if (!user_has_permission("view_faculty_announcements")) {
  64. continue;
  65. }
  66. }
  67. $rtn .= "<div class='announcement'>";
  68. if ($title) {
  69. $rtn .= "
  70. <div class='announcement-title'>" . filter_markup($title) . "</div>
  71. ";
  72. }
  73. $rtn .= "<div class='announcement-text'>" . filter_markup($announcement["body"], "full") . "</div>
  74. <div class='announcement-posted'>";
  75. // If we have not updated this announcement before, then print "posted",
  76. // else, print "updated" date.
  77. if ($announcement["updated"] > $announcement["posted"]) {
  78. $rtn .= t("Updated") . " " . date("D, M jS Y - g:ia", $announcement["updated"]);
  79. }
  80. else {
  81. $rtn .= t("Posted") . " " . date("D, M jS Y - g:ia", $announcement["posted"]);
  82. }
  83. $rtn .= "</div>";
  84. $rtn .= "</div>";
  85. }
  86. return $rtn;
  87. }
  88. /**
  89. * hook_blocks. Returns an array of available blocks offered by this module in this format:
  90. * array(
  91. * delta => "This is the title of the block.",
  92. * ),
  93. * );
  94. *
  95. * Delta can be just about anything machine-readable. Alphanumeric and underscores only.
  96. * Ex: 0, 1, fun_2, etc.
  97. *
  98. */
  99. function announcements_blocks() {
  100. return array(
  101. "primary" => t("Primary announcements block"),
  102. );
  103. }
  104. /**
  105. * Called when it is time to render the block in question.
  106. * Expected to return an array which looks like this:
  107. * array(
  108. * "title" => "Some title goes here.",
  109. * "body" => "this is the primary body of the block",
  110. * );
  111. */
  112. function announcements_render_block($delta) {
  113. $rtn = array();
  114. if ($delta == "primary") {
  115. fp_add_css(fp_get_module_path("announcements") . "/css/announcements.css");
  116. $rtn["title"] = t("Announcements");
  117. $rtn["body"] = announcements_render_announcements();
  118. }
  119. return $rtn;
  120. }

Functions

Namesort descending Description
announcements_blocks hook_blocks. Returns an array of available blocks offered by this module in this format: array( delta => "This is the title of the block.", ), );
announcements_content_register_content_type Implementatin of content's hook_content_register_content_type
announcements_perm Implementation of hook_perm
announcements_render_announcements Return the HTML rendering the announcements we have in the database.
announcements_render_block Called when it is time to render the block in question. Expected to return an array which looks like this: array( "title" => "Some title goes here.", "body" => "this is the primary body of the block", );