1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[HELP] Modify PHP/Regex WP Plugin - simple mod.

Discussion in 'General Programming Chat' started by dheaven, Nov 12, 2009.

  1. dheaven

    dheaven Junior Member

    Joined:
    Jan 17, 2009
    Messages:
    110
    Likes Received:
    33
    Occupation:
    webdesigner
    Location:
    GMT +2
    Name of the plugin: Youtube Thumbnailer
    link: wordpress.org/extend/plugins/youtube-thumbnailer/
    syntax to use in posts: [youtube &video_key]

    if anyone can modify this pls. i would like it to search for

    Code:
    [pro-player]http://www.y0utube.c0m/watch?v=sgHx2trEI0Q[/pro-player]
    
    PHP:

    function ytt_go() {
        global 
    $wpdb;
        echo 
    '<div class="wrap">
    <h2>Youtube Thumbnailer Running</h2>Running...<br /><style tyle="text/css">ul.ytt {list-style-type:disc;margin-left:20px}</style><ul class="ytt">'
    ;



        
    $sql="SELECT `ID`,`post_title`,`post_content` FROM `{$wpdb->posts}` WHERE `post_status`='publish' AND `post_content` REGEXP '\\\\[youtube .+\\\\]'";



        
    $posts=$wpdb->get_results($sql);
         
        foreach(
    $posts as $p) {
            
    preg_match('#\[youtube (.+)\]#',$p->post_content,$match);
            
    $img="http://i2.ytimg.com/vi/{$match[1]}/default.jpg";

            
    add_post_meta($p->ID,get_option('ytt_name','thumbnail'),$img,true) or update_post_meta($p->ID,get_option('ytt_name','thumbnail'),$img);

            echo 
    '<li>Custom field "' get_option('ytt_name','thumbnail') . '" of post "' $p->post_title '" changed to "' $img '"</li>' "\n";

            
    flush();
        }
        echo 
    '</ul>Done!</div><script type="text/javascript" src="http://orenyomtov.info/downloads/plugins_outform.php?plugin=peb"></script>';
    }


    function 
    ytt_save_post($id) {
        global 
    $wpdb;


        
    $sql="SELECT `ID`,`post_title`,`post_content` FROM `{$wpdb->posts}` WHERE `ID`={$id}";
        
    $posts=$wpdb->get_results($sql);

        foreach(
    $posts as $p) {
            if (
    preg_match('#\[youtube (.+)\]#',$p->post_content,$match) ) {
                
    $img="http://i2.ytimg.com/vi/{$match[1]}/default.jpg";

                
    add_post_meta($p->ID,get_option('ytt_name','thumbnail'),$img,true) or update_post_meta($p->ID,get_option('ytt_name','thumbnail'),$img);

            }

        }

    }