Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Template often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Template, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class Template |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * The Template folder name see main/template |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | public $templateFolder = 'default'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The theme that will be used: chamilo, public_admin, chamilo_red, etc |
||
| 45 | * This variable is set from the database |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | public $theme = ''; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | public $preview_theme = ''; |
||
| 54 | public $title = null; |
||
| 55 | public $show_header; |
||
| 56 | public $show_footer; |
||
| 57 | public $help; |
||
| 58 | public $menu_navigation = array(); //Used in the userportal.lib.php function: return_navigation_course_links() |
||
| 59 | public $show_learnpath = false; // This is a learnpath section or not? |
||
| 60 | public $plugin = null; |
||
| 61 | public $course_id = null; |
||
| 62 | public $user_is_logged_in = false; |
||
| 63 | public $twig = null; |
||
| 64 | |||
| 65 | /* Loads chamilo plugins */ |
||
| 66 | public $load_plugins = false; |
||
| 67 | public static $params = array(); |
||
| 68 | public $force_plugin_load = false; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * |
||
| 72 | * @param string $title |
||
| 73 | * @param bool $show_header |
||
| 74 | * @param bool $show_footer |
||
| 75 | * @param bool $show_learnpath |
||
| 76 | * @param bool $hide_global_chat |
||
| 77 | * @param bool $load_plugins |
||
| 78 | * @param bool $sendHeaders send http headers or not |
||
| 79 | */ |
||
| 80 | public function __construct( |
||
| 81 | $title = '', |
||
| 82 | $show_header = true, |
||
| 83 | $show_footer = true, |
||
| 84 | $show_learnpath = false, |
||
| 85 | $hide_global_chat = false, |
||
| 86 | $load_plugins = true, |
||
| 87 | $sendHeaders = true |
||
| 88 | ) { |
||
| 89 | |||
| 90 | if ($show_header == false) { |
||
| 91 | Container::$legacyTemplate = '@ChamiloTheme/Layout/layout_one_col_no_content.html.twig'; |
||
| 92 | } |
||
| 93 | |||
| 94 | return; |
||
| 95 | // Page title |
||
| 96 | $this->title = $title; |
||
|
|
|||
| 97 | |||
| 98 | $this->show_learnpath = $show_learnpath; |
||
| 99 | |||
| 100 | if (empty($this->show_learnpath)) { |
||
| 101 | $origin = api_get_origin(); |
||
| 102 | if ($origin === 'learnpath') { |
||
| 103 | $this->show_learnpath = true; |
||
| 104 | $show_footer = false; |
||
| 105 | $show_header = false; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | $this->hide_global_chat = $hide_global_chat; |
||
| 109 | $this->load_plugins = $load_plugins; |
||
| 110 | |||
| 111 | $template_paths = array( |
||
| 112 | api_get_path(SYS_CODE_PATH).'template/overrides', // user defined templates |
||
| 113 | api_get_path(SYS_CODE_PATH).'template', //template folder |
||
| 114 | api_get_path(SYS_PLUGIN_PATH) // plugin folder |
||
| 115 | ); |
||
| 116 | |||
| 117 | $urlId = api_get_current_access_url_id(); |
||
| 118 | |||
| 119 | $cache_folder = api_get_path(SYS_ARCHIVE_PATH).'twig/'.$urlId.'/'; |
||
| 120 | |||
| 121 | if (!is_dir($cache_folder)) { |
||
| 122 | mkdir($cache_folder, api_get_permissions_for_new_directories(), true); |
||
| 123 | } |
||
| 124 | |||
| 125 | $loader = new Twig_Loader_Filesystem($template_paths); |
||
| 126 | |||
| 127 | //Setting Twig options depending on the server see http://twig.sensiolabs.org/doc/api.html#environment-options |
||
| 128 | if (api_get_setting('server_type') == 'test') { |
||
| 129 | $options = array( |
||
| 130 | //'cache' => api_get_path(SYS_ARCHIVE_PATH), //path to the cache folder |
||
| 131 | 'autoescape' => false, |
||
| 132 | 'debug' => true, |
||
| 133 | 'auto_reload' => true, |
||
| 134 | 'optimizations' => 0, |
||
| 135 | // turn on optimizations with -1 |
||
| 136 | 'strict_variables' => false, |
||
| 137 | //If set to false, Twig will silently ignore invalid variables |
||
| 138 | ); |
||
| 139 | } else { |
||
| 140 | $options = array( |
||
| 141 | 'cache' => $cache_folder, |
||
| 142 | //path to the cache folder |
||
| 143 | 'autoescape' => false, |
||
| 144 | 'debug' => false, |
||
| 145 | 'auto_reload' => false, |
||
| 146 | 'optimizations' => -1, |
||
| 147 | // turn on optimizations with -1 |
||
| 148 | 'strict_variables' => false |
||
| 149 | //If set to false, Twig will silently ignore invalid variables |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | |||
| 153 | $this->twig = new Twig_Environment($loader, $options); |
||
| 154 | |||
| 155 | $this->twig->addFilter('get_plugin_lang', new Twig_Filter_Function('get_plugin_lang')); |
||
| 156 | $this->twig->addFilter('get_lang', new Twig_Filter_Function('get_lang')); |
||
| 157 | $this->twig->addFilter('get_path', new Twig_Filter_Function('api_get_path')); |
||
| 158 | $this->twig->addFilter('get_setting', new Twig_Filter_Function('api_get_setting')); |
||
| 159 | $this->twig->addFilter('var_dump', new Twig_Filter_Function('var_dump')); |
||
| 160 | //$this->twig->addFilter('return_logo', new Twig_Filter_Function('return_logo')); |
||
| 161 | $this->twig->addFilter('return_message', new Twig_Filter_Function('Display::return_message_and_translate')); |
||
| 162 | $this->twig->addFilter('display_page_header', new Twig_Filter_Function('Display::page_header_and_translate')); |
||
| 163 | $this->twig->addFilter( |
||
| 164 | 'display_page_subheader', |
||
| 165 | new Twig_Filter_Function('Display::page_subheader_and_translate') |
||
| 166 | ); |
||
| 167 | $this->twig->addFilter('icon', new Twig_Filter_Function('Template::get_icon_path')); |
||
| 168 | $this->twig->addFilter('img', new Twig_Filter_Function('Template::get_image')); |
||
| 169 | $this->twig->addFilter('format_date', new Twig_Filter_Function('Template::format_date')); |
||
| 170 | $this->twig->addFilter('api_get_local_time', new Twig_Filter_Function('api_get_local_time')); |
||
| 171 | $this->twig->addFilter('user_info', new Twig_Filter_Function('api_get_user_info')); |
||
| 172 | |||
| 173 | /* |
||
| 174 | $lexer = new Twig_Lexer($this->twig, array( |
||
| 175 | //'tag_comment' => array('{*', '*}'), |
||
| 176 | //'tag_comment' => array('{#', '#}'), |
||
| 177 | //'tag_block' => array('{', '}'), |
||
| 178 | //'tag_variable' => array('{$', '}'), |
||
| 179 | )); |
||
| 180 | $this->twig->setLexer($lexer); */ |
||
| 181 | |||
| 182 | //Setting system variables |
||
| 183 | $this->set_system_parameters(); |
||
| 184 | |||
| 185 | //Setting user variables |
||
| 186 | $this->set_user_parameters(); |
||
| 187 | |||
| 188 | //Setting course variables |
||
| 189 | $this->set_course_parameters(); |
||
| 190 | |||
| 191 | //Setting administrator variables |
||
| 192 | $this->setAdministratorParams(); |
||
| 193 | |||
| 194 | $this->setCSSEditor(); |
||
| 195 | |||
| 196 | //header and footer are showed by default |
||
| 197 | $this->set_footer($show_footer); |
||
| 198 | $this->set_header($show_header); |
||
| 199 | |||
| 200 | $this->set_header_parameters($sendHeaders); |
||
| 201 | $this->set_footer_parameters(); |
||
| 202 | |||
| 203 | $defaultStyle = api_get_configuration_value('default_template'); |
||
| 204 | if (!empty($defaultStyle)) { |
||
| 205 | $this->templateFolder = $defaultStyle; |
||
| 206 | } |
||
| 207 | |||
| 208 | $this->assign('template', $this->templateFolder); |
||
| 209 | $this->assign('locale', api_get_language_isocode()); |
||
| 210 | |||
| 211 | $this->assign('css_styles', $this->theme); |
||
| 212 | $this->assign('login_class', null); |
||
| 213 | |||
| 214 | $this->setLoginForm(); |
||
| 215 | |||
| 216 | // Chamilo plugins |
||
| 217 | if ($this->show_header) { |
||
| 218 | if ($this->load_plugins) { |
||
| 219 | |||
| 220 | $this->plugin = new AppPlugin(); |
||
| 221 | |||
| 222 | //1. Showing installed plugins in regions |
||
| 223 | $pluginRegions = $this->plugin->get_plugin_regions(); |
||
| 224 | foreach ($pluginRegions as $region) { |
||
| 225 | $this->set_plugin_region($region); |
||
| 226 | } |
||
| 227 | |||
| 228 | //2. Loading the course plugin info |
||
| 229 | global $course_plugin; |
||
| 230 | if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) { |
||
| 231 | //Load plugin get_langs |
||
| 232 | $this->plugin->load_plugin_lang_variables($course_plugin); |
||
| 233 | } |
||
| 234 | } |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @param string $image |
||
| 240 | * @param int $size |
||
| 241 | * |
||
| 242 | * @return string |
||
| 243 | */ |
||
| 244 | public static function get_icon_path($image, $size = ICON_SIZE_SMALL) |
||
| 245 | { |
||
| 246 | return Display::return_icon($image, '', array(), $size, false, true); |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @param string $image |
||
| 251 | * @param int $size |
||
| 252 | * @param string $name |
||
| 253 | * @return string |
||
| 254 | */ |
||
| 255 | public static function get_image($image, $size = ICON_SIZE_SMALL, $name) |
||
| 256 | { |
||
| 257 | return Display::return_icon($image, $name, array(), $size); |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @param string $timestamp |
||
| 262 | * @param string $format |
||
| 263 | * |
||
| 264 | * @return string |
||
| 265 | */ |
||
| 266 | public static function format_date($timestamp, $format = null) |
||
| 267 | { |
||
| 268 | return api_format_date($timestamp, $format); |
||
| 269 | } |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Return the item's url key: |
||
| 273 | * |
||
| 274 | * c_id=xx&id=xx |
||
| 275 | * |
||
| 276 | * @param object $item |
||
| 277 | * @return string |
||
| 278 | */ |
||
| 279 | public static function key($item) |
||
| 280 | { |
||
| 281 | $id = isset($item->id) ? $item->id : null; |
||
| 282 | $c_id = isset($item->c_id) ? $item->c_id : null; |
||
| 283 | $result = ''; |
||
| 284 | if ($c_id) { |
||
| 285 | $result = "c_id=$c_id"; |
||
| 286 | } |
||
| 287 | if ($id) { |
||
| 288 | if ($result) { |
||
| 289 | $result .= "&id=$id"; |
||
| 290 | } else { |
||
| 291 | $result .= "&id=$id"; |
||
| 292 | } |
||
| 293 | } |
||
| 294 | return $result; |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @param string $helpInput |
||
| 299 | */ |
||
| 300 | public function setHelp($helpInput = null) |
||
| 301 | { |
||
| 302 | if (!empty($helpInput)) { |
||
| 303 | $help = $helpInput; |
||
| 304 | } else { |
||
| 305 | $help = $this->help; |
||
| 306 | } |
||
| 307 | |||
| 308 | $content = ''; |
||
| 309 | if (api_get_setting('enable_help_link') == 'true') { |
||
| 310 | if (!empty($help)) { |
||
| 311 | $help = Security::remove_XSS($help); |
||
| 312 | $content = '<div class="help">'; |
||
| 313 | $content .= Display::url( |
||
| 314 | Display::return_icon('help.large.png', get_lang('Help')), |
||
| 315 | api_get_path(WEB_CODE_PATH) . 'help/help.php?open=' . $help, |
||
| 316 | [ |
||
| 317 | 'class' => 'ajax', |
||
| 318 | 'data-title' => get_lang('Help') |
||
| 319 | ] |
||
| 320 | ); |
||
| 321 | $content .= '</div>'; |
||
| 322 | } |
||
| 323 | } |
||
| 324 | $this->assign('help_content', $content); |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Use template system to parse the actions menu |
||
| 329 | * @todo finish it! |
||
| 330 | **/ |
||
| 331 | public function set_actions($actions) |
||
| 332 | { |
||
| 333 | $action_string = ''; |
||
| 334 | if (!empty($actions)) { |
||
| 335 | foreach ($actions as $action) { |
||
| 336 | $action_string .= $action; |
||
| 337 | } |
||
| 338 | } |
||
| 339 | $this->assign('actions', $actions); |
||
| 340 | } |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Render the template |
||
| 344 | * @param string $template The template path |
||
| 345 | * @param boolean $clearFlashMessages Clear the $_SESSION variables for flash messages |
||
| 346 | */ |
||
| 347 | public function display($template, $clearFlashMessages = true) |
||
| 348 | { |
||
| 349 | Container::$legacyTemplate = $template; |
||
| 350 | //echo $this->twig->render($template, $this->params); |
||
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Shortcut to display a 1 col layout (index.php) |
||
| 355 | * */ |
||
| 356 | public function display_one_col_template() |
||
| 357 | { |
||
| 358 | Container::$legacyTemplate = '@ChamiloTheme/Layout/layout_one_col.html.twig'; |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Shortcut to display a 2 col layout (userportal.php) |
||
| 363 | **/ |
||
| 364 | public function display_two_col_template() |
||
| 365 | { |
||
| 366 | Container::$legacyTemplate = '@ChamiloTheme/Layout/layout_two_col.html.twig'; |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Displays an empty template |
||
| 371 | */ |
||
| 372 | public function display_blank_template() |
||
| 373 | { |
||
| 374 | Container::$legacyTemplate = '@ChamiloTheme/Layout/no_layout.html.twig'; |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Displays an empty template |
||
| 379 | */ |
||
| 380 | public function display_no_layout_template() |
||
| 381 | { |
||
| 382 | Container::$legacyTemplate = '@ChamiloTheme/Layout/no_layout.html.twig'; |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Sets the footer visibility |
||
| 387 | * @param bool true if we show the footer |
||
| 388 | */ |
||
| 389 | public function set_footer($status) |
||
| 390 | { |
||
| 391 | $this->show_footer = $status; |
||
| 392 | $this->assign('show_footer', $status); |
||
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * return true if toolbar has to be displayed for user |
||
| 397 | * @return bool |
||
| 398 | */ |
||
| 399 | public static function isToolBarDisplayedForUser() |
||
| 400 | { |
||
| 401 | //Toolbar |
||
| 402 | $show_admin_toolbar = api_get_setting('show_admin_toolbar'); |
||
| 403 | $show_toolbar = false; |
||
| 404 | |||
| 405 | switch ($show_admin_toolbar) { |
||
| 406 | case 'do_not_show': |
||
| 407 | break; |
||
| 408 | case 'show_to_admin': |
||
| 409 | if (api_is_platform_admin()) { |
||
| 410 | $show_toolbar = true; |
||
| 411 | } |
||
| 412 | break; |
||
| 413 | case 'show_to_admin_and_teachers': |
||
| 414 | if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
||
| 415 | $show_toolbar = true; |
||
| 416 | } |
||
| 417 | break; |
||
| 418 | case 'show_to_all': |
||
| 419 | $show_toolbar = true; |
||
| 420 | break; |
||
| 421 | } |
||
| 422 | return $show_toolbar; |
||
| 423 | } |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Sets the header visibility |
||
| 427 | * @param bool true if we show the header |
||
| 428 | */ |
||
| 429 | public function set_header($status) |
||
| 430 | { |
||
| 431 | $this->show_header = $status; |
||
| 432 | $this->assign('show_header', $status); |
||
| 433 | |||
| 434 | $show_toolbar = 0; |
||
| 435 | |||
| 436 | if (self::isToolBarDisplayedForUser()) { |
||
| 437 | $show_toolbar = 1; |
||
| 438 | } |
||
| 439 | |||
| 440 | $this->assign('show_toolbar', $show_toolbar); |
||
| 441 | |||
| 442 | //Only if course is available |
||
| 443 | $show_course_shortcut = null; |
||
| 444 | $show_course_navigation_menu = null; |
||
| 445 | |||
| 446 | if (!empty($this->course_id) && $this->user_is_logged_in) { |
||
| 447 | if (api_get_setting('show_toolshortcuts') != 'false') { |
||
| 448 | //Course toolbar |
||
| 449 | $show_course_shortcut = CourseHome::show_navigation_tool_shortcuts(); |
||
| 450 | } |
||
| 451 | if (api_get_setting('show_navigation_menu') != 'false') { |
||
| 452 | //Course toolbar |
||
| 453 | $show_course_navigation_menu = CourseHome::show_navigation_menu(); |
||
| 454 | } |
||
| 455 | } |
||
| 456 | $this->assign('show_course_shortcut', $show_course_shortcut); |
||
| 457 | $this->assign('show_course_navigation_menu', $show_course_navigation_menu); |
||
| 458 | } |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @param string $name |
||
| 462 | * |
||
| 463 | * @return string |
||
| 464 | */ |
||
| 465 | public function get_template($name) |
||
| 466 | { |
||
| 467 | if ($name == 'layout/layout_1_col.tpl') { |
||
| 468 | $name = '@ChamiloTheme/Layout/layout_1_col.html.twig'; |
||
| 469 | } |
||
| 470 | |||
| 471 | if ($name == 'layout/layout_2_col.tpl') { |
||
| 472 | $name = '@ChamiloTheme/Layout/layout_2_col.html.twig'; |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * In Chamilo 1.x we use the tpl extension. |
||
| 477 | * In Chamilo 2.x we use twig but using the Symfony2 bridge |
||
| 478 | * In order to don't change all legacy main calls we just replace |
||
| 479 | * tpl with html.twig (the new template location should be: |
||
| 480 | * (src/Chamilo/CoreBundle/Resources/views/default/layout) |
||
| 481 | */ |
||
| 482 | $name = str_replace('.tpl', '.html.twig', $name); |
||
| 483 | |||
| 484 | return '@ChamiloCore/'.$this->templateFolder.'/'.$name; |
||
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Set course parameters |
||
| 489 | */ |
||
| 490 | private function set_course_parameters() |
||
| 491 | { |
||
| 492 | //Setting course id |
||
| 493 | $course = api_get_course_info(); |
||
| 494 | if (empty($course)) { |
||
| 495 | $this->assign('course_is_set', false); |
||
| 496 | return; |
||
| 497 | } |
||
| 498 | $this->assign('course_is_set', true); |
||
| 499 | $this->course_id = $course['id']; |
||
| 500 | $_c = array( |
||
| 501 | 'id' => $course['id'], |
||
| 502 | 'code' => $course['code'], |
||
| 503 | 'title' => $course['name'], |
||
| 504 | 'visibility' => $course['visibility'], |
||
| 505 | 'language' => $course['language'], |
||
| 506 | 'directory' => $course['directory'], |
||
| 507 | 'session_id' => api_get_session_id(), |
||
| 508 | 'user_is_teacher' => api_is_course_admin(), |
||
| 509 | 'student_view' => (!empty($_GET['isStudentView']) && $_GET['isStudentView'] == 'true'), |
||
| 510 | ); |
||
| 511 | $this->assign('course_code', $course['code']); |
||
| 512 | $this->assign('_c', $_c); |
||
| 513 | } |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Set user parameters |
||
| 517 | */ |
||
| 518 | private function set_user_parameters() |
||
| 519 | { |
||
| 520 | $user_info = array(); |
||
| 521 | $user_info['logged'] = 0; |
||
| 522 | $this->user_is_logged_in = false; |
||
| 523 | if (api_user_is_login()) { |
||
| 524 | $user_info = api_get_user_info(api_get_user_id(), true); |
||
| 525 | $user_info['logged'] = 1; |
||
| 526 | |||
| 527 | $user_info['is_admin'] = 0; |
||
| 528 | if (api_is_platform_admin()) { |
||
| 529 | $user_info['is_admin'] = 1; |
||
| 530 | } |
||
| 531 | |||
| 532 | $user_info['messages_count'] = MessageManager::getCountNewMessages(); |
||
| 533 | $this->user_is_logged_in = true; |
||
| 534 | } |
||
| 535 | // Setting the $_u array that could be use in any template |
||
| 536 | $this->assign('_u', $user_info); |
||
| 537 | } |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Set system parameters |
||
| 541 | */ |
||
| 542 | private function set_system_parameters() |
||
| 543 | { |
||
| 544 | global $_configuration; |
||
| 545 | $this->theme = api_get_visual_theme(); |
||
| 546 | //Setting app paths/URLs |
||
| 547 | $_p = array( |
||
| 548 | 'web' => api_get_path(WEB_PATH), |
||
| 549 | 'web_relative' => api_get_path(REL_PATH), |
||
| 550 | 'web_course' => api_get_path(WEB_COURSE_PATH), |
||
| 551 | 'web_main' => api_get_path(WEB_CODE_PATH), |
||
| 552 | 'web_css' => api_get_path(WEB_CSS_PATH), |
||
| 553 | 'web_css_theme' => api_get_path(WEB_CSS_PATH) . 'themes/' . $this->theme . '/', |
||
| 554 | 'web_ajax' => api_get_path(WEB_AJAX_PATH), |
||
| 555 | 'web_img' => api_get_path(WEB_IMG_PATH), |
||
| 556 | 'web_plugin' => api_get_path(WEB_PLUGIN_PATH), |
||
| 557 | 'web_lib' => api_get_path(WEB_LIBRARY_PATH), |
||
| 558 | 'web_upload' => api_get_path(WEB_UPLOAD_PATH), |
||
| 559 | 'web_self' => api_get_self(), |
||
| 560 | 'web_query_vars' => api_htmlentities($_SERVER['QUERY_STRING']), |
||
| 561 | 'web_self_query_vars' => api_htmlentities($_SERVER['REQUEST_URI']), |
||
| 562 | 'web_cid_query' => api_get_cidreq(), |
||
| 563 | ); |
||
| 564 | $this->assign('_p', $_p); |
||
| 565 | |||
| 566 | //Here we can add system parameters that can be use in any template |
||
| 567 | $_s = array( |
||
| 568 | 'software_name' => $_configuration['software_name'], |
||
| 569 | 'system_version' => $_configuration['system_version'], |
||
| 570 | 'site_name' => api_get_setting('siteName'), |
||
| 571 | 'institution' => api_get_setting('Institution'), |
||
| 572 | 'date' => api_format_date('now', DATE_FORMAT_LONG), |
||
| 573 | 'timezone' => api_get_timezone(), |
||
| 574 | 'gamification_mode' => api_get_setting('gamification_mode') |
||
| 575 | ); |
||
| 576 | $this->assign('_s', $_s); |
||
| 577 | } |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Set legacy twig globals in order to be hook in the LegacyListener.php |
||
| 581 | * @return array |
||
| 582 | */ |
||
| 583 | public static function getGlobals() |
||
| 584 | { |
||
| 585 | $_p = array( |
||
| 586 | 'web' => api_get_path(WEB_PATH), |
||
| 587 | 'web_relative' => api_get_path(REL_PATH), |
||
| 588 | 'web_course' => api_get_path(WEB_COURSE_PATH), |
||
| 589 | 'web_main' => api_get_path(WEB_CODE_PATH), |
||
| 590 | 'web_css' => api_get_path(WEB_CSS_PATH), |
||
| 591 | //'web_css_theme' => api_get_path(WEB_CSS_PATH) . 'themes/' . $this->theme . '/', |
||
| 592 | 'web_ajax' => api_get_path(WEB_AJAX_PATH), |
||
| 593 | 'web_img' => api_get_path(WEB_IMG_PATH), |
||
| 594 | 'web_plugin' => api_get_path(WEB_PLUGIN_PATH), |
||
| 595 | 'web_lib' => api_get_path(WEB_LIBRARY_PATH), |
||
| 596 | 'web_upload' => api_get_path(WEB_UPLOAD_PATH), |
||
| 597 | 'web_self' => api_get_self(), |
||
| 598 | 'web_query_vars' => api_htmlentities($_SERVER['QUERY_STRING']), |
||
| 599 | 'web_self_query_vars' => api_htmlentities($_SERVER['REQUEST_URI']), |
||
| 600 | 'web_cid_query' => api_get_cidreq(), |
||
| 601 | ); |
||
| 602 | |||
| 603 | $_s = array( |
||
| 604 | 'software_name' => api_get_configuration_value('software_name'), |
||
| 605 | 'system_version' => api_get_configuration_value('system_version'), |
||
| 606 | 'site_name' => api_get_setting('siteName'), |
||
| 607 | 'institution' => api_get_setting('Institution'), |
||
| 608 | 'date' => api_format_date('now', DATE_FORMAT_LONG), |
||
| 609 | 'timezone' => api_get_timezone(), |
||
| 610 | 'gamification_mode' => api_get_setting('gamification_mode') |
||
| 611 | ); |
||
| 612 | |||
| 613 | //$user_info = api_get_user_info(); |
||
| 614 | |||
| 615 | return [ |
||
| 616 | '_p' => $_p, |
||
| 617 | '_s' => $_s, |
||
| 618 | // '_u' => $user_info, |
||
| 619 | 'template' => 'default' // @todo setup template folder in config.yml; |
||
| 620 | ]; |
||
| 621 | } |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Set theme, include mainstream CSS files |
||
| 625 | * @return void |
||
| 626 | * @see setCssCustomFiles() for additional CSS sheets |
||
| 627 | */ |
||
| 628 | public function setCssFiles() |
||
| 675 | |||
| 676 | /** |
||
| 677 | * |
||
| 678 | */ |
||
| 679 | public function setCSSEditor() |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Prepare custom CSS to be added at the very end of the <head> section |
||
| 692 | * @return void |
||
| 693 | * @see setCssFiles() for the mainstream CSS files |
||
| 694 | */ |
||
| 695 | public function setCssCustomFiles() |
||
| 759 | |||
| 760 | /** |
||
| 761 | * Declare and define the template variable that will be used to load |
||
| 762 | * javascript libraries in the header. |
||
| 763 | */ |
||
| 764 | public function set_js_files() |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Special function to declare last-minute JS libraries which depend on |
||
| 861 | * other things to be declared first. In particular, it might be useful |
||
| 862 | * under IE9 with compatibility mode, which for some reason is getting |
||
| 863 | * upset when a variable is used in a function (even if not used yet) |
||
| 864 | * when this variable hasn't been defined yet. |
||
| 865 | */ |
||
| 866 | public function set_js_files_post() |
||
| 885 | |||
| 886 | /** |
||
| 887 | * Set header parameters |
||
| 888 | * @param bool $sendHeaders send headers |
||
| 889 | */ |
||
| 890 | private function set_header_parameters($sendHeaders) |
||
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Set footer parameters |
||
| 1190 | */ |
||
| 1191 | private function set_footer_parameters() |
||
| 1263 | |||
| 1264 | /** |
||
| 1265 | * Show footer js template. |
||
| 1266 | */ |
||
| 1267 | public function show_footer_js_template() |
||
| 1268 | { |
||
| 1269 | $tpl = $this->get_template('layout/footer.js.tpl'); |
||
| 1270 | $this->display($tpl); |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | /** |
||
| 1274 | * Sets the plugin content in a template variable |
||
| 1275 | * @param string $pluginRegion |
||
| 1276 | * @return null |
||
| 1277 | */ |
||
| 1278 | public function set_plugin_region($pluginRegion) |
||
| 1279 | { |
||
| 1280 | if (!empty($pluginRegion)) { |
||
| 1281 | $regionContent = $this->plugin->load_region($pluginRegion, $this, $this->force_plugin_load); |
||
| 1282 | |||
| 1283 | $pluginList = $this->plugin->get_installed_plugins(); |
||
| 1284 | View Code Duplication | foreach ($pluginList as $plugin_name) { |
|
| 1312 | |||
| 1313 | /** |
||
| 1314 | * @param string $template |
||
| 1315 | * @return string |
||
| 1316 | */ |
||
| 1317 | public function fetch($template = null) |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * @param string $variable |
||
| 1326 | * @param mixed $value |
||
| 1327 | */ |
||
| 1328 | public function assign($variable, $value = '') |
||
| 1332 | |||
| 1333 | /** |
||
| 1334 | * Adds a body class for login pages |
||
| 1335 | */ |
||
| 1336 | public function setLoginBodyClass() |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * The theme that will be used if the database is not working. |
||
| 1343 | * @return string |
||
| 1344 | */ |
||
| 1345 | public static function getThemeFallback() |
||
| 1353 | |||
| 1354 | /** |
||
| 1355 | * @param bool|true $setLoginForm |
||
| 1356 | */ |
||
| 1357 | public function setLoginForm($setLoginForm = true) |
||
| 1377 | |||
| 1378 | /** |
||
| 1379 | * @return string |
||
| 1380 | */ |
||
| 1381 | public function handleLoginFailed() |
||
| 1424 | |||
| 1425 | /** |
||
| 1426 | * @return string |
||
| 1427 | */ |
||
| 1428 | public function displayLoginForm() |
||
| 1507 | |||
| 1508 | /** |
||
| 1509 | * Set administrator variables |
||
| 1510 | */ |
||
| 1511 | private function setAdministratorParams() |
||
| 1522 | |||
| 1523 | public static function getParams() |
||
| 1527 | } |
||
| 1528 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.