<acronym> or <abbr> markup. Allows users to manage lists of acronyms and abbreviations 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: 2.0.0 Author: Chris Cox Author URI: http://www.renaissance-design.net Copyright 20011 Chris Cox 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' => 'PHP: Hypertext Preprocessor (recursive acronym)', '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); // Add default options -- Options not currently modifiable by user add_option('acronym_content', 1); add_option('acronym_comments', 1); Acronyms::theme_html5_check(); } /* string get_textdomain () * * returns the text domain to be used for internationalisation */ function get_textdomain() { return "Acronyms"; } /* void uninstall () */ function uninstall() { delete_option('acronym_acronyms'); delete_option('acronym_content'); delete_option('acronym_comments'); delete_option('acronym_html5'); } /** * 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, dirname( plugin_basename( __FILE__ ) ) ); $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 ) . ')' ?>



'; $header = file_get_contents(get_template_directory() . '/header.php'); if (strpos($header, $doctype) !== false) { update_option('acronym_html5', 1); } else { update_option('acronym_html5', 0); } } /* string acronym_replace ( string $text, array $acronyms ) * * Replaces known acronyms in $text with appropriate acronyms. * Note: acronym replacement is case-sensitive. */ function acronym_replace($text) { $acronyms = get_option('acronym_acronyms'); $html5 = get_option('acronym_html5'); $text = " $text "; if ($html5 == 1) { foreach ($acronyms as $acronym => $fulltext) { $text = preg_replace("|(?!<[^<>]*?)(?]*?>)|msU", "$acronym", $text); } } else { 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::count_acronyms($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')); register_uninstall_hook( __FILE__, array( 'Acronyms', 'uninstall' ) ); if (1 == get_option('acronym_content')) add_filter('the_content', array('Acronyms', 'acronym_replace')); if (1 == get_option('acronym_comments')) add_filter('comment_text', array('Acronyms', 'acronym_replace')); add_action('admin_menu', array('Acronyms', 'add_pages')); add_action('switch_theme', array('Acronyms', 'theme_html5_check')); ?>