当前位置: 代码迷 >> ColdFusion >> 除此而外一个
  详细解决方案

除此而外一个

热度:7515   发布时间:2013-02-26 00:00:00.0
另外一个

//整理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;
}


谢谢你了,如果方便的话能加你为QQ好友么?
------最佳解决方案--------------------------------------------------------
想知道$feed里的内容是什么。是因为涉及到unserialize,如果是php的serialize格式,就要写一个特别函数处理。
------其他解决方案--------------------------------------------------------
不懂,友情帮顶.
------其他解决方案--------------------------------------------------------
不懂,友情帮顶.
------其他解决方案--------------------------------------------------------
不懂,友情帮顶!
------其他解决方案--------------------------------------------------------
<cffunction name="mkfeed">
<cfargument name="feed">
    <cfargument name="actors" type="array"><!--- 如果出错, 就把type去掉 --->
    
    <!--- global $_SGLOBAL is request.SGLOBAL --->
    <cfwddx action="wddx2cfml" input="#feed.title_data#" output="title_data">
    <cfwddx action="wddx2cfml" input="#feed.body_data #" output="body_data">
    
    <!--- title --->
    <cfset var searchs = "">
    <cfset var replaces = "">
    <cfset var l_key = "">
    
    <!--- 这里不确定你是数组传递还是struct传递。建议使用struct传递 --->
    <cfloop collection="#title_data#" item="l_key">
     <!--- 这里会有问题,因为使用逗号作为分割符号。所以,你要找个其他的分割符合。 --->
     <cfset searchs = listappend(searchs,"{#l_key#}", ",")>
        <cfset replaces = listappend(replaces,title_data[l_key],",")> 
  相关解决方案