Wed
01
Jun
2005
I created a bridge in coppermine to use b2evolution user's db. It allows a single sign on system between both applications.
It's working with Coppermine 1.3.x and b2evolution 0.9.x
How to install it :
1/ Download http://daury.net/phpbb/b2evolution.inc.txt
2/ Save it under the name b2evolution.inc.php into gallery/bridge folder
3/ Edit the file gallery/include/init.inc.php and add the ligne
PHP:
define('UDB_INTEGRATION', 'phpbb'); |
4/ Edit gallery/bridge/b2evolution.inc.php and define paths for coppermine and b2evolution. See example bellow:
PHP:
// The web path to your coppermine directory | |
// If your URL to your gallery is for example 'http://yoursite_name.com/gallery/', | |
// you'll have to set the below var to '/gallery/'. | |
#define('CPG_PATH', '/cpg133/'); | |
define('CPG_PATH', '/blog/galerie/'); | |
| |
// The relative installation path to b2evolution (from Coppermine directory point of view) | |
// example: ./blogs | |
// ./blogs/conf | |
// ./gallery | |
// ./gallery/bridge | |
// you'll have to set the below var to '../blogs'. | |
#define('B2EVO_RELATIVE_PATH', '../blogs'); | |
// example: ./blogs | |
// ./blogs/conf | |
// ./blogs/gallery | |
// ./blogs/gallery/bridge | |
// you'll have to set the below var to '..'. | |
define('B2EVO_RELATIVE_PATH', '..'); | |
// example: ./b2evolution/blogs | |
// ./b2evolution/blogs/conf | |
// ./cpg133 | |
// ./cpg133/bridge | |
// you'll have to set the below var to '../b2evolution/blogs'. | |
#define('B2EVO_RELATIVE_PATH', '../b2evolution/blogs'); |
5/ It's all folks
If you want more information about bridge for Coppermine, check its documentation.
Bellow full code of the bridge:
PHP:
<?php | |
/************************* | |
Bridge for Coppermine Photo Gallery and b2evolution multi-blog | |
************************ | |
@copyright (c) 2005 Olivier Daury {@link http://daury.net} | |
@version v0.1 | |
| |
b2evolution version 0.9.x | |
coppermine gallery version 1.3.x | |
| |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation. {@link http://www.gnu.org/copyleft/gpl.html} | |
| |
@author This file built upon code from cpg bridge {@link http://coppermine.sourceforge.net} | |
| |
b2evolution @copyright (c)2003-2004 by Francois PLANQUE - {@link http://fplanque.net/} | |
Coppermine @copyright coppermine team {@link http://coppermine.sourceforge.net} | |
| |
******************************************** | |
$Source: /cvsroot/etoiles/cpg/bridge/b2evolution.inc.php,v $ | |
$Revision: 1.2 $ | |
$Author: slamp $ | |
$Date: 2005/06/01 14:11:22 $ | |
******************************************** | |
| |
@package bridge | |
| |
**********************************************/ | |
| |
// ------------------------------------------------------------------------- // | |
// b2evolution Integration for Coppermine // | |
// ------------------------------------------------------------------------- // | |
// Modify the values below according to your b2evolution installation // | |
// ------------------------------------------------------------------------- // | |
| |
// The web path to your coppermine directory | |
// If your URL to your gallery is for example 'http://yoursite_name.com/gallery/', | |
// you'll have to set the below var to '/gallery/'. | |
#define('CPG_PATH', '/cpg133/'); | |
define('CPG_PATH', '/blog/galerie/'); | |
| |
// The relative installation path to b2evolution (from Coppermine directory point of view) | |
// example: ./blogs | |
// ./blogs/conf | |
// ./gallery | |
// ./gallery/bridge | |
// you'll have to set the below var to '../blogs'. | |
#define('B2EVO_RELATIVE_PATH', '../blogs'); | |
// example: ./blogs | |
// ./blogs/conf | |
// ./blogs/gallery | |
// ./blogs/gallery/bridge | |
// you'll have to set the below var to '..'. | |
define('B2EVO_RELATIVE_PATH', '..'); | |
// example: ./b2evolution/blogs | |
// ./b2evolution/blogs/conf | |
// ./cpg133 | |
// ./cpg133/bridge | |
// you'll have to set the below var to '../b2evolution/blogs'. | |
#define('B2EVO_RELATIVE_PATH', '../b2evolution/blogs'); | |
| |
| |
// ------------------------------------------------------------------------- // | |
// You can keep the default values below if your instalation is standard | |
// ------------------------------------------------------------------------- // | |
| |
// needed ? $Settings = & new Settings(); | |
| |
/** | |
* First thing: Do the minimal initializations required for b2evo: | |
* we can't use /b2evocore/_main.php to make initializations as the function make_clickable() is defined in both b2evolution and Coppermine (file: /b2evocore/_functions.php) | |
*/ | |
require_once( dirname(__FILE__). '/../' . B2EVO_RELATIVE_PATH . '/b2evocore/_main.php' ); | |
#require_once( dirname(__FILE__). '/../' . B2EVO_RELATIVE_PATH . '/conf/_config.php' ); | |
#require_once( dirname(__FILE__). '/../' . B2EVO_RELATIVE_PATH . '/conf/_advanced.php' ); | |
//require_once( dirname(__FILE__). '/../' . B2EVO_RELATIVE_PATH . '/b2evocore/_functions_users.php' ); | |
//require_once( dirname(__FILE__). '/../' . B2EVO_RELATIVE_PATH . '/b2evocore/_class_db.php' ); | |
//require_once( dirname(__FILE__). '/../' . B2EVO_RELATIVE_PATH . '/b2evocore/_class_user.php' ); | |
#require_once( dirname(__FILE__). '/../' . B2EVO_RELATIVE_PATH . '/b2evocore/_class_group.php' ); | |
| |
// The web path to your b2evolution directory | |
// If your URL to your blog is for example 'http://yoursite_name.com/b2evolution/blogs/', | |
// you'll have to set the below var to '/b2evolution/blogs/'. | |
define('B2EVO_WEB_PATH', '/blog/'); | |
#define('B2EVO_WEB_PATH', '/b2evolution/blogs/'); | |
| |
$b2evo_web_path = preg_replace('#https?://[^/]+#', '', $baseurl ).'/'; | |
if (B2EVO_WEB_PATH != $b2evo_web_path) { | |
die( 'Your B2EVO_WEB_PATH ('.B2EVO_WEB_PATH.') set in b2evolution.inc.php seems invalid. It should be equal to ' .$b2evo_web_path. '. Please verify and correct that.' ); | |
} | |
| |
// database configuration, taken from b2evolution config file. You don't need to overwrite it. | |
define('B2EVO_DB_NAME', DB_NAME); // The name of the database used by the blog | |
define('B2EVO_DB_HOST', DB_HOST); // The name of the database server | |
define('B2EVO_DB_USERNAME', DB_USER); // The username to use to connect to the database | |
define('B2EVO_DB_PASSWORD', DB_PASSWORD); // The password to use to connect to the database | |
| |
// The b2evolution cookies, taken from b2evolution config file. You don't need to overwrite it. | |
define('B2EVO_COOKIE_USER', $cookie_user); // b2evolution user's cookie name | |
define('B2EVO_COOKIE_PASS', $cookie_pass); // b2evolution password's cookie name | |
| |
// The names for the database tables, taken from b2evolution config file. You don't need to overwrite it. | |
define('B2EVO_USER_TABLE', $tableusers); // b2evolution members table | |
define('B2EVO_GROUP_TABLE', $tablegroups); // b2evolution groups table | |
| |
/* @todo need to encode url */ | |
//LOGIN, LOGOUT and REGISTRATION redirection, taken from b2evolution config file. You don't need to overwrite it. | |
DEFINE('LOGIN_REDIR', $htsrv_subdir . '/login.php?redirect_to=' . CPG_PATH); | |
#DEFINE('LOGIN_REDIR', $htsrv_subdir . '/login.php?redirect_to=/b2evolution/blogs/cpg_redir.php'); | |
DEFINE('LOGOUT_FLAG', $htsrv_subdir . '/login.php?action=logout&redirect_to=' . CPG_PATH); | |
DEFINE('REGISTRATION_REDIR', $htsrv_subdir . '/register.php?redirect_to=' . CPG_PATH); | |
DEFINE('EDIT_USERS_REDIR', $admin_subdir . '/b2users.php?redirect_to=' . CPG_PATH); | |
DEFINE('EDIT_USER_PROFILE', '?disp=profile&redirect_to=' . CPG_PATH) ; | |
| |
// ------------------------------------------------------------------------- // | |
// Nothing to edit below this line | |
// ------------------------------------------------------------------------- // | |
// Group definitions | |
#define('PHPBB_MEMBERS_GROUP', 2); | |
#define('PHPBB_GUEST_GROUP', 3); | |
#define('PHPBB_BANNED_GROUP', 4); | |
define('B2EVO_ADMIN_GROUP', 1); | |
define('B2EVO_PRIV_BLOGGERS_GROUP', 2); | |
define('B2EVO_BLOGGERS_GROUP', 3); | |
define('B2EVO_BASIC_USERS_GROUP', 4); // <=> CPG group Anonymous = 3 | |
define('CPG_ADMIN_GROUP', 1); | |
define('CPG_ANONYMOUS_GROUP', 3); | |
| |
| |
debug_log(T_('BEGIN')); | |
| |
/* udb_authenticate(-) | |
Verify if a user is looged in, if yes authenticate it using cookies | |
* | |
* {@internal cpgGetUserData(-) }} | |
* {@internal User::verifylog(-) }} | |
* @author slamp | |
| |
*/ | |
function udb_authenticate() | |
{ | |
debug_log('udb_authenticate'); | |
| |
global $CONFIG, $UDB_DB_LINK_ID, $USER_DATA, $current_User; | |
global $CONFIG, $UDB_DB_LINK_ID, $USER_DATA, $_COOKIE, $cookie_user, $cookie_pass; | |
| |
debug_log("udb login: $current_User->login"); | |
debug_log("udb pass: $current_User->pass"); | |
| |
// For error checking | |
$CONFIG['TABLE_USERS'] = '**ERROR**'; | |
| |
// Permissions for a default group | |
// Default group data | |
$USER_DATA['group_quota'] = 1; | |
$USER_DATA['can_rate_pictures'] = 0; | |
$USER_DATA['can_send_ecards'] = 0; | |
$USER_DATA['can_post_comments'] = 0; | |
$USER_DATA['can_upload_pictures'] = 0; | |
$USER_DATA['can_create_albums'] = 0; | |
$USER_DATA['pub_upl_need_approval'] = 1; | |
$USER_DATA['priv_upl_need_approval'] = 1; | |
$USER_DATA['upload_form_config'] = 0; | |
$USER_DATA['num_file_upload'] = 0; | |
$USER_DATA['num_URI_upload'] = 0; | |
$USER_DATA['custom_user_upload'] = 0; | |
| |
// Login procedure: | |
// @todo add isset current_User in first if | |
if ( isset($_COOKIE[$cookie_user]) && isset($_COOKIE[$cookie_pass]) ) | |
{ | |
debug_log('udb: cookie defini'); | |
// get cookie | |
$udb_user_login = trim(strip_tags(get_magic_quotes_gpc() ? stripslashes($_COOKIE[$cookie_user]) : $_COOKIE[$cookie_user])); | |
$udb_user_pass = trim(strip_tags(get_magic_quotes_gpc() ? stripslashes($_COOKIE[$cookie_pass]) : $_COOKIE[$cookie_pass])); | |
} | |
elseif ( isset($current_User)) { | |
debug_log('udb: current_User defined'); | |
$udb_user_login = $current_User->login; | |
$udb_user_pass = $current_User->pass; | |
} | |
else { | |
debug_log('udb: cookie et current_User non defini'); | |
unset($udb_user_login); | |
unset($udb_user_pass); | |
} | |
| |
if ( isset($udb_user_login) && isset($udb_user_pass) ) | |
{ | |
$udb_userdata = get_userdatabylogin($udb_user_login); | |
// @todo: a traiter cas du pass pas en md5 if( !$pass_is_md5 ) $user_pass = md5( $user_pass ); | |
$udb_login_ok = ($udb_user_pass == $udb_userdata['user_pass']); | |
} | |
else { | |
$udb_login_ok = false; | |
} | |
| |
if ( $udb_login_ok ) | |
{ // login OK | |
debug_log("udb: login ok"); | |
$udb_current_User = new User( $udb_userdata ); // COPY! | |
| |
// $user_ID = $userdata_2['ID']; | |
// $user_nickname = $userdata['user_nickname']; | |
// $user_email = $userdata['user_email']; | |
// $user_url = $userdata['user_url']; | |
| |
debug_log('udb login: ' . $udb_current_User->login); | |
debug_log('udb groupe: ' .$udb_current_User->Group->ID); | |
debug_log('udb level: ' . $udb_current_User->level); | |
| |
// Even if in b2evolution, a user can be inside only one group at the same time, we use an array for groups to respects cpg functions | |
// Define the groups | |
$USER_DATA['groups'] = array(); | |
switch ($udb_current_User->Group->ID) { | |
case B2EVO_ADMIN_GROUP: // 1 | |
$USER_DATA['groups'][0] = CPG_ADMIN_GROUP; // 1 | |
break; | |
case B2EVO_PRIV_BLOGGERS_GROUP: // 2 | |
$USER_DATA['groups'][0] = 2; // a definir | |
break; | |
case B2EVO_BLOGGERS_GROUP: //3 | |
$USER_DATA['groups'][0] = 3; // a definir | |
break; | |
case B2EVO_BASIC_USERS_GROUP: //4 | |
$USER_DATA['groups'][0] = CPG_ANONYMOUS_GROUP; // 3 | |
break; | |
default: | |
$USER_DATA['groups'][0] = CPG_ANONYMOUS_GROUP; // a verifier | |
break; | |
} | |
debug_log('udb groupe CPG: ' . $USER_DATA['groups'][0]); | |
$USER_DATA = cpgGetUserData($USER_DATA['groups'][0], $USER_DATA['groups'], CPG_ANONYMOUS_GROUP); | |
debug_log('udb groupe CPG: ' . $USER_DATA['groups'][0]); | |
define('USER_ID', $udb_current_User->ID); | |
define('USER_NAME', $udb_current_User->login); // a ameliorer | |
define('USER_GROUP_SET', '(' . $USER_DATA['groups'][0] . ')'); | |
// define('USER_GROUP_SET', '(' . implode(',', $USER_DATA['groups']) . ')'; | |
debug_log('udb groupe set: ' . USER_GROUP_SET); | |
define('USER_IS_ADMIN', ($udb_current_User->Group->ID == B2EVO_ADMIN_GROUP)); | |
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']); | |
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']); | |
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']); | |
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']); | |
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']); | |
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']); | |
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']); | |
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']); | |
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']); | |
} | |
else | |
{ // login is NOT OK: | |
debug_log("udb: login failed"); | |
// Login failed: user is a guest, initialize all the critial user settings | |
// verifier qd anonyme le groupe a mettre | |
$USER_DATA = cpgGetUserData(CPG_ANONYMOUS_GROUP, array(CPG_ANONYMOUS_GROUP), CPG_ANONYMOUS_GROUP); | |
define('USER_ID', 0); | |
define('USER_NAME', 'Anonymous'); | |
define('USER_GROUP_SET', '(' . CPG_ANONYMOUS_GROUP . ')'); | |
define('USER_IS_ADMIN', 0); | |
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']); | |
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']); | |
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']); | |
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']); | |
define('USER_CAN_CREATE_ALBUMS', 0); | |
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']); | |
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']); | |
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']); | |
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']); | |
} | |
| |
// @todo voir si il faut copier udb_current_User dans current_User | |
debug_log('udb: end'); | |
debug_info(); | |
} | |
| |
/* udb_get_user_name(-) | |
Retrieve the name of a user | |
@return string | |
*/ | |
function udb_get_user_name |