2016-03-18 03:17:32 -04:00
< ? php
$plugin [ 'version' ] = '0.1' ;
$plugin [ 'author' ] = 'brent saner' ;
$plugin [ 'author_uri' ] = 'http://square-r00t.net/' ;
$plugin [ 'description' ] = 'A plugin to generate a tech-centric podcast feed.' ;
$plugin [ 'order' ] = 5 ;
2016-03-18 21:09:11 -04:00
//$plugin['media'] = 1;
$plugin [ 'media' ] = 0 ;
2016-03-18 03:17:32 -04:00
//if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
2016-03-18 21:09:11 -04:00
if ( ! defined ( 'PLUGIN_LIFECYCLE_NOTIFY' )) define ( 'PLUGIN_LIFECYCLE_NOTIFY' , 0x0002 ); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events
2016-03-18 03:17:32 -04:00
//$plugin['flags'] = PLUGIN_HAS_PREFS | PLUGIN_LIFECYCLE_NOTIFY;
2016-03-18 21:09:11 -04:00
$plugin [ 'flags' ] = PLUGIN_LIFECYCLE_NOTIFY ;
2016-03-18 03:17:32 -04:00
//if (!defined('txpinterface'))
// @include_once('zem_tpl.php');
2016-03-18 21:09:11 -04:00
register_callback ( 'bts_podcast_initdb' , 'plugin_lifecycle.bts_podcast' , 'enabled' );
2016-04-07 16:33:35 -04:00
register_callback ( 'bts_podcast_gen_metainfo' , 'article_saved' );
2016-03-18 21:09:11 -04:00
2016-03-18 03:17:32 -04:00
if ( 0 ) {
?>
# --- BEGIN PLUGIN HELP ---
h1 . Podcast generation ... * for nerds *.
h4 . For an exmaple of this in action , check out the various feeds for " Sysadministrivia " : http :// sysadministrivia . com .
This plugin performs multiple functions to aid in creating a podcast . It requires " getID3 " : http :// www . getid3 . org to be available in your PHP ' s path .
h5 . bts_podcast_path
The path to the media file .
Attributes :
2016-03-18 21:09:11 -04:00
* media =*
2016-03-18 03:17:32 -04:00
Useful for mp3 / oggcasts . Default is _mp3_ .
* base =*
2016-03-18 21:09:11 -04:00
Path to the media file ( excluding the filename itself ) . Default is _media /*$media*/ _ .
2016-03-18 03:17:32 -04:00
h5 . bts_podcast_filename
The filename of the media file . Automatically generated from the title by default .
Attributes :
2016-03-18 21:09:11 -04:00
* media =*
2016-03-18 03:17:32 -04:00
File extension . Recommended is either _mp3_ or _ogg_ . Default is _mp3_ .
* name =*
The string to use as the filename . Default is to use *@< txp : title />@* ( in a stripped manner - all symbols etc . replaced with . and - ) .
h5 . bts_podcast_guid
The GUID for the podcast . See the * Storing Checksums * section .
Attributes :
* string =*
The string to use as a GUID . Default is to use a SHA256 of the file ( byte - wise ) found at _ *@< txp : bts_podcast_path />@*/*@< txp : bts_podcast_filename />@* _ .
* byte =*
Boolean . Use byte checksumming instead of string checksumming . This requires a valid path for the * string =* attribute . Default is _1_ ( use byte checksumming ) .
* db =*
Boolean . Use the SHA256 table to look up the GUID ( see the * Storing Checksums * section below ) . Default is _1_ ( use the sha256 table ) .
h5 . bts_podcast_media_uri
The web path to fetch the file .
Attributes :
* uri =*
The path to use . Default is to use _ *@< txp : site_url />@@< txp : bts_podcast_path />@*/*@< txp : bts_podcast_filename />@* _ .
h3 . Storing Checksums
Using SHA256 sums as your GUID is a very handy thing - it not only gaurantees unique GUIDs ( which is the entire point of GUIDs ), but also gaurantees file integrity in transit .
However , it can take a while to generate SHA256 sums dynamically every time the feed is fetched . So how do we get around this ?
Simple ; we use a database !
This plugin creates a * sha256 * table in your Textpattern DB . There , it stores the checksums of MP3 and OGG files when an article in the " episodes " section is created . When the feed is pulled , they are fetched from the DB automatically ( assuming you ' re using * bts_podcast_guid * with _db = " 1 " _ ) .
# --- END PLUGIN HELP ---
< ? php
}
# --- BEGIN PLUGIN CODE ---
2016-04-07 16:33:35 -04:00
// Hooks/callbacks
2016-03-18 21:09:11 -04:00
function bts_podcast_initdb () {
2016-04-07 16:33:35 -04:00
safe_query ( " CREATE TABLE IF NOT EXISTS bts_podcast (id int(11) NOT NULL AUTO_INCREMENT,url_title varchar(64) NOT NULL,filename varchar(64) NOT NULL,type char(3) NOT NULL,checksum char(64) NOT NULL,bytesize varchar(16) NOT NULL,created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,changed timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (id),UNIQUE KEY unique_index (url_title,type)) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 " );
2016-03-18 21:09:11 -04:00
}
2016-03-18 03:17:32 -04:00
2016-04-07 16:33:35 -04:00
function bts_podcast_gen_metainfo ( $input ) {
$hash = hash_file ( 'sha256' , file_article_upload ());
// safe_query("INSERT INTO bts_podcast (url_title,filename,type,checksum,bytesize) VALUES ('" . $input['urltitle'] . "','" . $input['mediafile'] . "','" . $input['mediatype'] . "','" . $input['mediachksum'] . "','" . $input['mediabytes'] . "') ON DUPLICATE KEY UPDATE url_title = '" . $input['urltitle'] . "', filename = '" . $input['mediafile'] . "', type = '" . $input['mediatype'] . "', checksum = '" . $input['mediachksum'] . "', bytesize = '" . $input['mediabytes'] . "'");
2016-03-18 21:09:11 -04:00
}
2016-04-07 16:33:35 -04:00
//use pluggable_ui(event,step,default content, record set)
//event, i believe, is article_ui
//maybe use step "custom_fields" and totally replace custom fields with the file uploader?
//i should also find a way to get the "S0E0" format automatically used for the url title/permlink.
2016-03-18 21:09:11 -04:00
// Register the plugin...
2016-03-18 03:17:32 -04:00
if ( class_exists ( '\Textpattern\Tag\Registry' )) {
Txp :: get ( '\Textpattern\Tag\Registry' )
-> register ( 'bts_podcast_path' )
-> register ( 'bts_podcast_filename' )
-> register ( 'bts_podcast_guid' )
-> register ( 'bts_podcast_media_uri' );
}
2016-03-18 21:09:11 -04:00
// Tags
2016-03-18 03:17:32 -04:00
function bts_podcast_path ( $atts ) {
2016-03-18 21:09:11 -04:00
$default_vals = array ( 'media' => 'mp3' );
$default_vals [ 'base' ] = 'media/' . $default_vals [ 'media' ] . '/' ;
2016-03-18 03:17:32 -04:00
extract ( lAtts (( $default_vals ), $atts ));
if ( $base == 'media/mp3/' ) {
2016-03-18 21:09:11 -04:00
$base = 'media/' . $media . '/' ;
2016-03-18 03:17:32 -04:00
}
return $base ;
}
function bts_podcast_filename ( $atts ) {
extract ( lAtts ( array (
2016-03-18 21:09:11 -04:00
'media' => 'mp3' ,
2016-03-18 03:17:32 -04:00
'name' => NULL ,
), $atts ));
if ( ! $name ) {
2016-03-18 21:07:47 -04:00
$raw_name = strtolower ( title ( $atts ));
2016-03-18 03:17:32 -04:00
$stripped = trim ( $raw_name );
$replaced = preg_replace ( '(\s+|[^A-Za-z0-9\.\-]+)' , '.' , $stripped );
$name = preg_replace ( '(\.+)' , '.' , $replaced );
}
2016-03-18 21:09:11 -04:00
return $name . '.' . $media ;
2016-03-18 03:17:32 -04:00
}
function bts_podcast_guid ( $atts ) {
extract ( lAtts ( array (
'string' => '' ,
'byte' => '1' ,
'db' => '1' ,
2016-03-18 21:09:11 -04:00
'media' => 'mp3' ,
2016-03-18 03:17:32 -04:00
), $atts ));
if (( $byte == '1' && $db == '1' ) || ( $string == '' )) {
2016-04-07 16:33:35 -04:00
$checksum = fetch ( 'checksum' , 'bts_podcast' , 'filename' , bts_podcast_filename ( $atts ));
2016-03-18 03:17:32 -04:00
} elseif ( $byte == '1' ) {
$checksum = hash_file ( 'sha256' , $string );
} else {
$checksum = hash ( 'sha256' , $string );
}
return $checksum ;
}
function bts_podcast_media_uri ( $atts ) {
2016-03-18 21:09:11 -04:00
$default_vals = array ( 'media' => 'mp3' );
2016-03-18 21:07:47 -04:00
$default_vals [ 'uri' ] = site_url ( $atts ) . bts_podcast_path ( $atts ) . bts_podcast_filename ( $atts );
extract ( lAtts ( array ( $default_vals ), $atts ));
2016-04-07 16:33:35 -04:00
if ( ! isset ( $uri )) {
2016-03-18 21:09:11 -04:00
$uri = site_url ( $atts ) . bts_podcast_path ( $atts ) . bts_podcast_filename ( $atts );
}
return $uri ;
2016-03-18 03:17:32 -04:00
}
2016-04-07 16:33:35 -04:00
/*
function bts_podccast_filesize ( $atts ) {
}
function bts_podcast_medialength ( $atts ) {
}
function bts_podcast_get_guid ( $atts ) {
}
*/
// UNDER DEVELOPMENT: needs bts_podcast_filesize (which i need to rename to actually be bytesize)
// i also need to get media length so that can be returned in the actual feed.
/*
$metainfo_mp3 = array (
//$input['urltitle']
//$input['mediafile']
//$input['mediatype']
//$input['mediachksum']
//$input['mediabytes']
urltitle => title ( $atts ),
mediafile => bts_podcast_filename ( $atts ),
mediatype => 'mp3' ,
mediachksum => bts_podcast_guid ( $atts ),
mediabytes => bts_podcast_filesize ( $atts ));
$metainfo_ogg = array (
//$input['urltitle']
//$input['mediafile']
//$input['mediatype']
//$input['mediachksum']
//$input['mediabytes']
urltitle => title ( $atts ),
mediafile => bts_podcast_filename ( $atts ),
mediatype => 'mp3' ,
mediachksum => bts_podcast_guid ( $atts ),
mediabytes => bts_podcast_filesize ( $atts ));
bts_podcast_gen_metainfo ( $metainfo_mp3 );
bts_podcast_gen_metainfo ( $metainfo_ogg );
*/
2016-03-18 03:17:32 -04:00
# --- END PLUGIN CODE ---
?>