]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
a little standardization of the file plugin code
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 31 Dec 2010 14:47:38 +0000 (14:47 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 31 Dec 2010 14:47:38 +0000 (14:47 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7789 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/file/download.php
mod/file/index.php
mod/file/search.php
mod/file/thumbnail.php
mod/file/views/default/file/upload.php
mod/file/views/default/widgets/filerepo/content.php
mod/file/views/rss/object/file.php

index 55c5dc697f66fd0a9af5682cddbbe1b7b246b3fa..d7625901ef9503f0b26e1b893d9cce39d86ffc8f 100644 (file)
@@ -1,41 +1,42 @@
 <?php
-       /**
-        * Elgg file download.
-        * 
-        * @package ElggFile
-        */
+/**
+ * Elgg file download.
+ * 
+ * @package ElggFile
+ */
+require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
 
-       require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
+// Get the guid
+$file_guid = get_input("file_guid");
 
-       // Get the guid
-       $file_guid = get_input("file_guid");
-       
-       // Get the file
-       $file = get_entity($file_guid);
-       
-       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
-                       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
index b55f5c835a176aa77185fef2e5e7ccf2acea1cd6..3706f65b3d3b5df00242905a59e1bb3d93035ca4 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Elgg file browser
+ * Individual's or group's files
  *
  * @package ElggFile
  */
index 6e63f55f0580dfd7baf4407e6f70f86e07d121f5..0e541c276f1d97f6e8d2082e76d18c4196ecbd95 100644 (file)
 <?php
-
-       /**
-        * Elgg file search
-        *
-        * @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 = "<div class='files'>".$area1.$area2."</div>";
-
-               $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 = "<div class='files'>" . $area1 . $area2 . "</div>";
+
+$body = elgg_view_layout('one_column_with_sidebar', array('content' => $content));
+
+echo elgg_view_page($title, $body);
\ No newline at end of file
index 987153aebbc6cdcc1767ecc86e4485440730f37a..4da560a6c8ac6e08811859782a32f979ce34bb43 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * Elgg file thumbnail
  *
 require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
 
 // Get file GUID
-$file_guid = (int) get_input('file_guid',0);
+$file_guid = (int) get_input('file_guid', 0);
 
 // Get file thumbnail size
-$size = get_input('size','small');
+$size = get_input('size', 'small');
 
 // Get file entity
 if ($file = get_entity($file_guid)) {
@@ -62,5 +61,3 @@ if ($file = get_entity($file_guid)) {
        }
                
 }
-
-?>
\ No newline at end of file
index 0ef99348cb3911d2a430c87e902d4aa11d1b600d..041bd9227d93bd4711e49ba2af97084af251fba1 100644 (file)
@@ -1,40 +1,40 @@
 <?php
-       /**
       * Elgg file browser uploader
-        * 
       * @package ElggFile
       */
+/**
+ * Elgg file browser uploader
+ *
+ * @package ElggFile
+ */
 
-       global $CONFIG;
+global $CONFIG;
 
-       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;
-               }
-               $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']);
        
        
 ?>
index ee7bbe3cca8932817447cde2924410970781a735..130b5e3ded6235b2a6f9d17b3ba9cc24b24856c1 100644 (file)
@@ -68,4 +68,3 @@ if ($files) {
 
        echo "<p class='margin-top'>" . elgg_echo("file:none") . "</p>";
 }
-?>
\ No newline at end of file
index 52d26382f3bef27188a78f19e5fc9a694db9e5fe..a0660d6c817683f20a7a4601b830542d631619eb 100644 (file)
@@ -1,26 +1,21 @@
 <?php
-
-       /**
-        * Elgg RSS file object view
-        * 
-        * @package ElggFile
-        * @subpackage Core
-        */
-
-       $title = $vars['entity']->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);
+}
 ?>
 
-       <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>
+<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>