I have a rather complex website design in which I use individual stylesheets and javascript files (even appcache manifests and dynamically added homescreen icons in some future cases) to create single, unique pages. For this to work I have created a plugin that inserts a textarea in the entry editor where I add my files, one per line. The script assumes that I've generated a folder named as the slug using the Habari Silo (I might automate this, one day), and that if the file is not given as an absolute url, it must just prepend "
.
I'm currently also implementing an external file editor (though with login through Habari) which is nearing completion.
Long story short... currently, I just check $post->info->[name of the custom textarea] and loop through all the entries in my main theme template files. I wanted to remove this and add everything to either the theme file or a plugin (I have to run both, since extensive modification of the atom feed, which my site requires, must use the plugin class). For one, I cannot use Stacks (not enough control over what is and what isn't added to the header or footer, and some other issues) so I'm trying to set my own variables. I have tried many different things, but my problem is that I seem to be unable to either pass $post->info->[custom field] and $post->slug to the theme/plugin extension, or grant the function access to these vars. Adding $post to the function params, setting $post global, or even explicitly passing the values to a function. It just doesn't work for me.
class StereoDax extends Theme
{
/**
* Adding my own functions because I'm not happy with
* all the stuff Habari automagically adds to the header/footer
* Not using Stacks because regular vars give me more control
* with less code (including adding appcache manifests).
*/
public function theme_files( $post ) // tried $theme, etc... also tried setting global
{
// Create the new variables
$this->header = '';
$this->footer = '';
$this->head = '';
// Get all the files from the custom post element
$files = preg_split('/(\r?\n)+/', $post->info->custom_files);
// Split the files and check if they're local
foreach($files as $f)
{
if (strpos($f, '://') === false)
{
$f = Site::get_url('habari') . '/user/files/' . $post->slug . '/' . $f;
}
// CSS Files
if(stripos($f,'.css') !== false)
{
$this->header .= "\t<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"$f\" />\n";
}
// Appcache manifest
else if(stripos($f,'.appcache') !== false)
{
$this->head = " manifest=\"$f\"";
}
// JS (assumed, if not CSS or appcache)
else
{
$this->footer .= "\t<script type=\"text/javascript\" src=\"$f\"></script>\n";
}
}
}
}