-
Notifications
You must be signed in to change notification settings - Fork 2
/
featureContent.php
71 lines (52 loc) · 3.1 KB
/
featureContent.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
<?php
/**
* @author James Baster <[email protected]>
* @copyright City of Edinburgh Council & James Baster
* @license Open Source under the 3-clause BSD License
* @url https://github.com/City-Outdoors/City-Outdoors-Web
*/
require 'includes/src/global.php';
$currentUser = getCurrentUser();
$feature = Feature::loadByID($_GET['id']);
if (!$feature) die('Not found!');
$tpl = getSmarty($currentUser);
$tpl->assign('feature',$feature);
$tpl->assign('inCollectionTab',true);
if ($feature->getTitleItem()) $tpl->assign('inCollectionId',$feature->getTitleItem()->getCollectionId());
if ($_POST && isset($_POST['comment_body']) &&
(($currentUser && $_POST['CSFRToken'] == $_SESSION['CSFRToken']) || (!$currentUser && isset($_POST['tandc']) && $_POST['tandc'] == 'agree'))) {
if (isset($_FILES['picture']['error']) && in_array($_FILES['picture']['error'], array(UPLOAD_ERR_INI_SIZE,UPLOAD_ERR_FORM_SIZE))) {
$tpl->assign('errorMessage','Sorry, The file you uploaded was to big! Please reduce it or comment without it.');
} else if (isset($_FILES['picture']['error']) && in_array($_FILES['picture']['error'], array(UPLOAD_ERR_PARTIAL ,UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION))) {
$tpl->assign('errorMessage','Sorry, there was a problem uploading this file. Please try again or contact us for help.');
} else {
if ($currentUser && $currentUser->isAdministrator()) {
if ($_POST['post_as'] == 'anon') { // done this way around so if $_POST['post_as'] is undefined we post as user
$featureContent = $feature->newAnonymousContent($_POST['comment_body'], $_POST['post_as_anon'] , null, false, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
$featureContent->approve($currentUser); // post anon, however it as approved straight away
} else {
$featureContent = $feature->newContent($_POST['comment_body'], $currentUser , null, null, false, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
}
} else if ($currentUser) {
$featureContent = $feature->newContent($_POST['comment_body'], $currentUser , null, null, false, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
} else {
$featureContent = $feature->newAnonymousContent($_POST['comment_body'], $_POST['comment_name'] , null, false, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR']);
}
if (isset($_FILES['picture']['error']) && $_FILES['picture']['error'] === UPLOAD_ERR_OK) {
try {
$featureContent->newImage($_FILES['picture']['name'],$_FILES['picture']['tmp_name']);
} catch (Exception $e) {
$tpl->assign('errorMessage','Your comment was posted but there was a problem adding your image: '.$e->getMessage());
}
}
$tpl->display('featureContent.submitted.htm');
die();
}
}
$tpl->assign('commentBody', isset($_POST['comment_body']) ? $_POST['comment_body'] : '');
$tpl->assign('commentName', isset($_POST['comment_name']) ? $_POST['comment_name'] : '');
$featureImageSearch = new FeatureContentSearch();
$featureImageSearch->forFeature($feature);
$featureImageSearch->approvedOnly();
$tpl->assign('featureContentSearch',$featureImageSearch);
$tpl->display('featureContent.htm');