@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | class InstalledVersions |
| 13 | 13 | { |
| 14 | 14 | private static $installed = array ( |
| 15 | - 'root' => |
|
| 16 | - array ( |
|
| 15 | + 'root' => |
|
| 16 | + array ( |
|
| 17 | 17 | 'pretty_version' => 'dev-master', |
| 18 | 18 | 'version' => 'dev-master', |
| 19 | 19 | 'aliases' => |
@@ -21,87 +21,87 @@ discard block |
||
| 21 | 21 | ), |
| 22 | 22 | 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
| 23 | 23 | 'name' => 'ayecode/invoicing', |
| 24 | - ), |
|
| 25 | - 'versions' => |
|
| 26 | - array ( |
|
| 24 | + ), |
|
| 25 | + 'versions' => |
|
| 26 | + array ( |
|
| 27 | 27 | 'ayecode/ayecode-connect-helper' => |
| 28 | 28 | array ( |
| 29 | - 'pretty_version' => '1.0.3', |
|
| 30 | - 'version' => '1.0.3.0', |
|
| 31 | - 'aliases' => |
|
| 32 | - array ( |
|
| 33 | - ), |
|
| 34 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 29 | + 'pretty_version' => '1.0.3', |
|
| 30 | + 'version' => '1.0.3.0', |
|
| 31 | + 'aliases' => |
|
| 32 | + array ( |
|
| 33 | + ), |
|
| 34 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 35 | 35 | ), |
| 36 | 36 | 'ayecode/invoicing' => |
| 37 | 37 | array ( |
| 38 | - 'pretty_version' => 'dev-master', |
|
| 39 | - 'version' => 'dev-master', |
|
| 40 | - 'aliases' => |
|
| 41 | - array ( |
|
| 42 | - ), |
|
| 43 | - 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
|
| 38 | + 'pretty_version' => 'dev-master', |
|
| 39 | + 'version' => 'dev-master', |
|
| 40 | + 'aliases' => |
|
| 41 | + array ( |
|
| 42 | + ), |
|
| 43 | + 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
|
| 44 | 44 | ), |
| 45 | 45 | 'ayecode/wp-ayecode-ui' => |
| 46 | 46 | array ( |
| 47 | - 'pretty_version' => '0.1.41', |
|
| 48 | - 'version' => '0.1.41.0', |
|
| 49 | - 'aliases' => |
|
| 50 | - array ( |
|
| 51 | - ), |
|
| 52 | - 'reference' => '5646d3060999d75b74c0d723e44fe84fce9d2a4b', |
|
| 47 | + 'pretty_version' => '0.1.41', |
|
| 48 | + 'version' => '0.1.41.0', |
|
| 49 | + 'aliases' => |
|
| 50 | + array ( |
|
| 51 | + ), |
|
| 52 | + 'reference' => '5646d3060999d75b74c0d723e44fe84fce9d2a4b', |
|
| 53 | 53 | ), |
| 54 | 54 | 'ayecode/wp-font-awesome-settings' => |
| 55 | 55 | array ( |
| 56 | - 'pretty_version' => '1.0.12', |
|
| 57 | - 'version' => '1.0.12.0', |
|
| 58 | - 'aliases' => |
|
| 59 | - array ( |
|
| 60 | - ), |
|
| 61 | - 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 56 | + 'pretty_version' => '1.0.12', |
|
| 57 | + 'version' => '1.0.12.0', |
|
| 58 | + 'aliases' => |
|
| 59 | + array ( |
|
| 60 | + ), |
|
| 61 | + 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 62 | 62 | ), |
| 63 | 63 | 'ayecode/wp-super-duper' => |
| 64 | 64 | array ( |
| 65 | - 'pretty_version' => '1.0.23', |
|
| 66 | - 'version' => '1.0.23.0', |
|
| 67 | - 'aliases' => |
|
| 68 | - array ( |
|
| 69 | - ), |
|
| 70 | - 'reference' => '9473c0b7cf3ef4c32374222994a3e4613cdaeb48', |
|
| 65 | + 'pretty_version' => '1.0.23', |
|
| 66 | + 'version' => '1.0.23.0', |
|
| 67 | + 'aliases' => |
|
| 68 | + array ( |
|
| 69 | + ), |
|
| 70 | + 'reference' => '9473c0b7cf3ef4c32374222994a3e4613cdaeb48', |
|
| 71 | 71 | ), |
| 72 | 72 | 'composer/installers' => |
| 73 | 73 | array ( |
| 74 | - 'pretty_version' => 'v1.10.0', |
|
| 75 | - 'version' => '1.10.0.0', |
|
| 76 | - 'aliases' => |
|
| 77 | - array ( |
|
| 78 | - ), |
|
| 79 | - 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
| 74 | + 'pretty_version' => 'v1.10.0', |
|
| 75 | + 'version' => '1.10.0.0', |
|
| 76 | + 'aliases' => |
|
| 77 | + array ( |
|
| 78 | + ), |
|
| 79 | + 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
| 80 | 80 | ), |
| 81 | 81 | 'maxmind-db/reader' => |
| 82 | 82 | array ( |
| 83 | - 'pretty_version' => 'v1.6.0', |
|
| 84 | - 'version' => '1.6.0.0', |
|
| 85 | - 'aliases' => |
|
| 86 | - array ( |
|
| 87 | - ), |
|
| 88 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
| 83 | + 'pretty_version' => 'v1.6.0', |
|
| 84 | + 'version' => '1.6.0.0', |
|
| 85 | + 'aliases' => |
|
| 86 | + array ( |
|
| 87 | + ), |
|
| 88 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
| 89 | 89 | ), |
| 90 | 90 | 'roundcube/plugin-installer' => |
| 91 | 91 | array ( |
| 92 | - 'replaced' => |
|
| 93 | - array ( |
|
| 92 | + 'replaced' => |
|
| 93 | + array ( |
|
| 94 | 94 | 0 => '*', |
| 95 | - ), |
|
| 95 | + ), |
|
| 96 | 96 | ), |
| 97 | 97 | 'shama/baton' => |
| 98 | 98 | array ( |
| 99 | - 'replaced' => |
|
| 100 | - array ( |
|
| 99 | + 'replaced' => |
|
| 100 | + array ( |
|
| 101 | 101 | 0 => '*', |
| 102 | - ), |
|
| 102 | + ), |
|
| 103 | + ), |
|
| 103 | 104 | ), |
| 104 | - ), |
|
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | 107 | |
@@ -11,93 +11,93 @@ |
||
| 11 | 11 | |
| 12 | 12 | class InstalledVersions |
| 13 | 13 | { |
| 14 | -private static $installed = array ( |
|
| 14 | +private static $installed = array( |
|
| 15 | 15 | 'root' => |
| 16 | - array ( |
|
| 16 | + array( |
|
| 17 | 17 | 'pretty_version' => 'dev-master', |
| 18 | 18 | 'version' => 'dev-master', |
| 19 | 19 | 'aliases' => |
| 20 | - array ( |
|
| 20 | + array( |
|
| 21 | 21 | ), |
| 22 | 22 | 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
| 23 | 23 | 'name' => 'ayecode/invoicing', |
| 24 | 24 | ), |
| 25 | 25 | 'versions' => |
| 26 | - array ( |
|
| 26 | + array( |
|
| 27 | 27 | 'ayecode/ayecode-connect-helper' => |
| 28 | - array ( |
|
| 28 | + array( |
|
| 29 | 29 | 'pretty_version' => '1.0.3', |
| 30 | 30 | 'version' => '1.0.3.0', |
| 31 | 31 | 'aliases' => |
| 32 | - array ( |
|
| 32 | + array( |
|
| 33 | 33 | ), |
| 34 | 34 | 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
| 35 | 35 | ), |
| 36 | 36 | 'ayecode/invoicing' => |
| 37 | - array ( |
|
| 37 | + array( |
|
| 38 | 38 | 'pretty_version' => 'dev-master', |
| 39 | 39 | 'version' => 'dev-master', |
| 40 | 40 | 'aliases' => |
| 41 | - array ( |
|
| 41 | + array( |
|
| 42 | 42 | ), |
| 43 | 43 | 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
| 44 | 44 | ), |
| 45 | 45 | 'ayecode/wp-ayecode-ui' => |
| 46 | - array ( |
|
| 46 | + array( |
|
| 47 | 47 | 'pretty_version' => '0.1.41', |
| 48 | 48 | 'version' => '0.1.41.0', |
| 49 | 49 | 'aliases' => |
| 50 | - array ( |
|
| 50 | + array( |
|
| 51 | 51 | ), |
| 52 | 52 | 'reference' => '5646d3060999d75b74c0d723e44fe84fce9d2a4b', |
| 53 | 53 | ), |
| 54 | 54 | 'ayecode/wp-font-awesome-settings' => |
| 55 | - array ( |
|
| 55 | + array( |
|
| 56 | 56 | 'pretty_version' => '1.0.12', |
| 57 | 57 | 'version' => '1.0.12.0', |
| 58 | 58 | 'aliases' => |
| 59 | - array ( |
|
| 59 | + array( |
|
| 60 | 60 | ), |
| 61 | 61 | 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
| 62 | 62 | ), |
| 63 | 63 | 'ayecode/wp-super-duper' => |
| 64 | - array ( |
|
| 64 | + array( |
|
| 65 | 65 | 'pretty_version' => '1.0.23', |
| 66 | 66 | 'version' => '1.0.23.0', |
| 67 | 67 | 'aliases' => |
| 68 | - array ( |
|
| 68 | + array( |
|
| 69 | 69 | ), |
| 70 | 70 | 'reference' => '9473c0b7cf3ef4c32374222994a3e4613cdaeb48', |
| 71 | 71 | ), |
| 72 | 72 | 'composer/installers' => |
| 73 | - array ( |
|
| 73 | + array( |
|
| 74 | 74 | 'pretty_version' => 'v1.10.0', |
| 75 | 75 | 'version' => '1.10.0.0', |
| 76 | 76 | 'aliases' => |
| 77 | - array ( |
|
| 77 | + array( |
|
| 78 | 78 | ), |
| 79 | 79 | 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
| 80 | 80 | ), |
| 81 | 81 | 'maxmind-db/reader' => |
| 82 | - array ( |
|
| 82 | + array( |
|
| 83 | 83 | 'pretty_version' => 'v1.6.0', |
| 84 | 84 | 'version' => '1.6.0.0', |
| 85 | 85 | 'aliases' => |
| 86 | - array ( |
|
| 86 | + array( |
|
| 87 | 87 | ), |
| 88 | 88 | 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
| 89 | 89 | ), |
| 90 | 90 | 'roundcube/plugin-installer' => |
| 91 | - array ( |
|
| 91 | + array( |
|
| 92 | 92 | 'replaced' => |
| 93 | - array ( |
|
| 93 | + array( |
|
| 94 | 94 | 0 => '*', |
| 95 | 95 | ), |
| 96 | 96 | ), |
| 97 | 97 | 'shama/baton' => |
| 98 | - array ( |
|
| 98 | + array( |
|
| 99 | 99 | 'replaced' => |
| 100 | - array ( |
|
| 100 | + array( |
|
| 101 | 101 | 0 => '*', |
| 102 | 102 | ), |
| 103 | 103 | ), |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $installPath = $this->getPackageBasePath($package); |
| 167 | 167 | $io = $this->io; |
| 168 | - $outputStatus = function () use ($io, $installPath) { |
|
| 168 | + $outputStatus = function() use ($io, $installPath) { |
|
| 169 | 169 | $io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>')); |
| 170 | 170 | }; |
| 171 | 171 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - return $pattern ? : '(\w+)'; |
|
| 238 | + return $pattern ?: '(\w+)'; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | public function getLocations() |
| 37 | 37 | { |
| 38 | 38 | if ($this->matchesCakeVersion('>=', '3.0.0')) { |
| 39 | - $this->locations['plugin'] = $this->composer->getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/'; |
|
| 39 | + $this->locations['plugin'] = $this->composer->getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/'; |
|
| 40 | 40 | } |
| 41 | 41 | return $this->locations; |
| 42 | 42 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | protected function matchesCakeVersion($matcher, $version) |
| 52 | 52 | { |
| 53 | 53 | $repositoryManager = $this->composer->getRepositoryManager(); |
| 54 | - if (! $repositoryManager) { |
|
| 54 | + if (!$repositoryManager) { |
|
| 55 | 55 | return false; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | class OxidInstaller extends BaseInstaller |
| 7 | 7 | { |
| 8 | - const VENDOR_PATTERN = '/^modules\/(?P<vendor>.+)\/.+/'; |
|
| 8 | + const VENDOR_PATTERN = '/^modules\/(?P<vendor>.+)\/.+/'; |
|
| 9 | 9 | |
| 10 | 10 | protected $locations = array( |
| 11 | 11 | 'module' => 'modules/{$name}/', |
@@ -13,47 +13,47 @@ discard block |
||
| 13 | 13 | 'out' => 'out/{$name}/', |
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * getInstallPath |
|
| 18 | - * |
|
| 19 | - * @param PackageInterface $package |
|
| 20 | - * @param string $frameworkType |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function getInstallPath(PackageInterface $package, $frameworkType = '') |
|
| 24 | - { |
|
| 25 | - $installPath = parent::getInstallPath($package, $frameworkType); |
|
| 26 | - $type = $this->package->getType(); |
|
| 27 | - if ($type === 'oxid-module') { |
|
| 28 | - $this->prepareVendorDirectory($installPath); |
|
| 29 | - } |
|
| 30 | - return $installPath; |
|
| 31 | - } |
|
| 16 | + /** |
|
| 17 | + * getInstallPath |
|
| 18 | + * |
|
| 19 | + * @param PackageInterface $package |
|
| 20 | + * @param string $frameworkType |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function getInstallPath(PackageInterface $package, $frameworkType = '') |
|
| 24 | + { |
|
| 25 | + $installPath = parent::getInstallPath($package, $frameworkType); |
|
| 26 | + $type = $this->package->getType(); |
|
| 27 | + if ($type === 'oxid-module') { |
|
| 28 | + $this->prepareVendorDirectory($installPath); |
|
| 29 | + } |
|
| 30 | + return $installPath; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * prepareVendorDirectory |
|
| 35 | - * |
|
| 36 | - * Makes sure there is a vendormetadata.php file inside |
|
| 37 | - * the vendor folder if there is a vendor folder. |
|
| 38 | - * |
|
| 39 | - * @param string $installPath |
|
| 40 | - * @return void |
|
| 41 | - */ |
|
| 42 | - protected function prepareVendorDirectory($installPath) |
|
| 43 | - { |
|
| 44 | - $matches = ''; |
|
| 45 | - $hasVendorDirectory = preg_match(self::VENDOR_PATTERN, $installPath, $matches); |
|
| 46 | - if (!$hasVendorDirectory) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 33 | + /** |
|
| 34 | + * prepareVendorDirectory |
|
| 35 | + * |
|
| 36 | + * Makes sure there is a vendormetadata.php file inside |
|
| 37 | + * the vendor folder if there is a vendor folder. |
|
| 38 | + * |
|
| 39 | + * @param string $installPath |
|
| 40 | + * @return void |
|
| 41 | + */ |
|
| 42 | + protected function prepareVendorDirectory($installPath) |
|
| 43 | + { |
|
| 44 | + $matches = ''; |
|
| 45 | + $hasVendorDirectory = preg_match(self::VENDOR_PATTERN, $installPath, $matches); |
|
| 46 | + if (!$hasVendorDirectory) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $vendorDirectory = $matches['vendor']; |
|
| 51 | - $vendorPath = getcwd() . '/modules/' . $vendorDirectory; |
|
| 52 | - if (!file_exists($vendorPath)) { |
|
| 53 | - mkdir($vendorPath, 0755, true); |
|
| 54 | - } |
|
| 50 | + $vendorDirectory = $matches['vendor']; |
|
| 51 | + $vendorPath = getcwd() . '/modules/' . $vendorDirectory; |
|
| 52 | + if (!file_exists($vendorPath)) { |
|
| 53 | + mkdir($vendorPath, 0755, true); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $vendorMetaDataPath = $vendorPath . '/vendormetadata.php'; |
|
| 57 | - touch($vendorMetaDataPath); |
|
| 58 | - } |
|
| 56 | + $vendorMetaDataPath = $vendorPath . '/vendormetadata.php'; |
|
| 57 | + touch($vendorMetaDataPath); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php return array ( |
| 2 | - 'root' => |
|
| 3 | - array ( |
|
| 2 | + 'root' => |
|
| 3 | + array ( |
|
| 4 | 4 | 'pretty_version' => 'dev-master', |
| 5 | 5 | 'version' => 'dev-master', |
| 6 | 6 | 'aliases' => |
@@ -8,85 +8,85 @@ discard block |
||
| 8 | 8 | ), |
| 9 | 9 | 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
| 10 | 10 | 'name' => 'ayecode/invoicing', |
| 11 | - ), |
|
| 12 | - 'versions' => |
|
| 13 | - array ( |
|
| 11 | + ), |
|
| 12 | + 'versions' => |
|
| 13 | + array ( |
|
| 14 | 14 | 'ayecode/ayecode-connect-helper' => |
| 15 | 15 | array ( |
| 16 | - 'pretty_version' => '1.0.3', |
|
| 17 | - 'version' => '1.0.3.0', |
|
| 18 | - 'aliases' => |
|
| 19 | - array ( |
|
| 20 | - ), |
|
| 21 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 16 | + 'pretty_version' => '1.0.3', |
|
| 17 | + 'version' => '1.0.3.0', |
|
| 18 | + 'aliases' => |
|
| 19 | + array ( |
|
| 20 | + ), |
|
| 21 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
| 22 | 22 | ), |
| 23 | 23 | 'ayecode/invoicing' => |
| 24 | 24 | array ( |
| 25 | - 'pretty_version' => 'dev-master', |
|
| 26 | - 'version' => 'dev-master', |
|
| 27 | - 'aliases' => |
|
| 28 | - array ( |
|
| 29 | - ), |
|
| 30 | - 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
|
| 25 | + 'pretty_version' => 'dev-master', |
|
| 26 | + 'version' => 'dev-master', |
|
| 27 | + 'aliases' => |
|
| 28 | + array ( |
|
| 29 | + ), |
|
| 30 | + 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
|
| 31 | 31 | ), |
| 32 | 32 | 'ayecode/wp-ayecode-ui' => |
| 33 | 33 | array ( |
| 34 | - 'pretty_version' => '0.1.41', |
|
| 35 | - 'version' => '0.1.41.0', |
|
| 36 | - 'aliases' => |
|
| 37 | - array ( |
|
| 38 | - ), |
|
| 39 | - 'reference' => '5646d3060999d75b74c0d723e44fe84fce9d2a4b', |
|
| 34 | + 'pretty_version' => '0.1.41', |
|
| 35 | + 'version' => '0.1.41.0', |
|
| 36 | + 'aliases' => |
|
| 37 | + array ( |
|
| 38 | + ), |
|
| 39 | + 'reference' => '5646d3060999d75b74c0d723e44fe84fce9d2a4b', |
|
| 40 | 40 | ), |
| 41 | 41 | 'ayecode/wp-font-awesome-settings' => |
| 42 | 42 | array ( |
| 43 | - 'pretty_version' => '1.0.12', |
|
| 44 | - 'version' => '1.0.12.0', |
|
| 45 | - 'aliases' => |
|
| 46 | - array ( |
|
| 47 | - ), |
|
| 48 | - 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 43 | + 'pretty_version' => '1.0.12', |
|
| 44 | + 'version' => '1.0.12.0', |
|
| 45 | + 'aliases' => |
|
| 46 | + array ( |
|
| 47 | + ), |
|
| 48 | + 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
| 49 | 49 | ), |
| 50 | 50 | 'ayecode/wp-super-duper' => |
| 51 | 51 | array ( |
| 52 | - 'pretty_version' => '1.0.23', |
|
| 53 | - 'version' => '1.0.23.0', |
|
| 54 | - 'aliases' => |
|
| 55 | - array ( |
|
| 56 | - ), |
|
| 57 | - 'reference' => '9473c0b7cf3ef4c32374222994a3e4613cdaeb48', |
|
| 52 | + 'pretty_version' => '1.0.23', |
|
| 53 | + 'version' => '1.0.23.0', |
|
| 54 | + 'aliases' => |
|
| 55 | + array ( |
|
| 56 | + ), |
|
| 57 | + 'reference' => '9473c0b7cf3ef4c32374222994a3e4613cdaeb48', |
|
| 58 | 58 | ), |
| 59 | 59 | 'composer/installers' => |
| 60 | 60 | array ( |
| 61 | - 'pretty_version' => 'v1.10.0', |
|
| 62 | - 'version' => '1.10.0.0', |
|
| 63 | - 'aliases' => |
|
| 64 | - array ( |
|
| 65 | - ), |
|
| 66 | - 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
| 61 | + 'pretty_version' => 'v1.10.0', |
|
| 62 | + 'version' => '1.10.0.0', |
|
| 63 | + 'aliases' => |
|
| 64 | + array ( |
|
| 65 | + ), |
|
| 66 | + 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
| 67 | 67 | ), |
| 68 | 68 | 'maxmind-db/reader' => |
| 69 | 69 | array ( |
| 70 | - 'pretty_version' => 'v1.6.0', |
|
| 71 | - 'version' => '1.6.0.0', |
|
| 72 | - 'aliases' => |
|
| 73 | - array ( |
|
| 74 | - ), |
|
| 75 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
| 70 | + 'pretty_version' => 'v1.6.0', |
|
| 71 | + 'version' => '1.6.0.0', |
|
| 72 | + 'aliases' => |
|
| 73 | + array ( |
|
| 74 | + ), |
|
| 75 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
| 76 | 76 | ), |
| 77 | 77 | 'roundcube/plugin-installer' => |
| 78 | 78 | array ( |
| 79 | - 'replaced' => |
|
| 80 | - array ( |
|
| 79 | + 'replaced' => |
|
| 80 | + array ( |
|
| 81 | 81 | 0 => '*', |
| 82 | - ), |
|
| 82 | + ), |
|
| 83 | 83 | ), |
| 84 | 84 | 'shama/baton' => |
| 85 | 85 | array ( |
| 86 | - 'replaced' => |
|
| 87 | - array ( |
|
| 86 | + 'replaced' => |
|
| 87 | + array ( |
|
| 88 | 88 | 0 => '*', |
| 89 | - ), |
|
| 89 | + ), |
|
| 90 | + ), |
|
| 90 | 91 | ), |
| 91 | - ), |
|
| 92 | 92 | ); |
@@ -1,90 +1,90 @@ |
||
| 1 | -<?php return array ( |
|
| 1 | +<?php return array( |
|
| 2 | 2 | 'root' => |
| 3 | - array ( |
|
| 3 | + array( |
|
| 4 | 4 | 'pretty_version' => 'dev-master', |
| 5 | 5 | 'version' => 'dev-master', |
| 6 | 6 | 'aliases' => |
| 7 | - array ( |
|
| 7 | + array( |
|
| 8 | 8 | ), |
| 9 | 9 | 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
| 10 | 10 | 'name' => 'ayecode/invoicing', |
| 11 | 11 | ), |
| 12 | 12 | 'versions' => |
| 13 | - array ( |
|
| 13 | + array( |
|
| 14 | 14 | 'ayecode/ayecode-connect-helper' => |
| 15 | - array ( |
|
| 15 | + array( |
|
| 16 | 16 | 'pretty_version' => '1.0.3', |
| 17 | 17 | 'version' => '1.0.3.0', |
| 18 | 18 | 'aliases' => |
| 19 | - array ( |
|
| 19 | + array( |
|
| 20 | 20 | ), |
| 21 | 21 | 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
| 22 | 22 | ), |
| 23 | 23 | 'ayecode/invoicing' => |
| 24 | - array ( |
|
| 24 | + array( |
|
| 25 | 25 | 'pretty_version' => 'dev-master', |
| 26 | 26 | 'version' => 'dev-master', |
| 27 | 27 | 'aliases' => |
| 28 | - array ( |
|
| 28 | + array( |
|
| 29 | 29 | ), |
| 30 | 30 | 'reference' => '4b094a9228b10d14ba32d30d478a694ed5bf34eb', |
| 31 | 31 | ), |
| 32 | 32 | 'ayecode/wp-ayecode-ui' => |
| 33 | - array ( |
|
| 33 | + array( |
|
| 34 | 34 | 'pretty_version' => '0.1.41', |
| 35 | 35 | 'version' => '0.1.41.0', |
| 36 | 36 | 'aliases' => |
| 37 | - array ( |
|
| 37 | + array( |
|
| 38 | 38 | ), |
| 39 | 39 | 'reference' => '5646d3060999d75b74c0d723e44fe84fce9d2a4b', |
| 40 | 40 | ), |
| 41 | 41 | 'ayecode/wp-font-awesome-settings' => |
| 42 | - array ( |
|
| 42 | + array( |
|
| 43 | 43 | 'pretty_version' => '1.0.12', |
| 44 | 44 | 'version' => '1.0.12.0', |
| 45 | 45 | 'aliases' => |
| 46 | - array ( |
|
| 46 | + array( |
|
| 47 | 47 | ), |
| 48 | 48 | 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
| 49 | 49 | ), |
| 50 | 50 | 'ayecode/wp-super-duper' => |
| 51 | - array ( |
|
| 51 | + array( |
|
| 52 | 52 | 'pretty_version' => '1.0.23', |
| 53 | 53 | 'version' => '1.0.23.0', |
| 54 | 54 | 'aliases' => |
| 55 | - array ( |
|
| 55 | + array( |
|
| 56 | 56 | ), |
| 57 | 57 | 'reference' => '9473c0b7cf3ef4c32374222994a3e4613cdaeb48', |
| 58 | 58 | ), |
| 59 | 59 | 'composer/installers' => |
| 60 | - array ( |
|
| 60 | + array( |
|
| 61 | 61 | 'pretty_version' => 'v1.10.0', |
| 62 | 62 | 'version' => '1.10.0.0', |
| 63 | 63 | 'aliases' => |
| 64 | - array ( |
|
| 64 | + array( |
|
| 65 | 65 | ), |
| 66 | 66 | 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
| 67 | 67 | ), |
| 68 | 68 | 'maxmind-db/reader' => |
| 69 | - array ( |
|
| 69 | + array( |
|
| 70 | 70 | 'pretty_version' => 'v1.6.0', |
| 71 | 71 | 'version' => '1.6.0.0', |
| 72 | 72 | 'aliases' => |
| 73 | - array ( |
|
| 73 | + array( |
|
| 74 | 74 | ), |
| 75 | 75 | 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
| 76 | 76 | ), |
| 77 | 77 | 'roundcube/plugin-installer' => |
| 78 | - array ( |
|
| 78 | + array( |
|
| 79 | 79 | 'replaced' => |
| 80 | - array ( |
|
| 80 | + array( |
|
| 81 | 81 | 0 => '*', |
| 82 | 82 | ), |
| 83 | 83 | ), |
| 84 | 84 | 'shama/baton' => |
| 85 | - array ( |
|
| 85 | + array( |
|
| 86 | 86 | 'replaced' => |
| 87 | - array ( |
|
| 87 | + array( |
|
| 88 | 88 | 0 => '*', |
| 89 | 89 | ), |
| 90 | 90 | ), |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | * Bail if we are not in WP. |
| 8 | 8 | */ |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; |
|
| 10 | + exit; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Set the version only if its the current newest while loading. |
| 15 | 15 | */ |
| 16 | 16 | add_action('after_setup_theme', function () { |
| 17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | - $this_version = "0.1.41"; |
|
| 19 | - if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | - $ayecode_ui_version = $this_version ; |
|
| 21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | - } |
|
| 17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | + $this_version = "0.1.41"; |
|
| 19 | + if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | + $ayecode_ui_version = $this_version ; |
|
| 21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | + } |
|
| 23 | 23 | },0); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
| 27 | 27 | */ |
| 28 | 28 | add_action('after_setup_theme', function () { |
| 29 | - global $ayecode_ui_file_key; |
|
| 30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | - } |
|
| 29 | + global $ayecode_ui_file_key; |
|
| 30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | + } |
|
| 34 | 34 | },1); |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Add the function that calls the class. |
| 38 | 38 | */ |
| 39 | 39 | if(!function_exists('aui')){ |
| 40 | - function aui(){ |
|
| 41 | - if(!class_exists("AUI",false)){ |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - return AUI::instance(); |
|
| 45 | - } |
|
| 40 | + function aui(){ |
|
| 41 | + if(!class_exists("AUI",false)){ |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + return AUI::instance(); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |
@@ -6,39 +6,39 @@ |
||
| 6 | 6 | /** |
| 7 | 7 | * Bail if we are not in WP. |
| 8 | 8 | */ |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if (!defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Set the version only if its the current newest while loading. |
| 15 | 15 | */ |
| 16 | -add_action('after_setup_theme', function () { |
|
| 17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 16 | +add_action('after_setup_theme', function() { |
|
| 17 | + global $ayecode_ui_version, $ayecode_ui_file_key; |
|
| 18 | 18 | $this_version = "0.1.41"; |
| 19 | - if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | - $ayecode_ui_version = $this_version ; |
|
| 21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 19 | + if (version_compare($this_version, $ayecode_ui_version, '>')) { |
|
| 20 | + $ayecode_ui_version = $this_version; |
|
| 21 | + $ayecode_ui_file_key = wp_hash(__FILE__); |
|
| 22 | 22 | } |
| 23 | 23 | },0); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
| 27 | 27 | */ |
| 28 | -add_action('after_setup_theme', function () { |
|
| 28 | +add_action('after_setup_theme', function() { |
|
| 29 | 29 | global $ayecode_ui_file_key; |
| 30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 30 | + if ($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash(__FILE__)) { |
|
| 31 | + include_once(dirname(__FILE__) . '/includes/class-aui.php'); |
|
| 32 | + include_once(dirname(__FILE__) . '/includes/ayecode-ui-settings.php'); |
|
| 33 | 33 | } |
| 34 | 34 | },1); |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Add the function that calls the class. |
| 38 | 38 | */ |
| 39 | -if(!function_exists('aui')){ |
|
| 40 | - function aui(){ |
|
| 41 | - if(!class_exists("AUI",false)){ |
|
| 39 | +if (!function_exists('aui')) { |
|
| 40 | + function aui() { |
|
| 41 | + if (!class_exists("AUI", false)) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | return AUI::instance(); |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // Exit if accessed directly |
|
| 4 | + exit; // Exit if accessed directly |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -11,231 +11,231 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Holds the class instance. |
|
| 16 | - * |
|
| 17 | - * @since 1.0.0 |
|
| 18 | - * @var null |
|
| 19 | - */ |
|
| 20 | - private static $instance = null; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Holds the current AUI version number. |
|
| 24 | - * |
|
| 25 | - * @var string $ver The current version number. |
|
| 26 | - */ |
|
| 27 | - public static $ver = '0.1.41'; |
|
| 28 | - |
|
| 29 | - public static $options = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * There can be only one. |
|
| 33 | - * |
|
| 34 | - * @since 1.0.0 |
|
| 35 | - * @return AUI|null |
|
| 36 | - */ |
|
| 37 | - public static function instance() { |
|
| 38 | - if ( self::$instance == null ) { |
|
| 39 | - self::$instance = new AUI(); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - return self::$instance; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * AUI constructor. |
|
| 47 | - * |
|
| 48 | - * @since 1.0.0 |
|
| 49 | - */ |
|
| 50 | - private function __construct() { |
|
| 51 | - if ( function_exists( "__autoload" ) ) { |
|
| 52 | - spl_autoload_register( "__autoload" ); |
|
| 53 | - } |
|
| 54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 55 | - |
|
| 56 | - // load options |
|
| 57 | - self::$options = get_option('aui_options'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Autoload any components on the fly. |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * |
|
| 65 | - * @param $classname |
|
| 66 | - */ |
|
| 67 | - private function autoload( $classname ) { |
|
| 68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
| 69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
| 70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
| 71 | - include_once( $file_path ); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Get the AUI options. |
|
| 77 | - * |
|
| 78 | - * @param $option |
|
| 79 | - * |
|
| 80 | - * @return string|void |
|
| 81 | - */ |
|
| 82 | - public function get_option( $option ){ |
|
| 83 | - $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
| 84 | - |
|
| 85 | - if ( ! $result && $option) { |
|
| 86 | - if( $option == 'color_primary' ){ |
|
| 87 | - $result = AUI_PRIMARY_COLOR; |
|
| 88 | - }elseif( $option == 'color_secondary' ){ |
|
| 89 | - $result = AUI_SECONDARY_COLOR; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - return $result; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function render( $items = array() ) { |
|
| 96 | - $output = ''; |
|
| 97 | - |
|
| 98 | - if ( ! empty( $items ) ) { |
|
| 99 | - foreach ( $items as $args ) { |
|
| 100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
| 101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
| 102 | - $output .= $this->$render( $args ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $output; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Render and return a bootstrap alert component. |
|
| 112 | - * |
|
| 113 | - * @since 1.0.0 |
|
| 114 | - * |
|
| 115 | - * @param array $args |
|
| 116 | - * |
|
| 117 | - * @return string The rendered component. |
|
| 118 | - */ |
|
| 119 | - public function alert( $args = array() ) { |
|
| 120 | - return AUI_Component_Alert::get( $args ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Render and return a bootstrap input component. |
|
| 125 | - * |
|
| 126 | - * @since 1.0.0 |
|
| 127 | - * |
|
| 128 | - * @param array $args |
|
| 129 | - * |
|
| 130 | - * @return string The rendered component. |
|
| 131 | - */ |
|
| 132 | - public function input( $args = array() ) { |
|
| 133 | - return AUI_Component_Input::input( $args ); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Render and return a bootstrap textarea component. |
|
| 138 | - * |
|
| 139 | - * @since 1.0.0 |
|
| 140 | - * |
|
| 141 | - * @param array $args |
|
| 142 | - * |
|
| 143 | - * @return string The rendered component. |
|
| 144 | - */ |
|
| 145 | - public function textarea( $args = array() ) { |
|
| 146 | - return AUI_Component_Input::textarea( $args ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Render and return a bootstrap button component. |
|
| 151 | - * |
|
| 152 | - * @since 1.0.0 |
|
| 153 | - * |
|
| 154 | - * @param array $args |
|
| 155 | - * |
|
| 156 | - * @return string The rendered component. |
|
| 157 | - */ |
|
| 158 | - public function button( $args = array() ) { |
|
| 159 | - return AUI_Component_Button::get( $args ); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Render and return a bootstrap button component. |
|
| 164 | - * |
|
| 165 | - * @since 1.0.0 |
|
| 166 | - * |
|
| 167 | - * @param array $args |
|
| 168 | - * |
|
| 169 | - * @return string The rendered component. |
|
| 170 | - */ |
|
| 171 | - public function badge( $args = array() ) { |
|
| 172 | - $defaults = array( |
|
| 173 | - 'class' => 'badge badge-primary align-middle', |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - // maybe set type |
|
| 177 | - if ( empty( $args['href'] ) ) { |
|
| 178 | - $defaults['type'] = 'badge'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 183 | - */ |
|
| 184 | - $args = wp_parse_args( $args, $defaults ); |
|
| 185 | - |
|
| 186 | - return AUI_Component_Button::get( $args ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Render and return a bootstrap dropdown component. |
|
| 191 | - * |
|
| 192 | - * @since 1.0.0 |
|
| 193 | - * |
|
| 194 | - * @param array $args |
|
| 195 | - * |
|
| 196 | - * @return string The rendered component. |
|
| 197 | - */ |
|
| 198 | - public function dropdown( $args = array() ) { |
|
| 199 | - return AUI_Component_Dropdown::get( $args ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Render and return a bootstrap select component. |
|
| 204 | - * |
|
| 205 | - * @since 1.0.0 |
|
| 206 | - * |
|
| 207 | - * @param array $args |
|
| 208 | - * |
|
| 209 | - * @return string The rendered component. |
|
| 210 | - */ |
|
| 211 | - public function select( $args = array() ) { |
|
| 212 | - return AUI_Component_Input::select( $args ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Render and return a bootstrap radio component. |
|
| 217 | - * |
|
| 218 | - * @since 1.0.0 |
|
| 219 | - * |
|
| 220 | - * @param array $args |
|
| 221 | - * |
|
| 222 | - * @return string The rendered component. |
|
| 223 | - */ |
|
| 224 | - public function radio( $args = array() ) { |
|
| 225 | - return AUI_Component_Input::radio( $args ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Render and return a bootstrap pagination component. |
|
| 230 | - * |
|
| 231 | - * @since 1.0.0 |
|
| 232 | - * |
|
| 233 | - * @param array $args |
|
| 234 | - * |
|
| 235 | - * @return string The rendered component. |
|
| 236 | - */ |
|
| 237 | - public function pagination( $args = array() ) { |
|
| 238 | - return AUI_Component_Pagination::get( $args ); |
|
| 239 | - } |
|
| 14 | + /** |
|
| 15 | + * Holds the class instance. |
|
| 16 | + * |
|
| 17 | + * @since 1.0.0 |
|
| 18 | + * @var null |
|
| 19 | + */ |
|
| 20 | + private static $instance = null; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Holds the current AUI version number. |
|
| 24 | + * |
|
| 25 | + * @var string $ver The current version number. |
|
| 26 | + */ |
|
| 27 | + public static $ver = '0.1.41'; |
|
| 28 | + |
|
| 29 | + public static $options = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * There can be only one. |
|
| 33 | + * |
|
| 34 | + * @since 1.0.0 |
|
| 35 | + * @return AUI|null |
|
| 36 | + */ |
|
| 37 | + public static function instance() { |
|
| 38 | + if ( self::$instance == null ) { |
|
| 39 | + self::$instance = new AUI(); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + return self::$instance; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * AUI constructor. |
|
| 47 | + * |
|
| 48 | + * @since 1.0.0 |
|
| 49 | + */ |
|
| 50 | + private function __construct() { |
|
| 51 | + if ( function_exists( "__autoload" ) ) { |
|
| 52 | + spl_autoload_register( "__autoload" ); |
|
| 53 | + } |
|
| 54 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 55 | + |
|
| 56 | + // load options |
|
| 57 | + self::$options = get_option('aui_options'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Autoload any components on the fly. |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * |
|
| 65 | + * @param $classname |
|
| 66 | + */ |
|
| 67 | + private function autoload( $classname ) { |
|
| 68 | + $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
| 69 | + $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
| 70 | + if ( $file_path && is_readable( $file_path ) ) { |
|
| 71 | + include_once( $file_path ); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Get the AUI options. |
|
| 77 | + * |
|
| 78 | + * @param $option |
|
| 79 | + * |
|
| 80 | + * @return string|void |
|
| 81 | + */ |
|
| 82 | + public function get_option( $option ){ |
|
| 83 | + $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
| 84 | + |
|
| 85 | + if ( ! $result && $option) { |
|
| 86 | + if( $option == 'color_primary' ){ |
|
| 87 | + $result = AUI_PRIMARY_COLOR; |
|
| 88 | + }elseif( $option == 'color_secondary' ){ |
|
| 89 | + $result = AUI_SECONDARY_COLOR; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + return $result; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function render( $items = array() ) { |
|
| 96 | + $output = ''; |
|
| 97 | + |
|
| 98 | + if ( ! empty( $items ) ) { |
|
| 99 | + foreach ( $items as $args ) { |
|
| 100 | + $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
| 101 | + if ( $render && method_exists( __CLASS__, $render ) ) { |
|
| 102 | + $output .= $this->$render( $args ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $output; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Render and return a bootstrap alert component. |
|
| 112 | + * |
|
| 113 | + * @since 1.0.0 |
|
| 114 | + * |
|
| 115 | + * @param array $args |
|
| 116 | + * |
|
| 117 | + * @return string The rendered component. |
|
| 118 | + */ |
|
| 119 | + public function alert( $args = array() ) { |
|
| 120 | + return AUI_Component_Alert::get( $args ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Render and return a bootstrap input component. |
|
| 125 | + * |
|
| 126 | + * @since 1.0.0 |
|
| 127 | + * |
|
| 128 | + * @param array $args |
|
| 129 | + * |
|
| 130 | + * @return string The rendered component. |
|
| 131 | + */ |
|
| 132 | + public function input( $args = array() ) { |
|
| 133 | + return AUI_Component_Input::input( $args ); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Render and return a bootstrap textarea component. |
|
| 138 | + * |
|
| 139 | + * @since 1.0.0 |
|
| 140 | + * |
|
| 141 | + * @param array $args |
|
| 142 | + * |
|
| 143 | + * @return string The rendered component. |
|
| 144 | + */ |
|
| 145 | + public function textarea( $args = array() ) { |
|
| 146 | + return AUI_Component_Input::textarea( $args ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Render and return a bootstrap button component. |
|
| 151 | + * |
|
| 152 | + * @since 1.0.0 |
|
| 153 | + * |
|
| 154 | + * @param array $args |
|
| 155 | + * |
|
| 156 | + * @return string The rendered component. |
|
| 157 | + */ |
|
| 158 | + public function button( $args = array() ) { |
|
| 159 | + return AUI_Component_Button::get( $args ); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Render and return a bootstrap button component. |
|
| 164 | + * |
|
| 165 | + * @since 1.0.0 |
|
| 166 | + * |
|
| 167 | + * @param array $args |
|
| 168 | + * |
|
| 169 | + * @return string The rendered component. |
|
| 170 | + */ |
|
| 171 | + public function badge( $args = array() ) { |
|
| 172 | + $defaults = array( |
|
| 173 | + 'class' => 'badge badge-primary align-middle', |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + // maybe set type |
|
| 177 | + if ( empty( $args['href'] ) ) { |
|
| 178 | + $defaults['type'] = 'badge'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 183 | + */ |
|
| 184 | + $args = wp_parse_args( $args, $defaults ); |
|
| 185 | + |
|
| 186 | + return AUI_Component_Button::get( $args ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Render and return a bootstrap dropdown component. |
|
| 191 | + * |
|
| 192 | + * @since 1.0.0 |
|
| 193 | + * |
|
| 194 | + * @param array $args |
|
| 195 | + * |
|
| 196 | + * @return string The rendered component. |
|
| 197 | + */ |
|
| 198 | + public function dropdown( $args = array() ) { |
|
| 199 | + return AUI_Component_Dropdown::get( $args ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Render and return a bootstrap select component. |
|
| 204 | + * |
|
| 205 | + * @since 1.0.0 |
|
| 206 | + * |
|
| 207 | + * @param array $args |
|
| 208 | + * |
|
| 209 | + * @return string The rendered component. |
|
| 210 | + */ |
|
| 211 | + public function select( $args = array() ) { |
|
| 212 | + return AUI_Component_Input::select( $args ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Render and return a bootstrap radio component. |
|
| 217 | + * |
|
| 218 | + * @since 1.0.0 |
|
| 219 | + * |
|
| 220 | + * @param array $args |
|
| 221 | + * |
|
| 222 | + * @return string The rendered component. |
|
| 223 | + */ |
|
| 224 | + public function radio( $args = array() ) { |
|
| 225 | + return AUI_Component_Input::radio( $args ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Render and return a bootstrap pagination component. |
|
| 230 | + * |
|
| 231 | + * @since 1.0.0 |
|
| 232 | + * |
|
| 233 | + * @param array $args |
|
| 234 | + * |
|
| 235 | + * @return string The rendered component. |
|
| 236 | + */ |
|
| 237 | + public function pagination( $args = array() ) { |
|
| 238 | + return AUI_Component_Pagination::get( $args ); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | 241 | } |
| 242 | 242 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // Exit if accessed directly |
|
| 4 | + exit; // Exit if accessed directly |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -11,372 +11,372 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI_Component_Helper { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * A component helper for generating a input name. |
|
| 16 | - * |
|
| 17 | - * @param $text |
|
| 18 | - * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
| 19 | - * |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public static function name($text,$multiple = false){ |
|
| 23 | - $output = ''; |
|
| 24 | - |
|
| 25 | - if($text){ |
|
| 26 | - $is_multiple = strpos($text, '[') === false && $multiple ? '[]' : ''; |
|
| 27 | - $output = ' name="'.esc_attr($text).$is_multiple.'" '; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - return $output; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * A component helper for generating a item id. |
|
| 35 | - * |
|
| 36 | - * @param $text string The text to be used as the value. |
|
| 37 | - * |
|
| 38 | - * @return string The sanitized item. |
|
| 39 | - */ |
|
| 40 | - public static function id($text){ |
|
| 41 | - $output = ''; |
|
| 42 | - |
|
| 43 | - if($text){ |
|
| 44 | - $output = ' id="'.sanitize_html_class($text).'" '; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - return $output; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * A component helper for generating a item title. |
|
| 52 | - * |
|
| 53 | - * @param $text string The text to be used as the value. |
|
| 54 | - * |
|
| 55 | - * @return string The sanitized item. |
|
| 56 | - */ |
|
| 57 | - public static function title($text){ |
|
| 58 | - $output = ''; |
|
| 59 | - |
|
| 60 | - if($text){ |
|
| 61 | - $output = ' title="'.esc_attr($text).'" '; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - return $output; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * A component helper for generating a item value. |
|
| 69 | - * |
|
| 70 | - * @param $text string The text to be used as the value. |
|
| 71 | - * |
|
| 72 | - * @return string The sanitized item. |
|
| 73 | - */ |
|
| 74 | - public static function value($text){ |
|
| 75 | - $output = ''; |
|
| 76 | - |
|
| 77 | - if($text){ |
|
| 78 | - $output = ' value="'.sanitize_text_field($text).'" '; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - return $output; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * A component helper for generating a item class attribute. |
|
| 86 | - * |
|
| 87 | - * @param $text string The text to be used as the value. |
|
| 88 | - * |
|
| 89 | - * @return string The sanitized item. |
|
| 90 | - */ |
|
| 91 | - public static function class_attr($text){ |
|
| 92 | - $output = ''; |
|
| 93 | - |
|
| 94 | - if($text){ |
|
| 95 | - $classes = self::esc_classes($text); |
|
| 96 | - if(!empty($classes)){ |
|
| 97 | - $output = ' class="'.$classes.'" '; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $output; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Escape a string of classes. |
|
| 106 | - * |
|
| 107 | - * @param $text |
|
| 108 | - * |
|
| 109 | - * @return string |
|
| 110 | - */ |
|
| 111 | - public static function esc_classes($text){ |
|
| 112 | - $output = ''; |
|
| 113 | - |
|
| 114 | - if($text){ |
|
| 115 | - $classes = explode(" ",$text); |
|
| 116 | - $classes = array_map("trim",$classes); |
|
| 117 | - $classes = array_map("sanitize_html_class",$classes); |
|
| 118 | - if(!empty($classes)){ |
|
| 119 | - $output = implode(" ",$classes); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $output; |
|
| 124 | - |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param $args |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public static function data_attributes($args){ |
|
| 133 | - $output = ''; |
|
| 134 | - |
|
| 135 | - if(!empty($args)){ |
|
| 136 | - |
|
| 137 | - foreach($args as $key => $val){ |
|
| 138 | - if(substr( $key, 0, 5 ) === "data-"){ |
|
| 139 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $output; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param $args |
|
| 149 | - * |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public static function aria_attributes($args){ |
|
| 153 | - $output = ''; |
|
| 154 | - |
|
| 155 | - if(!empty($args)){ |
|
| 156 | - |
|
| 157 | - foreach($args as $key => $val){ |
|
| 158 | - if(substr( $key, 0, 5 ) === "aria-"){ |
|
| 159 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $output; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Build a font awesome icon from a class. |
|
| 169 | - * |
|
| 170 | - * @param $class |
|
| 171 | - * @param bool $space_after |
|
| 172 | - * @param array $extra_attributes An array of extra attributes. |
|
| 173 | - * |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
| 177 | - $output = ''; |
|
| 178 | - |
|
| 179 | - if($class){ |
|
| 180 | - $classes = self::esc_classes($class); |
|
| 181 | - if(!empty($classes)){ |
|
| 182 | - $output = '<i class="'.$classes.'" '; |
|
| 183 | - // extra attributes |
|
| 184 | - if(!empty($extra_attributes)){ |
|
| 185 | - $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
| 186 | - } |
|
| 187 | - $output .= '></i>'; |
|
| 188 | - if($space_after){ |
|
| 189 | - $output .= " "; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $output; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param $args |
|
| 199 | - * |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public static function extra_attributes($args){ |
|
| 203 | - $output = ''; |
|
| 204 | - |
|
| 205 | - if(!empty($args)){ |
|
| 206 | - |
|
| 207 | - if( is_array($args) ){ |
|
| 208 | - foreach($args as $key => $val){ |
|
| 209 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 210 | - } |
|
| 211 | - }else{ |
|
| 212 | - $output .= ' '.$args.' '; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $output; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @param $args |
|
| 222 | - * |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public static function help_text($text){ |
|
| 226 | - $output = ''; |
|
| 227 | - |
|
| 228 | - if($text){ |
|
| 229 | - $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - return $output; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Replace element require context with JS. |
|
| 238 | - * |
|
| 239 | - * @param $input |
|
| 240 | - * |
|
| 241 | - * @return string|void |
|
| 242 | - */ |
|
| 243 | - public static function element_require( $input ) { |
|
| 244 | - |
|
| 245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 246 | - |
|
| 247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
| 248 | - "jQuery(form).find('[data-argument=\"", |
|
| 249 | - "\"]').find('input,select,textarea').val()", |
|
| 250 | - "\"]').find('input:checked').val()", |
|
| 251 | - ), $input ) ); |
|
| 252 | - |
|
| 253 | - if($output){ |
|
| 254 | - $output = ' data-element-require="'.$output.'" '; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $output; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Returns an array of allowed HTML tags and attributes for a given context. |
|
| 262 | - * |
|
| 263 | - * @since 0.1.41 |
|
| 264 | - * |
|
| 265 | - * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
| 266 | - * 'strip', 'data', 'entities', or the name of a field filter such as |
|
| 267 | - * 'pre_user_description'. |
|
| 268 | - * @param array $input Input. |
|
| 269 | - * @return array Array of allowed HTML tags and their allowed attributes. |
|
| 270 | - */ |
|
| 271 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
| 272 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
| 273 | - |
|
| 274 | - if ( is_array( $allowed_html ) ) { |
|
| 275 | - // <iframe> |
|
| 276 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
| 277 | - $allowed_html['iframe'] = array( |
|
| 278 | - 'class' => true, |
|
| 279 | - 'id' => true, |
|
| 280 | - 'src' => true, |
|
| 281 | - 'width' => true, |
|
| 282 | - 'height' => true, |
|
| 283 | - 'frameborder' => true, |
|
| 284 | - 'marginwidth' => true, |
|
| 285 | - 'marginheight' => true, |
|
| 286 | - 'scrolling' => true, |
|
| 287 | - 'style' => true, |
|
| 288 | - 'title' => true, |
|
| 289 | - 'allow' => true, |
|
| 290 | - 'allowfullscreen' => true, |
|
| 291 | - 'data-*' => true, |
|
| 292 | - ); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Filters the allowed html tags. |
|
| 298 | - * |
|
| 299 | - * @since 0.1.41 |
|
| 300 | - * |
|
| 301 | - * @param array[]|string $allowed_html Allowed html tags. |
|
| 302 | - * @param @param string|array $context The context for which to retrieve tags. |
|
| 303 | - * @param array $input Input field. |
|
| 304 | - */ |
|
| 305 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Filters content and keeps only allowable HTML elements. |
|
| 310 | - * |
|
| 311 | - * This function makes sure that only the allowed HTML element names, attribute |
|
| 312 | - * names and attribute values plus only sane HTML entities will occur in |
|
| 313 | - * $string. You have to remove any slashes from PHP's magic quotes before you |
|
| 314 | - * call this function. |
|
| 315 | - * |
|
| 316 | - * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
| 317 | - * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
| 318 | - * covers all common link protocols, except for 'javascript' which should not |
|
| 319 | - * be allowed for untrusted users. |
|
| 320 | - * |
|
| 321 | - * @since 0.1.41 |
|
| 322 | - * |
|
| 323 | - * @param string|array $value Content to filter through kses. |
|
| 324 | - * @param array $input Input Field. |
|
| 325 | - * @return string Filtered content with only allowed HTML elements. |
|
| 326 | - */ |
|
| 327 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
| 328 | - if ( $value === '' ) { |
|
| 329 | - return $value; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
| 333 | - |
|
| 334 | - if ( ! is_array( $allowed_html ) ) { |
|
| 335 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $filtered = trim( wp_unslash( $value ) ); |
|
| 339 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
| 340 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
| 341 | - |
|
| 342 | - return $filtered; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
| 347 | - * |
|
| 348 | - * @since 0.1.41 |
|
| 349 | - * |
|
| 350 | - * @param mixed $value The value to be stripped. |
|
| 351 | - * @param array $input Input Field. |
|
| 352 | - * @return mixed Stripped value. |
|
| 353 | - */ |
|
| 354 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
| 355 | - $original = $value; |
|
| 356 | - |
|
| 357 | - if ( is_array( $value ) ) { |
|
| 358 | - foreach ( $value as $index => $item ) { |
|
| 359 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
| 360 | - } |
|
| 361 | - } elseif ( is_object( $value ) ) { |
|
| 362 | - $object_vars = get_object_vars( $value ); |
|
| 363 | - |
|
| 364 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 365 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
| 366 | - } |
|
| 367 | - } else { |
|
| 368 | - $value = self::_sanitize_html_field( $value, $input ); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Filters content and keeps only allowable HTML elements. |
|
| 373 | - * |
|
| 374 | - * @since 0.1.41 |
|
| 375 | - * |
|
| 376 | - * @param string|array $value Content to filter through kses. |
|
| 377 | - * @param string|array $value Original content without filter. |
|
| 378 | - * @param array $input Input Field. |
|
| 379 | - */ |
|
| 380 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
| 381 | - } |
|
| 14 | + /** |
|
| 15 | + * A component helper for generating a input name. |
|
| 16 | + * |
|
| 17 | + * @param $text |
|
| 18 | + * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
| 19 | + * |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public static function name($text,$multiple = false){ |
|
| 23 | + $output = ''; |
|
| 24 | + |
|
| 25 | + if($text){ |
|
| 26 | + $is_multiple = strpos($text, '[') === false && $multiple ? '[]' : ''; |
|
| 27 | + $output = ' name="'.esc_attr($text).$is_multiple.'" '; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + return $output; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * A component helper for generating a item id. |
|
| 35 | + * |
|
| 36 | + * @param $text string The text to be used as the value. |
|
| 37 | + * |
|
| 38 | + * @return string The sanitized item. |
|
| 39 | + */ |
|
| 40 | + public static function id($text){ |
|
| 41 | + $output = ''; |
|
| 42 | + |
|
| 43 | + if($text){ |
|
| 44 | + $output = ' id="'.sanitize_html_class($text).'" '; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + return $output; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * A component helper for generating a item title. |
|
| 52 | + * |
|
| 53 | + * @param $text string The text to be used as the value. |
|
| 54 | + * |
|
| 55 | + * @return string The sanitized item. |
|
| 56 | + */ |
|
| 57 | + public static function title($text){ |
|
| 58 | + $output = ''; |
|
| 59 | + |
|
| 60 | + if($text){ |
|
| 61 | + $output = ' title="'.esc_attr($text).'" '; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + return $output; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * A component helper for generating a item value. |
|
| 69 | + * |
|
| 70 | + * @param $text string The text to be used as the value. |
|
| 71 | + * |
|
| 72 | + * @return string The sanitized item. |
|
| 73 | + */ |
|
| 74 | + public static function value($text){ |
|
| 75 | + $output = ''; |
|
| 76 | + |
|
| 77 | + if($text){ |
|
| 78 | + $output = ' value="'.sanitize_text_field($text).'" '; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + return $output; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * A component helper for generating a item class attribute. |
|
| 86 | + * |
|
| 87 | + * @param $text string The text to be used as the value. |
|
| 88 | + * |
|
| 89 | + * @return string The sanitized item. |
|
| 90 | + */ |
|
| 91 | + public static function class_attr($text){ |
|
| 92 | + $output = ''; |
|
| 93 | + |
|
| 94 | + if($text){ |
|
| 95 | + $classes = self::esc_classes($text); |
|
| 96 | + if(!empty($classes)){ |
|
| 97 | + $output = ' class="'.$classes.'" '; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $output; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Escape a string of classes. |
|
| 106 | + * |
|
| 107 | + * @param $text |
|
| 108 | + * |
|
| 109 | + * @return string |
|
| 110 | + */ |
|
| 111 | + public static function esc_classes($text){ |
|
| 112 | + $output = ''; |
|
| 113 | + |
|
| 114 | + if($text){ |
|
| 115 | + $classes = explode(" ",$text); |
|
| 116 | + $classes = array_map("trim",$classes); |
|
| 117 | + $classes = array_map("sanitize_html_class",$classes); |
|
| 118 | + if(!empty($classes)){ |
|
| 119 | + $output = implode(" ",$classes); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $output; |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param $args |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public static function data_attributes($args){ |
|
| 133 | + $output = ''; |
|
| 134 | + |
|
| 135 | + if(!empty($args)){ |
|
| 136 | + |
|
| 137 | + foreach($args as $key => $val){ |
|
| 138 | + if(substr( $key, 0, 5 ) === "data-"){ |
|
| 139 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $output; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param $args |
|
| 149 | + * |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public static function aria_attributes($args){ |
|
| 153 | + $output = ''; |
|
| 154 | + |
|
| 155 | + if(!empty($args)){ |
|
| 156 | + |
|
| 157 | + foreach($args as $key => $val){ |
|
| 158 | + if(substr( $key, 0, 5 ) === "aria-"){ |
|
| 159 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $output; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Build a font awesome icon from a class. |
|
| 169 | + * |
|
| 170 | + * @param $class |
|
| 171 | + * @param bool $space_after |
|
| 172 | + * @param array $extra_attributes An array of extra attributes. |
|
| 173 | + * |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
| 177 | + $output = ''; |
|
| 178 | + |
|
| 179 | + if($class){ |
|
| 180 | + $classes = self::esc_classes($class); |
|
| 181 | + if(!empty($classes)){ |
|
| 182 | + $output = '<i class="'.$classes.'" '; |
|
| 183 | + // extra attributes |
|
| 184 | + if(!empty($extra_attributes)){ |
|
| 185 | + $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
| 186 | + } |
|
| 187 | + $output .= '></i>'; |
|
| 188 | + if($space_after){ |
|
| 189 | + $output .= " "; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $output; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param $args |
|
| 199 | + * |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public static function extra_attributes($args){ |
|
| 203 | + $output = ''; |
|
| 204 | + |
|
| 205 | + if(!empty($args)){ |
|
| 206 | + |
|
| 207 | + if( is_array($args) ){ |
|
| 208 | + foreach($args as $key => $val){ |
|
| 209 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 210 | + } |
|
| 211 | + }else{ |
|
| 212 | + $output .= ' '.$args.' '; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return $output; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @param $args |
|
| 222 | + * |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public static function help_text($text){ |
|
| 226 | + $output = ''; |
|
| 227 | + |
|
| 228 | + if($text){ |
|
| 229 | + $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + return $output; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Replace element require context with JS. |
|
| 238 | + * |
|
| 239 | + * @param $input |
|
| 240 | + * |
|
| 241 | + * @return string|void |
|
| 242 | + */ |
|
| 243 | + public static function element_require( $input ) { |
|
| 244 | + |
|
| 245 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 246 | + |
|
| 247 | + $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
| 248 | + "jQuery(form).find('[data-argument=\"", |
|
| 249 | + "\"]').find('input,select,textarea').val()", |
|
| 250 | + "\"]').find('input:checked').val()", |
|
| 251 | + ), $input ) ); |
|
| 252 | + |
|
| 253 | + if($output){ |
|
| 254 | + $output = ' data-element-require="'.$output.'" '; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $output; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Returns an array of allowed HTML tags and attributes for a given context. |
|
| 262 | + * |
|
| 263 | + * @since 0.1.41 |
|
| 264 | + * |
|
| 265 | + * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
| 266 | + * 'strip', 'data', 'entities', or the name of a field filter such as |
|
| 267 | + * 'pre_user_description'. |
|
| 268 | + * @param array $input Input. |
|
| 269 | + * @return array Array of allowed HTML tags and their allowed attributes. |
|
| 270 | + */ |
|
| 271 | + public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
| 272 | + $allowed_html = wp_kses_allowed_html( $context ); |
|
| 273 | + |
|
| 274 | + if ( is_array( $allowed_html ) ) { |
|
| 275 | + // <iframe> |
|
| 276 | + if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
| 277 | + $allowed_html['iframe'] = array( |
|
| 278 | + 'class' => true, |
|
| 279 | + 'id' => true, |
|
| 280 | + 'src' => true, |
|
| 281 | + 'width' => true, |
|
| 282 | + 'height' => true, |
|
| 283 | + 'frameborder' => true, |
|
| 284 | + 'marginwidth' => true, |
|
| 285 | + 'marginheight' => true, |
|
| 286 | + 'scrolling' => true, |
|
| 287 | + 'style' => true, |
|
| 288 | + 'title' => true, |
|
| 289 | + 'allow' => true, |
|
| 290 | + 'allowfullscreen' => true, |
|
| 291 | + 'data-*' => true, |
|
| 292 | + ); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Filters the allowed html tags. |
|
| 298 | + * |
|
| 299 | + * @since 0.1.41 |
|
| 300 | + * |
|
| 301 | + * @param array[]|string $allowed_html Allowed html tags. |
|
| 302 | + * @param @param string|array $context The context for which to retrieve tags. |
|
| 303 | + * @param array $input Input field. |
|
| 304 | + */ |
|
| 305 | + return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Filters content and keeps only allowable HTML elements. |
|
| 310 | + * |
|
| 311 | + * This function makes sure that only the allowed HTML element names, attribute |
|
| 312 | + * names and attribute values plus only sane HTML entities will occur in |
|
| 313 | + * $string. You have to remove any slashes from PHP's magic quotes before you |
|
| 314 | + * call this function. |
|
| 315 | + * |
|
| 316 | + * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
| 317 | + * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
| 318 | + * covers all common link protocols, except for 'javascript' which should not |
|
| 319 | + * be allowed for untrusted users. |
|
| 320 | + * |
|
| 321 | + * @since 0.1.41 |
|
| 322 | + * |
|
| 323 | + * @param string|array $value Content to filter through kses. |
|
| 324 | + * @param array $input Input Field. |
|
| 325 | + * @return string Filtered content with only allowed HTML elements. |
|
| 326 | + */ |
|
| 327 | + public static function _sanitize_html_field( $value, $input = array() ) { |
|
| 328 | + if ( $value === '' ) { |
|
| 329 | + return $value; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
| 333 | + |
|
| 334 | + if ( ! is_array( $allowed_html ) ) { |
|
| 335 | + $allowed_html = wp_kses_allowed_html( 'post' ); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $filtered = trim( wp_unslash( $value ) ); |
|
| 339 | + $filtered = wp_kses( $filtered, $allowed_html ); |
|
| 340 | + $filtered = balanceTags( $filtered ); // Balances tags |
|
| 341 | + |
|
| 342 | + return $filtered; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
| 347 | + * |
|
| 348 | + * @since 0.1.41 |
|
| 349 | + * |
|
| 350 | + * @param mixed $value The value to be stripped. |
|
| 351 | + * @param array $input Input Field. |
|
| 352 | + * @return mixed Stripped value. |
|
| 353 | + */ |
|
| 354 | + public static function sanitize_html_field( $value, $input = array() ) { |
|
| 355 | + $original = $value; |
|
| 356 | + |
|
| 357 | + if ( is_array( $value ) ) { |
|
| 358 | + foreach ( $value as $index => $item ) { |
|
| 359 | + $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
| 360 | + } |
|
| 361 | + } elseif ( is_object( $value ) ) { |
|
| 362 | + $object_vars = get_object_vars( $value ); |
|
| 363 | + |
|
| 364 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
| 365 | + $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
| 366 | + } |
|
| 367 | + } else { |
|
| 368 | + $value = self::_sanitize_html_field( $value, $input ); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Filters content and keeps only allowable HTML elements. |
|
| 373 | + * |
|
| 374 | + * @since 0.1.41 |
|
| 375 | + * |
|
| 376 | + * @param string|array $value Content to filter through kses. |
|
| 377 | + * @param string|array $value Original content without filter. |
|
| 378 | + * @param array $input Input Field. |
|
| 379 | + */ |
|
| 380 | + return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
| 381 | + } |
|
| 382 | 382 | } |
| 383 | 383 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | +if (!defined('ABSPATH')) { |
|
| 4 | 4 | exit; // Exit if accessed directly |
| 5 | 5 | } |
| 6 | 6 | |
@@ -19,12 +19,12 @@ discard block |
||
| 19 | 19 | * |
| 20 | 20 | * @return string |
| 21 | 21 | */ |
| 22 | - public static function name($text,$multiple = false){ |
|
| 22 | + public static function name($text, $multiple = false) { |
|
| 23 | 23 | $output = ''; |
| 24 | 24 | |
| 25 | - if($text){ |
|
| 26 | - $is_multiple = strpos($text, '[') === false && $multiple ? '[]' : ''; |
|
| 27 | - $output = ' name="'.esc_attr($text).$is_multiple.'" '; |
|
| 25 | + if ($text) { |
|
| 26 | + $is_multiple = strpos($text, '[') === false && $multiple ? '[]' : ''; |
|
| 27 | + $output = ' name="' . esc_attr($text) . $is_multiple . '" '; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | return $output; |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return string The sanitized item. |
| 39 | 39 | */ |
| 40 | - public static function id($text){ |
|
| 40 | + public static function id($text) { |
|
| 41 | 41 | $output = ''; |
| 42 | 42 | |
| 43 | - if($text){ |
|
| 44 | - $output = ' id="'.sanitize_html_class($text).'" '; |
|
| 43 | + if ($text) { |
|
| 44 | + $output = ' id="' . sanitize_html_class($text) . '" '; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | return $output; |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return string The sanitized item. |
| 56 | 56 | */ |
| 57 | - public static function title($text){ |
|
| 57 | + public static function title($text) { |
|
| 58 | 58 | $output = ''; |
| 59 | 59 | |
| 60 | - if($text){ |
|
| 61 | - $output = ' title="'.esc_attr($text).'" '; |
|
| 60 | + if ($text) { |
|
| 61 | + $output = ' title="' . esc_attr($text) . '" '; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | return $output; |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return string The sanitized item. |
| 73 | 73 | */ |
| 74 | - public static function value($text){ |
|
| 74 | + public static function value($text) { |
|
| 75 | 75 | $output = ''; |
| 76 | 76 | |
| 77 | - if($text){ |
|
| 78 | - $output = ' value="'.sanitize_text_field($text).'" '; |
|
| 77 | + if ($text) { |
|
| 78 | + $output = ' value="' . sanitize_text_field($text) . '" '; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | return $output; |
@@ -88,13 +88,13 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return string The sanitized item. |
| 90 | 90 | */ |
| 91 | - public static function class_attr($text){ |
|
| 91 | + public static function class_attr($text) { |
|
| 92 | 92 | $output = ''; |
| 93 | 93 | |
| 94 | - if($text){ |
|
| 94 | + if ($text) { |
|
| 95 | 95 | $classes = self::esc_classes($text); |
| 96 | - if(!empty($classes)){ |
|
| 97 | - $output = ' class="'.$classes.'" '; |
|
| 96 | + if (!empty($classes)) { |
|
| 97 | + $output = ' class="' . $classes . '" '; |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | - public static function esc_classes($text){ |
|
| 111 | + public static function esc_classes($text) { |
|
| 112 | 112 | $output = ''; |
| 113 | 113 | |
| 114 | - if($text){ |
|
| 115 | - $classes = explode(" ",$text); |
|
| 116 | - $classes = array_map("trim",$classes); |
|
| 117 | - $classes = array_map("sanitize_html_class",$classes); |
|
| 118 | - if(!empty($classes)){ |
|
| 119 | - $output = implode(" ",$classes); |
|
| 114 | + if ($text) { |
|
| 115 | + $classes = explode(" ", $text); |
|
| 116 | + $classes = array_map("trim", $classes); |
|
| 117 | + $classes = array_map("sanitize_html_class", $classes); |
|
| 118 | + if (!empty($classes)) { |
|
| 119 | + $output = implode(" ", $classes); |
|
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | - public static function data_attributes($args){ |
|
| 132 | + public static function data_attributes($args) { |
|
| 133 | 133 | $output = ''; |
| 134 | 134 | |
| 135 | - if(!empty($args)){ |
|
| 135 | + if (!empty($args)) { |
|
| 136 | 136 | |
| 137 | - foreach($args as $key => $val){ |
|
| 138 | - if(substr( $key, 0, 5 ) === "data-"){ |
|
| 139 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 137 | + foreach ($args as $key => $val) { |
|
| 138 | + if (substr($key, 0, 5) === "data-") { |
|
| 139 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -149,14 +149,14 @@ discard block |
||
| 149 | 149 | * |
| 150 | 150 | * @return string |
| 151 | 151 | */ |
| 152 | - public static function aria_attributes($args){ |
|
| 152 | + public static function aria_attributes($args) { |
|
| 153 | 153 | $output = ''; |
| 154 | 154 | |
| 155 | - if(!empty($args)){ |
|
| 155 | + if (!empty($args)) { |
|
| 156 | 156 | |
| 157 | - foreach($args as $key => $val){ |
|
| 158 | - if(substr( $key, 0, 5 ) === "aria-"){ |
|
| 159 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 157 | + foreach ($args as $key => $val) { |
|
| 158 | + if (substr($key, 0, 5) === "aria-") { |
|
| 159 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -173,19 +173,19 @@ discard block |
||
| 173 | 173 | * |
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | - public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
| 176 | + public static function icon($class, $space_after = false, $extra_attributes = array()) { |
|
| 177 | 177 | $output = ''; |
| 178 | 178 | |
| 179 | - if($class){ |
|
| 179 | + if ($class) { |
|
| 180 | 180 | $classes = self::esc_classes($class); |
| 181 | - if(!empty($classes)){ |
|
| 182 | - $output = '<i class="'.$classes.'" '; |
|
| 181 | + if (!empty($classes)) { |
|
| 182 | + $output = '<i class="' . $classes . '" '; |
|
| 183 | 183 | // extra attributes |
| 184 | - if(!empty($extra_attributes)){ |
|
| 184 | + if (!empty($extra_attributes)) { |
|
| 185 | 185 | $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
| 186 | 186 | } |
| 187 | 187 | $output .= '></i>'; |
| 188 | - if($space_after){ |
|
| 188 | + if ($space_after) { |
|
| 189 | 189 | $output .= " "; |
| 190 | 190 | } |
| 191 | 191 | } |
@@ -199,17 +199,17 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public static function extra_attributes($args){ |
|
| 202 | + public static function extra_attributes($args) { |
|
| 203 | 203 | $output = ''; |
| 204 | 204 | |
| 205 | - if(!empty($args)){ |
|
| 205 | + if (!empty($args)) { |
|
| 206 | 206 | |
| 207 | - if( is_array($args) ){ |
|
| 208 | - foreach($args as $key => $val){ |
|
| 209 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 207 | + if (is_array($args)) { |
|
| 208 | + foreach ($args as $key => $val) { |
|
| 209 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
| 210 | 210 | } |
| 211 | - }else{ |
|
| 212 | - $output .= ' '.$args.' '; |
|
| 211 | + } else { |
|
| 212 | + $output .= ' ' . $args . ' '; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | } |
@@ -222,11 +222,11 @@ discard block |
||
| 222 | 222 | * |
| 223 | 223 | * @return string |
| 224 | 224 | */ |
| 225 | - public static function help_text($text){ |
|
| 225 | + public static function help_text($text) { |
|
| 226 | 226 | $output = ''; |
| 227 | 227 | |
| 228 | - if($text){ |
|
| 229 | - $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
| 228 | + if ($text) { |
|
| 229 | + $output .= '<small class="form-text text-muted">' . wp_kses_post($text) . '</small>'; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -240,18 +240,18 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return string|void |
| 242 | 242 | */ |
| 243 | - public static function element_require( $input ) { |
|
| 243 | + public static function element_require($input) { |
|
| 244 | 244 | |
| 245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 245 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
| 246 | 246 | |
| 247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
| 247 | + $output = esc_attr(str_replace(array("[%", "%]", "%:checked]"), array( |
|
| 248 | 248 | "jQuery(form).find('[data-argument=\"", |
| 249 | 249 | "\"]').find('input,select,textarea').val()", |
| 250 | 250 | "\"]').find('input:checked').val()", |
| 251 | - ), $input ) ); |
|
| 251 | + ), $input)); |
|
| 252 | 252 | |
| 253 | - if($output){ |
|
| 254 | - $output = ' data-element-require="'.$output.'" '; |
|
| 253 | + if ($output) { |
|
| 254 | + $output = ' data-element-require="' . $output . '" '; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | return $output; |
@@ -268,13 +268,13 @@ discard block |
||
| 268 | 268 | * @param array $input Input. |
| 269 | 269 | * @return array Array of allowed HTML tags and their allowed attributes. |
| 270 | 270 | */ |
| 271 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
| 272 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
| 271 | + public static function kses_allowed_html($context = 'post', $input = array()) { |
|
| 272 | + $allowed_html = wp_kses_allowed_html($context); |
|
| 273 | 273 | |
| 274 | - if ( is_array( $allowed_html ) ) { |
|
| 274 | + if (is_array($allowed_html)) { |
|
| 275 | 275 | // <iframe> |
| 276 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
| 277 | - $allowed_html['iframe'] = array( |
|
| 276 | + if (!isset($allowed_html['iframe']) && $context == 'post') { |
|
| 277 | + $allowed_html['iframe'] = array( |
|
| 278 | 278 | 'class' => true, |
| 279 | 279 | 'id' => true, |
| 280 | 280 | 'src' => true, |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * @param @param string|array $context The context for which to retrieve tags. |
| 303 | 303 | * @param array $input Input field. |
| 304 | 304 | */ |
| 305 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
| 305 | + return apply_filters('ayecode_ui_kses_allowed_html', $allowed_html, $context, $input); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -324,20 +324,20 @@ discard block |
||
| 324 | 324 | * @param array $input Input Field. |
| 325 | 325 | * @return string Filtered content with only allowed HTML elements. |
| 326 | 326 | */ |
| 327 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
| 328 | - if ( $value === '' ) { |
|
| 327 | + public static function _sanitize_html_field($value, $input = array()) { |
|
| 328 | + if ($value === '') { |
|
| 329 | 329 | return $value; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
| 332 | + $allowed_html = self::kses_allowed_html('post', $input); |
|
| 333 | 333 | |
| 334 | - if ( ! is_array( $allowed_html ) ) { |
|
| 335 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
| 334 | + if (!is_array($allowed_html)) { |
|
| 335 | + $allowed_html = wp_kses_allowed_html('post'); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - $filtered = trim( wp_unslash( $value ) ); |
|
| 339 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
| 340 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
| 338 | + $filtered = trim(wp_unslash($value)); |
|
| 339 | + $filtered = wp_kses($filtered, $allowed_html); |
|
| 340 | + $filtered = balanceTags($filtered); // Balances tags |
|
| 341 | 341 | |
| 342 | 342 | return $filtered; |
| 343 | 343 | } |
@@ -351,21 +351,21 @@ discard block |
||
| 351 | 351 | * @param array $input Input Field. |
| 352 | 352 | * @return mixed Stripped value. |
| 353 | 353 | */ |
| 354 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
| 354 | + public static function sanitize_html_field($value, $input = array()) { |
|
| 355 | 355 | $original = $value; |
| 356 | 356 | |
| 357 | - if ( is_array( $value ) ) { |
|
| 358 | - foreach ( $value as $index => $item ) { |
|
| 359 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
| 357 | + if (is_array($value)) { |
|
| 358 | + foreach ($value as $index => $item) { |
|
| 359 | + $value[$index] = self::_sanitize_html_field($value, $input); |
|
| 360 | 360 | } |
| 361 | - } elseif ( is_object( $value ) ) { |
|
| 362 | - $object_vars = get_object_vars( $value ); |
|
| 361 | + } elseif (is_object($value)) { |
|
| 362 | + $object_vars = get_object_vars($value); |
|
| 363 | 363 | |
| 364 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
| 365 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
| 364 | + foreach ($object_vars as $property_name => $property_value) { |
|
| 365 | + $value->$property_name = self::_sanitize_html_field($property_value, $input); |
|
| 366 | 366 | } |
| 367 | 367 | } else { |
| 368 | - $value = self::_sanitize_html_field( $value, $input ); |
|
| 368 | + $value = self::_sanitize_html_field($value, $input); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
@@ -377,6 +377,6 @@ discard block |
||
| 377 | 377 | * @param string|array $value Original content without filter. |
| 378 | 378 | * @param array $input Input Field. |
| 379 | 379 | */ |
| 380 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
| 380 | + return apply_filters('ayecode_ui_sanitize_html_field', $value, $original, $input); |
|
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // Exit if accessed directly |
|
| 4 | + exit; // Exit if accessed directly |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -11,1022 +11,1022 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI_Component_Input { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Build the component. |
|
| 16 | - * |
|
| 17 | - * @param array $args |
|
| 18 | - * |
|
| 19 | - * @return string The rendered component. |
|
| 20 | - */ |
|
| 21 | - public static function input($args = array()){ |
|
| 22 | - $defaults = array( |
|
| 23 | - 'type' => 'text', |
|
| 24 | - 'name' => '', |
|
| 25 | - 'class' => '', |
|
| 26 | - 'wrap_class' => '', |
|
| 27 | - 'id' => '', |
|
| 28 | - 'placeholder'=> '', |
|
| 29 | - 'title' => '', |
|
| 30 | - 'value' => '', |
|
| 31 | - 'required' => false, |
|
| 32 | - 'label' => '', |
|
| 33 | - 'label_after'=> false, |
|
| 34 | - 'label_class'=> '', |
|
| 35 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 36 | - 'help_text' => '', |
|
| 37 | - 'validation_text' => '', |
|
| 38 | - 'validation_pattern' => '', |
|
| 39 | - 'no_wrap' => false, |
|
| 40 | - 'input_group_right' => '', |
|
| 41 | - 'input_group_left' => '', |
|
| 42 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
| 43 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
| 44 | - 'step' => '', |
|
| 45 | - 'switch' => false, // to show checkbox as a switch |
|
| 46 | - 'checked' => false, // set a checkbox or radio as selected |
|
| 47 | - 'password_toggle' => true, // toggle view/hide password |
|
| 48 | - 'element_require' => '', // [%element_id%] == "1" |
|
| 49 | - 'extra_attributes' => array() // an array of extra attributes |
|
| 50 | - ); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 54 | - */ |
|
| 55 | - $args = wp_parse_args( $args, $defaults ); |
|
| 56 | - $output = ''; |
|
| 57 | - if ( ! empty( $args['type'] ) ) { |
|
| 58 | - // hidden label option needs to be empty |
|
| 59 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 60 | - |
|
| 61 | - $type = sanitize_html_class( $args['type'] ); |
|
| 62 | - |
|
| 63 | - $help_text = ''; |
|
| 64 | - $label = ''; |
|
| 65 | - $label_after = $args['label_after']; |
|
| 66 | - $label_args = array( |
|
| 67 | - 'title'=> $args['label'], |
|
| 68 | - 'for'=> $args['id'], |
|
| 69 | - 'class' => $args['label_class']." ", |
|
| 70 | - 'label_type' => $args['label_type'] |
|
| 71 | - ); |
|
| 72 | - |
|
| 73 | - // floating labels need label after |
|
| 74 | - if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
| 75 | - $label_after = true; |
|
| 76 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // Some special sauce for files |
|
| 80 | - if($type=='file' ){ |
|
| 81 | - $label_after = true; // if type file we need the label after |
|
| 82 | - $args['class'] .= ' custom-file-input '; |
|
| 83 | - }elseif($type=='checkbox'){ |
|
| 84 | - $label_after = true; // if type file we need the label after |
|
| 85 | - $args['class'] .= ' custom-control-input '; |
|
| 86 | - }elseif($type=='datepicker' || $type=='timepicker'){ |
|
| 87 | - $type = 'text'; |
|
| 88 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 89 | - $args['class'] .= ' bg-initial '; |
|
| 90 | - |
|
| 91 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
| 92 | - // enqueue the script |
|
| 93 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 94 | - $aui_settings->enqueue_flatpickr(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - // open/type |
|
| 99 | - $output .= '<input type="' . $type . '" '; |
|
| 100 | - |
|
| 101 | - // name |
|
| 102 | - if(!empty($args['name'])){ |
|
| 103 | - $output .= ' name="'.esc_attr($args['name']).'" '; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // id |
|
| 107 | - if(!empty($args['id'])){ |
|
| 108 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // placeholder |
|
| 112 | - if(isset($args['placeholder']) && '' != $args['placeholder'] ){ |
|
| 113 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // title |
|
| 117 | - if(!empty($args['title'])){ |
|
| 118 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // value |
|
| 122 | - if(!empty($args['value'])){ |
|
| 123 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // checked, for radio and checkboxes |
|
| 127 | - if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
| 128 | - $output .= ' checked '; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // validation text |
|
| 132 | - if(!empty($args['validation_text'])){ |
|
| 133 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
| 134 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - // validation_pattern |
|
| 138 | - if(!empty($args['validation_pattern'])){ |
|
| 139 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // step (for numbers) |
|
| 143 | - if(!empty($args['step'])){ |
|
| 144 | - $output .= ' step="'.$args['step'].'" '; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // required |
|
| 148 | - if(!empty($args['required'])){ |
|
| 149 | - $output .= ' required '; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // class |
|
| 153 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 154 | - $output .= ' class="form-control '.$class.'" '; |
|
| 155 | - |
|
| 156 | - // data-attributes |
|
| 157 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
| 158 | - |
|
| 159 | - // extra attributes |
|
| 160 | - if(!empty($args['extra_attributes'])){ |
|
| 161 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // close |
|
| 165 | - $output .= ' >'; |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - // label |
|
| 169 | - if(!empty($args['label'])){ |
|
| 170 | - if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
| 171 | - elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
| 172 | - $label = self::label( $label_args, $type ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // help text |
|
| 176 | - if(!empty($args['help_text'])){ |
|
| 177 | - $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - // set help text in the correct possition |
|
| 182 | - if($label_after){ |
|
| 183 | - $output .= $label . $help_text; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // some input types need a separate wrap |
|
| 187 | - if($type == 'file') { |
|
| 188 | - $output = self::wrap( array( |
|
| 189 | - 'content' => $output, |
|
| 190 | - 'class' => 'form-group custom-file' |
|
| 191 | - ) ); |
|
| 192 | - }elseif($type == 'checkbox'){ |
|
| 193 | - $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
| 194 | - $output = self::wrap( array( |
|
| 195 | - 'content' => $output, |
|
| 196 | - 'class' => 'custom-control '.$wrap_class |
|
| 197 | - ) ); |
|
| 198 | - |
|
| 199 | - if($args['label_type']=='horizontal'){ |
|
| 200 | - $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
| 201 | - } |
|
| 202 | - }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - // allow password field to toggle view |
|
| 206 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
| 14 | + /** |
|
| 15 | + * Build the component. |
|
| 16 | + * |
|
| 17 | + * @param array $args |
|
| 18 | + * |
|
| 19 | + * @return string The rendered component. |
|
| 20 | + */ |
|
| 21 | + public static function input($args = array()){ |
|
| 22 | + $defaults = array( |
|
| 23 | + 'type' => 'text', |
|
| 24 | + 'name' => '', |
|
| 25 | + 'class' => '', |
|
| 26 | + 'wrap_class' => '', |
|
| 27 | + 'id' => '', |
|
| 28 | + 'placeholder'=> '', |
|
| 29 | + 'title' => '', |
|
| 30 | + 'value' => '', |
|
| 31 | + 'required' => false, |
|
| 32 | + 'label' => '', |
|
| 33 | + 'label_after'=> false, |
|
| 34 | + 'label_class'=> '', |
|
| 35 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 36 | + 'help_text' => '', |
|
| 37 | + 'validation_text' => '', |
|
| 38 | + 'validation_pattern' => '', |
|
| 39 | + 'no_wrap' => false, |
|
| 40 | + 'input_group_right' => '', |
|
| 41 | + 'input_group_left' => '', |
|
| 42 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
| 43 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
| 44 | + 'step' => '', |
|
| 45 | + 'switch' => false, // to show checkbox as a switch |
|
| 46 | + 'checked' => false, // set a checkbox or radio as selected |
|
| 47 | + 'password_toggle' => true, // toggle view/hide password |
|
| 48 | + 'element_require' => '', // [%element_id%] == "1" |
|
| 49 | + 'extra_attributes' => array() // an array of extra attributes |
|
| 50 | + ); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 54 | + */ |
|
| 55 | + $args = wp_parse_args( $args, $defaults ); |
|
| 56 | + $output = ''; |
|
| 57 | + if ( ! empty( $args['type'] ) ) { |
|
| 58 | + // hidden label option needs to be empty |
|
| 59 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 60 | + |
|
| 61 | + $type = sanitize_html_class( $args['type'] ); |
|
| 62 | + |
|
| 63 | + $help_text = ''; |
|
| 64 | + $label = ''; |
|
| 65 | + $label_after = $args['label_after']; |
|
| 66 | + $label_args = array( |
|
| 67 | + 'title'=> $args['label'], |
|
| 68 | + 'for'=> $args['id'], |
|
| 69 | + 'class' => $args['label_class']." ", |
|
| 70 | + 'label_type' => $args['label_type'] |
|
| 71 | + ); |
|
| 72 | + |
|
| 73 | + // floating labels need label after |
|
| 74 | + if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
| 75 | + $label_after = true; |
|
| 76 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // Some special sauce for files |
|
| 80 | + if($type=='file' ){ |
|
| 81 | + $label_after = true; // if type file we need the label after |
|
| 82 | + $args['class'] .= ' custom-file-input '; |
|
| 83 | + }elseif($type=='checkbox'){ |
|
| 84 | + $label_after = true; // if type file we need the label after |
|
| 85 | + $args['class'] .= ' custom-control-input '; |
|
| 86 | + }elseif($type=='datepicker' || $type=='timepicker'){ |
|
| 87 | + $type = 'text'; |
|
| 88 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 89 | + $args['class'] .= ' bg-initial '; |
|
| 90 | + |
|
| 91 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
| 92 | + // enqueue the script |
|
| 93 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 94 | + $aui_settings->enqueue_flatpickr(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + // open/type |
|
| 99 | + $output .= '<input type="' . $type . '" '; |
|
| 100 | + |
|
| 101 | + // name |
|
| 102 | + if(!empty($args['name'])){ |
|
| 103 | + $output .= ' name="'.esc_attr($args['name']).'" '; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // id |
|
| 107 | + if(!empty($args['id'])){ |
|
| 108 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // placeholder |
|
| 112 | + if(isset($args['placeholder']) && '' != $args['placeholder'] ){ |
|
| 113 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // title |
|
| 117 | + if(!empty($args['title'])){ |
|
| 118 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // value |
|
| 122 | + if(!empty($args['value'])){ |
|
| 123 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // checked, for radio and checkboxes |
|
| 127 | + if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
| 128 | + $output .= ' checked '; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // validation text |
|
| 132 | + if(!empty($args['validation_text'])){ |
|
| 133 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
| 134 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + // validation_pattern |
|
| 138 | + if(!empty($args['validation_pattern'])){ |
|
| 139 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // step (for numbers) |
|
| 143 | + if(!empty($args['step'])){ |
|
| 144 | + $output .= ' step="'.$args['step'].'" '; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // required |
|
| 148 | + if(!empty($args['required'])){ |
|
| 149 | + $output .= ' required '; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // class |
|
| 153 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 154 | + $output .= ' class="form-control '.$class.'" '; |
|
| 155 | + |
|
| 156 | + // data-attributes |
|
| 157 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
| 158 | + |
|
| 159 | + // extra attributes |
|
| 160 | + if(!empty($args['extra_attributes'])){ |
|
| 161 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // close |
|
| 165 | + $output .= ' >'; |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + // label |
|
| 169 | + if(!empty($args['label'])){ |
|
| 170 | + if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
| 171 | + elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
| 172 | + $label = self::label( $label_args, $type ); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // help text |
|
| 176 | + if(!empty($args['help_text'])){ |
|
| 177 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + // set help text in the correct possition |
|
| 182 | + if($label_after){ |
|
| 183 | + $output .= $label . $help_text; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // some input types need a separate wrap |
|
| 187 | + if($type == 'file') { |
|
| 188 | + $output = self::wrap( array( |
|
| 189 | + 'content' => $output, |
|
| 190 | + 'class' => 'form-group custom-file' |
|
| 191 | + ) ); |
|
| 192 | + }elseif($type == 'checkbox'){ |
|
| 193 | + $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
| 194 | + $output = self::wrap( array( |
|
| 195 | + 'content' => $output, |
|
| 196 | + 'class' => 'custom-control '.$wrap_class |
|
| 197 | + ) ); |
|
| 198 | + |
|
| 199 | + if($args['label_type']=='horizontal'){ |
|
| 200 | + $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
| 201 | + } |
|
| 202 | + }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + // allow password field to toggle view |
|
| 206 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
| 207 | 207 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
| 208 | 208 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
| 209 | 209 | if($el.hasClass(\'fa-eye\')) |
| 210 | 210 | {$eli.attr(\'type\',\'text\');} |
| 211 | 211 | else{$eli.attr(\'type\',\'password\');}" |
| 212 | 212 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
| 213 | - } |
|
| 214 | - |
|
| 215 | - // input group wraps |
|
| 216 | - if($args['input_group_left'] || $args['input_group_right']){ |
|
| 217 | - $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
| 218 | - if($args['input_group_left']){ |
|
| 219 | - $output = self::wrap( array( |
|
| 220 | - 'content' => $output, |
|
| 221 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
| 222 | - 'input_group_left' => $args['input_group_left'], |
|
| 223 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 224 | - ) ); |
|
| 225 | - } |
|
| 226 | - if($args['input_group_right']){ |
|
| 227 | - $output = self::wrap( array( |
|
| 228 | - 'content' => $output, |
|
| 229 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
| 230 | - 'input_group_right' => $args['input_group_right'], |
|
| 231 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 232 | - ) ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - if(!$label_after){ |
|
| 238 | - $output .= $help_text; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
| 243 | - $output = self::wrap( array( |
|
| 244 | - 'content' => $output, |
|
| 245 | - 'class' => 'col-sm-10', |
|
| 246 | - ) ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - if(!$label_after){ |
|
| 250 | - $output = $label . $output; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - // wrap |
|
| 254 | - if(!$args['no_wrap']){ |
|
| 255 | - |
|
| 256 | - $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
| 257 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 258 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 259 | - $output = self::wrap(array( |
|
| 260 | - 'content' => $output, |
|
| 261 | - 'class' => $wrap_class, |
|
| 262 | - 'element_require' => $args['element_require'], |
|
| 263 | - 'argument_id' => $args['id'] |
|
| 264 | - )); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - return $output; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Build the component. |
|
| 276 | - * |
|
| 277 | - * @param array $args |
|
| 278 | - * |
|
| 279 | - * @return string The rendered component. |
|
| 280 | - */ |
|
| 281 | - public static function textarea($args = array()){ |
|
| 282 | - $defaults = array( |
|
| 283 | - 'name' => '', |
|
| 284 | - 'class' => '', |
|
| 285 | - 'wrap_class' => '', |
|
| 286 | - 'id' => '', |
|
| 287 | - 'placeholder'=> '', |
|
| 288 | - 'title' => '', |
|
| 289 | - 'value' => '', |
|
| 290 | - 'required' => false, |
|
| 291 | - 'label' => '', |
|
| 292 | - 'label_after'=> false, |
|
| 293 | - 'label_class' => '', |
|
| 294 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 295 | - 'help_text' => '', |
|
| 296 | - 'validation_text' => '', |
|
| 297 | - 'validation_pattern' => '', |
|
| 298 | - 'no_wrap' => false, |
|
| 299 | - 'rows' => '', |
|
| 300 | - 'wysiwyg' => false, |
|
| 301 | - 'allow_tags' => false, // Allow HTML tags |
|
| 302 | - 'element_require' => '', // [%element_id%] == "1" |
|
| 303 | - 'extra_attributes' => array(), // an array of extra attributes |
|
| 304 | - ); |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 308 | - */ |
|
| 309 | - $args = wp_parse_args( $args, $defaults ); |
|
| 310 | - $output = ''; |
|
| 311 | - |
|
| 312 | - // hidden label option needs to be empty |
|
| 313 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 314 | - |
|
| 315 | - // floating labels don't work with wysiwyg so set it as top |
|
| 316 | - if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
| 317 | - $args['label_type'] = 'top'; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - $label_after = $args['label_after']; |
|
| 321 | - |
|
| 322 | - // floating labels need label after |
|
| 323 | - if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
| 324 | - $label_after = true; |
|
| 325 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // label |
|
| 329 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
| 330 | - }elseif(!empty($args['label']) && !$label_after){ |
|
| 331 | - $label_args = array( |
|
| 332 | - 'title'=> $args['label'], |
|
| 333 | - 'for'=> $args['id'], |
|
| 334 | - 'class' => $args['label_class']." ", |
|
| 335 | - 'label_type' => $args['label_type'] |
|
| 336 | - ); |
|
| 337 | - $output .= self::label( $label_args ); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - // maybe horizontal label |
|
| 341 | - if($args['label_type']=='horizontal'){ |
|
| 342 | - $output .= '<div class="col-sm-10">'; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if(!empty($args['wysiwyg'])){ |
|
| 346 | - ob_start(); |
|
| 347 | - $content = $args['value']; |
|
| 348 | - $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
| 349 | - $settings = array( |
|
| 350 | - 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
| 351 | - 'quicktags' => false, |
|
| 352 | - 'media_buttons' => false, |
|
| 353 | - 'editor_class' => 'form-control', |
|
| 354 | - 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
| 355 | - 'teeny' => true, |
|
| 356 | - ); |
|
| 357 | - |
|
| 358 | - // maybe set settings if array |
|
| 359 | - if(is_array($args['wysiwyg'])){ |
|
| 360 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - wp_editor( $content, $editor_id, $settings ); |
|
| 364 | - $output .= ob_get_clean(); |
|
| 365 | - }else{ |
|
| 366 | - |
|
| 367 | - // open |
|
| 368 | - $output .= '<textarea '; |
|
| 369 | - |
|
| 370 | - // name |
|
| 371 | - if(!empty($args['name'])){ |
|
| 372 | - $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // id |
|
| 376 | - if(!empty($args['id'])){ |
|
| 377 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - // placeholder |
|
| 381 | - if(isset($args['placeholder']) && '' != $args['placeholder']){ |
|
| 382 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - // title |
|
| 386 | - if(!empty($args['title'])){ |
|
| 387 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - // validation text |
|
| 391 | - if(!empty($args['validation_text'])){ |
|
| 392 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
| 393 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - // validation_pattern |
|
| 397 | - if(!empty($args['validation_pattern'])){ |
|
| 398 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // required |
|
| 402 | - if(!empty($args['required'])){ |
|
| 403 | - $output .= ' required '; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // rows |
|
| 407 | - if(!empty($args['rows'])){ |
|
| 408 | - $output .= ' rows="'.absint($args['rows']).'" '; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - // class |
|
| 413 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
| 414 | - $output .= ' class="form-control '.$class.'" '; |
|
| 415 | - |
|
| 416 | - // extra attributes |
|
| 417 | - if(!empty($args['extra_attributes'])){ |
|
| 418 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - // close tag |
|
| 422 | - $output .= ' >'; |
|
| 423 | - |
|
| 424 | - // value |
|
| 425 | - if ( ! empty( $args['value'] ) ) { |
|
| 426 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
| 427 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 428 | - } else { |
|
| 429 | - $output .= sanitize_textarea_field( $args['value'] ); |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // closing tag |
|
| 434 | - $output .= '</textarea>'; |
|
| 435 | - |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - if(!empty($args['label']) && $label_after){ |
|
| 439 | - $label_args = array( |
|
| 440 | - 'title'=> $args['label'], |
|
| 441 | - 'for'=> $args['id'], |
|
| 442 | - 'class' => $args['label_class']." ", |
|
| 443 | - 'label_type' => $args['label_type'] |
|
| 444 | - ); |
|
| 445 | - $output .= self::label( $label_args ); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - // help text |
|
| 449 | - if(!empty($args['help_text'])){ |
|
| 450 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // maybe horizontal label |
|
| 454 | - if($args['label_type']=='horizontal'){ |
|
| 455 | - $output .= '</div>'; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - // wrap |
|
| 460 | - if(!$args['no_wrap']){ |
|
| 461 | - $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
| 462 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 463 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 464 | - $output = self::wrap(array( |
|
| 465 | - 'content' => $output, |
|
| 466 | - 'class' => $wrap_class, |
|
| 467 | - 'element_require' => $args['element_require'], |
|
| 468 | - 'argument_id' => $args['id'] |
|
| 469 | - )); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - return $output; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - public static function label($args = array(), $type = ''){ |
|
| 477 | - //<label for="exampleInputEmail1">Email address</label> |
|
| 478 | - $defaults = array( |
|
| 479 | - 'title' => 'div', |
|
| 480 | - 'for' => '', |
|
| 481 | - 'class' => '', |
|
| 482 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
| 483 | - ); |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 487 | - */ |
|
| 488 | - $args = wp_parse_args( $args, $defaults ); |
|
| 489 | - $output = ''; |
|
| 490 | - |
|
| 491 | - if($args['title']){ |
|
| 492 | - |
|
| 493 | - // maybe hide labels //@todo set a global option for visibility class |
|
| 494 | - if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
| 495 | - $class = $args['class']; |
|
| 496 | - }else{ |
|
| 497 | - $class = 'sr-only '.$args['class']; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - // maybe horizontal |
|
| 501 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
| 502 | - $class .= ' col-sm-2 col-form-label'; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - // open |
|
| 506 | - $output .= '<label '; |
|
| 507 | - |
|
| 508 | - // for |
|
| 509 | - if(!empty($args['for'])){ |
|
| 510 | - $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - // class |
|
| 514 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 515 | - $output .= ' class="'.$class.'" '; |
|
| 516 | - |
|
| 517 | - // close |
|
| 518 | - $output .= '>'; |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - // title, don't escape fully as can contain html |
|
| 522 | - if(!empty($args['title'])){ |
|
| 523 | - $output .= wp_kses_post($args['title']); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - // close wrap |
|
| 527 | - $output .= '</label>'; |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - return $output; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Wrap some content in a HTML wrapper. |
|
| 538 | - * |
|
| 539 | - * @param array $args |
|
| 540 | - * |
|
| 541 | - * @return string |
|
| 542 | - */ |
|
| 543 | - public static function wrap($args = array()){ |
|
| 544 | - $defaults = array( |
|
| 545 | - 'type' => 'div', |
|
| 546 | - 'class' => 'form-group', |
|
| 547 | - 'content' => '', |
|
| 548 | - 'input_group_left' => '', |
|
| 549 | - 'input_group_right' => '', |
|
| 550 | - 'input_group_left_inside' => false, |
|
| 551 | - 'input_group_right_inside' => false, |
|
| 552 | - 'element_require' => '', |
|
| 553 | - 'argument_id' => '', |
|
| 554 | - ); |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 558 | - */ |
|
| 559 | - $args = wp_parse_args( $args, $defaults ); |
|
| 560 | - $output = ''; |
|
| 561 | - if($args['type']){ |
|
| 562 | - |
|
| 563 | - // open |
|
| 564 | - $output .= '<'.sanitize_html_class($args['type']); |
|
| 565 | - |
|
| 566 | - // element require |
|
| 567 | - if(!empty($args['element_require'])){ |
|
| 568 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
| 569 | - $args['class'] .= " aui-conditional-field"; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // argument_id |
|
| 573 | - if( !empty($args['argument_id']) ){ |
|
| 574 | - $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - // class |
|
| 578 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 579 | - $output .= ' class="'.$class.'" '; |
|
| 580 | - |
|
| 581 | - // close wrap |
|
| 582 | - $output .= ' >'; |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - // Input group left |
|
| 586 | - if(!empty($args['input_group_left'])){ |
|
| 587 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
| 588 | - $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
| 589 | - $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - // content |
|
| 593 | - $output .= $args['content']; |
|
| 594 | - |
|
| 595 | - // Input group right |
|
| 596 | - if(!empty($args['input_group_right'])){ |
|
| 597 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
| 598 | - $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
| 599 | - $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - // close wrap |
|
| 604 | - $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - }else{ |
|
| 608 | - $output = $args['content']; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - return $output; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Build the component. |
|
| 616 | - * |
|
| 617 | - * @param array $args |
|
| 618 | - * |
|
| 619 | - * @return string The rendered component. |
|
| 620 | - */ |
|
| 621 | - public static function select($args = array()){ |
|
| 622 | - $defaults = array( |
|
| 623 | - 'class' => '', |
|
| 624 | - 'wrap_class' => '', |
|
| 625 | - 'id' => '', |
|
| 626 | - 'title' => '', |
|
| 627 | - 'value' => '', // can be an array or a string |
|
| 628 | - 'required' => false, |
|
| 629 | - 'label' => '', |
|
| 630 | - 'label_after'=> false, |
|
| 631 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 632 | - 'label_class' => '', |
|
| 633 | - 'help_text' => '', |
|
| 634 | - 'placeholder'=> '', |
|
| 635 | - 'options' => array(), // array or string |
|
| 636 | - 'icon' => '', |
|
| 637 | - 'multiple' => false, |
|
| 638 | - 'select2' => false, |
|
| 639 | - 'no_wrap' => false, |
|
| 640 | - 'element_require' => '', // [%element_id%] == "1" |
|
| 641 | - 'extra_attributes' => array(), // an array of extra attributes |
|
| 642 | - ); |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 646 | - */ |
|
| 647 | - $args = wp_parse_args( $args, $defaults ); |
|
| 648 | - $output = ''; |
|
| 649 | - |
|
| 650 | - // for now lets hide floating labels |
|
| 651 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
| 652 | - |
|
| 653 | - // hidden label option needs to be empty |
|
| 654 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - $label_after = $args['label_after']; |
|
| 658 | - |
|
| 659 | - // floating labels need label after |
|
| 660 | - if( $args['label_type'] == 'floating' ){ |
|
| 661 | - $label_after = true; |
|
| 662 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - // Maybe setup select2 |
|
| 666 | - $is_select2 = false; |
|
| 667 | - if(!empty($args['select2'])){ |
|
| 668 | - $args['class'] .= ' aui-select2'; |
|
| 669 | - $is_select2 = true; |
|
| 670 | - }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
| 671 | - $is_select2 = true; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - // select2 tags |
|
| 675 | - if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
| 676 | - $args['data-tags'] = 'true'; |
|
| 677 | - $args['data-token-separators'] = "[',']"; |
|
| 678 | - $args['multiple'] = true; |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - // select2 placeholder |
|
| 682 | - if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){ |
|
| 683 | - $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
| 684 | - $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - // label |
|
| 688 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
| 689 | - }elseif(!empty($args['label']) && !$label_after){ |
|
| 690 | - $label_args = array( |
|
| 691 | - 'title'=> $args['label'], |
|
| 692 | - 'for'=> $args['id'], |
|
| 693 | - 'class' => $args['label_class']." ", |
|
| 694 | - 'label_type' => $args['label_type'] |
|
| 695 | - ); |
|
| 696 | - $output .= self::label($label_args); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - // maybe horizontal label |
|
| 700 | - if($args['label_type']=='horizontal'){ |
|
| 701 | - $output .= '<div class="col-sm-10">'; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - // open/type |
|
| 705 | - $output .= '<select '; |
|
| 706 | - |
|
| 707 | - // style |
|
| 708 | - if($is_select2){ |
|
| 709 | - $output .= " style='width:100%;' "; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - // element require |
|
| 713 | - if(!empty($args['element_require'])){ |
|
| 714 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
| 715 | - $args['class'] .= " aui-conditional-field"; |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - // class |
|
| 719 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
| 720 | - $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
| 721 | - |
|
| 722 | - // name |
|
| 723 | - if(!empty($args['name'])){ |
|
| 724 | - $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - // id |
|
| 728 | - if(!empty($args['id'])){ |
|
| 729 | - $output .= AUI_Component_Helper::id($args['id']); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - // title |
|
| 733 | - if(!empty($args['title'])){ |
|
| 734 | - $output .= AUI_Component_Helper::title($args['title']); |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - // data-attributes |
|
| 738 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
| 739 | - |
|
| 740 | - // aria-attributes |
|
| 741 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
| 742 | - |
|
| 743 | - // extra attributes |
|
| 744 | - if(!empty($args['extra_attributes'])){ |
|
| 745 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - // required |
|
| 749 | - if(!empty($args['required'])){ |
|
| 750 | - $output .= ' required '; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - // multiple |
|
| 754 | - if(!empty($args['multiple'])){ |
|
| 755 | - $output .= ' multiple '; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - // close opening tag |
|
| 759 | - $output .= ' >'; |
|
| 760 | - |
|
| 761 | - // placeholder |
|
| 762 | - if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){ |
|
| 763 | - $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
| 764 | - }elseif($is_select2 && !empty($args['placeholder'])){ |
|
| 765 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - // Options |
|
| 769 | - if(!empty($args['options'])){ |
|
| 770 | - |
|
| 771 | - if(!is_array($args['options'])){ |
|
| 772 | - $output .= $args['options']; // not the preferred way but an option |
|
| 773 | - }else{ |
|
| 774 | - foreach($args['options'] as $val => $name){ |
|
| 775 | - $selected = ''; |
|
| 776 | - if(is_array($name)){ |
|
| 777 | - if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
| 778 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
| 779 | - |
|
| 780 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
| 781 | - } else { |
|
| 782 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
| 783 | - $option_value = isset($name['value']) ? $name['value'] : ''; |
|
| 784 | - if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
| 785 | - $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
| 786 | - } elseif(!empty($args['value'])) { |
|
| 787 | - $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
| 791 | - } |
|
| 792 | - }else{ |
|
| 793 | - if(!empty($args['value'])){ |
|
| 794 | - if(is_array($args['value'])){ |
|
| 795 | - $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
| 796 | - } elseif(!empty($args['value'])) { |
|
| 797 | - $selected = selected( $args['value'], $val, false); |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - // closing tag |
|
| 808 | - $output .= '</select>'; |
|
| 809 | - |
|
| 810 | - if(!empty($args['label']) && $label_after){ |
|
| 811 | - $label_args = array( |
|
| 812 | - 'title'=> $args['label'], |
|
| 813 | - 'for'=> $args['id'], |
|
| 814 | - 'class' => $args['label_class']." ", |
|
| 815 | - 'label_type' => $args['label_type'] |
|
| 816 | - ); |
|
| 817 | - $output .= self::label($label_args); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - // help text |
|
| 821 | - if(!empty($args['help_text'])){ |
|
| 822 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - // maybe horizontal label |
|
| 826 | - if($args['label_type']=='horizontal'){ |
|
| 827 | - $output .= '</div>'; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - // wrap |
|
| 832 | - if(!$args['no_wrap']){ |
|
| 833 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
| 834 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 835 | - $output = self::wrap(array( |
|
| 836 | - 'content' => $output, |
|
| 837 | - 'class' => $wrap_class, |
|
| 838 | - 'element_require' => $args['element_require'], |
|
| 839 | - 'argument_id' => $args['id'] |
|
| 840 | - )); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - return $output; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * Build the component. |
|
| 849 | - * |
|
| 850 | - * @param array $args |
|
| 851 | - * |
|
| 852 | - * @return string The rendered component. |
|
| 853 | - */ |
|
| 854 | - public static function radio($args = array()){ |
|
| 855 | - $defaults = array( |
|
| 856 | - 'class' => '', |
|
| 857 | - 'wrap_class' => '', |
|
| 858 | - 'id' => '', |
|
| 859 | - 'title' => '', |
|
| 860 | - 'horizontal' => false, // sets the lable horizontal |
|
| 861 | - 'value' => '', |
|
| 862 | - 'label' => '', |
|
| 863 | - 'label_class'=> '', |
|
| 864 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 865 | - 'inline' => true, |
|
| 866 | - 'required' => false, |
|
| 867 | - 'options' => array(), |
|
| 868 | - 'icon' => '', |
|
| 869 | - 'no_wrap' => false, |
|
| 870 | - 'element_require' => '', // [%element_id%] == "1" |
|
| 871 | - 'extra_attributes' => array() // an array of extra attributes |
|
| 872 | - ); |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 876 | - */ |
|
| 877 | - $args = wp_parse_args( $args, $defaults ); |
|
| 878 | - |
|
| 879 | - // for now lets use horizontal for floating |
|
| 880 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
| 881 | - |
|
| 882 | - $label_args = array( |
|
| 883 | - 'title'=> $args['label'], |
|
| 884 | - 'class' => $args['label_class']." pt-0 ", |
|
| 885 | - 'label_type' => $args['label_type'] |
|
| 886 | - ); |
|
| 887 | - |
|
| 888 | - $output = ''; |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - // label before |
|
| 893 | - if(!empty($args['label'])){ |
|
| 894 | - $output .= self::label( $label_args, 'radio' ); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - // maybe horizontal label |
|
| 898 | - if($args['label_type']=='horizontal'){ |
|
| 899 | - $output .= '<div class="col-sm-10">'; |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - if(!empty($args['options'])){ |
|
| 903 | - $count = 0; |
|
| 904 | - foreach($args['options'] as $value => $label){ |
|
| 905 | - $option_args = $args; |
|
| 906 | - $option_args['value'] = $value; |
|
| 907 | - $option_args['label'] = $label; |
|
| 908 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
| 909 | - $output .= self::radio_option($option_args,$count); |
|
| 910 | - $count++; |
|
| 911 | - } |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - // maybe horizontal label |
|
| 915 | - if($args['label_type']=='horizontal'){ |
|
| 916 | - $output .= '</div>'; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - // wrap |
|
| 921 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
| 922 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 923 | - $output = self::wrap(array( |
|
| 924 | - 'content' => $output, |
|
| 925 | - 'class' => $wrap_class, |
|
| 926 | - 'element_require' => $args['element_require'], |
|
| 927 | - 'argument_id' => $args['id'] |
|
| 928 | - )); |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - return $output; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * Build the component. |
|
| 936 | - * |
|
| 937 | - * @param array $args |
|
| 938 | - * |
|
| 939 | - * @return string The rendered component. |
|
| 940 | - */ |
|
| 941 | - public static function radio_option($args = array(),$count = ''){ |
|
| 942 | - $defaults = array( |
|
| 943 | - 'class' => '', |
|
| 944 | - 'id' => '', |
|
| 945 | - 'title' => '', |
|
| 946 | - 'value' => '', |
|
| 947 | - 'required' => false, |
|
| 948 | - 'inline' => true, |
|
| 949 | - 'label' => '', |
|
| 950 | - 'options' => array(), |
|
| 951 | - 'icon' => '', |
|
| 952 | - 'no_wrap' => false, |
|
| 953 | - 'extra_attributes' => array() // an array of extra attributes |
|
| 954 | - ); |
|
| 955 | - |
|
| 956 | - /** |
|
| 957 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 958 | - */ |
|
| 959 | - $args = wp_parse_args( $args, $defaults ); |
|
| 960 | - |
|
| 961 | - $output = ''; |
|
| 962 | - |
|
| 963 | - // open/type |
|
| 964 | - $output .= '<input type="radio"'; |
|
| 965 | - |
|
| 966 | - // class |
|
| 967 | - $output .= ' class="form-check-input" '; |
|
| 968 | - |
|
| 969 | - // name |
|
| 970 | - if(!empty($args['name'])){ |
|
| 971 | - $output .= AUI_Component_Helper::name($args['name']); |
|
| 972 | - } |
|
| 973 | - |
|
| 974 | - // id |
|
| 975 | - if(!empty($args['id'])){ |
|
| 976 | - $output .= AUI_Component_Helper::id($args['id'].$count); |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - // title |
|
| 980 | - if(!empty($args['title'])){ |
|
| 981 | - $output .= AUI_Component_Helper::title($args['title']); |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - // value |
|
| 985 | - if(isset($args['value'])){ |
|
| 986 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - // checked, for radio and checkboxes |
|
| 990 | - if( $args['checked'] ){ |
|
| 991 | - $output .= ' checked '; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - // data-attributes |
|
| 995 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
| 996 | - |
|
| 997 | - // aria-attributes |
|
| 998 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
| 999 | - |
|
| 1000 | - // extra attributes |
|
| 1001 | - if(!empty($args['extra_attributes'])){ |
|
| 1002 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - // required |
|
| 1006 | - if(!empty($args['required'])){ |
|
| 1007 | - $output .= ' required '; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - // close opening tag |
|
| 1011 | - $output .= ' >'; |
|
| 1012 | - |
|
| 1013 | - // label |
|
| 1014 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
| 1015 | - }elseif(!empty($args['label'])){ |
|
| 1016 | - $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - // wrap |
|
| 1020 | - if(!$args['no_wrap']){ |
|
| 1021 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
| 1022 | - $output = self::wrap(array( |
|
| 1023 | - 'content' => $output, |
|
| 1024 | - 'class' => $wrap_class |
|
| 1025 | - )); |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - |
|
| 1029 | - return $output; |
|
| 1030 | - } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // input group wraps |
|
| 216 | + if($args['input_group_left'] || $args['input_group_right']){ |
|
| 217 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
| 218 | + if($args['input_group_left']){ |
|
| 219 | + $output = self::wrap( array( |
|
| 220 | + 'content' => $output, |
|
| 221 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
| 222 | + 'input_group_left' => $args['input_group_left'], |
|
| 223 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 224 | + ) ); |
|
| 225 | + } |
|
| 226 | + if($args['input_group_right']){ |
|
| 227 | + $output = self::wrap( array( |
|
| 228 | + 'content' => $output, |
|
| 229 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
| 230 | + 'input_group_right' => $args['input_group_right'], |
|
| 231 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 232 | + ) ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + if(!$label_after){ |
|
| 238 | + $output .= $help_text; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
| 243 | + $output = self::wrap( array( |
|
| 244 | + 'content' => $output, |
|
| 245 | + 'class' => 'col-sm-10', |
|
| 246 | + ) ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + if(!$label_after){ |
|
| 250 | + $output = $label . $output; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + // wrap |
|
| 254 | + if(!$args['no_wrap']){ |
|
| 255 | + |
|
| 256 | + $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
| 257 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 258 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 259 | + $output = self::wrap(array( |
|
| 260 | + 'content' => $output, |
|
| 261 | + 'class' => $wrap_class, |
|
| 262 | + 'element_require' => $args['element_require'], |
|
| 263 | + 'argument_id' => $args['id'] |
|
| 264 | + )); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + return $output; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Build the component. |
|
| 276 | + * |
|
| 277 | + * @param array $args |
|
| 278 | + * |
|
| 279 | + * @return string The rendered component. |
|
| 280 | + */ |
|
| 281 | + public static function textarea($args = array()){ |
|
| 282 | + $defaults = array( |
|
| 283 | + 'name' => '', |
|
| 284 | + 'class' => '', |
|
| 285 | + 'wrap_class' => '', |
|
| 286 | + 'id' => '', |
|
| 287 | + 'placeholder'=> '', |
|
| 288 | + 'title' => '', |
|
| 289 | + 'value' => '', |
|
| 290 | + 'required' => false, |
|
| 291 | + 'label' => '', |
|
| 292 | + 'label_after'=> false, |
|
| 293 | + 'label_class' => '', |
|
| 294 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 295 | + 'help_text' => '', |
|
| 296 | + 'validation_text' => '', |
|
| 297 | + 'validation_pattern' => '', |
|
| 298 | + 'no_wrap' => false, |
|
| 299 | + 'rows' => '', |
|
| 300 | + 'wysiwyg' => false, |
|
| 301 | + 'allow_tags' => false, // Allow HTML tags |
|
| 302 | + 'element_require' => '', // [%element_id%] == "1" |
|
| 303 | + 'extra_attributes' => array(), // an array of extra attributes |
|
| 304 | + ); |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 308 | + */ |
|
| 309 | + $args = wp_parse_args( $args, $defaults ); |
|
| 310 | + $output = ''; |
|
| 311 | + |
|
| 312 | + // hidden label option needs to be empty |
|
| 313 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 314 | + |
|
| 315 | + // floating labels don't work with wysiwyg so set it as top |
|
| 316 | + if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
| 317 | + $args['label_type'] = 'top'; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + $label_after = $args['label_after']; |
|
| 321 | + |
|
| 322 | + // floating labels need label after |
|
| 323 | + if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
| 324 | + $label_after = true; |
|
| 325 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // label |
|
| 329 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
| 330 | + }elseif(!empty($args['label']) && !$label_after){ |
|
| 331 | + $label_args = array( |
|
| 332 | + 'title'=> $args['label'], |
|
| 333 | + 'for'=> $args['id'], |
|
| 334 | + 'class' => $args['label_class']." ", |
|
| 335 | + 'label_type' => $args['label_type'] |
|
| 336 | + ); |
|
| 337 | + $output .= self::label( $label_args ); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + // maybe horizontal label |
|
| 341 | + if($args['label_type']=='horizontal'){ |
|
| 342 | + $output .= '<div class="col-sm-10">'; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if(!empty($args['wysiwyg'])){ |
|
| 346 | + ob_start(); |
|
| 347 | + $content = $args['value']; |
|
| 348 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
| 349 | + $settings = array( |
|
| 350 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
| 351 | + 'quicktags' => false, |
|
| 352 | + 'media_buttons' => false, |
|
| 353 | + 'editor_class' => 'form-control', |
|
| 354 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
| 355 | + 'teeny' => true, |
|
| 356 | + ); |
|
| 357 | + |
|
| 358 | + // maybe set settings if array |
|
| 359 | + if(is_array($args['wysiwyg'])){ |
|
| 360 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + wp_editor( $content, $editor_id, $settings ); |
|
| 364 | + $output .= ob_get_clean(); |
|
| 365 | + }else{ |
|
| 366 | + |
|
| 367 | + // open |
|
| 368 | + $output .= '<textarea '; |
|
| 369 | + |
|
| 370 | + // name |
|
| 371 | + if(!empty($args['name'])){ |
|
| 372 | + $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // id |
|
| 376 | + if(!empty($args['id'])){ |
|
| 377 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + // placeholder |
|
| 381 | + if(isset($args['placeholder']) && '' != $args['placeholder']){ |
|
| 382 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + // title |
|
| 386 | + if(!empty($args['title'])){ |
|
| 387 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + // validation text |
|
| 391 | + if(!empty($args['validation_text'])){ |
|
| 392 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
| 393 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + // validation_pattern |
|
| 397 | + if(!empty($args['validation_pattern'])){ |
|
| 398 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // required |
|
| 402 | + if(!empty($args['required'])){ |
|
| 403 | + $output .= ' required '; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + // rows |
|
| 407 | + if(!empty($args['rows'])){ |
|
| 408 | + $output .= ' rows="'.absint($args['rows']).'" '; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + // class |
|
| 413 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
| 414 | + $output .= ' class="form-control '.$class.'" '; |
|
| 415 | + |
|
| 416 | + // extra attributes |
|
| 417 | + if(!empty($args['extra_attributes'])){ |
|
| 418 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + // close tag |
|
| 422 | + $output .= ' >'; |
|
| 423 | + |
|
| 424 | + // value |
|
| 425 | + if ( ! empty( $args['value'] ) ) { |
|
| 426 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
| 427 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 428 | + } else { |
|
| 429 | + $output .= sanitize_textarea_field( $args['value'] ); |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // closing tag |
|
| 434 | + $output .= '</textarea>'; |
|
| 435 | + |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + if(!empty($args['label']) && $label_after){ |
|
| 439 | + $label_args = array( |
|
| 440 | + 'title'=> $args['label'], |
|
| 441 | + 'for'=> $args['id'], |
|
| 442 | + 'class' => $args['label_class']." ", |
|
| 443 | + 'label_type' => $args['label_type'] |
|
| 444 | + ); |
|
| 445 | + $output .= self::label( $label_args ); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + // help text |
|
| 449 | + if(!empty($args['help_text'])){ |
|
| 450 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // maybe horizontal label |
|
| 454 | + if($args['label_type']=='horizontal'){ |
|
| 455 | + $output .= '</div>'; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + // wrap |
|
| 460 | + if(!$args['no_wrap']){ |
|
| 461 | + $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
| 462 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 463 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 464 | + $output = self::wrap(array( |
|
| 465 | + 'content' => $output, |
|
| 466 | + 'class' => $wrap_class, |
|
| 467 | + 'element_require' => $args['element_require'], |
|
| 468 | + 'argument_id' => $args['id'] |
|
| 469 | + )); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + return $output; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + public static function label($args = array(), $type = ''){ |
|
| 477 | + //<label for="exampleInputEmail1">Email address</label> |
|
| 478 | + $defaults = array( |
|
| 479 | + 'title' => 'div', |
|
| 480 | + 'for' => '', |
|
| 481 | + 'class' => '', |
|
| 482 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
| 483 | + ); |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 487 | + */ |
|
| 488 | + $args = wp_parse_args( $args, $defaults ); |
|
| 489 | + $output = ''; |
|
| 490 | + |
|
| 491 | + if($args['title']){ |
|
| 492 | + |
|
| 493 | + // maybe hide labels //@todo set a global option for visibility class |
|
| 494 | + if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
| 495 | + $class = $args['class']; |
|
| 496 | + }else{ |
|
| 497 | + $class = 'sr-only '.$args['class']; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + // maybe horizontal |
|
| 501 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
| 502 | + $class .= ' col-sm-2 col-form-label'; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // open |
|
| 506 | + $output .= '<label '; |
|
| 507 | + |
|
| 508 | + // for |
|
| 509 | + if(!empty($args['for'])){ |
|
| 510 | + $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + // class |
|
| 514 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 515 | + $output .= ' class="'.$class.'" '; |
|
| 516 | + |
|
| 517 | + // close |
|
| 518 | + $output .= '>'; |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + // title, don't escape fully as can contain html |
|
| 522 | + if(!empty($args['title'])){ |
|
| 523 | + $output .= wp_kses_post($args['title']); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + // close wrap |
|
| 527 | + $output .= '</label>'; |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + return $output; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Wrap some content in a HTML wrapper. |
|
| 538 | + * |
|
| 539 | + * @param array $args |
|
| 540 | + * |
|
| 541 | + * @return string |
|
| 542 | + */ |
|
| 543 | + public static function wrap($args = array()){ |
|
| 544 | + $defaults = array( |
|
| 545 | + 'type' => 'div', |
|
| 546 | + 'class' => 'form-group', |
|
| 547 | + 'content' => '', |
|
| 548 | + 'input_group_left' => '', |
|
| 549 | + 'input_group_right' => '', |
|
| 550 | + 'input_group_left_inside' => false, |
|
| 551 | + 'input_group_right_inside' => false, |
|
| 552 | + 'element_require' => '', |
|
| 553 | + 'argument_id' => '', |
|
| 554 | + ); |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 558 | + */ |
|
| 559 | + $args = wp_parse_args( $args, $defaults ); |
|
| 560 | + $output = ''; |
|
| 561 | + if($args['type']){ |
|
| 562 | + |
|
| 563 | + // open |
|
| 564 | + $output .= '<'.sanitize_html_class($args['type']); |
|
| 565 | + |
|
| 566 | + // element require |
|
| 567 | + if(!empty($args['element_require'])){ |
|
| 568 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
| 569 | + $args['class'] .= " aui-conditional-field"; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // argument_id |
|
| 573 | + if( !empty($args['argument_id']) ){ |
|
| 574 | + $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + // class |
|
| 578 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 579 | + $output .= ' class="'.$class.'" '; |
|
| 580 | + |
|
| 581 | + // close wrap |
|
| 582 | + $output .= ' >'; |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + // Input group left |
|
| 586 | + if(!empty($args['input_group_left'])){ |
|
| 587 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
| 588 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
| 589 | + $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + // content |
|
| 593 | + $output .= $args['content']; |
|
| 594 | + |
|
| 595 | + // Input group right |
|
| 596 | + if(!empty($args['input_group_right'])){ |
|
| 597 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
| 598 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
| 599 | + $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + // close wrap |
|
| 604 | + $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + }else{ |
|
| 608 | + $output = $args['content']; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + return $output; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Build the component. |
|
| 616 | + * |
|
| 617 | + * @param array $args |
|
| 618 | + * |
|
| 619 | + * @return string The rendered component. |
|
| 620 | + */ |
|
| 621 | + public static function select($args = array()){ |
|
| 622 | + $defaults = array( |
|
| 623 | + 'class' => '', |
|
| 624 | + 'wrap_class' => '', |
|
| 625 | + 'id' => '', |
|
| 626 | + 'title' => '', |
|
| 627 | + 'value' => '', // can be an array or a string |
|
| 628 | + 'required' => false, |
|
| 629 | + 'label' => '', |
|
| 630 | + 'label_after'=> false, |
|
| 631 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 632 | + 'label_class' => '', |
|
| 633 | + 'help_text' => '', |
|
| 634 | + 'placeholder'=> '', |
|
| 635 | + 'options' => array(), // array or string |
|
| 636 | + 'icon' => '', |
|
| 637 | + 'multiple' => false, |
|
| 638 | + 'select2' => false, |
|
| 639 | + 'no_wrap' => false, |
|
| 640 | + 'element_require' => '', // [%element_id%] == "1" |
|
| 641 | + 'extra_attributes' => array(), // an array of extra attributes |
|
| 642 | + ); |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 646 | + */ |
|
| 647 | + $args = wp_parse_args( $args, $defaults ); |
|
| 648 | + $output = ''; |
|
| 649 | + |
|
| 650 | + // for now lets hide floating labels |
|
| 651 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
| 652 | + |
|
| 653 | + // hidden label option needs to be empty |
|
| 654 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + $label_after = $args['label_after']; |
|
| 658 | + |
|
| 659 | + // floating labels need label after |
|
| 660 | + if( $args['label_type'] == 'floating' ){ |
|
| 661 | + $label_after = true; |
|
| 662 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + // Maybe setup select2 |
|
| 666 | + $is_select2 = false; |
|
| 667 | + if(!empty($args['select2'])){ |
|
| 668 | + $args['class'] .= ' aui-select2'; |
|
| 669 | + $is_select2 = true; |
|
| 670 | + }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
| 671 | + $is_select2 = true; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + // select2 tags |
|
| 675 | + if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
| 676 | + $args['data-tags'] = 'true'; |
|
| 677 | + $args['data-token-separators'] = "[',']"; |
|
| 678 | + $args['multiple'] = true; |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + // select2 placeholder |
|
| 682 | + if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){ |
|
| 683 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
| 684 | + $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + // label |
|
| 688 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
| 689 | + }elseif(!empty($args['label']) && !$label_after){ |
|
| 690 | + $label_args = array( |
|
| 691 | + 'title'=> $args['label'], |
|
| 692 | + 'for'=> $args['id'], |
|
| 693 | + 'class' => $args['label_class']." ", |
|
| 694 | + 'label_type' => $args['label_type'] |
|
| 695 | + ); |
|
| 696 | + $output .= self::label($label_args); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + // maybe horizontal label |
|
| 700 | + if($args['label_type']=='horizontal'){ |
|
| 701 | + $output .= '<div class="col-sm-10">'; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + // open/type |
|
| 705 | + $output .= '<select '; |
|
| 706 | + |
|
| 707 | + // style |
|
| 708 | + if($is_select2){ |
|
| 709 | + $output .= " style='width:100%;' "; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + // element require |
|
| 713 | + if(!empty($args['element_require'])){ |
|
| 714 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
| 715 | + $args['class'] .= " aui-conditional-field"; |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + // class |
|
| 719 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
| 720 | + $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
| 721 | + |
|
| 722 | + // name |
|
| 723 | + if(!empty($args['name'])){ |
|
| 724 | + $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + // id |
|
| 728 | + if(!empty($args['id'])){ |
|
| 729 | + $output .= AUI_Component_Helper::id($args['id']); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + // title |
|
| 733 | + if(!empty($args['title'])){ |
|
| 734 | + $output .= AUI_Component_Helper::title($args['title']); |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + // data-attributes |
|
| 738 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
| 739 | + |
|
| 740 | + // aria-attributes |
|
| 741 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
| 742 | + |
|
| 743 | + // extra attributes |
|
| 744 | + if(!empty($args['extra_attributes'])){ |
|
| 745 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + // required |
|
| 749 | + if(!empty($args['required'])){ |
|
| 750 | + $output .= ' required '; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + // multiple |
|
| 754 | + if(!empty($args['multiple'])){ |
|
| 755 | + $output .= ' multiple '; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + // close opening tag |
|
| 759 | + $output .= ' >'; |
|
| 760 | + |
|
| 761 | + // placeholder |
|
| 762 | + if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){ |
|
| 763 | + $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
| 764 | + }elseif($is_select2 && !empty($args['placeholder'])){ |
|
| 765 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + // Options |
|
| 769 | + if(!empty($args['options'])){ |
|
| 770 | + |
|
| 771 | + if(!is_array($args['options'])){ |
|
| 772 | + $output .= $args['options']; // not the preferred way but an option |
|
| 773 | + }else{ |
|
| 774 | + foreach($args['options'] as $val => $name){ |
|
| 775 | + $selected = ''; |
|
| 776 | + if(is_array($name)){ |
|
| 777 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
| 778 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
| 779 | + |
|
| 780 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
| 781 | + } else { |
|
| 782 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
| 783 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
| 784 | + if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
| 785 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
| 786 | + } elseif(!empty($args['value'])) { |
|
| 787 | + $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
| 791 | + } |
|
| 792 | + }else{ |
|
| 793 | + if(!empty($args['value'])){ |
|
| 794 | + if(is_array($args['value'])){ |
|
| 795 | + $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
| 796 | + } elseif(!empty($args['value'])) { |
|
| 797 | + $selected = selected( $args['value'], $val, false); |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + // closing tag |
|
| 808 | + $output .= '</select>'; |
|
| 809 | + |
|
| 810 | + if(!empty($args['label']) && $label_after){ |
|
| 811 | + $label_args = array( |
|
| 812 | + 'title'=> $args['label'], |
|
| 813 | + 'for'=> $args['id'], |
|
| 814 | + 'class' => $args['label_class']." ", |
|
| 815 | + 'label_type' => $args['label_type'] |
|
| 816 | + ); |
|
| 817 | + $output .= self::label($label_args); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + // help text |
|
| 821 | + if(!empty($args['help_text'])){ |
|
| 822 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + // maybe horizontal label |
|
| 826 | + if($args['label_type']=='horizontal'){ |
|
| 827 | + $output .= '</div>'; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + // wrap |
|
| 832 | + if(!$args['no_wrap']){ |
|
| 833 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
| 834 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 835 | + $output = self::wrap(array( |
|
| 836 | + 'content' => $output, |
|
| 837 | + 'class' => $wrap_class, |
|
| 838 | + 'element_require' => $args['element_require'], |
|
| 839 | + 'argument_id' => $args['id'] |
|
| 840 | + )); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + return $output; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * Build the component. |
|
| 849 | + * |
|
| 850 | + * @param array $args |
|
| 851 | + * |
|
| 852 | + * @return string The rendered component. |
|
| 853 | + */ |
|
| 854 | + public static function radio($args = array()){ |
|
| 855 | + $defaults = array( |
|
| 856 | + 'class' => '', |
|
| 857 | + 'wrap_class' => '', |
|
| 858 | + 'id' => '', |
|
| 859 | + 'title' => '', |
|
| 860 | + 'horizontal' => false, // sets the lable horizontal |
|
| 861 | + 'value' => '', |
|
| 862 | + 'label' => '', |
|
| 863 | + 'label_class'=> '', |
|
| 864 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 865 | + 'inline' => true, |
|
| 866 | + 'required' => false, |
|
| 867 | + 'options' => array(), |
|
| 868 | + 'icon' => '', |
|
| 869 | + 'no_wrap' => false, |
|
| 870 | + 'element_require' => '', // [%element_id%] == "1" |
|
| 871 | + 'extra_attributes' => array() // an array of extra attributes |
|
| 872 | + ); |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 876 | + */ |
|
| 877 | + $args = wp_parse_args( $args, $defaults ); |
|
| 878 | + |
|
| 879 | + // for now lets use horizontal for floating |
|
| 880 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
| 881 | + |
|
| 882 | + $label_args = array( |
|
| 883 | + 'title'=> $args['label'], |
|
| 884 | + 'class' => $args['label_class']." pt-0 ", |
|
| 885 | + 'label_type' => $args['label_type'] |
|
| 886 | + ); |
|
| 887 | + |
|
| 888 | + $output = ''; |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + // label before |
|
| 893 | + if(!empty($args['label'])){ |
|
| 894 | + $output .= self::label( $label_args, 'radio' ); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + // maybe horizontal label |
|
| 898 | + if($args['label_type']=='horizontal'){ |
|
| 899 | + $output .= '<div class="col-sm-10">'; |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + if(!empty($args['options'])){ |
|
| 903 | + $count = 0; |
|
| 904 | + foreach($args['options'] as $value => $label){ |
|
| 905 | + $option_args = $args; |
|
| 906 | + $option_args['value'] = $value; |
|
| 907 | + $option_args['label'] = $label; |
|
| 908 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
| 909 | + $output .= self::radio_option($option_args,$count); |
|
| 910 | + $count++; |
|
| 911 | + } |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + // maybe horizontal label |
|
| 915 | + if($args['label_type']=='horizontal'){ |
|
| 916 | + $output .= '</div>'; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + // wrap |
|
| 921 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
| 922 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 923 | + $output = self::wrap(array( |
|
| 924 | + 'content' => $output, |
|
| 925 | + 'class' => $wrap_class, |
|
| 926 | + 'element_require' => $args['element_require'], |
|
| 927 | + 'argument_id' => $args['id'] |
|
| 928 | + )); |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + return $output; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * Build the component. |
|
| 936 | + * |
|
| 937 | + * @param array $args |
|
| 938 | + * |
|
| 939 | + * @return string The rendered component. |
|
| 940 | + */ |
|
| 941 | + public static function radio_option($args = array(),$count = ''){ |
|
| 942 | + $defaults = array( |
|
| 943 | + 'class' => '', |
|
| 944 | + 'id' => '', |
|
| 945 | + 'title' => '', |
|
| 946 | + 'value' => '', |
|
| 947 | + 'required' => false, |
|
| 948 | + 'inline' => true, |
|
| 949 | + 'label' => '', |
|
| 950 | + 'options' => array(), |
|
| 951 | + 'icon' => '', |
|
| 952 | + 'no_wrap' => false, |
|
| 953 | + 'extra_attributes' => array() // an array of extra attributes |
|
| 954 | + ); |
|
| 955 | + |
|
| 956 | + /** |
|
| 957 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 958 | + */ |
|
| 959 | + $args = wp_parse_args( $args, $defaults ); |
|
| 960 | + |
|
| 961 | + $output = ''; |
|
| 962 | + |
|
| 963 | + // open/type |
|
| 964 | + $output .= '<input type="radio"'; |
|
| 965 | + |
|
| 966 | + // class |
|
| 967 | + $output .= ' class="form-check-input" '; |
|
| 968 | + |
|
| 969 | + // name |
|
| 970 | + if(!empty($args['name'])){ |
|
| 971 | + $output .= AUI_Component_Helper::name($args['name']); |
|
| 972 | + } |
|
| 973 | + |
|
| 974 | + // id |
|
| 975 | + if(!empty($args['id'])){ |
|
| 976 | + $output .= AUI_Component_Helper::id($args['id'].$count); |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + // title |
|
| 980 | + if(!empty($args['title'])){ |
|
| 981 | + $output .= AUI_Component_Helper::title($args['title']); |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + // value |
|
| 985 | + if(isset($args['value'])){ |
|
| 986 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + // checked, for radio and checkboxes |
|
| 990 | + if( $args['checked'] ){ |
|
| 991 | + $output .= ' checked '; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + // data-attributes |
|
| 995 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
| 996 | + |
|
| 997 | + // aria-attributes |
|
| 998 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
| 999 | + |
|
| 1000 | + // extra attributes |
|
| 1001 | + if(!empty($args['extra_attributes'])){ |
|
| 1002 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + // required |
|
| 1006 | + if(!empty($args['required'])){ |
|
| 1007 | + $output .= ' required '; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + // close opening tag |
|
| 1011 | + $output .= ' >'; |
|
| 1012 | + |
|
| 1013 | + // label |
|
| 1014 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
| 1015 | + }elseif(!empty($args['label'])){ |
|
| 1016 | + $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + // wrap |
|
| 1020 | + if(!$args['no_wrap']){ |
|
| 1021 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
| 1022 | + $output = self::wrap(array( |
|
| 1023 | + 'content' => $output, |
|
| 1024 | + 'class' => $wrap_class |
|
| 1025 | + )); |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + |
|
| 1029 | + return $output; |
|
| 1030 | + } |
|
| 1031 | 1031 | |
| 1032 | 1032 | } |
| 1033 | 1033 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | +if (!defined('ABSPATH')) { |
|
| 4 | 4 | exit; // Exit if accessed directly |
| 5 | 5 | } |
| 6 | 6 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return string The rendered component. |
| 20 | 20 | */ |
| 21 | - public static function input($args = array()){ |
|
| 21 | + public static function input($args = array()) { |
|
| 22 | 22 | $defaults = array( |
| 23 | 23 | 'type' => 'text', |
| 24 | 24 | 'name' => '', |
@@ -52,13 +52,13 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * Parse incoming $args into an array and merge it with $defaults |
| 54 | 54 | */ |
| 55 | - $args = wp_parse_args( $args, $defaults ); |
|
| 55 | + $args = wp_parse_args($args, $defaults); |
|
| 56 | 56 | $output = ''; |
| 57 | - if ( ! empty( $args['type'] ) ) { |
|
| 57 | + if (!empty($args['type'])) { |
|
| 58 | 58 | // hidden label option needs to be empty |
| 59 | 59 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
| 60 | 60 | |
| 61 | - $type = sanitize_html_class( $args['type'] ); |
|
| 61 | + $type = sanitize_html_class($args['type']); |
|
| 62 | 62 | |
| 63 | 63 | $help_text = ''; |
| 64 | 64 | $label = ''; |
@@ -66,24 +66,24 @@ discard block |
||
| 66 | 66 | $label_args = array( |
| 67 | 67 | 'title'=> $args['label'], |
| 68 | 68 | 'for'=> $args['id'], |
| 69 | - 'class' => $args['label_class']." ", |
|
| 69 | + 'class' => $args['label_class'] . " ", |
|
| 70 | 70 | 'label_type' => $args['label_type'] |
| 71 | 71 | ); |
| 72 | 72 | |
| 73 | 73 | // floating labels need label after |
| 74 | - if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
| 74 | + if ($args['label_type'] == 'floating' && $type != 'checkbox') { |
|
| 75 | 75 | $label_after = true; |
| 76 | 76 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // Some special sauce for files |
| 80 | - if($type=='file' ){ |
|
| 80 | + if ($type == 'file') { |
|
| 81 | 81 | $label_after = true; // if type file we need the label after |
| 82 | 82 | $args['class'] .= ' custom-file-input '; |
| 83 | - }elseif($type=='checkbox'){ |
|
| 83 | + }elseif ($type == 'checkbox') { |
|
| 84 | 84 | $label_after = true; // if type file we need the label after |
| 85 | 85 | $args['class'] .= ' custom-control-input '; |
| 86 | - }elseif($type=='datepicker' || $type=='timepicker'){ |
|
| 86 | + }elseif ($type == 'datepicker' || $type == 'timepicker') { |
|
| 87 | 87 | $type = 'text'; |
| 88 | 88 | //$args['class'] .= ' aui-flatpickr bg-initial '; |
| 89 | 89 | $args['class'] .= ' bg-initial '; |
@@ -99,65 +99,65 @@ discard block |
||
| 99 | 99 | $output .= '<input type="' . $type . '" '; |
| 100 | 100 | |
| 101 | 101 | // name |
| 102 | - if(!empty($args['name'])){ |
|
| 103 | - $output .= ' name="'.esc_attr($args['name']).'" '; |
|
| 102 | + if (!empty($args['name'])) { |
|
| 103 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // id |
| 107 | - if(!empty($args['id'])){ |
|
| 108 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
| 107 | + if (!empty($args['id'])) { |
|
| 108 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // placeholder |
| 112 | - if(isset($args['placeholder']) && '' != $args['placeholder'] ){ |
|
| 113 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
| 112 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
| 113 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // title |
| 117 | - if(!empty($args['title'])){ |
|
| 118 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
| 117 | + if (!empty($args['title'])) { |
|
| 118 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // value |
| 122 | - if(!empty($args['value'])){ |
|
| 123 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
| 122 | + if (!empty($args['value'])) { |
|
| 123 | + $output .= ' value="' . sanitize_text_field($args['value']) . '" '; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // checked, for radio and checkboxes |
| 127 | - if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
| 127 | + if (($type == 'checkbox' || $type == 'radio') && $args['checked']) { |
|
| 128 | 128 | $output .= ' checked '; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // validation text |
| 132 | - if(!empty($args['validation_text'])){ |
|
| 133 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
| 132 | + if (!empty($args['validation_text'])) { |
|
| 133 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
| 134 | 134 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // validation_pattern |
| 138 | - if(!empty($args['validation_pattern'])){ |
|
| 139 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
| 138 | + if (!empty($args['validation_pattern'])) { |
|
| 139 | + $output .= ' pattern="' . $args['validation_pattern'] . '" '; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // step (for numbers) |
| 143 | - if(!empty($args['step'])){ |
|
| 144 | - $output .= ' step="'.$args['step'].'" '; |
|
| 143 | + if (!empty($args['step'])) { |
|
| 144 | + $output .= ' step="' . $args['step'] . '" '; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // required |
| 148 | - if(!empty($args['required'])){ |
|
| 148 | + if (!empty($args['required'])) { |
|
| 149 | 149 | $output .= ' required '; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // class |
| 153 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 154 | - $output .= ' class="form-control '.$class.'" '; |
|
| 153 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
| 154 | + $output .= ' class="form-control ' . $class . '" '; |
|
| 155 | 155 | |
| 156 | 156 | // data-attributes |
| 157 | 157 | $output .= AUI_Component_Helper::data_attributes($args); |
| 158 | 158 | |
| 159 | 159 | // extra attributes |
| 160 | - if(!empty($args['extra_attributes'])){ |
|
| 160 | + if (!empty($args['extra_attributes'])) { |
|
| 161 | 161 | $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
| 162 | 162 | } |
| 163 | 163 | |
@@ -166,40 +166,40 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | |
| 168 | 168 | // label |
| 169 | - if(!empty($args['label'])){ |
|
| 170 | - if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
| 171 | - elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
| 172 | - $label = self::label( $label_args, $type ); |
|
| 169 | + if (!empty($args['label'])) { |
|
| 170 | + if ($type == 'file') {$label_args['class'] .= 'custom-file-label'; } |
|
| 171 | + elseif ($type == 'checkbox') {$label_args['class'] .= 'custom-control-label'; } |
|
| 172 | + $label = self::label($label_args, $type); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // help text |
| 176 | - if(!empty($args['help_text'])){ |
|
| 176 | + if (!empty($args['help_text'])) { |
|
| 177 | 177 | $help_text = AUI_Component_Helper::help_text($args['help_text']); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
| 181 | 181 | // set help text in the correct possition |
| 182 | - if($label_after){ |
|
| 182 | + if ($label_after) { |
|
| 183 | 183 | $output .= $label . $help_text; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // some input types need a separate wrap |
| 187 | - if($type == 'file') { |
|
| 188 | - $output = self::wrap( array( |
|
| 187 | + if ($type == 'file') { |
|
| 188 | + $output = self::wrap(array( |
|
| 189 | 189 | 'content' => $output, |
| 190 | 190 | 'class' => 'form-group custom-file' |
| 191 | - ) ); |
|
| 192 | - }elseif($type == 'checkbox'){ |
|
| 191 | + )); |
|
| 192 | + }elseif ($type == 'checkbox') { |
|
| 193 | 193 | $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
| 194 | - $output = self::wrap( array( |
|
| 194 | + $output = self::wrap(array( |
|
| 195 | 195 | 'content' => $output, |
| 196 | - 'class' => 'custom-control '.$wrap_class |
|
| 197 | - ) ); |
|
| 196 | + 'class' => 'custom-control ' . $wrap_class |
|
| 197 | + )); |
|
| 198 | 198 | |
| 199 | - if($args['label_type']=='horizontal'){ |
|
| 199 | + if ($args['label_type'] == 'horizontal') { |
|
| 200 | 200 | $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
| 201 | 201 | } |
| 202 | - }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
| 202 | + }elseif ($type == 'password' && $args['password_toggle'] && !$args['input_group_right']) { |
|
| 203 | 203 | |
| 204 | 204 | |
| 205 | 205 | // allow password field to toggle view |
@@ -213,49 +213,49 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // input group wraps |
| 216 | - if($args['input_group_left'] || $args['input_group_right']){ |
|
| 216 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
| 217 | 217 | $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
| 218 | - if($args['input_group_left']){ |
|
| 219 | - $output = self::wrap( array( |
|
| 218 | + if ($args['input_group_left']) { |
|
| 219 | + $output = self::wrap(array( |
|
| 220 | 220 | 'content' => $output, |
| 221 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
| 221 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 222 | 222 | 'input_group_left' => $args['input_group_left'], |
| 223 | 223 | 'input_group_left_inside' => $args['input_group_left_inside'] |
| 224 | - ) ); |
|
| 224 | + )); |
|
| 225 | 225 | } |
| 226 | - if($args['input_group_right']){ |
|
| 227 | - $output = self::wrap( array( |
|
| 226 | + if ($args['input_group_right']) { |
|
| 227 | + $output = self::wrap(array( |
|
| 228 | 228 | 'content' => $output, |
| 229 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
| 229 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 230 | 230 | 'input_group_right' => $args['input_group_right'], |
| 231 | 231 | 'input_group_right_inside' => $args['input_group_right_inside'] |
| 232 | - ) ); |
|
| 232 | + )); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if(!$label_after){ |
|
| 237 | + if (!$label_after) { |
|
| 238 | 238 | $output .= $help_text; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
| 242 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
| 243 | - $output = self::wrap( array( |
|
| 242 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
| 243 | + $output = self::wrap(array( |
|
| 244 | 244 | 'content' => $output, |
| 245 | 245 | 'class' => 'col-sm-10', |
| 246 | - ) ); |
|
| 246 | + )); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if(!$label_after){ |
|
| 249 | + if (!$label_after) { |
|
| 250 | 250 | $output = $label . $output; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | // wrap |
| 254 | - if(!$args['no_wrap']){ |
|
| 254 | + if (!$args['no_wrap']) { |
|
| 255 | 255 | |
| 256 | - $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
| 257 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 258 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 256 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
| 257 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 258 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 259 | 259 | $output = self::wrap(array( |
| 260 | 260 | 'content' => $output, |
| 261 | 261 | 'class' => $wrap_class, |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | * |
| 279 | 279 | * @return string The rendered component. |
| 280 | 280 | */ |
| 281 | - public static function textarea($args = array()){ |
|
| 281 | + public static function textarea($args = array()) { |
|
| 282 | 282 | $defaults = array( |
| 283 | 283 | 'name' => '', |
| 284 | 284 | 'class' => '', |
@@ -306,43 +306,43 @@ discard block |
||
| 306 | 306 | /** |
| 307 | 307 | * Parse incoming $args into an array and merge it with $defaults |
| 308 | 308 | */ |
| 309 | - $args = wp_parse_args( $args, $defaults ); |
|
| 309 | + $args = wp_parse_args($args, $defaults); |
|
| 310 | 310 | $output = ''; |
| 311 | 311 | |
| 312 | 312 | // hidden label option needs to be empty |
| 313 | 313 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
| 314 | 314 | |
| 315 | 315 | // floating labels don't work with wysiwyg so set it as top |
| 316 | - if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
| 316 | + if ($args['label_type'] == 'floating' && !empty($args['wysiwyg'])) { |
|
| 317 | 317 | $args['label_type'] = 'top'; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | $label_after = $args['label_after']; |
| 321 | 321 | |
| 322 | 322 | // floating labels need label after |
| 323 | - if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
| 323 | + if ($args['label_type'] == 'floating' && empty($args['wysiwyg'])) { |
|
| 324 | 324 | $label_after = true; |
| 325 | 325 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // label |
| 329 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
| 330 | - }elseif(!empty($args['label']) && !$label_after){ |
|
| 329 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
| 330 | + }elseif (!empty($args['label']) && !$label_after) { |
|
| 331 | 331 | $label_args = array( |
| 332 | 332 | 'title'=> $args['label'], |
| 333 | 333 | 'for'=> $args['id'], |
| 334 | - 'class' => $args['label_class']." ", |
|
| 334 | + 'class' => $args['label_class'] . " ", |
|
| 335 | 335 | 'label_type' => $args['label_type'] |
| 336 | 336 | ); |
| 337 | - $output .= self::label( $label_args ); |
|
| 337 | + $output .= self::label($label_args); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | // maybe horizontal label |
| 341 | - if($args['label_type']=='horizontal'){ |
|
| 341 | + if ($args['label_type'] == 'horizontal') { |
|
| 342 | 342 | $output .= '<div class="col-sm-10">'; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - if(!empty($args['wysiwyg'])){ |
|
| 345 | + if (!empty($args['wysiwyg'])) { |
|
| 346 | 346 | ob_start(); |
| 347 | 347 | $content = $args['value']; |
| 348 | 348 | $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
@@ -356,65 +356,65 @@ discard block |
||
| 356 | 356 | ); |
| 357 | 357 | |
| 358 | 358 | // maybe set settings if array |
| 359 | - if(is_array($args['wysiwyg'])){ |
|
| 360 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 359 | + if (is_array($args['wysiwyg'])) { |
|
| 360 | + $settings = wp_parse_args($args['wysiwyg'], $settings); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - wp_editor( $content, $editor_id, $settings ); |
|
| 363 | + wp_editor($content, $editor_id, $settings); |
|
| 364 | 364 | $output .= ob_get_clean(); |
| 365 | - }else{ |
|
| 365 | + } else { |
|
| 366 | 366 | |
| 367 | 367 | // open |
| 368 | 368 | $output .= '<textarea '; |
| 369 | 369 | |
| 370 | 370 | // name |
| 371 | - if(!empty($args['name'])){ |
|
| 372 | - $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
| 371 | + if (!empty($args['name'])) { |
|
| 372 | + $output .= ' name="' . sanitize_html_class($args['name']) . '" '; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | // id |
| 376 | - if(!empty($args['id'])){ |
|
| 377 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
| 376 | + if (!empty($args['id'])) { |
|
| 377 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | // placeholder |
| 381 | - if(isset($args['placeholder']) && '' != $args['placeholder']){ |
|
| 382 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
| 381 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
| 382 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | // title |
| 386 | - if(!empty($args['title'])){ |
|
| 387 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
| 386 | + if (!empty($args['title'])) { |
|
| 387 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // validation text |
| 391 | - if(!empty($args['validation_text'])){ |
|
| 392 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
| 391 | + if (!empty($args['validation_text'])) { |
|
| 392 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
| 393 | 393 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | // validation_pattern |
| 397 | - if(!empty($args['validation_pattern'])){ |
|
| 398 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
| 397 | + if (!empty($args['validation_pattern'])) { |
|
| 398 | + $output .= ' pattern="' . $args['validation_pattern'] . '" '; |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | // required |
| 402 | - if(!empty($args['required'])){ |
|
| 402 | + if (!empty($args['required'])) { |
|
| 403 | 403 | $output .= ' required '; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | // rows |
| 407 | - if(!empty($args['rows'])){ |
|
| 408 | - $output .= ' rows="'.absint($args['rows']).'" '; |
|
| 407 | + if (!empty($args['rows'])) { |
|
| 408 | + $output .= ' rows="' . absint($args['rows']) . '" '; |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
| 412 | 412 | // class |
| 413 | 413 | $class = !empty($args['class']) ? $args['class'] : ''; |
| 414 | - $output .= ' class="form-control '.$class.'" '; |
|
| 414 | + $output .= ' class="form-control ' . $class . '" '; |
|
| 415 | 415 | |
| 416 | 416 | // extra attributes |
| 417 | - if(!empty($args['extra_attributes'])){ |
|
| 417 | + if (!empty($args['extra_attributes'])) { |
|
| 418 | 418 | $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
| 419 | 419 | } |
| 420 | 420 | |
@@ -422,11 +422,11 @@ discard block |
||
| 422 | 422 | $output .= ' >'; |
| 423 | 423 | |
| 424 | 424 | // value |
| 425 | - if ( ! empty( $args['value'] ) ) { |
|
| 426 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
| 427 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 425 | + if (!empty($args['value'])) { |
|
| 426 | + if (!empty($args['allow_tags'])) { |
|
| 427 | + $output .= AUI_Component_Helper::sanitize_html_field($args['value'], $args); // Sanitize HTML. |
|
| 428 | 428 | } else { |
| 429 | - $output .= sanitize_textarea_field( $args['value'] ); |
|
| 429 | + $output .= sanitize_textarea_field($args['value']); |
|
| 430 | 430 | } |
| 431 | 431 | } |
| 432 | 432 | |
@@ -435,32 +435,32 @@ discard block |
||
| 435 | 435 | |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - if(!empty($args['label']) && $label_after){ |
|
| 438 | + if (!empty($args['label']) && $label_after) { |
|
| 439 | 439 | $label_args = array( |
| 440 | 440 | 'title'=> $args['label'], |
| 441 | 441 | 'for'=> $args['id'], |
| 442 | - 'class' => $args['label_class']." ", |
|
| 442 | + 'class' => $args['label_class'] . " ", |
|
| 443 | 443 | 'label_type' => $args['label_type'] |
| 444 | 444 | ); |
| 445 | - $output .= self::label( $label_args ); |
|
| 445 | + $output .= self::label($label_args); |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // help text |
| 449 | - if(!empty($args['help_text'])){ |
|
| 449 | + if (!empty($args['help_text'])) { |
|
| 450 | 450 | $output .= AUI_Component_Helper::help_text($args['help_text']); |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | // maybe horizontal label |
| 454 | - if($args['label_type']=='horizontal'){ |
|
| 454 | + if ($args['label_type'] == 'horizontal') { |
|
| 455 | 455 | $output .= '</div>'; |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | |
| 459 | 459 | // wrap |
| 460 | - if(!$args['no_wrap']){ |
|
| 461 | - $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
| 462 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 463 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 460 | + if (!$args['no_wrap']) { |
|
| 461 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
| 462 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 463 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 464 | 464 | $output = self::wrap(array( |
| 465 | 465 | 'content' => $output, |
| 466 | 466 | 'class' => $wrap_class, |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | return $output; |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - public static function label($args = array(), $type = ''){ |
|
| 476 | + public static function label($args = array(), $type = '') { |
|
| 477 | 477 | //<label for="exampleInputEmail1">Email address</label> |
| 478 | 478 | $defaults = array( |
| 479 | 479 | 'title' => 'div', |
@@ -485,20 +485,20 @@ discard block |
||
| 485 | 485 | /** |
| 486 | 486 | * Parse incoming $args into an array and merge it with $defaults |
| 487 | 487 | */ |
| 488 | - $args = wp_parse_args( $args, $defaults ); |
|
| 488 | + $args = wp_parse_args($args, $defaults); |
|
| 489 | 489 | $output = ''; |
| 490 | 490 | |
| 491 | - if($args['title']){ |
|
| 491 | + if ($args['title']) { |
|
| 492 | 492 | |
| 493 | 493 | // maybe hide labels //@todo set a global option for visibility class |
| 494 | - if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
| 494 | + if ($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type'])) { |
|
| 495 | 495 | $class = $args['class']; |
| 496 | - }else{ |
|
| 497 | - $class = 'sr-only '.$args['class']; |
|
| 496 | + } else { |
|
| 497 | + $class = 'sr-only ' . $args['class']; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | // maybe horizontal |
| 501 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
| 501 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
| 502 | 502 | $class .= ' col-sm-2 col-form-label'; |
| 503 | 503 | } |
| 504 | 504 | |
@@ -506,20 +506,20 @@ discard block |
||
| 506 | 506 | $output .= '<label '; |
| 507 | 507 | |
| 508 | 508 | // for |
| 509 | - if(!empty($args['for'])){ |
|
| 510 | - $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
| 509 | + if (!empty($args['for'])) { |
|
| 510 | + $output .= ' for="' . sanitize_text_field($args['for']) . '" '; |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | // class |
| 514 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 515 | - $output .= ' class="'.$class.'" '; |
|
| 514 | + $class = $class ? AUI_Component_Helper::esc_classes($class) : ''; |
|
| 515 | + $output .= ' class="' . $class . '" '; |
|
| 516 | 516 | |
| 517 | 517 | // close |
| 518 | 518 | $output .= '>'; |
| 519 | 519 | |
| 520 | 520 | |
| 521 | 521 | // title, don't escape fully as can contain html |
| 522 | - if(!empty($args['title'])){ |
|
| 522 | + if (!empty($args['title'])) { |
|
| 523 | 523 | $output .= wp_kses_post($args['title']); |
| 524 | 524 | } |
| 525 | 525 | |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | * |
| 541 | 541 | * @return string |
| 542 | 542 | */ |
| 543 | - public static function wrap($args = array()){ |
|
| 543 | + public static function wrap($args = array()) { |
|
| 544 | 544 | $defaults = array( |
| 545 | 545 | 'type' => 'div', |
| 546 | 546 | 'class' => 'form-group', |
@@ -556,55 +556,55 @@ discard block |
||
| 556 | 556 | /** |
| 557 | 557 | * Parse incoming $args into an array and merge it with $defaults |
| 558 | 558 | */ |
| 559 | - $args = wp_parse_args( $args, $defaults ); |
|
| 559 | + $args = wp_parse_args($args, $defaults); |
|
| 560 | 560 | $output = ''; |
| 561 | - if($args['type']){ |
|
| 561 | + if ($args['type']) { |
|
| 562 | 562 | |
| 563 | 563 | // open |
| 564 | - $output .= '<'.sanitize_html_class($args['type']); |
|
| 564 | + $output .= '<' . sanitize_html_class($args['type']); |
|
| 565 | 565 | |
| 566 | 566 | // element require |
| 567 | - if(!empty($args['element_require'])){ |
|
| 567 | + if (!empty($args['element_require'])) { |
|
| 568 | 568 | $output .= AUI_Component_Helper::element_require($args['element_require']); |
| 569 | 569 | $args['class'] .= " aui-conditional-field"; |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | // argument_id |
| 573 | - if( !empty($args['argument_id']) ){ |
|
| 574 | - $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
| 573 | + if (!empty($args['argument_id'])) { |
|
| 574 | + $output .= ' data-argument="' . esc_attr($args['argument_id']) . '"'; |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | // class |
| 578 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 579 | - $output .= ' class="'.$class.'" '; |
|
| 578 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
| 579 | + $output .= ' class="' . $class . '" '; |
|
| 580 | 580 | |
| 581 | 581 | // close wrap |
| 582 | 582 | $output .= ' >'; |
| 583 | 583 | |
| 584 | 584 | |
| 585 | 585 | // Input group left |
| 586 | - if(!empty($args['input_group_left'])){ |
|
| 586 | + if (!empty($args['input_group_left'])) { |
|
| 587 | 587 | $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
| 588 | - $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
| 589 | - $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
| 588 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
| 589 | + $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | // content |
| 593 | 593 | $output .= $args['content']; |
| 594 | 594 | |
| 595 | 595 | // Input group right |
| 596 | - if(!empty($args['input_group_right'])){ |
|
| 596 | + if (!empty($args['input_group_right'])) { |
|
| 597 | 597 | $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
| 598 | - $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
| 599 | - $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
| 598 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
| 599 | + $output .= '<div class="input-group-append ' . $position_class . '">' . $input_group_right . '</div>'; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | |
| 603 | 603 | // close wrap |
| 604 | - $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
| 604 | + $output .= '</' . sanitize_html_class($args['type']) . '>'; |
|
| 605 | 605 | |
| 606 | 606 | |
| 607 | - }else{ |
|
| 607 | + } else { |
|
| 608 | 608 | $output = $args['content']; |
| 609 | 609 | } |
| 610 | 610 | |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | * |
| 619 | 619 | * @return string The rendered component. |
| 620 | 620 | */ |
| 621 | - public static function select($args = array()){ |
|
| 621 | + public static function select($args = array()) { |
|
| 622 | 622 | $defaults = array( |
| 623 | 623 | 'class' => '', |
| 624 | 624 | 'wrap_class' => '', |
@@ -644,11 +644,11 @@ discard block |
||
| 644 | 644 | /** |
| 645 | 645 | * Parse incoming $args into an array and merge it with $defaults |
| 646 | 646 | */ |
| 647 | - $args = wp_parse_args( $args, $defaults ); |
|
| 647 | + $args = wp_parse_args($args, $defaults); |
|
| 648 | 648 | $output = ''; |
| 649 | 649 | |
| 650 | 650 | // for now lets hide floating labels |
| 651 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
| 651 | + if ($args['label_type'] == 'floating') {$args['label_type'] = 'hidden'; } |
|
| 652 | 652 | |
| 653 | 653 | // hidden label option needs to be empty |
| 654 | 654 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
@@ -657,47 +657,47 @@ discard block |
||
| 657 | 657 | $label_after = $args['label_after']; |
| 658 | 658 | |
| 659 | 659 | // floating labels need label after |
| 660 | - if( $args['label_type'] == 'floating' ){ |
|
| 660 | + if ($args['label_type'] == 'floating') { |
|
| 661 | 661 | $label_after = true; |
| 662 | 662 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | // Maybe setup select2 |
| 666 | 666 | $is_select2 = false; |
| 667 | - if(!empty($args['select2'])){ |
|
| 667 | + if (!empty($args['select2'])) { |
|
| 668 | 668 | $args['class'] .= ' aui-select2'; |
| 669 | 669 | $is_select2 = true; |
| 670 | - }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
| 670 | + }elseif (strpos($args['class'], 'aui-select2') !== false) { |
|
| 671 | 671 | $is_select2 = true; |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | // select2 tags |
| 675 | - if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
| 675 | + if (!empty($args['select2']) && $args['select2'] === 'tags') { // triple equals needed here for some reason |
|
| 676 | 676 | $args['data-tags'] = 'true'; |
| 677 | 677 | $args['data-token-separators'] = "[',']"; |
| 678 | 678 | $args['multiple'] = true; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | // select2 placeholder |
| 682 | - if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){ |
|
| 682 | + if ($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])) { |
|
| 683 | 683 | $args['data-placeholder'] = esc_attr($args['placeholder']); |
| 684 | 684 | $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | // label |
| 688 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
| 689 | - }elseif(!empty($args['label']) && !$label_after){ |
|
| 688 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
| 689 | + }elseif (!empty($args['label']) && !$label_after) { |
|
| 690 | 690 | $label_args = array( |
| 691 | 691 | 'title'=> $args['label'], |
| 692 | 692 | 'for'=> $args['id'], |
| 693 | - 'class' => $args['label_class']." ", |
|
| 693 | + 'class' => $args['label_class'] . " ", |
|
| 694 | 694 | 'label_type' => $args['label_type'] |
| 695 | 695 | ); |
| 696 | 696 | $output .= self::label($label_args); |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | // maybe horizontal label |
| 700 | - if($args['label_type']=='horizontal'){ |
|
| 700 | + if ($args['label_type'] == 'horizontal') { |
|
| 701 | 701 | $output .= '<div class="col-sm-10">'; |
| 702 | 702 | } |
| 703 | 703 | |
@@ -705,32 +705,32 @@ discard block |
||
| 705 | 705 | $output .= '<select '; |
| 706 | 706 | |
| 707 | 707 | // style |
| 708 | - if($is_select2){ |
|
| 708 | + if ($is_select2) { |
|
| 709 | 709 | $output .= " style='width:100%;' "; |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | // element require |
| 713 | - if(!empty($args['element_require'])){ |
|
| 713 | + if (!empty($args['element_require'])) { |
|
| 714 | 714 | $output .= AUI_Component_Helper::element_require($args['element_require']); |
| 715 | 715 | $args['class'] .= " aui-conditional-field"; |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | // class |
| 719 | 719 | $class = !empty($args['class']) ? $args['class'] : ''; |
| 720 | - $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
| 720 | + $output .= AUI_Component_Helper::class_attr('custom-select ' . $class); |
|
| 721 | 721 | |
| 722 | 722 | // name |
| 723 | - if(!empty($args['name'])){ |
|
| 724 | - $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
| 723 | + if (!empty($args['name'])) { |
|
| 724 | + $output .= AUI_Component_Helper::name($args['name'], $args['multiple']); |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | // id |
| 728 | - if(!empty($args['id'])){ |
|
| 728 | + if (!empty($args['id'])) { |
|
| 729 | 729 | $output .= AUI_Component_Helper::id($args['id']); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | // title |
| 733 | - if(!empty($args['title'])){ |
|
| 733 | + if (!empty($args['title'])) { |
|
| 734 | 734 | $output .= AUI_Component_Helper::title($args['title']); |
| 735 | 735 | } |
| 736 | 736 | |
@@ -741,17 +741,17 @@ discard block |
||
| 741 | 741 | $output .= AUI_Component_Helper::aria_attributes($args); |
| 742 | 742 | |
| 743 | 743 | // extra attributes |
| 744 | - if(!empty($args['extra_attributes'])){ |
|
| 744 | + if (!empty($args['extra_attributes'])) { |
|
| 745 | 745 | $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | // required |
| 749 | - if(!empty($args['required'])){ |
|
| 749 | + if (!empty($args['required'])) { |
|
| 750 | 750 | $output .= ' required '; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | // multiple |
| 754 | - if(!empty($args['multiple'])){ |
|
| 754 | + if (!empty($args['multiple'])) { |
|
| 755 | 755 | $output .= ' multiple '; |
| 756 | 756 | } |
| 757 | 757 | |
@@ -759,21 +759,21 @@ discard block |
||
| 759 | 759 | $output .= ' >'; |
| 760 | 760 | |
| 761 | 761 | // placeholder |
| 762 | - if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){ |
|
| 763 | - $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
| 764 | - }elseif($is_select2 && !empty($args['placeholder'])){ |
|
| 762 | + if (isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2) { |
|
| 763 | + $output .= '<option value="" disabled selected hidden>' . esc_attr($args['placeholder']) . '</option>'; |
|
| 764 | + }elseif ($is_select2 && !empty($args['placeholder'])) { |
|
| 765 | 765 | $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | // Options |
| 769 | - if(!empty($args['options'])){ |
|
| 769 | + if (!empty($args['options'])) { |
|
| 770 | 770 | |
| 771 | - if(!is_array($args['options'])){ |
|
| 771 | + if (!is_array($args['options'])) { |
|
| 772 | 772 | $output .= $args['options']; // not the preferred way but an option |
| 773 | - }else{ |
|
| 774 | - foreach($args['options'] as $val => $name){ |
|
| 773 | + } else { |
|
| 774 | + foreach ($args['options'] as $val => $name) { |
|
| 775 | 775 | $selected = ''; |
| 776 | - if(is_array($name)){ |
|
| 776 | + if (is_array($name)) { |
|
| 777 | 777 | if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
| 778 | 778 | $option_label = isset($name['label']) ? $name['label'] : ''; |
| 779 | 779 | |
@@ -781,23 +781,23 @@ discard block |
||
| 781 | 781 | } else { |
| 782 | 782 | $option_label = isset($name['label']) ? $name['label'] : ''; |
| 783 | 783 | $option_value = isset($name['value']) ? $name['value'] : ''; |
| 784 | - if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
| 784 | + if (!empty($args['multiple']) && !empty($args['value']) && is_array($args['value'])) { |
|
| 785 | 785 | $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
| 786 | - } elseif(!empty($args['value'])) { |
|
| 787 | - $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
| 786 | + } elseif (!empty($args['value'])) { |
|
| 787 | + $selected = selected($option_value, stripslashes_deep($args['value']), false); |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
| 791 | 791 | } |
| 792 | - }else{ |
|
| 793 | - if(!empty($args['value'])){ |
|
| 794 | - if(is_array($args['value'])){ |
|
| 795 | - $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
| 796 | - } elseif(!empty($args['value'])) { |
|
| 797 | - $selected = selected( $args['value'], $val, false); |
|
| 792 | + } else { |
|
| 793 | + if (!empty($args['value'])) { |
|
| 794 | + if (is_array($args['value'])) { |
|
| 795 | + $selected = in_array($val, $args['value']) ? 'selected="selected"' : ''; |
|
| 796 | + } elseif (!empty($args['value'])) { |
|
| 797 | + $selected = selected($args['value'], $val, false); |
|
| 798 | 798 | } |
| 799 | 799 | } |
| 800 | - $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
| 800 | + $output .= '<option value="' . esc_attr($val) . '" ' . $selected . '>' . esc_attr($name) . '</option>'; |
|
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | } |
@@ -807,31 +807,31 @@ discard block |
||
| 807 | 807 | // closing tag |
| 808 | 808 | $output .= '</select>'; |
| 809 | 809 | |
| 810 | - if(!empty($args['label']) && $label_after){ |
|
| 810 | + if (!empty($args['label']) && $label_after) { |
|
| 811 | 811 | $label_args = array( |
| 812 | 812 | 'title'=> $args['label'], |
| 813 | 813 | 'for'=> $args['id'], |
| 814 | - 'class' => $args['label_class']." ", |
|
| 814 | + 'class' => $args['label_class'] . " ", |
|
| 815 | 815 | 'label_type' => $args['label_type'] |
| 816 | 816 | ); |
| 817 | 817 | $output .= self::label($label_args); |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | // help text |
| 821 | - if(!empty($args['help_text'])){ |
|
| 821 | + if (!empty($args['help_text'])) { |
|
| 822 | 822 | $output .= AUI_Component_Helper::help_text($args['help_text']); |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | // maybe horizontal label |
| 826 | - if($args['label_type']=='horizontal'){ |
|
| 826 | + if ($args['label_type'] == 'horizontal') { |
|
| 827 | 827 | $output .= '</div>'; |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | |
| 831 | 831 | // wrap |
| 832 | - if(!$args['no_wrap']){ |
|
| 833 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
| 834 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 832 | + if (!$args['no_wrap']) { |
|
| 833 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
| 834 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 835 | 835 | $output = self::wrap(array( |
| 836 | 836 | 'content' => $output, |
| 837 | 837 | 'class' => $wrap_class, |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | * |
| 852 | 852 | * @return string The rendered component. |
| 853 | 853 | */ |
| 854 | - public static function radio($args = array()){ |
|
| 854 | + public static function radio($args = array()) { |
|
| 855 | 855 | $defaults = array( |
| 856 | 856 | 'class' => '', |
| 857 | 857 | 'wrap_class' => '', |
@@ -874,14 +874,14 @@ discard block |
||
| 874 | 874 | /** |
| 875 | 875 | * Parse incoming $args into an array and merge it with $defaults |
| 876 | 876 | */ |
| 877 | - $args = wp_parse_args( $args, $defaults ); |
|
| 877 | + $args = wp_parse_args($args, $defaults); |
|
| 878 | 878 | |
| 879 | 879 | // for now lets use horizontal for floating |
| 880 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
| 880 | + if ($args['label_type'] == 'floating') {$args['label_type'] = 'horizontal'; } |
|
| 881 | 881 | |
| 882 | 882 | $label_args = array( |
| 883 | 883 | 'title'=> $args['label'], |
| 884 | - 'class' => $args['label_class']." pt-0 ", |
|
| 884 | + 'class' => $args['label_class'] . " pt-0 ", |
|
| 885 | 885 | 'label_type' => $args['label_type'] |
| 886 | 886 | ); |
| 887 | 887 | |
@@ -890,36 +890,36 @@ discard block |
||
| 890 | 890 | |
| 891 | 891 | |
| 892 | 892 | // label before |
| 893 | - if(!empty($args['label'])){ |
|
| 894 | - $output .= self::label( $label_args, 'radio' ); |
|
| 893 | + if (!empty($args['label'])) { |
|
| 894 | + $output .= self::label($label_args, 'radio'); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | // maybe horizontal label |
| 898 | - if($args['label_type']=='horizontal'){ |
|
| 898 | + if ($args['label_type'] == 'horizontal') { |
|
| 899 | 899 | $output .= '<div class="col-sm-10">'; |
| 900 | 900 | } |
| 901 | 901 | |
| 902 | - if(!empty($args['options'])){ |
|
| 902 | + if (!empty($args['options'])) { |
|
| 903 | 903 | $count = 0; |
| 904 | - foreach($args['options'] as $value => $label){ |
|
| 904 | + foreach ($args['options'] as $value => $label) { |
|
| 905 | 905 | $option_args = $args; |
| 906 | 906 | $option_args['value'] = $value; |
| 907 | 907 | $option_args['label'] = $label; |
| 908 | 908 | $option_args['checked'] = $value == $args['value'] ? true : false; |
| 909 | - $output .= self::radio_option($option_args,$count); |
|
| 909 | + $output .= self::radio_option($option_args, $count); |
|
| 910 | 910 | $count++; |
| 911 | 911 | } |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | // maybe horizontal label |
| 915 | - if($args['label_type']=='horizontal'){ |
|
| 915 | + if ($args['label_type'] == 'horizontal') { |
|
| 916 | 916 | $output .= '</div>'; |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | |
| 920 | 920 | // wrap |
| 921 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
| 922 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
| 921 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
| 922 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 923 | 923 | $output = self::wrap(array( |
| 924 | 924 | 'content' => $output, |
| 925 | 925 | 'class' => $wrap_class, |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | * |
| 939 | 939 | * @return string The rendered component. |
| 940 | 940 | */ |
| 941 | - public static function radio_option($args = array(),$count = ''){ |
|
| 941 | + public static function radio_option($args = array(), $count = '') { |
|
| 942 | 942 | $defaults = array( |
| 943 | 943 | 'class' => '', |
| 944 | 944 | 'id' => '', |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | /** |
| 957 | 957 | * Parse incoming $args into an array and merge it with $defaults |
| 958 | 958 | */ |
| 959 | - $args = wp_parse_args( $args, $defaults ); |
|
| 959 | + $args = wp_parse_args($args, $defaults); |
|
| 960 | 960 | |
| 961 | 961 | $output = ''; |
| 962 | 962 | |
@@ -967,27 +967,27 @@ discard block |
||
| 967 | 967 | $output .= ' class="form-check-input" '; |
| 968 | 968 | |
| 969 | 969 | // name |
| 970 | - if(!empty($args['name'])){ |
|
| 970 | + if (!empty($args['name'])) { |
|
| 971 | 971 | $output .= AUI_Component_Helper::name($args['name']); |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | // id |
| 975 | - if(!empty($args['id'])){ |
|
| 976 | - $output .= AUI_Component_Helper::id($args['id'].$count); |
|
| 975 | + if (!empty($args['id'])) { |
|
| 976 | + $output .= AUI_Component_Helper::id($args['id'] . $count); |
|
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | // title |
| 980 | - if(!empty($args['title'])){ |
|
| 980 | + if (!empty($args['title'])) { |
|
| 981 | 981 | $output .= AUI_Component_Helper::title($args['title']); |
| 982 | 982 | } |
| 983 | 983 | |
| 984 | 984 | // value |
| 985 | - if(isset($args['value'])){ |
|
| 986 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
| 985 | + if (isset($args['value'])) { |
|
| 986 | + $output .= ' value="' . sanitize_text_field($args['value']) . '" '; |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | // checked, for radio and checkboxes |
| 990 | - if( $args['checked'] ){ |
|
| 990 | + if ($args['checked']) { |
|
| 991 | 991 | $output .= ' checked '; |
| 992 | 992 | } |
| 993 | 993 | |
@@ -998,12 +998,12 @@ discard block |
||
| 998 | 998 | $output .= AUI_Component_Helper::aria_attributes($args); |
| 999 | 999 | |
| 1000 | 1000 | // extra attributes |
| 1001 | - if(!empty($args['extra_attributes'])){ |
|
| 1001 | + if (!empty($args['extra_attributes'])) { |
|
| 1002 | 1002 | $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | // required |
| 1006 | - if(!empty($args['required'])){ |
|
| 1006 | + if (!empty($args['required'])) { |
|
| 1007 | 1007 | $output .= ' required '; |
| 1008 | 1008 | } |
| 1009 | 1009 | |
@@ -1011,13 +1011,13 @@ discard block |
||
| 1011 | 1011 | $output .= ' >'; |
| 1012 | 1012 | |
| 1013 | 1013 | // label |
| 1014 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
| 1015 | - }elseif(!empty($args['label'])){ |
|
| 1016 | - $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
| 1014 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
| 1015 | + }elseif (!empty($args['label'])) { |
|
| 1016 | + $output .= self::label(array('title'=>$args['label'], 'for'=>$args['id'] . $count, 'class'=>'form-check-label'), 'radio'); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | // wrap |
| 1020 | - if(!$args['no_wrap']){ |
|
| 1020 | + if (!$args['no_wrap']) { |
|
| 1021 | 1021 | $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
| 1022 | 1022 | $output = self::wrap(array( |
| 1023 | 1023 | 'content' => $output, |