PluginProbe
MaxGalleria / 2.6
MaxGalleria v2.6
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.6, at maxgalleria.php

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