From e3112dc160a611462cc77b22644f7050480888db Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 29 Apr 2008 16:59:19 +0000 Subject: Introducing profile icons. git-svn-id: https://code.elgg.org/elgg/trunk@564 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/profile/actions/iconupload.php | 45 +++++++++++++++++++++++++ mod/profile/editicon.php | 25 ++++++++++++++ mod/profile/graphics/defaultlarge.jpg | Bin 0 -> 9782 bytes mod/profile/graphics/defaultmedium.jpg | Bin 0 -> 4096 bytes mod/profile/graphics/defaultsmall.jpg | Bin 0 -> 1975 bytes mod/profile/icon.php | 41 ++++++++++++++++++++++ mod/profile/languages/en.php | 2 ++ mod/profile/start.php | 24 +++++++++++++ mod/profile/views/default/profile/editicon.php | 32 ++++++++++++++++++ mod/profile/views/default/profile/icon.php | 36 ++++++++++++++++++++ mod/profile/views/default/user/user.php | 12 ++++--- 11 files changed, 213 insertions(+), 4 deletions(-) create mode 100644 mod/profile/actions/iconupload.php create mode 100644 mod/profile/editicon.php create mode 100644 mod/profile/graphics/defaultlarge.jpg create mode 100644 mod/profile/graphics/defaultmedium.jpg create mode 100644 mod/profile/graphics/defaultsmall.jpg create mode 100644 mod/profile/icon.php create mode 100644 mod/profile/views/default/profile/editicon.php create mode 100644 mod/profile/views/default/profile/icon.php (limited to 'mod') diff --git a/mod/profile/actions/iconupload.php b/mod/profile/actions/iconupload.php new file mode 100644 index 000000000..bdb925838 --- /dev/null +++ b/mod/profile/actions/iconupload.php @@ -0,0 +1,45 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + */ + + // If we were given a correct icon + if ( + isloggedin() + && $small = get_resized_image_from_uploaded_file('profileicon',50,50) + && $medium = get_resized_image_from_uploaded_file('profileicon',100,100) + && $large = get_resized_image_from_uploaded_file('profileicon',200,200) + ) { + + $filehandler = new ElggFile(); + $filehandler->setFilename($_SESSION['user']->username . "large.jpg"); + $filehandler->open("write"); + $filehandler->write($large); + $filehandler->close(); + $filehandler->setFilename($_SESSION['user']->username . "medium.jpg"); + $filehandler->open("write"); + $filehandler->write($medium); + $filehandler->close(); + $filehandler->setFilename($_SESSION['user']->username . "small.jpg"); + $filehandler->open("write"); + $filehandler->write($small); + $filehandler->close(); + + system_message(elgg_echo("profile:icon:uploaded")); + + } else { + + system_message(elgg_echo("profile:icon:notfound")); + + } + + if (isloggedin()) forward($_SESSION['user']->getURL()); + +?> \ No newline at end of file diff --git a/mod/profile/editicon.php b/mod/profile/editicon.php new file mode 100644 index 000000000..2b33abb62 --- /dev/null +++ b/mod/profile/editicon.php @@ -0,0 +1,25 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + */ + + // Load the Elgg framework + require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); + + // Make sure we're logged in + if (!isloggedin()) forward(); + + // Get the form + $body = elgg_view("profile/editicon"); + + // Draw the page + page_draw(elgg_echo("profile:editicon"),$body); + +?> \ No newline at end of file diff --git a/mod/profile/graphics/defaultlarge.jpg b/mod/profile/graphics/defaultlarge.jpg new file mode 100644 index 000000000..a4492b666 Binary files /dev/null and b/mod/profile/graphics/defaultlarge.jpg differ diff --git a/mod/profile/graphics/defaultmedium.jpg b/mod/profile/graphics/defaultmedium.jpg new file mode 100644 index 000000000..b54cbe88b Binary files /dev/null and b/mod/profile/graphics/defaultmedium.jpg differ diff --git a/mod/profile/graphics/defaultsmall.jpg b/mod/profile/graphics/defaultsmall.jpg new file mode 100644 index 000000000..58d6c23b5 Binary files /dev/null and b/mod/profile/graphics/defaultsmall.jpg differ diff --git a/mod/profile/icon.php b/mod/profile/icon.php new file mode 100644 index 000000000..dd87ff939 --- /dev/null +++ b/mod/profile/icon.php @@ -0,0 +1,41 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + */ + + // Load the Elgg framework + require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); + + // Get the owning user + + $user = page_owner_entity(); // page_owner_entity(); + $username = $user->username; + + // Get the size + $size = strtolower(get_input('size')); + if (!in_array($size,array('large','medium','small'))) + $size = "medium"; + + // Try and get the icon + + $filehandler = new ElggFile(); + $filehandler->setFilename($username . $size . ".jpg"); + if ($filehandler->open("read") && $contents = $filehandler->read($filehandler->size())) { + } else { + + global $CONFIG; + $contents = @file_get_contents($CONFIG->pluginspath . "profile/graphics/default{$size}.jpg"); + + } + + header("Content-type: image/jpeg"); + echo $contents; + +?> \ No newline at end of file diff --git a/mod/profile/languages/en.php b/mod/profile/languages/en.php index 79a3300cf..6227f6657 100644 --- a/mod/profile/languages/en.php +++ b/mod/profile/languages/en.php @@ -21,6 +21,7 @@ 'profile:user' => "%s's profile", 'profile:edit' => "Edit profile", + 'profile:editicon' => "Change your profile picture", 'profile:description' => "About me", 'profile:location' => "Location", @@ -43,6 +44,7 @@ 'profile:notfound' => "Sorry; we could not find the specified profile.", 'profile:cantedit' => "Sorry; you do not have permission to edit this profile.", + 'profile:icon:notfound' => "Sorry; there was a problem uploading your profile icon.", ); diff --git a/mod/profile/start.php b/mod/profile/start.php index 03fe0eda1..86faded71 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -31,6 +31,7 @@ add_menu(elgg_echo('profile'), $CONFIG->wwwroot . "pg/profile/" . $_SESSION['user']->username,array( menu_item(elgg_echo('profile:yours'),$CONFIG->wwwroot . "pg/profile/" . $_SESSION['user']->username), menu_item(elgg_echo('profile:edit'),$CONFIG->wwwroot."mod/profile/edit.php"), + menu_item(elgg_echo('profile:editicon'),$CONFIG->wwwroot."mod/profile/editicon.php"), )); } @@ -53,6 +54,7 @@ // Register a page handler, so we can have nice URLs register_page_handler('profile','profile_page_handler'); + register_page_handler('icon','profile_icon_handler'); } @@ -74,6 +76,27 @@ } + /** + * Profile icon page handler + * + * @param array $page Array of page elements, forwarded by the page handling mechanism + */ + function profile_icon_handler($page) { + + global $CONFIG; + + // The username should be the file we're getting + if (isset($page[0])) { + set_input('username',$page[0]); + } + if (isset($page[1])) { + set_input('size',$page[1]); + } + // Include the standard profile index + include($CONFIG->pluginspath . "profile/icon.php"); + + } + /** * Profile URL generator for $user->getUrl(); * @@ -91,6 +114,7 @@ // Register actions global $CONFIG; register_action("profile/edit",false,$CONFIG->pluginspath . "profile/actions/edit.php"); + register_action("profile/iconupload",false,$CONFIG->pluginspath . "profile/actions/iconupload.php"); ?> \ No newline at end of file diff --git a/mod/profile/views/default/profile/editicon.php b/mod/profile/views/default/profile/editicon.php new file mode 100644 index 000000000..8e71f2f75 --- /dev/null +++ b/mod/profile/views/default/profile/editicon.php @@ -0,0 +1,32 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + * + * @uses $vars['entity'] The user entity + * @uses $vars['profile'] Profile items from $CONFIG->profile, defined in profile/start.php for now + */ + +?> + +
+

