Updated WordTube code

Just discovered that updating a plug-in deletes any spare files in its directory.

As a result, my hack to the Wordtube plugin disappeared.

This messed up my solution to the Wordtube streaming playlist problem.

To avoid having to re-upload my re-edited version of the myextractXML.php file every time the plug-in is uploaded, here it is again:

<?php
/*
+----------------------------------------------------------------+
+   wordtube-XSPF XML output for playlist
+   by Alex Rabe reviewed by Alakhnor
+   required for wordTube
+----------------------------------------------------------------+
*/


// look up for the path
if ( !defined('ABSPATH') )
    require_once( dirname(__FILE__) . '/wordtube-config.php');

global $wpdb;

// get the path url from querystring
$playlist_id = $_GET['id'];

$title = 'WordTube Playlist';

$themediafiles = array();
$limit = '';

if (substr($playlist_id,0,4) == 'last') {
    $l= (int) substr($playlist_id,4);
    if ($l <= 0) $l = 10;
    $limit = ' LIMIT 0,'.$l;
    $playlist_id = '0';
}
// Otherwise gets most viewed
if ($playlist_id == 'most') {
    $themediafiles = $wpdb->get_results("SELECT * FROM $wpdb->wordtube WHERE counter >0 ORDER BY counter DESC LIMIT 10");
// Otherwise gets mp3
} elseif ($playlist_id == 'music') {
    $themediafiles = $wpdb->get_results("SELECT * FROM $wpdb->wordtube WHERE file LIKE '%.mp3%' ORDER BY vid DESC");
// Otherwise gets flv
} elseif ($playlist_id == 'video') {
    $themediafiles = $wpdb->get_results("SELECT * FROM $wpdb->wordtube WHERE file LIKE '%.flv%' ORDER BY vid DESC");
// Shows all files when 0
} elseif ($playlist_id == '0') {
    // Updated to work with version 3.6 of the database
    $themediafiles = $wpdb->get_results( "SELECT * FROM $wpdb->wordtube ORDER BY vid DESC ".$limit );
// Otherwise gets playlist
} else {
    // Remove all evil code
    $playlist_id = intval($_GET['id']);
    $playlist = $wpdb->get_row("SELECT * FROM $wpdb->wordtube_playlist WHERE pid = '$playlist_id'");
    if ($playlist) {
        $select  = " SELECT * FROM {$wpdb->wordtube} w";
        $select .= " INNER JOIN {$wpdb->wordtube_med2play} m";
    // Updated to work with version 3.6 of the database
        $select .= " WHERE (m.playlist_id = %d" ;
        $select .= " AND m.media_id = w.vid) GROUP BY w.vid ";
        $select .= " ORDER BY m.porder {$playlist->playlist_order} ,w.vid {$playlist->playlist_order}";
    // Updated to work with version 3.6 of the database
        $themediafiles = $wpdb->get_results( $wpdb->prepare( $select , $playlist_id ) );
    // End update
        $title = $playlist->playlist_name;
    }
}

// Create XML / XSPF output
header("content-type:text/xml;charset=utf-8");
   
echo "\n"."<playlist version='1' xmlns='http://xspf.org/ns/0/'>";
echo "\n\t".'<title>' . esc_attr($title) . '</title>';
echo "\n\t".'<tracklist>';
   
if (is_array ($themediafiles)){

    foreach ($themediafiles as $media) {
       
                $creator = esc_attr(stripslashes($media->creator));
                if ($creator == '')
                    $creator = 'Unknown';
                if ($media->image == '')
                    $image = get_option('siteurl') . '/wp-content/plugins/' . dirname( plugin_basename(__FILE__) ) . '/images/wordtube.jpg';
                else
                    $image = $media->image;
                $file = pathinfo($media->file);
// Added by MT starts
                $mediafile = $media->file;
                if (substr($mediafile, 0, 4) == 'rtmp') {
                    preg_match('/^(.+)\?id=(.+)/', $mediafile, $match);
                    if (!empty ($match)) {     
                        $streamer = $match[1];
                        $mediafile = $match[2];
                    }
                }
// ends
        echo "\n\t\t".'<track>';
        echo "\n\t\t\t".'<title>' . esc_attr( stripslashes($media->name) ) . '</title>';
        echo "\n\t\t\t".'<creator>' . esc_attr($creator) . '</creator>';
        echo "\n\t\t\t".'<location>' . esc_attr($mediafile) . '</location>'; //modified by MT
// Added by MT
        if(!empty($streamer)):
            echo "\n\t\t\t".'<meta rel="streamer"/>' . esc_attr($streamer) . '';
        endif;
// ends
        echo "\n\t\t\t".'<image>' . esc_attr($image) . '</image>';
        echo "\n\t\t\t".'<annotation>' . esc_attr( stripslashes($media->description) ) .  '</annotation>';
        echo "\n\t\t\t".'<id>' . $media->vid . '</id>';
        echo "\n\t\t\t".'<counter>' . $media->counter . '</counter>';
        echo "\n\t\t\t".'<info>' . esc_attr($media->link) . '</info>';
        echo "\n\t\t".'</track>';
    }
} else {
    print_r($themediafiles);
}
     
echo "\n\t".'</tracklist>';
echo "\n"."</playlist>\n"; 

?>

Updated again!

This code was further updated on October 16, 2013 to reflect this change to the WordPress API.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
This entry was posted in Wordpress. Bookmark the permalink.

6 Responses to Updated WordTube code

  1. LUCHOSAR says:

    Greetings from Colombia.
    I’ve done what you mention but I get the list of thumbnails in the sidebar, some solution. Thanks.
    Please write to me you mundocrea1@hotmail.com
    (google translator)

  2. andres says:

    it has got to be a weird coincidence that im from colombia too and i also have the same darn problem with the playlists, gonna try ur fix

  3. Emma says:

    Thanks for the code – exactly what I needed.

    Emma

  4. skarld says:

    Thanks for updated WordTube update. Works on WordPress 3.7.1

  5. beachbum says:

    Thank you so much for this fix. I never noticed the playlist stop working but the php errors were bugging me all this time and I just let it go until today I finally had some time to research it.

    Cheerz to you sir.

Get in Touch

Your email address will not be published. Required fields are marked *