From: cash Date: Sun, 6 Feb 2011 22:12:56 +0000 (+0000) Subject: updated the file plugin to use the new icon structure X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=ae6e0093ba62cc6e69f6aa41d4f163de52747418;p=lorea%2Felgg.git 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 --- diff --git a/engine/lib/views.php b/engine/lib/views.php index d76456d83..bc9a6fd14 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -810,6 +810,9 @@ function elgg_view_entity_icon(ElggEntity $entity, $size = 'medium', $vars = arr if (empty($contents)) { $contents = elgg_view("icon/$entity_type/default", $vars); } + if (empty($contents)) { + $contents = elgg_view("icon/default", $vars); + } return $contents; } 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 { diff --git a/views/default/icon/default.php b/views/default/icon/default.php new file mode 100644 index 000000000..a29886064 --- /dev/null +++ b/views/default/icon/default.php @@ -0,0 +1,36 @@ +getURL(); +if (isset($vars['href'])) { + $url = $vars['href']; +} + +$img_src = $entity->getIcon($vars['size']); +$img = ""; + +if ($url) { + echo elgg_view('output/url', array( + 'href' => $url, + 'text' => $img, + )); +} else { + echo $img; +}