Mixin_Attach_To_Post

The NextGEN Gallery Mixin Attach To Post class.

Defined (1)

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

/products/photocrati_nextgen/modules/attach_to_post/package.module.attach_to_post.php  
  1. class Mixin_Attach_To_Post extends Mixin 
  2. function _load_displayed_gallery() 
  3. $mapper = C_Displayed_Gallery_Mapper::get_instance(); 
  4. // Fetch the displayed gallery by ID 
  5. if ($id = $this->object->param('id')) { 
  6. $this->object->_displayed_gallery = $mapper->find($id, TRUE); 
  7. } else { 
  8. if (isset($_REQUEST['shortcode'])) { 
  9. $params = str_replace('ngg_images', '', base64_decode($_REQUEST['shortcode'])); 
  10. $params = stripslashes($params); 
  11. $params = str_replace(array('[', ']'), array('[', ']'), $params); 
  12. $params = shortcode_parse_atts($params); 
  13. $this->object->_displayed_gallery = C_Displayed_Gallery_Renderer::get_instance()->params_to_displayed_gallery($params); 
  14. // If all else fails, then create fresh with a new displayed gallery 
  15. if (empty($this->object->_displayed_gallery)) { 
  16. $this->object->_displayed_gallery = $mapper->create(); 
  17. function mark_script($script_tag) 
  18. $this->object->_marked_scripts[$script_tag] = true; 
  19. function enqueue_display_tab_js() 
  20. // Enqueue backbone.js library, required by the Attach to Post display tab 
  21. wp_enqueue_script('backbone'); 
  22. // provided by WP 
  23. $this->object->mark_script('backbone'); 
  24. // Ensure underscore sting, a helper utility 
  25. wp_enqueue_script('underscore.string', $this->get_static_url('photocrati-attach_to_post#underscore.string.js'), array('underscore'), NGG_SCRIPT_VERSION); 
  26. $this->object->mark_script('underscore.string'); 
  27. // Enqueue the backbone app for the display tab 
  28. // Get all entities used by the display tab 
  29. $context = 'attach_to_post'; 
  30. $gallery_mapper = $this->get_registry()->get_utility('I_Gallery_Mapper', $context); 
  31. $album_mapper = $this->get_registry()->get_utility('I_Album_Mapper', $context); 
  32. $image_mapper = $this->get_registry()->get_utility('I_Image_Mapper', $context); 
  33. $display_type_mapper = $this->get_registry()->get_utility('I_Display_Type_Mapper', $context); 
  34. $sources = C_Displayed_Gallery_Source_Manager::get_instance(); 
  35. $security = $this->get_registry()->get_utility('I_Security_Manager'); 
  36. $settings = C_NextGen_Settings::get_instance(); 
  37. // Get the nextgen tags 
  38. global $wpdb; 
  39. $tags = $wpdb->get_results("SELECT DISTINCT name AS 'id', name FROM {$wpdb->terms}\n WHERE term_id IN (\n SELECT term_id FROM {$wpdb->term_taxonomy}\n WHERE taxonomy = 'ngg_tag'\n )"); 
  40. $all_tags = new stdClass(); 
  41. $all_tags->name = "All"; 
  42. $all_tags->id = "All"; 
  43. array_unshift($tags, $all_tags); 
  44. $display_types = array(); 
  45. $registry = C_Component_Registry::get_instance(); 
  46. foreach ($display_type_mapper->find_all() as $display_type) { 
  47. if (isset($display_type->hidden_from_igw) && $display_type->hidden_from_igw || isset($display_type->hidden_from_ui) && $display_type->hidden_from_ui) { 
  48. continue; 
  49. $available = $registry->is_module_loaded($display_type->name); 
  50. if (!apply_filters('ngg_atp_show_display_type', $available, $display_type)) { 
  51. continue; 
  52. $display_types[] = $display_type; 
  53. usort($display_types, array($this->object, '_display_type_list_sort')); 
  54. wp_enqueue_script('ngg_display_tab', $this->get_static_url('photocrati-attach_to_post#display_tab.js'), array('jquery', 'backbone', 'underscore.string', 'photocrati_ajax')); 
  55. $this->object->mark_script('ngg_display_tab'); 
  56. wp_localize_script('ngg_display_tab', 'igw_data', array('displayed_gallery_preview_url' => $settings->gallery_preview_url, 'displayed_gallery' => $this->object->_displayed_gallery->get_entity(), 'sources' => $sources->get_all(), 'gallery_primary_key' => $gallery_mapper->get_primary_key_column(), 'galleries' => $gallery_mapper->find_all(), 'albums' => $album_mapper->find_all(), 'tags' => $tags, 'display_types' => $display_types, 'sec_token' => $security->get_request_token('nextgen_edit_displayed_gallery')->get_json(), 'image_primary_key' => $image_mapper->get_primary_key_column(), 'display_type_priority_base' => NGG_DISPLAY_PRIORITY_BASE, 'display_type_priority_step' => NGG_DISPLAY_PRIORITY_STEP, 'shortcode_ref' => isset($_REQUEST['ref']) ? floatval($_REQUEST['ref']) : null, 'i18n' => array('sources' => __('Sources', 'nggallery'), 'optional' => __('(optional)', 'nggallery'), 'slug_tooltip' => __('Sets an SEO-friendly name to this gallery for URLs. Currently only in use by the Pro Lightbox', 'nggallery'), 'slug_label' => __('Slug', 'nggallery'), 'no_entities' => __('No entities to display for this source', 'nggallery'), 'exclude_question' => __('Exlude?', 'nggallery'), 'select_gallery' => __('Select a gallery', 'nggallery'), 'galleries' => __('Galleries', 'nggallery'), 'albums' => __('Albums', 'nggallery')))); 
  57. function enqueue_backend_resources() 
  58. $this->call_parent('enqueue_backend_resources'); 
  59. $this->mark_script('jquery-ui-accordion'); 
  60. $this->mark_script('nextgen_display_settings_page_placeholder_stub'); 
  61. $this->mark_script('iris'); 
  62. $this->mark_script('wp-color-picker'); 
  63. $this->mark_script('nextgen_admin_page'); 
  64. $this->mark_script('ngg_select2'); 
  65. // Enqueue frame event publishing 
  66. wp_enqueue_script('frame_event_publisher'); 
  67. $this->object->mark_script('frame_event_publisher'); 
  68. // Enqueue JQuery UI libraries 
  69. wp_enqueue_script('jquery-ui-tabs'); 
  70. wp_enqueue_script('jquery-ui-sortable'); 
  71. wp_enqueue_script('jquery-ui-tooltip'); 
  72. wp_enqueue_script('ngg_tabs', $this->get_static_url('photocrati-attach_to_post#ngg_tabs.js'), FALSE, NGG_SCRIPT_VERSION); 
  73. $this->object->mark_script('jquery-ui-tabs'); 
  74. $this->object->mark_script('jquery-ui-sortable'); 
  75. $this->object->mark_script('jquery-ui-tooltip'); 
  76. $this->object->mark_script('ngg_tabs'); 
  77. wp_enqueue_style('buttons'); 
  78. // Ensure select2 
  79. wp_enqueue_style('ngg_select2'); 
  80. wp_enqueue_script('ngg_select2'); 
  81. $this->object->mark_script('ngg_select2'); 
  82. // Ensure that the Photocrati AJAX library is loaded 
  83. wp_enqueue_script('photocrati_ajax'); 
  84. $this->object->mark_script('photocrati_ajax'); 
  85. // Enqueue logic for the Attach to Post interface as a whole 
  86. wp_enqueue_script('ngg_attach_to_post', $this->get_static_url('photocrati-attach_to_post#attach_to_post.js'), FALSE, NGG_SCRIPT_VERSION); 
  87. wp_enqueue_style('ngg_attach_to_post', $this->get_static_url('photocrati-attach_to_post#attach_to_post.css'), FALSE, NGG_SCRIPT_VERSION); 
  88. $this->object->mark_script('ngg_attach_to_post'); 
  89. $this->enqueue_display_tab_js(); 
  90. // TODO: for now mark Pro scripts to ensure they are enqueued properly, remove this after Pro upgrade with tagging added 
  91. $display_types = array('photocrati-nextgen_pro_slideshow', 'photocrati-nextgen_pro_horizontal_filmstrip', 'photocrati-nextgen_pro_thumbnail_grid', 'photocrati-nextgen_pro_blog_gallery', 'photocrati-nextgen_pro_film'); 
  92. foreach ($display_types as $display_type) { 
  93. $this->object->mark_script($display_type . '-js'); 
  94. $this->object->mark_script('nextgen_pro_albums_settings_script'); 
  95. /** 
  96. * Renders the interface 
  97. */ 
  98. function index_action($return = FALSE) 
  99. $this->object->enqueue_backend_resources(); 
  100. $this->object->do_not_cache(); 
  101. // Enqueue resources 
  102. return $this->object->render_view('photocrati-attach_to_post#attach_to_post', array('page_title' => $this->object->_get_page_title(), 'tabs' => $this->object->_get_main_tabs()), $return); 
  103. /** 
  104. * Displays a preview image for the displayed gallery 
  105. */ 
  106. function preview_action() 
  107. $found_preview_pic = FALSE; 
  108. $dyn_thumbs = C_Dynamic_Thumbnails_Manager::get_instance(); 
  109. $storage = C_Gallery_Storage::get_instance(); 
  110. $image_mapper = C_Image_Mapper::get_instance(); 
  111. // Get the first entity from the displayed gallery. We will use this 
  112. // for a preview pic 
  113. $results = $this->object->_displayed_gallery->get_included_entities(1); 
  114. $entity = array_pop($results); 
  115. $image = FALSE; 
  116. if ($entity) { 
  117. // This is an album or gallery 
  118. if (isset($entity->previewpic)) { 
  119. $image = (int) $entity->previewpic; 
  120. if ($image = $image_mapper->find($image)) { 
  121. $found_preview_pic = TRUE; 
  122. } else { 
  123. if (isset($entity->galleryid)) { 
  124. $image = $entity; 
  125. $found_preview_pic = TRUE; 
  126. // Were we able to find a preview pic? If so, then render it 
  127. $image_size = $dyn_thumbs->get_size_name(array('width' => 300, 'height' => 200, 'quality' => 90, 'type' => 'jpg', 'watermark' => FALSE, 'crop' => TRUE)); 
  128. add_filter('ngg_before_save_thumbnail', array(&$this, 'set_igw_placeholder_text')); 
  129. $found_preview_pic = $storage->render_image($image, $image_size, TRUE); 
  130. remove_filter('ngg_before_save_thumbnail', array(&$this, 'set_igw_placeholder_text')); 
  131. // Render invalid image if no preview pic is found 
  132. if (!$found_preview_pic) { 
  133. $filename = $this->object->get_static_abspath('photocrati-attach_to_post#invalid_image.png'); 
  134. $this->set_content_type('image/png'); 
  135. readfile($filename); 
  136. $this->render(); 
  137. /** 
  138. * Filter for ngg_before_save_thumbnail 
  139. */ 
  140. function set_igw_placeholder_text($thumbnail) 
  141. $settings = C_NextGen_Settings::get_instance(); 
  142. $thumbnail->applyFilter(IMG_FILTER_BRIGHTNESS, -25); 
  143. $watermark_settings = apply_filters('ngg_igw_placeholder_line_1_settings', array('text' => __("NextGEN Gallery", 'nggallery'), 'font_color' => 'ffffff', 'font' => 'YanoneKaffeesatz-Bold.ttf', 'font_size' => 32)); 
  144. if ($watermark_settings) { 
  145. $thumbnail->watermarkText = $watermark_settings['text']; 
  146. $thumbnail->watermarkCreateText($watermark_settings['font_color'], $watermark_settings['font'], $watermark_settings['font_size'], 100); 
  147. $thumbnail->watermarkImage('topCenter', 0, 72); 
  148. $watermark_settings = apply_filters('ngg_igw_placeholder_line_2_settings', array('text' => __("Click to edit", 'nggallery'), 'font_color' => 'ffffff', 'font' => 'YanoneKaffeesatz-Bold.ttf', 'font_size' => 15)); 
  149. if ($watermark_settings) { 
  150. $thumbnail->watermarkText = $watermark_settings['text']; 
  151. $thumbnail->watermarkCreateText($watermark_settings['font_color'], $watermark_settings['font'], $watermark_settings['font_size'], 100); 
  152. $thumbnail->watermarkImage('topCenter', 0, 108); 
  153. return $thumbnail; 
  154. /** 
  155. * Returns the page title of the Attach to Post interface 
  156. * @return string 
  157. */ 
  158. function _get_page_title() 
  159. return __('NextGEN Gallery - Attach To Post', 'nggallery'); 
  160. /** 
  161. * Returns the main tabs displayed on the Attach to Post interface 
  162. * @returns array 
  163. */ 
  164. function _get_main_tabs() 
  165. $retval = array(); 
  166. $security = $this->get_registry()->get_utility('I_Security_Manager'); 
  167. $sec_actor = $security->get_current_actor(); 
  168. if ($sec_actor->is_allowed('NextGEN Manage gallery')) { 
  169. $retval['displayed_tab'] = array('content' => $this->object->_render_display_tab(), 'title' => __('Display Galleries', 'nggallery')); 
  170. if ($sec_actor->is_allowed('NextGEN Upload images')) { 
  171. $retval['create_tab'] = array('content' => $this->object->_render_create_tab(), 'title' => __('Add Gallery / Images', 'nggallery')); 
  172. if ($sec_actor->is_allowed('NextGEN Manage others gallery') && $sec_actor->is_allowed('NextGEN Manage gallery')) { 
  173. $retval['galleries_tab'] = array('content' => $this->object->_render_galleries_tab(), 'title' => __('Manage Galleries', 'nggallery')); 
  174. if ($sec_actor->is_allowed('NextGEN Edit album')) { 
  175. $retval['albums_tab'] = array('content' => $this->object->_render_albums_tab(), 'title' => __('Manage Albums', 'nggallery')); 
  176. if ($sec_actor->is_allowed('NextGEN Manage tags')) { 
  177. $retval['tags_tab'] = array('content' => $this->object->_render_tags_tab(), 'title' => __('Manage Tags', 'nggallery')); 
  178. return $retval; 
  179. /** 
  180. * Renders a NextGen Gallery page in an iframe, suited for the attach to post 
  181. * interface 
  182. * @param string $page 
  183. * @return string 
  184. */ 
  185. function _render_ngg_page_in_frame($page, $tab_id = null) 
  186. $frame_url = admin_url("/admin.php?page={$page}&attach_to_post"); 
  187. $frame_url = nextgen_esc_url($frame_url); 
  188. if ($tab_id) { 
  189. $tab_id = " id='ngg-iframe-{$tab_id}'"; 
  190. return "<iframe name='{$page}' frameBorder='0'{$tab_id} class='ngg-attach-to-post ngg-iframe-page-{$page}' scrolling='no' src='{$frame_url}'></iframe>"; 
  191. /** 
  192. * Renders the display tab for adjusting how images/galleries will be 
  193. * displayed 
  194. * @return type 
  195. */ 
  196. function _render_display_tab() 
  197. return $this->object->render_partial('photocrati-attach_to_post#display_tab', array('messages' => array(), 'displayed_gallery' => $this->object->_displayed_gallery, 'tabs' => $this->object->_get_display_tabs()), TRUE); 
  198. /** 
  199. * Renders the tab used primarily for Gallery and Image creation 
  200. * @return type 
  201. */ 
  202. function _render_create_tab() 
  203. return $this->object->_render_ngg_page_in_frame('ngg_addgallery', 'create_tab'); 
  204. /** 
  205. * Renders the tab used for Managing Galleries 
  206. * @return string 
  207. */ 
  208. function _render_galleries_tab() 
  209. return $this->object->_render_ngg_page_in_frame('nggallery-manage-gallery', 'galleries_tab'); 
  210. /** 
  211. * Renders the tab used for Managing Albums 
  212. */ 
  213. function _render_albums_tab() 
  214. return $this->object->_render_ngg_page_in_frame('nggallery-manage-album', 'albums_tab'); 
  215. /** 
  216. * Renders the tab used for Managing Albums 
  217. * @return string 
  218. */ 
  219. function _render_tags_tab() 
  220. return $this->object->_render_ngg_page_in_frame('nggallery-tags', 'tags_tab');