| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Util; |
| 4 |
|
| 5 |
use BitCode\BitForm\Admin\Form\Helpers; |
| 6 |
|
| 7 |
final class Utilities |
| 8 |
{ |
| 9 |
public static function isPro() |
| 10 |
{ |
| 11 |
$integrateData = get_option('bitformpro_integrate_key_data'); |
| 12 |
$isProLicenseActivated = !empty($integrateData) && is_array($integrateData) && 'success' === $integrateData['status']; |
| 13 |
return class_exists('BitCode\\BitFormPro\\Plugin') && $isProLicenseActivated; |
| 14 |
} |
| 15 |
|
| 16 |
public static function getRealPath($dir, $name) |
| 17 |
{ |
| 18 |
if (!isset($dir)) { |
| 19 |
return false; |
| 20 |
} |
| 21 |
$directories = array_diff(scandir($dir), ['..', '.']); |
| 22 |
$name = strtolower($name); |
| 23 |
|
| 24 |
foreach ($directories as $directory) { |
| 25 |
$dirLower = strtolower($directory); |
| 26 |
if ($dirLower === $name) { |
| 27 |
return $directory; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
public static function getFileNameExceptExtension($filename) |
| 35 |
{ |
| 36 |
$path_parts = pathinfo($filename); |
| 37 |
return $path_parts['filename']; |
| 38 |
} |
| 39 |
|
| 40 |
public static function styleGenerator($styleObj, $important = false) |
| 41 |
{ |
| 42 |
if (is_array($styleObj)) { |
| 43 |
$styleObj = json_decode(json_encode($styleObj)); |
| 44 |
} |
| 45 |
$important = $important ? '!important' : ''; |
| 46 |
$classes = array_keys((array) $styleObj); |
| 47 |
$css = ''; |
| 48 |
foreach ($classes as $class) { |
| 49 |
$css .= $class; |
| 50 |
$props = (array) $styleObj->{$class}; |
| 51 |
$propsKeys = array_keys($props); |
| 52 |
$styleObject = '{'; |
| 53 |
foreach ($propsKeys as $property) { |
| 54 |
$value = $props[$property]; |
| 55 |
if (empty($value)) { |
| 56 |
continue; |
| 57 |
} |
| 58 |
if (is_object($value)) { |
| 59 |
continue; |
| 60 |
} |
| 61 |
$styleObject .= "{$property}:{$value}{$important};"; |
| 62 |
} |
| 63 |
$styleObject = rtrim($styleObject, ';'); |
| 64 |
$styleObject .= '}'; |
| 65 |
$css .= $styleObject; |
| 66 |
} |
| 67 |
|
| 68 |
return $css; |
| 69 |
} |
| 70 |
|
| 71 |
public static function appendCSS($formId, $css, $mode = 'a') |
| 72 |
{ |
| 73 |
$fileName = ''; |
| 74 |
$path = ''; |
| 75 |
$path = 'form-styles'; |
| 76 |
$fileName = "bitform-{$formId}.css"; |
| 77 |
Helpers::saveFile($path, $fileName, $css, $mode); |
| 78 |
$fileName = "bitform-{$formId}-formid.css"; |
| 79 |
Helpers::saveFile($path, $fileName, $css, $mode); |
| 80 |
} |
| 81 |
} |
| 82 |
|