]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2911. Embed plugins works again. Added menu for embed sections. This plugin...
authorBrett Profitt <brett.profitt@gmail.com>
Sun, 28 Aug 2011 01:54:13 +0000 (18:54 -0700)
committerBrett Profitt <brett.profitt@gmail.com>
Sun, 28 Aug 2011 01:54:13 +0000 (18:54 -0700)
mod/embed/languages/en.php
mod/embed/start.php
mod/embed/views/default/embed/embed.php
mod/embed/views/default/embed/item/gallery.php [deleted file]
mod/embed/views/default/embed/item/list.php [deleted file]
mod/embed/views/default/embed/layouts/gallery.php [deleted file]
mod/embed/views/default/embed/layouts/list.php [deleted file]
mod/embed/views/default/embed/upload/content.php [deleted file]
mod/embed/views/default/js/embed/embed.php
mod/embed/views/default/js/embed/inline.php [deleted file]
mod/file/start.php

index f3a49e38bbc5e47638999452c63ed38421009c40..287d34ca16576aaae1cae041d4024c29c27deeb9 100644 (file)
@@ -15,6 +15,8 @@ $english = array(
        // messages
        'embed:no_upload_content' => 'No upload content!',
        'embed:no_section_content' => 'No items found.',
+
+       'embed:no_sections' => 'No supported embed plugins found. Ask the site administrator to enabled a plugin with embed support.',
 );
 
 add_translation("en", $english);
\ No newline at end of file
index bdd832b4e36616313f01aea11c1a00ca21a86d8d..6c26163e965ab3ae1cfe3821984a0d3ec964adfc 100644 (file)
@@ -74,13 +74,34 @@ function embed_page_handler($page) {
                        //      listing
                        //      item
                        // default to embed/listing | item if not found.
-                       // @todo trigger for all right now. If we categorize these later we can trigger
-                       // for certain categories.
-                       $sections = elgg_trigger_plugin_hook('embed_get_sections', 'all', NULL, array());
-                       $upload_sections = elgg_trigger_plugin_hook('embed_get_upload_sections', 'all', NULL, array()); 
-                       
-                       elgg_sort_3d_array_by_value($sections, 'name');
-                       elgg_sort_3d_array_by_value($upload_sections, 'name');
+
+                       // @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', '');
@@ -97,4 +118,4 @@ function embed_page_handler($page) {
 
        // exit because this is in a modal display.
        exit;
-}
+}
\ No newline at end of file
index 2d8de1ca462770916f96e203683029f492259ee0..2bd3296909ab30a3b5242df64500cb49b0be1672 100644 (file)
@@ -12,7 +12,6 @@
 $sections = elgg_extract('sections', $vars, array());
 $active_section = elgg_extract('active_section', $vars, array_shift(array_keys($sections)), false);
 $upload_sections = elgg_extract('upload_sections', $vars, array());
