Permalink
Browse files

It works, with hackish title fix

  • Loading branch information...
betweenbrain committed May 15, 2012
1 parent 4c66aa5 commit 37a54a700445af0ccc644d44df5419f025f47b7b
Showing with 38 additions and 35 deletions.
  1. +38 −35 notranslate.php
View
@@ -5,54 +5,57 @@
class plgSystemNotranslate extends JPlugin
{
- function plgSystemNotranslate( &$subject, $config )
- {
- parent::__construct( $subject, $config );
- }
+ function plgSystemNotranslate( &$subject, $config ) {
+ parent::__construct( $subject, $config );
+ }
- function onAfterRender() {
- $app = JFactory::getApplication();
+ function onAfterRender() {
+ $app = JFactory::getApplication();
- if($app->isAdmin()) {
- return;
- }
+ if($app->isAdmin()) {
+ return;
+ }
- $buffer = JResponse::getBody();
- /*
- $buffer = preg_replace("/($targets)/i",'<i style="color:red;">\1</i>',$buffer);
- JResponse::setBody($buffer);
- */
+ $buffer = JResponse::getBody();
+ $targets = $this->params->get('exemptions');
+ $targets = explode(',', $targets);
- // Suppress errors - http://nl3.php.net/manual/en/function.libxml-use-internal-errors.php
- libxml_use_internal_errors(true);
+ /*
+ foreach ($targets as $target) {
+ $buffer = preg_replace("/($target)/i",'<span class="notranslate" style="color:red;width:auto;">\1</span>',$buffer);
+ }
+ JResponse::setBody($buffer);
+ */
- $doc = new DOMDocument;
- $doc->loadHTML($buffer);
- $xpath = new DOMXPath($doc);
+ // Suppress errors - http://nl3.php.net/manual/en/function.libxml-use-internal-errors.php
+ libxml_use_internal_errors(true);
- $targets = $this->params->get('exemptions');
- $targets = explode(',', $targets);
+ $doc = new DOMDocument;
+ $doc->loadHTML($buffer);
+ $xpath = new DOMXPath($doc);
- foreach ($targets as $target) {
+ foreach ($targets as $target) {
- // echo '<br/>Target: '.$target.'<br/>';
+ // echo '<br/>Target: '.$target.'<br/>';
+ $query = "//*[contains(text(),'$target')]";
- $query = "//*[contains(text(),'$target')]";
+ foreach($xpath->query($query) as $match) {
- foreach($xpath->query($query) as $match) {
+ $match = $match->textContent;
+ // echo 'Match: '.$match.'<br/>';
- $match = $match->textContent;
- // echo 'Match: '.$match.'<br/>';
+ $replacement = preg_replace("/($target)/i",'<span class="notranslate" style="color:red;width:auto;">\1</span>',$match);
+ // echo 'Replacement: '.$replacement.'<br/>';
- $replacement = preg_replace("/($target)/i",'<i class="notranslate" style="color:red;">\1</i>',$match);
- // echo 'Replt: '.$replacement.'<br/>';
+ $buffer = str_replace($match, $replacement, $buffer);
- $buffer = str_replace($match, $replacement, $buffer);
- JResponse::setBody($buffer);
- }
+ // Hackish fix for title text being altered
+ $buffer = preg_replace('/title=\"(.*?)\"/','',$buffer);
- }
+ JResponse::setBody($buffer);
+ }
+ }
- return true;
- }
+ return true;
+ }
}

0 comments on commit 37a54a7

Please sign in to comment.