Conditions | 14 |
Paths | 32 |
Total Lines | 167 |
Lines | 11 |
Ratio | 6.59 % |
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 |
||
27 | function template_searchform() |
||
28 | { |
||
29 | global $context, $settings, $txt, $scripturl, $modSettings; |
||
30 | |||
31 | echo ' |
||
32 | <form id="searchform" action="', $scripturl, '?action=search;sa=results" method="post" accept-charset="UTF-8" name="searchform"> |
||
33 | <h2 class="category_header', !empty($settings['use_buttons']) ? ' hdicon cat_img_search' : '', '"> |
||
34 | ', $txt['set_parameters'], ' |
||
35 | </h2>'; |
||
36 | |||
37 | // Any search errors to inform the user about |
||
38 | View Code Duplication | if (!empty($context['search_errors'])) |
|
39 | echo ' |
||
40 | <p class="errorbox">', implode('<br />', $context['search_errors']['messages']), '</p>'; |
||
41 | |||
42 | // Start off showing our basic search form |
||
43 | echo ' |
||
44 | <fieldset id="simple_search" class="content"> |
||
45 | <div id="search_term_input"> |
||
46 | <label for="search"> |
||
47 | <strong>', $txt['search_for'], '</strong> |
||
48 | </label>: |
||
49 | <input type="search" id="search" class="input_text" name="search" value="', $context['search_params']['search'], '" maxlength="', $context['search_string_limit'], '" size="40" placeholder="' . $txt['search'] . '" required="required" autofocus="autofocus" />', ' |
||
50 | <input id="submit" type="submit" name="s_search" value="' . $txt['search'] . '" /> |
||
51 | </div>'; |
||
52 | |||
53 | if (empty($modSettings['search_simple_fulltext'])) |
||
54 | echo ' |
||
55 | <p class="smalltext">', $txt['search_example'], '</p>'; |
||
56 | |||
57 | // Does the search require a visual verification screen to annoy them? |
||
58 | View Code Duplication | if (!empty($context['require_verification'])) |
|
59 | { |
||
60 | template_verification_controls($context['visual_verification_id'], ' |
||
61 | <div class="verification"> |
||
62 | <strong>' . $txt['search_visual_verification_label'] . ':</strong> |
||
63 | <br />', ' |
||
64 | </div>'); |
||
65 | } |
||
66 | |||
67 | // All of the advanced options, this div is collapsed by the JS when available |
||
68 | echo ' |
||
69 | <div id="advanced_search"> |
||
70 | <dl id="search_options"> |
||
71 | <dt class="righttext"><label for="searchtype"> |
||
72 | ', $txt['search_match'], ':</label> |
||
73 | </dt> |
||
74 | <dd> |
||
75 | <select name="searchtype" id="searchtype"> |
||
76 | <option value="1"', empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['all_words'], '</option> |
||
77 | <option value="2"', !empty($context['search_params']['searchtype']) ? ' selected="selected"' : '', '>', $txt['any_words'], '</option> |
||
78 | </select> |
||
79 | </dd> |
||
80 | <dt class="righttext"> |
||
81 | <label for="userspec">', $txt['by_user'], ':</label> |
||
82 | </dt> |
||
83 | <dd> |
||
84 | <input id="userspec" type="text" name="userspec" value="', $context['search_params']['userspec'], '" size="40" class="input_text" /> |
||
85 | </dd> |
||
86 | <dt class="righttext"> |
||
87 | <label for="sort">', $txt['search_order'], ':</label> |
||
88 | </dt> |
||
89 | <dd> |
||
90 | <select id="sort" name="sort"> |
||
91 | <option value="relevance|desc">', $txt['search_orderby_relevant_first'], '</option> |
||
92 | <option value="num_replies|desc">', $txt['search_orderby_large_first'], '</option> |
||
93 | <option value="num_replies|asc">', $txt['search_orderby_small_first'], '</option> |
||
94 | <option value="id_msg|desc">', $txt['search_orderby_recent_first'], '</option> |
||
95 | <option value="id_msg|asc">', $txt['search_orderby_old_first'], '</option> |
||
96 | </select> |
||
97 | </dd> |
||
98 | <dt class="righttext options"> |
||
99 | ', $txt['search_options'], ': |
||
100 | </dt> |
||
101 | <dd class="options"> |
||
102 | <input type="checkbox" name="show_complete" id="show_complete" value="1"', !empty($context['search_params']['show_complete']) ? ' checked="checked"' : '', ' /> |
||
103 | <label for="show_complete">', $txt['search_show_complete_messages'], '</label><br /> |
||
104 | <input type="checkbox" name="subject_only" id="subject_only" value="1"', !empty($context['search_params']['subject_only']) ? ' checked="checked"' : '', ' /> |
||
105 | <label for="subject_only">', $txt['search_subject_only'], '</label> |
||
106 | </dd> |
||
107 | <dt class="righttext between"> |
||
108 | ', $txt['search_post_age'], ': |
||
109 | </dt> |
||
110 | <dd> |
||
111 | <label for="minage">', $txt['search_between'], '</label> |
||
112 | <input type="text" name="minage" id="minage" value="', $context['search_params']['minage'], '" size="5" maxlength="4" class="input_text" /> |
||
113 | <label for="maxage">', $txt['search_and'], ' </label> |
||
114 | <input type="text" name="maxage" id="maxage" value="', $context['search_params']['maxage'], '" size="5" maxlength="4" class="input_text" /> ', $txt['days_word'], ' |
||
115 | </dd> |
||
116 | </dl> |
||
117 | </div> |
||
118 | <a id="upshrink_link" href="', $scripturl, '?action=search;advanced" class="linkbutton hide">', $txt['search_simple'], '</a>'; |
||
119 | |||
120 | // Set the initial search style for the form |
||
121 | echo ' |
||
122 | <input id="advanced" type="hidden" name="advanced" value="1" />'; |
||
123 | |||
124 | // If $context['search_params']['topic'] is set, that means we're searching just one topic. |
||
125 | if (!empty($context['search_params']['topic'])) |
||
126 | echo ' |
||
127 | <p>', $txt['search_specific_topic'], ' "', $context['search_topic']['link'], '".</p> |
||
128 | <input type="hidden" name="topic" value="', $context['search_topic']['id'], '" />'; |
||
129 | |||
130 | echo ' |
||
131 | </fieldset>'; |
||
132 | |||
133 | // This starts our selection area to allow searching by specific boards |
||
134 | if (empty($context['search_params']['topic'])) |
||
135 | { |
||
136 | echo ' |
||
137 | <fieldset id="pick_boards" class="content">'; |
||
138 | |||
139 | template_pick_boards('searchform'); |
||
140 | |||
141 | echo ' |
||
142 | </fieldset>'; |
||
143 | } |
||
144 | |||
145 | echo ' |
||
146 | </form>'; |
||
147 | |||
148 | // And now all the JS to make this work |
||
149 | addInlineJavascript(' |
||
150 | createEventListener(window); |
||
151 | window.addEventListener("load", initSearch, false); |
||
152 | |||
153 | var oAddMemberSuggest = new smc_AutoSuggest({ |
||
154 | sSelf: \'oAddMemberSuggest\', |
||
155 | sSessionId: elk_session_id, |
||
156 | sSessionVar: elk_session_var, |
||
157 | sControlId: \'userspec\', |
||
158 | sSearchType: \'member\', |
||
159 | bItemList: false |
||
160 | }); |
||
161 | |||
162 | // Set the search style |
||
163 | document.getElementById(\'advanced\').value = "' . (empty($context['minmax_preferences']['asearch']) ? '1' : '0') . '"; |
||
164 | |||
165 | // And allow for the collapsing of the advanced search options |
||
166 | var oSearchToggle = new elk_Toggle({ |
||
167 | bToggleEnabled: true, |
||
168 | bCurrentlyCollapsed: ' . (empty($context['minmax_preferences']['asearch']) ? 'false' : 'true') . ', |
||
169 | funcOnBeforeCollapse: function () { |
||
170 | document.getElementById(\'advanced\').value = \'0\'; |
||
171 | }, |
||
172 | funcOnBeforeExpand: function () { |
||
173 | document.getElementById(\'advanced\').value = \'1\'; |
||
174 | }, |
||
175 | aSwappableContainers: [ |
||
176 | \'advanced_search\' |
||
177 | ], |
||
178 | aSwapLinks: [ |
||
179 | { |
||
180 | sId: \'upshrink_link\', |
||
181 | msgExpanded: ' . JavaScriptEscape($txt['search_simple']) . ', |
||
182 | msgCollapsed: ' . JavaScriptEscape($txt['search_advanced']) . ' |
||
183 | } |
||
184 | ], |
||
185 | oThemeOptions: { |
||
186 | bUseThemeSettings: ' . ($context['user']['is_guest'] ? 'false' : 'true') . ', |
||
187 | sOptionName: \'minmax_preferences\', |
||
188 | sSessionId: elk_session_id, |
||
189 | sSessionVar: elk_session_var, |
||
190 | sAdditionalVars: \';minmax_key=asearch\' |
||
191 | }, |
||
192 | });', true); |
||
193 | } |
||
194 | |||
441 | } |