[geeklog-cvs] geeklog: Moved duplicate code to display a user's profile to USE...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Feb 21 14:53:38 EST 2010


changeset 7750:f80e6bf50494
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/f80e6bf50494
user: Dirk Haun <dirk at haun-online.de>
date: Sun Feb 21 13:50:01 2010 +0100
description:
Moved duplicate code to display a user's profile to USER_showProfile

diffstat:

 public_html/users.php        |  276 +---------------------------------------------
 public_html/usersettings.php |  230 +--------------------------------------
 system/lib-user.php          |  283 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 286 insertions(+), 503 deletions(-)

diffs (truncated from 838 to 300 lines):

diff -r 2aebb10845a7 -r f80e6bf50494 public_html/users.php
--- a/public_html/users.php	Sun Feb 21 11:24:07 2010 +0100
+++ b/public_html/users.php	Sun Feb 21 13:50:01 2010 +0100
@@ -55,278 +55,6 @@
 // echo COM_debug($_POST);
 
 /**
-* Shows a profile for a user
-*
-* This grabs the user profile for a given user and displays it
-*
-* @param    int     $uid    User ID of profile to get
-* @param    int     $msg    Message to display (if != 0)
-* @param    string  $plugin optional plugin name for message
-* @return   string          HTML for user profile page
-*
-*/
-function userprofile($uid, $msg = 0, $plugin = '')
-{
-    global $_CONF, $_TABLES, $_USER, $_IMAGE_TYPE,
-           $LANG01, $LANG04, $LANG09, $LANG28, $LANG_LOGIN, $LANG_ADMIN;
-
-    $retval = '';
-
-    if (COM_isAnonUser() &&
-        (($_CONF['loginrequired'] == 1) || ($_CONF['profileloginrequired'] == 1))) {
-        $retval .= COM_siteHeader('menu', $LANG_LOGIN[1]);
-        $retval .= SEC_loginRequiredForm();
-        $retval .= COM_siteFooter();
-
-        return $retval;
-    }
-
-    $result = DB_query("SELECT {$_TABLES['users']}.uid,username,fullname,regdate,homepage,about,location,pgpkey,photo,email,status FROM {$_TABLES['userinfo']},{$_TABLES['users']} WHERE {$_TABLES['userinfo']}.uid = {$_TABLES['users']}.uid AND {$_TABLES['users']}.uid = $uid");
-    $nrows = DB_numRows($result);
-    if ($nrows == 0) { // no such user
-        return COM_refresh($_CONF['site_url'] . '/index.php');
-    }
-    $A = DB_fetchArray($result);
-
-    if ($A['status'] == USER_ACCOUNT_DISABLED && !SEC_hasRights('user.edit')) {
-        COM_displayMessageAndAbort(30, '', 403, 'Forbidden');
-    }
-
-    $display_name = htmlspecialchars(COM_getDisplayName($uid, $A['username'],
-                                                        $A['fullname']));
-
-    $retval .= COM_siteHeader('menu', $LANG04[1] . ' ' . $display_name);
-    if ($msg > 0) {
-        $retval .= COM_showMessage($msg, $plugin);
-    }
-
-    // format date/time to user preference
-    $curtime = COM_getUserDateTimeFormat($A['regdate']);
-    $A['regdate'] = $curtime[0];
-
-    $user_templates = new Template($_CONF['path_layout'] . 'users');
-    $user_templates->set_file(array('profile' => 'profile.thtml',
-                                    'row'     => 'commentrow.thtml',
-                                    'strow'   => 'storyrow.thtml'));
-    $user_templates->set_var('xhtml', XHTML);
-    $user_templates->set_var('site_url', $_CONF['site_url']);
-    $user_templates->set_var('site_admin_url', $_CONF['site_admin_url']);
-    $user_templates->set_var('layout_url', $_CONF['layout_url']);
-    $user_templates->set_var('start_block_userprofile',
-            COM_startBlock($LANG04[1] . ' ' . $display_name));
-    $user_templates->set_var('end_block', COM_endBlock());
-    $user_templates->set_var('lang_username', $LANG04[2]);
-
-    if ($_CONF['show_fullname'] == 1) {
-        if (empty($A['fullname'])) {
-            $username = $A['username'];
-            $fullname = '';
-        } else {
-            $username = $A['fullname'];
-            $fullname = $A['username'];
-        }
-    } else {
-        $username = $A['username'];
-        $fullname = $A['fullname'];
-    }
-    $username = htmlspecialchars($username);
-    $fullname = htmlspecialchars($fullname);
-
-    if ($A['status'] == USER_ACCOUNT_DISABLED) {
-        $username = sprintf('<s title="%s">%s</s>', $LANG28[42], $username);
-        if (!empty($fullname)) {
-            $fullname = sprintf('<s title="%s">%s</s>', $LANG28[42], $fullname);
-        }
-    }
-
-    $user_templates->set_var('username', $username);
-    $user_templates->set_var('user_fullname', $fullname);
-
-    if (!COM_isAnonUser() && ($_USER['uid'] == $uid)) {
-        $edit_icon = '<img src="' . $_CONF['layout_url'] . '/images/edit.'
-                   . $_IMAGE_TYPE . '" alt="' . $LANG01[48]
-                   . '" title="' . $LANG01[48] . '"' . XHTML . '>';
-        $edit_link_url = COM_createLink($edit_icon,
-                            $_CONF['site_url'] . '/usersettings.php');
-        $user_templates->set_var('edit_icon', $edit_icon);
-        $user_templates->set_var('edit_link', $edit_link_url);
-        $user_templates->set_var('user_edit', $edit_link_url);
-    } elseif (SEC_hasRights('user.edit')) {
-        $edit_icon = '<img src="' . $_CONF['layout_url'] . '/images/edit.'
-                   . $_IMAGE_TYPE . '" alt="' . $LANG_ADMIN['edit']
-                   . '" title="' . $LANG_ADMIN['edit'] . '"' . XHTML . '>';
-        $edit_link_url = COM_createLink($edit_icon,
-            "{$_CONF['site_admin_url']}/user.php?mode=edit&uid={$A['uid']}");
-        $user_templates->set_var('edit_icon', $edit_icon);
-        $user_templates->set_var('edit_link', $edit_link_url);
-        $user_templates->set_var('user_edit', $edit_link_url);
-    }
-
-    if (isset ($A['photo']) && empty ($A['photo'])) {
-        $A['photo'] = '(none)'; // user does not have a photo
-    }
-    $photo = USER_getPhoto ($uid, $A['photo'], $A['email'], -1);
-    $user_templates->set_var ('user_photo', $photo);
-
-    $user_templates->set_var ('lang_membersince', $LANG04[67]);
-    $user_templates->set_var ('user_regdate', $A['regdate']);        
-    $user_templates->set_var ('lang_email', $LANG04[5]);
-    $user_templates->set_var ('user_id', $uid);
-    $user_templates->set_var ('uid', $uid);
-    $user_templates->set_var ('lang_sendemail', $LANG04[81]);
-    $user_templates->set_var ('lang_homepage', $LANG04[6]);
-    $user_templates->set_var ('user_homepage', COM_killJS ($A['homepage']));
-    $user_templates->set_var ('lang_location', $LANG04[106]);
-    $user_templates->set_var ('user_location', strip_tags ($A['location']));
-    $user_templates->set_var ('lang_bio', $LANG04[7]);
-    $user_templates->set_var ('user_bio', nl2br (stripslashes ($A['about'])));
-    $user_templates->set_var ('lang_pgpkey', $LANG04[8]);
-    $user_templates->set_var ('user_pgp', nl2br ($A['pgpkey']));
-    $user_templates->set_var ('start_block_last10stories',
-            COM_startBlock ($LANG04[82] . ' ' . $display_name));
-    $user_templates->set_var ('start_block_last10comments',
-            COM_startBlock($LANG04[10] . ' ' . $display_name));
-    $user_templates->set_var ('start_block_postingstats',
-            COM_startBlock ($LANG04[83] . ' ' . $display_name));
-    $user_templates->set_var ('lang_title', $LANG09[16]);
-    $user_templates->set_var ('lang_date', $LANG09[17]);
-
-    // for alternative layouts: use these as headlines instead of block titles
-    $user_templates->set_var ('headline_last10stories', $LANG04[82]);
-    $user_templates->set_var ('headline_last10comments', $LANG04[10]);
-    $user_templates->set_var ('headline_postingstats', $LANG04[83]);
-
-    $result = DB_query ("SELECT tid FROM {$_TABLES['topics']}"
-            . COM_getPermSQL ());
-    $nrows = DB_numRows ($result);
-    $tids = array ();
-    for ($i = 0; $i < $nrows; $i++) {
-        $T = DB_fetchArray ($result);
-        $tids[] = $T['tid'];
-    }
-    $topics = "'" . implode ("','", $tids) . "'";
-
-    // list of last 10 stories by this user
-    if (count($tids) > 0) {
-        $sql = "SELECT sid,title,UNIX_TIMESTAMP(date) AS unixdate FROM {$_TABLES['stories']} WHERE (uid = $uid) AND (draft_flag = 0) AND (date <= NOW()) AND (tid IN ($topics))" . COM_getPermSQL ('AND');
-        $sql .= " ORDER BY unixdate DESC LIMIT 10";
-        $result = DB_query ($sql);
-        $nrows = DB_numRows ($result);
-    } else {
-        $nrows = 0;
-    }
-    if ($nrows > 0) {
-        for ($i = 0; $i < $nrows; $i++) {
-            $C = DB_fetchArray ($result);
-            $user_templates->set_var ('cssid', ($i % 2) + 1);
-            $user_templates->set_var ('row_number', ($i + 1) . '.');
-            $articleUrl = COM_buildUrl ($_CONF['site_url']
-                                        . '/article.php?story=' . $C['sid']);
-            $user_templates->set_var ('article_url', $articleUrl);
-            $C['title'] = str_replace ('$', '$', $C['title']);
-            $user_templates->set_var ('story_title',
-                COM_createLink(
-                    stripslashes ($C['title']),
-                    $articleUrl,
-                    array ('class'=>'b'))
-            );
-            $storytime = COM_getUserDateTimeFormat ($C['unixdate']);
-            $user_templates->set_var ('story_date', $storytime[0]);
-            $user_templates->parse ('story_row', 'strow', true);
-        }
-    } else {
-        $user_templates->set_var ('story_row',
-                                  '<tr><td>' . $LANG01[37] . '</td></tr>');
-    }
-
-    // list of last 10 comments by this user
-    $sidArray = array();
-    if (count($tids) > 0) {
-        // first, get a list of all stories the current visitor has access to
-        $sql = "SELECT sid FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW()) AND (tid IN ($topics))" . COM_getPermSQL ('AND');
-        $result = DB_query($sql);
-        $numsids = DB_numRows($result);
-        for ($i = 1; $i <= $numsids; $i++) {
-            $S = DB_fetchArray ($result);
-            $sidArray[] = $S['sid'];
-        }
-    }
-    $sidList = implode("', '",$sidArray);
-    $sidList = "'$sidList'";
-
-    // then, find all comments by the user in those stories
-    $sql = "SELECT sid,title,cid,UNIX_TIMESTAMP(date) AS unixdate FROM {$_TABLES['comments']} WHERE (uid = $uid) GROUP BY sid,title,cid,UNIX_TIMESTAMP(date)";
-
-    // SQL NOTE:  Using a HAVING clause is usually faster than a where if the
-    // field is part of the select
-    // if (!empty ($sidList)) {
-    //     $sql .= " AND (sid in ($sidList))";
-    // }
-    if (!empty ($sidList)) {
-        $sql .= " HAVING sid in ($sidList)";
-
-
-    }
-    $sql .= " ORDER BY unixdate DESC LIMIT 10";
-
-
-    $result = DB_query($sql);
-    $nrows = DB_numRows($result);
-    if ($nrows > 0) {
-        for ($i = 0; $i < $nrows; $i++) {
-            $C = DB_fetchArray ($result);
-            $user_templates->set_var ('cssid', ($i % 2) + 1);
-            $user_templates->set_var ('row_number', ($i + 1) . '.');
-            $C['title'] = str_replace ('$', '$', $C['title']);
-            $comment_url = $_CONF['site_url'] .
-                    '/comment.php?mode=view&cid=' . $C['cid'];
-            $user_templates->set_var ('comment_title',
-                COM_createLink(
-                    stripslashes ($C['title']),
-                    $comment_url,
-                    array ('class'=>'b'))
-            );
-            $commenttime = COM_getUserDateTimeFormat ($C['unixdate']);
-            $user_templates->set_var ('comment_date', $commenttime[0]);
-            $user_templates->parse ('comment_row', 'row', true);
-        }
-    } else {
-        $user_templates->set_var('comment_row','<tr><td>' . $LANG01[29] . '</td></tr>');
-    }
-
-    // posting stats for this user
-    $user_templates->set_var ('lang_number_stories', $LANG04[84]);
-    $sql = "SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (uid = $uid) AND (draft_flag = 0) AND (date <= NOW())" . COM_getPermSQL ('AND');
-    $result = DB_query($sql);
-    $N = DB_fetchArray ($result);
-    $user_templates->set_var ('number_stories', COM_numberFormat ($N['count']));
-    $user_templates->set_var ('lang_number_comments', $LANG04[85]);
-    $sql = "SELECT COUNT(*) AS count FROM {$_TABLES['comments']} WHERE (uid = $uid)";
-    if (!empty ($sidList)) {
-        $sql .= " AND (sid in ($sidList))";
-    }
-    $result = DB_query ($sql);
-    $N = DB_fetchArray ($result);
-    $user_templates->set_var ('number_comments', COM_numberFormat($N['count']));
-    $user_templates->set_var ('lang_all_postings_by',
-                              $LANG04[86] . ' ' . $display_name);
-
-    // Call custom registration function if enabled and exists
-    if ($_CONF['custom_registration'] && function_exists ('CUSTOM_userDisplay') ) {
-        $user_templates->set_var ('customfields', CUSTOM_userDisplay ($uid));
-    }
-    PLG_profileVariablesDisplay ($uid, $user_templates);
-
-    $user_templates->parse ('output', 'profile');
-    $retval .= $user_templates->finish ($user_templates->get_var ('output'));
-
-    $retval .= PLG_profileBlocksDisplay ($uid);
-    $retval .= COM_siteFooter ();
-
-    return $retval;
-}
-
-/**
 * Emails password to a user
 *
 * This will email the given user their password.
@@ -901,7 +629,7 @@
         if (($msg > 0) && isset($_GET['plugin'])) {
             $plugin = COM_applyFilter($_GET['plugin']);
         }
-        $display .= userprofile($uid, $msg, $plugin);
+        $display .= USER_showProfile($uid, false, $msg, $plugin);
     } else {
         $display .= COM_refresh ($_CONF['site_url'] . '/index.php');
     }
@@ -913,7 +641,7 @@
         $username = addslashes ($username);
         $uid = DB_getItem ($_TABLES['users'], 'uid', "username = '$username'");
         if ($uid > 1) {
-            $display .= userprofile ($uid);
+            $display .= USER_showProfile($uid);
         } else {
             $display .= COM_refresh ($_CONF['site_url'] . '/index.php');
         }



More information about the geeklog-cvs mailing list