cvs: bugtracker /htdocs/images/profile/avatar .htaccess index.php /template/generic/user profile.php
| From: | Barry Carlyon | Date: | Fri, 15 Aug 2008 10:21:58 +0000 |
| Subject: | cvs: bugtracker /htdocs/images/profile/avatar .htaccess index.php /template/generic/user profile.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-2433@lists.php.net to get a copy of this message | ||
bcarlyon Fri Aug 15 10:21:58 2008 UTC
Added files:
/bugtracker/htdocs/images/profile/avatar .htaccess index.php
Modified files:
/bugtracker/template/generic/user profile.php
Log:
Sorta finished profile editing.
Now with profile display, of other users, (need to finish)
Added Gravtar and Pavatar Support (http://en.gravatar.com/ and http://pavatar.com/ )
http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/user/profile.php?r1=1.1&r2=1.2&diff_format=u Index: bugtracker/template/generic/user/profile.php diff -u bugtracker/template/generic/user/profile.php:1.1 bugtracker/template/generic/user/profile.php:1.2 --- bugtracker/template/generic/user/profile.php:1.1 Thu Aug 14 16:29:21 2008 +++ bugtracker/template/generic/user/profile.php Fri Aug 15 10:21:58 2008 @@ -37,7 +37,7 @@ * @author Barry Carlyon <bcarlyon@php.net> * @copyright 2008-2008 Barry Carlyon * @license http://www.opensource.org/licenses/bsd-license.php BSD License -* @version CVS: $Id: profile.php,v 1.1 2008/08/14 16:29:21 bcarlyon Exp $ +* @version CVS: $Id: profile.php,v 1.2 2008/08/15 10:21:58 bcarlyon Exp $ * @link http://gsoc.barrycarlyon.servegame.org/ */ @@ -47,6 +47,34 @@ $content = ''; + if ($view_user == 'update') { + trace('about to update a users profile'); + //we called an update process + $thishandle = loadvar('handle'); + trace($thishandle); + + if ($thishandle == $user->handle) { + trace('no really we are'); + $form_data['website'] = loadvar('website'); + + $query = 'UPDATE ' . USER_TABLE. ' SET '; + foreach ($form_data as $ref => $data) { + $query .= $ref . ' = "' . $db->protect_data($data) . '" '; + } + $query .= ' WHERE handle = \'' . $thishandle . '\''; + trace('query'); + $db->get_data($query); + if ($db->affected_rows) { + $content .= '<div id="success">Your profile has been successfully updated</div>'; + $view_user = $user->handle; + } else { + trigger_error('Failed to Updated your profile, or no update was required', E_USER_ERROR); + } + } else { + $template->meta_refresh(); + trigger_error('No user handle was specified', E_USER_ERROR); + } + } if ($view_user == $user->handle) { $template->page_title .= 'Profile'; $template->content_title = 'Profile'; @@ -54,20 +82,40 @@ include('cache/users.php'); $user_data = $users[$user->handle]; + if (sizeof($user_data)) { + $content = '<form action="/user/profile/update/" method="post" class="form" id="profile"> <div class="slim"> -<label for="handle">Handle:</label> <input type="text" name="handle" id="handle" value="' . $user->handle . '" disabled="disabled" /> +<label for="handle">Handle:</label> <input type="text" name="ahandle" id="ahandle" value="' . $user->handle . '" disabled="disabled" /> + <input type="hidden" name="handle" id="handle" value="' . $user->handle . '" /> <br /><br /> <label for="email">Email:</label> <input type="text" name="email" id="email" value="' . $user_data['email'] . '" disabled="disabled" /> <br /><br /> <label for="website">Website:</label> <input type="text" name="website" id="website" value="' . $user_data['website'] . '" /> <br /><br /> +<input type="submit" value="Update" /> +<br /><br /> </div> </form>'; + } else { + //need to recache the users file + trigger_error('We currently have no useful information on your profile', E_USER_ERROR); + } } elseif ($view_user) { - + //list of users } else { + include('cache/users.php'); + $content .= '<table>'; +// $users = + ksort($users); + + //limit + $loop = '<tr><td><img src="/images/profile/avatar/{DSP_HANDLE}.png" alt="{DSP_HANDLE}" /></td><td>{DSP_HANDLE}</td><td>{DSP_EMAIL}</td></tr>'; + $loop_data = array(); + + $content .= $template->loop($users, $loop); + $content .= '</table>'; } $template->prehtml = $content; } else { http://cvs.php.net/viewvc.cgi/bugtracker/htdocs/images/profile/avatar/.htaccess?view=markup&rev=1.1 Index: bugtracker/htdocs/images/profile/avatar/.htaccess +++ bugtracker/htdocs/images/profile/avatar/.htaccess RewriteEngine on RewriteRule ^(.*).png$ index.php?handle=$1 [L,PT] http://cvs.php.net/viewvc.cgi/bugtracker/htdocs/images/profile/avatar/index.php?view=markup&rev=1.1 Index: bugtracker/htdocs/images/profile/avatar/index.php +++ bugtracker/htdocs/images/profile/avatar/index.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:*/ /** * htdocs/images/profile/avatar/index.php * Lets generate a user profile avatar shall we * * Copyright (c) 2008, Barry Carlyon <bcarlyon@php.net> * All rights reserved. * * PHP versions 5 * * LICENSE: Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category BugTracking * @package GSoC Bugtracker * @author Barry Carlyon <bcarlyon@php.net> * @copyright 2008-2008 Barry Carlyon * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version CVS: $Id: index.php,v 1.1 2008/08/15 10:21:58 bcarlyon Exp $ * @link http://gsoc.barrycarlyon.servegame.org/ */ set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)) . '/../../../includes/'); include('config.php'); include('functions.php'); $handle = loadvar('handle'); include('cache/users.php'); $thisuser = isset($users[$handle]) ? $users[$handle] : FALSE; if ($thisuser) { $file = avatar($handle, $thisuser['email'], $thisuser['website']); if ($file) { header("Content-Type: image/png"); $fp = fopen($file, 'rb'); fpassthru($fp); exit; } } function avatar($name, $email, $site = FALSE) { $avatar_url = ''; if ($site && !$avatar_url) { $avatar_url = pavatar($site); } if (!$avatar_url) { $avatar_url = gravatar($email); } return $avatar_url; } function pavatar($site) { $avatar_url = ''; //header version $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $site); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); $result = curl_exec($ch); $resultArray = curl_getinfo($ch); curl_close($ch); if (($resultArray['http_code'] == "200")&&(!$avatar_url)) { //sites exists, no header pavatar, try link //<link rel="pavatar" href="http://example.com/path/my-pavatar.png" /> $data = explode("</head>",$result); $data = $data[0]; $data = explode("\n",$data); foreach ($data as $ref => $element) { if (strpos($element,'pavatar')) { $self = explode('href="',$element); $self = explode('"',$self[1]); $avatar_url = $self[0]; } } } if (($resultArray['http_code'] == "200")&&(!$avatar_url)) { //site exists, no header, no link try file if (@fclose(@fopen($site . '/pavatar.png', "r"))) { $avatar_url = $site . '/pavatar.png'; } } return $avatar_url; } function read_header($ch, $string) { global $avatar_url; $array = explode(':',$string); if ($array[0] == 'X-Pavatar') { $avatar_url = 'http:' . $array[2]; } return strlen($string); } function gravatar($email) { $email = md5($email); if (@fclose(@fopen('http://www.gravatar.com/avatar.php?gravatar_id=' . $email, "r"))) { return 'http://www.gravatar.com/avatar.php?gravatar_id=' . $email . '&size=80&default=http://leedsstudent.lsrfm.com/images/photo_peeps/gravanon.jpg'; } return ''; }
http://cvs.php.net/viewvc.cgi/bugtracker/template/generic/user/profile.php?r1=1.1&r2=1.2&diff_format=u Index: bugtracker/template/generic/user/profile.php diff -u bugtracker/template/generic/user/profile.php:1.1 bugtracker/template/generic/user/profile.php:1.2 --- bugtracker/template/generic/user/profile.php:1.1 Thu Aug 14 16:29:21 2008 +++ bugtracker/template/generic/user/profile.php Fri Aug 15 10:21:58 2008 @@ -37,7 +37,7 @@ * @author Barry Carlyon <bcarlyon@php.net> * @copyright 2008-2008 Barry Carlyon * @license http://www.opensource.org/licenses/bsd-license.php BSD License -* @version CVS: $Id: profile.php,v 1.1 2008/08/14 16:29:21 bcarlyon Exp $ +* @version CVS: $Id: profile.php,v 1.2 2008/08/15 10:21:58 bcarlyon Exp $ * @link http://gsoc.barrycarlyon.servegame.org/ */ @@ -47,6 +47,34 @@ $content = ''; + if ($view_user == 'update') { + trace('about to update a users profile'); + //we called an update process + $thishandle = loadvar('handle'); + trace($thishandle); + + if ($thishandle == $user->handle) { + trace('no really we are'); + $form_data['website'] = loadvar('website'); + + $query = 'UPDATE ' . USER_TABLE. ' SET '; + foreach ($form_data as $ref => $data) { + $query .= $ref . ' = "' . $db->protect_data($data) . '" '; + } + $query .= ' WHERE handle = \'' . $thishandle . '\''; + trace('query'); + $db->get_data($query); + if ($db->affected_rows) { + $content .= '<div id="success">Your profile has been successfully updated</div>'; + $view_user = $user->handle; + } else { + trigger_error('Failed to Updated your profile, or no update was required', E_USER_ERROR); + } + } else { + $template->meta_refresh(); + trigger_error('No user handle was specified', E_USER_ERROR); + } + } if ($view_user == $user->handle) { $template->page_title .= 'Profile'; $template->content_title = 'Profile'; @@ -54,20 +82,40 @@ include('cache/users.php'); $user_data = $users[$user->handle]; + if (sizeof($user_data)) { + $content = '<form action="/user/profile/update/" method="post" class="form" id="profile"> <div class="slim"> -<label for="handle">Handle:</label> <input type="text" name="handle" id="handle" value="' . $user->handle . '" disabled="disabled" /> +<label for="handle">Handle:</label> <input type="text" name="ahandle" id="ahandle" value="' . $user->handle . '" disabled="disabled" /> + <input type="hidden" name="handle" id="handle" value="' . $user->handle . '" /> <br /><br /> <label for="email">Email:</label> <input type="text" name="email" id="email" value="' . $user_data['email'] . '" disabled="disabled" /> <br /><br /> <label for="website">Website:</label> <input type="text" name="website" id="website" value="' . $user_data['website'] . '" /> <br /><br /> +<input type="submit" value="Update" /> +<br /><br /> </div> </form>'; + } else { + //need to recache the users file + trigger_error('We currently have no useful information on your profile', E_USER_ERROR); + } } elseif ($view_user) { - + //list of users } else { + include('cache/users.php'); + $content .= '<table>'; +// $users = + ksort($users); + + //limit + $loop = '<tr><td><img src="/images/profile/avatar/{DSP_HANDLE}.png" alt="{DSP_HANDLE}" /></td><td>{DSP_HANDLE}</td><td>{DSP_EMAIL}</td></tr>'; + $loop_data = array(); + + $content .= $template->loop($users, $loop); + $content .= '</table>'; } $template->prehtml = $content; } else { http://cvs.php.net/viewvc.cgi/bugtracker/htdocs/images/profile/avatar/.htaccess?view=markup&rev=1.1 Index: bugtracker/htdocs/images/profile/avatar/.htaccess +++ bugtracker/htdocs/images/profile/avatar/.htaccess RewriteEngine on RewriteRule ^(.*).png$ index.php?handle=$1 [L,PT] http://cvs.php.net/viewvc.cgi/bugtracker/htdocs/images/profile/avatar/index.php?view=markup&rev=1.1 Index: bugtracker/htdocs/images/profile/avatar/index.php +++ bugtracker/htdocs/images/profile/avatar/index.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:*/ /** * htdocs/images/profile/avatar/index.php * Lets generate a user profile avatar shall we * * Copyright (c) 2008, Barry Carlyon <bcarlyon@php.net> * All rights reserved. * * PHP versions 5 * * LICENSE: Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category BugTracking * @package GSoC Bugtracker * @author Barry Carlyon <bcarlyon@php.net> * @copyright 2008-2008 Barry Carlyon * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version CVS: $Id: index.php,v 1.1 2008/08/15 10:21:58 bcarlyon Exp $ * @link http://gsoc.barrycarlyon.servegame.org/ */ set_include_path(get_include_path() . PATH_SEPARATOR . dirname(dirname(__FILE__)) . '/../../../includes/'); include('config.php'); include('functions.php'); $handle = loadvar('handle'); include('cache/users.php'); $thisuser = isset($users[$handle]) ? $users[$handle] : FALSE; if ($thisuser) { $file = avatar($handle, $thisuser['email'], $thisuser['website']); if ($file) { header("Content-Type: image/png"); $fp = fopen($file, 'rb'); fpassthru($fp); exit; } } function avatar($name, $email, $site = FALSE) { $avatar_url = ''; if ($site && !$avatar_url) { $avatar_url = pavatar($site); } if (!$avatar_url) { $avatar_url = gravatar($email); } return $avatar_url; } function pavatar($site) { $avatar_url = ''; //header version $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $site); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header'); $result = curl_exec($ch); $resultArray = curl_getinfo($ch); curl_close($ch); if (($resultArray['http_code'] == "200")&&(!$avatar_url)) { //sites exists, no header pavatar, try link //<link rel="pavatar" href="http://example.com/path/my-pavatar.png" /> $data = explode("</head>",$result); $data = $data[0]; $data = explode("\n",$data); foreach ($data as $ref => $element) { if (strpos($element,'pavatar')) { $self = explode('href="',$element); $self = explode('"',$self[1]); $avatar_url = $self[0]; } } } if (($resultArray['http_code'] == "200")&&(!$avatar_url)) { //site exists, no header, no link try file if (@fclose(@fopen($site . '/pavatar.png', "r"))) { $avatar_url = $site . '/pavatar.png'; } } return $avatar_url; } function read_header($ch, $string) { global $avatar_url; $array = explode(':',$string); if ($array[0] == 'X-Pavatar') { $avatar_url = 'http:' . $array[2]; } return strlen($string); } function gravatar($email) { $email = md5($email); if (@fclose(@fopen('http://www.gravatar.com/avatar.php?gravatar_id=' . $email, "r"))) { return 'http://www.gravatar.com/avatar.php?gravatar_id=' . $email . '&size=80&default=http://leedsstudent.lsrfm.com/images/photo_peeps/gravanon.jpg'; } return ''; }