diff options
author | Sem <sembrestels@riseup.net> | 2011-11-18 07:32:27 +0100 |
---|---|---|
committer | Sem <sembrestels@riseup.net> | 2011-11-18 07:32:27 +0100 |
commit | e53d410129701ea1c9d19529afa493f11b5f5b70 (patch) | |
tree | d9963b24bf8932654b4a47e36602c75975e50dba /mod/profile | |
parent | 377da25d2965c64941f83baae119fc970ec60982 (diff) | |
parent | 08a962c98e2923724f8013d6eaae89101243752a (diff) | |
download | elgg-e53d410129701ea1c9d19529afa493f11b5f5b70.tar.gz elgg-e53d410129701ea1c9d19529afa493f11b5f5b70.tar.bz2 |
Merge github.com:Elgg/Elgg
Conflicts:
engine/lib/input.php
Diffstat (limited to 'mod/profile')
-rw-r--r-- | mod/profile/icon.php | 53 | ||||
-rw-r--r-- | mod/profile/icondirect.php | 45 | ||||
-rw-r--r-- | mod/profile/manifest.xml | 7 | ||||
-rw-r--r-- | mod/profile/start.php | 80 | ||||
-rw-r--r-- | mod/profile/views/default/profile/metatags.php | 4 | ||||
-rw-r--r-- | mod/profile/views/default/profile/owner_block.php | 2 |
6 files changed, 94 insertions, 97 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..f7188455e 100644 --- a/mod/profile/icondirect.php +++ b/mod/profile/icondirect.php @@ -1,38 +1,33 @@ <?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']; +$join_date = (int)$_GET['joindate']; $guid = (int)$_GET['guid']; $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,21 +35,22 @@ if ($mysql_dblink) { @mysql_close($mysql_dblink); - // if the simplecache is enabled, we get icon directly - if ($simplecache_enabled) { + if (isset($data_root)) { + + // this depends on ElggDiskFilestore::makeFileMatrix() + $user_path = date('Y/m/d/', $join_date) . $guid; - // first try to read icon directly - $user_path = date('Y/m/d/', $joindate) . $guid; - $filename = "$dataroot$user_path/profile/{$guid}{$size}.jpg"; + $filename = "$data_root$user_path/profile/{$guid}{$size}.jpg"; $contents = @file_get_contents($filename); if (!empty($contents)) { header("Content-type: image/jpeg"); - header('Expires: ' . date('r',time() + 864000)); + header('Expires: ' . date('r', 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) { + // this chunking is done for supposedly better performance + $split_string = str_split($contents, 1024); + foreach ($split_string as $chunk) { echo $chunk; } exit; @@ -64,8 +60,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 d811e373b..86fbc7b7b 100644 --- a/mod/profile/manifest.xml +++ b/mod/profile/manifest.xml @@ -8,11 +8,10 @@ <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 2c38fdd2d..adee838fc 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -20,6 +20,9 @@ function profile_init() { // will dictate the URL for all ElggUser objects elgg_register_entity_url_handler('user', 'all', 'profile_url'); + 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'); @@ -28,7 +31,6 @@ 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('page/elements/head', 'profile/metatags'); @@ -45,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) { @@ -81,7 +84,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; } /** @@ -95,14 +99,65 @@ function profile_url($user) { } /** + * 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; @@ -111,13 +166,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', diff --git a/mod/profile/views/default/profile/metatags.php b/mod/profile/views/default/profile/metatags.php index 54ee322e2..c6f674e6d 100644 --- a/mod/profile/views/default/profile/metatags.php +++ b/mod/profile/views/default/profile/metatags.php @@ -6,7 +6,9 @@ * */ -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" /> <?php diff --git a/mod/profile/views/default/profile/owner_block.php b/mod/profile/views/default/profile/owner_block.php index 5a65a3a26..35199726a 100644 --- a/mod/profile/views/default/profile/owner_block.php +++ b/mod/profile/views/default/profile/owner_block.php @@ -11,7 +11,7 @@ if (!$user) { return TRUE; } -$icon = elgg_view_entity_icon($user, 'large', array('override' => 'true')); +$icon = elgg_view_entity_icon($user, 'large', array('use_hover' => 'true')); // grab the actions and admin menu items from user hover $menu = elgg_trigger_plugin_hook('register', "menu:user_hover", array('entity' => $user), array()); |