XoopsModules25x /
news
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | // |
||
| 3 | // ------------------------------------------------------------------------ // |
||
| 4 | // XOOPS - PHP Content Management System // |
||
| 5 | // Copyright (c) 2000-2016 XOOPS.org // |
||
| 6 | // <http://xoops.org/> // |
||
| 7 | // ------------------------------------------------------------------------ // |
||
| 8 | // This program is free software; you can redistribute it and/or modify // |
||
| 9 | // it under the terms of the GNU General Public License as published by // |
||
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
||
| 11 | // (at your option) any later version. // |
||
| 12 | // // |
||
| 13 | // You may not change or alter any portion of this comment or credits // |
||
| 14 | // of supporting developers from this source code or any supporting // |
||
| 15 | // source code which is considered copyrighted (c) material of the // |
||
| 16 | // original comment or credit authors. // |
||
| 17 | // // |
||
| 18 | // This program is distributed in the hope that it will be useful, // |
||
| 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
| 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
| 21 | // GNU General Public License for more details. // |
||
| 22 | // // |
||
| 23 | // You should have received a copy of the GNU General Public License // |
||
| 24 | // along with this program; if not, write to the Free Software // |
||
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
| 26 | // ------------------------------------------------------------------------ // |
||
| 27 | /** |
||
| 28 | * AMS Import |
||
| 29 | * |
||
| 30 | * This script will import topics, articles, files, links, ratings, comments and notifications from AMS 2.41 |
||
| 31 | * |
||
| 32 | * @package News |
||
| 33 | * @author Herve Thouzard (http://www.herve-thouzard.com) |
||
| 34 | * @copyright 2005, 2006 - Herve Thouzard |
||
| 35 | */ |
||
| 36 | |||
| 37 | include_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; |
||
| 38 | xoops_cp_header(); |
||
| 39 | include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php'; |
||
| 40 | include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
||
| 41 | include_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php'; |
||
| 42 | include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php'; |
||
| 43 | include_once XOOPS_ROOT_PATH . '/class/xoopstree.php'; |
||
| 44 | |||
| 45 | if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) { |
||
| 46 | if (!isset($_POST['go'])) { |
||
| 47 | echo '<h1>Welcome to the AMS 2.41 import script</h1>'; |
||
| 48 | echo '<br /><br />Select the import options you wan to use :'; |
||
| 49 | echo "<form method='post' action='amsimport.php'>"; |
||
| 50 | echo "<br /><input type='checkbox' name='useforum' value='1' /> Import forums links inside news (at the bottom of the news)"; |
||
| 51 | echo "<br /><input type='checkbox' name='useextlinks' value='1' /> Import external links inside news (at the bottom of the news)"; |
||
| 52 | echo "<br /><br /><input type='submit' name='go' value='Import' />"; |
||
| 53 | echo '</form>'; |
||
| 54 | 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."; |
||
| 55 | } else { |
||
| 56 | // Launch the import |
||
| 57 | View Code Duplication | if (file_exists(XOOPS_ROOT_PATH . '/modules/AMS/language/' . $xoopsConfig['language'] . '/main.php')) { |
|
| 58 | include_once XOOPS_ROOT_PATH . '/modules/AMS/language/' . $xoopsConfig['language'] . '/main.php'; |
||
| 59 | } else { |
||
| 60 | include_once XOOPS_ROOT_PATH . '/modules/AMS/language/english/main.php'; |
||
| 61 | } |
||
| 62 | View Code Duplication | if (file_exists(XOOPS_ROOT_PATH . '/modules/AMS/language/' . $xoopsConfig['language'] . '/admin.php')) { |
|
| 63 | include_once XOOPS_ROOT_PATH . '/modules/AMS/language/' . $xoopsConfig['language'] . '/admin.php'; |
||
| 64 | } else { |
||
| 65 | include_once XOOPS_ROOT_PATH . '/modules/AMS/language/english/admin.php'; |
||
| 66 | } |
||
| 67 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 68 | // User's choices |
||
| 69 | $use_forum = (isset($_POST['useforum']) && $_POST['useforum'] == 1) ? 1 : 0; |
||
| 70 | $use_extlinks = (isset($_POST['useextlinks']) && $_POST['useextlinks'] == 1) ? 1 : 0; |
||
| 71 | // Retreive News module's ID |
||
| 72 | $module_handler = xoops_getHandler('module'); |
||
| 73 | $newsModule = $module_handler->getByDirname('news'); |
||
| 74 | $news_mid = $newsModule->getVar('mid'); |
||
| 75 | // Retreive AMS module's ID |
||
| 76 | $AmsModule = $module_handler->getByDirname('AMS'); |
||
| 77 | $ams_mid = $AmsModule->getVar('mid'); |
||
| 78 | |||
| 79 | // Retreive AMS tables names |
||
| 80 | $ams_topics = $xoopsDB->prefix('ams_topics'); |
||
| 81 | $ams_articles = $xoopsDB->prefix('ams_article'); |
||
| 82 | $ams_text = $xoopsDB->prefix('ams_text'); |
||
| 83 | $ams_files = $xoopsDB->prefix('ams_files'); |
||
| 84 | $ams_links = $xoopsDB->prefix('ams_link'); |
||
| 85 | $ams_rating = $xoopsDB->prefix('ams_rating'); |
||
| 86 | // Retreive News tables names |
||
| 87 | $news_stories_votedata = $xoopsDB->prefix('news_stories_votedata'); |
||
| 88 | // Misc |
||
| 89 | $comment_handler = xoops_getHandler('comment'); |
||
| 90 | $notification_handler = xoops_getHandler('notification'); |
||
| 91 | $ams_news_topics = array(); // Key => AMS Id, Value => News ID |
||
| 92 | |||
| 93 | // The import by itself |
||
| 94 | // Read topics by their order |
||
| 95 | $mytree = new XoopsTree($ams_topics, 'topic_id', 'topic_pid'); |
||
| 96 | $ams_topics = $mytree->getChildTreeArray(0, 'weight'); |
||
| 97 | foreach ($ams_topics as $one_amstopic) { |
||
| 98 | // First we create the topic |
||
| 99 | $topicpid = 0; |
||
| 100 | if ($one_amstopic['topic_pid'] != 0) { // Search for its the parent |
||
| 101 | if (array_key_exists($one_amstopic['topic_pid'], $ams_news_topics)) { |
||
| 102 | $topicpid = $ams_news_topics[$one_amstopic['topic_pid']]; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | $news_topic = new NewsTopic(); |
||
| 106 | $news_topic->setTopicPid($topicpid); |
||
| 107 | $news_topic->setTopicTitle($one_amstopic['topic_title']); |
||
| 108 | $news_topic->setTopicImgurl($one_amstopic['topic_imgurl']); |
||
| 109 | $news_topic->setMenu(0); |
||
| 110 | $news_topic->setTopicFrontpage(1); |
||
| 111 | $news_topic->Settopic_rssurl(''); |
||
| 112 | $news_topic->setTopicDescription(''); |
||
| 113 | $news_topic->setTopic_color('000000'); |
||
| 114 | $news_topic->store(); |
||
| 115 | echo '<br>- The following topic was imported : ' . $news_topic->topic_title(); |
||
| 116 | $ams_topicid = $one_amstopic['topic_id']; |
||
| 117 | $news_topicid = $news_topic->topic_id(); |
||
| 118 | $ams_news_topics[$ams_topicid] = $news_topicid; |
||
| 119 | |||
| 120 | // Then we insert all its articles |
||
| 121 | $result = $db->query('SELECT * FROM ' . $ams_articles . ' WHERE topicid=' . $ams_topicid . ' ORDER BY created'); |
||
| 122 | while ($article = $db->fetchArray($result)) { |
||
| 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 ($link = $db->fetchArray($result7)) { |
||
| 138 | if (trim($links) == '') { |
||
| 139 | $links = "\n\n" . _AMS_NW_RELATEDARTICLES . "\n\n"; |
||
| 140 | } |
||
| 141 | $links .= _AMS_NW_EXTERNALLINK . ' [url=' . $link['link_link'] . ']' . $link['link_title'] . '[/url]' . "\n"; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | // The forum |
||
| 146 | $forum = ''; |
||
| 147 | if ($use_forum && $one_amstopic['forum_id'] != 0) { |
||
| 148 | $forum = "\n\n" . '[url=' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $one_amstopic['forum_id'] . ']' . _AMS_AM_LINKEDFORUM . '[/url]' . "\n"; |
||
| 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 ? true : false; |
||
| 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 ($file = $db->fetchArray($result4)) { |
||
| 184 | $sfile = new sFiles(); |
||
| 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 ($ratings = $db->fetchArray($result5)) { |
||
| 199 | $result6 = $db->queryF('INSERT INTO ' . $news_stories_votedata . ' (storyid, ratinguser, rating, ratinghostname, ratingtimestamp) VALUES (' . $news_newsid . ',' . $ratings['ratinguser'] . ',' . $ratings['rating'] . ',' . $ratings['ratinghostname'] . ',' . $ratings['ratingtimestamp'] . ')'); |
||
| 200 | } |
||
| 201 | |||
| 202 | // The comments |
||
| 203 | $comments =& $comment_handler->getByItemId($ams_mid, $ams_newsid, 'ASC'); |
||
| 204 | View Code Duplication | if (is_array($comments) && count($comments) > 0) { |
|
| 205 | foreach ($comments as $onecomment) { |
||
| 206 | $onecomment->setNew(); |
||
| 207 | $onecomment->setVar('com_modid', $news_mid); |
||
| 208 | $onecomment->setVar('com_itemid', $news_newsid); |
||
| 209 | $comment_handler->insert($onecomment); |
||
| 210 | } |
||
| 211 | } |
||
| 212 | unset($comments); |
||
| 213 | |||
| 214 | // The notifications of this news |
||
| 215 | //$notifications =& $notification_handler->getByItemId($ams_mid, $ams_newsid, 'ASC'); |
||
|
0 ignored issues
–
show
|
|||
| 216 | $criteria = new CriteriaCompo(new Criteria('not_modid', $ams_mid)); |
||
| 217 | $criteria->add(new Criteria('not_itemid', $ams_newsid)); |
||
| 218 | $criteria->setOrder('ASC'); |
||
| 219 | $notifications = $notification_handler->getObjects($criteria); |
||
| 220 | View Code Duplication | if (is_array($notifications) && count($notifications) > 0) { |
|
| 221 | foreach ($notifications as $onenotification) { |
||
| 222 | $onenotification->setNew(); |
||
| 223 | $onenotification->setVar('not_modid', $news_mid); |
||
| 224 | $onenotification->setVar('not_itemid', $news_newsid); |
||
| 225 | $notification_handler->insert($onenotification); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | unset($notifications); |
||
| 229 | } |
||
| 230 | } |
||
| 231 | // Finally, import all the globals notifications |
||
| 232 | $criteria = new CriteriaCompo(new Criteria('not_modid', $ams_mid)); |
||
| 233 | $criteria->add(new Criteria('not_category', 'global')); |
||
| 234 | $criteria->setOrder('ASC'); |
||
| 235 | $notifications = $notification_handler->getObjects($criteria); |
||
| 236 | View Code Duplication | if (is_array($notifications) && count($notifications) > 0) { |
|
| 237 | foreach ($notifications as $onenotification) { |
||
| 238 | $onenotification->setNew(); |
||
| 239 | $onenotification->setVar('not_modid', $news_mid); |
||
| 240 | $onenotification->setVar('not_itemid', $news_newsid); |
||
| 241 | $notification_handler->insert($onenotification); |
||
| 242 | } |
||
| 243 | } |
||
| 244 | unset($notifications); |
||
| 245 | 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>"; |
||
| 246 | } |
||
| 247 | } else { |
||
| 248 | redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); |
||
| 249 | } |
||
| 250 | xoops_cp_footer(); |
||
| 251 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.