From 21a9631028e67a6ebcc4621beab4d262862c2080 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Sun, 6 Nov 2022 02:26:38 -0500 Subject: [PATCH 01/29] DirectoryChecker, FileChecker --- admin/index.php | 74 ++++++++---- assets/images/blank.png | Bin 0 -> 155 bytes class/Common/DirectoryChecker.php | 160 ++++++++++++++++++++++++++ class/Common/FileChecker.php | 158 +++++++++++++++++++++++++ language/english/directorychecker.php | 23 ++++ language/english/filechecker.php | 24 ++++ 6 files changed, 419 insertions(+), 20 deletions(-) create mode 100644 assets/images/blank.png create mode 100644 class/Common/DirectoryChecker.php create mode 100644 class/Common/FileChecker.php create mode 100644 language/english/directorychecker.php create mode 100644 language/english/filechecker.php diff --git a/admin/index.php b/admin/index.php index 4cecf55..4b68369 100644 --- a/admin/index.php +++ b/admin/index.php @@ -32,6 +32,7 @@ Blacklist, Common, Common\TestdataButtons, + Common\DirectoryChecker, Files, Helper, NewsStory, @@ -446,7 +447,7 @@ function confirmBeforePrune(): void xoops_cp_header(); $topiclist = ''; if (Request::hasVar('pruned_topics', 'POST')) { - $topiclist = implode(',', $_POST['pruned_topics']); + $topiclist = implode(',', Request::getString('pruned_topics', '', 'POST')); } echo '

' . _AM_NEWS_PRUNENEWS . '

'; $expired = 0; @@ -488,7 +489,7 @@ function pruneNews(): void } if (1 == Request::getInt('ok', 0, 'POST')) { - $story = new NewsStory(); +// $story = new NewsStory(); xoops_cp_header(); $count = $story->getCountStoriesPublishedBefore($timestamp, $expired, $topiclist); $msg = sprintf(_AM_NEWS_PRUNE_DELETED, $count); @@ -574,7 +575,7 @@ function launchNewsletter(): void $timestamp1 = mktime(0, 0, 0, (int)mb_substr($date1, 5, 2), (int)mb_substr($date1, 8, 2), (int)mb_substr($date1, 0, 4)); $timestamp2 = mktime(23, 59, 59, (int)mb_substr($date2, 5, 2), (int)mb_substr($date2, 8, 2), (int)mb_substr($date2, 0, 4)); if (Request::hasVar('export_topics', 'POST')) { - $topiclist = implode(',', $_POST['export_topics']); + $topiclist = implode(',', Request::getString('export_topics', '', 'POST')); } $tbltopics = []; $exportedstories = $story->exportNews($timestamp1, $timestamp2, $topiclist, 0, $tbltopics); @@ -720,7 +721,7 @@ function launchExport(): void $timestamp2 = mktime(23, 59, 59, (int)mb_substr($date2, 5, 2), (int)mb_substr($date2, 8, 2), (int)mb_substr($date2, 0, 4)); $topiclist = ''; if (Request::hasVar('export_topics', 'POST')) { - $topiclist = implode(',', $_POST['export_topics']); + $topiclist = implode(',', Request::getString('export_topics', '', 'POST')); } $topicsexport = Request::getInt('includetopics', 0, 'POST'); $tbltopics = []; @@ -1253,20 +1254,20 @@ function modTopicS(): void redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR1); } $xt->setTopicPid(Request::getInt('topic_pid', 0, 'POST')); - if (empty($_POST['topic_title'])) { + if (empty(Request::getString('topic_title', '', 'POST'))) { redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME); } if (Request::hasVar('items_count', 'SESSION')) { $_SESSION['items_count'] = -1; } - $xt->setTopicTitle($_POST['topic_title']); - if (Request::hasVar('topic_imgurl', 'POST') && '' !== $_POST['topic_imgurl']) { - $xt->setTopicImgurl($_POST['topic_imgurl']); + $xt->setTopicTitle(Request::getString('topic_title', '', 'POST')); + if (Request::hasVar('topic_imgurl', 'POST') && '' !== Request::getString('topic_imgurl', '', 'POST')) { + $xt->setTopicImgurl(Request::getString('topic_imgurl', '', 'POST')); } $xt->setMenu(Request::getInt('submenu', 0, 'POST')); $xt->setTopicFrontpage(Request::getInt('topic_frontpage', 0, 'POST')); if (Request::hasVar('topic_description', 'POST')) { - $xt->setTopicDescription($_POST['topic_description']); + $xt->setTopicDescription(Request::getString('topic_description', '', 'POST')); } else { $xt->setTopicDescription(''); } @@ -1387,16 +1388,16 @@ function addTopic(): void $topicpid = Request::getInt('topic_pid', 0, 'POST'); $xt = new NewsTopic(); - if (!$xt->topicExists($topicpid, $_POST['topic_title'])) { + if (!$xt->topicExists($topicpid, Request::getString('topic_title', '', 'POST'))) { $xt->setTopicPid($topicpid); - if (empty($_POST['topic_title']) || '' == xoops_trim($_POST['topic_title'])) { + if (empty(Request::getString('topic_title', '', 'POST')) || '' == xoops_trim(Request::getString('topic_title', '', 'POST'))) { redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME); } - $xt->setTopicTitle($_POST['topic_title']); + $xt->setTopicTitle(Request::getString('topic_title', '', 'POST')); //$xt->setTopicRssUrl($_POST['topic_rssfeed']); $xt->setTopic_color($_POST['topic_color']); - if (Request::hasVar('topic_imgurl', 'POST') && '' !== $_POST['topic_imgurl']) { - $xt->setTopicImgurl($_POST['topic_imgurl']); + if (Request::hasVar('topic_imgurl', 'POST') && '' !== Request::getString('topic_imgurl', '', 'POST')) { + $xt->setTopicImgurl(Request::getString('topic_imgurl', '', 'POST')); } $xt->setMenu(Request::getInt('submenu', 0, 'POST')); $xt->setTopicFrontpage(Request::getInt('topic_frontpage', 0, 'POST')); @@ -1425,7 +1426,7 @@ function addTopic(): void } } if (Request::hasVar('topic_description', 'POST')) { - $xt->setTopicDescription($_POST['topic_description']); + $xt->setTopicDescription(Request::getString('topic_description', '', 'POST')); } else { $xt->setTopicDescription(''); } @@ -1454,7 +1455,7 @@ function addTopic(): void /** @var \XoopsNotificationHandler $notificationHandler */ $notificationHandler = xoops_getHandler('notification'); $tags = []; - $tags['TOPIC_NAME'] = $_POST['topic_title']; + $tags['TOPIC_NAME'] = Request::getString('topic_title', '', 'POST'); $notificationHandler->triggerEvent('global', 0, 'new_category', $tags); redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED); } else { @@ -1749,12 +1750,12 @@ function saveMetagenBlackList(): void $blacklist = new Blacklist(); $words = $blacklist->getAllKeywords(); - if (Request::hasVar('go', 'POST') && _AM_DELETE == $_POST['go']) { + if (Request::hasVar('go', 'POST') && _AM_DELETE == Request::getString('go', '', 'POST')) { foreach ($_POST['blacklist'] as $black_id) { $blacklist->delete($black_id); } $blacklist->store(); - } elseif (Request::hasVar('go', 'POST') && _AM_ADD == $_POST['go']) { + } elseif (Request::hasVar('go', 'POST') && _AM_ADD == Request::getString('go', '', 'POST')) { $p_keywords = $_POST['keywords']; $keywords = explode("\n", $p_keywords); foreach ($keywords as $keyword) { @@ -1785,14 +1786,14 @@ function saveMetagenOptions(): void switch ($op) { case 'deletefile': xoops_cp_header(); - if ('newsletter' === $_GET['type']) { + if ('newsletter' === Request::getString('type', '', 'GET')) { $newsfile = XOOPS_ROOT_PATH . '/uploads/news/newsletter.txt'; if (unlink($newsfile)) { redirect_header('index.php', 2, _AM_NEWS_DELETED_OK); } else { redirect_header('index.php', 2, _AM_NEWS_DELETED_PB); } - } elseif ('xml' === $_GET['type']) { + } elseif ('xml' === Request::getString('type', '', 'GET')) { $xmlfile = XOOPS_ROOT_PATH . '/uploads/news/stories.xml'; if (unlink($xmlfile)) { redirect_header('index.php', 2, _AM_NEWS_DELETED_OK); @@ -2002,6 +2003,39 @@ function saveMetagenOptions(): void $adminObject->addConfigBoxLine([$folder[$i], '777'], 'chmod'); } + //------ check directories --------------- + + $adminObject->addConfigBoxLine(''); + $redirectFile = Request::getString('SCRIPT_NAME', '', 'SERVER'); + + //check directories + $adminObject->addConfigBoxLine(''); + //$path = $helper->getConfig('uploaddir') . '/'; + $path = $helper->getConfig('uploaddir'); + //$path0 = $helper->getModule()->getInfo('uploaddir'); + $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); + + $path = $helper->getConfig('batchdir') . '/'; + $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); + + $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('mainimagedir') . '/'; + $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); + //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); + + $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('screenshots') . '/'; + $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); + //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); + $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path . 'thumbs' . '/', 0777, $redirectFile)); + //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'thumbs' . '/' . 'blank.png', BLANK_FILE_PATH, $redirectFile)); + + $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage') . '/'; + $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); + //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); + $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path . 'thumbs' . '/', 0777, $redirectFile)); + //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'thumbs' . '/' . 'blank.png', BLANK_FILE_PATH, $redirectFile)); + + //--------------------------- + $adminObject->displayNavigation(basename(__FILE__)); //check for latest release diff --git a/assets/images/blank.png b/assets/images/blank.png new file mode 100644 index 0000000000000000000000000000000000000000..e1ee728af27616842d865ef5f55162dcb93a9b16 GIT binary patch literal 155 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4|3?y&GPYDK6>?NMQuI!gN<;1upcxOv22FVwA zL>4nJa0`Jj5jgR3=A9lx&I`x0{LtKJ|V9E|NjRvLl0f915%77L4Lsu p4$p3+0Xf{BE{-7;w~`YM0Bw|JV2qq$`wA$`;OXk;vd$@?2>{=>C42w? literal 0 HcmV?d00001 diff --git a/class/Common/DirectoryChecker.php b/class/Common/DirectoryChecker.php new file mode 100644 index 0000000..463d2b2 --- /dev/null +++ b/class/Common/DirectoryChecker.php @@ -0,0 +1,160 @@ +"; + $path_status .= "$path (" . \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTAVAILABLE') . ') '; + $path_status .= "
"; + $path_status .= ""; + $path_status .= ""; + $path_status .= ""; + $path_status .= "'; + $path_status .= '
'; + } elseif (@\is_writable($path)) { + $path_status = ""; + $path_status .= "$path (" . \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_AVAILABLE') . ') '; + $currentMode = \mb_substr(\decoct(\fileperms($path)), 2); + if ($currentMode != \decoct($mode)) { + $path_status = ""; + $path_status .= $path . \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), \decoct($mode), $currentMode); + $path_status .= "
"; + $path_status .= ""; + $path_status .= ""; + $path_status .= ""; + $path_status .= ""; + $path_status .= "'; + $path_status .= '
'; + } + } else { + $currentMode = \mb_substr(\decoct(\fileperms($path)), 2); + $path_status = ""; + $path_status .= $path . \sprintf(\constant('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE'), \decoct($mode), $currentMode); + $path_status .= "
"; + $path_status .= ""; + $path_status .= ""; + $path_status .= ""; + $path_status .= ""; + $path_status .= "'; + $path_status .= '
'; + } + + return $path_status; + } + + /** + * @param $target + * @param int $mode + * + * @return bool + */ + public static function createDirectory($target, $mode = 0777) + { + $target = \str_replace('..', '', $target); + + // https://www.php.net/manual/en/function.mkdir.php + return \is_dir($target) || (self::createDirectory(\dirname($target), $mode) && !\mkdir($target, $mode) && !\is_dir($target)); + } + + /** + * @param $target + * @param int $mode + * + * @return bool + */ + public static function setDirectoryPermissions($target, $mode = 0777) + { + $target = \str_replace('..', '', $target); + + return @\chmod($target, (int)$mode); + } + + /** + * @param $dir_path + * + * @return bool + */ + public static function dirExists($dir_path) + { + return \is_dir($dir_path); + } +} + +$op = Request::getString('op', '', 'POST'); +switch ($op) { + case 'createdir': + if (Request::hasVar('path', 'POST')) { + $path = $_POST['path']; + } + if (Request::hasVar('redirect', 'POST')) { + $redirect = $_POST['redirect']; + } + $msg = DirectoryChecker::createDirectory($path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED'); + \redirect_header($redirect, 2, $msg . ': ' . $path); + break; + case 'setdirperm': + if (Request::hasVar('path', 'POST')) { + $path = $_POST['path']; + } + if (Request::hasVar('redirect', 'POST')) { + $redirect = $_POST['redirect']; + } + if (Request::hasVar('mode', 'POST')) { + $mode = $_POST['mode']; + } + $msg = DirectoryChecker::setDirectoryPermissions($path, $mode) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET') : \constant('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET'); + \redirect_header($redirect, 2, $msg . ': ' . $path); + break; +} diff --git a/class/Common/FileChecker.php b/class/Common/FileChecker.php new file mode 100644 index 0000000..02e3d4b --- /dev/null +++ b/class/Common/FileChecker.php @@ -0,0 +1,158 @@ +"; + $path_status .= "$file_path (" . \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_AVAILABLE') . ') '; + } else { + $path_status = ""; + $path_status .= "$file_path (" . \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_NOTAVAILABLE') . ') '; + } + } elseif (self::compareFiles($file_path, $original_file_path)) { + $path_status = ""; + $path_status .= "$file_path (" . \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_AVAILABLE') . ') '; + } else { + $path_status = ""; + $path_status .= "$file_path (" . \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_NOTAVAILABLE') . ') '; + $path_status .= "
"; + $path_status .= ""; + $path_status .= ""; + $path_status .= ""; + $path_status .= ""; + $path_status .= "'; + $path_status .= '
'; + } + + + return $path_status; + } + + /** + * @param $source_path + * @param $destination_path + * + * @return bool + */ + public static function copyFile($source_path, $destination_path) + { + $source_path = \str_replace('..', '', $source_path); + $destination_path = \str_replace('..', '', $destination_path); + + return @\copy($source_path, $destination_path); + } + + /** + * @param $file1_path + * @param $file2_path + * + * @return bool + */ + public static function compareFiles($file1_path, $file2_path) + { + if (!self::fileExists($file1_path) || !self::fileExists($file2_path)) { + return false; + } + if (\filetype($file1_path) !== \filetype($file2_path)) { + return false; + } + if (\filesize($file1_path) !== \filesize($file2_path)) { + return false; + } + $crc1 = \mb_strtoupper(\dechex(\crc32(\file_get_contents($file1_path)))); + $crc2 = \mb_strtoupper(\dechex(\crc32(\file_get_contents($file2_path)))); + + return !($crc1 !== $crc2); + } + + /** + * @param $file_path + * + * @return bool + */ + public static function fileExists($file_path) + { + return \is_file($file_path); + } + + /** + * @param $target + * @param int $mode + * + * @return bool + */ + public static function setFilePermissions($target, $mode = 0777) + { + $target = \str_replace('..', '', $target); + + return @\chmod($target, (int)$mode); + } +} + +$op = Request::getString('op', '', 'POST'); +switch ($op) { + case 'copyfile': + if (Request::hasVar('original_file_path', 'POST')) { + $original_file_path = $_POST['original_file_path']; + } + if (Request::hasVar('file_path', 'POST')) { + $file_path = $_POST['file_path']; + } + if (Request::hasVar('redirect', 'POST')) { + $redirect = $_POST['redirect']; + } + $msg = FileChecker::copyFile($original_file_path, $file_path) ? \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED') : \constant('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED'); + \redirect_header($redirect, 2, $msg . ': ' . $file_path); + break; +} diff --git a/language/english/directorychecker.php b/language/english/directorychecker.php new file mode 100644 index 0000000..8b07977 --- /dev/null +++ b/language/english/directorychecker.php @@ -0,0 +1,23 @@ +Available"); +define('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTAVAILABLE', "Not available"); +define('CO_' . $moduleDirNameUpper . '_' . 'DC_NOTWRITABLE', "Should have permission ( %d ), but it has ( %d )"); +define('CO_' . $moduleDirNameUpper . '_' . 'DC_CREATETHEDIR', 'Create it'); +define('CO_' . $moduleDirNameUpper . '_' . 'DC_SETMPERM', 'Set the permission'); +define('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRCREATED', 'The directory has been created'); +define('CO_' . $moduleDirNameUpper . '_' . 'DC_DIRNOTCREATED', 'The directory cannot be created'); +define('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMSET', 'The permission has been set'); +define('CO_' . $moduleDirNameUpper . '_' . 'DC_PERMNOTSET', 'The permission cannot be set'); diff --git a/language/english/filechecker.php b/language/english/filechecker.php new file mode 100644 index 0000000..66afa78 --- /dev/null +++ b/language/english/filechecker.php @@ -0,0 +1,24 @@ +Available"); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_NOTAVAILABLE', "Not available"); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_NOTWRITABLE', "Should have permission ( %d ), but it has ( %d )"); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_COPYTHEFILE', 'Copy it'); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_CREATETHEFILE', 'Create it'); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_SETMPERM', 'Set the permission'); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_FILECOPIED', 'The file has been copied'); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_FILENOTCOPIED', 'The file cannot be copied'); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_PERMSET', 'The permission has been set'); +define('CO_' . $moduleDirNameUpper . '_' . 'FC_PERMNOTSET', 'The permission cannot be set'); From 33fc0a6ba32ade1058b552ddabe1e9407f5de99f Mon Sep 17 00:00:00 2001 From: mambax7 Date: Sun, 6 Nov 2022 02:29:31 -0500 Subject: [PATCH 02/29] template defaults --- templates/blocks/news_block_bigstory.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/blocks/news_block_bigstory.tpl b/templates/blocks/news_block_bigstory.tpl index efa9eb0..3765441 100644 --- a/templates/blocks/news_block_bigstory.tpl +++ b/templates/blocks/news_block_bigstory.tpl @@ -1,6 +1,6 @@

<{$block.message}>

- <{if $block.story_id|default:'' != ''}> + <{if isset($block.story_id) && $block.story_id|default:'' != ''}>

><{$block.story_title}>

