announcements.module
Search API
- 7.x modules/announcements/announcements.module
- 6.x modules/announcements/announcements.module
- 4.x modules/announcements/announcements.module
- 5.x modules/announcements/announcements.module
File
modules/announcements/announcements.moduleView source
- <?php
-
- /**
- * This module lets administrators create announcements, when then appear can appear in a block.
- *
- * This module uses the Content module to do all of its work. All it is really for is
- * specifying the content type, then handing its output as a block.
- */
-
-
- /**
- * Implementatin of content's hook_content_register_content_type
- *
- * @return unknown
- */
- function announcements_content_register_content_type() {
- $arr = array(
- "announcement" => array(
- "title" => t("Announcement"),
- "description" => t("This is a short announcement to the user, meant to be displayed like news items in a block."),
- "settings" => array(),
- ),
- );
-
-
- // In the settings region, I want some extra fields which will be used
- // when we display.
-
- $arr["announcement"]["settings"]["visibility"] = array(
- "type" => "radios",
- "label" => t("Visibility:"),
- "options" => array("public" => t("Public (all users, incl students)"),
- "faculty" => t("Only faculty/staff"), "hidden" => t("Hidden")
- ),
- "required" => TRUE,
- );
-
-
- return $arr;
- }
-
-
- /**
- * Implementation of hook_perm
- *
- */
- function announcements_perm() {
-
- return array(
- "view_faculty_announcements" => array(
- "title" => t("View faculty announcements"),
- ),
- );
- }
-
-
- /**
- * Return the HTML rendering the announcements we have in the database.
- */
- function announcements_render_announcements() {
-
- global $user;
-
- $rtn = "";
-
- $res = db_query("SELECT * FROM content WHERE type = 'announcement'
- ORDER BY updated DESC");
- while ($cur = db_fetch_array($res)) {
-
- $announcement = content_load($cur["cid"]);
- $title = $announcement["title"];
- if (strstr($title, "[hide]")) {
- $title = "";
- }
-
-
- // Visibility?
- if ($announcement["settings"]["visibility"] == "hidden") {
- continue;
- }
-
- if ($announcement["settings"]["visibility"] == "faculty") {
- if (!user_has_permission("view_faculty_announcements")) {
- continue;
- }
- }
-
-
- $rtn .= "<div class='announcement'>";
- if ($title) {
- $rtn .= "
- <div class='announcement-title'>" . filter_markup($title) . "</div>
- ";
- }
- $rtn .= "<div class='announcement-text'>" . filter_markup($announcement["body"], "full") . "</div>
- <div class='announcement-posted'>";
-
- // If we have not updated this announcement before, then print "posted",
- // else, print "updated" date.
- if ($announcement["updated"] > $announcement["posted"]) {
- $rtn .= t("Updated") . " " . date("D, M jS Y - g:ia", $announcement["updated"]);
- }
- else {
- $rtn .= t("Posted") . " " . date("D, M jS Y - g:ia", $announcement["posted"]);
- }
-
- $rtn .= "</div>";
-
- $rtn .= "</div>";
- }
-
- return $rtn;
- }
-
-
-
- /**
- * hook_blocks. Returns an array of available blocks offered by this module in this format:
- * array(
- * delta => "This is the title of the block.",
- * ),
- * );
- *
- * Delta can be just about anything machine-readable. Alphanumeric and underscores only.
- * Ex: 0, 1, fun_2, etc.
- *
- */
- function announcements_blocks() {
- return array(
- "primary" => t("Primary announcements 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",
- * );
- */
- function announcements_render_block($delta) {
-
- $rtn = array();
-
- if ($delta == "primary") {
-
- fp_add_css(fp_get_module_path("announcements") . "/css/announcements.css");
-
- $rtn["title"] = t("Announcements");
- $rtn["body"] = announcements_render_announcements();
- }
-
-
- return $rtn;
-
- }
Functions
Name | 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", ); |