| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.2.6 |
| 5 |
* |
| 6 |
* @author FirePlugins <[email protected]> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FPFramework\Helpers; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class Responsive |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Renders the given CSS. |
| 23 |
* |
| 24 |
* @param array $css |
| 25 |
* @param string $namespace |
| 26 |
* |
| 27 |
* @return string |
| 28 |
*/ |
| 29 |
public static function renderResponsiveCSS($css, $namespace = '') |
| 30 |
{ |
| 31 |
$output = ''; |
| 32 |
|
| 33 |
foreach (Controls\Responsive::$breakpoints as $breakpoint) |
| 34 |
{ |
| 35 |
if (!isset($css[$breakpoint]) || empty($css[$breakpoint])) |
| 36 |
{ |
| 37 |
continue; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* If we were given an array of strings of CSS, transform them to a string so we can output it. |
| 42 |
* |
| 43 |
* i.e. transform |
| 44 |
* [ |
| 45 |
* 'color: #fff;', |
| 46 |
* 'background: #000;' |
| 47 |
* ] |
| 48 |
* |
| 49 |
* to: |
| 50 |
* |
| 51 |
* 'color: #fff;background: #000;' |
| 52 |
*/ |
| 53 |
if (!is_string($css[$breakpoint])) |
| 54 |
{ |
| 55 |
$css[$breakpoint] = implode(' ', $css[$breakpoint]); |
| 56 |
} |
| 57 |
|
| 58 |
$function = 'get' . ucfirst($breakpoint) . 'Output'; |
| 59 |
if (!$output .= self::$function($css[$breakpoint], $namespace)) |
| 60 |
{ |
| 61 |
continue; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
return $output; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Returns the desktop CSS. |
| 70 |
* |
| 71 |
* @param string $css |
| 72 |
* @param string $namespace |
| 73 |
* |
| 74 |
* @return string |
| 75 |
*/ |
| 76 |
public static function getDesktopOutput($css, $namespace) |
| 77 |
{ |
| 78 |
return self::getGenericTemplate($css, '', $namespace); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns the tablet CSS. |
| 83 |
* |
| 84 |
* @param string $css |
| 85 |
* @param string $namespace |
| 86 |
* |
| 87 |
* @return string |
| 88 |
*/ |
| 89 |
public static function getTabletOutput($css, $namespace) |
| 90 |
{ |
| 91 |
return self::getGenericTemplate($css, '(max-width: 991px)', $namespace); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Returns the mobile CSS. |
| 96 |
* |
| 97 |
* @param string $css |
| 98 |
* @param string $namespace |
| 99 |
* |
| 100 |
* @return string |
| 101 |
*/ |
| 102 |
public static function getMobileOutput($css, $namespace) |
| 103 |
{ |
| 104 |
return self::getGenericTemplate($css, '(max-width: 575px)', $namespace); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Returns the responsive output of a specific media query size. |
| 109 |
* |
| 110 |
* @param string $css |
| 111 |
* @param string $size |
| 112 |
* @param string $namespace |
| 113 |
* |
| 114 |
* @return string |
| 115 |
*/ |
| 116 |
public static function getGenericTemplate($css, $size = '', $namespace = '') |
| 117 |
{ |
| 118 |
if (!is_string($css) || !is_string($size) || !is_string($namespace)) |
| 119 |
{ |
| 120 |
return ''; |
| 121 |
} |
| 122 |
|
| 123 |
if (empty($css)) |
| 124 |
{ |
| 125 |
return ''; |
| 126 |
} |
| 127 |
|
| 128 |
$namespace_prefix = $namespace_suffix = $size_prefix = $size_suffix = ''; |
| 129 |
|
| 130 |
if (!empty($size)) |
| 131 |
{ |
| 132 |
$size_prefix = '@media screen and ' . $size . ' { '; |
| 133 |
$size_suffix = ' }'; |
| 134 |
} |
| 135 |
|
| 136 |
if (!empty($namespace)) |
| 137 |
{ |
| 138 |
$namespace_prefix = $namespace . ' { '; |
| 139 |
$namespace_suffix = ' }'; |
| 140 |
} |
| 141 |
|
| 142 |
return $size_prefix . $namespace_prefix . $css . $namespace_suffix . $size_suffix; |
| 143 |
} |
| 144 |
} |