diff --git a/main/admin/user_edit.php b/main/admin/user_edit.php index 1862abdb93..fd462a5259 100755 --- a/main/admin/user_edit.php +++ b/main/admin/user_edit.php @@ -442,6 +442,8 @@ if ($error_drh) { $message = Display::return_message($err_msg, 'error'); } +$gravatarEnabled = api_get_configuration_value('gravatar_enabled'); + // USER PICTURE $image_path = UserManager::get_user_picture_path_by_id($user_id,'web'); $image_dir = $image_path['dir']; @@ -449,7 +451,11 @@ $image = $image_path['file']; $image_file = ($image != '' ? $image_dir.$image : api_get_path(WEB_CODE_PATH).'img/unknown.jpg'); $image_size = api_getimagesize($image_file); -$img_attributes = 'src="'.$image_file.'?rand='.time().'" ' +if (!$gravatarEnabled) { + $image_file .= '?rand='.time(); +} + +$img_attributes = 'src="'.$image_file.'" ' .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" '; @@ -462,7 +468,10 @@ $big_image = $image_dir.'big_'.$image; $big_image_size = api_getimagesize($big_image); $big_image_width = $big_image_size['width']; $big_image_height = $big_image_size['height']; -$url_big_image = $big_image.'?rnd='.time(); +$url_big_image = $image_file; +if (!$gravatarEnabled) { + $url_big_image = $big_image.'?rnd='.time(); +} $content = null; if ($image == '') { diff --git a/main/auth/profile.php b/main/auth/profile.php index 6b6d759513..a989e25936 100755 --- a/main/auth/profile.php +++ b/main/auth/profile.php @@ -323,8 +323,7 @@ function is_profile_editable() { * @return The filename of the new production or FALSE if the upload has failed */ function upload_user_production($user_id) { - $image_path = UserManager::get_user_picture_path_by_id($user_id, 'system'); - $production_repository = $image_path['dir']; + $production_repository = UserManager::getUserPathById($user_id, 'system'); if (!file_exists($production_repository)) { @mkdir($production_repository, api_get_permissions_for_new_directories(), true); @@ -692,6 +691,8 @@ if (!empty($msg_is_not_password)){ Display::addFlash(Display :: return_message($warning_msg, 'warning', false)); } +$gravatarEnabled = api_get_configuration_value('gravatar_enabled'); + // User picture size is calculated from SYSTEM path $image_syspath = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system', false, true); $image_syspath['dir'].$image_syspath['file']; @@ -701,7 +702,10 @@ $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', $image_dir = $image_path['dir']; $image = $image_path['file']; $image_file = $image_dir.$image; -$img_attributes = 'src="'.$image_file.'?rand='.time().'" ' +if (!$gravatarEnabled) { + $image_file .= '?rand='.time(); +} +$img_attributes = 'src="'.$image_file.'" ' .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; margin-top:0px;padding:5px;" '; @@ -711,8 +715,10 @@ $big_image = $image_dir.'big_'.$image; $big_image_size = api_getimagesize($big_image); $big_image_width = $big_image_size['width']; $big_image_height = $big_image_size['height']; -$url_big_image = $big_image.'?rnd='.time(); - +$url_big_image = $image_file; +if (!$gravatarEnabled) { + $url_big_image = $big_image.'?rnd='.time(); +} $show_delete_account_button = api_get_setting('platform_unsubscribe_allowed') == 'true' ? true : false; $tpl = new Template(get_lang('ModifyProfile')); diff --git a/main/chat/chat_functions.lib.php b/main/chat/chat_functions.lib.php index bc0df7c67d..ac46b479c1 100755 --- a/main/chat/chat_functions.lib.php +++ b/main/chat/chat_functions.lib.php @@ -222,6 +222,10 @@ function saveMessage($message, $userId, $_course, $session_id, $group_id, $previ $userPhoto = $userImage['dir'].$userImage['file']; } + if (api_get_configuration_value('gravatar_enabled')) { + $userPhoto = $userImage['file']; + } + $filePhoto = ''; if ($isMaster) { diff --git a/main/chat/chat_whoisonline.php b/main/chat/chat_whoisonline.php index 319f46847e..555af169af 100755 --- a/main/chat/chat_whoisonline.php +++ b/main/chat/chat_whoisonline.php @@ -122,6 +122,11 @@ if (!empty($course)) { } else { $fileUrl = $userImage['dir'].$userImage['file']; } + + if (api_get_configuration_value('gravatar_enabled')) { + $fileUrl = $userImage['file']; + } + $email = $user['email']; $url_user_profile=api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$user['user_id'].'&'; ?> diff --git a/main/gradebook/lib/fe/displaygradebook.php b/main/gradebook/lib/fe/displaygradebook.php index b2d3df5d9c..e98e7481ae 100755 --- a/main/gradebook/lib/fe/displaygradebook.php +++ b/main/gradebook/lib/fe/displaygradebook.php @@ -720,7 +720,12 @@ class DisplayGradebook //Web path $image_path = UserManager::get_user_picture_path_by_id($userid, 'web', false, true); $image_file = $image_path['dir'] . $image_path['file']; - $img_attributes = 'src="' . $image_file . '?rand=' . time() . '" ' . 'alt="' . $user['complete_name'] . '" '; + + if (!api_get_configuration_value('gravatar_enabled')) { + $image_file .= '?rand='.time(); + } + + $img_attributes = 'src="' . $image_file . '" ' . 'alt="' . $user['complete_name'] . '" '; if ($image_size[0] > 200) { //limit display width to 200px $img_attributes .= 'width="200" '; diff --git a/main/gradebook/user_info.php b/main/gradebook/user_info.php index 134c844928..f623536083 100755 --- a/main/gradebook/user_info.php +++ b/main/gradebook/user_info.php @@ -48,7 +48,11 @@ $image_size = getimagesize($image_syspath['dir'].$image_syspath['file']); $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false,true); $image_file = $image_path['dir'].$image_path['file']; -$img_attributes = 'src="'.$image_file.'?rand='.time().'" ' +if (!api_get_configuration_value('gravatar_enabled')) { + $image_file .= '?rand='.time(); +} + +$img_attributes = 'src="'.$image_file.'" ' .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" ' .'style="float:left; padding:5px;" '; diff --git a/main/inc/course_document.inc.php b/main/inc/course_document.inc.php index 44b75f1c23..6bd71b26a3 100755 --- a/main/inc/course_document.inc.php +++ b/main/inc/course_document.inc.php @@ -64,10 +64,9 @@ if (api_is_in_course()) { $http_www = $_configuration['root_web'].'home/default_platform_document/'; } else { // 4. The user is outside courses. - $my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'system'); - $base_work_dir = $my_path['dir'].'my_files/'; - $my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web'); - $http_www = $my_path['dir'].'my_files/'; + $userId = api_get_user_id(); + $base_work_dir = UserManager::getUserPathById($userId, 'system').'my_files/'; + $http_www = UserManager::getUserPathById($userId, 'web').'my_files/'; } } diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index 3096598c78..ade6b9b62c 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -1417,26 +1417,24 @@ function _api_format_user($user, $add_password = false) } $image_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename; - if ($picture_filename) { - if (file_exists($image_sys_path)) { - $result['avatar'] = api_get_path(WEB_CODE_PATH).$dir.$picture_filename; - $result['avatar_small'] = api_get_path(WEB_CODE_PATH).$dir.'small_'.$picture_filename; - $result['avatar_sys_path'] = api_get_path(SYS_CODE_PATH).$dir.$picture_filename; - } else if (api_get_configuration_value('gravatar_enabled')) { - $userEmail = isset($user['email']) ? $user['email'] : ''; - $gravatarType = api_get_configuration_value('gravatar_type'); - $avatarPaths = array( - 'avatar' => $result['avatar'], - 'avatar_small' => $result['avatar_small'], - 'avatar_sys_path' => $result['avatar_sys_path'] - ); - foreach ($avatarPaths as $key => $value) { - $avatarSize = api_getimagesize($value); - $avatarSize = $avatarSize['width'] > $avatarSize['height'] ? - $avatarSize['width'] : - $avatarSize['height']; - $result[$key] = UserManager::getGravatar($userEmail, $avatarSize, $gravatarType); - } + if ($picture_filename && file_exists($image_sys_path)) { + $result['avatar'] = api_get_path(WEB_CODE_PATH).$dir.$picture_filename; + $result['avatar_small'] = api_get_path(WEB_CODE_PATH).$dir.'small_'.$picture_filename; + $result['avatar_sys_path'] = api_get_path(SYS_CODE_PATH).$dir.$picture_filename; + } else if (api_get_configuration_value('gravatar_enabled')) { + $userEmail = isset($user['email']) ? $user['email'] : ''; + $gravatarType = api_get_configuration_value('gravatar_type'); + $avatarPaths = array( + 'avatar' => $result['avatar'], + 'avatar_small' => $result['avatar_small'], + 'avatar_sys_path' => $result['avatar_sys_path'] + ); + foreach ($avatarPaths as $key => $value) { + $avatarSize = api_getimagesize($value); + $avatarSize = $avatarSize['width'] > $avatarSize['height'] ? + $avatarSize['width'] : + $avatarSize['height']; + $result[$key] = UserManager::getGravatar($userEmail, $avatarSize, $gravatarType); } } diff --git a/main/inc/lib/certificate.lib.php b/main/inc/lib/certificate.lib.php index 8314e9f1fc..4dc7a3a1f0 100755 --- a/main/inc/lib/certificate.lib.php +++ b/main/inc/lib/certificate.lib.php @@ -89,15 +89,15 @@ class Certificate extends Model $this->certification_user_path = null; //Setting certification path - $path_info = UserManager::get_user_picture_path_by_id($this->user_id, 'system'); - $web_path_info = UserManager::get_user_picture_path_by_id($this->user_id, 'web'); + $path_info = UserManager::getUserPathById($this->user_id, 'system'); + $web_path_info = UserManager::getUserPathById($this->user_id, 'web'); - if (!empty($path_info) && isset($path_info['dir'])) { - $this->certification_user_path = $path_info['dir'].'certificate/'; - $this->certification_web_user_path = $web_path_info['dir'].'certificate/'; + if (!empty($path_info) && isset($path_info)) { + $this->certification_user_path = $path_info.'certificate/'; + $this->certification_web_user_path = $web_path_info.'certificate/'; - if (!is_dir($path_info['dir'])) { - mkdir($path_info['dir'], 0777, true); + if (!is_dir($path_info)) { + mkdir($path_info, 0777, true); } if (!is_dir($this->certification_user_path)) { mkdir($this->certification_user_path, 0777); diff --git a/main/inc/lib/extra_field_value.lib.php b/main/inc/lib/extra_field_value.lib.php index 793c79f6dc..93a1edd38d 100755 --- a/main/inc/lib/extra_field_value.lib.php +++ b/main/inc/lib/extra_field_value.lib.php @@ -173,8 +173,7 @@ class ExtraFieldValue extends Model $fileDir = "upload/sessions/"; break; case 'user': - $userPath = UserManager::get_user_picture_path_by_id($this->handler_id); - $fileDir = $userPath['dir']; + $fileDir = UserManager::getUserPathById($this->handler_id); break; } @@ -213,8 +212,7 @@ class ExtraFieldValue extends Model $fileDir = "upload/sessions/"; break; case 'user': - $userPath = UserManager::get_user_picture_path_by_id($this->handler_id); - $fileDir = $userPath['dir']; + $fileDir = UserManager::getUserPathById($this->handler_id); break; } diff --git a/main/inc/lib/group_portal_manager.lib.php b/main/inc/lib/group_portal_manager.lib.php index f527f86291..6d3e02dff2 100755 --- a/main/inc/lib/group_portal_manager.lib.php +++ b/main/inc/lib/group_portal_manager.lib.php @@ -912,8 +912,10 @@ class GroupPortalManager $base = ''; } + $noPicturePath = array('dir' => $base.'img/', 'file' => 'unknown.jpg'); + if (empty($id) || empty($type)) { - return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => ''); + return $anonymous ? $noPicturePath : array('dir' => '', 'file' => ''); } $id = intval($id); @@ -923,7 +925,7 @@ class GroupPortalManager $res = Database::query($sql); if (!Database::num_rows($res)) { - return $anonymous ? array('dir' => $base.'img/', 'file' => 'unknown.jpg') : array('dir' => '', 'file' => ''); + return $anonymous ? $noPicturePath : array('dir' => '', 'file' => ''); } $user = Database::fetch_array($res); @@ -940,9 +942,11 @@ class GroupPortalManager } else { $dir = $base.'upload/users/groups/'.$id.'/'; } + if (empty($picture_filename) && $anonymous) { - return array('dir' => $base.'img/', 'file' => 'unknown.jpg'); + return $noPicturePath; } + return array('dir' => $dir, 'file' => $picture_filename); } diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index 941a1a8e84..abf209dbca 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -502,7 +502,7 @@ class MessageManager if (!empty($group_id)) { $path_user_info = GroupPortalManager::get_group_picture_path_by_id($group_id, 'system', true); } else { - $path_user_info = UserManager::get_user_picture_path_by_id($message_user_id, 'system', true); + $path_user_info['dir'] = UserManager::getUserPathById($message_user_id, 'system'); } $path_message_attach = $path_user_info['dir'].'message_attachments/'; @@ -548,7 +548,7 @@ class MessageManager if (!empty($group_id)) { $path_user_info = GroupPortalManager::get_group_picture_path_by_id($group_id, 'system', true); } else { - $path_user_info = UserManager::get_user_picture_path_by_id($message_uid, 'system', true); + $path_user_info['dir'] = UserManager::getUserPathById($message_uid, 'system'); } $path_message_attach = $path_user_info['dir'].'message_attachments/'; diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index c87179670d..5ea4b03618 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -643,8 +643,12 @@ class SocialManager extends UserManager $img_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true, true); $big_image = UserManager::get_picture_user($user_id, $img_array['file'], '', USER_IMAGE_SIZE_BIG); - $big_image = $big_image['file'].'?'.uniqid(); - $normal_image = $img_array['dir'].$img_array['file'].'?'.uniqid(); + $big_image = $big_image['file']; + $normal_image = $img_array['dir'].$img_array['file']; + if (!api_get_configuration_value('gravatar_enabled')) { + $big_image .= '?'.uniqid(); + $normal_image .= '?'.uniqid(); + } //--- User image if ($img_array['file'] != 'unknown.jpg') { @@ -953,13 +957,14 @@ class SocialManager extends UserManager $status_icon = Display::span('', array('class' => 'online_user_in_text')); $user_status = $user_info['status'] == 1 ? Display::span('', array('class' => 'teacher_online')) : Display::span('', array('class' => 'student_online')); - if ($image_array['file'] == 'unknown.jpg' || !file_exists($image_array['dir'].$image_array['file'])) { + $friends_profile = UserManager::get_picture_user($uid, $image_array['file'], 80, USER_IMAGE_SIZE_ORIGINAL); + if (($image_array['file'] == 'unknown.jpg' + || !file_exists($image_array['dir'].$image_array['file'])) && + !api_get_configuration_value('gravatar_enabled')) { $friends_profile['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_180_100.jpg'; - $img = ''.$name.''; - } else { - $friends_profile = UserManager::get_picture_user($uid, $image_array['file'], 80, USER_IMAGE_SIZE_ORIGINAL); - $img = ''.$name.''; + } + $img = ''.$name.''; $name = ''.$status_icon.$user_status.$name.'
'; $html .= '
  • '.$img.'
    '.$name.'
  • '; } @@ -997,12 +1002,16 @@ class SocialManager extends UserManager $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList')); $html .= '
    '; + + $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'system'); + $sysdir = $sysdir_array['dir']; + $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'web'); if (strlen(trim($user_object->picture_uri)) > 0) { - $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'system'); - $sysdir = $sysdir_array['dir']; - $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'web'); $webdir = $webdir_array['dir']; - $fullurl = $webdir.$user_object->picture_uri; + $fullurl = $webdir; + $fullurl .= api_get_configuration_value('gravatar_enabled') ? + $webdir_array['file'] : + $user_object->picture_uri; $system_image_path = $sysdir.$user_object->picture_uri; list($width, $height, $type, $attr) = @getimagesize($system_image_path); $height += 30; @@ -1016,7 +1025,9 @@ class SocialManager extends UserManager //echo ''; $html .= ''.$alt.''; } else { - $html .= Display::return_icon('unknown.jpg', get_lang('Unknown')); + $html .= api_get_configuration_value('gravatar_enabled') ? + ''.$alt.'' : + Display::return_icon('unknown.jpg', get_lang('Unknown')); } if (!empty($status)) { $html .= '
    '.$status.'
    '; @@ -1059,10 +1070,9 @@ class SocialManager extends UserManager */ public static function display_productions($user_id) { - $sysdir_array = UserManager::get_user_picture_path_by_id($user_id, 'system', true); - $sysdir = $sysdir_array['dir']; $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true); - $webdir = $webdir_array['dir']; + $sysdir = UserManager::getUserPathById($user_id, 'system'); + $webdir = UserManager::getUserPathById($user_id, 'web'); if (!is_dir($sysdir)) { mkdir($sysdir, api_get_permissions_for_new_directories(), true); @@ -1190,9 +1200,8 @@ class SocialManager extends UserManager $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); // create directory - $pathUserInfo = UserManager::get_user_picture_path_by_id($userId, 'system', true); $social = '/social/'; - $pathMessageAttach = $pathUserInfo['dir'] . 'message_attachments'. $social; + $pathMessageAttach = UserManager::getUserPathById($userId, 'system').'message_attachments'.$social; $safeFileComment = Database::escape_string($fileComment); $safeFileName = Database::escape_string($fileAttach['name']); @@ -1246,6 +1255,7 @@ class SocialManager extends UserManager if (empty($start)) { $start = '0000-00-00'; } + $tblMessage = Database::get_main_table(TABLE_MESSAGE); $tblMessageAttachement = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT); @@ -1254,10 +1264,10 @@ class SocialManager extends UserManager $limit = intval($limit); $sql = "SELECT id, user_sender_id,user_receiver_id, send_date, content, parent_id, - (SELECT ma.path FROM $tblMessageAttachement ma WHERE ma.message_id = tm.id ) as path, - (SELECT ma.filename FROM $tblMessageAttachement ma WHERE ma.message_id = tm.id ) as filename - FROM $tblMessage tm - WHERE user_receiver_id = $userId + (SELECT ma.path FROM $tblMessageAttachement ma WHERE ma.message_id = tm.id ) as path, + (SELECT ma.filename FROM $tblMessageAttachement ma WHERE ma.message_id = tm.id ) as filename + FROM $tblMessage tm + WHERE user_receiver_id = $userId AND send_date > '$start' "; $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' "; $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' "; @@ -1426,9 +1436,13 @@ class SocialManager extends UserManager $wallImage = ''; if (!empty($message['path'])) { $pathUserInfo = UserManager::get_user_picture_path_by_id($authorId, 'web', true); - $pathImg = $pathUserInfo['dir'] . 'message_attachments'; - $imageBig = $pathImg .self::getImagePath($message['path'], IMAGE_WALL_BIG); - $imageSmall = $pathImg. self::getImagePath($message['path'], IMAGE_WALL_SMALL); + $imageBig = $pathUserInfo['file']; + $imageSmall = $pathUserInfo['file']; + if (!api_get_configuration_value('gravatar_enabled')) { + $pathImg = UserManager::getUserPathById($authorId, 'web').'message_attachments'; + $imageBig = $pathImg .self::getImagePath($message['path'], IMAGE_WALL_BIG); + $imageSmall = $pathImg. self::getImagePath($message['path'], IMAGE_WALL_SMALL); + } $wallImage = '
    '; } diff --git a/main/inc/lib/svg-edit/extensions/imagelib/users.php b/main/inc/lib/svg-edit/extensions/imagelib/users.php index 38b4e4b235..74e633b3d6 100755 --- a/main/inc/lib/svg-edit/extensions/imagelib/users.php +++ b/main/inc/lib/svg-edit/extensions/imagelib/users.php @@ -10,11 +10,9 @@ require_once '../../../../../inc/global.inc.php'; api_protect_course_script(); api_block_anonymous_users(); -$my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system'); -$user_disk_path = $my_path['dir'].'my_files/'; - -$my_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web'); -$user_web_path = $my_path['dir'].'my_files/'; +$userId = api_get_user_id(); +$user_disk_path = UserManager::getUserPathById($userId, 'system').'my_files/'; +$user_web_path = UserManager::getUserPathById($userId, 'web').'my_files/'; //get all files and folders $scan_files = scandir($user_disk_path); diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 72691c2dfe..0241e2470f 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -1234,10 +1234,10 @@ class UserManager default: // Base: empty, the result path below will be relative. $base = ''; } - + $gravatarEnabled = api_get_configuration_value('gravatar_enabled'); $noPicturePath = array('dir' => $base.'img/', 'file' => 'unknown.jpg'); - if (empty($id) || empty($type)) { + if ((empty($id) || empty($type)) && !$gravatarEnabled) { return $anonymous ? $noPicturePath : array('dir' => '', 'file' => ''); } @@ -1247,7 +1247,7 @@ class UserManager $sql = "SELECT email, picture_uri FROM $user_table WHERE user_id=".$user_id; $res = Database::query($sql); - if (!Database::num_rows($res)) { + if (!Database::num_rows($res) && !$gravatarEnabled) { return $anonymous ? $noPicturePath : array('dir' => '', 'file' => ''); } @@ -1265,27 +1265,23 @@ class UserManager $dir = $base.$userPath; } - if (empty($picture_filename) || - (!empty($picture_filename) && !file_exists($systemImagePath.$picture_filename)) - ) { - if ($anonymous) { - return $noPicturePath; - } + if ($gravatarEnabled) { + $avatarSize = api_getimagesize($noPicturePath['dir'].$noPicturePath['file']); + $avatarSize = $avatarSize['width'] > $avatarSize['height'] ? + $avatarSize['width'] : + $avatarSize['height']; + return array( + 'dir' => '', + 'file' => self::getGravatar( + $user['email'], + $avatarSize, + api_get_configuration_value('gravatar_type') + ) + ); + } - if (api_get_configuration_value('gravatar_enabled')) { - $avatarSize = api_getimagesize($noPicturePath['dir'].$noPicturePath['file']); - $avatarSize = $avatarSize['width'] > $avatarSize['height'] ? - $avatarSize['width'] : - $avatarSize['height']; - return array( - 'dir' => '', - 'file' => self::getGravatar( - $user['email'], - $avatarSize, - api_get_configuration_value('gravatar_type') - ) - ); - } + if (empty($picture_filename) && $anonymous) { + return $noPicturePath; } return array('dir' => $dir, 'file' => $picture_filename); @@ -3247,6 +3243,7 @@ class UserManager */ public static function get_picture_user($user_id, $picture_file, $height, $size_picture = USER_IMAGE_SIZE_MEDIUM, $style = '') { + $gravatarEnabled = api_get_configuration_value('gravatar_enabled'); $picture = array(); $picture['style'] = $style; if ($picture_file == 'unknown.jpg') { @@ -3261,7 +3258,9 @@ class UserManager break; } $picture['file'] = api_get_path(WEB_CODE_PATH).'img/'.$picture_file; - return $picture; + if (!$gravatarEnabled) { + return $picture; + } } switch ($size_picture) { @@ -3319,6 +3318,9 @@ class UserManager } } } + if ($gravatarEnabled) { + $picture['file'] = $image_array['file']; + } return $picture; } @@ -5285,4 +5287,37 @@ EOF; } return $url; } + + /** + * Get user path from user ID (returns an array). + * The return format is a complete path, enabling recovery of the directory + * with dirname(). This also works for the functions dealing with the + * user's productions, as they are located in the same directory. + * @param integer User ID + * @param string Optional. Type of path to return (can be 'system', 'rel', 'web') + * @return string User path + */ + public static function getUserPathById($id, $type = null) + { + $user_id = intval($id); + if (!$user_id) { + return null; + } + $userPath = "upload/users/$user_id/"; + if (api_get_setting('split_users_upload_directory') === 'true') { + $userPath = 'upload/users/'.substr((string) $user_id, 0, 1).'/'.$user_id.'/'; + } + switch ($type) { + case 'system': // Base: absolute system path. + $userPath = api_get_path(SYS_CODE_PATH).$userPath; + break; + case 'rel': // Base: semi-absolute web path (no server base). + $userPath = api_get_path(REL_CODE_PATH).$userPath; + break; + case 'web': // Base: absolute web path. + $userPath = api_get_path(WEB_CODE_PATH).$userPath; + break; + } + return $userPath; + } } diff --git a/main/messages/download.php b/main/messages/download.php index b3b60933f0..f77f28fc72 100755 --- a/main/messages/download.php +++ b/main/messages/download.php @@ -78,7 +78,7 @@ if ($not_allowed_to_edit) { if (!empty($row_users['group_id'])) { $path_user_info = GroupPortalManager::get_group_picture_path_by_id($row_users['group_id'], 'system', true); } else { - $path_user_info = UserManager::get_user_picture_path_by_id($message_uid, 'system', true); + $path_user_info['dir'] = UserManager::getUserPathById($message_uid, 'system'); } $full_file_name = $path_user_info['dir'].'message_attachments/'.$file_url; diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 9c25bb066b..6a577fd526 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -461,6 +461,7 @@ if (!empty($student_id)) { echo ''; echo ''; + $gravatarEnabled = api_get_configuration_value('gravatar_enabled'); $image_array = UserManager :: get_user_picture_path_by_id($user_info['user_id'], 'web', false, true); echo '
    '; @@ -470,8 +471,13 @@ if (!empty($student_id)) { $big_image_size = api_getimagesize($big_image); $big_image_width = $big_image_size['width']; $big_image_height = $big_image_size['height']; - $url_big_image = $big_image . '?rnd=' . time(); - $img_attributes = 'src="' . $image_file . '?rand=' . time() . '" ' . + $url_big_image = $image_file; + if (!$gravatarEnabled) { + $url_big_image = $big_image.'?rnd=' . time(); + $image_file .= '?rnd=' . time(); + } + + $img_attributes = 'src="' . $image_file . '" ' . 'alt="' . $user_info['complete_name']. '" ' . 'style="float:' . ($text_dir == 'rtl' ? 'right' : 'left') . '; padding:5px;" '; diff --git a/main/user/userInfo.php b/main/user/userInfo.php index d2e5c9edaf..e6f65974b5 100755 --- a/main/user/userInfo.php +++ b/main/user/userInfo.php @@ -338,7 +338,10 @@ elseif ($displayMode == "viewContentEdit") { $big_image_size = api_getimagesize($big_image); $big_image_width= $big_image_size['width']; $big_image_height= $big_image_size['height']; - $url_big_image = $big_image.'?rnd='.time(); + $url_big_image = $image_array['file']; + if (!api_get_configuration_value('gravatar_enabled')) { + $url_big_image = $big_image.'?rnd='.time(); + } if ($image_array['file']=='unknown.jpg') { echo ''; @@ -428,8 +431,10 @@ elseif ($displayMode == "viewContentEdit") { $big_image_size = api_getimagesize($big_image); $big_image_width= $big_image_size['width']; $big_image_height= $big_image_size['height']; - $url_big_image = $big_image.'?rnd='.time(); - + $url_big_image = $image_array['file']; + if (!api_get_configuration_value('gravatar_enabled')) { + $url_big_image = $big_image.'?rnd='.time(); + } if ($image_array['file']=='unknown.jpg') { echo ''; } else { diff --git a/main/wiki/wiki.inc.php b/main/wiki/wiki.inc.php index 402d094e62..32b428eeea 100755 --- a/main/wiki/wiki.inc.php +++ b/main/wiki/wiki.inc.php @@ -1853,23 +1853,25 @@ class Wiki $all_students_pages = array(); //data about teacher - $userinfo = api_get_user_info(api_get_user_id()); + $userId = api_get_user_id(); + $userinfo = api_get_user_info($userId); $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username'], ENT_QUOTES)); $name = $userinfo['complete_name']." - ".$username; - if (api_get_user_id()<>0) { - $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',false, true); + + $photo= ''.$name.''; + + if ($userId) { + $image_path = UserManager::get_user_picture_path_by_id($userId, 'web', false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; - $photo= ''.$name.''; - } else { - $photo= ''.$name.''; + $photo = '' . $name . ''; } //teacher assignment title $title_orig = $values['title']; //teacher assignment reflink - $link2teacher = $values['title'] = $title_orig."_uass".api_get_user_id(); + $link2teacher = $values['title'] = $title_orig."_uass".$userId; //first: teacher name, photo, and assignment description (original content) // $content_orig_A='
    '.$photo.'
    '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'
    ('.get_lang('Teacher').')

    '; @@ -1883,7 +1885,7 @@ class Wiki //Second: student list (names, photo and links to their works). //Third: Create Students work pages. foreach ($a_users_to_add as $o_user_to_add) { - if ($o_user_to_add['user_id'] != api_get_user_id()) { + if ($o_user_to_add['user_id'] != $userId) { //except that puts the task $assig_user_id = $o_user_to_add['user_id']; //identifies each page as created by the student, not by teacher $image_path = UserManager::get_user_picture_path_by_id($assig_user_id,'web',false, true); @@ -1933,7 +1935,7 @@ class Wiki } foreach ($a_users_to_add as $o_user_to_add) { - if ($o_user_to_add['user_id'] == api_get_user_id()) { + if ($o_user_to_add['user_id'] == $userId) { $assig_user_id=$o_user_to_add['user_id']; if ($assignment_type == 1) { $values['title']= $title_orig; @@ -3183,7 +3185,7 @@ class Wiki $sql="SELECT * FROM $tbl_wiki_discuss reviews, $user_table user WHERE reviews.c_id = $course_id AND reviews.publication_id='".$id."' AND user.user_id='".$firstuserid."' - ORDER BY id DESC"; + ORDER BY reviews.id DESC"; $result=Database::query($sql) or die(Database::error()); $countWPost = Database::num_rows($result); @@ -3229,13 +3231,14 @@ class Wiki $user_id = $row['userc_id']; $name = $userinfo['complete_name']; - if ($user_id<>0) { + + $author_photo= ''.api_htmlentities($name).''; + + if ($user_id) { $image_path = UserManager::get_user_picture_path_by_id($user_id,'web',false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; $author_photo= ''.api_htmlentities($name).''; - } else { - $author_photo= ''.api_htmlentities($name).''; } //stars diff --git a/src/Chamilo/CoreBundle/Component/Editor/Driver/PersonalDriver.php b/src/Chamilo/CoreBundle/Component/Editor/Driver/PersonalDriver.php index ec03cad18a..29fc311908 100644 --- a/src/Chamilo/CoreBundle/Component/Editor/Driver/PersonalDriver.php +++ b/src/Chamilo/CoreBundle/Component/Editor/Driver/PersonalDriver.php @@ -18,9 +18,9 @@ class PersonalDriver extends Driver implements DriverInterface public function setup() { $userId = api_get_user_id(); - $path = \UserManager::get_user_picture_path_by_id($userId, 'none'); - if (!empty($path['dir'])) { - $dir = api_get_path(SYS_CODE_PATH) . $path['dir']; + $path = \UserManager::getUserPathById($userId); + if (!empty($path)) { + $dir = api_get_path(SYS_CODE_PATH) . $path; if (!is_dir($dir)) { mkdir($dir); @@ -44,21 +44,15 @@ class PersonalDriver extends Driver implements DriverInterface if (!empty($userId)) { // Adding user personal files - $dir = \UserManager::get_user_picture_path_by_id( - $userId, - 'system' - ); + $dir = \UserManager::getUserPathById($userId, 'system'); - $dirWeb = \UserManager::get_user_picture_path_by_id( - $userId, - 'web' - ); + $dirWeb = \UserManager::getUserPathById($userId, 'web'); $driver = array( 'driver' => 'PersonalDriver', 'alias' => get_lang('MyFiles'), - 'path' => $dir['dir'] . 'my_files', - 'URL' => $dirWeb['dir'] . 'my_files', + 'path' => $dir.'my_files', + 'URL' => $dirWeb.'my_files', 'accessControl' => array($this, 'access') );