| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikWP - Libraries |
| 4 |
* @subpackage adapter.form |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
JLoader::import('adapter.form.fields.list'); |
| 15 |
|
| 16 |
/** |
| 17 |
* Form field class to handle dropdown fields containing |
| 18 |
* the available module layouts. |
| 19 |
* |
| 20 |
* @since 10.0 |
| 21 |
*/ |
| 22 |
class JFormFieldModuleLayout extends JFormFieldList |
| 23 |
{ |
| 24 |
/** |
| 25 |
* @override |
| 26 |
* Method to get the data to be passed to the layout for rendering. |
| 27 |
* |
| 28 |
* @return array An associative array of display data. |
| 29 |
*/ |
| 30 |
public function getLayoutData() |
| 31 |
{ |
| 32 |
$path = $this->modpath . DIRECTORY_SEPARATOR . 'tmpl' . DIRECTORY_SEPARATOR . '*.php'; |
| 33 |
|
| 34 |
$this->option = array(); |
| 35 |
|
| 36 |
// get default layouts contained in the plugin directory |
| 37 |
foreach (glob($path) as $layout) |
| 38 |
{ |
| 39 |
$value = basename($layout); |
| 40 |
$value = substr($value, 0, strrpos($value, '.')); |
| 41 |
$text = ucwords(preg_replace("/[_-]/", ' ', $value)); |
| 42 |
|
| 43 |
$this->option[$value] = $text; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Get existing overrides (if any). |
| 48 |
* |
| 49 |
* @since 10.1.2 |
| 50 |
*/ |
| 51 |
if (preg_match("/[\/\\\\]plugins[\/\\\\](.*?)[\/\\\\](.*?)[\/\\\\](.*?)$/", $this->modpath, $match)) |
| 52 |
{ |
| 53 |
$upload = wp_upload_dir(); |
| 54 |
|
| 55 |
$parts = array(); |
| 56 |
// push base upload path |
| 57 |
$parts[] = $upload['basedir']; |
| 58 |
// push plugin name |
| 59 |
$parts[] = $match[1]; |
| 60 |
// push default overrides folder |
| 61 |
$parts[] = 'overrides'; |
| 62 |
// push client dir (modules) |
| 63 |
$parts[] = $match[2]; |
| 64 |
// push widget name |
| 65 |
$parts[] = $match[3]; |
| 66 |
|
| 67 |
$layoutsPath = implode(DIRECTORY_SEPARATOR, $parts); |
| 68 |
|
| 69 |
// make sure the module override folder exists |
| 70 |
if (is_dir($layoutsPath)) |
| 71 |
{ |
| 72 |
// get all layouts contained in the override directory |
| 73 |
foreach (glob($layoutsPath . DIRECTORY_SEPARATOR . '*.php') as $layout) |
| 74 |
{ |
| 75 |
// prettify the layout name |
| 76 |
$text = basename($layout); |
| 77 |
$text = substr($text, 0, strrpos($text, '.')); |
| 78 |
$text = ucwords(preg_replace("/[_-]/", ' ', $text)); |
| 79 |
|
| 80 |
// use full path as value and concat "override" to the layout |
| 81 |
// name to allow the users to detect the custom files |
| 82 |
$this->option[$layout] = $text . ' (override)'; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
return parent::getLayoutData(); |
| 88 |
} |
| 89 |
} |
| 90 |
|