aboutsummaryrefslogtreecommitdiff
path: root/mod/file/pages
diff options
context:
space:
mode:
Diffstat (limited to 'mod/file/pages')
-rw-r--r--mod/file/pages/file/download.php38
-rw-r--r--mod/file/pages/file/edit.php40
-rw-r--r--mod/file/pages/file/friends.php36
-rw-r--r--mod/file/pages/file/owner.php57
-rw-r--r--mod/file/pages/file/search.php99
-rw-r--r--mod/file/pages/file/upload.php37
-rw-r--r--mod/file/pages/file/view.php46
-rw-r--r--mod/file/pages/file/world.php33
8 files changed, 386 insertions, 0 deletions
diff --git a/mod/file/pages/file/download.php b/mod/file/pages/file/download.php
new file mode 100644
index 000000000..76c1f1272
--- /dev/null
+++ b/mod/file/pages/file/download.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Elgg file download.
+ *
+ * @package ElggFile
+ */
+
+// Get the guid
+$file_guid = get_input("guid");
+
+// Get the file
+$file = get_entity($file_guid);
+if (!$file) {
+ register_error(elgg_echo("file:downloadfailed"));
+ forward();
+}
+
+$mime = $file->getMimeType();
+if (!$mime) {
+ $mime = "application/octet-stream";
+}
+
+$filename = $file->originalfilename;
+
+// fix for IE https issue
+header("Pragma: public");
+
+header("Content-type: $mime");
+if (strpos($mime, "image/") !== false || $mime == "application/pdf") {
+ header("Content-Disposition: inline; filename=\"$filename\"");
+} else {
+ header("Content-Disposition: attachment; filename=\"$filename\"");
+}
+
+ob_clean();
+flush();
+readfile($file->getFilenameOnFilestore());
+exit;
diff --git a/mod/file/pages/file/edit.php b/mod/file/pages/file/edit.php
new file mode 100644
index 000000000..b396c6e9b
--- /dev/null
+++ b/mod/file/pages/file/edit.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Edit a file
+ *
+ * @package ElggFile
+ */
+
+elgg_load_library('elgg:file');
+
+gatekeeper();
+
+$file_guid = (int) get_input('guid');
+$file = new FilePluginFile($file_guid);
+if (!$file) {
+ forward();
+}
+if (!$file->canEdit()) {
+ forward();
+}
+
+$title = elgg_echo('file:edit');
+
+elgg_push_breadcrumb(elgg_echo('file'), "file/all");
+elgg_push_breadcrumb($file->title, $file->getURL());
+elgg_push_breadcrumb($title);
+
+elgg_set_page_owner_guid($file->getContainerGUID());
+
+$form_vars = array('enctype' => 'multipart/form-data');
+$body_vars = file_prepare_form_vars($file);
+
+$content = elgg_view_form('file/upload', $form_vars, $body_vars);
+
+$body = elgg_view_layout('content', array(
+ 'content' => $content,
+ 'title' => $title,
+ 'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/file/pages/file/friends.php b/mod/file/pages/file/friends.php
new file mode 100644
index 000000000..d55c1e62b
--- /dev/null
+++ b/mod/file/pages/file/friends.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Friends Files
+ *
+ * @package ElggFile
+ */
+
+$owner = elgg_get_page_owner_entity();
+if (!$owner) {
+ forward('', '404');
+}
+
+elgg_push_breadcrumb(elgg_echo('file'), "file/all");
+elgg_push_breadcrumb($owner->name, "file/owner/$owner->username");
+elgg_push_breadcrumb(elgg_echo('friends'));
+
+elgg_register_title_button();
+
+$title = elgg_echo("file:friends");
+
+// offset is grabbed in list_user_friends_objects
+$content = list_user_friends_objects($owner->guid, 'file', 10, false);
+if (!$content) {
+ $content = elgg_echo("file:none");
+}
+
+$sidebar = file_get_type_cloud($owner->guid, true);
+
+$body = elgg_view_layout('content', array(
+ 'filter_context' => 'friends',
+ 'content' => $content,
+ 'title' => $title,
+ 'sidebar' => $sidebar,
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/file/pages/file/owner.php b/mod/file/pages/file/owner.php
new file mode 100644
index 000000000..99cf62714
--- /dev/null
+++ b/mod/file/pages/file/owner.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Individual's or group's files
+ *
+ * @package ElggFile
+ */
+
+// access check for closed groups
+group_gatekeeper();
+
+$owner = elgg_get_page_owner_entity();
+if (!$owner) {
+ forward('', '404');
+}
+
+elgg_push_breadcrumb(elgg_echo('file'), "file/all");
+elgg_push_breadcrumb($owner->name);
+
+elgg_register_title_button();
+
+$params = array();
+
+if ($owner->guid == elgg_get_logged_in_user_guid()) {
+ // user looking at own files
+ $params['filter_context'] = 'mine';
+} else if (elgg_instanceof($owner, 'user')) {
+ // someone else's files
+ // do not show select a tab when viewing someone else's posts
+ $params['filter_context'] = 'none';
+} else {
+ // group files
+ $params['filter'] = '';
+}
+
+$title = elgg_echo("file:user", array($owner->name));
+
+// List files
+$content = elgg_list_entities(array(
+ 'type' => 'object',
+ 'subtype' => 'file',
+ 'container_guid' => $owner->guid,
+ 'full_view' => FALSE,
+));
+if (!$content) {
+ $content = elgg_echo("file:none");
+}
+
+$sidebar = file_get_type_cloud(elgg_get_page_owner_guid());
+$sidebar = elgg_view('file/sidebar');
+
+$params['content'] = $content;
+$params['title'] = $title;
+$params['sidebar'] = $sidebar;
+
+$body = elgg_view_layout('content', $params);
+
+echo elgg_view_page($title, $body);
diff --git a/mod/file/pages/file/search.php b/mod/file/pages/file/search.php
new file mode 100644
index 000000000..d60dfb755
--- /dev/null
+++ b/mod/file/pages/file/search.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * List files by type
+ *
+ * @package ElggFile
+ */
+
+$page_owner_guid = get_input('page_owner', null);
+
+if ($page_owner_guid !== null) {
+ $page_owner_guid = sanitise_int($page_owner_guid);
+}
+
+if ($page_owner_guid) {
+ elgg_set_page_owner_guid($page_owner_guid);
+}
+$owner = elgg_get_page_owner_entity();
+
+group_gatekeeper();
+
+// Get input
+$md_type = 'simpletype';
+// avoid reflected XSS attacks by only allowing alnum characters
+$file_type = preg_replace('[\W]', '', get_input('tag'));
+$listtype = get_input('listtype');
+$friends = (bool)get_input('friends', false);
+
+// breadcrumbs
+elgg_push_breadcrumb(elgg_echo('file'), "file/all");
+if ($owner) {
+ if (elgg_instanceof($owner, 'user')) {
+ elgg_push_breadcrumb($owner->name, "file/owner/$owner->username");
+ } else {
+ elgg_push_breadcrumb($owner->name, "file/group/$owner->guid/all");
+ }
+}
+if ($friends && $owner) {
+ elgg_push_breadcrumb(elgg_echo('friends'), "file/friends/$owner->username");
+}
+if ($file_type) {
+ elgg_push_breadcrumb(elgg_echo("file:type:$file_type"));
+} else {
+ elgg_push_breadcrumb(elgg_echo('all'));
+}
+
+// title
+if (!$owner) {
+ // world files
+ $title = elgg_echo('all') . ' ' . elgg_echo("file:type:$file_type");
+} else {
+ $friend_string = $friends ? elgg_echo('file:title:friends') : '';
+ $type_string = elgg_echo("file:type:$file_type");
+ $title = elgg_echo('file:list:title', array($owner->name, $friend_string, $type_string));
+}
+
+
+$sidebar = file_get_type_cloud($page_owner_guid, $friends);
+
+if ($friends) {
+ // elgg_does not support getting objects that belong to an entity's friends
+ $friend_entities = get_user_friends($page_owner_guid, "", 999999, 0);
+ if ($friend_entities) {
+ $friend_guids = array();
+ foreach ($friend_entities as $friend) {
+ $friend_guids[] = $friend->getGUID();
+ }
+ }
+ $page_owner_guid = $friend_guids;
+}
+
+$limit = 10;
+if ($listtype == "gallery") {
+ $limit = 12;
+}
+
+$params = array(
+ 'type' => 'object',
+ 'subtype' => 'file',
+ 'container_guid' => $page_owner_guid,
+ 'limit' => $limit,
+ 'full_view' => false,
+);
+
+if ($file_type) {
+ $params['metadata_name'] = $md_type;
+ $params['metadata_value'] = $file_type;
+ $content = elgg_list_entities_from_metadata($params);
+} else {
+ $content = elgg_list_entities($params);
+}
+
+$body = elgg_view_layout('content', array(
+ 'filter' => '',
+ 'content' => $content,
+ 'title' => $title,
+ 'sidebar' => $sidebar,
+));
+
+echo elgg_view_page($title, $body); \ No newline at end of file
diff --git a/mod/file/pages/file/upload.php b/mod/file/pages/file/upload.php
new file mode 100644
index 000000000..3aa25b6db
--- /dev/null
+++ b/mod/file/pages/file/upload.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Upload a new file
+ *
+ * @package ElggFile
+ */
+
+elgg_load_library('elgg:file');
+
+$owner = elgg_get_page_owner_entity();
+
+gatekeeper();
+group_gatekeeper();
+
+$title = elgg_echo('file:add');
+
+// set up breadcrumbs
+elgg_push_breadcrumb(elgg_echo('file'), "file/all");
+if (elgg_instanceof($owner, 'user')) {
+ elgg_push_breadcrumb($owner->name, "file/owner/$owner->username");
+} else {
+ elgg_push_breadcrumb($owner->name, "file/group/$owner->guid/all");
+}
+elgg_push_breadcrumb($title);
+
+// create form
+$form_vars = array('enctype' => 'multipart/form-data');
+$body_vars = file_prepare_form_vars();
+$content = elgg_view_form('file/upload', $form_vars, $body_vars);
+
+$body = elgg_view_layout('content', array(
+ 'content' => $content,
+ 'title' => $title,
+ 'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/file/pages/file/view.php b/mod/file/pages/file/view.php
new file mode 100644
index 000000000..6c9566a89
--- /dev/null
+++ b/mod/file/pages/file/view.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * View a file
+ *
+ * @package ElggFile
+ */
+
+$file = get_entity(get_input('guid'));
+if (!$file) {
+ register_error(elgg_echo('noaccess'));
+ $_SESSION['last_forward_from'] = current_page_url();
+ forward('');
+}
+
+$owner = elgg_get_page_owner_entity();
+
+elgg_push_breadcrumb(elgg_echo('file'), 'file/all');
+
+$crumbs_title = $owner->name;
+if (elgg_instanceof($owner, 'group')) {
+ elgg_push_breadcrumb($crumbs_title, "file/group/$owner->guid/all");
+} else {
+ elgg_push_breadcrumb($crumbs_title, "file/owner/$owner->username");
+}
+
+$title = $file->title;
+
+elgg_push_breadcrumb($title);
+
+$content = elgg_view_entity($file, array('full_view' => true));
+$content .= elgg_view_comments($file);
+
+elgg_register_menu_item('title', array(
+ 'name' => 'download',
+ 'text' => elgg_echo('file:download'),
+ 'href' => "file/download/$file->guid",
+ 'link_class' => 'elgg-button elgg-button-action',
+));
+
+$body = elgg_view_layout('content', array(
+ 'content' => $content,
+ 'title' => $title,
+ 'filter' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/file/pages/file/world.php b/mod/file/pages/file/world.php
new file mode 100644
index 000000000..96c8de785
--- /dev/null
+++ b/mod/file/pages/file/world.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * All files
+ *
+ * @package ElggFile
+ */
+
+elgg_push_breadcrumb(elgg_echo('file'));
+
+elgg_register_title_button();
+
+$title = elgg_echo('file:all');
+
+$content = elgg_list_entities(array(
+ 'type' => 'object',
+ 'subtype' => 'file',
+ 'full_view' => FALSE
+));
+if (!$content) {
+ $content = elgg_echo('file:none');
+}
+
+$sidebar = file_get_type_cloud();
+$sidebar = elgg_view('file/sidebar');
+
+$body = elgg_view_layout('content', array(
+ 'filter_context' => 'all',
+ 'content' => $content,
+ 'title' => $title,
+ 'sidebar' => $sidebar,
+));
+
+echo elgg_view_page($title, $body);