-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpublic-sendecard.php
138 lines (116 loc) · 6.02 KB
/
public-sendecard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* ExtGallery User area
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright {@link https://xoops.org/ XOOPS Project}
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Zoullou (http://www.zoullou.net)
* @package ExtGallery
*/
use XoopsModules\Extgallery;
require_once __DIR__ . '/header.php';
//require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/publicPerm.php';
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
if (\Xmf\Request::hasVar('id', 'GET')) {
$photoId = \Xmf\Request::getInt('id', 0, 'GET');
} else {
$photoId = \Xmf\Request::getInt('photo_id', 0, 'POST');
}
if (\Xmf\Request::hasVar('step', 'POST')) {
$step = $_POST['step'];
} else {
$step = 'default';
}
/** @var Extgallery\PublicPhotoHandler $photoHandler */
$photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
$photo = $photoHandler->getPhoto($photoId);
$permHandler = Extgallery\PublicPermHandler::getInstance();
if (!$permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_ecard', $photo->getVar('cat_id'))) {
redirect_header('index.php', 3, _MD_EXTGALLERY_NOPERM);
}
/** @var xos_opal_Theme $xoTheme */
switch ($step) {
case 'send':
// require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/php-captcha.inc.php';
// Enable captcha only if GD is Used
if ('gd' === $helper->getConfig('graphic_lib')) {
if (!Extgallery\PhpCaptcha::Validate($_POST['captcha'])) {
redirect_header('public-photo.php?photoId=' . $photoId . '#photoNav', 3, _MD_EXTGALLERY_CAPTCHA_ERROR);
}
}
/** @var Extgallery\PublicEcardHandler $ecardHandler */
$ecardHandler = Extgallery\Helper::getInstance()->getHandler('PublicEcard');
/** @var Extgallery\PublicPhotoHandler $photoHandler */
$photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
if (\Xmf\Request::hasVar('HTTP_X_FORWARDED_FOR', 'SERVER')) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (\Xmf\Request::hasVar('HTTP_CLIENT_IP', 'SERVER')) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$data = [
'ecard_fromname' => $_POST['ecard_fromname'],
'ecard_fromemail' => $_POST['ecard_fromemail'],
'ecard_toname' => $_POST['ecard_toname'],
'ecard_toemail' => $_POST['ecard_toemail'],
'ecard_greetings' => $_POST['ecard_greetings'],
'ecard_desc' => $_POST['ecard_desc'],
'ecard_ip' => $ip,
'photo_id' => $photoId,
];
$ecardHandler->createEcard($data);
$photoHandler->updateEcard($photoId);
redirect_header('public-photo.php?photoId=' . $photoId . '#photoNav', 3, _MD_EXTGALLERY_ECARD_SENT);
break;
case 'default':
default:
$GLOBALS['xoopsOption']['template_main'] = 'extgallery_public-sendecard.tpl';
require_once XOOPS_ROOT_PATH . '/header.php';
if ('' != $photo->getVar('photo_serveur')) {
$photoUrl = $photo->getVar('photo_serveur') . 'thumb_' . $photo->getVar('photo_name');
} else {
$photoUrl = XOOPS_URL . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name');
}
$fromName = is_a($GLOBALS['xoopsUser'], 'XoopsUser') ? $GLOBALS['xoopsUser']->getVar('uname') : '';
$fromEmail = is_a($GLOBALS['xoopsUser'], 'XoopsUser') ? $GLOBALS['xoopsUser']->getVar('email') : '';
$form = new \XoopsThemeForm(_MD_EXTGALLERY_SEND_ECARD, 'send_ecard', 'public-sendecard.php', 'post', true);
$form->addElement(new \XoopsFormText(_MD_EXTGALLERY_FROM_NAME, 'ecard_fromname', '70', '255', $fromName), false);
$form->addElement(new \XoopsFormText(_MD_EXTGALLERY_FROM_EMAIL, 'ecard_fromemail', '70', '255', $fromEmail), false);
$form->addElement(new \XoopsFormText(_MD_EXTGALLERY_TO_NAME, 'ecard_toname', '70', '255', ''), false);
$form->addElement(new \XoopsFormText(_MD_EXTGALLERY_TO_EMAIL, 'ecard_toemail', '70', '255', ''), false);
$form->addElement(new \XoopsFormText(_MD_EXTGALLERY_GREETINGS, 'ecard_greetings', '110', '255', ''), false);
$form->addElement(new \XoopsFormTextArea(_MD_EXTGALLERY_DESC, 'ecard_desc', ''), false);
// Enable captcha only if GD is Used
if ('gd' === $helper->getConfig('graphic_lib')) {
$form->addElement(new \XoopsFormText(_MD_EXTGALLERY_SECURITY, 'captcha', '10', '5', ''), false);
}
$form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
$form->addElement(new \XoopsFormHidden('photo_id', $photoId));
$form->addElement(new \XoopsFormHidden('step', 'send'));
$form->assign($xoopsTpl);
$xoopsTpl->assign('photo', $photoUrl);
$xoopsTpl->assign('xoops_pagetitle', 'Send ' . $photo->getVar('photo_desc') . ' to eCard');
$xoTheme->addMeta('meta', 'description', $photo->getVar('photo_desc'));
$rel = 'alternate';
$attributes['rel'] = $rel;
$attributes['type'] = 'application/rss+xml';
$attributes['title'] = _MD_EXTGALLERY_RSS;
$attributes['href'] = XOOPS_URL . '/modules/extgallery/public-rss.php';
$xoTheme->addMeta('link', $rel, $attributes);
$xoTheme->addStylesheet('modules/extgallery/assets/css/style.css');
$lang = [
'to' => _MD_EXTGALLERY_TO,
'from' => _MD_EXTGALLERY_FROM,
];
$xoopsTpl->assign('lang', $lang);
require_once XOOPS_ROOT_PATH . '/footer.php';
break;
}