| Conditions | 14 |
| Paths | 1024 |
| Total Lines | 245 |
| Code Lines | 127 |
| Lines | 60 |
| Ratio | 24.49 % |
| Changes | 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 |
||
| 33 | /** |
||
| 34 | * @param int $articleID |
||
| 35 | */ |
||
| 36 | function editarticle($articleID = 0) |
||
| 37 | { |
||
| 38 | global $indexAdmin; |
||
| 39 | global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsLogger, $xoopsOption, $xoopsUserIsAdmin; |
||
| 40 | /** @var Soapbox\Helper $helper */ |
||
| 41 | $helper = Soapbox\Helper::getInstance(); |
||
| 42 | |||
| 43 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
|
|
|||
| 44 | $myts = \MyTextSanitizer::getInstance(); |
||
| 45 | |||
| 46 | if (file_exists(XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php')) { |
||
| 47 | require_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php'; |
||
| 48 | } else { |
||
| 49 | require_once XOOPS_ROOT_PATH . '/language/english/calendar.php'; |
||
| 50 | } |
||
| 51 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 52 | |||
| 53 | $articleID = (int)$articleID; |
||
| 54 | /** @var \XoopsModules\Soapbox\EntrydataHandler $entrydataHandler */ |
||
| 55 | $entrydataHandler = new \XoopsModules\Soapbox\EntrydataHandler(); |
||
| 56 | if (0 !== $articleID) { |
||
| 57 | //articleID check |
||
| 58 | $_entryob = $entrydataHandler->getArticleOnePermcheck($articleID, false, false); |
||
| 59 | if (!is_object($_entryob)) { |
||
| 60 | redirect_header('index.php', 1, _AM_SOAPBOX_NOARTS); |
||
| 61 | } |
||
| 62 | |||
| 63 | //adminMenu(2, _AM_SOAPBOX_ARTS._AM_SOAPBOX_EDITING. $_entryob->getVar('headline') ."'"); |
||
| 64 | //echo "<h3 style='color: #2F5376; '>" . _AM_SOAPBOX_ADMINARTMNGMT . "</h3>"; |
||
| 65 | $sform = new \XoopsThemeForm(_AM_SOAPBOX_MODART . ': ' . $_entryob->getVar('headline'), 'op', $myts->htmlSpecialChars(xoops_getenv('PHP_SELF')), 'post', true); |
||
| 66 | } else { |
||
| 67 | //create new entry object |
||
| 68 | $_entryob = $entrydataHandler->createArticle(true); |
||
| 69 | // $_entryob->cleanVars(); |
||
| 70 | |||
| 71 | /** |
||
| 72 | *initial first variables before we start |
||
| 73 | */ |
||
| 74 | $columnID = 1; |
||
| 75 | if (null !== $helper->getConfig('editorUser') && 'dhtml' !== $helper->getConfig('editorUser')) { |
||
| 76 | $html = 1; |
||
| 77 | $breaks = 0; |
||
| 78 | } |
||
| 79 | //adminMenu(2, _AM_SOAPBOX_ARTS._AM_SOAPBOX_CREATINGART); |
||
| 80 | //echo "<h3 style='color: #2F5376; '>" . _AM_SOAPBOX_ADMINARTMNGMT . "</h3>"; |
||
| 81 | $sform = new \XoopsThemeForm(_AM_SOAPBOX_NEWART, 'op', $myts->htmlSpecialChars(xoops_getenv('PHP_SELF')), 'post', true); |
||
| 82 | } |
||
| 83 | |||
| 84 | //get vars mode E |
||
| 85 | $entry_vars = $_entryob->getVars(); |
||
| 86 | foreach ($entry_vars as $k => $v) { |
||
| 87 | $e_articles[$k] = $_entryob->getVar($k, 'E'); |
||
| 88 | } |
||
| 89 | |||
| 90 | $sform->setExtra('enctype="multipart/form-data"'); |
||
| 91 | |||
| 92 | // COLUMN |
||
| 93 | /* |
||
| 94 | * Get information for pulldown menu using XoopsTree. |
||
| 95 | * First var is the database table |
||
| 96 | * Second var is the unique field ID for the categories |
||
| 97 | * Last one is not set as we do not have sub menus in WF-FAQ |
||
| 98 | */ |
||
| 99 | $canEditCategoryobArray = $entrydataHandler->getColumns(null, true); |
||
| 100 | $collist = []; |
||
| 101 | foreach ($canEditCategoryobArray as $key => $_can_edit_categoryob) { |
||
| 102 | $collist[$key] = $_can_edit_categoryob->getVar('name'); |
||
| 103 | } |
||
| 104 | $col_select = new \XoopsFormSelect('', 'columnID', (int)$e_articles['columnID']); |
||
| 105 | $col_select->addOptionArray($collist); |
||
| 106 | $col_select_tray = new \XoopsFormElementTray(_AM_SOAPBOX_COLNAME, '<br>'); |
||
| 107 | $col_select_tray->addElement($col_select); |
||
| 108 | $sform->addElement($col_select_tray); |
||
| 109 | |||
| 110 | // HEADLINE, LEAD, BODYTEXT |
||
| 111 | // This part is common to edit/add |
||
| 112 | $sform->addElement(new \XoopsFormText(_AM_SOAPBOX_ARTHEADLINE, 'headline', 50, 50, $e_articles['headline']), true); |
||
| 113 | |||
| 114 | // LEAD |
||
| 115 | // $sform -> addElement( new \XoopsFormTextArea( _AM_SOAPBOX_ARTLEAD, 'lead', $lead, 5, 60 ) ); |
||
| 116 | // $editor_lead=soapbox_getWysiwygForm($helper->getConfig('editorUser') , _AM_SOAPBOX_ARTLEAD , 'lead' , $e_articles['lead'] , '100%', '200px'); |
||
| 117 | // $sform->addElement($editor_lead,TRUE); |
||
| 118 | |||
| 119 | $editor_lead = new \XoopsFormElementTray(_AM_SOAPBOX_ARTLEAD, '<br>'); |
||
| 120 | if (class_exists('XoopsFormEditor')) { |
||
| 121 | $options['name'] = 'lead'; |
||
| 122 | $options['value'] = $e_articles['lead']; |
||
| 123 | $options['rows'] = 5; |
||
| 124 | $options['cols'] = '100%'; |
||
| 125 | $options['width'] = '100%'; |
||
| 126 | $options['height'] = '200px'; |
||
| 127 | $formmnote = new \XoopsFormEditor('', $helper->getConfig('editorUser'), $options, $nohtml = false, $onfailure = 'textarea'); |
||
| 128 | $editor_lead->addElement($formmnote); |
||
| 129 | } else { |
||
| 130 | $formmnote = new \XoopsFormDhtmlTextArea('', 'formmnote', $item->getVar('formmnote', 'e'), '100%', '100%'); |
||
| 131 | $editor_lead->addElement($formmnote); |
||
| 132 | } |
||
| 133 | $sform->addElement($editor_lead, false); |
||
| 134 | |||
| 135 | // TEASER |
||
| 136 | $sform->addElement(new \XoopsFormTextArea(_AM_SOAPBOX_ARTTEASER, 'teaser', $e_articles['teaser'], 10, 120)); |
||
| 137 | // $editor_teaser=soapbox_getWysiwygForm($helper->getConfig('editorUser') , _AM_SOAPBOX_ARTTEASER ,'teaser', $teaser , '100%', '120px'); |
||
| 138 | // $sform->addElement($editor_teaser,true); |
||
| 139 | // |
||
| 140 | $autoteaser_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_AUTOTEASER, 'autoteaser', 0, ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 141 | $sform->addElement($autoteaser_radio); |
||
| 142 | $sform->addElement(new \XoopsFormText(_AM_SOAPBOX_AUTOTEASERAMOUNT, 'teaseramount', 4, 4, 100)); |
||
| 143 | |||
| 144 | // BODY |
||
| 145 | //HACK by domifara for Wysiwyg |
||
| 146 | // if (null !== ($helper->getConfig('editorUser')) ) { |
||
| 147 | // $editor=soapbox_getWysiwygForm($helper->getConfig('editorUser') , _AM_SOAPBOX_ARTBODY, 'bodytext', $e_articles['bodytext'], '100%', '400px'); |
||
| 148 | // $sform->addElement($editor,true); |
||
| 149 | // } else { |
||
| 150 | // $sform -> addElement( new \XoopsFormDhtmlTextArea( _AM_SOAPBOX_ARTBODY, 'bodytext', $e_articles['bodytext'], 20, 120 ) ); |
||
| 151 | // } |
||
| 152 | |||
| 153 | $optionsTrayNote = new \XoopsFormElementTray(_AM_SOAPBOX_ARTBODY, '<br>'); |
||
| 154 | if (class_exists('XoopsFormEditor')) { |
||
| 155 | $options['name'] = 'bodytext'; |
||
| 156 | $options['value'] = $e_articles['bodytext']; |
||
| 157 | $options['rows'] = 5; |
||
| 158 | $options['cols'] = '100%'; |
||
| 159 | $options['width'] = '100%'; |
||
| 160 | $options['height'] = '400px'; |
||
| 161 | $bodynote = new \XoopsFormEditor('', $helper->getConfig('editorUser'), $options, $nohtml = false, $onfailure = 'textarea'); |
||
| 162 | $optionsTrayNote->addElement($bodynote); |
||
| 163 | } else { |
||
| 164 | $bodynote = new \XoopsFormDhtmlTextArea('', 'formmnote', $item->getVar('formmnote', 'e'), '100%', '100%'); |
||
| 165 | $optionsTrayNote->addElement($bodynote); |
||
| 166 | } |
||
| 167 | $sform->addElement($optionsTrayNote, false); |
||
| 168 | |||
| 169 | // IMAGE |
||
| 170 | // The article CAN have its own image :) |
||
| 171 | // First, if the article's image doesn't exist, set its value to the blank file |
||
| 172 | if (empty($e_articles['artimage']) |
||
| 173 | || !file_exists(XOOPS_ROOT_PATH . '/' . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir')) . '/' . $e_articles['artimage'])) { |
||
| 174 | $artimage = 'blank.png'; |
||
| 175 | } |
||
| 176 | // Code to create the image selector |
||
| 177 | $graph_array = \XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . '/' . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir'))); |
||
| 178 | $artimage_select = new \XoopsFormSelect('', 'artimage', $e_articles['artimage']); |
||
| 179 | $artimage_select->addOptionArray($graph_array); |
||
| 180 | $artimage_select->setExtra("onchange='showImgSelected(\"image5\", \"artimage\", \"" . $helper->getConfig('sbuploaddir') . '", "", "' . XOOPS_URL . "\")'"); |
||
| 181 | $artimage_tray = new \XoopsFormElementTray(_AM_SOAPBOX_SELECT_IMG, ' '); |
||
| 182 | $artimage_tray->addElement($artimage_select); |
||
| 183 | $artimage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . '/' . $myts->htmlSpecialChars($helper->getConfig('sbuploaddir')) . '/' . $e_articles['artimage'] . "' name='image5' id='image5' alt=''>")); |
||
| 184 | $sform->addElement($artimage_tray); |
||
| 185 | |||
| 186 | // Code to call the file browser to select an image to upload |
||
| 187 | $sform->addElement(new \XoopsFormFile(_AM_SOAPBOX_UPLOADIMAGE, 'cimage', (int)$helper->getConfig('maxfilesize')), false); |
||
| 188 | |||
| 189 | // WEIGHT |
||
| 190 | $sform->addElement(new \XoopsFormText(_AM_SOAPBOX_WEIGHT, 'weight', 4, 4, $e_articles['weight'])); |
||
| 191 | //---------- |
||
| 192 | // datesub |
||
| 193 | //---------- |
||
| 194 | //$datesub_caption = $myts->htmlSpecialChars( formatTimestamp( $e_articles['datesub'] , $helper->getConfig('dateformat')) . "=>"); |
||
| 195 | //$datesub_tray = new \XoopsFormDateTime( _AM_SOAPBOX_POSTED.'<br>' . $datesub_caption ,'datesub' , 15, time()) ; |
||
| 196 | $datesub_tray = new \XoopsFormDateTime(_AM_SOAPBOX_POSTED . '<br>', 'datesub', 15, $e_articles['datesub']); |
||
| 197 | |||
| 198 | // you don't want to change datesub |
||
| 199 | // $datesubnochage_checkbox = new \XoopsFormCheckBox( _AM_SOAPBOX_DATESUBNOCHANGE, 'datesubnochage', 0 ); |
||
| 200 | // $datesubnochage_checkbox->addOption(1, _AM_SOAPBOX_YES); |
||
| 201 | // $datesub_tray -> addElement( $datesubnochage_checkbox ); |
||
| 202 | $sform->addElement($datesub_tray); |
||
| 203 | //----------- |
||
| 204 | // Тэги |
||
| 205 | if (xoops_getModuleOption('usetag', 'soapbox')) { |
||
| 206 | $moduleHandler = xoops_getHandler('module'); |
||
| 207 | $tagsModule = $moduleHandler->getByDirname('tag'); |
||
| 208 | if (is_object($tagsModule)) { |
||
| 209 | require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php'; |
||
| 210 | $itemid = \Xmf\Request::getInt('articleID', 0, 'GET'); |
||
| 211 | $catid = 0; |
||
| 212 | $sform->addElement(new \XoopsModules\Tag\FormTag('item_tag', 60, 255, $itemid, $catid = 0)); |
||
| 213 | } |
||
| 214 | } |
||
| 215 | // COMMENTS |
||
| 216 | if (isset($GLOBALS['xoopsModuleConfig']['globaldisplaycomments']) |
||
| 217 | && 1 === $GLOBALS['xoopsModuleConfig']['globaldisplaycomments']) { |
||
| 218 | // COMMENTS |
||
| 219 | // Code to allow comments |
||
| 220 | $addcommentable_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_ALLOWCOMMENTS, 'commentable', $e_articles['commentable'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 221 | $sform->addElement($addcommentable_radio); |
||
| 222 | } |
||
| 223 | |||
| 224 | // OFFLINE |
||
| 225 | // Code to take article offline, for maintenance purposes |
||
| 226 | $offline_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_SWITCHOFFLINE, 'offline', $e_articles['offline'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 227 | $sform->addElement($offline_radio); |
||
| 228 | |||
| 229 | // ARTICLE IN BLOCK |
||
| 230 | // Code to put article in block |
||
| 231 | $block_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_BLOCK, 'block', $e_articles['block'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 232 | $sform->addElement($block_radio); |
||
| 233 | |||
| 234 | // notification public |
||
| 235 | $notifypub_radio = new \XoopsFormRadioYN(_AM_SOAPBOX_NOTIFY, 'notifypub', $e_articles['notifypub'], ' ' . _AM_SOAPBOX_YES . '', ' ' . _AM_SOAPBOX_NO . ''); |
||
| 236 | $sform->addElement($notifypub_radio); |
||
| 237 | |||
| 238 | // VARIOUS OPTIONS |
||
| 239 | //---------- |
||
| 240 | $options_tray = new \XoopsFormElementTray(_AM_SOAPBOX_OPTIONS, '<br>'); |
||
| 241 | |||
| 242 | $html_checkbox = new \XoopsFormCheckBox('', 'html', $e_articles['html']); |
||
| 243 | $html_checkbox->addOption(1, _AM_SOAPBOX_DOHTML); |
||
| 244 | $options_tray->addElement($html_checkbox); |
||
| 245 | |||
| 246 | $smiley_checkbox = new \XoopsFormCheckBox('', 'smiley', $e_articles['smiley']); |
||
| 247 | $smiley_checkbox->addOption(1, _AM_SOAPBOX_DOSMILEY); |
||
| 248 | $options_tray->addElement($smiley_checkbox); |
||
| 249 | |||
| 250 | $xcodes_checkbox = new \XoopsFormCheckBox('', 'xcodes', $e_articles['xcodes']); |
||
| 251 | $xcodes_checkbox->addOption(1, _AM_SOAPBOX_DOXCODE); |
||
| 252 | $options_tray->addElement($xcodes_checkbox); |
||
| 253 | |||
| 254 | $breaks_checkbox = new \XoopsFormCheckBox('', 'breaks', $e_articles['breaks']); |
||
| 255 | $breaks_checkbox->addOption(1, _AM_SOAPBOX_BREAKS); |
||
| 256 | $options_tray->addElement($breaks_checkbox); |
||
| 257 | |||
| 258 | $sform->addElement($options_tray); |
||
| 259 | //---------- |
||
| 260 | |||
| 261 | $sform->addElement(new \XoopsFormHidden('articleID', $e_articles['articleID'])); |
||
| 262 | |||
| 263 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 264 | $hidden = new \XoopsFormHidden('op', 'addart'); |
||
| 265 | $buttonTray->addElement($hidden); |
||
| 266 | |||
| 267 | if (!$e_articles['articleID']) { // there's no articleID? Then it's a new article |
||
| 268 | $butt_create = new \XoopsFormButton('', '', _AM_SOAPBOX_CREATE, 'submit'); |
||
| 269 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addart\'"'); |
||
| 270 | $buttonTray->addElement($butt_create); |
||
| 271 | |||
| 272 | $butt_clear = new \XoopsFormButton('', '', _AM_SOAPBOX_CLEAR, 'reset'); |
||
| 273 | $buttonTray->addElement($butt_clear); |
||
| 274 | |||
| 275 | $butt_cancel = new \XoopsFormButton('', '', _AM_SOAPBOX_CANCEL, 'button'); |
||
| 276 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 277 | $buttonTray->addElement($butt_cancel); |
||
| 278 | } else { // else, we're editing an existing article |
||
| 550 |