From ae6e0093ba62cc6e69f6aa41d4f163de52747418 Mon Sep 17 00:00:00 2001 From: cash Date: Sun, 6 Feb 2011 22:12:56 +0000 Subject: updated the file plugin to use the new icon structure git-svn-id: http://code.elgg.org/elgg/trunk@8051 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/file/start.php | 100 +++++++++++++++++---- mod/file/views/default/file/icon.php | 37 -------- .../default/file/icon/application/default.php | 8 -- .../views/default/file/icon/application/excel.php | 8 -- .../views/default/file/icon/application/msword.php | 8 -- .../views/default/file/icon/application/pdf.php | 8 -- .../default/file/icon/application/powerpoint.php | 8 -- .../default/file/icon/application/vnd.ms-excel.php | 6 -- .../file/icon/application/vnd.ms-powerpoint.php | 6 -- .../application/vnd.oasis.opendocument.text.php | 8 -- .../views/default/file/icon/application/x-gzip.php | 6 -- .../file/icon/application/x-rar-compressed.php | 6 -- .../default/file/icon/application/x-stuffit.php | 6 -- .../views/default/file/icon/application/zip.php | 6 -- mod/file/views/default/file/icon/archive.php | 8 -- mod/file/views/default/file/icon/audio.php | 8 -- mod/file/views/default/file/icon/audio/default.php | 6 -- mod/file/views/default/file/icon/default.php | 16 ---- mod/file/views/default/file/icon/document.php | 8 -- mod/file/views/default/file/icon/text/default.php | 6 -- .../views/default/file/icon/text/directory.php | 8 -- mod/file/views/default/file/icon/text/v-card.php | 6 -- mod/file/views/default/file/icon/video.php | 8 -- mod/file/views/default/file/icon/video/default.php | 6 -- mod/file/views/default/object/file.php | 9 +- 25 files changed, 86 insertions(+), 224 deletions(-) delete mode 100644 mod/file/views/default/file/icon.php delete mode 100644 mod/file/views/default/file/icon/application/default.php delete mode 100644 mod/file/views/default/file/icon/application/excel.php delete mode 100644 mod/file/views/default/file/icon/application/msword.php delete mode 100644 mod/file/views/default/file/icon/application/pdf.php delete mode 100644 mod/file/views/default/file/icon/application/powerpoint.php delete mode 100644 mod/file/views/default/file/icon/application/vnd.ms-excel.php delete mode 100644 mod/file/views/default/file/icon/application/vnd.ms-powerpoint.php delete mode 100644 mod/file/views/default/file/icon/application/vnd.oasis.opendocument.text.php delete mode 100644 mod/file/views/default/file/icon/application/x-gzip.php delete mode 100644 mod/file/views/default/file/icon/application/x-rar-compressed.php delete mode 100644 mod/file/views/default/file/icon/application/x-stuffit.php delete mode 100644 mod/file/views/default/file/icon/application/zip.php delete mode 100644 mod/file/views/default/file/icon/archive.php delete mode 100644 mod/file/views/default/file/icon/audio.php delete mode 100644 mod/file/views/default/file/icon/audio/default.php delete mode 100644 mod/file/views/default/file/icon/default.php delete mode 100644 mod/file/views/default/file/icon/document.php delete mode 100644 mod/file/views/default/file/icon/text/default.php delete mode 100644 mod/file/views/default/file/icon/text/directory.php delete mode 100644 mod/file/views/default/file/icon/text/v-card.php delete mode 100644 mod/file/views/default/file/icon/video.php delete mode 100644 mod/file/views/default/file/icon/video/default.php (limited to 'mod') diff --git a/mod/file/start.php b/mod/file/start.php index 4eb67cd32..360f64d1f 100644 --- a/mod/file/start.php +++ b/mod/file/start.php @@ -31,8 +31,9 @@ function file_init() { // Add a new file widget elgg_register_widget_type('filerepo', elgg_echo("file"), elgg_echo("file:widget:description")); - // Register a URL handler for files - register_entity_url_handler('file_url', 'object', 'file'); + // Register URL handlers for files + register_entity_url_handler('file_url_override', 'object', 'file'); + 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')); @@ -144,8 +145,8 @@ function file_notify_message($hook, $entity_type, $returnvalue, $params) { } /** -* Add a menu item to the user ownerblock -*/ + * Add a menu item to the user ownerblock + */ function file_owner_block_menu($hook, $type, $return, $params) { if (elgg_instanceof($params['entity'], 'user')) { $url = "pg/file/owner/{$params['entity']->username}"; @@ -256,6 +257,85 @@ function get_filetype_cloud($owner_guid = "", $friends = false) { 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 "pg/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) { + return "mod/file/thumbnail.php?file_guid=$file->guid&size=$size"; + } + + $mapping = array( + 'application/excel' => 'excel', + 'application/msword' => 'word', + 'application/pdf' => 'pdf', + 'application/powerpoint' => 'ppt', + 'application/vnd.ms-excel' => 'excel', + 'application/vnd.ms-powerpoint' => 'ppt', + 'application/vnd.oasis.opendocument.text' => 'openoffice', + '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 { + $exit = ''; + } + + $url = "mod/file/graphics/icons/{$type}{$ext}.gif"; + $url = elgg_trigger_plugin_hook('file:icon:url', 'override', $params, $url); + return $url; + } +} + /** * Register file as an embed type. * @@ -320,15 +400,3 @@ function file_embed_get_upload_sections($hook, $type, $value, $params) { return $value; } - -/** - * Populates the ->getUrl() method for file objects - * - * @param ElggEntity $entity File entity - * @return string File URL - */ -function file_url($entity) { - $title = $entity->title; - $title = elgg_get_friendly_title($title); - return "pg/file/view/" . $entity->getGUID() . "/" . $title; -} diff --git a/mod/file/views/default/file/icon.php b/mod/file/views/default/file/icon.php deleted file mode 100644 index 391afd0c8..000000000 --- a/mod/file/views/default/file/icon.php +++ /dev/null @@ -1,37 +0,0 @@ -"; -} else { - $base_type = substr($mime, 0, strpos($mime, '/')); - if ($mime && elgg_view_exists("file/icon/$mime")) { - $icon = elgg_view("file/icon/{$mime}", $vars); - } else if ($mime && elgg_view_exists("file/icon/$base_type/default")) { - $icon = elgg_view("file/icon/$base_type/default", $vars); - } else { - $icon = elgg_view('file/icon/default', $vars); - } -} - -echo $icon; diff --git a/mod/file/views/default/file/icon/application/default.php b/mod/file/views/default/file/icon/application/default.php deleted file mode 100644 index 6a7c7e13c..000000000 --- a/mod/file/views/default/file/icon/application/default.php +++ /dev/null @@ -1,8 +0,0 @@ -"; diff --git a/mod/file/views/default/file/icon/document.php b/mod/file/views/default/file/icon/document.php deleted file mode 100644 index 55a71394e..000000000 --- a/mod/file/views/default/file/icon/document.php +++ /dev/null @@ -1,8 +0,0 @@ - $mime, - 'thumbnail' => $file->thumbnail, - 'file_guid' => $file->guid, - 'size' => 'small' -)); +$file_icon = elgg_view_entity_icon($file, 'small'); $tags = elgg_view('output/tags', array('tags' => $file->tags)); $date = elgg_view_friendly_time($file->time_created); @@ -102,7 +97,7 @@ HTML; } elseif (elgg_in_context('gallery')) { echo ''; } else { -- cgit v1.2.3