| Conditions | 4 |
| Paths | 4 |
| Total Lines | 100 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 103 | function manageForm($default, $select_from_user_list = null, $sent_to = '', $tpl = null) |
||
| 104 | { |
||
| 105 | $form = new FormValidator( |
||
| 106 | 'compose_message', |
||
| 107 | null, |
||
| 108 | api_get_self(), |
||
| 109 | null, |
||
| 110 | ['enctype' => 'multipart/form-data'] |
||
| 111 | ); |
||
| 112 | |||
| 113 | $form->addText('title', get_lang('Subject')); |
||
| 114 | $form->addHtmlEditor( |
||
| 115 | 'content', |
||
| 116 | get_lang('Message'), |
||
| 117 | false, |
||
| 118 | false, |
||
| 119 | ['ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250', 'style' => true] |
||
| 120 | ); |
||
| 121 | |||
| 122 | $form->addLabel( |
||
| 123 | '', |
||
| 124 | '<div id="file_uploads"><div id="filepath_1"> |
||
| 125 | <div id="filepaths" class="form-horizontal"> |
||
| 126 | <div id="paths-file" class="form-group"> |
||
| 127 | <label class="col-sm-4">'.get_lang('Files attachments').'</label> |
||
| 128 | <input class="col-sm-8" type="file" name="attach_1"/> |
||
| 129 | </div> |
||
| 130 | </div> |
||
| 131 | <div id="paths-description" class="form-group"> |
||
| 132 | <label class="col-sm-4">'.get_lang('Description').'</label> |
||
| 133 | <div class="col-sm-8"> |
||
| 134 | <input id="file-descrtiption" class="form-control" type="text" name="legend[]" /> |
||
| 135 | </div> |
||
| 136 | </div> |
||
| 137 | </div> |
||
| 138 | </div>' |
||
| 139 | ); |
||
| 140 | |||
| 141 | $form->addLabel( |
||
| 142 | '', |
||
| 143 | '<span id="link-more-attach"><a class="btn btn-default" href="javascript://" onclick="return add_image_form()">'. |
||
| 144 | get_lang('Add one more file').'</a></span> ('. |
||
| 145 | sprintf( |
||
| 146 | get_lang('Maximun file size: %s'), |
||
| 147 | format_file_size(api_get_setting('message_max_upload_filesize')) |
||
| 148 | ).')' |
||
| 149 | ); |
||
| 150 | |||
| 151 | $form->addButtonSend(get_lang('Send message'), 'compose'); |
||
| 152 | $form->setRequiredNote('<span class="form_required">*</span> <small>'.get_lang('Required field').'</small>'); |
||
| 153 | |||
| 154 | $form->setDefaults($default); |
||
| 155 | $html = ''; |
||
| 156 | if ($form->validate()) { |
||
| 157 | $check = true; |
||
| 158 | if ($check) { |
||
| 159 | $file_comments = $_POST['legend']; |
||
| 160 | $title = $default['title']; |
||
| 161 | $content = $default['content']; |
||
| 162 | |||
| 163 | $res = MessageManager::send_message( |
||
| 164 | api_get_user_id(), |
||
| 165 | $title, |
||
| 166 | $content, |
||
| 167 | $_FILES, |
||
| 168 | $file_comments, |
||
| 169 | 0, |
||
| 170 | 0, |
||
| 171 | 0, |
||
| 172 | 0, |
||
| 173 | null, |
||
| 174 | false, |
||
| 175 | 0, |
||
| 176 | [], |
||
| 177 | true, |
||
| 178 | null, |
||
| 179 | MESSAGE_STATUS_PROMOTED |
||
| 180 | ); |
||
| 181 | |||
| 182 | if ($res) { |
||
| 183 | Display::addFlash(Display::return_message( |
||
| 184 | get_lang('Message Sent'), |
||
| 185 | 'confirmation', |
||
| 186 | false |
||
| 187 | )); |
||
| 188 | } |
||
| 189 | |||
| 190 | MessageManager::cleanAudioMessage(); |
||
| 191 | } |
||
| 192 | Security::clear_token(); |
||
| 193 | header('Location: '.api_get_path(WEB_PATH).'main/social/promoted_messages.php'); |
||
| 194 | exit; |
||
| 195 | } else { |
||
| 196 | $token = Security::get_token(); |
||
| 197 | $form->addElement('hidden', 'sec_token'); |
||
| 198 | $form->setConstants(['sec_token' => $token]); |
||
| 199 | $html .= $form->returnForm(); |
||
| 200 | } |
||
| 201 | |||
| 202 | return $html; |
||
| 203 | } |
||
| 262 |