| 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: 1.01 |
| 8 |
Author URI: http://bestwebsoft.com/ |
| 9 |
License: GPLv2 or later |
| 10 |
*/ |
| 11 |
|
| 12 |
/* © Copyright 2011 BestWebSoft ( admin@bestwebsoft.com ) |
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify |
| 15 |
it under the terms of the GNU General Public License, version 2, as |
| 16 |
published by the Free Software Foundation. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License |
| 24 |
along with this program; if not, write to the Free Software |
| 25 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 |
*/ |
| 27 |
$gllr_boxes = array ( |
| 28 |
'Upload-File' => array ( |
| 29 |
array( '_gllr_uploadedFile', '', '', '', '' ), |
| 30 |
) |
| 31 |
); |
| 32 |
|
| 33 |
if( ! function_exists( 'gllr_plugin_install' ) ) { |
| 34 |
function gllr_plugin_install() { |
| 35 |
if ( ! copy(WP_PLUGIN_DIR .'/gallery-plugin/themplate/gallery-template.php', TEMPLATEPATH .'/gallery-template.php')) |
| 36 |
{ |
| 37 |
add_action( 'admin_notices', create_function( '', 'Error copy template file' ) ); |
| 38 |
} |
| 39 |
if ( ! copy(WP_PLUGIN_DIR .'/gallery-plugin/themplate/gallery-single-template.php', TEMPLATEPATH .'/gallery-single-template.php')) |
| 40 |
{ |
| 41 |
add_action( 'admin_notices', create_function( '', 'Error copy template file' ) ); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if( ! function_exists( 'gllr_plugin_uninstall' ) ) { |
| 47 |
function gllr_plugin_uninstall() { |
| 48 |
if ( ! unlink(TEMPLATEPATH .'/gallery-template.php')) |
| 49 |
{ |
| 50 |
add_action( 'admin_notices', create_function( '', 'Error delete template file' ) ); |
| 51 |
} |
| 52 |
if ( ! unlink(TEMPLATEPATH .'/gallery-single-template.php')) |
| 53 |
{ |
| 54 |
add_action( 'admin_notices', create_function( '', 'Error delete template file' ) ); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
if( ! function_exists( 'gllr_plugin_header' ) ) { |
| 60 |
function gllr_plugin_header() { |
| 61 |
global $post_type; |
| 62 |
?> |
| 63 |
<style> |
| 64 |
#adminmenu #menu-posts-gallery div.wp-menu-image |
| 65 |
{ |
| 66 |
background: url("<?php echo get_bloginfo('url');?>/wp-content/plugins/gallery-plugin/images/icon_16.png") no-repeat scroll center center transparent; |
| 67 |
} |
| 68 |
#adminmenu #menu-posts-gallery:hover div.wp-menu-image, #adminmenu #menu-posts-gallery.wp-has-current-submenu div.wp-menu-image |
| 69 |
{ |
| 70 |
background: url("<?php echo get_bloginfo('url');?>/wp-content/plugins/gallery-plugin/images/icon_16_c.png") no-repeat scroll center center transparent; |
| 71 |
} |
| 72 |
.wrap #icon-edit.icon32-posts-gallery |
| 73 |
{ |
| 74 |
background: url("<?php echo get_bloginfo('url');?>/wp-content/plugins/gallery-plugin/images/icon_36.png") no-repeat scroll left top transparent; |
| 75 |
} |
| 76 |
</style> |
| 77 |
<?php |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
// Create post type for Gallery |
| 82 |
if( ! function_exists( 'post_type_images' ) ) { |
| 83 |
function post_type_images() { |
| 84 |
register_post_type('gallery', array( |
| 85 |
'labels' => array( |
| 86 |
'name' => __( 'Galleries', 'gallery'), |
| 87 |
'singular_name' => __( 'Gallery', 'gallery'), |
| 88 |
'add_new' => __( 'Add New', 'gallery'), |
| 89 |
'add_new_item' => __( 'Add New Gallery', 'gallery'), |
| 90 |
'edit_item' => __( 'Edit Gallery', 'gallery'), |
| 91 |
'new_item' => __( 'New Gallery', 'gallery'), |
| 92 |
'view_item' => __( 'View Gallery', 'gallery'), |
| 93 |
'search_items' => __( 'Search Galleries', 'gallery'), |
| 94 |
'not_found' => __( 'No Galleries found', 'gallery'), |
| 95 |
'parent_item_colon' => '', |
| 96 |
'menu_name' => __( 'Galleries', 'gallery') |
| 97 |
), |
| 98 |
'public' => true, |
| 99 |
'publicly_queryable' => true, |
| 100 |
'query_var' => true, |
| 101 |
'rewrite' => true, |
| 102 |
'capability_type' => 'post', |
| 103 |
'has_archive' => false, |
| 104 |
'hierarchical' => true, |
| 105 |
'supports' => array('title', 'editor'), |
| 106 |
'register_meta_box_cb' => 'init_metaboxes_gallery' |
| 107 |
)); |
| 108 |
|
| 109 |
wp_enqueue_style( 'gllrStylesheet', WP_PLUGIN_URL .'/gallery-plugin/css/stylesheet.css' ); |
| 110 |
wp_enqueue_style( 'gllrPrettyPhotoStylesheet', WP_PLUGIN_URL .'/gallery-plugin/pretty_photo/css/prettyPhoto.css' ); |
| 111 |
//wp_enqueue_script( 'gllrPrettyPhotoJq', WP_PLUGIN_URL .'/gallery-plugin/pretty_photo/jquery-1.6.2.min.js', array( 'jquery' ) ); |
| 112 |
wp_enqueue_script( 'gllrPrettyPhotoJs', WP_PLUGIN_URL .'/gallery-plugin/pretty_photo/js/jquery.prettyPhoto.js', array( 'jquery' ) ); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
if( ! function_exists( 'addImageAncestorToMenu' ) ) { |
| 117 |
function addImageAncestorToMenu( $classes ) { |
| 118 |
if ( is_singular( 'gallery' ) ) { |
| 119 |
global $wpdb, $post; |
| 120 |
|
| 121 |
if ( empty( $post->ancestors ) ) { |
| 122 |
return $classes; |
| 123 |
} |
| 124 |
|
| 125 |
$menuQuery = "SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = '_menu_item_object_id' AND meta_value IN (" . implode(',', $post->ancestors) . ")"; |
| 126 |
$menuItems = $wpdb->get_col( $menuQuery ); |
| 127 |
|
| 128 |
if ( is_array( $menuItems ) ) { |
| 129 |
foreach ( $menuItems as $menuItem ) { |
| 130 |
if ( in_array( 'menu-item-' . $menuItem, $classes ) ) { |
| 131 |
$classes[] = 'current-page-ancestor'; |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
return $classes; |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
function init_metaboxes_gallery() { |
| 142 |
add_meta_box( 'Upload-File', __( 'Upload File', 'gallery' ), 'gllr_post_custom_box', 'gallery', 'normal', 'high' ); |
| 143 |
wp_enqueue_script( 'jquery_min', WP_PLUGIN_URL .'/gallery-plugin/upload/jquery.js', array( 'jquery' ) ); |
| 144 |
wp_enqueue_script( 'jquery_upload', WP_PLUGIN_URL .'/gallery-plugin/upload/fileuploader.js', array( 'jquery' ) ); |
| 145 |
wp_enqueue_style( 'jquery_css', WP_PLUGIN_URL .'/gallery-plugin/upload/fileuploader.css' ); |
| 146 |
} |
| 147 |
|
| 148 |
// Create custom meta box for portfolio post type |
| 149 |
if ( ! function_exists( 'gllr_post_custom_box' ) ) { |
| 150 |
function gllr_post_custom_box( $obj = '', $box = '' ) { |
| 151 |
global $post; |
| 152 |
|
| 153 |
$post_types = get_post_types( array( '_builtin' => false ) ); |
| 154 |
?> |
| 155 |
<div style="padding-top:10px;"><label for="uploadscreen"><?php echo __( 'Choose a screenshot to upload:', 'gallery' ); ?></label> |
| 156 |
<input name="MAX_FILE_SIZE" value="1048576" type="hidden" /> |
| 157 |
<div id="file-uploader-demo1" style="padding-top:10px;"> |
| 158 |
<noscript> |
| 159 |
<p><?php echo __( 'Please enable JavaScript to use the file uploader.', 'gallery' ); ?></p> |
| 160 |
</noscript> |
| 161 |
</div> |
| 162 |
<ul id="files" ></ul> |
| 163 |
<div id="hidden"></div> |
| 164 |
<div style="clear:both;"></div></div> |
| 165 |
<script type="text/javascript"> |
| 166 |
jQuery(document).ready(function() |
| 167 |
{ |
| 168 |
var uploader = new qq.FileUploader({ |
| 169 |
element: document.getElementById('file-uploader-demo1'), |
| 170 |
action: '<?php echo WP_PLUGIN_URL; ?>/gallery-plugin/upload/php.php', |
| 171 |
debug: false, |
| 172 |
onComplete: function(id, fileName, result) { |
| 173 |
if(result.error) { |
| 174 |
// |
| 175 |
} |
| 176 |
else { |
| 177 |
jQuery('<li></li>').appendTo('#files').html('<img src="<?php echo WP_PLUGIN_URL; ?>/gallery-plugin/upload/files/'+fileName+'" alt="" /><div style="width:200px">'+fileName+'<br />' +result.width+'x'+result.height+'</div>').addClass('success'); |
| 178 |
jQuery('<input type="hidden" name="undefined[]" id="undefined" value="'+fileName+'" />').appendTo('#hidden'); |
| 179 |
} |
| 180 |
} |
| 181 |
}); |
| 182 |
jQuery('#images_albumdiv').remove(); |
| 183 |
|
| 184 |
}); |
| 185 |
|
| 186 |
function img_delete(id) { |
| 187 |
jQuery('#'+id).hide(); |
| 188 |
jQuery('#delete_images').append('<input type="hidden" name="delete_images[]" value="'+id+'" />'); |
| 189 |
} |
| 190 |
</script> |
| 191 |
<?php |
| 192 |
|
| 193 |
$posts = get_posts(array( |
| 194 |
"showposts" => -1, |
| 195 |
"what_to_show" => "posts", |
| 196 |
"post_status" => "inherit", |
| 197 |
"post_type" => "attachment", |
| 198 |
"orderby" => "menu_order ASC, ID ASC", |
| 199 |
"post_mime_type"=> "image/jpeg,image/gif,image/jpg,image/png", |
| 200 |
"post_parent" => $post->ID)); |
| 201 |
echo '<ul class="gallery clearfix">'; |
| 202 |
foreach ( $posts as $page ): |
| 203 |
echo '<li id="'.$page->ID.'">'; |
| 204 |
$image_attributes = wp_get_attachment_image_src( $page->ID, 'thumbnail' ); |
| 205 |
echo '<img src="'.$image_attributes[0].'" alt="'.$page->post_title.'" title="'.$page->post_title.'"/>'; |
| 206 |
echo '<div class="delete"><a href="javascript:void(0);" onclick="img_delete('.$page->ID.');">Delete</a><div/>'; |
| 207 |
echo '</li>'; |
| 208 |
endforeach; |
| 209 |
echo '</ul><div style="clear:both;"></div>'; |
| 210 |
echo '<div id="delete_images"></div>'; |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
// Use nonce for verification ... |
| 215 |
if( ! function_exists ( 'echo_gllr_nonce' ) ) { |
| 216 |
function echo_gllr_nonce () { |
| 217 |
echo sprintf( |
| 218 |
'<input type="hidden" name="%1$s" id="%1$s" value="%2$s" />', |
| 219 |
'gllr_nonce_name', |
| 220 |
wp_create_nonce( plugin_basename(__FILE__) ) |
| 221 |
); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
if ( ! function_exists ( 'gllr_save_postdata' ) ) { |
| 226 |
function gllr_save_postdata( $post_id, $post ) { |
| 227 |
global $post; |
| 228 |
global $wpdb; |
| 229 |
if( isset( $_REQUEST['undefined'] ) && ! empty( $_REQUEST['undefined'] ) ) { |
| 230 |
$array_file_name = $_REQUEST['undefined']; |
| 231 |
$uploadFile = array(); |
| 232 |
$newthumb = array(); |
| 233 |
|
| 234 |
$uploadDir = wp_upload_dir( ); |
| 235 |
|
| 236 |
while( list( $key, $val ) = each( $array_file_name ) ) { |
| 237 |
$imagename = $val; |
| 238 |
$uploadFile[] = $uploadDir["path"] ."/" . $imagename; |
| 239 |
} |
| 240 |
reset( $array_file_name ); |
| 241 |
require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
| 242 |
$i = 0; |
| 243 |
while( list( $key, $val ) = each( $array_file_name ) ) { |
| 244 |
$file_name = $val; |
| 245 |
if ( copy ( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name, $uploadFile[$i] ) ) { |
| 246 |
unlink( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name ); |
| 247 |
$overrides = array('test_form' => false ); |
| 248 |
|
| 249 |
$file = str_replace( "\\", "/",$uploadDir["path"] ) ."/" .$file_name; |
| 250 |
$filename = basename( $file ); |
| 251 |
|
| 252 |
$wp_filetype = wp_check_filetype( $filename, null ); |
| 253 |
$attachment = array( |
| 254 |
'post_mime_type' => $wp_filetype['type'], |
| 255 |
'post_title' => $filename, |
| 256 |
'post_content' => '', |
| 257 |
'post_status' => 'inherit' |
| 258 |
); |
| 259 |
$attach_id = wp_insert_attachment( $attachment, $file ); |
| 260 |
$attach_data = wp_generate_attachment_metadata( $attach_id, $file ); |
| 261 |
wp_update_attachment_metadata( $attach_id, $attach_data ); |
| 262 |
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE ID = %d", $post->ID, $attach_id ) ); |
| 263 |
} |
| 264 |
$i++; |
| 265 |
} |
| 266 |
} |
| 267 |
if( isset( $_REQUEST['delete_images'] ) ) { |
| 268 |
foreach( $_REQUEST['delete_images'] as $delete_id ) { |
| 269 |
wp_delete_attachment( $delete_id ); |
| 270 |
} |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
if ( ! function_exists ( 'gllr_admin_head' ) ) { |
| 276 |
function gllr_admin_head() { |
| 277 |
echo '<link rel="stylesheet" type="text/css" href="'.plugins_url( 'css/stylesheet.css', __FILE__ ).'">'; |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
if ( ! function_exists ( 'gllr_plugin_init' ) ) { |
| 282 |
function gllr_plugin_init() { |
| 283 |
// Internationalization, first(!) |
| 284 |
load_plugin_textdomain( 'gallery', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 285 |
|
| 286 |
// Other init stuff, be sure to it after load_plugins_textdomain if it involves translated text(!) |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
if( ! function_exists( 'gllr_custom_permalinks' ) ) { |
| 291 |
function gllr_custom_permalinks() { |
| 292 |
global $wp_rewrite; |
| 293 |
global $wpdb; |
| 294 |
$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"); |
| 295 |
if( ! empty( $parent ) ) { |
| 296 |
$wp_rewrite->add_rule( '(.+)/'.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[2]&posts_per_page=-1', 'top' ); |
| 297 |
$wp_rewrite->add_rule( ''.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[1]&posts_per_page=-1', 'top' ); |
| 298 |
$wp_rewrite->add_rule( '(.+)/'.$parent.'/page/([^/]+)/?$', 'index.php?pagename='.$parent.'&paged=$matches[2]', 'top' ); |
| 299 |
$wp_rewrite->add_rule( ''.$parent.'/page/([^/]+)/?$', 'index.php?pagename='.$parent.'&paged=$matches[1]', 'top' ); |
| 300 |
} |
| 301 |
|
| 302 |
$wp_rewrite->flush_rules(); |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
if ( ! function_exists( 'gllr_template_redirect' ) ) { |
| 307 |
function gllr_template_redirect() |
| 308 |
{ |
| 309 |
global $wp_query, $post, $posts; |
| 310 |
if( 'gallery' == get_post_type() && "" == $wp_query->query_vars["s"] ) { |
| 311 |
$category = get_term_by( 'slug', $wp_query->query_vars["taxonomy"], 'images_album'); |
| 312 |
if( 'private' == get_post_meta( $category->term_id, '_gllr_public_status', true ) && ! is_user_logged_in()) { |
| 313 |
@header( "Location: ".get_bloginfo( 'url' ) ); |
| 314 |
exit(); |
| 315 |
} |
| 316 |
include( TEMPLATEPATH . '/gallery-single-template.php' ); |
| 317 |
exit(); |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
// Change the columns for the edit CPT screen |
| 324 |
if ( ! function_exists( 'gllr_change_columns' ) ) { |
| 325 |
function gllr_change_columns( $cols ) { |
| 326 |
$cols = array( |
| 327 |
'cb' => '<input type="checkbox" />', |
| 328 |
'title' => __('Title', 'gallery'), |
| 329 |
'autor' => __('Author', 'gallery'), |
| 330 |
'gallery' => __('Foto\'s', 'gallery'), |
| 331 |
'status' => __('Public', 'gallery'), |
| 332 |
'dates' => __('Date', 'gallery') |
| 333 |
); |
| 334 |
return $cols; |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
if ( ! function_exists( 'gllr_custom_columns' ) ) { |
| 339 |
function gllr_custom_columns( $column, $post_id ) { |
| 340 |
global $wpdb; |
| 341 |
$post = get_post( $post_id ); |
| 342 |
$row = $wpdb->get_results( "SELECT * |
| 343 |
FROM $wpdb->posts |
| 344 |
WHERE $wpdb->posts.post_parent = $post_id |
| 345 |
AND $wpdb->posts.post_type = 'attachment' |
| 346 |
AND ( |
| 347 |
$wpdb->posts.post_status = 'inherit' |
| 348 |
) |
| 349 |
ORDER BY $wpdb->posts.post_title ASC" ); |
| 350 |
switch ( $column ) { |
| 351 |
//case "category": |
| 352 |
case "autor": |
| 353 |
$author_id=$post->post_author; |
| 354 |
echo '<a href="edit.php?post_type=post&author='.$author_id.'">'.get_the_author_meta( 'user_nicename' , $author_id ).'</a>'; |
| 355 |
break; |
| 356 |
case "gallery": |
| 357 |
echo count($row); |
| 358 |
break; |
| 359 |
case "status": |
| 360 |
if( $post->post_status == 'publish' ) |
| 361 |
echo '<a href="javascript:void(0)">Yes</a>'; |
| 362 |
else |
| 363 |
echo '<a href="javascript:void(0)">No</a>'; |
| 364 |
break; |
| 365 |
case "dates": |
| 366 |
echo strtolower( __( date( "F", strtotime( $post->post_date ) ), 'kerksite' ) )." ".date( "j Y", strtotime( $post->post_date ) ); |
| 367 |
break; |
| 368 |
} |
| 369 |
$wp_query = $old_query; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
if ( ! function_exists( 'get_ID_by_slug' ) ) { |
| 374 |
function get_ID_by_slug($page_slug) { |
| 375 |
$page = get_page_by_path($page_slug); |
| 376 |
if ($page) { |
| 377 |
return $page->ID; |
| 378 |
} else { |
| 379 |
return null; |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
if ( ! function_exists( 'getPostsAvailableToRegisteredUsers' ) ) { |
| 385 |
function getPostsAvailableToRegisteredUsers() |
| 386 |
{ |
| 387 |
$theme_location = 'menu_2'; |
| 388 |
$theme_locations = get_nav_menu_locations(); |
| 389 |
if( ! isset( $theme_locations[$theme_location] ) ) return false; |
| 390 |
|
| 391 |
$menu_obj = get_term( $theme_locations[$theme_location], 'nav_menu' ); |
| 392 |
if( ! $menu_obj ) |
| 393 |
$menu_obj = false; |
| 394 |
|
| 395 |
global $wpdb; |
| 396 |
|
| 397 |
// Menu posts |
| 398 |
$menuPosts = $wpdb->get_col(" |
| 399 |
SELECT |
| 400 |
pm.meta_value |
| 401 |
FROM |
| 402 |
$wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON t.term_id = tt.term_id |
| 403 |
INNER JOIN $wpdb->term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id |
| 404 |
INNER JOIN $wpdb->postmeta pm ON tr.object_id = pm.post_id |
| 405 |
WHERE |
| 406 |
t.slug = '".$menu_obj->slug."' AND |
| 407 |
pm.meta_key = '_menu_item_object_id' |
| 408 |
"); |
| 409 |
|
| 410 |
if (empty($menuPosts)) |
| 411 |
{ |
| 412 |
$menuPosts = array(); |
| 413 |
} |
| 414 |
|
| 415 |
// All private posts |
| 416 |
$privatePosts = array(); |
| 417 |
while (count($menuPosts)) |
| 418 |
{ |
| 419 |
$postId = array_shift($menuPosts); |
| 420 |
array_push($privatePosts, (int) $postId); |
| 421 |
|
| 422 |
$childPosts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type IN ('document', 'page', 'image')", $postId)); |
| 423 |
if (is_array($childPosts) && count($childPosts)) |
| 424 |
{ |
| 425 |
$menuPosts = array_merge($menuPosts, $childPosts); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
return array_unique($privatePosts); |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
if ( function_exists( 'add_image_size' ) ) { |
| 434 |
add_image_size( 'album-thumb', 120, 80, true ); //300 pixels wide (and unlimited height) |
| 435 |
add_image_size( 'foto-thumb', 160, 120, true ); //300 pixels wide (and unlimited height) |
| 436 |
} |
| 437 |
|
| 438 |
if( ! function_exists( 'gllr_plugin_header' ) ) { |
| 439 |
function gllr_plugin_header() { |
| 440 |
global $post_type; |
| 441 |
?> |
| 442 |
<style> |
| 443 |
#adminmenu #menu-posts-gallery div.wp-menu-image |
| 444 |
{ |
| 445 |
background: url("<?php echo get_bloginfo('url');?>/wp-content/plugins/gallery-plugin/images/icon_16.png") no-repeat scroll center center transparent; |
| 446 |
} |
| 447 |
#adminmenu #menu-posts-gallery:hover div.wp-menu-image, #adminmenu #menu-posts-gallery.wp-has-current-submenu div.wp-menu-image |
| 448 |
{ |
| 449 |
background: url("<?php echo get_bloginfo('url');?>/wp-content/plugins/gallery-plugin/images/icon_16_c.png") no-repeat scroll center center transparent; |
| 450 |
} |
| 451 |
<?php if ( $post_type == 'gallery' ) { ?> |
| 452 |
.wrap #icon-edit |
| 453 |
{ |
| 454 |
background: url("<?php echo get_bloginfo('url');?>/wp-content/plugins/gallery-plugin/images/icon_36.png") no-repeat scroll left top transparent; |
| 455 |
} |
| 456 |
<?php } ?> |
| 457 |
</style> |
| 458 |
<?php |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
if( ! function_exists( 'the_excerpt_max_charlength' ) ) { |
| 463 |
function the_excerpt_max_charlength($charlength) { |
| 464 |
$excerpt = get_the_excerpt(); |
| 465 |
$charlength++; |
| 466 |
if( strlen( $excerpt ) > $charlength ) { |
| 467 |
$subex = substr( $excerpt, 0, $charlength-5 ); |
| 468 |
$exwords = explode( " ", $subex ); |
| 469 |
$excut = - ( strlen ( $exwords [ count( $exwords ) - 1 ] ) ); |
| 470 |
if( $excut < 0 ) { |
| 471 |
echo substr( $subex, 0, $excut ); |
| 472 |
} |
| 473 |
else { |
| 474 |
echo $subex; |
| 475 |
} |
| 476 |
echo "..."; |
| 477 |
} |
| 478 |
else { |
| 479 |
echo $excerpt; |
| 480 |
} |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
if( ! function_exists( 'gllr_page_css_class' ) ) { |
| 485 |
function gllr_page_css_class( $classes, $item ) { |
| 486 |
$post_type = get_query_var( 'post_type' ); |
| 487 |
global $wpdb; |
| 488 |
$parent_id = 0; |
| 489 |
if( $post_type == "gallery" ) { |
| 490 |
$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"); |
| 491 |
while ($parent_id) { |
| 492 |
$page = get_page($parent_id); |
| 493 |
if($page->post_parent > 0 ) |
| 494 |
$parent_id = $page->post_parent; |
| 495 |
else |
| 496 |
break; |
| 497 |
} |
| 498 |
wp_reset_query(); |
| 499 |
} |
| 500 |
if ($item->ID == $parent_id) { |
| 501 |
array_push($classes, 'current_page_item'); |
| 502 |
} |
| 503 |
return $classes; |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
register_activation_hook( __FILE__, 'gllr_plugin_install'); // activate plugin |
| 508 |
register_deactivation_hook( __FILE__, 'gllr_plugin_uninstall'); // deactivate plugin |
| 509 |
|
| 510 |
add_action( 'admin_head', 'gllr_plugin_header' ); |
| 511 |
|
| 512 |
add_action( 'init', 'gllr_plugin_init' ); |
| 513 |
|
| 514 |
add_action( 'init', 'post_type_images' ); // register post type |
| 515 |
add_action( 'init', 'gllr_custom_permalinks' ); // add custom permalink for gallery |
| 516 |
|
| 517 |
add_action( 'template_redirect', 'gllr_template_redirect' ); // add themplate for single gallery page |
| 518 |
|
| 519 |
add_action( 'admin_head', 'gllr_admin_head' ); |
| 520 |
add_action( 'save_post', 'gllr_save_postdata', 1, 2 ); // save custom data from admin |
| 521 |
|
| 522 |
add_filter( 'nav_menu_css_class', 'addImageAncestorToMenu' ); |
| 523 |
add_filter( 'page_css_class', 'gllr_page_css_class', 10, 2 ); |
| 524 |
|
| 525 |
add_filter( 'manage_gallery_posts_columns', 'gllr_change_columns' ); |
| 526 |
add_action( 'manage_gallery_posts_custom_column', 'gllr_custom_columns', 10, 2 ); |
| 527 |
|
| 528 |
?> |