PHP class that generates RSS2.0

zhaozj2021-02-16  92

I want to write a blog. Later, because there is no time, some code I feel that I don't feel very well, so I gave up the road; I saw 9CBS out of blog, huh, huh. This is fine, don't have it. .

Now give a PHP code that you can think of writing, this code refers to the RSS 2.0 norm of bamboo shoots. Because of its limited level, it is not very understandable to XML. I hope that the broad masses of the people will criticize and correct, thank you.

/ * ----------------

How to use: Use the following array to bring the corresponding function.

1. Channel main $ channel = array (Title => 'channel name (must)', link => 'channel URL (essential)', Description => 'channel description (essential)', language => The language (optional) ', WebMaster =>' is responsible for the website administrator Email (optional) ', managingEditor =>' responsible for channel technical transaction, is the Email (optional) ' Release date, Follow the RFC822 format (2 or 4 digits) (optional) ', lastbuilddate =>' channel content final modification date (SAT, 07 Sep 2002 09:42:31 GMT) (optional) ', Skipdays =>' prompt news aggregat, those days it can skip. (Optional) ', copyright =>' channel content copyright instructions (optional) ', TTL =>' validity period, to indicate the channel The maximum time (optional) ',) can be cached.

2, channel picture $ image = array (URL => 'picture Link (essential)', title => 'image title, URL of an Alt property (essential)', link => 'website for HTTP ( In practice, it is often replaced by channel URL) (essential) ', width =>' picture of the width (pixel) of the pixels of 144, the default 88 (optional) ', Height =>' picture height (pixel) ) Maximum 400, default 31 (optional) ', description =>' Used for LINK Title attributes (optional) ');

3, channel item $ item = array (item) ', description =>' URL (essential) 'URL (essential)', LINK => 'item Comments => 'This review page URL (optional)', GUID => '1 unique marker string (optional)', author => 'The author's email (optional ) ', Enclosure =>' Describes the included media object (optional) ', category =>' contains one or several categories (optional) ', Pubdate =>' items ( Optional) ', Source_URL =>' This item comes from the RSS Road (optional) ', Source_Name =>' This item comes from the RSS Road (optional) '); ------------ ---- * / Class RSS2 {var $ channel_pre = ""; var $ str_image = ""; var $ str_item = "; var $ channel_end ="; / * constructor * / function RSS2 ($ CHANNEL, $ CHANNEL, $ Encoding = "GB2312") {$ this-> Channel ($ CHANNEL, $ Encoding);} / * Generate Channel Body * / Function Channel ($ Channel, $ Encoding = "GB2312") {$ this-> channel_pre. = " / n "; $ this-> channel_pre. =" / n ";

$ this-> Channel_pre. = " / N";

$ this-> Channel_pre. = "". $ channel ['title']. "</ title> / n"; // Channel Name (essential) $ this-> channel_pre. = "<link>" . $ channel ['link']. "</ link> / n"; // channel URL (essential) $ this-> channel_pre. = "<description>". $ channel ['description']. " / Description> / N "; // Channel Description (essential) $ this-> channel_pre. =" <generator> magicboy rss generator v1.0 </ generator> / n "; // Create this document (can selected)</p> <p>IF (Isset ($ CHANNEL ['Language']) $ this-> channel_pre. = "<language>". $ channel ['language']. "</ language> / n"; // Channel article language ( Optional) IF (ISSET ($ CHANNEL ['Webmaster']) $ this-> channel_pre. = "<Webmaster>". $ Channel ['Webmaster']. "</ Webmaster> / N"; // Responsible Technical affairs website administrator Email (ISSET ($ CHANNEL ['ManagingDitor'])) $ this-> Channel_pre. = "<ManagingEditor>". $ Channel ['managingEditor']. "</ ManagingEditor> / N "; // Responsible Email (optional) IF (ISSET ($ CHANNEL ['Pubdate'])) $ this-> Channel_pre. =" <pubdate> ". $ channel ['pubdate']." / pubdate> / n "; // channel content release date, format follows RFC822 format (2 or 4 bits) (optional) IF (isset ($ channel ($ channel ['lastbuilddate']) $ this-> channel_pre "<Lastbuilddate>". $ Channel ['lastbuilddate']. "</ Lastbuilddate> / n"; // Channel content final modification date (SAT, 07 Sep 2002 09:42:31 GMT) (optional) IF (Isset ($ CHANNEL ['SkipDays'])) $ this-> Channel_pre. = "<SkipDays>". $ channel ['skipdays']. "</ skipdays> / n"; // Tips News aggregator, Those days it can skip. (Optional) IF (isset ($ CHANNEL ['Copyright'])) $ this-> channel_pre. = "<Copyright>". $ Channel ['copyright']. "</ Copyright> / n"; // channel Content copyright instructions (optional) IF (isset ($ CHANNEL ['TTL'])) $ this-> channel_pre. = "<TTL>". $ CHANNEL ['TTL']. "</ Ttl> / n" ; // Validity period to indicate the maximum time (optional) that the channel can be cached (optional)</p> <p>$ this-> channel_end. = "</ channel> / n"; $ this-> channel_end. = "</ rS> / n";} / * Generate Channel Image * / Function Image ($ ISSET ($ this-> str_image)) ($ this-> str_image); $ this-> str_image. = "<image> / n"; if (isset ($ image ['url']) $ this-> str_image = "<Url>". "</ Url ']." </ Url> / n "; // Picture of URL (ISSET ($ image [']) $ THIS- > Str_Image. = "<title>". $ image ['title']. "</ title> / n"; // Picture of the title of the ALT attribute (required) IF (ISSET ($ image 'link'])) $ this-> str_image. = "<link>". $ image ['link']. "</ link> / n"; // Website URL (actually often replaced by channel URL) (Essential) IF (ISSET ($ image ['width']) $ this-> str_image. = "<Width>". "<Width ']." </ Width> / n "; // Picture Width (pixel) The maximum 144, default 88 (optional) IF (isset ($ image ['height']) $ this-> str_image. = "<Height>". $ Image ['height'] "</ height> / n"; // Picture of the height (pixel unit) maximum 400, default 31 (optional) IF (isset ($ image ['description']) $ this-> str_image. = "<Description>". $ Image ['description']. "</ Description> / n"; // Title property for LINK (optional) $ this-> str_image. = "</ Image> / n" } / * Channel item * / function item ($ it) {$ this-> str_item. = "<Item> / n"; $ this-> str _item. = "<title>". $ item ['Title']. "</ title> / n"; // Item (Item) title (essential) $ this-> str_item. = "<design>" . $ item ['description "]." </ description> / n "; // item Outline (essential) $ this-> str_item. =" <link> ". $ item [' link ']."</p> <p></ link> / n "; // item URL (essential)</p> <p>IF (Isset ($ Item ['Comments']) $ this-> str_item. = "<Comments>". $ item ['Comments']. "</ comments> / n"; // This item comments ( Comments' URL (optional) IF (ISSET ($ Item ['Guid'])) $ this-> Str_Item. = "<guid>". $ item ['guid']. "</ guid> / n "; // 1 unique marker string (optional) IF (ISSET ($ item ['author']) $ this-> str_item. =" <Author> ". $ Item ['author']." </ author> / n "; // The author's email (optional) IF (isset ($ item ['Enclosure']) $ this-> str_item. =" <enclosure> ". $ item [ENCLOSURE ']. "</ enclosure> / n"; // Describes the included media object (optional) IF (ISSET ($ Item [' category ']) $ this-> str_item. = "<category>". $ item ['category']. "</ category> / n"; // contains one or several categories of this item (optional) IF (ISSET ($ item ['Pubdate']) $ THIS -> str_item. = "<pubdate>". $ item ['pubdate']. "</ pubdate> / n"; // item release time (optional) IF (isset ($ item ['source_url']) $ this-> str_item. = "<source url = /" "" $ item ['source_url']. "/"> ". $ item ['Source_name']." </ source> / n "; // This item comes from RSS (optional) $ this-> str_item. = "<{>> }C }er () {IF ($ this-> channel_pre) && isset $ this-> channel_end && isset ($ this-> str_item) {header ("content-type: text / xml) Echo $ this-> channel_pre; echo $ this-> str_image; echo $ this-> str_item; echo $ this-> channel_end;}} / * erase channel * / function ERASE_CHANEL () {unset ($ this-> channel_pre ); Unset ($ this-> channel_end);} / * Erase channel image * / function ERASE_IMAGE () {unset ($ this-> str_image);</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-13437.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="13437" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.042</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '80DPb63ObboRxQGeeK5lwLld0jYsRR_2BeHa3vLt17b_2BQzK8nq2u_2FuB5uGlPZPnVnxrvhm_2BUI5QGbesi5o83hgpQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>