3 * Created on May 9, 2007
5 * @author Diego Andrés Ramírez Aragón <diego@somosmas.org>
6 * @copyright Diego Andrés Ramírez Aragón - 2007
9 function vanillaforum_pagesetup() {
10 global $PAGE, $CFG, $messages;
11 $vanilla_url = $CFG->wwwroot
."mod/vanillaforum/vanilla/";
13 // Checking if the database config its vanilla compatible
14 if ($CFG->dbtype
!= "mysql") {
15 $messages[] = __gettext("Your database engine its not compatible with vanilla.<br> Vanilla forum supports only mysql");
18 if (defined("context") && context
== "forum") {
19 $PAGE->menu
[] = array (
21 'html' => "<li><a href=\"" . $vanilla_url . " class=\"selected\" >" . __gettext("Forums"
24 $PAGE->menu
[] = array (
26 'html' => "<li><a href=\"" . $vanilla_url . "\" >" . __gettext("Forums"
33 function vanillaforum_init() {
34 global $CFG, $function, $db, $METATABLES;
35 if (!get_config('vanilla')) {
36 if (file_exists(dirname(__FILE__
)."/$CFG->dbtype.sql")) {
37 // Vanilla forum tables
38 modify_database(dirname(__FILE__
)."/vanilla/setup/mysql.sql");
39 // Elgg related tables updates
40 modify_database(dirname(__FILE__
)."/$CFG->dbtype.sql");
42 execute_sql("INSERT INTO LUM_Style Values(1,0,'default',".$db->qstr($CFG->wwwroot
."mod/vanillaforum/vanilla/themes/vanilla/styles/default/").",'preview.gif')");
43 // Creating vanilla categories for existing communities
44 $communities = get_records('users','user_type','community');
45 foreach($communities as $community){
46 $forum_desc = sprintf(__gettext("'%s' discussion forum"), $community->name
);
47 $forum_name = sprintf(__gettext("'%s' discussions"), $community->name
);
48 $query = "INSERT INTO LUM_Category (CategoryID,Name,Description) VALUES (" . $db->qstr($community->ident
) . "," . $db->qstr($forum_name) . "," . $db->qstr($forum_desc) . ")";
50 $query = "INSERT INTO LUM_CategoryRoleBlock (CategoryID,RoleID,Blocked) VALUES ($community->ident,1,1)";
52 $query = "INSERT INTO LUM_CategoryRoleBlock (CategoryID,RoleID,Blocked) VALUES ($community->ident,2,1)";
56 error("Error: Your database ($CFG->dbtype) is not yet fully supported by the Elgg messages plug-in. See the mod/messages directory.");
58 set_config('vanilla',time());
63 $function['display:sidebar'][] = dirname(__FILE__
) . "/lib/user_info_menu.php";
65 // Listen for community creation
66 listen_for_event("community", "publish", "vanilla_forum_sync");
67 listen_for_event("user", "delete", "vanilla_forum_sync");
72 * Function that handles the the syncronization with the Vanilla forum database
73 * @param string $object_type
74 * @param string $event
75 * @param mixed $object
78 function vanilla_forum_sync($object_type, $event, $object) {
79 global $db, $messages;
81 // If a community has been created create a new category in vanilla
82 if ($object_type == "community" && $event == "publish") {
83 $forum_desc = sprintf(__gettext("'%s' discussion forum"), $object->name
);
84 $forum_name = sprintf(__gettext("'%s' discussions"), $object->name
);
85 $query = "SELECT CategoryID from LUM_Category where CategoryID = ? ";
86 $vanilla_category = get_field_sql($query, array ($object->ident
));
87 if (!$vanilla_category) {
88 $query = "INSERT INTO LUM_Category (CategoryID,Name,Description) VALUES (" . $db->qstr($object->ident
) . "," . $db->qstr($forum_name) . "," . $db->qstr($forum_desc) . ")";
89 if (!execute_sql($query, false)) {
90 $messages[] = __gettext("Error creating the community forum");
93 $vanilla_category = $object->ident
;
95 $query = "INSERT INTO LUM_CategoryRoleBlock (CategoryID,RoleID,Blocked) VALUES ($vanilla_category,1,1)";
96 execute_sql($query, false);
97 $query = "INSERT INTO LUM_CategoryRoleBlock (CategoryID,RoleID,Blocked) VALUES ($vanilla_category,2,1)";
98 execute_sql($query, false);
101 if ($object_type == "user" && $event == "delete") {
102 if ($object->user_type
== "community") {
103 // Dropping vanilla category
104 $query = "SELECT CategoryID FROM LUM_Category WHERE CategoryID=?";
105 $vanilla_category = get_field_sql($query, array ($object->ident
));
106 if ($vanilla_category) {
107 $query = "UPDATE LUM_Discussion SET CategoryID = 1 WHERE CategoryID = " . $db->qstr($vanilla_category);
108 if (execute_sql($query, false)) {
109 execute_sql("DELETE FROM LUM_Category WHERE CategoryID=" . $db->qstr($vanilla_category), false);
110 execute_sql("DELETE FROM LUM_CategoryRoleBlock WHERE CategoryID=" . $db->qstr($vanilla_category), false);
111 $messages[] = sprintf(__gettext("Forums discussions related with the group '%s' were returned to the 'General' forum"), $object->name
);
113 $messages[] = __gettext("Error updating the discussion information");
116 $messages[] = sprintf(__gettext("Coudn't find any forum related with the %s community"), $object->name
);
118 // Delete community owner from vanilla