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

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