diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-06-03 14:38:18 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-06-03 14:38:18 +0000 |
commit | d56c072a940ef3084e6d47b45f62767c939cf5b8 (patch) | |
tree | d0761c60a5ce8a1101f0cc7d5c610b78939bc992 /mod/embed | |
parent | 7d01d0bab8b077ed2367a823a1a8d25d676a43da (diff) | |
download | elgg-d56c072a940ef3084e6d47b45f62767c939cf5b8.tar.gz elgg-d56c072a940ef3084e6d47b45f62767c939cf5b8.tar.bz2 |
Moved most of the logic for embed viewing into a single place.
Added gallery support (still no CSS).
git-svn-id: http://code.elgg.org/elgg/trunk@6339 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/embed')
-rw-r--r-- | mod/embed/views/default/embed/embed.php | 56 | ||||
-rw-r--r-- | mod/embed/views/default/embed/item/gallery.php | 53 | ||||
-rw-r--r-- | mod/embed/views/default/embed/layouts/gallery.php | 10 | ||||
-rw-r--r-- | mod/embed/views/default/embed/layouts/list.php | 55 |
4 files changed, 109 insertions, 65 deletions
diff --git a/mod/embed/views/default/embed/embed.php b/mod/embed/views/default/embed/embed.php index 09a15d7a0..4a14543d3 100644 --- a/mod/embed/views/default/embed/embed.php +++ b/mod/embed/views/default/embed/embed.php @@ -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 index 000000000..ed43ca1c3 --- /dev/null +++ b/mod/embed/views/default/embed/item/gallery.php @@ -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 diff --git a/mod/embed/views/default/embed/layouts/gallery.php b/mod/embed/views/default/embed/layouts/gallery.php index b3d9bbc7f..9a923b8a1 100644 --- a/mod/embed/views/default/embed/layouts/gallery.php +++ b/mod/embed/views/default/embed/layouts/gallery.php @@ -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 diff --git a/mod/embed/views/default/embed/layouts/list.php b/mod/embed/views/default/embed/layouts/list.php index d62d35417..0a1a299f0 100644 --- a/mod/embed/views/default/embed/layouts/list.php +++ b/mod/embed/views/default/embed/layouts/list.php @@ -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 |