+ : +

+

+ 'profileicon')); + + ?> +

+

+ " /> +

+
\ No newline at end of file diff --git a/mod/profile/views/default/profile/icon.php b/mod/profile/views/default/profile/icon.php new file mode 100644 index 000000000..577620b6f --- /dev/null +++ b/mod/profile/views/default/profile/icon.php @@ -0,0 +1,36 @@ + + * @copyright Curverider Ltd 2008 + * @link http://elgg.com/ + * + * @uses $vars['entity'] The user entity. If none specified, the current user is assumed. + * @uses $vars['size'] The size - small, medium or large. If none specified, medium is assumed. + */ + + // Get entity + if (empty($vars['entity'])) + $vars['entity'] = $vars['user']; + + $name = htmlentities($vars['entity']->name); + $username = $vars['entity']->username; + + // Get size + if (!in_array($vars['size'],array('small','medium','large'))) + $vars['size'] = "medium"; + + // Get any align and js + if (!empty($vars['align'])) { + $align = " align=\"{$vars['align']}\" "; + } else { + $align = ""; + } + +?> + + title="" /> \ No newline at end of file diff --git a/mod/profile/views/default/user/user.php b/mod/profile/views/default/user/user.php index d2411c3d9..e11c463ca 100644 --- a/mod/profile/views/default/user/user.php +++ b/mod/profile/views/default/user/user.php @@ -12,12 +12,16 @@ * @uses $vars['entity'] The user entity */ -?> + echo elgg_view( + "profile/icon", array( + 'entity' => $vars['entity'], + 'align' => "right", + 'size' => "large", + ) + ); +?>

name; ?>

-

- *** USER ICON TO COME *** -