每5分钟刷新/循环一次解析的RSS提要

时间:2014-12-04 14:37:51

标签: javascript php jquery rss

我正在制作一个显示器标牌显示器,并且只有一个标题和desc的“欢迎使用RSS”提要。我有来自feedEk的代码,已经调整了一点来解析feed并循环它所以我只有一个标题和desc。一次显示。此Feed可以随时添加或删除信息,因此我需要每隔五分钟刷新一次。我在这里尝试了几种解决方案,似乎无法解决这个问题。

以下是调整后的FeedEk代码,其中包含对调整的评论:

(function (e) {
e.fn.FeedEk = function (t) {
var n = {
    FeedUrl: "http://myrss.com/",
    MaxCount: 1,
    ShowDesc: true,
    ShowPubDate: false,
    CharacterLimit: 100,
    TitleLinkTarget: "_self",
    iterate: false
};
if (t) {
    e.extend(n, t)
}
var r = e(this).attr("id");
var i;

processFeedData = function (t) {
    //This just makes it flash too much
    //e("#" + r).empty();
    var s = "";
    en = t.responseData.feed.entries;

    if (n.iterate == true) {
        //Setting a variable to store current item
        i = window.feedcur = typeof(window.feedcur) === 'undefined' ? 0 : window.feedcur;

        t = en[i];
        s = makeString(t);

        //incrementing the current for the next time we loop through
        window.feedcur = ((i+1)%en.length);
    } else {
        for (i=0;i<en.length;i++) {
            t = en[i];
            s += makeString(t);
        }
    }
    //Changing this to just replace what was there (less blinky feeling)
    e("#" + r).html('<ul class="feedEkListSm">' + s + "</ul>");
}

makeString = function (t) {
    s = '<li><div class="itemTitleSm"><a href="' + t.link + '" target="' + n.TitleLinkTarget + '" >' + t.title + "</a></div><br>";
    if (n.ShowPubDate) {
        i = new Date(t.publishedDate);
        s += '<div class="itemDateSm">' + i.toLocaleDateString() + "</div>"
    }
    if (n.ShowDesc) {
        if (n.DescCharacterLimit > 0 && t.content.length > n.DescCharacterLimit) {
            s += '<div class="itemContentSm">' + t.content.substr(0, n.DescCharacterLimit) + "...</div>"
        } else {
            s += '<div class="itemContentSm">' + t.content + "</div>"
        }
    }
    return s;
}

if (typeof(window.feedContent) === 'undefined') {
    e("#" + r).empty().append('<div style="padding:3px;"><img src="loader.gif" /></div>');
    e.ajax({
        url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=" + n.MaxCount + "&output=json&q=" + encodeURIComponent(n.FeedUrl) + "&hl=en&callback=?",
        dataType: "json",
        success: function (t) {
            window.feedContent = t;
            processFeedData(window.feedContent);
        }
    });
} else {
    processFeedData(window.feedContent);
}        

}
})(jQuery)

在php页面上,我有以下代码,它循环一段时间。我已经尝试将其包装到另一个刷新它的功能但是没有用。我也试过刷新页面,但这只会使整个页面闪烁并仍然不刷新提要。它似乎每12至24小时刷新一次。

<!-- this is for the rss feed -->
<script type="text/javascript" >
$(document).ready(function () {
feedsettings = {
    FeedUrl: 'http://myrss.com/',
    MaxCount: 100,
    ShowDesc: true,
    ShowPubDate: false,
    DescCharacterLimit: 100,
    iterate: true
}
$('#divRss').FeedEk(feedsettings);

setInterval(function(){
    $('#divRss').FeedEk(feedsettings);
},7000);
});

</script>

<style>
.rssDiv{float:right; padding-left:35px;}
ul{width:500px !important}
</style>
<!-- end feed stuffs -->

非常感谢任何帮助指导协助或指导。我必须让这种自我维持,几乎没有额外的安装。我也在代码审查中发布了这个,但我认为最初发布这个可能是错误的地方。

0 个答案:

没有答案
相关问题