lightbox2.insert.inc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // $Id: lightbox2.insert.inc,v 1.1.2.6 2010/09/22 10:47:15 snpower Exp $
  3. /**
  4. * @file
  5. * Lightbox2 support for Insert module.
  6. */
  7. /**
  8. * Implementation of hook_insert_styles().
  9. */
  10. function lightbox2_insert_styles() {
  11. $cck_formatters = lightbox2_field_formatter_info();
  12. $insert_styles = array();
  13. // Reformat CCK formatter ids as Insert style ids.
  14. foreach ($cck_formatters as $formatter_id => $formatter_info) {
  15. // Currently only the "imagefield--lightbox2" formatters are implemented as styles.
  16. if (preg_match('/^imagefield__lightbox2__((?:_(?!_)|[^_])+)__((?:_(?!_)|[^_])+)$/', $formatter_id, $matches)) {
  17. $style_id = 'lightbox2--' . $matches[1] . '--' . $matches[2];
  18. $insert_styles[$style_id] = $formatter_info;
  19. }
  20. }
  21. return $insert_styles;
  22. }
  23. /**
  24. * Implementation of hook_insert_content().
  25. */
  26. function lightbox2_insert_content($item, $style, $widget) {
  27. if (preg_match('/^lightbox2--((?:-(?!-)|[^-])+)--((?:-(?!-)|[^-])+)$/', $style['name'], $matches)) {
  28. $image_preset_name = $matches[1];
  29. $link_preset_name = $matches[2];
  30. return theme('lightbox2_insert_image', $item, $widget, 'view', $image_preset_name, $link_preset_name);
  31. }
  32. else {
  33. return '';
  34. }
  35. }
  36. /**
  37. * Theme the content that will be inserted for Lightbox2 presets.
  38. */
  39. function template_preprocess_lightbox2_insert_image(&$vars) {
  40. if ($vars['image_preset_name'] != 'original') {
  41. $filepath = imagecache_create_path($vars['image_preset_name'], $vars['item']['filepath']);
  42. }
  43. else {
  44. $filepath = $vars['item']['filepath'];
  45. }
  46. $vars['url'] = insert_create_url($filepath);
  47. if ($vars['link_preset_name'] != 'original') {
  48. $linkpath = imagecache_create_path($vars['link_preset_name'], $vars['item']['filepath']);
  49. }
  50. else {
  51. $linkpath = $vars['item']['filepath'];
  52. }
  53. $vars['linkurl'] = insert_create_url($linkpath);
  54. $vars['download_link'] = '';
  55. $download_link_text = check_plain(variable_get('lightbox2_download_link_text', 'Download Original'));
  56. if (!empty($download_link_text) && user_access('download original image')) {
  57. $vars['download_link'] = '<br /><br />' . l($download_link_text, $vars['linkurl'], array('attributes' => array('target' => '_blank', 'id' => 'lightbox2-download-link-text')));
  58. }
  59. $vars['class'] = !empty($vars['widget']['insert_class']) ? $vars['widget']['insert_class'] : '';
  60. }