Feed item author support

master
vitalif 2010-02-15 19:06:58 +00:00
parent 1999f6045e
commit eccc4c976a
4 changed files with 40 additions and 7 deletions

View File

@ -316,14 +316,18 @@ function fof_db_find_item($feed_id, $item_guid)
}
}
function fof_db_add_item($feed_id, $guid, $link, $title, $content, $cached, $published, $updated)
$fof_db_item_fields = array('item_guid', 'item_link', 'item_title', 'item_author', 'item_content', 'item_cached', 'item_published', 'item_updated');
function fof_db_add_item($feed_id, $item)
{
global $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE, $fof_connection;
global $FOF_FEED_TABLE, $FOF_ITEM_TABLE, $FOF_SUBSCRIPTION_TABLE, $fof_connection, $fof_db_item_fields;
fof_safe_query("insert into $FOF_ITEM_TABLE (feed_id, item_link, item_guid, item_title, item_content, item_cached, item_published, item_updated) values (%d, '%s', '%s' ,'%s', '%s', %d, %d, %d)",
$feed_id, $link, $guid, $title, $content, $cached, $published, $updated);
$sql = "insert into $FOF_ITEM_TABLE (feed_id, ".implode(",", $fof_db_item_fields).") values (".intval($feed_id);
foreach ($fof_db_item_fields as $k)
$sql .= ", '".mysql_real_escape_string($item[$k])."'";
$sql .= ")";
fof_db_query($sql);
return(mysql_insert_id($fof_connection));
return mysql_insert_id($fof_connection);
}
function fof_db_get_items($user_id=1, $feed=NULL, $what="unread", $when=NULL, $start=NULL, $limit=NULL, $order="desc", $search=NULL)

View File

@ -815,6 +815,20 @@ function fof_update_feed($id)
foreach($rss->get_items() as $item)
{
$link = $item->get_permalink();
$author = $item->get_authors();
foreach ($author as &$a)
{
$an = htmlspecialchars($a->get_name());
$al = htmlspecialchars($a->get_link());
$ae = htmlspecialchars($a->get_email());
if ($al)
$a = "<a href=\"$al\">$an</a>";
else if ($ae)
$a = "<a href=\"mailto:$ae\">$an</a>";
else
$a = $an;
}
$author = implode(', ', $author);
$title = $item->get_title();
$content = $item->get_content();
$date = $item->get_date('U');
@ -836,7 +850,16 @@ function fof_update_feed($id)
list($link, $title, $content) = $filter($item, $link, $title, $content);
}
$id = fof_db_add_item($feed_id, $item_id, $link, $title, $content, time(), $date, $date);
$id = fof_db_add_item($feed_id, array(
'item_guid' => $item_id,
'item_link' => $link,
'item_title' => $title,
'item_author' => $author,
'item_content' => $content,
'item_cached' => time(),
'item_published' => $date,
'item_updated' => $date,
));
$fof_item = fof_db_get_item_by_id($id);
fof_apply_tags($fof_item);
fof_apply_plugin_tags($feed_id, $id, NULL);

View File

@ -55,6 +55,7 @@ function fof_render_item($item)
$item_link = $item['item_link'];
$item_id = $item['item_id'];
$item_title = $item['item_title'];
$item_author = $item['item_author'];
$item_content = $item['item_content'];
$item_read = $item['item_read'];
@ -167,7 +168,7 @@ function fof_render_item($item)
<a href="<?=htmlspecialchars($feed_link)?>" title="<?=htmlspecialchars($feed_description)?>"><?=htmlspecialchars($feed_title)?></a>
</h2>
<span class="meta">on <?php echo $item_published ?></span>
<span class="meta">on <?php echo $item_published ?><?= $item_author?" by $item_author":"" ?></span>
</div>

View File

@ -206,6 +206,7 @@ CREATE TABLE IF NOT EXISTS `$FOF_ITEM_TABLE` (
`item_published` int(11) NOT NULL default '0',
`item_updated` int(11) NOT NULL default '0',
`item_title` text NOT NULL,
`item_author` text NOT NULL,
`item_content` text NOT NULL,
PRIMARY KEY (`item_id`),
KEY `feed_id` (`feed_id`),
@ -261,6 +262,10 @@ if (!mysql_num_rows(fof_db_query("show columns from $FOF_FEED_TABLE like 'feed_c
!fof_db_query("ALTER TABLE $FOF_FEED_TABLE ADD `feed_cache_attempt_date` INT( 11 ) DEFAULT '0' AFTER `feed_cache_date`;"))
exit("Can't add column feed_cache_attempt_date to table $FOF_FEED_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
if (!mysql_num_rows(fof_db_query("show columns from $FOF_ITEM_TABLE like 'item_author'")) &&
!fof_db_query("ALTER TABLE $FOF_ITEM_TABLE ADD `item_author` text NOT NULL AFTER `item_title`;"))
exit("Can't add column item_author to table $FOF_ITEM_TABLE. MySQL says: <b>" . mysql_error() . "</b><br>");
?>
Schema up to date.<hr>