function put(&$vars) { extract($vars); // save a revision $rec = $collection->MoveFirst(); $Revision =& $db->model('Revision'); $r = $Revision->base(); $r->set_value('data', serialize($rec)); $r->set_value('profile_id', get_profile_id()); $r->set_value('target_id', $rec->entry_id); $r->save(); if (isset($request->params['identity']['nickname'])) { $nick = strtolower($request->params['identity']['nickname']); $request->set_param(array('identity', 'nickname'), $nick); if ($profile->nickname == $nick) { // nickname did not change } else { global $prefix; // if post_notice is set it's a remote user and can share a nickname with a local user $sql = "SELECT nickname FROM " . $prefix . "identities WHERE nickname LIKE '" . $db->escape_string($nick) . "' AND (post_notice = '' OR post_notice IS NULL)"; $result = $db->get_result($sql); if ($db->num_rows($result) > 0) { trigger_error('Sorry, that nickname is already being used.', E_USER_ERROR); } } } else { } if (isset($request->params['identity']['url'])) { if (strpos($request->params['identity']['url'], 'http') === false) { $request->params['identity']['url'] = 'http://' . $request->params['identity']['url']; } } if (isset($request->params['identity']['password'])) { $request->params['identity']['password'] = md5($request->params['identity']['password']); } $resource->update_from_post($request); $rec = $Identity->find($request->id); if (is_upload('identities', 'photo')) { $sql = "SELECT photo FROM " . $prefix . "identities WHERE id = " . $db->escape_string($request->id); $result = $db->get_result($sql); $upl = $_FILES['identity']['tmp_name']['photo']; $ext = '.' . type_of_image($upl); if (!$ext) { trigger_error("Sorry for the trouble, but your photo must be a JPG, PNG or GIF file.", E_USER_ERROR); } $content_type = type_of($ext); if ($blobval = $db->result_value($result, 0, "photo")) { $rec->set_value('avatar', $request->url_for(array('resource' => "_" . $rec->id)) . $ext); } elseif (exists_uploads_blob('identities', $rec->id)) { $rec->set_value('avatar', $request->url_for(array('resource' => "_" . $rec->id)) . $ext); } else { $rec->set_value('avatar', ''); } if (empty($rec->profile)) { $rec->set_value('profile', $request->url_for(array('resource' => "_" . $rec->id))); } if (empty($rec->profile_url)) { $rec->set_value('profile_url', $request->url_for(array('resource' => "" . $rec->nickname))); } $rec->save_changes(); $atomentry = $Identity->set_metadata($rec, $content_type, $rec->table, 'id'); } broadcast_omb_profile_update(); header_status('200 OK'); redirect_to(base_url(true)); }
function photoCreateCropThumb($p_thumb_file, $p_photo_file, $p_max_size, $p_quality = 100, $tmpfile = null) { if ($tmpfile == null) { $ext = 'jpg'; } else { $ext = type_of_image($tmpfile); } if ($ext == 'jpg') { $pic = imagecreatefromjpeg($p_photo_file); } if ($ext == 'gif') { $pic = imagecreatefromgif($p_photo_file); } if ($ext == 'png') { $image = imagecreatefromstring(file_get_contents($p_photo_file)); $width = imagesx($image); $height = imagesy($image); unset($image); $size = getimagesize($p_photo_file); $required_memory = Round($width * $height * $size['bits']) + 500000; unset($size); $new_limit = memory_get_usage() + $required_memory; ini_set("memory_limit", $new_limit); $pic = imagecreatefrompng($p_photo_file); } if ($pic) { $thumb = imagecreatetruecolor($p_max_size, $p_max_size); if (!$thumb) { trigger_error('Sorry, the thumbnail photo could not be created', E_USER_ERROR); } $width = imagesx($pic); $height = imagesy($pic); if ($width < $height) { $twidth = $p_max_size; $theight = $twidth * $height / $width; imagecopyresized($thumb, $pic, 0, 0, 0, $height / 2 - $width / 2, $twidth, $theight, $width, $height); } else { $theight = $p_max_size; $twidth = $theight * $width / $height; imagecopyresized($thumb, $pic, 0, 0, $width / 2 - $height / 2, 0, $twidth, $theight, $width, $height); } if ($ext == 'jpg') { imagejpeg($thumb, $p_thumb_file, $p_quality); } if ($ext == 'gif') { imagegif($thumb, $p_thumb_file); } if ($ext == 'png') { imagepng($thumb, $p_thumb_file); ini_restore("memory_limit"); } } }