summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-05-14 09:52:56 +0100
committerLester Caine <lester@lsces.co.uk>2026-05-14 09:52:56 +0100
commit83a18e46025e9b45705fa41909a6f85c34ee14eb (patch)
treed5d9801869d89081fc3640797e0bbd3ef9f0c8d2 /includes
parent0bd96c1c2d11b4b781dad5b5b98af3add4bd9369 (diff)
downloadrss-83a18e46025e9b45705fa41909a6f85c34ee14eb.tar.gz
rss-83a18e46025e9b45705fa41909a6f85c34ee14eb.tar.bz2
rss-83a18e46025e9b45705fa41909a6f85c34ee14eb.zip
php-cs-fixer tidies to php8.5 standards
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'includes')
-rwxr-xr-xincludes/classes/FeedCreator.php37
-rwxr-xr-xincludes/classes/FeedHtmlField.php8
-rwxr-xr-xincludes/classes/FeedItem.php1
-rw-r--r--includes/classes/RSSLib.php107
-rwxr-xr-xincludes/classes/UniversalFeedCreator.php33
-rwxr-xr-xincludes/rss_inc.php1
6 files changed, 81 insertions, 106 deletions
diff --git a/includes/classes/FeedCreator.php b/includes/classes/FeedCreator.php
index 2c071b5..a78bf6e 100755
--- a/includes/classes/FeedCreator.php
+++ b/includes/classes/FeedCreator.php
@@ -138,7 +138,6 @@ class FeedCreator extends HtmlDescribable {
*/
public $title, $description, $link;
-
/**
* Optional attributes of a feed.
*/
@@ -156,13 +155,11 @@ class FeedCreator extends HtmlDescribable {
*/
public $cssStyleSheet = '';
-
/**
* @access private
*/
public $items = [];
-
/**
* This feed's MIME content type.
* @since 1.4
@@ -170,7 +167,6 @@ class FeedCreator extends HtmlDescribable {
*/
public $contentType = "application/xml";
-
/**
* This feed's character encoding.
* @since 1.6.1
@@ -186,7 +182,6 @@ class FeedCreator extends HtmlDescribable {
public $generator = "support@rdmcloud.uk";
-
/**
* Any additional elements to include as an assiciated array. All $key => $value pairs
* will be included unencoded in the feed in the form
@@ -197,7 +192,6 @@ class FeedCreator extends HtmlDescribable {
*/
public $additionalElements = [];
-
/**
* Adds an FeedItem to the feed.
*
@@ -215,7 +209,7 @@ class FeedCreator extends HtmlDescribable {
**/
function version() {
- return FEEDCREATOR_VERSION." (".$this->generator.")";
+ return FEEDCREATOR_VERSION." (".$this->generator.")";
}
/**
@@ -257,7 +251,6 @@ class FeedCreator extends HtmlDescribable {
}
-
/**
* Creates a comment indicating the generator of this feed.
* The format of this comment seems to be recognized by
@@ -647,7 +640,7 @@ class RSSCreator091 extends FeedCreator {
$feed .= " <itunes:image href='" . $this->itunes['thumbnail'] . "'/>\n";
}
// itunes expects an explicit setting. we default to no because we're not into this facist crap, but if you need to set it to yes you can.
- $itunesExplicit = isset( $this->itunes['explicit'] ) ? $this->itunes['explicit'] : "no";
+ $itunesExplicit = $this->itunes['explicit'] ?? "no";
$feed .= " <itunes:explicit>" . $itunesExplicit . "</itunes:explicit>\n";
}
@@ -665,7 +658,7 @@ class RSSCreator091 extends FeedCreator {
if ($this->items[$i]->authorEmail!="") {
$feed.= " <author> " . htmlspecialchars($this->items[$i]->authorEmail) . " (".htmlspecialchars($this->items[$i]->author).")</author>\n";
} else {
- $feed.= " <author> no_email@example.com (".htmlspecialchars($this->items[$i]->author).")</author>\n";
+ $feed.= " <author> no_email@example.com (".htmlspecialchars($this->items[$i]->author).")</author>\n";
}
}
/*
@@ -691,7 +684,6 @@ class RSSCreator091 extends FeedCreator {
$feed .= " <pubDate>" . htmlspecialchars( $itemDate->rfc822() ) . "</pubDate>\n";
}
-
if ($this->items[$i]->guid!="") {
$feed.= " <guid isPermaLink=\"false\">".htmlspecialchars($this->items[$i]->guid)."</guid>\n";
} else {
@@ -712,9 +704,7 @@ class RSSCreator091 extends FeedCreator {
$feed.= "\" type=\"";
$feed.= $this->items[$i]->enclosure->type;
$feed.= "\"/>\n";
- }
-
-
+ }
$feed.= " </item>\n";
}
@@ -735,9 +725,9 @@ class RSSCreator091 extends FeedCreator {
*/
class RSSCreator20 extends RSSCreator091 {
- function RSSCreator20() {
- parent::_setRSSVersion("2.0");
- }
+ function RSSCreator20() {
+ parent::_setRSSVersion("2.0");
+ }
}
@@ -840,7 +830,6 @@ class PIECreator01 extends FeedCreator {
}
if ($this->category!="") {
-
$feed.= " <category term=\"" . htmlspecialchars($this->category) . "\" />\n";
}
if ($this->copyright!="") {
@@ -848,7 +837,6 @@ class PIECreator01 extends FeedCreator {
}
$feed.= " <generator>".$this->version()."</generator>\n";
-
$feed.= " <link rel=\"self\" type=\"application/atom+xml\" href=\"". htmlspecialchars($this->syndicationURL). "\" />\n";
$feed.= $this->_createAdditionalElements($this->additionalElements, " ");
for ($i=0;$i<count($this->items);$i++) {
@@ -862,7 +850,6 @@ class PIECreator01 extends FeedCreator {
$feed.= " <published>".htmlspecialchars($itemDate->iso8601())."</published>\n";
$feed.= " <updated>".htmlspecialchars($itemDate->iso8601())."</updated>\n";
-
$tempguid = $this->items[$i]->link;
if ($this->items[$i]->guid!="") {
$tempguid = $this->items[$i]->guid;
@@ -896,13 +883,11 @@ class PIECreator01 extends FeedCreator {
if ($this->items[$i]->description!="") {
-
/*
* ATOM should have at least summary tag, however this implementation may be inaccurate
*/
- $tempdesc = $this->items[$i]->getDescription();
- $temptype="";
-
+ $tempdesc = $this->items[$i]->getDescription();
+ $temptype="";
if ($this->items[$i]->descriptionHtmlSyndicated){
$temptype=" type=\"html\"";
@@ -914,7 +899,6 @@ class PIECreator01 extends FeedCreator {
$feed.= " <content". $temptype . ">". $tempdesc ."</content>\n";
}
-
$feed.= " <summary". $temptype . ">". $tempdesc ."</summary>\n";
} else {
@@ -935,8 +919,6 @@ class PIECreator01 extends FeedCreator {
$feed .=" /> \n";
-
-
}
$feed.= " </entry>\n";
}
@@ -944,7 +926,6 @@ class PIECreator01 extends FeedCreator {
return $feed;
}
-
}
/**
diff --git a/includes/classes/FeedHtmlField.php b/includes/classes/FeedHtmlField.php
index a5b37cb..bc1ec46 100755
--- a/includes/classes/FeedHtmlField.php
+++ b/includes/classes/FeedHtmlField.php
@@ -59,12 +59,12 @@ class FeedHtmlField {
// Remove Bootstrap wrapper divs
$html = preg_replace( '/<div[^>]*class="(container|row|col-[^"]*)"[^>]*>/', '', $html );
$html = preg_replace( '/<\/div>/', '', $html );
-
+
// Keep formatting, images, links; strip everything else
return preg_replace(
- '/\s+/',
- ' ',
- strip_tags( $html, '<p><br><img><strong><em><a><blockquote><ul><ol><li>' )
+ '/\s+/',
+ ' ',
+ strip_tags( $html, '<p><br><img><strong><em><a><blockquote><ul><ol><li>' ),
);
}
}
diff --git a/includes/classes/FeedItem.php b/includes/classes/FeedItem.php
index e60dab2..0b640ab 100755
--- a/includes/classes/FeedItem.php
+++ b/includes/classes/FeedItem.php
@@ -88,7 +88,6 @@ class EnclosureItem extends HtmlDescribable {
}
-
/**
* @package rss
* An FeedImage may be added to a FeedCreator feed.
diff --git a/includes/classes/RSSLib.php b/includes/classes/RSSLib.php
index 1fa38a0..4155a46 100644
--- a/includes/classes/RSSLib.php
+++ b/includes/classes/RSSLib.php
@@ -1,5 +1,6 @@
<?php
namespace Bitweaver\Rss;
+
use Bitweaver\BitBase;
use Bitweaver\KernelTools;
/**
@@ -57,7 +58,7 @@ class RSSLib extends BitBase {
if( is_numeric( $rss_id ) ) {
//if($this->rss_module_name_exists($name)) return false; // TODO: Check the name
$refresh = 60 * $refresh;
-
+
if ($rss_id) {
$query = "update `".BIT_DB_PREFIX."rss_modules` set `name`=?,`description`=?,`refresh`=?,`url`=?,`show_title`=?,`show_pub_date`=? where `rss_id`=?";
$bindvars= [ $name, $description, $refresh, $url, $show_title, $show_pub_date, $rss_id ];
@@ -67,7 +68,7 @@ class RSSLib extends BitBase {
values(?,?,?,?,?,?,?,?)";
$bindvars= [ $name, $description, $url, $refresh, '', 1000000, $show_title, $show_pub_date ];
}
-
+
$result = $this->mDb->query($query,$bindvars);
$ret = true;
}
@@ -78,8 +79,8 @@ class RSSLib extends BitBase {
$ret = FALSE;
if( is_numeric( $rss_id ) ) {
$query = "delete from `".BIT_DB_PREFIX."rss_modules` where `rss_id`=?";
-
- $result = $this->mDb->query($query,array($rss_id));
+
+ $result = $this->mDb->query($query,[$rss_id]);
$ret = true;
}
return $ret;
@@ -89,12 +90,12 @@ class RSSLib extends BitBase {
$ret = FALSE;
if( is_numeric( $rss_id ) ) {
$query = "select * from `".BIT_DB_PREFIX."rss_modules` where `rss_id`=?";
-
- $result = $this->mDb->query($query,array($rss_id));
-
+
+ $result = $this->mDb->query($query,[$rss_id]);
+
if (!$result->numRows())
return false;
-
+
$ret = $result->fetchRow();
}
return $ret;
@@ -134,24 +135,24 @@ class RSSLib extends BitBase {
$data = $this->rss_iconv( KernelTools::bit_http_request($info['url']));
$now = $gBitSystem->getUTCTime();
$query = "update `".BIT_DB_PREFIX."rss_modules` set `content`=?, `last_updated`=? where `rss_id`=?";
- $result = $this->mDb->query($query,array((string)$data,(int) $now, (int) $rss_id));
+ $result = $this->mDb->query($query,[(string)$data,(int) $now, (int) $rss_id]);
return $data;
- } else {
- return false;
}
+ return false;
+
}
public function rss_module_name_exists($name) {
$query = "select `name` from `".BIT_DB_PREFIX."rss_modules` where `name`=?";
- $result = $this->mDb->query($query,array($name));
+ $result = $this->mDb->query($query,[$name]);
return $result->numRows();
}
public function get_rss_module_id($name) {
$query = "select `rss_id` from `".BIT_DB_PREFIX."rss_modules` where `name`=?";
- $id = $this->mDb->getOne($query,array($name));
+ $id = $this->mDb->getOne($query,[$name]);
return $id;
}
@@ -159,8 +160,8 @@ class RSSLib extends BitBase {
$ret = FALSE;
if( is_numeric( $rss_id ) ) {
$query = "select `show_title` from `".BIT_DB_PREFIX."rss_modules` where `rss_id`=?";
-
- $ret = $this->mDb->getOne($query,array($rss_id));
+
+ $ret = $this->mDb->getOne($query,[$rss_id]);
}
return $ret;
}
@@ -169,8 +170,8 @@ class RSSLib extends BitBase {
$ret = FALSE;
if( is_numeric( $rss_id ) ) {
$query = "select `show_pub_date` from `".BIT_DB_PREFIX."rss_modules` where `rss_id`=?";
-
- $show_pub_date = $this->mDb->getOne($query,array($rss_id));
+
+ $show_pub_date = $this->mDb->getOne($query,[$rss_id]);
$ret = $show_pub_date;
}
return $ret;
@@ -200,11 +201,11 @@ class RSSLib extends BitBase {
if ($new_xmlstr === FALSE) {
// in_encod -> out_encod not supported, may be misspelled encoding
- $sencod = strtr($sencod, array(
+ $sencod = strtr($sencod, [
"-" => "",
"_" => "",
- " " => ""
- ));
+ " " => "",
+ ]);
$new_xmlstr = @iconv($sencod, $tencod, $xmlstr);
@@ -222,10 +223,10 @@ class RSSLib extends BitBase {
} elseif (function_exists('recode_string')) {
// I don't have recode support could somebody test it?
$xmlstr = @recode_string("$sencod..$tencod", $xmlstr);
- } else {
+ }
// This PHP intallation don't have any EncodConvFunc...
// somebody could create bit_iconv(...)?
- }
+
}
// Replace header, put the new encoding
@@ -234,98 +235,98 @@ class RSSLib extends BitBase {
return $xmlstr;
}
-
+
public function get_short_desc( $text ){
// first we can remove unwanted stuff like images and lists or whatever - this is rough
- $pattern = array(
+ $pattern = [
"!<img[^>]*>!is",
//"!<ul.*?</ul>!is",
- );
+ ];
$text = preg_replace( $pattern, "", $text );
-
- $text = substr($text, 0, 1000);
-
+
+ $text = substr($text, 0, 1000);
+
// now we strip remaining tags and xs whitespace
$text = trim( preg_replace( "!\s+!s", " ", strip_tags( $text )));
-
+
// finally we try to extract sentences as well as we can
// to add more characters to split sentences by add them after the last \? - you might want to add : or ;
preg_match_all( "#([\.!\?\s\)]*)(.*?[a-zA-Z][2]\s*[\.\!\?]+\)?)#s", $text, $matches );
-
+
return $matches[2];
}
-
+
public function get_short_descs( $items, $length=1 ){
- $shortdescs = Array();
-
+ $shortdescs = [];
+
if ( !empty($items) ){
foreach ($items as $item){
//we try to trim each story to given number of sentences
$sentences = $this->get_short_desc( $item->get_description() );
-
+
$shortdesc = NULL;
for ($n = 0; $n < $length; $n++){
$space = ($n > 0)?" ":NULL;
$shortdesc .= $space;
$shortdesc .= ( !empty( $sentences[$n] ) && $sentences[$n] != NULL ) ? $sentences[$n] : NULL;
}
-
+
$shortdescs[] = $shortdesc;
}
}
-
+
return $shortdescs;
}
public function parse_feeds( $pParamHash ){
//set path to rss feed cache
$cache_path = TEMP_PKG_PATH.'rss/simplepie';
-
+
//we do this earlier instead of later because if we can't cache the source we shouldn't be pulling the rss feed.
if( !is_dir( $cache_path ) && !KernelTools::mkdir_p( $cache_path ) ) {
\Bitweaver\bit_error_log( 'Can not create the cache directory: '.$cache_path );
-
+
return FALSE;
- }else{
+ }
//load up parser SimplePie
require_once( UTIL_PKG_INCLUDE_PATH.'simplepie/simplepie.php' );
$ids = ( !is_array( $pParamHash['id'] ) ) ? explode( ",", $pParamHash['id'] ) : $pParamHash['id'];
-
+
$urls = [];
-
+
foreach ($ids as $id){
if( @BitBase::verifyId( $id ) ) {
$feedHash = $this->get_rss_module( $id );
$urls[] = $feedHash['url'];
- }else{
+ }
//todo assign this as an error
//$repl = '<b>rss can not be found, id must be a number</b>';
- }
+
}
$feed = new \SimplePie();
-
+
//Instead of only passing in one feed url, we'll pass in an array of multiple feeds
$feed->set_feed_url( $urls );
-
+
$feed->set_cache_location( $cache_path );
-
+
//set cache time
$cache_time = !empty($pParamHash['cache_time'])?$pParamHash['cache_time']:1;
$feed->set_cache_duration( $cache_time );
-
+
//not sure - we may want to eventually use this
//$feed->set_stupidly_fast(TRUE);
-
+
// Initialize the feed object
$feed->init();
-
+
// This will work if all of the feeds accept the same settings.
$feed->handle_content_type();
-
+
$items = $feed->get_items();
-
+
return $items;
- }
- }
+
+ }
}
diff --git a/includes/classes/UniversalFeedCreator.php b/includes/classes/UniversalFeedCreator.php
index 93c7b02..2f32367 100755
--- a/includes/classes/UniversalFeedCreator.php
+++ b/includes/classes/UniversalFeedCreator.php
@@ -56,7 +56,6 @@ class UniversalFeedCreator extends FeedCreator {
$this->_feed = new AtomCreator10();
break;
-
case "ATOM0.3":
$this->_feed = new AtomCreator03();
break;
@@ -98,8 +97,6 @@ class UniversalFeedCreator extends FeedCreator {
return $this->_feed->createFeed();
}
-
-
/**
* Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect
* header may be sent to redirect the use to the newly created file.
@@ -115,30 +112,28 @@ class UniversalFeedCreator extends FeedCreator {
$this->_feed->saveFeed($filename, $displayContents);
}
-
/**
- * Turns on caching and checks if there is a recent version of this feed in the cache.
- * If there is, an HTTP redirect header is sent.
- * To effectively use caching, you should create the FeedCreator object and call this method
- * before anything else, especially before you do the time consuming task to build the feed
- * (web fetching, for example).
- *
- * @param string format format the feed should comply to. Valid values are:
- * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3".
- * @param string filename optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["SCRIPT_NAME"] with the extension changed to .xml (see _generateFilename()).
- * @param int timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour)
- */
+ * Turns on caching and checks if there is a recent version of this feed in the cache.
+ * If there is, an HTTP redirect header is sent.
+ * To effectively use caching, you should create the FeedCreator object and call this method
+ * before anything else, especially before you do the time consuming task to build the feed
+ * (web fetching, for example).
+ *
+ * @param string format format the feed should comply to. Valid values are:
+ * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3".
+ * @param string filename optional the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["SCRIPT_NAME"] with the extension changed to .xml (see _generateFilename()).
+ * @param int timeout optional the timeout in seconds before a cached version is refreshed (defaults to 3600 = 1 hour)
+ */
function useCached($format="RSS0.91", $filename="", $timeout=3600) {
- $this->_setFormat($format);
- $this->_feed->useCached($filename, $timeout);
+ $this->_setFormat($format);
+ $this->_feed->useCached($filename, $timeout);
}
-
/**
* Outputs feed to the browser - needed for on-the-fly feed generation (like it is done in WordPress, etc.)
*
* @param string format the feed should comply to. Valid values are:
- * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3".
+ * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM0.3".
*/
function outputFeed($format='RSS0.91') {
$this->_setFormat($format);
diff --git a/includes/rss_inc.php b/includes/rss_inc.php
index fde878b..0acb329 100755
--- a/includes/rss_inc.php
+++ b/includes/rss_inc.php
@@ -11,7 +11,6 @@
use Bitweaver\Rss\UniversalFeedCreator;
use Bitweaver\KernelTools;
use Bitweaver\Rss\FeedImage;
-use Bitweaver\Users\BaseAuth;
require_once( USERS_PKG_INCLUDE_PATH."users_lib.php" );
// make sure the feeds cache dir is available