3 //widget ident tells you which widget you are dealing with
5 // sets up the widget, leave blank
6 function commentwall_pagesetup() {
9 // tells Elgg the widget exists
10 function commentwall_init() {
11 global $CFG, $profile_id, $db, $messages, $page_owner;
13 $tables = $db->Metatables();
14 if (!in_array($CFG->prefix
. "profile_commentwall",$tables)) {
15 if (file_exists($CFG->dirroot
. "mod/commentwall/$CFG->dbtype.sql")) {
16 modify_database($CFG->dirroot
. "mod/commentwall/$CFG->dbtype.sql");
18 error("Error: Your database ($CFG->dbtype) is not yet fully supported by the comment wall. See the mod/commentwall directory.");
20 print_continue("index.php");
24 //If a comment has been submitted, populate the database here
25 $action = optional_param("action");
27 if($action == 'commentwall:add' && $sneaky == '') {
29 $widget_id = optional_param("widget_id");
30 $comment_id = optional_param("comment_id");
31 $comment = optional_param("comment");
33 // TODO: check for access permissions!
34 $access = run("users:access_level_sql_where",$_SESSION['userid']);
35 if ($widget = get_record_sql("select ident from {$CFG->prefix}widgets where {$access} and type = \"commentwall::example\"")) {
37 $logged_in_user = $_SESSION['userid']; // get the id of the person logged in
38 $profile_owner = optional_param("profile_id"); // get the profile owner
39 $sneaky = optional_param("sneaky"); // used to try and stop spam
40 $commentwall = new stdClass
;
41 $commentwall->parent_widget
= $widget_id;
42 $commentwall->comment_owner
= $_SESSION['userid'];
43 $commentwall->content
= $comment;
44 $commentwall->time_posted
= time();
46 $comment = new stdClass
;
47 $comment->owner
= $comment_owner;
48 $comment->posted
= time();
49 $comment->body
= $comment;
50 $comment = plugin_hook("weblog_comment","create",$comment);
53 insert_record("profile_commentwall",$commentwall);
55 //used to email the comment wall owner
56 notify_user(page_owner(), __gettext("Someone has posted to your comment wall"), __gettext("Check it out") . ": " . $CFG->wwwroot
. user_info("username", page_owner()) . "/profile/");
61 //To stop the back browser issue, use redirect
62 $_SESSION['messages'] = $messages;
63 header("Location: {$CFG->wwwroot}" . user_info("username", page_owner()) . "/profile/");
65 } else if ($action == 'commentwall:delete' &&
66 ($page_owner == $_SESSION['userid'])
67 ||
user_flag_get('admin',$_SESSION['userid'])) {
68 $widget_id = optional_param("widget_id");
69 $comment_id = optional_param("comment_id");
70 //check the comment actually exists
71 if ($records = get_records_sql("select * from {$CFG->prefix}profile_commentwall where ident={$comment_id}")) {
73 delete_records("profile_commentwall","ident",$comment_id);
74 $_SESSION['messages'] = $messages;
75 header("Location: {$CFG->wwwroot}" . user_info("username", page_owner()) . "/profile/");
80 listen_for_event("widget","delete","commentwall_widget_delete");
82 $CFG->widgets
->list[] = array(
83 'name' => __gettext("Comment Wall"),
84 'description' => __gettext("Leave me a comment."),
85 // Note that type must be of the form modulename::widgetname
86 'type' => "commentwall::example"
90 // handles the widget display
91 function commentwall_widget_display($widget) {
93 $owner = $widget->ident
;
94 $title = __gettext("Comment Wall");
95 if (!$limit_number = widget_get_data("widget_comment_number",$widget->ident
)) {
103 border-top:1px solid #ccc;
104 background:url({$CFG->wwwroot}mod/commentwall/images/comments_bk.gif) repeat-x;
107 border:1px solid #eee;
115 .delete-comment-icon img {
122 if ($records = get_records_sql("select * from {$CFG->prefix}profile_commentwall where parent_widget={$owner} ORDER BY time_posted DESC LIMIT {$limit_number}")) {
123 foreach($records as $record) {
124 $date = date("g:i a, F j", $record->time_posted
);
125 $body .= "<div class=\"comment\"><p>";
126 $returnConfirm = __gettext("Are you sure you want to delete this comment?");
127 $pathtodeleteicon = $CFG->wwwroot
. "/mod/commentwall/images/delete.gif";
130 $delete_path = $CFG->wwwroot
. "profile/index.php?profile_id=" . page_owner() ."&action=commentwall:delete&comment_id=" . $record->ident
;
132 // only show the option to delete if the logged in user owns the profile
133 if(page_owner() == $_SESSION['userid']) {
134 $commentmenu = <<< END
135 <a href
="$delete_path" onclick
="return confirm('$returnConfirm')" title
="delete comment" class="delete-comment-icon"><img src
="$pathtodeleteicon" /></a
>
137 $body .= $commentmenu;
139 if ($record->comment_owner
> 0) {
140 $body .= "<a href=\"" . $CFG->wwwroot
. user_info("username", $record->comment_owner
) . "\">";
141 $body .= user_icon_html($record->comment_owner
, 50);
143 $body .= "<b>" . user_name($record->comment_owner
) . "</b><small> at " . $date . " " . __gettext("says") . "</small><br />";
145 //display comments posted by guests
146 $body .= user_icon_html($record->comment_owner
, 50);
147 $body .= "<b>A guest</b><small> at " . $date . " " . __gettext("says") . "</small><br />";
149 $body .= $record->content
. "</p></div>";
152 $body .= "No comments - why not be the first!";
155 $body .= "<br /><form action=\"\" method=\"post\"><input type=\"hidden\" name=\"widget_id\" value=\"{$widget->ident}\"><input type=\"hidden\" name=\"comment-owner\" value=\"{$_SESSION['userid']}\"><input type=\"hidden\" name=\"action\" value=\"commentwall:add\"><p><textarea name=\"comment\" row=\"4\" column=\"40\"></textarea></p>";
156 $body .= "<p><input type=\"text\" name=\"sneaky\" value=\"\" id=\"sneaky\"><input type=\"submit\" name=\"\" value=\"post it\" /></form></p>";
164 // handles editing of the widget
165 function commentwall_widget_edit($widget) {
166 global $CFG, $page_owner;
169 Display form contents - without the form tags or save button.
170 Fields are of the form widget_data[data_name]; you can get data
171 out using widget_get_data("data_name",$widget->ident).
174 $widget_comment_number = widget_get_data("widget_comment_number",$widget->ident
);
175 if (empty($widget_comment_number)) { $widget_comment_number = 6; }
176 $body = "<h2>Comment Wall</h2>";
177 $body .= "<p>" . __gettext("How many comments would you like to appear?") . "</p>";
178 $body .= "<p><input type=\"text\" name=\"widget_data[widget_comment_number]\" value=\"{$widget_comment_number}\">";
179 $body .= "<p>Change the privacy level of your comment wall.</p>";
183 // delete all comments from the database when a user kills their comment wall
184 function commentwall_widget_delete($object_type, $event, $object) {
186 if ($object_type == "widget" && $event == "delete") {
188 delete_records("profile_commentwall", "parent_widget",$object->ident
);