1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11// This script will send a 1x1 transparent gif image, close connection and reindex the file corresponding to the id url argument
12// The goal is to process reindexation in a background job for which the user won't have to wait
13//
14// This trick has been found on the official php manual page comments of the register_shutdown_function function
15
16require_once('tiki-setup.php');
17
18// Reindex the file for search
19if (($id = (int)$_GET['id']) > 0) {
20	// Check feature
21	if ($prefs['feature_file_galleries'] == 'y'
22		&& $prefs['feature_search'] == 'y'
23		&& $prefs['feature_search_fulltext'] != 'y'
24		&& $prefs['search_refresh_index_mode'] == 'normal'
25		&& $prefs['fgal_asynchronous_indexing'] == 'y'
26	) {
27		$filegallib = TikiLib::lib('filegal');
28		require_once('lib/search/refresh-functions.php');
29
30		$info = $filegallib->get_file_info($id);
31
32		if ($info['galleryId'] > 0) {
33			$gal_info = $filegallib->get_file_gallery($info['galleryId']);
34
35			// Check perms
36			$tikilib->get_perm_object($info['galleryId'], 'file gallery', $gal_info, true);
37
38			if ($tiki_p_admin_file_galleries == 'y'
39				|| ( ( empty($fileInfo['lockedby']) || $fileInfo['lockedby'] == $user ) && $tiki_p_edit_gallery_file == 'y' )
40			) { // must be the owner or the locker or have the perms
41				error_reporting(0);
42				ignore_user_abort(true);
43				session_write_close(); // close the session to allow the user to continue browsing
44				register_shutdown_function('refresh_index', 'files', $id);
45			}
46		}
47	}
48}
49
50// Display the 1x1 transparent gif image
51header('Cache-Control: no-cache');
52header('Content-type: image/gif');
53header('Content-length: 85');
54print base64_decode(
55	'R0lGODlhAQABALMAAAAAAIAAAACAA' .
56	'ICAAAAAgIAAgACAgMDAwICAgP8AAA' .
57	'D/AP//AAAA//8A/wD//wBiZCH5BAE' .
58	'AAA8ALAAAAAABAAEAAAQC8EUAOw=='
59);
60flush();
61exit;
62