Delete';
echo '';
endforeach;
echo '
';
echo '
';
}
}
// Use nonce for verification ...
if( ! function_exists ( 'echo_gllr_nonce' ) ) {
function echo_gllr_nonce () {
echo sprintf(
'
',
'gllr_nonce_name',
wp_create_nonce( plugin_basename(__FILE__) )
);
}
}
if ( ! function_exists ( 'gllr_save_postdata' ) ) {
function gllr_save_postdata( $post_id, $post ) {
global $post;
global $wpdb;
if( isset( $_REQUEST['undefined'] ) && ! empty( $_REQUEST['undefined'] ) ) {
$array_file_name = $_REQUEST['undefined'];
$uploadFile = array();
$newthumb = array();
$uploadDir = wp_upload_dir( );
while( list( $key, $val ) = each( $array_file_name ) ) {
$imagename = $val;
$uploadFile[] = $uploadDir["path"] ."/" . $imagename;
}
reset( $array_file_name );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$i = 0;
while( list( $key, $val ) = each( $array_file_name ) ) {
$file_name = $val;
if ( copy ( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name, $uploadFile[$i] ) ) {
unlink( ABSPATH ."wp-content/plugins/gallery-plugin/upload/files/".$file_name );
$overrides = array('test_form' => false );
$file = str_replace( "\\", "/",$uploadDir["path"] ) ."/" .$file_name;
$filename = basename( $file );
$wp_filetype = wp_check_filetype( $filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => $filename,
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $file );
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
wp_update_attachment_metadata( $attach_id, $attach_data );
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d WHERE ID = %d", $post->ID, $attach_id ) );
}
$i++;
}
}
if( isset( $_REQUEST['delete_images'] ) ) {
foreach( $_REQUEST['delete_images'] as $delete_id ) {
wp_delete_attachment( $delete_id );
}
}
}
}
if ( ! function_exists ( 'gllr_admin_head' ) ) {
function gllr_admin_head() {
echo '
';
}
}
if ( ! function_exists ( 'gllr_plugin_init' ) ) {
function gllr_plugin_init() {
// Internationalization, first(!)
load_plugin_textdomain( 'gallery', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
// Other init stuff, be sure to it after load_plugins_textdomain if it involves translated text(!)
}
}
if( ! function_exists( 'gllr_custom_permalinks' ) ) {
function gllr_custom_permalinks() {
global $wp_rewrite;
global $wpdb;
$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");
if( ! empty( $parent ) ) {
$wp_rewrite->add_rule( '(.+)/'.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[2]&posts_per_page=-1', 'top' );
$wp_rewrite->add_rule( ''.$parent.'/([^/]+)/?$', 'index.php?post_type=gallery&title=$matches[1]&posts_per_page=-1', 'top' );
$wp_rewrite->add_rule( '(.+)/'.$parent.'/page/([^/]+)/?$', 'index.php?pagename='.$parent.'&paged=$matches[2]', 'top' );
$wp_rewrite->add_rule( ''.$parent.'/page/([^/]+)/?$', 'index.php?pagename='.$parent.'&paged=$matches[1]', 'top' );
}
$wp_rewrite->flush_rules();
}
}
if ( ! function_exists( 'gllr_template_redirect' ) ) {
function gllr_template_redirect()
{
global $wp_query, $post, $posts;
if( 'gallery' == get_post_type() && "" == $wp_query->query_vars["s"] ) {
$category = get_term_by( 'slug', $wp_query->query_vars["taxonomy"], 'images_album');
if( 'private' == get_post_meta( $category->term_id, '_gllr_public_status', true ) && ! is_user_logged_in()) {
@header( "Location: ".get_bloginfo( 'url' ) );
exit();
}
include( TEMPLATEPATH . '/gallery-single-template.php' );
exit();
}
}
}
// Change the columns for the edit CPT screen
if ( ! function_exists( 'gllr_change_columns' ) ) {
function gllr_change_columns( $cols ) {
$cols = array(
'cb' => '
',
'title' => __('Title', 'gallery'),
'autor' => __('Author', 'gallery'),
'gallery' => __('Foto\'s', 'gallery'),
'status' => __('Public', 'gallery'),
'dates' => __('Date', 'gallery')
);
return $cols;
}
}
if ( ! function_exists( 'gllr_custom_columns' ) ) {
function gllr_custom_columns( $column, $post_id ) {
global $wpdb;
$post = get_post( $post_id );
$row = $wpdb->get_results( "SELECT *
FROM $wpdb->posts
WHERE $wpdb->posts.post_parent = $post_id
AND $wpdb->posts.post_type = 'attachment'
AND (
$wpdb->posts.post_status = 'inherit'
)
ORDER BY $wpdb->posts.post_title ASC" );
switch ( $column ) {
//case "category":
case "autor":
$author_id=$post->post_author;
echo '
'.get_the_author_meta( 'user_nicename' , $author_id ).'';
break;
case "gallery":
echo count($row);
break;
case "status":
if( $post->post_status == 'publish' )
echo '
Yes';
else
echo '
No';
break;
case "dates":
echo strtolower( __( date( "F", strtotime( $post->post_date ) ), 'kerksite' ) )." ".date( "j Y", strtotime( $post->post_date ) );
break;
}
$wp_query = $old_query;
}
}
if ( ! function_exists( 'get_ID_by_slug' ) ) {
function get_ID_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
}
}
if ( ! function_exists( 'getPostsAvailableToRegisteredUsers' ) ) {
function getPostsAvailableToRegisteredUsers()
{
$theme_location = 'menu_2';
$theme_locations = get_nav_menu_locations();
if( ! isset( $theme_locations[$theme_location] ) ) return false;
$menu_obj = get_term( $theme_locations[$theme_location], 'nav_menu' );
if( ! $menu_obj )
$menu_obj = false;
global $wpdb;
// Menu posts
$menuPosts = $wpdb->get_col("
SELECT
pm.meta_value
FROM
$wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON t.term_id = tt.term_id
INNER JOIN $wpdb->term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
INNER JOIN $wpdb->postmeta pm ON tr.object_id = pm.post_id
WHERE
t.slug = '".$menu_obj->slug."' AND
pm.meta_key = '_menu_item_object_id'
");
if (empty($menuPosts))
{
$menuPosts = array();
}
// All private posts
$privatePosts = array();
while (count($menuPosts))
{
$postId = array_shift($menuPosts);
array_push($privatePosts, (int) $postId);
$childPosts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type IN ('document', 'page', 'image')", $postId));
if (is_array($childPosts) && count($childPosts))
{
$menuPosts = array_merge($menuPosts, $childPosts);
}
}
return array_unique($privatePosts);
}
}
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'album-thumb', 120, 80, true ); //300 pixels wide (and unlimited height)
add_image_size( 'foto-thumb', 160, 120, true ); //300 pixels wide (and unlimited height)
}
if( ! function_exists( 'gllr_plugin_header' ) ) {
function gllr_plugin_header() {
global $post_type;
?>
$charlength ) {
$subex = substr( $excerpt, 0, $charlength-5 );
$exwords = explode( " ", $subex );
$excut = - ( strlen ( $exwords [ count( $exwords ) - 1 ] ) );
if( $excut < 0 ) {
echo substr( $subex, 0, $excut );
}
else {
echo $subex;
}
echo "...";
}
else {
echo $excerpt;
}
}
}
if( ! function_exists( 'gllr_page_css_class' ) ) {
function gllr_page_css_class( $classes, $item ) {
$post_type = get_query_var( 'post_type' );
global $wpdb;
$parent_id = 0;
if( $post_type == "gallery" ) {
$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");
while ($parent_id) {
$page = get_page($parent_id);
if($page->post_parent > 0 )
$parent_id = $page->post_parent;
else
break;
}
wp_reset_query();
}
if ($item->ID == $parent_id) {
array_push($classes, 'current_page_item');
}
return $classes;
}
}
register_activation_hook( __FILE__, 'gllr_plugin_install'); // activate plugin
register_deactivation_hook( __FILE__, 'gllr_plugin_uninstall'); // deactivate plugin
add_action( 'admin_head', 'gllr_plugin_header' );
add_action( 'init', 'gllr_plugin_init' );
add_action( 'init', 'post_type_images' ); // register post type
add_action( 'init', 'gllr_custom_permalinks' ); // add custom permalink for gallery
add_action( 'template_redirect', 'gllr_template_redirect' ); // add themplate for single gallery page
add_action( 'admin_head', 'gllr_admin_head' );
add_action( 'save_post', 'gllr_save_postdata', 1, 2 ); // save custom data from admin
add_filter( 'nav_menu_css_class', 'addImageAncestorToMenu' );
add_filter( 'page_css_class', 'gllr_page_css_class', 10, 2 );
add_filter( 'manage_gallery_posts_columns', 'gllr_change_columns' );
add_action( 'manage_gallery_posts_custom_column', 'gllr_custom_columns', 10, 2 );
?>