This commit is contained in:
brent s. 2016-03-18 21:09:11 -04:00
parent b8bbb27871
commit 241ab1689a

View File

@ -6,17 +6,21 @@ $plugin['author_uri'] = 'http://square-r00t.net/';
$plugin['description'] = 'A plugin to generate a tech-centric podcast feed.'; $plugin['description'] = 'A plugin to generate a tech-centric podcast feed.';


$plugin['order'] = 5; $plugin['order'] = 5;
//$plugin['type'] = 1; //$plugin['media'] = 1;
$plugin['type'] = 0; $plugin['media'] = 0;


//if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events //if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
//if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events


//$plugin['flags'] = PLUGIN_HAS_PREFS | PLUGIN_LIFECYCLE_NOTIFY; //$plugin['flags'] = PLUGIN_HAS_PREFS | PLUGIN_LIFECYCLE_NOTIFY;
$plugin['flags'] = PLUGIN_LIFECYCLE_NOTIFY;


//if (!defined('txpinterface')) //if (!defined('txpinterface'))
// @include_once('zem_tpl.php'); // @include_once('zem_tpl.php');


register_callback('bts_podcast_initdb','plugin_lifecycle.bts_podcast', 'enabled');
register_callback('bts_podcast_genguid','article_saved');

if (0) { if (0) {
?> ?>
# --- BEGIN PLUGIN HELP --- # --- BEGIN PLUGIN HELP ---
@ -30,18 +34,18 @@ h5. bts_podcast_path
The path to the media file. The path to the media file.


Attributes: Attributes:
*type=* *media=*
Useful for mp3/oggcasts. Default is _mp3_. Useful for mp3/oggcasts. Default is _mp3_.


*base=* *base=*
Path to the media file (excluding the filename itself). Default is _media/*$type*/_. Path to the media file (excluding the filename itself). Default is _media/*$media*/_.




h5. bts_podcast_filename h5. bts_podcast_filename
The filename of the media file. Automatically generated from the title by default. The filename of the media file. Automatically generated from the title by default.


Attributes: Attributes:
*type=* *media=*
File extension. Recommended is either _mp3_ or _ogg_. Default is _mp3_. File extension. Recommended is either _mp3_ or _ogg_. Default is _mp3_.


*name=* *name=*
@ -84,8 +88,16 @@ This plugin creates a *sha256* table in your Textpattern DB. There, it stores th


# --- BEGIN PLUGIN CODE --- # --- BEGIN PLUGIN CODE ---


// Plugin code goes here. No need to escape quotes. // Hooks
function bts_podcast_initdb () {
safe_query("CREATE TABLE IF NOT EXISTS sha256 (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,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)");
}


function bts_podcast_gen_guid () {
hash_file('sha256',file_article_upload());
}

// Register the plugin...
if(class_exists('\Textpattern\Tag\Registry')) { if(class_exists('\Textpattern\Tag\Registry')) {
Txp::get('\Textpattern\Tag\Registry') Txp::get('\Textpattern\Tag\Registry')
->register('bts_podcast_path') ->register('bts_podcast_path')
@ -94,12 +106,13 @@ if(class_exists('\Textpattern\Tag\Registry')) {
->register('bts_podcast_media_uri'); ->register('bts_podcast_media_uri');
} }


// Tags
function bts_podcast_path($atts) { function bts_podcast_path($atts) {
$default_vals = array('type' => 'mp3'); $default_vals = array('media' => 'mp3');
$default_vals['base'] = 'media/' . $default_vals['type'] . '/'; $default_vals['base'] = 'media/' . $default_vals['media'] . '/';
extract(lAtts(($default_vals), $atts)); extract(lAtts(($default_vals), $atts));
if ($base == 'media/mp3/') { if ($base == 'media/mp3/') {
$base = 'media/' . $type . '/'; $base = 'media/' . $media . '/';
} }
return $base; return $base;
} }
@ -107,7 +120,7 @@ function bts_podcast_path($atts) {


function bts_podcast_filename($atts) { function bts_podcast_filename($atts) {
extract(lAtts(array( extract(lAtts(array(
'type' => 'mp3', 'media' => 'mp3',
'name' => NULL, 'name' => NULL,
), $atts)); ), $atts));
if (! $name) { if (! $name) {
@ -116,7 +129,7 @@ function bts_podcast_filename($atts) {
$replaced = preg_replace('(\s+|[^A-Za-z0-9\.\-]+)','.',$stripped); $replaced = preg_replace('(\s+|[^A-Za-z0-9\.\-]+)','.',$stripped);
$name = preg_replace('(\.+)','.',$replaced); $name = preg_replace('(\.+)','.',$replaced);
} }
return $name . '.' . $type; return $name . '.' . $media;
} }




@ -125,10 +138,10 @@ function bts_podcast_guid ($atts) {
'string' => '', 'string' => '',
'byte' => '1', 'byte' => '1',
'db' => '1', 'db' => '1',
'media' => 'mp3',
), $atts)); ), $atts));


if (($byte == '1' && $db == '1') || ($string == '')) { if (($byte == '1' && $db == '1') || ($string == '')) {
//$checksum = safe_query('select checksum from sha256 where url_title = \'' . article_url_title() . '\' and filename = \'' . bts_podcast_filename() . '\'');
$checksum = fetch('checksum','sha256','filename',bts_podcast_filename($atts)); $checksum = fetch('checksum','sha256','filename',bts_podcast_filename($atts));
} elseif ($byte == '1') { } elseif ($byte == '1') {
$checksum = hash_file('sha256',$string); $checksum = hash_file('sha256',$string);
@ -140,11 +153,12 @@ return $checksum;




function bts_podcast_media_uri ($atts) { function bts_podcast_media_uri ($atts) {
$default_vals = array('type' => 'mp3'); $default_vals = array('media' => 'mp3');
//$default_vals['uri'] = site_url($atts) . bts_podcast_path($type=$default_vals['type']) . bts_podcast_filename($type=$default_vals['type']);
$default_vals['uri'] = site_url($atts) . bts_podcast_path($atts) . bts_podcast_filename($atts); $default_vals['uri'] = site_url($atts) . bts_podcast_path($atts) . bts_podcast_filename($atts);
extract(lAtts(array($default_vals), $atts)); extract(lAtts(array($default_vals), $atts));
//if ($uri == site_url() . if ( $uri == '') {
$uri = site_url($atts) . bts_podcast_path($atts) . bts_podcast_filename($atts);
}
return $uri; return $uri;
} }