From 755187045527c5c15ea3b9e70fe7a451d7796585 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 18 Jun 2011 17:56:44 -0400 Subject: using the new lightbox and hacking away at the complicated embed/embed view --- mod/embed/start.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mod/embed/start.php') diff --git a/mod/embed/start.php b/mod/embed/start.php index f6f49a53f..ce6c6ec11 100644 --- a/mod/embed/start.php +++ b/mod/embed/start.php @@ -36,10 +36,13 @@ function embed_longtext_menu($hook, $type, $items, $vars) { 'name' => 'embed', 'href' => "embed?{$active_section}internal_id={$vars['id']}", 'text' => elgg_echo('media:insert'), - 'rel' => 'facebox', - 'link_class' => 'elgg-longtext-control', + 'rel' => 'lightbox', + 'link_class' => 'elgg-longtext-control elgg-lightbox', 'priority' => 1, )); + + elgg_load_js('lightbox'); + elgg_load_css('lightbox'); return $items; } -- cgit v1.2.3 From d462b57edfeab81bd90a5d0321ea3d1fcbbddff3 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 18 Jun 2011 21:30:01 -0400 Subject: rewrote the insert javascript as an intermediate step. I'm sure I completely broke ECML integration and uploading files. --- mod/embed/start.php | 18 ++++-- mod/embed/views/default/embed/css.php | 24 ++++---- mod/embed/views/default/embed/embed.php | 93 +++++++---------------------- mod/embed/views/default/js/embed/embed.php | 39 ++++++++++++ mod/embed/views/default/js/embed/inline.php | 26 ++++++++ 5 files changed, 112 insertions(+), 88 deletions(-) create mode 100644 mod/embed/views/default/js/embed/embed.php create mode 100644 mod/embed/views/default/js/embed/inline.php (limited to 'mod/embed/start.php') diff --git a/mod/embed/start.php b/mod/embed/start.php index ce6c6ec11..3b6e58ce1 100644 --- a/mod/embed/start.php +++ b/mod/embed/start.php @@ -13,17 +13,24 @@ elgg_register_event_handler('init', 'system', 'embed_init'); */ function embed_init() { elgg_extend_view('css/elgg', 'embed/css'); - elgg_extend_view('js/elgg', 'embed/js'); - elgg_extend_view('js/elgg', 'embed/lightbox_init'); elgg_register_plugin_hook_handler('register', 'menu:longtext', 'embed_longtext_menu'); // Page handler for the modal media embed elgg_register_page_handler('embed', 'embed_page_handler'); - elgg_register_js('elgg.embed', 'mod/embed/js/embed.js', 'footer'); + elgg_register_js('elgg.embed', 'js/embed/embed.js', 'footer'); } +/** + * Add the embed menu item to the long text menu + * + * @param string $hook + * @param string $type + * @param array $items + * @param array $vars + * @return array + */ function embed_longtext_menu($hook, $type, $items, $vars) { // yeah this is naughty. embed and ecml might want to merge. if (elgg_is_active_plugin('ecml')) { @@ -37,12 +44,13 @@ function embed_longtext_menu($hook, $type, $items, $vars) { 'href' => "embed?{$active_section}internal_id={$vars['id']}", 'text' => elgg_echo('media:insert'), 'rel' => 'lightbox', - 'link_class' => 'elgg-longtext-control elgg-lightbox', - 'priority' => 1, + 'link_class' => "elgg-longtext-control elgg-lightbox embed-control embed-control-{$vars['id']}", + 'priority' => 10, )); elgg_load_js('lightbox'); elgg_load_css('lightbox'); + elgg_load_js('elgg.embed'); return $items; } diff --git a/mod/embed/views/default/embed/css.php b/mod/embed/views/default/embed/css.php index c20116bf2..1ce994cfe 100644 --- a/mod/embed/views/default/embed/css.php +++ b/mod/embed/views/default/embed/css.php @@ -8,12 +8,15 @@ .embed-wrapper { width: 730px; min-height: 400px; - padding: 5px; + margin: 5px; } .embed-wrapper h2 { color: #333333; margin-bottom: 10px; } +.embed-wrapper .elgg-list-item { + cursor: pointer; +} /* *************************************** EMBED TABBED PAGE NAVIGATION @@ -22,6 +25,15 @@ color: #666; } +.embed-wrapper p { + color: #333; +} +.embed-wrapper .elgg-image-block:hover { + background-color: #eee; +} + /*************** Form ******************/ @@ -51,15 +63,7 @@ .embed-wrapper .elgg-input-file { background-color: white; } -.embed-wrapper p { - color:#333; -} -.embed-wrapper p.entity-title { - color:#666; -} -.embed-wrapper .elgg-image-block:hover { - background-color: #eee; -} + .embed-wrapper label { color:#333; } diff --git a/mod/embed/views/default/embed/embed.php b/mod/embed/views/default/embed/embed.php index f09d76a4b..9f0ac730f 100644 --- a/mod/embed/views/default/embed/embed.php +++ b/mod/embed/views/default/embed/embed.php @@ -29,8 +29,6 @@ if (!$sections) { $layout = isset($section_info['layout']) ? $section_info['layout'] : 'list'; $params = array( - //'type' => $type, - //'subtype' => $subtype, 'offset' => $offset, 'limit' => $limit, 'section' => $active_section, @@ -43,10 +41,13 @@ if (!$sections) { if ($section_content = elgg_view("embed/$active_section/content", $params)) { // handles its own pagination $content .= $section_content; - } elseif ($embed_info = elgg_trigger_plugin_hook('embed_get_items', $active_section, $params, array('items' => array(), 'count' => 0))) { - // check if we have an override for this section type. - $view = "embed/$active_section/item/$layout"; + } 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); + // 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"; } @@ -54,37 +55,16 @@ if (!$sections) { if (!isset($embed_info['items']) || !is_array($embed_info['items']) || !count($embed_info['items'])) { $content .= elgg_echo('embed:no_section_content'); } else { - // 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 = elgg_is_active_plugin('ecml')){ - $ecml_valid_keyword = ecml_is_valid_keyword($active_section); - } else { - $ecml_valid_keyword = FALSE; - } - - $items_content = ''; - - $params['content'] = $items_content; - $params['count'] = $embed_info['count']; - - $content .= elgg_view('navigation/pagination', $params); - $content .= elgg_view("embed/layouts/$layout", $params); + elgg_push_context('widgets'); + $content .= elgg_view_entity_list($embed_info['items'], array( + 'full_view' => false, + )); + elgg_pop_context(); + + $js = elgg_view('js/embed/inline', array( + 'items' => $embed_info['items'], + )); } - } else { - $content .= elgg_echo('embed:no_section_content'); } } else { $content .= elgg_echo('embed:invalid_section'); @@ -92,42 +72,9 @@ if (!$sections) { } echo '
' . $content . '
'; -?> - - - +if (isset($js)) { + echo ''; +} diff --git a/mod/embed/views/default/js/embed/embed.php b/mod/embed/views/default/js/embed/embed.php new file mode 100644 index 000000000..78ad125ef --- /dev/null +++ b/mod/embed/views/default/js/embed/embed.php @@ -0,0 +1,39 @@ +elgg.provide('elgg.embed'); + +elgg.embed.init = function() { + + // inserts the embed content into the textarea + $(".embed-wrapper .elgg-list-item").live('click', elgg.embed.insert); + + // caches the current textarea id + $(".embed-control").live('click', function() { + var classes = $(this).attr('class'); + var class = classes.split(/[, ]+/).pop(); + var textAreaId = class.substr(class.indexOf('embed-control-') + "embed-control-".length); + elgg.embed.textAreaId = textAreaId; + }); +} + +/** + * Inserts data attached to an embed list item in textarea + * + * @todo generalize lightbox closing and wysiwyg refreshing + * + * @param {Object} event + * @return void + */ +elgg.embed.insert = function(event) { + + var textAreaId = elgg.embed.textAreaId; + + var content = $(this).data('embed_code'); + $('#' + textAreaId).val($('#' + textAreaId).val() + ' ' + content + ' '); + + + + $.fancybox.close(); + + event.preventDefault(); +} + +elgg.register_hook_handler('init', 'system', elgg.embed.init); diff --git a/mod/embed/views/default/js/embed/inline.php b/mod/embed/views/default/js/embed/inline.php new file mode 100644 index 000000000..0672a68f8 --- /dev/null +++ b/mod/embed/views/default/js/embed/inline.php @@ -0,0 +1,26 @@ +name) ? $item->name : $item->title; + // don't let it be too long + $title = elgg_get_excerpt($title); + + $icon = "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 -- cgit v1.2.3 From 780d9cb45f90158fdb843c41c8c1203ebdb06a3f Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 18 Jun 2011 22:06:40 -0400 Subject: added back tab switching --- mod/embed/start.php | 8 +------- mod/embed/views/default/embed/tabs.php | 4 ++-- mod/embed/views/default/js/embed/embed.php | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'mod/embed/start.php') diff --git a/mod/embed/start.php b/mod/embed/start.php index 3b6e58ce1..e6fc5551b 100644 --- a/mod/embed/start.php +++ b/mod/embed/start.php @@ -32,16 +32,10 @@ function embed_init() { * @return array */ function embed_longtext_menu($hook, $type, $items, $vars) { - // yeah this is naughty. embed and ecml might want to merge. - if (elgg_is_active_plugin('ecml')) { - $active_section = 'active_section=web_services&'; - } else { - $active_section = ''; - } $items[] = ElggMenuItem::factory(array( 'name' => 'embed', - 'href' => "embed?{$active_section}internal_id={$vars['id']}", + 'href' => "embed", 'text' => elgg_echo('media:insert'), 'rel' => 'lightbox', 'link_class' => "elgg-longtext-control elgg-lightbox embed-control embed-control-{$vars['id']}", diff --git a/mod/embed/views/default/embed/tabs.php b/mod/embed/views/default/embed/tabs.php index a148ece9f..3f377fee5 100644 --- a/mod/embed/views/default/embed/tabs.php +++ b/mod/embed/views/default/embed/tabs.php @@ -16,7 +16,7 @@ foreach ($sections as $section_id => $section_info) { $tab = array( 'title' => $section_info['name'], 'url' => '#', - 'url_class' => 'embed_section', + 'url_class' => 'embed-section', 'url_id' => $section_id, ); @@ -31,7 +31,7 @@ if ($upload_sections) { $tabs[] = array( 'title' => elgg_echo('embed:upload'), 'url' => '#', - 'url_class' => 'embed_section', + 'url_class' => 'embed-section', 'url_id' => 'upload', 'selected' => ($active_section == 'upload') ); diff --git a/mod/embed/views/default/js/embed/embed.php b/mod/embed/views/default/js/embed/embed.php index b709af05e..3b398af3a 100644 --- a/mod/embed/views/default/js/embed/embed.php +++ b/mod/embed/views/default/js/embed/embed.php @@ -15,6 +15,8 @@ elgg.embed.init = function() { // special pagination helper for lightbox $('.embed-wrapper .elgg-pagination a').live('click', elgg.embed.pagination); + + $('.embed-section').live('click', elgg.embed.loadTab); } /** @@ -50,4 +52,17 @@ elgg.embed.pagination = function(event) { event.preventDefault(); } +/** + * Loads an embed tab + * + * @param {Object} 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); + event.preventDefault(); +} + elgg.register_hook_handler('init', 'system', elgg.embed.init); -- cgit v1.2.3 From 1f6b5cc6ac57ead98bbaa6c85323a69b6128629e Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 18 Jun 2011 22:14:42 -0400 Subject: fixed issue with embedding a file in an embedded file --- mod/embed/start.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mod/embed/start.php') diff --git a/mod/embed/start.php b/mod/embed/start.php index e6fc5551b..f6f1acc57 100644 --- a/mod/embed/start.php +++ b/mod/embed/start.php @@ -32,6 +32,10 @@ function embed_init() { * @return array */ function embed_longtext_menu($hook, $type, $items, $vars) { + + if (elgg_get_context() == 'embed') { + return $items; + } $items[] = ElggMenuItem::factory(array( 'name' => 'embed', -- cgit v1.2.3 From b307bcbdc8b0f269a5408a824dc4a7c3c2e9570f Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 2 Jul 2011 10:17:56 -0400 Subject: fixed embed plugin for #3544 --- mod/embed/start.php | 6 ++++-- mod/embed/views/default/embed/embed.php | 6 +++--- mod/embed/views/default/embed/upload/content.php | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'mod/embed/start.php') diff --git a/mod/embed/start.php b/mod/embed/start.php index f6f1acc57..bdd832b4e 100644 --- a/mod/embed/start.php +++ b/mod/embed/start.php @@ -81,8 +81,10 @@ function embed_page_handler($page) { elgg_sort_3d_array_by_value($sections, 'name'); elgg_sort_3d_array_by_value($upload_sections, 'name'); - $active_section = get_input('active_section', NULL); - $internal_id = get_input('internal_id', NULL); + $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, diff --git a/mod/embed/views/default/embed/embed.php b/mod/embed/views/default/embed/embed.php index 77ce03699..2d8de1ca4 100644 --- a/mod/embed/views/default/embed/embed.php +++ b/mod/embed/views/default/embed/embed.php @@ -10,7 +10,7 @@ */ $sections = elgg_extract('sections', $vars, array()); -$active_section = elgg_extract('active_section', $vars, array_shift(array_keys($sections))); +$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); @@ -20,8 +20,8 @@ if (!$sections) { $content = elgg_view_title(elgg_echo('embed:media')); $content .= elgg_view('embed/tabs', $vars); - $offset = max(0, get_input('offset', 0)); - $limit = get_input('limit', 5); + $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)) { diff --git a/mod/embed/views/default/embed/upload/content.php b/mod/embed/views/default/embed/upload/content.php index 24fce8112..8bedf5ad1 100644 --- a/mod/embed/views/default/embed/upload/content.php +++ b/mod/embed/views/default/embed/upload/content.php @@ -4,6 +4,7 @@ */ $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(); -- cgit v1.2.3