From f11e17658c9cd25c53295bfaf1f5e85449e4cce6 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Sun, 6 Nov 2022 02:33:47 -0500 Subject: [PATCH 03/29] isResultSet() --- admin/amsimport.php | 35 ++- archive.php | 8 +- blocks/news_archives.php | 3 +- class/Common/Blocksadmin.php | 10 +- class/Common/SysUtility.php | 14 +- class/Files.php | 9 +- class/NewsStory.php | 418 +++++++++++++++++++---------------- class/NewsTopic.php | 8 +- class/Utility.php | 24 +- class/XoopsTopic.php | 7 +- class/XoopsTree.php | 48 +++- include/functions.php | 24 +- include/notification.inc.php | 4 +- include/search.inc.php | 6 + ratenews.php | 18 +- xoops_version.php | 14 +- 16 files changed, 408 insertions(+), 242 deletions(-) diff --git a/admin/amsimport.php b/admin/amsimport.php index 1cbea36..f7c29f7 100644 --- a/admin/amsimport.php +++ b/admin/amsimport.php @@ -123,17 +123,29 @@ $ams_newsid = $article['storyid']; // We search for the last version - $result2 = $db->query('SELECT * FROM ' . $ams_text . ' WHERE storyid=' . $ams_newsid . ' AND current=1'); + $sql = 'SELECT * FROM ' . $ams_text . ' WHERE storyid=' . $ams_newsid . ' AND current=1'; + $result2 = $db->query($sql); + if (!$db->isResultSet($result2)) { + \trigger_error("Query Failed! SQL: $sql Error: " . $db->error(), \E_USER_ERROR); + } $text_lastversion = $db->fetchArray($result2); // We search for the number of votes - $result3 = $db->query('SELECT count(*) AS cpt FROM ' . $ams_rating . ' WHERE storyid=' . $ams_newsid); + $sql = 'SELECT count(*) AS cpt FROM ' . $ams_rating . ' WHERE storyid=' . $ams_newsid; + $result3 = $db->query($sql); + if (!$db->isResultSet($result3)) { + \trigger_error("Query Failed! SQL: $sql Error: " . $db->error(), \E_USER_ERROR); + } $votes = $db->fetchArray($result3); // The links $links = ''; if ($use_extlinks) { - $result7 = $db->query('SELECT * FROM ' . $ams_links . ' WHERE storyid=' . $ams_newsid . ' ORDER BY linkid'); + $sql = 'SELECT * FROM ' . $ams_links . ' WHERE storyid=' . $ams_newsid . ' ORDER BY linkid'; + $result7 = $db->query($sql); + if (!$db->isResultSet($result7)) { + \trigger_error("Query Failed! SQL: $sql Error: " . $db->error(), \E_USER_ERROR); + } while (false !== ($link = $db->fetchArray($result7))) { if ('' == trim($links)) { $links = "\n\n" . _AMS_NW_RELATEDARTICLES . "\n\n"; @@ -179,7 +191,11 @@ $news_newsid = $news->storyid(); // ******************** // The files - $result4 = $db->query('SELECT * FROM ' . $ams_files . ' WHERE storyid=' . $ams_newsid); + $sql = 'SELECT * FROM ' . $ams_files . ' WHERE storyid=' . $ams_newsid; + $result4 = $db->query($sql); + if (!$db->isResultSet($result4)) { + \trigger_error("Query Failed! SQL: $sql Error: " . $db->error(), \E_USER_ERROR); + } while (false !== ($file = $db->fetchArray($result4))) { $sfile = new Files(); $sfile->setFileRealName($file['filerealname']); @@ -194,11 +210,14 @@ } // The ratings - $result5 = $db->query('SELECT * FROM ' . $ams_rating . ' WHERE storyid=' . $ams_newsid); + $sql = 'SELECT * FROM ' . $ams_rating . ' WHERE storyid=' . $ams_newsid; + $result5 = $db->query($sql); + if (!$db->isResultSet($result5)) { + \trigger_error("Query Failed! SQL: $sql Error: " . $db->error(), \E_USER_ERROR); + } while (false !== ($ratings = $db->fetchArray($result5))) { - $result6 = $db->queryF( - 'INSERT INTO ' . $news_stories_votedata . ' (storyid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (' . $news_newsid . ',' . $ratings['ratinguser'] . ',' . $ratings['rating'] . ',' . $ratings['ratinghostname'] . ',' . $ratings['ratingtimestamp'] . ')' - ); + $sql = ' INSERT INTO ' . $news_stories_votedata . ' (storyid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (' . $news_newsid . ',' . $ratings['ratinguser'] . ',' . $ratings['rating'] . ',' . $ratings['ratinghostname'] . ',' . $ratings['ratingtimestamp'] . ')'; + $result6 = $db->queryF($sql); } // The comments diff --git a/archive.php b/archive.php index a63cf22..65eacf5 100644 --- a/archive.php +++ b/archive.php @@ -119,10 +119,10 @@ $useroffset = $xoopsConfig['default_TZ']; } } -$result = $xoopsDB->query('SELECT published FROM ' . $xoopsDB->prefix('news_stories') . ' WHERE (published>0 AND published<=' . time() . ') AND (expired = 0 OR expired <= ' . time() . ') ORDER BY published DESC'); -if (!$result) { - echo _ERRORS; - exit(); +$sql = 'SELECT published FROM ' . $xoopsDB->prefix('news_stories') . ' WHERE (published>0 AND published<=' . time() . ') AND (expired = 0 OR expired <= ' . time() . ') ORDER BY published DESC'; +$result = $xoopsDB->query($sql); +if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); } $years = []; $months = []; diff --git a/blocks/news_archives.php b/blocks/news_archives.php index f4411db..594c655 100644 --- a/blocks/news_archives.php +++ b/blocks/news_archives.php @@ -73,7 +73,8 @@ function b_news_archives_show($options) } $sql = "SELECT DISTINCT(FROM_UNIXTIME(published,'%Y-%m')) AS published FROM " . $xoopsDB->prefix('news_stories') . ' WHERE published>=' . $starting_date . ' AND published<=' . $ending_date . ' ORDER BY published ' . $sort_order; $result = $xoopsDB->query($sql); - if (!$result) { + if (!$db->isResultSet($result)) { +// \trigger_error("Query Failed! SQL: $sql Error: " . $db->error(), \E_USER_ERROR); return ''; } while (false !== ($myrow = $xoopsDB->fetchArray($result))) { diff --git a/class/Common/Blocksadmin.php b/class/Common/Blocksadmin.php index c3105b2..62b07a1 100644 --- a/class/Common/Blocksadmin.php +++ b/class/Common/Blocksadmin.php @@ -255,9 +255,15 @@ public function deleteBlock(int $bid): void $myblock = new \XoopsBlock($bid); $sql = \sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $bid); - $this->db->queryF($sql) || \trigger_error($GLOBALS['xoopsDB']->error()); + $result = $this->db->queryF($sql); + if (!$result) { + \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); + } $sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid); - $this->db->queryF($sql) || \trigger_error($GLOBALS['xoopsDB']->error()); + $result = $this->db->queryF($sql); + if (!$result) { + \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); + } $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED); } diff --git a/class/Common/SysUtility.php b/class/Common/SysUtility.php index 758bcb5..5d6d164 100644 --- a/class/Common/SysUtility.php +++ b/class/Common/SysUtility.php @@ -194,7 +194,11 @@ public static function getEditor($helper = null, $options = null) public static function fieldExists(string $fieldname, string $table): bool { global $xoopsDB; - $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); + $sql = "SHOW COLUMNS FROM $table LIKE '$fieldname'"; + $result = $xoopsDB->queryF($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } return ($xoopsDB->getRowsNum($result) > 0); } @@ -217,7 +221,7 @@ public static function cloneRecord($tableName, $id_field, $id) $tempTable = $GLOBALS['xoopsDB']->fetchArray($result, \MYSQLI_ASSOC); } if (!$tempTable) { - \trigger_error($GLOBALS['xoopsDB']->error()); + \trigger_error("Query Failed! SQL: $sql- Error: " . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); } // set the auto-incremented id's value to blank. unset($tempTable[$id_field]); @@ -247,7 +251,11 @@ public static function tableExists(string $tablename): bool $GLOBALS['xoopsLogger']->addDeprecated( \basename(\dirname(__DIR__, 2)) . ' Module: ' . __FUNCTION__ . ' function is deprecated, please use Xmf\Database\Tables method(s) instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}" ); - $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '$tablename'"); + $sql = "SHOW TABLES LIKE '$tablename'"; + $result = $GLOBALS['xoopsDB']->queryF($sql); + if (!$GLOBALS['xoopsDB']->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $GLOBALS['xoopsDB']->error(), E_USER_ERROR); + } if ($GLOBALS['xoopsDB']->isResultSet($result)) { $ret = $GLOBALS['xoopsDB']->getRowsNum($result) > 0; diff --git a/class/Files.php b/class/Files.php index 66fcd8d..326ae9e 100644 --- a/class/Files.php +++ b/class/Files.php @@ -136,7 +136,11 @@ public function getAllbyStory($storyid) public function getFile($id): void { $sql = 'SELECT * FROM ' . $this->table . ' WHERE fileid=' . (int)$id; - $array = $this->db->fetchArray($this->db->query($sql)); + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)){ + \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); + } + $array = $this->db->fetchArray($result); $this->makeFile($array); } @@ -381,6 +385,9 @@ public function getCountbyStory($storyid) { $sql = 'SELECT count(fileid) AS cnt FROM ' . $this->table . ' WHERE storyid=' . (int)$storyid; $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)){ + \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); + } $myrow = $this->db->fetchArray($result); return $myrow['cnt']; diff --git a/class/NewsStory.php b/class/NewsStory.php index 746f580..6103621 100644 --- a/class/NewsStory.php +++ b/class/NewsStory.php @@ -72,18 +72,18 @@ public function __construct($storyid = -1) */ public function getCountStoriesPublishedBefore($timestamp, $expired, $topicslist = '') { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $sql = 'SELECT count(*) AS cpt FROM ' . $db->prefix('news_stories') . ' WHERE published <=' . $timestamp; + $count = 0; + $sql = 'SELECT count(*) AS cpt FROM ' . $this->db->prefix('news_stories') . ' WHERE published <=' . $timestamp; if ($expired) { $sql .= ' AND (expired>0 AND expired<=' . \time() . ')'; } if ('' !== \trim($topicslist)) { $sql .= ' AND topicid IN (' . $topicslist . ')'; } - $result = $db->query($sql); - [$count] = $db->fetchRow($result); - + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + [$count] = $this->db->fetchRow($result); + } return $count; } @@ -93,10 +93,12 @@ public function getCountStoriesPublishedBefore($timestamp, $expired, $topicslist */ public function getStory($storyid): void { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $sql = 'SELECT s.*, t.* FROM ' . $this->table . ' s, ' . $db->prefix('news_topics') . ' t WHERE (storyid=' . (int)$storyid . ') AND (s.topicid=t.topic_id)'; - $array = $db->fetchArray($db->query($sql)); + $sql = 'SELECT s.*, t.* FROM ' . $this->table . ' s, ' . $this->db->prefix('news_topics') . ' t WHERE (storyid=' . (int)$storyid . ') AND (s.topicid=t.topic_id)'; + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)){ + \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); + } + $array = $this->db->fetchArray($result); $this->makeStory($array); } @@ -110,12 +112,10 @@ public function getStory($storyid): void public function deleteBeforeDate($timestamp, $expired, $topicslist = '') { global $xoopsModule; - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); $mid = $xoopsModule->getVar('mid'); - $prefix = $db->prefix('news_stories'); - $vote_prefix = $db->prefix('news_stories_votedata'); - $files_prefix = $db->prefix('news_stories_files'); + $prefix = $this->db->prefix('news_stories'); + $vote_prefix = $this->db->prefix('news_stories_votedata'); + $files_prefix = $this->db->prefix('news_stories_files'); $sql = 'SELECT storyid FROM ' . $prefix . ' WHERE published <=' . $timestamp; if ($expired) { $sql .= ' (AND expired>0 AND expired<=' . \time() . ')'; @@ -123,21 +123,28 @@ public function deleteBeforeDate($timestamp, $expired, $topicslist = '') if ('' !== \trim($topicslist)) { $sql .= ' AND topicid IN (' . $topicslist . ')'; } - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } + while (false !== ($myrow = $this->db->fetchArray($result))) { \xoops_comment_delete($mid, $myrow['storyid']); // Delete comments \xoops_notification_deletebyitem($mid, 'story', $myrow['storyid']); // Delete notifications - $db->queryF('DELETE FROM ' . $vote_prefix . ' WHERE storyid=' . $myrow['storyid']); // Delete votes + $sql = 'DELETE FROM ' . $vote_prefix . ' WHERE storyid=' . $myrow['storyid']; + $result1 = $this->db->queryF($sql); // Delete votes // Remove files and records related to the files - $result2 = $db->query('SELECT * FROM ' . $files_prefix . ' WHERE storyid=' . $myrow['storyid']); - while (false !== ($myrow2 = $db->fetchArray($result2))) { + $sql = 'SELECT * FROM ' . $files_prefix . ' WHERE storyid=' . $myrow['storyid']; + $result2 = $this->db->query($sql); + while (false !== ($myrow2 = $this->db->fetchArray($result2))) { $name = XOOPS_ROOT_PATH . '/uploads/' . $myrow2['downloadname']; if (\is_file($name)) { \unlink($name); } - $db->query('DELETE FROM ' . $files_prefix . ' WHERE fileid=' . $myrow2['fileid']); + $sql = 'DELETE FROM ' . $files_prefix . ' WHERE fileid=' . $myrow2['fileid']; + $result3 = $this->db->query($sql); } - $db->queryF('DELETE FROM ' . $prefix . ' WHERE storyid=' . $myrow['storyid']); // Delete the story + $sql = 'DELETE FROM ' . $prefix . ' WHERE storyid=' . $myrow['storyid']; + $result4 = $this->db->queryF($sql); // Delete the story } return true; @@ -152,15 +159,13 @@ public function deleteBeforeDate($timestamp, $expired, $topicslist = '') */ public function _searchPreviousOrNextArticle($storyid, $next = true, $checkRight = false) { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); $ret = []; $storyid = (int)$storyid; if ($next) { - $sql = 'SELECT storyid, title FROM ' . $db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ') AND storyid > ' . $storyid; + $sql = 'SELECT storyid, title FROM ' . $this->db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ') AND storyid > ' . $storyid; $orderBy = ' ORDER BY storyid ASC'; } else { - $sql = 'SELECT storyid, title FROM ' . $db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ') AND storyid < ' . $storyid; + $sql = 'SELECT storyid, title FROM ' . $this->db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ') AND storyid < ' . $storyid; $orderBy = ' ORDER BY storyid DESC'; } if ($checkRight) { @@ -173,10 +178,10 @@ public function _searchPreviousOrNextArticle($storyid, $next = true, $checkRight } $sql .= $orderBy; - $result = $db->query($sql, 1); - if ($result) { + $result = $this->db->query($sql, 1); + if ($this->db->isResultSet($result)) { $myts = \MyTextSanitizer::getInstance(); - while (false !== ($row = $db->fetchArray($result))) { + while (false !== ($row = $this->db->fetchArray($result))) { $ret = ['storyid' => $row['storyid'], 'title' => \htmlspecialchars($row['title'], \ENT_QUOTES | \ENT_HTML5)]; } } @@ -281,7 +286,8 @@ public static function getAllPublished( $helper->redirect('/index.php', 5, $db->error()); } - while (false !== ($myrow = $db->fetchArray($result))) { + /** @var array $myrow */ + while (false !== ($myrow = $db->fetchArray($result))) { if ($asobject) { $ret[] = new self($myrow); } else { @@ -308,11 +314,9 @@ public function getArchive( $asobject = true, $order = 'published' ) { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); $myts = \MyTextSanitizer::getInstance(); $ret = []; - $sql = 'SELECT s.*, t.* FROM ' . $db->prefix('news_stories') . ' s, ' . $db->prefix('news_topics') . ' t WHERE (s.topicid=t.topic_id) AND (s.published > ' . $publish_start . ' AND s.published <= ' . $publish_end . ') AND (expired = 0 OR expired > ' . \time() . ') '; + $sql = 'SELECT s.*, t.* FROM ' . $this->db->prefix('news_stories') . ' s, ' . $this->db->prefix('news_topics') . ' t WHERE (s.topicid=t.topic_id) AND (s.published > ' . $publish_start . ' AND s.published <= ' . $publish_end . ') AND (expired = 0 OR expired > ' . \time() . ') '; if ($checkRight) { $topics = Utility::getMyItemIds('news_view'); @@ -324,12 +328,14 @@ public function getArchive( } } $sql .= " ORDER BY $order DESC"; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - if ($asobject) { - $ret[] = new self($myrow); - } else { - $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + if ($asobject) { + $ret[] = new self($myrow); + } else { + $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + } } } @@ -358,12 +364,10 @@ public function getBigStory( $asobject = true, $order = 'counter' ) { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); $myts = \MyTextSanitizer::getInstance(); $ret = []; $tdate = \mktime(0, 0, 0, (int)\date('n'), (int)\date('j'), (int)\date('Y')); - $sql = 'SELECT s.*, t.* FROM ' . $db->prefix('news_stories') . ' s, ' . $db->prefix('news_topics') . ' t WHERE (s.topicid=t.topic_id) AND (published > ' . $tdate . ' AND published < ' . \time() . ') AND (expired > ' . \time() . ' OR expired = 0) '; + $sql = 'SELECT s.*, t.* FROM ' . $this->db->prefix('news_stories') . ' s, ' . $this->db->prefix('news_topics') . ' t WHERE (s.topicid=t.topic_id) AND (published > ' . $tdate . ' AND published < ' . \time() . ') AND (expired > ' . \time() . ' OR expired = 0) '; if (0 != (int)$topic) { if (!\is_array($topic)) { @@ -388,12 +392,14 @@ public function getBigStory( } } $sql .= " ORDER BY $order DESC"; - $result = $db->query($sql, (int)$limit, (int)$start); - while (false !== ($myrow = $db->fetchArray($result))) { - if ($asobject) { - $ret[] = new self($myrow); - } else { - $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + $result = $this->db->query($sql, (int)$limit, (int)$start); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + if ($asobject) { + $ret[] = new self($myrow); + } else { + $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + } } } @@ -412,12 +418,10 @@ public function getBigStory( */ public function getAllPublishedByAuthor($uid, $checkRight = false, $asobject = true) { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); $myts = \MyTextSanitizer::getInstance(); $ret = []; - $tblstory = $db->prefix('news_stories'); - $tbltopics = $db->prefix('news_topics'); + $tblstory = $this->db->prefix('news_stories'); + $tbltopics = $this->db->prefix('news_topics'); $sql = 'SELECT ' . $tblstory @@ -447,34 +451,36 @@ public function getAllPublishedByAuthor($uid, $checkRight = false, $asobject = t } } $sql .= ' ORDER BY ' . $tbltopics . '.topic_title ASC, ' . $tblstory . '.published DESC'; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - if ($asobject) { - $ret[] = new self($myrow); - } else { - if ($myrow['nohtml']) { - $html = 0; - } else { - $html = 1; - } - if ($myrow['nosmiley']) { - $smiley = 0; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + if ($asobject) { + $ret[] = new self($myrow); } else { - $smiley = 1; + if ($myrow['nohtml']) { + $html = 0; + } else { + $html = 1; + } + if ($myrow['nosmiley']) { + $smiley = 0; + } else { + $smiley = 1; + } + $ret[$myrow['storyid']] = [ + 'title' => $myts->displayTarea($myrow['title'], $html, $smiley, 1), + 'topicid' => (int)$myrow['topicid'], + 'storyid' => (int)$myrow['storyid'], + 'hometext' => $myts->displayTarea($myrow['hometext'], $html, $smiley, 1), + 'counter' => (int)$myrow['counter'], + 'created' => (int)$myrow['created'], + 'topic_title' => $myts->displayTarea($myrow['topic_title'], $html, $smiley, 1), + 'topic_color' => $myts->displayTarea($myrow['topic_color']), + 'published' => (int)$myrow['published'], + 'rating' => (float)$myrow['rating'], + 'votes' => (int)$myrow['votes'], + ]; } - $ret[$myrow['storyid']] = [ - 'title' => $myts->displayTarea($myrow['title'], $html, $smiley, 1), - 'topicid' => (int)$myrow['topicid'], - 'storyid' => (int)$myrow['storyid'], - 'hometext' => $myts->displayTarea($myrow['hometext'], $html, $smiley, 1), - 'counter' => (int)$myrow['counter'], - 'created' => (int)$myrow['created'], - 'topic_title' => $myts->displayTarea($myrow['topic_title'], $html, $smiley, 1), - 'topic_color' => $myts->displayTarea($myrow['topic_color']), - 'published' => (int)$myrow['published'], - 'rating' => (float)$myrow['rating'], - 'votes' => (int)$myrow['votes'], - ]; } } @@ -505,11 +511,13 @@ public static function getAllExpired($limit = 0, $start = 0, $topic = 0, $ihome $sql .= ' ORDER BY expired DESC'; $result = $db->query($sql, (int)$limit, (int)$start); - while (false !== ($myrow = $db->fetchArray($result))) { - if ($asobject) { - $ret[] = new self($myrow); - } else { - $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + if ($db->isResultSet($result)) { + while (false !== ($myrow = $db->fetchArray($result))) { + if ($asobject) { + $ret[] = new self($myrow); + } else { + $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + } } } @@ -531,11 +539,14 @@ public static function getAllAutoStory($limit = 0, $asobject = true, $start = 0) $ret = []; $sql = 'SELECT * FROM ' . $db->prefix('news_stories') . ' WHERE published > ' . \time() . ' ORDER BY published ASC'; $result = $db->query($sql, (int)$limit, (int)$start); - while (false !== ($myrow = $db->fetchArray($result))) { - if ($asobject) { - $ret[] = new self($myrow); - } else { - $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + if ($db->isResultSet($result)) { + /** @var array $myrow */ + while (false !== ($myrow = $db->fetchArray($result))) { + if ($asobject) { + $ret[] = new self($myrow); + } else { + $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + } } } @@ -575,11 +586,14 @@ public static function getAllSubmitted($limit = 0, $asobject = true, $checkRight $sql = 'SELECT s.*, t.* FROM ' . $db->prefix('news_stories') . ' s, ' . $db->prefix('news_topics') . ' t '; $sql .= ' ' . $criteria->renderWhere() . ' AND (s.topicid=t.topic_id) ORDER BY created DESC'; $result = $db->query($sql, (int)$limit, (int)$start); - while (false !== ($myrow = $db->fetchArray($result))) { - if ($asobject) { - $ret[] = new self($myrow); - } else { - $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + if ($db->isResultSet($result)) { + /** @var array $myrow */ + while (false !== ($myrow = $db->fetchArray($result))) { + if ($asobject) { + $ret[] = new self($myrow); + } else { + $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + } } } @@ -623,9 +637,11 @@ public static function getAllStoriesCount($storytype = 1, $checkRight = false) } } $result = $db->query($sql); - $myrow = $db->fetchArray($result); - - return $myrow['cpt']; + if ($db->isResultSet($result)) { + $myrow = $db->fetchArray($result); + return $myrow['cpt']; + } + return 0; } /** @@ -641,8 +657,10 @@ public static function getByTopic($topicid, $limit = 0) $db = \XoopsDatabaseFactory::getDatabaseConnection(); $sql = 'SELECT * FROM ' . $db->prefix('news_stories') . ' WHERE topicid=' . (int)$topicid . ' ORDER BY published DESC'; $result = $db->query($sql, (int)$limit, 0); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret[] = new self($myrow); + if ($db->isResultSet($result)) { + while (false !== ($myrow = $db->fetchArray($result))) { + $ret[] = new self($myrow); + } } return $ret; @@ -652,10 +670,11 @@ public static function getByTopic($topicid, $limit = 0) * Count the number of news published for a specific topic * @param int $topicid * @param bool $checkRight - * @return mixed|null + * @return int */ public static function countPublishedByTopic($topicid = 0, $checkRight = false) { + $count = 0; /** @var \XoopsMySQLDatabase $db */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); $sql = 'SELECT COUNT(*) FROM ' . $db->prefix('news_stories') . ' WHERE published > 0 AND published <= ' . \time() . ' AND (expired = 0 OR expired > ' . \time() . ')'; @@ -669,12 +688,14 @@ public static function countPublishedByTopic($topicid = 0, $checkRight = false) $topics = \implode(',', $topics); $sql .= ' AND topicid IN (' . $topics . ')'; } else { - return null; + return $count; } } } $result = $db->query($sql); - [$count] = $db->fetchRow($result); + if ($db->isResultSet($result)) { + [$count] = $db->fetchRow($result); + } return $count; } @@ -1010,33 +1031,35 @@ public function exportNews( $order = 'published' ) { $ret = []; - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); $myts = \MyTextSanitizer::getInstance(); if ($usetopicsdef) { // We firt begin by exporting topics definitions // Before all we must know wich topics to export - $sql = 'SELECT DISTINCT topicid FROM ' . $db->prefix('news_stories') . ' WHERE (published >=' . $fromdate . ' AND published <= ' . $todate . ')'; + $sql = 'SELECT DISTINCT topicid FROM ' . $this->db->prefix('news_stories') . ' WHERE (published >=' . $fromdate . ' AND published <= ' . $todate . ')'; if ('' !== \trim($topicslist)) { $sql .= ' AND topicid IN (' . $topicslist . ')'; } - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - $tbltopics[] = $myrow['topicid']; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $tbltopics[] = $myrow['topicid']; + } } } // Now we can search for the stories - $sql = 'SELECT s.*, t.* FROM ' . $this->table . ' s, ' . $db->prefix('news_topics') . ' t WHERE (s.topicid=t.topic_id) AND (s.published >=' . $fromdate . ' AND s.published <= ' . $todate . ')'; + $sql = 'SELECT s.*, t.* FROM ' . $this->table . ' s, ' . $this->db->prefix('news_topics') . ' t WHERE (s.topicid=t.topic_id) AND (s.published >=' . $fromdate . ' AND s.published <= ' . $todate . ')'; if ('' !== \trim($topicslist)) { $sql .= ' AND topicid IN (' . $topicslist . ')'; } $sql .= " ORDER BY $order DESC"; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - if ($asobject) { - $ret[] = new self($myrow); - } else { - $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + if ($asobject) { + $ret[] = new self($myrow); + } else { + $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + } } } @@ -1299,10 +1322,10 @@ public function getRandomNews( $order = 'published', $topic_frontpage = false ) { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $ret = $rand_keys = $ret3 = []; - $sql = 'SELECT storyid FROM ' . $db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ')'; + $ret = []; + $rand_keys = []; + $ret3 = []; + $sql = 'SELECT storyid FROM ' . $this->db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ')'; if (0 != $topic) { if (!\is_array($topic)) { if ($checkRight) { @@ -1337,10 +1360,11 @@ public function getRandomNews( $sql .= ' AND t.topic_frontpage=1'; } $sql .= " ORDER BY $order DESC"; - $result = $db->query($sql); - - while (false !== ($myrow = $db->fetchArray($result))) { - $ret[] = $myrow['storyid']; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret[] = $myrow['storyid']; + } } $cnt = \count($ret); if ($cnt) { @@ -1369,17 +1393,17 @@ public function getRandomNews( public function getStats($limit) { $ret = []; - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $tbls = $db->prefix('news_stories'); - $tblt = $db->prefix('news_topics'); - $tblf = $db->prefix('news_stories_files'); + $tbls = $this->db->prefix('news_stories'); + $tblt = $this->db->prefix('news_topics'); + $tblf = $this->db->prefix('news_stories_files'); // Number of stories per topic, including expired and non published stories $ret2 = []; $sql = "SELECT count(s.storyid) as cpt, s.topicid, t.topic_title FROM $tbls s, $tblt t WHERE s.topicid=t.topic_id GROUP BY s.topicid ORDER BY t.topic_title"; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['topicid']] = $myrow; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['topicid']] = $myrow; + } } $ret['storiespertopic'] = $ret2; unset($ret2); @@ -1387,9 +1411,11 @@ public function getStats($limit) // Total of reads per topic $ret2 = []; $sql = "SELECT Sum(counter) as cpt, topicid FROM $tbls GROUP BY topicid ORDER BY topicid"; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['topicid']] = $myrow['cpt']; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['topicid']] = $myrow['cpt']; + } } $ret['readspertopic'] = $ret2; unset($ret2); @@ -1397,9 +1423,11 @@ public function getStats($limit) // Attached files per topic $ret2 = []; $sql = "SELECT Count(*) as cpt, s.topicid FROM $tblf f, $tbls s WHERE f.storyid=s.storyid GROUP BY s.topicid ORDER BY s.topicid"; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['topicid']] = $myrow['cpt']; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['topicid']] = $myrow['cpt']; + } } $ret['filespertopic'] = $ret2; unset($ret2); @@ -1407,9 +1435,11 @@ public function getStats($limit) // Expired articles per topic $ret2 = []; $sql = "SELECT Count(storyid) as cpt, topicid FROM $tbls WHERE expired>0 AND expired<=" . \time() . ' GROUP BY topicid ORDER BY topicid'; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['topicid']] = $myrow['cpt']; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['topicid']] = $myrow['cpt']; + } } $ret['expiredpertopic'] = $ret2; unset($ret2); @@ -1417,9 +1447,11 @@ public function getStats($limit) // Number of unique authors per topic $ret2 = []; $sql = "SELECT Count(Distinct(uid)) as cpt, topicid FROM $tbls GROUP BY topicid ORDER BY topicid"; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['topicid']] = $myrow['cpt']; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['topicid']] = $myrow['cpt']; + } } $ret['authorspertopic'] = $ret2; unset($ret2); @@ -1427,9 +1459,11 @@ public function getStats($limit) // Most readed articles $ret2 = []; $sql = "SELECT s.storyid, s.uid, s.title, s.counter, s.topicid, t.topic_title FROM $tbls s, $tblt t WHERE s.topicid=t.topic_id ORDER BY s.counter DESC"; - $result = $db->query($sql, (int)$limit); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['storyid']] = $myrow; + $result = $this->db->query($sql, (int)$limit); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['storyid']] = $myrow; + } } $ret['mostreadednews'] = $ret2; unset($ret2); @@ -1437,9 +1471,11 @@ public function getStats($limit) // Less readed articles $ret2 = []; $sql = "SELECT s.storyid, s.uid, s.title, s.counter, s.topicid, t.topic_title FROM $tbls s, $tblt t WHERE s.topicid=t.topic_id ORDER BY s.counter"; - $result = $db->query($sql, (int)$limit); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['storyid']] = $myrow; + $result = $this->db->query($sql, (int)$limit); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['storyid']] = $myrow; + } } $ret['lessreadednews'] = $ret2; unset($ret2); @@ -1447,9 +1483,11 @@ public function getStats($limit) // Best rated articles $ret2 = []; $sql = "SELECT s.storyid, s.uid, s.title, s.rating, s.topicid, t.topic_title FROM $tbls s, $tblt t WHERE s.topicid=t.topic_id ORDER BY s.rating DESC"; - $result = $db->query($sql, (int)$limit); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['storyid']] = $myrow; + $result = $this->db->query($sql, (int)$limit); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['storyid']] = $myrow; + } } $ret['besratednews'] = $ret2; unset($ret2); @@ -1457,9 +1495,11 @@ public function getStats($limit) // Most readed authors $ret2 = []; $sql = "SELECT Sum(counter) as cpt, uid FROM $tbls GROUP BY uid ORDER BY cpt DESC"; - $result = $db->query($sql, (int)$limit); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['uid']] = $myrow['cpt']; + $result = $this->db->query($sql, (int)$limit); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['uid']] = $myrow['cpt']; + } } $ret['mostreadedauthors'] = $ret2; unset($ret2); @@ -1467,9 +1507,11 @@ public function getStats($limit) // Best rated authors $ret2 = []; $sql = "SELECT Avg(rating) as cpt, uid FROM $tbls WHERE votes > 0 GROUP BY uid ORDER BY cpt DESC"; - $result = $db->query($sql, (int)$limit); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['uid']] = $myrow['cpt']; + $result = $this->db->query($sql, (int)$limit); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['uid']] = $myrow['cpt']; + } } $ret['bestratedauthors'] = $ret2; unset($ret2); @@ -1477,9 +1519,11 @@ public function getStats($limit) // Biggest contributors $ret2 = []; $sql = "SELECT Count(*) as cpt, uid FROM $tbls GROUP BY uid ORDER BY cpt DESC"; - $result = $db->query($sql, (int)$limit); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret2[$myrow['uid']] = $myrow['cpt']; + $result = $this->db->query($sql, (int)$limit); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret2[$myrow['uid']] = $myrow['cpt']; + } } $ret['biggestcontributors'] = $ret2; unset($ret2); @@ -1494,14 +1538,12 @@ public function getStats($limit) */ public function getOlderRecentNews(&$older, &$recent): void { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); - $sql = 'SELECT min(published) AS minpublish, max(published) AS maxpublish FROM ' . $db->prefix('news_stories'); - $result = $db->query($sql); - if (!$result) { - $older = $recent = 0; + $sql = 'SELECT min(published) AS minpublish, max(published) AS maxpublish FROM ' . $this->db->prefix('news_stories'); + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + [$older, $recent] = $this->db->fetchRow($result); } else { - [$older, $recent] = $db->fetchRow($result); + $older = $recent = 0; } } @@ -1518,10 +1560,8 @@ public function getOlderRecentNews(&$older, &$recent): void */ public function getWhosWho($checkRight = false, $limit = 0, $start = 0) { - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); $ret = []; - $sql = 'SELECT DISTINCT(uid) AS uid FROM ' . $db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ')'; + $sql = 'SELECT DISTINCT(uid) AS uid FROM ' . $this->db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ')'; if ($checkRight) { $topics = Utility::getMyItemIds('news_view'); if (\count($topics) > 0) { @@ -1532,9 +1572,11 @@ public function getWhosWho($checkRight = false, $limit = 0, $start = 0) } } $sql .= ' ORDER BY uid'; - $result = $db->query($sql); - while (false !== ($myrow = $db->fetchArray($result))) { - $ret[] = $myrow['uid']; + $result = $this->db->query($sql); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + $ret[] = $myrow['uid']; + } } return $ret; @@ -1656,11 +1698,11 @@ public function bodytext($format = 'Show') /** * Returns stories by Ids - * @param $ids - * @param bool $checkRight - * @param bool $asobject - * @param string $order - * @param bool $onlyOnline + * @param array|string $ids + * @param bool $checkRight + * @param bool $asobject + * @param string $order + * @param bool $onlyOnline * @return array|null */ public function getStoriesByIds( @@ -1671,11 +1713,9 @@ public function getStoriesByIds( $onlyOnline = true ) { $limit = $start = 0; - /** @var \XoopsMySQLDatabase $db */ - $db = \XoopsDatabaseFactory::getDatabaseConnection(); $myts = \MyTextSanitizer::getInstance(); $ret = []; - $sql = 'SELECT s.*, t.* FROM ' . $db->prefix('news_stories') . ' s, ' . $db->prefix('news_topics') . ' t WHERE '; + $sql = 'SELECT s.*, t.* FROM ' . $this->db->prefix('news_stories') . ' s, ' . $this->db->prefix('news_topics') . ' t WHERE '; if ($ids && \is_array($ids)) { \array_walk($ids, '\intval'); } @@ -1695,16 +1735,16 @@ public function getStoriesByIds( } } $sql .= " ORDER BY s.$order DESC"; - $result = $db->query($sql, $limit, $start); - - while (false !== ($myrow = $db->fetchArray($result))) { - if ($asobject) { - $ret[$myrow['storyid']] = new self($myrow); - } else { - $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + $result = $this->db->query($sql, $limit, $start); + if ($this->db->isResultSet($result)) { + while (false !== ($myrow = $this->db->fetchArray($result))) { + if ($asobject) { + $ret[$myrow['storyid']] = new self($myrow); + } else { + $ret[$myrow['storyid']] = \htmlspecialchars($myrow['title'], \ENT_QUOTES | \ENT_HTML5); + } } } - return $ret; } } diff --git a/class/NewsTopic.php b/class/NewsTopic.php index 07ae580..36768dd 100644 --- a/class/NewsTopic.php +++ b/class/NewsTopic.php @@ -131,6 +131,9 @@ public function makeMySelBox( $sql .= " ORDER BY $order"; } $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } if ($none) { $outbuffer .= "\n"; } @@ -175,8 +178,11 @@ public function getChildTreeArray($sel_id = 0, $order = '', $perms = '', $parray $sql .= " ORDER BY $order"; } $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } $count = $this->db->getRowsNum($result); - if (0 == $count) { + if ($count == 0) { return $parray; } while (false !== ($row = $this->db->fetchArray($result))) { diff --git a/class/Utility.php b/class/Utility.php index dad5f71..65b5135 100644 --- a/class/Utility.php +++ b/class/Utility.php @@ -69,11 +69,14 @@ public static function getModuleOption($option, $repmodule = 'news') public static function updateRating($storyid): void { global $xoopsDB; - $query = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; - $voteresult = $xoopsDB->query($query); - $votesDB = $xoopsDB->getRowsNum($voteresult); + $sql = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; + $result = $xoopsDB->query($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } + $votesDB = $xoopsDB->getRowsNum($result); $totalrating = 0; - while ([$rating] = $xoopsDB->fetchRow($voteresult)) { + while ([$rating] = $xoopsDB->fetchRow($result)) { $totalrating += $rating; } $finalrating = $totalrating / $votesDB; @@ -605,7 +608,12 @@ public static function updateCache(): void public static function existTable($tablename) { global $xoopsDB; - $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); + $sql = "SHOW TABLES LIKE '$tablename'"; + $result = $xoopsDB->queryF($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } + return ($xoopsDB->getRowsNum($result) > 0); } @@ -622,7 +630,11 @@ public static function existTable($tablename) public static function existField($fieldname, $table) { global $xoopsDB; - $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); + $sql = "SHOW COLUMNS FROM $table LIKE '$fieldname'"; + $result = $xoopsDB->queryF($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } return ($xoopsDB->getRowsNum($result) > 0); } diff --git a/class/XoopsTopic.php b/class/XoopsTopic.php index a89918a..3403c52 100644 --- a/class/XoopsTopic.php +++ b/class/XoopsTopic.php @@ -413,8 +413,11 @@ public function getTopicsList() public function topicExists($pid, $title) { $sql = 'SELECT COUNT(*) FROM ' . $this->table . ' WHERE topic_pid = ' . (int)$pid . " AND topic_title = '" . \trim($title) . "'"; - $rs = $this->db->query($sql); - [$count] = $this->db->fetchRow($rs); + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } + [$count] = $this->db->fetchRow($result); if ($count > 0) { return true; } diff --git a/class/XoopsTree.php b/class/XoopsTree.php index 2e10957..8a24808 100644 --- a/class/XoopsTree.php +++ b/class/XoopsTree.php @@ -89,7 +89,11 @@ public function getFirstChildId($sel_id) { $sel_id = (int)$sel_id; $idarray = []; - $result = $this->db->query('SELECT ' . $this->id . ' FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $sel_id); + $sql = 'SELECT ' . $this->id . ' FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $sel_id; + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } $count = $this->db->getRowsNum($result); if (0 == $count) { return $idarray; @@ -117,7 +121,10 @@ public function getAllChildId($sel_id, $order = '', $idarray = []) if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } $count = $this->db->getRowsNum($result); if (0 == $count) { return $idarray; @@ -146,7 +153,10 @@ public function getAllParentId($sel_id, $order = '', $idarray = []) if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } [$r_id] = $this->db->fetchRow($result); if (0 == $r_id) { return $idarray; @@ -170,7 +180,11 @@ public function getAllParentId($sel_id, $order = '', $idarray = []) public function getPathFromId($sel_id, $title, $path = '') { $sel_id = (int)$sel_id; - $result = $this->db->query('SELECT ' . $this->pid . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"); + $sql= 'SELECT ' . $this->pid . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } if (0 == $this->db->getRowsNum($result)) { return $path; } @@ -213,7 +227,10 @@ public function makeMySelBox($title, $order = '', $preset_id = 0, $none = 0, $se if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } if ($none) { echo "\n"; } @@ -253,7 +270,10 @@ public function getNicePathFromId($sel_id, $title, $funcURL, $path = '') $path = !empty($path) ? ' : ' . $path : $path; $sel_id = (int)$sel_id; $sql = 'SELECT ' . $this->pid . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; - $result = $this->db->query($sql); + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } if (0 == $this->db->getRowsNum($result)) { return $path; } @@ -281,7 +301,11 @@ public function getNicePathFromId($sel_id, $title, $funcURL, $path = '') public function getIdPathFromId($sel_id, $path = '') { $sel_id = (int)$sel_id; - $result = $this->db->query('SELECT ' . $this->pid . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"); + $sql = 'SELECT ' . $this->pid . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; + $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } if (0 == $this->db->getRowsNum($result)) { return $path; } @@ -312,8 +336,11 @@ public function getAllChild($sel_id = 0, $order = '', $parray = []) $sql .= " ORDER BY $order"; } $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } $count = $this->db->getRowsNum($result); - if (0 == $count) { + if ($count == 0) { return $parray; } while (false !== ($row = $this->db->fetchArray($result))) { @@ -342,8 +369,11 @@ public function getChildTreeArray($sel_id = 0, $order = '', $parray = [], $r_pre $sql .= " ORDER BY $order"; } $result = $this->db->query($sql); + if (!$this->db->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + } $count = $this->db->getRowsNum($result); - if (0 == $count) { + if ($count == 0) { return $parray; } while (false !== ($row = $this->db->fetchArray($result))) { diff --git a/include/functions.php b/include/functions.php index 760d950..d89f398 100644 --- a/include/functions.php +++ b/include/functions.php @@ -83,11 +83,14 @@ function news_getmoduleoption($option, $repmodule = 'news') function news_updaterating($storyid): void { global $xoopsDB; - $query = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; - $voteresult = $xoopsDB->query($query); - $votesDB = $xoopsDB->getRowsNum($voteresult); + $sql = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; + $result = $xoopsDB->query($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } + $votesDB = $xoopsDB->getRowsNum($result); $totalrating = 0; - while ([$rating] = $xoopsDB->fetchRow($voteresult)) { + while ([$rating] = $xoopsDB->fetchRow($result)) { $totalrating += $rating; } $finalrating = $totalrating / $votesDB; @@ -581,7 +584,12 @@ function news_updateCache(): void function news_TableExists($tablename) { global $xoopsDB; - $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); + + $sql = "SHOW TABLES LIKE '$tablename'"; + $result = $xoopsDB->queryF($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } return ($xoopsDB->getRowsNum($result) > 0); } @@ -598,7 +606,11 @@ function news_TableExists($tablename) function news_FieldExists($fieldname, $table) { global $xoopsDB; - $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); + $sql = "SHOW COLUMNS FROM $table LIKE '$fieldname'"; + $result = $xoopsDB->queryF($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } return ($xoopsDB->getRowsNum($result) > 0); } diff --git a/include/notification.inc.php b/include/notification.inc.php index fd7b3ed..e106af9 100644 --- a/include/notification.inc.php +++ b/include/notification.inc.php @@ -36,7 +36,7 @@ function news_notify_iteminfo($category, $item_id) // Assume we have a valid story id $sql = 'SELECT title FROM ' . $xoopsDB->prefix('news_stories') . ' WHERE storyid = ' . (int)$item_id; $result = $xoopsDB->query($sql); - if ($result) { + if ($xoopsDB->isResultSet($result)) { $result_array = $xoopsDB->fetchArray($result); $item['name'] = $result_array['title']; $item['url'] = XOOPS_URL . '/modules/news/article.php?storyid=' . (int)$item_id; @@ -51,7 +51,7 @@ function news_notify_iteminfo($category, $item_id) if ('category' === $category) { $sql = 'SELECT title FROM ' . $xoopsDB->prefix('news_topics') . ' WHERE topic_id = ' . (int)$item_id; $result = $xoopsDB->query($sql); - if ($result) { + if ($xoopsDB->isResultSet($result)) { $result_array = $xoopsDB->fetchArray($result); $item['name'] = $result_array['topic_id']; $item['url'] = XOOPS_URL . '/modules/news/index.php?storytopic=' . (int)$item_id; diff --git a/include/search.inc.php b/include/search.inc.php index 6ecaae4..ccb53c4 100644 --- a/include/search.inc.php +++ b/include/search.inc.php @@ -69,6 +69,9 @@ function news_search($queryarray, $andor, $limit, $offset, $userid) $sql .= 'ORDER BY created DESC'; $result = $xoopsDB->query($sql, $limit, $offset); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } $ret = []; $i = 0; while (false !== ($myrow = $xoopsDB->fetchArray($result))) { @@ -111,6 +114,9 @@ function news_search($queryarray, $andor, $limit, $offset, $userid) $i = $ind; $sql .= 'ORDER BY com_created DESC'; $result = $xoopsDB->query($sql, $limit, $offset); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } while (false !== ($myrow = $xoopsDB->fetchArray($result))) { $display = true; if ($modid && $grouppermHandler) { diff --git a/ratenews.php b/ratenews.php index 5f5ec8b..059ec1b 100644 --- a/ratenews.php +++ b/ratenews.php @@ -137,7 +137,11 @@ // Check if News POSTER is voting (UNLESS Anonymous users allowed to post) if (0 != $ratinguser) { - $result = $xoopsDB->query('SELECT uid FROM ' . $xoopsDB->prefix('news_stories') . " WHERE storyid=$storyid"); + $sql = 'SELECT uid FROM ' . $xoopsDB->prefix('news_stories') . " WHERE storyid=$storyid"; + $result = $xoopsDB->query($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } while ([$ratinguserDB] = $xoopsDB->fetchRow($result)) { if ($ratinguserDB == $ratinguser) { redirect_header(XOOPS_URL . '/modules/news/article.php?storyid=' . $storyid, 4, _NW_CANTVOTEOWN); @@ -145,7 +149,11 @@ } // Check if REG user is trying to vote twice. - $result = $xoopsDB->query('SELECT ratinguser FROM ' . $xoopsDB->prefix('news_stories_votedata') . " WHERE storyid=$storyid"); + $sql = 'SELECT ratinguser FROM ' . $xoopsDB->prefix('news_stories_votedata') . " WHERE storyid=$storyid"; + $result = $xoopsDB->query($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } while ([$ratinguserDB] = $xoopsDB->fetchRow($result)) { if ($ratinguserDB == $ratinguser) { redirect_header(XOOPS_URL . '/modules/news/article.php?storyid=' . $storyid, 4, _NW_VOTEONCE); @@ -154,7 +162,11 @@ } else { // Check if ANONYMOUS user is trying to vote more than once per day. $yesterday = (time() - (86400 * $anonwaitdays)); - $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('news_stories_votedata') . " WHERE storyid=$storyid AND ratinguser=0 AND ratinghostname = '$ip' AND ratingtimestamp > $yesterday"); + $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('news_stories_votedata') . " WHERE storyid=$storyid AND ratinguser=0 AND ratinghostname = '$ip' AND ratingtimestamp > $yesterday"; + $result = $xoopsDB->query($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } [$anonvotecount] = $xoopsDB->fetchRow($result); if ($anonvotecount >= 1) { redirect_header(XOOPS_URL . '/modules/news/article.php?storyid=' . $storyid, 4, _NW_VOTEONCE); diff --git a/xoops_version.php b/xoops_version.php index 197cba2..87b5c27 100644 --- a/xoops_version.php +++ b/xoops_version.php @@ -26,9 +26,9 @@ $moduleDirName = basename(__DIR__); $moduleDirNameUpper = \mb_strtoupper($moduleDirName); -$modversion['version'] = '1.72.0'; -$modversion['module_status'] = 'Beta 6'; -$modversion['release_date'] = '2022/10/24'; +$modversion['version'] = '1.73.0'; +$modversion['module_status'] = 'Beta 1'; +$modversion['release_date'] = '2022/11/05'; $modversion['name'] = _MI_NEWS_NAME; $modversion['description'] = _MI_NEWS_DESC; $modversion['credits'] = 'XOOPS Project, Christian, Pilou, Marco,
ALL the members of the Newbb Team, GIJOE, Zoullou, Mithrandir,
Setec Astronomy, Marcan, 5vision, Anne, Trabis, dhsoft, Mamba, Mage, Timgno'; @@ -44,7 +44,8 @@ //$modversion['icons16'] = '../../Frameworks/moduleclasses/icons/16'; //$modversion['icons32'] = '../../Frameworks/moduleclasses/icons/32'; $modversion['onInstall'] = 'include/install_function.php'; -$modversion['onUpdate'] = 'include/update_function.php'; +//$modversion['onUpdate'] = 'include/update_function.php'; +$modversion['onUpdate'] = 'include/onupdate.php'; $modversion['module_website_url'] = 'www.xoops.org/'; $modversion['module_website_name'] = 'XOOPS'; $modversion['author_website_url'] = 'https://xoops.org/'; @@ -230,7 +231,10 @@ // 2) If there's no topics to display as sub menus we can go on if (!isset($_SESSION['items_count']) || -1 == $_SESSION['items_count']) { $sql = 'SELECT COUNT(*) AS cpt FROM ' . $xoopsDB->prefix('news_topics') . ' WHERE menu=1'; - $result = $xoopsDB->query($sql); + $result = $xoopsDB->query($sql); + if (!$xoopsDB->isResultSet($result)) { + \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); + } [$count] = $xoopsDB->fetchRow($result); $_SESSION['items_count'] = $count; } else { From e6340d2025923cfa2eb82e023f6540b6309d4cbd Mon Sep 17 00:00:00 2001 From: mambax7 Date: Sun, 6 Nov 2022 03:04:53 -0500 Subject: [PATCH 04/29] Double quotes are unnecessary --- include/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/common.php b/include/common.php index 38afdfe..ece433a 100644 --- a/include/common.php +++ b/include/common.php @@ -93,7 +93,7 @@ xoops_loadLanguage('admin', $moduleDirName); xoops_loadLanguage('main', $moduleDirName); if (class_exists('D3LanguageManager')) { - require_once XOOPS_TRUST_PATH . "/libs/altsys/class/D3LanguageManager.class.php"; + require_once XOOPS_TRUST_PATH . '/libs/altsys/class/D3LanguageManager.class.php'; $langman = D3LanguageManager::getInstance(); $langman->read('admin.php', $moduleDirName); $langman->read('main.php', $moduleDirName); From 70f7c53e717cb347b505749b790f23d9e589a75f Mon Sep 17 00:00:00 2001 From: mambax7 Date: Sun, 6 Nov 2022 03:05:09 -0500 Subject: [PATCH 05/29] remove typecasting --- class/ObjectTree.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class/ObjectTree.php b/class/ObjectTree.php index 958dc21..1ad05d6 100644 --- a/class/ObjectTree.php +++ b/class/ObjectTree.php @@ -213,7 +213,7 @@ public function makeSelBox( $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); \trigger_error("makeSelBox() is deprecated since 2.5.9, please use makeSelectElement(), accessed from {$trace[0]['file']} line {$trace[0]['line']},"); $ret = ' Import forums links inside news (at the bottom of the news)"; - echo "
Import external links inside news (at the bottom of the news)"; - echo "

