Helper.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Backend view helper |
| 12 | * |
| 13 | * @since 6.9.21 https://github.com/aamplugin/advanced-access-manager/issues/341 |
| 14 | * @since 6.8.4 https://github.com/aamplugin/advanced-access-manager/issues/213 |
| 15 | * @since 6.0.0 Initial implementation of the class |
| 16 | * |
| 17 | * @package AAM |
| 18 | * @version 6.9.21 |
| 19 | */ |
| 20 | class AAM_Backend_View_Helper |
| 21 | { |
| 22 | |
| 23 | /** |
| 24 | * Was resizer library already loaded? |
| 25 | * |
| 26 | * @var boolean |
| 27 | * |
| 28 | * @access protected |
| 29 | * @static |
| 30 | * |
| 31 | * @version 6.8.4 |
| 32 | */ |
| 33 | protected static $isResizerLoaded = false; |
| 34 | |
| 35 | /** |
| 36 | * Prepare phrase or label |
| 37 | * |
| 38 | * @param string $phrase |
| 39 | * @param mixed $... |
| 40 | * |
| 41 | * @return string |
| 42 | * |
| 43 | * @access protected |
| 44 | * @version 6.0.0 |
| 45 | */ |
| 46 | public static function preparePhrase($phrase) |
| 47 | { |
| 48 | // Prepare search patterns |
| 49 | $num = func_num_args(); |
| 50 | $search = ($num > 1 ? array_fill(0, ($num - 1) * 2, null) : array()); |
| 51 | |
| 52 | array_walk($search, 'AAM_Backend_View_Helper::prepareWalk'); |
| 53 | |
| 54 | $replace = array(); |
| 55 | foreach (array_slice(func_get_args(), 1) as $key) { |
| 56 | array_push($replace, "<{$key}>", "</{$key}>"); |
| 57 | } |
| 58 | |
| 59 | // Localize the phase first |
| 60 | return preg_replace($search, $replace, __($phrase, 'advanced-access-manager'), 1); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Prepare the wrapper replacement |
| 65 | * |
| 66 | * @param string $value |
| 67 | * @param int $index |
| 68 | * |
| 69 | * @return void |
| 70 | * |
| 71 | * @access public |
| 72 | * @version 6.0.0 |
| 73 | */ |
| 74 | public static function prepareWalk(&$value, $index) |
| 75 | { |
| 76 | $value = '/\\' . ($index % 2 ? ']' : '[') . '/'; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Prepare and print iframe HTML markup |
| 81 | * |
| 82 | * @param string $url |
| 83 | * @param string $style |
| 84 | * @param string $id |
| 85 | * |
| 86 | * @return void |
| 87 | * |
| 88 | * @since 6.9.21 https://github.com/aamplugin/advanced-access-manager/issues/341 |
| 89 | * @since 6.8.4 Initial implementation of the method |
| 90 | * |
| 91 | * @access public |
| 92 | * @static |
| 93 | * |
| 94 | * @version 6.9.21 |
| 95 | */ |
| 96 | public static function loadIframe($url, $style = null, $id = 'aam-iframe') |
| 97 | { |
| 98 | echo '<iframe src="' . esc_url($url) . '" width="100%" id="' . esc_attr($id) . '" style="' . esc_attr($style) . '"></iframe>'; |
| 99 | |
| 100 | if (!self::$isResizerLoaded) { |
| 101 | echo '<script>' . file_get_contents(AAM_BASEDIR . '/media/js/iframe-resizer.js') . '</script>'; |
| 102 | self::$isResizerLoaded = true; |
| 103 | } |
| 104 | |
| 105 | echo '<script>iFrameResize({ log: false }, "#' . $id . '");</script>'; |
| 106 | } |
| 107 | |
| 108 | } |