diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3819313 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +*.swo diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..70b714a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tools"] + path = tools + url = https://github.com/textpattern/textpattern-plugin-template.git diff --git a/bts_hash/.keepme b/bts_hash/.keepme deleted file mode 100644 index e69de29..0000000 diff --git a/bts_podcast/bts_podcast.php b/bts_podcast/bts_podcast.php new file mode 100644 index 0000000..babc77d --- /dev/null +++ b/bts_podcast/bts_podcast.php @@ -0,0 +1,152 @@ + +# --- 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: + *type=* + Useful for mp3/oggcasts. Default is _mp3_. + + *base=* + Path to the media file (excluding the filename itself). Default is _media/*$type*/_. + + +h5. bts_podcast_filename +The filename of the media file. Automatically generated from the title by default. + +Attributes: + *ext=* + File extension. Recommended is either _mp3_ or _ogg_. Default is _mp3_. + + *name=* + The string to use as the filename. Default is to use *@@* (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 _*@@*/*@@*_. + + *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 _*@@@@*/*@@*_. + + +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 --- +register('bts_podcast_path') + ->register('bts_podcast_filename') + ->register('bts_podcast_guid') + ->register('bts_podcast_media_uri'); +} + +function bts_podcast_path($atts) { + $default_vals = array('type' => 'mp3'); + $default_vals['base'] = 'media/' . $default_vals['type'] . '/'; + extract(lAtts(($default_vals), $atts)); + if ($base == 'media/mp3/') { + $base = 'media/' . $type . '/'; + } + return $base; +} + + +function bts_podcast_filename($atts) { + extract(lAtts(array( + 'ext' => 'mp3', + 'name' => NULL, + ), $atts)); + if (! $name) { + $raw_name = strtolower(title()); + $stripped = trim($raw_name); + $replaced = preg_replace('(\s+|[^A-Za-z0-9\.\-]+)','.',$stripped); + $name = preg_replace('(\.+)','.',$replaced); + } + return $name . '.' . $ext; +} + + +function bts_podcast_guid ($atts) { + extract(lAtts(array( + 'string' => '', + 'byte' => '1', + 'db' => '1', + ), $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()); + } elseif ($byte == '1') { + $checksum = hash_file('sha256',$string); + } else { + $checksum = hash('sha256',$string); + } +return $checksum; +} + + +function bts_podcast_media_uri ($atts) { + extract(lAtts(array( + 'uri' => site_url() . bts_podcast_path() . bts_podcast_filename(), + ), $atts)); +return $uri; +} + + +# --- END PLUGIN CODE --- + +?> diff --git a/tools b/tools new file mode 160000 index 0000000..b3b6dd1 --- /dev/null +++ b/tools @@ -0,0 +1 @@ +Subproject commit b3b6dd175b87511305c616f63c763c1c8314e3bf