Skip to content
Browse files

Merge prep

  • Loading branch information...
1 parent 49d1ccb commit f101b9d0bc05faebc656aa774be874dd13fae74a @betweenbrain committed
Showing with 0 additions and 82 deletions.
  1. +0 −82 notranslate.php
View
82 notranslate.php
@@ -1,82 +0,0 @@
-<?php defined('_JEXEC') or die;
-
-jimport('joomla.plugin.plugin');
-
-class plgSystemNotranslate extends JPlugin
-{
-
- function plgSystemNotranslate(&$subject, $config)
- {
- parent::__construct($subject, $config);
- }
-
- function onAfterRender()
- {
- $app = JFactory::getApplication();
-
- if ($app->isAdmin()) {
- return;
- }
-
- $buffer = JResponse::getBody();
- $targets = $this->params->get('targets');
- $targets = explode(',', $targets);
-
- // Suppress errors - http://nl3.php.net/manual/en/function.libxml-use-internal-errors.php
- libxml_use_internal_errors(true);
-
- // Set up xpath goodness
- $doc = new DOMDocument;
- $doc->loadHTML($buffer);
- $xpath = new DOMXPath($doc);
-
- $i = '';
-
- foreach ($targets as $target) {
-
- $query = $xpath->evaluate("//*[contains(.,'" . trim($target) . "')]");
-
- foreach ($query as $match) {
-
- // String representation of a DOMElement - preserves HTML markup - http://www.php.net/manual/en/class.domelement.php#97570
- $match = $doc->saveXML($match);
-
- $hit = '<span class="notranslate" style="width:auto;">' . $target . '</span>';
-
- $replacement = preg_replace("/($target)/i", $hit, $match);
-
- // Skip previous replacements
- if (preg_match('/class=\"notranslate\"/', $match)) {
- continue;
- }
- // Skip document head
- elseif (preg_match('<(head|title)>', $match)) {
- continue;
- }
- // Skip matches with title attribute (HTML in the title is bad!)
- // TODO: Need to find a way to target inner contents of element that have title tag.
- // TODO: Need to filter attribute based on contents of attribute, not just presence of it.
- elseif (preg_match('/(title)=\"(.*?)\"/', $match, $attributes)) {
- // echo "Matched attributes: ".$attributes[0].'<br/>';
- // $matches = explode($attributes[0], $match);
- // echo 'Splinter: '.$matches[1].'<br/>';
- continue;
- } else {
-
- // Increment match count
- $i++;
-
- $buffer = str_replace($match, $replacement, $buffer);
-
- JResponse::setBody($buffer);
- }
- }
- }
-
- if ($this->params->get('showmatches') == 1) {
- echo '<p style="margin:0;padding:.5em;position:absolute;top:0;left:0;">Matches: ' . $i . '</p>';
- }
-
- return true;
- }
-}

0 comments on commit f101b9d

Please sign in to comment.
Something went wrong with that request. Please try again.