Integrating phorum with personal website
Posted by narcissius
Integrating phorum with personal website January 30, 2010 06:09PM |
Registered: 15 years ago Posts: 4 |
Hey forum,
first of all, phorum looks like a superb piece of software. Great work!
Secondly, the main reason I am writing here, is that I'm having some troubles integrating phorum with my current site. The site is written from scratch, by me, and I know it's ins and outs like they were my own ars .. pockets.
I am using the external authentication module, and that's working perfectly. When people access the forum, users are created and all is good. My main problem is that after the forum index is loaded, the links are wrong. My site is:
[www.domain.tld] .
that will use the generic integration module to load the index .. but the links in the forum there will be [www.domain.tld]... which will take my users away from the main site and remove the whole purpose of the integration. How can I circumvent this?
first of all, phorum looks like a superb piece of software. Great work!
Secondly, the main reason I am writing here, is that I'm having some troubles integrating phorum with my current site. The site is written from scratch, by me, and I know it's ins and outs like they were my own ars .. pockets.
I am using the external authentication module, and that's working perfectly. When people access the forum, users are created and all is good. My main problem is that after the forum index is loaded, the links are wrong. My site is:
[www.domain.tld] .
that will use the generic integration module to load the index .. but the links in the forum there will be [www.domain.tld]... which will take my users away from the main site and remove the whole purpose of the integration. How can I circumvent this?
Re: Integrating phorum with personal website January 31, 2010 05:13PM |
Registered: 15 years ago Posts: 24 |
Re: Integrating phorum with personal website February 01, 2010 02:30AM |
Registered: 15 years ago Posts: 4 |
Maybe a reply will kick-start the support for my url problem .. and if not, I can sleep well, satisfied by the thought that maybe I helped someone ;-)
Step 1:
Download the module. If you have ssh access to the server, you're fine using wget to get it. If not, download locally and unzip it. Download the module here
Step 2:
In "external_authentication" folder, go to "plugins_bin". Here, create a folder which you name whatever you like. I named mine after my domain, domain.tld. In this folder, create two files, hook_user_session_restore.php and info.php.
Step 3:
Info.php contains the following:
And the hook file contains the following:
It's the hook file that has most of my hacks. Pretty much what I did was use my userobject in the phorum script. When the user logs into my site, they instantiate and initialize a new object of type Bruker(), and this object gets stored in $_SESSION['bruker']; . The code "require_once("../core/user.php");" has my class definition, so it's required for phorum to understand the session variable. The code "$user_data = $_SESSION['bruker'];" fetches my user object and gives me access to all the info I need to fill in phorum.
In example, $username = $user_data->getUsername(); . getUsername is a method in my Bruker() class, and is used by phorum. You can see the different methods I use to get the integration going.
Step 4:
Activate the module in the admin panel of phorum. Go to "Global Settings" -> "Modules". Go to settings. Chose your newly configured info set, check all the boxes (if needed) and chose Save. After saving, activate the module at the root module menu.
I think that's pretty much what I did :)
edit mmakaay: added some [code] blocks around the PHP code for readability
Edited 1 time(s). Last edit at 02/01/2010 03:00AM by Maurice Makaay.
Step 1:
Download the module. If you have ssh access to the server, you're fine using wget to get it. If not, download locally and unzip it. Download the module here
Step 2:
In "external_authentication" folder, go to "plugins_bin". Here, create a folder which you name whatever you like. I named mine after my domain, domain.tld. In this folder, create two files, hook_user_session_restore.php and info.php.
Step 3:
Info.php contains the following:
Language: PHP<?php //add this external application';s info to the list of possible apps $PHORUM["phorum_mod_external_authentication"]["possible_apps"][] = array( //The name of your external application, possibly with the supported version //number "name" => "Domain.tld", //The folder for your plugin (the folder which contains this info.php file) "app_folder" => "domain.tld", //The required version of the External Authentication which has the //necessary hook support for your module "required_version" => "5.2.1.01", //Your name, callsign, etc. "author" => "Narcissius", ); ?>
And the hook file contains the following:
Language: PHPif (!defined("PHORUM")) return; require_once("../core/user.php"); if (empty($PHORUM["phorum_mod_external_authentication"]["app_path"])) return $session_data; $curcwd = getcwd(); chdir($PHORUM["phorum_mod_external_authentication"]["app_path"]); $user_data = $_SESSION[';bruker';]; if (empty($user_data)) { chdir($curcwd); if (!empty($PHORUM["phorum_mod_external_authentication"]["disable_phorum_login"])) { $session_data[PHORUM_SESSION_LONG_TERM] = FALSE; $session_data[PHORUM_SESSION_SHORT_TERM] = FALSE; } return $session_data; } chdir($curcwd); include_once("./include/api/user.php"); $username = $user_data->getUsername(); $user_id = phorum_api_user_search("username",$username); $phorum_user_data = phorum_api_user_get($user_id); if (empty($phorum_user_data)) { $phorum_user_data = array( // The user_id must be NULL to create a new user "user_id" => NULL, "username" => $username, "password" => md5($user_data->getPassword()), "email" => $user_data->getEmail(), "admin" => 0, "active" => PHORUM_USER_ACTIVE, ); if (!empty($PHORUM["phorum_mod_external_authentication"]["transfer_admin_status"])) { if ($user_data->isAdmin()) { $phorum_user_data["admin"] = 1; } } $user_id = phorum_api_user_save($phorum_user_data, PHORUM_FLAG_RAW_PASSWORD); } elseif (empty($phorum_user_data["active"])) { return $session_data; } else { if ($phorum_user_data["password"] != md5($user_data->getPassword())) { $phorum_user_data["password"] = md5($user_data->getPassword()); $user_id = phorum_api_user_save($phorum_user_data,PHORUM_FLAG_RAW_PASSWORD); } if ($user_data->isAdmin() && empty($phorum_user_data["admin"]) && !empty($PHORUM["phorum_mod_external_authentication"]["transfer_admin_status"])) { $phorum_user_data["admin"] = 1; $user_id = phorum_api_user_save($phorum_user_data); } elseif (!$user_data->isAdmin() && !empty($phorum_user_data["admin"]) && !empty($PHORUM["phorum_mod_external_authentication"]["transfer_admin_status"])) { $phorum_user_data["admin"] = 0; $user_id = phorum_api_user_save($phorum_user_data); } } $session_data[PHORUM_SESSION_LONG_TERM] = $user_id; $session_data[PHORUM_SESSION_SHORT_TERM] = $user_id;
It's the hook file that has most of my hacks. Pretty much what I did was use my userobject in the phorum script. When the user logs into my site, they instantiate and initialize a new object of type Bruker(), and this object gets stored in $_SESSION['bruker']; . The code "require_once("../core/user.php");" has my class definition, so it's required for phorum to understand the session variable. The code "$user_data = $_SESSION['bruker'];" fetches my user object and gives me access to all the info I need to fill in phorum.
In example, $username = $user_data->getUsername(); . getUsername is a method in my Bruker() class, and is used by phorum. You can see the different methods I use to get the integration going.
Step 4:
Activate the module in the admin panel of phorum. Go to "Global Settings" -> "Modules". Go to settings. Chose your newly configured info set, check all the boxes (if needed) and chose Save. After saving, activate the module at the root module menu.
I think that's pretty much what I did :)
edit mmakaay: added some [code] blocks around the PHP code for readability
Edited 1 time(s). Last edit at 02/01/2010 03:00AM by Maurice Makaay.
February 02, 2010 02:41PM |
Moderator Registered: 18 years ago Posts: 1,301 |
narcissius,
First off, thank you for laying out your step by step example of integrating Phorum via my External Authentication module. I hope it becomes useful for others looking to integrate as well. It also shows me that you have a good grasp on the coding basics needed to address your original problem.
When I coded the Drupal plugin for my External Authentication module, I ran into a similar need for redirecting the Phorum paths. I needed to allow Phorum to become another Drupal node with access just like any other Drupal node (ie http://www.domain.com/drupal/node/phorum). To accomplish this, I needed three bits of code.
The first two can be found in the "phorum_module_external_authentication.module" file in the Drupal plugin. Beginning at line 205, I added a phorum_custom_get_url() which Phorum automatically uses as an alternative when creating Phorum paths:
Finally, if you feel the need, the Drupal plugin also allows for requiring visitors to view the Phorum as a Drupal node. Thus, in the "hook_user_session_restore.php" file in the Drupal plugin, starting at line 34, there is a bit of code which checks to see if embedded mode is required and, if so, if the integrated header information has been provided. If not, then the visitor is immediately redirected to the Drupal node for Phorum:
I hope this has been in some way helpful. If you have any further questions, please let me know.
Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
First off, thank you for laying out your step by step example of integrating Phorum via my External Authentication module. I hope it becomes useful for others looking to integrate as well. It also shows me that you have a good grasp on the coding basics needed to address your original problem.
When I coded the Drupal plugin for my External Authentication module, I ran into a similar need for redirecting the Phorum paths. I needed to allow Phorum to become another Drupal node with access just like any other Drupal node (ie http://www.domain.com/drupal/node/phorum). To accomplish this, I needed three bits of code.
The first two can be found in the "phorum_module_external_authentication.module" file in the Drupal plugin. Beginning at line 205, I added a phorum_custom_get_url() which Phorum automatically uses as an alternative when creating Phorum paths:
Later, starting at line 239, I needed some code to rewrite the $_SERVER["QUERY_STRING"] into a format Phorum would recognize:Language: PHP// We have to alter the urls a little function phorum_custom_get_url ($page, $query_items, $suffix, $pathinfo) { $PHORUM=$GLOBALS["PHORUM"]; if (empty($GLOBALS["phorum_module_external_authentication_drupal_clean_urls"])) { $url = $GLOBALS["phorum_module_external_authentication_drupal_http_path"]."&"; $sep = ""; } else { $url = $GLOBALS["phorum_module_external_authentication_drupal_http_path"]; $sep = "?"; } if ($pathinfo !== NULL) $url .= $pathinfo; $url .= $sep.$page; if(count($query_items)) $url.=",".implode(",", $query_items); if(!empty($suffix)) $url.=$suffix; return $url; }
As you can see, both of these are customized to Drupal but I hope they will demonstrate the basic need to first give Phorum an alternate way of building paths and to second give Phorum the query string it expects. In Drupal, the admin can choose to use basic queries, in which every url has a "q" parameter (ie. http://www.domain.com/drupal/?q=node/phorum), or "clean urls" without the "q" (ie. http://www.domain.com/drupal/node/phorum). Drupal further complicates matters by providing language customization through the url (ie. an English page could be:http://www.domain.com/drupal/en/node/phorum). Keeping that in mind, I hope you can customize this code to your needs. It could be run in your index.php code if the query string contains "p=forum".Language: PHPif ($GLABALS["phorum_module_external_authentication_drupal_language_mode"] == LANGUAGE_NEGOTIATION_PATH || $GLABALS["phorum_module_external_authentication_drupal_language_mode"] == LANGUAGE_NEGOTIATION_PATH_DEFAULT) { global $language; if (!empty($language->prefix)) { $_SERVER["QUERY_STRING"] = str_replace("q=".$language->prefix."/phorum&","",$_SERVER["QUERY_STRING"]); $_SERVER["QUERY_STRING"] = str_replace("q=".$language->prefix."/phorum","",$_SERVER["QUERY_STRING"]); } $_SERVER["QUERY_STRING"] = str_replace("q=phorum&","",$_SERVER["QUERY_STRING"]); $_SERVER["QUERY_STRING"] = str_replace("q=phorum","",$_SERVER["QUERY_STRING"]); } else { $_SERVER["QUERY_STRING"] = str_replace("q=phorum&","",$_SERVER["QUERY_STRING"]); $_SERVER["QUERY_STRING"] = str_replace("q=phorum","",$_SERVER["QUERY_STRING"]); }
Finally, if you feel the need, the Drupal plugin also allows for requiring visitors to view the Phorum as a Drupal node. Thus, in the "hook_user_session_restore.php" file in the Drupal plugin, starting at line 34, there is a bit of code which checks to see if embedded mode is required and, if so, if the integrated header information has been provided. If not, then the visitor is immediately redirected to the Drupal node for Phorum:
You can see this in action by visiting my Phorum/Drupal test site: http://joecuria.devplay.org. This will take you to the Drupal home page with a link to the embedded Phorum (http://joecuria.devplay.org/drupal/phorum). However, if you were to visit my Phorum installation directly (http://joecuria.devplay.org/phorum) you would be redirected to the Drupal node (http://joecuria.devplay.org/drupal/phorum) This ensures that visitors only see the Phorum as an integral part of the Drupal installation.Language: PHP// if we are in embedded mode, do not allow access from outside Drupal if (!empty($PHORUM["phorum_mod_external_authentication"]["drupal_6_x"]["generic_integration_template"])) { if (empty($GLOBALS["INTEGRATE_HEADER"])) { $redirect_path = variable_get("phorum_module_external_authentication_drupal_http_path",""); $redirect_path .= variable_get("clean_url", 0) ? "" : "?q="; $redirect_path .= "phorum"; Header( "Location: " . $redirect_path ); } $user_data = $GLOBALS["user"]; }
I hope this has been in some way helpful. If you have any further questions, please let me know.
Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Integrating phorum with personal website November 04, 2010 05:53AM |
Registered: 15 years ago Posts: 4 |
Hey Joe,
I used your module for yet another integration, and it's working pretty much fine, except for one thing I can't make work. I'm trying to set the display_name to reflect a users full, real life, name. I have the information in my application database, and I am trying to register the user like this:
However, the display_name directive seems to be ignored. What am I doing wrong, or do I need to perform additional hacks to support this field?
I used your module for yet another integration, and it's working pretty much fine, except for one thing I can't make work. I'm trying to set the display_name to reflect a users full, real life, name. I have the information in my application database, and I am trying to register the user like this:
Language: PHP$phorum_user_data = array( // The user_id must be NULL to create a new user "user_id" => NULL, "username" => $username, "display_name" => $user_data[';fornavn';] . " " . $user_data[';etternavn';], "password" => $user_data[';passord';], "email" => $user_data[';epost';], "admin" => 0, "active" => PHORUM_USER_ACTIVE, ); if (!empty($PHORUM["phorum_mod_external_authentication"]["transfer_admin_status"])) { if ($_SESSION[';admin';] == "valid") { $phorum_user_data["admin"] = 1; } } $user_id = phorum_api_user_save($phorum_user_data, PHORUM_FLAG_RAW_PASSWORD);
However, the display_name directive seems to be ignored. What am I doing wrong, or do I need to perform additional hacks to support this field?
November 04, 2010 07:58AM |
Moderator Registered: 18 years ago Posts: 1,301 |
narcissius,
The display_name is actually generated by the Phorum system based on what you have assigned in the General Settings > Users section of the Admin section ("What to use as the display name"). Select "User's real name" there and have your code insert the real name into Phorum's "real_name" field:
Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
The display_name is actually generated by the Phorum system based on what you have assigned in the General Settings > Users section of the Admin section ("What to use as the display name"). Select "User's real name" there and have your code insert the real name into Phorum's "real_name" field:
Language: PHP"real_name" => $user_data[';fornavn';] . " " . $user_data[';etternavn';],
Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Integrating phorum with personal website November 04, 2010 08:12AM |
Registered: 15 years ago Posts: 4 |
Sorry, only registered users may post in this forum.