Personal #cms#php 2 min

Blog:CMS tips & tricks: Acronyms

Translation of the original in Catalan. Read it in: CatalàCastellano

In the blogcms forum I find a small modification of the NP_FancyText plug-in. What this modification does is, if it finds some acronyms in our text, it formats them with the acronym command. The cool thing would be that, instead of having the acronym definitions hard-coded, this would be in a table of the extraskins, so we could modify the acronyms without having to edit the code every time. For now I don't think I'll program it, since I don't use this feature much, I suppose out of laziness.

(at line 324)

Code:

$acronym_list = array(
 ‘ASP’ => ‘Active Server Pages’,
 ‘API’ => ‘Application Programming Interface’,
 ‘CD’ => ‘Compact Disk’,
 ‘CEO’ => ‘Chief Executive Officer’,
 ‘CGI’ => ‘Common Gateway Interface’,
 ‘CMS’ => ‘Content Management System’,
 ‘CSS’ => ‘Cascading Style Sheets’,
 ‘CVS’ => ‘Concurrent Versions System’,
 ‘DNS’ => ‘Domain Name System’,
 ‘DOM’ => ‘Document Object Model’,
 ‘DTD’ => ‘Document Type Definition’,
 ‘DVD’ => ‘Digital Versatile Disc’,
 ‘FAQ’ => ‘Frequently Asked Question’,
 ‘GB’ => ‘GigaByte’,
 ‘GPL’ => ‘GNU General Public License’,
 ‘GUI’ => ‘Graphical User Interface’,
 ‘GIF’ => ‘Graphic Interchange Format’,
 ‘HTML’ => ‘HyperText Markup Language’,
 ‘HTTP’ => ‘HyperText Transfer Protocol’,
 ‘IDE’ => ‘Integrated Development Environment / Intergrated Drive Electronics’,
 ‘IE’ => ‘Internet Explorer’,
 ‘IIS’ => ‘Internet Infomation Server’,
 ‘IM’ => ‘Instant Message/Messaging’,
 ‘IRC’ => ‘Internet Relay Chat’,
 ‘JSP’ => ‘Java Server Pages’,
 ‘JPG’ => ‘Joint Photographic experts Group’,
 ‘JPEG’ => ‘Joint Photographic Experts Group’,
 ‘KB’ => ‘KiloByte’,
 ‘MB’ => ‘MegaByte’,
 ‘MP3’ => ‘MPEG 1 audio layer 3’,
 ‘MS’ => ‘MicroSoft’,
 ‘MSDN’ => ‘MicroSoft Developer Network’,
 ‘MSIE’ => ‘MicroSoft Internet Explorer’,
 ‘MSN’ => ‘MicroSoft Network’,
 ‘NNTP’ => ‘Network News Transfer Protocol’,
 ‘P2P’ => ‘Peer To Peer’,
 ‘PDF’ => ‘Portable Document Format’,
 ‘GC’ => ‘Generated Content’,
 ‘PHP’ => ‘PHP: Hypertext Preprocessor’,
 ‘PNG’ => ‘Portable Network Graphics’,
 ‘RSS’ => ‘Really Simple Syndication’,
 ‘RTF’ => ‘Rich Text Format’,
 ‘SOAP’ => ‘Search Engine Optimisation’,
 ‘SOAP’ => ‘Simple Object Access Protocol’,
 ‘SSL’ => ‘Secured Sockets Layer’,
 ‘SVG’ => ‘Scalable Vector Graphics’,
 ‘TCP’ => ‘Transmission Control Protocol’,
 ‘URI’ => ‘Uniform Resource Identifier’,
 ‘URL’ => ‘Uniform Resource Locator’,
 ‘USB’ => ‘Universal Serial Bus’,
 ‘UI’ => ‘User Interface’,
 ‘VNC’ => ‘Virtual Network Computing’,
 ‘W3C’ => ‘World Wide Web Consortium’,
 ‘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 Transformation’,
 ‘XUL’ => ‘XML-based User interface Language’,
 ‘LI’ => ‘List Item’,
 ‘DIV’ => ‘DIVision’,
 ‘ABBR’ => ‘ABBReviation’,
 ‘P’ => ‘Paragraph’,
 ‘PRE’ => ‘PREformatted text’,
 ‘UL’ => ‘Unordered List’,
 ‘OL’ => ‘Ordered List’,
 ‘TR’ => ‘Table Row’,
 ‘TH’ => ‘Table Header cell’,
 ‘TD’ => ‘Table Data cell’,
 ‘A’ => ‘Anchor’,
 ‘IMG’ => ‘IMaGe’,
 ‘EM’ => ‘EMphasis’,
 ‘DEL’ => ‘DELeted text’,
 ‘INS’ => ‘INSerted text’,
 ‘KBD’ => ‘KeyBoarD input’,
 ‘IFRAME’ => ‘Inline FRAME’,
 ‘DIR’ => ‘DIRectory list’,
 ‘DL’ => ‘Definition List’,
 ‘DT’ => ‘Definition Term’,
 ‘DD’ => ‘Definition Description’,
 ‘EUR’ => ‘EURo’,
 ‘SAMP’ => ‘SAMPle output’,
 ‘USD’ => ‘United States Dollars’
);
foreach ($acronym_list as $acronym => $description) {
 $data = preg_replace("|(?<!<)(?<!:)\b$acronym\b(?!>)|msU" , "<acronym title=\"$description\">$acronym</acronym>" , $data);
 $data = preg_replace("|(<[A-Za-z]* [^>]*)<acronym title=\"$description\">$acronym</acronym>([^<]*>)|msU", "$1$acronym$2" , $data);
 $data = preg_replace("|[$]<acronym title=\"$description\">$acronym</acronym>[$]|msU", "$acronym", $data);
}