diff options
Diffstat (limited to 'mod/profile')
| -rw-r--r-- | mod/profile/icon.php | 53 | ||||
| -rw-r--r-- | mod/profile/icondirect.php | 66 | ||||
| -rw-r--r-- | mod/profile/manifest.xml | 10 | ||||
| -rw-r--r-- | mod/profile/start.php | 101 | ||||
| -rw-r--r-- | mod/profile/views/default/profile/css.php | 45 | ||||
| -rw-r--r-- | mod/profile/views/default/profile/details.php | 24 | ||||
| -rw-r--r-- | mod/profile/views/default/profile/js.php | 9 | ||||
| -rw-r--r-- | mod/profile/views/default/profile/metatags.php | 8 | ||||
| -rw-r--r--[-rwxr-xr-x] | mod/profile/views/default/profile/owner_block.php | 17 | ||||
| -rw-r--r-- | mod/profile/views/default/profile/wrapper.php | 8 |
10 files changed, 196 insertions, 145 deletions
diff --git a/mod/profile/icon.php b/mod/profile/icon.php deleted file mode 100644 index a624c0811..000000000 --- a/mod/profile/icon.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php -/** -* Elgg profile icon -* -* @package ElggProfile -*/ - -require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); - -// Get the owning user -$user = elgg_get_page_owner_entity(); - -// Get the size -$size = strtolower(get_input('size')); -if (!in_array($size,array('large','medium','small','tiny','master','topbar'))) - $size = "medium"; - -// If user doesn't exist, return default icon -if (!$user) { - $path = elgg_view("icon/user/default/$size"); - header("Location: $path"); - exit; -} - -// Try and get the icon -$filehandler = new ElggFile(); -$filehandler->owner_guid = $user->getGUID(); -$filehandler->setFilename("profile/" . $user->getGUID() . $size . ".jpg"); - -$success = false; -if ($filehandler->open("read")) { - if ($contents = $filehandler->read($filehandler->size())) { - $success = true; - } -} - -if (!$success) { - $path = elgg_view("icon/user/default/$size"); - header("Location: $path"); - exit; -} - -header("Content-type: image/jpeg"); -header('Expires: ' . date('r',time() + 864000)); -header("Pragma: public"); -header("Cache-Control: public"); -header("Content-Length: " . strlen($contents)); - -$splitString = str_split($contents, 1024); - -foreach($splitString as $chunk) { - echo $chunk; -}
\ No newline at end of file diff --git a/mod/profile/icondirect.php b/mod/profile/icondirect.php index fe4726d1a..5f1599e0d 100644 --- a/mod/profile/icondirect.php +++ b/mod/profile/icondirect.php @@ -1,38 +1,47 @@ <?php - /** * Elgg profile icon cache/bypass * + * * @package ElggProfile */ - // Get DB settings require_once(dirname(dirname(dirname(__FILE__))). '/engine/settings.php'); global $CONFIG; -$joindate = (int)$_GET['joindate']; +// won't be able to serve anything if no joindate or guid +if (!isset($_GET['joindate']) || !isset($_GET['guid'])) { + header("HTTP/1.1 404 Not Found"); + exit; +} + +$join_date = (int)$_GET['joindate']; +$last_cache = (int)$_GET['lastcache']; // icontime $guid = (int)$_GET['guid']; +// If is the same ETag, content didn't changed. +$etag = $last_cache . $guid; +if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") { + header("HTTP/1.1 304 Not Modified"); + exit; +} + $size = strtolower($_GET['size']); -if (!in_array($size,array('large','medium','small','tiny','master','topbar'))) { +if (!in_array($size, array('large', 'medium', 'small', 'tiny', 'master', 'topbar'))) { $size = "medium"; } -$mysql_dblink = @mysql_connect($CONFIG->dbhost,$CONFIG->dbuser,$CONFIG->dbpass, true); +$mysql_dblink = @mysql_connect($CONFIG->dbhost, $CONFIG->dbuser, $CONFIG->dbpass, true); if ($mysql_dblink) { - if (@mysql_select_db($CONFIG->dbname,$mysql_dblink)) { - - // get dataroot and simplecache_enabled in one select for efficiency - if ($result = mysql_query("select name, value from {$CONFIG->dbprefix}datalists where name in ('dataroot','simplecache_enabled')",$mysql_dblink)) { - $simplecache_enabled = true; + if (@mysql_select_db($CONFIG->dbname, $mysql_dblink)) { + $result = mysql_query("select name, value from {$CONFIG->dbprefix}datalists where name='dataroot'", $mysql_dblink); + if ($result) { $row = mysql_fetch_object($result); while ($row) { if ($row->name == 'dataroot') { - $dataroot = $row->value; - } else if ($row->name == 'simplecache_enabled') { - $simplecache_enabled = $row->value; + $data_root = $row->value; } $row = mysql_fetch_object($result); } @@ -40,23 +49,21 @@ if ($mysql_dblink) { @mysql_close($mysql_dblink); - // if the simplecache is enabled, we get icon directly - if ($simplecache_enabled) { + if (isset($data_root)) { - // first try to read icon directly - $user_path = date('Y/m/d/', $joindate) . $guid; - $filename = "$dataroot$user_path/profile/{$guid}{$size}.jpg"; - $contents = @file_get_contents($filename); - if (!empty($contents)) { + // this depends on ElggDiskFilestore::makeFileMatrix() + $user_path = date('Y/m/d/', $join_date) . $guid; + + $filename = "$data_root$user_path/profile/{$guid}{$size}.jpg"; + $filesize = @filesize($filename); + if ($filesize) { header("Content-type: image/jpeg"); - header('Expires: ' . date('r',time() + 864000)); + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true); header("Pragma: public"); header("Cache-Control: public"); - header("Content-Length: " . strlen($contents)); - $splitString = str_split($contents, 1024); - foreach($splitString as $chunk) { - echo $chunk; - } + header("Content-Length: $filesize"); + header("ETag: \"$etag\""); + readfile($filename); exit; } } @@ -64,8 +71,7 @@ if ($mysql_dblink) { } -// simplecache is not turned on or something went wrong so load engine and try that way +// something went wrong so load engine and try to forward to default icon require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); -$user = get_entity($guid); -set_input('username', $user->username); -require_once(dirname(__FILE__).'/icon.php'); +elgg_log("Profile icon direct failed.", "WARNING"); +forward("_graphics/icons/user/default{$size}.gif"); diff --git a/mod/profile/manifest.xml b/mod/profile/manifest.xml index cffd611df..86fbc7b7b 100644 --- a/mod/profile/manifest.xml +++ b/mod/profile/manifest.xml @@ -2,18 +2,16 @@ <plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> <name>Profile</name> <description>The default profile plugin.</description> - <author>Elgg.org</author> + <author>Core developers</author> <version>1.8</version> <category>bundled</category> <category>social</category> <website>http://elgg.org/</website> <copyright>See COPYRIGHT.txt</copyright> - <license>GNU Public License Version 2</license> + <license>GNU General Public License Version 2</license> <activate_on_install>true</activate_on_install> - <admin_interface>advanced</admin_interface> - <requires> - <type>elgg_version</type> - <version>2011010401</version> + <type>elgg_release</type> + <version>1.8</version> </requires> </plugin_manifest> diff --git a/mod/profile/start.php b/mod/profile/start.php index e17f955c5..ab596f235 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -7,6 +7,10 @@ elgg_register_event_handler('init', 'system', 'profile_init', 1); +// Metadata on users needs to be independent +// outside of init so it happens earlier in boot. See #3316 +register_metadata_as_independent('user'); + /** * Profile init function */ @@ -16,8 +20,9 @@ function profile_init() { // will dictate the URL for all ElggUser objects elgg_register_entity_url_handler('user', 'all', 'profile_url'); - // Metadata on users needs to be independent - register_metadata_as_independent('user'); + elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'profile_override_avatar_url'); + elgg_unregister_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook'); + elgg_register_simplecache_view('icon/user/default/tiny'); elgg_register_simplecache_view('icon/user/default/topbar'); @@ -26,11 +31,11 @@ function profile_init() { elgg_register_simplecache_view('icon/user/default/large'); elgg_register_simplecache_view('icon/user/default/master'); - // Register a page handler, so we can have nice URLs elgg_register_page_handler('profile', 'profile_page_handler'); - elgg_extend_view('html_head/extend', 'profile/metatags'); - elgg_extend_view('css/screen', 'profile/css'); + elgg_extend_view('page/elements/head', 'profile/metatags'); + elgg_extend_view('css/elgg', 'profile/css'); + elgg_extend_view('js/elgg', 'profile/js'); // allow ECML in parts of the profile elgg_register_plugin_hook_handler('get_views', 'ecml', 'profile_ecml_views_hook'); @@ -42,7 +47,8 @@ function profile_init() { /** * Profile page handler * - * @param array $page Array of page elements, forwarded by the page handling mechanism + * @param array $page Array of URL segments passed by the page handling mechanism + * @return bool */ function profile_page_handler($page) { @@ -50,6 +56,8 @@ function profile_page_handler($page) { $username = $page[0]; $user = get_user_by_username($username); elgg_set_page_owner_guid($user->guid); + } elseif (elgg_is_logged_in()) { + forward(elgg_get_logged_in_user_entity()->getURL()); } // short circuit if invalid or banned username @@ -65,9 +73,9 @@ function profile_page_handler($page) { if ($action == 'edit') { // use the core profile edit page - $base_dir = elgg_get_root_dir(); + $base_dir = elgg_get_root_path(); require "{$base_dir}pages/profile/edit.php"; - return; + return true; } // main profile page @@ -78,7 +86,8 @@ function profile_page_handler($page) { $content = elgg_view_layout('widgets', $params); $body = elgg_view_layout('one_column', array('content' => $content)); - echo elgg_view_page($title, $body); + echo elgg_view_page($user->name, $body); + return true; } /** @@ -88,18 +97,69 @@ function profile_page_handler($page) { * @return string User URL */ function profile_url($user) { - return elgg_get_site_url() . "pg/profile/" . $user->username; + return elgg_get_site_url() . "profile/" . $user->username; +} + +/** + * Use a URL for avatars that avoids loading Elgg engine for better performance + * + * @param string $hook + * @param string $entity_type + * @param string $return_value + * @param array $params + * @return string + */ +function profile_override_avatar_url($hook, $entity_type, $return_value, $params) { + + // if someone already set this, quit + if ($return_value) { + return null; + } + + $user = $params['entity']; + $size = $params['size']; + + if (!elgg_instanceof($user, 'user')) { + return null; + } + + $user_guid = $user->getGUID(); + $icon_time = $user->icontime; + + if (!$icon_time) { + return "_graphics/icons/user/default{$size}.gif"; + } + + if ($user->isBanned()) { + return null; + } + + $filehandler = new ElggFile(); + $filehandler->owner_guid = $user_guid; + $filehandler->setFilename("profile/{$user_guid}{$size}.jpg"); + + try { + if ($filehandler->exists()) { + $join_date = $user->getTimeCreated(); + return "mod/profile/icondirect.php?lastcache=$icon_time&joindate=$join_date&guid=$user_guid&size=$size"; + } + } catch (InvalidParameterException $e) { + elgg_log("Unable to get profile icon for user with GUID $user_guid", 'ERROR'); + return "_graphics/icons/default/$size.png"; + } + + return null; } /** * Parse ECML on parts of the profile * - * @param unknown_type $hook - * @param unknown_type $entity_type - * @param unknown_type $return_value - * @param unknown_type $params + * @param string $hook + * @param string $entity_type + * @param array $return_value + * @return array */ -function profile_ecml_views_hook($hook, $entity_type, $return_value, $params) { +function profile_ecml_views_hook($hook, $entity_type, $return_value) { $return_value['profile/profile_content'] = elgg_echo('profile'); return $return_value; @@ -108,13 +168,12 @@ function profile_ecml_views_hook($hook, $entity_type, $return_value, $params) { /** * Register profile widgets with default widgets * - * @param unknown_type $hook - * @param unknown_type $type - * @param unknown_type $return - * @param unknown_type $params + * @param string $hook + * @param string $type + * @param array $return * @return array */ -function profile_default_widgets_hook($hook, $type, $return, $params) { +function profile_default_widgets_hook($hook, $type, $return) { $return[] = array( 'name' => elgg_echo('profile'), 'widget_context' => 'profile', @@ -126,4 +185,4 @@ function profile_default_widgets_hook($hook, $type, $return, $params) { ); return $return; -}
\ No newline at end of file +} diff --git a/mod/profile/views/default/profile/css.php b/mod/profile/views/default/profile/css.php index d252dec68..e24f555a9 100644 --- a/mod/profile/views/default/profile/css.php +++ b/mod/profile/views/default/profile/css.php @@ -14,9 +14,11 @@ } .profile .elgg-inner { margin: 0 5px; - border: 2px solid #eeeeee; + border: 2px solid #eee; + -webkit-border-radius: 8px; -moz-border-radius: 8px; + border-radius: 8px; } #profile-details { padding: 15px; @@ -25,7 +27,7 @@ #profile-owner-block { width: 200px; float: left; - background-color: #eeeeee; + background-color: #eee; padding: 15px; } #profile-owner-block .large { @@ -37,8 +39,11 @@ } .profile-content-menu a { display: block; + -webkit-border-radius: 8px; -moz-border-radius: 8px; + border-radius: 8px; + background-color: white; margin: 3px 0 5px 0; padding: 2px 4px 2px 8px; @@ -53,16 +58,21 @@ } .profile-admin-menu-wrapper a { display: block; + -webkit-border-radius: 8px; -moz-border-radius: 8px; + border-radius: 8px; + background-color: white; margin: 3px 0 5px 0; padding: 2px 4px 2px 8px; } .profile-admin-menu-wrapper { background-color: white; + -webkit-border-radius: 8px; -moz-border-radius: 8px; + border-radius: 8px; } .profile-admin-menu-wrapper li a { background-color: white; @@ -74,32 +84,43 @@ } /*** profile details ***/ #profile-details .odd { - background-color:#f4f4f4; + background-color: #f4f4f4; + -webkit-border-radius: 4px; -moz-border-radius: 4px; - margin:0 0 7px 0; - padding:2px 4px 2px 4px; + border-radius: 4px; + + margin: 0 0 7px; + padding: 2px 4px; } #profile-details .even { background-color:#f4f4f4; + -webkit-border-radius: 4px; -moz-border-radius: 4px; - margin:0 0 7px 0; - padding:2px 4px 2px 4px; + border-radius: 4px; + + margin: 0 0 7px; + padding: 2px 4px; } .profile-aboutme-title { background-color:#f4f4f4; + -webkit-border-radius: 4px; -moz-border-radius: 4px; - margin:0 0 0px 0; - padding:2px 4px 2px 4px; + border-radius: 4px; + + margin: 0; + padding: 2px 4px; } .profile-aboutme-contents { - padding:2px 0 0 3px; + padding: 2px 0 0 3px; } .profile-banned-user { - border:2px solid red; - padding:4px 8px; + border: 2px solid red; + padding: 4px 8px; + -webkit-border-radius: 6px; -moz-border-radius: 6px; + border-radius: 6px; } diff --git a/mod/profile/views/default/profile/details.php b/mod/profile/views/default/profile/details.php index 04d95001d..da4e95690 100644 --- a/mod/profile/views/default/profile/details.php +++ b/mod/profile/views/default/profile/details.php @@ -21,16 +21,30 @@ if (is_array($profile_fields) && sizeof($profile_fields) > 0) { continue; } $value = $user->$shortname; + if (!empty($value)) { - //This function controls the alternating class + + // fix profile URLs populated by https://github.com/Elgg/Elgg/issues/5232 + // @todo Replace with upgrade script, only need to alter users with last_update after 1.8.13 + if ($valtype == 'url' && $value == 'http://') { + $user->$shortname = ''; + continue; + } + + // validate urls + if ($valtype == 'url' && !preg_match('~^https?\://~i', $value)) { + $value = "http://$value"; + } + + // this controls the alternating class $even_odd = ( 'odd' != $even_odd ) ? 'odd' : 'even'; ?> - <p class="<?php echo $even_odd; ?>"> + <div class="<?php echo $even_odd; ?>"> <b><?php echo elgg_echo("profile:{$shortname}"); ?>: </b> <?php - echo elgg_view("output/{$valtype}", array('value' => $user->$shortname)); + echo elgg_view("output/{$valtype}", array('value' => $value)); ?> - </p> + </div> <?php } } @@ -45,7 +59,7 @@ if (!elgg_get_config('profile_custom_fields')) { if ($user->description) { echo "<p class='profile-aboutme-title'><b>" . elgg_echo("profile:aboutme") . "</b></p>"; echo "<div class='profile-aboutme-contents'>"; - echo elgg_view('output/longtext', array('value' => $user->description)); + echo elgg_view('output/longtext', array('value' => $user->description, 'class' => 'mtn')); echo "</div>"; } } diff --git a/mod/profile/views/default/profile/js.php b/mod/profile/views/default/profile/js.php new file mode 100644 index 000000000..5a08a90bd --- /dev/null +++ b/mod/profile/views/default/profile/js.php @@ -0,0 +1,9 @@ + +// force the first column to at least be as large as the profile box in cols 2 and 3 +// we also want to run before the widget init happens so priority is < 500 +elgg.register_hook_handler('init', 'system', function() { + // only do this on the profile page's widget canvas. + if ($('.profile').length) { + $('#elgg-widget-col-1').css('min-height', $('.profile').outerHeight(true) + 1); + } +}, 400); diff --git a/mod/profile/views/default/profile/metatags.php b/mod/profile/views/default/profile/metatags.php index 54ee322e2..52048b8a7 100644 --- a/mod/profile/views/default/profile/metatags.php +++ b/mod/profile/views/default/profile/metatags.php @@ -6,9 +6,11 @@ * */ -if (elgg_get_page_owner_entity()) { +$owner = elgg_get_page_owner_entity(); + +if (elgg_instanceof($owner, 'user')) { ?> - <link rel="meta" type="application/rdf+xml" title="FOAF" href="<?php echo full_url(); ?>?view=foaf" /> + <link rel="meta" type="application/rdf+xml" title="FOAF" href="<?php echo current_page_url(); ?>?view=foaf" /> <?php -}
\ No newline at end of file +} diff --git a/mod/profile/views/default/profile/owner_block.php b/mod/profile/views/default/profile/owner_block.php index 0172a2e1d..63cb5391a 100755..100644 --- a/mod/profile/views/default/profile/owner_block.php +++ b/mod/profile/views/default/profile/owner_block.php @@ -11,10 +11,9 @@ if (!$user) { return TRUE; } -$icon = elgg_view("profile/icon", array( - 'entity' => $user, - 'size' => 'large', - 'override' => 'true' +$icon = elgg_view_entity_icon($user, 'large', array( + 'use_hover' => false, + 'use_link' => false, )); // grab the actions and admin menu items from user hover @@ -26,9 +25,9 @@ $admin = elgg_extract('admin', $menu, array()); $profile_actions = ''; if (elgg_is_logged_in() && $actions) { - $profile_actions = '<ul class="elgg-menu">'; + $profile_actions = '<ul class="elgg-menu profile-action-menu mvm">'; foreach ($actions as $action) { - $profile_actions .= '<li>' . $action->getLink(array('class' => 'elgg-button-action')) . '</li>'; + $profile_actions .= '<li>' . $action->getContent(array('class' => 'elgg-button elgg-button-action')) . '</li>'; } $profile_actions .= '</ul>'; } @@ -36,9 +35,11 @@ if (elgg_is_logged_in() && $actions) { // if admin, display admin links $admin_links = ''; if (elgg_is_admin_logged_in() && elgg_get_logged_in_user_guid() != elgg_get_page_owner_guid()) { + $text = elgg_echo('admin:options'); + $admin_links = '<ul class="profile-admin-menu-wrapper">'; - $admin_links .= '<li><a class="elgg-toggle" id="elgg-toggler-admin-menu">Admin options…</a>'; - $admin_links .= '<ul class="profile-admin-menu" id="elgg-togglee-admin-menu">'; + $admin_links .= "<li><a rel=\"toggle\" href=\"#profile-menu-admin\">$text…</a>"; + $admin_links .= '<ul class="profile-admin-menu" id="profile-menu-admin">'; foreach ($admin as $menu_item) { $admin_links .= elgg_view('navigation/menu/elements/item', array('item' => $menu_item)); } diff --git a/mod/profile/views/default/profile/wrapper.php b/mod/profile/views/default/profile/wrapper.php index 7bc0397f8..73b7934f2 100644 --- a/mod/profile/views/default/profile/wrapper.php +++ b/mod/profile/views/default/profile/wrapper.php @@ -9,10 +9,4 @@ <?php echo elgg_view('profile/owner_block'); ?> <?php echo elgg_view('profile/details'); ?> </div> -</div> -<?php //@todo JS 1.8: no ?> -<script type="text/javascript"> - $(document).ready(function() { - $('#elgg-widget-col-1').css('min-height', $('.profile').outerHeight(true) + 1); - }); -</script>
\ No newline at end of file +</div>
\ No newline at end of file |
