Bunch of diffs
| From: | Steph | Date: | Wed, 08 Sep 2004 10:17:59 +0000 |
| Subject: | Bunch of diffs | ||
| Groups: | php.pear.webmaster | ||
| Request: | Send a blank email to pear-webmaster+get-3087@lists.php.net to get a copy of this message | ||
Hi all,
As promised some days ago on irc - a new table structure, a couple of new
functions for /include/pear-database.php that deal with uploading and
retrieving data from the new table, a total rewrite of the existing
zendWhoIsWho function, a form intended for /public_html dir, and a link to
that form from /public_html/account_edit.php
This is all completely untested and I'm renowned for missing brackets etc,
so if you spot anything that has a touch of 'queasy-feely-doom' about it
please feel free to argue with me or fix it. If it involves adding extra
fields to the table, I need to know about it please!
We can go live with this as soon as the new functions have been tested.
Thanks for all your patience!
- Steph
DevZone Editor
www.zend.com
--- account_edit_orig.php Wed Sep 08 10:27:56 2004 +++ account_edit_new.php Wed Sep 08 10:36:16 2004 @@ -36,7 +36,8 @@ print '<h1>Edit Profile: '; print '<a href="/user/'. $handle . '">' . $handle . '</a></h1>' . "\n"; -print "<ul><li><a href=\"#password\">Manage your password</a></li></ul>"; +print "<ul><li><a href=\"#password\">Manage your password</a></li>"; +print "<li><a href='zend_edit.php?handle=$handle'>Update your zend.com profile</a></li></ul>"; $admin = $auth_user->isAdmin(); $user = $auth_user->is($handle); CREATE TABLE zendinfo ( handle varchar(20) NOT NULL default '', birthdate date default NULL, locale varchar(30) default NULL, timezone varchar(20) default NULL, occupation varchar(255) default NULL, currentjob varchar(255) default NULL, available tinyint(1) default NULL, certified enum('no', 'PHP 4','PHP 5') NOT NULL default 'no', otherquals text, spokenlangs varchar(255) default NULL, programlangs varchar(255) default NULL, otherphpnet text, otheross text, otherhobbies text, spare text, PRIMARY KEY (handle), ) TYPE=MyISAM; --- pear-database_orig.php Wed Sep 08 10:28:26 2004 +++ pear-database_new.php Wed Sep 08 10:45:00 2004 @@ -2314,7 +2314,7 @@ } // }}} - // {{{ * proto array user::getZendWhoIsWho([bool]) API 1.0 + // {{{ * proto array user::getZendWhoIsWho() API 1.0 /** * Get list of current developers and the packages they maintain. @@ -2325,27 +2325,19 @@ * of IP addresses. * * @access public - * @param bool Whether to return PECL developers (true) or PEAR - * developers (false) * @return array */ - function getZendWhoIsWho($pecl_only = false) { + function getZendWhoIsWho() { global $dbh; // IP whitelist - if (!in_array($_SERVER['REMOTE_ADDR'], array("127.0.0.1", "64.49.209.152", "209.61.191.11"))) { + if (!in_array($_SERVER['REMOTE_ADDR'], array("127.0.0.1", "209.61.191.11"))) { return array(); } - if ($pecl_only) { - $query_maintainers = "SELECT p.name, m.role, p.package_type " + $query_maintainers = "SELECT p.name, m.role, p.package_type " . "FROM maintains m, packages p " - . "WHERE m.package = p.id AND p.package_type='pecl' AND m.handle = ?"; - } else { - $query_maintainers = "SELECT p.name, m.role, p.package_type " - . "FROM maintains m, packages p " - . "WHERE m.package = p.id AND p.package_type='pear' AND m.handle = ?"; - } + . "WHERE m.package = p.id AND m.handle = ?"; $maintainers = $dbh->prepare($query_maintainers); @@ -2353,14 +2345,10 @@ . "FROM karma " . "WHERE level = 'pear.group' AND user = ?"); - // This fetches all users with pear.dev karma - $query = "SELECT u.handle, u.name, u.homepage, u.userinfo " - . "FROM users u, karma k " - . "WHERE k.user = u.handle AND k.level = 'pear.dev' AND u.registered = 1"; - - $query_group = "SELECT user " - . "FROM karma " - . "WHERE level = 'pear.group'"; + /* Some pecl devs don't have pear.dev karma. Need to check every registered user. */ + $query = "SELECT handle, name, homepage, userinfo FROM users WHERE registered = 1"; + + $query_group = "SELECT user FROM karma WHERE level = 'pear.group'"; $group_ids = $dbh->getCol($query_group); $group_ids = array_flip($group_ids); @@ -2379,10 +2367,31 @@ while ($row =& $sth->fetchRow(DB_FETCHMODE_ASSOC)) { $users[$id]['maintains'][] = $row; - if ($pecl_only && !isset($users[$id]['pecl']) && $row['package_type'] == 'pecl') { - $users[$id]['pecl'] = 1; + + switch ($users[$id]['type']) { + case '3': + break; + case '2': + if ($row['package_type'] == 'pear') { + $users[$id]['type'] = 3; + } + break; + case '1': + if ($row['package_type'] == 'pecl') { + $users[$id]['type'] = 3; + } + break; + default: + if ($row['package_type'] == 'pecl') { + $users[$id]['type'] = 2; + } + else { + $users[$id]['type'] = 1; + } + break; } } + if (isset($group_ids[$user['handle']])) { $users[$id]['group'] = 1; } else { @@ -2392,6 +2401,82 @@ return $users; } + + // }}} + // {{{ user::zendUpdate() + + /** + * Update zend profile + * + * @access public + * @param array User information + * @return int Number of fields updated + */ + function zendUpdate($data) { + global $dbh; + + $fields = array('handle', 'birthdate', 'locale', 'timezone', 'occupation', 'currentjob', 'available', 'certified', 'otherquals', 'spokenlangs', 'programlangs', 'otherphpnet', 'otheross', 'otherhobbies', 'spare'); + $update = ''; + + foreach($fields as $key => $value) { + $insert[] = "'".$data[$value]."'"; + $update = $update.$fields[$key]." = '".$data[$value]."', "; + } + + $exists = $dbh->getRow("SELECT * FROM zendinfo WHERE handle = '".$handle."'"); + + if(!empty($exists)) { + $update = "UPDATE zendinfo SET ".$update."WHERE handle = '".$data['handle']."'"; + $update = str_replace(', WHERE', ' WHERE', $update); + } else { + $insert = implode(', ', $insert); + $update = "INSERT INTO zendinfo VALUES (".$insert.")"; + } + + $dbh->query('"'.$update.'"'); + $fieldcount = $dbh->affectedRows(); + return $fieldcount; + } + + // }}} + // {{{ * proto array user::getZendProfile() API 1.0 + + /** + * XML-RPC collection of Zend profile info + * + * @access public + * @return array User info + * + * As with getZendWhoIsWho(), XML-RPC access to this function is whitelist-protected. + * + */ + function getZendProfile() { + global $dbh; + + // IP whitelist + if (!in_array($_SERVER['REMOTE_ADDR'], array("127.0.0.1", "209.61.191.11"))) { + return array(); + } + + $query_maintainers = "SELECT package FROM maintains WHERE handle = ?"; + $maintainers = $dbh->prepare($query_maintainers); + + $query = "SELECT * FROM zendinfo"; + $users = $dbh->getAll($query, null, DB_FETCHMODE_ASSOC); + + foreach ($users as $id => $user) { + // Figure out whether the user is currently active + $sth = $dbh->execute($maintainers, array($user['handle'])); + + // Skip if the user is maintaining nothing + if ($sth->numRows() == 0) { + unset($users[$id]); + continue; + } + } + return $users; + } + // }}} } class channel <?php /* +----------------------------------------------------------------------+ | PEAR Web site version 1.0 | +----------------------------------------------------------------------+ | Copyright (c) 2001-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: | +----------------------------------------------------------------------+ $Id: account-edit.php,v 1.35 2004/07/24 18:01:46 danielc Exp $ */ auth_require(); require_once 'HTML/Form.php'; if (isset($_GET['handle'])) { $handle = strtolower($_GET['handle']); } elseif (isset($_POST['handle'])) { $handle = strtolower($_POST['handle']); } else { $handle = ''; } ob_start(); response_header('Edit Zend Profile :: ' . $handle); print '<h1>Edit Zend Profile: '; print '<a href="http://www.zend.com/pear/person.php?'. $handle . '">' .. $handle . '</a></h1>' . "\n"; $admin = $auth_user->isAdmin(); $user = $auth_user->is($handle); if (!$admin && !$user) { PEAR::raiseError("Only the user or PEAR administrators can edit Zend profile information."); response_footer(); exit(); } if (empty($handle) && !isset($_POST['zcommand'])) { PEAR::raiseError("No valid handle found!"); } if (isset($_POST['zcommand'])) { $updated = user::zendUpdate($_POST); if($updated > 0) { report_success('Your Zend profile was successfully updated.'); } } $dbh->setFetchmode(DB_FETCHMODE_ASSOC); $row = $dbh->getRow('SELECT * FROM zendinfo WHERE handle = ?', array($handle)); if ($row === null) { error_handler($handle . ' is not a valid account name.', 'Invalid Account'); } $th = 'class="form-label_left"'; $td = 'class="form-input"'; $form = new HTML_Form($_SERVER['PHP_SELF'], 'post'); $form->addText('birthdate', 'Date of birth:', $row['birthdate'], 40, null, '', $th, $td); $form->addText('locale', 'Location:', $row['locale'], 40, null, '', $th, $td); $form->addText('timezone', 'Timezone:', $row['timezone'], 40, null, '', $th, $td); $form->addText('occupation', 'Occupation:', $row['occupation'], 40, null, '', $th, $td); $form->addTextarea('currentjob', 'Current employment:', $row['currentjob'], 40, 3, null, '', $th, $td); $form->addCheckbox('available', 'Available for work?', $row['available'], '', $th, $td); $form->addText('certified', 'Zend certified?', $row['certified'], 40, null, '', $th, $td); $form->addTextarea('otherquals', 'Other qualifications:', $row['email'], 40, 3, null, '', $th, $td); $form->addTextarea('spokenlangs', 'Spoken languages:', $row['showemail'], 40, 3, null, '', $th, $td); $form->addTextarea('programlangs', 'Programming languages:', $row['programlangs'], 40, 3, null, '', $th, $td); $form->addTextarea('otherphpnet', 'Other php.net work:', $row['otherphpnet'], 40, 3, null, '', $th, $td); $form->addTextarea('otheross', 'Other open source projects:' $row['otheross'], 40, 3, null, '', $th, $td); $form->addTextarea('otherhobbies', 'Non-programming hobbies:', $row['otherhobbies'], 40, 5, null, '', $th, $td); $form->addSubmit('submit', 'Submit', '', $th, $td); $form->addHidden('handle', $handle); $form->addHidden('zcommand', 'update'); $form->addHidden('spare', ''); $form->display('class="form-holder" style="margin-bottom: 2em;"' . ' cellspacing="1"', 'Edit Your Zend Profile', 'class="form-caption"'); ob_end_flush(); response_footer(); ?>
--- account_edit_orig.php Wed Sep 08 10:27:56 2004 +++ account_edit_new.php Wed Sep 08 10:36:16 2004 @@ -36,7 +36,8 @@ print '<h1>Edit Profile: '; print '<a href="/user/'. $handle . '">' . $handle . '</a></h1>' . "\n"; -print "<ul><li><a href=\"#password\">Manage your password</a></li></ul>"; +print "<ul><li><a href=\"#password\">Manage your password</a></li>"; +print "<li><a href='zend_edit.php?handle=$handle'>Update your zend.com profile</a></li></ul>"; $admin = $auth_user->isAdmin(); $user = $auth_user->is($handle); CREATE TABLE zendinfo ( handle varchar(20) NOT NULL default '', birthdate date default NULL, locale varchar(30) default NULL, timezone varchar(20) default NULL, occupation varchar(255) default NULL, currentjob varchar(255) default NULL, available tinyint(1) default NULL, certified enum('no', 'PHP 4','PHP 5') NOT NULL default 'no', otherquals text, spokenlangs varchar(255) default NULL, programlangs varchar(255) default NULL, otherphpnet text, otheross text, otherhobbies text, spare text, PRIMARY KEY (handle), ) TYPE=MyISAM; --- pear-database_orig.php Wed Sep 08 10:28:26 2004 +++ pear-database_new.php Wed Sep 08 10:45:00 2004 @@ -2314,7 +2314,7 @@ } // }}} - // {{{ * proto array user::getZendWhoIsWho([bool]) API 1.0 + // {{{ * proto array user::getZendWhoIsWho() API 1.0 /** * Get list of current developers and the packages they maintain. @@ -2325,27 +2325,19 @@ * of IP addresses. * * @access public - * @param bool Whether to return PECL developers (true) or PEAR - * developers (false) * @return array */ - function getZendWhoIsWho($pecl_only = false) { + function getZendWhoIsWho() { global $dbh; // IP whitelist - if (!in_array($_SERVER['REMOTE_ADDR'], array("127.0.0.1", "64.49.209.152", "209.61.191.11"))) { + if (!in_array($_SERVER['REMOTE_ADDR'], array("127.0.0.1", "209.61.191.11"))) { return array(); } - if ($pecl_only) { - $query_maintainers = "SELECT p.name, m.role, p.package_type " + $query_maintainers = "SELECT p.name, m.role, p.package_type " . "FROM maintains m, packages p " - . "WHERE m.package = p.id AND p.package_type='pecl' AND m.handle = ?"; - } else { - $query_maintainers = "SELECT p.name, m.role, p.package_type " - . "FROM maintains m, packages p " - . "WHERE m.package = p.id AND p.package_type='pear' AND m.handle = ?"; - } + . "WHERE m.package = p.id AND m.handle = ?"; $maintainers = $dbh->prepare($query_maintainers); @@ -2353,14 +2345,10 @@ . "FROM karma " . "WHERE level = 'pear.group' AND user = ?"); - // This fetches all users with pear.dev karma - $query = "SELECT u.handle, u.name, u.homepage, u.userinfo " - . "FROM users u, karma k " - . "WHERE k.user = u.handle AND k.level = 'pear.dev' AND u.registered = 1"; - - $query_group = "SELECT user " - . "FROM karma " - . "WHERE level = 'pear.group'"; + /* Some pecl devs don't have pear.dev karma. Need to check every registered user. */ + $query = "SELECT handle, name, homepage, userinfo FROM users WHERE registered = 1"; + + $query_group = "SELECT user FROM karma WHERE level = 'pear.group'"; $group_ids = $dbh->getCol($query_group); $group_ids = array_flip($group_ids); @@ -2379,10 +2367,31 @@ while ($row =& $sth->fetchRow(DB_FETCHMODE_ASSOC)) { $users[$id]['maintains'][] = $row; - if ($pecl_only && !isset($users[$id]['pecl']) && $row['package_type'] == 'pecl') { - $users[$id]['pecl'] = 1; + + switch ($users[$id]['type']) { + case '3': + break; + case '2': + if ($row['package_type'] == 'pear') { + $users[$id]['type'] = 3; + } + break; + case '1': + if ($row['package_type'] == 'pecl') { + $users[$id]['type'] = 3; + } + break; + default: + if ($row['package_type'] == 'pecl') { + $users[$id]['type'] = 2; + } + else { + $users[$id]['type'] = 1; + } + break; } } + if (isset($group_ids[$user['handle']])) { $users[$id]['group'] = 1; } else { @@ -2392,6 +2401,82 @@ return $users; } + + // }}} + // {{{ user::zendUpdate() + + /** + * Update zend profile + * + * @access public + * @param array User information + * @return int Number of fields updated + */ + function zendUpdate($data) { + global $dbh; + + $fields = array('handle', 'birthdate', 'locale', 'timezone', 'occupation', 'currentjob', 'available', 'certified', 'otherquals', 'spokenlangs', 'programlangs', 'otherphpnet', 'otheross', 'otherhobbies', 'spare'); + $update = ''; + + foreach($fields as $key => $value) { + $insert[] = "'".$data[$value]."'"; + $update = $update.$fields[$key]." = '".$data[$value]."', "; + } + + $exists = $dbh->getRow("SELECT * FROM zendinfo WHERE handle = '".$handle."'"); + + if(!empty($exists)) { + $update = "UPDATE zendinfo SET ".$update."WHERE handle = '".$data['handle']."'"; + $update = str_replace(', WHERE', ' WHERE', $update); + } else { + $insert = implode(', ', $insert); + $update = "INSERT INTO zendinfo VALUES (".$insert.")"; + } + + $dbh->query('"'.$update.'"'); + $fieldcount = $dbh->affectedRows(); + return $fieldcount; + } + + // }}} + // {{{ * proto array user::getZendProfile() API 1.0 + + /** + * XML-RPC collection of Zend profile info + * + * @access public + * @return array User info + * + * As with getZendWhoIsWho(), XML-RPC access to this function is whitelist-protected. + * + */ + function getZendProfile() { + global $dbh; + + // IP whitelist + if (!in_array($_SERVER['REMOTE_ADDR'], array("127.0.0.1", "209.61.191.11"))) { + return array(); + } + + $query_maintainers = "SELECT package FROM maintains WHERE handle = ?"; + $maintainers = $dbh->prepare($query_maintainers); + + $query = "SELECT * FROM zendinfo"; + $users = $dbh->getAll($query, null, DB_FETCHMODE_ASSOC); + + foreach ($users as $id => $user) { + // Figure out whether the user is currently active + $sth = $dbh->execute($maintainers, array($user['handle'])); + + // Skip if the user is maintaining nothing + if ($sth->numRows() == 0) { + unset($users[$id]); + continue; + } + } + return $users; + } + // }}} } class channel <?php /* +----------------------------------------------------------------------+ | PEAR Web site version 1.0 | +----------------------------------------------------------------------+ | Copyright (c) 2001-2003 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 2.02 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: | +----------------------------------------------------------------------+ $Id: account-edit.php,v 1.35 2004/07/24 18:01:46 danielc Exp $ */ auth_require(); require_once 'HTML/Form.php'; if (isset($_GET['handle'])) { $handle = strtolower($_GET['handle']); } elseif (isset($_POST['handle'])) { $handle = strtolower($_POST['handle']); } else { $handle = ''; } ob_start(); response_header('Edit Zend Profile :: ' . $handle); print '<h1>Edit Zend Profile: '; print '<a href="http://www.zend.com/pear/person.php?'. $handle . '">' .. $handle . '</a></h1>' . "\n"; $admin = $auth_user->isAdmin(); $user = $auth_user->is($handle); if (!$admin && !$user) { PEAR::raiseError("Only the user or PEAR administrators can edit Zend profile information."); response_footer(); exit(); } if (empty($handle) && !isset($_POST['zcommand'])) { PEAR::raiseError("No valid handle found!"); } if (isset($_POST['zcommand'])) { $updated = user::zendUpdate($_POST); if($updated > 0) { report_success('Your Zend profile was successfully updated.'); } } $dbh->setFetchmode(DB_FETCHMODE_ASSOC); $row = $dbh->getRow('SELECT * FROM zendinfo WHERE handle = ?', array($handle)); if ($row === null) { error_handler($handle . ' is not a valid account name.', 'Invalid Account'); } $th = 'class="form-label_left"'; $td = 'class="form-input"'; $form = new HTML_Form($_SERVER['PHP_SELF'], 'post'); $form->addText('birthdate', 'Date of birth:', $row['birthdate'], 40, null, '', $th, $td); $form->addText('locale', 'Location:', $row['locale'], 40, null, '', $th, $td); $form->addText('timezone', 'Timezone:', $row['timezone'], 40, null, '', $th, $td); $form->addText('occupation', 'Occupation:', $row['occupation'], 40, null, '', $th, $td); $form->addTextarea('currentjob', 'Current employment:', $row['currentjob'], 40, 3, null, '', $th, $td); $form->addCheckbox('available', 'Available for work?', $row['available'], '', $th, $td); $form->addText('certified', 'Zend certified?', $row['certified'], 40, null, '', $th, $td); $form->addTextarea('otherquals', 'Other qualifications:', $row['email'], 40, 3, null, '', $th, $td); $form->addTextarea('spokenlangs', 'Spoken languages:', $row['showemail'], 40, 3, null, '', $th, $td); $form->addTextarea('programlangs', 'Programming languages:', $row['programlangs'], 40, 3, null, '', $th, $td); $form->addTextarea('otherphpnet', 'Other php.net work:', $row['otherphpnet'], 40, 3, null, '', $th, $td); $form->addTextarea('otheross', 'Other open source projects:' $row['otheross'], 40, 3, null, '', $th, $td); $form->addTextarea('otherhobbies', 'Non-programming hobbies:', $row['otherhobbies'], 40, 5, null, '', $th, $td); $form->addSubmit('submit', 'Submit', '', $th, $td); $form->addHidden('handle', $handle); $form->addHidden('zcommand', 'update'); $form->addHidden('spare', ''); $form->display('class="form-holder" style="margin-bottom: 2em;"' . ' cellspacing="1"', 'Edit Your Zend Profile', 'class="form-caption"'); ob_end_flush(); response_footer(); ?>