1<?php
2/**
3 * projects Action Plugin: hajacking the modification of metadata
4 *
5 * @author     Junling Ma <junlingm@gmail.com>
6 */
7
8require_once(dirname(__FILE__).'/../lib/project.php');
9require_once DOKU_PLUGIN.'action.php';
10
11class action_plugin_projects_metadata extends DokuWiki_Action_Plugin {
12
13    function getInfo(){
14		return array(
15		 'author' => 'Junling Ma',
16		 'email'  => 'junlingm@gmail.com',
17		 'date'   => '2010-12-15',
18		 'name'   => 'Projects',
19		 'desc'   => 'Manage the projects media files',
20		 'url'    => 'http://www.math.uvic.ca/~jma'
21		 );
22	}
23
24    /**
25     * Register its handlers with the DokuWiki's event controller
26     */
27    function register(&$controller) {
28        $controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this,
29                                   'saved');
30    }
31
32	// the matedata has been rendered
33    function saved(&$event, $param) {
34		global $ID;
35		global $PROJECTS_REMAKE;
36		if (auth_quickaclcheck($ID) <= AUTH_READ) return;
37		$project = Project::project();
38		if ($project == NULL) return;
39		$file = $event->data['current']['ProjectFile'];
40		$name = noNS($ID);
41		if ($file == NULL) {
42			// check whether the file is deleted
43			if ($project->file($name) == NULL) return;
44			// it was int he project
45	    	if (!$project->remove_file($name)) {
46				msg('Other users are currently updating the project. Please save this page later.');
47				$evemt->data['current']['internal']['cache'] = false;
48			}
49			return;
50		}
51		if (!$project->update_file($file)) {
52			msg('Other users are currently updating the project. Please save this page later.');
53			$evemt->data['current']['internal']['cache'] = false;
54		}
55	}
56
57}
58
59?>