aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-30 12:14:22 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-30 12:14:22 +0000
commitc1f8c6378f37e2cac408731b07008a345c3ced8f (patch)
tree9073a80688d489f56fa2240f9274598d1ab58d32
parentc0412aa41a1efe0be21bdd6807280b6a55005053 (diff)
downloadelgg-c1f8c6378f37e2cac408731b07008a345c3ced8f.tar.gz
elgg-c1f8c6378f37e2cac408731b07008a345c3ced8f.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* First draft file upload git-svn-id: https://code.elgg.org/elgg/trunk@578 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--mod/file/actions/upload.php40
-rw-r--r--mod/file/friends.php34
-rw-r--r--mod/file/index.php27
-rw-r--r--mod/file/languages/en.php44
-rw-r--r--mod/file/start.php127
-rw-r--r--mod/file/upload.php13
-rw-r--r--mod/file/views/default/file/file.php36
-rw-r--r--mod/file/views/default/file/footer.php3
-rw-r--r--mod/file/views/default/file/upload.php25
-rw-r--r--mod/file/world.php31
10 files changed, 380 insertions, 0 deletions
diff --git a/mod/file/actions/upload.php b/mod/file/actions/upload.php
new file mode 100644
index 000000000..881470bc7
--- /dev/null
+++ b/mod/file/actions/upload.php
@@ -0,0 +1,40 @@
+<?php
+ /**
+ * Elgg file browser uploader action
+ *
+ * @package ElggFile
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ global $CONFIG;
+
+ // Get variables
+ $title = get_input("title");
+ $desc = get_input("description");
+ $tags = get_input("tags");
+
+ // Extract file from, save to default filestore (for now)
+ $prefix = "/file/";
+ $file = new ElggFile();
+ $file->setFilename($_FILES['upload']['name']);
+
+ $file->open("write");
+ $file->write(get_uploaded_file('upload'));
+ $file->close();
+
+ $file->title = $title;
+ $file->description = $desc;
+
+ $result = $file->save();
+
+ // Save tags
+ $tags = explode(",", $tags);
+ $file->tag = $tags;
+
+ if ($result)
+ system_message(elgg_echo("file:saved"));
+ else
+ system_message(elgg_echo("file:uploadfailed"));
+?> \ No newline at end of file
diff --git a/mod/file/friends.php b/mod/file/friends.php
new file mode 100644
index 000000000..a58912485
--- /dev/null
+++ b/mod/file/friends.php
@@ -0,0 +1,34 @@
+<?php
+ /**
+ * Elgg file browser
+ *
+ * @package ElggFile
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+ $limit = get_input("limit", 10);
+ $offset = get_input("offset", 0);
+
+ // Get objects of friends
+ $owners = array();
+ $users = get_entities_from_relationship("friend", page_owner(), false, "", "", 0, "time_created desc", $limit, $offset);
+ if ($users)
+ {
+ foreach ($users as $user)
+ $owners[] = $user->getOwner();
+ $objects = get_entities("object","file", $owners, "time_created desc", $limit, $offset);
+ }
+
+ // Draw page
+ $body .= file_draw($objects);
+
+ // Draw footer
+ $body .= file_draw_footer($limit, $offset);
+
+ // Finally draw the page
+ page_draw(sprintf(elgg_echo("file:friends"),$_SESSION['user']->name), $body);
+?> \ No newline at end of file
diff --git a/mod/file/index.php b/mod/file/index.php
new file mode 100644
index 000000000..577233276
--- /dev/null
+++ b/mod/file/index.php
@@ -0,0 +1,27 @@
+<?php
+ /**
+ * Elgg file browser
+ *
+ * @package ElggFile
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+ $limit = get_input("limit", 10);
+ $offset = get_input("offset", 0);
+
+ // Get objects
+ $objects = get_entities("object","file", page_owner(), "time_created desc", $limit, $offset);
+
+ // Draw page
+ $body .= file_draw($objects);
+
+ // Draw footer
+ $body .= file_draw_footer($limit, $offset);
+
+ // Finally draw the page
+ page_draw(sprintf(elgg_echo("file:yours"),$_SESSION['user']->name), $body);
+?> \ No newline at end of file
diff --git a/mod/file/languages/en.php b/mod/file/languages/en.php
new file mode 100644
index 000000000..451680430
--- /dev/null
+++ b/mod/file/languages/en.php
@@ -0,0 +1,44 @@
+<?php
+ /**
+ * Elgg file plugin language pack
+ *
+ * @package ElggFile
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ $english = array(
+
+ /**
+ * Menu items and titles
+ */
+
+ 'file' => "Files",
+ 'file:yours' => "%s's files",
+ 'file:friends' => "%s's friend's files",
+ 'file:all' => "All files",
+
+ 'file:upload' => "Upload a file",
+
+ 'file:file' => "File",
+ 'file:title' => "Title",
+ 'file:desc' => "Description",
+ 'file:tags' => "Tags",
+
+ /**
+ * Status messages
+ */
+
+ 'file:saved' => "Your file was successfully saved.",
+
+ /**
+ * Error messages
+ */
+
+ 'file:uploadfailed' => "Sorry; we could not save your file.",
+
+ );
+
+ add_translation("en",$english);
+?> \ No newline at end of file
diff --git a/mod/file/start.php b/mod/file/start.php
new file mode 100644
index 000000000..98ee4ff46
--- /dev/null
+++ b/mod/file/start.php
@@ -0,0 +1,127 @@
+<?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
+ ));
+ }
+
+ /**
+ * 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");
+?> \ No newline at end of file
diff --git a/mod/file/upload.php b/mod/file/upload.php
new file mode 100644
index 000000000..d0e0a9901
--- /dev/null
+++ b/mod/file/upload.php
@@ -0,0 +1,13 @@
+<?php
+ /**
+ * Elgg file browser uploader
+ *
+ * @package ElggFile
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ // Render the file upload page
+ page_draw(elgg_echo("file:upload"), elgg_view("file/upload", NULL));
+?> \ No newline at end of file
diff --git a/mod/file/views/default/file/file.php b/mod/file/views/default/file/file.php
new file mode 100644
index 000000000..1b2beae53
--- /dev/null
+++ b/mod/file/views/default/file/file.php
@@ -0,0 +1,36 @@
+<?php
+ /**
+ * Elgg file browser.
+ * File renderer.
+ *
+ * @package ElggFile
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ global $CONFIG;
+
+ $tags = $vars['tags'];
+ $title = $vars['title'];
+ $desc = $vars['description'];
+
+?>
+<div class="file">
+ <table width="100%">
+ <tr>
+ <td valign="top">
+ <div class="file_icon">
+ </div>
+ </td>
+ <td valign="top">
+ <div class="title"><?php echo $title; ?></div>
+ <div class="description"><?php echo $desc; ?></div>
+ <div class="tags"><?php
+ foreach ($tags as $tag)
+ echo "<a href=\"" . $CONFIG->wwwroot . "pg/file/". $_SESSION['user']->username . "/world/?tag=$tag\">$tag</a> ";
+ ?></div>
+ </td>
+ </tr>
+ </table>
+</div>
diff --git a/mod/file/views/default/file/footer.php b/mod/file/views/default/file/footer.php
new file mode 100644
index 000000000..15c5adc7f
--- /dev/null
+++ b/mod/file/views/default/file/footer.php
@@ -0,0 +1,3 @@
+<?php
+
+?> \ No newline at end of file
diff --git a/mod/file/views/default/file/upload.php b/mod/file/views/default/file/upload.php
new file mode 100644
index 000000000..d318b85a3
--- /dev/null
+++ b/mod/file/views/default/file/upload.php
@@ -0,0 +1,25 @@
+<?php
+ /**
+ * Elgg file browser uploader
+ *
+ * @package ElggFile
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ global $CONFIG;
+
+?>
+<form action="<?php echo $vars['url']; ?>action/file/upload" enctype="multipart/form-data" method="post">
+
+ <table>
+ <tr><td><?php echo elgg_echo("file:file");?>:</td><td><div id="file"><input type="file" name="upload" /></div></td></tr>
+ <tr><td><?php echo elgg_echo("file:title");?>:</td><td><div id="title"><input type="text" name="title" size="49" /></div></td></tr>
+ <tr><td valign="top"><?php echo elgg_echo("file:desc");?>:</td><td><div id="description"><textarea name="description" cols="50" rows="10"></textarea></div></td></tr>
+ <tr><td valign="top"><?php echo elgg_echo("file:tags");?>:</td><td><div id="tags"><textarea name="tags" cols="50"></textarea></div></td></tr>
+ </table>
+
+ <input type="submit" name="Upload" value="Upload" />
+
+</form> \ No newline at end of file
diff --git a/mod/file/world.php b/mod/file/world.php
new file mode 100644
index 000000000..ffb689050
--- /dev/null
+++ b/mod/file/world.php
@@ -0,0 +1,31 @@
+<?php
+ /**
+ * Elgg file browser
+ *
+ * @package ElggFile
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+
+ $limit = get_input("limit", 10);
+ $offset = get_input("offset", 0);
+ $tag = get_input("tag");
+
+ // Get objects
+ if ($tag!="")
+ $objects = get_entities_from_metadata("tag", $tag, "object", "file", $limit, $offset);
+ else
+ $objects = get_entities("object","file", "", "time_created desc", $limit, $offset);
+
+ // Draw page
+ $body .= file_draw($objects);
+
+ // Draw footer
+ $body .= file_draw_footer($limit, $offset);
+
+ // Finally draw the page
+ page_draw(sprintf(elgg_echo("file:yours"),$_SESSION['user']->name), $body);
+?> \ No newline at end of file