Simple status box for the sidebar.
[elgg_plugins.git] / forum / lib.php
blob8aec56942010db0935f9e027a2e19f36a29b88d6
1 <?php
5 function forum_pagesetup()
7 global $CFG, $PAGE, $page_owner;
9 if (defined("context") && (context == "weblog") && run("users:type:get", page_owner()) == "community")
11 // Add to the submenu
12 $num = count($PAGE->menu_sub) + 1;
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>';
22 function forum_init()
26 global $function, $CFG, $page_owner, $profile_id, $db, $METATABLES;
27 include(dirname(__FILE__) . '/config.php');
32 if (in_array($CFG->prefix . "weblog_posts", $METATABLES)) {
33 $messagesTable = $db->MetaColumnNames($CFG->prefix . "weblog_posts", true);
34 // If dosn't exists adding the colummns 'last_updated'
35 if (!in_array("last_updated", $messagesTable)) {
36 if (file_exists($CFG->dirroot . "mod/forum/$CFG->dbtype.sql")) {
37 modify_database($CFG->dirroot . "mod/forum/$CFG->dbtype.sql");
38 } else {
39 error("Error: Your database ($CFG->dbtype) is not yet fully supported by the Elgg forum plug-in. See the mod/forum directory.");
41 print_continue($CFG->wwwroot);
42 exit();
46 listen_for_event("weblog_post","publish","forum_publish_blog");
47 listen_for_event("weblog_post","republish","forum_publish_blog");
48 listen_for_event("weblog_post","delete","forum_publish_blog");
49 listen_for_event("weblog_comment","publish","forum_publish_blog");
50 listen_for_event("weblog_comment","delete","forum_publish_blog");
54 //redirect some functions to use our custom pages for community details...
55 $function['userdetails:edit:details'][] = $CFG->dirroot . "mod/forum/userdetails_edit.php";
56 $function['userdetails:init'][] = $CFG->dirroot . "mod/forum/userdetails_actions.php";
59 foreach($function['display:sidebar'] as $key => $file)
62 if ($file == $CFG->dirroot . "mod/blog/lib/weblogs_user_info_menu.php")
64 $custom_sidebar=$CFG->dirroot . 'mod/forum/forum_user_info_menu.php';
65 $function['display:sidebar'][$key] = $custom_sidebar;
71 } // end function forum_init
74 function forum_publish_blog($object_type, $event, $object)
76 global $CFG, $PAGE, $profile_id, $page_owner;
77 global $redirect_url;
80 include(dirname(__FILE__) . '/config.php');
82 //echo run("users:type:get", page_owner());
84 if ($object_type == "weblog_comment") {
85 $post = get_record('weblog_posts','ident',$object->post_id);
86 $post_id = $post->ident;
87 $community=$post->weblog;
89 if ($forum_sort == 1){
90 //NOW UPDATE THE LAST_MODIFIED STATUS OF THE WEBLOG_POST TO BE NOW SO THAT WE CAN SORT ON THIS IN THE FORUM VIEW...
91 $post->last_updated=time();
92 update_record('weblog_posts',$post);
97 if ($object_type == "weblog_post") {
98 $post_id = $object->ident;
99 $community=$object->weblog;
101 if ($forum_sort == 1){
102 //NOW UPDATE THE LAST_MODIFIED STATUS OF THE WEBLOG_POST TO BE NOW SO THAT WE CAN SORT ON THIS IN THE FORUM VIEW...
103 $object->last_updated=time();
104 update_record('weblog_posts',$object);
110 $forum_flag = user_flag_get('forum', $community);
112 //echo $forum_flag;
113 //echo $forum_default;
115 if ((!$forum_flag) && ($forum_default == 0))
117 $use_forum= "yes";
119 else if ((!$forum_flag) && ($forum_default == 1))
121 $use_forum= "no";
123 else
125 $use_forum= $forum_flag;
129 if ($use_forum == "yes" && run('users:type:get', $community) == 'community')
131 if ($object_type == 'weblog_post') {
132 if ($event == 'delete') {
133 $community_record=get_record('users','ident',$community);
134 $redirect_url = $CFG->wwwroot . 'mod/forum/forum.php?weblog=' . $community_record->username;
135 define('redirect_url',$redirect_url);
136 } else {
137 $redirect_url = $CFG->wwwroot . 'mod/forum/forum_view_thread.php?post=' . $post_id;
138 define('redirect_url',$redirect_url);
142 if ($object_type == 'weblog_comment') {
143 $redirect_url = $CFG->wwwroot . 'mod/forum/forum_view_thread.php?post=' . $post_id;
144 define('redirect_url',$redirect_url);
149 return $object;