PluginProbe
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress / 3.01
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress v3.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 3.01, at gallery-plugin.php

745 lines 33.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: 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: 3.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 ( ! file_exists( get_stylesheet_directory() .'/gallery-template.php' ) ) {
36 @copy( WP_PLUGIN_DIR .'/gallery-plugin/template/gallery-template.php', get_stylesheet_directory() .'/gallery-template.php' );
37 }
38 else {
39 @copy( get_stylesheet_directory() .'/gallery-template.php', get_stylesheet_directory() .'/gallery-template.php.bak' );
40 @copy( WP_PLUGIN_DIR .'/gallery-plugin/template/gallery-template.php', get_stylesheet_directory() .'/gallery-template.php' );
41 }
42 if ( ! file_exists( get_stylesheet_directory() .'/gallery-single-template.php' ) ) {
43 @copy( WP_PLUGIN_DIR .'/gallery-plugin/template/gallery-single-template.php', get_stylesheet_directory() .'/gallery-single-template.php' );
44 }
45 else {
46 @copy( get_stylesheet_directory() .'/gallery-single-template.php', get_stylesheet_directory() .'/gallery-single-template.php.bak' );
47 @copy( WP_PLUGIN_DIR .'/gallery-plugin/template/gallery-single-template.php', get_stylesheet_directory() .'/gallery-single-template.php' );
48 }
49 }
50 }
51
52 if( ! function_exists( 'gllr_admin_error' ) ) {
53 function gllr_admin_error() {
54 $post = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : "" ;
55 $post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : "" ;
56 if ( ( 'gallery' == get_post_type( $post ) || 'gallery' == $post_type ) && ( ! file_exists( get_stylesheet_directory() .'/gallery-template.php' ) || ! file_exists( get_stylesheet_directory() .'/gallery-single-template.php' ) ) ) {
57 echo '<div class="error"><p><strong>'.__( 'The following files "gallery-template.php" and "gallery-single-template.php" were not found in the directory of your theme. Please copy them from the directory `/wp-content/plugins/gallery-plugin/template/` to the directory of your theme for the correct work of the Gallery plugin', 'gallery' ).'</strong></p></div>';
58 }
59 }
60 }
61
62 if( ! function_exists( 'gllr_plugin_uninstall' ) ) {
63 function gllr_plugin_uninstall() {
64 if ( file_exists( get_stylesheet_directory() .'/gallery-template.php' ) && ! unlink( get_stylesheet_directory() .'/gallery-template.php' ) ) {
65 add_action( 'admin_notices', create_function( '', ' return "Error delete template file";' ) );
66 }
67 if ( file_exists( get_stylesheet_directory() .'/gallery-single-template.php' ) && ! unlink( get_stylesheet_directory() .'/gallery-single-template.php' ) ) {
68 add_action( 'admin_notices', create_function( '', ' return "Error delete template file";' ) );
69 }
70 if( get_option( 'gllr_options' ) ) {
71 delete_option( 'gllr_options' );
72 }
73 }
74 }
75
76 // Create post type for Gallery
77 if( ! function_exists( 'post_type_images' ) ) {
78 function post_type_images() {
79 register_post_type('gallery', array(
80 'labels' => array(
81 'name' => __( 'Galleries', 'gallery' ),
82 'singular_name' => __( 'Gallery', 'gallery' ),
83 'add_new' => __( 'Add New', 'gallery' ),
84 'add_new_item' => __( 'Add New Gallery', 'gallery' ),
85 'edit_item' => __( 'Edit Gallery', 'gallery' ),
86 'new_item' => __( 'New Gallery', 'gallery' ),
87 'view_item' => __( 'View Gallery', 'gallery' ),
88 'search_items' => __( 'Search Galleries', 'gallery' ),
89 'not_found' => __( 'No Galleries found', 'gallery' ),
90 'parent_item_colon' => '',
91 'menu_name' => __( 'Galleries', 'gallery' )
92 ),
93 'public' => true,
94 'publicly_queryable' => true,
95 'query_var' => true,
96 'rewrite' => true,
97 'capability_type' => 'post',
98 'has_archive' => false,
99 'hierarchical' => true,
100 'supports' => array('title', 'editor', 'thumbnail', 'author' ),
101 'register_meta_box_cb' => 'init_metaboxes_gallery'
102 ));
103 }
104 }
105
106 if( ! function_exists( 'addImageAncestorToMenu' ) ) {
107 function addImageAncestorToMenu( $classes ) {
108 if ( is_singular( 'gallery' ) ) {
109 global $wpdb, $post;
110
111 if ( empty( $post->ancestors ) ) {
112 $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" );
113 while ( $parent_id ) {
114 $page = get_page( $parent_id );
115 if( $page->post_parent > 0 )
116 $parent_id = $page->post_parent;
117 else
118 break;
119 }
120 wp_reset_query();
121 if( empty( $parent_id ) )
122 return $classes;
123 $post_ancestors = array( $parent_id );
124 }
125 else {
126 $post_ancestors = $post->ancestors;
127 }
128
129 $menuQuery = "SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_menu_item_object_id' AND meta_value IN (" . implode(',', $post_ancestors) . ")";
130 $menuItems = $wpdb->get_col( $menuQuery );
131
132 if ( is_array( $menuItems ) ) {
133 foreach ( $menuItems as $menuItem ) {
134 if ( in_array( 'menu-item-' . $menuItem, $classes ) ) {
135 $classes[] = 'current-page-ancestor';
136 }
137 }
138 }
139 }
140
141 return $classes;
142 }
143 }
144
145 function init_metaboxes_gallery() {
146 add_meta_box( 'Upload-File', __( 'Upload File', 'gallery' ), 'gllr_post_custom_box', 'gallery', 'normal', 'high' );
147 }
148
149 // Create custom meta box for portfolio post type
150 if ( ! function_exists( 'gllr_post_custom_box' ) ) {
151 function gllr_post_custom_box( $obj = '', $box = '' ) {
152 global $post;
153 $key = "gllr_image_text";
154 $error = "";
155 $uploader = true;
156
157 $post_types = get_post_types( array( '_builtin' => false ) );
158 if( ! is_writable ( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/" ) )
159 @chmod( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/", 0777 );
160 if( ! is_writable ( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/" ) ) {
161 $error = "The gallery temp directory not writeable by your webserver. Пожалуйста, используйте стандартный функционал wp для загрузки изобюражений (медиа библиотеку)";
162 $uploader = false;
163 }
164 ?>
165 <div style="padding-top:10px;"><label for="uploadscreen"><?php echo __( 'Choose a screenshot to upload:', 'gallery' ); ?></label>
166 <input name="MAX_FILE_SIZE" value="1048576" type="hidden" />
167 <div id="file-uploader-demo1" style="padding-top:10px;">
168 <?php echo $error; ?>
169 <noscript>
170 <p><?php echo __( 'Please enable JavaScript to use the file uploader.', 'gallery' ); ?></p>
171 </noscript>
172 </div>
173 <ul id="files" ></ul>
174 <div id="hidden"></div>
175 <div style="clear:both;"></div></div>
176 <script type="text/javascript">
177 <?php if ($uploader === true) { ?>
178 jQuery(document).ready(function()
179 {
180 var uploader = new qq.FileUploader({
181 element: document.getElementById('file-uploader-demo1'),
182 action: '<?php echo plugins_url( "upload/php.php" , __FILE__ ); ?>',
183 debug: false,
184 onComplete: function(id, fileName, result) {
185 if(result.error) {
186 //
187 }
188 else {
189 jQuery('<li></li>').appendTo('#files').html('<img src="<?php echo plugins_url( "upload/files/" , __FILE__ ); ?>'+fileName+'" alt="" /><div style="width:200px">'+fileName+'<br />' +result.width+'x'+result.height+'</div>').addClass('success');
190 jQuery('<input type="hidden" name="undefined[]" id="undefined" value="'+fileName+'" />').appendTo('#hidden');
191 }
192 }
193 });
194 jQuery('#images_albumdiv').remove();
195
196 });
197 <?php } ?>
198 function img_delete(id) {
199 jQuery('#'+id).hide();
200 jQuery('#delete_images').append('<input type="hidden" name="delete_images[]" value="'+id+'" />');
201 }
202 </script>
203 <?php
204
205 $posts = get_posts(array(
206 "showposts" => -1,
207 "what_to_show" => "posts",
208 "post_status" => "inherit",
209 "post_type" => "attachment",
210 "orderby" => "menu_order",
211 "order" => "ASC",
212 "post_mime_type"=> "image/jpeg,image/gif,image/jpg,image/png",
213 "post_parent" => $post->ID)); ?>
214 <ul class="gallery clearfix">
215 <?php foreach ( $posts as $page ):
216 $image_text = get_post_meta( $page->ID, $key, FALSE );
217 echo '<li id="'.$page->ID.'" class="gllr_image_block">';
218 $image_attributes = wp_get_attachment_image_src( $page->ID, 'thumbnail' );
219 echo '<img src="'.$image_attributes[0].'" alt="'.$page->post_title.'" title="'.$page->post_title.'" height="'.get_option( 'thumbnail_size_h' ).'" width="'.get_option( 'thumbnail_size_w' ).'" />';
220 echo '<input type="text" name="gllr_image_text['.$page->ID.']" value="'.get_post_meta( $page->ID, $key, TRUE ).'" class="gllr_image_text" />';
221 echo '<div class="delete"><a href="javascript:void(0);" onclick="img_delete('.$page->ID.');">Delete</a><div/>';
222 echo '</li>';
223 endforeach; ?>
224 </ul><div style="clear:both;"></div>
225 <div id="delete_images"></div>
226 <?php }
227 }
228
229 // Use nonce for verification ...
230 if( ! function_exists ( 'echo_gllr_nonce' ) ) {
231 function echo_gllr_nonce () {
232 echo sprintf(
233 '<input type="hidden" name="%1$s" id="%1$s" value="%2$s" />',
234 'gllr_nonce_name',
235 wp_create_nonce( plugin_basename(__FILE__) )
236 );
237 }
238 }
239
240 if ( ! function_exists ( 'gllr_save_postdata' ) ) {
241 function gllr_save_postdata( $post_id, $post ) {
242 global $post, $wpdb;
243 $key = "gllr_image_text";
244
245 if( isset( $_REQUEST['undefined'] ) && ! empty( $_REQUEST['undefined'] ) ) {
246 $array_file_name = $_REQUEST['undefined'];
247 $uploadFile = array();
248 $newthumb = array();
249
250 $uploadDir = wp_upload_dir( );
251
252 while( list( $key, $val ) = each( $array_file_name ) ) {
253 $imagename = $val;
254 $uploadFile[] = $uploadDir["path"] ."/" . $imagename;
255 }
256 reset( $array_file_name );
257 require_once( ABSPATH . 'wp-admin/includes/image.php' );
258 $i = 0;
259 while( list( $key, $val ) = each( $array_file_name ) ) {
260 $file_name = $val;
261 if ( copy ( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name, $uploadFile[$i] ) ) {
262 unlink( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name );
263 $overrides = array('test_form' => false );
264
265 $file = str_replace( "\\", "/",$uploadDir["path"] ) ."/" .$file_name;
266 $filename = basename( $file );
267
268 $wp_filetype = wp_check_filetype( $filename, null );
269 $attachment = array(
270 'post_mime_type' => $wp_filetype['type'],
271 'post_title' => $filename,
272 'post_content' => '',
273 'post_status' => 'inherit'
274 );
275 $attach_id = wp_insert_attachment( $attachment, $file );
276 $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
277 wp_update_attachment_metadata( $attach_id, $attach_data );
278 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE ID = %d", $post->ID, $attach_id ) );
279 }
280 $i++;
281 }
282 }
283 if( isset( $_REQUEST['delete_images'] ) ) {
284 foreach( $_REQUEST['delete_images'] as $delete_id ) {
285 delete_post_meta( $delete_id, $key );
286 wp_delete_attachment( $delete_id );
287 }
288 }
289 if( isset( $_REQUEST['gllr_image_text'] ) ) {
290 $posts = get_posts(array(
291 "showposts" => -1,
292 "what_to_show" => "posts",
293 "post_status" => "inherit",
294 "post_type" => "attachment",
295 "orderby" => "menu_order",
296 "order" => "ASC",
297 "post_mime_type"=> "image/jpeg,image/gif,image/jpg,image/png",
298 "post_parent" => $post->ID));
299 foreach ( $posts as $page ) {
300 if( isset( $_REQUEST['gllr_image_text'][$page->ID] ) ) {
301 $value = $_REQUEST['gllr_image_text'][$page->ID];
302 if( get_post_meta( $page->ID, $key, FALSE ) && $value ) {
303 // Custom field has a value and this custom field exists in database
304 update_post_meta( $page->ID, $key, $value );
305 }
306 elseif($value) {
307 // Custom field has a value, but this custom field does not exist in database
308 add_post_meta( $page->ID, $key, $value );
309 }
310 }
311 }
312 }
313 }
314 }
315
316 if ( ! function_exists ( 'gllr_plugin_init' ) ) {
317 function gllr_plugin_init() {
318 // Internationalization, first(!)
319 load_plugin_textdomain( 'gallery', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
320 }
321 }
322
323 if( ! function_exists( 'gllr_custom_permalinks' ) ) {
324 function gllr_custom_permalinks() {
325 global $wp_rewrite;
326 global $wpdb;
327 $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");
328 if( ! empty( $parent ) ) {
329 $wp_rewrite->add_rule( '(.+)/'.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[2]&posts_per_page=-1', 'top' );
330 $wp_rewrite->add_rule( ''.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[1]&posts_per_page=-1', 'top' );
331 $wp_rewrite->add_rule( ''.$parent.'/page/([^/]+)/?$', 'index.php?pagename='.$parent.'&paged=$matches[1]', 'top' );
332 $wp_rewrite->add_rule( ''.$parent.'/page/([^/]+)?$', 'index.php?pagename='.$parent.'&paged=$matches[1]', 'top' );
333 }
334 else {
335 $wp_rewrite->add_rule( '(.+)/gallery/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[2]&posts_per_page=-1', 'top' );
336 $wp_rewrite->add_rule( 'gallery/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[1]&posts_per_page=-1', 'top' );
337 $wp_rewrite->add_rule( 'gallery/page/([^/]+)/?$', 'index.php?pagename=gallery&paged=$matches[1]', 'top' );
338 $wp_rewrite->add_rule( 'gallery/page/([^/]+)?$', 'index.php?pagename=gallery&paged=$matches[1]', 'top' );
339 }
340
341
342 $wp_rewrite->flush_rules();
343 }
344 }
345
346 if ( ! function_exists( 'gllr_template_redirect' ) ) {
347 function gllr_template_redirect() {
348 global $wp_query, $post, $posts;
349 if( 'gallery' == get_post_type() && "" == $wp_query->query_vars["s"] ) {
350 include( TEMPLATEPATH . '/gallery-single-template.php' );
351 exit();
352 }
353 }
354 }
355
356
357 // Change the columns for the edit CPT screen
358 if ( ! function_exists( 'gllr_change_columns' ) ) {
359 function gllr_change_columns( $cols ) {
360 $cols = array(
361 'cb' => '<input type="checkbox" />',
362 'title' => __( 'Title', 'gallery' ),
363 'autor' => __( 'Author', 'gallery' ),
364 'gallery' => __( 'Photo\'s', 'gallery' ),
365 'status' => __( 'Public', 'gallery' ),
366 'dates' => __( 'Date', 'gallery' )
367 );
368 return $cols;
369 }
370 }
371
372 if ( ! function_exists( 'gllr_custom_columns' ) ) {
373 function gllr_custom_columns( $column, $post_id ) {
374 global $wpdb;
375 $post = get_post( $post_id );
376 $row = $wpdb->get_results( "SELECT *
377 FROM $wpdb->posts
378 WHERE $wpdb->posts.post_parent = $post_id
379 AND $wpdb->posts.post_type = 'attachment'
380 AND (
381 $wpdb->posts.post_status = 'inherit'
382 )
383 ORDER BY $wpdb->posts.post_title ASC" );
384 switch ( $column ) {
385 //case "category":
386 case "autor":
387 $author_id=$post->post_author;
388 echo '<a href="edit.php?post_type=post&amp;author='.$author_id.'">'.get_the_author_meta( 'user_nicename' , $author_id ).'</a>';
389 break;
390 case "gallery":
391 echo count($row);
392 break;
393 case "status":
394 if( $post->post_status == 'publish' )
395 echo '<a href="javascript:void(0)">Yes</a>';
396 else
397 echo '<a href="javascript:void(0)">No</a>';
398 break;
399 case "dates":
400 echo strtolower( __( date( "F", strtotime( $post->post_date ) ), 'kerksite' ) )." ".date( "j Y", strtotime( $post->post_date ) );
401 break;
402 }
403 }
404 }
405
406 if ( ! function_exists( 'get_ID_by_slug' ) ) {
407 function get_ID_by_slug($page_slug) {
408 $page = get_page_by_path($page_slug);
409 if ($page) {
410 return $page->ID;
411 }
412 else {
413 return null;
414 }
415 }
416 }
417
418 if( ! function_exists( 'the_excerpt_max_charlength' ) ) {
419 function the_excerpt_max_charlength( $charlength ) {
420 $excerpt = get_the_excerpt();
421 $charlength ++;
422 if( strlen( $excerpt ) > $charlength ) {
423 $subex = substr( $excerpt, 0, $charlength-5 );
424 $exwords = explode( " ", $subex );
425 $excut = - ( strlen ( $exwords [ count( $exwords ) - 1 ] ) );
426 if( $excut < 0 ) {
427 echo substr( $subex, 0, $excut );
428 }
429 else {
430 echo $subex;
431 }
432 echo "...";
433 }
434 else {
435 echo $excerpt;
436 }
437 }
438 }
439
440 if( ! function_exists( 'gllr_page_css_class' ) ) {
441 function gllr_page_css_class( $classes, $item ) {
442 global $wpdb;
443 $post_type = get_query_var( 'post_type' );
444 $parent_id = 0;
445 if( $post_type == "gallery" ) {
446 $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" );
447 while ( $parent_id ) {
448 $page = get_page( $parent_id );
449 if( $page->post_parent > 0 )
450 $parent_id = $page->post_parent;
451 else
452 break;
453 }
454 wp_reset_query();
455 }
456 if ( $item->ID == $parent_id ) {
457 array_push( $classes, 'current_page_item' );
458 }
459 return $classes;
460 }
461 }
462
463 if( ! function_exists( 'bws_add_menu_render' ) ) {
464 function bws_add_menu_render() {
465 global $title;
466 $active_plugins = get_option('active_plugins');
467 $all_plugins = get_plugins();
468
469 $array_activate = array();
470 $array_install = array();
471 $array_recomend = array();
472 $count_activate = $count_install = $count_recomend = 0;
473 $array_plugins = array(
474 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' ),
475 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' ),
476 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' ),
477 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' ),
478 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', '' ),
479 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', '' ),
480 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' ),
481 array( 'custom-search-plugin\/custom-search-plugin.php', 'Custom Search Plugin', 'http://wordpress.org/extend/plugins/custom-search-plugin/', 'http://bestwebsoft.com/plugin/custom-search-plugin/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Custom+Search+plugin+bestwebsoft&plugin-search-input=Search+Plugins', 'admin.php?page=custom_search.php' ),
482 array( 'quotes-and-tips\/quotes-and-tips.php', 'Quotes and Tips', 'http://wordpress.org/extend/plugins/quotes-and-tips/', 'http://bestwebsoft.com/plugin/quotes-and-tips/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Quotes+and+Tips+bestwebsoft&plugin-search-input=Search+Plugins', 'admin.php?page=quotes-and-tips.php' ),
483 array( 'google-sitemap-plugin\/google-sitemap-plugin.php', 'Google sitemap plugin', 'http://wordpress.org/extend/plugins/google-sitemap-plugin/', 'http://bestwebsoft.com/plugin/google-sitemap-plugin/', '/wp-admin/plugin-install.php?tab=search&type=term&s=Google+sitemap+plugin+bestwebsoft&plugin-search-input=Search+Plugins', 'admin.php?page=google-sitemap-plugin.php' )
484 );
485 foreach($array_plugins as $plugins) {
486 if( 0 < count( preg_grep( "/".$plugins[0]."/", $active_plugins ) ) ) {
487 $array_activate[$count_activate]['title'] = $plugins[1];
488 $array_activate[$count_activate]['link'] = $plugins[2];
489 $array_activate[$count_activate]['href'] = $plugins[3];
490 $array_activate[$count_activate]['url'] = $plugins[5];
491 $count_activate++;
492 }
493 else if( array_key_exists(str_replace("\\", "", $plugins[0]), $all_plugins) ) {
494 $array_install[$count_install]['title'] = $plugins[1];
495 $array_install[$count_install]['link'] = $plugins[2];
496 $array_install[$count_install]['href'] = $plugins[3];
497 $count_install++;
498 }
499 else {
500 $array_recomend[$count_recomend]['title'] = $plugins[1];
501 $array_recomend[$count_recomend]['link'] = $plugins[2];
502 $array_recomend[$count_recomend]['href'] = $plugins[3];
503 $array_recomend[$count_recomend]['slug'] = $plugins[4];
504 $count_recomend++;
505 }
506 }
507 ?>
508 <div class="wrap">
509 <div class="icon32 icon32-bws" id="icon-options-general"></div>
510 <h2><?php echo $title;?></h2>
511 <?php if( 0 < $count_activate ) { ?>
512 <div>
513 <h3><?php _e( 'Activated plugins', 'gallery' ); ?></h3>
514 <?php foreach( $array_activate as $activate_plugin ) { ?>
515 <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>
516 <?php } ?>
517 </div>
518 <?php } ?>
519 <?php if( 0 < $count_install ) { ?>
520 <div>
521 <h3><?php _e( 'Installed plugins', 'gallery' ); ?></h3>
522 <?php foreach($array_install as $install_plugin) { ?>
523 <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>
524 <?php } ?>
525 </div>
526 <?php } ?>
527 <?php if( 0 < $count_recomend ) { ?>
528 <div>
529 <h3><?php _e( 'Recommended plugins', 'gallery' ); ?></h3>
530 <?php foreach( $array_recomend as $recomend_plugin ) { ?>
531 <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>
532 <?php } ?>
533 <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>
534 </div>
535 <?php } ?>
536 </div>
537 <?php
538 }
539 }
540
541 if( ! function_exists( 'add_gllr_admin_menu' ) ) {
542 function add_gllr_admin_menu() {
543 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url("images/px.png", __FILE__), 1001);
544 add_submenu_page('bws_plugins', __( 'Gallery', 'gallery' ), __( 'Gallery', 'gallery' ), 'manage_options', "gallery-plugin.php", 'gllr_settings_page');
545
546 //call register settings function
547 add_action( 'admin_init', 'register_gllr_settings' );
548 }
549 }
550
551 // register settings function
552 if( ! function_exists( 'register_gllr_settings' ) ) {
553 function register_gllr_settings() {
554 global $wpmu;
555 global $gllr_options;
556
557 $gllr_option_defaults = array(
558 'gllr_custom_size_name' => array( 'album-thumb', 'photo-thumb' ),
559 'gllr_custom_size_px' => array( array(120, 80), array(160, 120) ),
560 'custom_image_row_count' => 3
561 );
562
563 // install the option defaults
564 if ( 1 == $wpmu ) {
565 if( ! get_site_option( 'gllr_options' ) ) {
566 add_site_option( 'gllr_options', $gllr_option_defaults, '', 'yes' );
567 }
568 }
569 else {
570 if( ! get_option( 'gllr_options' ) )
571 add_option( 'gllr_options', $gllr_option_defaults, '', 'yes' );
572 }
573
574 // get options from the database
575 if ( 1 == $wpmu )
576 $gllr_options = get_site_option( 'gllr_options' ); // get options from the database
577 else
578 $gllr_options = get_option( 'gllr_options' );// get options from the database
579
580 // array merge incase this version has added new options
581 $gllr_options = array_merge( $gllr_option_defaults, $gllr_options );
582 if ( function_exists( 'add_image_size' ) ) {
583 add_image_size( 'album-thumb', $gllr_options['gllr_custom_size_px'][0][0], $gllr_options['gllr_custom_size_px'][0][1], true );
584 add_image_size( 'photo-thumb', $gllr_options['gllr_custom_size_px'][1][0], $gllr_options['gllr_custom_size_px'][1][1], true );
585 }
586 }
587 }
588
589 if( ! function_exists( 'gllr_settings_page' ) ) {
590 function gllr_settings_page() {
591 global $gllr_options;
592 $error = "";
593
594 // Save data for settings page
595 if( isset( $_REQUEST['gllr_form_submit'] ) ) {
596 $gllr_request_options = array();
597 $gllr_request_options["gllr_custom_size_name"] = $gllr_options["gllr_custom_size_name"];
598
599 $gllr_request_options["gllr_custom_size_px"] = array(
600 array( intval( trim( $_REQUEST['custom_image_size_w_album'] ) ), intval( trim($_REQUEST['custom_image_size_h_album'] ) ) ),
601 array( intval( trim( $_REQUEST['custom_image_size_w_photo'] ) ), intval( trim($_REQUEST['custom_image_size_h_photo'] ) ) )
602 );
603 $gllr_request_options["custom_image_row_count"] = intval( trim( $_REQUEST['custom_image_row_count'] ) );
604 if( $gllr_request_options["custom_image_row_count"] == "" || $gllr_request_options["custom_image_row_count"] < 1 )
605 $gllr_request_options["custom_image_row_count"] = 1;
606
607 // array merge incase this version has added new options
608 $gllr_options = array_merge( $gllr_options, $gllr_request_options );
609
610 // Check select one point in the blocks Arithmetic actions and Difficulty on settings page
611 update_option( 'gllr_options', $gllr_options, '', 'yes' );
612 $message = __( "Options saved.", 'gallery' );
613 }
614
615 if ( ! file_exists( get_stylesheet_directory() .'/gallery-template.php' ) || ! file_exists( get_stylesheet_directory() .'/gallery-single-template.php' ) ) {
616 $error .= __( 'The following files "gallery-template.php" and "gallery-single-template.php" were not found in the directory of your theme. Please copy them from the directory `/wp-content/plugins/gallery-plugin/template/` to the directory of your theme for the correct work of the Gallery plugin', 'gallery' );
617 }
618
619 // Display form on the setting page
620 ?>
621 <div class="wrap">
622 <div class="icon32 icon32-bws" id="icon-options-general"></div>
623 <h2><?php _e('Gallery Options', 'gallery' ); ?></h2>
624 <div class="updated fade" <?php if( ! isset( $_REQUEST['gllr_form_submit'] ) || $error != "" ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>
625 <div class="error" <?php if( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div>
626 <form method="post" action="admin.php?page=gallery-plugin.php" id="gllr_form_image_size">
627 <table class="form-table">
628 <tr valign="top">
629 <th scope="row"><?php _e('The size of the cover album for gallery', 'gallery' ); ?> </th>
630 <td>
631 <label for="custom_image_size_name"><?php _e( 'Image size name', 'gallery' ); ?></label> <?php echo $gllr_options["gllr_custom_size_name"][0]; ?><br />
632 <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 />
633 <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]; ?>" />
634 </td>
635 </tr>
636 <tr valign="top">
637 <th scope="row"><?php _e('Size for gallery image', 'gallery' ); ?> </th>
638 <td>
639 <label for="custom_image_size_name"><?php _e( 'Image size name', 'gallery' ); ?></label> <?php echo $gllr_options["gllr_custom_size_name"][1]; ?><br />
640 <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 />
641 <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]; ?>" />
642 </td>
643 </tr>
644 <tr valign="top">
645 <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>
646 </tr>
647 <tr valign="top">
648 <th scope="row"><?php _e('Count images in row', 'gallery' ); ?> </th>
649 <td>
650 <input type="text" name="custom_image_row_count" value="<?php echo $gllr_options["custom_image_row_count"]; ?>" />
651 </td>
652 </tr>
653 </table>
654 <input type="hidden" name="gllr_form_submit" value="submit" />
655 <p class="submit">
656 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
657 </p>
658 </form>
659 </div>
660 <?php }
661 }
662
663 if( ! function_exists( 'gllr_register_plugin_links' ) ) {
664 function gllr_register_plugin_links($links, $file) {
665 $base = plugin_basename(__FILE__);
666 if ($file == $base) {
667 $links[] = '<a href="admin.php?page=gallery-plugin.php">' . __( 'Settings', 'gallery' ) . '</a>';
668 $links[] = '<a href="http://wordpress.org/extend/plugins/gallery-plugin/faq/" target="_blank">' . __( 'FAQ', 'gallery' ) . '</a>';
669 $links[] = '<a href="Mailto:plugin@bestwebsoft.com">' . __( 'Support', 'gallery' ) . '</a>';
670 }
671 return $links;
672 }
673 }
674
675 if( ! function_exists( 'gllr_plugin_action_links' ) ) {
676 function gllr_plugin_action_links( $links, $file ) {
677 //Static so we don't call plugin_basename on every plugin row.
678 static $this_plugin;
679 if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
680
681 if ( $file == $this_plugin ){
682 $settings_link = '<a href="admin.php?page=gallery-plugin.php">' . __( 'Settings', 'gallery' ) . '</a>';
683 array_unshift( $links, $settings_link );
684 }
685 return $links;
686 } // end function gllr_plugin_action_links
687 }
688
689 if( ! function_exists( 'gllr_add_script' ) ){
690 function gllr_add_script() { ?>
691 <script type="text/javascript">
692 if ( ! window.jQuery ) {
693 document.write('<s'+'cript src="http://code.jquery.com/jquery-latest.js"></s'+'cript>');
694 }
695 </script>
696 <?php }
697 }
698
699 if ( ! function_exists ( 'gllr_admin_head' ) ) {
700 function gllr_admin_head() {
701 wp_enqueue_style( 'gllrStylesheet', plugins_url( 'css/stylesheet.css', __FILE__ ) );
702 wp_enqueue_style( 'gllrFileuploaderCss', plugins_url( 'upload/fileuploader.css', __FILE__ ) );
703 wp_enqueue_script( 'gllrFileuploaderJs', plugins_url( 'upload/fileuploader.js', __FILE__ ), array( 'jquery' ) );
704 }
705 }
706
707 if ( ! function_exists ( 'gllr_wp_head' ) ) {
708 function gllr_wp_head() {
709 wp_enqueue_style( 'gllrStylesheet', plugins_url( 'css/stylesheet.css', __FILE__ ) );
710 wp_enqueue_style( 'gllrFancyboxStylesheet', plugins_url( 'fancybox/jquery.fancybox-1.3.4.css', __FILE__ ) );
711 wp_enqueue_script( 'gllrFancyboxMousewheelJs', plugins_url( 'fancybox/jquery.mousewheel-3.0.4.pack.js', __FILE__ ), array( 'jquery' ) );
712 wp_enqueue_script( 'gllrFancyboxJs', plugins_url( 'fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__ ), array( 'jquery' ) );
713 }
714 }
715
716 register_activation_hook( __FILE__, 'gllr_plugin_install' ); // activate plugin
717 register_uninstall_hook( __FILE__, 'gllr_plugin_uninstall' ); // deactivate plugin
718
719 // adds "Settings" link to the plugin action page
720 add_filter( 'plugin_action_links', 'gllr_plugin_action_links', 10, 2 );
721 //Additional links on the plugin page
722 add_filter( 'plugin_row_meta', 'gllr_register_plugin_links', 10, 2 );
723
724 add_action( 'admin_menu', 'add_gllr_admin_menu' );
725 add_action( 'init', 'gllr_plugin_init' );
726
727 add_action( 'init', 'post_type_images' ); // register post type
728 add_action( 'init', 'gllr_custom_permalinks' ); // add custom permalink for gallery
729
730 add_action( 'admin_init', 'gllr_admin_error' );
731
732 add_action( 'template_redirect', 'gllr_template_redirect' ); // add themplate for single gallery page
733
734 add_action( 'save_post', 'gllr_save_postdata', 1, 2 ); // save custom data from admin
735
736 add_filter( 'nav_menu_css_class', 'addImageAncestorToMenu' );
737 add_filter( 'page_css_class', 'gllr_page_css_class', 10, 2 );
738
739 add_filter( 'manage_gallery_posts_columns', 'gllr_change_columns' );
740 add_action( 'manage_gallery_posts_custom_column', 'gllr_custom_columns', 10, 2 );
741
742 add_action( 'wp_head', 'gllr_add_script' );
743 add_action( 'admin_enqueue_scripts', 'gllr_admin_head' );
744 add_action( 'wp_enqueue_scripts', 'gllr_wp_head' );
745 ?>