PluginProbe
MaxGalleria / 2.4
MaxGalleria v2.4
6.5.3 trunk 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.2.2 2.3 2.4 2.5 2.6 2.6.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 All 135 releases
maxgalleria / maxgalleria.php

maxgalleria.php in MaxGalleria 2.4, at maxgalleria.php

649 lines 22.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: MaxGalleria
4 Plugin URI: http://maxgalleria.com
5 Description: The gallery platform for WordPress.
6 Version: 2.4
7 Author: Max Foundry
8 Author URI: http://maxfoundry.com
9
10 Copyright 2014 Max Foundry, LLC (http://maxfoundry.com)
11 */
12
13 class MaxGalleria {
14 private $_addons;
15
16 public $admin;
17 public $common;
18 public $meta;
19 public $nextgen;
20 public $settings;
21 public $shortcode;
22 public $shortcode_thumb;
23 public $new_gallery;
24 public $image_gallery;
25 public $video_gallery;
26 public $gallery_widget;
27 public $gallery_thumb_widget;
28
29 public function __construct() {
30 $this->_addons = array();
31
32 $this->set_global_constants();
33 $this->set_activation_hooks();
34 $this->initialize_properties();
35 $this->add_thumb_sizes();
36 $this->setup_hooks();
37 $this->register_media_sources();
38 $this->register_templates();
39 }
40
41 function activate() {
42 update_option(MAXGALLERIA_VERSION_KEY, MAXGALLERIA_VERSION_NUM);
43
44 // Copy gallery post type template file to theme directory
45 $source = MAXGALLERIA_PLUGIN_DIR . '/single-maxgallery.php';
46 $destination = $this->get_theme_dir() . '/single-maxgallery.php';
47 copy($source, $destination);
48
49 flush_rewrite_rules();
50 }
51
52 public function add_thumb_sizes() {
53 // In addition to the thumbnail support when registering the custom post type, we need to add theme support
54 // to properly handle the featured image for a gallery, just in case the theme itself doesn't have it.
55 add_theme_support('post-thumbnails');
56
57 // Additional sizes, cropped
58 add_image_size(MAXGALLERIA_META_IMAGE_THUMB_SMALL, 100, 100, true);
59 add_image_size(MAXGALLERIA_META_IMAGE_THUMB_MEDIUM, 150, 150, true);
60 add_image_size(MAXGALLERIA_META_IMAGE_THUMB_LARGE, 200, 200, true);
61 add_image_size(MAXGALLERIA_META_VIDEO_THUMB_SMALL, 150, 100, true);
62 add_image_size(MAXGALLERIA_META_VIDEO_THUMB_MEDIUM, 200, 133, true);
63 add_image_size(MAXGALLERIA_META_VIDEO_THUMB_LARGE, 250, 166, true);
64 }
65
66 public function admin_page_is_maxgallery_post_type($post_id = 0) {
67 global $post;
68 global $post_type;
69
70 if (isset($post_id) && $post_id > 0 && get_post_type($post_id) == MAXGALLERIA_POST_TYPE) {
71 return true;
72 }
73
74 if (isset($_GET['post']) && $_GET['post'] > 0 && get_post_type($_GET['post']) == MAXGALLERIA_POST_TYPE) {
75 return true;
76 }
77
78 if (isset($_GET['post_type']) && $_GET['post_type'] == MAXGALLERIA_POST_TYPE) {
79 return true;
80 }
81
82 if (isset($post_type) && $post_type == MAXGALLERIA_POST_TYPE) {
83 return true;
84 }
85
86 if (isset($post) && $post->post_type == MAXGALLERIA_POST_TYPE) {
87 return true;
88 }
89
90 return false;
91 }
92
93 public function admin_page_is_media_edit() {
94 if ($this->common->url_contains('wp-admin/media.php') && $this->common->url_contains('action=edit')) {
95 return true;
96 }
97
98 return false;
99 }
100
101 public function admin_page_is_post_edit() {
102 if ($this->common->url_contains('wp-admin/post.php') && $this->common->url_contains('action=edit')) {
103 return true;
104 }
105
106 return false;
107 }
108
109 public function call_function_for_each_site($function) {
110 global $wpdb;
111
112 // Hold this so we can switch back to it
113 $current_blog = $wpdb->blogid;
114
115 // Get all the blogs/sites in the network and invoke the function for each one
116 $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
117 foreach ($blog_ids as $blog_id) {
118 switch_to_blog($blog_id);
119 call_user_func($function);
120 }
121
122 // Now switch back to the root blog
123 switch_to_blog($current_blog);
124 }
125
126 public function create_gallery_columns($column) {
127 // The Title and Date columns are standard, so we don't have to explicitly provide output for them
128
129 global $post;
130 $maxgallery = new MaxGalleryOptions($post->ID);
131
132 // Get all the attachments (the -1 gets all of them)
133 $args = array('post_parent' => $post->ID, 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'asc', 'numberposts' => -1);
134 $attachments = get_posts($args);
135
136 // Rounded borders
137 $style = 'border-radius: 2px; -moz-border-radius: 2px; -webkit-border-radius: 2px;';
138
139 switch ($column) {
140 case 'type':
141 if ($maxgallery->is_image_gallery()) {
142 echo '<img src="' . MAXGALLERIA_PLUGIN_URL . '/images/image-32.png" alt="' . __('Image', 'maxgalleria') . '" title="' . __('Image', 'maxgalleria') . '" style="' . $style . '" />';
143 }
144
145 if ($maxgallery->is_video_gallery()) {
146 echo '<img src="' . MAXGALLERIA_PLUGIN_URL . '/images/video-32.png" alt="' . __('Video', 'maxgalleria') . '" title="' . __('Video', 'maxgalleria') . '" style="' . $style . '" />';
147 }
148
149 break;
150 case 'thumbnail':
151 if (has_post_thumbnail($post->ID)) {
152 echo get_the_post_thumbnail($post->ID, array(32, 32), array('style' => $style));
153 }
154 else {
155 // Show the first thumb
156 foreach ($attachments as $attachment) {
157 $no_media_icon = 0;
158 echo wp_get_attachment_image($attachment->ID, array(32, 32), $no_media_icon, array('style' => $style));
159 break;
160 }
161 }
162 break;
163 case 'template':
164 $template_key = $maxgallery->get_template();
165 echo $this->get_template_name($template_key);
166 break;
167 case 'number':
168 if ($maxgallery->is_image_gallery()) {
169 if (count($attachments) == 0) { _e('0 images', 'maxgalleria'); }
170 if (count($attachments) == 1) { _e('1 image', 'maxgalleria'); }
171 if (count($attachments) > 1) { printf(__('%d images', 'maxgalleria'), count($attachments)); }
172 }
173
174 if ($maxgallery->is_video_gallery()) {
175 if (count($attachments) == 0) { _e('0 videos', 'maxgalleria'); }
176 if (count($attachments) == 1) { _e('1 video', 'maxgalleria'); }
177 if (count($attachments) > 1) { printf(__('%d videos', 'maxgalleria'), count($attachments)); }
178 }
179
180 break;
181 case 'shortcode':
182 echo '[maxgallery id="' . $post->ID . '"]';
183
184 if ($post->post_status == 'publish') {
185 echo '<br />';
186 echo '[maxgallery name="' . $post->post_name . '"]';
187 }
188
189 break;
190 }
191 }
192
193 public function create_plugin_action_links($links, $file) {
194 static $this_plugin;
195
196 if (!$this_plugin) {
197 $this_plugin = plugin_basename(__FILE__);
198 }
199
200 if ($file == $this_plugin) {
201 $settings_link = '<a href="' . admin_url() . 'edit.php?post_type=' . MAXGALLERIA_POST_TYPE . '&page=maxgalleria-settings">' . __('Settings', 'maxgalleria') . '</a>';
202 array_unshift($links, $settings_link);
203
204 $galleries_link = '<a href="' . admin_url() . 'edit.php?post_type=' . MAXGALLERIA_POST_TYPE . '">' . __('Galleries', 'maxgalleria') . '</a>';
205 array_unshift($links, $galleries_link);
206 }
207
208 return $links;
209 }
210
211 public function create_sortable_gallery_columns($vars) {
212 if (isset($vars['orderby'])) {
213 switch ($vars['orderby']) {
214 case 'type':
215 $vars = array_merge($vars, array('meta_key' => 'maxgallery_type', 'orderby' => 'meta_value'));
216 break;
217 case 'template':
218 $vars = array_merge($vars, array('meta_key' => 'maxgallery_template', 'orderby' => 'meta_value'));
219 break;
220 }
221 }
222
223 return $vars;
224 }
225
226 function deactivate() {
227 delete_option(MAXGALLERIA_VERSION_KEY);
228
229 // Delete the gallery post type template file from the theme directory
230 $file = $this->get_theme_dir() . '/single-maxgallery.php';
231 unlink($file);
232
233 flush_rewrite_rules();
234 }
235
236 public function define_gallery_columns($columns) {
237 $columns = apply_filters(MAXGALLERIA_FILTER_GALLERY_COLUMNS, array(
238 'cb' => '<input type="checkbox" />',
239 'title' => __('Title', 'maxgalleria'),
240 'thumbnail' => __('Thumbnail', 'maxgalleria'),
241 'type' => __('Type', 'maxgalleria'),
242 'template' => __('Template', 'maxgalleria'),
243 'number' => __('Number of Media', 'maxgalleria'),
244 'shortcode' => __('Shortcode', 'maxgalleria'),
245 'date' => __('Date', 'maxgalleria')
246 ));
247
248 return $columns;
249 }
250
251 public function define_sortable_gallery_columns($columns) {
252 // Title and Date are sortable by default
253
254 $columns['type'] = 'type';
255 $columns['template'] = 'template';
256 $columns['number'] = 'number';
257
258 return $columns;
259 }
260
261 public function do_activation($network_wide) {
262 if ($network_wide) {
263 $this->call_function_for_each_site(array($this, 'activate'));
264 }
265 else {
266 $this->activate();
267 }
268 }
269
270 public function do_deactivation($network_wide) {
271 if ($network_wide) {
272 $this->call_function_for_each_site(array($this, 'deactivate'));
273 }
274 else {
275 $this->deactivate();
276 }
277 }
278
279 public function enqueue_admin_print_scripts() {
280 if ($this->admin_page_is_maxgallery_post_type()) {
281 wp_enqueue_script('thickbox');
282 wp_enqueue_script('media-upload');
283
284 // For the media uploader
285 wp_enqueue_media();
286 wp_enqueue_script('maxgalleria-media-script', MAXGALLERIA_PLUGIN_URL . '/js/media.js', array('jquery'));
287
288 // Other stuff
289 wp_enqueue_script('jquery-ui-core');
290 wp_enqueue_script('jquery-ui-tabs');
291 wp_enqueue_script('maxgalleria-datatables', MAXGALLERIA_PLUGIN_URL . '/libs/datatables/jquery.dataTables.min.js', array('jquery'));
292 wp_enqueue_script('maxgalleria-datatables-row-reordering', MAXGALLERIA_PLUGIN_URL . '/libs/datatables/jquery.dataTables.rowReordering.js', array('jquery'));
293 wp_enqueue_script('maxgalleria-fancybox', MAXGALLERIA_PLUGIN_URL . '/libs/fancybox/jquery.fancybox-1.3.4.pack.js', array('jquery'));
294 wp_enqueue_script('maxgalleria-easing', MAXGALLERIA_PLUGIN_URL . '/libs/fancybox/jquery.easing-1.3.pack.js', array('jquery'));
295 wp_enqueue_script('maxgalleria-simplemodal', MAXGALLERIA_PLUGIN_URL . '/libs/simplemodal/jquery.simplemodal-1.4.3.min.js', array('jquery'));
296 }
297 }
298
299 public function enqueue_admin_print_styles() {
300 if ($this->admin_page_is_maxgallery_post_type()) {
301 wp_enqueue_style('thickbox');
302 wp_enqueue_style('maxgalleria-jquery-ui', MAXGALLERIA_PLUGIN_URL . '/libs/jquery-ui/jquery-ui.css');
303 wp_enqueue_style('maxgalleria-fancybox', MAXGALLERIA_PLUGIN_URL . '/libs/fancybox/jquery.fancybox-1.3.4.css');
304 wp_enqueue_style('maxgalleria-simplemodal', MAXGALLERIA_PLUGIN_URL . '/libs/simplemodal/simplemodal.css');
305 wp_enqueue_style('maxgalleria', MAXGALLERIA_PLUGIN_URL . '/maxgalleria.css');
306 }
307 }
308
309 public function get_all_addons() {
310 return $this->_addons;
311 }
312
313 public function get_media_source_addons() {
314 $media_source_addons = array();
315
316 foreach ($this->_addons as $addon) {
317 if ($addon['type'] == 'media_source') {
318 array_push($media_source_addons, $addon);
319 }
320 }
321
322 return $media_source_addons;
323 }
324
325 public function get_template_addons() {
326 $template_addons = array();
327
328 foreach ($this->_addons as $addon) {
329 if ($addon['type'] == 'template') {
330 array_push($template_addons, $addon);
331 }
332 }
333
334 return $template_addons;
335 }
336
337 public function get_template_name($template_key) {
338 $template_name = '';
339 $templates = $this->get_template_addons();
340
341 foreach ($templates as $template) {
342 if ($template['key'] == $template_key) {
343 $template_name = $template['name'];
344 break;
345 }
346 }
347
348 return $template_name;
349 }
350
351 public function get_theme_dir() {
352 return ABSPATH . 'wp-content/themes/' . get_template();
353 }
354
355 public function hide_add_new() {
356 global $submenu;
357 unset($submenu['edit.php?post_type=' . MAXGALLERIA_POST_TYPE][10]);
358 }
359
360 public function initialize_properties() {
361 // The order doesn't really matter, except maxgallery-options.php must be included first so
362 // that the MaxGalleryOptions class can be created in other parts of the system as needed
363
364 require_once 'maxgallery-options.php';
365 require_once 'maxgalleria-admin.php';
366 require_once 'maxgalleria-common.php';
367 require_once 'maxgalleria-meta.php';
368 require_once 'maxgalleria-nextgen.php';
369 require_once 'maxgalleria-settings.php';
370 require_once 'maxgalleria-shortcode.php';
371 require_once 'maxgalleria-shortcode-thumb.php';
372 require_once 'maxgalleria-new-gallery.php';
373 require_once 'maxgalleria-image-gallery.php';
374 require_once 'maxgalleria-video-gallery.php';
375 require_once 'widgets/gallery-widget.php';
376 require_once 'widgets/gallery-thumb-widget.php';
377
378 $this->admin = new MaxGalleriaAdmin();
379 $this->common = new MaxGalleriaCommon();
380 $this->meta = new MaxGalleriaMeta();
381 $this->nextgen = new MaxGalleriaNextGen();
382 $this->settings = new MaxGalleriaSettings();
383 $this->shortcode = new MaxGalleriaShortcode();
384 $this->shortcode_thumb = new MaxGalleriaShortcodeThumb();
385 $this->new_gallery = new MaxGalleriaNewGallery();
386 $this->image_gallery = new MaxGalleriaImageGallery();
387 $this->video_gallery = new MaxGalleriaVideoGallery();
388 $this->gallery_widget = new MaxGalleriaGalleryWidget();
389 $this->gallery_thumb_widget = new MaxGalleriaGalleryThumbWidget();
390 }
391
392 public function load_textdomain() {
393 load_plugin_textdomain('maxgalleria', false, dirname(plugin_basename(__FILE__)) . '/languages/');
394 }
395
396 public function media_button($context) {
397 global $pagenow, $wp_version;
398 $output = '';
399
400 // Only run in post/page creation and edit screens
401 if (in_array($pagenow, array('post.php', 'page.php', 'post-new.php', 'post-edit.php'))) {
402 $title = __('Add Gallery', 'maxgalleria');
403 $icon = MAXGALLERIA_PLUGIN_URL . '/images/maxgalleria-icon-16.png';
404 $img = '<span class="wp-media-buttons-icon" style="background-image: url(' . $icon . '); width: 16px; height: 16px; margin-top: 1px;"></span>';
405 $output = '<a href="#TB_inline?width=640&inlineId=select-maxgallery-container" class="thickbox button" title="' . $title . '" style="padding-left: .4em;">' . $img . ' ' . $title . '</a>';
406 }
407
408 return $context . $output;
409 }
410
411 public function media_button_admin_footer() {
412 require_once 'maxgalleria-media-button.php';
413 }
414
415 public function register_gallery_post_type() {
416 $slug = $this->settings->get_rewrite_slug();
417 $exclude_from_search = $this->settings->get_exclude_galleries_from_search();
418 $exclude_from_search = $exclude_from_search == 'on' ? true : false;
419
420 $labels = apply_filters(MAXGALLERIA_FILTER_GALLERY_POST_TYPE_LABELS, array(
421 'name' => __('Galleries', 'maxgalleria'),
422 'singular_name' => __('Gallery', 'maxgalleria'),
423 'add_new' => __('Add New', 'maxgalleria'),
424 'add_new_item' => __('Add New Gallery', 'maxgalleria'),
425 'edit_item' => __('Edit Gallery', 'maxgalleria'),
426 'new_item' => __('New Gallery', 'maxgalleria'),
427 'view_item' => __('View Gallery', 'maxgalleria'),
428 'search_items' => __('Search Galleries', 'maxgalleria'),
429 'not_found' => __('No galleries found', 'maxgalleria'),
430 'not_found_in_trash' => __('No galleries found in trash', 'maxgalleria'),
431 'parent_item_colon' => ''
432 ));
433
434 $args = apply_filters(MAXGALLERIA_FILTER_GALLERY_POST_TYPE_ARGS, array(
435 'labels' => $labels,
436 'public' => true,
437 'publicly_queryable' => true,
438 'show_ui' => true,
439 'show_in_menu' => true,
440 'query_var' => true,
441 'menu_icon' => MAXGALLERIA_PLUGIN_URL . '/images/maxgalleria-icon-16.png',
442 'rewrite' => array('slug' => $slug),
443 'capability_type' => 'post',
444 'hierarchical' => false,
445 'supports' => array('title', 'thumbnail'),
446 'taxonomies' => array('category', 'post_tag'),
447 'exclude_from_search' => $exclude_from_search
448 ));
449
450 register_post_type(MAXGALLERIA_POST_TYPE, $args);
451 }
452
453 public function register_addon($addon) {
454 array_push($this->_addons, $addon);
455 }
456
457 public function register_media_sources() {
458 // YouTube
459 require_once MAXGALLERIA_PLUGIN_DIR . '/addons/media-sources/youtube/youtube.php';
460 $youtube = new MaxGalleriaYouTube();
461 $youtube_addon = array(
462 'key' => $youtube->addon_key,
463 'name' => $youtube->addon_name,
464 'type' => $youtube->addon_type,
465 'subtype' => $youtube->addon_subtype,
466 'settings' => $youtube->addon_settings
467 );
468 $this->register_addon($youtube_addon);
469 }
470
471 public function register_templates() {
472 // Image Tiles template
473 require_once MAXGALLERIA_PLUGIN_DIR . '/addons/templates/image-tiles/image-tiles.php';
474 $image_tiles = new MaxGalleriaImageTiles();
475 $image_tiles_addon = array(
476 'key' => $image_tiles->addon_key,
477 'name' => $image_tiles->addon_name,
478 'type' => $image_tiles->addon_type,
479 'subtype' => $image_tiles->addon_subtype,
480 'settings' => $image_tiles->addon_settings,
481 'image' => $image_tiles->addon_image,
482 'output' => $image_tiles->addon_output
483 );
484 $this->register_addon($image_tiles_addon);
485
486 // Video Tiles template
487 require_once MAXGALLERIA_PLUGIN_DIR . '/addons/templates/video-tiles/video-tiles.php';
488 $video_tiles = new MaxGalleriaVideoTiles();
489 $video_tiles_addon = array(
490 'key' => $video_tiles->addon_key,
491 'name' => $video_tiles->addon_name,
492 'type' => $video_tiles->addon_type,
493 'subtype' => $video_tiles->addon_subtype,
494 'settings' => $video_tiles->addon_settings,
495 'image' => $video_tiles->addon_image,
496 'output' => $video_tiles->addon_output
497 );
498 $this->register_addon($video_tiles_addon);
499 }
500
501 public function register_widgets() {
502 register_widget('MaxGalleriaGalleryWidget');
503 register_widget('MaxGalleriaGalleryThumbWidget');
504 }
505
506 public function set_activation_hooks() {
507 register_activation_hook(__FILE__, array($this, 'do_activation'));
508 register_deactivation_hook(__FILE__, array($this, 'do_deactivation'));
509 }
510
511 public function set_global_constants() {
512 define('MAXGALLERIA_VERSION_KEY', 'maxgalleria_version');
513 define('MAXGALLERIA_VERSION_NUM', '2.4');
514 define('MAXGALLERIA_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
515 define('MAXGALLERIA_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . MAXGALLERIA_PLUGIN_NAME);
516 define('MAXGALLERIA_PLUGIN_URL', plugin_dir_url('') . '/' . MAXGALLERIA_PLUGIN_NAME);
517 define('MAXGALLERIA_POST_TYPE', 'maxgallery');
518 define('MAXGALLERIA_SETTINGS', admin_url() . 'edit.php?post_type=' . MAXGALLERIA_POST_TYPE . '&page=maxgalleria-settings');
519 define('MAXGALLERIA_META_IMAGE_THUMB_SMALL', 'maxgallery-meta-image-thumb-small');
520 define('MAXGALLERIA_META_IMAGE_THUMB_MEDIUM', 'maxgallery-meta-image-thumb-medium');
521 define('MAXGALLERIA_META_IMAGE_THUMB_LARGE', 'maxgallery-meta-image-thumb-large');
522 define('MAXGALLERIA_META_VIDEO_THUMB_SMALL', 'maxgallery-meta-video-thumb-small');
523 define('MAXGALLERIA_META_VIDEO_THUMB_MEDIUM', 'maxgallery-meta-video-thumb-medium');
524 define('MAXGALLERIA_META_VIDEO_THUMB_LARGE', 'maxgallery-meta-video-thumb-large');
525 define('MAXGALLERIA_THUMB_SHAPE_LANDSCAPE', 'landscape');
526 define('MAXGALLERIA_THUMB_SHAPE_PORTRAIT', 'portrait');
527 define('MAXGALLERIA_THUMB_SHAPE_SQUARE', 'square');
528 define('MAXGALLERIA_SETTING_REWRITE_SLUG', 'maxgalleria_setting_rewrite_slug');
529 define('MAXGALLERIA_SETTING_EXCLUDE_GALLERIES_FROM_SEARCH', 'maxgalleria_setting_exlude_galleries_from_search');
530 define('MAXGALLERIA_SETTING_DEFAULT_IMAGE_GALLERY_TEMPLATE', 'maxgalleria_setting_default_image_gallery_template');
531 define('MAXGALLERIA_SETTING_DEFAULT_VIDEO_GALLERY_TEMPLATE', 'maxgalleria_setting_default_video_gallery_template');
532
533 // Bring in all the actions and filters
534 require_once 'maxgalleria-hooks.php';
535 }
536
537 public function set_icon_edit_image() {
538 if ($this->admin_page_is_maxgallery_post_type()) {
539 echo '<style>';
540 echo '#icon-edit { background: url("'. MAXGALLERIA_PLUGIN_URL . '/images/maxgalleria-icon-32.png' . '") no-repeat transparent; }';
541 echo '</style>';
542 }
543 }
544
545 public function setup_hooks() {
546 add_action('init', array($this, 'load_textdomain'));
547 add_action('init', array($this, 'register_gallery_post_type'));
548 add_filter('plugin_action_links', array($this, 'create_plugin_action_links'), 10, 2);
549 add_action('admin_print_scripts', array($this, 'enqueue_admin_print_scripts'));
550 add_action('admin_print_styles', array($this, 'enqueue_admin_print_styles'));
551 add_action('admin_head', array($this, 'set_icon_edit_image'));
552 add_action('admin_menu', array($this, 'hide_add_new'));
553 add_filter('manage_edit-' . MAXGALLERIA_POST_TYPE . '_columns', array($this, 'define_gallery_columns'));
554 add_filter('manage_edit-' . MAXGALLERIA_POST_TYPE . '_sortable_columns', array($this, 'define_sortable_gallery_columns'));
555 add_action('manage_posts_custom_column', array($this, 'create_gallery_columns'));
556 add_filter('request', array($this, 'create_sortable_gallery_columns'));
557 add_filter('media_upload_tabs', array($this, 'set_media_upload_tabs'), 50, 1);
558 add_filter('media_view_strings', array($this, 'set_media_view_strings'), 50, 1);
559 add_filter('post_mime_types', array($this, 'set_post_mime_types'), 50, 1);
560 add_filter('upload_mimes', array($this, 'set_upload_mimes'), 50, 1);
561 add_action('media_buttons_context', array($this, 'media_button'));
562 add_action('admin_footer', array($this, 'media_button_admin_footer'));
563 add_action('widgets_init', array($this, 'register_widgets'));
564 }
565
566 public function set_media_upload_tabs($tabs) {
567 // Remove the "From URL", "Gallery", and "NextGEN" tabs from the media library popup.
568 // Only the tabs "From Computer" and "Media Library" should be shown.
569
570 if ($this->admin_page_is_maxgallery_post_type()) {
571 unset($tabs['type_url']); // From URL tab
572 unset($tabs['gallery']); // Gallery tab
573 unset($tabs['nextgen']); // NextGEN tab
574 }
575
576 return $tabs;
577 }
578
579 public function set_media_view_strings($strings) {
580 if ($this->admin_page_is_maxgallery_post_type()) {
581 // Remove these
582 unset($strings['insertFromUrlTitle']);
583 unset($strings['setFeaturedImageTitle']);
584 unset($strings['createGalleryTitle']);
585 unset($strings['createPlaylistTitle']);
586 unset($strings['createVideoPlaylistTitle']);
587
588 // Change these for better context in MaxGalleria galleries
589 $strings['insertMediaTitle'] = __('Add Images', 'maxgalleria');
590 $strings['insertIntoPost'] = __('Add to Gallery', 'maxgalleria');
591 $strings['uploadedToThisPost'] = __('Added to this gallery', 'maxgalleria');
592 }
593
594 return $strings;
595 }
596
597 public function set_post_mime_types($mime_types) {
598 // Remove the video and audio types
599
600 if ($this->admin_page_is_maxgallery_post_type()) {
601 unset($mime_types['video']);
602 unset($mime_types['audio']);
603 }
604
605 return $mime_types;
606 }
607
608 public function set_upload_mimes($mime_types) {
609 // Only allow image file type uploads. The complete list allowed by WordPress is
610 // located in the get_allowed_mime_types() function in wp-includes/functions.php.
611
612 if ($this->admin_page_is_maxgallery_post_type()) {
613 $mime_types = array(
614 'jpg|jpeg|jpe' => 'image/jpeg',
615 'gif' => 'image/gif',
616 'png' => 'image/png',
617 'bmp' => 'image/bmp',
618 'tif/tiff' => 'image/tiff'
619 );
620 }
621
622 return $mime_types;
623 }
624
625 public function thickbox_l10n_fix() {
626 // When combining scripts, localization is lost for thickbox.js, so we call this
627 // function to fix it. See http://wordpress.org/support/topic/plugin-affecting-photo-galleriessliders
628 // for more details.
629 echo '<script type="text/javascript">';
630 echo "var thickboxL10n = " . json_encode(array(
631 'next' => __('Next >'),
632 'prev' => __('< Prev'),
633 'image' => __('Image'),
634 'of' => __('of'),
635 'close' => __('Close'),
636 'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'),
637 'loadingAnimation' => includes_url('js/thickbox/loadingAnimation.gif'),
638 'closeImage' => includes_url('js/thickbox/tb-close.png')));
639 echo '</script>';
640 }
641
642 }
643
644
645
646
647 // Let's get this party started
648 $maxgalleria = new MaxGalleria();
649 ?>