用户注册 登录
珍珠湾全球网 返回首页

岳东晓 -- 珍珠湾全球网 ... http://ydx.zzwave.com [收藏] [复制] [分享] [RSS] 岳东晓 -- 珍珠湾全球网

日志

DISCUZ X 日志同步到论坛的部分代码

热度 4已有 10731 次阅读2012-11-4 02:07 |系统分类:科技| 博客, 论坛

真正的程序员都是尽量偷懒的,能少些一个字不愿多写一个,最烦的是打字速度低于思考速度。在简洁方面,PERL还是比PHP强多了。这个DISCUZ日志同步到论坛与微博的功能用PERL大概400行代码就搞定了。下面是部分代码

sub sync_blogs_to_forum {
        my ($bids, $fid, $mic,  $pend, $ipover) = @_;
        for my $bid(@$bids) {
                next if not $bid;
                my ($s, $c, $cs, $post, $uid, $ip) =  get_post_from_blog($bid);
                if ($CFG{gtest} && $c)  {
                        print "Content $post <br>" ;
                        next;
                }
                my $bsrc ="blog:$bid";
                my $destloc ='';
                my $rec=undef;
                                        
                eval {
                        my $tid=0;
                        if($fid >0) {
                                        $destloc = "forum:$fid";
                                        $rec = check_sync_status($bsrc, $destloc);
                                        if(not ref($rec)) {
                                                $tid = add_post($fid, $s, $post,  $uid, $ipover||$ip);
                                                set_sync_status($bsrc, $destloc, $tid) if $tid;
                                        }else {   
                                                $tid = $rec->[0];
                                        }
                                        print qq!Added <a href="/forum.php?mod=viewthread\&tid=$tid">$s</a><p>! if $tid;
                
                        }else {
                                #print "No sync forum<p>";
                        }
                        if($mic) {
                                        $destloc = "mblog";
                                        $rec = check_sync_status($bsrc, $destloc);
                                        my $mid;
        
                                        my $msg = substr($cs, 0, 128);
                                        $msg .= qq! -- <a href="/blog-$uid-$bid.html">$s</a>!;
                                        if((not ref($rec)) || (time()-$rec->[1])>24*3600) {
                                                $mid = add_microblog($msg,  $uid, $ipover||$ip);
                                                set_sync_status($bsrc, $destloc, $mid) if $mid;
                                        }else {
                                                $mid = $rec->[0];
                                        }
                                        print "$msg<p>Posted MID=$mid <br>" if  $mid;
                        }else {
                                #print "No sync mic<p>";
                        }
                };
                if($@) {
                        print "Error: $@<br>" ;
                }
        }
}


路过

鸡蛋
2

鲜花

支持

雷人

难过

搞笑

刚表态过的朋友 (2 人)

 

发表评论 评论 (4 个评论)

回复 往事并不如烟 2012-11-4 02:38
    
回复 cat 2012-11-4 03:41
往事并不如烟:      
  
回复 往事并不如烟 2012-11-4 04:14
cat:   
真晕啊~~
回复 蓝天绿地 2012-11-4 04:30
I like PERL

facelist

您需要登录后才可以评论 登录 | 用户注册

Archiver|手机版|珍珠湾全球网

GMT+8, 2024-4-27 13:39 , Processed in 0.021981 second(s), 8 queries , Apc On.

Powered by Discuz! X2.5

回顶部