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

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