]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
using the menu system for the embed tabs and adding a reusable select list view
authorcash <cash.costello@gmail.com>
Sat, 1 Oct 2011 16:42:00 +0000 (12:42 -0400)
committercash <cash.costello@gmail.com>
Sat, 1 Oct 2011 16:42:00 +0000 (12:42 -0400)
mod/embed/languages/en.php
mod/embed/start.php
mod/embed/views/default/embed/item.php [new file with mode: 0644]
mod/embed/views/default/embed/layout.php [new file with mode: 0644]
mod/embed/views/default/embed/list.php [new file with mode: 0644]
mod/embed/views/default/js/embed/embed.php
mod/embed/views/default/navigation/menu/embed.php [new file with mode: 0644]
mod/file/start.php

index 287d34ca16576aaae1cae041d4024c29c27deeb9..6ae99a56f0f5499c39827b3cc534965bea76f439 100644 (file)
@@ -5,7 +5,6 @@
  */
 
 $english = array(
-       'media:insert' => 'Embed content',
        'embed:embed' => 'Embed',
        'embed:media' => 'Embed content',
        'embed:instructions' => 'Click on any file to embed it into your content.',
index 6c26163e965ab3ae1cfe3821984a0d3ec964adfc..a87776c7e795151f28fbcae2b92776e1b4bf379e 100644 (file)
@@ -15,6 +15,7 @@ function embed_init() {
        elgg_extend_view('css/elgg', 'embed/css');
        
        elgg_register_plugin_hook_handler('register', 'menu:longtext', 'embed_longtext_menu');
+       elgg_register_plugin_hook_handler('register', 'menu:embed', 'embed_select_tab', 1000);
 
        // Page handler for the modal media embed
        elgg_register_page_handler('embed', 'embed_page_handler');
@@ -40,7 +41,7 @@ function embed_longtext_menu($hook, $type, $items, $vars) {
        $items[] = ElggMenuItem::factory(array(
                'name' => 'embed',
                'href' => "embed",
-               'text' => elgg_echo('media:insert'),
+               'text' => elgg_echo('embed:media'),
                'rel' => 'lightbox',
                'link_class' => "elgg-longtext-control elgg-lightbox embed-control embed-control-{$vars['id']}",
                'priority' => 10,
@@ -54,68 +55,83 @@ function embed_longtext_menu($hook, $type, $items, $vars) {
 }
 
 /**
- * Serves pages for upload and embed.
+ * Select the correct embed tab for display
  *
- * @param $page
+ * @param string $hook
+ * @param string $type
+ * @param array $items
+ * @param array $vars
  */
-function embed_page_handler($page) {
-       if (!isset($page[0])) {
-               $page[0] = 'embed';
+function embed_select_tab($hook, $type, $items, $vars) {
+
+       $tab_name = array_pop(explode('/', full_url()));
+       foreach ($items as $item) {
+               if ($item->getName() == $tab_name) {
+                       $item->setSelected();
+                       elgg_set_config('embed_tab', $item);
+               }
        }
 
-       switch ($page[0]) {
-               case 'upload':
-                       echo elgg_view('embed/upload');
-                       break;
-               case 'embed':
-               default:
-                       // trigger hook to get section tabs
-                       // use views for embed/section/
-                       //      listing
-                       //      item
-                       // default to embed/listing | item if not found.
-
-                       // @todo the menu system is good for registering and sorting, but not great for
-                       // displaying tabs.
-                       // Pulling in the menu manually and passing it through the embed/tabs view.
-                       // We should work on making it easier to use tabs through the menu system, then fix
-                       // this mess.
-                       $menus = get_config('menus');
-                       $menu = $menus['embed:sections'];
-
-                       $sections = array();
-                       $upload_sections = array();
-
-                       foreach ($menu as $item) {
-                               switch ($item->section) {
-                                       case 'upload':
-                                               $upload_sections[$item->getName()] = array(
-                                                       'name' => $item->getText(),
-                                               );
-                                               break;
-
-                                       default:
-                                               $sections[$item->getName()] = array(
-                                                       'name' => $item->getText(),
-                                               );
-                                               break;
-                               }
-                       }
-
-                       $active_section = get_input('active_section', '');
-                       $active_section = preg_replace('[\W]', '', $active_section);
-                       $internal_id = get_input('internal_id', '');
-                       $internal_id = preg_replace('[\W]', '', $internal_id);
-
-                       echo elgg_view('embed/embed', array(
-                               'sections' => $sections,
-                               'active_section' => $active_section,
-                               'upload_sections' => $upload_sections,
-                               'internal_id' => $internal_id
-                       ));
-                       break;
+       if (!elgg_get_config('embed_tab') && count($items) > 0) {
+               $items[0]->setSelected();
+               elgg_set_config('embed_tab', $items[0]);
        }
+}
+
+/**
+ * Serves the content for the embed lightbox
+ *
+ * @param array $page URL segments
+ */
+function embed_page_handler($page) {
+
+       echo elgg_view('embed/layout');
 
        // exit because this is in a modal display.
        exit;
-}
\ No newline at end of file
+}
+
+/**
+ * A special listing function for selectable content
+ *
+ * This calls a custom list view for entities. 
+ *
+ * @param array $entities Array of ElggEntity objects
+ * @param array $vars     Display parameters
+ * @return string
+ */
+function embed_list_items($entities, $vars = array()) {
+
+       $defaults = array(
+               'items' => $entities,
+               'list_class' => 'elgg-list-entity',
+       );
+
+       $vars = array_merge($defaults, $vars);
+
+       return elgg_view('embed/list', $vars);
+}
+
+/**
+ * Set the options for the list of embedable content
+ *
+ * @param array $options
+ * @return array
+ */
+function embed_get_list_options($options = array()) {
+
+       if (elgg_get_page_owner_guid()) {
+               $container_guid = elgg_get_page_owner_guid();
+       } else {
+               $container_guid = elgg_get_logged_in_user_guid();
+       }
+
+       $defaults = array(
+               'limit' => 6,
+               'container_guid' => $container_guid,
+       );
+
+       $options = array_merge($defaults, $options);
+
+       return $options;
+}
diff --git a/mod/embed/views/default/embed/item.php b/mod/embed/views/default/embed/item.php
new file mode 100644 (file)
index 0000000..a64a67d
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Embeddable content list item view
+ *
+ * @uses $vars['entity']
+ */
+
+$entity = $vars['entity'];
+
+$image = elgg_view_entity_icon($entity, 'small');
+
+$body = "<h4>" . $entity->title . "</h4>";
+
+$icon = "<img src=\"{$entity->getIconURL('small')}\" />";
+
+$embed_code = elgg_view('output/url', array(
+       'href' => $entity->getURL(),
+       'title' => $title,
+       'text' => $icon,
+       'encode_text' => FALSE
+));
+
+
+echo "<div class=\"embed_data\" id=\"embed_{$entity->getGUID()}\">";
+echo elgg_view_image_block($image, $body);
+echo '</div>';
+
+// @todo JS 1.8: is this approach better than inline js?
+echo "<script type=\"text/javascript\">
+       $('#embed_{$entity->getGUID()}').data('embed_code', " . json_encode($embed_code) . ");
+</script>";
diff --git a/mod/embed/views/default/embed/layout.php b/mod/embed/views/default/embed/layout.php
new file mode 100644 (file)
index 0000000..73c2681
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Layout of embed panel loaded in lightbox
+ */
+
+$title =  elgg_view_title(elgg_echo('embed:media'));
+
+$menu = elgg_view_menu('embed');
+
+$selected = elgg_get_config('embed_tab');
+switch ($selected->getData('tab_type')) {
+       case 'select':
+               $tab = elgg_list_entities(
+                               embed_get_list_options($selected->getData('options')),
+                               'elgg_get_entities',
+                               'embed_list_items'
+                               );
+               if (!$tab) {
+                       $tab = elgg_echo('embed:no_section_content');
+               }
+               break;
+       case 'upload':
+               $tab = elgg_view($selected->getData('view'), $vars);
+               break;
+}
+
+echo <<<HTML
+<div class="embed-wrapper">
+       $title
+       $menu
+       $tab
+</div>
+HTML;
diff --git a/mod/embed/views/default/embed/list.php b/mod/embed/views/default/embed/list.php
new file mode 100644 (file)
index 0000000..e36280e
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+/**
+ * View a list of embeddable items
+ *
+ * @package Elgg
+ *
+ * @uses $vars['items']       Array of ElggEntity objects
+ * @uses $vars['offset']      Index of the first list item in complete list
+ * @uses $vars['limit']       Number of items per page
+ * @uses $vars['count']       Number of items in the complete list
+ *
+ * @uses $vars['pagination']  Show pagination? (default: true)
+ * @uses $vars['position']    Position of the pagination: before, after, or both
+ * @uses $vars['full_view']   Show the full view of the items (default: false)
+ * @uses $vars['list_class']  Additional CSS class for the <ul> element
+ * @uses $vars['item_class']  Additional CSS class for the <li> elements
+ */
+
+$items = $vars['items'];
+$offset = $vars['offset'];
+$limit = $vars['limit'];
+$count = $vars['count'];
+
+$offset_key = elgg_extract('offset_key', $vars, 'offset');
+
+$list_class = 'elgg-list';
+if (isset($vars['list_class'])) {
+       $list_class = "$list_class {$vars['list_class']}";
+}
+
+$item_class = 'elgg-item';
+if (isset($vars['item_class'])) {
+       $item_class = "$item_class {$vars['item_class']}";
+}
+
+$html = "";
+$nav = "";
+
+if ($count) {
+       $nav .= elgg_view('navigation/pagination', array(
+               'offset' => $offset,
+               'count' => $count,
+               'limit' => $limit,
+               'offset_key' => $offset_key,
+       ));
+}
+
+if (is_array($items) && count($items) > 0) {
+       $html .= "<ul class=\"$list_class\">";
+       foreach ($items as $item) {
+               $id = "elgg-{$item->getType()}-{$item->getGUID()}";
+               $html .= "<li id=\"$id\" class=\"$item_class\">";
+               $html .= elgg_view('embed/item', array('entity' => $item));
+               $html .= '</li>';
+       }
+       $html .= '</ul>';
+}
+
+$html .= $nav;
+
+echo $html;
index e9e08f9a0d79aeee472a5d8c564e1cf5484914ea..49c277b6975dc3f433ef50145c50a3eec3c39ac8 100644 (file)
@@ -15,9 +15,9 @@ elgg.embed.init = function() {
        });
 
        // special pagination helper for lightbox
-       $('.embed-wrapper .elgg-pagination a').live('click', elgg.embed.pagination);
+       $('.embed-wrapper .elgg-pagination a').live('click', elgg.embed.loadContent);
 
-       $('.embed-section').live('click', elgg.embed.loadTab);
+       $('.embed-section').live('click', elgg.embed.loadContent);
 
        $('.embed-upload .elgg-form').live('submit', elgg.embed.submit);
 }
@@ -87,7 +87,7 @@ elgg.embed.submit = function(event) {
  * @param {Object} event
  * @return void
  */
-elgg.embed.pagination = function(event) {
+elgg.embed.loadContent = function(event) {
        $('.embed-wrapper').parent().load($(this).attr('href'));
        event.preventDefault();
 }
@@ -99,9 +99,7 @@ elgg.embed.pagination = function(event) {
  * @return void
  */
 elgg.embed.loadTab = function(event) {
-       var section = $(this).attr('id');
-       var url = elgg.config.wwwroot + 'embed/embed?active_section=' + section;
-       $('.embed-wrapper').parent().load(url);
+       $('.embed-wrapper').parent().load($(this).attr('href'));
        event.preventDefault();
 }
 
diff --git a/mod/embed/views/default/navigation/menu/embed.php b/mod/embed/views/default/navigation/menu/embed.php
new file mode 100644 (file)
index 0000000..36cedc4
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Embed tabs
+ *
+ * @uses $vars['menu']['select']
+ * @uses $vars['menu']['upload']
+ */
+
+$tabs = array();
+foreach (array('select', 'upload') as $type) {
+       foreach ($vars['menu'][$type] as $menu_item) {
+               $tabs[] = array(
+                       'title' => $menu_item->getText(),
+                       'url' => 'embed/tab/' . $menu_item->getName(),
+                       'url_class' => 'embed-section',
+                       'selected' => $menu_item->getSelected(),
+               );
+       }
+}
+
+echo elgg_view('navigation/tabs', array('tabs' => $tabs));
index 749d7a519a7e2168c12df8765600bc08c88bb754..16ce0e2337a79b8b52d8c6967a614f5bd187406b 100644 (file)
@@ -61,19 +61,28 @@ function file_init() {
        $item = ElggMenuItem::factory(array(
                'name' => 'file',
                'text' => elgg_echo('file'),
-               'href' => '#',
-               'section' => 'select'
+               'section' => 'select',
+               'data' => array(
+                       'tab_type' => 'select',
+                       'options' => array(
+                               'type' => 'object',
+                               'subtype' => 'file',
+                       ),
+               ),
        ));
-       elgg_register_menu_item('embed:sections', $item);
+       elgg_register_menu_item('embed', $item);
 
        $item = ElggMenuItem::factory(array(
                'name' => 'file_upload',
                'text' => elgg_echo('file:upload'),
-               'href' => '#',
-               'section' => 'upload'
+               'section' => 'upload',
+               'data' => array(
+                       'tab_type' => 'upload',
+                       'view' => 'embed/file_upload/content',
+               ),
        ));
 
-       elgg_register_menu_item('embed:sections', $item);
+       elgg_register_menu_item('embed', $item);
 }
 
 /**