1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112:
<?php
$plugin_is_filter = 5 | CLASS_PLUGIN;
$plugin_description = gettext('Adds user address fields');
$plugin_author = "Stephen Billard (sbillard)";
$plugin_category = gettext('Users');
require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/common/fieldExtender.php');
class userAddressFields extends fieldExtender {
function __construct() {
global $_userAddressFields;
$firstTime = extensionEnabled('userAddressFields') && is_null(getOption('userAddressFields_addedFields'));
parent::constructor('userAddressFields', self::fields());
if ($firstTime) {
$result = query('SELECT * FROM ' . prefix('administrators') . ' WHERE `valid`!=0');
if ($result) {
while ($row = db_fetch_assoc($result)) {
$custom = getSerializedArray($row['custom_data']);
if (!empty($custom)) {
$sql = 'UPDATE ' . prefix('administrators') . ' SET ';
foreach ($custom as $field => $val) {
$sql.= '`' . $field . '`=' . db_quote($val) . ',';
}
$sql .= '`custom_data`=NULL WHERE `id`=' . $row['id'];
query($sql);
}
}
db_free_result($result);
}
}
}
static function fields() {
return array(
array('table' => 'administrators', 'name' => 'street', 'desc' => gettext('Street'), 'type' => 'tinytext'),
array('table' => 'administrators', 'name' => 'website', 'desc' => gettext('Website'), 'type' => 'tinytext'),
array('table' => 'administrators', 'name' => 'city', 'desc' => gettext('City'), 'type' => 'tinytext'),
array('table' => 'administrators', 'name' => 'country', 'desc' => gettext('Country'), 'type' => 'tinytext'),
array('table' => 'administrators', 'name' => 'state', 'desc' => gettext('State'), 'type' => 'tinytext'),
array('table' => 'administrators', 'name' => 'postal', 'desc' => gettext('Postal code'), 'type' => 'tinytext')
);
}
static function addToSearch($list) {
return parent::_addToSearch($list, self::fields());
}
static function adminSave($updated, $userobj, $i, $alter) {
parent::_adminSave($updated, $userobj, $i, $alter, self::fields());
}
static function adminEdit($html, $userobj, $i, $background, $current) {
return parent::_adminEdit($html, $userobj, $i, $background, $current, self::fields());
}
static function mediaItemSave($object, $i) {
return parent::_mediaItemSave($object, $i, self::fields());
}
static function mediaItemEdit($html, $object, $i) {
return parent::_mediaItemEdit($html, $object, $i, self::fields());
}
static function zenpageItemSave($custom, $object) {
return parent::_zenpageItemSave($custom, $object, self::fields());
}
static function zenpageItemEdit($html, $object) {
return parent::_zenpageItemEdit($html, $object, self::fields());
}
static function register() {
parent::_register('userAddressFields', self::fields());
}
static function adminNotice($tab, $subtab) {
parent::_adminNotice($tab, $subtab, 'userAddressFields');
}
static function getCustomData($obj) {
return parent::_getCustomData($obj, self::fields());
}
static function setCustomData($obj, $values) {
parent::_setCustomData($obj, $values);
}
}
if (OFFSET_PATH == 2) {
setOptionDefault('zp_plugin_userAddressFields', $plugin_is_filter);
new userAddressFields;
} else {
userAddressFields::register();
}
?>