aboutsummaryrefslogtreecommitdiff
path: root/mod/file/start.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/file/start.php')
-rw-r--r--mod/file/start.php515
1 files changed, 264 insertions, 251 deletions
diff --git a/mod/file/start.php b/mod/file/start.php
index 3376befeb..64533616c 100644
--- a/mod/file/start.php
+++ b/mod/file/start.php
@@ -1,148 +1,163 @@
<?php
- /**
- * Elgg file browser
- *
- * @package ElggFile
- */
+/**
+ * Elgg file browser
+ *
+ * @package ElggFile
+ */
- /**
- * Override the ElggFile so that
- */
- class FilePluginFile extends ElggFile {
- protected function initialise_attributes() {
- parent::initialise_attributes();
+/**
+ * Override the ElggFile so that
+ */
+class FilePluginFile extends ElggFile {
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
- $this->attributes['subtype'] = "file";
- }
+ $this->attributes['subtype'] = "file";
+ }
- public function __construct($guid = null) {
- parent::__construct($guid);
- }
+ public function __construct($guid = null) {
+ parent::__construct($guid);
}
+}
- /**
- * File plugin initialisation functions.
- */
- function file_init() {
- global $CONFIG;
+/**
+ * File plugin initialisation functions.
+ */
+function file_init() {
+ global $CONFIG;
- // Set up menu (tools dropdown)
- $item = new ElggMenuItem('file', elgg_echo('file'), 'pg/file');
- elgg_register_menu_item('site', $item);
+ // Site navigation
+ $item = new ElggMenuItem('file', elgg_echo('file'), 'pg/file/all');
+ elgg_register_menu_item('site', $item);
- // Extend CSS
- elgg_extend_view('css/screen', 'file/css');
+ // Extend CSS
+ elgg_extend_view('css/screen', 'file/css');
- // extend group main page
- elgg_extend_view('groups/tool_latest','file/groupprofile_files');
+ // extend group main page
+ elgg_extend_view('groups/tool_latest', 'file/groupprofile_files');
- // Register a page handler, so we can have nice URLs
- register_page_handler('file','file_page_handler');
+ // Register a page handler, so we can have nice URLs
+ register_page_handler('file', 'file_page_handler');
- // Add a new file widget
- elgg_register_widget_type('filerepo',elgg_echo("file"),elgg_echo("file:widget:description"));
+ // Add a new file widget
+ elgg_register_widget_type('filerepo', elgg_echo("file"), elgg_echo("file:widget:description"));
- // Register a URL handler for files
- register_entity_url_handler('file_url','object','file');
+ // Register a URL handler for files
+ register_entity_url_handler('file_url', 'object', 'file');
- // Register granular notification for this object type
- if (is_callable('register_notification_object')) {
- register_notification_object('object', 'file', elgg_echo('file:newupload'));
- }
+ // Register granular notification for this object type
+ register_notification_object('object', 'file', elgg_echo('file:newupload'));
- // Listen to notification events and supply a more useful message
- elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'file_notify_message');
+ // Listen to notification events and supply a more useful message
+ elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'file_notify_message');
- // add the group files tool option
- add_group_tool_option('file',elgg_echo('groups:enablefiles'),true);
+ // add the group files tool option
+ add_group_tool_option('file', elgg_echo('groups:enablefiles'), true);
- // Register entity type
- register_entity_type('object','file');
+ // Register entity type
+ register_entity_type('object', 'file');
- elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'file_owner_block_menu');
+ elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'file_owner_block_menu');
+
+ // embed support
+ elgg_register_plugin_hook_handler('embed_get_sections', 'all', 'file_embed_get_sections');
+ elgg_register_plugin_hook_handler('embed_get_items', 'file', 'file_embed_get_items');
+ elgg_register_plugin_hook_handler('embed_get_upload_sections', 'all', 'file_embed_get_upload_sections');
+}
- // embed support
- elgg_register_plugin_hook_handler('embed_get_sections', 'all', 'file_embed_get_sections');
- elgg_register_plugin_hook_handler('embed_get_items', 'file', 'file_embed_get_items');
- elgg_register_plugin_hook_handler('embed_get_upload_sections', 'all', 'file_embed_get_upload_sections');
+/**
+ * Dispatches file pages.
+ * URLs take the form of
+ * All files: pg/file/all
+ * User's files: pg/file/owner/<username>
+ * Friends' files: pg/file/friends/<username>
+ * View file: pg/file/view/<guid>/<title>
+ * New file: pg/file/new/<guid>
+ * Edit file: pg/file/edit/<guid>/<revision>
+ * Group files: pg/file/group/<guid>/owner
+ *
+ * Title is ignored
+ *
+ * @param array $page
+ * @return NULL
+ */
+function file_page_handler($page) {
+ if (!isset($page[0])) {
+ $page[0] = 'all';
}
- /**
- * File page handler
- *
- * @param array $page Array of page elements, forwarded by the page handling mechanism
- */
- function file_page_handler($page) {
+ $file_dir = elgg_get_plugin_path() . 'file';
+
+ $page_type = $page[0];
+ switch ($page_type) {
+ case 'owner':
+ set_input('username', $page[1]);
+ include "$file_dir/index.php";
+ break;
+ case 'friends':
+ set_input('username', $page[1]);
+ include "$file_dir/friends.php";
+ break;
+ case 'view':
+ set_input('guid', $page[1]);
+ include "$file_dir/view.php";
+ break;
+ case 'new':
+ set_input('guid', $page[1]);
+ include "$file_dir/upload.php";
+ break;
+ case 'edit':
+ set_input('guid', $page[1]);
+ include "$file_dir/edit.php";
+ break;
+ case 'group':
+ break;
+ case 'all':
+ default:
+ include "$file_dir/world.php";
+ break;
+ }
+}
+/**
+ * Returns a more meaningful message
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $entity_type
+ * @param unknown_type $returnvalue
+ * @param unknown_type $params
+*/
+function file_notify_message($hook, $entity_type, $returnvalue, $params) {
+ $entity = $params['entity'];
+ $to_entity = $params['to_entity'];
+ $method = $params['method'];
+ if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'file'))
+ {
+ $descr = $entity->description;
+ $title = $entity->title;
global $CONFIG;
-
- // The username should be the file we're getting
- if (isset($page[0])) {
- set_input('username',$page[0]);
+ $url = elgg_get_site_url() . "pg/view/" . $entity->guid;
+ if ($method == 'sms') {
+ $owner = $entity->getOwnerEntity();
+ return $owner->name . ' ' . elgg_echo("file:via") . ': ' . $url . ' (' . $title . ')';
}
-
- if (isset($page[1])) {
- switch($page[1]) {
- case "read":
- set_input('guid',$page[2]);
- include(dirname(dirname(dirname(__FILE__))) . "/pages/entities/index.php");
- break;
- 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");
+ if ($method == 'email') {
+ $owner = $entity->getOwnerEntity();
+ return $owner->name . ' ' . elgg_echo("file:via") . ': ' . $entity->title . "\n\n" . $descr . "\n\n" . $entity->getURL();
}
-
- }
-
- /**
- * Returns a more meaningful message
- *
- * @param unknown_type $hook
- * @param unknown_type $entity_type
- * @param unknown_type $returnvalue
- * @param unknown_type $params
- */
- function file_notify_message($hook, $entity_type, $returnvalue, $params) {
- $entity = $params['entity'];
- $to_entity = $params['to_entity'];
- $method = $params['method'];
- if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'file'))
- {
- $descr = $entity->description;
- $title = $entity->title;
- global $CONFIG;
- $url = elgg_get_site_url() . "pg/view/" . $entity->guid;
- if ($method == 'sms') {
- $owner = $entity->getOwnerEntity();
- return $owner->name . ' ' . elgg_echo("file:via") . ': ' . $url . ' (' . $title . ')';
- }
- if ($method == 'email') {
- $owner = $entity->getOwnerEntity();
- return $owner->name . ' ' . elgg_echo("file:via") . ': ' . $entity->title . "\n\n" . $descr . "\n\n" . $entity->getURL();
- }
- if ($method == 'web') {
- $owner = $entity->getOwnerEntity();
- return $owner->name . ' ' . elgg_echo("file:via") . ': ' . $entity->title . "\n\n" . $descr . "\n\n" . $entity->getURL();
- }
- }
- return null;
+ if ($method == 'web') {
+ $owner = $entity->getOwnerEntity();
+ return $owner->name . ' ' . elgg_echo("file:via") . ': ' . $entity->title . "\n\n" . $descr . "\n\n" . $entity->getURL();
}
+ }
+ return null;
+}
/**
- * Add a menu item to the user ownerblock
- */
+* Add a menu item to the user ownerblock
+*/
function file_owner_block_menu($hook, $type, $return, $params) {
if (elgg_instanceof($params['entity'], 'user')) {
$url = "pg/file/owner/{$params['entity']->username}";
@@ -159,164 +174,162 @@ function file_owner_block_menu($hook, $type, $return, $params) {
return $return;
}
- /**
- * Returns an overall file type from the mimetype
- *
- * @param string $mimetype The MIME type
- * @return string The overall type
- */
- function get_general_file_type($mimetype) {
-
- switch($mimetype) {
- case "application/msword":
- return "document";
- break;
- case "application/pdf":
- return "document";
- break;
- }
+/**
+ * Returns an overall file type from the mimetype
+ *
+ * @param string $mimetype The MIME type
+ * @return string The overall type
+ */
+function get_general_file_type($mimetype) {
- if (substr_count($mimetype,'text/'))
+ switch($mimetype) {
+ case "application/msword":
+ return "document";
+ break;
+ case "application/pdf":
return "document";
+ break;
+ }
- if (substr_count($mimetype,'audio/'))
- return "audio";
+ if (substr_count($mimetype,'text/'))
+ return "document";
- if (substr_count($mimetype,'image/'))
- return "image";
+ if (substr_count($mimetype,'audio/'))
+ return "audio";
- if (substr_count($mimetype,'video/'))
- return "video";
+ if (substr_count($mimetype,'image/'))
+ return "image";
- if (substr_count($mimetype,'opendocument'))
- return "document";
+ if (substr_count($mimetype,'video/'))
+ return "video";
- return "general";
- }
+ if (substr_count($mimetype,'opendocument'))
+ return "document";
- /**
- * Returns a list of filetypes to search specifically on
- *
- * @param int|array $owner_guid The GUID(s) of the owner(s) of the files
- * @param true|false $friends Whether we're looking at the owner or the owner's friends
- * @return string The typecloud
- */
- function get_filetype_cloud($owner_guid = "", $friends = false) {
-
- if ($friends) {
- if ($friendslist = get_user_friends($user_guid, "", 999999, 0)) {
- $friendguids = array();
- foreach($friendslist as $friend) {
- $friendguids[] = $friend->getGUID();
- }
+ return "general";
+}
+
+/**
+ * Returns a list of filetypes to search specifically on
+ *
+ * @param int|array $owner_guid The GUID(s) of the owner(s) of the files
+ * @param true|false $friends Whether we're looking at the owner or the owner's friends
+ * @return string The typecloud
+ */
+function get_filetype_cloud($owner_guid = "", $friends = false) {
+
+ if ($friends) {
+ if ($friendslist = get_user_friends($user_guid, "", 999999, 0)) {
+ $friendguids = array();
+ foreach($friendslist as $friend) {
+ $friendguids[] = $friend->getGUID();
}
- $friendofguid = $owner_guid;
- $owner_guid = $friendguids;
- } else {
- $friendofguid = false;
}
-
- elgg_register_tag_metadata_name('simpletype');
- $options = array(
- 'type' => 'object',
- 'subtype' => 'file',
- 'owner_guid' => $owner_guid,
- 'threshold' => 0,
- 'limit' => 10,
- 'tag_names' => array('simpletype')
- );
- $types = elgg_get_tags($options);
-
- return elgg_view('file/typecloud',array('owner_guid' => $owner_guid, 'friend_guid' => $friendofguid, 'types' => $types));
+ $friendofguid = $owner_guid;
+ $owner_guid = $friendguids;
+ } else {
+ $friendofguid = false;
}
- /**
- * Register file as an embed type.
- *
- * @param unknown_type $hook
- * @param unknown_type $type
- * @param unknown_type $value
- * @param unknown_type $params
- */
- function file_embed_get_sections($hook, $type, $value, $params) {
- $value['file'] = array(
- 'name' => elgg_echo('file'),
- 'layout' => 'list',
- 'icon_size' => 'small',
- );
-
- return $value;
- }
+ elgg_register_tag_metadata_name('simpletype');
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'file',
+ 'owner_guid' => $owner_guid,
+ 'threshold' => 0,
+ 'limit' => 10,
+ 'tag_names' => array('simpletype')
+ );
+ $types = elgg_get_tags($options);
+
+ return elgg_view('file/typecloud',array('owner_guid' => $owner_guid, 'friend_guid' => $friendofguid, 'types' => $types));
+}
- /**
- * Return a list of files for embedding
- *
- * @param unknown_type $hook
- * @param unknown_type $type
- * @param unknown_type $value
- * @param unknown_type $params
- */
- function file_embed_get_items($hook, $type, $value, $params) {
- $options = array(
- 'owner_guid' => get_loggedin_userid(),
- 'type_subtype_pair' => array('object' => 'file'),
- 'count' => TRUE
- );
+/**
+ * Register file as an embed type.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $value
+ * @param unknown_type $params
+ */
+function file_embed_get_sections($hook, $type, $value, $params) {
+ $value['file'] = array(
+ 'name' => elgg_echo('file'),
+ 'layout' => 'list',
+ 'icon_size' => 'small',
+ );
+
+ return $value;
+}
- if ($count = elgg_get_entities($options)) {
- $value['count'] += $count;
+/**
+ * Return a list of files for embedding
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $value
+ * @param unknown_type $params
+ */
+function file_embed_get_items($hook, $type, $value, $params) {
+ $options = array(
+ 'owner_guid' => get_loggedin_userid(),
+ 'type_subtype_pair' => array('object' => 'file'),
+ 'count' => TRUE
+ );
- unset($options['count']);
- $options['offset'] = $params['offset'];
- $options['limit'] = $params['limit'];
+ if ($count = elgg_get_entities($options)) {
+ $value['count'] += $count;
- $items = elgg_get_entities($options);
+ unset($options['count']);
+ $options['offset'] = $params['offset'];
+ $options['limit'] = $params['limit'];
- $value['items'] = array_merge($items, $value['items']);
- }
+ $items = elgg_get_entities($options);
- return $value;
+ $value['items'] = array_merge($items, $value['items']);
}
- /**
- * Register file as an embed type.
- *
- * @param unknown_type $hook
- * @param unknown_type $type
- * @param unknown_type $value
- * @param unknown_type $params
- */
- function file_embed_get_upload_sections($hook, $type, $value, $params) {
- $value['file'] = array(
- 'name' => elgg_echo('file'),
- 'view' => 'file/embed_upload'
- );
-
- return $value;
- }
+ return $value;
+}
+/**
+ * Register file as an embed type.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $type
+ * @param unknown_type $value
+ * @param unknown_type $params
+ */
+function file_embed_get_upload_sections($hook, $type, $value, $params) {
+ $value['file'] = array(
+ 'name' => elgg_echo('file'),
+ 'view' => 'file/embed_upload'
+ );
- /**
- * Populates the ->getUrl() method for file objects
- *
- * @param ElggEntity $entity File entity
- * @return string File URL
- */
- function file_url($entity) {
- $title = $entity->title;
- $title = elgg_get_friendly_title($title);
- return "pg/file/" . $entity->getOwnerEntity()->username . "/read/" . $entity->getGUID() . "/" . $title;
- }
+ return $value;
+}
- // Make sure test_init is called on initialisation
- elgg_register_event_handler('init','system','file_init');
- // Register actions
- elgg_register_action("file/upload", $CONFIG->pluginspath . "file/actions/upload.php");
- elgg_register_action("file/save", $CONFIG->pluginspath . "file/actions/save.php");
- elgg_register_action("file/delete", $CONFIG->pluginspath. "file/actions/delete.php");
+/**
+ * Populates the ->getUrl() method for file objects
+ *
+ * @param ElggEntity $entity File entity
+ * @return string File URL
+ */
+function file_url($entity) {
+ $title = $entity->title;
+ $title = elgg_get_friendly_title($title);
+ return "pg/file/view/" . $entity->getGUID() . "/" . $title;
+}
+
+// Make sure test_init is called on initialisation
+elgg_register_event_handler('init','system','file_init');
- // temporary - see #2010
- elgg_register_action("file/download", $CONFIG->pluginspath. "file/actions/download.php");
+// Register actions
+elgg_register_action("file/upload", $CONFIG->pluginspath . "file/actions/file/upload.php");
+elgg_register_action("file/save", $CONFIG->pluginspath . "file/actions/file/save.php");
+elgg_register_action("file/delete", $CONFIG->pluginspath. "file/actions/file/delete.php");
-?>
+// temporary - see #2010
+elgg_register_action("file/download", $CONFIG->pluginspath. "file/actions/file/download.php");