Created
March 16, 2019 17:36
-
-
Save gregzawadzki/5cc599fbed512f607a73bcb84921b176 to your computer and use it in GitHub Desktop.
This processor is intended for use in Daux.io normalizing urls
This file contains hidden or 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
<?php | |
/** | |
* This processor is intended for use in Daux.io | |
* It may be dangerous in case you're not carefull while naming directories | |
* | |
* File Xxx.md and xxX.md would be translated into xxx.md | |
* File geś.md and gęs.md would become ges.md | |
* | |
* You've been warned :) | |
* | |
* @license dunno, some kind of free license, do whatever you want with this processor | |
* | |
* @author Grzegorz Zawadzki <[email protected]> | |
* | |
*/ | |
namespace Todaymade\Daux\Extension; | |
use Todaymade\Daux\Tree\Root; | |
class Processor extends \Todaymade\Daux\Processor | |
{ | |
public function manipulateTree(Root $root) | |
{ | |
$this->parseDirectory($root); | |
} | |
private function parseDirectory(\Todaymade\Daux\Tree\Directory $object) { | |
foreach($object->getEntries() as $tempname => $val) { | |
$this->updateUri($val); | |
if($val instanceof \Todaymade\Daux\Tree\Directory) | |
$this->parseDirectory($val); | |
} | |
} | |
private function updateUri(\Todaymade\Daux\Tree\Entry $object) { | |
$object->setUri($x = $this->fixString($object->getUri())); | |
} | |
private function fixString($str) { | |
// Taken from: https://stackoverflow.com/questions/3371697/replacing-accented-characters-php | |
$unwanted_array = array( | |
'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', | |
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', | |
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', | |
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', | |
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y' ); | |
return mb_strtolower(strtr( $str, $unwanted_array)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment