Conditions | 8 |
Paths | 11 |
Total Lines | 75 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
115 | function check_system_version() |
||
116 | { |
||
117 | // the chamilo version of your installation |
||
118 | $system_version = trim(api_get_configuration_value('system_version')); |
||
119 | |||
120 | if (ini_get('allow_url_fopen') == 1) { |
||
121 | // The number of courses |
||
122 | $number_of_courses = Statistics::countCourses(); |
||
123 | |||
124 | // The number of users |
||
125 | $number_of_users = Statistics::countUsers(); |
||
126 | $number_of_active_users = Statistics::countUsers(null, null, null, true); |
||
127 | |||
128 | // The number of sessions |
||
129 | $number_of_sessions = Statistics::countSessions(); |
||
130 | $packager = api_get_configuration_value('packager'); |
||
131 | if (empty($packager)) { |
||
132 | $packager = 'chamilo'; |
||
133 | } |
||
134 | |||
135 | $data = array( |
||
136 | 'url' => api_get_path(WEB_PATH), |
||
137 | 'campus' => api_get_setting('siteName'), |
||
138 | 'contact' => api_get_setting('emailAdministrator'), // the admin's e-mail, with the only purpose of being able to contact admins to inform about critical security issues |
||
139 | 'version' => $system_version, |
||
140 | 'numberofcourses' => $number_of_courses, // to sum up into non-personal statistics - see https://version.chamilo.org/stats/ |
||
141 | 'numberofusers' => $number_of_users, // to sum up into non-personal statistics |
||
142 | 'numberofactiveusers' => $number_of_active_users, // to sum up into non-personal statistics |
||
143 | 'numberofsessions' => $number_of_sessions, |
||
144 | //The donotlistcampus setting recovery should be improved to make |
||
145 | // it true by default - this does not affect numbers counting |
||
146 | 'donotlistcampus' => api_get_setting('donotlistcampus'), |
||
147 | 'organisation' => api_get_setting('Institution'), |
||
148 | 'language' => api_get_setting('platformLanguage'), //helps us know the spread of language usage for campuses, by main language |
||
149 | 'adminname' => api_get_setting('administratorName').' '.api_get_setting('administratorSurname'), //not sure this is necessary... |
||
150 | 'ip' => $_SERVER['REMOTE_ADDR'], //the admin's IP address, with the only purpose of trying to geolocate portals around the globe to draw a map |
||
151 | // Reference to the packager system or provider through which |
||
152 | // Chamilo is installed/downloaded. Packagers can change this in |
||
153 | // the default config file (main/install/configuration.dist.php) |
||
154 | // or in the installed config file. The default value is 'chamilo' |
||
155 | 'packager' => $packager, |
||
156 | ); |
||
157 | $version = null; |
||
158 | // version.php has been updated to include the version in an HTTP header |
||
159 | // called "X-Chamilo-Version", so that we don't have to worry about |
||
160 | // issues with the content not being returned by fread for some reason |
||
161 | $res = _http_request('version.chamilo.org', 80, '/version.php', $data, 5, null, true); |
||
162 | $lines = preg_split('/\r\n/', $res); |
||
163 | foreach ($lines as $line) { |
||
164 | $elements = preg_split('/:/', $line); |
||
165 | // extract the X-Chamilo-Version header from the version.php response |
||
166 | if (strcmp(trim($elements[0]), 'X-Chamilo-Version') === 0) { |
||
167 | $version = trim($elements[1]); |
||
168 | } |
||
169 | } |
||
170 | if (substr($res, 0, 5) != 'Error') { |
||
171 | if (empty($version)) { |
||
172 | $version_info = $res; |
||
173 | } else { |
||
174 | $version_info = $version; |
||
175 | } |
||
176 | |||
177 | if ($system_version != $version_info) { |
||
178 | $output = '<br /><span style="color:red">' . get_lang('YourVersionNotUpToDate') . '. '.get_lang('LatestVersionIs').' <b>Chamilo '.$version_info.'</b>. '.get_lang('YourVersionIs').' <b>Chamilo '.$system_version. '</b>. '.str_replace('http://www.chamilo.org', '<a href="http://www.chamilo.org">http://www.chamilo.org</a>', get_lang('PleaseVisitOurWebsite')).'</span>'; |
||
179 | } else { |
||
180 | $output = '<br /><span style="color:green">'.get_lang('VersionUpToDate').': Chamilo '.$version_info.'</span>'; |
||
181 | } |
||
182 | } else { |
||
183 | $output = '<span style="color:red">' . get_lang('ImpossibleToContactVersionServerPleaseTryAgain') . '</span>'; |
||
184 | } |
||
185 | } else { |
||
186 | $output = '<span style="color:red">' . get_lang('AllowurlfopenIsSetToOff') . '</span>'; |
||
187 | } |
||
188 | return $output; |
||
189 | } |
||
190 | |||
242 |