Advertisement
Guest User

Untitled

a guest
Jun 11th, 2012
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.74 KB | None | 0 0
  1. <?php
  2.  
  3. function load_pmg_single_doc() {
  4.     register_widget('PMG_Single_Doc');
  5. }
  6. add_action('widgets_init', 'load_pmg_single_doc');
  7.  
  8. class PMG_Single_Doc extends WP_Widget {
  9.  
  10.     function PMG_Single_Doc() {
  11.         $widget_ops = array('classname' => 'widget_text', 'description' => __('A widget that displays download links to a document of your choosing.'));
  12.         $control_ops = array('width' => 400, 'height' => 350);
  13.         $this->WP_Widget('PMG_Single_Doc', 'Single Document Widget', $widget_ops, $control_ops );
  14.     }
  15.  
  16.     function widget( $args, $instance ) {
  17.         extract($args);
  18.         $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
  19.         $url = apply_filters( 'widget_url', empty( $instance['url'] ) ? '' : $instance['url'], $instance );
  20.         $desc = apply_filters( 'widget_text', empty( $instance['desc'] ) ? '' : $instance['desc'], $instance );
  21.        
  22.         $before_widget = preg_replace('/class="(.*?)"/i', 'class="$1 downloadsWidget"', $before_widget);
  23.        
  24.         echo $before_widget;
  25.        
  26.         if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
  27.             <?php
  28.        
  29.                 if ( $url ) {      
  30.                     $pdf = $url;
  31.                     $info = pathinfo($pdf);
  32.                     $filename =  basename($pdf,'.'.$info['extension']);
  33.                    
  34.                     $uploads = wp_upload_dir();
  35.                     $file_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
  36.                     $dest_path = str_replace( '.pdf', '.jpg', $file_path );
  37.                     $dest_url = str_replace( '.pdf', '.jpg', $pdf );
  38.                                      
  39.                     exec("convert \"{$file_path}[0]\" -colorspace RGB -geometry 60 $dest_path"); ?>
  40.                     <div class="entry">
  41.                         <div class="widgetImg">
  42.                             <p><a href="<?php echo $url; ?>" title="<?php echo $filename; ?>"><?php echo "<img src='".$dest_url."' alt='".$filename."' class='blueBorder' />"; ?></a></p>
  43.                         </div>
  44.                        
  45.                         <div class="widgetText">
  46.                             <?php echo wpautop( $desc ); ?>
  47.                            
  48.                             <p><a class="downloadLink" href="<?php echo $url; ?>" title="<?php echo $filename; ?>">Download</a></p>
  49.                         </div>
  50.                     </div>
  51.                     <?php }
  52.             ?>
  53.         <?php
  54.         echo $after_widget;
  55.     }
  56.  
  57.     function update( $new_instance, $old_instance ) {
  58.         $instance = $old_instance;
  59.         $instance['title'] = strip_tags($new_instance['title']);
  60.         $instance['url'] = strip_tags($new_instance['url']);
  61.         if ( current_user_can('unfiltered_html') )
  62.             $instance['desc'] =  $new_instance['desc'];
  63.         else
  64.             $instance['desc'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['desc']) ) ); // wp_filter_post_kses() expects slashed
  65.        
  66.         $instance['filter'] = isset($new_instance['filter']);
  67.         return $instance;
  68.     }
  69.  
  70.     function form( $instance ) {
  71.         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'numposts' => '', 'desc' => '', 'url' => '' ) );
  72.         $title = strip_tags($instance['title']);
  73.         $url = strip_tags($instance['url']);
  74.         $desc = esc_textarea($instance['desc']);
  75. ?>
  76.         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  77.         <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
  78.        
  79.         <p><label for="<?php echo $this->get_field_id('url'); ?>"><?php _e('URL of PDF attachment <em>(must be PDF)</em>:'); ?></label>
  80.         <input class="widefat" id="<?php echo $this->get_field_id('numposts'); ?>" name="<?php echo $this->get_field_name('url'); ?>" type="text" value="<?php echo esc_attr($url); ?>" /></p>
  81.        
  82.         <p><label for="<?php echo $this->get_field_id('desc'); ?>"><?php _e('Description:'); ?></label>
  83.         <textarea class="widefat" id="<?php echo $this->get_field_id('desc'); ?>" name="<?php echo $this->get_field_name('desc'); ?>"><?php echo $desc; ?></textarea></p>
  84. <?php
  85.     }
  86. }
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement