-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from matecat/@@-syntax
@@ syntax
- Loading branch information
Showing
6 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Matecat\SubFiltering\Filters; | ||
|
||
use Matecat\SubFiltering\Commons\AbstractHandler; | ||
use Matecat\SubFiltering\Commons\Constants; | ||
|
||
class Snails extends AbstractHandler | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function transform( $segment ) | ||
{ | ||
preg_match_all( '/@@[^<>\s]+?@@|@[^<>\s@]+?@/', $segment, $html, PREG_SET_ORDER ); | ||
foreach ( $html as $pos => $snail_variable ) { | ||
//check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag | ||
if( !strstr($snail_variable[0], Constants::GTPLACEHOLDER) ){ | ||
//replace subsequent elements excluding already encoded | ||
$segment = preg_replace( | ||
'/' . preg_quote( $snail_variable[0], '/' ) . '/', | ||
'<ph id="__mtc_' . $this->getPipeline()->getNextId() . '" equiv-text="base64:' . base64_encode( $snail_variable[ 0 ] ) . '"/>', | ||
$segment, | ||
1 | ||
); | ||
} | ||
} | ||
|
||
return $segment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters