コード例 #1
0
ファイル: lib-comment.php プロジェクト: ivywe/geeklog
/**
* Provide feed data
*
* @param    int     $feed       feed ID
* @param    ref     $link
* @param    ref     $update
* @return   array               feed entries
*
*/
function plugin_getfeedcontent_comment($feed, &$link, &$update)
{
    global $_CONF, $_TABLES;
    $result = DB_query("SELECT topic,limits,content_length FROM {$_TABLES['syndication']} WHERE fid = '{$feed}'");
    $S = DB_fetchArray($result);
    // If topic is all then make it root so all topics are returned (since articles cannot belong to all topics)
    if ($S['topic'] == TOPIC_ALL_OPTION or empty($S['topic'])) {
        $S['topic'] = TOPIC_ROOT;
    }
    // Retrieve list of inherited topics for anonymous user
    $tid_list = TOPIC_getChildList($S['topic'], 1);
    $sql = "SELECT c.cid, c.sid, c.title as title, c.comment, UNIX_TIMESTAMP(c.date) AS modified, " . " s.title as articleTitle, c.uid, s.uid as articleAuthor " . "FROM {$_TABLES['comments']} c, {$_TABLES['stories']} s, {$_TABLES['topic_assignments']} ta " . "WHERE (s.draft_flag = 0) AND (s.date <= NOW()) " . COM_getPermSQL('AND', 1, 2, 's') . " AND ta.type = 'article' AND ta.id = s.sid " . " AND c.type = 'article' AND s.sid = c.sid " . "AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$S['topic']}'))) " . "GROUP BY c.cid " . "ORDER BY modified DESC  LIMIT 0, {$S['limits']} ";
    $result = DB_query($sql);
    $content = array();
    $cids = array();
    $nrows = DB_numRows($result);
    for ($i = 0; $i < $nrows; $i++) {
        $row = DB_fetchArray($result);
        $cids[] = $row['cid'];
        $title = stripslashes($row['title']);
        $body = stripslashes($row['comment']);
        if ($S['content_length'] > 1) {
            $body = SYND_truncateSummary($body, $S['content_length']);
        }
        $articleLink = COM_buildUrl($_CONF['site_url'] . "/article.php?story={$row['sid']}");
        $link = $_CONF['site_url'] . "/comment.php?mode=view&cid={$row['cid']}";
        $articleTitle = $row['articleTitle'];
        if ($_CONF['comment_feeds_article_tag_position'] != 'none') {
            $articleAuthor = sprintf($_CONF['comment_feeds_article_author_tag'], $_CONF['site_url'] . '/users.php?mode=profile&uid=' . $row['articleAuthor'], COM_getDisplayName($row['articleAuthor']));
            $commentAuthor = sprintf($_CONF['comment_feeds_comment_author_tag'], $_CONF['site_url'] . '/users.php?mode=profile&uid=' . $row['uid'], COM_getDisplayName($row['uid']));
            $magicTag = sprintf($_CONF['comment_feeds_article_tag'], $articleLink, $articleTitle, $articleAuthor, $commentAuthor);
            if ($_CONF['comment_feeds_article_tag_position'] == 'start') {
                $body = $magicTag . $body;
            } else {
                $body .= $magicTag;
            }
        }
        $content[] = array('title' => $title, 'summary' => $body, 'link' => $link, 'uid' => $row['uid'], 'author' => COM_getDisplayName($row['uid']), 'date' => $row['modified'], 'format' => 'html');
    }
    $link = $_CONF['site_url'];
    $update = implode(',', $cids);
    return $content;
}
コード例 #2
0
/**
* Update a feed.
* Re-written by Michael Jervis (mike AT fuckingbrit DOT com)
* to use the new architecture
*
* @param   int   $fid   feed id
*
*/
function SYND_updateFeed($fid)
{
    global $_CONF, $_TABLES, $_SYND_DEBUG;
    $result = DB_query("SELECT * FROM {$_TABLES['syndication']} WHERE fid = {$fid}");
    $A = DB_fetchArray($result);
    if ($A['is_enabled'] == 1) {
        // Import the feed handling classes:
        require_once $_CONF['path_system'] . '/classes/syndication/parserfactory.class.php';
        require_once $_CONF['path_system'] . '/classes/syndication/feedparserbase.class.php';
        // Load the actual feed handlers:
        $factory = new FeedParserFactory($_CONF['path_system'] . '/classes/syndication/');
        $format = explode('-', $A['format']);
        $feed = $factory->writer($format[0], $format[1]);
        if ($feed) {
            $feed->encoding = $A['charset'];
            $feed->lang = $A['language'];
            if ($A['type'] == 'article') {
                if ($A['topic'] == '::all') {
                    $content = SYND_getFeedContentAll(false, $A['limits'], $link, $data, $A['content_length'], $format[0], $format[1], $fid);
                } elseif ($A['topic'] == '::frontpage') {
                    $content = SYND_getFeedContentAll(true, $A['limits'], $link, $data, $A['content_length'], $format[0], $format[1], $fid);
                } else {
                    // feed for a single topic only
                    $content = SYND_getFeedContentPerTopic($A['topic'], $A['limits'], $link, $data, $A['content_length'], $format[0], $format[1], $fid);
                }
            } else {
                $content = PLG_getFeedContent($A['type'], $fid, $link, $data, $format[0], $format[1]);
                // can't randomly change the api to send a max length, so
                // fix it here:
                if ($A['content_length'] != 1) {
                    $count = count($content);
                    for ($i = 0; $i < $count; $i++) {
                        $content[$i]['summary'] = SYND_truncateSummary($content[$i]['text'], $A['content_length']);
                    }
                }
            }
            if (empty($link)) {
                $link = $_CONF['site_url'];
            }
            $feed->title = $A['title'];
            $feed->description = $A['description'];
            if (empty($A['feedlogo'])) {
                $feed->feedlogo = '';
            } else {
                $feed->feedlogo = $_CONF['site_url'] . $A['feedlogo'];
            }
            $feed->sitelink = $link;
            $feed->copyright = 'Copyright ' . strftime('%Y') . ' ' . $_CONF['site_name'];
            $feed->sitecontact = $_CONF['site_mail'];
            $feed->system = 'Geeklog';
            /* Gather any other stuff */
            $feed->namespaces = PLG_getFeedNSExtensions($A['type'], $format[0], $format[1], $A['topic'], $fid);
            /* If the feed is RSS, and trackback is enabled */
            if ($_CONF['trackback_enabled'] && $format[0] == 'RSS') {
                /* Check to see if an article has trackbacks enabled, and if
                 * at least one does, then include the trackback namespace:
                 */
                $trackbackenabled = false;
                foreach ($content as $item) {
                    if (array_key_exists('extensions', $item) && array_key_exists('trackbacktag', $item['extensions'])) {
                        // Found at least one article, with a trackbacktag
                        // in it's extensions tag.
                        $trackbackenabled = true;
                        break;
                    }
                }
                if ($trackbackenabled) {
                    $feed->namespaces[] = 'xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"';
                }
            }
            /* Inject the namespace for Atom into RSS feeds. Illogical?
             * Well apparantly not:
             * http://feedvalidator.org/docs/warning/MissingAtomSelfLink.html
             */
            if ($format[0] == 'RSS') {
                $feed->namespaces[] = 'xmlns:atom="http://www.w3.org/2005/Atom"';
            }
            if (!empty($A['filename'])) {
                $filename = $A['filename'];
            } else {
                $pos = strrpos($_CONF['rdf_file'], '/');
                $filename = substr($_CONF['rdf_file'], $pos + 1);
            }
            $feed->url = SYND_getFeedUrl($filename);
            $feed->extensions = PLG_getFeedExtensionTags($A['type'], $format[0], $format[1], $A['topic'], $fid, $feed);
            /* Inject the self reference for Atom into RSS feeds. Illogical?
             * Well apparantly not:
             * http://feedvalidator.org/docs/warning/MissingAtomSelfLink.html
             */
            if ($format[0] == 'RSS') {
                $feed->extensions[] = '<atom:link href="' . $feed->url . '" rel="self" type="application/rss+xml" />';
            }
            $feed->articles = $content;
            $feed->createFeed(SYND_getFeedPath($filename));
        } else {
            COM_errorLog("Unable to get a feed writer for {$format[0]} version {$format[1]}.", 1);
        }
        if (empty($data)) {
            $data = 'NULL';
        } else {
            $data = "'" . $data . "'";
        }
        if ($_SYND_DEBUG) {
            COM_errorLog("update_info for feed {$fid} is {$data}", 1);
        }
        DB_query("UPDATE {$_TABLES['syndication']} SET updated = NOW(), update_info = {$data} WHERE fid = {$fid}");
    }
}