"; - echo ''; - echo "

If you check the two last options then the forum's link and all the external links will be added at the end of the body text."; - } else { + if (isset($_POST['go'])) { // Launch the import /** @var \XoopsModules\Ams\Helper $amsHelper */ $amsHelper = AmsHelper::getInstance(); @@ -264,6 +255,15 @@ } unset($notifications); echo "

The import is finished, don't forget to verify and set the topics permissions !

"; + } else { + echo '

Welcome to the AMS 2.41 import script

'; + echo '

Select the import options you wan to use :'; + echo "
"; + echo "
Import forums links inside news (at the bottom of the news)"; + echo "
Import external links inside news (at the bottom of the news)"; + echo "

"; + echo '
'; + echo "

If you check the two last options then the forum's link and all the external links will be added at the end of the body text."; } } else { redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); diff --git a/admin/index.php b/admin/index.php index 4b68369..a1d1d25 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1344,12 +1344,7 @@ function modTopicS(): void function delTopic(): void { global $xoopsDB, $xoopsModule; - if (!isset($_POST['ok'])) { - xoops_cp_header(); - echo '

' . _AM_CONFIG . '

'; - $xt = new XoopsTopic($xoopsDB->prefix('news_topics'), Request::getInt('topic_id', 0, 'GET')); - xoops_confirm(['op' => 'delTopic', 'topic_id' => Request::getInt('topic_id', 0, 'GET'), 'ok' => 1], 'index.php', _AM_WAYSYWTDTTAL . '
' . $xt->topic_title('S')); - } else { + if (isset($_POST['ok'])) { xoops_cp_header(); $xt = new \XoopsTopic($xoopsDB->prefix('news_topics'), Request::getInt('topic_id', 0, 'POST')); if (Request::hasVar('items_count', 'SESSION')) { @@ -1377,6 +1372,11 @@ function delTopic(): void } Utility::updateCache(); redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED); + } else { + xoops_cp_header(); + echo '

' . _AM_CONFIG . '

