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

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