ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Opened 12 years ago

#2219 new enhancement

コミュニティー書き込みのRSSフィードの生成機能

Reported by: imamura623 Owned by: nobody
Priority: minor Milestone:
Component: その他 Version:
Keywords: 2.11要望 Cc:

Description

http://sns.openpne.jp/?m=pc&a=page_fh_diary&target_c_diary_id=16235 より転記

これに類するものをパッケージにつけて欲しい
----------------------------
<?php

require_once('config.inc.php');

// DBアクセスのパラメータ
$dbHost=$_OPENPNE_DSN_LIST['main']['dsn']['hostspec'];
$dbName=$_OPENPNE_DSN_LIST['main']['dsn']['database'];
$dbUser=$_OPENPNE_DSN_LIST['main']['dsn']['username'];
$dbPassword=$_OPENPNE_DSN_LIST['main']['dsn']['password'];
$baseURL = OPENPNE_URL;

mb_internal_encoding('UTF-8'); 


// データベースに接続し、選択する
$dbLink = mysql_connect($dbHost,$dbUser,$dbPassword)
or die('Could not connect: ' . mysql_error());

mysql_select_db($dbName) or die('Could not select database');
mysql_query('SET NAMES utf8') or die('set charctor code failed: ' . mysql_error());


// SQL クエリを実行する
$query= <<< EOD
SELECT 
Max(c_commu_topic_comment.r_datetime) AS last_modify, 
c_commu_topic.c_commu_topic_id AS topic_id, 
c_commu_topic.name AS topic_title, 
Count(c_commu_topic_comment.number) - 1 AS comment_num, 
c_commu.name AS commu_name, 
c_commu.image_filename AS image_filename, 
c_commu_category.name AS commu_category

FROM (
(c_commu_topic_comment INNER JOIN c_commu ON c_commu_topic_comment.c_commu_id = c_commu.c_commu_id) 
INNER JOIN c_commu_category ON c_commu.c_commu_category_id = c_commu_category.c_commu_category_id) 
INNER JOIN c_commu_topic ON c_commu_topic_comment.c_commu_topic_id = c_commu_topic.c_commu_topic_id
WHERE (
((c_commu.public_flag)="auth_sns")) 
OR 
(((c_commu.public_flag)="public"))
GROUP BY c_commu_topic.c_commu_topic_id, c_commu_topic.name, c_commu.name, c_commu.image_filename, c_commu_category.name
ORDER BY Max(c_commu_topic_comment.r_datetime) DESC
limit 0,20
EOD;

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$RssGenDateTime=date('D, d M Y H:i:s O');


$httpOutputString= <<< EOD
<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0">

<channel>
<title>encafeコミュニティー新着情報</title>
<link>http://encafe.jp/sns/?m=pc&amp;a=page_h_com_find_all</link>
<description>コミュニティー書き込み新着状況</description>
<language>ja</language>
<lastBuildDate>${RssGenDateTime}</lastBuildDate>
<generator>kaz_a RSS Genarator version 0.1+</generator>
<ttl>23</ttl>
EOD;

while( $recoard = mysql_fetch_array($result) ){

$link=$baseURL . '?m=pc&amp;a=page_c_topic_detail&amp;target_c_commu_topic_id=' . $recoard['topic_id'] . '&amp;comment_count=' . $recoard['comment_num'] ;
if(mb_strlen($recoard['topic_title']) <= 40){
$subject=$recoard['topic_title'];
}else{
$subject=mb_substr($recoard['topic_title'],0,36) . '...';
}
if($recoard['comment_num'] > 0){
$subject .= '(' . $recoard['comment_num'] . ')';
}
$NickName=$recoard['commu_name'];
$LastModifyTime=makeTimeRFC822($recoard['last_modify']);
$category= $recoard['commu_category'];
$mediaURL = $baseURL . 'img.php?filename=' . $recoard['image_filename'] . '&amp;w=76&amp;h=76';

$httpOutputString .= <<< EOD

<item>
<title>${subject}</title>
<author>{$NickName}</author>
<category>${category}</category>
<link>${link}</link>
<guid isPermaLink="false">${link}</guid>
<pubDate>$LastModifyTime</pubDate>
</item>

EOD;
}
$httpOutputString .= <<< EOD
</channel>
</rss>
EOD;

// 結果セットを開放する
mysql_free_result($result);

// 接続を閉じる
mysql_close($dbLink);

header("Content-type: text/xml;charset=UTF-8");
echo mb_convert_encoding($httpOutputString,'UTF-8');
//echo $httpOutputString;

function makeTimeRFC822($datetime){
//$datetime Ex. "2007-10-16 03:00:00"
//return RFC 822形式の日付・時刻表示

$dt=explode(' ',$datetime);
$d=explode('-',$dt[0]);
$t=explode(':',$dt[1]);
return date('D, d M Y H:i:s O',mktime($t['0'],$t['1'],$t['2'],$d['1'],$d['2'],$d['0']));

}

?>

Change History (0)

Note: See TracTickets for help on using tickets.