diff options
Diffstat (limited to 'mod/embed')
| -rw-r--r-- | mod/embed/README.txt | 76 | ||||
| -rw-r--r-- | mod/embed/languages/en.php | 21 | ||||
| -rw-r--r-- | mod/embed/manifest.xml | 22 | ||||
| -rw-r--r-- | mod/embed/start.php | 165 | ||||
| -rw-r--r-- | mod/embed/views/default/embed/addcontentjs.php | 7 | ||||
| -rw-r--r-- | mod/embed/views/default/embed/css.php | 37 | ||||
| -rw-r--r-- | mod/embed/views/default/embed/item.php | 39 | ||||
| -rw-r--r-- | mod/embed/views/default/embed/layout.php | 40 | ||||
| -rw-r--r-- | mod/embed/views/default/embed/list.php | 58 | ||||
| -rw-r--r-- | mod/embed/views/default/js/embed/embed.php | 147 | ||||
| -rw-r--r-- | mod/embed/views/default/navigation/menu/embed.php | 18 | 
11 files changed, 630 insertions, 0 deletions
diff --git a/mod/embed/README.txt b/mod/embed/README.txt new file mode 100644 index 000000000..51b120d96 --- /dev/null +++ b/mod/embed/README.txt @@ -0,0 +1,76 @@ +Embed plugin + +CONTENTS: +	1. Overview +	2. Adding a Tab +	3. Populating a Select Tab +	4. Populating an Upload Tab +	5. Other WYSIWYG Editors and Embed + +	 +1. Overview +	The Embed plugin is a simple way to allow users to link to or embed +	their personal network content or third party resources in any text area. + +	The Embed plugin adds a menu item to the longtext menu. Clicking on this +	link pops up a lightbox. The lightbox supports lists of content for insertion +	and uploading new content. + + +2. Adding a Tab +	The Embed plugin uses the menu system to manage its tabs. Use +	elgg_register_menu_item() for the embed menu to add a new tab like this: + +	$item = ElggMenuItem::factory(array( +		'name' => 'file', +		'text' => elgg_echo('file'), +		'priority' => 10, +		'data' => array( +			'options' => array( +				'type' => 'object', +				'subtype' => 'file', +			), +		), +	)); +	elgg_register_menu_item('embed', $item); + +	Parameters: +		name: The unique name of the tab. +		text: The text shown on the tab +		priority: Placement of the tab. +		data: An array of parameters for creating the tab and its content. +			When listing content using the embed list view, pass the options for the +			elgg_list_entities() function as 'options'. +			When using a custom view for listing content or for uploading new +			content, pass the view name as 'view'. + +	See the file plugin for examples of registering both tab types. + + +3. Populating a Content Select Tab +	Nothing should be required other than setting the options parameter array +	when registering the tab. See the view embed/item to see how an entity is +	rendered. + +	If creating a custom list, the <li> elements must have a class of .embed-item. +	The HTML content that is inserted must use the class .embed-insert. + + +4. Populating an Upload Tab +	The view that is registered must be defined. It must include a form for +	uploading the content. The form must .elgg-form-embed. Somewhere in the view +	must be a hidden input field with the name embed_hidden with its value be +	the name of the tab to forward the user to when uploading is complete. + +	See the view embed/file_upload/content for an example + +	 +5. Other WYSIWYG Editors and Embed +	Embed ships with support for the default input/longtext textarea. +	Plugins replacing this view are expected to include JaVascript to +	allow embed to work with the new editors. +	 +	To add custom JavaScript into the Embed plugin's elgg.embed.insert() function, +	override the view embed/custom_insert_js. The textarea jQuery object is +	available as the variable textArea and the content to be inserted is the +	variable content. See the TinyMCE plugin for an example of this view.
\ No newline at end of file diff --git a/mod/embed/languages/en.php b/mod/embed/languages/en.php new file mode 100644 index 000000000..6ae99a56f --- /dev/null +++ b/mod/embed/languages/en.php @@ -0,0 +1,21 @@ +<?php +/** + * Embed English language strings + * + */ + +$english = array( +	'embed:embed' => 'Embed', +	'embed:media' => 'Embed content', +	'embed:instructions' => 'Click on any file to embed it into your content.', +	'embed:upload' => 'Upload media', +	'embed:upload_type' => 'Upload type: ', + +	// 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 diff --git a/mod/embed/manifest.xml b/mod/embed/manifest.xml new file mode 100644 index 000000000..81ca9194e --- /dev/null +++ b/mod/embed/manifest.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> +	<name>Embed</name> +	<author>Core developers</author> +	<version>1.8.1</version> +	<category>bundled</category> +	<category>enhancement</category> +	<description>Allows users to easily upload and embed media into text areas.</description> +	<website>http://www.elgg.org/</website> +	<copyright>See COPYRIGHT.txt</copyright> +	<license>GNU General Public License version 2</license> +	<requires> +		<type>elgg_release</type> +		<version>1.8</version> +	</requires> +	<requires> +		<type>plugin</type> +		<name>file</name> +		<version>1.8.1</version> +	</requires> +	<activate_on_install>true</activate_on_install> +</plugin_manifest> diff --git a/mod/embed/start.php b/mod/embed/start.php new file mode 100644 index 000000000..1da35aa46 --- /dev/null +++ b/mod/embed/start.php @@ -0,0 +1,165 @@ +<?php +/** + * Elgg media embed plugin + * + * @package ElggEmbed + */ + + +elgg_register_event_handler('init', 'system', 'embed_init'); + +/** + * Init function + */ +function embed_init() { +	elgg_extend_view('css/elgg', 'embed/css'); +	elgg_extend_view('css/admin', 'embed/css'); + +	if (elgg_is_logged_in()) { +		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'); +	 +	$embed_js = elgg_get_simplecache_url('js', 'embed/embed'); +	elgg_register_simplecache_view('js/embed/embed'); +	elgg_register_js('elgg.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) { + +	if (elgg_get_context() == 'embed') { +		return $items; +	} + +	$url = 'embed'; + +	$page_owner = elgg_get_page_owner_entity(); +	if (elgg_instanceof($page_owner, 'group') && $page_owner->isMember()) { +		$url = 'embed?container_guid=' . $page_owner->getGUID(); +	} + +	$items[] = ElggMenuItem::factory(array( +		'name' => 'embed', +		'href' => $url, +		'text' => elgg_echo('embed:media'), +		'rel' => "embed-lightbox-{$vars['id']}", +		'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('jquery.form'); +	elgg_load_js('elgg.embed'); +	 +	return $items; +} + +/** + * Select the correct embed tab for display + * + * @param string $hook + * @param string $type + * @param array $items + * @param array $vars + */ +function embed_select_tab($hook, $type, $items, $vars) { + +	// can this ba called from page handler instead? +	$page = get_input('page'); +	$tab_name = array_pop(explode('/', $page)); +	foreach ($items as $item) { +		if ($item->getName() == $tab_name) { +			$item->setSelected(); +			elgg_set_config('embed_tab', $item); +		} +	} + +	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) { + +	$container_guid = (int)get_input('container_guid'); +	if ($container_guid) { +		$container = get_entity($container_guid); + +		if (elgg_instanceof($container, 'group') && $container->isMember()) { +			// embedding inside a group so save file to group files +			elgg_set_page_owner_guid($container_guid); +		} +	} + +	echo elgg_view('embed/layout'); + +	// exit because this is in a modal display. +	exit; +} + +/** + * 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()) { + +	$container_guids = array(elgg_get_logged_in_user_guid()); +	if (elgg_get_page_owner_guid()) { +		$page_owner_guid = elgg_get_page_owner_guid(); +		if ($page_owner_guid != elgg_get_logged_in_user_guid()) { +			$container_guids[] = $page_owner_guid; +		} +	} + +	$defaults = array( +		'limit' => 6, +		'container_guids' => $container_guids, +		'item_class' => 'embed-item', +	); + +	$options = array_merge($defaults, $options); + +	return $options; +} diff --git a/mod/embed/views/default/embed/addcontentjs.php b/mod/embed/views/default/embed/addcontentjs.php new file mode 100644 index 000000000..ffed211f5 --- /dev/null +++ b/mod/embed/views/default/embed/addcontentjs.php @@ -0,0 +1,7 @@ +<?php  +/** + * Blank for compatibility. + * @deprecated 1.8 + */ + +elgg_deprecated_notice("The view 'embed/addcontentjs' has been deprecated.", 1.8); diff --git a/mod/embed/views/default/embed/css.php b/mod/embed/views/default/embed/css.php new file mode 100644 index 000000000..034c0fcfe --- /dev/null +++ b/mod/embed/views/default/embed/css.php @@ -0,0 +1,37 @@ +<?php +/** + * Elgg embed CSS - standard across all themes + *  + * @package embed + */ +?> +.embed-wrapper { +	width: 730px; +	min-height: 400px; +	margin: 20px 15px; +} +.embed-wrapper h2 { +	color: #333333; +	margin-bottom: 10px; +} +.embed-wrapper .elgg-item { +	cursor: pointer; +} + +/* *************************************** +	EMBED TABBED PAGE NAVIGATION +*************************************** */ +.embed-wrapper .elgg-tabs a:hover { +	color: #666; +} + +.embed-wrapper p { +	color: #333; +} +.embed-item { +	padding-left: 5px; +	padding-right: 5px; +} +.embed-item:hover { +	background-color: #eee; +} diff --git a/mod/embed/views/default/embed/item.php b/mod/embed/views/default/embed/item.php new file mode 100644 index 000000000..3060de879 --- /dev/null +++ b/mod/embed/views/default/embed/item.php @@ -0,0 +1,39 @@ +<?php +/** + * Embeddable content list item view + * + * @uses $vars['entity'] ElggEntity object + */ + +$entity = $vars['entity']; + +$title = $entity->title; +if (!$title) { +	$title = $entity->name; +} + +// different entity types have different title attribute names. +$title = isset($entity->name) ? $entity->name : $entity->title; +// don't let it be too long +$title = elgg_get_excerpt($title); + +$owner = $entity->getOwnerEntity(); +if ($owner) { +	$author_text = elgg_echo('byline', array($owner->name)); +	$date = elgg_view_friendly_time($entity->time_created); +	$subtitle = "$author_text $date"; +} else { +	$subtitle = ''; +} + +$params = array( +	'title' => $title, +	'entity' => $entity, +	'subtitle' => $subtitle, +	'tags' => FALSE, +); +$body = elgg_view('object/elements/summary', $params); + +$image = elgg_view_entity_icon($entity, 'small', array('link_class' => 'embed-insert')); + +echo elgg_view_image_block($image, $body); diff --git a/mod/embed/views/default/embed/layout.php b/mod/embed/views/default/embed/layout.php new file mode 100644 index 000000000..1ca263037 --- /dev/null +++ b/mod/embed/views/default/embed/layout.php @@ -0,0 +1,40 @@ +<?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'); +if ($selected->getData('view')) { +	$tab = elgg_view($selected->getData('view'), $vars); +} else { +	$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'); +	} +} + +$tab .= elgg_view('graphics/ajax_loader', array( +	'class' => 'embed-throbber mtl', +)); + +$container_info = elgg_view('input/hidden', array( +	'name' => 'embed_container_guid', +	'value' => elgg_get_page_owner_guid(), +)); + +echo <<<HTML +<div class="embed-wrapper"> +	$title +	$menu +	$tab +	$container_info +</div> +HTML; diff --git a/mod/embed/views/default/embed/list.php b/mod/embed/views/default/embed/list.php new file mode 100644 index 000000000..c13639cff --- /dev/null +++ b/mod/embed/views/default/embed/list.php @@ -0,0 +1,58 @@ +<?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['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; 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..e84427f24 --- /dev/null +++ b/mod/embed/views/default/js/embed/embed.php @@ -0,0 +1,147 @@ +//<script> +elgg.provide('elgg.embed'); + +elgg.embed.init = function() { + +	// inserts the embed content into the textarea +	$(".embed-item").live('click', elgg.embed.insert); + +	// caches the current textarea id +	$(".embed-control").live('click', function() { +		var classes = $(this).attr('class'); +		var embedClass = classes.split(/[, ]+/).pop(); +		var textAreaId = embedClass.substr(embedClass.indexOf('embed-control-') + "embed-control-".length); +		elgg.embed.textAreaId = textAreaId; +	}); + +	// special pagination helper for lightbox +	$('.embed-wrapper .elgg-pagination a').live('click', elgg.embed.forward); + +	$('.embed-section').live('click', elgg.embed.forward); + +	$('.elgg-form-embed').live('submit', elgg.embed.submit); +}; + +/** + * Inserts data attached to an embed list item in textarea + * + * @todo generalize lightbox closing + * + * @param {Object} event + * @return void + */ +elgg.embed.insert = function(event) { +	var textAreaId = elgg.embed.textAreaId; +	var textArea = $('#' + textAreaId); + +	// generalize this based on a css class attached to what should be inserted +	var content = ' ' + $(this).find(".embed-insert").parent().html() + ' '; + +	// this is a temporary work-around for #3971 +	if (content.indexOf('thumbnail.php') != -1) { +		content = content.replace('size=small', 'size=medium'); +	} + +	textArea.val(textArea.val() + content); +	textArea.focus(); +	 +<?php +// See the TinyMCE plugin for an example of this view +echo elgg_view('embed/custom_insert_js'); +?> + +	$.fancybox.close(); + +	event.preventDefault(); +}; + +/** + * Submit an upload form through Ajax + * + * Requires the jQuery Form Plugin. Because files cannot be uploaded with + * XMLHttpRequest, the plugin uses an invisible iframe. This results in the + * the X-Requested-With header not being set. To work around this, we are + * sending the header as a POST variable and Elgg's code checks for it in + * elgg_is_xhr(). + * + * @param {Object} event + * @return bool + */ +elgg.embed.submit = function(event) { +	$('.embed-wrapper .elgg-form-file-upload').hide(); +	$('.embed-throbber').show(); +	 +	$(this).ajaxSubmit({ +		dataType : 'json', +		data     : { 'X-Requested-With' : 'XMLHttpRequest'}, +		success  : function(response) { +			if (response) { +				if (response.system_messages) { +					elgg.register_error(response.system_messages.error); +					elgg.system_message(response.system_messages.success); +				} +				if (response.status >= 0) { +					var forward = $('input[name=embed_forward]').val(); +					var url = elgg.normalize_url('embed/tab/' + forward); +					url = elgg.embed.addContainerGUID(url); +					$('.embed-wrapper').parent().load(url); +				} else { +					// incorrect response, presumably an error has been displayed +					$('.embed-throbber').hide(); +					$('.embed-wrapper .elgg-form-file-upload').show(); +				} +			} + +			// ie 7 and 8 have a null response because of the use of an iFrame +			// so just show the list after upload. +			// http://jquery.malsup.com/form/#file-upload claims you can wrap JSON +			// in a textarea, but a quick test didn't work, and that is fairly +			// intrusive to the rest of the ajax system. +			else if (response === undefined && $.browser.msie) { +				var forward = $('input[name=embed_forward]').val(); +				var url = elgg.normalize_url('embed/tab/' + forward); +				url = elgg.embed.addContainerGUID(url); +				$('.embed-wrapper').parent().load(url); +			} +		}, +		error    : function(xhr, status) { +			// @todo nothing for now +		} +	}); + +	// this was bubbling up the DOM causing a submission +	event.preventDefault(); +	event.stopPropagation(); +}; + +/** + * Loads content within the lightbox + * + * @param {Object} event + * @return void + */ +elgg.embed.forward = function(event) { +	// make sure container guid is passed +	var url = $(this).attr('href'); +	url = elgg.embed.addContainerGUID(url); + +	$('.embed-wrapper').parent().load(url); +	event.preventDefault(); +}; + +/** + * Adds the container guid to a URL + * + * @param {string} url + * @return string + */ +elgg.embed.addContainerGUID = function(url) { +	if (url.indexOf('container_guid=') == -1) { +		var guid = $('input[name=embed_container_guid]').val(); +		return url + '?container_guid=' + guid; +	} else { +		return url; +	} +}; + +elgg.register_hook_handler('init', 'system', elgg.embed.init); diff --git a/mod/embed/views/default/navigation/menu/embed.php b/mod/embed/views/default/navigation/menu/embed.php new file mode 100644 index 000000000..bca673f59 --- /dev/null +++ b/mod/embed/views/default/navigation/menu/embed.php @@ -0,0 +1,18 @@ +<?php +/** + * Embed tabs + * + * @uses $vars['menu']['default'] + */ + +$tabs = array(); +foreach ($vars['menu']['default'] as $menu_item) { +	$tabs[] = array( +		'title' => $menu_item->getText(), +		'url' => 'embed/tab/' . $menu_item->getName(), +		'link_class' => 'embed-section', +		'selected' => $menu_item->getSelected(), +	); +} + +echo elgg_view('navigation/tabs', array('tabs' => $tabs));  | 