-$internal_id = elgg_extract('internal_id', $vars);
 
 if (!$sections) {
        $content = elgg_echo('embed:no_sections');
@@ -23,57 +22,17 @@ if (!$sections) {
        $offset = (int)max(0, get_input('offset', 0));
        $limit = (int)get_input('limit', 5);
 
-       // build the items and layout.
-       if ($active_section == 'upload' || array_key_exists($active_section, $sections)) {
-               $section_info = $sections[$active_section];
-               $layout = isset($section_info['layout']) ? $section_info['layout'] : 'list';
-
-               $params =  array(
-                       'offset' => $offset,
-                       'limit' => $limit,
-                       'section' => $active_section,
-                       'upload_sections' => $upload_sections,
-                       'internal_id' => $internal_id
-               );
-
-               // allow full override for this section
-               // check for standard hook
-               if ($section_content = elgg_view("embed/$active_section/content", $params)) {
-                       // handles its own pagination
-                       $content .= $section_content;
-               } else {
-                       // see if anyone has any items to display for the active section
-                       $result = array('items' => array(), 'count' => 0);
-                       $embed_info = elgg_trigger_plugin_hook('embed_get_items', $active_section, $params, $result);
+       // find the view to display
+       // @todo make it so you don't have to manually create views for each page
+       $view = "embed/$active_section/content";
+       
+       $section_content = elgg_view($view, $vars);
 
-                       // do we use default view or has someone defined "embed/$active_section/item/$layout"
-                       $view = "embed/$active_section/item/$layout";
-                       if (!elgg_view_exists($view)) {
-                               $view = "embed/item/$layout";
-                       }
-                       
-                       if (!isset($embed_info['items']) || !is_array($embed_info['items']) || !count($embed_info['items'])) {
-                               $content .= elgg_echo('embed:no_section_content');
-                       } else {
-
-                               elgg_push_context('widgets');
-                               $content .= elgg_view_entity_list($embed_info['items'], array(
-                                       'full_view' => false,
-                                       'count' => $embed_info['count'],
-                                       'pagination' => true,
-                                       'position' => 'before',
-                                       'offset' => $offset,
-                                       'limit' => $limit,
-                               ));
-                               elgg_pop_context();
-
-                               $js = elgg_view('js/embed/inline', array(
-                                       'items' => $embed_info['items'],
-                               ));
-                       }
-               }
+       // build the items and layout.
+       if ($section_content) {
+               $content .= $section_content;
        } else {
-               $content .= elgg_echo('embed:invalid_section');
+               $content .= elgg_echo('embed:no_section_content');
        }
 }
 
diff --git a/mod/embed/views/default/embed/item/gallery.php b/mod/embed/views/default/embed/item/gallery.php
deleted file mode 100644 (file)
index daee8ee..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/**
- * Default item view for embed items in gallery display.
- *
- * Why don't we recycle the view/type/subtype views?
- * Because we need to have special JavaScript that fires when you click on
- * the icon / title.
- *
- * @todo Yes this is copy and pasted.  Pete needs to theme.  I'll DRY it up later.
- *
- * @uses object $vars['item'] The item to display
- * @return string A formatted item
- */
-
-$item = $vars['item'];
-$section = $vars['section'];
-$target = $vars['target'];
-$ecml_keyword = (isset($vars['ecml_enabled']) && isset($vars['ecml_keyword'])) ? $vars['ecml_keyword'] : NULL;
-$icon_size = $vars['icon_size'];
-
-// @todo add entity checking.
-
-// different entity types have different title attribute names.
-$title = isset($item->name) ? $item->name : $item->title;
-// don't let it be too long
-$title = elgg_get_excerpt($title);
-
-// @todo you can disable plugins that are required by other plugins
-// (embed requires ecml) so fallback to a hard-coded check to see if ecml is enabled.
-// #grumble
-if ($ecml_keyword) {
-       $embed_code = "[$ecml_keyword guid={$item->getGUID()}]";
-} else {
-       // fallback to inserting a hard link to the object with its icon
-       $icon = "<img src=\"{$item->getIcon($icon_size)}\" />" . htmlentities($title, ENT_QUOTES, 'UTF-8');
-
-       $embed_code = elgg_view('output/url', array(
-               'href' => $item->getURL(),
-               'title' => $title,
-               'text' => $title,
-               'encode_text' => FALSE
-       ));
-}
-
-$icon = "<img src=\"{$item->getIcon($icon_size)}\" />";
-$info = htmlentities($title, ENT_QUOTES, 'UTF-8');
-
-$listing = elgg_view('entities/gallery_listing', array('icon' => $icon, 'info' => $info));
-
-// @todo JS 1.8: no
-echo "<div class=\"embed_data\" id=\"embed_{$item->getGUID()}\">$listing</div>";
-echo "<script type=\"text/javascript\">
-       $('#embed_{$item->getGUID()}').data('embed_code', " . json_encode($embed_code) . ");
-</script>";
\ No newline at end of file
diff --git a/mod/embed/views/default/embed/item/list.php b/mod/embed/views/default/embed/item/list.php
deleted file mode 100644 (file)
index 89a2ffb..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-/**
- * Default item view for embed items in list display.
- *
- * Why don't we recycle the view/type/subtype views?
- * Because we need to have special JavaScript that fires when you click on
- * the icon / title.
- *
- * @uses object $vars['item'] The item to display
- * @return string A formatted item
- */
-
-$item = $vars['item'];
-$section = $vars['section'];
-$target = $vars['target'];
-$ecml_keyword = (isset($vars['ecml_enabled']) && $vars['ecml_enabled'] && isset($vars['ecml_keyword'])) ? $vars['ecml_keyword'] : NULL;
-$icon_size = $vars['icon_size'];
-$owner = $item->getOwnerEntity();
-
-// @todo add entity checking.
-
-// different entity types have different title attribute names.
-$title = isset($item->name) ? $item->name : $item->title;
-// don't let it be too long
-$title = elgg_get_excerpt($title);
-
-$author_text = elgg_echo('byline', array($owner->name));
-$date = elgg_view_friendly_time($item->time_created);
-
-$subtitle = "$author_text $date";
-
-// @todo you can disable plugins that are required by other plugins
-// (embed requires ecml) so fallback to a hard-coded check to see if ecml is enabled.
-// #grumble
-if ($ecml_keyword) {
-       $embed_code = "[$ecml_keyword guid={$item->getGUID()}]";
-} else {
-       // fallback to inserting a hard link to the object with its icon
-       $icon = "<img src=\"{$item->getIcon($icon_size)}\" />" . htmlentities($title, ENT_QUOTES, 'UTF-8');
-
-       $embed_code = elgg_view('output/url', array(
-               'href' => $item->getURL(),
-               'title' => $title,
-               'text' => $icon,
-               'encode_text' => FALSE
-       ));
-}
-
-$item_icon = elgg_view_entity_icon($item, $icon_size);
-
-$params = array(
-       'title' => $title,
-       'entity' => $item,
-       'subtitle' => $subtitle,
-       'tags' => FALSE,
-);
-$list_body = elgg_view('object/elements/summary', $params);
-
-// @todo JS 1.8: is this approach better than inline js?
-echo "<div class=\"embed_data\" id=\"embed_{$item->getGUID()}\">" . elgg_view_image_block($item_icon, $list_body) . '</div>';
-echo "<script type=\"text/javascript\">
-       $('#embed_{$item->getGUID()}').data('embed_code', " . json_encode($embed_code) . ");
-</script>";
\ No newline at end of file
diff --git a/mod/embed/views/default/embed/layouts/gallery.php b/mod/embed/views/default/embed/layouts/gallery.php
deleted file mode 100644 (file)
index 70b6d33..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-/**
- * Embed - Gallery items
- *
- * @uses string $vars['content'] Pre-formatted content.
- *
- */
-$active_section = elgg_extract('section', $vars, array());
-
-echo "<div class='embed_modal_$active_section'>" . elgg_extract('content', $vars, '') . "</div>";
diff --git a/mod/embed/views/default/embed/layouts/list.php b/mod/embed/views/default/embed/layouts/list.php
deleted file mode 100644 (file)
index 5d62e57..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-/**
- * Embed - List items
- *
- * @uses string $vars['content'] Pre-formatted content.
- *
- */
-$active_section = elgg_extract('section', $vars, array());
-
-echo "<div class='embed_modal_$active_section'>" . elgg_extract('content', $vars, '') . "</div>";
\ No newline at end of file
diff --git a/mod/embed/views/default/embed/upload/content.php b/mod/embed/views/default/embed/upload/content.php
deleted file mode 100644 (file)
index 8bedf5a..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-/**
- * Special upload form
- */
-$upload_sections = elgg_extract('upload_sections', $vars, array());
-$active_section = get_input('active_upload_section', array_shift(array_keys($upload_sections)));
-$active_section = preg_replace('[\W]', '', $active_section);
-
-$options = array();
-
-if ($upload_sections) {
-       foreach ($upload_sections as $id => $info) {
-               $options[$id] = $info['name'];
-       }
-
-       $input = elgg_view('input/dropdown', array(
-               'name' => 'download_section',
-               'options_values' => $options,
-               'id' => 'embed_upload',
-               'value' => $active_section
-       ));
-
-       // hack this in for now as we clean up this mess
-       $form_vars = array(
-               'enctype' => 'multipart/form-data',
-               'class' => 'elgg-form',
-       );
-       $upload_content = elgg_view_form('file/upload', $form_vars);
-/*
-       if (!$upload_content = elgg_view($upload_sections[$active_section]['view'])) {
-               $upload_content = elgg_echo('embed:no_upload_content');
-       }
-*/
-       echo "<div class='mbm'>" . elgg_echo('embed:upload_type') . "$input</div>";
-       echo "<div class='embed-upload'>";
-       echo $upload_content;
-       echo "</div>";
-
-} else {
-       echo elgg_echo('embed:no_upload_sections');
-}
index ea92ba1fd719e876dea966e7490e2cacbdecd02e..5c15cd95a52629c44209dc8e14abfd50f8d6358a 100644 (file)
@@ -1,9 +1,10 @@
+//<script>
 elgg.provide('elgg.embed');
 
 elgg.embed.init = function() {
 
        // inserts the embed content into the textarea
-       $(".embed-wrapper .elgg-item").live('click', elgg.embed.insert);
+       $(".embed_data").live('click', elgg.embed.insert);
 
        // caches the current textarea id
        $(".embed-control").live('click', function() {
@@ -30,7 +31,7 @@ elgg.embed.init = function() {
  * @return void
  */
 elgg.embed.insert = function(event) {
-
+console.log("omfg");
        var textAreaId = elgg.embed.textAreaId;
 
        var content = $(this).data('embed_code');
diff --git a/mod/embed/views/default/js/embed/inline.php b/mod/embed/views/default/js/embed/inline.php
deleted file mode 100644 (file)
index 0672a68..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-/**
- * Inline embed JavaScript for attaching the insert data to list items
- *
- * @uses $vars['items']
- */
-
-foreach ($vars['items'] as $item) {
-
-       // different entity types have different title attribute names.
-       $title = isset($item->name) ? $item->name : $item->title;
-       // don't let it be too long
-       $title = elgg_get_excerpt($title);
-
-       $icon = "<img src=\"{$item->getIcon($icon_size)}\" />" . htmlspecialchars($title, ENT_QUOTES, 'UTF-8', false);
-
-       $embed_code = elgg_view('output/url', array(
-               'href' => $item->getURL(),
-               'title' => $title,
-               'text' => $icon,
-               'encode_text' => false,
-       ));
-       $embed_code = json_encode($embed_code);
-
-       echo "$('#elgg-object-{$item->getGUID()}').data('embed_code', $embed_code);";
-}
\ No newline at end of file
index b94dc309a69c8b31627e59cf676f3bd48b79b324..749d7a519a7e2168c12df8765600bc08c88bb754 100644 (file)
@@ -57,11 +57,23 @@ function file_init() {
        // temporary - see #2010
        elgg_register_action("file/download", "$action_path/download.php");
 
-
        // embed support
-       elgg_register_plugin_hook_handler('embed_get_sections', 'all', 'file_embed_get_sections');
-       elgg_register_plugin_hook_handler('embed_get_items', 'file', 'file_embed_get_items');
-       elgg_register_plugin_hook_handler('embed_get_upload_sections', 'all', 'file_embed_get_upload_sections');
+       $item = ElggMenuItem::factory(array(
+               'name' => 'file',
+               'text' => elgg_echo('file'),
+               'href' => '#',
+               'section' => 'select'
+       ));
+       elgg_register_menu_item('embed:sections', $item);
+
+       $item = ElggMenuItem::factory(array(
+               'name' => 'file_upload',
+               'text' => elgg_echo('file:upload'),
+               'href' => '#',
+               'section' => 'upload'
+       ));
+
+       elgg_register_menu_item('embed:sections', $item);
 }
 
 /**
@@ -332,69 +344,4 @@ function file_icon_url_override($hook, $type, $returnvalue, $params) {
                $url = elgg_trigger_plugin_hook('file:icon:url', 'override', $params, $url);
                return $url;
        }
-}
-
-/**
- * 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'),
-               'layout' => 'list',
-               'icon_size' => 'small',
-       );
-
-       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' => elgg_get_logged_in_user_guid(),
-               '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;
-}
-
-/**
- * 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_upload_sections($hook, $type, $value, $params) {
-       $value['file'] = array(
-               'name' => elgg_echo('file'),
-               'view' => 'file/embed_upload'
-       );
-
-       return $value;
-}
+}
\ No newline at end of file