1<?php
2/*
3 * Gallery - a web based photo album viewer and editor
4 * Copyright (C) 2000-2008 Bharat Mediratta
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21/**
22 * Generate JavaScript for deleting item
23 * @package GalleryCore
24 * @subpackage UserInterface
25 * @author Felix Rabinvoich <felix@rabinovich.org> thanks to mindless for guidance
26 * @version $Revision: 18144 $
27 */
28class ItemDeleteJsView extends GalleryView {
29    /**
30     * @see GalleryView::isImmediate
31     */
32    function isImmediate() {
33	return true;
34    }
35
36    /**
37     * @see GalleryView::isAllowedInEmbedOnly
38     */
39    function isAllowedInEmbedOnly() {
40	return true;
41    }
42
43    /**
44     * @see GalleryView::shouldSaveSession
45     */
46    function shouldSaveSession() {
47	return false;
48    }
49
50    /**
51     * @see GalleryView::renderImmediate
52     */
53    function renderImmediate($status, $error) {
54	GalleryCoreApi::requireOnce('modules/core/classes/GalleryTemplate.class');
55	$template = new GalleryTemplate(dirname(dirname(dirname(__FILE__))));
56	$template->setVariable('l10Domain', 'modules_core');
57
58	if (function_exists('getallheaders')) {
59	    $headers = getallheaders();
60	    if (isset($headers['If-modified-since'])) {
61		$headers['If-Modified-Since'] = $headers['If-modified-since'];
62	    }
63	    if (isset($headers['If-Modified-Since']) &&
64		    ($when = strtotime($headers['If-Modified-Since'])) > 0) {
65		/* Check date on language files to determine if we should resend the strings. */
66		/**
67		 * TODO: Create an API to check whether the translation file has changed
68		 *       and refactor the hardcoded .mo file locations.
69		 */
70		global $gallery;
71		$platform =& $gallery->getPlatform();
72		list ($ret, $lang) = $gallery->getActiveLanguageCode();
73		if ($ret) {
74		    return $ret;
75		}
76		$inc = $gallery->getConfig('data.gallery.base')
77		    . "locale/$lang/LC_MESSAGES/modules_core.mo";
78		if ($platform->file_exists($inc)) {
79		    if (($stat = $platform->stat($inc)) && $stat[9] > $when) {
80			$new = true;
81		    }
82		} else {
83		    $lang = substr($lang, 0, 2);
84		    $inc = $gallery->getConfig('data.gallery.base')
85			. "locale/$lang/LC_MESSAGES/modules_core.mo";
86		    if ($platform->file_exists($inc) && ($stat = $platform->stat($inc))
87			&& $stat[9] > $when) {
88			$new = true;
89		    }
90		}
91		if (!isset($new)) {
92		    header('HTTP/1.0 304 Not Modified');
93		    return null;
94		}
95	    }
96	}
97
98	header('Content-type: text/javascript; charset=UTF-8');
99	header('Last-Modified: ' . GalleryUtilities::getHttpDate());
100	header('Expires: ' . GalleryUtilities::getHttpDate(time() + 2592000));
101
102	$ret = $template->display('modules/core/templates/ItemDeleteJs.tpl');
103	return $ret;
104    }
105}
106?>
107