Source of file AuthBlockShortcodeProvider.php
Size: 1,890 Bytes - Last Modified: 2021-12-24T06:47:57+00:00
/var/www/docs.ssmods.com/process/src/src/View/Shortcodes/AuthBlockShortcodeProvider.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | <?php namespace Fosforus\AuthBlockShortcode\View\Shortcodes; use SilverStripe\View\Parsers\ShortcodeHandler; use SilverStripe\View\Parsers\ShortcodeParser; use SilverStripe\Security\Permission; use SilverStripe\Security\Security; /** * Provider for the [authblock] shortcode tag used to determine logged-in state * in the HTML Editor field. * Provides the html needed for the frontend and the editor field itself. */ class AuthBlockShortcodeProvider implements ShortcodeHandler { /** * Gets the list of shortcodes provided by this handler * * @return mixed */ public static function get_shortcodes() { return array('authblock'); } /** * AuthBlock shortcode parser * * @param array $arguments * @param string $content * @param ShortcodeParser $parser * @param string $shortcode * @param array $extra * * @return string */ public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = array()) { $ret = false; if (isset($arguments['auth']) && strtolower($arguments['auth']) == 'false') { if (empty(Security::getCurrentUser())) { $ret = true; } } elseif (!isset($arguments['auth']) || strtolower($arguments['auth']) == 'true') { if (Security::getCurrentUser()) { if (isset($arguments['perm'])) { if (Permission::check($arguments['perm'])) { $ret = true; } } else { $ret = true; } } } if ($ret) { return $content; // parse this also? } return ''; } } |