From cf14306c2b3f82a81f8d56669a71633b4d4b5fce Mon Sep 17 00:00:00 2001 From: marvin-borner@live.com Date: Mon, 16 Apr 2018 21:09:05 +0200 Subject: Main merge to user management system - files are now at /main/public/ --- main/app/sprinkles/core/src/Twig/CacheHelper.php | 58 ++++++++++ main/app/sprinkles/core/src/Twig/CoreExtension.php | 124 +++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100755 main/app/sprinkles/core/src/Twig/CacheHelper.php create mode 100755 main/app/sprinkles/core/src/Twig/CoreExtension.php (limited to 'main/app/sprinkles/core/src/Twig') diff --git a/main/app/sprinkles/core/src/Twig/CacheHelper.php b/main/app/sprinkles/core/src/Twig/CacheHelper.php new file mode 100755 index 0000000..14aea49 --- /dev/null +++ b/main/app/sprinkles/core/src/Twig/CacheHelper.php @@ -0,0 +1,58 @@ +ci = $ci; + } + + /** + * Function that delete the Twig cache directory content + * + * @access public + * @return bool true/false if operation is successfull + */ + public function clearCache() + { + // Get location + $path = $this->ci->locator->findResource('cache://twig', true, true); + + // Get Filesystem instance + $fs = new FileSystem; + + // Make sure directory exist and delete it + if ($fs->exists($path)) { + return $fs->deleteDirectory($path, true); + } + + // It's still considered a success if directory doesn't exist yet + return true; + } +} diff --git a/main/app/sprinkles/core/src/Twig/CoreExtension.php b/main/app/sprinkles/core/src/Twig/CoreExtension.php new file mode 100755 index 0000000..6a89d12 --- /dev/null +++ b/main/app/sprinkles/core/src/Twig/CoreExtension.php @@ -0,0 +1,124 @@ +services = $services; + } + + /** + * Get the name of this extension. + * + * @return string + */ + public function getName() + { + return 'userfrosting/core'; + } + + /** + * Adds Twig functions `getAlerts` and `translate`. + * + * @return array[\Twig_SimpleFunction] + */ + public function getFunctions() + { + return array( + // Add Twig function for fetching alerts + new \Twig_SimpleFunction('getAlerts', function ($clear = true) { + if ($clear) { + return $this->services['alerts']->getAndClearMessages(); + } else { + return $this->services['alerts']->messages(); + } + }), + new \Twig_SimpleFunction('translate', function ($hook, $params = array()) { + return $this->services['translator']->translate($hook, $params); + }, [ + 'is_safe' => ['html'] + ]) + ); + } + + /** + * Adds Twig filters `unescape`. + * + * @return array[\Twig_SimpleFilter] + */ + public function getFilters() + { + return array( + /** + * Converts phone numbers to a standard format. + * + * @param String $num A unformatted phone number + * @return String Returns the formatted phone number + */ + new \Twig_SimpleFilter('phone', function ($num) { + return Util::formatPhoneNumber($num); + }), + new \Twig_SimpleFilter('unescape', function ($string) { + return html_entity_decode($string); + }) + ); + } + + /** + * Adds Twig global variables `site` and `assets`. + * + * @return array[mixed] + */ + public function getGlobals() + { + // CSRF token name and value + $csrfNameKey = $this->services->csrf->getTokenNameKey(); + $csrfValueKey = $this->services->csrf->getTokenValueKey(); + $csrfName = $this->services->csrf->getTokenName(); + $csrfValue = $this->services->csrf->getTokenValue(); + + $csrf = [ + 'csrf' => [ + 'keys' => [ + 'name' => $csrfNameKey, + 'value' => $csrfValueKey + ], + 'name' => $csrfName, + 'value' => $csrfValue + ] + ]; + + $site = array_replace_recursive($this->services->config['site'], $csrf); + + return [ + 'site' => $site, + 'assets' => $this->services->assets + ]; + } +} -- cgit v1.2.3