|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* My Module module for xoops |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright 2020 XOOPS Project (https://xooops.org) |
|
16
|
|
|
* @license GPL 2.0 or later |
|
17
|
|
|
* @package mymodule |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
* @min_xoops 2.5.9 |
|
20
|
|
|
* @author TDM XOOPS - Email:<[email protected]> - Website:<http://xoops.org> |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
use Xmf\Request; |
|
24
|
|
|
use XoopsModules\Mymodule; |
|
25
|
|
|
use XoopsModules\Mymodule\Constants; |
|
26
|
|
|
|
|
27
|
|
|
require __DIR__ . '/header.php'; |
|
28
|
|
|
$op = Request::getString('op', 'form'); |
|
29
|
|
|
$lid = Request::getInt('lid'); |
|
30
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'mymodule_articles.tpl'; |
|
31
|
|
|
include_once XOOPS_ROOT_PATH . '/header.php'; |
|
32
|
|
|
// Define Stylesheet |
|
33
|
|
|
$GLOBALS['xoTheme']->addStylesheet( $style, null ); |
|
34
|
|
|
switch($op) { |
|
35
|
|
|
case 'form': |
|
36
|
|
|
default: |
|
37
|
|
|
// Navigation |
|
38
|
|
|
$navigation = _MA_MYMODULE_RATE; |
|
|
|
|
|
|
39
|
|
|
$GLOBALS['xoopsTpl']->assign('navigation', $navigation); |
|
40
|
|
|
// Title of page |
|
41
|
|
|
$title = _MA_MYMODULE_RATE . ' - '; |
|
42
|
|
|
$title .= $GLOBALS['xoopsModule']->name(); |
|
43
|
|
|
$GLOBALS['xoopsTpl']->assign('xoops_pagetitle', $title); |
|
44
|
|
|
// Description |
|
45
|
|
|
$GLOBALS['xoTheme']->addMeta( 'meta', 'description', strip_tags(_MA_MYMODULE_RATE)); |
|
46
|
|
|
// Form Create |
|
47
|
|
|
$articlesObj = $articlesHandler->create(); |
|
48
|
|
|
$form = $articlesObj->getFormArticles(); |
|
49
|
|
|
$GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
50
|
|
|
|
|
51
|
|
|
break; |
|
52
|
|
|
case 'save': |
|
53
|
|
|
// Security Check |
|
54
|
|
|
if($GLOBALS['xoopsSecurity']->check()) { |
|
55
|
|
|
redirect_header('articles.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
56
|
|
|
} |
|
57
|
|
|
$articlesObj = $articlesHandler->create(); |
|
58
|
|
|
$articlesObj->setVar('art_cat', Request::getInt('art_cat', 0)); |
|
59
|
|
|
$articlesObj->setVar('art_title', Request::getString('art_title', '')); |
|
60
|
|
|
$articlesObj->setVar('art_descr', Request::getString('art_descr', '')); |
|
61
|
|
|
// Set Var art_img |
|
62
|
|
|
include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
63
|
|
|
$uploader = new \XoopsMediaUploader(MYMODULE_UPLOAD_IMAGE_PATH . '/articles/', |
|
64
|
|
|
$helper->getConfig('mimetypes'), |
|
65
|
|
|
$helper->getConfig('maxsize'), null, null); |
|
66
|
|
|
if($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
|
67
|
|
|
$extension = preg_replace('/^.+\.([^.]+)$/sU', '', $_FILES['attachedfile']['name']); |
|
68
|
|
|
$imgName = str_replace(' ', '', Request::getString('art_title')) . '.' . $extension; |
|
69
|
|
|
$uploader->setPrefix($imgName); |
|
70
|
|
|
$uploader->fetchMedia($_POST['xoops_upload_file'][0]); |
|
71
|
|
|
if(!$uploader->upload()) { |
|
72
|
|
|
$errors = $uploader->getErrors(); |
|
73
|
|
|
redirect_header('javascript:history.go(-1).php', 3, $errors); |
|
74
|
|
|
} else { |
|
75
|
|
|
$articlesObj->setVar('art_img', $uploader->getSavedFileName()); |
|
76
|
|
|
} |
|
77
|
|
|
} else { |
|
78
|
|
|
$articlesObj->setVar('art_img', Request::getString('art_img')); |
|
79
|
|
|
} |
|
80
|
|
|
$articlesObj->setVar('art_online', Request::getInt('art_online', 0)); |
|
81
|
|
|
// Set Var art_file |
|
82
|
|
|
include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
83
|
|
|
$uploader = new \XoopsMediaUploader(MYMODULE_UPLOAD_FILES_PATH . '/articles/', |
|
84
|
|
|
$helper->getConfig('mimetypes'), |
|
85
|
|
|
$helper->getConfig('maxsize'), null, null); |
|
86
|
|
|
if($uploader->fetchMedia($_POST['xoops_upload_file'][1])) { |
|
87
|
|
|
$extension = preg_replace('/^.+\.([^.]+)$/sU', '', $_FILES['art_file']['name']); |
|
88
|
|
|
$imgName = str_replace(' ', '', Request::getString('art_title')) . '.' . $extension; |
|
89
|
|
|
$uploader->setPrefix($imgName); |
|
90
|
|
|
$uploader->fetchMedia($_POST['xoops_upload_file'][1]); |
|
91
|
|
|
if(!$uploader->upload()) { |
|
92
|
|
|
$errors = $uploader->getErrors(); |
|
93
|
|
|
redirect_header('javascript:history.go(-1).php', 3, $errors); |
|
94
|
|
|
} else { |
|
95
|
|
|
$articlesObj->setVar('art_file', $uploader->getSavedFileName()); |
|
96
|
|
|
} |
|
97
|
|
|
} else { |
|
98
|
|
|
$articlesObj->setVar('art_file', Request::getString('art_file')); |
|
99
|
|
|
} |
|
100
|
|
|
$articleCreated = date_create_from_format(_SHORTDATESTRING, $_POST['art_created']); |
|
101
|
|
|
$articlesObj->setVar('art_created', $articleCreated->getTimestamp()); |
|
102
|
|
|
$articlesObj->setVar('art_submitter', Request::getInt('art_submitter', 0)); |
|
103
|
|
|
// Insert Data |
|
104
|
|
|
if($articles1->insert($articlesObj)) { |
|
105
|
|
|
redirect_header('index.php', 2, _MA_MYMODULE_FORM_OK); |
|
106
|
|
|
} |
|
107
|
|
|
// Get Form Error |
|
108
|
|
|
$GLOBALS['xoopsTpl']->assign('error', $articlesObj->getHtmlErrors()); |
|
109
|
|
|
$form = $articlesObj->getFormArticles(); |
|
110
|
|
|
$GLOBALS['xoopsTpl']->assign('form', $form->display()); |
|
111
|
|
|
|
|
112
|
|
|
break; |
|
113
|
|
|
} |
|
114
|
|
|
// Breadcrumbs |
|
115
|
|
|
$xoBreadcrumbs[] = ['title' => RATE_MA_MYMODULE_]; |
|
|
|
|
|
|
116
|
|
|
require __DIR__ . '/footer.php'; |
|
117
|
|
|
|