|
1
|
|
|
<?php namespace XoopsModules\Smartobject; |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* You may not change or alter any portion of this comment or credits |
|
5
|
|
|
* of supporting developers from this source code or any supporting source code |
|
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
* |
|
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
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @copyright XOOPS Project https://xoops.org/ |
|
15
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
16
|
|
|
* @package |
|
17
|
|
|
* @since |
|
18
|
|
|
* @author XOOPS Development Team |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use XoopsModules\Smartobject; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
25
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class Link |
|
29
|
|
|
*/ |
|
30
|
|
|
class Link extends Smartobject\BaseSmartObject |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Link constructor. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
38
|
|
|
$this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
39
|
|
|
$this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
40
|
|
|
$this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
41
|
|
|
$this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
42
|
|
|
$this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
43
|
|
|
$this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
44
|
|
|
$this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
45
|
|
|
$this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
46
|
|
|
$this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
47
|
|
|
$this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
48
|
|
|
$this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
49
|
|
|
$this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* returns a specific variable for the object in a proper format |
|
54
|
|
|
* |
|
55
|
|
|
* @access public |
|
56
|
|
|
* @param string $key key of the object's variable to be returned |
|
57
|
|
|
* @param string $format format to use for the output |
|
58
|
|
|
* @return mixed formatted value of the variable |
|
59
|
|
|
*/ |
|
60
|
|
View Code Duplication |
public function getVar($key, $format = 's') |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
if ('s' === $format && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
63
|
|
|
// return call_user_func(array($this, $key)); |
|
64
|
|
|
return $this->{$key}(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return parent::getVar($key, $format); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
public function from_uid() |
|
74
|
|
|
{ |
|
75
|
|
|
$ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
return $ret; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param bool $withContact |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function to_uid($withContact = false) |
|
85
|
|
|
{ |
|
86
|
|
|
$ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
return $ret; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return string |
|
93
|
|
|
*/ |
|
94
|
|
|
public function date() |
|
95
|
|
|
{ |
|
96
|
|
|
$ret = formatTimestamp($this->getVar('date', 'e')); |
|
97
|
|
|
|
|
98
|
|
|
return $ret; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param bool $full |
|
103
|
|
|
* @return mixed|string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function link($full = false) |
|
106
|
|
|
{ |
|
107
|
|
|
$ret = $this->getVar('link', 'e'); |
|
108
|
|
|
if ($full) { |
|
109
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
110
|
|
|
$ret = $myts->displayTarea($ret); |
|
111
|
|
|
|
|
112
|
|
|
return $ret; |
|
113
|
|
|
} else { |
|
114
|
|
|
$ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
115
|
|
|
|
|
116
|
|
|
return $ret; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getViewItemLink() |
|
124
|
|
|
{ |
|
125
|
|
|
$ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
126
|
|
|
|
|
127
|
|
|
return $ret; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
View Code Duplication |
public function getFromInfo() |
|
|
|
|
|
|
134
|
|
|
{ |
|
135
|
|
|
// check if from_uid represent a user |
|
136
|
|
|
|
|
137
|
|
|
if ($this->getVar('from_uid')) { |
|
138
|
|
|
$user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid')); |
|
139
|
|
|
if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
140
|
|
|
$user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
141
|
|
|
} |
|
142
|
|
|
} else { |
|
143
|
|
|
$user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $user; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return array |
|
151
|
|
|
*/ |
|
152
|
|
|
public function toArray() |
|
153
|
|
|
{ |
|
154
|
|
|
$ret = parent::toArray(); |
|
155
|
|
|
$ret['fromInfo'] = $this->getFromInfo(); |
|
156
|
|
|
$ret['toInfo'] = $this->getToInfo(); |
|
157
|
|
|
$ret['fullLink'] = $this->link(true); |
|
158
|
|
|
|
|
159
|
|
|
return $ret; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return string |
|
164
|
|
|
*/ |
|
165
|
|
View Code Duplication |
public function getToInfo() |
|
|
|
|
|
|
166
|
|
|
{ |
|
167
|
|
|
// check if from_uid represent a user |
|
168
|
|
|
|
|
169
|
|
|
if ($this->getVar('to_uid')) { |
|
170
|
|
|
$user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid')); |
|
171
|
|
|
if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
172
|
|
|
$user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
173
|
|
|
} |
|
174
|
|
|
} else { |
|
175
|
|
|
$user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
return $user; |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.