aboutsummaryrefslogtreecommitdiff
path: root/mod/file/start.php
blob: adf446cb59cceefed76611eee67539bc98581071 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
	/**
	 * Elgg file browser
	 * 
	 * @package ElggFile
	 * @author Marcus Povey
	 * @copyright Curverider Ltd 2008
	 * @link http://elgg.com/
	 */


	/**
	 * File plugin initialisation functions.
	 */
	function file_init() 
	{
		// Get config
		global $CONFIG;
				
		// Set up menu for logged in users
		if (isloggedin()) 
		{
			add_menu(elgg_echo('file'), $CONFIG->wwwroot . "pg/file/" . $_SESSION['user']->username, array(
				menu_item(sprintf(elgg_echo("file:yours"),$_SESSION['user']->name), $CONFIG->wwwroot . "pg/file/" . $_SESSION['user']->username),
				menu_item(sprintf(elgg_echo('file:friends'),$_SESSION['user']->name), $CONFIG->wwwroot . "pg/file/". $_SESSION['user']->username . "/friends/"),
				menu_item(elgg_echo('file:all'), $CONFIG->wwwroot . "pg/file/". $_SESSION['user']->username . "/world/"),
				menu_item(elgg_echo('file:upload'), $CONFIG->wwwroot . "pg/file/". $_SESSION['user']->username . "/new/")
			));
		}
		else
		{
			add_menu(elgg_echo('file'), $CONFIG->wwwroot . "pg/file/" . $_SESSION['user']->username . "/", array(
				menu_item(elgg_echo('file:all'), $CONFIG->wwwroot . "pg/file/". $_SESSION['user']->username . "/world/"),
			));
		}
		
		// Register a page handler, so we can have nice URLs
		register_page_handler('file','file_page_handler');
			
	}

	/**
	 * File page handler
	 *
	 * @param array $page Array of page elements, forwarded by the page handling mechanism
	 */
	function file_page_handler($page) {
		
		global $CONFIG;
		
		// The username should be the file we're getting
		if (isset($page[0])) {
			set_input('username',$page[0]);
		}
		
		if (isset($page[1])) 
		{
    		switch($page[1]) 
    		{
    			case "friends":  
    				include($CONFIG->pluginspath . "file/friends.php");
          		break;
   				case "world":  
   					include($CONFIG->pluginspath . "file/world.php");
          		break;
    			case "new":  
    				include($CONFIG->pluginspath . "file/upload.php");
          		break;
    		}
		}
		else
		{
			// Include the standard profile index
			include($CONFIG->pluginspath . "file/index.php");
		}
		
	}
	
	/**
	 * Draw an individual file.
	 *
	 * @param ElggFile $file
	 */
	function file_draw_file(ElggFile $file)
	{
		// Get tags
		$tags = $file->getMetaData("tag");
		if (!is_array($tags))
			$tags = array($tags);
	
		// Draw file 
		return elgg_view("file/file", array(
			"tags" => $tags,
			"title" => $file->title,
			"description" => $file->description,
			"mimetype" => $file->getMimeType()
		));
	}
	
	/**
	 * Draw a given set of objects.
	 *
	 * @param array $objects
	 */
	function file_draw(array $objects)
	{
		$body = "";
		
		foreach ($objects as $object)
			$body .= file_draw_file($object);
			
		return $body;
	}
	
	function file_draw_footer($limit, $offset)
	{
		return elgg_view("file/footer", array(
			"limit" => $limit,
			"offset" => $offset
		));
	}
	
	// Make sure test_init is called on initialisation
	register_event_handler('init','system','file_init');
	
	// Register an action
	register_action("file/upload", false, $CONFIG->pluginspath . "file/actions/upload.php");
?>