另外一个
//整理feed
function mkfeed($feed, $actors=array()) {
global $_SGLOBAL;
$title_data = unserialize($feed['title_data']);
$body_data = unserialize($feed['body_data']);
//title
$searchs = $replaces = array();
if($title_data) {
foreach (array_keys($title_data) as $key) {
$searchs[] = '{'.$key.'}';
$replaces[] = $title_data[$key];
}
}
$searchs[] = '{actor}';
$feedspaceusername = getspacenames($feed[uid]);//这里是一个方法可以不用翻译
$replaces[] = empty($actors)?"<a href="space.php?uid=$feed[uid]" target="_blank">$feedspaceusername</a>":implode(mlang('dot'), $actors);
$searchs[] = '{app}';
if(empty($_SGLOBAL['app'][$feed['appid']])) {
$replaces[] = '';
} else {
$app = $_SGLOBAL['app'][$feed['appid']];
$replaces[] = "<a href="$app[url]" target="_blank">$app[name]</a>";
}
$feed['title_template'] = str_replace($searchs, $replaces, $feed['title_template']);
//body
$searchs = $replaces = array();
if($body_data) {
foreach (array_keys($body_data) as $key) {
$searchs[] = '{'.$key.'}';
$replaces[] = $body_data[$key];
}
}
$searchs[] = '{actor}';
$replaces[] = "<a href="space.php?uid=$feed[uid]" target="_blank">$feedspaceusername</a>";
$feed['body_template'] = str_replace($searchs, $replaces, $feed['body_template']);
return $feed;
}
</cfloop>
<cfset searchs = listappend(searchs,"{actor}", ",")>
<cfset feedspaceusername = getspacenames(feed.uid)><!--- 这里是一个方法可以不用翻译 --->
<cfif arraylen(actors) eq 0>
<cfset replaces = listappend(replaces,"<a href=""space.php?uid=#feed.uid#"" target=""_blank"">#feedspaceusername#</a>",",")>
<cfelse>
<cfset replaces = listappend(replaces,"#arraytolist(actors)#",",")> <!--- 这里没有把mlang翻译。把逗号作为分隔符 --->
</cfif>
<cfset feed.title_template = replacelist(feed.title_template, $searchs, $replaces)>
<!--- body --->
<cfset searchs = ""> <!--- 不能使用var,否则是重复定义 --->
<cfset replaces = "">
<cfloop collection="#body_data#" item="l_key">
<!--- 这里会有问题,因为使用逗号作为分割符号。所以,你要找个其他的分割符合。 --->
<cfset searchs = listappend(searchs,"{#l_key#}", ",")>
<cfset replaces = listappend(replaces,body_data[l_key],",")>
</cfloop>
<cfset searchs = listappend(searchs,"{actor}", ",")>
<cfset replaces = listappend(replaces,"<a href=""space.php?uid=#feed.uid#"" target=""_blank"">#feedspaceusername#</a>",",")>
<cfset feed.body_template = replace(feed.body_template, searchs, replaces)>
<cfreturn feed>
</cffunction>
[其他解释]