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

744 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.03
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 $time = current_time('mysql');
250
251 $uploadDir = wp_upload_dir( $time );
252
253 while( list( $key, $val ) = each( $array_file_name ) ) {
254 $imagename = $val;
255 $uploadFile[] = $uploadDir["path"] ."/" . $imagename;
256 }
257 reset( $array_file_name );
258 require_once( ABSPATH . 'wp-admin/includes/image.php' );
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[$key] ) ) {
262 unlink( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name );
263 $overrides = array('test_form' => false );
264
265 $file = $uploadFile[$key];
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 }
281 }
282 if( isset( $_REQUEST['delete_images'] ) ) {
283 foreach( $_REQUEST['delete_images'] as $delete_id ) {
284 delete_post_meta( $delete_id, $key );
285 wp_delete_attachment( $delete_id );
286 }
287 }
288 if( isset( $_REQUEST['gllr_image_text'] ) ) {
289 $posts = get_posts(array(
290 "showposts" => -1,
291 "what_to_show" => "posts",
292 "post_status" => "inherit",
293 "post_type" => "attachment",
294 "orderby" => "menu_order",
295 "order" => "ASC",
296 "post_mime_type"=> "image/jpeg,image/gif,image/jpg,image/png",
297 "post_parent" => $post->ID));
298 foreach ( $posts as $page ) {
299 if( isset( $_REQUEST['gllr_image_text'][$page->ID] ) ) {
300 $value = $_REQUEST['gllr_image_text'][$page->ID];
301 if( get_post_meta( $page->ID, $key, FALSE ) && $value ) {
302 // Custom field has a value and this custom field exists in database
303 update_post_meta( $page->ID, $key, $value );
304 }
305 elseif($value) {
306 // Custom field has a value, but this custom field does not exist in database
307 add_post_meta( $page->ID, $key, $value );
308 }
309 }
310 }
311 }
312 }
313 }
314
315 if ( ! function_exists ( 'gllr_plugin_init' ) ) {
316 function gllr_plugin_init() {
317 // Internationalization, first(!)
318 load_plugin_textdomain( 'gallery', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
319 }
320 }
321
322 if( ! function_exists( 'gllr_custom_permalinks' ) ) {
323 function gllr_custom_permalinks() {
324 global $wp_rewrite;
325 global $wpdb;
326 $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");
327 if( ! empty( $parent ) ) {
328 $wp_rewrite->add_rule( '(.+)/'.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[2]&posts_per_page=-1', 'top' );
329 $wp_rewrite->add_rule( ''.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[1]&posts_per_page=-1', 'top' );
330 $wp_rewrite->add_rule( ''.$parent.'/page/([^/]+)/?$', 'index.php?pagename='.$parent.'&paged=$matches[1]', 'top' );
331 $wp_rewrite->add_rule( ''.$parent.'/page/([^/]+)?$', 'index.php?pagename='.$parent.'&paged=$matches[1]', 'top' );
332 }
333 else {
334 $wp_rewrite->add_rule( '(.+)/gallery/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[2]&posts_per_page=-1', 'top' );
335 $wp_rewrite->add_rule( 'gallery/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[1]&posts_per_page=-1', 'top' );
336 $wp_rewrite->add_rule( 'gallery/page/([^/]+)/?$', 'index.php?pagename=gallery&paged=$matches[1]', 'top' );
337 $wp_rewrite->add_rule( 'gallery/page/([^/]+)?$', 'index.php?pagename=gallery&paged=$matches[1]', 'top' );
338 }
339
340
341 $wp_rewrite->flush_rules();
342 }
343 }
344
345 if ( ! function_exists( 'gllr_template_redirect' ) ) {
346 function gllr_template_redirect() {
347 global $wp_query, $post, $posts;
348 if( 'gallery' == get_post_type() && "" == $wp_query->query_vars["s"] ) {
349 include( TEMPLATEPATH . '/gallery-single-template.php' );
350 exit();
351 }
352 }
353 }
354
355
356 // Change the columns for the edit CPT screen
357 if ( ! function_exists( 'gllr_change_columns' ) ) {
358 function gllr_change_columns( $cols ) {
359 $cols = array(
360 'cb' => '<input type="checkbox" />',
361 'title' => __( 'Title', 'gallery' ),
362 'autor' => __( 'Author', 'gallery' ),
363 'gallery' => __( 'Photo\'s', 'gallery' ),
364 'status' => __( 'Public', 'gallery' ),
365 'dates' => __( 'Date', 'gallery' )
366 );
367 return $cols;
368 }
369 }
370
371 if ( ! function_exists( 'gllr_custom_columns' ) ) {
372 function gllr_custom_columns( $column, $post_id ) {
373 global $wpdb;
374 $post = get_post( $post_id );
375 $row = $wpdb->get_results( "SELECT *
376 FROM $wpdb->posts
377 WHERE $wpdb->posts.post_parent = $post_id
378 AND $wpdb->posts.post_type = 'attachment'
379 AND (
380 $wpdb->posts.post_status = 'inherit'
381 )
382 ORDER BY $wpdb->posts.post_title ASC" );
383 switch ( $column ) {
384 //case "category":
385 case "autor":
386 $author_id=$post->post_author;
387 echo '<a href="edit.php?post_type=post&amp;author='.$author_id.'">'.get_the_author_meta( 'user_nicename' , $author_id ).'</a>';
388 break;
389 case "gallery":
390 echo count($row);
391 break;
392 case "status":
393 if( $post->post_status == 'publish' )
394 echo '<a href="javascript:void(0)">Yes</a>';
395 else
396 echo '<a href="javascript:void(0)">No</a>';
397 break;
398 case "dates":
399 echo strtolower( __( date( "F", strtotime( $post->post_date ) ), 'kerksite' ) )." ".date( "j Y", strtotime( $post->post_date ) );
400 break;
401 }
402 }
403 }
404
405 if ( ! function_exists( 'get_ID_by_slug' ) ) {
406 function get_ID_by_slug($page_slug) {
407 $page = get_page_by_path($page_slug);
408 if ($page) {
409 return $page->ID;
410 }
411 else {
412 return null;
413 }
414 }
415 }
416
417 if( ! function_exists( 'the_excerpt_max_charlength' ) ) {
418 function the_excerpt_max_charlength( $charlength ) {
419 $excerpt = get_the_excerpt();
420 $charlength ++;
421 if( strlen( $excerpt ) > $charlength ) {
422 $subex = substr( $excerpt, 0, $charlength-5 );
423 $exwords = explode( " ", $subex );
424 $excut = - ( strlen ( $exwords [ count( $exwords ) - 1 ] ) );
425 if( $excut < 0 ) {
426 echo substr( $subex, 0, $excut );
427 }
428 else {
429 echo $subex;
430 }
431 echo "...";
432 }
433 else {
434 echo $excerpt;
435 }
436 }
437 }
438
439 if( ! function_exists( 'gllr_page_css_class' ) ) {
440 function gllr_page_css_class( $classes, $item ) {
441 global $wpdb;
442 $post_type = get_query_var( 'post_type' );
443 $parent_id = 0;
444 if( $post_type == "gallery" ) {
445 $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" );
446 while ( $parent_id ) {
447 $page = get_page( $parent_id );
448 if( $page->post_parent > 0 )
449 $parent_id = $page->post_parent;
450 else
451 break;
452 }
453 wp_reset_query();
454 }
455 if ( $item->ID == $parent_id ) {
456 array_push( $classes, 'current_page_item' );
457 }
458 return $classes;
459 }
460 }
461
462 if( ! function_exists( 'bws_add_menu_render' ) ) {
463 function bws_add_menu_render() {
464 global $title;
465 $active_plugins = get_option('active_plugins');
466 $all_plugins = get_plugins();
467
468 $array_activate = array();
469 $array_install = array();
470 $array_recomend = array();
471 $count_activate = $count_install = $count_recomend = 0;
472 $array_plugins = array(
473 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' ),
474 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' ),
475 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' ),
476 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' ),
477 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', '' ),
478 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', '' ),
479 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' ),
480 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' ),
481 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' ),
482 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' )
483 );
484 foreach($array_plugins as $plugins) {
485 if( 0 < count( preg_grep( "/".$plugins[0]."/", $active_plugins ) ) ) {
486 $array_activate[$count_activate]['title'] = $plugins[1];
487 $array_activate[$count_activate]['link'] = $plugins[2];
488 $array_activate[$count_activate]['href'] = $plugins[3];
489 $array_activate[$count_activate]['url'] = $plugins[5];
490 $count_activate++;
491 }
492 else if( array_key_exists(str_replace("\\", "", $plugins[0]), $all_plugins) ) {
493 $array_install[$count_install]['title'] = $plugins[1];
494 $array_install[$count_install]['link'] = $plugins[2];
495 $array_install[$count_install]['href'] = $plugins[3];
496 $count_install++;
497 }
498 else {
499 $array_recomend[$count_recomend]['title'] = $plugins[1];
500 $array_recomend[$count_recomend]['link'] = $plugins[2];
501 $array_recomend[$count_recomend]['href'] = $plugins[3];
502 $array_recomend[$count_recomend]['slug'] = $plugins[4];
503 $count_recomend++;
504 }
505 }
506 ?>
507 <div class="wrap">
508 <div class="icon32 icon32-bws" id="icon-options-general"></div>
509 <h2><?php echo $title;?></h2>
510 <?php if( 0 < $count_activate ) { ?>
511 <div>
512 <h3><?php _e( 'Activated plugins', 'gallery' ); ?></h3>
513 <?php foreach( $array_activate as $activate_plugin ) { ?>
514 <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>
515 <?php } ?>
516 </div>
517 <?php } ?>
518 <?php if( 0 < $count_install ) { ?>
519 <div>
520 <h3><?php _e( 'Installed plugins', 'gallery' ); ?></h3>
521 <?php foreach($array_install as $install_plugin) { ?>
522 <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>
523 <?php } ?>
524 </div>
525 <?php } ?>
526 <?php if( 0 < $count_recomend ) { ?>
527 <div>
528 <h3><?php _e( 'Recommended plugins', 'gallery' ); ?></h3>
529 <?php foreach( $array_recomend as $recomend_plugin ) { ?>
530 <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>
531 <?php } ?>
532 <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>
533 </div>
534 <?php } ?>
535 </div>
536 <?php
537 }
538 }
539
540 if( ! function_exists( 'add_gllr_admin_menu' ) ) {
541 function add_gllr_admin_menu() {
542 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url("images/px.png", __FILE__), 1001);
543 add_submenu_page('bws_plugins', __( 'Gallery', 'gallery' ), __( 'Gallery', 'gallery' ), 'manage_options', "gallery-plugin.php", 'gllr_settings_page');
544
545 //call register settings function
546 add_action( 'admin_init', 'register_gllr_settings' );
547 }
548 }
549
550 // register settings function
551 if( ! function_exists( 'register_gllr_settings' ) ) {
552 function register_gllr_settings() {
553 global $wpmu;
554 global $gllr_options;
555
556 $gllr_option_defaults = array(
557 'gllr_custom_size_name' => array( 'album-thumb', 'photo-thumb' ),
558 'gllr_custom_size_px' => array( array(120, 80), array(160, 120) ),
559 'custom_image_row_count' => 3
560 );
561
562 // install the option defaults
563 if ( 1 == $wpmu ) {
564 if( ! get_site_option( 'gllr_options' ) ) {
565 add_site_option( 'gllr_options', $gllr_option_defaults, '', 'yes' );
566 }
567 }
568 else {
569 if( ! get_option( 'gllr_options' ) )
570 add_option( 'gllr_options', $gllr_option_defaults, '', 'yes' );
571 }
572
573 // get options from the database
574 if ( 1 == $wpmu )
575 $gllr_options = get_site_option( 'gllr_options' ); // get options from the database
576 else
577 $gllr_options = get_option( 'gllr_options' );// get options from the database
578
579 // array merge incase this version has added new options
580 $gllr_options = array_merge( $gllr_option_defaults, $gllr_options );
581 if ( function_exists( 'add_image_size' ) ) {
582 add_image_size( 'album-thumb', $gllr_options['gllr_custom_size_px'][0][0], $gllr_options['gllr_custom_size_px'][0][1], true );
583 add_image_size( 'photo-thumb', $gllr_options['gllr_custom_size_px'][1][0], $gllr_options['gllr_custom_size_px'][1][1], true );
584 }
585 }
586 }
587
588 if( ! function_exists( 'gllr_settings_page' ) ) {
589 function gllr_settings_page() {
590 global $gllr_options;
591 $error = "";
592
593 // Save data for settings page
594 if( isset( $_REQUEST['gllr_form_submit'] ) ) {
595 $gllr_request_options = array();
596 $gllr_request_options["gllr_custom_size_name"] = $gllr_options["gllr_custom_size_name"];
597
598 $gllr_request_options["gllr_custom_size_px"] = array(
599 array( intval( trim( $_REQUEST['custom_image_size_w_album'] ) ), intval( trim($_REQUEST['custom_image_size_h_album'] ) ) ),
600 array( intval( trim( $_REQUEST['custom_image_size_w_photo'] ) ), intval( trim($_REQUEST['custom_image_size_h_photo'] ) ) )
601 );
602 $gllr_request_options["custom_image_row_count"] = intval( trim( $_REQUEST['custom_image_row_count'] ) );
603 if( $gllr_request_options["custom_image_row_count"] == "" || $gllr_request_options["custom_image_row_count"] < 1 )
604 $gllr_request_options["custom_image_row_count"] = 1;
605
606 // array merge incase this version has added new options
607 $gllr_options = array_merge( $gllr_options, $gllr_request_options );
608
609 // Check select one point in the blocks Arithmetic actions and Difficulty on settings page
610 update_option( 'gllr_options', $gllr_options, '', 'yes' );
611 $message = __( "Options saved.", 'gallery' );
612 }
613
614 if ( ! file_exists( get_stylesheet_directory() .'/gallery-template.php' ) || ! file_exists( get_stylesheet_directory() .'/gallery-single-template.php' ) ) {
615 $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' );
616 }
617
618 // Display form on the setting page
619 ?>
620 <div class="wrap">
621 <div class="icon32 icon32-bws" id="icon-options-general"></div>
622 <h2><?php _e('Gallery Options', 'gallery' ); ?></h2>
623 <div class="updated fade" <?php if( ! isset( $_REQUEST['gllr_form_submit'] ) || $error != "" ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>
624 <div class="error" <?php if( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div>
625 <form method="post" action="admin.php?page=gallery-plugin.php" id="gllr_form_image_size">
626 <table class="form-table">
627 <tr valign="top">
628 <th scope="row"><?php _e('The size of the cover album for gallery', 'gallery' ); ?> </th>
629 <td>
630 <label for="custom_image_size_name"><?php _e( 'Image size name', 'gallery' ); ?></label> <?php echo $gllr_options["gllr_custom_size_name"][0]; ?><br />
631 <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 />
632 <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]; ?>" />
633 </td>
634 </tr>
635 <tr valign="top">
636 <th scope="row"><?php _e('Size for gallery image', '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"][1]; ?><br />
639 <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 />
640 <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]; ?>" />
641 </td>
642 </tr>
643 <tr valign="top">
644 <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>
645 </tr>
646 <tr valign="top">
647 <th scope="row"><?php _e('Count images in row', 'gallery' ); ?> </th>
648 <td>
649 <input type="text" name="custom_image_row_count" value="<?php echo $gllr_options["custom_image_row_count"]; ?>" />
650 </td>
651 </tr>
652 </table>
653 <input type="hidden" name="gllr_form_submit" value="submit" />
654 <p class="submit">
655 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
656 </p>
657 </form>
658 </div>
659 <?php }
660 }
661
662 if( ! function_exists( 'gllr_register_plugin_links' ) ) {
663 function gllr_register_plugin_links($links, $file) {
664 $base = plugin_basename(__FILE__);
665 if ($file == $base) {
666 $links[] = '<a href="admin.php?page=gallery-plugin.php">' . __( 'Settings', 'gallery' ) . '</a>';
667 $links[] = '<a href="http://wordpress.org/extend/plugins/gallery-plugin/faq/" target="_blank">' . __( 'FAQ', 'gallery' ) . '</a>';
668 $links[] = '<a href="Mailto:plugin@bestwebsoft.com">' . __( 'Support', 'gallery' ) . '</a>';
669 }
670 return $links;
671 }
672 }
673
674 if( ! function_exists( 'gllr_plugin_action_links' ) ) {
675 function gllr_plugin_action_links( $links, $file ) {
676 //Static so we don't call plugin_basename on every plugin row.
677 static $this_plugin;
678 if ( ! $this_plugin ) $this_plugin = plugin_basename(__FILE__);
679
680 if ( $file == $this_plugin ){
681 $settings_link = '<a href="admin.php?page=gallery-plugin.php">' . __( 'Settings', 'gallery' ) . '</a>';
682 array_unshift( $links, $settings_link );
683 }
684 return $links;
685 } // end function gllr_plugin_action_links
686 }
687
688 if( ! function_exists( 'gllr_add_script' ) ){
689 function gllr_add_script() { ?>
690 <script type="text/javascript">
691 if ( ! window.jQuery ) {
692 document.write('<s'+'cript src="http://code.jquery.com/jquery-latest.js"></s'+'cript>');
693 }
694 </script>
695 <?php }
696 }
697
698 if ( ! function_exists ( 'gllr_admin_head' ) ) {
699 function gllr_admin_head() {
700 wp_enqueue_style( 'gllrStylesheet', plugins_url( 'css/stylesheet.css', __FILE__ ) );
701 wp_enqueue_style( 'gllrFileuploaderCss', plugins_url( 'upload/fileuploader.css', __FILE__ ) );
702 wp_enqueue_script( 'gllrFileuploaderJs', plugins_url( 'upload/fileuploader.js', __FILE__ ), array( 'jquery' ) );
703 }
704 }
705
706 if ( ! function_exists ( 'gllr_wp_head' ) ) {
707 function gllr_wp_head() {
708 wp_enqueue_style( 'gllrStylesheet', plugins_url( 'css/stylesheet.css', __FILE__ ) );
709 wp_enqueue_style( 'gllrFancyboxStylesheet', plugins_url( 'fancybox/jquery.fancybox-1.3.4.css', __FILE__ ) );
710 wp_enqueue_script( 'gllrFancyboxMousewheelJs', plugins_url( 'fancybox/jquery.mousewheel-3.0.4.pack.js', __FILE__ ), array( 'jquery' ) );
711 wp_enqueue_script( 'gllrFancyboxJs', plugins_url( 'fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__ ), array( 'jquery' ) );
712 }
713 }
714
715 register_activation_hook( __FILE__, 'gllr_plugin_install' ); // activate plugin
716 register_uninstall_hook( __FILE__, 'gllr_plugin_uninstall' ); // deactivate plugin
717
718 // adds "Settings" link to the plugin action page
719 add_filter( 'plugin_action_links', 'gllr_plugin_action_links', 10, 2 );
720 //Additional links on the plugin page
721 add_filter( 'plugin_row_meta', 'gllr_register_plugin_links', 10, 2 );
722
723 add_action( 'admin_menu', 'add_gllr_admin_menu' );
724 add_action( 'init', 'gllr_plugin_init' );
725
726 add_action( 'init', 'post_type_images' ); // register post type
727 add_action( 'init', 'gllr_custom_permalinks' ); // add custom permalink for gallery
728
729 add_action( 'admin_init', 'gllr_admin_error' );
730
731 add_action( 'template_redirect', 'gllr_template_redirect' ); // add themplate for single gallery page
732
733 add_action( 'save_post', 'gllr_save_postdata', 1, 2 ); // save custom data from admin
734
735 add_filter( 'nav_menu_css_class', 'addImageAncestorToMenu' );
736 add_filter( 'page_css_class', 'gllr_page_css_class', 10, 2 );
737
738 add_filter( 'manage_gallery_posts_columns', 'gllr_change_columns' );
739 add_action( 'manage_gallery_posts_custom_column', 'gllr_custom_columns', 10, 2 );
740
741 add_action( 'wp_head', 'gllr_add_script' );
742 add_action( 'admin_enqueue_scripts', 'gllr_admin_head' );
743 add_action( 'wp_enqueue_scripts', 'gllr_wp_head' );
744 ?>