t('Pirate filter')); case 'description': return t('Ah, Squiddy! I got nothing against ye. I just heard there was gold in yer belly. Ha ha har, ha ha ha har!'); case 'settings': return _pirate_filter_settings(); case 'process': if (format_date(time(), 'custom', 'md') != '0919') { return $text; } // Invoke hook_captain(). Also allows other modules to alter our patterns. // Cache must be flushed for invocations of this hook to be felt. $patterns = array(); $patterns = module_invoke_all('captain', $patterns); // Most of the following code is taken from Drupal 7 core's Filter module // in order to exclude text within tags, such as URLs that might get // modified using the replacement patterns. $ignore_tags = 'a|script|style|code|pre'; $open_tag = ''; $chunks = preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($patterns as $pattern_search => $pattern_replace) { $chunk_type = 'text'; for ($i = 0; $i < count($chunks); $i++) { if ($chunk_type == 'text') { // Only process this text if there are no unclosed $ignore_tags. if ($open_tag == '') { // If there is a match, inject a link into this chunk via the callback // function contained in $task. $chunks[$i] = preg_replace($pattern_search, $pattern_replace, $chunks[$i]); } // Text chunk is done, so next chunk must be a tag. $chunk_type = 'tag'; } else { // Only process this tag if there are no unclosed $ignore_tags. if ($open_tag == '') { // Check whether this tag is contained in $ignore_tags. if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) { $open_tag = $matches[1]; } } // Otherwise, check whether this is the closing tag for $open_tag. else { if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) { $open_tag = ''; } } // Tag chunk is done, so next chunk must be text. $chunk_type = 'text'; } } $text = implode($chunks); } return $text; default: return $text; } } /** * Implement hook_captain(). */ function pirate_captain($patterns) { $pirate_patterns = array( '%\bmy\b%' => 'me', '%\bboss\b%' => 'admiral', '%\bmanager\b%' => 'admiral', '%\b[Cc]aptain\b%' => "Cap'n", '%\bmyself\b%' => 'meself', '%\byour\b%' => 'yer', '%\byou\b%' => 'ye', '%\bfriend\b%' => 'matey', '%\bfriends\b%' => 'maties', '%\bco[-]?worker\b%' => 'shipmate', '%\bco[-]?workers\b%' => 'shipmates', '%\bpeople\b%' => 'scallywags', '%\bearlier\b%' => 'afore', '%\bold\b%' => 'auld', '%\bthe\b%' => "th'", '%\bof\b%' => "o'", "%\bdon't\b%" => "dern't", '%\bdo not\b%' => "dern't", '%\bnever\b%' => "no nay ne'er", '%\bever\b%' => "e'er", '%\bover\b%' => "o'er", '%\bYes\b%' => 'Aye', '%\bNo\b%' => 'Nay', '%\bYeah\b%' => 'Aye', '%\byeah\b%' => 'aye', '%\bare\b%' => 'be', '%\bDrupalists\b%' => 'Bucaneers', '%\bthere\b%' => 'thar', '%b\bnot\b%' => 'nay', '%\bdesign\b%' => 'bounty', '%\bonline\b%' => 'on the plank', '/and\b/' => "an'", '/ious\b/' => "i'us", "%\bdon't know\b%" => "dinna", "%\bdidn't know\b%" => "did nay know", "%\bhadn't\b%" => "ha'nae", "%\bdidn't\b%" => "di'nae", "%\bwasn't\b%" => "weren't", "%\bhaven't\b%" => "ha'nae", '%\bfor\b%' => 'fer', '%\bbetween\b%' => 'betwixt', '%\baround\b%' => "aroun'", '%\bto\b%' => "t'", "%\bit's\b%" => "'tis", '%\bwoman\b%' => 'wench', '%\bwomen\b%' => 'wenches', '%\blady\b%' => 'wench', '%\bwife\b%' => 'lady', '%\bgirl\b%' => 'lass', '%\bgirls\b%' => 'lassies', '%\bguy\b%' => 'lubber', '%\bman\b%' => 'lubber', '%\bfellow\b%' => 'lubber', '%\bdude\b%' => 'lubber', '%\bboy\b%' => 'lad', '%\bboys\b%' => 'laddies', '%\bchildren\b%' => 'little sandcrabs', '%\bkids\b%' => 'minnows', '%\bhim\b%' => 'that scurvey dog', '%\bher\b%' => 'that comely wench', '%\bhim\.\b%' => 'that drunken sailor', '%\bHe\b%' => 'The ornery cuss', '%\bShe\b%' => 'The winsome lass', "%\bhe's\b%" => 'he be', "%\bshe's\b%" => 'she be', '%\bwas\b%' => "were bein'", '%\bHey\b%' => 'Avast', '%\bher\.\b%' => 'that lovely lass', '%\bfood\b%' => 'chow', '%\bmoney\b%' => 'dubloons', '%\bdollars\b%' => 'pieces of eight', '%\bcents\b%' => 'shillings', '%\broad\b%' => 'sea', '%\broads\b%' => 'seas', '%\bstreet\b%' => 'river', '%\bstreets\b%' => 'rivers', '%\bhighway\b%' => 'ocean', '%\bhighways\b%' => 'oceans', '%\binterstate\b%' => 'high sea', '%\bprobably\b%' => 'likely', '%\bidea\b%' => 'notion', '%\bcar\b%' => 'boat', '%\bcars\b%' => 'boats', '%\btruck\b%' => 'schooner', '%\btrucks\b%' => 'schooners', '%\bSUV\b%' => 'ship', '%\bairplane\b%' => 'flying machine', '%\bjet\b%' => 'flying machine', '%\bmachine\b%' => 'contraption', '%\bdriving\b%' => 'sailing', '%\bunderstand\b%' => 'reckon', '%\bdrive\b%' => 'sail', '%\bdied\b%' => 'snuffed it', '/ing\b/' => "in'", '/ings\b/' => "in's", // These next two do cool random substitutions. '/(\.\s)/e' => 'avast("$0",3)', '/([!\?]\s)/e' => 'avast("$0",2)', // Greater chance after exclamation. ); return array_merge($pirate_patterns, $patterns); } /** * Implementation of hook_filter_tips(). */ function pirate_filter_tips($delta, $format, $long = FALSE) { return variable_get('pirate_display_tip', 1) ? "Avast! This website be taken over by pirates on September 19th. Yarr!" : ''; } /** * Settings for the Pirate filter. */ function _pirate_filter_settings() { $form['pirate_filter'] = array( '#type' => 'fieldset', '#title' => t('Pirate filter'), ); $form['pirate_filter']['pirate_display_tip'] = array( '#title' => t('Display Pirate filter tip'), '#description' => t('In case you want to make it a surprise on September 19th that pirates have taken over your site.'), '#type' => 'checkbox', '#default_value' => variable_get('pirate_display_tip', 1), ); return $form; } // Support function for pirate(). // this could probably be refactored to make it more generic, allowing // different filters to pass their own patterns in. function avast($stub = '', $chance = 5) { $shouts = array( ", avast$stub", "$stub Ahoy!", ", and a bottle of rum!", ", by Blackbeard's sword$stub", ", by Davy Jones' locker$stub", "$stub Walk the plank!", "$stub Aarrr!", "$stub Yaaarrrrr!", ", pass the grog!", ", and dinna spare the whip!", ", with a chest full of booty$stub", ", and a bucket o' chum$stub", ", we'll keel-haul ye!", "$stub Shiver me timbers!", "$stub And hoist the mainsail!", "$stub And swab the deck!", ", ye scurvey dog$stub", "$stub Fire the cannons!", ", to be sure$stub", ", I'll warrant ye$stub", ", on a dead man's chest!", "$stub Load the cannons!", "$stub Prepare to be boarded!", ", I'll warrant ye$stub", "$stub Ye'll be sleepin' with the fishes!", "$stub The sharks will eat well tonight!", "$stub Oho!", "$stub Fetch me spyglass!", ", shiver me timbers", ", yo ho, ho", ", ya bilge rat!", ", Get out of me rum!", ", feed the fishes", ", me Jolly Roger", ", Ya horn swogglin' scurvy cur!", ", Ya swabbie!", ", All Hands Hoay!", ", Avast me hearties!", ", Dance the Hempen Jig", ", Hornswaggle", ", Ya lily livered swabbie!", ); shuffle($shouts); return (((1 == rand(1, $chance))?array_shift($shouts):$stub) . ' '); }