1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* ExtGallery 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 {@link http://xoops.org/ XOOPS Project} |
13
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
14
|
|
|
* @author Zoullou (http://www.zoullou.net) |
15
|
|
|
* @package ExtGallery |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
19
|
|
|
|
20
|
|
|
include_once __DIR__ . '/ExtgalleryPersistableObjectHandler.php'; |
21
|
|
|
include_once __DIR__ . '/extgalleryMailer.php'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class ExtgalleryPublicEcard |
25
|
|
|
*/ |
26
|
|
|
class ExtgalleryPublicEcard extends XoopsObject |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
public $externalKey = array(); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* ExtgalleryPublicEcard constructor. |
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
parent::__construct(); |
36
|
|
|
$this->initVar('ecard_id', XOBJ_DTYPE_TXTBOX, null, false); |
37
|
|
|
$this->initVar('ecard_cardid', XOBJ_DTYPE_TXTBOX, null, false); |
38
|
|
|
$this->initVar('ecard_fromname', XOBJ_DTYPE_TXTBOX, 0, false); |
39
|
|
|
$this->initVar('ecard_fromemail', XOBJ_DTYPE_EMAIL, '', false, 255); |
40
|
|
|
$this->initVar('ecard_toname', XOBJ_DTYPE_TXTBOX, '', false, 255); |
41
|
|
|
$this->initVar('ecard_toemail', XOBJ_DTYPE_EMAIL, '', false, 255); |
42
|
|
|
$this->initVar('ecard_greetings', XOBJ_DTYPE_TXTBOX, 0, false); |
43
|
|
|
$this->initVar('ecard_desc', XOBJ_DTYPE_TXTAREA, 0, false); |
44
|
|
|
$this->initVar('ecard_date', XOBJ_DTYPE_INT, 0, false); |
45
|
|
|
$this->initVar('ecard_ip', XOBJ_DTYPE_TXTBOX, 0, true); |
46
|
|
|
$this->initVar('uid', XOBJ_DTYPE_INT, 0, false); |
47
|
|
|
$this->initVar('photo_id', XOBJ_DTYPE_INT, 0, false); |
48
|
|
|
|
49
|
|
|
$this->externalKey['photo_id'] = array( |
50
|
|
|
'className' => 'publicphoto', |
51
|
|
|
'getMethodeName' => 'getPhoto', |
52
|
|
|
'keyName' => 'photo', |
53
|
|
|
'core' => false |
54
|
|
|
); |
55
|
|
|
$this->externalKey['uid'] = array( |
56
|
|
|
'className' => 'user', |
57
|
|
|
'getMethodeName' => 'get', |
58
|
|
|
'keyName' => 'user', |
59
|
|
|
'core' => true |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $key |
65
|
|
|
* |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
public function getExternalKey($key) |
69
|
|
|
{ |
70
|
|
|
return $this->externalKey[$key]; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Class ExtgalleryPublicEcardHandler |
76
|
|
|
*/ |
77
|
|
|
class ExtgalleryPublicEcardHandler extends ExtgalleryPersistableObjectHandler |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
/** |
80
|
|
|
* ExtgalleryPublicEcardHandler constructor. |
81
|
|
|
* @param XoopsDatabase $db |
82
|
|
|
*/ |
83
|
|
|
public function __construct(XoopsDatabase $db) |
84
|
|
|
{ |
85
|
|
|
parent::__construct($db, 'extgallery_publicecard', 'ExtgalleryPublicEcard', 'ecard_id'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param $data |
90
|
|
|
* |
91
|
|
|
* @return bool |
|
|
|
|
92
|
|
|
*/ |
93
|
|
|
public function createEcard($data) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$ecard = $this->create(); |
96
|
|
|
$ecard->setVars($data); |
97
|
|
|
$ecard->setVar('ecard_date', time()); |
98
|
|
|
$uid = is_a($GLOBALS['xoopsUser'], 'XoopsUser') ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
99
|
|
|
$ecard->setVar('uid', $uid); |
100
|
|
|
$ecard->setVar('ecard_cardid', md5(uniqid(mt_rand(), true))); |
101
|
|
|
|
102
|
|
|
if (!$this->insert($ecard, true)) { |
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
$this->send($ecard); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param $ecard |
110
|
|
|
*/ |
111
|
|
|
public function send(&$ecard) |
112
|
|
|
{ |
113
|
|
|
/** @var ExtgalleryPublicPhotoHandler $photoHandler */ |
114
|
|
|
$photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery'); |
115
|
|
|
$photo = $photoHandler->get($ecard->getVar('photo_id')); |
116
|
|
|
|
117
|
|
|
$mailer = new extgalleryMailer('included'); |
118
|
|
|
|
119
|
|
|
$mailer->setEcardId($ecard->getVar('ecard_cardid', 'p')); |
120
|
|
|
$mailer->setSubject(sprintf(_MD_EXTGALLERY_ECARD_TITLE, $ecard->getVar('ecard_fromname', 'p'))); |
121
|
|
|
$mailer->setToEmail($ecard->getVar('ecard_toemail', 'p')); |
122
|
|
|
$mailer->setToName($ecard->getVar('ecard_toname', 'p')); |
123
|
|
|
$mailer->setFromEmail($ecard->getVar('ecard_fromemail', 'p')); |
124
|
|
|
$mailer->setFromName($ecard->getVar('ecard_fromname', 'p')); |
125
|
|
|
$mailer->setGreetings($ecard->getVar('ecard_greetings', 'p')); |
126
|
|
|
$mailer->setDescription($ecard->getVar('ecard_desc', 'p')); |
127
|
|
|
$mailer->setPhoto($photo); |
128
|
|
|
$mailer->send(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param $ecardId |
133
|
|
|
* |
134
|
|
|
* @return bool |
135
|
|
|
*/ |
136
|
|
|
public function getEcard($ecardId) |
137
|
|
|
{ |
138
|
|
|
$criteria = new Criteria('ecard_cardid', $ecardId); |
139
|
|
|
$ecard =& $this->getObjects($criteria); |
140
|
|
|
if (count($ecard) != 1) { |
141
|
|
|
return false; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $ecard[0]; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.