summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStella Power2010-03-07 23:01:46 (GMT)
committer Stella Power2010-03-07 23:01:46 (GMT)
commit10946343c1cb5fdc60da27d3b14e78ea351d66cb (patch)
tree184e5ca6930a66d1272689c029e712141008f3f0
parentea497dd0ff75188b3969d08252510e080e550524 (diff)
#613946 by origo - support for insert module
-rw-r--r--lightbox2-insert-image.tpl.php26
-rw-r--r--lightbox2.insert.inc53
-rw-r--r--lightbox2.module14
3 files changed, 93 insertions, 0 deletions
diff --git a/lightbox2-insert-image.tpl.php b/lightbox2-insert-image.tpl.php
new file mode 100644
index 0000000..a68f065
--- /dev/null
+++ b/lightbox2-insert-image.tpl.php
@@ -0,0 +1,26 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Template file for Lightbox2 content inserted via the Insert module.
+ *
+ * Available variables:
+ * - $item: The complete item being inserted.
+ * - $url: The URL to the image.
+ * - $linkurl: The URL to the image being linked to.
+ * - $class: A set of classes assigned to this image (if any).
+ * - $image_preset_name: The ImageCache preset being used for the image.
+ * - $link_preset_name: The ImageCache preset being used for the linked to image.
+ *
+ * Note that ALT and Title fields should not be filled in here, instead they
+ * should use placeholders that will be updated through JavaScript when the
+ * image is inserted.
+ *
+ * Available placeholders:
+ * - __alt__: The ALT text, intended for use in the <img> tag.
+ * - __title__: The Title text, intended for use in the <img> tag.
+ * - __description__: A description of the image, sometimes used as a caption.
+ */
+?>
+<a rel="lightbox[group1][__description__]" href="<?php print $linkurl ?>"><img src="<?php print $url ?>" alt="__alt__" title="__title__" class="imagecache-<?php print $image_preset_name ?><?php print $class ? ' ' . $class : '' ?>" /></a> \ No newline at end of file
diff --git a/lightbox2.insert.inc b/lightbox2.insert.inc
new file mode 100644
index 0000000..b3d5c74
--- /dev/null
+++ b/lightbox2.insert.inc
@@ -0,0 +1,53 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Lightbox2 support for Insert module.
+ */
+
+/**
+ * Implementation of hook_insert_styles().
+ */
+function lightbox2_insert_styles() {
+ $insert_styles = lightbox2_field_formatter_info();
+ return $insert_styles;
+}
+
+/**
+ * Implementation of hook_insert_content().
+ */
+function lightbox2_insert_content($item, $style, $widget) {
+ if (preg_match('/^lightbox2--((?:-(?!-)|[^-])+)--((?:-(?!-)|[^-])+)$/', $style['name'], $matches)) {
+ $image_preset_name = $matches[1];
+ $link_preset_name = $matches[2];
+ return theme('lightbox2_insert_image', $item, $widget, 'view', $image_preset_name, $link_preset_name);
+ }
+ else {
+ return '';
+ }
+}
+
+/**
+ * Theme the content that will be inserted for Lightbox2 presets.
+ */
+function template_preprocess_lightbox2_insert_image(&$vars) {
+ if ($vars['image_preset_name'] != 'original') {
+ $filepath = imagecache_create_path($vars['image_preset_name'], $vars['item']['filepath']);
+ }
+ else {
+ $filepath = $vars['item']['filepath'];
+ }
+ $vars['url'] = insert_create_url($filepath);
+
+ if ($vars['link_preset_name'] != 'original') {
+ $linkpath = imagecache_create_path($vars['link_preset_name'], $vars['item']['filepath']);
+ }
+ else {
+ $linkpath = $vars['item']['filepath'];
+ }
+ $vars['linkurl'] = insert_create_url($linkpath);
+
+ $vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : '';
+}
+
diff --git a/lightbox2.module b/lightbox2.module
index 7849ac4..c22d9af 100644
--- a/lightbox2.module
+++ b/lightbox2.module
@@ -242,6 +242,11 @@ function lightbox2_menu() {
* Implementation of hook_init().
*/
function lightbox2_init() {
+ // Insert support
+ if (module_exists('insert')) {
+ module_load_include('inc', 'lightbox2', 'lightbox2.insert');
+ }
+
if (lightbox2_exclude_these_paths() != 1) {
lightbox2_add_files();
}
@@ -922,6 +927,15 @@ function lightbox2_theme() {
}
}
+ // Additional Insert theme functions.
+ if (module_exists('insert')) {
+ // Theme functions in lightbox2.insert.inc.
+ $theme['lightbox2_insert_image'] = array(
+ 'arguments' => array('item' => NULL, 'widget' => NULL, 'type' => NULL, 'image_preset_name' => NULL, 'link_preset_name' => NULL),
+ 'template' => 'lightbox2-insert-image',
+ );
+ }
+
return $theme;
}