aboutsummaryrefslogtreecommitdiff
path: root/mod/file
diff options
context:
space:
mode:
Diffstat (limited to 'mod/file')
-rw-r--r--mod/file/actions/file/delete.php33
-rw-r--r--mod/file/actions/file/download.php11
-rw-r--r--mod/file/actions/file/upload.php207
-rw-r--r--mod/file/classes/FilePluginFile.php31
-rw-r--r--mod/file/download.php12
-rw-r--r--mod/file/graphics/icons/application.gifbin0 -> 2465 bytes
-rw-r--r--mod/file/graphics/icons/application_lrg.gifbin0 -> 7781 bytes
-rw-r--r--mod/file/graphics/icons/archive.gifbin0 -> 2419 bytes
-rw-r--r--mod/file/graphics/icons/archive_lrg.gifbin0 -> 7918 bytes
-rw-r--r--mod/file/graphics/icons/excel.gifbin0 -> 2509 bytes
-rw-r--r--mod/file/graphics/icons/excel_lrg.gifbin0 -> 7571 bytes
-rw-r--r--mod/file/graphics/icons/general.gifbin0 -> 1528 bytes
-rw-r--r--mod/file/graphics/icons/general_lrg.gifbin0 -> 4594 bytes
-rw-r--r--mod/file/graphics/icons/music.gifbin0 -> 2297 bytes
-rw-r--r--mod/file/graphics/icons/music_lrg.gifbin0 -> 6748 bytes
-rw-r--r--mod/file/graphics/icons/openoffice.gifbin0 -> 2313 bytes
-rw-r--r--mod/file/graphics/icons/openoffice_lrg.gifbin0 -> 6617 bytes
-rw-r--r--mod/file/graphics/icons/pages.gifbin0 -> 2766 bytes
-rw-r--r--mod/file/graphics/icons/pages_lrg.gifbin0 -> 10234 bytes
-rw-r--r--mod/file/graphics/icons/pdf.gifbin0 -> 2197 bytes
-rw-r--r--mod/file/graphics/icons/pdf_lrg.gifbin0 -> 6014 bytes
-rw-r--r--mod/file/graphics/icons/ppt.gifbin0 -> 2495 bytes
-rw-r--r--mod/file/graphics/icons/ppt_lrg.gifbin0 -> 7423 bytes
-rw-r--r--mod/file/graphics/icons/text.gifbin0 -> 2881 bytes
-rw-r--r--mod/file/graphics/icons/text_lrg.gifbin0 -> 9855 bytes
-rw-r--r--mod/file/graphics/icons/vcard.gifbin0 -> 2385 bytes
-rw-r--r--mod/file/graphics/icons/vcard_lrg.gifbin0 -> 6798 bytes
-rw-r--r--mod/file/graphics/icons/video.gifbin0 -> 2603 bytes
-rw-r--r--mod/file/graphics/icons/video_lrg.gifbin0 -> 7319 bytes
-rw-r--r--mod/file/graphics/icons/word.gifbin0 -> 2479 bytes
-rw-r--r--mod/file/graphics/icons/word_lrg.gifbin0 -> 7350 bytes
-rw-r--r--mod/file/languages/en.php118
-rw-r--r--mod/file/lib/file.php45
-rw-r--r--mod/file/manifest.xml18
-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.php58
-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.php36
-rw-r--r--mod/file/start.php416
-rw-r--r--mod/file/thumbnail.php57
-rw-r--r--mod/file/views/default/embed/file_upload/content.php17
-rw-r--r--mod/file/views/default/file/css.php15
-rw-r--r--mod/file/views/default/file/group_module.php45
-rw-r--r--mod/file/views/default/file/sidebar.php14
-rw-r--r--mod/file/views/default/file/specialcontent/image/default.php20
-rw-r--r--mod/file/views/default/file/typecloud.php50
-rw-r--r--mod/file/views/default/forms/file/upload.php68
-rw-r--r--mod/file/views/default/icon/object/file.php54
-rw-r--r--mod/file/views/default/object/file.php107
-rw-r--r--mod/file/views/default/river/object/file/create.php13
-rw-r--r--mod/file/views/default/widgets/filerepo/content.php33
-rw-r--r--mod/file/views/default/widgets/filerepo/edit.php25
-rw-r--r--mod/file/views/rss/file/enclosure.php16
57 files changed, 1815 insertions, 0 deletions
diff --git a/mod/file/actions/file/delete.php b/mod/file/actions/file/delete.php
new file mode 100644
index 000000000..72585aa36
--- /dev/null
+++ b/mod/file/actions/file/delete.php
@@ -0,0 +1,33 @@
+<?php
+/**
+* Elgg file delete
+*
+* @package ElggFile
+*/
+
+$guid = (int) get_input('guid');
+
+$file = new FilePluginFile($guid);
+if (!$file->guid) {
+ register_error(elgg_echo("file:deletefailed"));
+ forward('file/all');
+}
+
+if (!$file->canEdit()) {
+ register_error(elgg_echo("file:deletefailed"));
+ forward($file->getURL());
+}
+
+$container = $file->getContainerEntity();
+
+if (!$file->delete()) {
+ register_error(elgg_echo("file:deletefailed"));
+} else {
+ system_message(elgg_echo("file:deleted"));
+}
+
+if (elgg_instanceof($container, 'group')) {
+ forward("file/group/$container->guid/all");
+} else {
+ forward("file/owner/$container->username");
+}
diff --git a/mod/file/actions/file/download.php b/mod/file/actions/file/download.php
new file mode 100644
index 000000000..d6abb8398
--- /dev/null
+++ b/mod/file/actions/file/download.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Elgg file browser download action.
+ *
+ * @package ElggFile
+ */
+
+// @todo this is here for backwards compatibility (first version of embed plugin?)
+$download_page_handler = elgg_get_plugins_path() . 'file/download.php';
+
+include $download_page_handler;
diff --git a/mod/file/actions/file/upload.php b/mod/file/actions/file/upload.php
new file mode 100644
index 000000000..d6dce2528
--- /dev/null
+++ b/mod/file/actions/file/upload.php
@@ -0,0 +1,207 @@
+<?php
+/**
+ * Elgg file uploader/edit action
+ *
+ * @package ElggFile
+ */
+
+// Get variables
+$title = htmlspecialchars(get_input('title', '', false), ENT_QUOTES, 'UTF-8');
+$desc = get_input("description");
+$access_id = (int) get_input("access_id");
+$container_guid = (int) get_input('container_guid', 0);
+$guid = (int) get_input('file_guid');
+$tags = get_input("tags");
+
+if ($container_guid == 0) {
+ $container_guid = elgg_get_logged_in_user_guid();
+}
+
+elgg_make_sticky_form('file');
+
+// check if upload failed
+if (!empty($_FILES['upload']['name']) && $_FILES['upload']['error'] != 0) {
+ register_error(elgg_echo('file:cannotload'));
+ forward(REFERER);
+}
+
+// check whether this is a new file or an edit
+$new_file = true;
+if ($guid > 0) {
+ $new_file = false;
+}
+
+if ($new_file) {
+ // must have a file if a new file upload
+ if (empty($_FILES['upload']['name'])) {
+ $error = elgg_echo('file:nofile');
+ register_error($error);
+ forward(REFERER);
+ }
+
+ $file = new FilePluginFile();
+ $file->subtype = "file";
+
+ // if no title on new upload, grab filename
+ if (empty($title)) {
+ $title = htmlspecialchars($_FILES['upload']['name'], ENT_QUOTES, 'UTF-8');
+ }
+
+} else {
+ // load original file object
+ $file = new FilePluginFile($guid);
+ if (!$file) {
+ register_error(elgg_echo('file:cannotload'));
+ forward(REFERER);
+ }
+
+ // user must be able to edit file
+ if (!$file->canEdit()) {
+ register_error(elgg_echo('file:noaccess'));
+ forward(REFERER);
+ }
+
+ if (!$title) {
+ // user blanked title, but we need one
+ $title = $file->title;
+ }
+}
+
+$file->title = $title;
+$file->description = $desc;
+$file->access_id = $access_id;
+$file->container_guid = $container_guid;
+
+$tags = explode(",", $tags);
+$file->tags = $tags;
+
+// we have a file upload, so process it
+if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
+
+ $prefix = "file/";
+
+ // if previous file, delete it
+ if ($new_file == false) {
+ $filename = $file->getFilenameOnFilestore();
+ if (file_exists($filename)) {
+ unlink($filename);
+ }
+
+ // use same filename on the disk - ensures thumbnails are overwritten
+ $filestorename = $file->getFilename();
+ $filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
+ } else {
+ $filestorename = elgg_strtolower(time().$_FILES['upload']['name']);
+ }
+
+ $file->setFilename($prefix . $filestorename);
+ $mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']);
+
+ // hack for Microsoft zipped formats
+ $info = pathinfo($_FILES['upload']['name']);
+ $office_formats = array('docx', 'xlsx', 'pptx');
+ if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
+ switch ($info['extension']) {
+ case 'docx':
+ $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
+ break;
+ case 'xlsx':
+ $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+ break;
+ case 'pptx':
+ $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
+ break;
+ }
+ }
+
+ // check for bad ppt detection
+ if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
+ $mime_type = "application/vnd.ms-powerpoint";
+ }
+
+ $file->setMimeType($mime_type);
+ $file->originalfilename = $_FILES['upload']['name'];
+ $file->simpletype = file_get_simple_type($mime_type);
+
+ // Open the file to guarantee the directory exists
+ $file->open("write");
+ $file->close();
+ move_uploaded_file($_FILES['upload']['tmp_name'], $file->getFilenameOnFilestore());
+
+ $guid = $file->save();
+
+ // if image, we need to create thumbnails (this should be moved into a function)
+ if ($guid && $file->simpletype == "image") {
+ $file->icontime = time();
+
+ $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
+ if ($thumbnail) {
+ $thumb = new ElggFile();
+ $thumb->setMimeType($_FILES['upload']['type']);
+
+ $thumb->setFilename($prefix."thumb".$filestorename);
+ $thumb->open("write");
+ $thumb->write($thumbnail);
+ $thumb->close();
+
+ $file->thumbnail = $prefix."thumb".$filestorename;
+ unset($thumbnail);
+ }
+
+ $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
+ if ($thumbsmall) {
+ $thumb->setFilename($prefix."smallthumb".$filestorename);
+ $thumb->open("write");
+ $thumb->write($thumbsmall);
+ $thumb->close();
+ $file->smallthumb = $prefix."smallthumb".$filestorename;
+ unset($thumbsmall);
+ }
+
+ $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
+ if ($thumblarge) {
+ $thumb->setFilename($prefix."largethumb".$filestorename);
+ $thumb->open("write");
+ $thumb->write($thumblarge);
+ $thumb->close();
+ $file->largethumb = $prefix."largethumb".$filestorename;
+ unset($thumblarge);
+ }
+ }
+} else {
+ // not saving a file but still need to save the entity to push attributes to database
+ $file->save();
+}
+
+// file saved so clear sticky form
+elgg_clear_sticky_form('file');
+
+
+// handle results differently for new files and file updates
+if ($new_file) {
+ if ($guid) {
+ $message = elgg_echo("file:saved");
+ system_message($message);
+ add_to_river('river/object/file/create', 'create', elgg_get_logged_in_user_guid(), $file->guid);
+ } else {
+ // failed to save file object - nothing we can do about this
+ $error = elgg_echo("file:uploadfailed");
+ register_error($error);
+ }
+
+ $container = get_entity($container_guid);
+ if (elgg_instanceof($container, 'group')) {
+ forward("file/group/$container->guid/all");
+ } else {
+ forward("file/owner/$container->username");
+ }
+
+} else {
+ if ($guid) {
+ system_message(elgg_echo("file:saved"));
+ } else {
+ register_error(elgg_echo("file:uploadfailed"));
+ }
+
+ forward($file->getURL());
+}
diff --git a/mod/file/classes/FilePluginFile.php b/mod/file/classes/FilePluginFile.php
new file mode 100644
index 000000000..edf914231
--- /dev/null
+++ b/mod/file/classes/FilePluginFile.php
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * Override the ElggFile
+ */
+class FilePluginFile extends ElggFile {
+ protected function initializeAttributes() {
+ parent::initializeAttributes();
+
+ $this->attributes['subtype'] = "file";
+ }
+
+ public function __construct($guid = null) {
+ parent::__construct($guid);
+ }
+
+ public function delete() {
+
+ $thumbnails = array($this->thumbnail, $this->smallthumb, $this->largethumb);
+ foreach ($thumbnails as $thumbnail) {
+ if ($thumbnail) {
+ $delfile = new ElggFile();
+ $delfile->owner_guid = $this->owner_guid;
+ $delfile->setFilename($thumbnail);
+ $delfile->delete();
+ }
+ }
+
+ return parent::delete();
+ }
+}
diff --git a/mod/file/download.php b/mod/file/download.php
new file mode 100644
index 000000000..b2acdffec
--- /dev/null
+++ b/mod/file/download.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Elgg file download.
+ *
+ * @package ElggFile
+ */
+require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+// Get the guid
+$file_guid = get_input("file_guid");
+
+forward("file/download/$file_guid");
diff --git a/mod/file/graphics/icons/application.gif b/mod/file/graphics/icons/application.gif
new file mode 100644
index 000000000..bfba76a97
--- /dev/null
+++ b/mod/file/graphics/icons/application.gif
Binary files differ
diff --git a/mod/file/graphics/icons/application_lrg.gif b/mod/file/graphics/icons/application_lrg.gif
new file mode 100644
index 000000000..65f8eadb4
--- /dev/null
+++ b/mod/file/graphics/icons/application_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/archive.gif b/mod/file/graphics/icons/archive.gif
new file mode 100644
index 000000000..2213cdadd
--- /dev/null
+++ b/mod/file/graphics/icons/archive.gif
Binary files differ
diff --git a/mod/file/graphics/icons/archive_lrg.gif b/mod/file/graphics/icons/archive_lrg.gif
new file mode 100644
index 000000000..6e3df3fd4
--- /dev/null
+++ b/mod/file/graphics/icons/archive_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/excel.gif b/mod/file/graphics/icons/excel.gif
new file mode 100644
index 000000000..ecd1d57d2
--- /dev/null
+++ b/mod/file/graphics/icons/excel.gif
Binary files differ
diff --git a/mod/file/graphics/icons/excel_lrg.gif b/mod/file/graphics/icons/excel_lrg.gif
new file mode 100644
index 000000000..84d1375d5
--- /dev/null
+++ b/mod/file/graphics/icons/excel_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/general.gif b/mod/file/graphics/icons/general.gif
new file mode 100644
index 000000000..20958b9a4
--- /dev/null
+++ b/mod/file/graphics/icons/general.gif
Binary files differ
diff --git a/mod/file/graphics/icons/general_lrg.gif b/mod/file/graphics/icons/general_lrg.gif
new file mode 100644
index 000000000..3458915e5
--- /dev/null
+++ b/mod/file/graphics/icons/general_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/music.gif b/mod/file/graphics/icons/music.gif
new file mode 100644
index 000000000..5e9df08bc
--- /dev/null
+++ b/mod/file/graphics/icons/music.gif
Binary files differ
diff --git a/mod/file/graphics/icons/music_lrg.gif b/mod/file/graphics/icons/music_lrg.gif
new file mode 100644
index 000000000..1c0792cc3
--- /dev/null
+++ b/mod/file/graphics/icons/music_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/openoffice.gif b/mod/file/graphics/icons/openoffice.gif
new file mode 100644
index 000000000..053ad5bb5
--- /dev/null
+++ b/mod/file/graphics/icons/openoffice.gif
Binary files differ
diff --git a/mod/file/graphics/icons/openoffice_lrg.gif b/mod/file/graphics/icons/openoffice_lrg.gif
new file mode 100644
index 000000000..da28607fa
--- /dev/null
+++ b/mod/file/graphics/icons/openoffice_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/pages.gif b/mod/file/graphics/icons/pages.gif
new file mode 100644
index 000000000..7efcb7278
--- /dev/null
+++ b/mod/file/graphics/icons/pages.gif
Binary files differ
diff --git a/mod/file/graphics/icons/pages_lrg.gif b/mod/file/graphics/icons/pages_lrg.gif
new file mode 100644
index 000000000..234a52672
--- /dev/null
+++ b/mod/file/graphics/icons/pages_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/pdf.gif b/mod/file/graphics/icons/pdf.gif
new file mode 100644
index 000000000..94362a4f0
--- /dev/null
+++ b/mod/file/graphics/icons/pdf.gif
Binary files differ
diff --git a/mod/file/graphics/icons/pdf_lrg.gif b/mod/file/graphics/icons/pdf_lrg.gif
new file mode 100644
index 000000000..aff869d04
--- /dev/null
+++ b/mod/file/graphics/icons/pdf_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/ppt.gif b/mod/file/graphics/icons/ppt.gif
new file mode 100644
index 000000000..88ab26d5c
--- /dev/null
+++ b/mod/file/graphics/icons/ppt.gif
Binary files differ
diff --git a/mod/file/graphics/icons/ppt_lrg.gif b/mod/file/graphics/icons/ppt_lrg.gif
new file mode 100644
index 000000000..075590fd8
--- /dev/null
+++ b/mod/file/graphics/icons/ppt_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/text.gif b/mod/file/graphics/icons/text.gif
new file mode 100644
index 000000000..897aa77f9
--- /dev/null
+++ b/mod/file/graphics/icons/text.gif
Binary files differ
diff --git a/mod/file/graphics/icons/text_lrg.gif b/mod/file/graphics/icons/text_lrg.gif
new file mode 100644
index 000000000..d42ea4de1
--- /dev/null
+++ b/mod/file/graphics/icons/text_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/vcard.gif b/mod/file/graphics/icons/vcard.gif
new file mode 100644
index 000000000..202df68dd
--- /dev/null
+++ b/mod/file/graphics/icons/vcard.gif
Binary files differ
diff --git a/mod/file/graphics/icons/vcard_lrg.gif b/mod/file/graphics/icons/vcard_lrg.gif
new file mode 100644
index 000000000..68ced88d2
--- /dev/null
+++ b/mod/file/graphics/icons/vcard_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/video.gif b/mod/file/graphics/icons/video.gif
new file mode 100644
index 000000000..56aca7589
--- /dev/null
+++ b/mod/file/graphics/icons/video.gif
Binary files differ
diff --git a/mod/file/graphics/icons/video_lrg.gif b/mod/file/graphics/icons/video_lrg.gif
new file mode 100644
index 000000000..69cc706d9
--- /dev/null
+++ b/mod/file/graphics/icons/video_lrg.gif
Binary files differ
diff --git a/mod/file/graphics/icons/word.gif b/mod/file/graphics/icons/word.gif
new file mode 100644
index 000000000..6f7dff340
--- /dev/null
+++ b/mod/file/graphics/icons/word.gif
Binary files differ
diff --git a/mod/file/graphics/icons/word_lrg.gif b/mod/file/graphics/icons/word_lrg.gif
new file mode 100644
index 000000000..4c39108de
--- /dev/null
+++ b/mod/file/graphics/icons/word_lrg.gif
Binary files differ
diff --git a/mod/file/languages/en.php b/mod/file/languages/en.php
new file mode 100644
index 000000000..b3344cb43
--- /dev/null
+++ b/mod/file/languages/en.php
@@ -0,0 +1,118 @@
+<?php
+/**
+ * Elgg file plugin language pack
+ *
+ * @package ElggFile
+ */
+
+$english = array(
+
+ /**
+ * Menu items and titles
+ */
+ 'file' => "Files",
+ 'file:user' => "%s's files",
+ 'file:friends' => "Friends' files",
+ 'file:all' => "All site files",
+ 'file:edit' => "Edit file",
+ 'file:more' => "More files",
+ 'file:list' => "list view",
+ 'file:group' => "Group files",
+ 'file:gallery' => "gallery view",
+ 'file:gallery_list' => "Gallery or list view",
+ 'file:num_files' => "Number of files to display",
+ 'file:user:gallery'=>'View %s gallery',
+ 'file:upload' => "Upload a file",
+ 'file:replace' => 'Replace file content (leave blank to not change file)',
+ 'file:list:title' => "%s's %s %s",
+ 'file:title:friends' => "Friends'",
+
+ 'file:add' => 'Upload a file',
+
+ 'file:file' => "File",
+ 'file:title' => "Title",
+ 'file:desc' => "Description",
+ 'file:tags' => "Tags",
+
+ 'file:list:list' => 'Switch to the list view',
+ 'file:list:gallery' => 'Switch to the gallery view',
+
+ 'file:types' => "Uploaded file types",
+
+ 'file:type:' => 'Files',
+ 'file:type:all' => "All files",
+ 'file:type:video' => "Videos",
+ 'file:type:document' => "Documents",
+ 'file:type:audio' => "Audio",
+ 'file:type:image' => "Pictures",
+ 'file:type:general' => "General",
+
+ 'file:user:type:video' => "%s's videos",
+ 'file:user:type:document' => "%s's documents",
+ 'file:user:type:audio' => "%s's audio",
+ 'file:user:type:image' => "%s's pictures",
+ 'file:user:type:general' => "%s's general files",
+
+ 'file:friends:type:video' => "Your friends' videos",
+ 'file:friends:type:document' => "Your friends' documents",
+ 'file:friends:type:audio' => "Your friends' audio",
+ 'file:friends:type:image' => "Your friends' pictures",
+ 'file:friends:type:general' => "Your friends' general files",
+
+ 'file:widget' => "File widget",
+ 'file:widget:description' => "Showcase your latest files",
+
+ 'groups:enablefiles' => 'Enable group files',
+
+ 'file:download' => "Download this",
+
+ 'file:delete:confirm' => "Are you sure you want to delete this file?",
+
+ 'file:tagcloud' => "Tag cloud",
+
+ 'file:display:number' => "Number of files to display",
+
+ 'river:create:object:file' => '%s uploaded the file %s',
+ 'river:comment:object:file' => '%s commented on the file %s',
+
+ 'item:object:file' => 'Files',
+
+ 'file:newupload' => 'A new file has been uploaded',
+ 'file:notification' =>
+'%s uploaded a new file:
+
+%s
+%s
+
+View and comment on the new file:
+%s
+',
+
+ /**
+ * Embed media
+ **/
+
+ 'file:embed' => "Embed media",
+ 'file:embedall' => "All",
+
+ /**
+ * Status messages
+ */
+
+ 'file:saved' => "Your file was successfully saved.",
+ 'file:deleted' => "Your file was successfully deleted.",
+
+ /**
+ * Error messages
+ */
+
+ 'file:none' => "No files.",
+ 'file:uploadfailed' => "Sorry; we could not save your file.",
+ 'file:downloadfailed' => "Sorry; this file is not available at this time.",
+ 'file:deletefailed' => "Your file could not be deleted at this time.",
+ 'file:noaccess' => "You do not have permissions to change this file",
+ 'file:cannotload' => "There was an error uploading the file",
+ 'file:nofile' => "You must select a file",
+);
+
+add_translation("en", $english); \ No newline at end of file
diff --git a/mod/file/lib/file.php b/mod/file/lib/file.php
new file mode 100644
index 000000000..6f94772e7
--- /dev/null
+++ b/mod/file/lib/file.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * File helper functions
+ *
+ * @package ElggFile
+ */
+
+/**
+ * Prepare the upload/edit form variables
+ *
+ * @param FilePluginFile $file
+ * @return array
+ */
+function file_prepare_form_vars($file = null) {
+
+ // input names => defaults
+ $values = array(
+ 'title' => '',
+ 'description' => '',
+ 'access_id' => ACCESS_DEFAULT,
+ 'tags' => '',
+ 'container_guid' => elgg_get_page_owner_guid(),
+ 'guid' => null,
+ 'entity' => $file,
+ );
+
+ if ($file) {
+ foreach (array_keys($values) as $field) {
+ if (isset($file->$field)) {
+ $values[$field] = $file->$field;
+ }
+ }
+ }
+
+ if (elgg_is_sticky_form('file')) {
+ $sticky_values = elgg_get_sticky_values('file');
+ foreach ($sticky_values as $key => $value) {
+ $values[$key] = $value;
+ }
+ }
+
+ elgg_clear_sticky_form('file');
+
+ return $values;
+}
diff --git a/mod/file/manifest.xml b/mod/file/manifest.xml
new file mode 100644
index 000000000..26282a8e3
--- /dev/null
+++ b/mod/file/manifest.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>File</name>
+ <author>Core developers</author>
+ <version>1.8.1</version>
+ <category>bundled</category>
+ <category>content</category>
+ <category>widget</category>
+ <description>File browser plugin</description>
+ <website>http://www.elgg.org/</website>
+ <copyright>See COPYRIGHT.txt</copyright>
+ <license>GNU General Public License version 2</license>
+ <requires>
+ <type>elgg_release</type>
+ <version>1.8</version>
+ </requires>
+ <activate_on_install>true</activate_on_install>
+</plugin_manifest>
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..f504bdc1f
--- /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('file/all');
+}
+
+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..fb87af1b2
--- /dev/null
+++ b/mod/file/pages/file/owner.php
@@ -0,0 +1,58 @@
+<?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('file/all');
+}
+
+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(
+ 'types' => 'object',
+ 'subtypes' => 'file',
+ 'container_guid' => $owner->guid,
+ 'limit' => 10,
+ '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..402a28933
--- /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(
+ 'types' => 'object',
+ 'subtypes' => '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..770dfd6e8
--- /dev/null
+++ b/mod/file/pages/file/world.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ * All files
+ *
+ * @package ElggFile
+ */
+
+elgg_push_breadcrumb(elgg_echo('file'));
+
+elgg_register_title_button();
+
+$limit = get_input("limit", 10);
+
+$title = elgg_echo('file:all');
+
+$content = elgg_list_entities(array(
+ 'types' => 'object',
+ 'subtypes' => 'file',
+ 'limit' => $limit,
+ '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);
diff --git a/mod/file/start.php b/mod/file/start.php
new file mode 100644
index 000000000..7c0c216b2
--- /dev/null
+++ b/mod/file/start.php
@@ -0,0 +1,416 @@
+<?php
+/**
+ * Elgg file plugin
+ *
+ * @package ElggFile
+ */
+
+elgg_register_event_handler('init', 'system', 'file_init');
+
+/**
+ * File plugin initialization functions.
+ */
+function file_init() {
+
+ // register a library of helper functions
+ elgg_register_library('elgg:file', elgg_get_plugins_path() . 'file/lib/file.php');
+
+ // Site navigation
+ $item = new ElggMenuItem('file', elgg_echo('file'), 'file/all');
+ elgg_register_menu_item('site', $item);
+
+ // Extend CSS
+ elgg_extend_view('css/elgg', 'file/css');
+
+ // add enclosure to rss item
+ elgg_extend_view('extensions/item', 'file/enclosure');
+
+ // extend group main page
+ elgg_extend_view('groups/tool_latest', 'file/group_module');
+
+ // Register a page handler, so we can have nice URLs
+ elgg_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"));
+
+ // Register URL handlers for files
+ elgg_register_entity_url_handler('object', 'file', 'file_url_override');
+ elgg_register_plugin_hook_handler('entity:icon:url', 'object', 'file_icon_url_override');
+
+ // 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');
+
+ // add the group files tool option
+ add_group_tool_option('file', elgg_echo('groups:enablefiles'), true);
+
+ // Register entity type for search
+ elgg_register_entity_type('object', 'file');
+
+ // add a file link to owner blocks
+ elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'file_owner_block_menu');
+
+ // Register actions
+ $action_path = elgg_get_plugins_path() . 'file/actions/file';
+ elgg_register_action("file/upload", "$action_path/upload.php");
+ elgg_register_action("file/delete", "$action_path/delete.php");
+ // temporary - see #2010
+ elgg_register_action("file/download", "$action_path/download.php");
+
+ // embed support
+ $item = ElggMenuItem::factory(array(
+ 'name' => 'file',
+ 'text' => elgg_echo('file'),
+ 'priority' => 10,
+ 'data' => array(
+ 'options' => array(
+ 'type' => 'object',
+ 'subtype' => 'file',
+ ),
+ ),
+ ));
+ elgg_register_menu_item('embed', $item);
+
+ $item = ElggMenuItem::factory(array(
+ 'name' => 'file_upload',
+ 'text' => elgg_echo('file:upload'),
+ 'priority' => 100,
+ 'data' => array(
+ 'view' => 'embed/file_upload/content',
+ ),
+ ));
+
+ elgg_register_menu_item('embed', $item);
+}
+
+/**
+ * Dispatches file pages.
+ * URLs take the form of
+ * All files: file/all
+ * User's files: file/owner/<username>
+ * Friends' files: file/friends/<username>
+ * View file: file/view/<guid>/<title>
+ * New file: file/add/<guid>
+ * Edit file: file/edit/<guid>
+ * Group files: file/group/<guid>/all
+ * Download: file/download/<guid>
+ *
+ * Title is ignored
+ *
+ * @param array $page
+ * @return bool
+ */
+function file_page_handler($page) {
+
+ if (!isset($page[0])) {
+ $page[0] = 'all';
+ }
+
+ $file_dir = elgg_get_plugins_path() . 'file/pages/file';
+
+ $page_type = $page[0];
+ switch ($page_type) {
+ case 'owner':
+ file_register_toggle();
+ include "$file_dir/owner.php";
+ break;
+ case 'friends':
+ file_register_toggle();
+ include "$file_dir/friends.php";
+ break;
+ case 'read': // Elgg 1.7 compatibility
+ register_error(elgg_echo("changebookmark"));
+ forward("file/view/{$page[1]}");
+ break;
+ case 'view':
+ set_input('guid', $page[1]);
+ include "$file_dir/view.php";
+ break;
+ case 'add':
+ include "$file_dir/upload.php";
+ break;
+ case 'edit':
+ set_input('guid', $page[1]);
+ include "$file_dir/edit.php";
+ break;
+ case 'search':
+ file_register_toggle();
+ include "$file_dir/search.php";
+ break;
+ case 'group':
+ file_register_toggle();
+ include "$file_dir/owner.php";
+ break;
+ case 'all':
+ file_register_toggle();
+ include "$file_dir/world.php";
+ break;
+ case 'download':
+ set_input('guid', $page[1]);
+ include "$file_dir/download.php";
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
+/**
+ * Adds a toggle to extra menu for switching between list and gallery views
+ */
+function file_register_toggle() {
+ $url = elgg_http_remove_url_query_element(current_page_url(), 'list_type');
+
+ if (get_input('list_type', 'list') == 'list') {
+ $list_type = "gallery";
+ $icon = elgg_view_icon('grid');
+ } else {
+ $list_type = "list";
+ $icon = elgg_view_icon('list');
+ }
+
+ if (substr_count($url, '?')) {
+ $url .= "&list_type=" . $list_type;
+ } else {
+ $url .= "?list_type=" . $list_type;
+ }
+
+
+ elgg_register_menu_item('extras', array(
+ 'name' => 'file_list',
+ 'text' => $icon,
+ 'href' => $url,
+ 'title' => elgg_echo("file:list:$list_type"),
+ 'priority' => 1000,
+ ));
+}
+
+/**
+ * Creates the notification message body
+ *
+ * @param string $hook
+ * @param string $entity_type
+ * @param string $returnvalue
+ * @param array $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;
+ $url = elgg_get_site_url() . "view/" . $entity->guid;
+ $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
+ */
+function file_owner_block_menu($hook, $type, $return, $params) {
+ if (elgg_instanceof($params['entity'], 'user')) {
+ $url = "file/owner/{$params['entity']->username}";
+ $item = new ElggMenuItem('file', elgg_echo('file'), $url);
+ $return[] = $item;
+ } else {
+ if ($params['entity']->file_enable != "no") {
+ $url = "file/group/{$params['entity']->guid}/all";
+ $item = new ElggMenuItem('file', elgg_echo('file:group'), $url);
+ $return[] = $item;
+ }
+ }
+
+ return $return;
+}
+
+/**
+ * Returns an overall file type from the mimetype
+ *
+ * @param string $mimetype The MIME type
+ * @return string The overall type
+ */
+function file_get_simple_type($mimetype) {
+
+ if ($simpletype = elgg_trigger_plugin_hook('file:simpletype', $mimetype, null, null)) {
+ return $simpletype;
+ }
+
+ switch ($mimetype) {
+ case "application/msword":
+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
+ return "document";
+ break;
+ case "application/pdf":
+ return "document";
+ break;
+ case "application/ogg":
+ return "audio";
+ break;
+ }
+
+ if (substr_count($mimetype, 'text/')) {
+ return "document";
+ }
+
+ if (substr_count($mimetype, 'audio/')) {
+ return "audio";
+ }
+
+ if (substr_count($mimetype, 'image/')) {
+ return "image";
+ }
+
+ if (substr_count($mimetype, 'video/')) {
+ return "video";
+ }
+
+ if (substr_count($mimetype, 'opendocument')) {
+ return "document";
+ }
+
+ return "general";
+}
+
+// deprecated and will be removed
+function get_general_file_type($mimetype) {
+ elgg_deprecated_notice('Use file_get_simple_type() instead of get_general_file_type()', 1.8);
+ return file_get_simple_type($mimetype);
+}
+
+/**
+ * Returns a list of filetypes
+ *
+ * @param int $container_guid The GUID of the container of the files
+ * @param bool $friends Whether we're looking at the container or the container's friends
+ * @return string The typecloud
+ */
+function file_get_type_cloud($container_guid = "", $friends = false) {
+
+ $container_guids = $container_guid;
+
+ if ($friends) {
+ // tags interface does not support pulling tags on friends' content so
+ // we need to grab all friends
+ $friend_entities = get_user_friends($container_guid, "", 999999, 0);
+ if ($friend_entities) {
+ $friend_guids = array();
+ foreach ($friend_entities as $friend) {
+ $friend_guids[] = $friend->getGUID();
+ }
+ }
+ $container_guids = $friend_guids;
+ }
+
+ elgg_register_tag_metadata_name('simpletype');
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'file',
+ 'container_guids' => $container_guids,
+ 'threshold' => 0,
+ 'limit' => 10,
+ 'tag_names' => array('simpletype')
+ );
+ $types = elgg_get_tags($options);
+
+ $params = array(
+ 'friends' => $friends,
+ 'types' => $types,
+ );
+
+ return elgg_view('file/typecloud', $params);
+}
+
+function get_filetype_cloud($owner_guid = "", $friends = false) {
+ elgg_deprecated_notice('Use file_get_type_cloud instead of get_filetype_cloud', 1.8);
+ return file_get_type_cloud($owner_guid, $friends);
+}
+
+/**
+ * Populates the ->getUrl() method for file objects
+ *
+ * @param ElggEntity $entity File entity
+ * @return string File URL
+ */
+function file_url_override($entity) {
+ $title = $entity->title;
+ $title = elgg_get_friendly_title($title);
+ return "file/view/" . $entity->getGUID() . "/" . $title;
+}
+
+/**
+ * Override the default entity icon for files
+ *
+ * Plugins can override or extend the icons using the plugin hook: 'file:icon:url', 'override'
+ *
+ * @return string Relative URL
+ */
+function file_icon_url_override($hook, $type, $returnvalue, $params) {
+ $file = $params['entity'];
+ $size = $params['size'];
+ if (elgg_instanceof($file, 'object', 'file')) {
+
+ // thumbnails get first priority
+ if ($file->thumbnail) {
+ $ts = (int)$file->icontime;
+ return "mod/file/thumbnail.php?file_guid=$file->guid&size=$size&icontime=$ts";
+ }
+
+ $mapping = array(
+ 'application/excel' => 'excel',
+ 'application/msword' => 'word',
+ 'application/ogg' => 'music',
+ 'application/pdf' => 'pdf',
+ 'application/powerpoint' => 'ppt',
+ 'application/vnd.ms-excel' => 'excel',
+ 'application/vnd.ms-powerpoint' => 'ppt',
+ 'application/vnd.oasis.opendocument.text' => 'openoffice',
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'word',
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'excel',
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'ppt',
+ 'application/x-gzip' => 'archive',
+ 'application/x-rar-compressed' => 'archive',
+ 'application/x-stuffit' => 'archive',
+ 'application/zip' => 'archive',
+
+ 'text/directory' => 'vcard',
+ 'text/v-card' => 'vcard',
+
+ 'application' => 'application',
+ 'audio' => 'music',
+ 'text' => 'text',
+ 'video' => 'video',
+ );
+
+ $mime = $file->mimetype;
+ if ($mime) {
+ $base_type = substr($mime, 0, strpos($mime, '/'));
+ } else {
+ $mime = 'none';
+ $base_type = 'none';
+ }
+
+ if (isset($mapping[$mime])) {
+ $type = $mapping[$mime];
+ } elseif (isset($mapping[$base_type])) {
+ $type = $mapping[$base_type];
+ } else {
+ $type = 'general';
+ }
+
+ if ($size == 'large') {
+ $ext = '_lrg';
+ } else {
+ $ext = '';
+ }
+
+ $url = "mod/file/graphics/icons/{$type}{$ext}.gif";
+ $url = elgg_trigger_plugin_hook('file:icon:url', 'override', $params, $url);
+ return $url;
+ }
+}
diff --git a/mod/file/thumbnail.php b/mod/file/thumbnail.php
new file mode 100644
index 000000000..851f13a8f
--- /dev/null
+++ b/mod/file/thumbnail.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Elgg file thumbnail
+ *
+ * @package ElggFile
+ */
+
+// Get engine
+require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+// Get file GUID
+$file_guid = (int) get_input('file_guid', 0);
+
+// Get file thumbnail size
+$size = get_input('size', 'small');
+
+$file = get_entity($file_guid);
+if (!$file || $file->getSubtype() != "file") {
+ exit;
+}
+
+$simpletype = $file->simpletype;
+if ($simpletype == "image") {
+
+ // Get file thumbnail
+ switch ($size) {
+ case "small":
+ $thumbfile = $file->thumbnail;
+ break;
+ case "medium":
+ $thumbfile = $file->smallthumb;
+ break;
+ case "large":
+ default:
+ $thumbfile = $file->largethumb;
+ break;
+ }
+
+ // Grab the file
+ if ($thumbfile && !empty($thumbfile)) {
+ $readfile = new ElggFile();
+ $readfile->owner_guid = $file->owner_guid;
+ $readfile->setFilename($thumbfile);
+ $mime = $file->getMimeType();
+ $contents = $readfile->grabFile();
+
+ // caching images for 10 days
+ header("Content-type: $mime");
+ header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
+ header("Pragma: public", true);
+ header("Cache-Control: public", true);
+ header("Content-Length: " . strlen($contents));
+
+ echo $contents;
+ exit;
+ }
+}
diff --git a/mod/file/views/default/embed/file_upload/content.php b/mod/file/views/default/embed/file_upload/content.php
new file mode 100644
index 000000000..8b630c828
--- /dev/null
+++ b/mod/file/views/default/embed/file_upload/content.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * Upload a file through the embed interface
+ */
+
+$form_vars = array(
+ 'enctype' => 'multipart/form-data',
+ 'class' => 'elgg-form-embed',
+);
+$body_vars = array('container_guid' => elgg_get_page_owner_guid());
+echo elgg_view_form('file/upload', $form_vars, $body_vars);
+
+// the tab we want to be forwarded to after upload is complete
+echo elgg_view('input/hidden', array(
+ 'name' => 'embed_forward',
+ 'value' => 'file',
+)); \ No newline at end of file
diff --git a/mod/file/views/default/file/css.php b/mod/file/views/default/file/css.php
new file mode 100644
index 000000000..5476ed7e2
--- /dev/null
+++ b/mod/file/views/default/file/css.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * File CSS extender
+ *
+ * @package ElggFile
+ */
+?>
+.file-photo {
+ text-align: center;
+ margin-bottom: 15px;
+}
+.file-gallery-item {
+ text-align: center;
+ width: 165px;
+}
diff --git a/mod/file/views/default/file/group_module.php b/mod/file/views/default/file/group_module.php
new file mode 100644
index 000000000..ad6c58dbb
--- /dev/null
+++ b/mod/file/views/default/file/group_module.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Group file module
+ */
+
+$group = elgg_get_page_owner_entity();
+
+if ($group->file_enable == "no") {
+ return true;
+}
+
+$all_link = elgg_view('output/url', array(
+ 'href' => "file/group/$group->guid/all",
+ 'text' => elgg_echo('link:view:all'),
+ 'is_trusted' => true,
+));
+
+elgg_push_context('widgets');
+$options = array(
+ 'type' => 'object',
+ 'subtype' => 'file',
+ 'container_guid' => elgg_get_page_owner_guid(),
+ 'limit' => 6,
+ 'full_view' => false,
+ 'pagination' => false,
+);
+$content = elgg_list_entities($options);
+elgg_pop_context();
+
+if (!$content) {
+ $content = '<p>' . elgg_echo('file:none') . '</p>';
+}
+
+$new_link = elgg_view('output/url', array(
+ 'href' => "file/add/$group->guid",
+ 'text' => elgg_echo('file:add'),
+ 'is_trusted' => true,
+));
+
+echo elgg_view('groups/profile/module', array(
+ 'title' => elgg_echo('file:group'),
+ 'content' => $content,
+ 'all_link' => $all_link,
+ 'add_link' => $new_link,
+));
diff --git a/mod/file/views/default/file/sidebar.php b/mod/file/views/default/file/sidebar.php
new file mode 100644
index 000000000..f61b8e64e
--- /dev/null
+++ b/mod/file/views/default/file/sidebar.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * File sidebar
+ */
+
+echo elgg_view('page/elements/comments_block', array(
+ 'subtypes' => 'file',
+ 'owner_guid' => elgg_get_page_owner_guid(),
+));
+
+echo elgg_view('page/elements/tagcloud_block', array(
+ 'subtypes' => 'file',
+ 'owner_guid' => elgg_get_page_owner_guid(),
+));
diff --git a/mod/file/views/default/file/specialcontent/image/default.php b/mod/file/views/default/file/specialcontent/image/default.php
new file mode 100644
index 000000000..431ac9f4f
--- /dev/null
+++ b/mod/file/views/default/file/specialcontent/image/default.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Display an image
+ *
+ * @uses $vars['entity']
+ */
+
+$file = $vars['entity'];
+
+$image_url = $file->getIconURL('large');
+$image_url = elgg_format_url($image_url);
+$download_url = elgg_get_site_url() . "file/download/{$file->getGUID()}";
+
+if ($vars['full_view']) {
+ echo <<<HTML
+ <div class="file-photo">
+ <a href="$download_url"><img class="elgg-photo" src="$image_url" /></a>
+ </div>
+HTML;
+}
diff --git a/mod/file/views/default/file/typecloud.php b/mod/file/views/default/file/typecloud.php
new file mode 100644
index 000000000..4253bf674
--- /dev/null
+++ b/mod/file/views/default/file/typecloud.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Type cloud
+ */
+
+function file_type_cloud_get_url($type, $friends) {
+ $url = elgg_get_site_url() . 'file/search?subtype=file';
+
+ if ($type->tag != "all") {
+ $url .= "&md_type=simpletype&tag=" . urlencode($type->tag);
+ }
+
+ if ($friends) {
+ $url .= "&friends=$friends";
+ }
+
+ if ($type->tag == "image") {
+ $url .= "&list_type=gallery";
+ }
+
+ if (elgg_get_page_owner_guid()) {
+ $url .= "&page_owner=" . elgg_get_page_owner_guid();
+ }
+
+ return $url;
+}
+
+
+$types = elgg_extract('types', $vars, array());
+if (!$types) {
+ return true;
+}
+
+$friends = elgg_extract('friends', $vars, false);
+
+$all = new stdClass;
+$all->tag = "all";
+elgg_register_menu_item('page', array(
+ 'name' => 'file:all',
+ 'text' => elgg_echo('all'),
+ 'href' => file_type_cloud_get_url($all, $friends),
+));
+
+foreach ($types as $type) {
+ elgg_register_menu_item('page', array(
+ 'name' => "file:$type->tag",
+ 'text' => elgg_echo("file:type:$type->tag"),
+ 'href' => file_type_cloud_get_url($type, $friends),
+ ));
+}
diff --git a/mod/file/views/default/forms/file/upload.php b/mod/file/views/default/forms/file/upload.php
new file mode 100644
index 000000000..f637a419e
--- /dev/null
+++ b/mod/file/views/default/forms/file/upload.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Elgg file upload/save form
+ *
+ * @package ElggFile
+ */
+
+// once elgg_view stops throwing all sorts of junk into $vars, we can use
+$title = elgg_extract('title', $vars, '');
+$desc = elgg_extract('description', $vars, '');
+$tags = elgg_extract('tags', $vars, '');
+$access_id = elgg_extract('access_id', $vars, ACCESS_DEFAULT);
+$container_guid = elgg_extract('container_guid', $vars);
+if (!$container_guid) {
+ $container_guid = elgg_get_logged_in_user_guid();
+}
+$guid = elgg_extract('guid', $vars, null);
+
+if ($guid) {
+ $file_label = elgg_echo("file:replace");
+ $submit_label = elgg_echo('save');
+} else {
+ $file_label = elgg_echo("file:file");
+ $submit_label = elgg_echo('upload');
+}
+
+?>
+<div>
+ <label><?php echo $file_label; ?></label><br />
+ <?php echo elgg_view('input/file', array('name' => 'upload')); ?>
+</div>
+<div>
+ <label><?php echo elgg_echo('title'); ?></label><br />
+ <?php echo elgg_view('input/text', array('name' => 'title', 'value' => $title)); ?>
+</div>
+<div>
+ <label><?php echo elgg_echo('description'); ?></label>
+ <?php echo elgg_view('input/longtext', array('name' => 'description', 'value' => $desc)); ?>
+</div>
+<div>
+ <label><?php echo elgg_echo('tags'); ?></label>
+ <?php echo elgg_view('input/tags', array('name' => 'tags', 'value' => $tags)); ?>
+</div>
+<?php
+
+$categories = elgg_view('input/categories', $vars);
+if ($categories) {
+ echo $categories;
+}
+
+?>
+<div>
+ <label><?php echo elgg_echo('access'); ?></label><br />
+ <?php echo elgg_view('input/access', array('name' => 'access_id', 'value' => $access_id)); ?>
+</div>
+<div class="elgg-foot">
+<?php
+
+echo elgg_view('input/hidden', array('name' => 'container_guid', 'value' => $container_guid));
+
+if ($guid) {
+ echo elgg_view('input/hidden', array('name' => 'file_guid', 'value' => $guid));
+}
+
+echo elgg_view('input/submit', array('value' => $submit_label));
+
+?>
+</div>
diff --git a/mod/file/views/default/icon/object/file.php b/mod/file/views/default/icon/object/file.php
new file mode 100644
index 000000000..a3190310b
--- /dev/null
+++ b/mod/file/views/default/icon/object/file.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * File icon view
+ *
+ * @uses $vars['entity'] The entity the icon represents - uses getIconURL() method
+ * @uses $vars['size'] topbar, tiny, small, medium (default), large, master
+ * @uses $vars['href'] Optional override for link
+ * @uses $vars['img_class'] Optional CSS class added to img
+ * @uses $vars['link_class'] Optional CSS class added to link
+ */
+
+$entity = $vars['entity'];
+
+$sizes = array('small', 'medium', 'large', 'tiny', 'master', 'topbar');
+// Get size
+if (!in_array($vars['size'], $sizes)) {
+ $vars['size'] = "medium";
+}
+
+$title = $entity->title;
+$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false);
+
+$url = $entity->getURL();
+if (isset($vars['href'])) {
+ $url = $vars['href'];
+}
+
+$class = '';
+if (isset($vars['img_class'])) {
+ $class = $vars['img_class'];
+}
+if ($entity->thumbnail) {
+ $class = "class=\"elgg-photo $class\"";
+} else if ($class) {
+ $class = "class=\"$class\"";
+}
+
+$img_src = $entity->getIconURL($vars['size']);
+$img_src = elgg_format_url($img_src);
+$img = "<img $class src=\"$img_src\" alt=\"$title\" />";
+
+if ($url) {
+ $params = array(
+ 'href' => $url,
+ 'text' => $img,
+ 'is_trusted' => true,
+ );
+ if (isset($vars['link_class'])) {
+ $params['class'] = $vars['link_class'];
+ }
+ echo elgg_view('output/url', $params);
+} else {
+ echo $img;
+}
diff --git a/mod/file/views/default/object/file.php b/mod/file/views/default/object/file.php
new file mode 100644
index 000000000..64f19c483
--- /dev/null
+++ b/mod/file/views/default/object/file.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * File renderer.
+ *
+ * @package ElggFile
+ */
+
+$full = elgg_extract('full_view', $vars, FALSE);
+$file = elgg_extract('entity', $vars, FALSE);
+
+if (!$file) {
+ return TRUE;
+}
+
+$owner = $file->getOwnerEntity();
+$container = $file->getContainerEntity();
+$categories = elgg_view('output/categories', $vars);
+$excerpt = elgg_get_excerpt($file->description);
+$mime = $file->mimetype;
+$base_type = substr($mime, 0, strpos($mime,'/'));
+
+$owner_link = elgg_view('output/url', array(
+ 'href' => "file/owner/$owner->username",
+ 'text' => $owner->name,
+ 'is_trusted' => true,
+));
+$author_text = elgg_echo('byline', array($owner_link));
+
+$file_icon = elgg_view_entity_icon($file, 'small');
+
+$date = elgg_view_friendly_time($file->time_created);
+
+$comments_count = $file->countComments();
+//only display if there are commments
+if ($comments_count != 0) {
+ $text = elgg_echo("comments") . " ($comments_count)";
+ $comments_link = elgg_view('output/url', array(
+ 'href' => $file->getURL() . '#file-comments',
+ 'text' => $text,
+ 'is_trusted' => true,
+ ));
+} else {
+ $comments_link = '';
+}
+
+$metadata = elgg_view_menu('entity', array(
+ 'entity' => $vars['entity'],
+ 'handler' => 'file',
+ 'sort_by' => 'priority',
+ 'class' => 'elgg-menu-hz',
+));
+
+$subtitle = "$author_text $date $comments_link $categories";
+
+// do not show the metadata and controls in widget view
+if (elgg_in_context('widgets')) {
+ $metadata = '';
+}
+
+if ($full && !elgg_in_context('gallery')) {
+
+ $extra = '';
+ if (elgg_view_exists("file/specialcontent/$mime")) {
+ $extra = elgg_view("file/specialcontent/$mime", $vars);
+ } else if (elgg_view_exists("file/specialcontent/$base_type/default")) {
+ $extra = elgg_view("file/specialcontent/$base_type/default", $vars);
+ }
+
+ $params = array(
+ 'entity' => $file,
+ 'title' => false,
+ 'metadata' => $metadata,
+ 'subtitle' => $subtitle,
+ );
+ $params = $params + $vars;
+ $summary = elgg_view('object/elements/summary', $params);
+
+ $text = elgg_view('output/longtext', array('value' => $file->description));
+ $body = "$text $extra";
+
+ echo elgg_view('object/elements/full', array(
+ 'entity' => $file,
+ 'icon' => $file_icon,
+ 'summary' => $summary,
+ 'body' => $body,
+ ));
+
+} elseif (elgg_in_context('gallery')) {
+ echo '<div class="file-gallery-item">';
+ echo "<h3>" . $file->title . "</h3>";
+ echo elgg_view_entity_icon($file, 'medium');
+ echo "<p class='subtitle'>$owner_link $date</p>";
+ echo '</div>';
+} else {
+ // brief view
+
+ $params = array(
+ 'entity' => $file,
+ 'metadata' => $metadata,
+ 'subtitle' => $subtitle,
+ 'content' => $excerpt,
+ );
+ $params = $params + $vars;
+ $list_body = elgg_view('object/elements/summary', $params);
+
+ echo elgg_view_image_block($file_icon, $list_body);
+}
diff --git a/mod/file/views/default/river/object/file/create.php b/mod/file/views/default/river/object/file/create.php
new file mode 100644
index 000000000..e8e6142e0
--- /dev/null
+++ b/mod/file/views/default/river/object/file/create.php
@@ -0,0 +1,13 @@
+<?php
+/**
+ * File river view.
+ */
+
+$object = $vars['item']->getObjectEntity();
+$excerpt = strip_tags($object->description);
+$excerpt = elgg_get_excerpt($excerpt);
+
+echo elgg_view('river/elements/layout', array(
+ 'item' => $vars['item'],
+ 'message' => $excerpt,
+)); \ No newline at end of file
diff --git a/mod/file/views/default/widgets/filerepo/content.php b/mod/file/views/default/widgets/filerepo/content.php
new file mode 100644
index 000000000..f3e152de3
--- /dev/null
+++ b/mod/file/views/default/widgets/filerepo/content.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Elgg file widget view
+ *
+ * @package ElggFile
+ */
+
+
+$num = $vars['entity']->num_display;
+
+$options = array(
+ 'type' => 'object',
+ 'subtype' => 'file',
+ 'container_guid' => $vars['entity']->owner_guid,
+ 'limit' => $num,
+ 'full_view' => FALSE,
+ 'pagination' => FALSE,
+);
+$content = elgg_list_entities($options);
+
+echo $content;
+
+if ($content) {
+ $url = "file/owner/" . elgg_get_page_owner_entity()->username;
+ $more_link = elgg_view('output/url', array(
+ 'href' => $url,
+ 'text' => elgg_echo('file:more'),
+ 'is_trusted' => true,
+ ));
+ echo "<span class=\"elgg-widget-more\">$more_link</span>";
+} else {
+ echo elgg_echo('file:none');
+}
diff --git a/mod/file/views/default/widgets/filerepo/edit.php b/mod/file/views/default/widgets/filerepo/edit.php
new file mode 100644
index 000000000..cab35b6ef
--- /dev/null
+++ b/mod/file/views/default/widgets/filerepo/edit.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Elgg file widget edit view
+ *
+ * @package ElggFile
+ */
+
+
+// set default value
+if (!isset($vars['entity']->num_display)) {
+ $vars['entity']->num_display = 4;
+}
+
+$params = array(
+ 'name' => 'params[num_display]',
+ 'value' => $vars['entity']->num_display,
+ 'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20),
+);
+$dropdown = elgg_view('input/dropdown', $params);
+
+?>
+<div>
+ <?php echo elgg_echo('file:num_files'); ?>:
+ <?php echo $dropdown; ?>
+</div>
diff --git a/mod/file/views/rss/file/enclosure.php b/mod/file/views/rss/file/enclosure.php
new file mode 100644
index 000000000..fb4a899d9
--- /dev/null
+++ b/mod/file/views/rss/file/enclosure.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Link to download the file
+ *
+ * @uses $vars['entity']
+ */
+
+if (elgg_instanceof($vars['entity'], 'object', 'file')) {
+ $download_url = elgg_get_site_url() . 'file/download/' . $vars['entity']->getGUID();
+ $size = $vars['entity']->size();
+ $mime_type = $vars['entity']->getMimeType();
+ echo <<<END
+
+ <enclosure url="$download_url" length="$size" type="$mime_type" />";
+END;
+}