tiki-edit_image.php 4.14 KB
Newer Older
lrargerich's avatar
lrargerich committed
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
6
// $Id$
7 8 9 10

require_once ('tiki-setup.php');

include_once ("lib/imagegals/imagegallib.php");
lrargerich's avatar
lrargerich committed
11

12
if ($prefs['feature_categories'] == 'y') {
13 14 15 16 17 18
	global $categlib;
	if (!is_object($categlib)) {
		include_once('lib/categories/categlib.php');
	}
}

19
$access->check_feature('feature_galleries');
lrargerich's avatar
lrargerich committed
20 21 22

// Sanity anyone?
if (!$_REQUEST['edit'] or !$_REQUEST['galleryId']) {
23 24
	$smarty->assign('msg', tra("Invalid request to edit an image"));

25
	$smarty->display("error.tpl");
26
	die;
lrargerich's avatar
lrargerich committed
27 28
}

29 30
$tikilib->get_perm_object( $_REQUEST['galleryId'], 'image gallery' );

31
$access->check_permission('tiki_p_upload_images');
lrargerich's avatar
lrargerich committed
32

33
$imageId=$_REQUEST['edit'];
lrargerich's avatar
lrargerich committed
34
$foo = parse_url($_SERVER["REQUEST_URI"]);
35 36
$foo1 = str_replace("tiki-edit_image", "tiki-browse_image", $foo["path"]);
$foo2 = str_replace("tiki-edit_image", "show_image", $foo["path"]);
37 38
$smarty->assign('url_browse', $tikilib->httpPrefix(). $foo1);
$smarty->assign('url_show', $tikilib->httpPrefix(). $foo2);
lrargerich's avatar
lrargerich committed
39

40 41 42 43 44 45 46 47
$gal_info = $imagegallib->get_gallery($_REQUEST["galleryId"]);

if (!isset($_REQUEST['sort_mode'])) {
	$sort_mode = $gal_info['sortorder'].'_'.$gal_info['sortdirection'];
} else $sort_mode = $_REQUEST['sort_mode'];
$smarty->assign('sort_mode', $sort_mode);

if (isset($_REQUEST["editimage"]) || isset($_REQUEST["editimage_andgonext"])) {
48
	check_ticket('edit-image');
49

50
	$access->check_permission('tiki_p_upload_images');
51 52 53 54 55 56 57 58 59

	if ($gal_info["thumbSizeX"] == 0)
		$gal_info["thumbSizeX"] = 80;

	if ($gal_info["thumbSizeY"] == 0)
		$gal_info["thumbSizeY"] = 80;

	// Check the user to be admin or owner or the gallery is public
	if ($tiki_p_admin_galleries != 'y' && (!$user || $user != $gal_info["user"]) && $gal_info["public"] != 'y') {
60
		$smarty->assign('errortype', 401);
61
		$smarty->assign('msg', tra("You have permission to edit images but not in this gallery"));
62

63
		$smarty->display("error.tpl");
64 65 66 67 68
		die;
	}

	$error_msg = '';

69
	// Avoid warnings
70
	if ($prefs['feature_maps'] != 'y') {
71 72 73 74
	    $_REQUEST['lat'] = '';
	    $_REQUEST['lon'] = '';
	}

75
	if (!empty($_FILES['userfile']) && !empty($_FILES['userfile']['name'])) {
76 77
	  if ((!empty($prefs['gal_match_regex']) && !preg_match('/'.$prefs['gal_match_regex'].'/', $_FILES['userfile']['name'], $reqs))
		  || (!empty($prefs['gal_nmatch_regex']) && preg_match('/'.$prefs['gal_nmatch_regex'].'/', $_FILES['userfile']['name'], $reqs))) {
78 79 80 81 82 83 84
			$smarty->assign('msg', tra('Invalid imagename (using filters for filenames)'));
			$smarty->display('error.tpl');
			die;
		}
	}

	if ($imagegallib->edit_image($imageId, $_REQUEST['name'], $_REQUEST['description'],$_REQUEST['lat'],$_REQUEST['lon'], $_FILES['userfile'])) {
85
		$smarty->assign('show', 'y');
86
		$cat_type = 'image';
87
		$cat_objid = $imageId;
88
		$cat_desc = $_REQUEST['description'];
89 90
		$cat_lat = $_REQUEST['lat'];
		$cat_lon = $_REQUEST['lon'];
91 92 93 94
		$cat_name = $_REQUEST['name'];
		$cat_href = "tiki-browse_image.php?imageId=".$cat_objid;
		include_once("categorize.php");

95 96 97 98 99
		if (isset($_REQUEST["editimage_andgonext"])) {
		        $prevnext = $imagegallib->get_prev_and_next_image($sort_mode, NULL, $imageId, $_REQUEST["galleryId"]);
		        if ($prevnext['next']) $imageId=$prevnext['next'];
		}

100 101 102
	} else {
		$smarty->assign('msg', tra("Failed to edit the image"));

103
		$smarty->display("error.tpl");
104 105
		die;
	}
lrargerich's avatar
lrargerich committed
106 107
}

108 109
$info = $imagegallib->get_image($imageId);
$smarty->assign_by_ref('imageId', $imageId);
110 111 112
$smarty->assign_by_ref('galleryId', $info['galleryId']);
$smarty->assign_by_ref('name', $info['name']);
$smarty->assign_by_ref('description', $info['description']);
113 114
$smarty->assign_by_ref('lat', $info['lat']);
$smarty->assign_by_ref('lon', $info['lon']);
115 116
$smarty->assign_by_ref('filename', $info['filename']);
$smarty->assign_by_ref('gal_info', $gal_info);
117 118

$cat_type = 'image';
119
$cat_objid = $imageId;
120 121
include_once ("categorize_list.php");

122
ask_ticket('edit-image');
lrargerich's avatar
lrargerich committed
123

124 125 126
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');

lrargerich's avatar
lrargerich committed
127
// Display the template
128
$smarty->assign('mid', 'tiki-edit_image.tpl');
129
$smarty->display("tiki.tpl");