diff options
Diffstat (limited to 'mod/profile/actions')
-rw-r--r-- | mod/profile/actions/cropicon.php | 80 | ||||
-rw-r--r-- | mod/profile/actions/deletedefaultprofileitem.php | 25 | ||||
-rw-r--r-- | mod/profile/actions/edit.php | 95 | ||||
-rw-r--r-- | mod/profile/actions/editdefault.php | 39 | ||||
-rw-r--r-- | mod/profile/actions/iconupload.php | 91 | ||||
-rw-r--r-- | mod/profile/actions/resetdefaultprofile.php | 30 |
6 files changed, 360 insertions, 0 deletions
diff --git a/mod/profile/actions/cropicon.php b/mod/profile/actions/cropicon.php new file mode 100644 index 000000000..f86799ccf --- /dev/null +++ b/mod/profile/actions/cropicon.php @@ -0,0 +1,80 @@ +<?php + + /** + * Elgg profile plugin upload new user icon action + * + * @package ElggProfile + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd <info@elgg.com> + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + */ + + gatekeeper(); + + $x1 = (int) get_input('x_1',0); + $y1 = (int) get_input('y_1',0); + $x2 = (int) get_input('x_2',0); + $y2 = (int) get_input('y_2',0); + + // username is set in form which ensures the page owner is set + $user = page_owner_entity(); + + if (!$user || !$user->canEdit()) { + register_error(elgg_echo("profile:icon:noaccess")); + forward(); + } + + $filehandler = new ElggFile(); + $filehandler->owner_guid = $user->getGUID(); + $filehandler->setFilename("profile/" . $user->username . "master" . ".jpg"); + $filename = $filehandler->getFilenameOnFilestore(); + + $topbar = get_resized_image_from_existing_file($filename,16,16, true, $x1, $y1, $x2, $y2); + $tiny = get_resized_image_from_existing_file($filename,25,25, true, $x1, $y1, $x2, $y2); + $small = get_resized_image_from_existing_file($filename,40,40, true, $x1, $y1, $x2, $y2); + $medium = get_resized_image_from_existing_file($filename,100,100, true, $x1, $y1, $x2, $y2); + + if ($small !== false + && $medium !== false + && $tiny !== false) { + + $filehandler = new ElggFile(); + $filehandler->owner_guid = $user->getGUID(); + $filehandler->setFilename("profile/" . $user->username . "medium.jpg"); + $filehandler->open("write"); + $filehandler->write($medium); + $filehandler->close(); + $filehandler->setFilename("profile/" . $user->username . "small.jpg"); + $filehandler->open("write"); + $filehandler->write($small); + $filehandler->close(); + $filehandler->setFilename("profile/" . $user->username . "tiny.jpg"); + $filehandler->open("write"); + $filehandler->write($tiny); + $filehandler->close(); + $filehandler->setFilename("profile/" . $user->username . "topbar.jpg"); + $filehandler->open("write"); + $filehandler->write($topbar); + $filehandler->close(); + + $user->x1 = $x1; + $user->x2 = $x2; + $user->y1 = $y1; + $user->y2 = $y2; + + $user->icontime = time(); + + system_message(elgg_echo("profile:icon:uploaded")); + + } else { + register_error(elgg_echo("profile:icon:notfound")); + } + + //forward the user back to the upload page to crop + + $url = $vars['url'] . "pg/profile/{$user->username}/editicon/"; + + if (isloggedin()) forward($url); + +?> diff --git a/mod/profile/actions/deletedefaultprofileitem.php b/mod/profile/actions/deletedefaultprofileitem.php new file mode 100644 index 000000000..309816035 --- /dev/null +++ b/mod/profile/actions/deletedefaultprofileitem.php @@ -0,0 +1,25 @@ +<?php + /** + * Elgg profile plugin edit default profile action removal + * + * @package ElggProfile + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd <info@elgg.com> + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + */ + + global $CONFIG; + + admin_gatekeeper(); + + $id = (int)get_input('id'); + + if ( ($id) && (set_plugin_setting("admin_defined_profile_$id", '', 'profile')) && + (set_plugin_setting("admin_defined_profile_type_$id", '', 'profile'))) + system_message(elgg_echo('profile:editdefault:delete:success')); + else + register_error(elgg_echo('profile:editdefault:delete:fail')); + + forward($_SERVER['HTTP_REFERER']); +?> diff --git a/mod/profile/actions/edit.php b/mod/profile/actions/edit.php new file mode 100644 index 000000000..bc14cd6e6 --- /dev/null +++ b/mod/profile/actions/edit.php @@ -0,0 +1,95 @@ +<?php + + /** + * Elgg profile plugin edit action + * + * @package ElggProfile + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd <info@elgg.com> + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + */ + + // Load configuration + global $CONFIG; + + gatekeeper(); + + // Get profile fields + $input = array(); + $accesslevel = get_input('accesslevel'); + if (!is_array($accesslevel)) $accesslevel = array(); + + foreach($CONFIG->profile as $shortname => $valuetype) { + // the decoding is a stop gag to prevent && showing up in profile fields + // because it is escaped on both input (get_input()) and output (view:output/text). see #561 and #1405. + // must decode in utf8 or string corruption occurs. see #1567. + $value = html_entity_decode(get_input($shortname), ENT_COMPAT, 'UTF-8'); + + // limit to reasonable sizes. + if ($valuetype != 'longtext' && elgg_strlen($value) > 250) { + $error = sprintf(elgg_echo('profile:field_too_long'), elgg_echo("profile:{$shortname}")); + register_error($error); + forward($_SERVER['HTTP_REFERER']); + } + + if ($valuetype == 'tags') { + $value = string_to_tag_array($value); + } + + $input[$shortname] = $value; + } + + // Get the page owner to see if the currently logged in user canEdit() the page owner. + + $user = page_owner_entity(); + if (!$user) { + $user = $_SESSION['user']; + + // @todo this doesn't make sense...??? + set_page_owner($user->getGUID()); + } + if ($user->canEdit()) { + + // Save stuff + if (sizeof($input) > 0) + foreach($input as $shortname => $value) { + //$user->$shortname = $value; + remove_metadata($user->guid, $shortname); + if (isset($accesslevel[$shortname])) { + $access_id = (int) $accesslevel[$shortname]; + } else { + // this should never be executed since the access level should always be set + $access_id = ACCESS_PRIVATE; + } + if (is_array($value)) { + $i = 0; + foreach($value as $interval) { + $i++; + if ($i == 1) { $multiple = false; } else { $multiple = true; } + create_metadata($user->guid, $shortname, $interval, 'text', $user->guid, $access_id, $multiple); + } + } else { + create_metadata($user->guid, $shortname, $value, 'text', $user->guid, $access_id); + } + } + $user->save(); + + // Notify of profile update + trigger_elgg_event('profileupdate',$user->type,$user); + + //add to river + add_to_river('river/user/default/profileupdate','update',$_SESSION['user']->guid,$_SESSION['user']->guid,get_default_access($_SESSION['user'])); + + system_message(elgg_echo("profile:saved")); + + // Forward to the user's profile + forward($user->getUrl()); + + } else { + // If we can't, display an error + + system_message(elgg_echo("profile:noaccess")); + } + +?> diff --git a/mod/profile/actions/editdefault.php b/mod/profile/actions/editdefault.php new file mode 100644 index 000000000..cf662e9b2 --- /dev/null +++ b/mod/profile/actions/editdefault.php @@ -0,0 +1,39 @@ +<?php + + /** + * Elgg profile plugin edit default profile action + * + * @package ElggProfile + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd <info@elgg.com> + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + */ + + // Load configuration + global $CONFIG; + + admin_gatekeeper(); + + $label = sanitise_string(get_input('label')); + $type = sanitise_string(get_input('type')); + + if (($label) && ($type)) + { + $n = 0; + while (get_plugin_setting("admin_defined_profile_$n", 'profile')) {$n++;} // find free space + + if ( (set_plugin_setting("admin_defined_profile_$n", $label, 'profile')) && + (set_plugin_setting("admin_defined_profile_type_$n", $type, 'profile'))) { + set_plugin_setting('user_defined_fields', TRUE, 'profile'); + system_message(elgg_echo('profile:editdefault:success')); + } else { + register_error(elgg_echo('profile:editdefault:fail')); + } + + } + else + register_error(elgg_echo('profile:editdefault:fail')); + + forward($_SERVER['HTTP_REFERER']); +?> diff --git a/mod/profile/actions/iconupload.php b/mod/profile/actions/iconupload.php new file mode 100644 index 000000000..f1d290694 --- /dev/null +++ b/mod/profile/actions/iconupload.php @@ -0,0 +1,91 @@ +<?php + + /** + * Elgg profile plugin upload new user icon action + * + * @package ElggProfile + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd <info@elgg.com> + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + */ + + gatekeeper(); + + $user = page_owner_entity(); + if (!$user) + $user = $_SESSION['user']; + + // If we were given a correct icon + if ( + (isloggedin()) && + ($user) && + ($user->canEdit()) + ) { + + + $topbar = get_resized_image_from_uploaded_file('profileicon',16,16, true); + $tiny = get_resized_image_from_uploaded_file('profileicon',25,25, true); + $small = get_resized_image_from_uploaded_file('profileicon',40,40, true); + $medium = get_resized_image_from_uploaded_file('profileicon',100,100, true); + $large = get_resized_image_from_uploaded_file('profileicon',200,200); + $master = get_resized_image_from_uploaded_file('profileicon',550,550); + + if ($small !== false + && $medium !== false + && $large !== false + && $tiny !== false) { + + $filehandler = new ElggFile(); + $filehandler->owner_guid = $user->getGUID(); + $filehandler->setFilename("profile/" . $user->username . "large.jpg"); + $filehandler->open("write"); + $filehandler->write($large); + $filehandler->close(); + $filehandler->setFilename("profile/" . $user->username . "medium.jpg"); + $filehandler->open("write"); + $filehandler->write($medium); + $filehandler->close(); + $filehandler->setFilename("profile/" . $user->username . "small.jpg"); + $filehandler->open("write"); + $filehandler->write($small); + $filehandler->close(); + $filehandler->setFilename("profile/" . $user->username . "tiny.jpg"); + $filehandler->open("write"); + $filehandler->write($tiny); + $filehandler->close(); + $filehandler->setFilename("profile/" . $user->username . "topbar.jpg"); + $filehandler->open("write"); + $filehandler->write($topbar); + $filehandler->close(); + $filehandler->setFilename("profile/" . $user->username . "master.jpg"); + $filehandler->open("write"); + $filehandler->write($master); + $filehandler->close(); + + $user->icontime = time(); + + system_message(elgg_echo("profile:icon:uploaded")); + + trigger_elgg_event('profileiconupdate',$user->type,$user); + + //add to river + add_to_river('river/user/default/profileiconupdate','update',$user->guid,$user->guid); + + } else { + system_message(elgg_echo("profile:icon:notfound")); + } + + } else { + + system_message(elgg_echo("profile:icon:notfound")); + + } + + //forward the user back to the upload page to crop + + $url = "pg/profile/{$user->username}/editicon/"; + + if (isloggedin()) forward($url); + +?> diff --git a/mod/profile/actions/resetdefaultprofile.php b/mod/profile/actions/resetdefaultprofile.php new file mode 100644 index 000000000..2100c95c2 --- /dev/null +++ b/mod/profile/actions/resetdefaultprofile.php @@ -0,0 +1,30 @@ +<?php + /** + * Elgg profile plugin edit default profile action + * + * @package ElggProfile + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd <info@elgg.com> + * @copyright Curverider Ltd 2008-2010 + * @link http://elgg.com/ + */ + + // Load configuration + global $CONFIG; + + admin_gatekeeper(); + + $n = 0; + while (get_plugin_setting("admin_defined_profile_$n", 'profile')) { + set_plugin_setting("admin_defined_profile_$n", '', 'profile'); + set_plugin_setting("admin_defined_profile_type_$n", '', 'profile'); + + $n++; + } + + set_plugin_setting('user_defined_fields', FALSE, 'profile'); + + system_message(elgg_echo('profile:defaultprofile:reset')); + + forward($_SERVER['HTTP_REFERER']); +?> |