]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Moved most of the logic for embed viewing into a single place.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 3 Jun 2010 14:38:18 +0000 (14:38 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 3 Jun 2010 14:38:18 +0000 (14:38 +0000)
Added gallery support (still no CSS).

git-svn-id: http://code.elgg.org/elgg/trunk@6339 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/embed/views/default/embed/embed.php
mod/embed/views/default/embed/item/gallery.php [new file with mode: 0644]
mod/embed/views/default/embed/layouts/gallery.php
mod/embed/views/default/embed/layouts/list.php

index 09a15d7a01854e44b7c8fcafca253dad816d63ec..4a14543d3651792e99f9d8034275ad41756bfa20 100644 (file)
@@ -2,6 +2,9 @@
 /**
  * Embed landing page
  *
+ * @todo Yes this is a lot of logic for a view.  A good bit of it can be moved
+ * to the page handler
+ *
  * @uses string $vars['sections'] Array of section_id => Section Display Name
  * @uses string $vars['active_section'] Currently selected section_id
  */
@@ -38,12 +41,7 @@ if (!$sections) {
        $tabs_html = elgg_view('navigation/tabs', array('tabs' => $tabs));
        $content .= $tabs_html;
 
-       $pagination_vars = array(
-
-       );
-
-       $content .= elgg_view('navigation/pagination', $pagination_vars);
-
+       // build the items and layout.
        if (array_key_exists($active_section, $sections)) {
                $section_info = $sections[$active_section];
                $layout = isset($section_info['layout']) ? $section_info['layout'] : 'list';
@@ -62,11 +60,39 @@ if (!$sections) {
                        // handles its own pagination
                        $content .= $section_content;
                } elseif ($embed_info = trigger_plugin_hook('embed_get_items', $active_section, $params, array('items' => array(), 'count' => 0))) {
-                       $params['items'] = $embed_info['items'];
+                       // check if we have an override for this section type.
+                       $view = "embed/$section/item/$layout";
+
+                       if (!elgg_view_exists($view)) {
+                               $view = "embed/item/$layout";
+                       }
+
+                       // pull out some common tests
+                       // embed requires ECML, but until we have plugin deps working
+                       // we need to explicitly check and use a fallback.
+                       if ($ecml_enabled = is_plugin_enabled('ecml')){
+                               $ecml_valid_keyword = ecml_is_valid_keyword($section);
+                       } else {
+                               $ecml_valid_keyword = FALSE;
+                       }
+
+                       $items_content = '';
+                       foreach ($embed_info['items'] as $item) {
+                               $item_params = array(
+                                       'section' => $section,
+                                       'item' => $item,
+                                       'ecml_enabled' => $ecml_enabled,
+                                       'ecml_keyword' => ($ecml_valid_keyword) ? $section : 'entity'
+                               );
+
+                               $items_content .= elgg_view($view, $item_params);
+                       }
+
+                       $params['content'] = $items_content;
                        $params['count'] = $embed_info['count'];
-                       // pagination here.
+
                        $content .= elgg_view('navigation/pagination', $params);
-                       $content .= elgg_view("embed/layouts/{$section_info['layout']}", $params);
+                       $content .= elgg_view("embed/layouts/$layout", $params);
                } else {
                        $content .= elgg_echo('embed:no_section_content');
                }
@@ -80,8 +106,13 @@ echo $content;
 
 <script type="text/javascript">
 $(document).ready(function() {
-
        // insert embed codes
+       $('.embed_data').click(function() {
+               var embed_code = $(this).data('embed_code');
+               elggEmbedInsertContent(embed_code);
+       });
+
+       // tabs
        $('.embed_section').click(function() {
                var section = $(this).attr('id');
                var url = '<?php echo $vars['url']; ?>pg/embed/embed?active_section=' + section;
@@ -90,7 +121,7 @@ $(document).ready(function() {
                return false;
        });
 
-       // handle pagination
+       // pagination
        function elggPaginationClick() {
                $('#facebox .body .content').load($(this).attr('href'));
                return false;
@@ -101,5 +132,4 @@ $(document).ready(function() {
        $('.pagination_previous').click(elggPaginationClick);
 });
 
-</script>
-
+</script>
\ No newline at end of file
diff --git a/mod/embed/views/default/embed/item/gallery.php b/mod/embed/views/default/embed/item/gallery.php
new file mode 100644 (file)
index 0000000..ed43ca1
--- /dev/null
@@ -0,0 +1,53 @@
+<?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;
+
+// @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_make_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()}\" />" . 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('tiny')}\" />";
+$info = htmlentities($title, ENT_QUOTES, 'UTF-8');
+
+$listing = elgg_view('entities/gallery_listing', array('icon' => $icon, 'info' => $info));
+
+// @todo is this approach better than inline js?
+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
index b3d9bbc7f3711e882119cd6b3af051245d859d04..9a923b8a1e89ca15b250fd9d13d0fb77a2947c54 100644 (file)
@@ -1 +1,11 @@
 <?php
+/**
+ * Embed - Gallery items
+ *
+ * @uses string $vars['content'] Pre-formatted content.
+ *
+ */
+
+$content = elgg_get_array_value('content', $vars, '');
+
+echo $content;
\ No newline at end of file
index d62d35417285d3fe1b487e749832d3855aba17c6..0a1a299f0b67758c615b580b14c45b5b640ad00a 100644 (file)
@@ -2,59 +2,10 @@
 /**
  * Embed - List items
  *
- * @todo Yes this is a lot of logic for a view.  The Javascript is faily complicated
- * and pulling entity views out was making it worse.
- * Once plugin deps are working, we'll remove the logic for that.
- *
- * @uses array $vars['items'] Array of ElggEntities
- * @uses string $vars['section'] The section_id.
+ * @uses string $vars['content'] Pre-formatted content.
  *
  */
 
-$items = isset($vars['items']) ? $vars['items'] : array();
-$section = $vars['section'];
-
-// pull out some common tests
-// embed requires ECML, but until we have plugin deps working
-// we need to explicitly check and use a fallback.
-if ($ecml_enabled = is_plugin_enabled('ecml')){
-       $ecml_valid_keyword = ecml_is_valid_keyword($section);
-} else {
-       $ecml_valid_keyword = FALSE;
-}
-
-// check if we have an override for this section type.
-$view = "embed/$section/item/list";
-if (!elgg_view_exists($view)) {
-       $view = "embed/item/list";
-}
-
-$content = '';
-foreach ($items as $item) {
-       // sanity checking
-       if (!elgg_instanceof($item)) {
-               continue;
-       }
-
-       $params = array(
-               'section' => $section,
-               'item' => $item,
-               'ecml_enabled' => $ecml_enabled,
-               'ecml_keyword' => ($ecml_valid_keyword) ? $section : 'entity'
-       );
-
-       $content .= elgg_view($view, $params);
-}
-
-echo $content;
-
-?>
+$content = elgg_get_array_value('content', $vars, '');
 
-<script type="text/javascript">
-$(document).ready(function() {
-       $('.embed_data').click(function() {
-               var embed_code = $(this).data('embed_code');
-               elggEmbedInsertContent(embed_code);
-       });
-});
-</script>
\ No newline at end of file
+echo $content;
\ No newline at end of file