Completed
Push — master ( d5e38f...a385a9 )
by Richard
16:37 queued 09:02
created

SystemsmiliesHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Smilies 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 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @author              Kazumi Ono (AKA onokazu)
15
 * @author              Gregory Mage (AKA Mage)
16
 * @package             system
17
 */
18
19
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
20
21
/**
22
 * System Smilies
23
 *
24
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
25
 * @package             system
26
 */
27
class SystemSmilies extends XoopsObject
28
{
29
    /**
30
     *
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
        $this->initVar('id', XOBJ_DTYPE_INT, null, false, 5);
36
        $this->initVar('code', XOBJ_DTYPE_TXTBOX, null, false);
37
        $this->initVar('smile_url', XOBJ_DTYPE_TXTBOX, null, false);
38
        $this->initVar('emotion', XOBJ_DTYPE_TXTBOX, null, false);
39
        $this->initVar('display', XOBJ_DTYPE_INT, null, false, 1);
40
    }
41
42
    /**
43
     * @param bool $action
44
     *
45
     * @return XoopsThemeForm
46
     */
47
    public function getForm($action = false)
48
    {
49 View Code Duplication
        if ($this->isNew()) {
50
            $blank_img = 'blank.gif';
51
        } else {
52
            $blank_img = str_replace('smilies/', '', $this->getVar('smile_url', 'e'));
53
        }
54
        if ($action === false) {
55
            $action = $_SERVER['REQUEST_URI'];
56
        }
57
58
        $title = $this->isNew() ? sprintf(_AM_SYSTEM_SMILIES_ADD) : sprintf(_AM_SYSTEM_SMILIES_EDIT);
59
60
        $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
61
        $form->setExtra('enctype="multipart/form-data"');
62
        $form->addElement(new XoopsFormText(_AM_SYSTEM_SMILIES_CODE, 'code', 26, 25, $this->getVar('code')), true);
63
        $form->addElement(new XoopsFormText(_AM_SYSTEM_SMILIES_DESCRIPTION, 'emotion', 50, 50, $this->getVar('emotion')), true);
64
65
        $imgtray_img     = new XoopsFormElementTray(_AM_SYSTEM_SMILIES_FILE, '<br>');
66
        $imgpath_img     = sprintf(_AM_SYSTEM_SMILIES_IMAGE_PATH, XOOPS_UPLOAD_PATH . '/smilies/');
67
        $imageselect_img = new XoopsFormSelect($imgpath_img, 'smile_url', $blank_img);
68
        $image_array_img = XoopsLists::getImgListAsArray(XOOPS_UPLOAD_PATH . '/smilies');
69
        $imageselect_img->addOption("$blank_img", $blank_img);
70
        foreach ($image_array_img as $image_img) {
71
            $imageselect_img->addOption("$image_img", $image_img);
72
        }
73
        $imageselect_img->setExtra('onchange="showImgSelected(\'xo-smilies-img\', \'smile_url\', \'smilies\', \'\', \'' . XOOPS_UPLOAD_URL . '\' )"');
74
        $imgtray_img->addElement($imageselect_img, false);
75
        $imgtray_img->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_UPLOAD_URL . '/smilies/' . $blank_img . "' name='image_img' id='xo-smilies-img' alt='' />"));
76
77
        $fileseltray_img = new XoopsFormElementTray('<br>', '<br><br>');
78
        $fileseltray_img->addElement(new XoopsFormFile(_AM_SYSTEM_SMILIES_UPLOADS, 'smile_url', 500000), false);
79
        $fileseltray_img->addElement(new XoopsFormLabel(''), false);
80
        $imgtray_img->addElement($fileseltray_img);
81
        $form->addElement($imgtray_img);
82
83
        if (!$this->isNew()) {
84
            $form->addElement(new XoopsFormHidden('smilies_id', $this->getVar('id')));
85
            $display = $this->getVar('display');
86
        } else {
87
            $display = 0;
88
        }
89
90
        $form->addElement(new XoopsFormRadioYN(_AM_SYSTEM_SMILIES_OFF, 'display', $display));
91
92
        $form->addElement(new XoopsFormHidden('op', 'save_smilie'));
93
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
94
95
        return $form;
96
    }
97
}
98
99
/**
100
 * System smilies handler class. (Singelton)
101
 *
102
 * This class is responsible for providing data access mechanisms to the data source
103
 * of XOOPS block class objects.
104
 *
105
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
106
 * @package             system
107
 * @subpackage          avatar
108
 */
109
class SystemsmiliesHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
110
{
111
    /**
112
     * @param null|XoopsDatabase $db
113
     */
114
    public function __construct(XoopsDatabase $db)
115
    {
116
        parent::__construct($db, 'smiles', 'SystemSmilies', 'id', 'code');
117
    }
118
}
119