-
Notifications
You must be signed in to change notification settings - Fork 2
/
post.php
161 lines (140 loc) · 5.37 KB
/
post.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* Post page
*
* @copyright http://smartfactory.ca The SmartFactory
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @since 1.0
* @author marcan aka Marc-André Lanciault <marcan@smartfactory.ca>
* @package imblogging
*
*/
/**
* Edit a Blog Post
*
* @param object $postObj ImbloggingPost object to be edited
*/
function editpost($postObj) {
global $imblogging_post_handler, $xoTheme, $icmsTpl;
$postObj->setControl('categories', array(
'name' => 'categories',
'module' => 'imtagging',
'userside' => true));
if (!icms::$user->isAdmin()) {
$postObj->hideFieldFromForm(array(
'post_published_date',
'post_uid',
'meta_keywords',
'meta_description',
'short_url'));
}
if (!$postObj->isNew()) {
if (!$postObj->userCanEditAndDelete()) {
redirect_header($postObj->getItemLink(true), 3, _NOPERM);
}
$postObj->loadCategories();
if (!icms::$user->isAdmin()) {
$postObj->hideFieldFromForm(array(
'post_published_date',
'post_uid',
'meta_keywords',
'meta_description',
'short_url'));
}
$sform = $postObj->getSecureForm(_MD_IMBLOGGING_POST_EDIT, 'addpost');
$sform->assign($icmsTpl, 'imblogging_postform');
$icmsTpl->assign('imblogging_category_path', $postObj->getVar('post_title') . ' > ' . _EDIT);
} else {
if (!$imblogging_post_handler->userCanSubmit()) {
redirect_header(IMBLOGGING_URL, 3, _NOPERM);
}
$postObj->setVar('post_uid', icms::$user->getVar("uid"));
$postObj->setVar('post_published_date', time());
if (!icms::$user->isAdmin()) {
$postObj->hideFieldFromForm(array(
'post_published_date',
'post_uid',
'meta_keywords',
'meta_description',
'short_url'));
}
$sform = $postObj->getSecureForm(_MD_IMBLOGGING_POST_SUBMIT, 'addpost');
$sform->assign($icmsTpl, 'imblogging_postform');
$icmsTpl->assign('imblogging_category_path', _SUBMIT);
}
$xoTheme->addStylesheet(ICMS_MODULES_URL . '/imtagging/module' . ((defined("_ADM_USE_RTL") && _ADM_USE_RTL) ? '_rtl' : '') . '.css');
}
include_once 'header.php';
$xoopsOption['template_main'] = 'imblogging_post.html';
include_once ICMS_ROOT_PATH . '/header.php';
$imblogging_post_handler = icms_getModuleHandler('post', $moddir, 'imblogging');
/* Use a naming convention that indicates the source of the content of the variable */
$clean_op = '';
if (isset($_GET['op'])) $clean_op = $_GET['op'];
if (isset($_POST['op'])) $clean_op = $_POST['op'];
/* Again, use a naming convention that indicates the source of the content of the variable */
$clean_post_id = isset($_GET['post_id']) ? (int) $_GET['post_id'] : 0;
/*
* Create a whitelist of valid values, be sure to use appropriate types for each value
* Be sure to include a value for no parameter, if you have a default condition
*/
$valid_op = array(
'mod',
'addpost',
'del',
'');
/* Only proceed if the supplied operation is a valid operation */
if (in_array($clean_op, $valid_op, true)) {
switch ($clean_op) {
case "mod":
$postObj = $imblogging_post_handler->get($clean_post_id);
if ($clean_post_id > 0 && $postObj->isNew()) {
redirect_header(icms_getPreviousPage('index.php'), 3, _NOPERM);
}
editpost($postObj);
break;
case "addpost":
if (!icms::$security->check()) {
redirect_header(icms_getPreviousPage('index.php'), 3, _MD_IMBLOGGING_SECURITY_CHECK_FAILED . implode('<br />', $xoopsSecurity->getErrors()));
}
$controller = new icms_ipf_Controller($imblogging_post_handler);
/* need to flush the template option to prevent error on redirect */
$xoopsOption['template_main'] = null;
$controller->storeFromDefaultForm(_MD_IMBLOGGING_POST_CREATED, _MD_IMBLOGGING_POST_MODIFIED);
break;
case "del":
$postObj = $imblogging_post_handler->get($clean_post_id);
if (!$postObj->userCanEditAndDelete()) {
redirect_header($postObj->getItemLink(true), 3, _NOPERM);
}
if (isset($_POST['confirm'])) {
if (!icms::$security->check()) {
redirect_header($impresscms->urls['previouspage'], 3, _MD_IMBLOGGING_SECURITY_CHECK_FAILED . implode('<br />', $xoopsSecurity->getErrors()));
}
}
$controller = new icms_ipf_Controller($imblogging_post_handler);
/* need to flush the template option to prevent error on redirect */
$xoopsOption['template_main'] = null;
$controller->handleObjectDeletionFromUserSide();
$icmsTpl->assign('imblogging_category_path', $postObj->getVar('post_title') . ' > ' . _DELETE);
break;
default:
$postArray = $imblogging_post_handler->getPost($clean_post_id);
$imblogging_post_handler->updateCounter($clean_post_id);
$icmsTpl->assign('imblogging_post', $postArray);
$icmsTpl->assign('imblogging_category_path', $postArray['post_title']);
$icmsTpl->assign('imblogging_showSubmitLink', true);
$icmsTpl->assign('imblogging_rss_url', IMBLOGGING_URL . 'rss.php');
$icmsTpl->assign('imblogging_rss_info', _MD_IMBLOGGING_RSS_GLOBAL);
if (icms::$module->config['com_rule'] && $postArray['post_cancomment']) {
$icmsTpl->assign('imblogging_post_comment', true);
include_once ICMS_ROOT_PATH . '/include/comment_view.php';
}
/* Generating meta information for this page */
$icms_metagen = new icms_ipf_Metagen($postArray['post_title'], $postArray['meta_keywords'], $postArray['meta_description']);
$icms_metagen->createMetaTags();
break;
}
}
$icmsTpl->assign('imblogging_module_home', icms_getModuleName(true, true));
include_once 'footer.php';