diff --git a/bts_podcast/bts_podcast.php b/bts_podcast/bts_podcast.php index d7ed79e..36595b5 100644 --- a/bts_podcast/bts_podcast.php +++ b/bts_podcast/bts_podcast.php @@ -6,17 +6,21 @@ $plugin['author_uri'] = 'http://square-r00t.net/'; $plugin['description'] = 'A plugin to generate a tech-centric podcast feed.'; $plugin['order'] = 5; -//$plugin['type'] = 1; -$plugin['type'] = 0; +//$plugin['media'] = 1; +$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_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_LIFECYCLE_NOTIFY; //if (!defined('txpinterface')) // @include_once('zem_tpl.php'); +register_callback('bts_podcast_initdb','plugin_lifecycle.bts_podcast', 'enabled'); +register_callback('bts_podcast_genguid','article_saved'); + if (0) { ?> # --- BEGIN PLUGIN HELP --- @@ -30,18 +34,18 @@ h5. bts_podcast_path The path to the media file. Attributes: - *type=* + *media=* Useful for mp3/oggcasts. Default is _mp3_. *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 The filename of the media file. Automatically generated from the title by default. Attributes: - *type=* + *media=* File extension. Recommended is either _mp3_ or _ogg_. Default is _mp3_. *name=* @@ -84,8 +88,16 @@ This plugin creates a *sha256* table in your Textpattern DB. There, it stores th # --- 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')) { Txp::get('\Textpattern\Tag\Registry') ->register('bts_podcast_path') @@ -94,12 +106,13 @@ if(class_exists('\Textpattern\Tag\Registry')) { ->register('bts_podcast_media_uri'); } +// Tags function bts_podcast_path($atts) { - $default_vals = array('type' => 'mp3'); - $default_vals['base'] = 'media/' . $default_vals['type'] . '/'; + $default_vals = array('media' => 'mp3'); + $default_vals['base'] = 'media/' . $default_vals['media'] . '/'; extract(lAtts(($default_vals), $atts)); if ($base == 'media/mp3/') { - $base = 'media/' . $type . '/'; + $base = 'media/' . $media . '/'; } return $base; } @@ -107,7 +120,7 @@ function bts_podcast_path($atts) { function bts_podcast_filename($atts) { extract(lAtts(array( - 'type' => 'mp3', + 'media' => 'mp3', 'name' => NULL, ), $atts)); if (! $name) { @@ -116,7 +129,7 @@ function bts_podcast_filename($atts) { $replaced = preg_replace('(\s+|[^A-Za-z0-9\.\-]+)','.',$stripped); $name = preg_replace('(\.+)','.',$replaced); } - return $name . '.' . $type; + return $name . '.' . $media; } @@ -125,10 +138,10 @@ function bts_podcast_guid ($atts) { 'string' => '', 'byte' => '1', 'db' => '1', + 'media' => 'mp3', ), $atts)); 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)); } elseif ($byte == '1') { $checksum = hash_file('sha256',$string); @@ -140,12 +153,13 @@ return $checksum; function bts_podcast_media_uri ($atts) { - $default_vals = array('type' => 'mp3'); - //$default_vals['uri'] = site_url($atts) . bts_podcast_path($type=$default_vals['type']) . bts_podcast_filename($type=$default_vals['type']); + $default_vals = array('media' => 'mp3'); $default_vals['uri'] = site_url($atts) . bts_podcast_path($atts) . bts_podcast_filename($atts); extract(lAtts(array($default_vals), $atts)); - //if ($uri == site_url() . -return $uri; + if ( $uri == '') { + $uri = site_url($atts) . bts_podcast_path($atts) . bts_podcast_filename($atts); + } + return $uri; }