简单生活
返回文章列表
646 字4 分钟

将 UCenter 事件导入 Discuz! X1.5 家园

设计开发#Discuz/ucenter

最初做站便是从 Discuz! 开始,还记得当年用的版本是 6.0,论坛关闭以后便没再继续使用。两年多过去了,现在的版本已经发展到了 Discuz! X1.5。可以说 Discuz! X1.5 将 UCHome 和 Discuz! 论坛很好的整合在了一起。

UCenter 对于站长来说是个很好的平台和工具,利用 UCenter 可以将很多程序的会员系统整合在一起,不仅仅是会员系统,还包括用户事件(feed)、短消息等。

一直使用 UCenter 整合使用 hdwiki、phpcms 等程序,最近开始测试 Discuz! X1.5。一段时间后发现 UCenter 后台中的用户事件积累了很长的列表,没有通知到 Discuz! X 的家园。到 dz 论坛去找答案,发现很多人有我同样的问题,不过都没有很好的办法解决,无奈之下,只好自己动手。

从论坛中得知 UCHome 可以显示 UCenter 中其他应用的事件,研究了相关代码后发现,UCHome 通过程序的计划任务定时获取 UCenter 中的事件并导入到 UCHome 数据库,某个目录下 cron/getfeed.php 的脚本,而 Discuz! X 的计划任务中则没有这一项。

那么我们只需要改造一下这个脚本,让它在 Discuz! X 下工作就可以了,还是不废话了,直接贴出源码:

<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
//从uc获取feed
include_once(DISCUZ_ROOT.'./config/config_UCenter.php');
include_once(DISCUZ_ROOT.'./uc_client/client.php');
//去掉slassh
function sstripslashes($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = sstripslashes($val);
}
} else {
$string = stripslashes($string);
}
return $string;
}
if($results = uc_feed_get(10)) {//每次取10个
$cols = array('uid','username','appid','icon','dateline','hash_template','hash_data','title_template','title_data','body_template','body_data','body_general','image_1','image_1_link','image_2','image_2_link','image_3','image_3_link','image_4','image_4_link','target_ids');
$inserts = array();
foreach ($results as $value) {
if(empty($value['uid']) || empty($value['username'])) continue;
$vs = array();
foreach ($cols as $key) {
if(is_array($value[$key])) {
//数组处理
$value[$key] = addslashes(serialize(sstripslashes($value[$key])));
} else {
$value[$key] = addslashes(sstripslashes($value[$key]));
}
$vs[] = '\''.$value[$key].'\'';
}
$inserts[] = '('.implode(',', $vs).')';
}
//入库
if($inserts) {
DB::query("INSERT INTO ".DB::table('home_feed')." (`".implode('`,`', $cols)."`) VALUES ".implode(',', $inserts));
}
}
?>

保存上面的代码另存为 getfeed.php,上传至 /source/include/cron/ ,再到后台去添加一个自定义的计划任务,可以自由设定多久执行一次。

下载地址:/zb_users/upload/2011/2/getfeed.rar

最后说说 dz 的计划任务,这不是 linux 的 cron,而是一个伪 cron,wordpress 中也有类似的伪 cron,没有进一步仔细研究这个计划任务是怎样实现的。

历史留言归档

10
静态只读归档
杜
杜保华
更新了,赶紧来占个沙发
S
spraygun
ucenter 原来有这个作用啊,我的去本地服务器试验一下。
P
palm
不仔细一看,还经为是新浪博客呢。
L
lzh
不能用,有错误,一运行就报错:<br/><br/>UCenter info: MySQL Query Error<br/>SQL:SELECT * FROM [Table]notelist WHERE closed='0' AND app1&lt;'1' AND app1&gt;'-5' LIMIT 1<br/>Error:Unknown column 'app1' in 'where clause'<br/>Errno:1054
博
狼的旋律博主
不好意思,帮不了你,这个脚本在我的站上运行的很好
西
西楚中国风
这个写的很详细,测试一下!
逍
逍遥鱼
按照的你提示设置了,但是没有成功!我在hdwiki上新增词条,discuz!x1.5家园还是没有事件通知。求解!我已经发邮件到你邮箱,有空请回复一下,谢谢!<br/><br/> 地址:http://www.yibo.org/home.php<br/> http://baike.yibo.org/index.php
K
KH
这个伪cron是靠用户访问网站实现的
博
狼的旋律博主
呵呵,已经解决了[F]Misdoubt[/F]
博
狼的旋律博主
受教了[F]Adore[/F]