]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added embed support to file plugin.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 6 Jul 2010 20:41:07 +0000 (20:41 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 6 Jul 2010 20:41:07 +0000 (20:41 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@6645 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/file/start.php

index b8a26fab59e5c9d426cbcc3c606539f67e0a8347..f3da33caf53993c9d81ae36c18156b8c8c411b47 100644 (file)
 
                // Register entity type
                register_entity_type('object','file');
+
+               // embed support
+               register_plugin_hook('embed_get_sections', 'all', 'file_embed_get_sections');
+               register_plugin_hook('embed_get_items', 'file', 'file_embed_get_items');
        }
        
        /**
 
        }
        
+       /**
+        * Register file as an embed type.
+        *
+        * @param unknown_type $hook
+        * @param unknown_type $type
+        * @param unknown_type $value
+        * @param unknown_type $params
+        */
+       function file_embed_get_sections($hook, $type, $value, $params) {
+               $value['file'] = array(
+                       'name' => elgg_echo('file:files'),
+                       'layout' => 'list',
+                       'icon_size' => 'medium',
+               );
+       
+               return $value;
+       }
+       
+       /**
+        * Return a list of files for embedding
+        *
+        * @param unknown_type $hook
+        * @param unknown_type $type
+        * @param unknown_type $value
+        * @param unknown_type $params
+        */
+       function file_embed_get_items($hook, $type, $value, $params) {
+               $options = array(
+                       'owner_guid' => get_loggedin_userid(),
+                       'type_subtype_pair' => array('object' => 'file'),
+                       'count' => TRUE
+               );
+       
+               if ($count = elgg_get_entities($options)) {
+                       $value['count'] += $count;
+               
+                       unset($options['count']);
+                       $options['offset'] = $params['offset'];
+                       $options['limit'] = $params['limit'];
+               
+                       $items = elgg_get_entities($options);
+               
+                       $value['items'] = array_merge($items, $value['items']);
+               }
+       
+               return $value;
+       }
+       
        /**
         * Populates the ->getUrl() method for file objects
         *