This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ /** * WP Facebox * julienne fries! */ class WP_Facebox { var $opts; var $site; var $home; var $root; // plugin root dir /* Utilities */ function header() { echo << \n HTML; } function invoke_header() { $selectors = array(); if ( $this->opts['do_default'] ) $selectors[] = "a[rel*='facebox']"; if ( $this->opts['do_gallery'] ) $selectors[] = ".gallery-item a"; $selectors = implode(', ', $selectors); if ( !empty($selectors) ) echo "\n"; } function rel_replace( $content ) { $pattern = "/(.*?)<\/a>/i"; $replacement = '$7'; $content = preg_replace($pattern, $replacement, $content); return $content; } function filter_gallery_link( $link, $id ) { // By default, the gallery shortcode creates permalinks to the attachment // Facebox, however, expects a direct link to the resource // wp_get_attachment_url does this for us // I <3 filters return wp_get_attachment_url( $id ); } /* Init / Constructor */ function init() { $this->home = get_option('home'); $this->site = get_option('siteurl'); $this->root = $this->site . '/wp-content/plugins/wp-facebox'; wp_register_script( 'facebox', "{$this->root}/facebox.js", array('jquery'), '1.2' ); if ( $this->opts['loadscript'] ) { wp_enqueue_script( 'facebox' ); add_action( 'wp_print_scripts', array(&$this, 'header') ); add_action( 'wp_head', array(&$this, 'invoke_header') ); // turn gallery permalinks into direct links add_filter( 'attachment_link', array(&$this, 'filter_gallery_link'), 11, 2 ); } if ( $this->opts['autofilter'] ) { add_filter( 'the_content', array(&$this, 'rel_replace') ); } } function WP_Facebox() { // constructor // TODO: implement admin options interface for these values // For the time being, turn off options by replacing 1 with 0 $this->opts = array( 'autofilter' => 1, 'do_default' => 1, 'do_gallery' => 1, 'loadscript' => 1 ); // don't disable 'loadscript', unless you're only after the header output $this->init(); } } // make those julienne fries, baby $wp_facebox = new WP_Facebox(); ?>