/** * Apply house style rules as the content is saved * * @param string $content * @return string */ public function ContentSavePre($content) { # Remove comments from the start of the text, because otherwise they can be taken to be the first paragraph. # Can't unilaterally remove all comments because WordPress "more" feature is implemented as a comment. $content = trim($content); while (strpos($content, "<!--") === 0) { $end_pos = strpos($content, "-->"); if ($end_pos === false) { break; } # avoid infinite loop $content = trim(substr($content, $end_pos + 3)); } # Expand lists of people at the start of meeting minutes. Matches from the prompt up to the end of the line $content = preg_replace_callback('/(\\n[0-9]+\\.)\\s*(Present|Apologies for absence):(.*)/', array($this, 'ListPeople_MatchEvaluator'), $content); $searches = array(); $replaces = array(); # Expand abbreviations and fix capitalisation/punctuation. # Use space rather than \b before SC and SE to avoid affecting links to filenames $searches[] = '/ SC\\b/'; $replaces[] = 'Stoolball Club'; $searches[] = '/ SE\\b/'; $replaces[] = 'Stoolball England'; $searches[] = '/([a-z,;\'-]\\s+)Leagues and Associations/'; # lowercase where it follows another word $replaces[] = '$1leagues and associations'; $searches[] = '/Leagues and Associations/'; # if previous didn't match, likely start of a sentence so leave the L uppercase $replaces[] = 'Leagues and associations'; # lowercase stoolball where it falls between two all-lowercase words, or at the end of a sentence after a lowercase word $searches[] = '/(\\b[a-z]+\\b\\s+)Stoolball\\b([.?!]|\\s+\\b[a-z])/'; $replaces[] = '$1stoolball$2'; $searches[] = '/[S|s]toolball [E|e]ngland/'; # ...but always capitalise Stoolball England $replaces[] = 'Stoolball England'; $searches[] = '/e-mail/'; $replaces[] = 'email'; $searches[] = '/web site/'; $replaces[] = 'website'; # Use Stoolball England email addresses foreach ($this->settings->GetPublicEmailAliases() as $private_email => $public_email) { $searches[] = '/\\b' . $private_email . '\\b/'; $replaces[] = $public_email; } # Tidy headings $searches[] = '/(<h[2-6]>.*?)<strong>(.*?)<\\/strong>(.*?<\\/h[2-6]>)/'; # strong within a heading (usually bold text converted to heading) $replaces[] = '$1$2$3'; # When pasting minutes, the numbered headings need a space after the number $searches[] = '/(\\n[0-9]+\\.)([A-Z])/'; $replaces[] = '$1 $2'; # When pasting minutes, automatically spot headers $searches[] = "/(\n)([0-9]+\\.\\s*.+):/"; $replaces[] = "\$1<h2>\$2</h2>" . chr(13) . chr(13); # When pasting minutes, tidy common phrase $searches[] = '/([0-9]+\\.\\s*Minutes of the last .* meeting): The Minutes/'; $replaces[] = '<h2>$1</h2>' . chr(13) . chr(13) . 'The minutes'; # No colons after headings $searches[] = '/(<h[2-6]>.*?):\\s*(<\\/h[2-6]>)/'; $replaces[] = '$1$2'; # Unwanted attributes $searches[] = '/ (align|lang)=[^ >]+/'; # broad match for characters used because not sure how to match " $replaces[] = ''; # Removing image height so that images can resize down in narrow windows using max-width 100% $searches[] = '/<img([^>]*) height=["0-9]+/'; $replaces[] = '<img$1'; # Unwanted styles # NOTE: Can leave ugly, unwanted spans with empty style attributes $searches[] = '/(font-size|margin-left|margin-bottom|margin-top|margin-right|font-family)\\s*:\\s*[A-Za-z-0-9,;]+;?/'; $replaces[] = ''; # Empty tags $searches[] = '/<p( [^>]*)?>\\s*<\\/p>/'; $replaces[] = ''; $searches[] = '/<span>([^<]*)<\\/span>/'; $replaces[] = '$1'; # No superscript for ordinals $searches[] = '/([0-9]+)<sup>?(st|nd|rd|th)\\s*<\\/sup>/'; $replaces[] = '$1$2'; # No tabs or multiple spaces $searches[] = '/ /'; $replaces[] = ' '; $searches[] = '/[\\t ]+/'; $replaces[] = ' '; # Fix time punctuation $searches[] = '/\\b([0-9]+)(\\.|:)([0-9]+)\\s*(a|p)\\s*\\.?\\s*m\\.?\\b/'; # with minutes $replaces[] = '$1.$3$4m'; $searches[] = '/\\b([0-9]+)\\s*(a|p)\\s*\\.?\\s*m\\.?\\b/'; # without minutes $replaces[] = '$1$2m'; $searches[] = '/\\b([0-9]+)\\.00(am|pm)\\b/'; # remove .00 minutes $replaces[] = '$1$2'; $searches[] = '/\\b([0-9]{1,2})(\\.[0-9]{1,2})?(am|pm).(\\s+[a-z])/'; # remove stray . after am/pm when followed by lowercase $replaces[] = '$1$2$3$4'; # Fix dates $searches[] = '/(January|February|March|April|May|June|July|August|September|October|November|December)\\s+([0-9]{1,2})(st|nd|rd|th)?\\b/'; # We're not American $replaces[] = '$2 $1'; $searches[] = '/([0-9]{1,2})(<sup>)?(st|nd|rd|th)\\s*(<\\/sup>)?\\s*(January|February|March|April|May|June|July|August|September|October|November|December)/'; # Remove ordinals $replaces[] = '$1 $5'; $searches[] = '/(January|February|March|April|May|June|July|August|September|October|November|December),\\s+([0-9]{4})\\b/'; # Remove comma between month and year $replaces[] = '$1 $2'; $searches[] = '/(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),\\s+([0-9]{1,2})\\s+(January|February|March|April|May|June|July|August|September|October|November|December)/'; # Remove comma between day and date $replaces[] = '$1 $2 $3'; # Fix Kay's signoff $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).1.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 January $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).2.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 February $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).3.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 March $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).4.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 April $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).5.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 May $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).6.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 June $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).7.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 July $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).8.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 August $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).9.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 September $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).10.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 October $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).11.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 November $2'; $searches[] = '/KRP\\/JEP\\/([0-9]{1,2}).12.(20[0-9][0-9])/'; $replaces[] = 'John and Kay Price' . chr(13) . '$1 December $2'; $content = preg_replace($searches, $replaces, $content); # Expand common abbreviations at first mention # $content = $this->ExpandAbbreviation('SE', 'Stoolball England', $content); return $content; }