C_Widget_Gallery

The NextGEN Gallery C Widget Gallery class.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/widget/package.module.widget.php  
  1. class C_Widget_Gallery extends WP_Widget 
  2. function __construct() 
  3. $widget_ops = array('classname' => 'ngg_images', 'description' => __('Add recent or random images from the galleries', 'nggallery')); 
  4. parent::__construct('ngg-images', __('NextGEN Widget', 'nggallery'), $widget_ops); 
  5. function form($instance) 
  6. // used for rendering utilities 
  7. $parent = C_Widget::get_instance(); 
  8. // defaults 
  9. $instance = wp_parse_args((array) $instance, array('exclude' => 'all', 'height' => '75', 'items' => '4', 'list' => '', 'show' => 'thumbnail', 'title' => 'Gallery', 'type' => 'recent', 'webslice' => TRUE, 'width' => '100')); 
  10. $parent->render_partial('photocrati-widget#form_gallery', array('self' => $this, 'instance' => $instance, 'title' => esc_attr($instance['title']), 'items' => intval($instance['items']), 'height' => esc_attr($instance['height']), 'width' => esc_attr($instance['width']))); 
  11. function update($new_instance, $old_instance) 
  12. $instance = $old_instance; 
  13. // do not allow 0 or less 
  14. if ((int) $new_instance['items'] <= 0) { 
  15. $new_instance['items'] = 4; 
  16. // for clarity: empty the list if we're showing every gallery anyway 
  17. if ($new_instance['exclude'] == 'all') { 
  18. $new_instance['list'] = ''; 
  19. // remove gallery ids that do not exist 
  20. if (in_array($new_instance['exclude'], array('denied', 'allow'))) { 
  21. // do search 
  22. $mapper = C_Gallery_Mapper::get_instance(); 
  23. $ids = explode(', ', $new_instance['list']); 
  24. foreach ($ids as $ndx => $id) { 
  25. if (!$mapper->find($id)) { 
  26. unset($ids[$ndx]); 
  27. $new_instance['list'] = implode(', ', $ids); 
  28. // reset to show all galleries IF there are no valid galleries in the list 
  29. if ($new_instance['exclude'] !== 'all' && empty($new_instance['list'])) { 
  30. $new_instance['exclude'] = 'all'; 
  31. $instance['title'] = strip_tags($new_instance['title']); 
  32. $instance['items'] = (int) $new_instance['items']; 
  33. $instance['type'] = $new_instance['type']; 
  34. $instance['show'] = $new_instance['show']; 
  35. $instance['width'] = (int) $new_instance['width']; 
  36. $instance['height'] = (int) $new_instance['height']; 
  37. $instance['exclude'] = $new_instance['exclude']; 
  38. $instance['list'] = $new_instance['list']; 
  39. $instance['webslice'] = (bool) $new_instance['webslice']; 
  40. return $instance; 
  41. function widget($args, $instance) 
  42. $router = C_Router::get_instance(); 
  43. wp_enqueue_style('nextgen_widgets_style', $router->get_static_url('photocrati-widget#widgets.css'), FALSE, NGG_SCRIPT_VERSION); 
  44. wp_enqueue_style('nextgen_basic_thumbnails_style', $router->get_static_url('photocrati-nextgen_basic_gallery#thumbnails/nextgen_basic_thumbnails.css'), FALSE, NGG_SCRIPT_VERSION); 
  45. // these are handled by extract() but I want to silence my IDE warnings that these vars don't exist 
  46. $before_widget = NULL; 
  47. $before_title = NULL; 
  48. $after_widget = NULL; 
  49. $after_title = NULL; 
  50. $widget_id = NULL; 
  51. extract($args); 
  52. $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base); 
  53. $renderer = C_Displayed_Gallery_Renderer::get_instance(); 
  54. $factory = C_Component_Factory::get_instance(); 
  55. $view = $factory->create('mvc_view', ''); 
  56. // IE8 webslice support if needed 
  57. if (!empty($instance['webslice'])) { 
  58. $before_widget .= '<div class="hslice" id="ngg-webslice">'; 
  59. $before_title = str_replace('class="', 'class="entry-title ', $before_title); 
  60. $after_widget = '</div>' . $after_widget; 
  61. $source = $instance['type'] == 'random' ? 'random_images' : 'recent'; 
  62. $template = !empty($instance['template']) ? $instance['template'] : $view->get_template_abspath('photocrati-widget#display_gallery'); 
  63. $params = array('slug' => 'widget-' . $args['widget_id'], 'source' => $source, 'display_type' => NGG_BASIC_THUMBNAILS, 'images_per_page' => $instance['items'], 'maximum_entity_count' => $instance['items'], 'template' => $template, 'image_type' => $instance['show'] == 'original' ? 'full' : 'thumb', 'show_all_in_lightbox' => FALSE, 'show_slideshow_link' => FALSE, 'show_thumbnail_link' => FALSE, 'use_imagebrowser_effect' => FALSE, 'disable_pagination' => TRUE, 'image_width' => $instance['width'], 'image_height' => $instance['height'], 'ngg_triggers_display' => 'never', 'widget_setting_title' => $title, 'widget_setting_before_widget' => $before_widget, 'widget_setting_before_title' => $before_title, 'widget_setting_after_widget' => $after_widget, 'widget_setting_after_title' => $after_title, 'widget_setting_width' => $instance['width'], 'widget_setting_height' => $instance['height'], 'widget_setting_show_setting' => $instance['show'], 'widget_setting_widget_id' => $widget_id); 
  64. switch ($instance['exclude']) { 
  65. case 'all': 
  66. break; 
  67. case 'denied': 
  68. $mapper = C_Gallery_Mapper::get_instance(); 
  69. $gallery_ids = array(); 
  70. $list = explode(', ', $instance['list']); 
  71. foreach ($mapper->find_all() as $gallery) { 
  72. if (!in_array($gallery->{$gallery->id_field}, $list)) { 
  73. $gallery_ids[] = $gallery->{$gallery->id_field}; 
  74. $params['container_ids'] = implode(', ', $gallery_ids); 
  75. break; 
  76. case 'allow': 
  77. $params['container_ids'] = $instance['list']; 
  78. break; 
  79. echo $renderer->display_images($params);