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