diff options
Diffstat (limited to 'mod/file')
-rw-r--r-- | mod/file/actions/file/upload.php | 13 | ||||
-rw-r--r-- | mod/file/download.php | 29 | ||||
-rw-r--r-- | mod/file/languages/en.php | 9 | ||||
-rw-r--r-- | mod/file/manifest.xml | 9 | ||||
-rw-r--r-- | mod/file/pages/file/download.php | 38 | ||||
-rw-r--r-- | mod/file/pages/file/friends.php | 3 | ||||
-rw-r--r-- | mod/file/pages/file/owner.php | 3 | ||||
-rw-r--r-- | mod/file/pages/file/search.php | 7 | ||||
-rw-r--r-- | mod/file/pages/file/view.php | 2 | ||||
-rw-r--r-- | mod/file/pages/file/world.php | 3 | ||||
-rw-r--r-- | mod/file/start.php | 78 | ||||
-rw-r--r-- | mod/file/views/default/embed/file/content.php | 61 | ||||
-rw-r--r-- | mod/file/views/default/embed/file_upload/content.php | 13 | ||||
-rw-r--r-- | mod/file/views/default/file/group_module.php | 2 | ||||
-rw-r--r-- | mod/file/views/default/icon/object/file.php | 25 | ||||
-rw-r--r-- | mod/file/views/default/object/file.php | 28 | ||||
-rw-r--r-- | mod/file/views/default/river/object/file/create.php | 2 | ||||
-rw-r--r-- | mod/file/views/default/widgets/filerepo/content.php | 1 | ||||
-rw-r--r-- | mod/file/views/rss/file/enclosure.php | 16 | ||||
-rw-r--r-- | mod/file/views/rss/object/file.php | 21 |
20 files changed, 199 insertions, 164 deletions
diff --git a/mod/file/actions/file/upload.php b/mod/file/actions/file/upload.php index 88a01745d..3edc87952 100644 --- a/mod/file/actions/file/upload.php +++ b/mod/file/actions/file/upload.php @@ -19,6 +19,11 @@ if ($container_guid == 0) { 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; @@ -29,7 +34,6 @@ if ($guid > 0) { 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); @@ -90,10 +94,11 @@ if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) { $filestorename = elgg_strtolower(time().$_FILES['upload']['name']); } - $file->setFilename($prefix.$filestorename); - $file->setMimeType($_FILES['upload']['type']); + $mime_type = $file->detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']); + $file->setFilename($prefix . $filestorename); + $file->setMimeType($mime_type); $file->originalfilename = $_FILES['upload']['name']; - $file->simpletype = file_get_simple_type($_FILES['upload']['type']); + $file->simpletype = file_get_simple_type($mime_type); // Open the file to guarantee the directory exists $file->open("write"); diff --git a/mod/file/download.php b/mod/file/download.php index 8e0287a1e..b2acdffec 100644 --- a/mod/file/download.php +++ b/mod/file/download.php @@ -9,31 +9,4 @@ require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); // Get the guid $file_guid = get_input("file_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) { - header("Content-Disposition: inline; filename=\"$filename\""); -} else { - header("Content-Disposition: attachment; filename=\"$filename\""); -} - -ob_clean(); -flush(); -readfile($file->getFilenameOnFilestore()); -exit; +forward("file/download/$file_guid"); diff --git a/mod/file/languages/en.php b/mod/file/languages/en.php index 72b198d54..278076927 100644 --- a/mod/file/languages/en.php +++ b/mod/file/languages/en.php @@ -35,6 +35,9 @@ $english = array( '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', @@ -75,6 +78,8 @@ $english = array( 'item:object:file' => 'Files', + 'file:newupload' => 'A new file has been uploaded', + /** * Embed media **/ @@ -93,12 +98,12 @@ $english = array( * Error messages */ - 'file:none' => "No files uploaded.", + '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 loading the file", + 'file:cannotload' => "There was an error uploading the file", 'file:nofile' => "You must select a file", ); diff --git a/mod/file/manifest.xml b/mod/file/manifest.xml index aac9c3f6b..26282a8e3 100644 --- a/mod/file/manifest.xml +++ b/mod/file/manifest.xml @@ -2,18 +2,17 @@ <plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> <name>File</name> <author>Core developers</author> - <version>1.8</version> + <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 Public License version 2</license> + <license>GNU General Public License version 2</license> <requires> - <type>elgg_version</type> - <version>2010030101</version> + <type>elgg_release</type> + <version>1.8</version> </requires> - <admin_interface>simple</admin_interface> <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..00e6d500e --- /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) { + 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/friends.php b/mod/file/pages/file/friends.php index 0b351efaf..f504bdc1f 100644 --- a/mod/file/pages/file/friends.php +++ b/mod/file/pages/file/friends.php @@ -6,6 +6,9 @@ */ $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"); diff --git a/mod/file/pages/file/owner.php b/mod/file/pages/file/owner.php index 4e2ec89d4..fb87af1b2 100644 --- a/mod/file/pages/file/owner.php +++ b/mod/file/pages/file/owner.php @@ -9,6 +9,9 @@ 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); diff --git a/mod/file/pages/file/search.php b/mod/file/pages/file/search.php index 569657fd4..402a28933 100644 --- a/mod/file/pages/file/search.php +++ b/mod/file/pages/file/search.php @@ -5,7 +5,12 @@ * @package ElggFile */ -$page_owner_guid = (int)get_input('page_owner', null); +$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); } diff --git a/mod/file/pages/file/view.php b/mod/file/pages/file/view.php index 50c55a74f..a571c9d68 100644 --- a/mod/file/pages/file/view.php +++ b/mod/file/pages/file/view.php @@ -28,7 +28,7 @@ $content .= elgg_view_comments($file); elgg_register_menu_item('title', array( 'name' => 'download', 'text' => elgg_echo('file:download'), - 'href' => "mod/file/download.php?file_guid=$file->guid", + 'href' => "file/download/$file->guid", 'link_class' => 'elgg-button elgg-button-action', )); diff --git a/mod/file/pages/file/world.php b/mod/file/pages/file/world.php index e438ca2f0..770dfd6e8 100644 --- a/mod/file/pages/file/world.php +++ b/mod/file/pages/file/world.php @@ -19,6 +19,9 @@ $content = elgg_list_entities(array( 'limit' => $limit, 'full_view' => FALSE )); +if (!$content) { + $content = elgg_echo('file:none'); +} $sidebar = file_get_type_cloud(); $sidebar = elgg_view('file/sidebar'); diff --git a/mod/file/start.php b/mod/file/start.php index 749d7a519..e15a9ad61 100644 --- a/mod/file/start.php +++ b/mod/file/start.php @@ -22,6 +22,9 @@ function file_init() { // 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'); @@ -61,19 +64,26 @@ function file_init() { $item = ElggMenuItem::factory(array( 'name' => 'file', 'text' => elgg_echo('file'), - 'href' => '#', - 'section' => 'select' + 'priority' => 10, + 'data' => array( + 'options' => array( + 'type' => 'object', + 'subtype' => 'file', + ), + ), )); - elgg_register_menu_item('embed:sections', $item); + elgg_register_menu_item('embed', $item); $item = ElggMenuItem::factory(array( 'name' => 'file_upload', 'text' => elgg_echo('file:upload'), - 'href' => '#', - 'section' => 'upload' + 'priority' => 100, + 'data' => array( + 'view' => 'embed/file_upload/content', + ), )); - elgg_register_menu_item('embed:sections', $item); + elgg_register_menu_item('embed', $item); } /** @@ -86,11 +96,12 @@ function file_init() { * 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 NULL + * @return bool */ function file_page_handler($page) { @@ -103,9 +114,11 @@ function file_page_handler($page) { $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 'view': @@ -120,25 +133,64 @@ function file_page_handler($page) { 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': - default: + 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 unknown_type $hook - * @param unknown_type $entity_type - * @param unknown_type $returnvalue - * @param unknown_type $params + * @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']; @@ -337,7 +389,7 @@ function file_icon_url_override($hook, $type, $returnvalue, $params) { if ($size == 'large') { $ext = '_lrg'; } else { - $exit = ''; + $ext = ''; } $url = "mod/file/graphics/icons/{$type}{$ext}.gif"; diff --git a/mod/file/views/default/embed/file/content.php b/mod/file/views/default/embed/file/content.php deleted file mode 100644 index 865a158a7..000000000 --- a/mod/file/views/default/embed/file/content.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php -/** - * List files available for upload - */ - -$active_section = elgg_extract('active_section', $vars); - -$options = array( - 'owner_guid' => elgg_get_logged_in_user_guid(), - 'type_subtype_pair' => array('object' => 'file'), - 'count' => true -); - -$count = elgg_get_entities($options); - -if ($count) { - echo "<div class='embed_modal_$active_section'>"; - - unset($options['count']); - $items = elgg_get_entities($options); - - foreach ($items as $item) { - - // different entity types have different title attribute names. - $title = isset($item->name) ? $item->name : $item->title; - // don't let it be too long - $title = elgg_get_excerpt($title); - - $author_text = elgg_echo('byline', array($owner->name)); - $date = elgg_view_friendly_time($item->time_created); - - $subtitle = "$author_text $date"; - - $icon = "<img src=\"{$item->getIconURL($icon_size)}\" />" . htmlentities($title, ENT_QUOTES, 'UTF-8'); - - $embed_code = elgg_view('output/url', array( - 'href' => $item->getURL(), - 'title' => $title, - 'text' => $icon, - 'encode_text' => FALSE - )); - - $item_icon = elgg_view_entity_icon($item, $icon_size); - - $params = array( - 'title' => $title, - 'entity' => $item, - 'subtitle' => $subtitle, - 'tags' => FALSE, - ); - $list_body = elgg_view('object/elements/summary', $params); - - // @todo JS 1.8: is this approach better than inline js? - echo "<div class=\"embed_data\" id=\"embed_{$item->getGUID()}\">" . elgg_view_image_block($item_icon, $list_body) . '</div>'; - echo "<script type=\"text/javascript\"> - $('#embed_{$item->getGUID()}').data('embed_code', " . json_encode($embed_code) . "); - </script>"; - } - - echo '</div>'; -}
\ No newline at end of file diff --git a/mod/file/views/default/embed/file_upload/content.php b/mod/file/views/default/embed/file_upload/content.php index 13c18f745..4d3db0d97 100644 --- a/mod/file/views/default/embed/file_upload/content.php +++ b/mod/file/views/default/embed/file_upload/content.php @@ -5,11 +5,12 @@ $form_vars = array( 'enctype' => 'multipart/form-data', - 'class' => 'elgg-form', + 'class' => 'elgg-form-embed', ); -$upload_content = elgg_view_form('file/upload', $form_vars); +echo elgg_view_form('file/upload', $form_vars); -echo "<div class='mbm'>" . elgg_echo('embed:upload_type') . "$input</div>"; -echo "<div class='embed-upload'>"; -echo $upload_content; -echo "</div>";
\ No newline at end of file +// 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/group_module.php b/mod/file/views/default/file/group_module.php index c37b13927..ad6c58dbb 100644 --- a/mod/file/views/default/file/group_module.php +++ b/mod/file/views/default/file/group_module.php @@ -12,6 +12,7 @@ if ($group->file_enable == "no") { $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'); @@ -33,6 +34,7 @@ if (!$content) { $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( diff --git a/mod/file/views/default/icon/object/file.php b/mod/file/views/default/icon/object/file.php index 6357d418f..a3190310b 100644 --- a/mod/file/views/default/icon/object/file.php +++ b/mod/file/views/default/icon/object/file.php @@ -2,9 +2,11 @@ /** * 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['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']; @@ -16,6 +18,7 @@ if (!in_array($vars['size'], $sizes)) { } $title = $entity->title; +$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false); $url = $entity->getURL(); if (isset($vars['href'])) { @@ -23,8 +26,13 @@ if (isset($vars['href'])) { } $class = ''; +if (isset($vars['img_class'])) { + $class = $vars['img_class']; +} if ($entity->thumbnail) { - $class = 'class="elgg-photo"'; + $class = "class=\"elgg-photo $class\""; +} else if ($class) { + $class = "class=\"$class\""; } $img_src = $entity->getIconURL($vars['size']); @@ -32,10 +40,15 @@ $img_src = elgg_format_url($img_src); $img = "<img $class src=\"$img_src\" alt=\"$title\" />"; if ($url) { - echo elgg_view('output/url', array( + $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 index 95e190d35..1db9863c9 100644 --- a/mod/file/views/default/object/file.php +++ b/mod/file/views/default/object/file.php @@ -19,11 +19,10 @@ $excerpt = elgg_get_excerpt($file->description); $mime = $file->mimetype; $base_type = substr($mime, 0, strpos($mime,'/')); -$body = elgg_view('output/longtext', array('value' => $file->description)); - $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)); @@ -39,6 +38,7 @@ if ($comments_count != 0) { $comments_link = elgg_view('output/url', array( 'href' => $file->getURL() . '#file-comments', 'text' => $text, + 'is_trusted' => true, )); } else { $comments_link = ''; @@ -51,7 +51,7 @@ $metadata = elgg_view_menu('entity', array( 'class' => 'elgg-menu-hz', )); -$subtitle = "$author_text $date $categories $comments_link"; +$subtitle = "$author_text $date $comments_link $categories"; // do not show the metadata and controls in widget view if (elgg_in_context('widgets')) { @@ -67,27 +67,25 @@ if ($full && !elgg_in_context('gallery')) { $extra = elgg_view("file/specialcontent/$base_type/default", $vars); } - $header = elgg_view_title($file->title); - $params = array( 'entity' => $file, - 'title' => false, 'metadata' => $metadata, 'subtitle' => $subtitle, 'tags' => $tags, ); $params = $params + $vars; - $list_body = elgg_view('object/elements/summary', $params); + $summary = elgg_view('object/elements/summary', $params); - $file_info = elgg_view_image_block($file_icon, $list_body); + $text = elgg_view('output/longtext', array('value' => $file->description)); + $body = "$text $extra"; - echo <<<HTML -$file_info -<div class="file elgg-content"> - $body - $extra -</div> -HTML; + echo elgg_view('object/elements/full', array( + 'entity' => $file, + 'title' => false, + 'icon' => $file_icon, + 'summary' => $summary, + 'body' => $body, + )); } elseif (elgg_in_context('gallery')) { echo '<div class="file-gallery-item">'; diff --git a/mod/file/views/default/river/object/file/create.php b/mod/file/views/default/river/object/file/create.php index dad629120..e8e6142e0 100644 --- a/mod/file/views/default/river/object/file/create.php +++ b/mod/file/views/default/river/object/file/create.php @@ -7,7 +7,7 @@ $object = $vars['item']->getObjectEntity(); $excerpt = strip_tags($object->description); $excerpt = elgg_get_excerpt($excerpt); -echo elgg_view('river/item', array( +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 index 4288b9e56..f3e152de3 100644 --- a/mod/file/views/default/widgets/filerepo/content.php +++ b/mod/file/views/default/widgets/filerepo/content.php @@ -25,6 +25,7 @@ if ($content) { $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 { 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; +} diff --git a/mod/file/views/rss/object/file.php b/mod/file/views/rss/object/file.php deleted file mode 100644 index a0660d6c8..000000000 --- a/mod/file/views/rss/object/file.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php -/** - * Elgg RSS file object view - * - * @package ElggFile - * @subpackage Core - */ -$title = $vars['entity']->title; -if (empty($title)) { - $title = elgg_get_excerpt($vars['entity']->description, 32); -} -?> - -<item> - <guid isPermaLink='true'><?php echo $vars['entity']->getURL(); ?></guid> - <pubDate><?php echo date("r", $vars['entity']->time_created) ?></pubDate> - <link><?php echo $vars['entity']->getURL(); ?></link> - <title><![CDATA[<?php echo $title; ?>]]></title> - <description><![CDATA[<?php echo (autop($vars['entity']->description)); ?>]]></description> - <enclosure url="<?php echo elgg_get_site_url(); ?>mod/file/download.php?file_guid=<?php echo $vars['entity']->getGUID(); ?>" length="<?php echo $vars['entity']->size(); ?>" type="<?php echo $vars['entity']->getMimeType(); ?>" /> -</item> |