| Conditions | 14 |
| Paths | 1024 |
| Total Lines | 229 |
| Code Lines | 126 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 31 | function editarticle($articleID = '') |
||
| 32 | { |
||
| 33 | global $indexAdmin; |
||
| 34 | global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsLogger, $xoopsOption, $xoopsUserIsAdmin; |
||
| 35 | /** @var Soapbox\Helper $helper */ |
||
| 36 | $helper = Soapbox\Helper::getInstance(); |
||
| 37 | |||
| 38 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
|
|
|||
| 39 | $myts = \MyTextSanitizer::getInstance(); |
||
| 40 | |||
| 41 | if (file_exists(XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php')) { |
||
| 42 | require_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php'; |
||
| 43 | } else { |
||
| 44 | require_once XOOPS_ROOT_PATH . '/language/english/calendar.php'; |
||
| 45 | } |
||
| 46 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 47 | |||
| 48 | //------------------------------------- |
||
| 49 | /** @var \XoopsModules\Soapbox\EntrydataHandler $entrydataHandler */ |
||
| 50 | $entrydataHandler = new \XoopsModules\Soapbox\EntrydataHandler(); |
||
| 51 | |||
| 52 | if (!$articleID) { |
||
| 53 | redirect_header('index.php', 1, _AM_SOAPBOX_NOARTS); |
||
| 54 | } |
||
| 55 | //get entry object |
||
| 56 | $_entryob = $entrydataHandler->getArticle($articleID); |
||
| 57 | if (!is_object($_entryob)) { |
||
| 58 | redirect_header('index.php', 1, _AM_SOAPBOX_NOARTTOEDIT); |
||
| 59 | } |
||
| 60 | //get vars mode E |
||
| 61 | $entry_vars = $_entryob->getVars(); |
||
| 62 | foreach ($entry_vars as $k => $v) { |
||
| 63 | $e_articles[$k] = $_entryob->getVar($k, 'E'); |
||
| 64 | } |
||
| 65 | //xoops_cp_header(); |
||
| 66 | //$adminObject->displayNavigation(basename(__FILE__)); |
||
| 67 | |||
| 68 | // Module menu |
||
| 69 | //adminMenu(3, _AM_SOAPBOX_SUBMITS." > '". $_entryob->getVar('headline') ."'"); |
||
| 70 | |||
| 71 | // echo "<h3 style='color: #2F5376; '>" . _AM_SOAPBOX_SUBMITSMNGMT . "</h3>"; |
||
| 72 | $sform = new \XoopsThemeForm(_AM_SOAPBOX_AUTHART . ': ' . $_entryob->getVar('headline'), 'op', xoops_getenv('PHP_SELF'), 'post', true); |
||
| 73 | |||
| 74 | $sform->setExtra('enctype="multipart/form-data"'); |
||
| 75 | |||
| 76 | //get category object |
||
| 77 | $_categoryob = $entrydataHandler->getColumn($e_articles['columnID']); |
||
| 78 | if (is_object($_categoryob)) { |
||
| 79 | $sform->addElement(new \XoopsFormLabel(_AM_SOAPBOX_COLNAME, $_categoryob->getVar('name'))); |
||
| 80 | $sform->addElement(new \XoopsFormHidden('columnID', $e_articles['columnID'])); |
||
| 81 | } else { |
||
| 82 | $_can_editcategoryobArray = $entrydataHandler->getColumns(null, true); |
||
| 83 | //---------------------------- |
||
| 84 | $collist = []; |
||
| 85 | foreach ($_can_editcategoryobArray as $key => $_can_edit_categoryob) { |
||
| 86 | $collist[$key] = $_can_edit_categoryob->getVar('name'); |
||
| 87 | } |
||
| 88 | $col_select = new \XoopsFormSelect('', 'columnID', (int)$e_articles['columnID']); |
||
| 89 | $col_select->addOptionArray($collist); |
||
| 90 | $col_select_tray = new \XoopsFormElementTray(_AM_SOAPBOX_COLNAME, '<br>'); |
||
| 91 | $col_select_tray->addElement($col_select); |
||
| 92 | $sform->addElement($col_select_tray); |
||
| 93 | } |
||
| 94 | |||
| 95 | if (isset($headline)) { |
||
| 96 | $headline = $myts->htmlSpecialChars(stripslashes($headline)); |
||
| 97 | } |
||
| 98 | |||
| 99 | // HEADLINE, LEAD, BODYTEXT |
||
| 100 | // This part is common to edit/add |
||
| 101 | $sform->addElement(new \XoopsFormText(_AM_SOAPBOX_ARTHEADLINE, 'headline', 50, 50, $e_articles['headline']), true); |
||
| 102 | |||
| 103 | // LEAD |
||
| 104 | // $sform -> addElement( new \XoopsFormTextArea( _AM_SOAPBOX_ARTLEAD, 'lead', $lead, 5, 60 ) ); |
||
| 105 | // $editor_lead=soapbox_getWysiwygForm($helper->getConfig('editorUser') , _AM_SOAPBOX_ARTLEAD , 'lead' , $e_articles['lead'] , '100%', '200px'); |
||
| 106 | // $sform->addElement($editor_lead,true); |
||
| 107 | |||
| 108 | $editor_lead = new \XoopsFormElementTray(_AM_SOAPBOX_ARTLEAD, '<br>'); |
||
| 109 | if (class_exists('XoopsFormEditor')) { |
||
| 110 | $options['name'] = 'lead'; |
||
| 111 | $options['value'] = $e_articles['lead']; |
||
| 112 | $options['rows'] = 5; |
||
| 113 | $options['cols'] = '100%'; |
||
| 114 | $options['width'] = '100%'; |
||
| 115 | $options['height'] = '200px'; |
||
| 116 | $formmnote = new \XoopsFormEditor('', $helper->getConfig('editorUser'), $options, $nohtml = false, $onfailure = 'textarea'); |
||
| 117 | $editor_lead->addElement($formmnote); |
||
| 118 | } else { |
||
| 119 | $formmnote = new \XoopsFormDhtmlTextArea('', 'formmnote', $item->getVar('formmnote', 'e'), '100%', '100%'); |
||
| 120 | $editor_lead->addElement($formmnote); |
||
| 121 | } |
||
| 122 | $sform->addElement($editor_lead, false); |
||
| 123 | |||
| 124 | // TEASER |
||
| 125 | $sform->addElement(new \XoopsFormTextArea(_AM_SOAPBOX_ARTTEASER, 'teaser', $e_articles['teaser'], 10, 120)); |
||
| 126 | // $editor_teaser=soapbox_getWysiwygForm($helper->getConfig('editorUser') , _AM_SOAPBOX_ARTTEASER ,'teaser', $teaser , '100%', '120px'); |
||
| 127 | // $sform->addElement($editor_teaser,true); |
||
| 128 | // |
||
| 129 | $autoteaser_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_AUTOTEASER, 'autoteaser', 0, ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 130 | $sform->addElement($autoteaser_radio); |
||
| 131 | $sform->addElement(new \XoopsFormText(_AM_SOAPBOX_AUTOTEASERAMOUNT, 'teaseramount', 4, 4, 100)); |
||
| 132 | |||
| 133 | // BODY |
||
| 134 | //HACK by domifara for Wysiwyg |
||
| 135 | // if (null !== ($helper->getConfig('editorUser')) ) { |
||
| 136 | // $editor=soapbox_getWysiwygForm($helper->getConfig('editorUser') , _AM_SOAPBOX_ARTBODY, 'bodytext', $e_articles['bodytext'], '100%', '400px'); |
||
| 137 | // $sform->addElement($editor,true); |
||
| 138 | // } else { |
||
| 139 | // $sform -> addElement( new \XoopsFormDhtmlTextArea( _AM_SOAPBOX_ARTBODY, 'bodytext', $e_articles['bodytext'], 20, 120 ) ); |
||
| 140 | // } |
||
| 141 | |||
| 142 | $optionsTrayNote = new \XoopsFormElementTray(_AM_SOAPBOX_ARTBODY, '<br>'); |
||
| 143 | if (class_exists('XoopsFormEditor')) { |
||
| 144 | $options['name'] = 'bodytext'; |
||
| 145 | $options['value'] = $e_articles['bodytext']; |
||
| 146 | $options['rows'] = 5; |
||
| 147 | $options['cols'] = '100%'; |
||
| 148 | $options['width'] = '100%'; |
||
| 149 | $options['height'] = '400px'; |
||
| 150 | $bodynote = new \XoopsFormEditor('', $helper->getConfig('editorUser'), $options, $nohtml = false, $onfailure = 'textarea'); |
||
| 151 | $optionsTrayNote->addElement($bodynote); |
||
| 152 | } else { |
||
| 153 | $bodynote = new \XoopsFormDhtmlTextArea('', 'formmnote', $item->getVar('formmnote', 'e'), '100%', '100%'); |
||
| 154 | $optionsTrayNote->addElement($bodynote); |
||
| 155 | } |
||
| 156 | $sform->addElement($optionsTrayNote, false); |
||
| 157 | |||
| 158 | // IMAGE |
||
| 159 | // The article CAN have its own image :) |
||
| 160 | // First, if the article's image doesn't exist, set its value to the blank file |
||
| 161 | |||
| 162 | if (empty($e_articles['artimage']) |
||
| 163 | || !file_exists(XOOPS_ROOT_PATH . '/' . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir')) . '/' . $e_articles['artimage'])) { |
||
| 164 | $artimage = 'blank.png'; |
||
| 165 | } |
||
| 166 | |||
| 167 | // Code to create the image selector |
||
| 168 | $graph_array = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . '/' . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir'))); |
||
| 169 | $artimage_select = new \XoopsFormSelect('', 'artimage', $e_articles['artimage']); |
||
| 170 | $artimage_select->addOptionArray($graph_array); |
||
| 171 | $artimage_select->setExtra("onchange='showImgSelected(\"image5\", \"artimage\", \"" . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir')) . '", "", "' . XOOPS_URL . "\")'"); |
||
| 172 | $artimage_tray = new \XoopsFormElementTray(_AM_SOAPBOX_SELECT_IMG, ' '); |
||
| 173 | $artimage_tray->addElement($artimage_select); |
||
| 174 | $artimage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . '/' . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir')) . '/' . $e_articles['artimage'] . "' name='image5' id='image5' alt=''>")); |
||
| 175 | $sform->addElement($artimage_tray); |
||
| 176 | |||
| 177 | // Code to call the file browser to select an image to upload |
||
| 178 | $sform->addElement(new \XoopsFormFile(_AM_SOAPBOX_UPLOADIMAGE, 'cimage', (int)$helper->getConfig('maxfilesize')), false); |
||
| 179 | |||
| 180 | // WEIGHT |
||
| 181 | $sform->addElement(new \XoopsFormText(_AM_SOAPBOX_WEIGHT, 'weight', 4, 4, $e_articles['weight'])); |
||
| 182 | //---------- |
||
| 183 | // datesub |
||
| 184 | //---------- |
||
| 185 | $datesub_caption = $myts->htmlSpecialChars(formatTimestamp($e_articles['datesub'], $helper->getConfig('dateformat')) . '=>'); |
||
| 186 | $datesub_tray = new \XoopsFormDateTime(_AM_SOAPBOX_POSTED . '<br>' . $datesub_caption, 'datesub', 15, time()); |
||
| 187 | // you don't want to change datesub |
||
| 188 | $datesubnochage_checkbox = new \XoopsFormCheckBox(_AM_SOAPBOX_DATESUBNOCHANGE, 'datesubnochage', 0); |
||
| 189 | $datesubnochage_checkbox->addOption(1, _AM_SOAPBOX_YES); |
||
| 190 | $datesub_tray->addElement($datesubnochage_checkbox); |
||
| 191 | $sform->addElement($datesub_tray); |
||
| 192 | //----------- |
||
| 193 | |||
| 194 | // COMMENTS |
||
| 195 | if (isset($GLOBALS['xoopsModuleConfig']['globaldisplaycomments']) |
||
| 196 | && 1 === $GLOBALS['xoopsModuleConfig']['globaldisplaycomments']) { |
||
| 197 | // COMMENTS |
||
| 198 | // Code to allow comments |
||
| 199 | $addcommentable_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_ALLOWCOMMENTS, 'commentable', $e_articles['commentable'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 200 | $sform->addElement($addcommentable_radio); |
||
| 201 | } |
||
| 202 | |||
| 203 | // OFFLINE |
||
| 204 | // Code to take article offline, for maintenance purposes |
||
| 205 | $offline_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_SWITCHOFFLINE, 'offline', $e_articles['offline'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 206 | $sform->addElement($offline_radio); |
||
| 207 | |||
| 208 | // ARTICLE IN BLOCK |
||
| 209 | // Code to put article in block |
||
| 210 | $block_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_BLOCK, 'block', $e_articles['block'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 211 | $sform->addElement($block_radio); |
||
| 212 | |||
| 213 | // notification public |
||
| 214 | $notifypub_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_NOTIFY, 'notifypub', $e_articles['notifypub'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 215 | $sform->addElement($notifypub_radio); |
||
| 216 | |||
| 217 | // VARIOUS OPTIONS |
||
| 218 | //---------- |
||
| 219 | $options_tray = new \XoopsFormElementTray(_AM_SOAPBOX_OPTIONS, '<br>'); |
||
| 220 | |||
| 221 | $html_checkbox = new \XoopsFormCheckBox('', 'html', $e_articles['html']); |
||
| 222 | $html_checkbox->addOption(1, _AM_SOAPBOX_DOHTML); |
||
| 223 | $options_tray->addElement($html_checkbox); |
||
| 224 | |||
| 225 | $smiley_checkbox = new \XoopsFormCheckBox('', 'smiley', $e_articles['smiley']); |
||
| 226 | $smiley_checkbox->addOption(1, _AM_SOAPBOX_DOSMILEY); |
||
| 227 | $options_tray->addElement($smiley_checkbox); |
||
| 228 | |||
| 229 | $xcodes_checkbox = new \XoopsFormCheckBox('', 'xcodes', $e_articles['xcodes']); |
||
| 230 | $xcodes_checkbox->addOption(1, _AM_SOAPBOX_DOXCODE); |
||
| 231 | $options_tray->addElement($xcodes_checkbox); |
||
| 232 | |||
| 233 | $breaks_checkbox = new \XoopsFormCheckBox('', 'breaks', $e_articles['breaks']); |
||
| 234 | $breaks_checkbox->addOption(1, _AM_SOAPBOX_BREAKS); |
||
| 235 | $options_tray->addElement($breaks_checkbox); |
||
| 236 | |||
| 237 | $sform->addElement($options_tray); |
||
| 238 | //---------- |
||
| 239 | |||
| 240 | $sform->addElement(new \XoopsFormHidden('articleID', $e_articles['articleID'])); |
||
| 241 | |||
| 242 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 243 | $hidden = new \XoopsFormHidden('op', 'authart'); |
||
| 244 | $buttonTray->addElement($hidden); |
||
| 245 | |||
| 246 | $butt_save = new \XoopsFormButton('', '', _AM_SOAPBOX_AUTHORIZE, 'submit'); |
||
| 247 | $butt_save->setExtra('onclick="this.form.elements.op.value=\'authart\'"'); |
||
| 248 | $buttonTray->addElement($butt_save); |
||
| 249 | |||
| 250 | $butt_cancel = new \XoopsFormButton('', '', _AM_SOAPBOX_CANCEL, 'button'); |
||
| 251 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 252 | $buttonTray->addElement($butt_cancel); |
||
| 253 | |||
| 254 | $sform->addElement($buttonTray); |
||
| 255 | //----------- |
||
| 256 | // $xoopsGTicket->addTicketXoopsFormElement($sform, __LINE__); |
||
| 257 | //----------- |
||
| 258 | $sform->display(); |
||
| 259 | unset($hidden); |
||
| 260 | } |
||
| 465 |