Plugin Directory

Changeset 1247838


Ignore:
Timestamp:
09/17/2015 05:55:59 PM (10 years ago)
Author:
mobileappbuilder
Message:

FIX: Wordpress plugin doesn't parse / escape accented characters correctly for article body (SE-19983)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mobile-app-api/trunk/model/class-shoutem-posts-dao.php

    r1232731 r1247838  
    295295    $content = '<figure>'.$content.'<figcaption class="image-caption">'.$attr['caption'].'</figcaption>'.'</figure>';
    296296
    297     $dom = new DOMDocument();
    298     @$dom->loadHTML(do_shortcode(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')));
     297    $dom = shoutem_html_load($content);
    299298    foreach ($dom->getElementsByTagName('img') as $img) {
    300299        $img->setAttribute('caption', $attr['caption']);
     
    303302        }
    304303    }
    305 
    306     $output = substr($dom->saveXML($dom->getElementsByTagName('body')->item(0)), 6, -7);
    307     return mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8');
     304    return shoutem_html_save($dom);
    308305}
    309306
     
    327324    }
    328325
    329     $dom = new DOMDocument();
    330     // supress warnings caused by HTML5 tags
    331     @$dom->loadHTML('<?xml encoding="UTF-8">'.mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
     326    $dom = shoutem_html_load($content);
    332327
    333328    $nodes_to_wrap = array();
     
    353348    }
    354349
    355     $output = substr($dom->saveXML($dom->getElementsByTagName('body')->item(0)), 6, -7);
    356     return mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8');
     350    return shoutem_html_save($dom);
     351}
     352
     353function shoutem_html_load($html) {
     354    if (function_exists('mb_encode_numericentity')) {
     355        $html = mb_encode_numericentity($html, array (0x80, 0xffff, 0, 0xffff), 'UTF-8');
     356    }
     357    $dom = new DOMDocument();
     358    // supress warnings caused by HTML5 tags
     359    @$dom->loadHTML('<?xml encoding="UTF-8">'.$html);
     360    return $dom;
     361}
     362
     363function shoutem_html_save($dom) {
     364    $html = substr($dom->saveXML($dom->getElementsByTagName('body')->item(0)), 6, -7);
     365    if (function_exists('mb_decode_numericentity')) {
     366        $html = mb_decode_numericentity($html, array (0x80, 0xffff, 0, 0xffff), 'UTF-8');
     367    }
     368    return $html;
    357369}
    358370
Note: See TracChangeset for help on using the changeset viewer.