这个项目本来承诺在国庆期间发布的,但后来发现,joomla1.5 Native已经是主流,而研究表明CB1.2已经直接采用joomla1.5框架本身的验证插件进行验证,因此,CB组件不再需要——不少呼吁不装CB的朋友们有福了:-)。
因业余时间完成了Wordpress for Ucenter桥接器并应用于公司站点后,感叹于WP代码的清晰和扩展开发的轻松(将在以后介绍思路),我在今天晚上复核了Joomla1.5框架库的所有代码,重新发现了系统架构设计者的伟大,然后完全重写这个方案(将逐步在blog.treeber.com发布)。
当前已经完成/api/uc.php及附带函数文件,应该能够做到在其他应用中的登录、注销、改名、删除用户等动作均反馈到Joomla1.5中。
而从Joomla1.5中同步至应用中,则将以Joomla1.5自动化插件(bot)及CB插件的形式发布(当前在kolidon本地机器的测试版本尚需修改Authenticate插件中内容,正在设法解决。
如上,今天先放出api/uc.php文件,以供急需的朋友调试后使用(即,用户的登录、注册等均应在其他ucenter支持的应用中完成),api目录中尚需要另一个文件func_joomla_cb_user.inc.php,请在http://blog.treeber.com版本2安装说明一文中下载。
安装办法
在configuration.php相同的目录中新增configuration_ucenter.php文件,加一些预定义常量(不推荐在configuration.php中直接加);
注意事项亦主要在保证joomla中用户最大ID小于Ucenter中最大用户ID(Joomla新安装最佳)。
× 特别注意1:
当前代码仅供试验,使用此方案后,您的joomla中的用户密码极可能与实际密码不符!此问题将在此方案的完整版和安装说明放出后得到解决。
× 特别注意2:
目前需要修改源码,文件plugins/authentication/joomla.php中
约88行,将
$testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
改为
if($options['checkpassword']=='skip')
$testcrypt = $crypt;
else
$testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
<!--p /** * UCenter 应用程序接口 for joomla1.5.x版(discuz, xspace等comsenz系程序社区化功能与joomla1.0.x的完美整合) * ucenter for joomla,KOLIDON version 3.1 ucenter支持的各类应用程序中的用户、站内短消息、好友、积分、头像,可自动同步到joomla1.5.x中。 本程序基于comsenz 提供的ucenter开放的API接口进行开发,安装请参见作者个人站点。 * @Author: kolidon@gmail.com * @Site: http://blog.treeber.com * licensing under CCA3.0 **/ define('UC_VERSION', '1.0.0'); //UCenter 版本标识 define('API_DELETEUSER', 1); //用户删除 API 接口开关 define('API_RENAMEUSER', 1); //用户改名 API 接口开关 define('API_UPDATEPW', 1); //用户改密码 API 接口开关 define('API_GETTAG', 0); //获取标签 API 接口开关 define('API_SYNLOGIN', 1); //同步登录 API 接口开关 define('API_SYNLOGOUT', 1); //同步登出 API 接口开关 define('API_UPDATEBADWORDS', 0); //更新关键字列表 开关 define('API_UPDATEHOSTS', 1); //更新域名解析缓存 开关 define('API_UPDATEAPPS', 1); //更新应用列表 开关 define('API_UPDATECLIENT', 1); //更新客户端缓存 开关 define('API_UPDATECREDIT', 0); //更新用户积分 开关 define('API_GETCREDITSETTINGS', 1); //向 UCenter 提供积分设置 开关 define('API_UPDATECREDITSETTINGS', 0); //更新应用积分设置 开关 define('API_RETURN_SUCCEED', '1'); define('API_RETURN_FAILED', '-1'); define('API_RETURN_FORBIDDEN', '-2'); //error_reporting(E_ALL); //joomla library include files check this constant; define( '_VALID_MOS', 1 ); define('UC_API', 1); define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc()); define('S_ROOT', substr(dirname(__FILE__), 0, -3)); define('UC_CLIENT_ROOT', S_ROOT.'./uc_client/'); include_once('func_joomla_cb_user.inc.php'); define( '_JEXEC', 1 ); define('JPATH_BASE', S_ROOT ); define( 'DS', DIRECTORY_SEPARATOR ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); $mainframe =& JFactory::getApplication('site'); $mainfram-->initialise(); $database = & JFactory::getDBO(); include_once(UC_CLIENT_ROOT.'./client.php'); //var_dump($database); $code = $_GET['code']; parse_str(uc_authcode($code, 'DECODE', UC_KEY), $get); if(MAGIC_QUOTES_GPC) { $get = dstripslashes($get); } if(time() - $get['time'] > 3600) { exit('Authracation has expiried'); } if(empty($get)) { exit('Invalid Request'); } $action = $get['action']; $timestamp = time(); if($action == 'test') { exit(API_RETURN_SUCCEED); } elseif($action == 'deleteuser') { !API_DELETEUSER && exit(API_RETURN_FORBIDDEN); //删除用户 API 接口 $uids = $get['ids']; //todo:: clean all the content\pictures\files\videos, set their userid to 0 //delete the user in joomla systable and comprofiler $database->setQuery("DELETE FROM #__users WHERE id IN ($uids);"); $database->query(); $database->setQuery("select aro_id FROM #__core_acl_aro WHERE value IN ($uids);"); $aro_id = $database->loadResult(); $database->setQuery("DELETE FROM #__core_acl_groups_aro_map WHERE aro_id IN ($aro_id);"); $database->query(); $database->setQuery("DELETE FROM #__core_acl_aro WHERE `value` IN ($uids);"); $database->query(); $database->setQuery("DELETE FROM #__comprofiler WHERE user_id IN ($uids);"); $database->query(); exit(API_RETURN_SUCCEED); } elseif($action == 'renameuser') { !API_RENAMEUSER && exit(API_RETURN_FORBIDDEN); //用户改名 API 接口 $id = $get['uid']; $usernamenew = $get['newusername']; $activeuser = uc_get_user($id, 1); //todo, the very first,we need to syn all the user table to prevent the username or id collision //Now we imagine everything is ok //if joomla user not exsits, add it checkuserexists_user($activeuser); $database->setQuery("update #__users set username='$usernamenew' WHERE id IN ($id);"); $database->query(); //if user in comprofiler not exsits, add it checkuserexists_comprofiler($activeuser); exit(API_RETURN_SUCCEED); } elseif($action == 'updatepw') { !API_UPDATEPW && exit(API_RETURN_FORBIDDEN); //此处问题在于更新的ucenter版本中已经不再提供password //因此,问题留待本地登录同步成功通知ucenter前重生成,或索性将joomla1.5中密码废弃 //若废弃密码,则用户在joomla1.5中登录时,应向ucenter查询用户密码正确性 $username = $get['username']; $password = $get['password']; $activeuser = uc_get_user($username); checkuserexists_user($activeuser); checkuserexists_comprofiler($activeuser); $database->setQuery("update #__users set password='". md5($password) ."' WHERE username ='$username';"); $database->query(); //遗留代码 exit(API_RETURN_SUCCEED); } elseif($action == 'synlogin' && $_GET['time'] == $get['time']) { //echo "hello"; !API_SYNLOGIN && exit(API_RETURN_FORBIDDEN); //同步登录 API 接口 $id = intval($get['uid']); // is uer exists? $activeuser = uc_get_user($id, 1); checkuserexists_user($activeuser); checkuserexists_comprofiler($activeuser); $database->setQuery("select username, password from #__users where id=$id"); list($username, $password) = $database->loadRow(); //exit($username.$password); header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); $mainframe->login( array( 'username' => $username, 'password' => $password ), array( 'checkpassword' => 'skip' ) ); exit(API_RETURN_SUCCEED); } elseif($action == 'synlogout') { !API_SYNLOGOUT && exit(API_RETURN_FORBIDDEN); //同步登出 API 接口 //当前应不需去除session表中记录 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); // needed for IE6 to accept this anti-spam cookie in higher security setting. $mainframe->logout(); } else { exit(API_RETURN_FAILED); } function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) { $ckey_length = 4; $key = md5($key ? $key : UC_KEY); $keya = md5(substr($key, 0, 16)); $keyb = md5(substr($key, 16, 16)); $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; $cryptkey = $keya.md5($keya.$keyc); $key_length = strlen($cryptkey); $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; $string_length = strlen($string); $result = ''; $box = range(0, 255); $rndkey = array(); for($i = 0; $i <= 255; $i++) { $rndkey[$i] = ord($cryptkey[$i % $key_length]); } for($j = $i = 0; $i < 256; $i++) { $j = ($j + $box[$i] + $rndkey[$i]) % 256; $tmp = $box[$i]; $box[$i] = $box[$j]; $box[$j] = $tmp; } for($a = $j = $i = 0; $i < $string_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $tmp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $tmp; $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); } if($operation == 'DECODE') { if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) { return substr($result, 26); } else { return ''; } } else { return $keyc.str_replace('=', '', base64_encode($result)); } } function dsetcookie($var, $value, $life = 0, $prefix = 1) { global $cookiedomain, $cookiepath, $timestamp, $_SERVER; setcookie($var, $value, $life ? $timestamp + $life : 0, $cookiepath, $cookiedomain, $_SERVER['SERVER_PORT'] == 443 ? 1 : 0); } function dstripslashes($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dstripslashes($val); } } else { $string = stripslashes($string); } return $string; }

关注WEB应用系统架构,侧重效能、可用性研究。欢迎访问treeber.com查看本站整理自网络的非原创精华(筹建中)。
black
October 9th, 2008 at 6:53 pm
你太伟大了!!!!!
black
October 9th, 2008 at 8:03 pm
Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in C:\ComsenzEXP\wwwroot\Joomla\configuration.php on line 54
这个是什么意思?
我是本地测试ucenter和joomla
black
October 9th, 2008 at 8:03 pm
ufonba
October 9th, 2008 at 10:22 pm
想不到我才没上几天,就发现LZ的BLOG有了巨大变化。沙发坐不到,拿块地板走也好。
kolidon
October 10th, 2008 at 11:40 pm
black,方便的话能否将你的configuration.php贴在这儿?
太帅了
October 11th, 2008 at 2:53 am
终于等来好消息!
freeman
October 15th, 2008 at 4:10 pm
感谢啊!
希望作者能再完善代码,期待正式版,那时马上开始整合咯!
还有一定要跟进DZ的步伐呀,DISCUZ 7.0已经出了!~
urbest
October 16th, 2008 at 8:09 am
特别想请教一下:如果想让登陆时保持“remember”状态,该怎么办呢?一般discuz登陆都会保持状态,如果joomla关闭浏览器就没有登陆状态了会比较麻烦,谢谢博主的辛勤工作给广大j友带来的福音
keung
October 23rd, 2008 at 1:39 pm
pls 跟进DZ的步伐,DISCUZ 7.0已经出了!
+1
thanks!
black
October 25th, 2008 at 10:31 am
不好意思 最近出差 没来看你的blog 谢谢回应 我先再桥接一次 再出现问题的话再来请教你
jmdog
October 29th, 2008 at 5:07 pm
兄弟,加油啊,千千万万人民都 支持你干 这事
Japhy
November 1st, 2008 at 8:58 am
DZ7.0好像只是官方测试,程序应该还没有释出吧!
zob1ch
November 11th, 2008 at 3:00 pm
where can I get the api and plugin for j 1.5.x and discuz 6.1 integration?
zob1ch
November 11th, 2008 at 3:03 pm
oh and can it be done without community builder - just native integration of joomla 1.5.x and discuz 6.1 ?
zob1ch
November 13th, 2008 at 3:08 pm
pleeease write a normal instruction ((( where to put api, which config file to edit... didn't understand about configuration.php and configuration_ucenter.php - are they supposed to be in one directory? what do I put to *_ucenter.php
zob1ch
November 13th, 2008 at 7:56 pm
請寫一步一步的指示版本j1.5.x + d6.1.0一體化
zob1ch
November 14th, 2008 at 4:02 pm
看看 http://www.discuz.net/viewthread.php?tid=1109381&highlight=joomla
kolidon
November 24th, 2008 at 6:18 pm
Thanks for your appreciation. I'll publish all the code (api, joomla plugin and joomla hack), and write a handbook sometimes when I pull through my company project.
flysnoiwnger
December 10th, 2008 at 1:10 pm
老大你太有才啦。
hibaby
December 11th, 2008 at 10:02 am
期待,祝你公司项目早日完工,好能给大家带来好消息
Dark.a
December 11th, 2008 at 5:23 pm
discuz 7.0 什么时候有时间再写个教材呢,数千人等候你的成果呢。
支持,
freeman
December 15th, 2008 at 1:15 pm
还在苦苦等等与DZ 7.0的整合完美版。
如果作者收费也是完全支持的!
ufonba
December 23rd, 2008 at 8:08 pm
好久没见更新了。
at
January 1st, 2009 at 5:16 pm
新年新气象,期待有好消息
xiaoxiao
February 26th, 2009 at 4:08 pm
按上面的步骤做了,也没出错,但discuz6.1.0与joomla1.5.6未能实现同步登录与登出,当往joomla里注册的用户,登录成功后,discuz6没有登录,如果往其手动登录joomla里注册的用户,discuz则报,用户名无效。。。。
这该怎么办,期待博主及把有知道的朋友的高见....
蝎子
May 19th, 2009 at 7:23 am
wp整合ucenter的思路可以说一下么? 或者干脆共享下源码吧 XD
qidai
May 19th, 2009 at 1:02 pm
期待老大的插件放出~~~