1: <?php
2: /**
3: * Avatar Class Manager
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
13: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14: * @package system
15: */
16:
17: // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
18:
19: include_once $GLOBALS['xoops']->path('/kernel/avatar.php');
20:
21: /**
22: * System Avatar
23: *
24: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
25: * @package system
26: */
27: class SystemAvatar extends XoopsAvatar
28: {
29: /**
30: *
31: */
32: public function __construct()
33: {
34: parent::__construct();
35: }
36:
37: /**
38: * @return XoopsThemeForm
39: */
40: public function getForm()
41: {
42: if ($this->isNew()) {
43: $blank_img = 'blank.gif';
44: } else {
45: $blank_img = str_replace('avatars/', '', $this->getVar('avatar_file', 'e'));
46: }
47: // Get User Config
48: /** @var XoopsConfigHandler $config_handler */
49: $config_handler = xoops_getHandler('config');
50: $xoopsConfigUser = $config_handler->getConfigsByCat(XOOPS_CONF_USER);
51: // New and edit form
52: $form = new XoopsThemeForm(_AM_SYSTEM_AVATAR_ADD, 'avatar_form', 'admin.php', 'post', true);
53: $form->setExtra('enctype="multipart/form-data"');
54: // Name
55: $form->addElement(new XoopsFormText(_IMAGENAME, 'avatar_name', 50, 255, $this->getVar('avatar_name', 'e')), true);
56: // Name description
57: $maxpixel = '<div>' . _US_MAXPIXEL . '&nbsp;:&nbsp;' . $xoopsConfigUser['avatar_width'] . ' x ' . $xoopsConfigUser['avatar_height'] . '</div>';
58: $maxsize = '<div>' . _US_MAXIMGSZ . '&nbsp;:&nbsp;' . $xoopsConfigUser['avatar_maxsize'] . '</div>';
59: // Upload part
60: $imgtray_img = new XoopsFormElementTray(_IMAGEFILE, '<br>');
61: $imgtray_img->setDescription($maxpixel . $maxsize);
62: $imageselect_img = new XoopsFormSelect(sprintf(_AM_SYSTEM_AVATAR_USE_FILE, XOOPS_UPLOAD_PATH . '/avatars/'), 'avatar_file', $blank_img);
63: $image_array_img = XoopsLists::getImgListAsArray(XOOPS_UPLOAD_PATH . '/avatars');
64: $imageselect_img->addOption("$blank_img", $blank_img);
65: foreach ($image_array_img as $image_img) {
66: $imageselect_img->addOption("$image_img", $image_img);
67: }
68: $imageselect_img->setExtra("onchange='showImgSelected(\"xo-avatar-img\", \"avatar_file\", \"avatars\", \"\", \"" . XOOPS_UPLOAD_URL . "\")'");
69: $imgtray_img->addElement($imageselect_img, false);
70: $imgtray_img->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_UPLOAD_URL . '/avatars/' . $blank_img . "' name='image_img' id='xo-avatar-img' alt='' />"));
71: $fileseltray_img = new XoopsFormElementTray('<br>', '<br><br>');
72: $fileseltray_img->addElement(new XoopsFormFile(_AM_SYSTEM_AVATAR_UPLOAD, 'avatar_file', 500000), false);
73: $imgtray_img->addElement($fileseltray_img);
74: $form->addElement($imgtray_img);
75: // Weight
76: $form->addElement(new XoopsFormText(_IMGWEIGHT, 'avatar_weight', 3, 4, $this->getVar('avatar_weight', 'e')));
77: // Display
78: $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'avatar_display', $this->getVar('avatar_display', 'e'), _YES, _NO));
79: // Hidden
80: if ($this->isNew()) {
81: $form->addElement(new XoopsFormHidden('avatar_type', 's'));
82: }
83: $form->addElement(new XoopsFormHidden('op', 'save'));
84: $form->addElement(new XoopsFormHidden('fct', 'avatars'));
85: $form->addElement(new XoopsFormHidden('avatar_id', $this->getVar('avatar_id', 'e')));
86: // Button
87: $form->addElement(new XoopsFormButton('', 'avt_button', _SUBMIT, 'submit'));
88:
89: return $form;
90: }
91: }
92:
93: /**
94: * System avatar handler class. (Singelton)
95: *
96: * This class is responsible for providing data access mechanisms to the data source
97: * of XOOPS block class objects.
98: *
99: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
100: * @package system
101: * @subpackage avatar
102: */
103: class SystemAvatarHandler extends XoopsAvatarHandler
104: {
105: /**
106: * @param $db
107: */
108: public function __construct($db)
109: {
110: parent::__construct($db);
111: $this->className = 'SystemAvatar';
112: }
113:
114: /**
115: * Create new Object
116: *
117: * @param bool $isNew
118: * @return object
119: */
120: public function create($isNew = true)
121: {
122: $avatar = new SystemAvatar();
123: if ($isNew) {
124: $avatar->setNew();
125: }
126:
127: return $avatar;
128: }
129:
130: /**
131: * Egt Object
132: *
133: * @param int $id
134: * @return object|false
135: */
136: public function get($id)
137: {
138: $avatar = false;
139: $id = (int)$id;
140: if ($id > 0) {
141: $sql = 'SELECT * FROM ' . $this->db->prefix('avatar') . ' WHERE avatar_id=' . $id;
142: $result = $this->db->query($sql);
143: if (!$this->db->isResultSet($result)) {
144: return false;
145: }
146: $numrows = $this->db->getRowsNum($result);
147: if ($numrows == 1) {
148: $avatar = new SystemAvatar();
149: $avatar->assignVars($this->db->fetchArray($result));
150:
151: return $avatar;
152: }
153: }
154:
155: return $avatar;
156: }
157: }
158: