acronyms. Allows users to manage lists of acronyms through admin interface. Based on Joel Bennett's Acronym Replacer plugin (http://www.huddledmasses.org/) and Joel Pan's NP_Acronym plugin for Nucleus CMS. Version: 1.6.2 Author: Joel Pan Author URI: http://ketsugi.com/ Copyright 2008 Joel Pan 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ class Acronyms { /* void install () * Creates tables and populates default acronyms. */ function install () { // Populate defaults $acronyms = array( 'AFAIK' => 'As far as I know', 'AIM' => 'AOL Instant Messenger', 'AJAX' => 'Asynchronous JavaScript and XML', 'AOL' => 'America Online', 'API' => 'Application Programming Interface', 'ASAP' => 'As soon as possible', 'ASCII' => 'American Standard Code for Information Interchange', 'ASP' => 'Active Server Pages', 'BTW' => 'By The Way', 'CD' => 'Compact Disc', 'CGI' => 'Common Gateway Interface', 'CMS' => 'Content Management System', 'CSS' => 'Cascading Style Sheets', 'CVS' => 'Concurrent Versions System', 'DBA' => 'Database Administrator', 'DHTML' => 'Dynamic HyperText Markup Language', 'DMCA' => 'Digital Millenium Copyright Act', 'DNS' => 'Domain Name Server', 'DOM' => 'Document Object Model', 'DTD' => 'Document Type Definition', 'DVD' => 'Digital Versatile Disc', 'EOF' => 'End of file', 'EOL' => 'End of line', 'EOM' => 'End of message', 'EOT' => 'End of text', 'FAQ' => 'Frequently Asked Questions', 'FDL' => 'GNU Free Documentation License', 'FTP' => 'File Transfer Protocol', 'FUD' => 'Fear, Uncertainty, and Doubt', 'GB' => 'Gigabyte', 'GHz' => 'Gigahertz', 'GIF' => 'Graphics Interchange Format', 'GPL' => 'GNU General Public License', 'GUI' => 'Graphical User Interface', 'HDD' => 'Hard Disk Drive', 'HTML' => 'HyperText Markup Language', 'HTTP' => 'HyperText Transfer Protocol', 'IANAL' => 'I am not a lawyer', 'ICANN' => 'Internet Corporation for Assigned Names and Numbers', 'IE' => 'Internet Explorer', 'IE5' => 'Internet Explorer 5', 'IE6' => 'Internet Explorer 6', 'IIRC' => 'If I remember correctly', 'IIS' => 'Internet Information Services', 'IM' => 'Instant Message', 'IMAP' => 'Internet Message Access Protocol', 'IMHO' => 'In my humble opinion', 'IMO' => 'In my opinion', 'IOW' => 'In other words', 'IP' => 'Internet Protocol', 'IRC' => 'Internet Relay Chat', 'IRL' => 'In real life', 'ISO' => 'International Organization for Standardization', 'ISP' => 'Internet Service Provider', 'JDK' => 'Java Development Kit', 'JPEG' => 'Joint Photographics Experts Group', 'JPG' => 'Joint Photographics Experts Group', 'JS' => 'JavaScript', 'KB' => 'Kilobyte', 'KISS' => 'Keep it simple, stupid', 'LGPL' => 'GNU Lesser General Public License', 'LOL' => 'Laughing out loud', 'MB' => 'Megabyte', 'MHz' => 'Megahertz', 'MIME' => 'Multipurpose Internet Mail Extension', 'MIT' => 'Massachusetts Institute of Technology', 'MML' => 'Mathematical Markup Language', 'MPEG' => 'Motion Picture Experts Group', 'MS' => 'Microsoft', 'MSDN' => 'Microsoft Developer Network', 'MSIE' => 'Microsoft Internet Explorer', 'MSN' => 'Microsoft Network', 'OMG' => 'Oh my goodness', 'OPML' => 'Outline Processor Markup Language', 'OS' => 'Operating System', 'OSS' => 'Open Source Software', 'OTOH' => 'On the other hand', 'P2P' => 'Peer to Peer', 'PDA' => 'Personal Digital Assistant', 'PDF' => 'Portable Document Format', 'PHP' => 'Pre-Hypertext Processing', 'PICS' => 'Platform for Internet Content Selection', 'PIN' => 'Personal Identification Number', 'PITA' => 'Pain in the Ass', 'PNG' => 'Portable Network Graphics', 'POP' => 'Post Office Protocol', 'POP3' => 'Post Office Protocol 3', 'Perl' => 'Practical Extraction and Report Language', 'QoS' => 'Quality of Service', 'RAID' => 'Redundant Array of Inexpensive Disks', 'RDF' => 'Resource Description Framework', 'ROFL' => 'Rolling on the floor laughing', 'ROFLMAO' => 'Rolling on the floor laughing my ass off', 'RPC' => 'Remote Procedure Call', 'RSS' => 'Really Simple Syndication', 'RTF' => 'Rich Text File', 'RTFM' => 'Read The Fucking Manual', 'SCSI' => 'Small Computer System Interface', 'SDK' => 'Software Development Kit', 'SGML' => 'Standard General Markup Language', 'SMIL' => 'Synchronized Multimedia Integration Language', 'SMTP' => 'Simple Mail Transfer Protocol', 'SOAP' => 'Simple Object Access Protocol', 'SQL' => 'Structured Query Language', 'SSH' => 'Secure Shell', 'SSI' => 'Server Side Includes', 'SSL' => 'Secure Sockets Layer', 'SVG' => 'Scalable Vector Graphics', 'SVN' => 'Subversion', 'TIA' => 'Thanks In Advance', 'TIFF' => 'Tagged Image File Format', 'TLD' => 'Top Level Domain', 'TOC' => 'Table of Contents', 'URI' => 'Uniform Resource Identifier', 'URL' => 'Uniform Resource Locator', 'URN' => 'Uniform Resource Name', 'USB' => 'Universal Serial Bus', 'VB' => 'Visual Basic', 'VBA' => 'Visual Basic for Applications', 'W3C' => 'World Wide Web Consortium', 'WAN' => 'Wide Area Network', 'WAP' => 'Wireless Access Protocol', 'WML' => 'Wireless Markup Language', 'WP' => 'WordPress', 'WTF' => 'What the fuck', 'WWW' => 'World Wide Web', 'WYSIWYG' => 'What You See Is What You Get', 'XHTML' => 'eXtensible HyperText Markup Language', 'XML' => 'eXtensible Markup Language', 'XSL' => 'eXtensible Stylesheet Language', 'XSLT' => 'eXtensible Stylesheet Language Transformations', 'XUL' => 'XML User Interface Language', 'YMMV' => 'Your mileage may vary' ); add_option( 'acronym_acronyms', $acronyms ); } /* string get_textdomain () * * returns the text domain to be used for internationalisation */ function get_textdomain () { return "Acronyms"; } /* void uninstall () */ function uninstall () { // Perhaps I should remove the acronyms when uninstalling to clear out the cruft? But what if the user is just temporarily deactivating the plugin with the intention to activate it again later, and doesn't want to lose all his/her custom acronyms? echo "BOOYAH"; } /** * Adds the Management page to WordPress * * @return void **/ function add_pages () { $domain = Acronyms::get_textdomain(); // Add the Manage page add_management_page( __( 'Manage Acronyms', $domain ), __( 'Acronyms', $domain ), "manage_options", __FILE__, array( 'Acronyms', 'manage_acronyms' ) ); } /** * void management_handler () * * handles actions for adding, editing or deleting acronyms * */ function management_handler () { $domain = Acronyms::get_textdomain(); load_plugin_textdomain( $domain, "/wp-content/plugins/your-plugin-directory/" ); $title = __( 'Acronyms', $domain ); $parent_file = 'tools.php?page=' . Acronyms::get_parent_url(); if ( 'acronyms.php' == substr( $parent_file, -12 ) ) { $acronyms = get_option( 'acronym_acronyms' ); wp_reset_vars(array('action', 'acronym')); if ( isset( $_GET['delete-acronyms'] ) ) // Bulk delete array of acronyms $action = 'delete-acronyms'; else if ( isset( $_GET['search'] ) ) // Search term for redirecting to less crufty HTTP GET URL $action = 'search'; else $action = $_GET['action']; switch ($action) { case 'add-acronym': check_admin_referer('add_acronym');; $acronym = $_GET['acronym']; $fulltext = $_GET['fulltext']; if ( Acronyms::update ( $acronym, $fulltext ) ) $message = 1; else $message = 4; wp_redirect( "$parent_file&message=$message" ); exit; break; case 'edit-acronym': $acronym = $_GET['acronym']; $fulltext = $_GET['fulltext']; check_admin_referer('edit_acronym'); if ( Acronyms::update ( $acronym, $fulltext ) ) $message = 3; else $message = 5; wp_redirect( "$parent_file&message=$message" ); exit; break; case 'delete-acronym': check_admin_referer('delete_acronym'); if ( !current_user_can('manage_categories') ) wp_die(__('Cheatin’ uh?')); $acronym = $_GET['acronym']; Acronyms::delete ( $acronym ); $message = 2; wp_redirect( "$parent_file&message=$message" ); exit; break; case 'delete-acronyms': check_admin_referer('delete-acronyms'); if ( !current_user_can('manage_categories') ) wp_die(__('Cheatin’ uh?')); $acronyms = $_GET['delete_acronyms']; foreach( (array) $acronyms as $acronym ) { Acronyms::delete ( $acronym ); } if ( 1 < ( count( $acronyms ) ) ) $message = 6; else $message = 2; wp_redirect( "$parent_file&message=$message" ); exit; break; case 'search': $s = '&s=' . urlencode( $_GET['search'] ); $p = isset( $_GET['p'] ) ? '&p=' . $_GET['p'] : ''; $n = isset( $_GET['n'] ) && 15 != $_GET['n'] ? '&n=' . $_GET['n'] : ''; wp_redirect( "$parent_file$s$p$n" ); } } } /** * Manage Acronyms page * * @return void **/ function manage_acronyms () { $domain = Acronyms::get_textdomain(); // Set any error/notice messages based on the 'message' GET value $message = $_GET['message']; $messages[1] = __( 'Acronym added.', $domain ); $messages[2] = __( 'Acronym deleted.', $domain ); $messages[3] = __( 'Acronym updated.', $domain ); $messages[4] = __( 'Acronym not added.', $domain ); $messages[5] = __( 'Acronym not updated.', $domain ); $messages[6] = __( 'Acronyms deleted.', $domain ); if ( isset( $message ) ) { ?>


' . __('add new', $domain ) . ')' ?>



acronyms. * Note: acronym replacement is case-sensitive. */ function acronym_replace ( $text ) { $acronyms = get_option( 'acronym_acronyms' ); $text = " $text "; foreach ( $acronyms as $acronym => $fulltext ) $text = preg_replace( "|(?!<[^<>]*?)(?!\[[^\[\]]*?)(?]*?>)|msU", "$acronym" , $text ); $text = trim($text); return $text; } /* string show_acronym_list ( string $s, int $n, int $p ) * * Displays the list of acronyms, filtered by search term $s and showing page # $p based on $n per page */ function show_acronym_list ( $s, $n, $p = '1' ) { $domain = Acronyms::get_textdomain(); // Sort the acronyms appropriately $acronyms = get_option( 'acronym_acronyms' ); uksort( $acronyms, "strnatcasecmp"); ?> $fulltext ) { if ( ( '' == $s ) || ( ( false !== strpos( strtolower( $acronym ), strtolower( $s ) ) ) || ( false !== strpos( strtolower( $fulltext ), strtolower( $s ) ) ) ) ) { if ( 0 == $n || ( ++$index >= $index_start && $index <= $index_end ) ) { ?>
') ) { return true;}return false;"/>
add_query_arg( 'p', '%#%' ), 'format' => '', 'total' => $t, 'current' => $p, 'add_args' => $n ) ); if ( 0 < $n && $page_links ) { echo '
'; $range = $n * ( $p - 1 ) + 1 . '-' . $n * $p; $total = Acronyms::acronyms_count( $s ); echo ''; _e( "Displaying $range of $total" ); echo ''; echo "$page_links
"; } ?>

'; $action = 'edit-acronym'; $nonce_action = 'edit_acronym'; } else { $heading = __( 'Add Acronym', $domain ); $submit_text = __( 'Add Acronym', $domain ); $form = '
'; $action = 'add-acronym'; $nonce_action = 'add_acronym'; } ?>

/>

', $domain ) ?>

' . __( 'Cancel' ) . '' ?>

$fulltext ) { if ( false !== strpos( strtolower( $acronym ), strtolower( $s ) ) || ( false !== strpos( strtolower( $fulltext ), strtolower( $s ) ) ) ) { $index++; } } return $index; } } /* string get_parent_url () * */ function get_parent_url() { return $_GET['page']; } } /* END CLASS acronyms */ add_action( 'admin_init', array( 'Acronyms', 'management_handler' ) ); register_activation_hook( __FILE__, array( 'Acronyms', 'install' ) ); add_filter( 'the_content', array( 'Acronyms', 'acronym_replace' ) ); add_filter( 'comment_text', array( 'Acronyms', 'acronym_replace' ) ); add_action( 'admin_menu', array( 'Acronyms', 'add_pages' ) ); ?>