Skip to content

Instantly share code, notes, and snippets.

@faitno
Created November 16, 2015 12:43
Show Gist options
  • Save faitno/bf202b14173f5d41717f to your computer and use it in GitHub Desktop.
Save faitno/bf202b14173f5d41717f to your computer and use it in GitHub Desktop.
Add custom modificator to fenom on modx
<?php
// /core/model/modx/pdotools/pdotoolscustom.class.php
require_once MODX_CORE_PATH . 'components/pdotools/model/pdotools/pdotools.class.php';
class pdotoolscustom extends pdoTools {
public function getFenom() {
if (!$this->fenom) {
try {
if (!class_exists('Fenom')) {
require MODX_CORE_PATH . 'components/pdotools/model/' . '/fenom/Fenom.php';
require MODX_CORE_PATH . 'components/pdotools/model/' . '/fenom/Fenom/ProviderInterface.php';
require MODX_CORE_PATH . 'components/pdotools/model/' . '/fenom/Providers/ModChunk.php';
require MODX_CORE_PATH . 'components/pdotools/model/' . '/fenom/Providers/ModTemplate.php';
Fenom::registerAutoload();
}
$cache = MODX_CORE_PATH . 'cache/';
if (!file_exists($cache)) {
mkdir($cache);
}
$this->fenom = Fenom::factory(new modChunkProvider($this), $cache);
$this->fenom->addProvider('template', new modTemplateProvider($this));
$default_options = array(
'force_compile' => true,
'disable_cache' => true,
'force_include' => true,
);
if (!$this->modx->getOption('pdotools_fenom_php', null, false)) {
$this->fenom->removeAccessor('php');
$default_options['disable_native_funcs'] = true;
}
if ($options = $this->modx->fromJSON($this->modx->getOption('pdotools_fenom_options'))) {
$options = array_merge($options, $default_options);
}
else {
$options = $default_options;
}
$this->fenom->setOptions($options);
$this->fenom->addModifier('days', function ($day) {
$a=substr($day,strlen($day)-1,1);
if($a==1) $str="день";
if($a==2 || $a==3 || $a==4) $str="дня";
if($a==5 || $a==6 || $a==7 || $a==8 || $a==9 || $a==0) $str="дней";
return $str;
});
}
catch (Exception $e) {
$this->modx->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage());
return false;
}
}
return $this->fenom;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment