acf
This commit is contained in:
63
plugins/system/acf/ACF/Helpers/Field.php
Normal file
63
plugins/system/acf/ACF/Helpers/Field.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2023 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class Field
|
||||
{
|
||||
/**
|
||||
* Returns the widget for which the ACF custom field is based upon.
|
||||
*
|
||||
* @param string $type
|
||||
* @param object $field_options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function isWidgetBased($type = '', $field_options = [])
|
||||
{
|
||||
if (!$type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$widget_name = self::getWidgetName($type);
|
||||
|
||||
$widget = \NRFramework\Widgets\Helper::find($widget_name);
|
||||
|
||||
if ($widget === 'Map' && !is_null($field_options->fieldparams))
|
||||
{
|
||||
return !empty($field_options->fieldparams['provider']) ? $field_options->fieldparams['provider'] : $widget;
|
||||
}
|
||||
|
||||
return $widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the widget name of an ACF custom field.
|
||||
*
|
||||
* @param string @type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getWidgetName($type = '')
|
||||
{
|
||||
// Remove the "acf" prefix
|
||||
$type = str_replace('acf', '', $type);
|
||||
|
||||
// Map for any ACF fields that do not automatically translate to a Widget
|
||||
$map = [
|
||||
'address' => 'MapAddress'
|
||||
];
|
||||
|
||||
// Transform a field type to its corresponding widget from the map
|
||||
return isset($map[$type]) ? $map[$type] : $type;
|
||||
}
|
||||
}
|
||||
189
plugins/system/acf/ACF/Helpers/Fields/Address.php
Normal file
189
plugins/system/acf/ACF/Helpers/Fields/Address.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
|
||||
class Address
|
||||
{
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* If this accepts one image:
|
||||
* - Tells YooTheme to use the default type for the dropdown mapping option.
|
||||
*
|
||||
* If this accepts multiple images:
|
||||
* - Tells YooTheme to only return the value of this field in the dropdown mapping option.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'latitude',
|
||||
'metadata' => [
|
||||
'label' => 'Latitude'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'longitude',
|
||||
'metadata' => [
|
||||
'label' => 'Longitude'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'value',
|
||||
'metadata' => [
|
||||
'label' => 'Coordinates'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'address',
|
||||
'metadata' => [
|
||||
'label' => 'Address'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'postal_code',
|
||||
'metadata' => [
|
||||
'label' => 'Postal Code'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'country_code',
|
||||
'metadata' => [
|
||||
'label' => 'Country Code'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'country',
|
||||
'metadata' => [
|
||||
'label' => 'Country'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'state',
|
||||
'metadata' => [
|
||||
'label' => 'State'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'municipality',
|
||||
'metadata' => [
|
||||
'label' => 'Municipality'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'town',
|
||||
'metadata' => [
|
||||
'label' => 'Town'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'city',
|
||||
'metadata' => [
|
||||
'label' => 'City'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'road',
|
||||
'metadata' => [
|
||||
'label' => 'Road'
|
||||
],
|
||||
]
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? json_encode($item["field{$args['field_id']}"]) : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
if (is_string($value))
|
||||
{
|
||||
if (!$value = json_decode($value, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$lat = isset($value['address']['latitude']) ? $value['address']['latitude'] : null;
|
||||
$lng = isset($value['address']['longitude']) ? $value['address']['longitude'] : null;
|
||||
|
||||
return [
|
||||
'latitude' => $lat,
|
||||
'longitude' => $lng,
|
||||
'value' => $lat && $lng ? implode(',', [$lat, $lng]) : null,
|
||||
'address' => isset($value['address']['address']) ? $value['address']['address'] : null,
|
||||
'postal_code' => isset($value['address']['postal_code']) ? $value['address']['postal_code'] : null,
|
||||
'country_code' => isset($value['address']['country_code']) ? $value['address']['country_code'] : null,
|
||||
'country' => isset($value['address']['country']) ? $value['address']['country'] : null,
|
||||
'state' => isset($value['address']['state']) ? $value['address']['state'] : null,
|
||||
'municipality' => isset($value['address']['municipality']) ? $value['address']['municipality'] : null,
|
||||
'town' => isset($value['address']['town']) ? $value['address']['town'] : null,
|
||||
'city' => isset($value['address']['city']) ? $value['address']['city'] : null,
|
||||
'road' => isset($value['address']['road']) ? $value['address']['road'] : null
|
||||
];
|
||||
}
|
||||
}
|
||||
172
plugins/system/acf/ACF/Helpers/Fields/Articles.php
Normal file
172
plugins/system/acf/ACF/Helpers/Fields/Articles.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Builder\Joomla\Source\ArticleHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
class Articles
|
||||
{
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* If this accepts one image:
|
||||
* - Tells YooTheme to use the default type for the dropdown mapping option.
|
||||
*
|
||||
* If this accepts multiple images:
|
||||
* - Tells YooTheme to only return the value of this field in the dropdown mapping option.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
if ($field->only_use_in_subform === 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$max_articles = (int) $field->fieldparams->get('max_articles', 0);
|
||||
$multiple = $max_articles === 0 || $max_articles > 1;
|
||||
return $multiple ? ['listOf' => 'Article'] : 'Article';
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$ids = $field->rawvalue;
|
||||
|
||||
$max_articles = 0;
|
||||
$multiple = true;
|
||||
|
||||
// Handle Linked Articles
|
||||
$field_type = $field->fieldparams->get('articles_type', 'default');
|
||||
if ($field_type === 'linked')
|
||||
{
|
||||
|
||||
if (in_array($ids, ['1', 'true']))
|
||||
{
|
||||
$ids = self::getLinkedArticlesIDs($item->id, $field);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$max_articles = (int) $field->fieldparams->get('max_articles', 0);
|
||||
$multiple = $max_articles === 0 || $max_articles > 1;
|
||||
}
|
||||
|
||||
if (is_scalar($ids))
|
||||
{
|
||||
$ids = [(int) $ids];
|
||||
}
|
||||
|
||||
if (!is_array($ids))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$value = ArticleHelper::get($ids);
|
||||
|
||||
if ($field->only_use_in_subform === 1)
|
||||
{
|
||||
$data = array_values(array_map(function($article) {
|
||||
return $article->title;
|
||||
}, $value));
|
||||
|
||||
return implode(', ', $data);
|
||||
}
|
||||
|
||||
if ($multiple)
|
||||
{
|
||||
return array_values(array_map(function ($value) {
|
||||
return is_scalar($value) ? compact('value') : $value;
|
||||
}, $value));
|
||||
}
|
||||
else
|
||||
{
|
||||
return array_shift($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function getLinkedArticlesIDs($item_id = null, $field = [])
|
||||
{
|
||||
if (!$acf_articles = array_filter($field->fieldparams->get('articles_fields', [])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab all linked articles
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select('a.id')
|
||||
->from($db->quoteName('#__fields_values', 'fv'))
|
||||
->join('LEFT', $db->quoteName('#__content', 'a') . ' ON a.id = fv.item_id')
|
||||
->where($db->quoteName('fv.field_id') . ' IN (' . implode(',', $acf_articles) . ')')
|
||||
->where($db->quoteName('fv.value') . ' = ' . $db->q($item_id));
|
||||
|
||||
// Filter results
|
||||
require_once JPATH_PLUGINS . '/fields/acfarticles/fields/acfarticlesfilters.php';
|
||||
$payload = $field->fieldparams;
|
||||
$filters = new \ACFArticlesFilters($query, $payload);
|
||||
$query = $filters->apply();
|
||||
|
||||
// Set query
|
||||
$db->setQuery($query);
|
||||
|
||||
// Get articles
|
||||
if (!$articles = $db->loadAssocList())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Return article IDs
|
||||
$articles = array_map(function($article) {
|
||||
return $article['id'];
|
||||
}, $articles);
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
}
|
||||
93
plugins/system/acf/ACF/Helpers/Fields/Chainedfields.php
Normal file
93
plugins/system/acf/ACF/Helpers/Fields/Chainedfields.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
|
||||
class Chainedfields
|
||||
{
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* If this accepts one image:
|
||||
* - Tells YooTheme to use the default type for the dropdown mapping option.
|
||||
*
|
||||
* If this accepts multiple images:
|
||||
* - Tells YooTheme to only return the value of this field in the dropdown mapping option.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'value',
|
||||
'metadata' => [
|
||||
'label' => 'Choices'
|
||||
],
|
||||
]
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : null;
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
if (!$value = $field->rawvalue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return [
|
||||
'value' => implode(', ', $value)
|
||||
];
|
||||
}
|
||||
}
|
||||
139
plugins/system/acf/ACF/Helpers/Fields/Country.php
Normal file
139
plugins/system/acf/ACF/Helpers/Fields/Country.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
|
||||
class Country
|
||||
{
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$multiple_selection = $field->fieldparams->get('multiple_selection', '0') === '1';
|
||||
if (!$multiple_selection)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'code',
|
||||
'metadata' => [
|
||||
'label' => 'Country Code'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'name',
|
||||
'metadata' => [
|
||||
'label' => 'Country Name'
|
||||
],
|
||||
]
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
$multiple_selection = $field->fieldparams->get('multiple_selection', '0') === '1';
|
||||
|
||||
if ($multiple_selection)
|
||||
{
|
||||
if (!is_array($value))
|
||||
{
|
||||
$value = [$value];
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => implode(',', $value),
|
||||
'name' => implode(',', self::getNames($value))
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
// If it's an array, try to grab the first item.
|
||||
if (is_array($value))
|
||||
{
|
||||
$value = array_values($value);
|
||||
$value = isset($value[0]) ? $value[0] : $value;
|
||||
}
|
||||
|
||||
if (!is_string($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$display_mode = $field->fieldparams->get('countrydisplay', 'name');
|
||||
|
||||
if ($display_mode === 'code')
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (!$country = \NRFramework\Countries::getCountry($value))
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $country['name'];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getNames($items = [])
|
||||
{
|
||||
return array_map(function ($value) {
|
||||
$country = \NRFramework\Countries::getCountry($value);
|
||||
return isset($country['name']) ? $country['name'] : $value['code'];
|
||||
}, $items);
|
||||
}
|
||||
}
|
||||
58
plugins/system/acf/ACF/Helpers/Fields/Downloadbutton.php
Normal file
58
plugins/system/acf/ACF/Helpers/Fields/Downloadbutton.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
|
||||
class Downloadbutton
|
||||
{
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$filename = $field->rawvalue;
|
||||
|
||||
if (!is_string($filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$directory = $field->fieldparams->get('directory');
|
||||
|
||||
return implode(DIRECTORY_SEPARATOR, [$directory, $filename]);
|
||||
}
|
||||
}
|
||||
107
plugins/system/acf/ACF/Helpers/Fields/Faq.php
Normal file
107
plugins/system/acf/ACF/Helpers/Fields/Faq.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
|
||||
class Faq
|
||||
{
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'question',
|
||||
'metadata' => [
|
||||
'label' => 'Question'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'answer',
|
||||
'metadata' => [
|
||||
'label' => 'Answer'
|
||||
],
|
||||
],
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
return ['listOf' => $name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
if (is_string($value))
|
||||
{
|
||||
if (!$value = json_decode($value, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($value['value']) || !is_array($value['value']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$value = array_values($value['value']);
|
||||
$value = array_filter($value, function($item) {
|
||||
return !empty($item['question']) && !empty($item['answer']);
|
||||
});
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
388
plugins/system/acf/ACF/Helpers/Fields/Gallery.php
Normal file
388
plugins/system/acf/ACF/Helpers/Fields/Gallery.php
Normal file
@ -0,0 +1,388 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
class Gallery
|
||||
{
|
||||
public static function deleteFilesFromItem($item_id = '')
|
||||
{
|
||||
if (!$item_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self::deleteGalleryFiles($item_id);
|
||||
|
||||
if (version_compare(JVERSION, '4', '>='))
|
||||
{
|
||||
self::deleteGalleryFilesInSubform($item_id);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function deleteGalleryFiles($item_id = '')
|
||||
{
|
||||
if (!$item_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('fv.value')
|
||||
->from('#__fields_values AS fv')
|
||||
->join('LEFT', '#__fields AS f ON fv.field_id = f.id')
|
||||
->where('fv.item_id = ' . $db->quote($item_id))
|
||||
->where('f.type = ' . $db->quote('acfgallery'));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$fieldsValues = $db->loadAssocList();
|
||||
|
||||
if (!$fieldsValues)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($fieldsValues as $value)
|
||||
{
|
||||
$files = json_decode($value['value'], true);
|
||||
|
||||
if (!$files)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($files['items']) || !is_array($files['items']) || !count($files['items']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($files['items'] as $file)
|
||||
{
|
||||
self::deleteGalleryItem('source', $file);
|
||||
self::deleteGalleryItem('image', $file);
|
||||
self::deleteGalleryItem('thumbnail', $file);
|
||||
self::deleteGalleryItem('slideshow', $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function deleteGalleryFilesInSubform($item_id = '')
|
||||
{
|
||||
if (!$item_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Get all ACF File Upload custom field IDs
|
||||
$query = $db->getQuery(true)
|
||||
->select('distinct f.id')
|
||||
->from('#__fields as f')
|
||||
->join('LEFT', '#__fields_values AS fv ON fv.field_id = f.id')
|
||||
->where('fv.item_id = ' . (int) $item_id)
|
||||
->where('f.type = ' . $db->quote('acfgallery'));
|
||||
$db->setQuery($query);
|
||||
$fileupload_ids = array_keys($db->loadAssocList('id'));
|
||||
|
||||
if (!$fileupload_ids)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all Subform custom fields
|
||||
$query->clear()
|
||||
->select('f.id as field_id, fv.item_id as item_id, fv.value as value')
|
||||
->from('#__fields as f')
|
||||
->join('LEFT', '#__fields_values AS fv ON fv.field_id = f.id')
|
||||
->where('fv.item_id = ' . (int) $item_id)
|
||||
->where('f.type = ' . $db->quote('subform'));
|
||||
$db->setQuery($query);
|
||||
$subform_fields = $db->loadAssocList();
|
||||
|
||||
foreach ($subform_fields as $subform_field)
|
||||
{
|
||||
if (!$subform_field_items = json_decode($subform_field['value'], true))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($subform_field_items as $row => &$row_items)
|
||||
{
|
||||
if (!is_array($row_items))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($row_items as $field_name => &$field_value)
|
||||
{
|
||||
// Get the field id
|
||||
$field_id = str_replace('field', '', $field_name);
|
||||
|
||||
// Check if its a gallery field
|
||||
if (!in_array($field_id, $fileupload_ids))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_array($field_value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($field_value['items']) || !is_array($field_value['items']) || !count($field_value['items']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($field_value['items'] as $file)
|
||||
{
|
||||
self::deleteGalleryItem('source', $file);
|
||||
self::deleteGalleryItem('image', $file);
|
||||
self::deleteGalleryItem('thumbnail', $file);
|
||||
self::deleteGalleryItem('slideshow', $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function deleteGalleryItem($key, $item)
|
||||
{
|
||||
if (isset($item[$key]) && !empty($item[$key]))
|
||||
{
|
||||
// Original file path
|
||||
$path = implode(DIRECTORY_SEPARATOR, [JPATH_SITE, $item[$key]]);
|
||||
|
||||
if (!file_exists($path))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* If this accepts one image:
|
||||
* - Tells YooTheme to use the default type for the dropdown mapping option.
|
||||
*
|
||||
* If this accepts multiple images:
|
||||
* - Tells YooTheme to only return the value of this field in the dropdown mapping option.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'thumb',
|
||||
'metadata' => [
|
||||
'label' => 'Thumbnail Image URL'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'value',
|
||||
'metadata' => [
|
||||
'label' => 'Full Image URL'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'source',
|
||||
'metadata' => [
|
||||
'label' => 'Source Image URL'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'caption',
|
||||
'metadata' => [
|
||||
'label' => 'Caption'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'alt',
|
||||
'metadata' => [
|
||||
'label' => 'Alt'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'tags',
|
||||
'metadata' => [
|
||||
'label' => 'Tags'
|
||||
],
|
||||
]
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
$limit_files = (int) $field->fieldparams->get('limit_files', 0);
|
||||
if ($limit_files === 1)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
|
||||
return ['listOf' => $name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? json_encode($item["field{$args['field_id']}"]) : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
if (is_string($value))
|
||||
{
|
||||
if (!$value = json_decode($value, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($value['items']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$tagsHelper = new TagsHelper();
|
||||
|
||||
// Apply ordering
|
||||
$ordering = $field->fieldparams->get('ordering', 'default');
|
||||
self::randomize($value['items'], $ordering);
|
||||
|
||||
$limit_files = (int) $field->fieldparams->get('limit_files', 0);
|
||||
if ($limit_files === 1)
|
||||
{
|
||||
$uploaded_data = array_values($value['items']);
|
||||
|
||||
$tags = isset($uploaded_data[0]['tags']) && is_array($uploaded_data[0]['tags']) ? $tagsHelper->getTagNames($uploaded_data[0]['tags']) : [];
|
||||
|
||||
return [
|
||||
'caption' => isset($uploaded_data[0]['caption']) ? $uploaded_data[0]['caption'] : '',
|
||||
'source' => isset($uploaded_data[0]['source']) ? $uploaded_data[0]['source'] : '',
|
||||
'thumb' => isset($uploaded_data[0]['thumbnail']) ? $uploaded_data[0]['thumbnail'] : '',
|
||||
'alt' => isset($uploaded_data[0]['alt']) ? $uploaded_data[0]['alt'] : '',
|
||||
'value' => isset($uploaded_data[0]['image']) ? $uploaded_data[0]['image'] : '',
|
||||
'tags' => implode(', ', $tags)
|
||||
];
|
||||
}
|
||||
|
||||
$data = array_values(array_map(function($item) use ($tagsHelper) {
|
||||
$tags = isset($item['tags']) && is_array($item['tags']) ? $tagsHelper->getTagNames($item['tags']) : [];
|
||||
|
||||
return [
|
||||
'value' => $item['image'],
|
||||
'thumb' => $item['thumbnail'],
|
||||
'source' => isset($item['source']) ? $item['source'] : '',
|
||||
'alt' => isset($item['alt']) ? $item['alt'] : '',
|
||||
'caption' => $item['caption'],
|
||||
'tags' => implode(', ', $tags)
|
||||
];
|
||||
}, $value['items']));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function randomize(&$data = [], $ordering = 'default')
|
||||
{
|
||||
if (!is_array($data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($ordering)
|
||||
{
|
||||
case 'random':
|
||||
shuffle($data);
|
||||
break;
|
||||
case 'alphabetical':
|
||||
usort($data, [__CLASS__, 'compareByThumbnailASC']);
|
||||
break;
|
||||
case 'reverse_alphabetical':
|
||||
usort($data, [__CLASS__, 'compareByThumbnailDESC']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares thumbnail file names in ASC order
|
||||
*
|
||||
* @param array $a
|
||||
* @param array $b
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function compareByThumbnailASC($a, $b)
|
||||
{
|
||||
return strcmp(basename($a['thumbnail']), basename($b['thumbnail']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares thumbnail file names in DESC order
|
||||
*
|
||||
* @param array $a
|
||||
* @param array $b
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function compareByThumbnailDESC($a, $b)
|
||||
{
|
||||
return strcmp(basename($b['thumbnail']), basename($a['thumbnail']));
|
||||
}
|
||||
}
|
||||
136
plugins/system/acf/ACF/Helpers/Fields/Map.php
Normal file
136
plugins/system/acf/ACF/Helpers/Fields/Map.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
|
||||
class Map
|
||||
{
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'address',
|
||||
'metadata' => [
|
||||
'label' => Text::_('NR_MARKER_ADDRESS')
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'coordinates',
|
||||
'metadata' => [
|
||||
'label' => Text::_('NR_MARKER_COORDINATES')
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'latitude',
|
||||
'metadata' => [
|
||||
'label' => Text::_('NR_MARKER_LATITUDE')
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'longitude',
|
||||
'metadata' => [
|
||||
'label' => Text::_('NR_MARKER_LONGITUDE')
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'label',
|
||||
'metadata' => [
|
||||
'label' => Text::_('NR_MARKER_LABEL')
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'description',
|
||||
'metadata' => [
|
||||
'label' => Text::_('NR_MARKER_DESCRIPTION')
|
||||
],
|
||||
],
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
return ['listOf' => $name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
if (is_string($value))
|
||||
{
|
||||
if (!$value = json_decode($value, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($value as $key => &$v)
|
||||
{
|
||||
if (!isset($v['latitude']) || !isset($v['longitude']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$v['coordinates'] = $v['latitude'] . ',' . $v['longitude'];
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
66
plugins/system/acf/ACF/Helpers/Fields/Osm.php
Normal file
66
plugins/system/acf/ACF/Helpers/Fields/Osm.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
|
||||
class Osm
|
||||
{
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? json_encode($item["field{$args['field_id']}"]) : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
if (!is_string($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$value = json_decode($value, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($value['coordinates']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return $value['coordinates'];
|
||||
}
|
||||
}
|
||||
65
plugins/system/acf/ACF/Helpers/Fields/Php.php
Normal file
65
plugins/system/acf/ACF/Helpers/Fields/Php.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
class Php
|
||||
{
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
if (!$value = $field->rawvalue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get plugin params
|
||||
$plugin = PluginHelper::getPlugin('fields', 'acfphp');
|
||||
$params = new Registry($plugin->params);
|
||||
|
||||
// Enable buffer output
|
||||
$executer = new \NRFramework\Executer($value);
|
||||
|
||||
return $executer
|
||||
->setForbiddenPHPFunctions($params->get('forbidden_php_functions'))
|
||||
->run();
|
||||
}
|
||||
}
|
||||
58
plugins/system/acf/ACF/Helpers/Fields/Soundcloud.php
Normal file
58
plugins/system/acf/ACF/Helpers/Fields/Soundcloud.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
|
||||
class Soundcloud
|
||||
{
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
$value = is_string($value) ? json_decode($value, true) : $value;
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return isset($value['id']) ? $value['id'] : null;
|
||||
}
|
||||
}
|
||||
141
plugins/system/acf/ACF/Helpers/Fields/Telephone.php
Normal file
141
plugins/system/acf/ACF/Helpers/Fields/Telephone.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
|
||||
class Telephone
|
||||
{
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* If this accepts one image:
|
||||
* - Tells YooTheme to use the default type for the dropdown mapping option.
|
||||
*
|
||||
* If this accepts multiple images:
|
||||
* - Tells YooTheme to only return the value of this field in the dropdown mapping option.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'phone_number',
|
||||
'metadata' => [
|
||||
'label' => 'Phone Number'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'calling_code',
|
||||
'metadata' => [
|
||||
'label' => 'Calling Code'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'country_code',
|
||||
'metadata' => [
|
||||
'label' => 'Country Code'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'country_name',
|
||||
'metadata' => [
|
||||
'label' => 'Country Name'
|
||||
],
|
||||
]
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
// var_dump($info->rootValue['parent']->children[0]);
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
if (is_string($value) && json_decode($value, true))
|
||||
{
|
||||
$value = json_decode($value, true);
|
||||
}
|
||||
|
||||
$countryCode = '';
|
||||
$callingCode = '';
|
||||
|
||||
if (is_array($value))
|
||||
{
|
||||
$countryCode = isset($value['code']) ? $value['code'] : '';
|
||||
$phoneNumber = isset($value['value']) ? $value['value'] : '';
|
||||
|
||||
if ($phoneNumber)
|
||||
{
|
||||
$callingCode = \NRFramework\Countries::getCallingCodeByCountryCode($countryCode);
|
||||
$callingCode = $callingCode !== '' ? '+' . $callingCode : '';
|
||||
|
||||
$value = $callingCode . $phoneNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!$value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return [
|
||||
'phone_number' => $value,
|
||||
'calling_code' => $callingCode,
|
||||
'country_code' => $countryCode,
|
||||
'country_name' => ($countryCode ? \NRFramework\Countries::toCountryName($countryCode) : '')
|
||||
];
|
||||
}
|
||||
}
|
||||
300
plugins/system/acf/ACF/Helpers/Fields/Upload.php
Normal file
300
plugins/system/acf/ACF/Helpers/Fields/Upload.php
Normal file
@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
class Upload
|
||||
{
|
||||
|
||||
public static function deleteFilesFromItem($item_id = '')
|
||||
{
|
||||
if (!$item_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self::deleteFileUploadFiles($item_id);
|
||||
|
||||
if (version_compare(JVERSION, '4', '>='))
|
||||
{
|
||||
self::deleteFileUploadFilesInSubform($item_id);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function deleteFileUploadFiles($item_id = '')
|
||||
{
|
||||
if (!$item_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('fv.value')
|
||||
->from('#__fields_values AS fv')
|
||||
->join('LEFT', '#__fields AS f ON fv.field_id = f.id')
|
||||
->where('fv.item_id = ' . $db->quote($item_id))
|
||||
->where('f.type = ' . $db->quote('acfupload'));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$fieldsValues = $db->loadAssocList();
|
||||
|
||||
if (!$fieldsValues)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($fieldsValues as $value)
|
||||
{
|
||||
$files = json_decode($value['value'], true);
|
||||
|
||||
if (!$files)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$filePath = implode(DIRECTORY_SEPARATOR, [JPATH_ROOT, $file['value']]);
|
||||
|
||||
if (!file_exists($filePath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
unlink($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function deleteFileUploadFilesInSubform($item_id = '')
|
||||
{
|
||||
if (!$item_id)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Get all ACF File Upload custom field IDs
|
||||
$query = $db->getQuery(true)
|
||||
->select('distinct f.id')
|
||||
->from('#__fields as f')
|
||||
->join('LEFT', '#__fields_values AS fv ON fv.field_id = f.id')
|
||||
->where('fv.item_id = ' . (int) $item_id)
|
||||
->where('f.type = ' . $db->quote('acfupload'));
|
||||
$db->setQuery($query);
|
||||
$fileupload_ids = array_keys($db->loadAssocList('id'));
|
||||
|
||||
if (!$fileupload_ids)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all Subform custom fields
|
||||
$query->clear()
|
||||
->select('f.id as field_id, fv.item_id as item_id, fv.value as value')
|
||||
->from('#__fields as f')
|
||||
->join('LEFT', '#__fields_values AS fv ON fv.field_id = f.id')
|
||||
->where('fv.item_id = ' . (int) $item_id)
|
||||
->where('f.type = ' . $db->quote('subform'));
|
||||
$db->setQuery($query);
|
||||
$subform_fields = $db->loadAssocList();
|
||||
|
||||
foreach ($subform_fields as $subform_field)
|
||||
{
|
||||
if (!$subform_field_items = json_decode($subform_field['value'], true))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($subform_field_items as $row => &$row_items)
|
||||
{
|
||||
if (!is_array($row_items))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($row_items as $field_name => &$field_value)
|
||||
{
|
||||
// Get the field id
|
||||
$field_id = str_replace('field', '', $field_name);
|
||||
|
||||
// Check if its a gallery field
|
||||
if (!in_array($field_id, $fileupload_ids))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_array($field_value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($field_value as $file)
|
||||
{
|
||||
$filePath = implode(DIRECTORY_SEPARATOR, [JPATH_ROOT, $file['value']]);
|
||||
|
||||
if (!file_exists($filePath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
unlink($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* If this accepts one image:
|
||||
* - Tells YooTheme to use the default type for the dropdown mapping option.
|
||||
*
|
||||
* If this accepts multiple images:
|
||||
* - Tells YooTheme to only return the value of this field in the dropdown mapping option.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$limit_files = (int) $field->fieldparams->get('limit_files', 0);
|
||||
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'value',
|
||||
'metadata' => [
|
||||
'label' => 'File URL'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'title',
|
||||
'metadata' => [
|
||||
'label' => 'Title'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'description',
|
||||
'metadata' => [
|
||||
'label' => 'Description'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'filesize',
|
||||
'metadata' => [
|
||||
'label' => 'File size'
|
||||
],
|
||||
],
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
if ($limit_files === 1)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
|
||||
return ['listOf' => $name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? json_encode($item["field{$args['field_id']}"]) : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
$value = is_string($value) ? json_decode($value, true) ?? $value : $value;
|
||||
|
||||
if (!is_array($value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$value = array_values($value);
|
||||
|
||||
if (is_array($value))
|
||||
{
|
||||
// Fix new lines in description
|
||||
foreach ($value as $key => &$val)
|
||||
{
|
||||
if (isset($val['description']))
|
||||
{
|
||||
$val['description'] = nl2br($val['description']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($value as $key => &$val)
|
||||
{
|
||||
$val['filesize'] = '';
|
||||
|
||||
$path = implode(DIRECTORY_SEPARATOR, [JPATH_ROOT, $val['value']]);
|
||||
if (file_exists($path))
|
||||
{
|
||||
$val['filesize'] = filesize($path);
|
||||
$val['filesize'] = sprintf("%4.2f MB", $val['filesize'] / 1024 / 1024);
|
||||
}
|
||||
|
||||
if (isset($val['value']))
|
||||
{
|
||||
$val['value'] = $val['value'];
|
||||
}
|
||||
}
|
||||
|
||||
$limit_files = (int) $field->fieldparams->get('limit_files', 0);
|
||||
if ($limit_files === 1 && is_array($value) && count($value) === 1)
|
||||
{
|
||||
return $value[0];
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
106
plugins/system/acf/ACF/Helpers/Fields/Url.php
Normal file
106
plugins/system/acf/ACF/Helpers/Fields/Url.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers\Fields;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use YOOtheme\Builder\Joomla\Fields\Type\FieldsType;
|
||||
use YOOtheme\Str;
|
||||
|
||||
class Url
|
||||
{
|
||||
/**
|
||||
* Returns the YooTheme type.
|
||||
*
|
||||
* If this accepts one image:
|
||||
* - Tells YooTheme to use the default type for the dropdown mapping option.
|
||||
*
|
||||
* If this accepts multiple images:
|
||||
* - Tells YooTheme to only return the value of this field in the dropdown mapping option.
|
||||
*
|
||||
* @param object $field
|
||||
* @param object $source
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getYooType($field = [], $source = [])
|
||||
{
|
||||
$fields = [
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'url',
|
||||
'metadata' => [
|
||||
'label' => 'URL'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'text',
|
||||
'metadata' => [
|
||||
'label' => 'Label'
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'String',
|
||||
'name' => 'target',
|
||||
'metadata' => [
|
||||
'label' => 'Target'
|
||||
],
|
||||
]
|
||||
];
|
||||
$name = Str::camelCase(['Field', $field->name], true);
|
||||
$source->objectType($name, compact('fields'));
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field value to an appropriate value that YooTheme can understand.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yooResolve($item, $args, $ctx, $info)
|
||||
{
|
||||
// var_dump($info->rootValue['parent']->children[0]);
|
||||
$name = str_replace('String', '', strtr($info->fieldName, '_', '-'));
|
||||
|
||||
// Check if it's a subform field
|
||||
$subfield = clone \ACF\Helpers\Yoo::getSubfield($args['field_id'], $args['context']);
|
||||
|
||||
// When we have a subform field, the $item is an array of values
|
||||
if (!$subfield || !is_array($item))
|
||||
{
|
||||
if (!isset($item->id) || !($field = FieldsType::getField($name, $item, $args['context'])))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set rawvalue
|
||||
$subfield->rawvalue = isset($item["field{$args['field_id']}"]) ? $item["field{$args['field_id']}"] : '';
|
||||
|
||||
// Use the subform field
|
||||
$field = $subfield;
|
||||
}
|
||||
|
||||
$value = $field->rawvalue;
|
||||
|
||||
if (is_string($value))
|
||||
{
|
||||
if (!$value = json_decode($value, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
0
plugins/system/acf/ACF/Helpers/Fields/index.php
Normal file
0
plugins/system/acf/ACF/Helpers/Fields/index.php
Normal file
48
plugins/system/acf/ACF/Helpers/Previewer.php
Normal file
48
plugins/system/acf/ACF/Helpers/Previewer.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class Previewer
|
||||
{
|
||||
/**
|
||||
* Returns the field previewer data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getFieldPreviewData($field = '')
|
||||
{
|
||||
if (empty($field))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get path to file
|
||||
$file = implode(DIRECTORY_SEPARATOR, [self::getJsonDirectory(), $field . '.json']);
|
||||
|
||||
if (!file_exists($file))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return file_get_contents($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the fields previewer JSON directory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getJsonDirectory()
|
||||
{
|
||||
return implode(DIRECTORY_SEPARATOR, [JPATH_SITE, 'media', 'plg_system_acf', 'data', 'previewer']);
|
||||
}
|
||||
}
|
||||
87
plugins/system/acf/ACF/Helpers/Yoo.php
Normal file
87
plugins/system/acf/ACF/Helpers/Yoo.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace ACF\Helpers;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use NRFramework\Functions;
|
||||
use YOOtheme\Builder\Joomla\Fields\FieldsHelper;
|
||||
use YOOtheme\Application as YooApplication;
|
||||
use YOOtheme\Event;
|
||||
|
||||
class Yoo
|
||||
{
|
||||
public static function initFieldParser()
|
||||
{
|
||||
// Ensure YOOtheme Pro is ready
|
||||
if (!class_exists(YooApplication::class, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Event::on('source.com_fields.field', function($config, $field, $source, $context) {
|
||||
// If it's not an ACF Field, return current config
|
||||
if (substr($field->type, 0, 3) !== 'acf')
|
||||
{
|
||||
return $config;
|
||||
}
|
||||
|
||||
// Get the helper class of the field
|
||||
$helperClass = '\ACF\Helpers\Fields\\' . ucfirst(substr($field->type, 3));
|
||||
|
||||
// If it does not exist, return current config
|
||||
if (!class_exists($helperClass))
|
||||
{
|
||||
return $config;
|
||||
}
|
||||
|
||||
// If the method does not have a resolve method, return current config
|
||||
if (!method_exists($helperClass, 'yooResolve'))
|
||||
{
|
||||
return $config;
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'extensions' => [
|
||||
'call' => [
|
||||
'func' => $helperClass . '::yooResolve',
|
||||
'args' => ['context' => $context, 'field_id' => $field->id]
|
||||
]
|
||||
],
|
||||
] + $config;
|
||||
|
||||
// Get and set the type
|
||||
$type = method_exists($helperClass, 'getYooType') ? $helperClass::getYooType($field, $source) : '';
|
||||
if (!empty($type))
|
||||
{
|
||||
$payload['type'] = $type;
|
||||
}
|
||||
|
||||
return $payload;
|
||||
});
|
||||
}
|
||||
|
||||
public static function getSubfield($id, $context)
|
||||
{
|
||||
static $fields = [];
|
||||
|
||||
if (!isset($fields[$context]))
|
||||
{
|
||||
$fields[$context] = [];
|
||||
|
||||
foreach (FieldsHelper::getFields($context, null, true) as $field)
|
||||
{
|
||||
$fields[$context][$field->id] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
return !empty($fields[$context][$id]) ? $fields[$context][$id] : null;
|
||||
}
|
||||
}
|
||||
0
plugins/system/acf/ACF/Helpers/index.php
Normal file
0
plugins/system/acf/ACF/Helpers/index.php
Normal file
Reference in New Issue
Block a user