Karl Rixon aka the php Oracle for the pagination function, the tricks and teaching me php. Gallery options in the Pages menu. Version: 2.2 Author: Thomas Michalak aka TM Author URI: http://www.fuck-dance-lets-art.com */ /* Copyright 2008/2010 Thomas Michalak (email : http://www.fuck-dance-lets-art.com/contact-me ) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once('all_in_one_gallery_functions.php'); /*************************************************************/ /* THE OPTION PANNEL THE OPTION PANNEL THE OPTION PANNEL */ /*************************************************************/ add_option(allInOneGallery_select_page, ''); add_option(allInOneGallery_css_theme, 'Blue'); add_option(allInOneGallery_how_many_columms, '4'); add_option(allInOneGallery_thumb_size, 'default'); add_option(allInOneGallery_ecluded_cat, ''); add_option(allInOneGallery_exclude_empty_cat_switch, "Off"); add_option(allInOneGallery_img_exclude, ''); add_option(allInOneGallery_message_switch, 'On'); add_option(allInOneGallery_welcome_message, 'All images that have been posted on '.get_bloginfo('name').' website are accessible here. Browse through the categories and view all images that are related to each category. Click on a thumbnail to see the full size. You can also read the related post by clicking on view this post'); add_option(allInOneGallery_welcome_category, ''); add_option(allInOneGallery_thumb_link_switch, 'Off'); add_option(allInOneGallery_pagination_switch, 'Off'); add_option(allInOneGallery_post_per_page, '2'); function all_in_one_gallery_menu() { add_pages_page('All in One Gallery Options', 'All in One Gallery', 2, __FILE__, 'all_in_one_gallery_options'); } function all_in_one_gallery_style_and_magic(){ //A bit of style echo ''; //A Bit of magic echo ''; } add_thickbox(); add_action('admin_head', 'all_in_one_gallery_style_and_magic'); /* function my_action_callback() { $test = ''; $catID = $_POST['catID']; $allMyPosts = get_posts('numberposts=-1&post_type=any&category='.$catID); //Get all images $onlyPostsImages = array(); foreach($allMyPosts as $key => $post){ $postID = $post->ID; $post_attch = get_children('post_type=attachment&post_mime_type=image&post_parent='.$postID); if($post_attch !== FALSE){ $thumbs = ''; foreach($post_attch as $attachment => $attachment_object){ $OriginalID = $attachment_object->ID; $imagearray = wp_get_attachment_image_src($OriginalID, 'thumbnail', false); $imageURI = $imagearray[0]; $imageID = get_post($OriginalID); $imageTitle = $imageID->post_title; $imageCaption = $imageID->post_excerpt; $imageDescription = $imageID->post_content; //Output list of thumbs $thumbs .= '
  • '; } $onlyPostsImages[$post->post_title] = $thumbs; } } //Construct String to send back $myResponse = ''; foreach($onlyPostsImages as $title => $Allthumbs){ $myResponse .= '

    '.$title.'

    '; $myResponse .= ''; } echo $myResponse; die(); } add_action('wp_ajax_my_special_action', 'my_action_callback'); */ function all_in_one_gallery_options() { //allInOneGalleryDebug(get_option('allInOneGallery_img_exclude')); //The form echo '
    '; echo '

    All in one Gallery

    '; echo '

    Display all you galleries in one place

    '; echo '
    '; wp_nonce_field('update-options'); echo ''; // Select Page echo ''; echo ''; echo ''; //Categories and Page selections echo ''; echo ''; echo ''; echo ''; // Welcome Message Options echo ''; echo ''; //Message On/Off echo ''; /* // Extra Options echo ''; echo ''; // Thumbs link to Post echo ''; */ //Extras echo ''; echo ''; echo ''; //End of Options echo '
    Place and Style your Online Gallery'; echo '
    • Select in wich page you want to display the gallery
    • '; //Select a Style $dir = dirname(__FILE__)."/all_in_one_gallery_themes"; $blackList = array('.', '..'); echo '
    • Select your gallery\'s menu color style
    • '; // Number of Columns echo '
    • Select how many columns in the gallery
    • '; // Thumbs Size $imagesSizes = array('default', 'thumbnails', 'medium', 'large', 'full'); echo '
    • Select images size
    '; echo '
    Exclude categories from showing'; //Exclude Empty Categories On/Off echo '
      '; echo '

      Exclude Empty Categories:

      '; $excludeEmpty_status = get_option('allInOneGallery_exclude_empty_cat_switch'); $switch_name = array('On', 'Off', 'Clear All'); foreach($switch_name as $value){ if($value == $excludeEmpty_status){ $sel = ' checked = true'; $sel_style = ' class = selected'; }else{ $sel = ''; $sel_style = ''; } //update_option(allInOneGallery_message_switch, false); echo '
    • '; } echo '
    '; // Exclude Categories echo '
      '; //Hidden Field For Excluded Images $excludedImages = get_option('allInOneGallery_img_exclude'); if(!empty($excludedImages)){ foreach($excludedImages as $excludedImagesCatID => $excludedImagesPostArray ){ $myCat = get_category($excludedImagesCatID); echo '
    Welcome Message
      '; $message_status = get_option('allInOneGallery_message_switch'); $switch_name = array('On', 'Off'); foreach($switch_name as $value){ if($value == $message_status){ $sel = ' checked = true'; $sel_style = ' class = selected'; }else{ $sel = ''; $sel_style = ''; } //update_option(allInOneGallery_message_switch, false); echo '
    • '; } echo '
    '; //Message content ( if switch is On ) $textarea_content = get_option('allInOneGallery_welcome_message'); echo '

    If the Welcome message is ON, display the message below

    '; echo ''; //Category to show First ( if switch if Off ) echo '

    If the Welcome message is Off, Select a category\'s gallery to display (exluded categories won\'t appear in this option)

    '; echo ''; echo '
    Extras
      '; echo '

      Thumbs will link to it\'s post:

      '; $thumbLink_status = get_option('allInOneGallery_thumb_link_switch'); $switch_name = array('On', 'Off'); foreach($switch_name as $value){ if($value == $thumbLink_status){ $sel = ' checked = true'; $sel_style = ' class = selected'; }else{ $sel = ''; $sel_style = ''; } //update_option(allInOneGallery_message_switch, false); echo '
    • '; } echo '
    '; echo '
    Extras'; //Pagination On/Off echo '
      '; echo '

      Enable pagination:

      '; $nbrPosts_status = get_option('allInOneGallery_pagination_switch'); $switch_name = array('On', 'Off'); foreach($switch_name as $value){ if($value == $nbrPosts_status){ $sel = ' checked = true'; $sel_style = ' class = selected'; }else{ $sel = ''; $sel_style = ''; } echo '
    • '; } echo '
    '; //Number of post per page $postPerPage = get_option('allInOneGallery_post_per_page'); echo '
      '; echo ''; echo '
    '; echo '
    '; echo ''; echo ''; echo '

    '; echo ''; echo '

    '; echo '
    '; echo '
    '; } add_action('admin_menu', 'all_in_one_gallery_menu'); /********** CHECK IS CATEGORY IS EMPTY *****************/ function allInOneGalleryEmptyCat($catID){ if(ctype_digit($catID)) $myPs = get_posts('numberposts=-1&post_type=any&category='.$catID); else if ($catID == 'Pages') $myPs = get_posts('numberposts=-1&post_type=page'); foreach($myPs as $p){ //Info about the post $pID = $p->ID; $p_attachments = get_children('post_type=attachment&post_mime_type=image&post_parent='.$pID); if(empty($p_attachments)){ $all_ps_attachements[] = FALSE; }else{ $all_ps_attachements[] = TRUE; } } //If there is no posts with attachements, say it if(!in_array(TRUE, $all_ps_attachements)){ $isEmpty = TRUE; }else{ $isEmpty = FALSE; } return $isEmpty; } /*************************************************************************************************************************/ /*************************************************************************************************************************/ /* */ /* THE PLUGIN THE PLUGIN THE PLUGIN THE PLUGIN THE PLUGIN THE PLUGIN THE PLUGIN THE PLUGIN THE PLUGIN THE PLUGIN */ /* */ /*************************************************************************************************************************/ /*************************************************************************************************************************/ /*check if the plugin should take effect*/ function allInOneGalleryTakeEffect(){ //Look at user's page choice $userPageChoice = get_option(allInOneGallery_select_page); //look at the current page name $my_page_name = get_the_title(); //Check if it's a page and compare it with the user's page choice if (is_page() && $my_page_name === $userPageChoice){ $doIt = TRUE; }else{ $doIt = FALSE; } return $doIt; } /*get users choice of category*/ function allInOneGalleryUserChoice(){ $myRequests = array(); if(empty($_GET)){ $myRequests['cat_id'] = ''; $myRequests['from'] = 0; }else{ if(isset($_GET['catRequest'])) $myRequests['cat_id'] = ($_GET['catRequest']); if(isset($_GET['from'])) $myRequests['from'] = ($_GET['from']); } $myRequests['page'] = isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1; $myRequests['to'] = get_option('allInOneGallery_post_per_page'); return $myRequests; } /*Display the Categories*/ function allInOneGalleryCategories($pageID, $user_cat_choice_id){ $category = get_categories(); $exlcu_cat = get_option('allInOneGallery_ecluded_cat'); echo '
    '; echo '
    '; echo ''; echo '
    '; } /*Pagination*/ function pagination($data, $currentPage, $perPage, $pID, $cat){ //Total items $totalItems = count($data); // The items on the current page. $offset = ($currentPage - 1) * $perPage; $firstItem = $offset + 1; $lastItem = $offset + $perPage < $totalItems ? $offset + $perPage : $totalItems; // Some useful variables for making links. $firstPage = 1; $lastPage = ceil($totalItems / $perPage); $prevPage = $currentPage - 1 > 0 ? $currentPage - 1 : 1; $nextPage = $currentPage + 1 > $lastPage ? $lastPage : $currentPage + 1; // Get the items for the current page $items = array_slice($data, $offset, $perPage); //Output $myURL = '?page_id='.$pID.'&catRequest='.$cat; $outPut .= ''; $pagination = array(); $pagination['output'] = $outPut; $pagination['array'] = $items; return $pagination; } /*Add the content*/ function allInOneGalleryContent($content) { //allInOneGalleryDebug(); if (allInOneGalleryTakeEffect() === TRUE){ $my_page_ID = get_the_ID(); $userRequests = allInOneGalleryUserChoice(); $user_cat_choice_id = $userRequests['cat_id']; $galleryCurrentPage = $userRequests['page']; $to = $userRequests['to']; $excludedImages = get_option('allInOneGallery_img_exclude'); //Check Thumb size if(get_option(allInOneGallery_thumb_size) === 'default') $myImgSize = ''; else $myImgSize = ' size="'.get_option(allInOneGallery_thumb_size).'"'; //Check what type of welcome message the user wants $welcome_user_choice = get_option('allInOneGallery_message_switch'); if($welcome_user_choice == 'On'){ //Select the welcome message if(empty($user_cat_choice_id)){ $user_cat_choice_id = ''; } }else{ //Select the welcome category if(empty($user_cat_choice_id)){ $user_cat_choice_id = get_option('allInOneGallery_welcome_category'); } } //Display Categories menu $content .= allInOneGalleryCategories($my_page_ID, $user_cat_choice_id); //Display Posts and Gallery for the selected category $content .= ''; $content .= '
    '; } return $content; } add_action('the_content', 'allInOneGalleryContent'); /*****************************************************************************/ /* CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS CSS */ /*****************************************************************************/ function allInOneGalleryCss(){ if(allInOneGalleryTakeEffect() === true){ echo ''; } } add_action('wp_head', 'allInOneGalleryCss'); ?>