1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

Textpattern中调用 近期评论 能不能不用 用户名(文章标题) 的方式。

本帖由 DKEN2008-09-13 发布。版面名称:源码讨论

  1. DKEN

    DKEN Well-Known Member

    注册:
    2006-08-07
    帖子:
    3,358
    赞:
    33
    Textpattern中调用 近期评论 能不能不用 用户名(文章标题) 的方式。
    见下面地址的左边
    http://www.luweiqing.com/article/332/about-education-something
    Recent comments
    * 锐风 (在多浏览器使用silverlight的遇到若干问题)
    * 锐风 (PyWordPress)
    * inso (PyWordPress)
    * lee (PyWordPress)
    * inso (中国雅虎推出邮件客户端)

    怎样才可以直接调用讨论内容??!!
     
  2. fen

    fen New Member

    注册:
    2005-12-18
    帖子:
    3,050
    赞:
    25
  3. DKEN

    DKEN Well-Known Member

    注册:
    2006-08-07
    帖子:
    3,358
    赞:
    33
    THANK Fen

    收藏ING,,
     
  4. DKEN

    DKEN Well-Known Member

    注册:
    2006-08-07
    帖子:
    3,358
    赞:
    33
    关于这个插件的一点小改进。
    这个的插件的评论链接是该评论文章的标题。
    如下面加上红色代码后
    评论链接就会在评论文章的标题后面回评论编号(#c000000)
    也就是评论链接和官方的一样。

    代码:
    function wyn_recent_comments ($atts, $thing) {
    	extract (lAtts (array (
    		'class'    => __FUNCTION__,
    		'wraptag' => 'ul',
    		'break'  => 'li',
    		'label' => '',
    		'labeltag' => '',
    		'limit'    => 10,
    		'wordcount' => 10,
    		'messagebreak' => '...',
    		'format' => '%content%',
    		'atitle' => '%commenter% on %time%',
    		'section' => '',
    		'timeformat' => '%d %b %Y · %X',
    		), $atts));
    
    	/* create sql things */
    	$cols = 'discussid, ID, name, unix_timestamp(txp_discuss.posted) as time, message, Title';
    	$tables = safe_pfx_j ('txp_discuss, textpattern');
    	$where = 'parentid=ID and visible=1' . ('' == trim ($section) ? '' : " and Section='$section'") . ' order by time desc limit ' . $limit;
    
    	$sql = 'SELECT ' . $cols . ' FROM ' . $tables . ' WHERE ' . $where . ';';
    
    	$rs = startRows ($sql);
    	if ($rs) {
    		$out = array ();
    		while ($o = nextRow ($rs)) {
    			extract ($o);
    
    			$time = safe_strftime($timeformat, $time);
    
    			/* 0 if for no limit */
    			if ($wordcount != 0) {
    				$message = trim (doStripTags ($message));
    				$message = utf8_substr ($message, 0, $wordcount, $messagebreak);
    			}
    
    			$atitleattr = preg_replace ('/%title%/', $Title, $atitle);
    			$atitleattr = preg_replace ('/%commenter%/', $name, $atitleattr);
    			$atitleattr = preg_replace ('/%time%/', $time, $atitleattr);
    			$atitleattr = preg_replace ('/%content%/', $message, $atitleattr); /* who will use content here ??? */
    
    			$cont = preg_replace ('/%title%/', $Title, $format);
    			$cont = preg_replace ('/%commenter%/', $name, $cont);
    			$cont = preg_replace ('/%time%/', $time, $cont);
    			$cont = preg_replace ('/%content%/', $message, $cont);
    
    			$link = '<a href="' . permlinkurl_id ($ID) . '#c' . $discussid . '" title="' . $atitleattr . '">' . $cont . '</a>';
    
    			$out[] = $link;
    		}
    
    		return doLabel ($label, $labeltag) . doWrap ($out, $wraptag, $break, $class);
    	}
    }
    
    function utf8_substr($string, $start, $length, $wordbreak) {
    	/* just return original thing if length is 0 or less than 0 */
    	if ($length <= 0) {
    		return $string;
    	}
    
    	preg_match_all ('/[\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF][\x80-\xBF]|[\xF0-\xF4][\x80-\xBF][\x80-\xBF][\x80-\xBF]/', $string, $rs);
    
    	$out = '';
            $size = count ($rs[0]);
    
    	$end = $start + $length;
    	if ($end > $size - 1) {
    		$end = $size;
    	}
    
    	for ($i = $start; $i < $end; $i++) {
          	        $out .= $rs[0][$i];
    	}
    
    	if ($end < $size - 1) {
    		$out .= $wordbreak;
    	}
    
    	return $out;
    }
    :)
     
  5. ANBYS

    ANBYS New Member

    注册:
    2010-05-23
    帖子:
    39
    赞:
    0
    多谢分享。
     
  6. vipeaksally

    vipeaksally New Member

    注册:
    2013-12-02
    帖子:
    15
    赞:
    0
    4楼回复的很好
     
  7. lunzuo

    lunzuo New Member

    注册:
    2012-09-28
    帖子:
    171
    赞:
    0
    好像火星文。。