| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
function forum_pagesetup() |
|---|
| 6 |
{ |
|---|
| 7 |
global $CFG, $PAGE, $page_owner; |
|---|
| 8 |
|
|---|
| 9 |
if (defined("context") && (context == "weblog") && run("users:type:get", page_owner()) == "community") |
|---|
| 10 |
{ |
|---|
| 11 |
|
|---|
| 12 |
$num = count($PAGE->menu_sub) + 1; |
|---|
| 13 |
|
|---|
| 14 |
$PAGE->menu_sub[$num]['name'] = "weblog:forum"; |
|---|
| 15 |
$PAGE->menu_sub[$num]['html'] = '<a href="'.$CFG->wwwroot . 'mod/forum/forum.php?weblog='.user_info('username',page_owner()).'">' . __gettext("View as Forum") . '</a>'; |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
$forum_menu = run('sidebar:forum'); |
|---|
| 19 |
$forum_menu = sidebar_legacy_wrap($forum_menu); |
|---|
| 20 |
|
|---|
| 21 |
sidebar_add(20, 'sidebar-forum', $forum_menu, true, "Your Forum"); |
|---|
| 22 |
sidebar_remove('sidebar-blog'); |
|---|
| 23 |
|
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
function forum_init() |
|---|
| 27 |
{ |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
global $function, $CFG, $page_owner, $profile_id, $db, $METATABLES; |
|---|
| 31 |
include(dirname(__FILE__) . '/config.php'); |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
if (in_array($CFG->prefix . "weblog_posts", $METATABLES)) { |
|---|
| 37 |
$messagesTable = $db->MetaColumnNames($CFG->prefix . "weblog_posts", true); |
|---|
| 38 |
|
|---|
| 39 |
if (!in_array("last_updated", $messagesTable)) { |
|---|
| 40 |
if (file_exists($CFG->dirroot . "mod/forum/$CFG->dbtype.sql")) { |
|---|
| 41 |
modify_database($CFG->dirroot . "mod/forum/$CFG->dbtype.sql"); |
|---|
| 42 |
} else { |
|---|
| 43 |
error("Error: Your database ($CFG->dbtype) is not yet fully supported by the Elgg forum plug-in. See the mod/forum directory."); |
|---|
| 44 |
} |
|---|
| 45 |
print_continue($CFG->wwwroot); |
|---|
| 46 |
exit(); |
|---|
| 47 |
} |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
$CFG->widgets->list[]= array ('name' => __gettext("Forum widget"), |
|---|
| 51 |
'description' => __gettext("Displays the latest posts from a Community Forum of your choice."), |
|---|
| 52 |
'type' => "forum::forum"); |
|---|
| 53 |
|
|---|
| 54 |
listen_for_event("weblog_post","publish","forum_publish_blog"); |
|---|
| 55 |
listen_for_event("weblog_post","republish","forum_publish_blog"); |
|---|
| 56 |
listen_for_event("weblog_post","delete","forum_publish_blog"); |
|---|
| 57 |
listen_for_event("weblog_comment","publish","forum_publish_blog"); |
|---|
| 58 |
listen_for_event("weblog_comment","delete","forum_publish_blog"); |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
$function['userdetails:edit:details'][] = $CFG->dirroot . "mod/forum/userdetails_edit.php"; |
|---|
| 64 |
$function['userdetails:init'][] = $CFG->dirroot . "mod/forum/userdetails_actions.php"; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
//{ |
|---|
| 69 |
|
|---|
| 70 |
// if ($file == $CFG->dirroot . "mod/blog/lib/weblogs_user_info_menu.php") |
|---|
| 71 |
// { |
|---|
| 72 |
// $custom_sidebar=$CFG->dirroot . 'mod/forum/forum_user_info_menu.php'; |
|---|
| 73 |
// $function['display:sidebar'][$key] = $custom_sidebar; |
|---|
| 74 |
// } |
|---|
| 75 |
|
|---|
| 76 |
//} |
|---|
| 77 |
|
|---|
| 78 |
$function['sidebar:forum'][] = $CFG->dirroot . 'mod/forum/forum_user_info_menu.php'; |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
function forum_publish_blog($object_type, $event, $object) |
|---|
| 85 |
{ |
|---|
| 86 |
global $CFG, $PAGE, $profile_id, $page_owner; |
|---|
| 87 |
global $redirect_url; |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
include(dirname(__FILE__) . '/config.php'); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
if ($object_type == "weblog_comment") { |
|---|
| 95 |
$post = get_record('weblog_posts','ident',$object->post_id); |
|---|
| 96 |
$post_id = $post->ident; |
|---|
| 97 |
$community=$post->weblog; |
|---|
| 98 |
|
|---|
| 99 |
if ($forum_sort == 1){ |
|---|
| 100 |
|
|---|
| 101 |
$post->last_updated=time(); |
|---|
| 102 |
update_record('weblog_posts',$post); |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
if ($object_type == "weblog_post") { |
|---|
| 108 |
$post_id = $object->ident; |
|---|
| 109 |
$community=$object->weblog; |
|---|
| 110 |
|
|---|
| 111 |
if ($forum_sort == 1){ |
|---|
| 112 |
|
|---|
| 113 |
$object->last_updated=time(); |
|---|
| 114 |
update_record('weblog_posts',$object); |
|---|
| 115 |
} |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
$forum_flag = user_flag_get('forum', $community); |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
//echo $forum_default; |
|---|
| 124 |
|
|---|
| 125 |
if ((!$forum_flag) && ($forum_default == 0)) |
|---|
| 126 |
{ |
|---|
| 127 |
$use_forum= "yes"; |
|---|
| 128 |
} |
|---|
| 129 |
else if ((!$forum_flag) && ($forum_default == 1)) |
|---|
| 130 |
{ |
|---|
| 131 |
$use_forum= "no"; |
|---|
| 132 |
} |
|---|
| 133 |
else |
|---|
| 134 |
{ |
|---|
| 135 |
$use_forum= $forum_flag; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
if ($use_forum == "yes" && run('users:type:get', $community) == 'community') |
|---|
| 140 |
{ |
|---|
| 141 |
if ($object_type == 'weblog_post') { |
|---|
| 142 |
if ($event == 'delete') { |
|---|
| 143 |
$community_record=get_record('users','ident',$community); |
|---|
| 144 |
$redirect_url = $CFG->wwwroot . 'mod/forum/forum.php?weblog=' . $community_record->username; |
|---|
| 145 |
define('redirect_url',$redirect_url); |
|---|
| 146 |
} else { |
|---|
| 147 |
$redirect_url = $CFG->wwwroot . 'mod/forum/forum_view_thread.php?post=' . $post_id; |
|---|
| 148 |
define('redirect_url',$redirect_url); |
|---|
| 149 |
} |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
if ($object_type == 'weblog_comment') { |
|---|
| 153 |
$redirect_url = $CFG->wwwroot . 'mod/forum/forum_view_thread.php?post=' . $post_id; |
|---|
| 154 |
define('redirect_url',$redirect_url); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
return $object; |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
function forum_widget_display($widget) { |
|---|
| 167 |
|
|---|
| 168 |
global $CFG; |
|---|
| 169 |
|
|---|
| 170 |
$blog_id= widget_get_data("blog_id", $widget->ident); |
|---|
| 171 |
$blog_posts= widget_get_data("blog_posts", $widget->ident); |
|---|
| 172 |
|
|---|
| 173 |
$style .= "<style type=\"text/css\">"; |
|---|
| 174 |
$style .= str_replace('{{url}}', $CFG->wwwroot, file_get_contents($CFG->dirroot . "mod/forum/widget_css")); |
|---|
| 175 |
$style .= "</style>"; |
|---|
| 176 |
|
|---|
| 177 |
$body= ""; |
|---|
| 178 |
$body .=$style; |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
if (empty ($blog_id)) { |
|---|
| 183 |
global $page_owner; |
|---|
| 184 |
$blog_id= $page_owner; |
|---|
| 185 |
} |
|---|
| 186 |
if (empty ($blog_posts)) { |
|---|
| 187 |
$blog_posts= 1; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
$body .='<div class="forum-post">'; |
|---|
| 191 |
$where= run("users:access_level_sql_where", $_SESSION['userid']); |
|---|
| 192 |
$posts= get_records_sql("select * from " . $CFG->prefix . "weblog_posts where ($where) and weblog = $blog_id order by last_updated desc limit $blog_posts"); |
|---|
| 193 |
|
|---|
| 194 |
if (is_array($posts) && !empty ($posts)) { |
|---|
| 195 |
$body .="<ul>"; |
|---|
| 196 |
foreach ($posts as $post) { |
|---|
| 197 |
$body .= '<li><a href="' . $CFG->wwwroot . 'mod/forum/forum_view_thread.php?post=' . $post->ident . '">' . $post->title . '</a> by ' . run("profile:display:name", $post->owner) . '</li>'; |
|---|
| 198 |
} |
|---|
| 199 |
$body .='<li><a href="' . $CFG->wwwroot . user_info("username",$blog_id) . '/forum">[' . __gettext("View all Forum posts") . ']</a></li></ul>'; |
|---|
| 200 |
} |
|---|
| 201 |
$body .= '</div>'; |
|---|
| 202 |
|
|---|
| 203 |
return array ('title' => __gettext('Forum').' :: <a href="' . $CFG->wwwroot . user_info("username",$blog_id) . '/forum">' . htmlspecialchars(user_name($blog_id), ENT_COMPAT, 'utf-8') . '</a>', 'content' => $body); |
|---|
| 204 |
|
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
function forum_widget_edit($widget) { |
|---|
| 213 |
|
|---|
| 214 |
global $CFG, $page_owner; |
|---|
| 215 |
|
|---|
| 216 |
$blog_id= widget_get_data("blog_id", $widget->ident); |
|---|
| 217 |
$blog_posts= widget_get_data("blog_posts", $widget->ident); |
|---|
| 218 |
if (empty ($blog_posts)) { |
|---|
| 219 |
$blog_posts= 1; |
|---|
| 220 |
} |
|---|
| 221 |
if (empty ($blog_id)) { |
|---|
| 222 |
$blog_id= $page_owner; |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
$connections= get_records_sql("select u.ident, u.name from " . $CFG->prefix . "friends f join " . $CFG->prefix . "users u on u.ident = f.friend where f.owner = " . $_SESSION['userid'] . " AND u.user_type=\"community\" order by u.name asc"); |
|---|
| 226 |
$data= new stdClass; |
|---|
| 227 |
$data->ident= $page_owner; |
|---|
| 228 |
$data->name= run("profile:display:name", $page_owner); |
|---|
| 229 |
$connections[]= $data; |
|---|
| 230 |
if ($page_owner != $_SESSION['userid']) { |
|---|
| 231 |
$data= new stdClass; |
|---|
| 232 |
$data->ident= $_SESSION['userid']; |
|---|
| 233 |
$data->name= run("profile:display:name", $_SESSION['userid']); |
|---|
| 234 |
$connections[]= $data; |
|---|
| 235 |
} |
|---|
| 236 |
|
|---|
| 237 |
$body= "<h2>" . __gettext("Forum widget") . "</h2>"; |
|---|
| 238 |
$body .= "<p>" . __gettext("This widget displays the last couple of forum posts from a community forum. To begin, select the community from your connections below:") . "</p>"; |
|---|
| 239 |
|
|---|
| 240 |
$body .= "<p><select name=\"widget_data[blog_id]\">\n"; |
|---|
| 241 |
if (is_array($connections) && !empty ($connections)) { |
|---|
| 242 |
foreach ($connections as $connection) { |
|---|
| 243 |
if ($connection->ident == $blog_id) { |
|---|
| 244 |
$selected= "selected=\"selected\""; |
|---|
| 245 |
} else { |
|---|
| 246 |
$selected= ""; |
|---|
| 247 |
} |
|---|
| 248 |
$body .= "<option value=\"" . $connection->ident . "\" $selected>" . $connection->name . "</option>\n"; |
|---|
| 249 |
} |
|---|
| 250 |
} |
|---|
| 251 |
$body .= "</select></p>\n"; |
|---|
| 252 |
|
|---|
| 253 |
$body .= "<p>" . __gettext("Then enter the number of forum posts you'd like to display:") . "</p>"; |
|---|
| 254 |
|
|---|
| 255 |
$body .= "<p><input type=\"text\" name=\"widget_data[blog_posts]\" value=\"" . $blog_posts . "\" /></p>"; |
|---|
| 256 |
|
|---|
| 257 |
return $body; |
|---|
| 258 |
|
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
?> |
|---|