Apple Movie Trailer Wordpress Widget

I found another great widget, which displays a random Apple Movie trailer, complete with movie poster.

Sadly, I ran into exactly the same problem that I did with the APOD widget - use of url file access functions is strictly verboten on my web host. So, here is the modded version of the widget to use cURL:



<?php
/*
Plugin Name: Apple Trailer Sidebar Widget
Description: Adds a sidebar widget that shows the latest movie trailers from apple.com
Author: Patrick Queisler
Version: 1.1
Author URI: <a href="http://www.sosuechtig.de</p>
<p>Version" title="http://www.sosuechtig.de</p>
<p>Version">http://www.sosuechtig.de</p>
<p>Version</p></a> 1.1 - Erich Beyrent [http://www.beyrent.net]: added cURL functions to fetch the data from Apple
*/

function widget_appletrailer_init() {

    if ( !
function_exists('register_sidebar_widget') )
        return;
        
    function 
widget_appletrailer($args) {
        
        
extract($args);
        
$options get_option('widget_appletrailer');
        
$title $options['title'];
        
        echo 
$before_widget $before_title $title $after_title;
        function 
appledotcom_parser(){
            
$myfile '';
            
$lines = <a href="http://twitter.com/file">@file</a>("http://wdirect.apple.com/trailers/home/externalA.js");
            if(
$lines)
            {
                foreach (
$lines as $line_num=> $line
                {
                    
$myfile .= stripslashes($line);
                }
            }
            else
            {
                
$ch curl_init();
                
curl_setopt($chCURLOPT_URL"http://wdirect.apple.com/trailers/home/externalA.js");
                
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
                
$myfile curl_exec($ch);
                
curl_close ($ch);
            }    
            
            
$out eregi_replace("href=\"/trailers/","target=\"_blank\" href=\"http://www.apple.com/trailers/",$myfile);
            return 
$out;
        }
        function 
get_trailer(){
            echo 
"<center><script language=\"JavaScript\" type=\"text/javascript\">";
            echo 
appledotcom_parser();
            echo 
"loadRandomD();
            </script></center>"
;
        }
        
get_trailer();
        echo 
$after_widget;
    }


    function 
widget_appletrailer_control() {

        
$options get_option('widget_appletrailer');
        if ( !
is_array($options) )
            
$options = array('title'=>'');
        if ( 
$_POST['appletrailer-submit'] ) {

            
$options['title'] = strip_tags(stripslashes($_POST['appletrailer-title']));
            
update_option('widget_appletrailer'$options);
        }

        
$title htmlspecialchars($options['title'], ENT_QUOTES);
        
        echo 
'<p style="text-align:right;"><label for="appletrailer-title">Title: <input style="width: 200px;" id="appletrailer-title" name="appletrailer-title" type="text" value="'.$title.'" /></label></p>';
        echo 
'<input type="hidden" id="appletrailer-submit" name="appletrailer-submit" value="1" />';
    }
    
    
register_sidebar_widget('Apple Trailer''widget_appletrailer');
    
register_widget_control('Apple Trailer''widget_appletrailer_control'300100);
}

add_action('plugins_loaded''widget_appletrailer_init');

?>

Apple, beyrent, curl, movie, php, plugin, security, trailers, widget, wordpress, Apple, curl, movie, php, plugin, security, trailers, widget, wordpress

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

About Erich

Erich is a web developer and a native New Englander who is passionate about life, the universe, and everything.

He is a Drupal consultant, previously employed as a senior developer at Harvard University, working on the IQSS OpenScholar project.  Prior to joining the team at Harvard, he was the engineering manager at CommonPlaces e-Solutions, in Hampstead, NH, contributing as the lead engineer on the Greenopolis.com and Twolia.com.

Erich is active in the Drupal community, having contributed modules and patches to the community. He presented at DrupalCon in Szeged Hungary, and co-presented at DrupalCon 2009 in Washington, DC.

Erich lives in New Hampshire with his wife, two sons, and three weimaraners.  When not writing code, Erich enjoys landscaping and woodworking.

Faceted search

Categories

Content type

Project types

Artwork Type

Artwork Tags

Recent comments

Activity Stream

August 29, 2011

August 25, 2011

August 24, 2011

August 23, 2011

August 15, 2011

August 11, 2011

August 10, 2011

August 9, 2011

August 4, 2011

August 3, 2011