Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function load_pmg_single_doc() {
- register_widget('PMG_Single_Doc');
- }
- add_action('widgets_init', 'load_pmg_single_doc');
- class PMG_Single_Doc extends WP_Widget {
- function PMG_Single_Doc() {
- $widget_ops = array('classname' => 'widget_text', 'description' => __('A widget that displays download links to a document of your choosing.'));
- $control_ops = array('width' => 400, 'height' => 350);
- $this->WP_Widget('PMG_Single_Doc', 'Single Document Widget', $widget_ops, $control_ops );
- }
- function widget( $args, $instance ) {
- extract($args);
- $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
- $url = apply_filters( 'widget_url', empty( $instance['url'] ) ? '' : $instance['url'], $instance );
- $desc = apply_filters( 'widget_text', empty( $instance['desc'] ) ? '' : $instance['desc'], $instance );
- $before_widget = preg_replace('/class="(.*?)"/i', 'class="$1 downloadsWidget"', $before_widget);
- echo $before_widget;
- if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
- <?php
- if ( $url ) {
- $pdf = $url;
- $info = pathinfo($pdf);
- $filename = basename($pdf,'.'.$info['extension']);
- $uploads = wp_upload_dir();
- $file_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
- $dest_path = str_replace( '.pdf', '.jpg', $file_path );
- $dest_url = str_replace( '.pdf', '.jpg', $pdf );
- exec("convert \"{$file_path}[0]\" -colorspace RGB -geometry 60 $dest_path"); ?>
- <div class="entry">
- <div class="widgetImg">
- <p><a href="<?php echo $url; ?>" title="<?php echo $filename; ?>"><?php echo "<img src='".$dest_url."' alt='".$filename."' class='blueBorder' />"; ?></a></p>
- </div>
- <div class="widgetText">
- <?php echo wpautop( $desc ); ?>
- <p><a class="downloadLink" href="<?php echo $url; ?>" title="<?php echo $filename; ?>">Download</a></p>
- </div>
- </div>
- <?php }
- ?>
- <?php
- echo $after_widget;
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- $instance['url'] = strip_tags($new_instance['url']);
- if ( current_user_can('unfiltered_html') )
- $instance['desc'] = $new_instance['desc'];
- else
- $instance['desc'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['desc']) ) ); // wp_filter_post_kses() expects slashed
- $instance['filter'] = isset($new_instance['filter']);
- return $instance;
- }
- function form( $instance ) {
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'numposts' => '', 'desc' => '', 'url' => '' ) );
- $title = strip_tags($instance['title']);
- $url = strip_tags($instance['url']);
- $desc = esc_textarea($instance['desc']);
- ?>
- <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
- <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>
- <p><label for="<?php echo $this->get_field_id('url'); ?>"><?php _e('URL of PDF attachment <em>(must be PDF)</em>:'); ?></label>
- <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>
- <p><label for="<?php echo $this->get_field_id('desc'); ?>"><?php _e('Description:'); ?></label>
- <textarea class="widefat" id="<?php echo $this->get_field_id('desc'); ?>" name="<?php echo $this->get_field_name('desc'); ?>"><?php echo $desc; ?></textarea></p>
- <?php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement