1"use strict"; 2 3if (!fc_defined("FCBase")) fc_define("FCBase"); 4 5FCBase.rss = { 6 locale: "en-US", // ISO language code - http://www.lingoes.net/en/translator/langcode.htm 7 path: "shared/rss/", 8 file: "rss.php", 9 // charset: "UTF-8", 10 cors: true, 11 async: true, 12 data: [], 13 callback: null 14}; 15 16$.rssFeed = function(data, options) { 17 var padNum = function(number) { 18 return ("0" + number).slice(-2); 19 }; 20 21 /* 22 var options = $.extend({ 23 selector: null, 24 url: null, 25 page: 1, 26 total: 5, 27 maxTitle: 40, 28 maxDesc: 100, 29 endText: "...", 30 noImage: "shared/img/shared/no-image.jpg" 31 }, options); 32 33 // console.log(data); 34 */ 35 36 // $.support.cors = FCBase.rss.cors; // fixed no transport error 37 $.ajax({ 38 url: FCBase.rss.path + FCBase.rss.file, 39 crossDomain: true, 40 cache: false, 41 async: FCBase.rss.async, 42 method: "POST", 43 dataType: "json", 44 data: { 45 data: JSON.stringify(data) 46 }, 47 beforeSend: function(xhr) { 48 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 49 // if (options.charset) xhr.overrideMimeType("text/html;charset=" + options.charset); 50 }, 51 error: function(jqXHR, textStatus, errorThrown) { 52 console.log(textStatus + ": " + errorThrown); 53 54 return false; 55 }, 56 success: function(json) { 57 if (json.status == "success") { 58 if (json.data && Object.keys(json.data).length > 0) { 59 $.each(json.data, function(k, d) { 60 if (d.status == "success" && d.data) { 61 if (d.type == "xml") { 62 var _counter_ = 0, 63 _option_ = FCBase.rss.data[k], 64 $elm = $(_option_.selector); 65 66 if ($elm.length > 0) { 67 var _feed_ = $.parseXML(d.data), 68 $entries = false; 69 70 if ($(_feed_).find("item").length > 0) $entries = $(_feed_).find("item"); 71 else if ($(_feed_).find("entry").length > 0) $entries = $(_feed_).find("entry"); 72 73 if ($entries) { 74 $elm.empty(); // clear 75 76 $entries.each(function(i) { 77 if (_option_.total && _counter_ >= _option_.total) { 78 if (_option_.callback && _option_.callback.constructor === Function) _option_.callback(); 79 80 return false; 81 } 82 83 var _title_ = false, 84 _category_ = false, 85 _date_ = false, 86 _dateUTC_ = false, 87 _year_ = false, 88 _month_ = false, 89 _monthLong_ = false, 90 _monthShort_ = false, 91 _weekdayLong_ = false, 92 _weekdayShort_ = false, 93 _day_ = false, 94 _hour_ = false, 95 _minute_ = false, 96 _second_ = false, 97 _author_ = false, 98 _link_ = false, 99 _description_ = false, 100 _content_ = false, 101 _thumbnail_ = false, 102 _images_ = [], 103 104 // elements 105 $title = $("title", this), 106 $category = $("category", this), 107 $pubDate = $("pubDate", this), 108 $modified = $("modified", this), 109 $date = $("date", this), 110 $dcDate = $("dc\\:date", this), 111 $author = $("author", this), 112 $creator = $("creator", this), 113 $dcAuthor = $("dc\\:author", this), 114 $dcCreator = $("dc\\:creator", this), 115 $link = $("link", this), 116 $guid = $("guid", this), 117 $description = $("description", this), 118 $content = $("content", this), 119 $contentEncoded = $("content\\:encoded", this); 120 121 122 123 if ($title.text()) { 124 _title_ = $title.text(); 125 var _title_length_ = $title.text().length; 126 if (_option_.maxTitle) { // limit 127 _title_ = _title_.substring(0, _option_.maxTitle - 1); 128 if (_option_.endText && (_option_.maxTitle < _title_length_)) _title_ += _option_.endText; 129 } 130 } 131 132 if ($category.text()) _category_ = $category.text(); 133 134 if ($pubDate.text()) _dateUTC_ = $pubDate.text(); 135 else if ($modified.text()) _dateUTC_ = $modified.text(); 136 else if ($date.text()) _dateUTC_ = $date.text(); 137 else if ($dcDate.text()) _dateUTC_ = $dcDate.text(); 138 139 if (_dateUTC_) { 140 var _dateParse_ = new Date(_dateUTC_); 141 if (_dateParse_) { 142 if (typeof Intl == "undefined") { 143 var weekdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"), 144 months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
144November", "December"); 145 146 _year_ = _dateParse_.getUTCFullYear(); 147 _month_ = padNum(_dateParse_.getUTCMonth() + 1); 148 _monthLong_ = months[_dateParse_.getUTCMonth()]; 149 _monthShort_ = _monthLong_ ? _monthLong_.substr(0, 3) : null; 150 _day_ = padNum(_dateParse_.getUTCDate()); 151 _weekdayLong_ = weekdays[_dateParse_.getUTCDate()]; 152 _weekdayShort_ = _weekdayLong_ ? _weekdayLong_.substr(0, 3) : null; 153 _hour_ = padNum(_dateParse_.getUTCHours()); 154 _minute_ = padNum(_dateParse_.getUTCMinutes()); 155 _second_ = padNum(_dateParse_.getUTCSeconds()); 156 } 157 else { // https://caniuse.com/#feat=internationalization 158 _year_ = new Intl.DateTimeFormat(FCBase.rss.locale, {year: "numeric"}).format(_dateParse_); 159 _month_ = new Intl.DateTimeFormat(FCBase.rss.locale, {month: "2-digit"}).format(_dateParse_); 160 _monthLong_ = new Intl.DateTimeFormat(FCBase.rss.locale, {month: "long"}).format(_dateParse_); 161 _monthShort_ = new Intl.DateTimeFormat(FCBase.rss.locale, {month: "short"}).format(_dateParse_); 162 _weekdayLong_ = new Intl.DateTimeFormat(FCBase.rss.locale, {weekday: "long"}).format(_dateParse_); 163 _weekdayShort_ = new Intl.DateTimeFormat(FCBase.rss.locale, {weekday: "short"}).format(_dateParse_); 164 _day_ = new Intl.DateTimeFormat(FCBase.rss.locale, {day: "2-digit"}).format(_dateParse_); 165 _hour_ = new Intl.DateTimeFormat(FCBase.rss.locale, {hour: "2-digit"}).format(_dateParse_); 166 _minute_ = new Intl.DateTimeFormat(FCBase.rss.locale, {minute: "2-digit"}).format(_dateParse_); 167 _second_ = new Intl.DateTimeFormat(FCBase.rss.locale, {second: "2-digit"}).format(_dateParse_); 168 } 169 } 170 } 171 172 if ($author.text()) _author_ = $author.text(); 173 else if ($creator.text()) _author_ = $creator.text(); 174 else if ($author.text()) _author_ = $author.text(); 175 else if ($creator.text()) _author_ = $creator.text(); 176 177 if ($link.text()) _link_ = $link.text(); 178 else if ($link.attr("href").length > 0) _link_ = $link.attr("href"); 179 else if ($guid.text()) _link_ = $guid.text(); // wp permalink 180 181 if ($description.text()) { 182 _description_ = $description.text(); 183 _description_.replace(/\s+/g, "").replace(" ", ""); // remove whitespaces 184 var _desc_length_ = _description_.length; 185 if (_option_.maxDesc) { // limit 186 _description_ = _description_.substring(0, _option_.maxDesc - 1); 187 if (_option_.endText && (_option_.maxDesc < _desc_length_)) _description_ += _option_.endText; 188 } 189 } 190 191 if ($content.text()) _content_ = $content.text(); 192 else if ($content.context && $content.context.textContent) _content_ = $content.context.textContent; // fixed for Edge 193 else if ($contentEncoded.text()) _content_ = $contentEncoded.text(); 194 else if ($contentEncoded.context && $contentEncoded.context.textContent) _content_ = $contentEncoded.context.textContent; // fixed for Edge 195 196 // Check ImageSize Exist 197 if(typeof _option_.ImageSize == 'undefined'){ 198 199 _option_.ImageSize = { 200 width: 300, 201 height: 200 202 } 203 204 } else if(typeof _option_.noImage == 'undefined') { // Check noImage Exist 205 206 _option_.noImage = 'https://via.placeholder.com/300x200.png?text=Test+No+Image'; 207 208 console.log('aaaaaa') 209 210 } 211 212 if (_content_) { 213 var _html_ = $.parseHTML("<div>" + _content_ + "</div>"), 214 $images = $(_html_).find("img"); 215 216 if ($(this).find("thumbnail").text()) { 217 var imgSrc = $(this).find("thumbnail").text(); 218 _thumbnail_ = '<img src="' + imgSrc + '" alt="' + (_title_ ? _title_.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, "") : "") + '">'; // only one thumbnail 219 _images_.push(imgSrc); 220 } 221 222 $images.each(function() { 223 var _src_ = $(this).attr("src"); 224 225 if (_src_ && !_src_.match("s.w.org")) { 226 _images_.push(_src_); 227 228 if (!_thumbnail_) _thumbnail_ = '<span style="display:block; background: url(' + _src_ + ') no-repeat center center; background-size:cover; width:' + _option_.ImageSize.width + 'px; height:' + _option_.ImageSize.height + 'px;"></span>'; // first 229 } 230 }); 231 232 if (!_thumbnail_ && _option_.noImage) _thumbnail_ = '<span style="display:block;
232 background: url(' + _option_.noImage + ') no-repeat center center; background-size:cover; width:' + _option_.ImageSize.width + 'px; height:' + _option_.ImageSize.height + 'px;"></span>'; // no image 233 } 234 235 if (_title_ && !_title_.match("PR")) { 236 var _output_ = _option_.template; 237 238 _output_ = 239 _output_ 240 .replace(/\{YEARS?\}/ig, (_year_ ? _year_ : "")) 241 .replace(/\{MONTHS?\}/ig, (_month_ ? _month_ : "")) 242 .replace(/\{DAYS?\}/ig, (_day_ ? _day_ : "")) 243 .replace(/\{HOURS?\}/ig, (_hour_ ? _hour_ : "")) 244 .replace(/\{MINUTES?\}/ig, (_minute_ ? _minute_ : "")) 245 .replace(/\{SECONDS?\}/ig, (_second_ ? _second_ : "")) 246 .replace(/\{MONTHS?-LONG\}/ig, (_monthLong_ ? _monthLong_ : "")) 247 .replace(/\{MONTHS?-SHORT\}/ig, (_monthShort_ ? _monthShort_ : "")) 248 .replace(/\{WEEKDAYS?-LONG\}/ig, (_weekdayLong_ ? _weekdayLong_ : "")) 249 .replace(/\{WEEKDAYS?-SHORT\}/ig, (_weekdayShort_ ? _weekdayShort_ : "")) 250 .replace(/\{DATE\}/ig, ((_year_ && _month_ && _day_) ? (_year_ + "-" + _month_ + "-" + _day_) : "")) 251 .replace(/\{TIME\}/ig, ((_hour_ && _minute_ && _second_) ? (_hour_ + ":" + _minute_ + ":" + _second_) : "")) 252 .replace(/\{(URL|LINK|PERMALINK)\}/ig, (_link_ ? _link_ : "")) 253 .replace(/\{(USERS?|AUTHORS?|CREATOR)\}/ig, (_author_ ? _author_ : "")) 254 .replace(/\{(CAT|CATEGORY|CATEGORIES)\}/ig, (_category_ ? _category_ : "")) 255 .replace(/\{(TITLE|NAME)\}/ig, (_title_ ? _title_ : "")) 256 .replace(/\{(DESC|DESCRIPTION)\}/ig, (_description_ ? _description_ : "")) 257 .replace(/\{(CONTENT|POST|DETAIL)S?\}/ig, (_content_ ? _content_ : "")) 258 .replace(/\{(IMG|IMAGE|PHOTO|THUMB|THUMBNAIL)S?\}/ig, (_thumbnail_ ? _thumbnail_ : "")); 259 260 $(_option_.selector).append(_output_); // insert to screen 261 262 _counter_++; 263 } 264 265 if (i >= $entries.length - 1) { // ended 266 if (_option_.callback && _option_.callback.constructor === Function) _option_.callback(); 267 } 268 }); 269 } 270 else console.info("No results found"); 271 } 272 else console.error(_option_.selector, "element does not exist"); 273 } 274 } 275 else console.error(d.http_code, d.request_url + "\n" + d.message); 276 }); 277 } 278 else console.error(json.message); // missing data-response 279 } 280 else console.error(json.message); 281 } 282 }) 283 .done(function() { 284 if (FCBase.rss.callback && FCBase.rss.callback.constructor === Function) callback.call(this); 285 }); 286}; 287 288$(document).ready(function () { 289 var _data_ = {}; 290 291 $.each(FCBase.rss.data, function (idx, rss) { 292 var uid = Math.random().toString(36).substring(3); 293 294 if (rss.selector) { 295 var $el = $(rss.selector); 296 297 if ($el.length > 0) { 298 _data_[uid] = { 299 key: uid, 300 url: rss.url, 301 page: rss.page 302 }; 303 304 FCBase.rss.data[uid] = rss; 305 delete FCBase.rss.data[idx]; 306 const observer = new IntersectionObserver((entries, observerSelf) => { 307 entries.forEach(entry => { 308 if (entry.isIntersecting) { 309 let loadObj = {}; 310 loadObj[uid] = _data_[uid]; 311 $.rssFeed(loadObj); 312 313 observerSelf.unobserve(entry.target); 314 } 315 }); 316 }, { 317 root: null, 318 rootMargin: '200% 0px', 319 threshold: 0.1 320 }); 321 322 observer.observe($el[0]); 323 } else { 324 console.error(rss.selector, "element does not exist"); 325 } 326 } else { 327 console.error("Missing `selector`"); 328 } 329 }); 330});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.