1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Extgallery; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* ExtGallery Class Manager |
7
|
|
|
* |
8
|
|
|
* You may not change or alter any portion of this comment or credits |
9
|
|
|
* of supporting developers from this source code or any supporting source code |
10
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
11
|
|
|
* This program is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
14
|
|
|
* |
15
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
16
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
17
|
|
|
* @author Zoullou (http://www.zoullou.net) |
18
|
|
|
* @package ExtGallery |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Criteria; |
22
|
|
|
use XoopsDatabase; |
23
|
|
|
use XoopsModules\Extgallery; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
use function md5; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Class Extgallery\PublicEcardHandler |
37
|
|
|
*/ |
38
|
|
|
class PublicEcardHandler extends Extgallery\PersistableObjectHandler |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* Extgallery\PublicEcardHandler constructor. |
42
|
|
|
* @param \XoopsDatabase|null $db |
43
|
|
|
*/ |
44
|
|
|
public function __construct(XoopsDatabase $db = null) |
45
|
|
|
{ |
46
|
|
|
parent::__construct($db, 'extgallery_publicecard', Extgallery\PublicEcard::class, 'ecard_id'); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param $data |
51
|
|
|
* |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
|
|
public function createEcard($data) |
55
|
|
|
{ |
56
|
|
|
$ecard = $this->create(); |
57
|
|
|
$ecard->setVars($data); |
58
|
|
|
$ecard->setVar('ecard_date', \time()); |
59
|
|
|
$uid = \is_a($GLOBALS['xoopsUser'], 'XoopsUser') ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
60
|
|
|
$ecard->setVar('uid', $uid); |
61
|
|
|
$ecard->setVar('ecard_cardid', md5(\uniqid(\mt_rand(), true))); |
62
|
|
|
|
63
|
|
|
if (!$this->insert($ecard, true)) { |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
$this->send($ecard); |
67
|
|
|
|
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $ecard |
73
|
|
|
*/ |
74
|
|
|
public function send($ecard) |
75
|
|
|
{ |
76
|
|
|
/** @var Extgallery\PublicPhotoHandler $photoHandler */ |
77
|
|
|
$photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto'); |
78
|
|
|
$photo = $photoHandler->get($ecard->getVar('photo_id')); |
79
|
|
|
|
80
|
|
|
$mailer = new Extgallery\Mailer('included'); |
81
|
|
|
|
82
|
|
|
$mailer->setEcardId($ecard->getVar('ecard_cardid', 'p')); |
83
|
|
|
$mailer->setSubject(\sprintf(\_MD_EXTGALLERY_ECARD_TITLE, $ecard->getVar('ecard_fromname', 'p'))); |
84
|
|
|
$mailer->setToEmail($ecard->getVar('ecard_toemail', 'p')); |
85
|
|
|
$mailer->setToName($ecard->getVar('ecard_toname', 'p')); |
86
|
|
|
$mailer->setFromEmail($ecard->getVar('ecard_fromemail', 'p')); |
87
|
|
|
$mailer->setFromName($ecard->getVar('ecard_fromname', 'p')); |
88
|
|
|
$mailer->setGreetings($ecard->getVar('ecard_greetings', 'p')); |
89
|
|
|
$mailer->setDescription($ecard->getVar('ecard_desc', 'p')); |
90
|
|
|
$mailer->setPhoto($photo); |
91
|
|
|
$mailer->send(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param $ecardId |
96
|
|
|
* |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
|
|
public function getEcard($ecardId) |
100
|
|
|
{ |
101
|
|
|
$criteria = new Criteria('ecard_cardid', $ecardId); |
102
|
|
|
$ecard = $this->getObjects($criteria); |
103
|
|
|
if (1 != \count($ecard)) { |
104
|
|
|
return false; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $ecard[0]; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|