/** * @covers \Alchemy\Phrasea\Controller\Admin\ConnectedUsers::appName */ public function testAppName() { $appNameResult = ConnectedUsers::appName(self::$DI['app']['translator'], 1000); $this->assertNull($appNameResult); $appNameResult = ConnectedUsers::appName(self::$DI['app']['translator'], 0); $this->assertTrue(is_string($appNameResult)); }
public function setupTwig() { $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) { $paths = (require $app['plugins.directory'] . '/twig-paths.php'); if ($app['browser']->isTablet() || $app['browser']->isMobile()) { $paths[] = $app['root.path'] . '/config/templates/mobile'; $paths[] = $app['root.path'] . '/templates/mobile'; $paths['phraseanet'] = $app['root.path'] . '/config/templates/mobile'; $paths['phraseanet'] = $app['root.path'] . '/templates/mobile'; } $paths[] = $app['root.path'] . '/config/templates/web'; $paths[] = $app['root.path'] . '/templates/web'; $paths['phraseanet'] = $app['root.path'] . '/config/templates/web'; $paths['phraseanet'] = $app['root.path'] . '/templates/web'; foreach ($paths as $namespace => $path) { if (!is_int($namespace)) { $app['twig.loader.filesystem']->addPath($path, $namespace); } else { $app['twig.loader.filesystem']->addPath($path); } } $twig->addGlobal('current_date', new \DateTime()); $twig->addExtension(new \Twig_Extension_Core()); $twig->addExtension(new \Twig_Extension_Optimizer()); $twig->addExtension(new \Twig_Extension_Escaper()); // add filter trans $twig->addExtension(new TranslationExtension($app['translator'])); // add filter localizeddate $twig->addExtension(new \Twig_Extensions_Extension_Intl()); // add filters truncate, wordwrap, nl2br $twig->addExtension(new \Twig_Extensions_Extension_Text()); $twig->addExtension(new JSUniqueID()); $twig->addExtension(new Camelize()); $twig->addExtension(new BytesConverter()); $twig->addFilter('serialize', new \Twig_Filter_Function('serialize')); $twig->addFilter('stristr', new \Twig_Filter_Function('stristr')); $twig->addFilter('get_class', new \Twig_Filter_Function('get_class')); $twig->addFilter('stripdoublequotes', new \Twig_Filter_Function('stripdoublequotes')); $twig->addFilter('get_collection_logo', new \Twig_Filter_Function('collection::getLogo')); $twig->addFilter('floor', new \Twig_Filter_Function('floor')); $twig->addFilter('ceil', new \Twig_Filter_Function('ceil')); $twig->addFilter('max', new \Twig_Filter_Function('max')); $twig->addFilter('min', new \Twig_Filter_Function('min')); $twig->addFilter('bas_labels', new \Twig_Filter_Function('phrasea::bas_labels')); $twig->addFilter('sbas_names', new \Twig_Filter_Function('phrasea::sbas_names')); $twig->addFilter('sbas_labels', new \Twig_Filter_Function('phrasea::sbas_labels')); $twig->addFilter('sbas_from_bas', new \Twig_Filter_Function('phrasea::sbasFromBas')); $twig->addFilter('key_exists', new \Twig_Filter_Function('array_key_exists')); $twig->addFilter('round', new \Twig_Filter_Function('round')); $twig->addFilter('count', new \Twig_Filter_Function('count')); $twig->addFilter('formatOctets', new \Twig_Filter_Function('p4string::format_octets')); $twig->addFilter('base_from_coll', new \Twig_Filter_Function('phrasea::baseFromColl')); $twig->addFilter(new \Twig_SimpleFilter('AppName', function ($value) use($app) { return ConnectedUsers::appName($app['translator'], $value); })); $twig->addFilter(new \Twig_SimpleFilter('escapeSimpleQuote', function ($value) { $ret = str_replace("'", "\\'", $value); return $ret; })); $twig->addFilter(new \Twig_SimpleFilter('thesaurus', function (\Twig_Environment $twig, $value) { if (!$value instanceof \ThesaurusValue) { return str_replace(['[[em]]', '[[/em]]'], ['<em>', '</em>'], twig_escape_filter($twig, $value)); } return "<a class=\"bounce\" onclick=\"bounce('" . $value->getField()->get_databox()->get_sbas_id() . "','" . str_replace("'", "\\'", $value->getQuery()) . "', '" . str_replace("'", "\\'", $value->getField()->get_name()) . "');return(false);\">" . str_replace(['[[em]]', '[[/em]]'], ['<em>', '</em>'], twig_escape_filter($twig, $value->getValue())) . "</a>"; }, ['needs_environment' => true, 'is_safe' => ['html']])); $twig->addFilter(new \Twig_SimpleFilter('escapeDoubleQuote', function ($value) { return str_replace('"', '\\"', $value); })); return $twig; })); }
public function setupTwig() { $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) { $twig->setCache($app['cache.path'] . '/twig'); $paths = (require $app['plugins.directory'] . '/twig-paths.php'); if ($app['browser']->isTablet() || $app['browser']->isMobile()) { $paths[] = $app['root.path'] . '/config/templates/mobile'; $paths[] = $app['root.path'] . '/templates/mobile'; $paths['phraseanet'] = $app['root.path'] . '/config/templates/mobile'; $paths['phraseanet'] = $app['root.path'] . '/templates/mobile'; } $paths[] = $app['root.path'] . '/config/templates/web'; $paths[] = $app['root.path'] . '/templates/web'; $paths['phraseanet'] = $app['root.path'] . '/config/templates/web'; $paths['phraseanet'] = $app['root.path'] . '/templates/web'; foreach ($paths as $namespace => $path) { if (!is_int($namespace)) { $app['twig.loader.filesystem']->addPath($path, $namespace); } else { $app['twig.loader.filesystem']->addPath($path); } } $twig->addGlobal('current_date', new \DateTime()); $twig->addExtension(new \Twig_Extension_Core()); $twig->addExtension(new \Twig_Extension_Optimizer()); $twig->addExtension(new \Twig_Extension_Escaper()); // add filter trans $twig->addExtension(new TranslationExtension($app['translator'])); // add filter localizeddate $twig->addExtension(new \Twig_Extensions_Extension_Intl()); // add filters truncate, wordwrap, nl2br $twig->addExtension(new \Twig_Extensions_Extension_Text()); $twig->addExtension(new JSUniqueID()); $twig->addExtension(new Fit()); $twig->addExtension(new Camelize()); $twig->addExtension(new BytesConverter()); $twig->addFilter('serialize', new \Twig_Filter_Function('serialize')); $twig->addFilter('stristr', new \Twig_Filter_Function('stristr')); $twig->addFilter('get_class', new \Twig_Filter_Function('get_class')); $twig->addFilter('stripdoublequotes', new \Twig_Filter_Function('stripdoublequotes')); $twig->addFilter('get_collection_logo', new \Twig_Filter_Function('collection::getLogo')); $twig->addFilter('floor', new \Twig_Filter_Function('floor')); $twig->addFilter('ceil', new \Twig_Filter_Function('ceil')); $twig->addFilter('max', new \Twig_Filter_Function('max')); $twig->addFilter('min', new \Twig_Filter_Function('min')); $twig->addFilter('bas_labels', new \Twig_Filter_Function('phrasea::bas_labels')); $twig->addFilter('sbas_names', new \Twig_Filter_Function('phrasea::sbas_names')); $twig->addFilter('sbas_labels', new \Twig_Filter_Function('phrasea::sbas_labels')); $twig->addFilter('sbas_from_bas', new \Twig_Filter_Function('phrasea::sbasFromBas')); $twig->addFilter('key_exists', new \Twig_Filter_Function('array_key_exists')); $twig->addFilter('round', new \Twig_Filter_Function('round')); $twig->addFilter('count', new \Twig_Filter_Function('count')); $twig->addFilter('formatOctets', new \Twig_Filter_Function('p4string::format_octets')); $twig->addFilter('base_from_coll', new \Twig_Filter_Function('phrasea::baseFromColl')); $twig->addFilter(new \Twig_SimpleFilter('AppName', function ($value) use($app) { return ConnectedUsers::appName($app['translator'], $value); })); $twig->addFilter(new \Twig_SimpleFilter('escapeSimpleQuote', function ($value) { return str_replace("'", "\\'", $value); })); $twig->addFilter(new \Twig_SimpleFilter('highlight', function (\Twig_Environment $twig, $string) { return str_replace(['[[em]]', '[[/em]]'], ['<em>', '</em>'], $string); }, ['needs_environment' => true, 'is_safe' => ['html']])); $twig->addFilter(new \Twig_SimpleFilter('linkify', function (\Twig_Environment $twig, $string) { return preg_replace("(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\\w:#%/;\$()~_?/\\-=\\\\.&]*)([^']{1}))", '$1 $2 <a title="' . _('Open the URL in a new window') . '" class="ui-icon ui-icon-extlink" href="$2" style="display:inline;padding:2px 5px;margin:0 4px 0 2px;" target="_blank"> </a>$7', $string); }, ['needs_environment' => true, 'is_safe' => ['html']])); $twig->addFilter(new \Twig_SimpleFilter('bounce', function (\Twig_Environment $twig, $fieldValue, $fieldName, $searchRequest, $sbasId) { // bounce value if it is present in thesaurus as well return "<a class=\"bounce\" onclick=\"bounce('" . $sbasId . "','" . str_replace("'", "\\'", $searchRequest) . "', '" . str_replace("'", "\\'", $fieldName) . "');return(false);\">" . $fieldValue . "</a>"; }, ['needs_environment' => true, 'is_safe' => ['html']])); $twig->addFilter(new \Twig_SimpleFilter('escapeDoubleQuote', function ($value) { return str_replace('"', '\\"', $value); })); return $twig; })); }