mambax7 /
smartfaq
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 | * Module: SmartFAQ |
||
| 5 | * Author: Marius Scurtescu <[email protected]> |
||
| 6 | * Licence: GNU |
||
| 7 | * |
||
| 8 | * Import script from XoopsFAQ to SmartFAQ. |
||
| 9 | * |
||
| 10 | * It was tested with XoopsFAQ version 1.1 and SmartFAQ version 1.0 beta |
||
| 11 | * |
||
| 12 | */ |
||
| 13 | |||
| 14 | include_once __DIR__ . '/admin_header.php'; |
||
| 15 | |||
| 16 | $importFromModuleName = 'XoopsFAQ'; |
||
| 17 | $scriptname = 'xoopsfaq.php'; |
||
| 18 | |||
| 19 | $op = 'start'; |
||
| 20 | |||
| 21 | View Code Duplication | if (isset($_POST['op']) && ($_POST['op'] === 'go')) { |
|
|
0 ignored issues
–
show
|
|||
| 22 | $op = $_POST['op']; |
||
| 23 | } |
||
| 24 | |||
| 25 | if ($op === 'start') { |
||
| 26 | xoops_cp_header(); |
||
| 27 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 28 | |||
| 29 | $result = $xoopsDB->query('select count(*) from ' . $xoopsDB->prefix('xoopsfaq_categories')); |
||
| 30 | list($totalCat) = $xoopsDB->fetchRow($result); |
||
| 31 | |||
| 32 | sf_collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 33 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a> " . sprintf(_AM_SF_IMPORT_FROM, $importFromModuleName) . '</h3>'; |
||
| 34 | echo "<div id='bottomtable'>"; |
||
| 35 | |||
| 36 | if ($totalCat == 0) { |
||
| 37 | echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . _AM_SF_IMPORT_NO_CATEGORY . '</span>'; |
||
| 38 | } else { |
||
| 39 | include_once XOOPS_ROOT_PATH . '/class/xoopstree.php'; |
||
| 40 | |||
| 41 | $result = $xoopsDB->query('select count(*) from ' . $xoopsDB->prefix('xoopsfaq_contents')); |
||
| 42 | list($totalFAQ) = $xoopsDB->fetchRow($result); |
||
| 43 | |||
| 44 | if ($totalFAQ == 0) { |
||
| 45 | echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . sprintf(_AM_SF_IMPORT_MODULE_FOUND_NO_FAQ, $importFromModuleName, $totalCat) . '</span>'; |
||
| 46 | } else { |
||
| 47 | echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . sprintf(_AM_SF_IMPORT_MODULE_FOUND, $importFromModuleName, $totalCat, $totalFAQ) . '</span>'; |
||
| 48 | |||
| 49 | $form = new XoopsThemeForm(_AM_SF_IMPORT_SETTINGS, 'import_form', XOOPS_URL . '/modules/smartfaq/admin/' . $scriptname); |
||
| 50 | |||
| 51 | // Categories to be imported |
||
| 52 | $cat_cbox = new XoopsFormCheckBox(sprintf(_AM_SF_IMPORT_CATEGORIES, $importFromModuleName), 'import_category', -1); |
||
| 53 | $result = $xoopsDB->query('select c.category_id, c.category_title, count(q.contents_id) from ' . $xoopsDB->prefix('xoopsfaq_categories') . ' as c, ' . $xoopsDB->prefix('xoopsfaq_contents') . ' as q where c.category_id=q.category_id group by c.category_id order by category_order'); |
||
| 54 | |||
| 55 | while (list($cid, $cat_title, $count) = $xoopsDB->fetchRow($result)) { |
||
| 56 | $cat_cbox->addOption($cid, "$cat_title ($count)<br\>"); |
||
| 57 | } |
||
| 58 | $form->addElement($cat_cbox); |
||
| 59 | |||
| 60 | // SmartFAQ parent category |
||
| 61 | $mytree = new XoopsTree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid'); |
||
| 62 | ob_start(); |
||
| 63 | $mytree->makeMySelBox('name', 'weight', $preset_id = 0, $none = 1, $sel_name = 'parent_category'); |
||
| 64 | $form->addElement(new XoopsFormLabel(_AM_SF_IMPORT_PARENT_CATEGORY, ob_get_contents())); |
||
| 65 | ob_end_clean(); |
||
| 66 | |||
| 67 | // Auto-Approve |
||
| 68 | $form->addElement(new XoopsFormRadioYN(_AM_SF_IMPORT_AUTOAPPROVE, 'autoaprove', 1, ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '')); |
||
| 69 | |||
| 70 | // Submitted and answered by |
||
| 71 | $memberHandler = xoops_getHandler('member'); |
||
| 72 | $user_select = new XoopsFormSelect(_AM_SF_IMPORTED_USER, 'uid', 0); |
||
| 73 | $user_select->addOption(0, '----'); |
||
| 74 | $criteria = new CriteriaCompo(); |
||
| 75 | $criteria->setSort('uname'); |
||
| 76 | $criteria->setOrder('ASC'); |
||
| 77 | $user_select->addOptionArray($memberHandler->getUserList($criteria)); |
||
| 78 | $form->addElement($user_select); |
||
| 79 | |||
| 80 | // Q&As can be commented? |
||
| 81 | $form->addElement(new XoopsFormRadioYN(_AM_SF_IMPORT_ALLOWCOMMENTS, 'cancomment', 1, ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '')); |
||
| 82 | |||
| 83 | $group_list = $memberHandler->getGroupList(); |
||
| 84 | $groups_selected = array(); |
||
| 85 | $groups_checkbox = new XoopsFormCheckBox(_AM_SF_IMPORT_PERMISSIONS, 'groups_read'); |
||
| 86 | View Code Duplication | foreach ($group_list as $group_id => $group_name) { |
|
| 87 | if ($group_id != XOOPS_GROUP_ADMIN) { |
||
| 88 | $groups_selected [] = $group_id; |
||
| 89 | $groups_checkbox->addOption($group_id, $group_name); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | $groups_checkbox->setValue($groups_selected); |
||
| 93 | $form->addElement($groups_checkbox); |
||
| 94 | |||
| 95 | $form->addElement(new XoopsFormHidden('op', 'go')); |
||
| 96 | $form->addElement(new XoopsFormButton('', 'import', _AM_SF_IMPORT, 'submit')); |
||
| 97 | $form->display(); |
||
| 98 | } |
||
| 99 | |||
| 100 | exit(); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($op === 'go') { |
||
| 105 | include_once __DIR__ . '/admin_header.php'; |
||
| 106 | |||
| 107 | $import_category = (isset($_POST['import_category']) ? $_POST['import_category'] : null); |
||
| 108 | if (!$import_category) { |
||
| 109 | redirect_header($scriptname, 2, _AM_SF_NOCATSELECTED); |
||
| 110 | } |
||
| 111 | |||
| 112 | xoops_cp_header(); |
||
| 113 | |||
| 114 | sf_collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 115 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a> " . sprintf(_AM_SF_IMPORT_FROM, $importFromModuleName) . '</h3>'; |
||
| 116 | echo "<div id='bottomtable'>"; |
||
| 117 | echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . _AM_SF_IMPORT_RESULT . '</span>'; |
||
| 118 | |||
| 119 | $cnt_imported_cat = 0; |
||
| 120 | $cnt_imported_faq = 0; |
||
| 121 | |||
| 122 | $parentId = $_POST['parent_category']; |
||
| 123 | $groups_read = isset($_POST['groups_read']) ? $_POST['groups_read'] : array(); |
||
| 124 | $uid = !empty($_POST['uid']) ? $_POST['uid'] : 0; |
||
| 125 | $cancomment = $_POST['cancomment']; |
||
| 126 | $autoaprove = $_POST['autoaprove']; |
||
| 127 | |||
| 128 | View Code Duplication | if (is_array($_POST['import_category'])) { |
|
| 129 | $import_category_list = implode(',', $_POST['import_category']); |
||
| 130 | } else { |
||
| 131 | $import_category_list = $_POST['import_category']; |
||
| 132 | } |
||
| 133 | |||
| 134 | $categoryHandler = sf_gethandler('category'); |
||
| 135 | $faqHandler = sf_gethandler('faq'); |
||
| 136 | $answerHandler = sf_gethandler('answer'); |
||
| 137 | |||
| 138 | /*echo "Parent Category ID: $parentId<br/>"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
55% of this comment could be valid code. Did you maybe forget this after debugging?
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. Loading history...
|
|||
| 139 | echo "Groups Read: " . implode (",", $groups_read) . "<br/>"; |
||
| 140 | echo "Import Categories: $import_category_list<br/>"; |
||
| 141 | echo "User ID: $uid<br/>"; |
||
| 142 | echo "Can Comment: $cancomment<br/>"; |
||
| 143 | echo "Auto aprove: $autoaprove<br/>";*/ |
||
| 144 | |||
| 145 | $resultCat = $xoopsDB->query('select * from ' . $xoopsDB->prefix('xoopsfaq_categories') . " where category_id in ($import_category_list) order by category_order"); |
||
| 146 | |||
| 147 | while ($arrCat = $xoopsDB->fetchArray($resultCat)) { |
||
| 148 | extract($arrCat, EXTR_PREFIX_ALL, 'xcat'); |
||
| 149 | |||
| 150 | // insert category into SmartFAQ |
||
| 151 | $categoryObj = $categoryHandler->create(); |
||
| 152 | |||
| 153 | $categoryObj->setVar('parentid', $parentId); |
||
| 154 | $categoryObj->setVar('weight', $xcat_category_order); |
||
| 155 | $categoryObj->setGroups_read($groups_read); |
||
| 156 | $categoryObj->setVar('name', $xcat_category_title); |
||
| 157 | |||
| 158 | if (!$categoryObj->store(false)) { |
||
| 159 | echo sprintf(_AM_SF_IMPORT_CATEGORY_ERROR, $xcat_name) . '<br/>'; |
||
| 160 | continue; |
||
| 161 | } |
||
| 162 | |||
| 163 | sf_saveCategory_Permissions($categoryObj->getGroups_read(), $categoryObj->categoryid(), 'category_read'); |
||
| 164 | |||
| 165 | ++$cnt_imported_cat; |
||
| 166 | |||
| 167 | echo sprintf(_AM_SF_IMPORT_CATEGORY_SUCCESS, $xcat_category_title) . "<br\>"; |
||
| 168 | |||
| 169 | $resultFAQ = $xoopsDB->query('select * from ' . $xoopsDB->prefix('xoopsfaq_contents') . " where category_id=$xcat_category_id order by contents_order"); |
||
| 170 | while ($arrFAQ = $xoopsDB->fetchArray($resultFAQ)) { |
||
| 171 | extract($arrFAQ, EXTR_PREFIX_ALL, 'xfaq'); |
||
| 172 | |||
| 173 | if ($xfaq_contents_visible != 1) { |
||
| 174 | $qstatus = _SF_STATUS_OFFLINE; |
||
| 175 | } elseif ($autoaprove) { |
||
| 176 | $qstatus = _SF_STATUS_PUBLISHED; |
||
| 177 | } else { |
||
| 178 | $qstatus = _SF_STATUS_SUBMITTED; |
||
| 179 | } |
||
| 180 | |||
| 181 | // insert question into SmartFAQ |
||
| 182 | $faqObj = $faqHandler->create(); |
||
| 183 | $answerObj = $answerHandler->create(); |
||
| 184 | |||
| 185 | $faqObj->setGroups_read($groups_read); |
||
| 186 | $faqObj->setVar('categoryid', $categoryObj->categoryid()); |
||
| 187 | $faqObj->setVar('question', $xfaq_contents_title); |
||
| 188 | $faqObj->setVar('uid', $uid); |
||
| 189 | $faqObj->setVar('status', $qstatus); |
||
| 190 | $faqObj->setVar('weight', $xfaq_contents_order); |
||
| 191 | $faqObj->setVar('html', $xfaq_contents_nohtml == 1 ? 0 : 1); |
||
| 192 | $faqObj->setVar('smiley', $xfaq_contents_nosmiley == 1 ? 0 : 1); |
||
| 193 | $faqObj->setVar('xcodes', $xfaq_contents_noxcode == 1 ? 0 : 1); |
||
| 194 | $faqObj->setVar('cancomment', $cancomment); |
||
| 195 | |||
| 196 | View Code Duplication | if (!$faqObj->store(false)) { |
|
| 197 | echo sprintf(' ' . _AM_SF_IMPORT_FAQ_ERROR, $xfaq_contents_title) . '<br/>'; |
||
| 198 | continue; |
||
| 199 | } else { |
||
| 200 | $answerObj->setVar('faqid', $faqObj->faqid()); |
||
| 201 | $answerObj->setVar('answer', $xfaq_contents_contents); |
||
| 202 | $answerObj->setVar('uid', $uid); |
||
| 203 | $answerObj->setVar('status', _SF_AN_STATUS_APPROVED); |
||
| 204 | |||
| 205 | if (!$answerObj->store()) { |
||
| 206 | echo sprintf(' ' . _AM_SF_IMPORT_FAQ_ERROR) . '<br/>'; |
||
| 207 | continue; |
||
| 208 | } else { |
||
| 209 | echo ' ' . sprintf(_AM_SF_IMPORTED_QUESTION, $faqObj->question(50)) . '<br />'; |
||
| 210 | ++$cnt_imported_faq; |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | echo '<br/>'; |
||
| 216 | } |
||
| 217 | |||
| 218 | echo 'Done.<br/>'; |
||
| 219 | echo sprintf(_AM_SF_IMPORTED_CATEGORIES, $cnt_imported_cat) . '<br/>'; |
||
| 220 | echo sprintf(_AM_SF_IMPORTED_QUESTIONS, $cnt_imported_faq) . '<br/>'; |
||
| 221 | |||
| 222 | exit(); |
||
| 223 | } |
||
| 224 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.