Conditions | 35 |
Paths | > 20000 |
Total Lines | 276 |
Code Lines | 196 |
Lines | 25 |
Ratio | 9.06 % |
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 |
||
34 | function edit($lid = 0) |
||
35 | { |
||
36 | global $xoopsDB, $xtubemyts, $mytree, $xtubeImageArray, $xoopsModuleConfig; |
||
37 | |||
38 | $sql = 'SELECT * FROM ' . $xoopsDB->prefix('xoopstube_videos') . ' WHERE lid=' . $lid; |
||
39 | if (!$result = $xoopsDB->query($sql)) { |
||
40 | XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__); |
||
41 | |||
42 | return false; |
||
43 | } |
||
44 | $video_array = $xoopsDB->fetchArray($xoopsDB->query($sql)); |
||
45 | $directory = $xoopsModuleConfig['videoimgdir']; |
||
46 | $lid = $video_array['lid'] ? $video_array['lid'] : 0; |
||
47 | $cid = $video_array['cid'] ? $video_array['cid'] : 0; |
||
48 | $title = $video_array['title'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['title']) : ''; |
||
49 | $vidid = $video_array['vidid'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['vidid']) : ''; |
||
50 | $picurl = $video_array['picurl'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['picurl']) : 'http://'; |
||
51 | $publisher = $video_array['publisher'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['publisher']) : ''; |
||
52 | $screenshot = $video_array['screenshot'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['screenshot']) : ''; |
||
53 | $descriptionb = $video_array['description'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['description']) : ''; |
||
54 | $published = $video_array['published'] ? $video_array['published'] : time(); |
||
55 | $expired = $video_array['expired'] ? $video_array['expired'] : 0; |
||
56 | $updated = $video_array['updated'] ? $video_array['updated'] : 0; |
||
57 | $offline = $video_array['offline'] ? $video_array['offline'] : 0; |
||
58 | $vidsource = $video_array['vidsource'] ? $video_array['vidsource'] : 0; |
||
59 | $ipaddress = $video_array['ipaddress'] ? $video_array['ipaddress'] : 0; |
||
60 | $notifypub = $video_array['notifypub'] ? $video_array['notifypub'] : 0; |
||
61 | $time = $video_array['time'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['time']) : '0:00:00'; |
||
62 | $keywords = $video_array['keywords'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['keywords']) : ''; |
||
63 | $item_tag = $video_array['item_tag'] ? $xtubemyts->htmlSpecialCharsStrip($video_array['item_tag']) : ''; |
||
64 | |||
65 | include_once __DIR__ . '/admin_header.php'; |
||
66 | xoops_cp_header(); |
||
67 | //xtubeRenderAdminMenu( _AM_XOOPSTUBE_MVIDEOS ); |
||
68 | |||
69 | if ($lid) { |
||
70 | $_vote_data = xtubeGetVoteDetails($lid); |
||
71 | $text_info |
||
72 | = ' |
||
73 | <table width="100%" style="font-size: 90%;"> |
||
74 | <tr> |
||
75 | <td style="width: 25%; border-right: #E8E8E8 1px solid; vertical-align: top; padding-left: 10px;"> |
||
76 | <div><b>' . _AM_XOOPSTUBE_VIDEO_ID . ' </b>' . $lid . '</div> |
||
77 | <div><b>' . _AM_XOOPSTUBE_MINDEX_SUBMITTED . ': </b>' . xtubeGetTimestamp( |
||
78 | formatTimestamp($video_array['date'], $xoopsModuleConfig['dateformat']) |
||
79 | ) . '</div> |
||
80 | <div><b>' . _AM_XOOPSTUBE_MOD_MODIFYSUBMITTER . ' </b>' . xtubeGetLinkedUserNameFromId( |
||
81 | $video_array['submitter'] |
||
82 | ) . '</div> |
||
83 | <div><b>' . _AM_XOOPSTUBE_VIDEO_IP . ' </b>' . $ipaddress . '</div> |
||
84 | <div><b>' . _AM_XOOPSTUBE_VIDEO_VIEWS . ' </b>' . $video_array['hits'] . '</div> |
||
85 | </td> |
||
86 | <td style="width: 25%; border-right: #E8E8E8 1px solid; vertical-align: top; padding-left: 10px;"> |
||
87 | <div><b>' . _AM_XOOPSTUBE_VOTE_TOTALRATE . ': </b>' . intval($_vote_data['rate']) . '</div> |
||
88 | <div><b>' . _AM_XOOPSTUBE_VOTE_USERAVG . ': </b>' . intval(round($_vote_data['avg_rate'], 2)) . '</div> |
||
89 | <div><b>' . _AM_XOOPSTUBE_VOTE_MAXRATE . ': </b>' . intval($_vote_data['min_rate']) . '</div> |
||
90 | <div><b>' . _AM_XOOPSTUBE_VOTE_MINRATE . ': </b>' . intval($_vote_data['max_rate']) . '</div> |
||
91 | </td> |
||
92 | <td style="width: 25%; border-right: #E8E8E8 1px solid; vertical-align: top; padding-left: 10px;"> |
||
93 | <div><b>' . _AM_XOOPSTUBE_VOTE_MOSTVOTEDTITLE . ': </b>' . intval($_vote_data['max_title']) . '</div> |
||
94 | <div><b>' . _AM_XOOPSTUBE_VOTE_LEASTVOTEDTITLE . ': </b>' . intval($_vote_data['min_title']) . '</div> |
||
95 | <div><b>' . _AM_XOOPSTUBE_VOTE_REGISTERED . ': </b>' . (intval( |
||
96 | $_vote_data['rate'] - $_vote_data['null_ratinguser'] |
||
97 | )) . '</div> |
||
98 | <div><b>' . _AM_XOOPSTUBE_VOTE_NONREGISTERED . ': </b>' . intval($_vote_data['null_ratinguser']) . '</div> |
||
99 | </td> |
||
100 | <td style="width: 25%; vertical-align: top; padding-left: 10px;"> |
||
101 | <div>' . xtubeGetVideoThumb( |
||
102 | $video_array['vidid'], |
||
103 | $video_array['title'], |
||
104 | $video_array['vidsource'], |
||
105 | $video_array['picurl'], |
||
106 | $video_array['screenshot'] |
||
107 | ) . '</div> |
||
108 | </td> |
||
109 | </tr> |
||
110 | </table>'; |
||
111 | echo ' |
||
112 | <fieldset style="border: #E8E8E8 1px solid;"><legend style="display: inline; font-weight: bold; color: #0A3760;">' . _AM_XOOPSTUBE_INFORMATION . '</legend> |
||
113 | <div style="padding: 8px;">' . $text_info . '</div> |
||
114 | <!-- <div style="padding: 8px;"><li>' . $xtubeImageArray['deleteimg'] . ' ' . _AM_XOOPSTUBE_VOTE_DELETEDSC . '</li></div>\n --> |
||
115 | </fieldset> |
||
116 | <br />'; |
||
117 | } |
||
118 | unset($_vote_data); |
||
119 | |||
120 | $caption = ($lid) ? _AM_XOOPSTUBE_VIDEO_MODIFYFILE : _AM_XOOPSTUBE_VIDEO_CREATENEWFILE; |
||
121 | |||
122 | $sform = new XoopsThemeForm($caption, 'storyform', xoops_getenv('PHP_SELF')); |
||
123 | $sform->setExtra('enctype="multipart / form - data"'); |
||
124 | |||
125 | // Video title |
||
126 | $sform->addElement(new XoopsFormText(_AM_XOOPSTUBE_VIDEO_TITLE, 'title', 70, 255, $title), true); |
||
127 | |||
128 | // Video source |
||
129 | $vidsource_array = array( |
||
130 | 0 => _AM_XOOPSTUBE_YOUTUBE, |
||
131 | 1 => _AM_XOOPSTUBE_METACAFE, |
||
132 | 2 => _AM_XOOPSTUBE_IFILM, |
||
133 | 3 => _AM_XOOPSTUBE_PHOTOBUCKET, |
||
134 | 4 => _AM_XOOPSTUBE_VIDDLER, |
||
135 | 100 => _AM_XOOPSTUBE_GOOGLEVIDEO, |
||
136 | 101 => _AM_XOOPSTUBE_MYSPAVETV, |
||
137 | 102 => _AM_XOOPSTUBE_DAILYMOTION, |
||
138 | 103 => _AM_XOOPSTUBE_BLIPTV, |
||
139 | 104 => _AM_XOOPSTUBE_CLIPFISH, |
||
140 | 105 => _AM_XOOPSTUBE_LIVELEAK, |
||
141 | 106 => _AM_XOOPSTUBE_MAKTOOB, |
||
142 | 107 => _AM_XOOPSTUBE_VEOH, |
||
143 | 108 => _AM_XOOPSTUBE_VIMEO, |
||
144 | 109 => _MD_XOOPSTUBE_MEGAVIDEO, |
||
145 | 200 => _MD_XOOPSTUBE_XOOPSTUBE |
||
146 | ); // #200 is reserved for XoopsTube's internal FLV player |
||
147 | $vidsource_select = new XoopsFormSelect(_AM_XOOPSTUBE_VIDSOURCE, 'vidsource', $vidsource); |
||
148 | $vidsource_select->addOptionArray($vidsource_array); |
||
149 | $sform->addElement($vidsource_select); |
||
150 | |||
151 | // Video code |
||
152 | $videocode = new XoopsFormText(_AM_XOOPSTUBE_VIDEO_DLVIDID, 'vidid', 70, 512, $vidid); |
||
153 | $videocode->setDescription('<br /><span style="font-size: small;">' . _AM_XOOPSTUBE_VIDEO_DLVIDIDDSC . '</span>'); |
||
154 | $sform->addElement($videocode, true); |
||
155 | $note = _AM_XOOPSTUBE_VIDEO_DLVIDID_NOTE; |
||
156 | $sform->addElement(new XoopsFormLabel('', $note)); |
||
157 | |||
158 | // Picture url |
||
159 | $picurl = new XoopsFormText(_AM_XOOPSTUBE_VIDEO_PICURL, 'picurl', 70, 255, $picurl); |
||
160 | $picurl->setDescription( |
||
161 | '<br /><span style="font-weight: normal;font-size: smaller;">' . _AM_XOOPSTUBE_VIDEO_PICURLNOTE . '</span>' |
||
162 | ); |
||
163 | $sform->addElement($picurl, false); |
||
164 | |||
165 | // Video publisher |
||
166 | $sform->addElement(new XoopsFormText(_AM_XOOPSTUBE_VIDEO_PUBLISHER, 'publisher', 70, 255, $publisher), true); |
||
167 | |||
168 | // Time form |
||
169 | $timeform = new XoopsFormText(_AM_XOOPSTUBE_TIME, 'time', 7, 7, $time); |
||
170 | $timeform->setDescription('<span style="font-size: small;">(h:mm:ss)</span>'); |
||
171 | $sform->addElement($timeform, false); |
||
172 | |||
173 | // Category menu |
||
174 | ob_start(); |
||
175 | $mytree->makeMySelBox('title', 'title', $cid, 0); |
||
176 | $sform->addElement(new XoopsFormLabel(_AM_XOOPSTUBE_VIDEO_CATEGORY, ob_get_contents())); |
||
177 | ob_end_clean(); |
||
178 | |||
179 | // Description form |
||
180 | // $editor = xtube_getWysiwygForm( _AM_XOOPSTUBE_VIDEO_DESCRIPTION, 'descriptionb', $descriptionb ); |
||
181 | // $sform -> addElement( $editor, false ); |
||
182 | |||
183 | $optionsTrayNote = new XoopsFormElementTray(_AM_XOOPSTUBE_VIDEO_DESCRIPTION, '<br />'); |
||
184 | View Code Duplication | if (class_exists('XoopsFormEditor')) { |
|
185 | $options['name'] = 'descriptionb'; |
||
186 | $options['value'] = $descriptionb; |
||
187 | $options['rows'] = 5; |
||
188 | $options['cols'] = '100%'; |
||
189 | $options['width'] = '100%'; |
||
190 | $options['height'] = '200px'; |
||
191 | $descriptionb = new XoopsFormEditor('', $xoopsModuleConfig['form_options'], $options, $nohtml = false, $onfailure = 'textarea'); |
||
192 | $optionsTrayNote->addElement($descriptionb); |
||
193 | } else { |
||
194 | $descriptionb = new XoopsFormDhtmlTextArea( |
||
195 | '', 'descriptionb', $item->getVar( |
||
196 | 'descriptionb', |
||
197 | 'e' |
||
198 | ), '100%', '100%' |
||
199 | ); |
||
200 | $optionsTrayNote->addElement($descriptionb); |
||
201 | } |
||
202 | |||
203 | $sform->addElement($optionsTrayNote, false); |
||
204 | |||
205 | // Meta keywords form |
||
206 | $keywords = new XoopsFormTextArea(_AM_XOOPSTUBE_KEYWORDS, 'keywords', $keywords, 7, 60, false); |
||
207 | $keywords->setDescription( |
||
208 | "<br /><br /><br /><br /><span style='font-size: smaller;'>" . _AM_XOOPSTUBE_KEYWORDS_NOTE . "</span>" |
||
209 | ); |
||
210 | $sform->addElement($keywords); |
||
211 | |||
212 | // Insert tags if Tag-module is installed |
||
213 | View Code Duplication | if (xtubeIsModuleTagInstalled()) { |
|
214 | include_once XOOPS_ROOT_PATH . "/modules/tag/include/formtag.php"; |
||
215 | $text_tags = new XoopsFormTag("item_tag", 70, 255, $video_array['item_tag'], 0); |
||
216 | $sform->addElement($text_tags); |
||
217 | } else { |
||
218 | $sform->addElement(new XoopsFormHidden('item_tag', $video_array['item_tag'])); |
||
219 | } |
||
220 | |||
221 | // Video Publish Date |
||
222 | $sform->addElement(new XoopsFormDateTime(_AM_XOOPSTUBE_VIDEO_SETPUBLISHDATE, 'published', $size = 15, $published)); |
||
223 | |||
224 | if ($lid) { |
||
225 | $sform->addElement(new XoopsFormHidden('was_published', $published)); |
||
226 | $sform->addElement(new XoopsFormHidden('was_expired', $expired)); |
||
227 | } |
||
228 | |||
229 | // Video Expire Date |
||
230 | $isexpired = ($expired > time()) ? 1 : 0; |
||
231 | $expiredates = ($expired > time()) ? _AM_XOOPSTUBE_VIDEO_EXPIREDATESET . xtubeGetTimestamp( |
||
232 | formatTimestamp($expired, $xoopsModuleConfig['dateformat']) |
||
233 | ) : _AM_XOOPSTUBE_VIDEO_SETDATETIMEEXPIRE; |
||
234 | $warning = ($published > $expired && $expired > time()) ? _AM_XOOPSTUBE_VIDEO_EXPIREWARNING : ''; |
||
235 | $expiredate_checkbox = new XoopsFormCheckBox('', 'expiredateactivate', $isexpired); |
||
236 | $expiredate_checkbox->addOption(1, $expiredates . " <br /> <br /> "); |
||
237 | |||
238 | $expiredate_tray = new XoopsFormElementTray(_AM_XOOPSTUBE_VIDEO_EXPIREDATE . $warning, ''); |
||
239 | $expiredate_tray->addElement($expiredate_checkbox); |
||
240 | $expiredate_tray->addElement( |
||
241 | new XoopsFormDateTime(_AM_XOOPSTUBE_VIDEO_SETEXPIREDATE . " <br /> ", 'expired', 15, $expired) |
||
242 | ); |
||
243 | $expiredate_tray->addElement( |
||
244 | new XoopsFormRadioYN(_AM_XOOPSTUBE_VIDEO_CLEAREXPIREDATE, 'clearexpire', 0, ' ' . _YES . '', ' ' . _NO . '') |
||
245 | ); |
||
246 | $sform->addElement($expiredate_tray); |
||
247 | |||
248 | // Set video offline yes/no |
||
249 | $videostatus_radio = new XoopsFormRadioYN( |
||
250 | _AM_XOOPSTUBE_VIDEO_FILESSTATUS, 'offline', $offline, ' ' . _YES . '', ' ' . _NO . '' |
||
251 | ); |
||
252 | $sform->addElement($videostatus_radio); |
||
253 | |||
254 | // Set video status as updated yes/no |
||
255 | $up_dated = ($updated == 0) ? 0 : 1; |
||
256 | $video_updated_radio = new XoopsFormRadioYN( |
||
257 | _AM_XOOPSTUBE_VIDEO_SETASUPDATED, 'up_dated', $up_dated, ' ' . _YES . '', ' ' . _NO . '' |
||
258 | ); |
||
259 | $sform->addElement($video_updated_radio); |
||
260 | |||
261 | $result = $xoopsDB->query( |
||
262 | "SELECT COUNT( * ) FROM " . $xoopsDB->prefix('xoopstube_broken') . " WHERE lid = " . $lid |
||
263 | ); |
||
264 | list ($broken_count) = $xoopsDB->fetchRow($result); |
||
265 | if ($broken_count > 0) { |
||
266 | $video_updated_radio = new XoopsFormRadioYN( |
||
267 | _AM_XOOPSTUBE_VIDEO_DELEDITMESS, 'delbroken', 1, ' ' . _YES . '', ' ' . _NO . '' |
||
268 | ); |
||
269 | $sform->addElement($editmess_radio); |
||
270 | } |
||
271 | |||
272 | if ($lid && $published == 0) { |
||
273 | $approved = ($published == 0) ? 0 : 1; |
||
274 | $approve_checkbox = new XoopsFormCheckBox(_AM_XOOPSTUBE_VIDEO_EDITAPPROVE, "approved", 1); |
||
275 | $approve_checkbox->addOption(1, " "); |
||
276 | $sform->addElement($approve_checkbox); |
||
277 | } |
||
278 | |||
279 | if (!$lid) { |
||
280 | $button_tray = new XoopsFormElementTray('', ''); |
||
281 | $button_tray->addElement(new XoopsFormHidden('status', 1)); |
||
282 | $button_tray->addElement(new XoopsFormHidden('notifypub', $notifypub)); |
||
283 | $button_tray->addElement(new XoopsFormHidden('op', 'save')); |
||
284 | $button_tray->addElement(new XoopsFormButton('', '', _AM_XOOPSTUBE_BSAVE, 'submit')); |
||
285 | $sform->addElement($button_tray); |
||
286 | } else { |
||
287 | $button_tray = new XoopsFormElementTray('', ''); |
||
288 | $button_tray->addElement(new XoopsFormHidden('lid', $lid)); |
||
289 | $button_tray->addElement(new XoopsFormHidden('status', 2)); |
||
290 | $hidden = new XoopsFormHidden('op', 'save'); |
||
291 | $button_tray->addElement($hidden); |
||
292 | |||
293 | $butt_dup = new XoopsFormButton('', '', _AM_XOOPSTUBE_BMODIFY, 'submit'); |
||
294 | $butt_dup->setExtra('onclick="this . form . elements . op . value = \'save\'"'); |
||
295 | $button_tray->addElement($butt_dup); |
||
296 | $butt_dupct = new XoopsFormButton('', '', _AM_XOOPSTUBE_BDELETE, 'submit'); |
||
297 | $butt_dupct->setExtra('onclick="this.form.elements.op.value=\'delete\'"'); |
||
298 | $button_tray->addElement($butt_dupct); |
||
299 | $butt_dupct2 = new XoopsFormButton('', '', _AM_XOOPSTUBE_BCANCEL, 'submit'); |
||
300 | $butt_dupct2->setExtra('onclick="this.form.elements.op.value=\'videosConfigMenu\'"'); |
||
301 | $button_tray->addElement($butt_dupct2); |
||
302 | $sform->addElement($button_tray); |
||
303 | } |
||
304 | $sform->display(); |
||
305 | unset($hidden); |
||
306 | include_once __DIR__ . '/admin_footer.php'; |
||
307 | |||
308 | return null; |
||
309 | } |
||
310 | |||
673 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.