XoopsModules25x /
news
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php declare(strict_types=1); |
||||||
| 2 | /* |
||||||
| 3 | * You may not change or alter any portion of this comment or credits |
||||||
| 4 | * of supporting developers from this source code or any supporting source code |
||||||
| 5 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||||||
| 6 | * |
||||||
| 7 | * This program is distributed in the hope that it will be useful, |
||||||
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
| 10 | */ |
||||||
| 11 | |||||||
| 12 | /** |
||||||
| 13 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||||||
| 14 | * @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
||||||
| 15 | * @author XOOPS Development Team |
||||||
| 16 | */ |
||||||
| 17 | |||||||
| 18 | /** |
||||||
| 19 | * AMS Import |
||||||
| 20 | * |
||||||
| 21 | * This script will import topics, articles, files, links, ratings, comments and notifications from AMS 2.41 |
||||||
| 22 | * |
||||||
| 23 | * @author Hervé Thouzard (https://www.herve-thouzard.com) |
||||||
| 24 | * @copyright 2005, 2006 - Hervé Thouzard |
||||||
| 25 | */ |
||||||
| 26 | |||||||
| 27 | use XoopsModules\Ams; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 28 | use XoopsModules\Ams\Helper as AmsHelper; |
||||||
|
0 ignored issues
–
show
The type
XoopsModules\Ams\Helper was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 29 | use XoopsModules\News\Files; |
||||||
| 30 | use XoopsModules\News\NewsStory; |
||||||
| 31 | use XoopsModules\News\NewsTopic; |
||||||
| 32 | |||||||
| 33 | require \dirname(__DIR__, 3) . '/include/cp_header.php'; |
||||||
| 34 | xoops_cp_header(); |
||||||
| 35 | |||||||
| 36 | //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
||||||
| 37 | //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php'; |
||||||
| 38 | //require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php'; |
||||||
| 39 | require_once XOOPS_ROOT_PATH . '/class/xoopstree.php'; |
||||||
| 40 | |||||||
| 41 | if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) { |
||||||
| 42 | if (!isset($_POST['go'])) { |
||||||
| 43 | echo '<h1>Welcome to the AMS 2.41 import script</h1>'; |
||||||
| 44 | echo '<br><br>Select the import options you wan to use :'; |
||||||
| 45 | echo "<form method='post' action='amsimport.php'>"; |
||||||
| 46 | echo "<br><input type='checkbox' name='useforum' value='1'> Import forums links inside news (at the bottom of the news)"; |
||||||
| 47 | echo "<br><input type='checkbox' name='useextlinks' value='1'> Import external links inside news (at the bottom of the news)"; |
||||||
| 48 | echo "<br><br><input type='submit' name='go' value='Import'>"; |
||||||
| 49 | echo '</form>'; |
||||||
| 50 | echo "<br><br>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."; |
||||||
| 51 | } else { |
||||||
| 52 | // Launch the import |
||||||
| 53 | /** @var \XoopsModules\Ams\Helper $amsHelper */ |
||||||
| 54 | $amsHelper = AmsHelper::getInstance(); |
||||||
| 55 | $amsHelper->loadLanguage('admin'); |
||||||
| 56 | $amsHelper->loadLanguage('main'); |
||||||
| 57 | |||||||
| 58 | /** @var \XoopsMySQLDatabase $db */ |
||||||
| 59 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||||||
| 60 | // User's choices |
||||||
| 61 | $use_forum = (isset($_POST['useforum']) && 1 == $_POST['useforum']) ? 1 : 0; |
||||||
| 62 | $use_extlinks = (isset($_POST['useextlinks']) && 1 == $_POST['useextlinks']) ? 1 : 0; |
||||||
| 63 | // Retrieve News module's ID |
||||||
| 64 | /** @var \XoopsModuleHandler $moduleHandler */ |
||||||
| 65 | $moduleHandler = xoops_getHandler('module'); |
||||||
| 66 | $newsModule = $moduleHandler->getByDirname('news'); |
||||||
| 67 | $news_mid = $newsModule->getVar('mid'); |
||||||
| 68 | // Retrieve AMS module's ID |
||||||
| 69 | $AmsModule = $moduleHandler->getByDirname('AMS'); |
||||||
| 70 | $ams_mid = $AmsModule->getVar('mid'); |
||||||
| 71 | |||||||
| 72 | // Retrieve AMS tables names |
||||||
| 73 | $ams_topics = $xoopsDB->prefix('ams_topics'); |
||||||
| 74 | $ams_articles = $xoopsDB->prefix('ams_article'); |
||||||
| 75 | $ams_text = $xoopsDB->prefix('ams_text'); |
||||||
| 76 | $ams_files = $xoopsDB->prefix('ams_files'); |
||||||
| 77 | $ams_links = $xoopsDB->prefix('ams_link'); |
||||||
| 78 | $ams_rating = $xoopsDB->prefix('ams_rating'); |
||||||
| 79 | // Retrieve News tables names |
||||||
| 80 | $news_stories_votedata = $xoopsDB->prefix('news_stories_votedata'); |
||||||
| 81 | // Misc |
||||||
| 82 | $commentHandler = xoops_getHandler('comment'); |
||||||
| 83 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||||||
| 84 | $notificationHandler = xoops_getHandler('notification'); |
||||||
| 85 | $ams_news_topics = []; // Key => AMS Id, Value => News ID |
||||||
| 86 | |||||||
| 87 | // The import by itself |
||||||
| 88 | // Read topics by their order |
||||||
| 89 | $mytree = new \XoopsTree($ams_topics, 'topic_id', 'topic_pid'); |
||||||
| 90 | $ams_topics = $mytree->getChildTreeArray(0, 'weight'); |
||||||
| 91 | foreach ($ams_topics as $one_amstopic) { |
||||||
| 92 | // First we create the topic |
||||||
| 93 | $topicpid = 0; |
||||||
| 94 | if (0 != $one_amstopic['topic_pid']) { // Search for its the parent |
||||||
| 95 | if (array_key_exists($one_amstopic['topic_pid'], $ams_news_topics)) { |
||||||
| 96 | $topicpid = $ams_news_topics[$one_amstopic['topic_pid']]; |
||||||
| 97 | } |
||||||
| 98 | } |
||||||
| 99 | $news_topic = new NewsTopic(); |
||||||
| 100 | $news_topic->setTopicPid($topicpid); |
||||||
| 101 | $news_topic->setTopicTitle($one_amstopic['topic_title']); |
||||||
| 102 | $news_topic->setTopicImgurl($one_amstopic['topic_imgurl']); |
||||||
| 103 | $news_topic->setMenu(0); |
||||||
| 104 | $news_topic->setTopicFrontpage(1); |
||||||
| 105 | $news_topic->setTopicRssUrl(''); |
||||||
| 106 | $news_topic->setTopicDescription(''); |
||||||
| 107 | $news_topic->setTopic_color('000000'); |
||||||
| 108 | $news_topic->store(); |
||||||
| 109 | echo '<br>- The following topic was imported : ' . $news_topic->topic_title(); |
||||||
| 110 | $ams_topicid = $one_amstopic['topic_id']; |
||||||
| 111 | $news_topicid = $news_topic->topic_id(); |
||||||
| 112 | $ams_news_topics[$ams_topicid] = $news_topicid; |
||||||
| 113 | |||||||
| 114 | // Then we insert all its articles |
||||||
| 115 | $sql = 'SELECT * FROM ' . $ams_articles . ' WHERE topicid=' . $ams_topicid . ' ORDER BY created'; |
||||||
| 116 | $result = $db->query($sql); |
||||||
| 117 | |||||||
| 118 | if (!$db->isResultSet($result)) { |
||||||
| 119 | \trigger_error("Query Failed! SQL: $sql Error: " . $db->error(), \E_USER_ERROR); |
||||||
| 120 | } |
||||||
| 121 | |||||||
| 122 | while (false !== ($article = $db->fetchArray($result))) { |
||||||
|
0 ignored issues
–
show
It seems like
$result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 123 | $ams_newsid = $article['storyid']; |
||||||
| 124 | |||||||
| 125 | // We search for the last version |
||||||
| 126 | $result2 = $db->query('SELECT * FROM ' . $ams_text . ' WHERE storyid=' . $ams_newsid . ' AND current=1'); |
||||||
| 127 | $text_lastversion = $db->fetchArray($result2); |
||||||
| 128 | |||||||
| 129 | // We search for the number of votes |
||||||
| 130 | $result3 = $db->query('SELECT count(*) AS cpt FROM ' . $ams_rating . ' WHERE storyid=' . $ams_newsid); |
||||||
| 131 | $votes = $db->fetchArray($result3); |
||||||
| 132 | |||||||
| 133 | // The links |
||||||
| 134 | $links = ''; |
||||||
| 135 | if ($use_extlinks) { |
||||||
| 136 | $result7 = $db->query('SELECT * FROM ' . $ams_links . ' WHERE storyid=' . $ams_newsid . ' ORDER BY linkid'); |
||||||
| 137 | while (false !== ($link = $db->fetchArray($result7))) { |
||||||
| 138 | if ('' == trim($links)) { |
||||||
| 139 | $links = "\n\n" . _AMS_NW_RELATEDARTICLES . "\n\n"; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 140 | } |
||||||
| 141 | $links .= _AMS_NW_EXTERNALLINK . ' [url=' . $link['link_link'] . ']' . $link['link_title'] . '[/url]' . "\n"; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 142 | } |
||||||
| 143 | } |
||||||
| 144 | |||||||
| 145 | // The forum |
||||||
| 146 | $forum = ''; |
||||||
| 147 | if ($use_forum && 0 != $one_amstopic['forum_id']) { |
||||||
| 148 | $forum = "\n\n" . '[url=' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $one_amstopic['forum_id'] . ']' . _AMS_AM_LINKEDFORUM . '[/url]' . "\n"; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 149 | } |
||||||
| 150 | |||||||
| 151 | // We create the story |
||||||
| 152 | $news = new NewsStory(); |
||||||
| 153 | $news->setUid($text_lastversion['uid']); |
||||||
| 154 | $news->setTitle($article['title']); |
||||||
| 155 | $news->created = $article['created']; |
||||||
| 156 | $news->setPublished($article['published']); |
||||||
| 157 | $news->setExpired($article['expired']); |
||||||
| 158 | $news->setHostname($article['hostname']); |
||||||
| 159 | $news->setNohtml($article['nohtml']); |
||||||
| 160 | $news->setNosmiley($article['nosmiley']); |
||||||
| 161 | $news->setHometext($text_lastversion['hometext']); |
||||||
| 162 | $news->setBodytext($text_lastversion['bodytext'] . $links . $forum); |
||||||
| 163 | $news->setKeywords(''); |
||||||
| 164 | $news->setDescription(''); |
||||||
| 165 | $news->counter = $article['counter']; |
||||||
| 166 | $news->setTopicId($news_topicid); |
||||||
| 167 | $news->setIhome($article['ihome']); |
||||||
| 168 | $news->setNotifyPub($article['notifypub']); |
||||||
| 169 | $news->story_type = $article['story_type']; |
||||||
| 170 | $news->setTopicdisplay($article['topicdisplay']); |
||||||
| 171 | $news->setTopicalign($article['topicalign']); |
||||||
| 172 | $news->setComments($article['comments']); |
||||||
| 173 | $news->rating = $article['rating']; |
||||||
| 174 | $news->votes = $votes['cpt']; |
||||||
| 175 | $approved = $article['published'] > 0; |
||||||
| 176 | $news->approved = $approved; |
||||||
| 177 | $news->store($approved); |
||||||
| 178 | echo '<br> This story was imported : ' . $news->title(); |
||||||
| 179 | $news_newsid = $news->storyid(); // ******************** |
||||||
| 180 | |||||||
| 181 | // The files |
||||||
| 182 | $result4 = $db->query('SELECT * FROM ' . $ams_files . ' WHERE storyid=' . $ams_newsid); |
||||||
| 183 | while (false !== ($file = $db->fetchArray($result4))) { |
||||||
| 184 | $sfile = new Files(); |
||||||
| 185 | $sfile->setFileRealName($file['filerealname']); |
||||||
| 186 | $sfile->setStoryid($news_newsid); |
||||||
| 187 | $sfile->date = $file['date']; |
||||||
| 188 | $sfile->setMimetype($file['mimetype']); |
||||||
| 189 | $sfile->setDownloadname($file['downloadname']); |
||||||
| 190 | $sfile->counter = $file['counter']; |
||||||
| 191 | $sfile->store(); |
||||||
| 192 | echo '<br> This file was imported : ' . $sfile->getDownloadname(); |
||||||
| 193 | $news_fileid = $sfile->fileid; |
||||||
| 194 | } |
||||||
| 195 | |||||||
| 196 | // The ratings |
||||||
| 197 | $result5 = $db->query('SELECT * FROM ' . $ams_rating . ' WHERE storyid=' . $ams_newsid); |
||||||
| 198 | while (false !== ($ratings = $db->fetchArray($result5))) { |
||||||
| 199 | $result6 = $db->queryF( |
||||||
| 200 | 'INSERT INTO ' . $news_stories_votedata . ' (storyid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (' . $news_newsid . ',' . $ratings['ratinguser'] . ',' . $ratings['rating'] . ',' . $ratings['ratinghostname'] . ',' . $ratings['ratingtimestamp'] . ')' |
||||||
| 201 | ); |
||||||
| 202 | } |
||||||
| 203 | |||||||
| 204 | // The comments |
||||||
| 205 | $comments = $commentHandler->getByItemId($ams_mid, $ams_newsid, 'ASC'); |
||||||
|
0 ignored issues
–
show
The method
getByItemId() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsCommentHandler or XoopsNotificationHandler or XoopsPersistableObjectHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 206 | if ($comments && is_array($comments)) { |
||||||
| 207 | foreach ($comments as $onecomment) { |
||||||
| 208 | $onecomment->setNew(); |
||||||
| 209 | $onecomment->setVar('com_modid', $news_mid); |
||||||
| 210 | $onecomment->setVar('com_itemid', $news_newsid); |
||||||
| 211 | $commentHandler->insert($onecomment); |
||||||
| 212 | } |
||||||
| 213 | } |
||||||
| 214 | unset($comments); |
||||||
| 215 | |||||||
| 216 | // The notifications of this news |
||||||
| 217 | //$notifications =& $notificationHandler->getByItemId($ams_mid, $ams_newsid, 'ASC'); |
||||||
| 218 | $criteria = new \CriteriaCompo(new \Criteria('not_modid', $ams_mid)); |
||||||
|
0 ignored issues
–
show
It seems like
$ams_mid can also be of type array and array; however, parameter $value of Criteria::__construct() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 219 | $criteria->add(new \Criteria('not_itemid', $ams_newsid)); |
||||||
| 220 | $criteria->setOrder('ASC'); |
||||||
| 221 | $notifications = $notificationHandler->getObjects($criteria); |
||||||
| 222 | if ($notifications && is_array($notifications)) { |
||||||
| 223 | foreach ($notifications as $onenotification) { |
||||||
| 224 | $onenotification->setNew(); |
||||||
| 225 | $onenotification->setVar('not_modid', $news_mid); |
||||||
| 226 | $onenotification->setVar('not_itemid', $news_newsid); |
||||||
| 227 | $notificationHandler->insert($onenotification); |
||||||
| 228 | } |
||||||
| 229 | } |
||||||
| 230 | unset($notifications); |
||||||
| 231 | } |
||||||
| 232 | } |
||||||
| 233 | // Finally, import all the globals notifications |
||||||
| 234 | $criteria = new \CriteriaCompo(new \Criteria('not_modid', $ams_mid)); |
||||||
| 235 | $criteria->add(new \Criteria('not_category', 'global')); |
||||||
| 236 | $criteria->setOrder('ASC'); |
||||||
| 237 | $notifications = $notificationHandler->getObjects($criteria); |
||||||
| 238 | if ($notifications && is_array($notifications)) { |
||||||
| 239 | foreach ($notifications as $onenotification) { |
||||||
| 240 | $onenotification->setNew(); |
||||||
| 241 | $onenotification->setVar('not_modid', $news_mid); |
||||||
| 242 | $onenotification->setVar('not_itemid', $news_newsid); |
||||||
| 243 | $notificationHandler->insert($onenotification); |
||||||
| 244 | } |
||||||
| 245 | } |
||||||
| 246 | unset($notifications); |
||||||
| 247 | echo "<p><a href='" . XOOPS_URL . "/modules/news/admin/groupperms.php'>The import is finished, don't forget to verify and set the topics permissions !</a></p>"; |
||||||
| 248 | } |
||||||
| 249 | } else { |
||||||
| 250 | redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); |
||||||
| 251 | } |
||||||
| 252 | xoops_cp_footer(); |
||||||
| 253 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths