Plugin Directory

Changeset 485261


Ignore:
Timestamp:
01/05/2012 07:37:14 PM (14 years ago)
Author:
alvaron
Message:
 
Location:
youtubenails
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • youtubenails/branches/readme.txt

    r355277 r485261  
    44Tags: youtube,thumbnails,video
    55Requires at least: 3.0.3
    6 Tested up to: 3.0.3
    7 Stable tag: 2.0.0
     6Tested up to: 3.2.1
     7Stable tag: 3.0.0
    88
    99== Description ==
    1010
    11 Create a dynamic gallery widget(works as shortcode too, if desired), with thumbnails of each post with youtube videos displayed on the content linked to the post permalink. It checks all you video posts, but you can filter them by category and choose the number of posts.
     11Create a dynamic gallery multiple widget(works as shortcode too), with thumbnails of each post with youtube/vimeo(beta) videos displayed on the content linked to the post single. Checks all you video posts, but you can filter them by category and choose the number of posts.
    1212
    1313Based on
     
    51517. The table id for the result table wp_ytbnstb;
    5252
    53 To work as short code
     53To work as short code, call
     54[ytbn nop="2" ln="1" catg="" tbsz="1" cpad="3" cpin="3"]
    5455
    55 call it on php  youtubenails_show(8,1,'',2,3,3);
     56or call it on php as function  youtubenails_show(8,1,'',2,3,3);
    5657
    5758where the parameters are
     
    7677
    7778== Changelog ==
     793.0.0
     80Supports multiple widgets and shortcodes;
     81Vimeo supported(beta feature);
     82
    78832.0.0
    7984
     
    9095
    9196<!--
     97http://www.youtube.com/watch?v=gNwuES4lMeQ
     98
    9299<iframe title="YouTube video player" class="youtube-player" type="text/html" width="480" height="390" src="http://www.youtube.com/embed/yXYW4c-FndI" frameborder="0" allowFullScreen></iframe>
    93100
  • youtubenails/branches/youtubenails.php

    r354590 r485261  
    44Plugin URI: http://youtubenails.sourceforge.net/
    55Description:Create a dynamic gallery of thumbnails of each post with youtube videos displayed on the content linked to the post permalink
    6 Version: 2.0.0
     6Version: 3.0.0
    77Author: Alvaro Neto
    88Author URI: http://wpworks.wordpress.com/
     
    2626    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2727*/
     28//
     29add_shortcode('ytbn','ytbn_short');
     30//
     31function ytbn_short($atts, $content = null){
     32   extract(shortcode_atts(array(
     33        'ptype' => 'post',
     34        'nop' => '8',
     35        'ln' => 3,
     36        'catg' => '',
     37        'tbsz' => 2,
     38        'cpad' => 3,
     39        'cpin' =>3,
     40        'ech' => false     
     41    ), $atts));
     42    ob_start();         
     43    $ytbnres=youtubenails_show($nop,$ln,$catg,$tbsz,$cpad,$cpin,$ech);
     44    echo $ytbnres;
     45    $ytbn_string = ob_get_contents();
     46    ob_end_clean();
     47    return $ytbn_string;
     48}
     49//
     50/**
     51 * Add FAQ and support information
     52 */
     53add_filter('plugin_row_meta', 'wp_ytbn_plugin_links', 10, 2);
     54function wp_ytbn_plugin_links ($links, $file)
     55{
     56    if ($file == plugin_basename(__FILE__)) {
     57        $links[] = '<a href="http://www.wpworking.com/">' . __('Donate', 'wp_ytbn') . '</a>';
     58    }
     59    return $links;
     60}
     61//
    2862function partrat($par,$def)
    2963{
     
    3670    return $par;
    3771}
     72function getVimeoInfo($id, $info = 'thumbnail_medium') {
     73    if (!function_exists('curl_init')) die('CURL is not installed, impossible to display vimeo, sorry!');
     74    $ch = curl_init();
     75    curl_setopt($ch, CURLOPT_URL, "vimeo.com/api/v2/video/$id.php");
     76    curl_setopt($ch, CURLOPT_HEADER, 0);
     77    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     78    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     79    $output = unserialize(curl_exec($ch));
     80    $output = $output[0][$info];
     81    curl_close($ch);
     82    return $output;
     83}
    3884 
    39 function youtubenails_show($nop=8,$ln=3,$catg='',$tbsz=2,$cpad=3,$cpin=3)
     85function youtubenails_show($nop=8,$ln=3,$catg='',$tbsz=2,$cpad=3,$cpin=3,$ech=true)
    4086{
    4187    $nop = partrat($nop,8);
     
    4591    $cpad = partrat($cpad,3);
    4692    $cpin = partrat($cpin,3);
     93    $ech = partrat($ech,true);
    4794   
    4895    //echo "cpad:".$cpad."<br>";
     
    60107    }
    61108   
    62     if (have_posts()) :
     109    //if (have_posts()) :
    63110     // Gets the post's content
    64111     global $post;
     
    67114            $myposts = get_posts("numberposts=".$nop."&category_name='".$catg."'");
    68115            //get_posts('category_name='.$catg);
     116            query_posts("numberposts=".$nop."&category_name='".$catg."'");
    69117        else:
    70118            $myposts = get_posts("numberposts=".$nop);
     119            query_posts("numberposts=".$nop);
    71120            //get_posts();
    72121        endif;
     
    76125        if($lmtcnt>0):
    77126             $tbhtml = "<table cellpadding='".$cpad."' cellspacing='".$cpin."' border='0' id='wp_ytbnstb'>";
    78              foreach($myposts as $post) :
    79                 $post_id = $post->ID;
     127             while (have_posts()) : the_post();
     128                $post_id = get_the_ID();
    80129                $post_array = get_post($post_id);
    81130                //$markup = get_the_content();
     
    102151                // Checks for a standard YouTube embed
    103152                preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
    104                
    105                
    106153               
    107154                // Checks for YouTube iframe
     
    140187                        //echo "teste6";
    141188                        $new_thumbnail = $youtube_thumbnail;
    142                     } else {
     189                    }
     190                    else {
    143191                        //echo "teste7";
    144192                        $ch = curl_init($youtube_thumbnail);
     
    154202                    }
    155203                }
    156                 //echo $new_thumbnail;
    157                 $rwcnt = $rwcnt + 1;           
     204                // Vimeo
     205                if($new_thumbnail==null) {
     206               
     207                    // Standard embed code
     208                    preg_match('#<object[^>]+>.+?http://vimeo.com/moogaloop.swf\?clip_id=([A-Za-z0-9\-_]+)&.+?</object>#s', $markup, $matches);
     209                   
     210                    // Find Vimeo embedded with iframe code
     211                    if(!isset($matches[1])) {
     212                        preg_match('#http://player.vimeo.com/video/([0-9]+)#s', $markup, $matches);
     213                    }
     214                   
     215                    // If we still haven't found anything, check for Vimeo embedded with JR_embed
     216                    if(!isset($matches[1])) {
     217                        preg_match('#\[vimeo id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
     218                    }
     219           
     220                    // If we still haven't found anything, check for Vimeo URL
     221                    if(!isset($matches[1])) {
     222                        preg_match('#http://w?w?w?.?vimeo.com/([A-Za-z0-9\-_]+)#s', $markup, $matches);
     223                    }
     224                   
     225                    // If we still haven't found anything, check for Vimeo URL
     226                    if(!isset($matches[1])) {
     227                        preg_match('#http://?vimeo.com/([A-Za-z0-9\-_]+)#s', $markup, $matches);
     228                    }
     229           
     230                    // If we still haven't found anything, check for Vimeo shortcode
     231                    if(!isset($matches[1])) {
     232                        preg_match('#\[vimeo clip_id="([A-Za-z0-9\-_]+)"[^>]*]#s', $markup, $matches);
     233                    }
     234                    if(!isset($matches[1])) {
     235                        preg_match('#\[vimeo video_id="([A-Za-z0-9\-_]+)"[^>]*]#s', $markup, $matches);
     236                    }
     237               
     238                    // Now if we've found a Vimeo ID, let's set the thumbnail URL
     239                    if(isset($matches[1])) {
     240                        $vimeo_thumbnail = getVimeoInfo($matches[1], $info = 'thumbnail_small');
     241                        if(isset($vimeo_thumbnail)) {
     242                            $new_thumbnail = $vimeo_thumbnail;
     243                        }
     244                    }
     245                }
     246               
     247                    $rwcnt = $rwcnt + 1;           
    158248                    if($new_thumbnail!=null):
    159249                    //echo "teste8";
     
    167257                        }
    168258                    endif;
    169                 endforeach;
     259                endwhile;
    170260            $tbhtml .= "</table>";
    171261            echo $tbhtml;
    172         endif;     
     262        //endif;       
    173263    endif;
    174264}
     
    208298      'tbsz' => '',
    209299      'cpad' => '',
    210       'cpin ' => ''
     300      'cpin' => ''
    211301      );
    212302  }
     
    261351function youtubenails_init()
    262352{
    263   register_sidebar_widget(__('YouTubeNails'), 'widget_youtubenails_show'); 
    264   register_widget_control(   'YouTubeNails', 'youtubenails_control', 400, 400 );
    265 }
    266 add_action("plugins_loaded", "youtubenails_init");
     353  //register_sidebar_widget(__('YouTubeNails'), 'widget_youtubenails_show'); 
     354  //register_widget_control(   'YouTubeNails', 'youtubenails_control', 400, 400 );
     355}
     356//add_action("plugins_loaded", "youtubenails_init");
     357add_action('widgets_init', 'ytbn_register_widgets');
     358function ytbn_register_widgets(){
     359    // curl need to be installed
     360    register_widget('YTBN_Widget');
     361}
     362//
     363class YTBN_Widget extends WP_Widget {
     364    function YTBN_Widget() {
     365        /* Widget settings. */
     366        $widget_ops = array( 'classname' => 'ytbn', 'description' => 'This is the YouTubeNails Plugin Widget.' );
     367        /* Widget control settings. */
     368        $control_ops = array( 'width' => 700, 'height' => 300, 'id_base' => 'ytbn-widget' );
     369        /* Create the widget. */
     370        $this->WP_Widget( 'ytbn-widget', 'YTBN Widget', $widget_ops, $control_ops );
     371    }
     372    function widget( $args, $instance ) {
     373        extract( $args );
     374        //$instance = get_option("widget_getPostListThumbs");
     375        if (!is_array( $options ))
     376        {
     377        $options = array(
     378            'nop' => '',
     379            'ln' => '',
     380            'catg' => '',
     381            'tbsz' => '',
     382            'cpad' => '',
     383            'cpin ' => ''
     384             );
     385        }
     386     /*echo $before_widget;
     387        echo $before_title;
     388              echo $options['title'];
     389            echo $after_title; 
     390          echo $after_widget;*/
     391          //Our Widget Content
     392            youtubenails_show($instance['nop'],$instance['ln'],$instance['catg'],$instance['tbsz'],$instance['cpad'],$instance['cpin']);
     393    }
     394    function update( $new_instance, $old_instance ) {
     395        $instance = $old_instance;
     396        /* Strip tags (if needed) and update the widget settings. */
     397        $instance['nop'] = $new_instance['nop'];
     398        $instance['ln'] = $new_instance['ln'];
     399        $instance['catg'] = $new_instance['catg'];
     400        $instance['tbsz'] = $new_instance['tbsz'];
     401        $instance['cpad'] = $new_instance['cpad'];
     402        $instance['cpin'] = $new_instance['cpin'];
     403        return $instance;
     404    }
     405    function form( $instance ) {
     406        /* Set up some default widget settings. */
     407        $defaults = array(
     408       
     409        'ptype' => 'post',
     410        'nop' => '8',
     411        'ln' => 3,
     412        'catg' => '',
     413        'tbsz' => 2,
     414        'cpad' => 3,
     415        'cpin' =>3,
     416        'ech' => false
     417        );
     418        $instance = wp_parse_args( (array) $instance, $defaults );
    267419?>
     420        <p>   
     421            <label for="<?php echo $this->get_field_id( 'nop' ); ?>">Number of Posts(default is 8): </label><br />
     422            <input type="text" id="<?php echo $this->get_field_id( 'nop' ); ?>" name="<?php echo $this->get_field_name( 'nop' ); ?>" value="<?php echo $instance['nop'];?>" size="4"/>
     423            <br />
     424            <label for="<?php echo $this->get_field_id( 'ln' ); ?>">Number of columns on each row(default is 3): </label><br />
     425            <input type="text" id="<?php echo $this->get_field_id( 'ln' ); ?>" name="<?php echo $this->get_field_name( 'ln' ); ?>" value="<?php echo $instance['ln'];?>" size="4"/>
     426            <br />
     427            <label for="<?php echo $this->get_field_id( 'catg' ); ?>">A specific category of posts(default is all, leave it blank): </label><br />
     428            <input type="text" id="<?php echo $this->get_field_id( 'catg' ); ?>" name="<?php echo $this->get_field_name( 'catg' ); ?>" value="<?php echo $instance['catg'];?>" size="20"/>
     429            <br /> 
     430            <label for="<?php echo $this->get_field_id( 'tbsz' ); ?>">The thumbnail type based on YouTube API(default is 2, see the list below): </label><br />
     431            <input type="text" id="<?php echo $this->get_field_id( 'tbsz' ); ?>" name="<?php echo $this->get_field_name( 'tbsz' ); ?>" value="<?php echo $instance['tbsz'];?>" size="4"/>
     432            <br /><label style="font-size:9px">YouTube API sizes and types:<br /> 0 = big 480 x 360<br />
     433                    1 = small 120 x 90 different from 2 & 3<br />
     434                    2 = small 120 x 90 different from 1 & 3<br />
     435                    3 = small 120 x 90 different from 2 & 1</label><br />
     436            <br /> 
     437             <label for="<?php echo $this->get_field_id( 'cpad' ); ?>">The result table cellpadding(default is 3): </label><br />
     438            <input type="text" id="<?php echo $this->get_field_id( 'cpad' ); ?>" name="<?php echo $this->get_field_name( 'cpad' ); ?>" value="<?php echo $instance['cpad'];?>" size="4"/>
     439            <br />
     440            <label for="<?php echo $this->get_field_id( 'cpin' ); ?>">The result table cellspacing(default is 3): </label><br />
     441            <input type="text" id="<?php echo $this->get_field_id( 'cpin' ); ?>" name="<?php echo $this->get_field_name( 'cpin' ); ?>" value="<?php echo $instance['cpin'];?>" size="4"/>
     442            <br />
     443            <label>The result list will be a table, that uses the css class 'wp_ytbnstb', so you can play with the table properties, and the inside elements.</label><br />
     444            <input type="hidden" id="youtubenails-Submit" name="youtubenails-Submit" value="1" />
     445          </p> 
     446        <?php
     447    }
     448}
     449?>
  • youtubenails/trunk/readme.txt

    r355277 r485261  
    44Tags: youtube,thumbnails,video
    55Requires at least: 3.0.3
    6 Tested up to: 3.0.3
    7 Stable tag: 2.0.0
     6Tested up to: 3.2.1
     7Stable tag: 3.0.0
    88
    99== Description ==
    1010
    11 Create a dynamic gallery widget(works as shortcode too, if desired), with thumbnails of each post with youtube videos displayed on the content linked to the post permalink. It checks all you video posts, but you can filter them by category and choose the number of posts.
     11Create a dynamic gallery multiple widget(works as shortcode too), with thumbnails of each post with youtube/vimeo(beta) videos displayed on the content linked to the post single. Checks all you video posts, but you can filter them by category and choose the number of posts.
    1212
    1313Based on
     
    51517. The table id for the result table wp_ytbnstb;
    5252
    53 To work as short code
     53To work as short code, call
     54[ytbn nop="2" ln="1" catg="" tbsz="1" cpad="3" cpin="3"]
    5455
    55 call it on php  youtubenails_show(8,1,'',2,3,3);
     56or call it on php as function  youtubenails_show(8,1,'',2,3,3);
    5657
    5758where the parameters are
     
    7677
    7778== Changelog ==
     793.0.0
     80Supports multiple widgets and shortcodes;
     81Vimeo supported(beta feature);
     82
    78832.0.0
    7984
     
    9095
    9196<!--
     97http://www.youtube.com/watch?v=gNwuES4lMeQ
     98
    9299<iframe title="YouTube video player" class="youtube-player" type="text/html" width="480" height="390" src="http://www.youtube.com/embed/yXYW4c-FndI" frameborder="0" allowFullScreen></iframe>
    93100
  • youtubenails/trunk/youtubenails.php

    r354590 r485261  
    44Plugin URI: http://youtubenails.sourceforge.net/
    55Description:Create a dynamic gallery of thumbnails of each post with youtube videos displayed on the content linked to the post permalink
    6 Version: 2.0.0
     6Version: 3.0.0
    77Author: Alvaro Neto
    88Author URI: http://wpworks.wordpress.com/
     
    2626    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2727*/
     28//
     29add_shortcode('ytbn','ytbn_short');
     30//
     31function ytbn_short($atts, $content = null){
     32   extract(shortcode_atts(array(
     33        'ptype' => 'post',
     34        'nop' => '8',
     35        'ln' => 3,
     36        'catg' => '',
     37        'tbsz' => 2,
     38        'cpad' => 3,
     39        'cpin' =>3,
     40        'ech' => false     
     41    ), $atts));
     42    ob_start();         
     43    $ytbnres=youtubenails_show($nop,$ln,$catg,$tbsz,$cpad,$cpin,$ech);
     44    echo $ytbnres;
     45    $ytbn_string = ob_get_contents();
     46    ob_end_clean();
     47    return $ytbn_string;
     48}
     49//
     50/**
     51 * Add FAQ and support information
     52 */
     53add_filter('plugin_row_meta', 'wp_ytbn_plugin_links', 10, 2);
     54function wp_ytbn_plugin_links ($links, $file)
     55{
     56    if ($file == plugin_basename(__FILE__)) {
     57        $links[] = '<a href="http://www.wpworking.com/">' . __('Donate', 'wp_ytbn') . '</a>';
     58    }
     59    return $links;
     60}
     61//
    2862function partrat($par,$def)
    2963{
     
    3670    return $par;
    3771}
     72function getVimeoInfo($id, $info = 'thumbnail_medium') {
     73    if (!function_exists('curl_init')) die('CURL is not installed, impossible to display vimeo, sorry!');
     74    $ch = curl_init();
     75    curl_setopt($ch, CURLOPT_URL, "vimeo.com/api/v2/video/$id.php");
     76    curl_setopt($ch, CURLOPT_HEADER, 0);
     77    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     78    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     79    $output = unserialize(curl_exec($ch));
     80    $output = $output[0][$info];
     81    curl_close($ch);
     82    return $output;
     83}
    3884 
    39 function youtubenails_show($nop=8,$ln=3,$catg='',$tbsz=2,$cpad=3,$cpin=3)
     85function youtubenails_show($nop=8,$ln=3,$catg='',$tbsz=2,$cpad=3,$cpin=3,$ech=true)
    4086{
    4187    $nop = partrat($nop,8);
     
    4591    $cpad = partrat($cpad,3);
    4692    $cpin = partrat($cpin,3);
     93    $ech = partrat($ech,true);
    4794   
    4895    //echo "cpad:".$cpad."<br>";
     
    60107    }
    61108   
    62     if (have_posts()) :
     109    //if (have_posts()) :
    63110     // Gets the post's content
    64111     global $post;
     
    67114            $myposts = get_posts("numberposts=".$nop."&category_name='".$catg."'");
    68115            //get_posts('category_name='.$catg);
     116            query_posts("numberposts=".$nop."&category_name='".$catg."'");
    69117        else:
    70118            $myposts = get_posts("numberposts=".$nop);
     119            query_posts("numberposts=".$nop);
    71120            //get_posts();
    72121        endif;
     
    76125        if($lmtcnt>0):
    77126             $tbhtml = "<table cellpadding='".$cpad."' cellspacing='".$cpin."' border='0' id='wp_ytbnstb'>";
    78              foreach($myposts as $post) :
    79                 $post_id = $post->ID;
     127             while (have_posts()) : the_post();
     128                $post_id = get_the_ID();
    80129                $post_array = get_post($post_id);
    81130                //$markup = get_the_content();
     
    102151                // Checks for a standard YouTube embed
    103152                preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
    104                
    105                
    106153               
    107154                // Checks for YouTube iframe
     
    140187                        //echo "teste6";
    141188                        $new_thumbnail = $youtube_thumbnail;
    142                     } else {
     189                    }
     190                    else {
    143191                        //echo "teste7";
    144192                        $ch = curl_init($youtube_thumbnail);
     
    154202                    }
    155203                }
    156                 //echo $new_thumbnail;
    157                 $rwcnt = $rwcnt + 1;           
     204                // Vimeo
     205                if($new_thumbnail==null) {
     206               
     207                    // Standard embed code
     208                    preg_match('#<object[^>]+>.+?http://vimeo.com/moogaloop.swf\?clip_id=([A-Za-z0-9\-_]+)&.+?</object>#s', $markup, $matches);
     209                   
     210                    // Find Vimeo embedded with iframe code
     211                    if(!isset($matches[1])) {
     212                        preg_match('#http://player.vimeo.com/video/([0-9]+)#s', $markup, $matches);
     213                    }
     214                   
     215                    // If we still haven't found anything, check for Vimeo embedded with JR_embed
     216                    if(!isset($matches[1])) {
     217                        preg_match('#\[vimeo id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
     218                    }
     219           
     220                    // If we still haven't found anything, check for Vimeo URL
     221                    if(!isset($matches[1])) {
     222                        preg_match('#http://w?w?w?.?vimeo.com/([A-Za-z0-9\-_]+)#s', $markup, $matches);
     223                    }
     224                   
     225                    // If we still haven't found anything, check for Vimeo URL
     226                    if(!isset($matches[1])) {
     227                        preg_match('#http://?vimeo.com/([A-Za-z0-9\-_]+)#s', $markup, $matches);
     228                    }
     229           
     230                    // If we still haven't found anything, check for Vimeo shortcode
     231                    if(!isset($matches[1])) {
     232                        preg_match('#\[vimeo clip_id="([A-Za-z0-9\-_]+)"[^>]*]#s', $markup, $matches);
     233                    }
     234                    if(!isset($matches[1])) {
     235                        preg_match('#\[vimeo video_id="([A-Za-z0-9\-_]+)"[^>]*]#s', $markup, $matches);
     236                    }
     237               
     238                    // Now if we've found a Vimeo ID, let's set the thumbnail URL
     239                    if(isset($matches[1])) {
     240                        $vimeo_thumbnail = getVimeoInfo($matches[1], $info = 'thumbnail_small');
     241                        if(isset($vimeo_thumbnail)) {
     242                            $new_thumbnail = $vimeo_thumbnail;
     243                        }
     244                    }
     245                }
     246               
     247                    $rwcnt = $rwcnt + 1;           
    158248                    if($new_thumbnail!=null):
    159249                    //echo "teste8";
     
    167257                        }
    168258                    endif;
    169                 endforeach;
     259                endwhile;
    170260            $tbhtml .= "</table>";
    171261            echo $tbhtml;
    172         endif;     
     262        //endif;       
    173263    endif;
    174264}
     
    208298      'tbsz' => '',
    209299      'cpad' => '',
    210       'cpin ' => ''
     300      'cpin' => ''
    211301      );
    212302  }
     
    261351function youtubenails_init()
    262352{
    263   register_sidebar_widget(__('YouTubeNails'), 'widget_youtubenails_show'); 
    264   register_widget_control(   'YouTubeNails', 'youtubenails_control', 400, 400 );
    265 }
    266 add_action("plugins_loaded", "youtubenails_init");
     353  //register_sidebar_widget(__('YouTubeNails'), 'widget_youtubenails_show'); 
     354  //register_widget_control(   'YouTubeNails', 'youtubenails_control', 400, 400 );
     355}
     356//add_action("plugins_loaded", "youtubenails_init");
     357add_action('widgets_init', 'ytbn_register_widgets');
     358function ytbn_register_widgets(){
     359    // curl need to be installed
     360    register_widget('YTBN_Widget');
     361}
     362//
     363class YTBN_Widget extends WP_Widget {
     364    function YTBN_Widget() {
     365        /* Widget settings. */
     366        $widget_ops = array( 'classname' => 'ytbn', 'description' => 'This is the YouTubeNails Plugin Widget.' );
     367        /* Widget control settings. */
     368        $control_ops = array( 'width' => 700, 'height' => 300, 'id_base' => 'ytbn-widget' );
     369        /* Create the widget. */
     370        $this->WP_Widget( 'ytbn-widget', 'YTBN Widget', $widget_ops, $control_ops );
     371    }
     372    function widget( $args, $instance ) {
     373        extract( $args );
     374        //$instance = get_option("widget_getPostListThumbs");
     375        if (!is_array( $options ))
     376        {
     377        $options = array(
     378            'nop' => '',
     379            'ln' => '',
     380            'catg' => '',
     381            'tbsz' => '',
     382            'cpad' => '',
     383            'cpin ' => ''
     384             );
     385        }
     386     /*echo $before_widget;
     387        echo $before_title;
     388              echo $options['title'];
     389            echo $after_title; 
     390          echo $after_widget;*/
     391          //Our Widget Content
     392            youtubenails_show($instance['nop'],$instance['ln'],$instance['catg'],$instance['tbsz'],$instance['cpad'],$instance['cpin']);
     393    }
     394    function update( $new_instance, $old_instance ) {
     395        $instance = $old_instance;
     396        /* Strip tags (if needed) and update the widget settings. */
     397        $instance['nop'] = $new_instance['nop'];
     398        $instance['ln'] = $new_instance['ln'];
     399        $instance['catg'] = $new_instance['catg'];
     400        $instance['tbsz'] = $new_instance['tbsz'];
     401        $instance['cpad'] = $new_instance['cpad'];
     402        $instance['cpin'] = $new_instance['cpin'];
     403        return $instance;
     404    }
     405    function form( $instance ) {
     406        /* Set up some default widget settings. */
     407        $defaults = array(
     408       
     409        'ptype' => 'post',
     410        'nop' => '8',
     411        'ln' => 3,
     412        'catg' => '',
     413        'tbsz' => 2,
     414        'cpad' => 3,
     415        'cpin' =>3,
     416        'ech' => false
     417        );
     418        $instance = wp_parse_args( (array) $instance, $defaults );
    267419?>
     420        <p>   
     421            <label for="<?php echo $this->get_field_id( 'nop' ); ?>">Number of Posts(default is 8): </label><br />
     422            <input type="text" id="<?php echo $this->get_field_id( 'nop' ); ?>" name="<?php echo $this->get_field_name( 'nop' ); ?>" value="<?php echo $instance['nop'];?>" size="4"/>
     423            <br />
     424            <label for="<?php echo $this->get_field_id( 'ln' ); ?>">Number of columns on each row(default is 3): </label><br />
     425            <input type="text" id="<?php echo $this->get_field_id( 'ln' ); ?>" name="<?php echo $this->get_field_name( 'ln' ); ?>" value="<?php echo $instance['ln'];?>" size="4"/>
     426            <br />
     427            <label for="<?php echo $this->get_field_id( 'catg' ); ?>">A specific category of posts(default is all, leave it blank): </label><br />
     428            <input type="text" id="<?php echo $this->get_field_id( 'catg' ); ?>" name="<?php echo $this->get_field_name( 'catg' ); ?>" value="<?php echo $instance['catg'];?>" size="20"/>
     429            <br /> 
     430            <label for="<?php echo $this->get_field_id( 'tbsz' ); ?>">The thumbnail type based on YouTube API(default is 2, see the list below): </label><br />
     431            <input type="text" id="<?php echo $this->get_field_id( 'tbsz' ); ?>" name="<?php echo $this->get_field_name( 'tbsz' ); ?>" value="<?php echo $instance['tbsz'];?>" size="4"/>
     432            <br /><label style="font-size:9px">YouTube API sizes and types:<br /> 0 = big 480 x 360<br />
     433                    1 = small 120 x 90 different from 2 & 3<br />
     434                    2 = small 120 x 90 different from 1 & 3<br />
     435                    3 = small 120 x 90 different from 2 & 1</label><br />
     436            <br /> 
     437             <label for="<?php echo $this->get_field_id( 'cpad' ); ?>">The result table cellpadding(default is 3): </label><br />
     438            <input type="text" id="<?php echo $this->get_field_id( 'cpad' ); ?>" name="<?php echo $this->get_field_name( 'cpad' ); ?>" value="<?php echo $instance['cpad'];?>" size="4"/>
     439            <br />
     440            <label for="<?php echo $this->get_field_id( 'cpin' ); ?>">The result table cellspacing(default is 3): </label><br />
     441            <input type="text" id="<?php echo $this->get_field_id( 'cpin' ); ?>" name="<?php echo $this->get_field_name( 'cpin' ); ?>" value="<?php echo $instance['cpin'];?>" size="4"/>
     442            <br />
     443            <label>The result list will be a table, that uses the css class 'wp_ytbnstb', so you can play with the table properties, and the inside elements.</label><br />
     444            <input type="hidden" id="youtubenails-Submit" name="youtubenails-Submit" value="1" />
     445          </p> 
     446        <?php
     447    }
     448}
     449?>
Note: See TracChangeset for help on using the changeset viewer.