From 24ef7261d523155ee1c58e8297516e726b4ce80b Mon Sep 17 00:00:00 2001 From: cash Date: Fri, 31 Dec 2010 14:47:38 +0000 Subject: a little standardization of the file plugin code git-svn-id: http://code.elgg.org/elgg/trunk@7789 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/file/download.php | 73 ++++---- mod/file/index.php | 2 +- mod/file/search.php | 201 ++++++++++----------- mod/file/thumbnail.php | 7 +- mod/file/views/default/file/upload.php | 66 +++---- .../views/default/widgets/filerepo/content.php | 1 - mod/file/views/rss/object/file.php | 41 ++--- 7 files changed, 190 insertions(+), 201 deletions(-) (limited to 'mod') diff --git a/mod/file/download.php b/mod/file/download.php index 55c5dc697..d7625901e 100644 --- a/mod/file/download.php +++ b/mod/file/download.php @@ -1,41 +1,42 @@ 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\""); +// Get the file +$file = get_entity($file_guid); - $contents = $file->grabFile(); - $splitString = str_split($contents, 8192); - foreach($splitString as $chunk) - echo $chunk; - exit; +if ($file) { + $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 { - register_error(elgg_echo("file:downloadfailed")); - forward(); - } \ No newline at end of file + header("Content-Disposition: attachment; filename=\"$filename\""); + } + + $contents = $file->grabFile(); + $splitString = str_split($contents, 8192); + foreach ($splitString as $chunk) { + echo $chunk; + } + exit; +} else { + register_error(elgg_echo("file:downloadfailed")); + forward(); +} \ No newline at end of file diff --git a/mod/file/index.php b/mod/file/index.php index b55f5c835..3706f65b3 100644 --- a/mod/file/index.php +++ b/mod/file/index.php @@ -1,6 +1,6 @@ $friend) - $owner_guid[$key] = (int) $friend->getGUID(); - } else { - $owner_guid = array(); - } - } else { - $owner_guid = get_input('owner_guid',0); - if (substr_count($owner_guid,',')) { - $owner_guid = explode(",",$owner_guid); - } - } - $page_owner = get_input('page_owner',0); - if ($page_owner) { - set_page_owner($page_owner); - } else { - if ($friends) { - set_page_owner($friends); - } else { - if ($owner_guid > 0 && !is_array($owner_guid)) - set_page_owner($owner_guid); - } - } - - if (is_callable('group_gatekeeper')) group_gatekeeper(); - - if (empty($tag)) { - $title = elgg_echo('file:type:all'); - $area2 = elgg_view_title(elgg_echo('file:type:all')); - $area2 = elgg_view('page/elements/content_header', array('context' => "everyone", 'type' => 'file')); - } else { - $title = elgg_echo('searchtitle',array($tag)); - if (is_array($owner_guid)) { - //$area2 = elgg_view_title(elgg_echo("file:friends:type:" . $tag)); - $area2 = elgg_view('page/elements/content_header', array('context' => "friends", 'type' => 'file')); - } else if (elgg_get_page_owner_guid() && elgg_get_page_owner_guid() != get_loggedin_userid()) { - //$area2 = elgg_view_title(elgg_echo("file:user:type:" . $tag,array(elgg_get_page_owner()->name))); - $area2 = elgg_view('page/elements/content_header', array('context' => "mine", 'type' => 'file')); - } else{ - //$area2 = elgg_view_title(elgg_echo("file:type:" . $tag)); - $area2 = elgg_view('page/elements/content_header', array('context' => "everyone", 'type' => 'file')); - } - } - if ($friends) { - $area1 = get_filetype_cloud($friends,true); - } else if ($owner_guid) { - $area1 = get_filetype_cloud($owner_guid); - } else { - $area1 = get_filetype_cloud(); - } - - elgg_push_context('search'); - - $offset = (int)get_input('offset', 0); - $limit = 10; - - if ($listtype == "gallery") { - $limit = 12; - } - - if (!empty($tag)) { - $params = array( - 'metadata_name' => $md_type, - 'metadata_value' => $tag, - 'types' => 'object', - 'subtypes' => 'file', - 'owner_guid' => $owner_guid, - 'limit' => $limit, - ); - $area2 .= elgg_list_entities_from_metadata($params); - } else { - $area2 .= elgg_list_entities(array('types' => 'object', 'subtypes' => 'file', 'owner_guid' => $owner_guid, 'limit' => $limit, 'offset' => $offset)); - } - - elgg_pop_context(); - - $content = "
".$area1.$area2."
"; - - $body = elgg_view_layout('one_column_with_sidebar', array('content' => $content)); - - echo elgg_view_page($title, $body); - -?> \ No newline at end of file +/** + * List files by type + * + * @package ElggFile + + */ +// Load Elgg engine +require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); + + +// Get input +$md_type = 'simpletype'; +$tag = get_input('tag'); +$listtype = get_input('listtype'); + +$friends = (int) get_input('friends_guid', 0); +if ($friends) { + if ($owner_guid = get_user_friends($user_guid, "", 999999, 0)) { + foreach ($owner_guid as $key => $friend) + $owner_guid[$key] = (int) $friend->getGUID(); + } else { + $owner_guid = array(); + } +} else { + $owner_guid = get_input('owner_guid', 0); + if (substr_count($owner_guid, ',')) { + $owner_guid = explode(",", $owner_guid); + } +} +$page_owner = get_input('page_owner', 0); +if ($page_owner) { + set_page_owner($page_owner); +} else { + if ($friends) { + set_page_owner($friends); + } else { + if ($owner_guid > 0 && !is_array($owner_guid)) + set_page_owner($owner_guid); + } +} + +if (is_callable('group_gatekeeper')) + group_gatekeeper(); + +if (empty($tag)) { + $title = elgg_echo('file:type:all'); + $area2 = elgg_view_title(elgg_echo('file:type:all')); + $area2 = elgg_view('page/elements/content_header', array('context' => "everyone", 'type' => 'file')); +} else { + $title = elgg_echo('searchtitle', array($tag)); + if (is_array($owner_guid)) { + //$area2 = elgg_view_title(elgg_echo("file:friends:type:" . $tag)); + $area2 = elgg_view('page/elements/content_header', array('context' => "friends", 'type' => 'file')); + } else if (elgg_get_page_owner_guid() && elgg_get_page_owner_guid() != get_loggedin_userid()) { + //$area2 = elgg_view_title(elgg_echo("file:user:type:" . $tag,array(elgg_get_page_owner()->name))); + $area2 = elgg_view('page/elements/content_header', array('context' => "mine", 'type' => 'file')); + } else { + //$area2 = elgg_view_title(elgg_echo("file:type:" . $tag)); + $area2 = elgg_view('page/elements/content_header', array('context' => "everyone", 'type' => 'file')); + } +} +if ($friends) { + $area1 = get_filetype_cloud($friends, true); +} else if ($owner_guid) { + $area1 = get_filetype_cloud($owner_guid); +} else { + $area1 = get_filetype_cloud(); +} + +elgg_push_context('search'); + +$offset = (int) get_input('offset', 0); +$limit = 10; + +if ($listtype == "gallery") { + $limit = 12; +} + +if (!empty($tag)) { + $params = array( + 'metadata_name' => $md_type, + 'metadata_value' => $tag, + 'types' => 'object', + 'subtypes' => 'file', + 'owner_guid' => $owner_guid, + 'limit' => $limit, + ); + $area2 .= elgg_list_entities_from_metadata($params); +} else { + $area2 .= elgg_list_entities(array('types' => 'object', 'subtypes' => 'file', 'owner_guid' => $owner_guid, 'limit' => $limit, 'offset' => $offset)); +} + +elgg_pop_context(); + +$content = "
" . $area1 . $area2 . "
"; + +$body = elgg_view_layout('one_column_with_sidebar', array('content' => $content)); + +echo elgg_view_page($title, $body); \ No newline at end of file diff --git a/mod/file/thumbnail.php b/mod/file/thumbnail.php index 987153aeb..4da560a6c 100644 --- a/mod/file/thumbnail.php +++ b/mod/file/thumbnail.php @@ -1,5 +1,4 @@ \ No newline at end of file diff --git a/mod/file/views/default/file/upload.php b/mod/file/views/default/file/upload.php index 0ef99348c..041bd9227 100644 --- a/mod/file/views/default/file/upload.php +++ b/mod/file/views/default/file/upload.php @@ -1,40 +1,40 @@ title; - $description = $vars['entity']->description; - $tags = $vars['entity']->tags; - $access_id = $vars['entity']->access_id; - $container_guid = $vars['entity']->container_guid; - } else { - $action_type = "new"; - $action = "file/upload"; - $title = isset($_SESSION['uploadtitle']) ? $_SESSION['uploadtitle'] : ''; - $description = isset($_SESSION['uploaddesc']) ? $_SESSION['uploaddesc'] : ''; - $tags = isset($_SESSION['uploadtags']) ? $_SESSION['uploadtags'] : ''; - if (defined('ACCESS_DEFAULT')) { - $access_id = ACCESS_DEFAULT; - } else { - $access_id = 0; - } - $access_id = isset($_SESSION['uploadaccessid']) ? $_SESSION['uploadaccessid'] : $access_id; - $container_guid = elgg_get_page_owner_guid(); +if (isset($vars['entity'])) { + $action_type = "update"; + $action = "file/upload"; + $title = $vars['entity']->title; + $description = $vars['entity']->description; + $tags = $vars['entity']->tags; + $access_id = $vars['entity']->access_id; + $container_guid = $vars['entity']->container_guid; +} else { + $action_type = "new"; + $action = "file/upload"; + $title = isset($_SESSION['uploadtitle']) ? $_SESSION['uploadtitle'] : ''; + $description = isset($_SESSION['uploaddesc']) ? $_SESSION['uploaddesc'] : ''; + $tags = isset($_SESSION['uploadtags']) ? $_SESSION['uploadtags'] : ''; + if (defined('ACCESS_DEFAULT')) { + $access_id = ACCESS_DEFAULT; + } else { + $access_id = 0; } - - // make sure session cache is cleared - unset($_SESSION['uploadtitle']); - unset($_SESSION['uploaddesc']); - unset($_SESSION['uploadtags']); - unset($_SESSION['uploadaccessid']); + $access_id = isset($_SESSION['uploadaccessid']) ? $_SESSION['uploadaccessid'] : $access_id; + $container_guid = elgg_get_page_owner_guid(); +} + +// make sure session cache is cleared +unset($_SESSION['uploadtitle']); +unset($_SESSION['uploaddesc']); +unset($_SESSION['uploadtags']); +unset($_SESSION['uploadaccessid']); ?> diff --git a/mod/file/views/default/widgets/filerepo/content.php b/mod/file/views/default/widgets/filerepo/content.php index ee7bbe3cc..130b5e3de 100644 --- a/mod/file/views/default/widgets/filerepo/content.php +++ b/mod/file/views/default/widgets/filerepo/content.php @@ -68,4 +68,3 @@ if ($files) { echo "

" . elgg_echo("file:none") . "

"; } -?> \ No newline at end of file diff --git a/mod/file/views/rss/object/file.php b/mod/file/views/rss/object/file.php index 52d26382f..a0660d6c8 100644 --- a/mod/file/views/rss/object/file.php +++ b/mod/file/views/rss/object/file.php @@ -1,26 +1,21 @@ title; - if (empty($title)) { - $title = substr($vars['entity']->description,0,32); - if (strlen($vars['entity']->description) > 32) - $title .= " ..."; - } - +/** + * Elgg RSS file object view + * + * @package ElggFile + * @subpackage Core + */ +$title = $vars['entity']->title; +if (empty($title)) { + $title = elgg_get_excerpt($vars['entity']->description, 32); +} ?> - - getURL(); ?> - time_created) ?> - getURL(); ?> - <![CDATA[<?php echo $title; ?>]]> - description)); ?>]]> - - + + getURL(); ?> + time_created) ?> + getURL(); ?> + <![CDATA[<?php echo $title; ?>]]> + description)); ?>]]> + + -- cgit v1.2.3