'; + $xt = new XoopsTopic($xoopsDB->prefix('news_topics'), Request::getInt('topic_id', 0, 'GET')); + xoops_confirm(['op' => 'delTopic', 'topic_id' => Request::getInt('topic_id', 0, 'GET'), 'ok' => 1], 'index.php', _AM_WAYSYWTDTTAL . '
' . $xt->topic_title('S')); } } @@ -1388,7 +1388,9 @@ function addTopic(): void $topicpid = Request::getInt('topic_pid', 0, 'POST'); $xt = new NewsTopic(); - if (!$xt->topicExists($topicpid, Request::getString('topic_title', '', 'POST'))) { + if ($xt->topicExists($topicpid, Request::getString('topic_title', '', 'POST'))) { + redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR); + } else { $xt->setTopicPid($topicpid); if (empty(Request::getString('topic_title', '', 'POST')) || '' == xoops_trim(Request::getString('topic_title', '', 'POST'))) { redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME); @@ -1458,8 +1460,6 @@ function addTopic(): void $tags['TOPIC_NAME'] = Request::getString('topic_title', '', 'POST'); $notificationHandler->triggerEvent('global', 0, 'new_category', $tags); redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED); - } else { - redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR); } } diff --git a/class/Common/Blocksadmin.php b/class/Common/Blocksadmin.php index 62b07a1..d0abcda 100644 --- a/class/Common/Blocksadmin.php +++ b/class/Common/Blocksadmin.php @@ -125,12 +125,12 @@ public function listBlocks(): void $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); - } else { + if ($this->db->isResultSet($result)) { while (false !== ($row = $this->db->fetchArray($result))) { $modules[] = (int)$row['module_id']; } + } else { + \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); } $cachetimeOptions = ''; foreach ($cachetimes as $cachetime => $cachetimeName) { @@ -284,12 +284,12 @@ public function cloneBlock(int $bid): void $myblock = new \XoopsBlock($bid); $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid; $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); - } else { + if ($this->db->isResultSet($result)) { while (false !== ($row = $this->db->fetchArray($result))) { $modules[] = (int)$row['module_id']; } + } else { + \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); } $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']); @@ -434,12 +434,12 @@ public function editBlock(int $bid): void $modules = []; $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid; $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); - } else { + if ($this->db->isResultSet($result)) { while (false !== ($row = $this->db->fetchArray($result))) { $modules[] = (int)$row['module_id']; } + } else { + \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); } $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']); diff --git a/class/Files.php b/class/Files.php index fdc2157..2772fee 100644 --- a/class/Files.php +++ b/class/Files.php @@ -167,12 +167,12 @@ public function store() $counter = $this->counter; $storyid = $this->storyid; - if (!isset($this->fileid)) { + if (isset($this->fileid)) { + $sql = 'UPDATE ' . $this->table . ' SET storyid=' . $storyid . ",filerealname='" . $fileRealName . "',date=" . $date . ",mimetype='" . $mimetype . "',downloadname='" . $downloadname . "',counter=" . $counter . ' WHERE fileid=' . $this->getFileid(); + } else { $newid = (int)$this->db->genId($this->table . '_fileid_seq'); $sql = 'INSERT INTO ' . $this->table . ' (fileid, storyid, filerealname, date, mimetype, downloadname, counter) ' . 'VALUES (' . $newid . ',' . $storyid . ",'" . $fileRealName . "','" . $date . "','" . $mimetype . "','" . $downloadname . "'," . $counter . ')'; $this->fileid = $newid; - } else { - $sql = 'UPDATE ' . $this->table . ' SET storyid=' . $storyid . ",filerealname='" . $fileRealName . "',date=" . $date . ",mimetype='" . $mimetype . "',downloadname='" . $downloadname . "',counter=" . $counter . ' WHERE fileid=' . $this->getFileid(); } if (!$result = $this->db->query($sql)) { return false; diff --git a/class/NewsStory.php b/class/NewsStory.php index a919b1c..875f1f9 100644 --- a/class/NewsStory.php +++ b/class/NewsStory.php @@ -239,17 +239,7 @@ public static function getAllPublished( $ret = []; $sql = 'SELECT s.*, t.* FROM ' . $db->prefix('news_stories') . ' s, ' . $db->prefix('news_topics') . ' t WHERE (s.published > 0 AND s.published <= ' . \time() . ') AND (s.expired = 0 OR s.expired > ' . \time() . ') AND (s.topicid=t.topic_id) '; if (0 != $topic) { - if (!\is_array($topic)) { - if ($checkRight) { - $topics = Utility::getMyItemIds('news_view'); - if (!\in_array($topic, $topics, true)) { - return null; - } - $sql .= ' AND s.topicid=' . (int)$topic . ' AND (s.ihome=1 OR s.ihome=0)'; - } else { - $sql .= ' AND s.topicid=' . (int)$topic . ' AND (s.ihome=1 OR s.ihome=0)'; - } - } else { + if (\is_array($topic)) { if ($checkRight) { $topics = Utility::getMyItemIds('news_view'); $topic = \array_intersect($topic, $topics); @@ -259,6 +249,16 @@ public static function getAllPublished( } else { return null; } + } else { + if ($checkRight) { + $topics = Utility::getMyItemIds('news_view'); + if (!\in_array($topic, $topics, true)) { + return null; + } + $sql .= ' AND s.topicid=' . (int)$topic . ' AND (s.ihome=1 OR s.ihome=0)'; + } else { + $sql .= ' AND s.topicid=' . (int)$topic . ' AND (s.ihome=1 OR s.ihome=0)'; + } } } else { if ($checkRight) { @@ -1100,68 +1100,68 @@ public function store($approved = false) $this->topicdisplay = 1; } $expired = !empty($this->expired) ? $this->expired : 0; - if (!isset($this->storyid)) { - //$newpost = 1; - $newstoryid = $this->db->genId($this->table . '_storyid_seq'); - $created = \time(); - $published = $this->approved ? (int)$this->published : 0; + if (isset($this->storyid)) { $sql = \sprintf( - "INSERT INTO `%s` (storyid, uid, title, created, published, expired, hostname, nohtml, nosmiley, hometext, bodytext, counter, topicid, ihome, notifypub, story_type, topicdisplay, topicalign, comments, rating, votes, description, keywords, picture, pictureinfo, subtitle) VALUES (%u, %u, '%s', %u, %u, %u, '%s', %u, %u, '%s', '%s', %u, %u, %u, %u, '%s', %u, '%s', %u, %u, %u, '%s', '%s', '%s', '%s', '%s')", + "UPDATE `%s` SET title='%s', published=%u, expired=%u, nohtml=%u, nosmiley=%u, hometext='%s', bodytext='%s', topicid=%u, ihome=%u, topicdisplay=%u, topicalign='%s', comments=%u, rating=%u, votes=%u, uid=%u, description='%s', keywords='%s', picture='%s' , pictureinfo='%s' , subtitle='%s' WHERE storyid = %u", $this->table, - $newstoryid, - (int)$this->uid(), $title, - $created, - $published, + (int)$this->published(), $expired, - $hostname, $this->nohtml(), $this->nosmiley(), $hometext, $bodytext, - $counter, (int)$this->topicid(), $this->ihome(), - $this->notifypub(), - $type, (int)$this->topicdisplay(), $this->topicalign, (int)$this->comments(), $rating, $votes, + (int)$this->uid(), $description, $keywords, $picture, $pictureinfo, - $subtitle + $subtitle, + (int)$this->storyid() ); + $newstoryid = (int)$this->storyid(); } else { + //$newpost = 1; + $newstoryid = $this->db->genId($this->table . '_storyid_seq'); + $created = \time(); + $published = $this->approved ? (int)$this->published : 0; $sql = \sprintf( - "UPDATE `%s` SET title='%s', published=%u, expired=%u, nohtml=%u, nosmiley=%u, hometext='%s', bodytext='%s', topicid=%u, ihome=%u, topicdisplay=%u, topicalign='%s', comments=%u, rating=%u, votes=%u, uid=%u, description='%s', keywords='%s', picture='%s' , pictureinfo='%s' , subtitle='%s' WHERE storyid = %u", + "INSERT INTO `%s` (storyid, uid, title, created, published, expired, hostname, nohtml, nosmiley, hometext, bodytext, counter, topicid, ihome, notifypub, story_type, topicdisplay, topicalign, comments, rating, votes, description, keywords, picture, pictureinfo, subtitle) VALUES (%u, %u, '%s', %u, %u, %u, '%s', %u, %u, '%s', '%s', %u, %u, %u, %u, '%s', %u, '%s', %u, %u, %u, '%s', '%s', '%s', '%s', '%s')", $this->table, + $newstoryid, + (int)$this->uid(), $title, - (int)$this->published(), + $created, + $published, $expired, + $hostname, $this->nohtml(), $this->nosmiley(), $hometext, $bodytext, + $counter, (int)$this->topicid(), $this->ihome(), + $this->notifypub(), + $type, (int)$this->topicdisplay(), $this->topicalign, (int)$this->comments(), $rating, $votes, - (int)$this->uid(), $description, $keywords, $picture, $pictureinfo, - $subtitle, - (int)$this->storyid() + $subtitle ); - $newstoryid = (int)$this->storyid(); } if (!$this->db->queryF($sql)) { return false; diff --git a/class/Registryfile.php b/class/Registryfile.php index 272d548..64eddc4 100644 --- a/class/Registryfile.php +++ b/class/Registryfile.php @@ -51,10 +51,10 @@ public function setfile($fichier = null): void public function getfile($fichier = null) { $fw = ''; - if (!$fichier) { - $fw = $this->filename; - } else { + if ($fichier) { $fw = XOOPS_UPLOAD_PATH . '/' . $fichier; + } else { + $fw = $this->filename; } if (\file_exists($fw)) { return file_get_contents($fw); @@ -72,10 +72,10 @@ public function getfile($fichier = null) public function savefile($content, $fichier = null) { $fw = ''; - if (!$fichier) { - $fw = $this->filename; - } else { + if ($fichier) { $fw = XOOPS_UPLOAD_PATH . '/' . $fichier; + } else { + $fw = $this->filename; } if (\is_file($fw)) { @\unlink($fw); diff --git a/class/XoopsStory.php b/class/XoopsStory.php index 9cd37db..7f914d9 100644 --- a/class/XoopsStory.php +++ b/class/XoopsStory.php @@ -254,36 +254,7 @@ public function store($approved = false) $this->topicdisplay = 1; } $expired = !empty($this->expired) ? $this->expired : 0; - if (!isset($this->storyid)) { - //$newpost = 1; - $newstoryid = $this->db->genId($this->table . '_storyid_seq'); - $created = \time(); - $published = $this->approved ? $this->published : 0; - - $sql = \sprintf( - "INSERT INTO `%s` (storyid, uid, title, created, published, expired, hostname, nohtml, nosmiley, hometext, bodytext, counter, topicid, ihome, notifypub, story_type, topicdisplay, topicalign, comments) VALUES (%u, %u, '%s', %u, %u, %u, '%s', %u, %u, '%s', '%s', %u, %u, %u, %u, '%s', %u, '%s', %u)", - $this->table, - $newstoryid, - $this->uid, - $title, - $created, - $published, - $expired, - $this->hostname, - $this->nohtml, - $this->nosmiley, - $hometext, - $bodytext, - 0, - $this->topicid, - $this->ihome, - $this->notifypub, - $this->type, - $this->topicdisplay, - $this->topicalign, - $this->comments - ); - } else { + if (isset($this->storyid)) { if ($this->approved) { $sql = \sprintf( "UPDATE `%s` SET title = '%s', published = %u, expired = %u, nohtml = %u, nosmiley = %u, hometext = '%s', bodytext = '%s', topicid = %u, ihome = %u, topicdisplay = %u, topicalign = '%s', comments = %u WHERE storyid = %u", @@ -321,6 +292,35 @@ public function store($approved = false) ); } $newstoryid = $this->storyid; + } else { + //$newpost = 1; + $newstoryid = $this->db->genId($this->table . '_storyid_seq'); + $created = \time(); + $published = $this->approved ? $this->published : 0; + + $sql = \sprintf( + "INSERT INTO `%s` (storyid, uid, title, created, published, expired, hostname, nohtml, nosmiley, hometext, bodytext, counter, topicid, ihome, notifypub, story_type, topicdisplay, topicalign, comments) VALUES (%u, %u, '%s', %u, %u, %u, '%s', %u, %u, '%s', '%s', %u, %u, %u, %u, '%s', %u, '%s', %u)", + $this->table, + $newstoryid, + $this->uid, + $title, + $created, + $published, + $expired, + $this->hostname, + $this->nohtml, + $this->nosmiley, + $hometext, + $bodytext, + 0, + $this->topicid, + $this->ihome, + $this->notifypub, + $this->type, + $this->topicdisplay, + $this->topicalign, + $this->comments + ); } if (!$result = $this->db->query($sql)) { return false; diff --git a/ratenews.php b/ratenews.php index 059ec1b..874023b 100644 --- a/ratenews.php +++ b/ratenews.php @@ -114,10 +114,10 @@ if (!empty($_POST['submit'])) { // The form was submited $eh = new ErrorHandler(); //ErrorHandler object - if (!is_object($xoopsUser)) { - $ratinguser = 0; - } else { + if (is_object($xoopsUser)) { $ratinguser = $xoopsUser->getVar('uid'); + } else { + $ratinguser = 0; } //Make sure only 1 anonymous from an IP in a single day. diff --git a/submit.php b/submit.php index 214e0d7..ae3f639 100644 --- a/submit.php +++ b/submit.php @@ -111,18 +111,18 @@ $approveprivilege = 1; } else { unset($tmpstory); - if (!Utility::isAdminGroup()) { - redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); - } else { + if (Utility::isAdminGroup()) { $approveprivilege = 1; + } else { + redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); } } } - } elseif (!Utility::isAdminGroup()) { + } elseif (Utility::isAdminGroup()) { + $approveprivilege = 1; + } else { unset($tmpstory); redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); - } else { - $approveprivilege = 1; } } @@ -174,10 +174,10 @@ $type = $story->type(); $topicdisplay = $story->topicdisplay(); $topicalign = $story->topicalign(false); - if (!Utility::isAdminGroup()) { - require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php'; - } else { + if (Utility::isAdminGroup()) { require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php'; + } else { + require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.inc.php'; } echo ''; break; @@ -550,10 +550,10 @@ echo _ERRORS; } $returnside = Request::getInt('returnside', 0, 'POST'); - if (!$returnside) { - redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_THANKS); - } else { + if ($returnside) { redirect_header(XOOPS_URL . '/modules/news/admin/index.php?op=newarticle', 2, _NW_THANKS); + } else { + redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_THANKS); } break; case 'form': From a53f3c5e6157a02b28c6ec717c01b512b922cd70 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Sun, 6 Nov 2022 07:47:25 -0500 Subject: [PATCH 10/29] PSR-12: Usage of 'else if' construct --- class/NewsStory.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/class/NewsStory.php b/class/NewsStory.php index 875f1f9..bb492de 100644 --- a/class/NewsStory.php +++ b/class/NewsStory.php @@ -249,8 +249,7 @@ public static function getAllPublished( } else { return null; } - } else { - if ($checkRight) { + } elseif ($checkRight) { $topics = Utility::getMyItemIds('news_view'); if (!\in_array($topic, $topics, true)) { return null; @@ -258,7 +257,6 @@ public static function getAllPublished( $sql .= ' AND s.topicid=' . (int)$topic . ' AND (s.ihome=1 OR s.ihome=0)'; } else { $sql .= ' AND s.topicid=' . (int)$topic . ' AND (s.ihome=1 OR s.ihome=0)'; - } } } else { if ($checkRight) { @@ -826,7 +824,7 @@ public function textlink() public function prepare2show($filescount) { global $xoopsUser, $xoopsConfig, $xoopsModule; - /** @var News\Helper $helper */ + /** @var Helper $helper */ $helper = Helper::getInstance(); $dirname = \basename(\dirname(__DIR__)); From cc13714f393df48d8848c00cd3d7ec0cdc53babb Mon Sep 17 00:00:00 2001 From: mambax7 Date: Sun, 6 Nov 2022 07:49:06 -0500 Subject: [PATCH 11/29] namespaces --- admin/admin_header.php | 2 +- admin/menu.php | 5 +-- admin/upgrade.php | 49 ++++++++++++------------- archive.php | 11 +++--- article.php | 2 +- backendt.php | 7 ++-- blocks/news_bigstory.php | 9 ++--- blocks/news_moderate.php | 9 ++--- blocks/news_randomnews.php | 11 +++--- blocks/news_topicsnav.php | 3 +- class/Common/DirectoryChecker.php | 6 ++-- comment_new.php | 8 +++-- comment_post.php | 5 +-- include/common.php | 7 ++-- include/functions.php | 13 +++---- include/oninstall.php | 7 ++-- include/onuninstall.php | 7 ++-- include/search.inc.php | 5 +-- include/storyform.inc.php | 20 ++++++----- include/storyform.original.php | 16 +++++---- include/update_function.php | 60 ++++++++++++++++--------------- list.tag.php | 3 +- micro_summary.php | 5 +-- newsbythisauthor.php | 22 ++++++------ print.php | 7 ++-- ratenews.php | 9 ++--- topics_directory.php | 7 ++-- view.tag.php | 2 +- whoswho.php | 11 +++--- xoops_version.php | 10 +++--- 30 files changed, 185 insertions(+), 153 deletions(-) diff --git a/admin/admin_header.php b/admin/admin_header.php index 6d83e94..cb842c9 100644 --- a/admin/admin_header.php +++ b/admin/admin_header.php @@ -21,7 +21,7 @@ use XoopsModules\News\Helper; require \dirname(__DIR__, 3) . '/include/cp_header.php'; -require_once $GLOBALS['xoops']->path('www/class/xoopsformloader.php'); +require \dirname(__DIR__, 3) . '/class/xoopsformloader.php'; // require_once \dirname(__DIR__) . '/class/Utility.php'; require_once \dirname(__DIR__) . '/include/common.php'; diff --git a/admin/menu.php b/admin/menu.php index 91f66a1..e7326bb 100644 --- a/admin/menu.php +++ b/admin/menu.php @@ -17,12 +17,13 @@ use Xmf\Module\Admin; use XoopsModules\News; +use XoopsModules\News\Helper; -/** @var News\Helper $helper */ +/** @var Helper $helper */ $moduleDirName = \basename(\dirname(__DIR__)); $moduleDirNameUpper = \mb_strtoupper($moduleDirName); -$helper = News\Helper::getInstance(); +$helper = Helper::getInstance(); $helper->loadLanguage('common'); $helper->loadLanguage('feedback'); diff --git a/admin/upgrade.php b/admin/upgrade.php index 4b6ca49..3cd2c05 100644 --- a/admin/upgrade.php +++ b/admin/upgrade.php @@ -16,6 +16,7 @@ */ use XoopsModules\News; +use XoopsModules\News\Utility; require \dirname(__DIR__, 3) . '/include/cp_header.php'; xoops_cp_header(); @@ -23,7 +24,7 @@ if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) { $errors = 0; // 1) Create, if it does not exists, the stories_files table - if (!News\Utility::existTable($xoopsDB->prefix('news_stories_files'))) { + if (!Utility::existTable($xoopsDB->prefix('news_stories_files'))) { $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_files') . " ( fileid INT(8) UNSIGNED NOT NULL AUTO_INCREMENT, filerealname VARCHAR(255) NOT NULL DEFAULT '', @@ -50,24 +51,24 @@ } // 2.1) Add the new fields to the topic table - if (!News\Utility::existField('menu', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField("menu TINYINT( 1 ) DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_topics')); + if (!Utility::existField('menu', $xoopsDB->prefix('news_topics'))) { + Utility::addField("menu TINYINT( 1 ) DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_topics')); } - if (!News\Utility::existField('topic_frontpage', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField("topic_frontpage TINYINT( 1 ) DEFAULT '1' NOT NULL", $xoopsDB->prefix('news_topics')); + if (!Utility::existField('topic_frontpage', $xoopsDB->prefix('news_topics'))) { + Utility::addField("topic_frontpage TINYINT( 1 ) DEFAULT '1' NOT NULL", $xoopsDB->prefix('news_topics')); } - if (!News\Utility::existField('topic_rssurl', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField('topic_rssurl VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('news_topics')); + if (!Utility::existField('topic_rssurl', $xoopsDB->prefix('news_topics'))) { + Utility::addField('topic_rssurl VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('news_topics')); } - if (!News\Utility::existField('topic_description', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField('topic_description TEXT NOT NULL', $xoopsDB->prefix('news_topics')); + if (!Utility::existField('topic_description', $xoopsDB->prefix('news_topics'))) { + Utility::addField('topic_description TEXT NOT NULL', $xoopsDB->prefix('news_topics')); } - if (!News\Utility::existField('topic_color', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField("topic_color varchar(6) NOT NULL default '000000'", $xoopsDB->prefix('news_topics')); + if (!Utility::existField('topic_color', $xoopsDB->prefix('news_topics'))) { + Utility::addField("topic_color varchar(6) NOT NULL default '000000'", $xoopsDB->prefix('news_topics')); } // 3) If it does not exists, create the table stories_votedata - if (!News\Utility::existTable($xoopsDB->prefix('news_stories_votedata'))) { + if (!Utility::existTable($xoopsDB->prefix('news_stories_votedata'))) { $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_votedata') . " ( ratingid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, storyid INT(8) UNSIGNED NOT NULL DEFAULT '0', @@ -87,23 +88,23 @@ } // 4) Create the four new fields for the votes in the story table - if (!News\Utility::existField('rating', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField("rating DOUBLE( 6, 4 ) DEFAULT '0.0000' NOT NULL", $xoopsDB->prefix('news_stories')); + if (!Utility::existField('rating', $xoopsDB->prefix('news_stories'))) { + Utility::addField("rating DOUBLE( 6, 4 ) DEFAULT '0.0000' NOT NULL", $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('votes', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField("votes INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_stories')); + if (!Utility::existField('votes', $xoopsDB->prefix('news_stories'))) { + Utility::addField("votes INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('keywords', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField('keywords VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); + if (!Utility::existField('keywords', $xoopsDB->prefix('news_stories'))) { + Utility::addField('keywords VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('description', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField('description VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); + if (!Utility::existField('description', $xoopsDB->prefix('news_stories'))) { + Utility::addField('description VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('pictureinfo', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField('pictureinfo VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); + if (!Utility::existField('pictureinfo', $xoopsDB->prefix('news_stories'))) { + Utility::addField('pictureinfo VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('subtitle', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField('subtitle VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); + if (!Utility::existField('subtitle', $xoopsDB->prefix('news_stories'))) { + Utility::addField('subtitle VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); } // 5) Add some indexes to the topics table diff --git a/archive.php b/archive.php index 65eacf5..1618c62 100644 --- a/archive.php +++ b/archive.php @@ -69,6 +69,7 @@ use Xmf\Request; use XoopsModules\News; use XoopsModules\News\NewsStory; +use XoopsModules\News\Utility; require_once \dirname(__DIR__, 2) . '/mainfile.php'; $GLOBALS['xoopsOption']['template_main'] = 'news_archive.tpl'; @@ -101,9 +102,9 @@ if ($fromyear && $frommonth) { $pgtitle = sprintf(' - %d - %d', $fromyear, $frommonth); } -$infotips = News\Utility::getModuleOption('infotips'); -$restricted = News\Utility::getModuleOption('restrictindex'); -$dateformat = News\Utility::getModuleOption('dateformat'); +$infotips = Utility::getModuleOption('infotips'); +$restricted = Utility::getModuleOption('restrictindex'); +$dateformat = Utility::getModuleOption('dateformat'); if ('' === $dateformat) { $dateformat = 'm'; } @@ -183,7 +184,7 @@ $story = []; $htmltitle = ''; if ($infotips > 0) { - $story['infotips'] = News\Utility::makeInfotips($article->hometext()); + $story['infotips'] = Utility::makeInfotips($article->hometext()); $htmltitle = ' title="' . $story['infotips'] . '"'; } $story['title'] = "activated = false; -if (!News\Utility::getModuleOption('topicsrss')) { +if (!Utility::getModuleOption('topicsrss')) { exit(); } @@ -53,8 +54,8 @@ mb_http_output('pass'); } -$restricted = News\Utility::getModuleOption('restrictindex'); -$newsnumber = News\Utility::getModuleOption('storyhome'); +$restricted = Utility::getModuleOption('restrictindex'); +$newsnumber = Utility::getModuleOption('storyhome'); $charset = 'utf-8'; diff --git a/blocks/news_bigstory.php b/blocks/news_bigstory.php index ed1a807..ca359ae 100644 --- a/blocks/news_bigstory.php +++ b/blocks/news_bigstory.php @@ -18,6 +18,7 @@ use XoopsModules\News; use XoopsModules\News\Helper; use XoopsModules\News\NewsStory; +use XoopsModules\News\Utility; /** * @return array|null|false @@ -34,9 +35,9 @@ function b_news_bigstory_show() $helper = Helper::getInstance(); $myts = \MyTextSanitizer::getInstance(); - $restricted = News\Utility::getModuleOption('restrictindex'); - $dateformat = News\Utility::getModuleOption('dateformat'); - $infotips = News\Utility::getModuleOption('infotips'); + $restricted = Utility::getModuleOption('restrictindex'); + $dateformat = Utility::getModuleOption('dateformat'); + $infotips = Utility::getModuleOption('infotips'); $block = []; $onestory = new NewsStory(); @@ -47,7 +48,7 @@ function b_news_bigstory_show() foreach ($stories as $key => $story) { $htmltitle = ''; if ($infotips > 0) { - $block['infotips'] = News\Utility::makeInfotips($story->hometext()); + $block['infotips'] = Utility::makeInfotips($story->hometext()); $htmltitle = ' title="' . $block['infotips'] . '"'; } else { $htmltitle = ' title="' . $story->title('Show') . '"'; diff --git a/blocks/news_moderate.php b/blocks/news_moderate.php index 1b3c6c8..f5e4973 100644 --- a/blocks/news_moderate.php +++ b/blocks/news_moderate.php @@ -18,6 +18,7 @@ use XoopsModules\News; use XoopsModules\News\Helper; use XoopsModules\News\NewsStory; +use XoopsModules\News\Utility; /** * Display a block where news moderators can show news that needs to be moderated. @@ -34,10 +35,10 @@ function b_news_topics_moderate() $helper = Helper::getInstance(); $block = []; - $dateformat = News\Utility::getModuleOption('dateformat'); - $infotips = News\Utility::getModuleOption('infotips'); + $dateformat = Utility::getModuleOption('dateformat'); + $infotips = Utility::getModuleOption('infotips'); - $storyarray = NewsStory:: getAllSubmitted(0, true, News\Utility::getModuleOption('restrictindex')); + $storyarray = NewsStory:: getAllSubmitted(0, true, Utility::getModuleOption('restrictindex')); if (count($storyarray) > 0) { $block['lang_story_title'] = _MB_TITLE; $block['lang_story_date'] = _MB_POSTED; @@ -49,7 +50,7 @@ function b_news_topics_moderate() $title = $newstory->title(); $htmltitle = ''; if ($infotips > 0) { - $story['infotips'] = News\Utility::makeInfotips($newstory->hometext()); + $story['infotips'] = Utility::makeInfotips($newstory->hometext()); $htmltitle = ' title="' . $story['infotips'] . '"'; } diff --git a/blocks/news_randomnews.php b/blocks/news_randomnews.php index 513867b..2f28a59 100644 --- a/blocks/news_randomnews.php +++ b/blocks/news_randomnews.php @@ -18,6 +18,7 @@ use XoopsModules\News; use XoopsModules\News\Helper; use XoopsModules\News\NewsStory; +use XoopsModules\News\Utility; // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; @@ -40,9 +41,9 @@ function b_news_randomnews_show($options) $block['sort'] = $options[0]; $tmpstory = new NewsStory(); - $restricted = News\Utility::getModuleOption('restrictindex'); - $dateformat = News\Utility::getModuleOption('dateformat'); - $infotips = News\Utility::getModuleOption('infotips'); + $restricted = Utility::getModuleOption('restrictindex'); + $dateformat = Utility::getModuleOption('dateformat'); + $infotips = Utility::getModuleOption('infotips'); if ('' == $dateformat) { $dateformat = 's'; } @@ -76,12 +77,12 @@ function b_news_randomnews_show($options) if ($options[3] > 0) { $html = 1 == $story->nohtml() ? 0 : 1; - $news['teaser'] = News\Utility::truncateTagSafe($myts->displayTarea($story->hometext, $html), $options[3] + 3); + $news['teaser'] = Utility::truncateTagSafe($myts->displayTarea($story->hometext, $html), $options[3] + 3); $news['infotips'] = ' title="' . $story->title() . '"'; } else { $news['teaser'] = ''; if ($infotips > 0) { - $news['infotips'] = ' title="' . News\Utility::makeInfotips($story->hometext()) . '"'; + $news['infotips'] = ' title="' . Utility::makeInfotips($story->hometext()) . '"'; } else { $news['infotips'] = ' title="' . $story->title() . '"'; } diff --git a/blocks/news_topicsnav.php b/blocks/news_topicsnav.php index 16a6a77..3bbbf8b 100644 --- a/blocks/news_topicsnav.php +++ b/blocks/news_topicsnav.php @@ -18,6 +18,7 @@ use XoopsModules\News; use XoopsModules\News\Helper; use XoopsModules\News\NewsTopic; +use XoopsModules\News\Utility; /** * @param $options @@ -38,7 +39,7 @@ function b_news_topicsnav_show($options) $newscountbytopic = []; $perms = ''; $xt = new NewsTopic(); - $restricted = News\Utility::getModuleOption('restrictindex'); + $restricted = Utility::getModuleOption('restrictindex'); if ($restricted) { global $xoopsUser; /** @var \XoopsModuleHandler $moduleHandler */ diff --git a/class/Common/DirectoryChecker.php b/class/Common/DirectoryChecker.php index 463d2b2..e1233f4 100644 --- a/class/Common/DirectoryChecker.php +++ b/class/Common/DirectoryChecker.php @@ -36,9 +36,9 @@ class DirectoryChecker { /** - * @param $path - * @param int $mode - * @param $redirectFile + * @param string $path + * @param int $mode + * @param string|null $redirectFile * * @return bool|string */ diff --git a/comment_new.php b/comment_new.php index 5830504..b488aa5 100644 --- a/comment_new.php +++ b/comment_new.php @@ -17,12 +17,14 @@ use Xmf\Request; use XoopsModules\News; +use XoopsModules\News\Helper; use XoopsModules\News\NewsStory; +use XoopsModules\News\Utility; require_once \dirname(__DIR__, 2) . '/mainfile.php'; -/** @var News\Helper $helper */ -$helper = News\Helper::getInstance(); +/** @var Helper $helper */ +$helper = Helper::getInstance(); // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; @@ -44,7 +46,7 @@ if ($com_itemid > 0) { $article = new NewsStory($com_itemid); if ($article->storyid > 0) { - $com_replytext = _POSTEDBY . ' ' . $article->uname() . ' ' . _DATE . ' ' . formatTimestamp($article->published(), News\Utility::getModuleOption('dateformat')) . '

' . $article->hometext(); + $com_replytext = _POSTEDBY . ' ' . $article->uname() . ' ' . _DATE . ' ' . formatTimestamp($article->published(), Utility::getModuleOption('dateformat')) . '

' . $article->hometext(); $bodytext = $article->bodytext(); if ('' !== $bodytext) { $com_replytext .= '

' . $bodytext; diff --git a/comment_post.php b/comment_post.php index ef346b2..7539b42 100644 --- a/comment_post.php +++ b/comment_post.php @@ -16,11 +16,12 @@ */ use XoopsModules\News; +use XoopsModules\News\Helper; require_once \dirname(__DIR__, 2) . '/mainfile.php'; -/** @var News\Helper $helper */ -$helper = News\Helper::getInstance(); +/** @var Helper $helper */ +$helper = Helper::getInstance(); // We verify that the user can post comments ********************************** if (null === $helper->getModule()) { diff --git a/include/common.php b/include/common.php index ece433a..c61613b 100644 --- a/include/common.php +++ b/include/common.php @@ -16,6 +16,7 @@ */ use XoopsModules\News; +use XoopsModules\News\Helper; use XoopsModules\News\Utility; require_once \dirname(__DIR__) . '/preloads/autoloader.php'; @@ -24,10 +25,10 @@ $moduleDirNameUpper = \mb_strtoupper($moduleDirName); /** @var \XoopsDatabase $db */ -/** @var News\Helper $helper */ -/** @var News\Utility $utility */ +/** @var Helper $helper */ +/** @var Utility $utility */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); -$helper = News\Helper::getInstance(); +$helper = Helper::getInstance(); $utility = new Utility(); //$configurator = new \XoopsModules\News\Common\Configurator(); diff --git a/include/functions.php b/include/functions.php index 3cc35f4..32ff294 100644 --- a/include/functions.php +++ b/include/functions.php @@ -34,6 +34,7 @@ use XoopsModules\News\Blacklist; use XoopsModules\News\NewsTopic; use XoopsModules\News\Registryfile; +use XoopsModules\News\Utility; /** * @param $option @@ -371,11 +372,11 @@ function news_CreateMetaDatas($story = null): void /** @var \XoopsConfigHandler $configHandler */ $configHandler = xoops_getHandler('config'); $xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER); - $content .= '\n"; - $content .= '\n"; - $content .= '\n"; - $content .= '\n"; - $content .= '\n"; + $content .= '\n"; + $content .= '\n"; + $content .= '\n"; + $content .= '\n"; + $content .= '\n"; $content .= '\n"; $content .= '\n"; $content .= '\n"; @@ -383,7 +384,7 @@ function news_CreateMetaDatas($story = null): void $content .= '\n"; $content .= '\n"; if (isset($xoopsConfigMetaFooter['meta_copyright'])) { - $content .= '\n"; + $content .= '\n"; } } diff --git a/include/oninstall.php b/include/oninstall.php index 25ef2c1..027753c 100644 --- a/include/oninstall.php +++ b/include/oninstall.php @@ -17,6 +17,7 @@ use XoopsModules\News; use XoopsModules\News\Common\Configurator; +use XoopsModules\News\Helper; use XoopsModules\News\Utility; /** @@ -28,7 +29,7 @@ function xoops_module_pre_install_news(\XoopsModule $module) { require_once \dirname(__DIR__) . '/preloads/autoloader.php'; - /** @var News\Utility $utility */ + /** @var Utility $utility */ $utility = new Utility(); $xoopsSuccess = $utility::checkVerXoops($module); $phpSuccess = $utility::checkVerPhp($module); @@ -55,8 +56,8 @@ function xoops_module_install_news(\XoopsModule $module) $moduleDirName = \basename(\dirname(__DIR__)); - /** @var News\Helper $helper */ - $helper = News\Helper::getInstance(); + /** @var Helper $helper */ + $helper = Helper::getInstance(); $utility = new Utility(); $configurator = new Configurator(); // Load language files diff --git a/include/onuninstall.php b/include/onuninstall.php index 55177ff..68a1d78 100644 --- a/include/onuninstall.php +++ b/include/onuninstall.php @@ -10,6 +10,7 @@ */ use XoopsModules\News; +use XoopsModules\News\Helper; use XoopsModules\News\Utility; /** @@ -36,10 +37,10 @@ function xoops_module_uninstall_news(\XoopsModule $module) $moduleDirName = \basename(\dirname(__DIR__)); $moduleDirNameUpper = \mb_strtoupper($moduleDirName); - /** @var News\Helper $helper */ - $helper = News\Helper::getInstance(); + /** @var Helper $helper */ + $helper = Helper::getInstance(); - /** @var News\Utility $utility */ + /** @var Utility $utility */ $utility = new Utility(); $success = true; diff --git a/include/search.inc.php b/include/search.inc.php index ccb53c4..43f9dc8 100644 --- a/include/search.inc.php +++ b/include/search.inc.php @@ -16,6 +16,7 @@ */ use XoopsModules\News; +use XoopsModules\News\Utility; /** * @param $queryarray @@ -29,9 +30,9 @@ function news_search($queryarray, $andor, $limit, $offset, $userid) { global $xoopsDB, $xoopsUser; - $restricted = News\Utility::getModuleOption('restrictindex'); + $restricted = Utility::getModuleOption('restrictindex'); $highlight = false; - $highlight = News\Utility::getModuleOption('keywordshighlight'); // keywords highlighting + $highlight = Utility::getModuleOption('keywordshighlight'); // keywords highlighting /** @var \XoopsModuleHandler $moduleHandler */ $moduleHandler = xoops_getHandler('module'); diff --git a/include/storyform.inc.php b/include/storyform.inc.php index 4049254..52736e5 100644 --- a/include/storyform.inc.php +++ b/include/storyform.inc.php @@ -16,10 +16,12 @@ */ use Xmf\Request; +use XoopsModules\Tag\FormTag; use XoopsModules\News; use XoopsModules\News\Files; use XoopsModules\News\NewsTopic; -use XoopsModules\Tag\FormTag; +use XoopsModules\News\Utility; + $moduleDirName = \basename(\dirname(__DIR__)); xoops_load('utility', $moduleDirName); @@ -49,7 +51,7 @@ $allTopics = $xt->getAllTopics($helper->getConfig('restrictindex'), 'news_submit'); $topic_tree = new \XoopsObjectTree($allTopics, 'topic_id', 'topic_pid'); -if (News\Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { +if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { $topic_select = $topic_tree->makeSelectElement('topic_id', 'topic_title', '--', $topicid, false, 0, '', _NW_TOPIC); $sform->addElement($topic_select); } else { @@ -89,26 +91,26 @@ } } -$editor = News\Utility::getWysiwygForm(_NW_THESCOOP, 'hometext', $hometext, 15, 60, 'hometext_hidden'); +$editor = Utility::getWysiwygForm(_NW_THESCOOP, 'hometext', $hometext, 15, 60, 'hometext_hidden'); $sform->addElement($editor, true); //Extra info //If admin -> if submit privilege if ($approveprivilege) { - $editor2 = News\Utility::getWysiwygForm(_AM_EXTEXT, 'bodytext', $bodytext, 15, 60, 'bodytext_hidden'); + $editor2 = Utility::getWysiwygForm(_AM_EXTEXT, 'bodytext', $bodytext, 15, 60, 'bodytext_hidden'); $sform->addElement($editor2, false); - if (News\Utility::getModuleOption('tags') && \class_exists(\XoopsModules\Tag\FormTag::class) && xoops_isActiveModule('tag')) { + if (Utility::getModuleOption('tags') && \class_exists(\XoopsModules\Tag\FormTag::class) && xoops_isActiveModule('tag')) { $itemIdForTag = $storyid ?? 0; $sform->addElement(new \XoopsModules\Tag\FormTag('item_tag', 60, 255, $itemIdForTag, 0)); } - if (News\Utility::getModuleOption('metadata')) { + if (Utility::getModuleOption('metadata')) { $sform->addElement(new xoopsFormText(_NW_META_DESCRIPTION, 'description', 50, 255, $description), false); $sform->addElement(new xoopsFormText(_NW_META_KEYWORDS, 'keywords', 50, 255, $keywords), false); } -} elseif (News\Utility::getModuleOption('tags') && \class_exists(\XoopsModules\Tag\FormTag::class) && xoops_isActiveModule('tag')) { +} elseif (Utility::getModuleOption('tags') && \class_exists(\XoopsModules\Tag\FormTag::class) && xoops_isActiveModule('tag')) { $itemIdForTag = $storyid ?? 0; $sform->addElement(new \XoopsModules\Tag\FormTag('item_tag', 60, 255, $itemIdForTag, 0)); } @@ -240,8 +242,8 @@ $sform->addElement($type_hidden); echo '

' . _NW_SUBMITNEWS . '

'; -if ('' !== xoops_trim(News\Utility::getModuleOption('submitintromsg'))) { - echo "


" . nl2br(News\Utility::getModuleOption('submitintromsg')) . '

'; +if ('' !== xoops_trim(Utility::getModuleOption('submitintromsg'))) { + echo "


" . nl2br(Utility::getModuleOption('submitintromsg')) . '

'; } $sform->display(); diff --git a/include/storyform.original.php b/include/storyform.original.php index 9b579aa..d2ed548 100644 --- a/include/storyform.original.php +++ b/include/storyform.original.php @@ -18,14 +18,16 @@ use Xmf\Request; use XoopsModules\News; use XoopsModules\News\Files; +use XoopsModules\News\Helper; use XoopsModules\News\NewsTopic; +use XoopsModules\News\Utility; use XoopsModules\Tag\FormTag; require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; require_once XOOPS_ROOT_PATH . '/modules/news/config.php'; -/** @var News\Helper $helper */ -$helper = News\Helper::getInstance(); +/** @var Helper $helper */ +$helper = Helper::getInstance(); xoops_loadLanguage('calendar'); if (!isset($subtitle)) { @@ -55,7 +57,7 @@ $moduleDirName = \basename(\dirname(__DIR__)); xoops_load('utility', $moduleDirName); -if (News\Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { +if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { // $topic_select = $topic_tree->makeSelBox('topic_id', 'topic_title', '-- ', $topicid, false); $topic_select = $topic_tree->makeSelectElement('topic_id', 'topic_title', '--', $topicid, false, 0, '', _NW_TOPIC); $sform->addElement($topic_select); @@ -94,21 +96,21 @@ } } -$editor = News\Utility::getWysiwygForm(_NW_THESCOOP, 'hometext', $hometext, 15, 60, 'hometext_hidden'); +$editor = Utility::getWysiwygForm(_NW_THESCOOP, 'hometext', $hometext, 15, 60, 'hometext_hidden'); $sform->addElement($editor, true); //Extra info //If admin -> if submit privilege if ($approveprivilege) { - $editor2 = News\Utility::getWysiwygForm(_AM_EXTEXT, 'bodytext', $bodytext, 15, 60, 'bodytext_hidden'); + $editor2 = Utility::getWysiwygForm(_AM_EXTEXT, 'bodytext', $bodytext, 15, 60, 'bodytext_hidden'); $sform->addElement($editor2, false); - if (News\Utility::getModuleOption('tags') && \class_exists(\XoopsModules\Tag\FormTag::class) && xoops_isActiveModule('tag')) { + if (Utility::getModuleOption('tags') && \class_exists(\XoopsModules\Tag\FormTag::class) && xoops_isActiveModule('tag')) { $itemIdForTag = $storyid ?? 0; $sform->addElement(new \XoopsModules\Tag\FormTag('item_tag', 60, 255, $itemIdForTag, 0)); } - if (News\Utility::getModuleOption('metadata')) { + if (Utility::getModuleOption('metadata')) { $sform->addElement(new xoopsFormText(_NW_META_DESCRIPTION, 'description', 50, 255, $description), false); $sform->addElement(new xoopsFormText(_NW_META_KEYWORDS, 'keywords', 50, 255, $keywords), false); } diff --git a/include/update_function.php b/include/update_function.php index 6e3e99f..6734435 100644 --- a/include/update_function.php +++ b/include/update_function.php @@ -15,7 +15,9 @@ * @author Voltan */ -use XoopsModules\News; +use XoopsModules\News\{ + Utility +}; /** * @return bool @@ -27,14 +29,14 @@ function xoops_module_update_news() //0) Rename all tables - if (News\Utility::existTable($xoopsDB->prefix('stories_files'))) { + if (Utility::existTable($xoopsDB->prefix('stories_files'))) { $sql = 'ALTER TABLE ' . $xoopsDB->prefix('stories_files') . ' RENAME ' . $xoopsDB->prefix('news_stories_files'); $result = $xoopsDB->queryF($sql); if (!$result) { echo '
' . _AM_NEWS_UPGRADEFAILED . ' ' . _AM_NEWS_UPGRADEFAILED2; ++$errors; } - } elseif (!News\Utility::existTable($xoopsDB->prefix('news_stories_files'))) { + } elseif (!Utility::existTable($xoopsDB->prefix('news_stories_files'))) { // 1) Create, if it does not exists, the stories_files table $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_files') . " ( fileid INT(8) UNSIGNED NOT NULL AUTO_INCREMENT, @@ -53,7 +55,7 @@ function xoops_module_update_news() } } - if (News\Utility::existTable($xoopsDB->prefix('stories'))) { + if (Utility::existTable($xoopsDB->prefix('stories'))) { $sql = 'ALTER TABLE ' . $xoopsDB->prefix('stories') . ' RENAME ' . $xoopsDB->prefix('news_stories'); $result = $xoopsDB->queryF($sql); if (!$result) { @@ -62,7 +64,7 @@ function xoops_module_update_news() } } - if (News\Utility::existTable($xoopsDB->prefix('topics'))) { + if (Utility::existTable($xoopsDB->prefix('topics'))) { $sql = 'ALTER TABLE ' . $xoopsDB->prefix('topics') . ' RENAME ' . $xoopsDB->prefix('news_topics'); $result = $xoopsDB->queryF($sql); if (!$result) { @@ -71,7 +73,7 @@ function xoops_module_update_news() } } - if (News\Utility::existTable($xoopsDB->prefix('stories_files'))) { + if (Utility::existTable($xoopsDB->prefix('stories_files'))) { $sql = 'ALTER TABLE ' . $xoopsDB->prefix('stories_files') . ' RENAME ' . $xoopsDB->prefix('news_stories_files'); $result = $xoopsDB->queryF($sql); if (!$result) { @@ -106,24 +108,24 @@ function xoops_module_update_news() // 2.1) Add the new fields to the topic table - if (!News\Utility::existField('menu', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField("menu TINYINT( 1 ) DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_topics')); + if (!Utility::existField('menu', $xoopsDB->prefix('news_topics'))) { + Utility::addField("menu TINYINT( 1 ) DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_topics')); } - if (!News\Utility::existField('topic_frontpage', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField("topic_frontpage TINYINT( 1 ) DEFAULT '1' NOT NULL", $xoopsDB->prefix('news_topics')); + if (!Utility::existField('topic_frontpage', $xoopsDB->prefix('news_topics'))) { + Utility::addField("topic_frontpage TINYINT( 1 ) DEFAULT '1' NOT NULL", $xoopsDB->prefix('news_topics')); } - if (!News\Utility::existField('topic_rssurl', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField('topic_rssurl VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('news_topics')); + if (!Utility::existField('topic_rssurl', $xoopsDB->prefix('news_topics'))) { + Utility::addField('topic_rssurl VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('news_topics')); } - if (!News\Utility::existField('topic_description', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField('topic_description TEXT NOT NULL', $xoopsDB->prefix('news_topics')); + if (!Utility::existField('topic_description', $xoopsDB->prefix('news_topics'))) { + Utility::addField('topic_description TEXT NOT NULL', $xoopsDB->prefix('news_topics')); } - if (!News\Utility::existField('topic_color', $xoopsDB->prefix('news_topics'))) { - News\Utility::addField("topic_color varchar(6) NOT NULL default '000000'", $xoopsDB->prefix('news_topics')); + if (!Utility::existField('topic_color', $xoopsDB->prefix('news_topics'))) { + Utility::addField("topic_color varchar(6) NOT NULL default '000000'", $xoopsDB->prefix('news_topics')); } // 3) If it does not exists, create the table stories_votedata - if (!News\Utility::existTable($xoopsDB->prefix('news_stories_votedata'))) { + if (!Utility::existTable($xoopsDB->prefix('news_stories_votedata'))) { $sql = 'CREATE TABLE ' . $xoopsDB->prefix('news_stories_votedata') . " ( ratingid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, storyid INT(8) UNSIGNED NOT NULL DEFAULT '0', @@ -143,23 +145,23 @@ function xoops_module_update_news() } // 4) Create the four new fields for the votes in the story table - if (!News\Utility::existField('rating', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField("rating DOUBLE( 6, 4 ) DEFAULT '0.0000' NOT NULL", $xoopsDB->prefix('news_stories')); + if (!Utility::existField('rating', $xoopsDB->prefix('news_stories'))) { + Utility::addField("rating DOUBLE( 6, 4 ) DEFAULT '0.0000' NOT NULL", $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('votes', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField("votes INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_stories')); + if (!Utility::existField('votes', $xoopsDB->prefix('news_stories'))) { + Utility::addField("votes INT( 11 ) UNSIGNED DEFAULT '0' NOT NULL", $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('keywords', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField('keywords VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); + if (!Utility::existField('keywords', $xoopsDB->prefix('news_stories'))) { + Utility::addField('keywords VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('description', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField('description VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); + if (!Utility::existField('description', $xoopsDB->prefix('news_stories'))) { + Utility::addField('description VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('pictureinfo', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField('pictureinfo VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); + if (!Utility::existField('pictureinfo', $xoopsDB->prefix('news_stories'))) { + Utility::addField('pictureinfo VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); } - if (!News\Utility::existField('subtitle', $xoopsDB->prefix('news_stories'))) { - News\Utility::addField('subtitle VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); + if (!Utility::existField('subtitle', $xoopsDB->prefix('news_stories'))) { + Utility::addField('subtitle VARCHAR(255) NOT NULL', $xoopsDB->prefix('news_stories')); } // 5) Add some indexes to the topics table diff --git a/list.tag.php b/list.tag.php index 0ee6464..d746d95 100644 --- a/list.tag.php +++ b/list.tag.php @@ -26,10 +26,11 @@ */ use XoopsModules\News; +use XoopsModules\News\Utility; require_once __DIR__ . '/header.php'; -if (!News\Utility::getModuleOption('tags') || !xoops_isActiveModule('tag')) { +if (!Utility::getModuleOption('tags') || !xoops_isActiveModule('tag')) { redirect_header('index.php', 2, _ERRORS); } require_once XOOPS_ROOT_PATH . '/modules/tag/list.tag.php'; diff --git a/micro_summary.php b/micro_summary.php index 2408082..ba6e707 100644 --- a/micro_summary.php +++ b/micro_summary.php @@ -31,14 +31,15 @@ use XoopsModules\News; use XoopsModules\News\NewsStory; +use XoopsModules\News\Utility; require_once \dirname(__DIR__, 2) . '/mainfile.php'; // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; -if (!News\Utility::getModuleOption('firefox_microsummaries')) { +if (!Utility::getModuleOption('firefox_microsummaries')) { exit(); } $story = new NewsStory(); -$restricted = News\Utility::getModuleOption('restrictindex'); +$restricted = Utility::getModuleOption('restrictindex'); $sarray = []; // Get the last news from all topics according to the module's restrictions $sarray = NewsStory::getAllPublished(1, 0, $restricted, 0); diff --git a/newsbythisauthor.php b/newsbythisauthor.php index bf0ffe2..9904bd5 100644 --- a/newsbythisauthor.php +++ b/newsbythisauthor.php @@ -67,19 +67,21 @@ use Xmf\Request; use XoopsModules\News; +use XoopsModules\News\Helper; use XoopsModules\News\NewsStory; +use XoopsModules\News\Utility; require_once \dirname(__DIR__, 2) . '/mainfile.php'; //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php'; //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php'; -/** @var News\Helper $helper */ -$helper = News\Helper::getInstance(); +/** @var Helper $helper */ +$helper = Helper::getInstance(); global $xoopsUser; -$helper = News\Helper::getInstance(); +$helper = Helper::getInstance(); $helper->loadLanguage('modinfo'); $uid = Request::getInt('uid', 0, 'GET'); @@ -87,7 +89,7 @@ redirect_header('index.php', 2, _ERRORS); } -if (!News\Utility::getModuleOption('newsbythisauthor')) { +if (!Utility::getModuleOption('newsbythisauthor')) { redirect_header('index.php', 2, _ERRORS); } @@ -96,8 +98,8 @@ $GLOBALS['xoopsOption']['template_main'] = 'news_by_this_author.tpl'; require_once XOOPS_ROOT_PATH . '/header.php'; -$dateformat = News\Utility::getModuleOption('dateformat'); -$infotips = News\Utility::getModuleOption('infotips'); +$dateformat = Utility::getModuleOption('dateformat'); +$infotips = Utility::getModuleOption('infotips'); $thisuser = new \XoopsUser($uid); switch ($helper->getConfig('displayname')) { @@ -123,7 +125,7 @@ $xoopsTpl->assign('lang_date', _NW_DATE); $xoopsTpl->assign('lang_hits', _NW_VIEWS); $xoopsTpl->assign('lang_title', _NW_TITLE); -$xoopsTpl->assign('news_rating', News\Utility::getModuleOption('ratenews')); +$xoopsTpl->assign('news_rating', Utility::getModuleOption('ratenews')); $xoopsTpl->assign('lang_rating', _NW_RATING); $xoopsTpl->assign('author_name_with_link', sprintf("
%s", XOOPS_URL . '/userinfo.php?uid=' . $uid, $authname)); @@ -163,7 +165,7 @@ } $htmltitle = ''; if ($infotips > 0) { - $htmltitle = ' title="' . News\Utility::makeInfotips($article['hometext']) . '"'; + $htmltitle = ' title="' . Utility::makeInfotips($article['hometext']) . '"'; } ++$count_articles; $count_reads += $article['counter']; @@ -190,12 +192,12 @@ ] ); $xoopsTpl->assign('xoops_pagetitle', _MI_NEWSBYTHISAUTHOR . ' - ' . $authname . ' - ' . htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5)); -$xoopsTpl->assign('advertisement', News\Utility::getModuleOption('advertisement')); +$xoopsTpl->assign('advertisement', Utility::getModuleOption('advertisement')); /** * Create the meta datas */ -News\Utility::createMetaDatas(); +Utility::createMetaDatas(); $meta_description = _MI_NEWSBYTHISAUTHOR . ' - ' . $authname . ' - ' . $xoopsModule->name('s'); if (isset($xoTheme) && is_object($xoTheme)) { diff --git a/print.php b/print.php index 71279d7..6b9b7da 100644 --- a/print.php +++ b/print.php @@ -35,6 +35,7 @@ use Xmf\Request; use XoopsModules\News; use XoopsModules\News\NewsStory; +use XoopsModules\News\Utility; require_once \dirname(__DIR__, 2) . '/mainfile.php'; // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; @@ -73,7 +74,7 @@ if ('' !== trim($story->keywords())) { $xoops_meta_keywords = $story->keywords(); } else { - $xoops_meta_keywords = News\Utility::createMetaKeywords($story->hometext() . ' ' . $story->bodytext()); + $xoops_meta_keywords = Utility::createMetaKeywords($story->hometext() . ' ' . $story->bodytext()); } if ('' !== trim($story->description())) { @@ -86,7 +87,7 @@ function PrintPage(): void { global $xoopsConfig, $xoopsModule, $story, $xoops_meta_keywords, $xoops_meta_description; $myts = \MyTextSanitizer::getInstance(); - $datetime = formatTimestamp($story->published(), News\Utility::getModuleOption('dateformat')); ?> + $datetime = formatTimestamp($story->published(), Utility::getModuleOption('dateformat')); ?> '; $supplemental = ''; - if (News\Utility::getModuleOption('footNoteLinks')) { + if (Utility::getModuleOption('footNoteLinks')) { $supplemental = "footnoteLinks('content','content'); "; ?> 'si", // Strip out javascript "''si", // Strip out img tags - "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags + "'<[\/\!]*?[^<>]*?>'i", // Strip out HTML tags "'([\r\n])[\s]+'", // Strip out white space "'&(quot|#34);'i", // Replace HTML entities "'&(amp|#38);'i", diff --git a/include/functions.php b/include/functions.php index 32ff294..d173035 100644 --- a/include/functions.php +++ b/include/functions.php @@ -148,7 +148,7 @@ function news_html2text($document) $search = [ "']*?>.*?'si", // Strip out javascript "''si", // Strip out img tags - "'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags + "'<[\/\!]*?[^<>]*?>'i", // Strip out HTML tags "'([\r\n])[\s]+'", // Strip out white space "'&(quot|#34);'i", // Replace HTML entities "'&(amp|#38);'i", From b391134796bafa75cb02cb2a8680f394c1adc417 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Sun, 6 Nov 2022 08:29:39 -0500 Subject: [PATCH 18/29] Missing parameter's type declaration --- admin/functions.php | 2 +- blocks/news_archives.php | 2 +- class/Common/Breadcrumb.php | 2 +- class/Common/DirectoryChecker.php | 14 ++++---- class/Common/FileChecker.php | 4 +-- class/Common/FilesManagement.php | 10 +++--- class/Common/Migrate.php | 4 +-- class/Common/SysUtility.php | 4 +-- class/Common/TestdataButtons.php | 5 +-- class/Files.php | 16 ++++----- class/Keyhighlighter.php | 2 +- class/NewsStory.php | 35 ++++++++++---------- class/ObjectTree.php | 54 +++++++++++++++---------------- class/PageNav.php | 10 +++--- class/Utility.php | 20 ++++++------ include/comment_functions.php | 2 +- include/functions.php | 20 ++++++------ testdata/index.php | 2 +- 18 files changed, 104 insertions(+), 104 deletions(-) diff --git a/admin/functions.php b/admin/functions.php index dcc3abc..a383729 100644 --- a/admin/functions.php +++ b/admin/functions.php @@ -30,7 +30,7 @@ * @copyright:: (c) Hervé Thouzard (https://www.herve-thouzard.com) * @author :: Hervé Thouzard (https://www.herve-thouzard.com) & Dojo Javscript Toolkit */ -function news_collapsableBar($tablename = '', $iconname = ''): void +function news_collapsableBar(string $tablename = '', string $iconname = ''): void { ?> -
  • @@ -193,7 +193,7 @@ <{if $fbcomments === true}>
    - <{/if}> diff --git a/templates/news_by_topic.tpl b/templates/news_by_topic.tpl index e0cc4e2..2bd3e93 100644 --- a/templates/news_by_topic.tpl +++ b/templates/news_by_topic.tpl @@ -6,7 +6,7 @@ <{foreach item=topic from=$columns[i]}>
    <{$topic.title}> + href="<{$xoops_url}>/modules/<{$xoops_dirname}>/index.php?storytopic=<{$topic.id}>"><{$topic.title}>
    <{counter start=0 print=false assign=storynum}> <{foreach item=story from=$topic.stories}> @@ -17,7 +17,7 @@
      <{/if}>
    • <{$story.title}> + href="<{$xoops_url}>/modules/<{$xoops_dirname}>/article.php?storyid=<{$story.id}>"><{$story.title}> (<{$story.posttime}>)
    • <{/if}> @@ -26,7 +26,7 @@
    <{if $storynum > 1}> <{$lang_morereleases}><{$topic.title}> + href="<{$xoops_url}>/modules/<{$xoops_dirname}>/index.php?storytopic=<{$topic.id}>"><{$lang_morereleases}><{$topic.title}> <{/if}>
    <{/foreach}> diff --git a/templates/news_index.tpl b/templates/news_index.tpl index 9567480..aad1533 100644 --- a/templates/news_index.tpl +++ b/templates/news_index.tpl @@ -5,7 +5,7 @@ <{if $displaynav === true}>
    -
    + <{$topic_select}>

    diff --git a/templates/news_item.tpl b/templates/news_item.tpl index 3f94a68..edfaf10 100644 --- a/templates/news_item.tpl +++ b/templates/news_item.tpl @@ -26,7 +26,7 @@
    <{$story.adminlink}> <{if $rates}><{$lang_ratingc}> <{$story.rating}> (<{$story.votes}>) - - <{$lang_ratethisnews}> - <{/if}> <{$story.morelink}> diff --git a/templates/news_ratenews.tpl b/templates/news_ratenews.tpl index 98f5318..faed7cb 100644 --- a/templates/news_ratenews.tpl +++ b/templates/news_ratenews.tpl @@ -10,7 +10,7 @@
    -
    + <{securityToken}><{*//mb*}>    + onclick="location='<{$xoops_url}>/modules/<{$xoops_dirname}>/article.php?storyid=<{$news.storyid}>'">
    diff --git a/templates/news_topics_directory.tpl b/templates/news_topics_directory.tpl index 2020756..1f11186 100644 --- a/templates/news_topics_directory.tpl +++ b/templates/news_topics_directory.tpl @@ -5,7 +5,7 @@
      <{foreach item=topic from=$topics}>
    • <{$topic.prefix}><{$topic.title}> + href="<{$xoops_url}>/modules/<{$xoops_dirname}>/index.php?storytopic=<{$topic.id}>"><{$topic.title}> (<{$topic.news_count}>)
    • <{/foreach}> diff --git a/templates/news_whos_who.tpl b/templates/news_whos_who.tpl index f47d524..65772a4 100644 --- a/templates/news_whos_who.tpl +++ b/templates/news_whos_who.tpl @@ -5,7 +5,7 @@
        <{foreach item=who from=$whoswho}>
      • <{$who.name}>
      • + href="<{$xoops_url}>/modules/<{$xoops_dirname}>/newsbythisauthor.php?uid=<{$who.uid}>"><{$who.name}> <{/foreach}>
      diff --git a/testdata/index.php b/testdata/index.php index 234bb0b..d6bbf3a 100644 --- a/testdata/index.php +++ b/testdata/index.php @@ -159,7 +159,7 @@ function exportSchema(): void /** * loadTableFromArrayWithReplace * - * @param string $table value with should be used insead of original value of $search + * @param string $table value which should be used instead of original value of $search * * @param array $data array of rows to insert * Each element of the outer array represents a single table row. diff --git a/xoops_version.php b/xoops_version.php index 8dffa42..b4299b6 100644 --- a/xoops_version.php +++ b/xoops_version.php @@ -15,10 +15,11 @@ * @author XOOPS Development Team */ -use XoopsModules\News; -use XoopsModules\News\Helper; -use XoopsModules\News\NewsTopic; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + Helper, + NewsTopic, + Utility +}; require_once __DIR__ . '/preloads/autoloader.php'; /** @var Helper $helper */ @@ -30,7 +31,7 @@ $modversion['version'] = '1.73.0'; $modversion['module_status'] = 'Beta 1'; -$modversion['release_date'] = '2022/11/05'; +$modversion['release_date'] = '2023/04/20'; $modversion['name'] = _MI_NEWS_NAME; $modversion['description'] = _MI_NEWS_DESC; $modversion['credits'] = 'XOOPS Project, Christian, Pilou, Marco,
      ALL the members of the Newbb Team, GIJOE, Zoullou, Mithrandir,
      Setec Astronomy, Marcan, 5vision, Anne, Trabis, dhsoft, Mamba, Mage, Timgno'; From 7c90b53f17e8a392abfffb48808b86ecefc88a4d Mon Sep 17 00:00:00 2001 From: mambax7 Date: Fri, 21 Apr 2023 02:49:52 -0400 Subject: [PATCH 21/29] fixed type --- class/ObjectTree.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/class/ObjectTree.php b/class/ObjectTree.php index eb8849d..ff755e8 100644 --- a/class/ObjectTree.php +++ b/class/ObjectTree.php @@ -114,11 +114,11 @@ public function getFirstChild(string $key): array /** * returns an array of all child objects of an object specified by its id * - * @param string $key ID of the parent - * @param array $ret (Empty when called from client) Array of children from previous recursions. + * @param string|int $key ID of the parent + * @param array $ret (Empty when called from client) Array of children from previous recursions. * @return array Array of child nodes. */ - public function getAllChild(string $key, array $ret = []): array + public function getAllChild($key, array $ret = []): array { if (isset($this->tree[$key]['child'])) { foreach ($this->tree[$key]['child'] as $childKey) { From 21c70d6520913cfe5b26bd35b6ed265c10a64593 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Fri, 21 Apr 2023 03:02:51 -0400 Subject: [PATCH 22/29] Missing strict types declaration --- class/Common/DirectoryChecker.php | 2 +- language/english/directorychecker.php | 2 +- language/english/filechecker.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/class/Common/DirectoryChecker.php b/class/Common/DirectoryChecker.php index ce8e727..83e29e2 100644 --- a/class/Common/DirectoryChecker.php +++ b/class/Common/DirectoryChecker.php @@ -1,4 +1,4 @@ - Date: Fri, 21 Apr 2023 03:03:07 -0400 Subject: [PATCH 23/29] Helper --- class/Common/VersionChecks.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/class/Common/VersionChecks.php b/class/Common/VersionChecks.php index 32c2a60..5f34bf3 100644 --- a/class/Common/VersionChecks.php +++ b/class/Common/VersionChecks.php @@ -17,6 +17,9 @@ * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) * @author mamba */ + +use Xmf\Module\Helper; + trait VersionChecks { /** @@ -92,7 +95,7 @@ public static function checkVerPhp(\XoopsModule $module = null): bool * @return string|array|null info about the latest module version, if newer */ public static function checkVerModule( - \Xmf\Module\Helper $helper, + Helper $helper, ?string $source = null, ?string $default = null ): ?array { From e11fd36461a9e99c001302b9ef8b279a0d840256 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Fri, 21 Apr 2023 07:57:01 -0400 Subject: [PATCH 24/29] cleanup, types, cosmetics --- .scrutinizer.yml | 2 +- admin/admin_header.php | 5 +- admin/amsimport.php | 9 +- admin/functions.php | 6 +- admin/index.php | 2 +- admin/upgrade.php | 5 +- archive.php | 7 +- backendt.php | 2 +- blocks/news_archives.php | 9 +- blocks/news_bigstory.php | 9 +- blocks/news_block_tag.php | 8 +- blocks/news_moderate.php | 11 +- blocks/news_randomnews.php | 11 +- blocks/news_top.php | 5 +- blocks/news_topics.php | 11 +- blocks/news_topicsnav.php | 2 +- class/Blacklist.php | 2 +- class/Common/Blocksadmin.php | 4 +- class/Common/Breadcrumb.php | 9 +- class/Common/Configurator.php | 26 ++--- class/Common/DirectoryChecker.php | 13 +-- class/Common/FilesManagement.php | 50 +++++---- class/Common/SysUtility.php | 16 +-- class/Common/TestdataButtons.php | 4 +- class/Files.php | 50 ++++----- class/Helper.php | 2 +- class/Keyhighlighter.php | 23 ++-- class/Mimetype.php | 8 +- class/NewsStory.php | 167 ++++++++++++++++-------------- class/NewsTopic.php | 2 +- class/ObjectTree.php | 12 +-- class/Utility.php | 86 ++++++--------- class/XoopsStory.php | 34 +++--- class/XoopsTopic.php | 26 ++--- class/XoopsTree.php | 20 ++-- class/plugins/plugin.tag.php | 2 +- comment_new.php | 11 +- comment_post.php | 2 +- config.php | 5 +- include/functions.php | 54 ++++------ include/install_function.php | 4 +- include/notification.inc.php | 2 +- include/oninstall.php | 13 +-- include/onuninstall.php | 4 +- include/onupdate.php | 4 +- include/search.inc.php | 7 +- include/storyform.original.php | 22 ++-- include/update_function.php | 2 +- index.php | 9 +- micro_summary.php | 7 +- newsbythisauthor.php | 9 +- preloads/core.php | 4 +- print.php | 7 +- ratenews.php | 7 +- testdata/index.php | 2 +- topics_directory.php | 8 +- visit.php | 6 +- whoswho.php | 7 +- 58 files changed, 422 insertions(+), 434 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 83b0351..245f626 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,7 +1,7 @@ # language: php build: environment: - php: 8.0.11 + php: 8.1 nodes: tests: true analysis: diff --git a/admin/admin_header.php b/admin/admin_header.php index 131a7c7..934346f 100644 --- a/admin/admin_header.php +++ b/admin/admin_header.php @@ -17,8 +17,9 @@ **/ use Xmf\Module\Admin; -use XoopsModules\News; -use XoopsModules\News\Helper; +use XoopsModules\News\{ + Helper +}; require_once \dirname(__DIR__) . '/preloads/autoloader.php'; diff --git a/admin/amsimport.php b/admin/amsimport.php index bf0463b..41ba08d 100644 --- a/admin/amsimport.php +++ b/admin/amsimport.php @@ -24,11 +24,12 @@ * @copyright 2005, 2006 - Hervé Thouzard */ -use XoopsModules\Ams; use XoopsModules\Ams\Helper as AmsHelper; -use XoopsModules\News\Files; -use XoopsModules\News\NewsStory; -use XoopsModules\News\NewsTopic; +use XoopsModules\News\{ + Files, + NewsStory, + NewsTopic +}; require \dirname(__DIR__, 3) . '/include/cp_header.php'; xoops_cp_header(); diff --git a/admin/functions.php b/admin/functions.php index a383729..c266502 100644 --- a/admin/functions.php +++ b/admin/functions.php @@ -25,14 +25,14 @@ * * NOTE : Please give credits if you copy this code ! * - * @param string $tablename + * @param string|null $tablename * @param string $iconname * @copyright:: (c) Hervé Thouzard (https://www.herve-thouzard.com) * @author :: Hervé Thouzard (https://www.herve-thouzard.com) & Dojo Javscript Toolkit */ -function news_collapsableBar(string $tablename = '', string $iconname = ''): void +function news_collapsableBar(?string $tablename = null, string $iconname = ''): void { - ?> + ?>$tablename ??= ''; '); } - } catch (\Throwable $e) { + } catch (\Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n", '
      '; } } @@ -55,15 +53,15 @@ public static function copyFile(string $file, string $folder): bool } /** - * @param $src - * @param $dst + * @param string $src + * @param string $dst */ - public static function recurseCopy($src, $dst): void + public static function recurseCopy(string $src, string $dst): void { $dir = \opendir($src); // @mkdir($dst); if (!@\mkdir($dst) && !\is_dir($dst)) { - throw new RuntimeException('The directory ' . $dst . ' could not be created.'); + throw new \RuntimeException('The directory ' . $dst . ' could not be created.'); } while (false !== ($file = \readdir($dir))) { if (('.' !== $file) && ('..' !== $file)) { @@ -90,18 +88,18 @@ public static function recurseCopy($src, $dst): void public static function deleteDirectory(string $src): bool { // Only continue if user is a 'global' Admin - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { return false; } $success = true; // remove old files - $dirInfo = new SplFileInfo($src); + $dirInfo = new \SplFileInfo($src); // validate is a directory if ($dirInfo->isDir()) { $fileList = \array_diff(\scandir($src, \SCANDIR_SORT_NONE), ['..', '.']); foreach ($fileList as $k => $v) { - $fileInfo = new SplFileInfo("{$src}/{$v}"); + $fileInfo = new \SplFileInfo("$src/$v"); if ($fileInfo->isDir()) { // recursively handle subdirectories if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { @@ -135,7 +133,7 @@ public static function deleteDirectory(string $src): bool public static function rrmdir(string $src): bool { // Only continue if user is a 'global' Admin - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { return false; } @@ -147,7 +145,7 @@ public static function rrmdir(string $src): bool $success = true; // Open the source directory to read in files - $iterator = new DirectoryIterator($src); + $iterator = new \DirectoryIterator($src); foreach ($iterator as $fObj) { if ($fObj->isFile()) { $filename = $fObj->getPathname(); @@ -176,7 +174,7 @@ public static function rrmdir(string $src): bool public static function rmove(string $src, string $dest): bool { // Only continue if user is a 'global' Admin - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { return false; } @@ -191,13 +189,13 @@ public static function rmove(string $src, string $dest): bool } // Open the source directory to read in files - $iterator = new DirectoryIterator($src); + $iterator = new \DirectoryIterator($src); foreach ($iterator as $fObj) { if ($fObj->isFile()) { - \rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); + \rename($fObj->getPathname(), "$dest/" . $fObj->getFilename()); } elseif (!$fObj->isDot() && $fObj->isDir()) { // Try recursively on directory - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); + self::rmove($fObj->getPathname(), "$dest/" . $fObj->getFilename()); // rmdir($fObj->getPath()); // now delete the directory } } @@ -212,15 +210,15 @@ public static function rmove(string $src, string $dest): bool * @param string $src - Source of files being moved * @param string $dest - Destination of files being moved * - * @return bool true on success + * @uses \Xmf\Module\Helper::getHelper() * @uses \Xmf\Module\Helper::isUserAdmin() * - * @uses \Xmf\Module\Helper::getHelper() + * @return bool true on success */ public static function rcopy(string $src, string $dest): bool { // Only continue if user is a 'global' Admin - if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { return false; } @@ -235,12 +233,12 @@ public static function rcopy(string $src, string $dest): bool } // Open the source directory to read in files - $iterator = new DirectoryIterator($src); + $iterator = new \DirectoryIterator($src); foreach ($iterator as $fObj) { if ($fObj->isFile()) { - \copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); + \copy($fObj->getPathname(), "$dest/" . $fObj->getFilename()); } elseif (!$fObj->isDot() && $fObj->isDir()) { - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); + self::rcopy($fObj->getPathname(), "$dest/" . $fObj->getFilename()); } } diff --git a/class/Common/SysUtility.php b/class/Common/SysUtility.php index 3c35825..fdf73b9 100644 --- a/class/Common/SysUtility.php +++ b/class/Common/SysUtility.php @@ -23,7 +23,9 @@ */ use XoopsFormEditor; -use XoopsModules\News\Helper; +use XoopsModules\News\{ + Helper +}; /** * Class SysUtility @@ -47,7 +49,7 @@ class SysUtility * * @return string Trimmed string. */ - public static function truncateHtml(string $text, $length = 100, $ending = '...', $exact = false, $considerHtml = true): string + public static function truncateHtml(string $text, int $length = 100, string $ending = '...', bool $exact = false, bool $considerHtml = true): string { if ($considerHtml) { // if the plain text is shorter than the maximum length, return the whole text @@ -139,11 +141,11 @@ public static function truncateHtml(string $text, $length = 100, $ending = '...' } /** - * @param \Xmf\Module\Helper $helper - * @param array|null $options + * @param \Xmf\Module\Helper|null $helper + * @param array|null $options * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor */ - public static function getEditor($helper = null, $options = null) + public static function getEditor(\Xmf\Module\Helper $helper = null, array $options = null) { /** @var Helper $helper */ if (null === $options) { @@ -196,13 +198,13 @@ public static function fieldExists(string $fieldname, string $table): bool } /** - * @param array|string $tableName + * @param string $tableName * @param string $id_field * @param int $id * * @return mixed */ - public static function cloneRecord($tableName, string $id_field, int $id) + public static function cloneRecord(string $tableName, string $id_field, int $id) { $new_id = false; $table = $GLOBALS['xoopsDB']->prefix($tableName); diff --git a/class/Common/TestdataButtons.php b/class/Common/TestdataButtons.php index 0aea19f..498789c 100644 --- a/class/Common/TestdataButtons.php +++ b/class/Common/TestdataButtons.php @@ -21,7 +21,9 @@ use Xmf\Yaml; use Xmf\Module\Admin; -use XoopsModules\News\Helper; +use XoopsModules\News\{ + Helper +}; /** @var Helper $helper */ diff --git a/class/Files.php b/class/Files.php index e8dbdb1..7eec3c2 100644 --- a/class/Files.php +++ b/class/Files.php @@ -25,20 +25,20 @@ */ class Files { - public $db; - public $table; - public $fileid; - public $filerealname; - public $storyid; - public $date; - public $mimetype; - public $downloadname; - public $counter; + public \XoopsDatabase $db; + public string $table; + public int $fileid; + public string $filerealname; + public int $storyid; + public int $date; + public string $mimetype; + public string $downloadname; + public int $counter; /** * @param array|int $fileid */ - public function __construct($fileid = -1) + public function __construct(int $fileid = -1) { /** @var \XoopsMySQLDatabase $db */ $this->db = \XoopsDatabaseFactory::getDatabaseConnection(); @@ -63,7 +63,7 @@ public function __construct($fileid = -1) * * @return string */ - public function createUploadName($folder, $filename, $trimname = false): string + public function createUploadName(string $folder, string $filename, bool $trimname = false): string { $workingfolder = $folder; if ('/' !== \xoops_substr($workingfolder, mb_strlen($workingfolder) - 1, 1)) { @@ -112,7 +112,7 @@ public function giveMimetype(string $filename = ''): string } /** - * @param $storyid + * @param string|int $storyid * * @return array */ @@ -131,7 +131,7 @@ public function getAllbyStory($storyid): array } /** - * @param $id + * @param string|int $id */ public function getFile($id): void { @@ -145,9 +145,9 @@ public function getFile($id): void } /** - * @param $array + * @param array $array */ - public function makeFile($array): void + public function makeFile(array $array): void { foreach ($array as $key => $value) { $this->$key = $value; @@ -217,15 +217,15 @@ public function updateCounter(): bool // **************************************************************************************************************** /** - * @param $filename + * @param string $filename */ - public function setFileRealName($filename): void + public function setFileRealName(string $filename): void { $this->filerealname = $filename; } /** - * @param $id + * @param string|int $id */ public function setStoryid($id): void { @@ -233,17 +233,17 @@ public function setStoryid($id): void } /** - * @param $value + * @param string $value */ - public function setMimetype($value): void + public function setMimetype(string $value): void { $this->mimetype = $value; } /** - * @param $value + * @param string $value */ - public function setDownloadname($value): void + public function setDownloadname(string $value): void { $this->downloadname = $value; } @@ -377,7 +377,7 @@ public function getDownloadname(string $format = 'S'): string // Deprecated /** - * @param $storyid + * @param string|int $storyid * * @return mixed */ @@ -394,11 +394,11 @@ public function getCountbyStory($storyid) } /** - * @param $stories + * @param array $stories * * @return array */ - public function getCountbyStories($stories): array + public function getCountbyStories(array $stories): array { $ret = []; if (\count($stories) > 0) { diff --git a/class/Helper.php b/class/Helper.php index 17ea2c5..7cc6ee2 100644 --- a/class/Helper.php +++ b/class/Helper.php @@ -77,7 +77,7 @@ public function getHandler($name) $db = \XoopsDatabaseFactory::getDatabaseConnection(); $helper = self::getInstance(); $ret = new $class($db, $helper); - $this->addLog("Getting handler '{$name}'"); + $this->addLog("Getting handler '$name'"); return $ret; } diff --git a/class/Keyhighlighter.php b/class/Keyhighlighter.php index 58acf24..a2cc1c5 100644 --- a/class/Keyhighlighter.php +++ b/class/Keyhighlighter.php @@ -22,15 +22,15 @@ class Keyhighlighter /** * @access private */ - public $preg_keywords = ''; + public string $preg_keywords = ''; /** * @access private */ - public $keywords = ''; + public string $keywords = ''; /** * @access private */ - public $singlewords = false; + public bool $singlewords = false; /** * @access private */ @@ -42,9 +42,9 @@ class Keyhighlighter * This is the main constructor of Keyhighlighter class.
      * It's the only public method of the class. * - * @param string $keywords the keywords you want to highlight - * @param bool $singlewords specify if it has to highlight also the single words. - * @param callback $replace_callback a custom callback for keyword highlight. + * @param string $keywords the keywords you want to highlight + * @param bool|null $singlewords specify if it has to highlight also the single words. + * @param callback|null $replace_callback a custom callback for keyword highlight. * * */ // public function __construct () - public function __construct(string $keywords, bool $singlewords = false, $replace_callback = null) + public function __construct(string $keywords, ?bool $singlewords = null, callable $replace_callback = null) { + $singlewords ??= false; $this->keywords = $keywords; $this->singlewords = $singlewords; $this->replace_callback = $replace_callback; @@ -68,10 +69,10 @@ public function __construct(string $keywords, bool $singlewords = false, $replac /** * @access private - * @param $replace_matches + * @param array $replace_matches * @return mixed */ - public function replace($replace_matches) + public function replace(array $replace_matches) { $patterns = []; if ($this->singlewords) { @@ -98,10 +99,10 @@ public function replace($replace_matches) /** * @access private - * @param $buffer + * @param string $buffer * @return string */ - public function highlight($buffer): string + public function highlight(string $buffer): string { $buffer = '>' . $buffer . '<'; $this->preg_keywords = \preg_replace('/[^\w ]/i', '', $this->keywords); diff --git a/class/Mimetype.php b/class/Mimetype.php index 18029ee..fe6513e 100644 --- a/class/Mimetype.php +++ b/class/Mimetype.php @@ -76,11 +76,11 @@ class Mimetype { /** - * @param $filename + * @param string $filename * * @return string */ - public function getType($filename): string + public function getType(string $filename): string { // get base name of the filename provided by user $filename = \basename($filename); @@ -96,11 +96,11 @@ public function getType($filename): string } /** - * @param $ext + * @param string $ext * * @return string */ - public function privFindType($ext): string + public function privFindTypestring $ext): string { // create mimetypes array $mimetypes = $this->privBuildMimeArray(); diff --git a/class/NewsStory.php b/class/NewsStory.php index b0ce080..d3105ab 100644 --- a/class/NewsStory.php +++ b/class/NewsStory.php @@ -65,12 +65,12 @@ public function __construct($storyid = -1) /** * Returns the number of stories published before a date - * @param $timestamp - * @param $expired - * @param string $topicslist + * @param int $timestamp + * @param int $expired + * @param string $topicslist * @return mixed */ - public function getCountStoriesPublishedBefore($timestamp, $expired, $topicslist = '') + public function getCountStoriesPublishedBefore(int $timestamp, int $expired, string $topicslist = '') { $count = 0; $sql = 'SELECT count(*) AS cpt FROM ' . $this->db->prefix('news_stories') . ' WHERE published <=' . $timestamp; @@ -109,7 +109,7 @@ public function getStory($storyid): void * @param string $topicslist * @return bool */ - public function deleteBeforeDate($timestamp, $expired, $topicslist = ''): bool + public function deleteBeforeDate($timestamp, $expired, string $topicslist = ''): bool { global $xoopsModule; $mid = $xoopsModule->getVar('mid'); @@ -157,7 +157,7 @@ public function deleteBeforeDate($timestamp, $expired, $topicslist = ''): bool * * @return array */ - public function _searchPreviousOrNextArticle($storyid, $next = true, $checkRight = false): ?array + public function _searchPreviousOrNextArticle($storyid, bool $next = true, bool $checkRight = false): ?array { $ret = []; $storyid = (int)$storyid; @@ -195,7 +195,7 @@ public function _searchPreviousOrNextArticle($storyid, $next = true, $checkRight * * @return null|array */ - public function getNextArticle($storyid, $checkRight = false): ?array + public function getNextArticle(int $storyid, bool $checkRight = false): ?array { return $this->_searchPreviousOrNextArticle($storyid, true, $checkRight); } @@ -206,7 +206,7 @@ public function getNextArticle($storyid, $checkRight = false): ?array * * @return array */ - public function getPreviousArticle($storyid, $checkRight = false): ?array + public function getPreviousArticle($storyid, bool $checkRight = false): ?array { return $this->_searchPreviousOrNextArticle($storyid, false, $checkRight); } @@ -224,14 +224,14 @@ public function getPreviousArticle($storyid, $checkRight = false): ?array * @return array|null */ public static function getAllPublished( - $limit = 0, - $start = 0, - $checkRight = false, - $topic = 0, - $ihome = 0, - $asobject = true, - $order = 'published', - $topic_frontpage = false + int $limit = 0, + int $start = 0, + bool $checkRight = false, + $topic = 0, + int $ihome = 0, + bool $asobject = true, + string $order = 'published', + bool $topic_frontpage = false ): ?array { /** @var \XoopsMySQLDatabase $db */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); @@ -308,9 +308,9 @@ public static function getAllPublished( public function getArchive( $publish_start, $publish_end, - $checkRight = false, - $asobject = true, - $order = 'published' + bool $checkRight = false, + bool $asobject = true, + string $order = 'published' ): ?array { $myts = \MyTextSanitizer::getInstance(); $ret = []; @@ -354,13 +354,13 @@ public function getArchive( * @return array */ public function getBigStory( - $limit = 0, - $start = 0, - $checkRight = false, - $topic = 0, - $ihome = 0, - $asobject = true, - $order = 'counter' + int $limit = 0, + int $start = 0, + bool $checkRight = false, + $topic = 0, + int $ihome = 0, + bool $asobject = true, + string $order = 'counter' ): ?array { $myts = \MyTextSanitizer::getInstance(); $ret = []; @@ -413,7 +413,7 @@ public function getBigStory( * * @return array */ - public function getAllPublishedByAuthor($uid, $checkRight = false, $asobject = true): array + public function getAllPublishedByAuthor(int $uid, bool $checkRight = false, bool $asobject = true): array { $myts = \MyTextSanitizer::getInstance(); $ret = []; @@ -493,7 +493,7 @@ public function getAllPublishedByAuthor($uid, $checkRight = false, $asobject = t * @param bool $asobject * @return array */ - public static function getAllExpired($limit = 0, $start = 0, $topic = 0, $ihome = 0, $asobject = true): array + public static function getAllExpired(int $limit = 0, int $start = 0, int $topic = 0, int $ihome = 0, bool $asobject = true): array { /** @var \XoopsMySQLDatabase $db */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); @@ -528,7 +528,7 @@ public static function getAllExpired($limit = 0, $start = 0, $topic = 0, $ihome * @param int $start * @return array */ - public static function getAllAutoStory($limit = 0, $asobject = true, $start = 0): array + public static function getAllAutoStory(int $limit = 0, bool $asobject = true, int $start = 0): array { /** @var \XoopsMySQLDatabase $db */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); @@ -553,16 +553,18 @@ public static function getAllAutoStory($limit = 0, $asobject = true, $start = 0) /** * Get all submitted stories awaiting approval * - * @param int $limit Denotes where to start the query + * @param int|null $limit Denotes where to start the query * @param bool $asobject true will return the stories as an array of objects, false will return storyid => title - * @param bool $checkRight whether to check the user's rights to topics + * @param bool|null $checkRight whether to check the user's rights to topics * * @param int $start * * @return array */ - public static function getAllSubmitted(int $limit = 0, $asobject = true, bool $checkRight = false, $start = 0): array + public static function getAllSubmitted(?int $limit = null, bool $asobject = true, ?bool $checkRight = null, int $start = 0): array { + $checkRight ??= false; + $limit ??= 0; /** @var \XoopsMySQLDatabase $db */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); $myts = \MyTextSanitizer::getInstance(); @@ -600,13 +602,14 @@ public static function getAllSubmitted(int $limit = 0, $asobject = true, bool $c /** * Used in the module's admin to know the number of expired, automated or pubilshed news * - * @param int $storytype 1=Expired, 2=Automated, 3=New submissions, 4=Last published stories + * @param int|null $storytype 1=Expired, 2=Automated, 3=New submissions, 4=Last published stories * @param bool $checkRight verify permissions or not ? * * @return int */ - public static function getAllStoriesCount(int $storytype = 1, bool $checkRight = false): int + public static function getAllStoriesCount(?int $storytype = null, bool $checkRight = false): int { + $storytype ??= 1; /** @var \XoopsMySQLDatabase $db */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); $sql = 'SELECT count(*) AS cpt FROM ' . $db->prefix('news_stories') . ' WHERE '; @@ -665,13 +668,14 @@ public static function getByTopic($topicid, int $limit = 0): array /** * Count the number of news published for a specific topic - * @param int $topicid + * @param int|null $topicid * @param bool|int $checkRight * @return int|string */ - public static function countPublishedByTopic(int $topicid = 0, $checkRight = false) + public static function countPublishedByTopic(?int $topicid = null, $checkRight = false) { - $count = 0; + $topicid ??= 0; + $count = 0; /** @var \XoopsMySQLDatabase $db */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); $sql = 'SELECT COUNT(*) FROM ' . $db->prefix('news_stories') . ' WHERE published > 0 AND published <= ' . \time() . ' AND (expired = 0 OR expired > ' . \time() . ')'; @@ -740,7 +744,7 @@ public function adminlink(): string * @param string $format * @return string */ - public function topic_imgurl($format = 'S'): string + public function topic_imgurl(string $format = 'S'): string { if ('' === \trim($this->topic_imgurl)) { $this->topic_imgurl = 'blank.png'; @@ -769,7 +773,7 @@ public function topic_imgurl($format = 'S'): string * * @return string */ - public function topic_title($format = 'S'): string + public function topic_title(string $format = 'S'): string { $myts = \MyTextSanitizer::getInstance(); switch ($format) { @@ -954,7 +958,7 @@ public function prepare2show($filescount): array * @param int $uid * @return null|string */ - public function uname($uid = 0) + public function uname(int $uid = 0): ?string { global $xoopsConfig; static $tblusers = []; @@ -1019,13 +1023,13 @@ public function uname($uid = 0) * @internal param string $topiclist If not empty, a list of topics to limit to */ public function exportNews( - $fromdate, - $todate, - $topicslist, - $usetopicsdef, - &$tbltopics, - $asobject = true, - $order = 'published' + int $fromdate, + int $todate, + string $topicslist, + $usetopicsdef, + &$tbltopics, + bool $asobject = true, + string $order = 'published' ): array { $ret = []; $myts = \MyTextSanitizer::getInstance(); @@ -1068,7 +1072,7 @@ public function exportNews( * @param bool $approved * @return bool|int */ - public function store($approved = false) + public function store(bool $approved = false) { $myts = \MyTextSanitizer::getInstance(); $counter = $this->counter ?? 0; @@ -1256,7 +1260,7 @@ public function setKeywords($data): void * * @return string */ - public function description($format = 'S'): string + public function description(string $format = 'S'): string { $myts = \MyTextSanitizer::getInstance(); switch (mb_strtoupper($format)) { @@ -1280,7 +1284,7 @@ public function description($format = 'S'): string * * @return string */ - public function keywords($format = 'S'): string + public function keywords(string $format = 'S'): string { $myts = \MyTextSanitizer::getInstance(); switch (mb_strtoupper($format)) { @@ -1302,27 +1306,31 @@ public function keywords($format = 'S'): string /** * Returns a random number of news * @param int $limit - * @param int $start - * @param bool $checkRight + * @param int|null $start + * @param bool|null $checkRight * @param array|int $topic - * @param int $ihome - * @param string $order + * @param int|null $ihome + * @param string|null $order * @param bool $topic_frontpage * @return array */ public function getRandomNews( - $limit = 0, - int $start = 0, - bool $checkRight = false, - $topic = 0, - int $ihome = 0, - string $order = 'published', - bool $topic_frontpage = false + int $limit = 0, + ?int $start = null, + ?bool $checkRight = null, + $topic = 0, + ?int $ihome = null, + ?string $order = null, + bool $topic_frontpage = false ): ?array { - $ret = []; - $rand_keys = []; - $ret3 = []; - $sql = 'SELECT storyid FROM ' . $this->db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ')'; + $order ??= 'published'; + $checkRight ??= false; + $ihome ??= 0; + $start ??= 0; + $ret = []; + $rand_keys = []; + $ret3 = []; + $sql = 'SELECT storyid FROM ' . $this->db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ')'; if (0 != $topic) { if (!\is_array($topic)) { if ($checkRight) { @@ -1555,7 +1563,7 @@ public function getOlderRecentNews(&$older, &$recent): void * * @return array|null */ - public function getWhosWho($checkRight = false, $limit = 0, int $start = 0): ?array + public function getWhosWho(bool $checkRight = false, int $limit = 0, int $start = 0): ?array { $ret = []; $sql = 'SELECT DISTINCT(uid) AS uid FROM ' . $this->db->prefix('news_stories') . ' WHERE (published > 0 AND published <= ' . \time() . ') AND (expired = 0 OR expired > ' . \time() . ')'; @@ -1623,7 +1631,7 @@ public function auto_summary($text, &$titles): string * * @return array|string|string[] */ - public function hometext($format = 'Show') + public function hometext(string $format = 'Show') { $hometext = ''; $myts = \MyTextSanitizer::getInstance(); @@ -1660,7 +1668,7 @@ public function hometext($format = 'Show') * * @return array|string|string[] */ - public function bodytext($format = 'Show') + public function bodytext(string $format = 'Show') { $myts = \MyTextSanitizer::getInstance(); $html = 1; @@ -1696,23 +1704,26 @@ public function bodytext($format = 'Show') /** * Returns stories by Ids * @param array|string $ids - * @param bool $checkRight - * @param bool $asobject - * @param string $order + * @param bool|null $checkRight + * @param bool|null $asobject + * @param string|null $order * @param bool $onlyOnline * @return array|null */ public function getStoriesByIds( $ids, - bool $checkRight = true, - bool $asobject = true, - string $order = 'published', + ?bool $checkRight = null, + ?bool $asobject = null, + ?string $order = null, bool $onlyOnline = true ): ?array { - $limit = $start = 0; - $myts = \MyTextSanitizer::getInstance(); - $ret = []; - $sql = 'SELECT s.*, t.* FROM ' . $this->db->prefix('news_stories') . ' s, ' . $this->db->prefix('news_topics') . ' t WHERE '; + $order ??= 'published'; + $asobject ??= true; + $checkRight ??= true; + $limit = $start = 0; + $myts = \MyTextSanitizer::getInstance(); + $ret = []; + $sql = 'SELECT s.*, t.* FROM ' . $this->db->prefix('news_stories') . ' s, ' . $this->db->prefix('news_topics') . ' t WHERE '; if ($ids && \is_array($ids)) { \array_walk($ids, '\intval'); } diff --git a/class/NewsTopic.php b/class/NewsTopic.php index 82d72f5..7e9f270 100644 --- a/class/NewsTopic.php +++ b/class/NewsTopic.php @@ -566,7 +566,7 @@ public function topic_description($format = 'S'): string * * @return string */ - public function topic_imgurl($format = 'S') + public function topic_imgurl(string $format = 'S') { if ('' === \trim($this->topic_imgurl)) { $this->topic_imgurl = 'blank.png'; diff --git a/class/ObjectTree.php b/class/ObjectTree.php index ff755e8..4806c53 100644 --- a/class/ObjectTree.php +++ b/class/ObjectTree.php @@ -28,11 +28,11 @@ class ObjectTree /** * @access private */ - protected $parentId; - protected $myId; - protected $rootId; - protected $tree = []; - protected $objects; + private string $parentId; + private string $myId; + private string $rootId; + private array $tree = []; + private array $objects; /** * Constructor @@ -88,7 +88,7 @@ public function &getTree(): array * @param string $key ID of the object to retrieve * @return object Object within the tree */ - public function &getByKey(string $key) + public function &getByKey(string $key): object { return $this->tree[$key]['obj']; } diff --git a/class/Utility.php b/class/Utility.php index 5b0e983..3460966 100644 --- a/class/Utility.php +++ b/class/Utility.php @@ -26,7 +26,7 @@ class Utility extends Common\SysUtility * @param string $repmodule * @return bool|mixed */ - public static function getModuleOption($option, $repmodule = 'news') + public static function getModuleOption(string $option, string $repmodule = 'news') { global $xoopsModuleConfig, $xoopsModule; static $tbloptions = []; @@ -62,11 +62,11 @@ public static function getModuleOption($option, $repmodule = 'news') /** * Updates rating data in item table for a given item * - * @param $storyid + * @param int $storyid * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ - public static function updateRating($storyid): void + public static function updateRating(int $storyid): void { global $xoopsDB; $sql = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; @@ -203,7 +203,7 @@ public static function isX23(): bool * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ - public static function getWysiwygForm($caption, $name, $value = '', $width = '100%', $height = '400px', $supplemental = '') + public static function getWysiwygForm(string $caption, string $name, string $value = '', string $width = '100%', string $height = '400px', string $supplemental = '') { $editor_option = \mb_strtolower(static::getModuleOption('form_options')); $editor = false; @@ -224,18 +224,6 @@ public static function getWysiwygForm($caption, $name, $value = '', $width = '10 // Only for Xoops 2.0.x switch ($editor_option) { - case 'fckeditor': - if (\is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php')) { - require_once XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'; - $editor = new XoopsFormFckeditor($caption, $name, $value); - } - break; - case 'htmlarea': - if (\is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { - require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; - $editor = new XoopsFormHtmlarea($caption, $name, $value); - } - break; case 'dhtmltextarea': case 'dhtml': $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); @@ -258,23 +246,17 @@ public static function getWysiwygForm($caption, $name, $value = '', $width = '10 ); } break; - case 'koivi': - if (\is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { - require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; - $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); - } - break; } return $editor; } /** - * @param \Xmf\Module\Helper $helper - * @param array|null $options + * @param \Xmf\Module\Helper|null $helper + * @param array|null $options * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor */ - public static function getEditor($helper = null, $options = null) + public static function getEditor(\Xmf\Module\Helper $helper = null, array $options = null) { /** @var Helper $helper */ if (null === $options) { @@ -311,12 +293,12 @@ public static function getEditor($helper = null, $options = null) /** * Internal function * - * @param $text + * @param string $text * @return array|string|string[] * @copyright (c) HervĂ© Thouzard * @author HervĂ© Thouzard (https://www.herve-thouzard.com) */ - public static function getDublinQuotes($text) + public static function getDublinQuotes(string $text) { return \str_replace('"', ' ', $text); } @@ -329,7 +311,7 @@ public static function getDublinQuotes($text) * - The meta keywords * - The meta description * - * @param null $story + * @param object|null $story * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ @@ -426,12 +408,12 @@ public static function createMetaDatas($story = null): void /** * Create the meta keywords based on the content * - * @param $content + * @param string $content * @return string * @copyright (c) HervĂ© Thouzard * @author HervĂ© Thouzard (https://www.herve-thouzard.com) */ - public static function createMetaKeywords($content): string + public static function createMetaKeywords(string $content): string { global $cfg; require_once XOOPS_ROOT_PATH . '/modules/news/config.php'; @@ -600,12 +582,12 @@ public static function updateCache(): void /** * Verify that a mysql table exists * - * @param $tablename + * @param string $tablename * @return bool * @copyright (c) HervĂ© Thouzard * @author HervĂ© Thouzard (https://www.herve-thouzard.com) */ - public static function existTable($tablename): bool + public static function existTable(string $tablename): bool { global $xoopsDB; $sql = "SHOW TABLES LIKE '$tablename'"; @@ -621,13 +603,13 @@ public static function existTable($tablename): bool /** * Verify that a field exists inside a mysql table * - * @param $fieldname - * @param $table + * @param string $fieldname + * @param string $table * @return bool * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ - public static function existField($fieldname, $table): bool + public static function existField(string $fieldname, string $table): bool { global $xoopsDB; $sql = "SHOW COLUMNS FROM $table LIKE '$fieldname'"; @@ -642,13 +624,13 @@ public static function existField($fieldname, $table): bool /** * Add a field to a mysql table * - * @param $field - * @param $table + * @param string $field + * @param string $table * @return bool|\mysqli_result * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ - public static function addField($field, $table) + public static function addField(string $field, string $table) { global $xoopsDB; $result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field;"); @@ -712,12 +694,12 @@ public static function isBot() /** * Create an infotip * - * @param $text + * @param string $text * @return string|null * @copyright (c) HervĂ© Thouzard * @author HervĂ© Thouzard (https://www.herve-thouzard.com) */ - public static function makeInfotips($text): ?string + public static function makeInfotips(string $text): ?string { $infotips = static::getModuleOption('infotips'); if ($infotips > 0) { @@ -735,7 +717,7 @@ public static function makeInfotips($text): ?string * @author Monte Ohrt , modified by Amos Robinson * */ - public static function closeTags($string): string + public static function closeTags(string $string): string { // match opened tags if (\preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { @@ -777,16 +759,16 @@ public static function closeTags($string): string * Makes sure no tags are left half-open or half-closed * (e.g. "Banana in a , modified by Amos Robinson * */ - public static function truncateTagSafe($string, $length = 80, $etc = '...', $break_words = false): string + public static function truncateTagSafe(string $string, int $length = 80, string $etc = '...', bool $break_words = false): string { if (0 == $length) { return ''; @@ -818,12 +800,12 @@ public static function truncateTagSafe($string, $length = 80, $etc = '...', $bre * @return bool */ public static function resizePicture( - $src_path, - $dst_path, - $param_width, - $param_height, - $keep_original = false, - $fit = 'inside' + string $src_path, + string $dst_path, + int $param_width, + int $param_height, + bool $keep_original = false, + string $fit = 'inside' ): bool { // require_once XOOPS_PATH . '/vendor/wideimage/WideImage.php'; $resize = true; diff --git a/class/XoopsStory.php b/class/XoopsStory.php index 4fde536..fd322f8 100644 --- a/class/XoopsStory.php +++ b/class/XoopsStory.php @@ -37,18 +37,18 @@ class XoopsStory public $topicid; public $uid; public $title; - public $hometext; - public $bodytext = ''; - public $counter; + public $hometext; + public string $bodytext = ''; + public $counter; public $created; public $published; public $expired; - public $hostname; - public $nohtml = 0; - public $nosmiley = 0; - public $ihome = 0; - public $notifypub = 0; - public $type; + public $hostname; + public int $nohtml = 0; + public int $nosmiley = 0; + public int $ihome = 0; + public int $notifypub = 0; + public $type; public $approved; public $topicdisplay; public $topicalign; @@ -158,7 +158,7 @@ public function setHostname($value): void /** * @param int $value */ - public function setNohtml($value = 0): void + public function setNohtml(int $value = 0): void { $this->nohtml = $value; } @@ -166,7 +166,7 @@ public function setNohtml($value = 0): void /** * @param int $value */ - public function setNosmiley($value = 0): void + public function setNosmiley(int $value = 0): void { $this->nosmiley = $value; } @@ -232,7 +232,7 @@ public function setComments($value): void * * @return bool */ - public function store($approved = false) + public function store(bool $approved = false): bool { //$newpost = 0; $myts = \MyTextSanitizer::getInstance(); @@ -417,7 +417,7 @@ public function uid() /** * @return string */ - public function uname() + public function uname(): string { return XoopsUser::getUnameFromId($this->uid); } @@ -427,7 +427,7 @@ public function uname() * * @return string */ - public function title($format = 'Show'): string + public function title(string $format = 'Show'): string { $myts = \MyTextSanitizer::getInstance(); $smiley = 1; @@ -453,7 +453,7 @@ public function title($format = 'Show'): string * * @return string */ - public function hometext($format = 'Show') + public function hometext(string $format = 'Show'): string { $myts = \MyTextSanitizer::getInstance(); $html = 1; @@ -488,7 +488,7 @@ public function hometext($format = 'Show') * * @return string */ - public function bodytext($format = 'Show') + public function bodytext(string $format = 'Show'): string { $myts = \MyTextSanitizer::getInstance(); $html = 1; @@ -595,7 +595,7 @@ public function topicdisplay() * * @return string */ - public function topicalign($astext = true): string + public function topicalign(bool $astext = true): string { if ($astext) { if ('R' === $this->topicalign) { diff --git a/class/XoopsTopic.php b/class/XoopsTopic.php index b5d8e9b..5c75ee3 100644 --- a/class/XoopsTopic.php +++ b/class/XoopsTopic.php @@ -33,26 +33,26 @@ */ class XoopsTopic { - public $db; - public $menu; + public \XoopsDatabase $db; + public $menu; public $mid; // module id used for setting permission public $prefix; // only used in topic tree - public $table; - public $topic_color; + public string $table; + public $topic_color; public $topic_description; public $topic_frontpage; public $topic_id; public $topic_imgurl; public $topic_pid; public $topic_rssurl; - public $topic_title; - public $use_permission = false; + public $topic_title; + public bool $use_permission = false; /** * @param string $table * @param array|int $topicid */ - public function __construct($table, $topicid = 0) + public function __construct(string $table, $topicid = 0) { /** @var \XoopsMySQLDatabase $db */ $this->db = \XoopsDatabaseFactory::getDatabaseConnection(); @@ -123,7 +123,7 @@ public function usePermission($mid): void /** * @return bool */ - public function store() + public function store(): bool { $myts = \MyTextSanitizer::getInstance(); $title = ''; @@ -242,7 +242,7 @@ public function topic_pid() * * @return string */ - public function topic_title($format = 'S'): string + public function topic_title(string $format = 'S'): string { $myts = \MyTextSanitizer::getInstance(); switch ($format) { @@ -264,7 +264,7 @@ public function topic_title($format = 'S'): string * * @return string */ - public function topic_imgurl($format = 'S') + public function topic_imgurl(string $format = 'S'): string { $myts = \MyTextSanitizer::getInstance(); switch ($format) { @@ -342,11 +342,11 @@ public function getChildTopicsTreeArray(): array /** * @param int $none - * @param $seltopic + * @param int $seltopic * @param string $selname * @param string $onchange */ - public function makeTopicSelBox($none = 0, $seltopic = -1, $selname = '', $onchange = ''): void + public function makeTopicSelBox(int $none = 0, int $seltopic = -1, string $selname = '', string $onchange = ''): void { $xt = new XoopsTree($this->table, 'topic_id', 'topic_pid'); if (-1 != $seltopic) { @@ -387,7 +387,7 @@ public function getAllChildTopicsId(): array /** * @return array */ - public function getTopicsList() + public function getTopicsList(): array { $ret = []; $result = $this->db->query('SELECT topic_id, topic_pid, topic_title FROM ' . $this->table); diff --git a/class/XoopsTree.php b/class/XoopsTree.php index e7e35a8..fc65df9 100644 --- a/class/XoopsTree.php +++ b/class/XoopsTree.php @@ -32,7 +32,7 @@ class XoopsTree public $pid; // name of parent id used in table $table public $order; //specifies the order of query results public $title; // name of a field in table $table which will be used when selection box and paths are generated - public $db; + public \XoopsDatabase $db; //constructor of class XoopsTree //sets the names of table, unique id, and parend id @@ -60,7 +60,7 @@ public function __construct($table_name, $id_name, $pid_name) * * @return array */ - public function getFirstChild($sel_id, $order = ''): array + public function getFirstChild($sel_id, string $order = ''): array { $sel_id = (int)$sel_id; $arr = []; @@ -114,7 +114,7 @@ public function getFirstChildId($sel_id): array * * @return array */ - public function getAllChildId($sel_id, $order = '', $idarray = []): array + public function getAllChildId($sel_id, string $order = '', array $idarray = []): array { $sel_id = (int)$sel_id; $sql = 'SELECT ' . $this->id . ' FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $sel_id; @@ -146,7 +146,7 @@ public function getAllChildId($sel_id, $order = '', $idarray = []): array * * @return array */ - public function getAllParentId($sel_id, $order = '', $idarray = []): array + public function getAllParentId($sel_id, string $order = '', array $idarray = []): array { $sel_id = (int)$sel_id; $sql = 'SELECT ' . $this->pid . ' FROM ' . $this->table . ' WHERE ' . $this->id . '=' . $sel_id; @@ -177,7 +177,7 @@ public function getAllParentId($sel_id, $order = '', $idarray = []): array * * @return string */ - public function getPathFromId($sel_id, $title, $path = ''): string + public function getPathFromId($sel_id, string $title, string $path = ''): string { $sel_id = (int)$sel_id; $sql= 'SELECT ' . $this->pid . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; @@ -212,7 +212,7 @@ public function getPathFromId($sel_id, $title, $path = ''): string * @param string $sel_name * @param string $onchange */ - public function makeMySelBox($title, $order = '', $preset_id = 0, $none = 0, $sel_name = '', $onchange = ''): void + public function makeMySelBox($title, string $order = '', int $preset_id = 0, int $none = 0, string $sel_name = '', string $onchange = ''): void { if ('' == $sel_name) { $sel_name = $this->id; @@ -265,7 +265,7 @@ public function makeMySelBox($title, $order = '', $preset_id = 0, $none = 0, $se * * @return string */ - public function getNicePathFromId($sel_id, $title, $funcURL, $path = ''): string + public function getNicePathFromId($sel_id, string $title, string $funcURL, string $path = ''): string { $path = !empty($path) ? ' : ' . $path : $path; $sel_id = (int)$sel_id; @@ -298,7 +298,7 @@ public function getNicePathFromId($sel_id, $title, $funcURL, $path = ''): string * * @return string */ - public function getIdPathFromId($sel_id, $path = ''): string + public function getIdPathFromId($sel_id, string $path = ''): string { $sel_id = (int)$sel_id; $sql = 'SELECT ' . $this->pid . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; @@ -340,7 +340,7 @@ public function getAllChild($sel_id = 0, $order = '', $parray = []) \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); } $count = $this->db->getRowsNum($result); - if ($count == 0) { + if (0 == $count) { return $parray; } while (false !== ($row = $this->db->fetchArray($result))) { @@ -373,7 +373,7 @@ public function getChildTreeArray($sel_id = 0, $order = '', $parray = [], $r_pre \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); } $count = $this->db->getRowsNum($result); - if ($count == 0) { + if (0 == $count) { return $parray; } while (false !== ($row = $this->db->fetchArray($result))) { diff --git a/class/plugins/plugin.tag.php b/class/plugins/plugin.tag.php index ac8411d..8e44d41 100644 --- a/class/plugins/plugin.tag.php +++ b/class/plugins/plugin.tag.php @@ -31,7 +31,7 @@ * @param $items * @return bool|null */ -function news_tag_iteminfo(&$items) +function news_tag_iteminfo(&$items): ?bool { if (empty($items) || !\is_array($items)) { return false; diff --git a/comment_new.php b/comment_new.php index b488aa5..bf1a2a8 100644 --- a/comment_new.php +++ b/comment_new.php @@ -16,10 +16,11 @@ */ use Xmf\Request; -use XoopsModules\News; -use XoopsModules\News\Helper; -use XoopsModules\News\NewsStory; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + Helper, + NewsStory, + Utility +}; require_once \dirname(__DIR__, 2) . '/mainfile.php'; @@ -29,7 +30,7 @@ // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; // We verify that the user can post comments ********************************** -if (null === $helper->getModule()) { +if (!is_object($helper->getModule())) { exit(); } diff --git a/comment_post.php b/comment_post.php index 7539b42..56b7d68 100644 --- a/comment_post.php +++ b/comment_post.php @@ -24,7 +24,7 @@ $helper = Helper::getInstance(); // We verify that the user can post comments ********************************** -if (null === $helper->getModule()) { +if (!is_object($helper->getModule())) { exit(); } diff --git a/config.php b/config.php index 2253f82..e9c7977 100644 --- a/config.php +++ b/config.php @@ -23,8 +23,9 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------ // -use XoopsModules\News; -use XoopsModules\News\Helper; +use XoopsModules\News\{ + Helper +}; /** @var \XoopsModules\News\Helper $helper */ $helper = Helper::getInstance(); diff --git a/include/functions.php b/include/functions.php index f0d146b..7a7a057 100644 --- a/include/functions.php +++ b/include/functions.php @@ -42,7 +42,7 @@ * @param string $repmodule * @return bool|mixed */ -function news_getmoduleoption($option, string $repmodule = 'news') +function news_getmoduleoption(string $option, string $repmodule = 'news') { global $xoopsModuleConfig, $xoopsModule; static $tbloptions = []; @@ -113,7 +113,7 @@ function news_updaterating($storyid): void * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ -function news_MygetItemIds($permtype = 'news_view') +function news_MygetItemIds(string $permtype = 'news_view'): array { global $xoopsUser; static $tblperms = []; @@ -196,7 +196,7 @@ static function ($matches) { * * @return bool need to say it ? */ -function news_isX23() +function news_isX23(): bool { $x23 = false; $xv = str_replace('XOOPS ', '', XOOPS_VERSION); @@ -220,7 +220,7 @@ function news_isX23() * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ -function news_getWysiwygForm($caption, $name, $value = '', $width = '100%', $height = '400px', $supplemental = '') +function news_getWysiwygForm(string $caption, string $name, string $value = '', string $width = '100%', string $height = '400px', string $supplemental = '') { $editor_option = \mb_strtolower(news_getmoduleoption('form_options')); $editor = false; @@ -241,18 +241,6 @@ function news_getWysiwygForm($caption, $name, $value = '', $width = '100%', $hei // Only for Xoops 2.0.x switch ($editor_option) { - case 'fckeditor': - if (is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php')) { - require_once XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'; - $editor = new \XoopsFormFckeditor($caption, $name, $value); - } - break; - case 'htmlarea': - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { - require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; - $editor = new \XoopsFormHtmlarea($caption, $name, $value); - } - break; case 'dhtmltextarea': case 'dhtml': $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); @@ -275,12 +263,6 @@ function news_getWysiwygForm($caption, $name, $value = '', $width = '100%', $hei ); } break; - case 'koivi': - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { - require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; - $editor = new \XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); - } - break; } return $editor; @@ -409,7 +391,7 @@ function news_CreateMetaDatas($story = null): void * @copyright (c) HervĂ© Thouzard * @author HervĂ© Thouzard (https://www.herve-thouzard.com) */ -function news_createmeta_keywords($content) +function news_createmeta_keywords($content): string { require_once XOOPS_ROOT_PATH . '/modules/news/config.php'; // require_once XOOPS_ROOT_PATH . '/modules/news/class/blacklist.php'; @@ -583,7 +565,7 @@ function news_updateCache(): void * @copyright (c) HervĂ© Thouzard * @author HervĂ© Thouzard (https://www.herve-thouzard.com) */ -function news_TableExists($tablename) +function news_TableExists($tablename): bool { global $xoopsDB; @@ -605,7 +587,7 @@ function news_TableExists($tablename) * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ -function news_FieldExists($fieldname, $table) +function news_FieldExists($fieldname, $table): bool { global $xoopsDB; $sql = "SHOW COLUMNS FROM $table LIKE '$fieldname'"; @@ -637,7 +619,7 @@ function news_AddField($field, $table) /** * Verify that the current user is a member of the Admin group */ -function news_is_admin_group() +function news_is_admin_group(): bool { global $xoopsUser, $xoopsModule; if (is_object($xoopsUser)) { @@ -695,7 +677,7 @@ function news_isbot() * @copyright (c) HervĂ© Thouzard * @author HervĂ© Thouzard (https://www.herve-thouzard.com) */ -function news_make_infotips($text) +function news_make_infotips($text): ?string { $infotips = news_getmoduleoption('infotips'); if ($infotips > 0) { @@ -713,7 +695,7 @@ function news_make_infotips($text) * @author Monte Ohrt , modified by Amos Robinson * */ -function news_close_tags($string) +function news_close_tags(string $string): string { // match opened tags if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { @@ -764,7 +746,7 @@ function news_close_tags($string) * @author Monte Ohrt , modified by Amos Robinson * */ -function news_truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false) +function news_truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false): string { if (0 == $length) { return ''; @@ -796,13 +778,13 @@ function news_truncate_tagsafe($string, $length = 80, $etc = '...', $break_words * @return bool */ function news_resizePicture( - $src_path, - $dst_path, - $param_width, - $param_height, - $keep_original = false, - $fit = 'inside' -) { + string $src_path, + string $dst_path, + int $param_width, + int $param_height, + bool $keep_original = false, + string $fit = 'inside' +): bool { // require_once XOOPS_PATH . '/vendor/wideimage/WideImage.php'; $resize = true; $pictureDimensions = getimagesize($src_path); diff --git a/include/install_function.php b/include/install_function.php index 248c7a2..56f50fd 100644 --- a/include/install_function.php +++ b/include/install_function.php @@ -15,7 +15,7 @@ * @author Voltan * @return bool */ -function xoops_module_pre_install_news(\XoopsModule $module) +function xoops_module_pre_install_news(\XoopsModule $module): bool { // Check if this XOOPS version is supported $minSupportedVersion = explode('.', '2.5.0'); @@ -48,7 +48,7 @@ function xoops_module_pre_install_news(\XoopsModule $module) * @param \XoopsModule $module * @return bool */ -function xoops_module_install_news(\XoopsModule $module) +function xoops_module_install_news(\XoopsModule $module): bool { $module_id = $module->getVar('mid'); /** @var \XoopsGroupPermHandler $grouppermHandler */ diff --git a/include/notification.inc.php b/include/notification.inc.php index c562e5f..70b1b04 100644 --- a/include/notification.inc.php +++ b/include/notification.inc.php @@ -20,7 +20,7 @@ * @param mixed $item_id * @return array|null */ -function news_notify_iteminfo($category, $item_id) +function news_notify_iteminfo($category, $item_id): ?array { if ('global' === $category) { $item['name'] = ''; diff --git a/include/oninstall.php b/include/oninstall.php index 027753c..74ed051 100644 --- a/include/oninstall.php +++ b/include/oninstall.php @@ -15,10 +15,11 @@ * @author XOOPS Development Team */ -use XoopsModules\News; -use XoopsModules\News\Common\Configurator; -use XoopsModules\News\Helper; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + Common\Configurator, + Helper, + Utility +}; /** * Prepares system prior to attempting to install module @@ -26,7 +27,7 @@ * * @return bool true if ready to install, false if not */ -function xoops_module_pre_install_news(\XoopsModule $module) +function xoops_module_pre_install_news(\XoopsModule $module): bool { require_once \dirname(__DIR__) . '/preloads/autoloader.php'; /** @var Utility $utility */ @@ -50,7 +51,7 @@ function xoops_module_pre_install_news(\XoopsModule $module) * * @return bool true if installation successful, false if not */ -function xoops_module_install_news(\XoopsModule $module) +function xoops_module_install_news(\XoopsModule $module): bool { require_once \dirname(__DIR__, 3) . '/mainfile.php'; diff --git a/include/onuninstall.php b/include/onuninstall.php index 846e15c..e7c1a77 100644 --- a/include/onuninstall.php +++ b/include/onuninstall.php @@ -20,7 +20,7 @@ * * @return bool true if ready to uninstall, false if not */ -function xoops_module_pre_uninstall_news(\XoopsModule $module) +function xoops_module_pre_uninstall_news(\XoopsModule $module): bool { // Do some synchronization return true; @@ -32,7 +32,7 @@ function xoops_module_pre_uninstall_news(\XoopsModule $module) * * @return bool true if uninstallation successful, false if not */ -function xoops_module_uninstall_news(\XoopsModule $module) +function xoops_module_uninstall_news(\XoopsModule $module): bool { // return true; diff --git a/include/onupdate.php b/include/onupdate.php index 6066086..d4f3384 100644 --- a/include/onupdate.php +++ b/include/onupdate.php @@ -33,7 +33,7 @@ * * @return bool true if ready to install, false if not */ -function xoops_module_pre_update_news(\XoopsModule $module) +function xoops_module_pre_update_news(\XoopsModule $module): bool { $moduleDirName = \basename(\dirname(__DIR__)); /** @var Helper $helper */ @@ -54,7 +54,7 @@ function xoops_module_pre_update_news(\XoopsModule $module) * * @return bool true if update successful, false if not */ -function xoops_module_update_news(\XoopsModule $module, $previousVersion = null) +function xoops_module_update_news(\XoopsModule $module, $previousVersion = null): bool { $moduleDirName = \basename(\dirname(__DIR__)); $moduleDirNameUpper = \mb_strtoupper($moduleDirName); diff --git a/include/search.inc.php b/include/search.inc.php index 43f9dc8..97dbf30 100644 --- a/include/search.inc.php +++ b/include/search.inc.php @@ -15,8 +15,9 @@ * @author XOOPS Development Team */ -use XoopsModules\News; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + Utility +}; /** * @param $queryarray @@ -27,7 +28,7 @@ * * @return array */ -function news_search($queryarray, $andor, $limit, $offset, $userid) +function news_search($queryarray, $andor, $limit, $offset, $userid): array { global $xoopsDB, $xoopsUser; $restricted = Utility::getModuleOption('restrictindex'); diff --git a/include/storyform.original.php b/include/storyform.original.php index d2ed548..9e1fac3 100644 --- a/include/storyform.original.php +++ b/include/storyform.original.php @@ -16,11 +16,12 @@ */ use Xmf\Request; -use XoopsModules\News; -use XoopsModules\News\Files; -use XoopsModules\News\Helper; -use XoopsModules\News\NewsTopic; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + Files, + Helper, + NewsTopic, + Utility +}; use XoopsModules\Tag\FormTag; require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; @@ -57,14 +58,9 @@ $moduleDirName = \basename(\dirname(__DIR__)); xoops_load('utility', $moduleDirName); -if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { - // $topic_select = $topic_tree->makeSelBox('topic_id', 'topic_title', '-- ', $topicid, false); - $topic_select = $topic_tree->makeSelectElement('topic_id', 'topic_title', '--', $topicid, false, 0, '', _NW_TOPIC); - $sform->addElement($topic_select); -} else { - $topic_select = $topic_tree->makeSelBox('topic_id', 'topic_title', '-- ', $topicid, false); - $sform->addElement(new \XoopsFormLabel(_NW_TOPIC, $topic_select)); -} +$topic_select = $topic_tree->makeSelectElement('topic_id', 'topic_title', '--', $topicid, false, 0, '', _NW_TOPIC); +$sform->addElement($topic_select); + //If admin - show admin form //TODO: Change to "If submit privilege" diff --git a/include/update_function.php b/include/update_function.php index 6734435..5b58fb3 100644 --- a/include/update_function.php +++ b/include/update_function.php @@ -22,7 +22,7 @@ /** * @return bool */ -function xoops_module_update_news() +function xoops_module_update_news(): bool { global $xoopsDB; $errors = 0; diff --git a/index.php b/index.php index 464454d..a4004f9 100644 --- a/index.php +++ b/index.php @@ -174,13 +174,8 @@ $allTopics = $xt->getAllTopics($helper->getConfig('restrictindex')); $topic_tree = new ObjectTree($allTopics, 'topic_id', 'topic_pid'); - if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { - $topic_select = $topic_tree->makeSelectElement('storytopic', 'topic_title', '--', $xoopsOption['storytopic'], true, 0, '', ''); - $xoopsTpl->assign('topic_select', $topic_select->render()); - } else { - $topic_select = $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', $xoopsOption['storytopic'], true); - $xoopsTpl->assign('topic_select', $topic_select); - } + $topic_select = $topic_tree->makeSelectElement('storytopic', 'topic_title', '--', $xoopsOption['storytopic'], true, 0, '', ''); + $xoopsTpl->assign('topic_select', $topic_select->render()); $storynum_options = ''; for ($i = 5; $i <= 30; $i += 5) { diff --git a/micro_summary.php b/micro_summary.php index ba6e707..dcc846b 100644 --- a/micro_summary.php +++ b/micro_summary.php @@ -29,9 +29,10 @@ * */ -use XoopsModules\News; -use XoopsModules\News\NewsStory; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + NewsStory, + Utility +}; require_once \dirname(__DIR__, 2) . '/mainfile.php'; // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; diff --git a/newsbythisauthor.php b/newsbythisauthor.php index 9904bd5..f1b37fe 100644 --- a/newsbythisauthor.php +++ b/newsbythisauthor.php @@ -66,10 +66,11 @@ */ use Xmf\Request; -use XoopsModules\News; -use XoopsModules\News\Helper; -use XoopsModules\News\NewsStory; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + Helper, + NewsStory, + Utility +}; require_once \dirname(__DIR__, 2) . '/mainfile.php'; //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; diff --git a/preloads/core.php b/preloads/core.php index 29c14b6..e07054a 100644 --- a/preloads/core.php +++ b/preloads/core.php @@ -22,9 +22,9 @@ class NewsCorePreload extends \XoopsPreloadItem { // to add PSR-4 autoloader /** - * @param $args + * @param array $args */ - public static function eventCoreIncludeCommonEnd($args): void + public static function eventCoreIncludeCommonEnd(array $args): void { require_once __DIR__ . '/autoloader.php'; } diff --git a/print.php b/print.php index 6b9b7da..f082903 100644 --- a/print.php +++ b/print.php @@ -33,9 +33,10 @@ */ use Xmf\Request; -use XoopsModules\News; -use XoopsModules\News\NewsStory; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + NewsStory, + Utility +}; require_once \dirname(__DIR__, 2) . '/mainfile.php'; // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; diff --git a/ratenews.php b/ratenews.php index 0894b05..7790f8f 100644 --- a/ratenews.php +++ b/ratenews.php @@ -55,9 +55,10 @@ */ use Xmf\Request; -use XoopsModules\News; -use XoopsModules\News\NewsStory; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + NewsStory, + Utility +}; require_once __DIR__ . '/header.php'; require_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php'; diff --git a/testdata/index.php b/testdata/index.php index d6bbf3a..1deb8cd 100644 --- a/testdata/index.php +++ b/testdata/index.php @@ -168,7 +168,7 @@ function exportSchema(): void * @param string $replace * @return int number of rows inserted */ -function loadTableFromArrayWithReplace($table, $data, $search, $replace) +function loadTableFromArrayWithReplace(string $table, array $data, string $search, string $replace): int { /** @var \XoopsMySQLDatabase $db */ $db = \XoopsDatabaseFactory::getDatabaseConnection(); diff --git a/topics_directory.php b/topics_directory.php index 219b564..468f9a5 100644 --- a/topics_directory.php +++ b/topics_directory.php @@ -25,9 +25,11 @@ * @copyright (c) HervĂ© Thouzard - https://www.herve-thouzard.com */ -use XoopsModules\News; -use XoopsModules\News\NewsTopic; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + Helper, + NewsTopic, + Utility +}; require_once \dirname(__DIR__, 2) . '/mainfile.php'; //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; diff --git a/visit.php b/visit.php index 2ba5ccc..d449b19 100644 --- a/visit.php +++ b/visit.php @@ -16,8 +16,10 @@ */ use Xmf\Request; -use XoopsModules\News\Files; -use XoopsModules\News\NewsStory; +use XoopsModules\News\{ + Files, + NewsStory +}; require_once \dirname(__DIR__, 2) . '/mainfile.php'; // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php'; diff --git a/whoswho.php b/whoswho.php index 687060b..02e52c3 100644 --- a/whoswho.php +++ b/whoswho.php @@ -25,9 +25,10 @@ * @copyright (c) HervĂ© Thouzard (https://www.herve-thouzard.com) */ -use XoopsModules\News; -use XoopsModules\News\NewsStory; -use XoopsModules\News\Utility; +use XoopsModules\News\{ + NewsStory, + Utility +}; require_once \dirname(__DIR__, 2) . '/mainfile.php'; //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; From 6856d90efb10305baf6d3e60d58466059d5f7712 Mon Sep 17 00:00:00 2001 From: mambax7 Date: Tue, 3 Sep 2024 01:07:37 -0400 Subject: [PATCH 25/29] 1.73.0 Beta 2 --- admin/amsimport.php | 6 +- admin/index.php | 87 +++-- admin/migrate.php | 2 +- archive.php | 9 +- article.php | 9 +- backendt.php | 6 +- blocks/news_top.php | 12 +- blocks/news_topicsnav.php | 2 +- class/Common/Blocksadmin.php | 31 +- class/Common/DirectoryChecker.php | 2 +- class/Common/FileChecker.php | 22 +- class/Common/FilesManagement.php | 8 +- class/Common/Migrate.php | 2 +- class/Common/ModuleStats.php | 41 ++ class/Common/SysUtility.php | 430 +++++++++++++++++---- class/Common/VersionChecks.php | 13 +- class/Keyhighlighter.php | 2 +- class/Mimetype.php | 2 +- class/NewsStoriesHandler.php | 2 +- class/NewsStory.php | 126 +++--- class/NewsStoryHandler.php | 2 +- class/NewsTopic.php | 38 +- class/NewsTopicsHandler.php | 2 +- class/ObjectTree.php | 6 +- class/PageNav.php | 48 +-- class/Registryfile.php | 2 +- class/Utility.php | 138 +++---- class/XoopsStory.php | 62 +-- class/XoopsTopic.php | 12 +- class/XoopsTree.php | 67 +--- class/plugins/plugin.tag.php | 2 +- config/config.php | 8 +- docs/changelog.txt | 11 +- header.php | 26 ++ include/functions.php | 23 +- include/install_function.php | 6 +- include/onuninstall.php | 2 +- include/onupdate.php | 12 +- include/search.inc.php | 2 +- include/update_function.php | 6 +- index.php | 2 +- makepdf.php | 2 +- preloads/autoloader.php | 8 +- print.php | 2 +- ratenews.php | 23 +- submit.php | 2 +- templates/blocks/news_block_moderate.tpl | 2 +- templates/blocks/news_block_randomnews.tpl | 2 +- templates/blocks/news_block_top.tpl | 14 +- templates/news_archive.tpl | 6 +- templates/news_article.tpl | 14 +- templates/news_by_this_author.tpl | 14 +- templates/news_by_topic.tpl | 4 +- templates/news_index.tpl | 2 +- templates/news_item.tpl | 11 +- templates/news_ratenews.tpl | 2 +- templates/news_rss.tpl | 2 +- testdata/index.php | 6 +- topics_directory.php | 4 +- xoops_version.php | 15 +- 60 files changed, 850 insertions(+), 576 deletions(-) create mode 100644 class/Common/ModuleStats.php diff --git a/admin/amsimport.php b/admin/amsimport.php index 41ba08d..70b325d 100644 --- a/admin/amsimport.php +++ b/admin/amsimport.php @@ -214,7 +214,7 @@ // The comments $comments = $commentHandler->getByItemId($ams_mid, $ams_newsid, 'ASC'); - if ($comments && is_array($comments)) { + if ($comments && \is_array($comments)) { foreach ($comments as $onecomment) { $onecomment->setNew(); $onecomment->setVar('com_modid', $news_mid); @@ -230,7 +230,7 @@ $criteria->add(new \Criteria('not_itemid', $ams_newsid)); $criteria->setOrder('ASC'); $notifications = $notificationHandler->getObjects($criteria); - if ($notifications && is_array($notifications)) { + if ($notifications && \is_array($notifications)) { foreach ($notifications as $onenotification) { $onenotification->setNew(); $onenotification->setVar('not_modid', $news_mid); @@ -246,7 +246,7 @@ $criteria->add(new \Criteria('not_category', 'global')); $criteria->setOrder('ASC'); $notifications = $notificationHandler->getObjects($criteria); - if ($notifications && is_array($notifications)) { + if ($notifications && \is_array($notifications)) { foreach ($notifications as $onenotification) { $onenotification->setNew(); $onenotification->setVar('not_modid', $news_mid); diff --git a/admin/index.php b/admin/index.php index e50e042..17e919d 100644 --- a/admin/index.php +++ b/admin/index.php @@ -40,7 +40,8 @@ ObjectTree, PageNav, Registryfile, - Utility + Utility, + XoopsTopic }; /** @var Admin $adminObject */ @@ -86,8 +87,8 @@ function newSubmissions(): void { global $dateformat, $pathIcon16; $start = Request::getInt('startnew', 0, 'GET'); - $newsubcount = NewsStory::getAllStoriesCount(3, false); - $storyarray = NewsStory::getAllSubmitted(Utility::getModuleOption('storycountadmin'), true, (bool)Utility::getModuleOption('restrictindex'), $start); + $newsubcount = NewsStory::getAllStoriesCount(3, 0); + $storyarray = NewsStory::getAllSubmitted(Utility::getModuleOption('storycountadmin'), true, Utility::getModuleOption('restrictindex'), $start); if (count($storyarray) > 0) { $pagenav = new PageNav($newsubcount, Utility::getModuleOption('storycountadmin'), $start, 'startnew', 'op=newarticle'); news_collapsableBar('newsub', 'topnewsubicon'); @@ -165,7 +166,7 @@ function autoStories(): void global $dateformat, $pathIcon16; $start = Request::getInt('startauto', 0, 'GET'); - $storiescount = NewsStory::getAllStoriesCount(2, false); + $storiescount = NewsStory::getAllStoriesCount(2, 0); $storyarray = NewsStory::getAllAutoStory(Utility::getModuleOption('storycountadmin'), true, $start); $class = ''; if (count($storyarray) > 0) { @@ -266,8 +267,8 @@ function lastStories(): void echo '
      '; echo "
      "; $start = Request::getInt('start', 0, 'GET'); - $storyarray = NewsStory::getAllPublished(Utility::getModuleOption('storycountadmin'), $start, false, 0, 1); - $storiescount = NewsStory::getAllStoriesCount(4, false); + $storyarray = NewsStory::getAllPublished(Utility::getModuleOption('storycountadmin'), $start, 0, 0, 1); + $storiescount = NewsStory::getAllStoriesCount(4, 0); $pagenav = new PageNav($storiescount, Utility::getModuleOption('storycountadmin'), $start, 'start', 'op=newarticle'); $class = ''; echo "
      " @@ -333,7 +334,7 @@ function expStories(): void { global $dateformat, $pathIcon16; $start = Request::getInt('startexp', 0, 'GET'); - $expiredcount = NewsStory::getAllStoriesCount(1, false); + $expiredcount = NewsStory::getAllStoriesCount(1, 0); $storyarray = NewsStory::getAllExpired(Utility::getModuleOption('storycountadmin'), $start, 0, 1); $pagenav = new PageNav($expiredcount, Utility::getModuleOption('storycountadmin'), $start, 'startexp', 'op=newarticle'); @@ -924,6 +925,7 @@ function topicsmanager(): void $sform->setExtra('enctype="multipart/form-data"'); $sform->addElement(new \XoopsFormText(_AM_TOPICNAME, 'topic_title', 50, 255, $topic_title), true); $editor = Utility::getWysiwygForm(_AM_TOPIC_DESCR, 'topic_description', $topic_description, 15, 60, 'hometext_hidden'); +// $editor = Utility::getEditor($helper,_AM_TOPIC_DESCR, 'topic_description', $topic_description, 15, 60, 'hometext_hidden'); if ($editor) { $sform->addElement($editor, false); } @@ -1574,7 +1576,7 @@ function getStats(): void $url2, $myts->displayTarea($data['title']), $url3, - htmlspecialchars($news->uname($data['uid']), ENT_QUOTES | ENT_HTML5), + htmlspecialchars($news->uname((int)$data['uid']), ENT_QUOTES | ENT_HTML5), $data['counter'] ); } @@ -1596,7 +1598,7 @@ function getStats(): void $url2, $myts->displayTarea($data['title']), $url3, - htmlspecialchars($news->uname($data['uid']), ENT_QUOTES | ENT_HTML5), + htmlspecialchars($news->uname((int)$data['uid']), ENT_QUOTES | ENT_HTML5), $data['counter'] ); } @@ -1618,7 +1620,7 @@ function getStats(): void $url2, $myts->displayTarea($data['title']), $url3, - htmlspecialchars($news->uname($data['uid']), ENT_QUOTES | ENT_HTML5), + htmlspecialchars($news->uname((int)$data['uid']), ENT_QUOTES | ENT_HTML5), number_format((float)$data['rating'], 2) ); } @@ -1719,7 +1721,7 @@ function getMetagen(): void $metablack = new Blacklist(); $words = $metablack->getAllKeywords(); - if ($words && is_array($words)) { + if ($words && \is_array($words)) { foreach ($words as $key => $value) { $blacklist->addOption($key, $value); } @@ -2005,34 +2007,41 @@ function saveMetagenOptions(): void //------ check directories --------------- - $adminObject->addConfigBoxLine(''); - $redirectFile = Request::getString('SCRIPT_NAME', '', 'SERVER'); - - //check directories - $adminObject->addConfigBoxLine(''); - //$path = $helper->getConfig('uploaddir') . '/'; - $path = $helper->getConfig('uploaddir'); - //$path0 = $helper->getModule()->getInfo('uploaddir'); - $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); - - $path = $helper->getConfig('batchdir') . '/'; - $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); - - $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('mainimagedir') . '/'; - $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); - //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); - - $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('screenshots') . '/'; - $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); - //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); - $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path . 'thumbs' . '/', 0777, $redirectFile)); - //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'thumbs' . '/' . 'blank.png', BLANK_FILE_PATH, $redirectFile)); - - $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage') . '/'; - $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); - //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); - $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path . 'thumbs' . '/', 0777, $redirectFile)); - //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'thumbs' . '/' . 'blank.png', BLANK_FILE_PATH, $redirectFile)); + //check for upload folders, create if needed + $configurator = new Common\Configurator(); + foreach (array_keys($configurator->uploadFolders) as $i) { + $utility::createFolder($configurator->uploadFolders[$i]); + $adminObject->addConfigBoxLine($configurator->uploadFolders[$i], 'folder'); + } + +// $adminObject->addConfigBoxLine(''); +// $redirectFile = Request::getString('SCRIPT_NAME', '', 'SERVER'); +// +// //check directories +// $adminObject->addConfigBoxLine(''); +// //$path = $helper->getConfig('uploaddir') . '/'; +// $path = $helper->getConfig('uploaddir'); +// //$path0 = $helper->getModule()->getInfo('uploaddir'); +// $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); +// +// $path = $helper->getConfig('batchdir') . '/'; +// $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); +// +// $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('mainimagedir') . '/'; +// $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); +// //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); +// +// $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('screenshots') . '/'; +// $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); +// //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); +// $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path . 'thumbs' . '/', 0777, $redirectFile)); +// //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'thumbs' . '/' . 'blank.png', BLANK_FILE_PATH, $redirectFile)); +// +// $path = XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage') . '/'; +// $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path, 0777, $redirectFile)); +// //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'blank.png', BLANK_FILE_PATH, $redirectFile)); +// $adminObject->addConfigBoxLine(DirectoryChecker::getDirectoryStatus($path . 'thumbs' . '/', 0777, $redirectFile)); +// //$adminObject->addConfigBoxLine(FileChecker::getFileStatus($path . 'thumbs' . '/' . 'blank.png', BLANK_FILE_PATH, $redirectFile)); //--------------------------- diff --git a/admin/migrate.php b/admin/migrate.php index 18393b4..e427cad 100644 --- a/admin/migrate.php +++ b/admin/migrate.php @@ -15,7 +15,7 @@ * Migration for XOOPS modules * * @copyright XOOPS Project (https://xoops.org) - * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) + * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) * @author Richard Griffith * @author Michael Beck */ diff --git a/archive.php b/archive.php index 2d75a49..8aa5b20 100644 --- a/archive.php +++ b/archive.php @@ -96,7 +96,9 @@ 12 => _CAL_DECEMBER, ]; +/** @var int $fromyear */ $fromyear = Request::getInt('year', 0, 'GET'); +/** @var int $frommonth */ $frommonth = Request::getInt('month', 0, 'GET'); $pgtitle = ''; @@ -122,10 +124,7 @@ } } $sql = 'SELECT published FROM ' . $xoopsDB->prefix('news_stories') . ' WHERE (published>0 AND published<=' . time() . ') AND (expired = 0 OR expired <= ' . time() . ') ORDER BY published DESC'; -$result = $xoopsDB->query($sql); -if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); -} +$result = Utility::queryAndCheck($xoopsDB, $sql); $years = []; $months = []; $i = 0; @@ -220,7 +219,7 @@ $xoopsTpl->assign('lang_newsarchives', _NW_NEWSARCHIVES); /** - * Create the meta datas + * Create the metadatas */ Utility::createMetaDatas(); diff --git a/article.php b/article.php index e09f0d4..f53f8f5 100644 --- a/article.php +++ b/article.php @@ -162,6 +162,7 @@ redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); } +/** @var int $storypage */ $storypage = Request::getInt('page', 0, 'GET'); $dateformat = Utility::getModuleOption('dateformat'); $hcontent = ''; @@ -344,7 +345,7 @@ function my_highlighter($matches): string */ $complement = ''; if (Utility::getModuleOption('enhanced_pagenav') - && (isset($arr_titles) && is_array($arr_titles) + && (isset($arr_titles) && \is_array($arr_titles) && isset($arr_titles, $storypage) && $storypage > 0)) { $complement = ' - ' . $arr_titles[$storypage]; @@ -435,7 +436,7 @@ function my_highlighter($matches): string $nextTitle = $next['title']; } - $previous = $tmparticle->getPreviousArticle($storyid, $helper->getConfig('restrictindex')); + $previous = $tmparticle->getPreviousArticle($storyid, (int)$helper->getConfig('restrictindex')); if (count($previous) > 0) { $previousId = $previous['storyid']; $previousTitle = $previous['title']; @@ -460,7 +461,7 @@ function my_highlighter($matches): string } /** - * Manage all the meta datas + * Manage all the metadatas */ Utility::createMetaDatas($article); @@ -503,7 +504,7 @@ function my_highlighter($matches): string $xoopsTpl->assign('rates', true); $xoopsTpl->assign('lang_ratingc', _NW_RATINGC); $xoopsTpl->assign('lang_ratethisnews', _NW_RATETHISNEWS); - $story['rating'] = number_format($article->rating(), 2); + $story['rating'] =number_format((float)$article->rating(), 2); if (1 == $article->votes) { $story['votes'] = _NW_ONEVOTE; } else { diff --git a/backendt.php b/backendt.php index 2146d3d..3532cc1 100644 --- a/backendt.php +++ b/backendt.php @@ -68,9 +68,9 @@ if (!$tpl->isCached('db:news_rss.tpl', $topicid)) { $xt = new NewsTopic($topicid); $sarray = NewsStory::getAllPublished($newsnumber, 0, $restricted, $topicid); - if ($sarray && is_array($sarray)) { - $sitename = htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES); - $slogan = htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES); + if ($sarray && \is_array($sarray)) { + $sitename = htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES | ENT_HTML5); + $slogan = htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES | ENT_HTML5); $tpl->assign('channel_title', xoops_utf8_encode($sitename)); $tpl->assign('channel_link', XOOPS_URL . '/'); $tpl->assign('channel_desc', xoops_utf8_encode($slogan)); diff --git a/blocks/news_top.php b/blocks/news_top.php index fe7aa22..6d2a018 100644 --- a/blocks/news_top.php +++ b/blocks/news_top.php @@ -223,7 +223,7 @@ function b_news_top_show($options) $spotlight['id'] = $tmpstory->storyid(); $spotlight['date'] = formatTimestamp($tmpstory->published(), $dateformat); $spotlight['hits'] = $tmpstory->counter(); - $spotlight['rating'] = number_format($tmpstory->rating(), 2); + $spotlight['rating'] =number_format((float)$tmpstory->rating(), 2); $spotlight['votes'] = $tmpstory->votes(); if ('' !== xoops_trim($tmpstory->bodytext())) { $spotlight['read_more'] = true; @@ -273,7 +273,7 @@ function b_news_top_show($options) $news['id'] = $story->storyid(); $news['date'] = formatTimestamp($story->published(), $dateformat); $news['hits'] = $story->counter(); - $news['rating'] = number_format($story->rating(), 2); + $news['rating'] =number_format((float)$story->rating(), 2); $news['votes'] = $story->votes(); $news['topicid'] = $story->topicid(); $news['topic_title'] = $story->topic_title(); @@ -349,7 +349,7 @@ function b_news_top_show($options) $news['id'] = $story->storyid(); $news['date'] = formatTimestamp($story->published(), $dateformat); $news['hits'] = $story->counter(); - $news['rating'] = number_format($story->rating(), 2); + $news['rating'] =number_format((float)$story->rating(), 2); $news['votes'] = $story->votes(); $news['topicid'] = $story->topicid(); $news['topic_title'] = $story->topic_title(); @@ -395,10 +395,10 @@ function b_news_top_show($options) } else { // ************************ Classical view ************************************************************************************************************** $tmpstory = new NewsStory(); if (isset($options[14]) && 0 == (int)$options[14]) { - $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]); + $stories = NewsStory::getAllPublished((int)$options[1], 0, $restricted, 0, 1, true, $options[0]); } else { $topics = array_slice($options, 14); - $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]); + $stories = NewsStory::getAllPublished((int)$options[1], 0, $restricted, $topics, 1, true, $options[0]); } if (!$stories) { @@ -635,7 +635,7 @@ function b_news_top_edit($options): string $form .= '>' . _MB_NEWS_RECENT_SPECIFIC . ''; $form .= '

      ' . _MB_NEWS_SPOTLIGHT_ARTICLE . '
      '; - $articles = NewsStory::getAllPublished(200, 0, false, 0, 0, false); // I have limited the listbox to the last 200 articles + $articles = NewsStory::getAllPublished(200, 0, 0, 0, 0, false); // I have limited the listbox to the last 200 articles $form .= "'; if ($addEmptyOption) { $ret .= ''; @@ -300,7 +300,7 @@ public function __get(string $name) { $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1); if ('_tree' === $name) { - \trigger_error("XoopsObjectTree::\$_tree is deprecated, accessed from {$trace[0]['file']} line {$trace[0]['line']},"); + \trigger_error("XoopsObjectTree::\$_tree is deprecated, accessed from {$trace[0]['file']} line {$trace[0]['line']},", E_USER_DEPRECATED); return $this->tree; } diff --git a/class/PageNav.php b/class/PageNav.php index 1abd97f..ef91fea 100644 --- a/class/PageNav.php +++ b/class/PageNav.php @@ -34,30 +34,31 @@ class PageNav /**#@+ * @access private */ - public $total; - public $perpage; - public $current; - public $url; + public int $total; + public int $perpage; + public int $current; + public string $url; /**#@-*/ /** * Constructor * - * @param int|string $total_items Total number of items - * @param int $items_perpage Number of items per page - * @param int $current_start First item on the current page - * @param string $start_name Name for "start" or "offset" - * @param string $extra_arg Additional arguments to pass in the URL + * @param int|string $total_items Total number of items + * @param int $items_perpage Number of items per page + * @param int $current_start First item on the current page + * @param string|null $start_name Name for "start" or "offset" + * @param string $extra_arg Additional arguments to pass in the URL **/ - public function __construct($total_items, int $items_perpage, int $current_start, string $start_name = 'start', string $extra_arg = '') + public function __construct($total_items, int $items_perpage, int $current_start, ?string $start_name = null, string $extra_arg = '') { + $start_name ??= 'start'; $this->total = (int)$total_items; $this->perpage = (int)$items_perpage; $this->current = (int)$current_start; if ('' !== $extra_arg && ('&' !== mb_substr($extra_arg, -5) || '&' !== mb_substr($extra_arg, -1))) { $extra_arg .= '&'; } - $this->url = $_SERVER['SCRIPT_NAME'] . '?' . $extra_arg . trim($start_name) . '='; + $this->url = $_SERVER['SCRIPT_NAME'] . '?' . $extra_arg . \trim($start_name) . '='; } /** @@ -73,14 +74,14 @@ public function renderNav(int $offset = 4): string if ($this->total <= $this->perpage) { return $ret; } - $total_pages = ceil($this->total / $this->perpage); + $total_pages = \ceil($this->total / $this->perpage); if ($total_pages > 1) { $prev = $this->current - $this->perpage; if ($prev >= 0) { $ret .= '« '; } $counter = 1; - $current_page = (int)floor(($this->current + $this->perpage) / $this->perpage); + $current_page = (int)\floor(($this->current + $this->perpage) / $this->perpage); while ($counter <= $total_pages) { if ($counter == $current_page) { $ret .= '(' . $counter . ') '; @@ -117,13 +118,13 @@ public function renderSelect(bool $showbutton = false): ?string if ($this->total < $this->perpage) { return null; } - $total_pages = ceil($this->total / $this->perpage); + $total_pages = \ceil($this->total / $this->perpage); $ret = ''; if ($total_pages > 1) { $ret = '
      '; $ret .= ''; if ($showbutton) { - $ret .= ' '; + $ret .= ' '; } $ret .= '
      '; } @@ -145,23 +146,24 @@ public function renderSelect(bool $showbutton = false): ?string /** * Create an enhanced navigational dropdown list * - * @param bool $showbutton Show the "Go" button? + * @param bool|null $showbutton Show the "Go" button? * @param null $titles * * @return string */ - public function renderEnhancedSelect(bool $showbutton = false, $titles = null): ?string + public function renderEnhancedSelect(?bool $showbutton = null, $titles = null): ?string { + $showbutton ??= false; if ($this->total < $this->perpage) { return null; } - $total_pages = ceil($this->total / $this->perpage); + $total_pages = \ceil($this->total / $this->perpage); $ret = ''; if ($total_pages > 1) { $ret = '
      '; $ret .= ''; if ($showbutton) { - $ret .= ' '; + $ret .= ' '; } $ret .= '
      '; } @@ -193,7 +195,7 @@ public function renderImageNav(int $offset = 4): ?string if ($this->total < $this->perpage) { return null; } - $total_pages = ceil($this->total / $this->perpage); + $total_pages = \ceil($this->total / $this->perpage); $ret = ''; if ($total_pages > 1) { $ret = ''; @@ -202,7 +204,7 @@ public function renderImageNav(int $offset = 4): ?string $ret .= ''; } $counter = 1; - $current_page = (int)floor(($this->current + $this->perpage) / $this->perpage); + $current_page = (int)\floor(($this->current + $this->perpage) / $this->perpage); while ($counter <= $total_pages) { if ($counter == $current_page) { $ret .= ''; diff --git a/class/Registryfile.php b/class/Registryfile.php index 4704347..3ca7018 100644 --- a/class/Registryfile.php +++ b/class/Registryfile.php @@ -81,7 +81,7 @@ public function savefile($content, $fichier = null): bool @\unlink($fw); } /** @var resource $fp */ - $fp = \fopen($fw, 'wb') || exit(_ERRORS); + $fp = \fopen($fw, 'wb') || exit(\_ERRORS); \fwrite($fp, $content); \fclose($fp); diff --git a/class/Utility.php b/class/Utility.php index 3460966..3b22aad 100644 --- a/class/Utility.php +++ b/class/Utility.php @@ -2,18 +2,8 @@ namespace XoopsModules\News; -use MyTextSanitizer; use WideImage\WideImage; use Xmf\Request; -use XoopsFormDhtmlTextArea; -use XoopsFormEditor; -use XoopsFormFckeditor; -use XoopsFormHtmlarea; -use XoopsFormTextArea; -use XoopsFormTinyeditorTextArea; -use XoopsFormWysiwygTextArea; -use XoopsObjectTree; -use XoopsTpl; /** * Class Utility @@ -24,7 +14,7 @@ class Utility extends Common\SysUtility /** * @param string $option * @param string $repmodule - * @return bool|mixed + * @return mixed */ public static function getModuleOption(string $option, string $repmodule = 'news') { @@ -69,18 +59,15 @@ public static function getModuleOption(string $option, string $repmodule = 'news public static function updateRating(int $storyid): void { global $xoopsDB; - $sql = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; - $result = $xoopsDB->query($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } + $sql = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; + $result = self::queryAndCheck($xoopsDB, $sql); $votesDB = $xoopsDB->getRowsNum($result); $totalrating = 0; while ([$rating] = $xoopsDB->fetchRow($result)) { $totalrating += $rating; } $finalrating = $totalrating / $votesDB; - $finalrating = \number_format($finalrating, 4); + $finalrating = \number_format((float)$finalrating, 4); $sql = \sprintf('UPDATE `%s` SET rating = %u, votes = %u WHERE storyid = %u', $xoopsDB->prefix('news_stories'), $finalrating, $votesDB, $storyid); $xoopsDB->queryF($sql); } @@ -196,14 +183,14 @@ public static function isX23(): bool * @param string $caption * @param string $name * @param string $value - * @param string $width - * @param string $height + * @param int $width + * @param int $height * @param string $supplemental * @return bool|\XoopsFormEditor|\XoopsFormTextArea * @author HervĂ© Thouzard (https://www.herve-thouzard.com) * @copyright (c) HervĂ© Thouzard */ - public static function getWysiwygForm(string $caption, string $name, string $value = '', string $width = '100%', string $height = '400px', string $supplemental = '') + public static function getWysiwygForm(string $caption, string $name, string $value = '', int $width = 15, int $height = 60, string $supplemental = '') { $editor_option = \mb_strtolower(static::getModuleOption('form_options')); $editor = false; @@ -212,12 +199,12 @@ public static function getWysiwygForm(string $caption, string $name, string $val $editor_configs['value'] = $value; $editor_configs['rows'] = 35; $editor_configs['cols'] = 60; - $editor_configs['width'] = '100%'; - $editor_configs['height'] = '350px'; + $editor_configs['width'] = (string)$width; + $editor_configs['height'] = (string)$height; $editor_configs['editor'] = $editor_option; if (static::isX23()) { - $editor = new XoopsFormEditor($caption, $name, $editor_configs); + $editor = new \XoopsFormEditor($caption, $name, $editor_configs); return $editor; } @@ -226,16 +213,16 @@ public static function getWysiwygForm(string $caption, string $name, string $val switch ($editor_option) { case 'dhtmltextarea': case 'dhtml': - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); + $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); break; case 'textarea': - $editor = new XoopsFormTextArea($caption, $name, $value); + $editor = new \XoopsFormTextArea($caption, $name, $value); break; case 'tinyeditor': case 'tinymce': if (\is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; - $editor = new XoopsFormTinyeditorTextArea( + $editor = new \XoopsFormTinyeditorTextArea( [ 'caption' => $caption, 'name' => $name, @@ -251,44 +238,44 @@ public static function getWysiwygForm(string $caption, string $name, string $val return $editor; } - /** - * @param \Xmf\Module\Helper|null $helper - * @param array|null $options - * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor - */ - public static function getEditor(\Xmf\Module\Helper $helper = null, array $options = null) - { - /** @var Helper $helper */ - if (null === $options) { - $options = []; - $options['name'] = 'Editor'; - $options['value'] = 'Editor'; - $options['rows'] = 10; - $options['cols'] = '100%'; - $options['width'] = '100%'; - $options['height'] = '400px'; - } - - if (null === $helper) { - $helper = Helper::getInstance(); - } - - $isAdmin = $helper->isUserAdmin(); - - if (\class_exists('XoopsFormEditor')) { - if ($isAdmin) { - $descEditor = new XoopsFormEditor(\ucfirst($options['name']), $helper->getConfig('editorAdmin'), $options, $nohtml = false, $onfailure = 'textarea'); - } else { - $descEditor = new XoopsFormEditor(\ucfirst($options['name']), $helper->getConfig('editorUser'), $options, $nohtml = false, $onfailure = 'textarea'); - } - } else { - $descEditor = new XoopsFormDhtmlTextArea(\ucfirst($options['name']), $options['name'], $options['value'], '100%', '100%'); - } - - // $form->addElement($descEditor); - - return $descEditor; - } +// /** +// * @param \Xmf\Module\Helper|null $helper +// * @param array|null $options +// * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor +// */ +// public static function getEditor(\Xmf\Module\Helper $helper = null, ?array $options = null) +// { +// /** @var Helper $helper */ +// if (null === $options) { +// $options = []; +// $options['name'] = 'Editor'; +// $options['value'] = 'Editor'; +// $options['rows'] = 10; +// $options['cols'] = '100%'; +// $options['width'] = '100%'; +// $options['height'] = '400px'; +// } +// +// if (null === $helper) { +// $helper = Helper::getInstance(); +// } +// +// $isAdmin = $helper->isUserAdmin(); +// +// if (\class_exists('XoopsFormEditor')) { +// if ($isAdmin) { +// $descEditor = new \XoopsFormEditor(\ucfirst((string) $options['name']), $helper->getConfig('editorAdmin'), $options, $nohtml = false, $onfailure = 'textarea'); +// } else { +// $descEditor = new \XoopsFormEditor(\ucfirst((string) $options['name']), $helper->getConfig('editorUser'), $options, $nohtml = false, $onfailure = 'textarea'); +// } +// } else { +// $descEditor = new \XoopsFormDhtmlTextArea(\ucfirst((string) $options['name']), $options['name'], $options['value']); +// } +// +// // $form->addElement($descEditor); +// +// return $descEditor; +// } /** * Internal function @@ -304,7 +291,7 @@ public static function getDublinQuotes(string $text) } /** - * Creates all the meta datas : + * Creates all the metadatas : * - For Mozilla/Netscape and Opera the site navigation's bar * - The Dublin's Core Metadata * - The link for Firefox 2 micro summaries @@ -338,7 +325,7 @@ public static function createMetaDatas($story = null): void // require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php'; $xt = new NewsTopic(); $allTopics = $xt->getAllTopics(static::getModuleOption('restrictindex')); - $topic_tree = new XoopsObjectTree($allTopics, 'topic_id', 'topic_pid'); + $topic_tree = new \XoopsObjectTree($allTopics, 'topic_id', 'topic_pid'); $topics_arr = $topic_tree->getAllChild(0); foreach ($topics_arr as $onetopic) { $content .= \sprintf("\n", $onetopic->topic_title(), XOOPS_URL . '/modules/news/index.php?storytopic=' . $onetopic->topic_id()); @@ -371,7 +358,7 @@ public static function createMetaDatas($story = null): void } /** - * Dublin Core's meta datas + * Dublin Core's metadatas */ if (static::getModuleOption('dublincore') && isset($story) && \is_object($story)) { /** @var XoopsConfigHandler $configHandler */ @@ -386,7 +373,7 @@ public static function createMetaDatas($story = null): void $content .= '\n"; $content .= '\n"; $content .= '\n"; - $content .= '\n"; + $content .= '\n"; $content .= '\n"; if (isset($xoopsConfigMetaFooter['meta_copyright'])) { $content .= '\n"; @@ -561,7 +548,7 @@ public static function updateCache(): void require_once XOOPS_ROOT_PATH . '/class/template.php'; $tplfileHandler = \xoops_getHandler('tplfile'); $tpllist = $tplfileHandler->find(null, null, null, $folder); - $xoopsTpl = new XoopsTpl(); + $xoopsTpl = new \XoopsTpl(); \xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache // Remove cache for each page. @@ -591,11 +578,7 @@ public static function existTable(string $tablename): bool { global $xoopsDB; $sql = "SHOW TABLES LIKE '$tablename'"; - $result = $xoopsDB->queryF($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } - + $result = Utility::queryFAndCheck($xoopsDB, $sql); return ($xoopsDB->getRowsNum($result) > 0); } @@ -613,10 +596,7 @@ public static function existField(string $fieldname, string $table): bool { global $xoopsDB; $sql = "SHOW COLUMNS FROM $table LIKE '$fieldname'"; - $result = $xoopsDB->queryF($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } + $result = Utility::queryFAndCheck($xoopsDB, $sql); return ($xoopsDB->getRowsNum($result) > 0); } @@ -774,7 +754,7 @@ public static function truncateTagSafe(string $string, int $length = 80, string return ''; } if (mb_strlen($string) > $length) { - $length -= mb_strlen($etc); + $length -= \mb_strlen($etc); if (!$break_words) { $string = \preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1)); $string = \preg_replace('/<[^>]*$/', '', $string); diff --git a/class/XoopsStory.php b/class/XoopsStory.php index fd322f8..c1a9eaf 100644 --- a/class/XoopsStory.php +++ b/class/XoopsStory.php @@ -1,10 +1,8 @@ -db */ - $this->db = XoopsDatabaseFactory::getDatabaseConnection(); + $this->db = \XoopsDatabaseFactory::getDatabaseConnection(); $this->table = ''; $this->topicstable = ''; if (\is_array($storyid)) { @@ -230,9 +228,9 @@ public function setComments($value): void /** * @param bool $approved * - * @return bool + * @return bool|int */ - public function store(bool $approved = false): bool + public function store(bool $approved = false) { //$newpost = 0; $myts = \MyTextSanitizer::getInstance(); @@ -346,13 +344,17 @@ public function getStory($storyid): void } /** - * @param $array + * @param array $array */ - public function makeStory($array): void + public function makeStory(array $array): void { foreach ($array as $key => $value) { $this->$key = $value; } + + if (!array_key_exists('type', $array)) { + $this->type = ''; // or some default value + } } /** @@ -419,7 +421,7 @@ public function uid() */ public function uname(): string { - return XoopsUser::getUnameFromId($this->uid); + return \XoopsUser::getUnameFromId($this->uid); } /** @@ -470,13 +472,13 @@ public function hometext(string $format = 'Show'): string $hometext = $myts->displayTarea($this->hometext, $html, $smiley, $xcodes); break; case 'Edit': - $hometext = \htmlspecialchars($this->hometext, \ENT_QUOTES); + $hometext = \htmlspecialchars($this->hometext, \ENT_QUOTES | ENT_HTML5); break; case 'Preview': $hometext = $myts->previewTarea($this->hometext, $html, $smiley, $xcodes); break; case 'InForm': - $hometext = \htmlspecialchars($this->hometext, \ENT_QUOTES); + $hometext = \htmlspecialchars($this->hometext, \ENT_QUOTES | ENT_HTML5); break; } @@ -505,13 +507,13 @@ public function bodytext(string $format = 'Show'): string $bodytext = $myts->displayTarea($this->bodytext, $html, $smiley, $xcodes); break; case 'Edit': - $bodytext = \htmlspecialchars($this->bodytext, \ENT_QUOTES); + $bodytext = \htmlspecialchars($this->bodytext, \ENT_QUOTES | ENT_HTML5); break; case 'Preview': $bodytext = $myts->previewTarea($this->bodytext, $html, $smiley, $xcodes); break; case 'InForm': - $bodytext = \htmlspecialchars($this->bodytext, \ENT_QUOTES); + $bodytext = \htmlspecialchars($this->bodytext, \ENT_QUOTES | ENT_HTML5); break; } diff --git a/class/XoopsTopic.php b/class/XoopsTopic.php index 5c75ee3..61d14aa 100644 --- a/class/XoopsTopic.php +++ b/class/XoopsTopic.php @@ -97,7 +97,8 @@ public function getTopic($topicid): void { $topicid = (int)$topicid; $sql = 'SELECT * FROM ' . $this->table . ' WHERE topic_id=' . $topicid; - $array = $this->db->fetchArray($this->db->query($sql)); + $result = Utility::queryAndCheck($this->db, $sql); + $array = $this->db->fetchArray($result); $this->makeTopic($array); } @@ -144,7 +145,7 @@ public function store(): bool $sql = \sprintf("UPDATE `%s` SET topic_pid = %u, topic_imgurl = '%s', topic_title = '%s' WHERE topic_id = %u", $this->table, $this->topic_pid, $imgurl, $title, $this->topic_id); } if (!$result = $this->db->query($sql)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); + \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), \E_USER_ERROR); } if ($this->use_permission) { if (empty($this->topic_id)) { @@ -390,7 +391,7 @@ public function getAllChildTopicsId(): array public function getTopicsList(): array { $ret = []; - $result = $this->db->query('SELECT topic_id, topic_pid, topic_title FROM ' . $this->table); + $result = Utility::queryAndCheck($this->db, 'SELECT topic_id, topic_pid, topic_title FROM ' . $this->table); if ($result) { $myts = \MyTextSanitizer::getInstance(); while (false !== ($myrow = $this->db->fetchArray($result))) { @@ -413,10 +414,7 @@ public function getTopicsList(): array public function topicExists($pid, $title): bool { $sql = 'SELECT COUNT(*) FROM ' . $this->table . ' WHERE topic_pid = ' . (int)$pid . " AND topic_title = '" . \trim($title) . "'"; - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($this->db, $sql); [$count] = $this->db->fetchRow($result); if ($count > 0) { return true; diff --git a/class/XoopsTree.php b/class/XoopsTree.php index fc65df9..8496f00 100644 --- a/class/XoopsTree.php +++ b/class/XoopsTree.php @@ -27,11 +27,11 @@ */ class XoopsTree { - public $table; //table with parent-child structure - public $id; //name of unique id for records in table $table - public $pid; // name of parent id used in table $table - public $order; //specifies the order of query results - public $title; // name of a field in table $table which will be used when selection box and paths are generated + public $table; //table with parent-child structure + public $id; //name of unique id for records in table $table + public $pid; // name of parent id used in table $table + public $order; //specifies the order of query results + public $title; // name of a field in table $table which will be used when selection box and paths are generated public \XoopsDatabase $db; //constructor of class XoopsTree //sets the names of table, unique id, and parend id @@ -68,7 +68,7 @@ public function getFirstChild($sel_id, string $order = ''): array if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); + $result = Utility::queryAndCheck($this->db, $sql); if ($this->db->isResultSet($result)) { while (false !== ($myrow = $this->db->fetchArray($result))) { $arr[] = $myrow; @@ -89,11 +89,8 @@ public function getFirstChildId($sel_id): array { $sel_id = (int)$sel_id; $idarray = []; - $sql = 'SELECT ' . $this->id . ' FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $sel_id; - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } + $sql = 'SELECT ' . $this->id . ' FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $sel_id; + $result = Utility::queryAndCheck($this->db, $sql); $count = $this->db->getRowsNum($result); if (0 == $count) { return $idarray; @@ -121,10 +118,7 @@ public function getAllChildId($sel_id, string $order = '', array $idarray = []): if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($this->db, $sql); $count = $this->db->getRowsNum($result); if (0 == $count) { return $idarray; @@ -153,10 +147,7 @@ public function getAllParentId($sel_id, string $order = '', array $idarray = []) if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($this->db, $sql); [$r_id] = $this->db->fetchRow($result); if (0 == $r_id) { return $idarray; @@ -180,11 +171,8 @@ public function getAllParentId($sel_id, string $order = '', array $idarray = []) public function getPathFromId($sel_id, string $title, string $path = ''): string { $sel_id = (int)$sel_id; - $sql= 'SELECT ' . $this->pid . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } + $sql = 'SELECT ' . $this->pid . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; + $result = Utility::queryAndCheck($this->db, $sql); if (0 == $this->db->getRowsNum($result)) { return $path; } @@ -227,10 +215,7 @@ public function makeMySelBox($title, string $order = '', int $preset_id = 0, int if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($this->db, $sql); if ($none) { echo "\n"; } @@ -270,10 +255,7 @@ public function getNicePathFromId($sel_id, string $title, string $funcURL, strin $path = !empty($path) ? ' : ' . $path : $path; $sel_id = (int)$sel_id; $sql = 'SELECT ' . $this->pid . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($this->db, $sql); if (0 == $this->db->getRowsNum($result)) { return $path; } @@ -301,11 +283,8 @@ public function getNicePathFromId($sel_id, string $title, string $funcURL, strin public function getIdPathFromId($sel_id, string $path = ''): string { $sel_id = (int)$sel_id; - $sql = 'SELECT ' . $this->pid . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } + $sql = 'SELECT ' . $this->pid . ' FROM ' . $this->table . ' WHERE ' . $this->id . "=$sel_id"; + $result = Utility::queryAndCheck($this->db, $sql); if (0 == $this->db->getRowsNum($result)) { return $path; } @@ -335,11 +314,8 @@ public function getAllChild($sel_id = 0, $order = '', $parray = []) if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } - $count = $this->db->getRowsNum($result); + $result = Utility::queryAndCheck($this->db, $sql); + $count = $this->db->getRowsNum($result); if (0 == $count) { return $parray; } @@ -368,11 +344,8 @@ public function getChildTreeArray($sel_id = 0, $order = '', $parray = [], $r_pre if ('' !== $order) { $sql .= " ORDER BY $order"; } - $result = $this->db->query($sql); - if (!$this->db->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); - } - $count = $this->db->getRowsNum($result); + $result = Utility::queryAndCheck($this->db, $sql); + $count = $this->db->getRowsNum($result); if (0 == $count) { return $parray; } diff --git a/class/plugins/plugin.tag.php b/class/plugins/plugin.tag.php index 8e44d41..ab4c019 100644 --- a/class/plugins/plugin.tag.php +++ b/class/plugins/plugin.tag.php @@ -79,7 +79,7 @@ function news_tag_synchronization($mid): void $where = "($itemHandler_table.published > 0 AND $itemHandler_table.published <= " . \time() . ") AND ($itemHandler_table.expired = 0 OR $itemHandler_table.expired > " . \time() . ')'; /* clear tag-item links */ - if (version_compare($xoopsDB->getServerVersion(), '4.1.0', 'ge')) : + if ($module->versionCompare($xoopsDB->getServerVersion(), '4.1.0', 'ge')) : $sql = " DELETE FROM {$linkHandler->table}" . ' WHERE ' . " tag_modid = {$mid}" diff --git a/config/config.php b/config/config.php index 330a69e..2f09702 100644 --- a/config/config.php +++ b/config/config.php @@ -32,14 +32,14 @@ ], 'uploadFolders' => [ XOOPS_UPLOAD_PATH . '/' . $moduleDirName, - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/category', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/screenshots', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/file', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/image', //XOOPS_UPLOAD_PATH . '/flags' ], 'copyBlankFiles' => [ XOOPS_UPLOAD_PATH . '/' . $moduleDirName, - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/category', - XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/screenshots', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/file', + XOOPS_UPLOAD_PATH . '/' . $moduleDirName . '/image', //XOOPS_UPLOAD_PATH . '/flags' ], diff --git a/docs/changelog.txt b/docs/changelog.txt index 3c717ac..d2a2388 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,3 +1,8 @@ +
      1.73.0 Beta 2 [2024-08-10]
      Dev: XOOPS 2.5.11, PHP 7.4.33, PHP 8.2.5 +
      +- PHP 8 and Smarty 4 updates (mamba) +- various code cosmetics (mamba) +
      1.73.0 Beta 1 [2023-04-20]
      Dev: XOOPS 2.5.11, PHP 7.4.33, PHP 8.2.5
      - PHP 8 and Smarty 3 updates (mamba) @@ -299,10 +304,10 @@ tables. This will optimize, check and analyze the tables in the database. - I have added a new option to activate Dublin Core Metadata in the article's page. For more explanations, see http://dublincore.org/ - Dublin Core Metadata are, as the name state, a set of meta datas used to + Dublin Core Metadata are, as the name state, a set of metadatas used to describe your documents. If you are a Firefox user, you can use this extension to visualize the Dublin - Meta Datas : + Metadata : https://addons.mozilla.org/firefox/528/ - You can display a "Bookmark this article at these sites" on the article's page To see an example, look at the bottom of this article : @@ -310,7 +315,7 @@ - You can use Firefox 2 Micro summaries : http://wiki.mozilla.org/Microsummaries If someone bookmarks your page with Firefox 2 they can choose to see the last title of your last news instead of the current page's title. - The News module modifies the meta datas of all its page to include a line + The News module modifies the metadatas of all its page to include a line like this one : but you can also add it in your theme so that when someone bookmark your site diff --git a/header.php b/header.php index 2bde8fe..3fb0bcd 100644 --- a/header.php +++ b/header.php @@ -14,4 +14,30 @@ * @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} * @author XOOPS Development Team */ + +use XoopsModules\News\{ + Helper +}; + require_once \dirname(__DIR__, 2) . '/mainfile.php'; +require XOOPS_ROOT_PATH . '/header.php'; + +require __DIR__ . '/preloads/autoloader.php'; + +$moduleDirName = basename(__DIR__); + +$helper = Helper::getInstance(); +// Load language files +$helper->loadLanguage('main'); + +$myts = \MyTextSanitizer::getInstance(); + +if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { + require $GLOBALS['xoops']->path('class/theme.php'); + $GLOBALS['xoTheme'] = new \xos_opal_Theme(); +} + +if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof XoopsTpl)) { + require $GLOBALS['xoops']->path('class/template.php'); + $xoopsTpl = new XoopsTpl(); +} diff --git a/include/functions.php b/include/functions.php index 7a7a057..8feaf19 100644 --- a/include/functions.php +++ b/include/functions.php @@ -86,17 +86,14 @@ function news_updaterating($storyid): void { global $xoopsDB; $sql = 'SELECT rating FROM ' . $xoopsDB->prefix('news_stories_votedata') . ' WHERE storyid = ' . $storyid; - $result = $xoopsDB->query($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($xoopsDB, $sql); $votesDB = $xoopsDB->getRowsNum($result); $totalrating = 0; while ([$rating] = $xoopsDB->fetchRow($result)) { $totalrating += $rating; } $finalrating = $totalrating / $votesDB; - $finalrating = number_format($finalrating, 4); + $finalrating =number_format((float)$finalrating, 4); $sql = sprintf('UPDATE `%s` SET rating = %u, votes = %u WHERE storyid = %u', $xoopsDB->prefix('news_stories'), $finalrating, $votesDB, $storyid); $xoopsDB->queryF($sql); } @@ -282,7 +279,7 @@ function DublinQuotes($text) } /** - * Creates all the meta datas : + * Creates all the metadatas : * - For Mozilla/Netscape and Opera the site navigation's bar * - The Dublin's Core Metadata * - The link for Firefox 2 micro summaries @@ -349,7 +346,7 @@ function news_CreateMetaDatas($story = null): void } /** - * Dublin Core's meta datas + * Dublin Core's metadatas */ if (news_getmoduleoption('dublincore') && isset($story) && is_object($story)) { /** @var \XoopsConfigHandler $configHandler */ @@ -570,10 +567,7 @@ function news_TableExists($tablename): bool global $xoopsDB; $sql = "SHOW TABLES LIKE '$tablename'"; - $result = $xoopsDB->queryF($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } + $result = Utility::queryFAndCheck($xoopsDB, $sql); return ($xoopsDB->getRowsNum($result) > 0); } @@ -591,10 +585,7 @@ function news_FieldExists($fieldname, $table): bool { global $xoopsDB; $sql = "SHOW COLUMNS FROM $table LIKE '$fieldname'"; - $result = $xoopsDB->queryF($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } + $result = Utility::queryFAndCheck($xoopsDB, $sql); return ($xoopsDB->getRowsNum($result) > 0); } @@ -752,7 +743,7 @@ function news_truncate_tagsafe($string, $length = 80, $etc = '...', $break_words return ''; } if (mb_strlen($string) > $length) { - $length -= mb_strlen($etc); + $length -= \mb_strlen($etc); if (!$break_words) { $string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1)); $string = preg_replace('/<[^>]*$/', '', $string); diff --git a/include/install_function.php b/include/install_function.php index 56f50fd..2bb7ec0 100644 --- a/include/install_function.php +++ b/include/install_function.php @@ -73,20 +73,20 @@ function xoops_module_install_news(\XoopsModule $module): bool // mkdir($dir, 0777); // } - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } chmod($dir, 0777); $dir = XOOPS_ROOT_PATH . '/uploads/news/file'; - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } chmod($dir, 0777); $dir = XOOPS_ROOT_PATH . '/uploads/news/image'; - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } chmod($dir, 0777); diff --git a/include/onuninstall.php b/include/onuninstall.php index e7c1a77..91bc396 100644 --- a/include/onuninstall.php +++ b/include/onuninstall.php @@ -65,7 +65,7 @@ function xoops_module_uninstall_news(\XoopsModule $module): bool // Remove xsitemap.xml from XOOPS root folder if it exists //------------------------------------------------------------------ $xmlfile = $GLOBALS['xoops']->path('xsitemap.xml'); - if (is_file($xmlfile)) { + if (\is_file($xmlfile)) { if (false === ($delOk = unlink($xmlfile))) { $module->setErrors(sprintf(_AM_XXXXX_ERROR_BAD_REMOVE, $xmlfile)); } diff --git a/include/onupdate.php b/include/onupdate.php index d4f3384..c295c92 100644 --- a/include/onupdate.php +++ b/include/onupdate.php @@ -216,7 +216,7 @@ function xoops_module_update_news(\XoopsModule $module, $previousVersion = null) // 6) Make files and folders $dir = XOOPS_ROOT_PATH . '/uploads/news'; - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } if (!is_writable($dir)) { @@ -224,7 +224,7 @@ function xoops_module_update_news(\XoopsModule $module, $previousVersion = null) } $dir = XOOPS_ROOT_PATH . '/uploads/news/file'; - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } if (!is_writable($dir)) { @@ -232,7 +232,7 @@ function xoops_module_update_news(\XoopsModule $module, $previousVersion = null) } $dir = XOOPS_ROOT_PATH . '/uploads/news/image'; - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } if (!is_writable($dir)) { @@ -246,7 +246,7 @@ function xoops_module_update_news(\XoopsModule $module, $previousVersion = null) copy($indexFile, XOOPS_ROOT_PATH . '/uploads/news/image/index.php'); } - $module = $helper->getModule(); +// $module = $helper->getModule(); // if (true === $module->versionCompare($previousVersion, $module->getInfo('version'))) { //delete old HTML templates @@ -258,7 +258,7 @@ function xoops_module_update_news(\XoopsModule $module, $previousVersion = null) foreach ($templateList as $k => $v) { $fileInfo = new \SplFileInfo($templateFolder . $v); if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { - if (is_file($templateFolder . $v)) { + if (\is_file($templateFolder . $v)) { unlink($templateFolder . $v); } } @@ -272,7 +272,7 @@ function xoops_module_update_news(\XoopsModule $module, $previousVersion = null) // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { foreach (array_keys($configurator->oldFiles) as $i) { $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); - if (is_file($tempFile)) { + if (\is_file($tempFile)) { unlink($tempFile); } } diff --git a/include/search.inc.php b/include/search.inc.php index 97dbf30..b172ff1 100644 --- a/include/search.inc.php +++ b/include/search.inc.php @@ -98,7 +98,7 @@ function news_search($queryarray, $andor, $limit, $offset, $userid): array $searchincomments = $cfg['config_search_comments']; if ($searchincomments && (isset($limit) && $i <= $limit)) { - require XOOPS_ROOT_PATH . '/include/comment_constants.php'; + require_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $ind = $i; $sql = 'SELECT com_id, com_modid, com_itemid, com_created, com_uid, com_title, com_text, com_status FROM ' . $xoopsDB->prefix('xoopscomments') . " WHERE (com_id>0) AND (com_modid=$modid) AND (com_status=" . XOOPS_COMMENT_ACTIVE . ') '; if (0 != $userid) { diff --git a/include/update_function.php b/include/update_function.php index 5b58fb3..0bed051 100644 --- a/include/update_function.php +++ b/include/update_function.php @@ -172,7 +172,7 @@ function xoops_module_update_news(): bool // 6) Make files and folders $dir = XOOPS_ROOT_PATH . '/uploads/news'; - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } if (!is_writable($dir)) { @@ -180,7 +180,7 @@ function xoops_module_update_news(): bool } $dir = XOOPS_ROOT_PATH . '/uploads/news/file'; - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } if (!is_writable($dir)) { @@ -188,7 +188,7 @@ function xoops_module_update_news(): bool } $dir = XOOPS_ROOT_PATH . '/uploads/news/image'; - if (!@mkdir($dir) && !is_dir($dir)) { + if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException('The directory ' . $dir . ' could not be created.'); } if (!is_writable($dir)) { diff --git a/index.php b/index.php index a4004f9..31e258a 100644 --- a/index.php +++ b/index.php @@ -309,7 +309,7 @@ $xoopsTpl->assign('advertisement', Utility::getModuleOption('advertisement')); /** - * Create the Meta Datas + * Create the Metadata */ Utility::createMetaDatas(); diff --git a/makepdf.php b/makepdf.php index 08adad2..b84d873 100644 --- a/makepdf.php +++ b/makepdf.php @@ -31,7 +31,7 @@ //2.5.8 $helper = Helper::getInstance(); -if (is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) { +if (\is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) { require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php'; } else { redirect_header($helper->url('index.php'), 3, \constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR_NO_PDF')); diff --git a/preloads/autoloader.php b/preloads/autoloader.php index f8de47d..2b465e9 100644 --- a/preloads/autoloader.php +++ b/preloads/autoloader.php @@ -6,13 +6,13 @@ spl_autoload_register( static function ($class): void { // project-specific namespace prefix - $prefix = 'XoopsModules\\' . ucfirst(basename(dirname(__DIR__))); + $prefix = 'XoopsModules\\' . \ucfirst(\basename(\dirname(__DIR__))); // base directory for the namespace prefix $baseDir = \dirname(__DIR__) . '/class/'; // does the class use the namespace prefix? - $len = mb_strlen($prefix); + $len = \mb_strlen($prefix); if (0 !== strncmp($prefix, $class, $len)) { return; @@ -24,10 +24,10 @@ static function ($class): void { // replace the namespace prefix with the base directory, replace namespace // separators with directory separators in the relative class name, append // with .php - $file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php'; + $file = $baseDir . \str_replace('\\', '/', $relativeClass) . '.php'; // if the file exists, require it - if (is_file($file)) { + if (\is_file($file)) { require_once $file; } } diff --git a/print.php b/print.php index f082903..8f9e7ff 100644 --- a/print.php +++ b/print.php @@ -274,7 +274,7 @@ function lastChildContainingText() { } echo '
      <' . $counter . '


      '; - printf(_NW_THISCOMESFROM, htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)); + printf(_NW_THISCOMESFROM, htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES | ENT_HTML5)); echo '
      ' . XOOPS_URL . '

      ' . _NW_URLFORSTORY . '
      ' . XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid() . ' diff --git a/ratenews.php b/ratenews.php index 7790f8f..cca8b9d 100644 --- a/ratenews.php +++ b/ratenews.php @@ -140,10 +140,7 @@ // Check if News POSTER is voting (UNLESS Anonymous users allowed to post) if (0 != $ratinguser) { $sql = 'SELECT uid FROM ' . $xoopsDB->prefix('news_stories') . " WHERE storyid=$storyid"; - $result = $xoopsDB->query($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($xoopsDB, $sql); while ([$ratinguserDB] = $xoopsDB->fetchRow($result)) { if ($ratinguserDB == $ratinguser) { redirect_header(XOOPS_URL . '/modules/news/article.php?storyid=' . $storyid, 4, _NW_CANTVOTEOWN); @@ -152,10 +149,7 @@ // Check if REG user is trying to vote twice. $sql = 'SELECT ratinguser FROM ' . $xoopsDB->prefix('news_stories_votedata') . " WHERE storyid=$storyid"; - $result = $xoopsDB->query($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($xoopsDB, $sql); while ([$ratinguserDB] = $xoopsDB->fetchRow($result)) { if ($ratinguserDB == $ratinguser) { redirect_header(XOOPS_URL . '/modules/news/article.php?storyid=' . $storyid, 4, _NW_VOTEONCE); @@ -163,12 +157,15 @@ } } else { // Check if ANONYMOUS user is trying to vote more than once per day. - $yesterday = (time() - (86400 * $anonwaitdays)); +// $yesterday = (time() - (86400 * $anonwaitdays)); + $date = new \DateTime(); + $date->sub(new \DateInterval("P{$anonwaitdays}D")); + $yesterday = $date->getTimestamp(); + + + $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('news_stories_votedata') . " WHERE storyid=$storyid AND ratinguser=0 AND ratinghostname = '$ip' AND ratingtimestamp > $yesterday"; - $result = $xoopsDB->query($sql); - if (!$xoopsDB->isResultSet($result)) { - \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); - } + $result = Utility::queryAndCheck($xoopsDB, $sql); [$anonvotecount] = $xoopsDB->fetchRow($result); if ($anonvotecount >= 1) { redirect_header(XOOPS_URL . '/modules/news/article.php?storyid=' . $storyid, 4, _NW_VOTEONCE); diff --git a/submit.php b/submit.php index c298cf8..b5a9e9c 100644 --- a/submit.php +++ b/submit.php @@ -428,7 +428,7 @@ $currentPicture = $story->picture(); if ('' !== xoops_trim($currentPicture)) { $currentPicture = XOOPS_ROOT_PATH . '/uploads/news/image/' . xoops_trim($story->picture()); - if (is_file($currentPicture) && file_exists($currentPicture)) { + if (\is_file($currentPicture) && file_exists($currentPicture)) { if (!unlink($currentPicture)) { trigger_error('Error, impossible to delete the picture attached to this article'); } diff --git a/templates/blocks/news_block_moderate.tpl b/templates/blocks/news_block_moderate.tpl index a74dae2..ecdfbf5 100644 --- a/templates/blocks/news_block_moderate.tpl +++ b/templates/blocks/news_block_moderate.tpl @@ -6,7 +6,7 @@ <{$block.lang_story_author}> <{$block.lang_story_action}> - <{foreach item=news from=$block.stories}> + <{foreach item=news from=$block.stories|default:null}> "> <{$news.title}> <{$news.topic_title}> diff --git a/templates/blocks/news_block_randomnews.tpl b/templates/blocks/news_block_randomnews.tpl index 5f55148..1124734 100644 --- a/templates/blocks/news_block_randomnews.tpl +++ b/templates/blocks/news_block_randomnews.tpl @@ -1,5 +1,5 @@
      - <{foreach item=news from=$block.stories}> + <{foreach item=news from=$block.stories|default:null}>

      diff --git a/templates/blocks/news_block_top.tpl b/templates/blocks/news_block_top.tpl index a5ee076..10151ad 100644 --- a/templates/blocks/news_block_top.tpl +++ b/templates/blocks/news_block_top.tpl @@ -879,7 +879,7 @@ <{* ************************************** Tabs creation ************************************** *}>
        - <{foreach item=onetab from=$block.tabs}> + <{foreach item=onetab from=$block.tabs|default:null}> <{if $block.current_tab == $onetab.id}>
      • <{$onetab.title}>
      • <{else}> @@ -893,7 +893,7 @@ , <{$block.spotlight.hits}> <{$block.lang_reads}>

      <{else}>
      - <{foreach item=onesummary from=$block.smallheader}> + <{foreach item=onesummary from=$block.smallheader|default:null}> <{$onesummary}>  <{/foreach}>
      @@ -918,7 +918,7 @@ - <{$block.spotlight.image}>  + <{$block.spotlight.image|default:''}> 

      <{$block.spotlight.text}>

      @@ -927,7 +927,7 @@
        - <{foreach item=onenews from=$block.spotlight.news}> + <{foreach item=onenews from=$block.spotlight.news|default:null}>
      • <{$onenews.date}> - <{$onenews.title_with_link}>
      • <{/foreach}>
      @@ -938,7 +938,7 @@ <{$block.topic_description}> - <{foreach item=onenews from=$block.news}> + <{foreach item=onenews from=$block.news|default:null}>
      • <{$onenews.title}>
      • @@ -976,7 +976,7 @@ - <{$block.spotlight.image}> + <{$block.spotlight.image|default:''}> <{$block.spotlight.text}> @@ -997,7 +997,7 @@ - <{foreach item=news from=$block.stories}> + <{foreach item=news from=$block.stories|default:null}> <{if $news.id != $block.spotlight.id|default:''}>

        diff --git a/templates/news_archive.tpl b/templates/news_archive.tpl index e47d5de..54c0e35 100644 --- a/templates/news_archive.tpl +++ b/templates/news_archive.tpl @@ -3,8 +3,8 @@ <{$lang_newsarchives}> - <{foreach item=year from=$years}> - <{foreach item=month from=$year.months}> + <{foreach item=year from=$years|default:null}> + <{foreach item=month from=$year.months|default:null}> <{$lang_views}> <{$lang_date}> - <{foreach item=story from=$stories}> + <{foreach item=story from=$stories|default:null}> "> <{$story.title}> <{include file="db:news_item.tpl" story=$story}> - <{if $xoops_isadmin}> + <{if isset($xoops_isadmin)}> 0}>
        <{$lang_attached_files}> - <{foreach item=onefile from=$attached_files}> + <{foreach item=onefile from=$attached_files|default:null}> <{$onefile.file_realname}>   <{/foreach}> @@ -37,16 +37,16 @@ <{if $pagenav|default:''}> <{/if}> - <{if $tags}> + <{if isset($tags) && $tags == true}>
        <{include file="db:tag_bar.tpl"}>
        <{/if}>
        - <{if $nav_links}> - <{if $previous_story_id != -1}> + <{if isset($previous_story_id) && $previous_story_id != -1}><{$lang_previous_story}> - <{/if}> - <{if $next_story_id!= -1}><{$lang_next_story}><{/if}> <{/if}> @@ -58,7 +58,7 @@ <{$lang_other_story}> - <{foreach item=onesummary from=$summary}> + <{foreach item=onesummary from=$summary|default:null}> "> <{$onesummary.story_published}> - ><{$onesummary.story_title}> diff --git a/templates/news_by_this_author.tpl b/templates/news_by_this_author.tpl index 9f63676..ba7ae6b 100644 --- a/templates/news_by_this_author.tpl +++ b/templates/news_by_this_author.tpl @@ -3,32 +3,32 @@

        - <{foreach item=topic from=$topics}> + <{foreach item=topic from=$topics|default:null}> - <{if $news_rating}> + <{if isset($news_rating)}> - <{if $news_rating}> + <{if isset($news_rating)}> <{/if}> - <{foreach item=article from=$topic.news}> + <{foreach item=article from=$topic.news|default:null}> - <{if $news_rating}> + <{if isset($news_rating)}> <{/if}> <{/foreach}> - <{if $news_rating}> + <{if isset($news_rating)}> <{/if}> - <{if $news_rating}> + <{if isset($news_rating)}> diff --git a/templates/news_by_topic.tpl b/templates/news_by_topic.tpl index 2bd3e93..78ef77c 100644 --- a/templates/news_by_topic.tpl +++ b/templates/news_by_topic.tpl @@ -3,13 +3,13 @@ <{section name=i loop=$columns}>
        <{else}> <{/if}><{$topic.topic_link}>
        <{$lang_date}> <{$lang_title}><{$lang_hits}><{$lang_hits}><{$lang_rating}>
        <{$article.published}> <{$article.article_link}><{$article.hits}><{$article.hits}><{$article.rating}>
        <{$topic.topic_count_articles}><{$topic.topic_count_reads}><{$topic.topic_count_reads}> 
        <{else}> <{/if}> 
        - <{foreach item=topic from=$columns[i]}> + <{foreach item=topic from=$columns[i]|default:null}>
        <{counter start=0 print=false assign=storynum}> - <{foreach item=story from=$topic.stories}> + <{foreach item=story from=$topic.stories|default:null}> <{if $storynum == 0}> <{include file="db:news_item.tpl" story=$story}>
        <{else}> diff --git a/templates/news_index.tpl b/templates/news_index.tpl index aad1533..bf55d5e 100644 --- a/templates/news_index.tpl +++ b/templates/news_index.tpl @@ -20,7 +20,7 @@ <{section name=i loop=$columns}> - + <{/section}>
        <{foreach item=story from=$columns[i]}><{include file="db:news_item.tpl" story=$story}><{/foreach}><{foreach item=story from=$columns[i]|default:null}><{include file="db:news_item.tpl" story=$story}><{/foreach}>
        diff --git a/templates/news_item.tpl b/templates/news_item.tpl index edfaf10..692d13e 100644 --- a/templates/news_item.tpl +++ b/templates/news_item.tpl @@ -1,7 +1,8 @@
        - <{if $displaytopictitle === true}> <{$story.topic_title}> -   <{/if}>

        <{$story.news_title}>

        + <{if $displaytopictitle === true}> <{$story.topic_title}> <{/if}> +

        <{$story.news_title}>

        <{$story.subtitle|default:''}>
        @@ -25,10 +26,10 @@
        <{$story.adminlink}> - <{if $rates}><{$lang_ratingc}> <{$story.rating}> (<{$story.votes}>) - - <{$lang_ratethisnews}> - - <{/if}> + <{if isset($rates)}><{$lang_ratingc|default:''}> <{$story.rating|default:''}> <{$story.votes|default:''}> + <{$lang_ratethisnews|default:''}> + <{/if}> <{$story.morelink}>
        diff --git a/templates/news_ratenews.tpl b/templates/news_ratenews.tpl index faed7cb..53e2bb2 100644 --- a/templates/news_ratenews.tpl +++ b/templates/news_ratenews.tpl @@ -11,7 +11,7 @@
        - <{securityToken}><{*//mb*}> + <{securityToken}>