Changeset 653 for trunk/lib


Ignore:
Timestamp:
Nov 28, 2018 1:40:13 AM (5 years ago)
Author:
anonymous
Message:

Update fancyTxt()

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Prefs.inc.php

    r644 r653  
    518518        // User_id must not be empty.
    519519        if ('' == $this->getParam('user_id')) {
    520             $app->logMsg(sprintf('Cannot save prefs because user_id not set.', null), LOG_WARNING, __FILE__, __LINE__);
     520            $app->logMsg(sprintf('Cannot load prefs because user_id not set.', null), LOG_WARNING, __FILE__, __LINE__);
    521521            return false;
    522522        }
     
    591591        // Skip this method if not using the db.
    592592        if ('database' != $this->getParam('storagetype')) {
    593             $app->logMsg('Prefs->save() does nothing unless using a database storagetype.', LOG_NOTICE, __FILE__, __LINE__);
     593            $app->logMsg('Prefs->save() does nothing unless using a database storagetype.', LOG_DEBUG, __FILE__, __LINE__);
    594594            return true;
    595595        }
     
    597597        // User_id must not be empty.
    598598        if ('' == $this->getParam('user_id')) {
    599             $app->logMsg(sprintf('Cannot save prefs because user_id not set.', null), LOG_WARNING, __FILE__, __LINE__);
     599            $app->logMsg(sprintf('Cannot save prefs because user_id not set.', null), LOG_DEBUG, __FILE__, __LINE__);
    600600            return false;
    601601        }
  • trunk/lib/Utilities.inc.php

    r652 r653  
    221221 * @return string         Cleaned text.
    222222 */
    223 function fancyTxt($text)
     223function fancyTxt($text, $extra_search=null, $extra_replace=null)
    224224{
    225225    $search = array();
    226226    $replace = array();
    227227
    228     // "double quoted text"  becomes  “double quoted text”
    229     $search['double_quotes']    = '/(^|[^\w=])(?:"|"|"|"|“)([^"]+?)(?:"|"|"|"|”)([^\w]|$)/ms'; // " is the same as " and " and "
    230     $replace['double_quotes']   = '$1“$2”$3';
    231 
    232     // text's apostrophes  become  text’s apostrophes
    233     $search['apostrophe']       = '/(\w)(?:\'|'|')(\w)/ms';
    234     $replace['apostrophe']      = '$1’$2';
    235 
    236     // 'single quoted text'  becomes  ‘single quoted text’
    237     $search['single_quotes']    = '/(^|[^\w=])(?:\'|'|‘)([^\']+?)(?:\'|'|’)([^\w]|$)/ms';
    238     $replace['single_quotes']   = '$1‘$2’$3';
    239 
    240     // plural posessives' apostrophes become posessives’
    241     $search['apostrophes']      = '/(s)(?:\'|'|')(\s)/ms';
    242     $replace['apostrophes']     = '$1’$2';
    243 
    244     // em--dashes  become em—dashes
    245     $search['em_dash']          = '/(\s*[^!<-])--([^>-]\s*)/';
    246     $replace['em_dash']         = '$1&mdash;$2';
    247 
    248     return preg_replace($search, $replace, $text);
     228    // "double quoted text"  →  “double quoted text”
     229    $search['_double_quotes']    = '/(?<=^|[^\w=(])(?:"|&quot;|&#0?34;|&#x22;|&ldquo;)([\w\'.
(—–-][^"]*?)(?:"|&quot;|&#0?34;|&#x22;|&rdquo;)(?=[^)\w]|$)/imsu'; // " is the same as &quot; and &#34; and &#034; and &#x22;
     230    $replace['_double_quotes']   = '“$1”';
     231
     232    // text's apostrophes  →  text’s apostrophes (except foot marks: 6'3")
     233    $search['_apostrophe']       = '/(?<=[a-z])(?:\'|&#0?39;)(?=\w)/imsu';
     234    $replace['_apostrophe']      = '’';
     235
     236    // 'single quoted text'  →  ‘single quoted text’
     237    $search['_single_quotes']    = '/(?<=^|[^\w=(])(?:\'|&#0?39;|&lsquo;)([\w"][^\']+?)(?:\'|&#0?39;|&rsquo;)(?=[^)\w]|$)/imsu';
     238    $replace['_single_quotes']   = '‘$1’';
     239
     240    // plural posessives' apostrophes  →  posessives’  (except foot marks: 6')
     241    $search['_apostrophes']      = '/(?<=s)(?:\'|&#0?39;|&rsquo;)(?=\s)/imsu';
     242    $replace['_apostrophes']     = '’';
     243
     244    // double--hyphens  →  en — dashes
     245    $search['_em_dash']          = '/(?<=[\w\s"\'”’)])--(?=[\w\s“”‘"\'(?])/imsu';
     246    $replace['_em_dash']         = ' – ';
     247
     248    // ...  →  

     249    $search['_elipsis']          = '/(?<=^|[^.])\.\.\.(?=[^.]|$)/imsu';
     250    $replace['_elipsis']         = '
';
     251
     252    if (is_array($extra_search) && is_array($extra_replace) && sizeof($extra_search) == sizeof($extra_replace)) {
     253        // Append additional search replacements.
     254        $search = array_merge($search, $extra_search);
     255        $replace = array_merge($replace, $extra_replace);
     256    }
     257
     258    return trim(preg_replace($search, $replace, $text));
    249259}
    250260
Note: See TracChangeset for help on using the changeset viewer.