Advertisement
Guest User

Polaroid Gallley

a guest
Dec 20th, 2010
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.96 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Polaroid Gallery
  4. Plugin URI: http://www.mikkonen.info/polaroid_gallery/
  5. Description: Used to overlay images as polaroid pictures on the current page or post and uses WordPress Media Library.
  6. Version: 2.0.1
  7. Author: Jani Mikkonen
  8. Author URI: http://www.mikkonen.info
  9. */
  10.  
  11. /** admin code **/
  12.  
  13. add_action('admin_init', 'polaroid_gallery_options_init');
  14. add_action('admin_menu', 'polaroid_gallery_options_add_page');
  15.  
  16. function polaroid_gallery_options_init() {
  17.     register_setting('polaroid_gallery_options', 'image_size');
  18.     register_setting('polaroid_gallery_options', 'ignore_columns');
  19.     register_setting('polaroid_gallery_options', 'custom_text');
  20.     register_setting('polaroid_gallery_options', 'custom_text_value');
  21.     register_setting('polaroid_gallery_options', 'thumbnail_option');
  22.     register_setting('polaroid_gallery_options', 'image_option');
  23.         //My added line
  24.     register_setting('polaroid_gallery_options', 'image_link');
  25. }
  26.  
  27. function polaroid_gallery_options_add_page() {
  28.     add_options_page('Polaroid Gallery Options', 'Polaroid Gallery', 'manage_options', 'polaroid_gallery_options', 'polaroid_gallery_options_do_page');
  29. }
  30.  
  31. function polaroid_gallery_options_do_page() {
  32.     ?>
  33.     <div class="wrap">
  34.         <?php screen_icon(); ?>
  35.         <h2><?php _e('Polaroid Gallery Options') ?></h2>
  36.         <form method="post" action="options.php">
  37.             <?php
  38.             settings_fields('polaroid_gallery_options');
  39.             $image_size         = get_option('image_size', 'large');
  40.             $ignore_columns     = get_option('ignore_columns', 'no');
  41.             $custom_text        = get_option('custom_text', 'no');
  42.             $custom_text_value  = get_option('custom_text_value', 'Image');
  43.             $thumbnail_option   = get_option('thumbnail_option', 'none');
  44.             $image_option       = get_option('image_option', 'title3');
  45.             $image_link         = get_option('image_link','yes');
  46.             ?>
  47.             <h3><?php _e('Gallery Settings'); ?></h3>
  48.             <p><?php _e('Choose the image size to display when user clicks the thumbnail. Images will be scaled to fit the screen if they are too large.'); ?></p>
  49.             <p><?php _e('You can adjust the image sizes via Settings -> Media.'); ?></p>
  50.             <table class="form-table">
  51.             <tr>
  52.                 <th scope="row"><?php _e('Image sizes') ?></th>
  53.                 <td>
  54.                     <fieldset>
  55.                         <legend class="screen-reader-text"><span><?php _e('Size') ?></span></legend>
  56.                         <label title='<?php _e("Medium"); ?>'><input type='radio' name='image_size' value='medium' <?php checked('medium', $image_size); ?>/> <?php _e("Medium"); ?></label><br />
  57.                         <label title='<?php _e("Large"); ?>'><input type='radio' name='image_size' value='large' <?php checked('large', $image_size); ?>/> <?php _e("Large"); ?></label><br />
  58.                         <label title='<?php _e("Full size"); ?>'><input type='radio' name='image_size' value='full' <?php checked('full', $image_size); ?>/> <?php _e("Full size"); ?></label><br />
  59.                     </fieldset>
  60.                 </td>
  61.             </tr>
  62.             <tr>
  63.                 <th scope="row"><?php _e('Ignore Gallery columns') ?></th>
  64.                 <td>
  65.                     <fieldset>
  66.                         <legend class="screen-reader-text"><span><?php _e('Ignore Gallery columns') ?></span></legend>
  67.                         <label title='<?php _e("No"); ?>'><input type='radio' name='ignore_columns' value='no' <?php checked('no', $ignore_columns); ?>/> <?php _e("No"); ?></label><br />
  68.                         <label title='<?php _e("Yes"); ?>'><input type='radio' name='ignore_columns' value='yes' <?php checked('yes', $ignore_columns); ?>/> <?php _e("Yes (good for fluid layouts)"); ?></label><br />
  69.                     </fieldset>
  70.                 </td>
  71.             </tr>
  72.             <tr>
  73.                 <th scope="row"><?php _e('Custom text for "Image"') ?></th>
  74.                 <td>
  75.                     <fieldset>
  76.                         <legend class="screen-reader-text"><span><?php _e('Custom text for "Image"') ?></span></legend>
  77.                         <label title='<?php _e("No"); ?>'><input type='radio' name='custom_text' value='no' <?php checked('no', $custom_text); ?>/> <?php _e("No (localized default text)"); ?></label><br />
  78.                         <label title='<?php _e("Yes"); ?>'><input type='radio' name='custom_text' value='yes' <?php checked('yes', $custom_text); ?>/> <?php _e("Yes"); ?></label><br />
  79.                         <label title='<?php _e("Text"); ?>'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php _e("Text"); ?>: <input type='text' name='custom_text_value' value='<?php print $custom_text_value; ?>' /></label><br />
  80.                     </fieldset>
  81.                 </td>
  82.             </tr>
  83.             <tr>
  84.                 <th scope="row"><?php _e('Thumbnails text settings') ?></th>
  85.                 <td>
  86.                     <fieldset>
  87.                         <legend class="screen-reader-text"><span><?php _e('Thumbnails text settings') ?></span></legend>
  88.                         <label title='<?php _e("None"); ?>'><input type='radio' name='thumbnail_option' value='none' <?php checked('none', $thumbnail_option); ?>/> <?php _e("None"); ?></label><br />
  89.                         <label title='<?php _e("Caption text"); ?>'><input type='radio' name='thumbnail_option' value='caption' <?php checked('caption', $thumbnail_option); ?>/> <?php _e("Caption text"); ?></label><br />
  90.                         <label title='<?php _e("Image #"); ?>'><input type='radio' name='thumbnail_option' value='image1' <?php checked('image1', $thumbnail_option); ?>/> <?php _e("Image #"); ?></label><br />
  91.                         <label title='<?php _e("Image #/#"); ?>'><input type='radio' name='thumbnail_option' value='image2' <?php checked('image2', $thumbnail_option); ?>/> <?php _e("Image #/#"); ?></label><br />
  92.                         <label title='<?php _e("#"); ?>'><input type='radio' name='thumbnail_option' value='number1' <?php checked('number1', $thumbnail_option); ?>/> <?php _e("#"); ?></label><br />
  93.                         <label title='<?php _e("#/#"); ?>'><input type='radio' name='thumbnail_option' value='number2' <?php checked('number2', $thumbnail_option); ?>/> <?php _e("#/#"); ?></label><br />
  94.                     </fieldset>
  95.                 </td>
  96.             </tr>
  97.             <tr>
  98.                 <th scope="row"><?php _e('Image text settings') ?></th>
  99.                 <td>
  100.                     <fieldset>
  101.                         <legend class="screen-reader-text"><span><?php _e('Image text settings') ?></span></legend>
  102.                         <label title='<?php _e("None"); ?>'><input type='radio' name='image_option' value='none' <?php checked('none', $image_option); ?>/> <?php _e("None"); ?></label><br />
  103.                         <label title='<?php _e("Title text"); ?>'><input type='radio' name='image_option' value='title1' <?php checked('title1', $image_option); ?>/> <?php _e("Title text"); ?></label><br />
  104.                         <label title='<?php _e("#  Title text"); ?>'><input type='radio' name='image_option' value='title2' <?php checked('title2', $image_option); ?>/> <?php _e("#  Title text"); ?></label><br />
  105.                         <label title='<?php _e("#/#  Title text"); ?>'><input type='radio' name='image_option' value='title3' <?php checked('title3', $image_option); ?>/> <?php _e("#/#  Title text"); ?></label><br />
  106.                         <label title='<?php _e("Image #  Title text"); ?>'><input type='radio' name='image_option' value='title4' <?php checked('title4', $image_option); ?>/> <?php _e("Image #  Title text"); ?></label><br />
  107.                         <label title='<?php _e("Image #/#  Title text"); ?>'><input type='radio' name='image_option' value='title5' <?php checked('title5', $image_option); ?>/> <?php _e("Image #/#  Title text"); ?></label><br />
  108.                         <label title='<?php _e("Image #"); ?>'><input type='radio' name='image_option' value='image1' <?php checked('image1', $image_option); ?>/> <?php _e("Image #"); ?></label><br />
  109.                         <label title='<?php _e("Image #/#"); ?>'><input type='radio' name='image_option' value='image2' <?php checked('image2', $image_option); ?>/> <?php _e("Image #/#"); ?></label><br />
  110.                         <label title='<?php _e("#"); ?>'><input type='radio' name='image_option' value='number1' <?php checked('number1', $image_option); ?>/> <?php _e("#"); ?></label><br />
  111.                         <label title='<?php _e("#/#"); ?>'><input type='radio' name='image_option' value='number2' <?php checked('number2', $image_option); ?>/> <?php _e("#/#"); ?></label><br />
  112.                     </fieldset>
  113.                 </td>
  114.             </tr>
  115.                 <!-- My added table row -->
  116.             <tr>
  117.                 <th scope="row"><?php _e('Check this box to have the built in gallery use the description field as an external link from the image thumbnail.') ?></th>
  118.                 <td>
  119.                     <fieldset>
  120.                         <legend class="screen-reader-text"><span><?php _e('Check this box to have the built in gallery use the description field as an external link from the image thumbnail.') ?></span></legend>
  121.                         <label title='<?php _e("Checked"); ?>'><input type="checkbox" name="image_link" value="yes"  <?php checked('yes', $image_link); ?> /></label>
  122.                     </fieldset>
  123.                 </td>
  124.             </tr>
  125.             </table>
  126.             <p class="submit">
  127.                 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
  128.             </p>
  129.         </form>
  130.     </div>
  131.     <?php
  132. }
  133.  
  134. /** plugin code **/
  135.  
  136. $polaroid_gallery_plugin_prefix = WP_PLUGIN_URL . "/polaroid-gallery/";
  137.  
  138. if (!is_admin()) {
  139.     // add javascript to head
  140.     wp_enqueue_script('jquery');
  141.     wp_enqueue_script('jquery.easing-1.3', ($polaroid_gallery_plugin_prefix.'js/jquery.easing-1.3.pack.js'));
  142.     wp_enqueue_script('jquery.mousewheel-3.0.2', ($polaroid_gallery_plugin_prefix.'js/jquery.mousewheel-3.0.2.pack.js'));
  143.     wp_enqueue_script('jquery.fancybox-1.3.1', ($polaroid_gallery_plugin_prefix.'js/jquery.fancybox-1.3.1.pack.js'));
  144.     wp_enqueue_script('polaroid_gallery-2.0', ($polaroid_gallery_plugin_prefix.'js/polaroid_gallery-2.0.js'));
  145.     // add css to head
  146.     wp_enqueue_style('polaroid_gallery_fancybox', ($polaroid_gallery_plugin_prefix . 'css/jquery.fancybox-1.3.1.css'));
  147.     wp_enqueue_style('polaroid_gallery_style', ($polaroid_gallery_plugin_prefix . 'css/polaroid_gallery.css'));
  148. }
  149.  
  150. function polaroid_gallery_shortcode($output, $attr) {
  151.     global $post, $wp_locale;
  152.    
  153.     // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
  154.     if ( isset( $attr['orderby'] ) ) {
  155.         $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
  156.         if ( !$attr['orderby'] ) {
  157.             unset( $attr['orderby'] );
  158.         }
  159.     }
  160.    
  161.     extract(shortcode_atts(array(
  162.         'order'      => 'ASC',
  163.         'orderby'    => 'menu_order ID',
  164.         'id'         => $post->ID,
  165.         'itemtag'    => '',
  166.         'icontag'    => '',
  167.         'captiontag' => '',
  168.         'columns'    => 3,
  169.         'size'       => 'thumbnail',
  170.         'include'    => '',
  171.         'exclude'    => ''
  172.     ), $attr));
  173.    
  174.     $image_size         = get_option('image_size', 'large');
  175.     $ignore_columns     = get_option('ignore_columns', 'no');
  176.    
  177.     //My added line
  178.     $image_link     = get_option('image_link', 'true');
  179.    
  180.     $id = intval($id);
  181.     if ( 'RAND' == $order ) {
  182.         $orderby = 'none';
  183.     }
  184.    
  185.     if ( !empty($include) ) {
  186.         $include = preg_replace( '/[^0-9,]+/', '', $include );
  187.         $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  188.         $attachments = array();
  189.         foreach ( $_attachments as $key => $val ) {
  190.             $attachments[$val->ID] = $_attachments[$key];
  191.         }
  192.     } elseif ( !empty($exclude) ) {
  193.         $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
  194.         $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  195.     } else {
  196.         $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
  197.     }
  198.    
  199.     if ( empty($attachments) ) {
  200.         return '';
  201.     }
  202.    
  203.     if ( is_feed() ) {
  204.         $output = "\n";
  205.         foreach ( $attachments as $att_id => $attachment ) {
  206.             $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
  207.         }
  208.         return $output;
  209.     }
  210.    
  211.     $columns = intval($columns);
  212.     if( $ignore_columns == 'yes' ) {
  213.         $columns = 0;
  214.     }
  215.     $output .= "
  216.         <div class='polaroid-gallery galleryid-{$id}'>";
  217.    
  218.     $i = 0;
  219.     foreach ( $attachments as $id => $attachment ) {
  220.         $image = wp_get_attachment_image_src($id, $size=$image_size, $icon = false);
  221.         $thumb = wp_get_attachment_image_src($id, $size='thumbnail', $icon = false);
  222.         $title = wptexturize(trim($attachment->post_title));
  223.         $alt = wptexturize(trim($attachment->post_excerpt));
  224.        
  225.         //My added line
  226.         $link = wptexturize(trim($attachment->post_content));
  227.  
  228.         if (($image_link == 'yes') && (substr($link,0,7) == 'http://')) {
  229.             $output .= '<a href="'. $link .'" title="'. $title .'"target=\'_blank\'" rel="polaroid_'. $post->ID .'" class="polaroid-gallery-item"><img src="'. $thumb[0] .'" width="'. $thumb[1] .'" height="'. $thumb[2] .'" alt="'. $alt .'" /></a>';
  230.         } else {
  231.     `       $output .= '<a href="'. $image[0] .'" title="'. $title .'" rel="polaroid_'. $post->ID .'" class="polaroid-gallery-item"><img src="'. $thumb[0] .'" width="'. $thumb[1] .'" height="'. $thumb[2] .'" alt="'. $alt .'" /></a>';
  232.         }
  233.         // End my if statement change
  234.        
  235.        
  236.         if ( $columns > 0 && ++$i % $columns == 0 ){
  237.             $output .= '
  238.             <br style="clear: both;" />';
  239.         }
  240.     }
  241.     if ( $columns > 0 && $i % $columns != 0 ) {
  242.         $output .= '
  243.             <br style="clear: both;" />';
  244.     }
  245.     if( $ignore_columns == 'yes' ) {
  246.         $output .= '
  247.             <br style="clear: both;" />';
  248.     }
  249.     $output .= "
  250.         </div>\n";
  251.    
  252.     return $output;
  253. }
  254. // //var polaroid_gallery_image_str = '". __('Image') ."';
  255. function polaroid_gallery_head() {
  256.     global $polaroid_gallery_plugin_prefix;
  257.    
  258.     $custom_text        = get_option('custom_text', 'no');
  259.     $custom_text_value  = get_option('custom_text_value', 'Image');
  260.     $thumbnail_option   = get_option('thumbnail_option', 'none');
  261.     $image_option       = get_option('image_option', 'title3');
  262.    
  263.     $text2image = __('Image');
  264.     if($custom_text == 'yes') {
  265.         $text2image = $custom_text_value;
  266.     }
  267.    
  268.     $polaroid_gallery_script = "
  269.     <script type=\"text/javascript\">
  270.     /* <![CDATA[ */
  271.     var polaroid_gallery = {
  272.         text2image: '". $text2image ."', thumbnail: '". $thumbnail_option ."', image: '". $image_option ."'
  273.     };
  274.     /* ]]> */
  275.     </script>
  276.     <!--[if lt IE 8]>
  277.         <link rel=\"stylesheet\" type=\"text/css\" href=\"". $polaroid_gallery_plugin_prefix ."css/jquery.fancybox-old-ie.css\" />
  278.     <![endif]-->\n";
  279.     print $polaroid_gallery_script;
  280. }
  281.  
  282. add_action('wp_head', 'polaroid_gallery_head');
  283. add_filter('post_gallery', 'polaroid_gallery_shortcode', 10, 2);
  284.  
  285. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement