Changeset 871

Show
Ignore:
Timestamp:
09/01/08 01:40:10 (3 months ago)
Author:
rickc
Message:

Plugins: podcast. More work on the publish form and getting information into and out of it. Also added a stylesheet so the controls added to the publish page are more usable.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/podcast/trunk/podcast.plugin.php

    r866 r871  
    1010class Podcast extends Plugin 
    1111{ 
    12 /*  private $itunesCategory = array( 
    13         'Arts' => array( 'Design', 'Fashion & Beauty', 'Food', 'Literature', 'Performing Arts', 'Visual Arts' ), 
    14         'Business' => array( 'Business News', 'Careers', 'Investing', 'Management & Marketing', 'Shopping' ), 
    15         'Comedy', 
    16         'Education' => array( 'Education Technology', 'Higher Education', 'K-12', 'Language Courses', 'Training' ), 
    17         'Games & Hobbies' => array( 'Automotive', 'Aviation', 'Hobbies', 'Other Games', 'Video Games' ), 
    18         'Government & Organizations' => array( 'Local', 'National', 'Non-Profit', 'Regional' ), 
    19         'Health' => array( 'Alternative Health', 'Fitness & Nutrition', 'Self-Help', 'Sexuality' ), 
    20         'Kids & Family', 
    21         'Music', 
    22         'News & Politics', 
    23         'Religion & Spirituality' => array( 'Buddhism', 'Christianity', 'Hinduism', 'Islam', 'Judaism', 'Other', 'Spirituality' ), 
    24         'Science & Medicine' => array( 'Medicine', 'Natural Sciences', 'Social Sciences' ), 
    25         'Society & Culture' => array( 'History', 'Personal Journals', 'Philosophy', 'Places & Travel' ), 
    26         'Sports & Recreation' => array( 'Amateur', 'College & High School', 'Outdoor', 'Professional' ), 
    27         'Technology' => array( 'Gadgets', 'Tech News', 'Podcasting', 'Software How-To' ), 
    28         'TV & Film', 
     12    const PODCAST_ITUNES = 0; 
     13 
     14/* 
     15    private $itunes_categories = array( 
     16        '0 => '', 
     17        1 => 'Arts' => array( 'Design', 'Fashion & Beauty', 'Food', 'Literature', 'Performing Arts', 'Visual Arts' ), 
     18        2 => 'Business' => array( 'Business News', 'Careers', 'Investing', 'Management & Marketing', 'Shopping' ), 
     19        3 => 'Comedy', 
     20        4 => 'Education' => array( 'Education Technology', 'Higher Education', 'K-12', 'Language Courses', 'Training' ), 
     21        5 => 'Games & Hobbies' => array( 'Automotive', 'Aviation', 'Hobbies', 'Other Games', 'Video Games' ), 
     22        6 => 'Government & Organizations' => array( 'Local', 'National', 'Non-Profit', 'Regional' ), 
     23        7 => 'Health' => array( 'Alternative Health', 'Fitness & Nutrition', 'Self-Help', 'Sexuality' ), 
     24        8 => 'Kids & Family', 
     25        9 => 'Music', 
     26        10 => 'News & Politics', 
     27        11 => 'Religion & Spirituality' => array( 'Buddhism', 'Christianity', 'Hinduism', 'Islam', 'Judaism', 'Other', 'Spirituality' ), 
     28        12 => 'Science & Medicine' => array( 'Medicine', 'Natural Sciences', 'Social Sciences' ), 
     29        13 => 'Society & Culture' => array( 'History', 'Personal Journals', 'Philosophy', 'Places & Travel' ), 
     30        14 => 'Sports & Recreation' => array( 'Amateur', 'College & High School', 'Outdoor', 'Professional' ), 
     31        15 => 'Technology' => array( 'Gadgets', 'Tech News', 'Podcasting', 'Software How-To' ), 
     32        16 => 'TV & Film', 
    2933    ); 
    3034*/ 
     35    private $itunes_categories = array( 
     36        0 => '', 
     37        1 => 'Arts', 
     38        2 => 'Business', 
     39        3 => 'Comedy', 
     40        4 => 'Education', 
     41        5 => 'Games & Hobbies', 
     42        6 => 'Government & Organizations', 
     43        7 => 'Health', 
     44        8 => 'Kids & Family', 
     45        9 => 'Music', 
     46        10 => 'News & Politics', 
     47        11 => 'Religion & Spirituality', 
     48        12 => 'Science & Medicine', 
     49        13 => 'Society & Culture', 
     50        14 => 'Sports & Recreation', 
     51        15 => 'Technology', 
     52        16 => 'TV & Film', 
     53    ); 
     54 
     55    private $itunes_subcategories = array( 
     56        'Arts' => array( 'Design', 'Fashion & Beauty', 'Food', 'Literature', 'Performing Arts', 'Visual Arts' ), 
     57        'Business' => array( 'Business News', 'Careers', 'Investing', 'Management & Marketing', 'Shopping' ), 
     58        'Education' => array( 'Education Technology', 'Higher Education', 'K-12', 'Language Courses', 'Training' ), 
     59        'Games & Hobbies' => array( 'Automotive', 'Aviation', 'Hobbies', 'Other Games', 'Video Games' ), 
     60        'Government & Organizations' => array( 'Local', 'National', 'Non-Profit', 'Regional' ), 
     61        'Health' => array( 'Alternative Health', 'Fitness & Nutrition', 'Self-Help', 'Sexuality' ), 
     62        'Religion & Spirituality' => array( 'Buddhism', 'Christianity', 'Hinduism', 'Islam', 'Judaism', 'Other', 'Spirituality' ), 
     63        'Science & Medicine' => array( 'Medicine', 'Natural Sciences', 'Social Sciences' ), 
     64        'Society & Culture' => array( 'History', 'Personal Journals', 'Philosophy', 'Places & Travel' ), 
     65        'Sports & Recreation' => array( 'Amateur', 'College & High School', 'Outdoor', 'Professional' ), 
     66        'Technology' => array( 'Gadgets', 'Tech News', 'Podcasting', 'Software How-To' ), 
     67    ); 
     68 
     69    private $itunes_explicit = array( 
     70        0 => 'Clean', 
     71        1 => 'No', 
     72        2 => 'Yes', 
     73    ); 
     74 
    3175    /** 
    3276    * 
     
    63107    function action_admin_header() 
    64108    { 
     109        Stack::add('admin_stylesheet', array($this->get_url() . '/podcast.css', 'screen')); 
     110 
    65111        $feeds = Options::get('podcast__feeds'); 
    66112        $output = ''; 
     
    182228        if( $form->content_type->value == Post::type('podcast') ) { 
    183229            $feeds = Options::get('podcast__feeds'); 
    184             $output = ''; 
    185             $control_id = 0; 
    186             $postfields = $form->publish_controls->append('fieldset', 'enclosures', 'Enclosures'); 
     230            $postfields = $form->publish_controls->append('fieldset', 'enclosures', _t( 'Enclosures' ) ); 
    187231            foreach($feeds as $feed => $feedtype) { 
    188                 $control_id = md5($feed); 
    189                 $fieldname = "enclosure_{$control_id}"; 
    190                 $customfield = $postfields->append('text', $fieldname, 'null:null', $feed); 
    191                 $customfield->value = isset($post->info->{$feed}) ? $post->info->{$feed} : ''; 
    192                 $customfield->template = 'tabcontrol_text'; 
     232                switch( $feedtype ) { 
     233                case self::PODCAST_ITUNES: 
     234                    $this->itunes_form( $form, $post, $feed ); 
     235                    break; 
     236                } 
    193237            } 
    194238        } 
     
    208252            $feeds = Options::get('podcast__feeds'); 
    209253            foreach($feeds as $feed => $feedtype) { 
    210                 $control_id = md5($feed); 
    211                 $fieldname = "enclosure_{$control_id}"; 
    212                 $customfield = $form->$fieldname; 
    213                 $post->info->{$feed} = $customfield->value; 
    214             } 
     254                switch( $feedtype ) { 
     255                    case self::PODCAST_ITUNES: 
     256                        $this->get_itunes_settings( $form, $post, $feed ); 
     257                    break; 
     258                } 
     259            } 
     260 
    215261        } 
    216262    } 
     
    327373                $guid= $item->addChild( 'guid', $post->guid ); 
    328374                $guid->addAttribute( 'isPermaLink', 'false' ); 
     375 
     376                list($url, $size, $duration, $explicit, $subtitle, $keywords, $summary, $block ) = $post->info->$feed; 
    329377                $enclosure = $item->addChild( 'enclosure' ); 
    330                 $enclosure->addAttribute( 'url', $post->info->feed ); 
    331                 $enclosure->addAttribute( 'length', filesize( $post->info->feed ) ); 
     378                $enclosure->addAttribute( 'url', $url ); 
     379                $enclosure->addAttribute( 'length', $size ); 
    332380                $enclosure->addAttribute( 'type', 'audio/mpeg' ); 
    333                 $category = $item->addChild( 'Category', '' ); 
    334  
    335                 $itunes_author = $item->addChild( 'xmlns:itunes:author', $post->author->displayname ); 
    336                 $itunes_explicit = $item->addChild( 'xmlns:itunes:explicit', 'Clean' ); 
    337                 $itunes_subtitle = $item->addChild( 'xmlns:itunes:subtitle', '' ); 
    338                 $itunes_summary = $item->addChild( 'xmlns:itunes:summary', '' ); 
    339                 $itunes_duration = $item->addChild( 'xmlns:itunes:duration', '' ); 
    340                 $itunes_keywords = $item->addChild( 'xmlns:itunes:keywords', '' ); 
     381 
     382                $itunes_author = $item->addChild( 'xmlns:itunes:author', htmlspecialchars( $post->author->displayname, ENT_COMPAT, 'UTF-8' ) ); 
     383                $itunes_explicit = $item->addChild( 'xmlns:itunes:explicit', $explicit ); 
     384                $itunes_subtitle = $item->addChild( 'xmlns:itunes:subtitle', htmlspecialchars( $subtitle, ENT_COMPAT, 'UTF-8' ) ); 
     385                $itunes_summary = $item->addChild( 'xmlns:itunes:summary', htmlspecialchars( $summary, ENT_COMPAT, 'UTF-8' ) ); 
     386                $itunes_duration = $item->addChild( 'xmlns:itunes:duration', $duration ); 
     387                $itunes_keywords = $item->addChild( 'xmlns:itunes:keywords', htmlspecialchars( $keywords, ENT_COMPAT, 'UTF-8' ) ); 
     388                $itunes_block = $item->addChild( 'xmlns:itunes:block', $block ); 
    341389 
    342390                Plugins::act( 'podcast_add_post', $item, $post ); 
     
    358406    } 
    359407 
     408    protected function itunes_form( $form, $post, $feed ) 
     409    { 
     410        $postfields = $form->publish_controls->enclosures; 
     411        if( isset( $post->info->$feed ) ) { 
     412            list($url, $size, $duration, $explicit, $subtitle, $keywords, $summary, $block ) = $post->info->$feed; 
     413        } 
     414        $control_id = md5($feed); 
     415        $fieldname = "{$control_id}_settings"; 
     416        $feed_fields = $postfields->append( 'fieldset', $fieldname, _t( 'Settings for ' ) . $feed ); 
     417        $feed_fields->class = 'podcast-settings'; 
     418 
     419        $fieldname = "enclosure_{$control_id}"; 
     420        $customfield = $feed_fields->append('text', $fieldname, 'null:null', _t( 'Podcast file:' ), 'tabcontrol_text' ); 
     421        $customfield->value = isset( $url ) ? $url : ''; 
     422 
     423        $fieldname = "explicit_{$control_id}"; 
     424        $customfield = $feed_fields->append( 'select', $fieldname, 'null:null', _t( 'Explicit:' ) ); 
     425        $customfield->template = 'tabcontrol_select'; 
     426        $customfield->options = $this->itunes_explicit; 
     427        if( isset( $explicit ) ) $customfield->value = $explicit; 
     428 
     429/*      $fieldname = "category_{$control_id}"; 
     430        $customfield = $feed_fields->append( 'select', $fieldname, 'null:null', _t( 'Category:' ) ); 
     431        $customfield->template = 'tabcontrol_select'; 
     432        $customfield->options = $this->itunes_categories; 
     433        $customfield->value = isset( $category ) ? $category : $this->itunes_categories[0]; 
     434*/ 
     435 
     436        $fieldname = "subtitle_{$control_id}"; 
     437        $customfield = $feed_fields->append( 'text', $fieldname, 'null:null', _t( 'Subtitle:' ), 'tabcontrol_text' ); 
     438        $customfield->value = isset( $subtitle ) ? $subtitle : ''; 
     439 
     440        $fieldname = "keywords_{$control_id}"; 
     441        $customfield = $feed_fields->append( 'text', $fieldname, 'null:null', _t( 'Keywords:' ), 'tabcontrol_text' ); 
     442        $customfield->value = isset( $keywords ) ? $keywords : ''; 
     443 
     444        $fieldname = "summary_{$control_id}"; 
     445        $customfield = $feed_fields->append( 'textarea', $fieldname, 'null:null', _t( 'Summary:' ), 'tabcontrol_textarea' ); 
     446        $customfield->value = isset( $summary ) ? $summary : ''; 
     447 
     448        $fieldname = "block_{$control_id}"; 
     449        $customfield = $feed_fields->append( 'checkbox', $fieldname, 'null:null', _t( 'Summary:' ), 'tabcontrol_checkbox' ); 
     450        $customfield->value = isset( $block ) ? $block : ''; 
     451    } 
     452 
     453    protected function get_itunes_settings( $form, $post, $feed ) 
     454    { 
     455        $control_id = md5($feed); 
     456 
     457        $fieldname = "enclosure_{$control_id}"; 
     458        $url = $form->$fieldname->value; 
     459 
     460        $fieldname = "explicit_{$control_id}"; 
     461        $explicit = $form->$fieldname->value; 
     462 
     463        $fieldname = "subtitle_{$control_id}"; 
     464        $subtitle = $form->$fieldname->value; 
     465 
     466        $fieldname = "keywords_{$control_id}"; 
     467        $keywords = $form->$fieldname->value; 
     468 
     469        $fieldname = "summary_{$control_id}"; 
     470        $summary = $form->$fieldname->value; 
     471 
     472        $size = strlen( file_get_contents( $url ) ); 
     473 
     474        $duration = ''; 
     475         
     476        $fieldname = "block_{$control_id}"; 
     477        $block = $form->$fieldname->value; 
     478 
     479        $post->info->$feed = array( $url, $size, $duration, $explicit, $subtitle, $keywords, $summary, $block ); 
     480    } 
    360481} 
    361482