Browse Source

Saving memory issues, do not load classes if we don't need it

Julio Montoya 12 years ago
parent
commit
876771ea9c
2 changed files with 12 additions and 9 deletions
  1. 5 3
      main/inc/lib/internationalization.lib.php
  2. 7 6
      main/inc/lib/template.lib.php

+ 5 - 3
main/inc/lib/internationalization.lib.php

@@ -583,7 +583,8 @@ function api_get_timezones()
  */
 function _api_get_timezone()
 {
-    $user_id = api_get_user_id();
+    $userId = api_get_user_id();
+
     // First, get the default timezone of the server
     $to_timezone = date_default_timezone_get();
     // Second, see if a timezone has been chosen for the platform
@@ -595,14 +596,15 @@ function _api_get_timezone()
     // If allowed by the administrator
     $use_users_timezone = api_get_setting('use_users_timezone', 'timezones');
 
-    if ($use_users_timezone == 'true') {
+    if ($use_users_timezone == 'true' && !empty($userId)) {
         // Get the timezone based on user preference, if it exists
-        $timezone_user = UserManager::get_extra_user_data_by_field($user_id, 'timezone');
+        $timezone_user = UserManager::get_extra_user_data_by_field($userId, 'timezone');
 
         if (isset($timezone_user['timezone']) && $timezone_user['timezone'] != null) {
             $to_timezone = $timezone_user['timezone'];
         }
     }
+
     return $to_timezone;
 }
 

+ 7 - 6
main/inc/lib/template.lib.php

@@ -90,7 +90,7 @@ class Template
 
         //Chamilo plugins
         if ($this->show_header) {
-            if ($app['template.load_plugins']) {
+            if ($app['template.load_plugins'] && !empty($app['plugins'])) {
 
                 $this->plugin = new AppPlugin();
 
@@ -639,16 +639,17 @@ class Template
                 $this->assign('footer_extra_content', $extra_footer);
             }
         }
-        $id_course = api_get_course_int_id();
+
+        $courseId = api_get_course_int_id();
 
         //Tutor name
         if (api_get_setting('show_tutor_data') == 'true') {
             // Course manager
             $id_session = api_get_session_id();
-            if (isset($id_course) && $id_course != -1) {
+            if (isset($courseId) && $courseId != -1 && !empty($courseId)) {
                 $tutor_data = '';
                 if ($id_session != 0) {
-                    $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $id_course);
+                    $coachs_email = CourseManager::get_email_of_tutor_to_session($id_session, $courseId);
                     $email_link = array();
                     foreach ($coachs_email as $coach) {
                         $email_link[] = Display::encrypted_mailto_link($coach['email'], $coach['complete_name']);
@@ -669,9 +670,9 @@ class Template
 
         if (api_get_setting('show_teacher_data') == 'true') {
             // course manager
-            if (isset($id_course) && $id_course != -1) {
+            if (isset($courseId) && $courseId != -1 && !empty($courseId)) {
                 $teacher_data = '';
-                $mail = CourseManager::get_emails_of_tutors_to_course($id_course);
+                $mail = CourseManager::get_emails_of_tutors_to_course($courseId);
                 if (!empty($mail)) {
                     $teachers_parsed = array();
                     foreach ($mail as $value) {