<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Terrysco&#039;s Blog &#187; userpoints</title>
	<atom:link href="http://www.terrysco.com/node/tag/userpoints/feed" rel="self" type="application/rss+xml" />
	<link>http://www.terrysco.com</link>
	<description>仅关注于互联网行业， Linux平台开发。</description>
	<lastBuildDate>Sat, 05 Nov 2011 21:24:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>用drupal和userpoints实现百度知道的基本功能</title>
		<link>http://www.terrysco.com/node/drupal-and-userpoints-zhidao.html</link>
		<comments>http://www.terrysco.com/node/drupal-and-userpoints-zhidao.html#comments</comments>
		<pubDate>Thu, 11 Dec 2008 20:00:18 +0000</pubDate>
		<dc:creator>terrysco</dc:creator>
				<category><![CDATA[CMS/FrameWork]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[userpoints]]></category>
		<category><![CDATA[百度知道]]></category>

		<guid isPermaLink="false">http://www.anyliv.com/www.terrysco.com/?p=69</guid>
		<description><![CDATA[<p>百度知道的基本系统有发布问题，回答问题，积分悬赏和选择答案这几项，现在我们用drupal来模拟它。其中积分我们使用的是userpoint接口，把知道系统的积分和用户积分合成到一起。而答题系统用drupal的评论系统，做一些更改和界面定制就行了，这里需要在template.php中向comment的hook传递一些变量，比如哪个评论id是最佳答案等等。</p><p>这里我们把知道作为一个新的节点类型，但没有用cck手动创建（因为需要定制的东西太多），而是直接用代码实现。</p><p>首先，创建这个模块的install文件，表结构如下：</p>...
]]></description>
			<content:encoded><![CDATA[<p>百度知道的基本系统有发布问题，回答问题，积分悬赏和选择答案这几项，现在我们用drupal来模拟它。其中积分我们使用的是userpoint接口，把知道系统的积分和用户积分合成到一起。而答题系统用drupal的评论系统，做一些更改和界面定制就行了，这里需要在template.php中向comment的hook传递一些变量，比如哪个评论id是最佳答案等等。</p>
<p>这里我们把知道作为一个新的节点类型，但没有用cck手动创建（因为需要定制的东西太多），而是直接用代码实现。</p>
<p>首先，创建这个模块的install文件，表结构如下：</p>
<p>function zhidao_install() {<br />&nbsp; switch ($GLOBALS['db_type']) {<br />&nbsp;&nbsp;&nbsp; case&#8217;mysql&#8217;:<br />&nbsp;&nbsp;&nbsp; case&#8217;mysqli&#8217;:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db_query(&quot;CREATE TABLE {zhidao} (<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nid int unsigned NOT NULL default &#8217;0&#8242;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vid int unsigned NOT NULL default &#8217;0&#8242;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; product_nid int unsigned NOT NULL default &#8217;0&#8242;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; offer_points int unsigned NOT NULL default &#8217;0&#8242;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; additional_points int unsigned NOT NULL default &#8217;0&#8242;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; best_cid int unsigned NOT NULL default &#8217;0&#8242;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRIMARY KEY(nid, vid),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UNIQUE KEY vid(vid),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KEY nid(nid)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) /*!40100 DEFAULT CHARACTER SET UTF8 */&quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br />&nbsp; }<br />}<br />/**<br />&nbsp;* Implementation of hook_uninstall().<br />*/<br />function zhidao_uninstall() {<br />&nbsp; db_query(&#8216;DROP TABLE {zhidao}&#8217;);<br />}</p>
<p>模块文件如下：</p>
<p>&lt;?php<br />/*<br />&nbsp;* @file<br />&nbsp;* 54user Zhidao system.<br />&nbsp;*/<br />&nbsp;<br />/**&nbsp;<br />&nbsp;* Implementation of hook_node_info().&nbsp;<br />&nbsp;*/&nbsp;<br />function zhidao_node_info() {&nbsp;<br />&nbsp; // We return an array since a module can define multiple node types.&nbsp;<br />&nbsp; // We&#8217;re only defining one node type, type &#8216;zhidao&#8217;.&nbsp;<br />&nbsp; return array(&nbsp;<br />&nbsp;&nbsp;&nbsp; &#8216;zhidao&#8217; =&gt; array(&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;name&#8217; =&gt; &#8216;知道&#8217;, // Required.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;module&#8217; =&gt; &#8216;zhidao&#8217;, // Required.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;description&#8217; =&gt; &#8216;模仿百度知道系统&#8217;, // Required.&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;has_title&#8217; =&gt; TRUE,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;title_label&#8217; =&gt; &#8216;问题&#8217;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;has_body&#8217; =&gt; TRUE,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;body_label&#8217; =&gt; &#8216;问题&#8217;,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;locked&#8217; =&gt; TRUE&nbsp;<br />&nbsp;&nbsp;&nbsp; )&nbsp;<br />&nbsp; );&nbsp;<br />}&nbsp;<br />&nbsp;<br />/*<br />&nbsp;* Implementation of hook_menu().&nbsp;<br />&nbsp;*/<br />function zhidao_menu($may_cache) {<br />&nbsp; $items = array();<br />&nbsp;&nbsp;<br />&nbsp; if ($may_cache) {<br />&nbsp;&nbsp;&nbsp; $items[] = array(&#8216;path&#8217; =&gt; &#8216;zhidao/best&#8217;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;title&#8217; =&gt; t(&#8216;select the best answer&#8217;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;type&#8217; =&gt; MENU_CALLBACK,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;callback&#8217; =&gt; &#8216;zhidao_best_page&#8217;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;access&#8217; =&gt; TRUE, // pending.<br />&nbsp;&nbsp;&nbsp; );<br />&nbsp; }<br />&nbsp; else {<br />&nbsp;&nbsp;&nbsp; // Do not cache this menu item during the development of this module.<br />&nbsp;&nbsp;&nbsp; $items[] = array(&#8216;path&#8217; =&gt; &#8216;node/add/zhidao&#8217;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;title&#8217; =&gt; t(&#8216;Zhidao&#8217;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;access&#8217; =&gt; user_access(&#8216;create zhidao&#8217;),<br />&nbsp;&nbsp;&nbsp; );<br />&nbsp; }<br />&nbsp; return $items;<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_perm().<br />&nbsp;*/<br />function zhidao_perm() {<br />&nbsp; return array(&#8216;create zhidao&#8217;, &#8216;edit own zhidao&#8217;, &#8216;do zhidao&#8217;);<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_access().<br />&nbsp;*/<br />function zhidao_access($op, $node) {<br />&nbsp; global $user;<br />&nbsp; if ($op == &#8216;create&#8217;) {<br />&nbsp;&nbsp;&nbsp; return (user_access(&#8216;create zhidao&#8217;));<br />&nbsp; }<br />&nbsp; if ($op == &#8216;update&#8217; || $op == &#8216;delete&#8217;) {<br />&nbsp;&nbsp;&nbsp; return (user_access(&#8216;edit own zhidao&#8217;) &amp;&amp; ($user-&gt;uid == $node-&gt;uid));<br />&nbsp; }<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_form().<br />&nbsp;*/<br />function zhidao_form($node) {<br />&nbsp;<br />&nbsp; global $user;<br />&nbsp;&nbsp;<br />&nbsp; if (&#8216;node&#8217; == arg(0) &amp;&amp; &#8216;add&#8217; == arg(1) &amp;&amp; &#8216;zhidao&#8217; == arg(2) &amp;&amp; is_numeric(arg(3))) {<br />&nbsp;&nbsp;&nbsp; $product = node_load(arg(3));<br />&nbsp; }<br />&nbsp; $form = array();<br />&nbsp; if ($product) {<br />&nbsp;&nbsp;&nbsp; $form['product_nid'] = array(&#8216;#type&#8217; =&gt; &#8216;value&#8217;, &#8216;#value&#8217; =&gt; $product-&gt;nid);<br />&nbsp;&nbsp;&nbsp; $form['product_name'] = array(&#8216;#prefix&#8217; =&gt; &#8216;&lt;h3 class=&quot;head&quot;&gt;&#8217;, &#8216;#value&#8217; =&gt; &#8216;产品名称: &#8216; .check_plain($product-&gt;title), &#8216;#suffix&#8217; =&gt; &#8216;&lt;/h3&gt;&#8217;);<br />&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp; // Get metadata for this node type<br />&nbsp; // (we use it for labeling title and body fields).<br />&nbsp; // We defined this in zhidao_node_info().<br />&nbsp; $type = node_get_types(&#8216;type&#8217;, $node);<br />&nbsp; $form['#theme'] = &#8216;zhidao_form&#8217;;<br />&nbsp; $form['title'] = array(<br />&nbsp;&nbsp;&nbsp; &#8216;#type&#8217; =&gt; &#8216;textfield&#8217;,<br />&nbsp;&nbsp;&nbsp; &#8216;#title&#8217; =&gt; check_plain($type-&gt;title_label),<br />&nbsp;&nbsp;&nbsp; &#8216;#required&#8217; =&gt; TRUE,<br />&nbsp;&nbsp;&nbsp; &#8216;#default_value&#8217; =&gt; $node-&gt;title,<br />&nbsp;&nbsp;&nbsp; &#8216;#weight&#8217; =&gt; -5<br />&nbsp; );<br />&nbsp; $form['body_filter']['filter'] = filter_form($node-&gt;format);<br />&nbsp;&nbsp;<br />&nbsp; $options = array();<br />&nbsp; for ($i = 0; $i &lt;= 100; $i+=20) {<br />&nbsp;&nbsp;&nbsp; $options[$i] = $i;<br />&nbsp; }<br />&nbsp; $form['current_user_points'] = array(<br />&nbsp;&nbsp;&nbsp; &#8216;#value&#8217; =&gt; &#8216;你的积分： &lt;span class=&quot;new&quot;&gt;&#8217;. userpoints_get_current_points($user-&gt;uid) .&#8217;&lt;/span&gt;&#8217;,<br />&nbsp; );<br />&nbsp; $form['offer_points'] = array(<br />&nbsp;&nbsp;&nbsp; &#8216;#type&#8217; =&gt; &#8216;select&#8217;,<br />&nbsp;&nbsp;&nbsp; &#8216;#title&#8217; =&gt; &#8216;悬赏积分&#8217;,<br />&nbsp;&nbsp;&nbsp; &#8216;#options&#8217; =&gt; $options,<br />&nbsp;&nbsp;&nbsp; &#8216;#default_value&#8217; =&gt; $node-&gt;offer_points,<br />&nbsp;&nbsp;&nbsp; &#8216;#weight&#8217; =&gt; 5<br />&nbsp; );<br />&nbsp; return $form;<br />}<br />&nbsp;<br />function theme_zhidao_form($form) {<br />&nbsp;<br />&nbsp; $output = ”;<br />&nbsp; $output .= drupal_render($form['product_name']);&nbsp;<br />&nbsp;&nbsp;<br />&nbsp; $output .= &#8216;&lt;div id=&quot;zhidao_form&quot;&gt;&#8217;;<br />&nbsp;&nbsp;<br />&nbsp; $output .= &#8216;&lt;div id=&quot;zhidao_similar_question&quot;&gt;&lt;/div&gt;&#8217;;<br />&nbsp; $output .= drupal_render($form);<br />&nbsp; $output .= &#8216;&lt;/div&gt;&#8217;;<br />&nbsp;&nbsp;<br />&nbsp; return $output;<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_validate().<br />&nbsp;*/<br />function zhidao_validate($node) {<br />&nbsp; global $user;<br />&nbsp; $current_user_points = userpoints_get_current_points($user-&gt;uid);<br />&nbsp;<br />&nbsp; // Enforce a minimum word length of 3.<br />&nbsp; if (isset($node-&gt;offer_points) &amp;&amp; $node-&gt;offer_points &gt; $current_user_points) {<br />&nbsp;&nbsp;&nbsp; form_set_error(&#8216;offer_points&#8217;, t(&#8216;you do not have enough points.&#8217;));<br />&nbsp; }<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_insert().<br />&nbsp;*/<br />function zhidao_insert($node) {<br />&nbsp; db_query(&quot;INSERT INTO {zhidao} (nid, vid, product_nid, offer_points) VALUES (%d, %d, %d, %d)&quot;, $node-&gt;ni<br />
d, $node-&gt;vid, $node-&gt;product_nid, (int) $node-&gt;offer_points);<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_update().<br />&nbsp;*/<br />function zhidao_update($node) {<br />&nbsp; if ($node-&gt;revision) {<br />&nbsp;&nbsp;&nbsp; zhidao_insert($node);<br />&nbsp; }<br />&nbsp; else {<br />&nbsp;&nbsp;&nbsp; db_query(&quot;UPDATE {zhidao} SET offer_points = %d WHERE vid = %d&quot;, (int) $node-&gt;offer_points, $node-&gt;vid);<br />&nbsp; }<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_delete().<br />&nbsp;*/<br />function zhidao_delete(&amp;$node) {<br />&nbsp; // Delete the related information we were saving for this node.<br />&nbsp; db_query(&#8216;DELETE FROM {zhidao} WHERE nid = %d&#8217;, $node-&gt;nid);<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_load().<br />&nbsp;*/<br />function zhidao_load($node) {<br />&nbsp; return db_fetch_object(db_query(&#8216;SELECT offer_points FROM {zhidao} WHERE vid = %d&#8217;,<br />$node-&gt;vid));<br />}<br />&nbsp;<br />/**<br />&nbsp;* Implementation of hook_view().<br />&nbsp;*/<br />function zhidao_view($node, $teaser = FALSE, $page = FALSE) {<br />&nbsp; if (!$teaser) {<br />&nbsp;&nbsp;&nbsp; // Use Drupal&#8217;s default node view.<br />&nbsp;&nbsp;&nbsp; $node = node_prepare($node, $teaser);<br />&nbsp;&nbsp;&nbsp; $node-&gt;content['offer_points'] = array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;#value&#8217; =&gt; theme(&#8216;zhidao_offer_points&#8217;, $node),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;#weight&#8217; =&gt; 2<br />&nbsp;&nbsp;&nbsp; );<br />&nbsp; }<br />&nbsp; if ($teaser) {<br />&nbsp;&nbsp;&nbsp; // Use Drupal&#8217;s default node view.<br />&nbsp;&nbsp;&nbsp; $node = node_prepare($node, $teaser);<br />&nbsp; }<br />&nbsp; return $node;<br />}<br />&nbsp;<br />function theme_zhidao_offer_points($node) {<br />&nbsp; $output = &#8216;&lt;span class=&quot;zhidao_offer_points&quot;&gt;&#8217; .t(&#8216;offer points: @points&#8217;, array(&#8216;@points&#8217; =&gt; $node-&gt;offer_points)). &#8216;&lt;/span&gt;&#8217;;<br />&nbsp; if (user_access(&#8216;do zhidao&#8217;)) {<br />&nbsp;&nbsp;&nbsp; $output .= &#8216;&lt;a href=&quot;#comment-form&quot; class=&quot;do_zhidao&quot;&gt;&lt;/a&gt;&#8217;;<br />&nbsp; }<br />&nbsp; return $output;<br />}<br />&nbsp;<br />function zhidao_additional_points($node, $comment) {<br />&nbsp; $form = array();<br />&nbsp; $best_cid = 0;<br />&nbsp; if (is_numeric(arg(2)) &amp;&amp; &#8216;best&#8217; == arg(1)) {<br />&nbsp;&nbsp;&nbsp; $best_cid = arg(2);<br />&nbsp; }<br />&nbsp; for ($i = 0; $i &lt;= 50; $i+=10) {<br />&nbsp;&nbsp;&nbsp; $options[$i] = $i;<br />&nbsp; }<br />&nbsp; $form['additional_points'] = array(&#8216;#type&#8217; =&gt; &#8216;select&#8217;, &#8216;#options&#8217; =&gt; $options, &#8216;#default_value&#8217; =&gt; 0);<br />&nbsp; $form['submit'] = array(&#8216;#type&#8217; =&gt; &#8216;submit&#8217;, &#8216;#value&#8217; =&gt; t(&#8216;submit&#8217;));<br />&nbsp; $form['offer_points'] = array(&#8216;#type&#8217; =&gt; &#8216;value&#8217;, &#8216;#value&#8217; =&gt; $node-&gt;offer_points);<br />&nbsp; $form['nid'] = array(&#8216;#type&#8217; =&gt; &#8216;value&#8217;, &#8216;#value&#8217; =&gt; $node-&gt;nid);<br />&nbsp; $form['comment_uid'] = array(&#8216;#type&#8217; =&gt; &#8216;value&#8217;, &#8216;#value&#8217; =&gt; $comment-&gt;uid);<br />&nbsp; $form['best_cid'] = array(&#8216;#type&#8217; =&gt; &#8216;value&#8217;, &#8216;#value&#8217; =&gt; $best_cid);<br />&nbsp;&nbsp;<br />&nbsp; return $form;<br />}<br />&nbsp;<br />function zhidao_additional_points_validate($form) {<br />&nbsp; global $user;<br />&nbsp; $current_user_points = userpoints_get_current_points($user-&gt;uid);<br />&nbsp; // Enforce a minimum word length of 3.<br />&nbsp; if ($form['offer_points'] + $form['additional_points'] &gt; $current_user_points) {<br />&nbsp;&nbsp;&nbsp; form_set_error(&#8216;additional_points&#8217;, t(&#8216;you do not have enough points.&#8217;));<br />&nbsp; }<br />}<br />&nbsp;<br />function zhidao_additional_points_submit($form_id, $form_values) {<br />&nbsp;&nbsp;<br />&nbsp; global $user;<br />&nbsp;&nbsp;<br />&nbsp; $points = (int) $form_values['offer_points'] + (int) $form_values['additional_points'];<br />&nbsp;&nbsp;<br />&nbsp; $to = user_load(array(&#8216;uid&#8217; =&gt; $form_values['comment_uid']));<br />&nbsp;<br />&nbsp; $params = array(<br />&nbsp;&nbsp;&nbsp; &#8216;uid&#8217; =&gt; $to-&gt;uid,<br />&nbsp;&nbsp;&nbsp; &#8216;points&#8217; =&gt; $points,<br />&nbsp;&nbsp;&nbsp; &#8216;operation&#8217; =&gt; &#8216;Zhidao: FROM &#8216; . $user-&gt;name,<br />&nbsp; );<br />&nbsp; userpoints_userpointsapi($params);<br />&nbsp;&nbsp;<br />&nbsp; $params = array(<br />&nbsp;&nbsp;&nbsp; &#8216;uid&#8217; =&gt; $user-&gt;uid,<br />&nbsp;&nbsp;&nbsp; &#8216;points&#8217; =&gt; -$points,<br />&nbsp;&nbsp;&nbsp; &#8216;operation&#8217; =&gt; &#8216;Zhidao: To &#8216; . $to-&gt;name,<br />&nbsp; );<br />&nbsp; userpoints_userpointsapi($params);<br />&nbsp;&nbsp;<br />&nbsp; if ($form_values['best_cid']) {<br />&nbsp;&nbsp;&nbsp; db_query(&#8216;UPDATE {zhidao} SET best_cid = %d, additional_points = %d WHERE nid = %d&#8217;, $form_values['best_cid'], $form_values['additional_points'], $form_values['nid']);<br />&nbsp; }<br />&nbsp; return &quot;node/{$form_values['nid']}&quot;;<br />}<br />&nbsp;<br />function zhidao_best_page($cid) {<br />&nbsp; $output = ”;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp; if (is_numeric($cid)) {<br />&nbsp;&nbsp;&nbsp; $comment = db_fetch_object(db_query(&#8216;SELECT * FROM {comments} WHERE cid = %d&#8217;, $cid));<br />&nbsp;&nbsp;&nbsp; if ($comment) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $node = node_load($comment-&gt;nid);<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (&#8216;zhidao&#8217; == $node-&gt;type) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $output .= &#8216;&lt;div id=&quot;zhidao_best_page&quot;&gt;&#8217;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $output .= &#8216;&lt;div&gt;&#8217;. check_plain($node-&gt;title). &#8216;&lt;/div&gt;&#8217;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $output .= &#8216;&lt;label&gt;&#8217; .t(&#8216;you select the best answer is: &#8216;). &#8216;&lt;/label&gt;&lt;div&gt;&#8217;.check_plain($comment-&gt;comment). &#8216;&lt;/div&gt;&#8217;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $output .= &#8216;&lt;label&gt;&#8217; .t(&#8216;additional userpoints&#8217;). &#8216;&lt;/label&gt;&lt;div&gt;&#8217; .drupal_get_form(&#8216;zhidao_additional_points&#8217;, $node, $comment). &#8216;&lt;/div&gt;&#8217;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $output .= &#8216;&lt;/div&gt;&#8217;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $output;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return drupal_not_found();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return drupal_not_found();<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp; }<br />}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.terrysco.com/node/drupal-and-userpoints-zhidao.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>扩展drupal的userpoints模块</title>
		<link>http://www.terrysco.com/node/drupal-userpoints-module.html</link>
		<comments>http://www.terrysco.com/node/drupal-userpoints-module.html#comments</comments>
		<pubDate>Sat, 13 Sep 2008 21:22:38 +0000</pubDate>
		<dc:creator>terrysco</dc:creator>
				<category><![CDATA[CMS/FrameWork]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[userpoints]]></category>

		<guid isPermaLink="false">http://www.anyliv.com/www.terrysco.com/?p=37</guid>
		<description><![CDATA[<p>这几天公司要用到用户积分的功能，现在一般的站点都有类似用户积分系统的概念，而drupal的userpoints模块可以给我们提供这样的功能。由于userpoints模块本身只提供了一个基本功能和api，所以需要一些特殊的功能，我们需要自己定制。<br /><br />类似contribute module有很多，我们随便找个便可以看到api的使用方法。比如user2userpoints模块，可以让用户之间可以互赠积分，主要功能就是这句：<br />&#60;?php<br />$params = array(<br />...</p>
]]></description>
			<content:encoded><![CDATA[<p>这几天公司要用到用户积分的功能，现在一般的站点都有类似用户积分系统的概念，而drupal的userpoints模块可以给我们提供这样的功能。由于userpoints模块本身只提供了一个基本功能和api，所以需要一些特殊的功能，我们需要自己定制。</p>
<p>类似contribute module有很多，我们随便找个便可以看到api的使用方法。比如user2userpoints模块，可以让用户之间可以互赠积分，主要功能就是这句：<br />&lt;?php<br />$params = array(<br />&nbsp;&nbsp;&nbsp; &#8216;uid&#8217; =&gt; $to-&gt;uid,<br />&nbsp;&nbsp;&nbsp; &#8216;points&#8217; =&gt; $points,<br />&nbsp;&nbsp;&nbsp; &#8216;operation&#8217; =&gt; &#8216;From: &#8216; . $user-&gt;name,<br />);<br />userpoints_userpointsapi($params);<br />?&gt;</p>
<p>其中 $to对象是表单传递过来的uid，用user_load生成的对象。就这么简单，另外，给赠送人再扣除就行了，$points换成-$points.</p>
<p>此外，userpoints模块如果扩展功能的时候，要对此功能进行设置，不必单独写menu的hook，我们可以使用他的一个userpoints的hook，传入op为setting即可添加表单项来保存我们的配置。如果传入的op值分别为<br />points_before和points_after分别做积分变化前后的操作，其中如果before返回false，将不做积分更改，这可让我们的控制很灵活。</p>
<p>drupal本身灵活的hook机制，在userpoints模块的代码中也能体现出来。module_invoke_all()&#8230;.<br />&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.terrysco.com/node/drupal-userpoints-module.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

