PluginProbe
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress / 2.01
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress v2.01
4.8.1 4.8.0 4.7.9 trunk 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.10 2.11 2.12 2011.1.01 2011.1.02 3.01 3.02 3.03 3.04 3.05 3.06 3.1 All 131 releases
gallery-plugin / gallery-plugin.php

gallery-plugin.php in Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress 2.01, at gallery-plugin.php

689 lines 28.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Gallery Plugin
4 Plugin URI: http://bestwebsoft.com/plugin/
5 Description: This plugin allows you to implement gallery page into web site.
6 Author: BestWebSoft
7 Version: 2.01
8 Author URI: http://bestwebsoft.com/
9 License: GPLv2 or later
10 */
11
12 /* © Copyright 2011 BestWebSoft ( admin@bestwebsoft.com )
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License, version 2, as
16 published by the Free Software Foundation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27 $gllr_boxes = array (
28 'Upload-File' => array (
29 array( '_gllr_uploadedFile', '', '', '', '' ),
30 )
31 );
32
33 if( ! function_exists( 'gllr_plugin_install' ) ) {
34 function gllr_plugin_install() {
35 if ( ! copy(WP_PLUGIN_DIR .'/gallery-plugin/template/gallery-template.php', TEMPLATEPATH .'/gallery-template.php' ) ) {
36 add_action( 'admin_notices', create_function( '', 'echo "Error copy template file";' ) );
37 }
38 if ( ! copy(WP_PLUGIN_DIR .'/gallery-plugin/template/gallery-single-template.php', TEMPLATEPATH .'/gallery-single-template.php') ) {
39 add_action( 'admin_notices', create_function( '', 'echo "Error copy template file";' ) );
40 }
41 }
42 }
43
44 if( ! function_exists( 'gllr_plugin_uninstall' ) ) {
45 function gllr_plugin_uninstall() {
46 if ( file_exists( TEMPLATEPATH .'/gallery-template.php' ) && ! unlink(TEMPLATEPATH .'/gallery-template.php') ) {
47 add_action( 'admin_notices', create_function( '', ' return "Error delete template file";' ) );
48 }
49 if ( file_exists( TEMPLATEPATH .'/gallery-single-template.php' ) && ! unlink(TEMPLATEPATH .'/gallery-single-template.php') ) {
50 add_action( 'admin_notices', create_function( '', ' return "Error delete template file";' ) );
51 }
52 if( get_option( 'gllr_options' ) ) {
53 delete_option( 'gllr_options' );
54 }
55 }
56 }
57
58 // Create post type for Gallery
59 if( ! function_exists( 'post_type_images' ) ) {
60 function post_type_images() {
61 register_post_type('gallery', array(
62 'labels' => array(
63 'name' => __( 'Galleries', 'gallery'),
64 'singular_name' => __( 'Gallery', 'gallery'),
65 'add_new' => __( 'Add New', 'gallery'),
66 'add_new_item' => __( 'Add New Gallery', 'gallery'),
67 'edit_item' => __( 'Edit Gallery', 'gallery'),
68 'new_item' => __( 'New Gallery', 'gallery'),
69 'view_item' => __( 'View Gallery', 'gallery'),
70 'search_items' => __( 'Search Galleries', 'gallery'),
71 'not_found' => __( 'No Galleries found', 'gallery'),
72 'parent_item_colon' => '',
73 'menu_name' => __( 'Galleries', 'gallery')
74 ),
75 'public' => true,
76 'publicly_queryable' => true,
77 'query_var' => true,
78 'rewrite' => true,
79 'capability_type' => 'post',
80 'has_archive' => false,
81 'hierarchical' => true,
82 'supports' => array('title', 'editor'),
83 'register_meta_box_cb' => 'init_metaboxes_gallery'
84 ));
85
86 wp_enqueue_style( 'gllrStylesheet', WP_PLUGIN_URL .'/gallery-plugin/css/stylesheet.css' );
87 wp_enqueue_style( 'gllrPrettyPhotoStylesheet', WP_PLUGIN_URL .'/gallery-plugin/pretty_photo/css/prettyPhoto.css' );
88 wp_enqueue_script( 'gllrPrettyPhotoJs', WP_PLUGIN_URL .'/gallery-plugin/pretty_photo/js/jquery.prettyPhoto.js', array( 'jquery' ) );
89 wp_enqueue_script( 'jquery_upload', WP_PLUGIN_URL .'/gallery-plugin/upload/fileuploader.js', array( 'jquery' ) );
90 wp_enqueue_style( 'jquery_css', WP_PLUGIN_URL .'/gallery-plugin/upload/fileuploader.css' );
91 }
92 }
93
94 if( ! function_exists( 'addImageAncestorToMenu' ) ) {
95 function addImageAncestorToMenu( $classes ) {
96 if ( is_singular( 'gallery' ) ) {
97 global $wpdb, $post;
98
99 if ( empty( $post->ancestors ) ) {
100 return $classes;
101 }
102
103 $menuQuery = "SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_menu_item_object_id' AND meta_value IN (" . implode(',', $post->ancestors) . ")";
104 $menuItems = $wpdb->get_col( $menuQuery );
105
106 if ( is_array( $menuItems ) ) {
107 foreach ( $menuItems as $menuItem ) {
108 if ( in_array( 'menu-item-' . $menuItem, $classes ) ) {
109 $classes[] = 'current-page-ancestor';
110 }
111 }
112 }
113 }
114
115 return $classes;
116 }
117 }
118
119 function init_metaboxes_gallery() {
120 add_meta_box( 'Upload-File', __( 'Upload File', 'gallery' ), 'gllr_post_custom_box', 'gallery', 'normal', 'high' );
121 }
122
123 // Create custom meta box for portfolio post type
124 if ( ! function_exists( 'gllr_post_custom_box' ) ) {
125 function gllr_post_custom_box( $obj = '', $box = '' ) {
126 global $post;
127 $key = "gllr_image_text";
128
129 $post_types = get_post_types( array( '_builtin' => false ) );
130 ?>
131 <div style="padding-top:10px;"><label for="uploadscreen"><?php echo __( 'Choose a screenshot to upload:', 'gallery' ); ?></label>
132 <input name="MAX_FILE_SIZE" value="1048576" type="hidden" />
133 <div id="file-uploader-demo1" style="padding-top:10px;">
134 <noscript>
135 <p><?php echo __( 'Please enable JavaScript to use the file uploader.', 'gallery' ); ?></p>
136 </noscript>
137 </div>
138 <ul id="files" ></ul>
139 <div id="hidden"></div>
140 <div style="clear:both;"></div></div>
141 <script type="text/javascript">
142 jQuery(document).ready(function()
143 {
144 var uploader = new qq.FileUploader({
145 element: document.getElementById('file-uploader-demo1'),
146 action: '<?php echo WP_PLUGIN_URL; ?>/gallery-plugin/upload/php.php',
147 debug: false,
148 onComplete: function(id, fileName, result) {
149 if(result.error) {
150 //
151 }
152 else {
153 jQuery('<li></li>').appendTo('#files').html('<img src="<?php echo WP_PLUGIN_URL; ?>/gallery-plugin/upload/files/'+fileName+'" alt="" /><div style="width:200px">'+fileName+'<br />' +result.width+'x'+result.height+'</div>').addClass('success');
154 jQuery('<input type="hidden" name="undefined[]" id="undefined" value="'+fileName+'" />').appendTo('#hidden');
155 }
156 }
157 });
158 jQuery('#images_albumdiv').remove();
159
160 });
161
162 function img_delete(id) {
163 jQuery('#'+id).hide();
164 jQuery('#delete_images').append('<input type="hidden" name="delete_images[]" value="'+id+'" />');
165 }
166 </script>
167 <?php
168
169 $posts = get_posts(array(
170 "showposts" => -1,
171 "what_to_show" => "posts",
172 "post_status" => "inherit",
173 "post_type" => "attachment",
174 "orderby" => "menu_order ASC, ID ASC",
175 "post_mime_type"=> "image/jpeg,image/gif,image/jpg,image/png",
176 "post_parent" => $post->ID)); ?>
177 <ul class="gallery clearfix">
178 <?php foreach ( $posts as $page ):
179 $image_text = get_post_meta( $page->ID, $key, FALSE );
180 echo '<li id="'.$page->ID.'" class="gllr_image_block">';
181 $image_attributes = wp_get_attachment_image_src( $page->ID, 'thumbnail' );
182 echo '<img src="'.$image_attributes[0].'" alt="'.$page->post_title.'" title="'.$page->post_title.'"/>';
183 echo '<input type="text" name="gllr_image_text['.$page->ID.']" value="'.get_post_meta( $page->ID, $key, TRUE ).'" class="gllr_image_text" />';
184 echo '<div class="delete"><a href="javascript:void(0);" onclick="img_delete('.$page->ID.');">Delete</a><div/>';
185 echo '</li>';
186 endforeach; ?>
187 </ul><div style="clear:both;"></div>
188 <div id="delete_images"></div>
189 <?php }
190 }
191
192 // Use nonce for verification ...
193 if( ! function_exists ( 'echo_gllr_nonce' ) ) {
194 function echo_gllr_nonce () {
195 echo sprintf(
196 '<input type="hidden" name="%1$s" id="%1$s" value="%2$s" />',
197 'gllr_nonce_name',
198 wp_create_nonce( plugin_basename(__FILE__) )
199 );
200 }
201 }
202
203 if ( ! function_exists ( 'gllr_save_postdata' ) ) {
204 function gllr_save_postdata( $post_id, $post ) {
205 global $post;
206 global $wpdb;
207 if( isset( $_REQUEST['undefined'] ) && ! empty( $_REQUEST['undefined'] ) ) {
208 $array_file_name = $_REQUEST['undefined'];
209 $uploadFile = array();
210 $newthumb = array();
211
212 $uploadDir = wp_upload_dir( );
213
214 while( list( $key, $val ) = each( $array_file_name ) ) {
215 $imagename = $val;
216 $uploadFile[] = $uploadDir["path"] ."/" . $imagename;
217 }
218 reset( $array_file_name );
219 require_once( ABSPATH . 'wp-admin/includes/image.php' );
220 $i = 0;
221 while( list( $key, $val ) = each( $array_file_name ) ) {
222 $file_name = $val;
223 if ( copy ( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name, $uploadFile[$i] ) ) {
224 unlink( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name );
225 $overrides = array('test_form' => false );
226
227 $file = str_replace( "\\", "/",$uploadDir["path"] ) ."/" .$file_name;
228 $filename = basename( $file );
229
230 $wp_filetype = wp_check_filetype( $filename, null );
231 $attachment = array(
232 'post_mime_type' => $wp_filetype['type'],
233 'post_title' => $filename,
234 'post_content' => '',
235 'post_status' => 'inherit'
236 );
237 $attach_id = wp_insert_attachment( $attachment, $file );
238 $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
239 wp_update_attachment_metadata( $attach_id, $attach_data );
240 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE ID = %d", $post->ID, $attach_id ) );
241 }
242 $i++;
243 }
244 }
245 $key = "gllr_image_text";
246 if( isset( $_REQUEST['delete_images'] ) ) {
247 foreach( $_REQUEST['delete_images'] as $delete_id ) {
248 delete_post_meta( $delete_id, $key );
249 wp_delete_attachment( $delete_id );
250 }
251 }
252 if( isset( $_REQUEST['gllr_image_text'] ) ) {
253 $posts = get_posts(array(
254 "showposts" => -1,
255 "what_to_show" => "posts",
256 "post_status" => "inherit",
257 "post_type" => "attachment",
258 "orderby" => "menu_order ASC, ID ASC",
259 "post_mime_type"=> "image/jpeg,image/gif,image/jpg,image/png",
260 "post_parent" => $post->ID));
261 foreach ( $posts as $page ) {
262 if( isset( $_REQUEST['gllr_image_text'][$page->ID] ) ) {
263 $value = $_REQUEST['gllr_image_text'][$page->ID];
264 if( get_post_meta( $page->ID, $key, FALSE ) && $value ) {
265 // Custom field has a value and this custom field exists in database
266 update_post_meta( $page->ID, $key, $value );
267 }
268 elseif($value) {
269 // Custom field has a value, but this custom field does not exist in database
270 add_post_meta( $page->ID, $key, $value );
271 }
272 }
273 }
274 }
275 }
276 }
277
278 if ( ! function_exists ( 'gllr_plugin_init' ) ) {
279 function gllr_plugin_init() {
280 // Internationalization, first(!)
281 load_plugin_textdomain( 'gallery', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
282 }
283 }
284
285 if( ! function_exists( 'gllr_custom_permalinks' ) ) {
286 function gllr_custom_permalinks() {
287 global $wp_rewrite;
288 global $wpdb;
289 $parent = $wpdb->get_var("SELECT $wpdb->posts.post_name FROM $wpdb->posts, $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = 'gallery-template.php' AND (post_status = 'publish' OR post_status = 'private') AND $wpdb->posts.ID = $wpdb->postmeta.post_id");
290 if( ! empty( $parent ) ) {
291 $wp_rewrite->add_rule( '(.+)/'.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[2]&posts_per_page=-1', 'top' );
292 $wp_rewrite->add_rule( ''.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[1]&posts_per_page=-1', 'top' );
293 $wp_rewrite->add_rule( '(.+)/'.$parent.'/page/([^/]+)/?$', 'index.php?pagename='.$parent.'&paged=$matches[2]', 'top' );
294 $wp_rewrite->add_rule( ''.$parent.'/page/([^/]+)/?$', 'index.php?pagename='.$parent.'&paged=$matches[1]', 'top' );
295 }
296
297 $wp_rewrite->flush_rules();
298 }
299 }
300
301 if ( ! function_exists( 'gllr_template_redirect' ) ) {
302 function gllr_template_redirect()
303 {
304 global $wp_query, $post, $posts;
305 if( 'gallery' == get_post_type() && "" == $wp_query->query_vars["s"] ) {
306 $category = get_term_by( 'slug', $wp_query->query_vars["taxonomy"], 'images_album');
307 if( 'private' == get_post_meta( $category->term_id, '_gllr_public_status', true ) && ! is_user_logged_in() ) {
308 @header( "Location: ".get_bloginfo( 'url' ) );
309 exit();
310 }
311 include( TEMPLATEPATH . '/gallery-single-template.php' );
312 exit();
313 }
314 }
315 }
316
317
318 // Change the columns for the edit CPT screen
319 if ( ! function_exists( 'gllr_change_columns' ) ) {
320 function gllr_change_columns( $cols ) {
321 $cols = array(
322 'cb' => '<input type="checkbox" />',
323 'title' => __( 'Title', 'gallery' ),
324 'autor' => __( 'Author', 'gallery' ),
325 'gallery' => __( 'Photo\'s', 'gallery' ),
326 'status' => __( 'Public', 'gallery' ),
327 'dates' => __( 'Date', 'gallery' )
328 );
329 return $cols;
330 }
331 }
332
333 if ( ! function_exists( 'gllr_custom_columns' ) ) {
334 function gllr_custom_columns( $column, $post_id ) {
335 global $wpdb;
336 $post = get_post( $post_id );
337 $row = $wpdb->get_results( "SELECT *
338 FROM $wpdb->posts
339 WHERE $wpdb->posts.post_parent = $post_id
340 AND $wpdb->posts.post_type = 'attachment'
341 AND (
342 $wpdb->posts.post_status = 'inherit'
343 )
344 ORDER BY $wpdb->posts.post_title ASC" );
345 switch ( $column ) {
346 //case "category":
347 case "autor":
348 $author_id=$post->post_author;
349 echo '<a href="edit.php?post_type=post&amp;author='.$author_id.'">'.get_the_author_meta( 'user_nicename' , $author_id ).'</a>';
350 break;
351 case "gallery":
352 echo count($row);
353 break;
354 case "status":
355 if( $post->post_status == 'publish' )
356 echo '<a href="javascript:void(0)">Yes</a>';
357 else
358 echo '<a href="javascript:void(0)">No</a>';
359 break;
360 case "dates":
361 echo strtolower( __( date( "F", strtotime( $post->post_date ) ), 'kerksite' ) )." ".date( "j Y", strtotime( $post->post_date ) );
362 break;
363 }
364 $wp_query = $old_query;
365 }
366 }
367
368 if ( ! function_exists( 'get_ID_by_slug' ) ) {
369 function get_ID_by_slug($page_slug) {
370 $page = get_page_by_path($page_slug);
371 if ($page) {
372 return $page->ID;
373 } else {
374 return null;
375 }
376 }
377 }
378
379 if ( ! function_exists( 'getPostsAvailableToRegisteredUsers' ) ) {
380 function getPostsAvailableToRegisteredUsers()
381 {
382 $theme_location = 'menu_2';
383 $theme_locations = get_nav_menu_locations();
384 if( ! isset( $theme_locations[$theme_location] ) ) return false;
385
386 $menu_obj = get_term( $theme_locations[$theme_location], 'nav_menu' );
387 if( ! $menu_obj )
388 $menu_obj = false;
389
390 global $wpdb;
391
392 // Menu posts
393 $menuPosts = $wpdb->get_col("
394 SELECT
395 pm.meta_value
396 FROM
397 $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON t.term_id = tt.term_id
398 INNER JOIN $wpdb->term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
399 INNER JOIN $wpdb->postmeta pm ON tr.object_id = pm.post_id
400 WHERE
401 t.slug = '".$menu_obj->slug."' AND
402 pm.meta_key = '_menu_item_object_id'
403 ");
404
405 if (empty($menuPosts))
406 {
407 $menuPosts = array();
408 }
409
410 // All private posts
411 $privatePosts = array();
412 while (count($menuPosts))
413 {
414 $postId = array_shift($menuPosts);
415 array_push($privatePosts, (int) $postId);
416
417 $childPosts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type IN ('document', 'page', 'image')", $postId));
418 if (is_array($childPosts) && count($childPosts))
419 {
420 $menuPosts = array_merge($menuPosts, $childPosts);
421 }
422 }
423
424 return array_unique($privatePosts);
425 }
426 }
427
428 if( ! function_exists( 'the_excerpt_max_charlength' ) ) {
429 function the_excerpt_max_charlength($charlength) {
430 $excerpt = get_the_excerpt();
431 $charlength++;
432 if( strlen( $excerpt ) > $charlength ) {
433 $subex = substr( $excerpt, 0, $charlength-5 );
434 $exwords = explode( " ", $subex );
435 $excut = - ( strlen ( $exwords [ count( $exwords ) - 1 ] ) );
436 if( $excut < 0 ) {
437 echo substr( $subex, 0, $excut );
438 }
439 else {
440 echo $subex;
441 }
442 echo "...";
443 }
444 else {
445 echo $excerpt;
446 }
447 }
448 }
449
450 if( ! function_exists( 'gllr_page_css_class' ) ) {
451 function gllr_page_css_class( $classes, $item ) {
452 $post_type = get_query_var( 'post_type' );
453 global $wpdb;
454 $parent_id = 0;
455 if( $post_type == "gallery" ) {
456 $parent_id = $wpdb->get_var("SELECT $wpdb->posts.ID FROM $wpdb->posts, $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = 'gallery-template.php' AND post_status = 'publish' AND $wpdb->posts.ID = $wpdb->postmeta.post_id");
457 while ($parent_id) {
458 $page = get_page($parent_id);
459 if($page->post_parent > 0 )
460 $parent_id = $page->post_parent;
461 else
462 break;
463 }
464 wp_reset_query();
465 }
466 if ($item->ID == $parent_id) {
467 array_push($classes, 'current_page_item');
468 }
469 return $classes;
470 }
471 }
472
473 if( ! function_exists( 'bws_add_menu_render' ) ) {
474 function bws_add_menu_render() {
475 global $title;
476 $active_plugins = get_option('active_plugins');
477 $all_plugins = get_plugins();
478
479 $array_activate = array();
480 $array_install = array();
481 $array_recomend = array();
482 $count_activate = $count_install = $count_recomend = 0;
483 $array_plugins = array(
484 array( 'captcha\/captcha.php', 'Captcha', 'http://wordpress.org/extend/plugins/captcha/', 'http://bestwebsoft.com/plugin/captcha-plugin/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Captcha+bestwebsoft&plugin-search-input=Search+Plugins', 'admin.php?page=captcha.php' ),
485 array( 'contact-form-plugin\/contact_form.php', 'Contact Form', 'http://wordpress.org/extend/plugins/contact-form-plugin/', 'http://bestwebsoft.com/plugin/contact-form/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Contact+Form+bestwebsoft&plugin-search-input=Search+Plugins', 'admin.php?page=contact_form.php' ),
486 array( 'facebook-button-plugin\/facebook-button-plugin.php', 'Facebook Like Button Plugin', 'http://wordpress.org/extend/plugins/facebook-button-plugin/', 'http://bestwebsoft.com/plugin/facebook-like-button-plugin/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Facebook+Like+Button+Plugin+bestwebsoft&plugin-search-input=Search+Plugins', 'admin.php?page=facebook-button-plugin.php' ),
487 array( 'twitter-plugin\/twitter.php', 'Twitter Plugin', 'http://wordpress.org/extend/plugins/twitter-plugin/', 'http://bestwebsoft.com/plugin/twitter-plugin/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Twitter+Plugin+bestwebsoft&plugin-search-input=Search+Plugins', 'admin.php?page=twitter.php' ),
488 array( 'portfolio\/portfolio.php', 'Portfolio', 'http://wordpress.org/extend/plugins/portfolio/', 'http://bestwebsoft.com/plugin/portfolio-plugin/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Portfolio+bestwebsoft&plugin-search-input=Search+Plugins', '' ),
489 array( 'gallery-plugin\/gallery-plugin.php', 'Gallery', 'http://wordpress.org/extend/plugins/gallery-plugin/', 'http://bestwebsoft.com/plugin/gallery-plugin/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Gallery+Plugin+bestwebsoft&plugin-search-input=Search+Plugins', '' ),
490 array( 'adsense-plugin\/adsense-plugin.php', 'Google AdSense Plugin', 'http://wordpress.org/extend/plugins/adsense-plugin/', 'http://bestwebsoft.com/plugin/google-adsense-plugin/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Adsense+Plugin+bestwebsoft&plugin-search-input=Search+Plugins', 'admin.php?page=adsense-plugin.php' )
491 );
492 foreach($array_plugins as $plugins)
493 {
494 if( 0 < count( preg_grep( "/".$plugins[0]."/", $active_plugins ) ) )
495 {
496 $array_activate[$count_activate]['title'] = $plugins[1];
497 $array_activate[$count_activate]['link'] = $plugins[2];
498 $array_activate[$count_activate]['href'] = $plugins[3];
499 $array_activate[$count_activate]['url'] = $plugins[5];
500 $count_activate++;
501 }
502 else if( array_key_exists(str_replace("\\", "", $plugins[0]), $all_plugins) )
503 {
504 $array_install[$count_install]['title'] = $plugins[1];
505 $array_install[$count_install]['link'] = $plugins[2];
506 $array_install[$count_install]['href'] = $plugins[3];
507 $count_install++;
508 }
509 else
510 {
511 $array_recomend[$count_recomend]['title'] = $plugins[1];
512 $array_recomend[$count_recomend]['link'] = $plugins[2];
513 $array_recomend[$count_recomend]['href'] = $plugins[3];
514 $array_recomend[$count_recomend]['slug'] = $plugins[4];
515 $count_recomend++;
516 }
517 }
518 ?>
519 <div class="wrap">
520 <div class="icon32 icon32-bws" id="icon-options-general"></div>
521 <h2><?php echo $title;?></h2>
522 <?php if( 0 < $count_activate ) { ?>
523 <div>
524 <h3><?php _e( 'Activated plugins', 'gallery' ); ?></h3>
525 <?php foreach( $array_activate as $activate_plugin ) { ?>
526 <div style="float:left; width:200px;"><?php echo $activate_plugin['title']; ?></div> <p><a href="<?php echo $activate_plugin['link']; ?>" target="_blank"><?php echo __( "Read more", 'gallery'); ?></a> <a href="<?php echo $activate_plugin['url']; ?>"><?php echo __( "Settings", 'gallery'); ?></a></p>
527 <?php } ?>
528 </div>
529 <?php } ?>
530 <?php if( 0 < $count_install ) { ?>
531 <div>
532 <h3><?php _e( 'Installed plugins', 'gallery' ); ?></h3>
533 <?php foreach($array_install as $install_plugin) { ?>
534 <div style="float:left; width:200px;"><?php echo $install_plugin['title']; ?></div> <p><a href="<?php echo $install_plugin['link']; ?>" target="_blank"><?php echo __( "Read more", 'gallery'); ?></a></p>
535 <?php } ?>
536 </div>
537 <?php } ?>
538 <?php if( 0 < $count_recomend ) { ?>
539 <div>
540 <h3><?php _e( 'Recommended plugins', 'gallery' ); ?></h3>
541 <?php foreach( $array_recomend as $recomend_plugin ) { ?>
542 <div style="float:left; width:200px;"><?php echo $recomend_plugin['title']; ?></div> <p><a href="<?php echo $recomend_plugin['link']; ?>" target="_blank"><?php echo __( "Read more", 'gallery'); ?></a> <a href="<?php echo $recomend_plugin['href']; ?>" target="_blank"><?php echo __( "Download", 'gallery'); ?></a> <a class="install-now" href="<?php echo get_bloginfo( "url" ) . $recomend_plugin['slug']; ?>" title="<?php esc_attr( sprintf( __( 'Install %s' ), $recomend_plugin['title'] ) ) ?>" target="_blank"><?php echo __( 'Install now from wordpress.org', 'gallery' ) ?></a></p>
543 <?php } ?>
544 <span style="color: rgb(136, 136, 136); font-size: 10px;"><?php _e( 'If you have any questions, please contact us via plugin@bestwebsoft.com or fill in our contact form on our site', 'gallery' ); ?> <a href="http://bestwebsoft.com/contact/">http://bestwebsoft.com/contact/</a></span>
545 </div>
546 <?php } ?>
547 </div>
548 <?php
549 }
550 }
551
552 if( ! function_exists( 'add_gllr_admin_menu' ) ) {
553 function add_gllr_admin_menu() {
554 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url("images/px.png", __FILE__), 1001);
555 add_submenu_page('bws_plugins', __( 'Gallery', 'gallery' ), __( 'Gallery', 'gallery' ), 'manage_options', "gallery-plugin.php", 'gllr_settings_page');
556
557 //call register settings function
558 add_action( 'admin_init', 'register_gllr_settings' );
559 }
560 }
561
562 // register settings function
563 if( ! function_exists( 'register_gllr_settings' ) ) {
564 function register_gllr_settings() {
565 global $wpmu;
566 global $gllr_options;
567
568 $gllr_option_defaults = array(
569 'gllr_custom_size_name' => array( 'album-thumb', 'photo-thumb' ),
570 'gllr_custom_size_px' => array( array(120, 80), array(160, 120) ),
571 'custom_image_row_count' => 3
572 );
573
574 // install the option defaults
575 if ( 1 == $wpmu ) {
576 if( !get_site_option( 'gllr_options' ) ) {
577 add_site_option( 'gllr_options', $gllr_option_defaults, '', 'yes' );
578 }
579 }
580 else {
581 if( !get_option( 'gllr_options' ) )
582 add_option( 'gllr_options', $gllr_option_defaults, '', 'yes' );
583 }
584
585 // get options from the database
586 if ( 1 == $wpmu )
587 $gllr_options = get_site_option( 'gllr_options' ); // get options from the database
588 else
589 $gllr_options = get_option( 'gllr_options' );// get options from the database
590
591 // array merge incase this version has added new options
592 $gllr_options = array_merge( $gllr_option_defaults, $gllr_options );
593 if ( function_exists( 'add_image_size' ) ) {
594 add_image_size( 'album-thumb', $gllr_options['gllr_custom_size_px'][0][0], $gllr_options['gllr_custom_size_px'][0][1], true );
595 add_image_size( 'photo-thumb', $gllr_options['gllr_custom_size_px'][1][0], $gllr_options['gllr_custom_size_px'][1][1], true );
596 }
597 }
598 }
599
600 if( ! function_exists( 'gllr_settings_page' ) ) {
601 function gllr_settings_page() {
602 global $gllr_options;
603 $error = "";
604
605 // Save data for settings page
606 if( isset( $_REQUEST['gllr_form_submit'] ) ) {
607 $gllr_request_options = array();
608 $gllr_request_options["gllr_custom_size_name"] = $gllr_options["gllr_custom_size_name"];
609
610 $gllr_request_options["gllr_custom_size_px"] = array(
611 array( intval( trim( $_REQUEST['custom_image_size_w_album'] ) ), intval( trim($_REQUEST['custom_image_size_h_album'] ) ) ),
612 array( intval( trim( $_REQUEST['custom_image_size_w_photo'] ) ), intval( trim($_REQUEST['custom_image_size_h_photo'] ) ) )
613 );
614 $gllr_request_options["custom_image_row_count"] = intval( trim( $_REQUEST['custom_image_row_count'] ) );
615 if( $gllr_request_options["custom_image_row_count"] == "" || $gllr_request_options["custom_image_row_count"] < 1 )
616 $gllr_request_options["custom_image_row_count"] = 1;
617
618 // array merge incase this version has added new options
619 $gllr_options = array_merge( $gllr_options, $gllr_request_options );
620
621 // Check select one point in the blocks Arithmetic actions and Difficulty on settings page
622 update_option( 'gllr_options', $gllr_options, '', 'yes' );
623 $message = __( "Options saved.", 'gallery' );
624 }
625
626 // Display form on the setting page
627 ?>
628 <div class="wrap">
629 <div class="icon32 icon32-bws" id="icon-options-general"></div>
630 <h2><?php _e('Gallery Options', 'gallery' ); ?></h2>
631 <div class="updated fade" <?php if( ! isset( $_REQUEST['gllr_form_submit'] ) || $error != "" ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>
632 <div class="error" <?php if( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div>
633 <form method="post" action="admin.php?page=gallery-plugin.php" id="gllr_form_image_size">
634 <table class="form-table">
635 <tr valign="top">
636 <th scope="row"><?php _e('The size of the cover album for gallery', 'gallery' ); ?> </th>
637 <td>
638 <label for="custom_image_size_name"><?php _e( 'Image size name', 'gallery' ); ?></label> <?php echo $gllr_options["gllr_custom_size_name"][0]; ?><br />
639 <label for="custom_image_size_w"><?php _e( 'Width (in px)', 'gallery' ); ?></label> <input type="text" name="custom_image_size_w_album" value="<?php echo $gllr_options["gllr_custom_size_px"][0][0]; ?>" /><br />
640 <label for="custom_image_size_h"><?php _e( 'Height (in px)', 'gallery' ); ?></label> <input type="text" name="custom_image_size_h_album" value="<?php echo $gllr_options["gllr_custom_size_px"][0][1]; ?>" />
641 </td>
642 </tr>
643 <tr valign="top">
644 <th scope="row"><?php _e('Size for gallery image', 'gallery' ); ?> </th>
645 <td>
646 <label for="custom_image_size_name"><?php _e( 'Image size name', 'gallery' ); ?></label> <?php echo $gllr_options["gllr_custom_size_name"][1]; ?><br />
647 <label for="custom_image_size_w"><?php _e( 'Width (in px)', 'gallery' ); ?></label> <input type="text" name="custom_image_size_w_photo" value="<?php echo $gllr_options["gllr_custom_size_px"][1][0]; ?>" /><br />
648 <label for="custom_image_size_h"><?php _e( 'Height (in px)', 'gallery' ); ?></label> <input type="text" name="custom_image_size_h_photo" value="<?php echo $gllr_options["gllr_custom_size_px"][1][1]; ?>" />
649 </td>
650 </tr>
651 <tr valign="top">
652 <td colspan="2"><span style="color: #888888;font-size: 10px;"><?php _e( 'WordPress will create a copy of the post thumbnail with the specified dimensions when you upload a new photo.', 'gallery' ); ?></span></th>
653 </tr>
654 <tr valign="top">
655 <th scope="row"><?php _e('Count images in row', 'gallery' ); ?> </th>
656 <td>
657 <input type="text" name="custom_image_row_count" value="<?php echo $gllr_options["custom_image_row_count"]; ?>" />
658 </td>
659 </tr>
660 </table>
661 <input type="hidden" name="gllr_form_submit" value="submit" />
662 <p class="submit">
663 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
664 </p>
665 </form>
666 </div>
667 <?php }
668 }
669
670 register_activation_hook( __FILE__, 'gllr_plugin_install'); // activate plugin
671 register_uninstall_hook( __FILE__, 'gllr_plugin_uninstall'); // deactivate plugin
672
673 add_action( 'admin_menu', 'add_gllr_admin_menu' );
674 add_action( 'init', 'gllr_plugin_init' );
675
676 add_action( 'init', 'post_type_images' ); // register post type
677 add_action( 'init', 'gllr_custom_permalinks' ); // add custom permalink for gallery
678
679 add_action( 'template_redirect', 'gllr_template_redirect' ); // add themplate for single gallery page
680
681 add_action( 'save_post', 'gllr_save_postdata', 1, 2 ); // save custom data from admin
682
683 add_filter( 'nav_menu_css_class', 'addImageAncestorToMenu' );
684 add_filter( 'page_css_class', 'gllr_page_css_class', 10, 2 );
685
686 add_filter( 'manage_gallery_posts_columns', 'gllr_change_columns' );
687 add_action( 'manage_gallery_posts_custom_column', 'gllr_custom_columns', 10, 2 );
688
689 ?>