first commit
This commit is contained in:
BIN
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/collect-logo.png
vendored
Normal file
BIN
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/collect-logo.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Collect\Contracts\Support;
|
||||
|
||||
interface Arrayable
|
||||
{
|
||||
/**
|
||||
* Get the instance as an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Collect\Contracts\Support;
|
||||
|
||||
interface Jsonable
|
||||
{
|
||||
/**
|
||||
* Convert the object to its JSON representation.
|
||||
*
|
||||
* @param int $options
|
||||
* @return string
|
||||
*/
|
||||
public function toJson($options = 0);
|
||||
}
|
||||
533
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Arr.php
vendored
Normal file
533
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Arr.php
vendored
Normal file
@@ -0,0 +1,533 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Collect\Support;
|
||||
|
||||
use ArrayAccess;
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
class Arr
|
||||
{
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* Determine whether the given value is array accessible.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function accessible($value)
|
||||
{
|
||||
return is_array($value) || $value instanceof ArrayAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an element to an array using "dot" notation if it doesn't exist.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function add($array, $key, $value)
|
||||
{
|
||||
if (is_null(static::get($array, $key))) {
|
||||
static::set($array, $key, $value);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapse an array of arrays into a single array.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function collapse($array)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($array as $values) {
|
||||
if ($values instanceof Collection) {
|
||||
$values = $values->all();
|
||||
} elseif (! is_array($values)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$results = array_merge($results, $values);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide an array into two arrays. One with keys and the other with values.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function divide($array)
|
||||
{
|
||||
return [array_keys($array), array_values($array)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array with dots.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param string $prepend
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function dot($array, $prepend = '')
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value) && ! empty($value)) {
|
||||
$results = array_merge($results, static::dot($value, $prepend.$key.'.'));
|
||||
} else {
|
||||
$results[$prepend.$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the given array except for a specified array of items.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param mixed[]|string $keys
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function except($array, $keys)
|
||||
{
|
||||
static::forget($array, $keys);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given key exists in the provided array.
|
||||
*
|
||||
* @param \ArrayAccess<mixed>|mixed[] $array
|
||||
* @param string|int $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($array, $key)
|
||||
{
|
||||
if ($array instanceof ArrayAccess) {
|
||||
return $array->offsetExists($key);
|
||||
}
|
||||
|
||||
return array_key_exists($key, $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first element in an array passing a given truth test.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param callable|null $callback
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function first($array, callable $callback = null, $default = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
if (empty($array)) {
|
||||
return value($default);
|
||||
}
|
||||
|
||||
foreach ($array as $item) {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (call_user_func($callback, $value, $key)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return value($default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last element in an array passing a given truth test.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param callable|null $callback
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function last($array, callable $callback = null, $default = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
return empty($array) ? value($default) : end($array);
|
||||
}
|
||||
|
||||
return static::first(array_reverse($array, true), $callback, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a multi-dimensional array into a single level.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param int $depth
|
||||
* @return array
|
||||
*/
|
||||
public static function flatten($array, $depth = INF)
|
||||
{
|
||||
return array_reduce($array, function ($result, $item) use ($depth) {
|
||||
$item = $item instanceof Collection ? $item->all() : $item;
|
||||
|
||||
if (! is_array($item)) {
|
||||
return array_merge($result, [$item]);
|
||||
} elseif ($depth === 1) {
|
||||
return array_merge($result, array_values($item));
|
||||
} else {
|
||||
return array_merge($result, static::flatten($item, $depth - 1));
|
||||
}
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove one or many array items from a given array using "dot" notation.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param mixed[]|string $keys
|
||||
* @return void
|
||||
*/
|
||||
public static function forget(&$array, $keys)
|
||||
{
|
||||
$original = &$array;
|
||||
|
||||
$keys = (array) $keys;
|
||||
|
||||
if (count($keys) === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
// if the exact key exists in the top-level, remove it
|
||||
if (static::exists($array, $key)) {
|
||||
unset($array[$key]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$parts = explode('.', $key);
|
||||
|
||||
// clean up before each pass
|
||||
$array = &$original;
|
||||
|
||||
while (count($parts) > 1) {
|
||||
$part = array_shift($parts);
|
||||
|
||||
if (isset($array[$part]) && is_array($array[$part])) {
|
||||
$array = &$array[$part];
|
||||
} else {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
unset($array[array_shift($parts)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from an array using "dot" notation.
|
||||
*
|
||||
* @param \ArrayAccess<mixed>|mixed[] $array
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($array, $key, $default = null)
|
||||
{
|
||||
if (! static::accessible($array)) {
|
||||
return value($default);
|
||||
}
|
||||
|
||||
if (is_null($key)) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
if (static::exists($array, $key)) {
|
||||
return $array[$key];
|
||||
}
|
||||
|
||||
foreach (explode('.', $key) as $segment) {
|
||||
if (static::accessible($array) && static::exists($array, $segment)) {
|
||||
$array = $array[$segment];
|
||||
} else {
|
||||
return value($default);
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an item or items exist in an array using "dot" notation.
|
||||
*
|
||||
* @param \ArrayAccess<mixed>|mixed[] $array
|
||||
* @param string|mixed[] $keys
|
||||
* @return bool
|
||||
*/
|
||||
public static function has($array, $keys)
|
||||
{
|
||||
if (is_null($keys)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$keys = (array) $keys;
|
||||
|
||||
if (! $array) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($keys === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$subKeyArray = $array;
|
||||
|
||||
if (static::exists($array, $key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (explode('.', $key) as $segment) {
|
||||
if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) {
|
||||
$subKeyArray = $subKeyArray[$segment];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an array is associative.
|
||||
*
|
||||
* An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAssoc(array $array)
|
||||
{
|
||||
$keys = array_keys($array);
|
||||
|
||||
return array_keys($keys) !== $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a subset of the items from the given array.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param mixed[]|string $keys
|
||||
* @return array
|
||||
*/
|
||||
public static function only($array, $keys)
|
||||
{
|
||||
return array_intersect_key($array, array_flip((array) $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluck an array of values from an array.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param string|mixed[] $value
|
||||
* @param string|mixed[]|null $key
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function pluck($array, $value, $key = null)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
list($value, $key) = static::explodePluckParameters($value, $key);
|
||||
|
||||
foreach ($array as $item) {
|
||||
$itemValue = data_get($item, $value);
|
||||
|
||||
// If the key is "null", we will just append the value to the array and keep
|
||||
// looping. Otherwise we will key the array using the value of the key we
|
||||
// received from the developer. Then we'll return the final array form.
|
||||
if (is_null($key)) {
|
||||
$results[] = $itemValue;
|
||||
} else {
|
||||
$itemKey = data_get($item, $key);
|
||||
|
||||
$results[$itemKey] = $itemValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explode the "value" and "key" arguments passed to "pluck".
|
||||
*
|
||||
* @param string|mixed[] $value
|
||||
* @param string|mixed[]|null $key
|
||||
* @return mixed[]
|
||||
*/
|
||||
protected static function explodePluckParameters($value, $key)
|
||||
{
|
||||
$value = is_string($value) ? explode('.', $value) : $value;
|
||||
|
||||
$key = is_null($key) || is_array($key) ? $key : explode('.', $key);
|
||||
|
||||
return [$value, $key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an item onto the beginning of an array.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param mixed $value
|
||||
* @param mixed $key
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function prepend($array, $value, $key = null)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
array_unshift($array, $value);
|
||||
} else {
|
||||
$array = [$key => $value] + $array;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value from the array, and remove it.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function pull(&$array, $key, $default = null)
|
||||
{
|
||||
$value = static::get($array, $key, $default);
|
||||
|
||||
static::forget($array, $key);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an array item to a given value using "dot" notation.
|
||||
*
|
||||
* If no key is given to the method, the entire array will be replaced.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function set(&$array, $key, $value)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return $array = $value;
|
||||
}
|
||||
|
||||
$keys = explode('.', $key);
|
||||
|
||||
while (count($keys) > 1) {
|
||||
$key = array_shift($keys);
|
||||
|
||||
// If the key doesn't exist at this depth, we will just create an empty array
|
||||
// to hold the next value, allowing us to create the arrays to hold final
|
||||
// values at the correct depth. Then we'll keep digging into the array.
|
||||
if (! isset($array[$key]) || ! is_array($array[$key])) {
|
||||
$array[$key] = [];
|
||||
}
|
||||
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
$array[array_shift($keys)] = $value;
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the array using the given callback or "dot" notation.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param callable|string $callback
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function sort($array, $callback)
|
||||
{
|
||||
return Collection::make($array)->sortBy($callback)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively sort an array by keys and values.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function sortRecursive($array)
|
||||
{
|
||||
foreach ($array as &$value) {
|
||||
if (is_array($value)) {
|
||||
$value = static::sortRecursive($value);
|
||||
}
|
||||
}
|
||||
|
||||
if (static::isAssoc($array)) {
|
||||
ksort($array);
|
||||
} else {
|
||||
sort($array);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the array using the given callback.
|
||||
*
|
||||
* @param mixed[] $array
|
||||
* @param callable $callback
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function where($array, callable $callback)
|
||||
{
|
||||
return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed ...$arrays
|
||||
*
|
||||
* @return mixed[]|mixed[mixed]
|
||||
*/
|
||||
public static function crossJoin(...$arrays)
|
||||
{
|
||||
$results = [[]];
|
||||
|
||||
foreach ($arrays as $index => $array) {
|
||||
$append = [];
|
||||
|
||||
foreach ($results as $product) {
|
||||
foreach ($array as $item) {
|
||||
$product[$index] = $item;
|
||||
|
||||
$append[] = $product;
|
||||
}
|
||||
}
|
||||
|
||||
$results = $append;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
1507
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Collection.php
vendored
Normal file
1507
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/collect/src/Illuminate/Support/Collection.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Collect\Support\Traits;
|
||||
|
||||
use Closure;
|
||||
use BadMethodCallException;
|
||||
|
||||
trait Macroable
|
||||
{
|
||||
/**
|
||||
* The registered string macros.
|
||||
*
|
||||
* @var callable[]
|
||||
*/
|
||||
protected static $macros = [];
|
||||
|
||||
/**
|
||||
* Register a custom macro.
|
||||
*
|
||||
* @param string $name
|
||||
* @param callable $macro
|
||||
* @return void
|
||||
*/
|
||||
public static function macro($name, callable $macro)
|
||||
{
|
||||
static::$macros[$name] = $macro;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if macro is registered.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasMacro($name)
|
||||
{
|
||||
return isset(static::$macros[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically handle calls to the class.
|
||||
*
|
||||
* @param string $method
|
||||
* @param mixed[] $parameters
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
if (! static::hasMacro($method)) {
|
||||
throw new BadMethodCallException("Method {$method} does not exist.");
|
||||
}
|
||||
|
||||
if (static::$macros[$method] instanceof Closure) {
|
||||
return call_user_func_array(Closure::bind(static::$macros[$method], null, static::class), $parameters);
|
||||
}
|
||||
|
||||
return call_user_func_array(static::$macros[$method], $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically handle calls to the class.
|
||||
*
|
||||
* @param string $method
|
||||
* @param mixed[] $parameters
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (! static::hasMacro($method)) {
|
||||
throw new BadMethodCallException("Method {$method} does not exist.");
|
||||
}
|
||||
|
||||
if (static::$macros[$method] instanceof Closure) {
|
||||
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
|
||||
}
|
||||
|
||||
return call_user_func_array(static::$macros[$method], $parameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
use WPML\Collect\Support\Arr;
|
||||
use WPML\Collect\Support\Collection;
|
||||
|
||||
if (! function_exists('wpml_collect')) {
|
||||
/**
|
||||
* @param mixed|null $value
|
||||
*
|
||||
* @return \WPML\Collect\Support\Collection<mixed>
|
||||
*/
|
||||
function wpml_collect( $value = null ) {
|
||||
return new Collection( $value );
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('value')) {
|
||||
/**
|
||||
* Return the default value of the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function value( $value ) {
|
||||
return $value instanceof Closure ? $value() : $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('data_get')) {
|
||||
/**
|
||||
* Get an item from an array or object using "dot" notation.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @param string|string[] $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
function data_get($target, $key, $default = null)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return $target;
|
||||
}
|
||||
|
||||
$key = is_array($key) ? $key : explode('.', $key);
|
||||
|
||||
while (($segment = array_shift($key)) !== null) {
|
||||
if ($segment === '*') {
|
||||
if ($target instanceof Collection) {
|
||||
$target = $target->all();
|
||||
} elseif (! is_array($target)) {
|
||||
return value($default);
|
||||
}
|
||||
|
||||
$result = Arr::pluck($target, $key);
|
||||
|
||||
return in_array('*', $key) ? Arr::collapse($result) : $result;
|
||||
}
|
||||
|
||||
if (Arr::accessible($target) && Arr::exists($target, $segment)) {
|
||||
$target = $target[$segment];
|
||||
} elseif (is_object($target) && isset($target->{$segment})) {
|
||||
$target = $target->{$segment};
|
||||
} else {
|
||||
return value($default);
|
||||
}
|
||||
}
|
||||
|
||||
return $target;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('with')) {
|
||||
/**
|
||||
* Return the given object. Useful for chaining.
|
||||
*
|
||||
* @param mixed $object
|
||||
* @return mixed
|
||||
*/
|
||||
function with($object)
|
||||
{
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
479
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/README.md
vendored
Normal file
479
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/README.md
vendored
Normal file
@@ -0,0 +1,479 @@
|
||||
# WPML Core API
|
||||
|
||||
## Table of Contents
|
||||
|
||||
* [IfOriginalPost](#iforiginalpost)
|
||||
* [getTranslations](#gettranslations)
|
||||
* [getTranslationIds](#gettranslationids)
|
||||
* [Languages](#languages)
|
||||
* [getActive](#getactive)
|
||||
* [getFlagUrl](#getflagurl)
|
||||
* [withFlags](#withflags)
|
||||
* [getAll](#getall)
|
||||
* [PostTranslations](#posttranslations)
|
||||
* [setAsSource](#setassource)
|
||||
* [setAsTranslationOf](#setastranslationof)
|
||||
* [get](#get)
|
||||
* [getIfOriginal](#getiforiginal)
|
||||
* [Translations](#translations)
|
||||
* [setLanguage](#setlanguage)
|
||||
* [setAsSource](#setassource-1)
|
||||
* [setAsTranslationOf](#setastranslationof-1)
|
||||
* [get](#get-1)
|
||||
* [getIfOriginal](#getiforiginal-1)
|
||||
* [isOriginal](#isoriginal)
|
||||
|
||||
## IfOriginalPost
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
* Full name: \WPML\Element\API\IfOriginalPost
|
||||
|
||||
|
||||
### getTranslations
|
||||
|
||||
Gets the element details for the translations of the given post id.
|
||||
|
||||
```php
|
||||
IfOriginalPost::getTranslations( integer $id = null ): \WPML\Collect\Support\Collection|callable
|
||||
```
|
||||
|
||||
Returns an empty array if the id is not an original post.
|
||||
|
||||
element details structure:
|
||||
```php
|
||||
(object) [
|
||||
'original' => false, // bool True if the element is the original, false if a translation
|
||||
'element_id' => 123, // int The element id
|
||||
'source_language_code' => 'en', // string The source language code
|
||||
'language_code' => 'de', // string The language of the element
|
||||
'trid' => 456, // int The translation id that links translations to source.
|
||||
]
|
||||
```
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$id` | **integer** | The post id. Optional. If missing then returns a callable waiting for the id. |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### getTranslationIds
|
||||
|
||||
Get the element ids for the translations of the given post id.
|
||||
|
||||
```php
|
||||
IfOriginalPost::getTranslationIds( integer $id = null ): \WPML\Collect\Support\Collection|callable
|
||||
```
|
||||
|
||||
Returns an empty array if the id is not an original post.
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$id` | **integer** | The post id. Optional. If missing then returns a callable waiting for the id. |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Languages
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
* Full name: \WPML\Element\API\Languages
|
||||
|
||||
|
||||
### getActive
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Languages::getActive( ): array
|
||||
```
|
||||
|
||||
It returns an array of the active languages.
|
||||
|
||||
The returned array is indexed by language code and every element has the following structure:
|
||||
```
|
||||
'fr' => [
|
||||
'code' => 'fr',
|
||||
'id' => 3,
|
||||
'english_name' => 'French',
|
||||
'native_name' => 'Français',
|
||||
'major' => 1,
|
||||
'default_locale' => 'fr_FR',
|
||||
'encode_url' => 0,
|
||||
'tag' => 'fr ,
|
||||
'display_name' => 'French
|
||||
]
|
||||
```
|
||||
|
||||
* This method is **static**.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### getFlagUrl
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Languages::getFlagUrl( mixed $...$code ): callable|string
|
||||
```
|
||||
|
||||
- Curried :: string → string
|
||||
|
||||
Gets the flag url for the given language code.
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$code` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### withFlags
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Languages::withFlags( mixed $...$langs ): callable|array
|
||||
```
|
||||
|
||||
- Curried :: [code => lang] → [code => lang]
|
||||
|
||||
Adds the language flag url to the array of languages.
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$langs` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### getAll
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Languages::getAll( ): callable|array
|
||||
```
|
||||
|
||||
void → [lang]
|
||||
|
||||
It returns an array of the all the languages.
|
||||
|
||||
The returned array is indexed by language code and every element has the following structure:
|
||||
```
|
||||
'fr' => [
|
||||
'code' => 'fr',
|
||||
'id' => 3,
|
||||
'english_name' => 'French',
|
||||
'native_name' => 'Français',
|
||||
'major' => 1,
|
||||
'default_locale' => 'fr_FR',
|
||||
'encode_url' => 0,
|
||||
'tag' => 'fr ,
|
||||
'display_name' => 'French
|
||||
]
|
||||
```
|
||||
|
||||
* This method is **static**.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## PostTranslations
|
||||
|
||||
Class PostTranslations
|
||||
|
||||
|
||||
|
||||
* Full name: \WPML\Element\API\PostTranslations
|
||||
|
||||
|
||||
### setAsSource
|
||||
|
||||
|
||||
|
||||
```php
|
||||
PostTranslations::setAsSource( mixed $...$el_id, mixed $...$language_code ): callable|integer
|
||||
```
|
||||
|
||||
- Curried :: int → string → void
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
| `$...$language_code` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### setAsTranslationOf
|
||||
|
||||
|
||||
|
||||
```php
|
||||
PostTranslations::setAsTranslationOf( mixed $...$el_id, mixed $...$translated_id, mixed $...$language_code ): callable|integer
|
||||
```
|
||||
|
||||
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
| `$...$translated_id` | **mixed** | |
|
||||
| `$...$language_code` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### get
|
||||
|
||||
|
||||
|
||||
```php
|
||||
PostTranslations::get( mixed $...$el_id ): callable|array
|
||||
```
|
||||
|
||||
- Curried :: int → [object]
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### getIfOriginal
|
||||
|
||||
|
||||
|
||||
```php
|
||||
PostTranslations::getIfOriginal( mixed $...$el_id ): callable|array
|
||||
```
|
||||
|
||||
- Curried :: int → [object]
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Translations
|
||||
|
||||
Class Translations
|
||||
|
||||
|
||||
|
||||
* Full name: \WPML\Element\API\Translations
|
||||
|
||||
|
||||
### setLanguage
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Translations::setLanguage( mixed $...$el_id, mixed $...$el_type, mixed $...$trid, mixed $...$language_code, mixed $...$src_language_code, mixed $...$check_duplicates ): callable|integer
|
||||
```
|
||||
|
||||
- Curried :: int → string → int|null → string → string → string|null → bool → bool|int|null|string
|
||||
|
||||
Wrapper function for SitePress::set_element_language_details
|
||||
|
||||
- int $el_id the element's ID (for terms we use the `term_taxonomy_id`)
|
||||
- string $el_type
|
||||
- int $trid
|
||||
- string $language_code
|
||||
- null|string $src_language_code
|
||||
- bool $check_duplicates
|
||||
|
||||
returns bool|int|null|string
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
| `$...$el_type` | **mixed** | |
|
||||
| `$...$trid` | **mixed** | |
|
||||
| `$...$language_code` | **mixed** | |
|
||||
| `$...$src_language_code` | **mixed** | |
|
||||
| `$...$check_duplicates` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### setAsSource
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Translations::setAsSource( mixed $...$el_id, mixed $...$el_type, mixed $...$language_code ): callable|integer
|
||||
```
|
||||
|
||||
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
| `$...$el_type` | **mixed** | |
|
||||
| `$...$language_code` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### setAsTranslationOf
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Translations::setAsTranslationOf( mixed $...$el_id, mixed $...$el_type, mixed $...$translated_id, mixed $...$language_code ): callable|integer
|
||||
```
|
||||
|
||||
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
| `$...$el_type` | **mixed** | |
|
||||
| `$...$translated_id` | **mixed** | |
|
||||
| `$...$language_code` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### get
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Translations::get( mixed $...$el_id, mixed $...$el_type ): callable|array
|
||||
```
|
||||
|
||||
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
| `$...$el_type` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### getIfOriginal
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Translations::getIfOriginal( mixed $...$el_id, mixed $...$el_type ): callable|array
|
||||
```
|
||||
|
||||
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
| `$...$el_type` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
### isOriginal
|
||||
|
||||
|
||||
|
||||
```php
|
||||
Translations::isOriginal( mixed $...$el_id, mixed $...$translations ): callable|boolean
|
||||
```
|
||||
|
||||
|
||||
|
||||
* This method is **static**.
|
||||
**Parameters:**
|
||||
|
||||
| Parameter | Type | Description |
|
||||
|-----------|------|-------------|
|
||||
| `$...$el_id` | **mixed** | |
|
||||
| `$...$translations` | **mixed** | |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
--------
|
||||
> This document was automatically generated from source code comments on 2020-06-28 using [phpDocumentor](http://www.phpdoc.org/) and [cvuorinen/phpdoc-markdown-public](https://github.com/cvuorinen/phpdoc-markdown-public)
|
||||
138
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Convert/Ids.php
vendored
Normal file
138
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Convert/Ids.php
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Convert;
|
||||
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Lens;
|
||||
use WPML\FP\Lst;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\FP\Str;
|
||||
use WPML\FP\Type;
|
||||
use function WPML\FP\compose;
|
||||
use function WPML\FP\pipe;
|
||||
|
||||
class Ids {
|
||||
|
||||
const ANY_POST = 'any_post';
|
||||
const ANY_TERM = 'any_term';
|
||||
|
||||
/**
|
||||
* @param int|string|array|mixed $ids
|
||||
* @param string|null $elementType
|
||||
* @param bool $fallbackToOriginal
|
||||
* @param string|null $targetLang
|
||||
*
|
||||
* @return callable|mixed|null
|
||||
*/
|
||||
public static function convert( $ids, $elementType = null, $fallbackToOriginal = false, $targetLang = null ) {
|
||||
$isId = function( $id ) {
|
||||
return is_numeric( $id ) && ! is_float( $id );
|
||||
};
|
||||
|
||||
$getElementType = self::selectGetElementType( $elementType );
|
||||
|
||||
/**
|
||||
* @param int|string|mixed $id
|
||||
*
|
||||
* @return int|string|null|mixed
|
||||
*/
|
||||
$convertId = function( $id ) use ( $isId, $getElementType, $fallbackToOriginal, $targetLang ) {
|
||||
/** @var \SitePress $sitepress */
|
||||
global $sitepress;
|
||||
|
||||
if ( ! $isId( $id ) ) {
|
||||
return $id;
|
||||
}
|
||||
|
||||
$convertedId = $sitepress->get_object_id( $id, $getElementType( (int) $id ), $fallbackToOriginal, $targetLang );
|
||||
|
||||
if ( $convertedId ) {
|
||||
return is_string( $id ) ? (string) $convertedId : $convertedId;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
try {
|
||||
return $isId( $ids )
|
||||
? $convertId( $ids )
|
||||
: Obj::over( self::selectLens( $ids ), $convertId, $ids );
|
||||
} catch ( \Exception $e ) {
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* In case of multiple IDs in the same conversion, we'll consider
|
||||
* all the IDs part of the same family, and we'll try to retrieve
|
||||
* the family from the first ID only (for performance reasons).
|
||||
*
|
||||
* @param string|null $elementType
|
||||
*
|
||||
* @return callable int|string -> string
|
||||
*/
|
||||
private static function selectGetElementType( $elementType ) {
|
||||
$memorize = function( $getElementType ) {
|
||||
return Fns::memorizeWith( Fns::always( 'same' ), $getElementType );
|
||||
};
|
||||
|
||||
if ( self::ANY_POST === $elementType ) {
|
||||
return $memorize( 'get_post_type' );
|
||||
} elseif ( self::ANY_TERM === $elementType ) {
|
||||
return $memorize( pipe( 'get_term', Obj::prop( 'taxonomy' ) ) );
|
||||
}
|
||||
|
||||
return Fns::always( $elementType );
|
||||
}
|
||||
|
||||
/**
|
||||
* We'll use lenses when we possibly have multiple IDs
|
||||
* inside the data (passed in different formats).
|
||||
*
|
||||
* @param int|string|array|mixed $ids
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
private static function selectLens( $ids ) {
|
||||
$getLensFilteredMapped = function() {
|
||||
return compose( Lens::iso( 'array_filter', 'array_filter' ), Obj::lensMapped() );
|
||||
};
|
||||
|
||||
if ( is_array( $ids ) ) {
|
||||
return $getLensFilteredMapped();
|
||||
} elseif ( Type::isSerialized( $ids ) ) {
|
||||
return compose( Lens::isoUnserialized(), $getLensFilteredMapped() );
|
||||
} elseif ( Type::isJson( $ids ) ) {
|
||||
return compose( Lens::isoJsonDecoded(), $getLensFilteredMapped() );
|
||||
} elseif ( is_string( $ids ) && $glue = self::guessGlue( $ids ) ) { // phpcs:ignore
|
||||
return compose( Lens::iso( Str::split( $glue ), Lst::join( $glue ) ), $getLensFilteredMapped() );
|
||||
}
|
||||
|
||||
// Noop lens, always set the same as original.
|
||||
return Lens::iso( Fns::always( $ids ), Fns::always( $ids ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the unique separator pattern between IDs or return false otherwise.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public static function guessGlue( $string ) {
|
||||
preg_match_all( '/[^0-9]+/', $string, $matches );
|
||||
$uniqueGlues = array_unique( $matches[0] );
|
||||
|
||||
if ( count( $uniqueGlues ) > 1 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$glue = $uniqueGlues[0];
|
||||
|
||||
if ( $glue === $string ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $glue;
|
||||
}
|
||||
}
|
||||
27
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/DocPage.php
vendored
Normal file
27
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/DocPage.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace WPML;
|
||||
|
||||
class DocPage {
|
||||
|
||||
public static function getTranslateAutomatically() {
|
||||
return 'https://wpml.org/documentation/getting-started-guide/#how-to-translate-pages-posts-and-custom-posts/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore';
|
||||
}
|
||||
|
||||
public static function gettingStartedGuide() {
|
||||
return 'https://wpml.org/documentation/getting-started-guide/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmltm';
|
||||
}
|
||||
|
||||
public static function editorOptions() {
|
||||
return 'https://wpml.org/documentation/translating-your-contents/translation-editor-options/?utm_source=wpmlplugin&utm_campaign=tm-settings&utm_medium=translation-editor-options&utm_term=translation-management';
|
||||
}
|
||||
|
||||
public static function addTranslationServiceForm() {
|
||||
return 'https://wpml.org/documentation/content-translation/#add-service-form';
|
||||
}
|
||||
|
||||
public static function aboutATE() {
|
||||
return 'https://wpml.org/documentation/translating-your-contents/advanced-translation-editor/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmltm';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Element\API\Entity;
|
||||
|
||||
use WPML\FP\Lst;
|
||||
|
||||
class LanguageMapping {
|
||||
/** @var string */
|
||||
private $sourceCode;
|
||||
/** @var string */
|
||||
private $sourceName;
|
||||
/** @var int */
|
||||
private $targetId;
|
||||
/** @var string */
|
||||
private $targetCode;
|
||||
|
||||
/**
|
||||
* @param string $sourceCode
|
||||
* @param string $sourceName
|
||||
* @param int $targetId
|
||||
* @param string $targetCode
|
||||
*/
|
||||
public function __construct( $sourceCode = null, $sourceName = null, $targetId = null, $targetCode = null ) {
|
||||
$this->sourceCode = $sourceCode;
|
||||
$this->sourceName = $sourceName;
|
||||
$this->targetId = (int) $targetId;
|
||||
$this->targetCode = $targetCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toATEFormat () {
|
||||
return [
|
||||
'source_language' => [ 'code' => $this->sourceCode, 'name' => $this->sourceName ],
|
||||
'target_language' => [ 'id' => $this->targetId, 'code' => $this->targetCode ],
|
||||
];
|
||||
}
|
||||
|
||||
public function __get( $name ) {
|
||||
return isset( $this->$name ) ? $this->$name : null;
|
||||
}
|
||||
|
||||
public function __isset( $name ) {
|
||||
return Lst::includes( $name, array_keys( get_object_vars( $this ) ) );
|
||||
}
|
||||
|
||||
public function matches( $languageCode ) {
|
||||
return strtolower( $this->sourceCode ) === strtolower( $languageCode );
|
||||
}
|
||||
}
|
||||
51
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/IfOriginalPost.php
vendored
Normal file
51
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/IfOriginalPost.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Element\API;
|
||||
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Obj;
|
||||
use function WPML\FP\curryN;
|
||||
use function WPML\FP\pipe;
|
||||
|
||||
class IfOriginalPost {
|
||||
|
||||
/**
|
||||
* Gets the element details for the translations of the given post id.
|
||||
* Returns an empty array if the id is not an original post.
|
||||
*
|
||||
* element details structure:
|
||||
* ```php
|
||||
* (object) [
|
||||
* 'original' => false, // bool True if the element is the original, false if a translation
|
||||
* 'element_id' => 123, // int The element id
|
||||
* 'source_language_code' => 'en', // string The source language code
|
||||
* 'language_code' => 'de', // string The language of the element
|
||||
* 'trid' => 456, // int The translation id that links translations to source.
|
||||
* ]
|
||||
* ```
|
||||
*
|
||||
* @param int $id The post id. Optional. If missing then returns a callable waiting for the id.
|
||||
*
|
||||
* @return \WPML\Collect\Support\Collection<mixed>|callable
|
||||
*/
|
||||
public static function getTranslations( $id = null ) {
|
||||
$get = pipe( PostTranslations::getIfOriginal(), Fns::reject( Obj::prop( 'original' ) ), 'wpml_collect' );
|
||||
|
||||
return call_user_func_array( curryN( 1, $get ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element ids for the translations of the given post id.
|
||||
* Returns an empty array if the id is not an original post.
|
||||
*
|
||||
* @param int $id The post id. Optional. If missing then returns a callable waiting for the id.
|
||||
*
|
||||
* @return \WPML\Collect\Support\Collection<mixed>|callable
|
||||
*/
|
||||
public static function getTranslationIds( $id = null ) {
|
||||
$get = pipe( self::getTranslations(), Fns::map( Obj::prop( 'element_id' ) ) );
|
||||
|
||||
return call_user_func_array( curryN( 1, $get ), func_get_args() );
|
||||
}
|
||||
}
|
||||
|
||||
450
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Languages.php
vendored
Normal file
450
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Languages.php
vendored
Normal file
@@ -0,0 +1,450 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Element\API;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Logic;
|
||||
use WPML\FP\Lst;
|
||||
use WPML\FP\Maybe;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\FP\Relation;
|
||||
use WPML\FP\Str;
|
||||
use WPML\FP\Nothing;
|
||||
use WPML\FP\Just;
|
||||
use WPML\LIB\WP\User;
|
||||
use function WPML\FP\curryN;
|
||||
use function WPML\FP\pipe;
|
||||
use WPML\API\Settings;
|
||||
|
||||
/**
|
||||
* @method static callable|string getCodeByName( ...$name ) - Curried :: string->string
|
||||
*
|
||||
* It returns language code according to the given name in the current display language.
|
||||
*
|
||||
* eg. 'Französisch' in German will return 'fr'
|
||||
*
|
||||
* @method static array getActive()
|
||||
*
|
||||
* It returns an array of the active languages.
|
||||
*
|
||||
* The returned array is indexed by language code and every element has the following structure:
|
||||
* ```
|
||||
* 'fr' => [
|
||||
* 'code' => 'fr',
|
||||
* 'id' => 3,
|
||||
* 'english_name' => 'French',
|
||||
* 'native_name' => 'Français',
|
||||
* 'major' => 1,
|
||||
* 'default_locale' => 'fr_FR',
|
||||
* 'encode_url' => 0,
|
||||
* 'tag' => 'fr ,
|
||||
* 'display_name' => 'French
|
||||
* ]
|
||||
* ```
|
||||
* @method static array getSecondaries()
|
||||
*
|
||||
* It returns an array of the secondary languages.
|
||||
*
|
||||
* The returned array is indexed by language code and every element has the following structure:
|
||||
* ```
|
||||
* 'fr' => [
|
||||
* 'code' => 'fr',
|
||||
* 'id' => 3,
|
||||
* 'english_name' => 'French',
|
||||
* 'native_name' => 'Français',
|
||||
* 'major' => 1,
|
||||
* 'default_locale' => 'fr_FR',
|
||||
* 'encode_url' => 0,
|
||||
* 'tag' => 'fr ,
|
||||
* 'display_name' => 'French
|
||||
* ]
|
||||
* ```
|
||||
* @method static array getSecondaryCodes()
|
||||
*
|
||||
* It returns an array of the secondary language codes.
|
||||
*
|
||||
* @method static array|callback getLanguageDetails( ...$code ) - Curried :: string->array
|
||||
*
|
||||
* It returns details of a language.
|
||||
*
|
||||
* An example output:
|
||||
* ```
|
||||
* [
|
||||
* 'code' => 'fr',
|
||||
* 'id' => 3,
|
||||
* 'english_name' => 'French',
|
||||
* 'native_name' => 'Français',
|
||||
* 'major' => 1,
|
||||
* 'default_locale' => 'fr_FR',
|
||||
* 'encode_url' => 0,
|
||||
* 'tag' => 'fr ,
|
||||
* 'display_name' => 'French
|
||||
* ]
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* @method static array getDefault()
|
||||
*
|
||||
* It returns a default language details.
|
||||
*
|
||||
* An example output:
|
||||
*```
|
||||
*[
|
||||
* 'code' => 'fr',
|
||||
* 'id' => 3,
|
||||
* 'english_name' => 'French',
|
||||
* 'native_name' => 'Français',
|
||||
* 'major' => 1,
|
||||
* 'default_locale' => 'fr_FR',
|
||||
* 'encode_url' => 0,
|
||||
* 'tag' => 'fr ,
|
||||
* 'display_name' => 'French
|
||||
* ]
|
||||
*```
|
||||
*
|
||||
* @method static string getDefaultCode()
|
||||
*
|
||||
* It returns a default language code.
|
||||
*
|
||||
* @method static string getCurrentCode()
|
||||
*
|
||||
* It returns a current language code.
|
||||
*
|
||||
* @method static callable|string getFlagUrl( ...$code ) - Curried :: string → string
|
||||
*
|
||||
* Gets the flag url for the given language code.
|
||||
*
|
||||
* @method static callable|string getFlag( ...$code ) - Curried :: string → [string, bool]
|
||||
*
|
||||
* Returns flag url and from_template
|
||||
*
|
||||
* @method static callable|array withFlags( ...$langs ) - Curried :: [code => lang] → [code => lang]
|
||||
*
|
||||
* Adds the language flag url to the array of languages.
|
||||
*
|
||||
* @method static array getAll( $lang = false ) string|false → [lang]
|
||||
*
|
||||
* It returns an array of the all the languages.
|
||||
*
|
||||
* The returned array is indexed by language code and every element has the following structure:
|
||||
* ```
|
||||
* 'fr' => [
|
||||
* 'code' => 'fr',
|
||||
* 'id' => 3,
|
||||
* 'english_name' => 'French',
|
||||
* 'native_name' => 'Français',
|
||||
* 'major' => 1,
|
||||
* 'default_locale' => 'fr_FR',
|
||||
* 'encode_url' => 0,
|
||||
* 'tag' => 'fr ,
|
||||
* 'display_name' => 'French
|
||||
* ]
|
||||
* ```
|
||||
*
|
||||
* @method static callable|int|false setLanguageTranslation( ...$langCode, ...$displayLangCode, ...$name ) - Curried :: string->string->string->int|false
|
||||
*
|
||||
* It sets a language translation.
|
||||
*
|
||||
* @method static callable|int|false setFlag( ...$langCode, ...$flag, ...$fromTemplate ) - Curried :: string->string->bool->int|false
|
||||
*
|
||||
* It sets a language flag.
|
||||
*
|
||||
* @method static callable|string getWPLocale( ...$langDetails ) - Curried :: array->string
|
||||
*
|
||||
* @method static callable|string downloadWPLocale( $locale ) - Curried :: string->string
|
||||
*
|
||||
* It attempts to download a WP language pack for a specific locale, stores the result in settings.
|
||||
*/
|
||||
class Languages {
|
||||
use Macroable;
|
||||
|
||||
const LANGUAGES_MAPPING_OPTION = 'wpml_languages_mapping';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'getCodeByName', curryN( 1, function ( $name ) {
|
||||
global $wpdb;
|
||||
|
||||
$lang_code_query = "
|
||||
SELECT language_code
|
||||
FROM {$wpdb->prefix}icl_languages_translations
|
||||
WHERE name = %s AND display_language_code = %s
|
||||
";
|
||||
|
||||
return $wpdb->get_var( $wpdb->prepare( $lang_code_query, $name, self::getCurrentCode() ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'getActive', function () {
|
||||
global $sitepress;
|
||||
|
||||
return self::withBuiltInInfo( $sitepress->get_active_languages() );
|
||||
} );
|
||||
|
||||
self::macro( 'getLanguageDetails', curryN( 1, function ( $code ) {
|
||||
global $sitepress;
|
||||
|
||||
return self::addBuiltInInfo( $sitepress->get_language_details( $code ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'getDefaultCode', function () {
|
||||
global $sitepress;
|
||||
|
||||
return $sitepress->get_default_language();
|
||||
} );
|
||||
|
||||
self::macro('getCurrentCode', function() {
|
||||
global $sitepress;
|
||||
|
||||
return $sitepress->get_current_language();
|
||||
});
|
||||
|
||||
self::macro( 'getDefault', function() {
|
||||
$defaultCode = self::getDefaultCode();
|
||||
|
||||
return $defaultCode ? self::getLanguageDetails( $defaultCode ) : null;
|
||||
} );
|
||||
|
||||
self::macro(
|
||||
'getSecondaries',
|
||||
pipe( [ self::class, 'getActive' ], Fns::reject( function( $lang ) { return Relation::propEq( 'code', self::getDefaultCode(), $lang ); } ) )
|
||||
);
|
||||
|
||||
self::macro( 'getSecondaryCodes', pipe( [ self::class, 'getSecondaries' ], Lst::pluck( 'code' ) ) );
|
||||
|
||||
self::macro( 'getAll', function ( $userLang = false ) {
|
||||
global $sitepress;
|
||||
|
||||
return self::withBuiltInInfo( $sitepress->get_languages( $userLang ) );
|
||||
} );
|
||||
|
||||
self::macro( 'getFlagUrl', curryN( 1, function ( $code ) {
|
||||
global $sitepress;
|
||||
|
||||
return $sitepress->get_flag_url( $code );
|
||||
} ) );
|
||||
|
||||
self::macro( 'getFlag', curryN( 1, function ( $code ) {
|
||||
global $sitepress;
|
||||
|
||||
return $sitepress->get_flag( $code );
|
||||
} ) );
|
||||
|
||||
self::macro( 'withFlags', curryN( 1, function ( $langs ) {
|
||||
$addFlag = function ( $lang, $code ) {
|
||||
$flag = self::getFlag( $code );
|
||||
|
||||
$lang['flag_url'] = self::getFlagUrl( $code );
|
||||
$lang['flag_from_template'] = Obj::prop( 'from_template', $flag );
|
||||
|
||||
return $lang;
|
||||
};
|
||||
|
||||
return Fns::map( $addFlag, $langs );
|
||||
} ) );
|
||||
|
||||
self::macro( 'setLanguageTranslation', curryN( 3, function ( $langCode, $displayLangCode, $name ) {
|
||||
global $wpdb;
|
||||
|
||||
$sql = "
|
||||
REPLACE INTO {$wpdb->prefix}icl_languages_translations (`language_code`, `display_language_code`, `name`)
|
||||
VALUE (%s, %s, %s)
|
||||
";
|
||||
|
||||
return $wpdb->query( $wpdb->prepare( $sql, $langCode, $displayLangCode, $name ) ) ? $wpdb->insert_id : false;
|
||||
} ) );
|
||||
|
||||
|
||||
self::macro( 'setFlag', curryN( 3, function ( $langCode, $flag, $fromTemplate ) {
|
||||
global $wpdb;
|
||||
|
||||
$sql = "
|
||||
REPLACE INTO {$wpdb->prefix}icl_flags (`lang_code`, `flag`, `from_template`)
|
||||
VALUES (%s, %s, %d)
|
||||
";
|
||||
|
||||
return $wpdb->query( $wpdb->prepare( $sql, $langCode, $flag, $fromTemplate ) ) ? $wpdb->insert_id : false;
|
||||
} ) );
|
||||
|
||||
self::macro( 'getWPLocale', curryN( 1, function ( array $langDetails ) {
|
||||
return Logic::firstSatisfying( Logic::isTruthy(), [
|
||||
pipe( Obj::prop( 'default_locale' ), [ self::class, 'downloadWPLocale'] ),
|
||||
pipe( Obj::prop( 'tag' ), [ self::class, 'downloadWPLocale'] ),
|
||||
pipe( Obj::prop( 'code' ), [ self::class, 'downloadWPLocale'] ),
|
||||
Obj::prop( 'default_locale' ),
|
||||
], $langDetails );
|
||||
} ) );
|
||||
|
||||
self::macro( 'downloadWPLocale', curryN( 1, function ( $locale ) {
|
||||
if ( ! function_exists( 'wp_download_language_pack' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
|
||||
}
|
||||
|
||||
$downloaded_locales = Settings::get( Settings::WPML_DOWNLOADED_LOCALES_KEY, [] );
|
||||
|
||||
if ( ! $downloaded_locales || ! isset( $downloaded_locales[ $locale ] ) ) {
|
||||
|
||||
$downloaded_locale = wp_download_language_pack( $locale );
|
||||
if ( false === $downloaded_locale ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$downloaded_locales[ $locale ] = $downloaded_locale;
|
||||
Settings::setAndSave( Settings::WPML_DOWNLOADED_LOCALES_KEY, $downloaded_locales );
|
||||
}
|
||||
|
||||
return $downloaded_locales[ $locale ];
|
||||
} ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried :: string → bool
|
||||
* Determine if the language is Right to Left
|
||||
*
|
||||
* @param string|null $code
|
||||
*
|
||||
* @return callable|bool
|
||||
*/
|
||||
public static function isRtl( $code = null ) {
|
||||
$isRtl = function ( $code ) {
|
||||
global $sitepress;
|
||||
|
||||
return $sitepress->is_rtl( $code );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 1, $isRtl ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried :: [code => lang] → [code => lang]
|
||||
*
|
||||
* Adds language direction, right to left, to the languages data
|
||||
*
|
||||
* @param string[] $langs
|
||||
*
|
||||
* @return callable|mixed[]
|
||||
*/
|
||||
public static function withRtl( $langs = null ) {
|
||||
$withRtl = function ( $langs ) {
|
||||
$addRtl = function ( $lang, $code ) {
|
||||
$lang['rtl'] = self::isRtl( $code );
|
||||
|
||||
return $lang;
|
||||
};
|
||||
|
||||
return Fns::map( $addRtl, $langs );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 1, $withRtl ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried :: string -> string|false
|
||||
*
|
||||
* Returns the language code given a locale
|
||||
*
|
||||
* @param string|null $locale
|
||||
*
|
||||
* @return callable|string|false
|
||||
*/
|
||||
public static function localeToCode( $locale = null ) {
|
||||
$localeToCode = function ( $locale ) {
|
||||
$allLangs = Obj::values( self::getAll() );
|
||||
|
||||
$guessedCode = Maybe::of( $locale )
|
||||
->map( Str::split( '_' ) )
|
||||
->map( Lst::nth( 0 ) )
|
||||
->filter( Lst::includes( Fns::__, Lst::pluck( 'code', $allLangs ) ) )
|
||||
->getOrElse( false );
|
||||
|
||||
$getByNonEmptyLocales = pipe( Fns::filter( Obj::prop( 'default_locale' ) ), Lst::keyBy( 'default_locale') );
|
||||
|
||||
return Obj::pathOr(
|
||||
$guessedCode,
|
||||
[ $locale, 'code' ],
|
||||
$getByNonEmptyLocales( $allLangs )
|
||||
);
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 1, $localeToCode ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $english_name
|
||||
* @param string $default_locale
|
||||
* @param int $major
|
||||
* @param int $active
|
||||
* @param int $encode_url
|
||||
* @param string $tag
|
||||
* @param string $country
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public static function add( $code, $english_name, $default_locale, $major = 0, $active = 0, $encode_url = 0, $tag = '', $country = null ) {
|
||||
global $wpdb;
|
||||
|
||||
$languages = self::getAll();
|
||||
$existingCodes = Obj::keys( $languages );
|
||||
|
||||
$res = $wpdb->insert(
|
||||
$wpdb->prefix . 'icl_languages', [
|
||||
'code' => $code,
|
||||
'english_name' => $english_name,
|
||||
'default_locale' => $default_locale,
|
||||
'major' => $major,
|
||||
'active' => $active,
|
||||
'encode_url' => $encode_url,
|
||||
'tag' => $tag,
|
||||
'country' => $country,
|
||||
]
|
||||
);
|
||||
|
||||
if ( ! $res ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$languageId = $wpdb->insert_id;
|
||||
$codes = Lst::concat( $existingCodes, [ $code ] );
|
||||
|
||||
Fns::map( self::setLanguageTranslation( $code, Fns::__, $english_name ), $codes );
|
||||
|
||||
Fns::map( Fns::converge(
|
||||
self::setLanguageTranslation( Fns::__, $code, Fns::__ ),
|
||||
[ Obj::prop( 'code' ), Obj::prop( 'english_name' ) ]
|
||||
), $languages );
|
||||
|
||||
return $languageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Just|Nothing
|
||||
*/
|
||||
public static function getUserLanguageCode() {
|
||||
return Maybe::fromNullable( User::getCurrent() )
|
||||
->map( function ( $user ) {
|
||||
return $user->locale ?: null;
|
||||
} )
|
||||
->map( self::localeToCode() );
|
||||
}
|
||||
|
||||
public static function withBuiltInInfo( $languages ) {
|
||||
return Fns::map( [ self::class, 'addBuiltInInfo' ], $languages );
|
||||
}
|
||||
|
||||
public static function addBuiltInInfo( $language ) {
|
||||
if ( $language ) {
|
||||
$builtInLanguageCodes = Obj::values( \icl_get_languages_codes() );
|
||||
$isBuiltIn = pipe( Obj::prop( 'code' ), Lst::includes( Fns::__, $builtInLanguageCodes ) );
|
||||
|
||||
return Obj::addProp( 'built_in', $isBuiltIn, $language );
|
||||
} else {
|
||||
return $language;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Languages::init();
|
||||
125
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/OptionManager.php
vendored
Normal file
125
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/OptionManager.php
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
|
||||
namespace WPML\WP;
|
||||
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
class OptionManager {
|
||||
|
||||
private $group_keys_key = 'WPML_Group_Keys';
|
||||
|
||||
/**
|
||||
* Get a WordPress option that is stored by group.
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get( $group, $key, $default = false ) {
|
||||
$data = get_option( $this->get_key( $group ), array() );
|
||||
|
||||
return isset( $data[ $key ] ) ? $data[ $key ] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a WordPress option that is stored by group
|
||||
* The value is then stored by key in the group.
|
||||
*
|
||||
* eg. set( 'TM-wizard', 'complete', 'true' ) will create or add to the option WPML(TM-wizard)
|
||||
* The dat in the option will then be an array of items stored by key.
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param bool $autoload
|
||||
*/
|
||||
public function set( $group, $key, $value, $autoload = true ) {
|
||||
$group_key = $this->get_key( $group );
|
||||
|
||||
$data = get_option( $group_key, array() );
|
||||
$data[ $key ] = $value;
|
||||
update_option( $group_key, $data, $autoload );
|
||||
|
||||
$this->store_group_key( $group_key );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_key( $group ) {
|
||||
return 'WPML(' . $group . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group_key
|
||||
*/
|
||||
private function store_group_key( $group_key ) {
|
||||
$group_keys = get_option( $this->group_keys_key, array() );
|
||||
$group_keys[] = $group_key;
|
||||
update_option( $this->group_keys_key, array_unique( $group_keys ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the options that need to be deleted on WPML reset.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function reset_options( $options ) {
|
||||
$options[] = $this->group_keys_key;
|
||||
|
||||
return array_merge( $options, get_option( $this->group_keys_key, array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried :: string → string → a → void
|
||||
* @param string|null $group
|
||||
* @param string|null $key
|
||||
* @param mixed|null $value
|
||||
*
|
||||
* @return callable|void
|
||||
*/
|
||||
public static function updateWithoutAutoLoad( $group = null, $key = null, $value = null ) {
|
||||
$update = function ( $group, $key, $value ) {
|
||||
( new OptionManager() )->set( $group, $key, $value, false );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 3, $update ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried :: string → string → a → void
|
||||
* @param string|null $group
|
||||
* @param string|null $key
|
||||
* @param mixed|null $value
|
||||
*
|
||||
* @return callable|void
|
||||
*/
|
||||
public static function update( $group = null, $key = null, $value = null ) {
|
||||
return call_user_func_array( curryN( 3, [ new OptionManager(), 'set' ] ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried :: a → string → string → b
|
||||
* @param mixed|null $default
|
||||
* @param string|null $group
|
||||
* @param string|null $key
|
||||
*
|
||||
* @return callable|mixed
|
||||
*/
|
||||
public static function getOr( $default = null, $group = null, $key = null ) {
|
||||
$get = function ( $default, $group, $key ) {
|
||||
return ( new OptionManager() )->get( $group, $key, $default );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 3, $get ), func_get_args() );
|
||||
}
|
||||
}
|
||||
31
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Post.php
vendored
Normal file
31
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Post.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace WPML\Element\API;
|
||||
|
||||
use WPML\FP\Curryable;
|
||||
|
||||
/**
|
||||
* Class Post
|
||||
* @package WPML\Element\API
|
||||
*
|
||||
* @method static callable|string getLang( ...$postId ): Curried :: int->string
|
||||
*/
|
||||
class Post {
|
||||
|
||||
use Curryable;
|
||||
|
||||
public static function init() {
|
||||
|
||||
self::curryN( 'getLang', 1, function ( $postId ) {
|
||||
/** @var \WPML_Admin_Post_Actions $wpml_post_translations */
|
||||
global $wpml_post_translations;
|
||||
|
||||
return $wpml_post_translations->get_element_lang_code( $postId );
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Post::init();
|
||||
62
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/PostTranslations.php
vendored
Normal file
62
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/PostTranslations.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Element\API;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Lst;
|
||||
use WPML\LIB\WP\Post;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
/**
|
||||
* Class PostTranslations
|
||||
* @package WPML\Element\API
|
||||
* @method static callable|int setAsSource( ...$el_id, ...$language_code ) - Curried :: int → string → void
|
||||
* @method static callable|int setAsTranslationOf( ...$el_id, ...$translated_id, ...$language_code )
|
||||
* @method static callable|array get( ...$el_id ) - Curried :: int → [object]
|
||||
* @method static callable|array|null getInLanguage( ...$el_id, ...$language_code ) - Curried :: int → string → array|null
|
||||
* @method static callable|array|null getInCurrentLanguage( ...$el_id ) - Curried :: int → array|null
|
||||
* @method static callable|array getIfOriginal( ...$el_id ) - Curried :: int → [object]
|
||||
* @method static callable|array getOriginal( ...$element_id ) - Curried :: int → object|null
|
||||
* @method static callable|array getOriginalId( ...$element_id ) - Curried :: int → int
|
||||
*/
|
||||
class PostTranslations {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'setAsSource', curryN( 2, self::withPostType( Translations::setAsSource() ) ) );
|
||||
|
||||
self::macro( 'setAsTranslationOf', curryN( 3, self::withPostType( Translations::setAsTranslationOf() ) ) );
|
||||
|
||||
self::macro( 'get', curryN( 1, self::withPostType( Translations::get() ) ) );
|
||||
|
||||
self::macro( 'getInLanguage', curryN( 2, self::withPostType( Translations::getInLanguage() ) ) );
|
||||
|
||||
self::macro( 'getInCurrentLanguage', curryN( 1, self::withPostType( Translations::getInCurrentLanguage() ) ) );
|
||||
|
||||
self::macro( 'getIfOriginal', curryN( 1, self::withPostType( Translations::getIfOriginal() ) ) );
|
||||
|
||||
self::macro( 'getOriginal', curryN( 1, self::withPostType( Translations::getOriginal() ) ) );
|
||||
|
||||
self::macro( 'getOriginalId', curryN( 1, self::withPostType( Translations::getOriginalId() ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
public static function withPostType( $fn ) {
|
||||
return function () use ( $fn ) {
|
||||
$args = func_get_args();
|
||||
|
||||
return call_user_func_array( $fn, Lst::insert( 1, 'post_' . Post::getType( $args[0] ), $args ) );
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
PostTranslations::init();
|
||||
67
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/PostTypes.php
vendored
Normal file
67
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/PostTypes.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\API;
|
||||
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Lst;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\LIB\WP\PostType;
|
||||
use WPML\Settings\PostType\Automatic;
|
||||
|
||||
class PostTypes {
|
||||
|
||||
/**
|
||||
* @return array eg. [ 'page', 'post' ]
|
||||
*/
|
||||
public static function getTranslatable() {
|
||||
global $sitepress;
|
||||
|
||||
return Obj::keys( $sitepress->get_translatable_documents() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of post types where keys are like: 'post', 'page' and so on
|
||||
*
|
||||
* @return array<string, \WP_Post_Type>
|
||||
*/
|
||||
public static function getTranslatableWithInfo() {
|
||||
global $sitepress;
|
||||
|
||||
$postTypes = $sitepress->get_translatable_documents( true );
|
||||
return \apply_filters( 'wpml_get_translatable_types', $postTypes );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array eg. [ 'page', 'post' ]
|
||||
*/
|
||||
public static function getDisplayAsTranslated() {
|
||||
global $sitepress;
|
||||
|
||||
return Obj::keys( $sitepress->get_display_as_translated_documents() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets post types that are translatable and excludes ones that are display as translated.
|
||||
*
|
||||
* @return array eg. [ 'page', 'post' ]
|
||||
*/
|
||||
public static function getOnlyTranslatable() {
|
||||
return Obj::values( Lst::diff( self::getTranslatable(), self::getDisplayAsTranslated() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets post types that are automatically translatable.
|
||||
*
|
||||
* @return array eg. [ 'page', 'post' ]
|
||||
*/
|
||||
public static function getAutomaticTranslatable() {
|
||||
return Fns::filter( [ Automatic::class, 'isAutomatic' ], self::getOnlyTranslatable() );
|
||||
}
|
||||
|
||||
public static function withNames( $postTypes ) {
|
||||
$getPostTypeName = function ( $postType ) {
|
||||
return PostType::getPluralName( $postType )->getOrElse( $postType );
|
||||
};
|
||||
return Fns::map( $getPostTypeName, $postTypes );
|
||||
}
|
||||
}
|
||||
95
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Records/Translations.php
vendored
Normal file
95
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Records/Translations.php
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Records;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\Collect\Support\Collection;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\FP\Relation;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
/**
|
||||
* Class Translations
|
||||
* @package WPML\Records
|
||||
*
|
||||
* @method static callable|array getByTrid( ...$trid )
|
||||
*
|
||||
* Returns array of records from wp_icl_translations matching given $trid
|
||||
*/
|
||||
class Translations {
|
||||
|
||||
const OLDEST_FIRST = 'ASC';
|
||||
const NEWEST_FIRST = 'DESC';
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'getByTrid', curryN( 1, function ( $trid ) {
|
||||
global $wpdb;
|
||||
|
||||
$sql = "SELECT * FROM {$wpdb->prefix}icl_translations WHERE trid = %d";
|
||||
|
||||
return $wpdb->get_results( $wpdb->prepare( $sql, $trid ) );
|
||||
} ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $order
|
||||
* @param string|null $postType
|
||||
*
|
||||
* @return callable|Collection
|
||||
*/
|
||||
public static function getForPostType( array $order = null, $postType = null ) {
|
||||
$get = function ( array $order, $postType ) {
|
||||
global $wpdb;
|
||||
|
||||
$orderBy = Obj::propOr( self::NEWEST_FIRST, $postType, $order );
|
||||
$sql = "SELECT translations.element_id, translations.language_code, translations.source_language_code, translations.trid, translation_status.status, translation_status.needs_update
|
||||
FROM {$wpdb->prefix}icl_translations translations
|
||||
LEFT JOIN {$wpdb->prefix}icl_translation_status translation_status ON translation_status.translation_id = translations.translation_id
|
||||
WHERE translations.element_type = %s
|
||||
ORDER BY translations.element_id $orderBy
|
||||
";
|
||||
|
||||
return wpml_collect( $wpdb->get_results( $wpdb->prepare( $sql, 'post_' . $postType ) ) );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $get ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $lang
|
||||
* @param Collection|null $translations
|
||||
*
|
||||
* @return callable|Collection
|
||||
*/
|
||||
public static function getSourceInLanguage( $lang = null, Collection $translations = null ) {
|
||||
$getSource = function ( $defaultLang, Collection $translations ) {
|
||||
return self::getSource( $translations )->filter( Relation::propEq( 'language_code', $defaultLang ) )->values();
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $getSource ), func_get_args() );
|
||||
}
|
||||
|
||||
public static function getSource( Collection $translations = null) {
|
||||
$getSource = function ( Collection $translations ) {
|
||||
return $translations->filter( Relation::propEq( 'source_language_code', null ) )->values();
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 1, $getSource ), func_get_args() );
|
||||
}
|
||||
|
||||
public static function getSourceByTrid( $trid = null ) {
|
||||
$getSourceByTrid = function ( $trid ) {
|
||||
return self::getSource( \wpml_collect( self::getByTrid( $trid ) ) )->first();
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 1, $getSourceByTrid ), func_get_args() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Translations::init();
|
||||
25
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Sanitize.php
vendored
Normal file
25
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Sanitize.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\API;
|
||||
|
||||
class Sanitize {
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public static function string( $value, $flags = ENT_QUOTES ) {
|
||||
return is_string( $value ) || is_numeric( $value )
|
||||
? str_replace( '&', '&', htmlspecialchars( strip_tags( $value ), $flags ) ) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $property
|
||||
* @param array $arr
|
||||
*
|
||||
* @return null|false|string
|
||||
*/
|
||||
public static function stringProp( $property, $arr, $flags = ENT_QUOTES ) {
|
||||
return isset( $arr[ $property ] ) ? self::string( $arr[ $property ], $flags ) : null;
|
||||
}
|
||||
}
|
||||
74
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Settings.php
vendored
Normal file
74
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Settings.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\API;
|
||||
|
||||
use WPML\FP\Lst;
|
||||
use WPML\FP\Obj;
|
||||
|
||||
class Settings {
|
||||
|
||||
const WPML_DOWNLOADED_LOCALES_KEY = 'wpml_downloaded_locales';
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param bool|mixed $default
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function get( $key, $default = false ) {
|
||||
return self::getOr( $default, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $default
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function getOr( $default, $key ) {
|
||||
global $sitepress;
|
||||
return $sitepress->get_setting( $key, $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function set( $key, $value ) {
|
||||
global $sitepress;
|
||||
return $sitepress->set_setting( $key, $value, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function setAndSave( $key, $value ) {
|
||||
global $sitepress;
|
||||
return $sitepress->set_setting( $key, $value, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the setting using the sub key and value.
|
||||
* Assumes that the setting found by the main key is an array or object
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $subKey
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function assoc( $key, $subKey, $value ) {
|
||||
return self::setAndSave( $key, Obj::assoc( $subKey, $value, self::getOr([], $key ) ) );
|
||||
}
|
||||
|
||||
public static function pathOr( $default, $path ) {
|
||||
$key = Lst::nth( 0, $path );
|
||||
|
||||
return Obj::pathOr( $default, Lst::drop( 1, $path ), self::getOr( [], $key ) );
|
||||
}
|
||||
}
|
||||
20
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Timer.php
vendored
Normal file
20
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Timer.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace WPML;
|
||||
|
||||
class Timer {
|
||||
|
||||
private $endTime;
|
||||
|
||||
public function start( $timeOut ) {
|
||||
$this->endTime = time() + $timeOut;
|
||||
}
|
||||
|
||||
public function hasTimedOut() {
|
||||
return time() > $this->endTime;
|
||||
}
|
||||
|
||||
public function hasNotTimedOut() {
|
||||
return ! $this->hasTimedOut();
|
||||
}
|
||||
}
|
||||
111
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Translations.php
vendored
Normal file
111
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Translations.php
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Element\API;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Maybe;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\FP\Relation;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
/**
|
||||
* Class Translations
|
||||
* @package WPML\Element\API
|
||||
* @method static callable|int setLanguage( ...$el_id, ...$el_type, ...$trid, ...$language_code, ...$src_language_code, ...$check_duplicates )
|
||||
*
|
||||
* - Curried :: int → string → int|null → string → string → string|null → bool → bool|int|null|string
|
||||
*
|
||||
* Wrapper function for SitePress::set_element_language_details
|
||||
*
|
||||
* - int $el_id the element's ID (for terms we use the `term_taxonomy_id`)
|
||||
* - string $el_type
|
||||
* - int $trid
|
||||
* - string $language_code
|
||||
* - null|string $src_language_code
|
||||
* - bool $check_duplicates
|
||||
*
|
||||
* returns bool|int|null|string
|
||||
*
|
||||
* @method static callable|int setAsSource( ...$el_id, ...$el_type, ...$language_code )
|
||||
* @method static callable|int setAsTranslationOf( ...$el_id, ...$el_type, ...$translated_id, ...$language_code )
|
||||
* @method static callable|array get( ...$el_id, ...$el_type )
|
||||
* @method static callable|array|null getInLanguage( ...$el_id, ...$el_type, ...$language_code )
|
||||
* @method static callable|array|null getInCurrentLanguage( ...$el_id, ...$el_type )
|
||||
* @method static callable|array getIfOriginal( ...$el_id, ...$el_type )
|
||||
* @method static callable|array getOriginal( ...$element_id, ...$element_type )
|
||||
* @method static callable|array getOriginalId( ...$element_id, ...$element_type )
|
||||
* @method static callable|bool isOriginal( ...$el_id, ...$translations )
|
||||
*/
|
||||
class Translations {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'setLanguage', curryN( 6, function (
|
||||
$el_id,
|
||||
$el_type,
|
||||
$trid,
|
||||
$language_code,
|
||||
$src_language_code,
|
||||
$check_duplicate
|
||||
) {
|
||||
global $sitepress;
|
||||
$sitepress->set_element_language_details( $el_id, $el_type, $trid, $language_code, $src_language_code, $check_duplicate );
|
||||
} ) );
|
||||
|
||||
self::macro( 'setAsSource', self::setLanguage( Fns::__, Fns::__, null, Fns::__, null, true ) );
|
||||
|
||||
self::macro( 'setAsTranslationOf', curryN( 4,
|
||||
function ( $el_id, $el_type, $translated_id, $language_code ) {
|
||||
global $sitepress;
|
||||
$trid = $sitepress->get_element_trid( $el_id, $el_type );
|
||||
self::setLanguage( $translated_id, $el_type, $trid, $language_code, null, true );
|
||||
} ) );
|
||||
|
||||
self::macro( 'get', curryN( 2, function ( $el_id, $el_type ) {
|
||||
global $sitepress;
|
||||
$trid = $sitepress->get_element_trid( $el_id, $el_type );
|
||||
|
||||
return $sitepress->get_element_translations( $trid, $el_type, false, false, false, false, true );
|
||||
} ) );
|
||||
|
||||
self::macro( 'getInLanguage', curryN( 3, function( $el_id, $el_type, $language_code ) {
|
||||
return wpml_collect( self::get( $el_id, $el_type ) )
|
||||
->filter( Relation::propEq( 'language_code', $language_code ) )
|
||||
->first();
|
||||
} ) );
|
||||
|
||||
self::macro( 'getInCurrentLanguage', curryN( 2, function( $el_id, $el_type ) {
|
||||
return self::getInLanguage( $el_id, $el_type, Languages::getCurrentCode() );
|
||||
} ) );
|
||||
|
||||
self::macro( 'getIfOriginal', curryN( 2, function ( $el_id, $el_type ) {
|
||||
return Maybe::of( self::get( $el_id, $el_type ) )
|
||||
->filter( self::isOriginal( $el_id ) )
|
||||
->getOrElse( [] );
|
||||
} ) );
|
||||
|
||||
self::macro( 'getOriginal', curryN( 2, function( $element_id, $element_type ) {
|
||||
return wpml_collect( self::get( $element_id, $element_type ) )
|
||||
->first( Obj::prop( 'original' ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'getOriginalId', curryN( 2, function( $element_id, $element_type ) {
|
||||
return (int) Obj::prop( 'element_id', self::getOriginal( $element_id, $element_type ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'isOriginal', curryN( 2, function ( $id, $translations ) {
|
||||
$isElementOriginal = curryN( 3, function ( $id, $state, $element ) {
|
||||
return $state || ( $element->original && (int) $element->element_id === ( int ) $id );
|
||||
} );
|
||||
|
||||
return Fns::reduce( $isElementOriginal( $id ), false, $translations );
|
||||
} ) );
|
||||
}
|
||||
}
|
||||
|
||||
Translations::init();
|
||||
142
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/TranslationsRepository.php
vendored
Normal file
142
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/TranslationsRepository.php
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Element\API;
|
||||
|
||||
use WPML\FP\Cast;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Lst;
|
||||
use WPML\FP\Obj;
|
||||
|
||||
class TranslationsRepository {
|
||||
/**
|
||||
* It contains merged data from 3 tables: icl_translations, icl_translation_status and the latest record from icl_translate_job
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $data = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $tridLanguageIndex = [];
|
||||
|
||||
/** @var array */
|
||||
private static $translationIdIndex = [];
|
||||
|
||||
public static function preloadForPosts( $posts ) {
|
||||
global $wpdb;
|
||||
|
||||
$sql = self::getSqlTemplate();
|
||||
|
||||
$condition = Lst::join(
|
||||
' OR ',
|
||||
Fns::map( function ( $post ) use ( $wpdb ) {
|
||||
return $wpdb->prepare(
|
||||
'(element_id = %d AND element_type = %s)',
|
||||
Obj::prop( 'ID', $post ),
|
||||
'post_' . Obj::prop( 'post_type', $post )
|
||||
);
|
||||
}, $posts ) );
|
||||
|
||||
$sql .= "
|
||||
WHERE translations.trid IN (
|
||||
SELECT trid FROM {$wpdb->prefix}icl_translations WHERE {$condition}
|
||||
)
|
||||
";
|
||||
|
||||
self::appendResult( $sql );
|
||||
}
|
||||
|
||||
public static function reset() {
|
||||
self::$data = [];
|
||||
self::$translationIdIndex = [];
|
||||
self::$tridLanguageIndex = [];
|
||||
}
|
||||
|
||||
public static function getByTridAndLanguage( $trid, $language ) {
|
||||
return isset( self::$tridLanguageIndex[ $trid ][ $language ] ) ? self::$tridLanguageIndex[ $trid ][ $language ] : null;
|
||||
}
|
||||
|
||||
public static function getByTranslationId( $translationId ) {
|
||||
return isset( self::$translationIdIndex[ $translationId ] ) ? self::$translationIdIndex[ $translationId ] : null;
|
||||
}
|
||||
|
||||
private static function getSqlTemplate() {
|
||||
global $wpdb;
|
||||
|
||||
$sql = "
|
||||
SELECT translations.translation_id,
|
||||
translations.element_type,
|
||||
translations.element_id,
|
||||
translations.trid,
|
||||
translations.language_code,
|
||||
translations.source_language_code,
|
||||
(
|
||||
SELECT element_id FROM {$wpdb->prefix}icl_translations as originalTranslation
|
||||
WHERE originalTranslation.trid = translations.trid and originalTranslation.source_language_code IS NULL
|
||||
) as original_doc_id,
|
||||
NULLIF(translations.source_language_code, '') IS NULL AS original,
|
||||
translation_status.rid,
|
||||
translation_status.status,
|
||||
translation_status.translator_id,
|
||||
translation_status.needs_update,
|
||||
translation_status.review_status,
|
||||
translation_status.translation_service,
|
||||
translation_status.batch_id,
|
||||
translation_status.timestamp,
|
||||
translation_status.tp_id,
|
||||
translation_status.ate_comm_retry_count,
|
||||
jobs.max_job_id as job_id,
|
||||
jobs.translated,
|
||||
jobs.editor,
|
||||
jobs.editor_job_id,
|
||||
jobs.automatic,
|
||||
jobs.ate_sync_count
|
||||
FROM {$wpdb->prefix}icl_translations as translations
|
||||
LEFT JOIN {$wpdb->prefix}icl_translation_status translation_status ON translation_status.translation_id = translations.translation_id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
MAX(job_id) as max_job_id,
|
||||
translated,
|
||||
editor,
|
||||
editor_job_id,
|
||||
automatic,
|
||||
ate_sync_count,
|
||||
rid
|
||||
FROM {$wpdb->prefix}icl_translate_job
|
||||
GROUP BY job_id
|
||||
) as jobs ON jobs.rid = translation_status.rid
|
||||
";
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
private static function appendResult( $sql ) {
|
||||
/** @var \wpdb */
|
||||
global $wpdb;
|
||||
|
||||
$results = $wpdb->get_results( $wpdb->prepare( $sql . ' AND 1 = %d', 1 ) ); // this is needed to utilize WPDBMock::prepare mock
|
||||
self::$data = Lst::concat( self::$data, Fns::map( Obj::evolve( [
|
||||
'translation_id' => Cast::toInt(),
|
||||
'element_id' => Cast::toInt(),
|
||||
'trid' => Cast::toInt(),
|
||||
'original_doc_id' => Cast::toInt(),
|
||||
'rid' => Cast::toInt(),
|
||||
'status' => Cast::toInt(),
|
||||
'translator_id' => Cast::toInt(),
|
||||
'batch_id' => Cast::toInt(),
|
||||
'tp_id' => Cast::toInt(),
|
||||
'ate_comm_retry_count' => Cast::toInt(),
|
||||
'job_id' => Cast::toInt(),
|
||||
'translated' => Cast::toBool(),
|
||||
'editor_job_id' => Cast::toInt(),
|
||||
'ate_sync_count' => Cast::toInt(),
|
||||
'automatic' => Cast::toBool(),
|
||||
] ), $results ) );
|
||||
|
||||
foreach ( $results as &$row ) {
|
||||
self::$tridLanguageIndex[ Obj::prop( 'trid', $row ) ][ Obj::prop( 'language_code', $row ) ] = &$row;
|
||||
self::$translationIdIndex[ Obj::prop( 'translation_id', $row ) ] = &$row;
|
||||
}
|
||||
}
|
||||
}
|
||||
150
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/UIPage.php
vendored
Normal file
150
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/UIPage.php
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace WPML;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Logic;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\FP\Relation;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
/**
|
||||
* Class UIPage
|
||||
* @package WPML
|
||||
*
|
||||
* @method static callback|bool isLanguages( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isTranslationManagement( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isTMDashboard( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isTMBasket( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isTMJobs( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isTMTranslators( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isTMATE( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isTroubleshooting( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isTranslationQueue( ...$get ) - Curried :: array → bool
|
||||
* @method static callback|bool isPage( ...$page, ...$get ) - Curried :: string → array → bool
|
||||
* @method static string getLanguages()
|
||||
* @method static string getTroubleshooting()
|
||||
* @method static string getTM()
|
||||
* @method static string getTMDashboard()
|
||||
* @method static string getTMBasket()
|
||||
* @method static string getTMATE()
|
||||
* @method static string getTMTranslators()
|
||||
* @method static string getTMJobs()
|
||||
* @method static string getTranslationQueue()
|
||||
*/
|
||||
class UIPage {
|
||||
|
||||
const TM_PAGE = 'tm/menu/main.php';
|
||||
|
||||
use Macroable;
|
||||
|
||||
public static function init() {
|
||||
self::macro( 'isPage', Relation::propEq( 'page' ) );
|
||||
|
||||
self::macro( 'isLanguages', self::isPage( WPML_PLUGIN_FOLDER . '/menu/languages.php' ) );
|
||||
|
||||
self::macro( 'isTranslationManagement', self::isPage( self::TM_PAGE ) );
|
||||
|
||||
self::macro( 'isTMDashboard', Logic::both(
|
||||
self::isTranslationManagement(),
|
||||
Logic::anyPass( [ Relation::propEq( 'sm', null ), Relation::propEq( 'sm', 'dashboard' ) ] )
|
||||
) );
|
||||
|
||||
self::macro( 'isTMBasket', Logic::both( self::isTranslationManagement(), Relation::propEq( 'sm', 'basket' ) ) );
|
||||
|
||||
self::macro( 'isTMJobs', Logic::both( self::isTranslationManagement(), Relation::propEq( 'sm', 'jobs' ) ) );
|
||||
|
||||
self::macro( 'isTMTranslators', Logic::both( self::isTranslationManagement(), Relation::propEq( 'sm', 'translators' ) ) );
|
||||
|
||||
self::macro( 'isTMATE', Logic::both( self::isTranslationManagement(), Relation::propEq( 'sm', 'ate-ams' ) ) );
|
||||
|
||||
self::macro( 'isTroubleshooting', self::isPage( WPML_PLUGIN_FOLDER . '/menu/troubleshooting.php' ) );
|
||||
|
||||
self::macro( 'isTranslationQueue', self::isPage( 'tm/menu/translations-queue.php' ) );
|
||||
|
||||
self::macro( 'getTM', Fns::always( 'admin.php?page=' . self::TM_PAGE ) );
|
||||
|
||||
self::macro( 'getTMDashboard', Fns::always( self::getTM() . '&sm=dashboard' ) );
|
||||
|
||||
self::macro( 'getTMBasket', Fns::always( self::getTM() . '&sm=basket' ) );
|
||||
|
||||
self::macro( 'getTMATE', Fns::always( self::getTM() . '&sm=ate-ams' ) );
|
||||
|
||||
self::macro( 'getTMTranslators', Fns::always( self::getTM() . '&sm=translators' ) );
|
||||
|
||||
self::macro( 'getTMJobs', Fns::always( self::getTM() . '&sm=jobs' ) );
|
||||
|
||||
self::macro( 'getLanguages', Fns::always( 'admin.php?page=' . WPML_PLUGIN_FOLDER . '/menu/languages.php' ) );
|
||||
|
||||
self::macro( 'getTranslationQueue', Fns::always( 'admin.php?page=tm/menu/translations-queue.php' ) );
|
||||
|
||||
self::macro( 'getTroubleshooting', Fns::always( 'admin.php?page=' . WPML_PLUGIN_FOLDER . '/menu/troubleshooting.php' ) );
|
||||
|
||||
}
|
||||
|
||||
public static function isSettings( array $get = null ) {
|
||||
$isSettings = function ( $get ) {
|
||||
return defined( 'WPML_TM_FOLDER' )
|
||||
? self::isPage( WPML_TM_FOLDER . '/menu/settings', $get )
|
||||
: self::isPage( WPML_PLUGIN_FOLDER . '/menu/translation-options.php', $get );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 1, $isSettings ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $get
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isMainSettingsTab( array $get = null ) {
|
||||
return self::isSettingTab( 'mcsetup', $get );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $get
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isNotificationSettingsTab( array $get = null ) {
|
||||
return self::isSettingTab( 'notifications', $get );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $get
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCustomXMLConfigSettingsTab( array $get = null ) {
|
||||
return self::isSettingTab( 'custom-xml-config', $get );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string|null $tab
|
||||
* @param array|null $get
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSettingTab( $tab = null, array $get = null ) {
|
||||
$fn = function ( $tab, $get ) {
|
||||
if ( self::isSettings( $get ) ) {
|
||||
return Obj::propOr( 'mcsetup', 'sm', $get ) === $tab;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $fn ), func_get_args() );
|
||||
}
|
||||
|
||||
public static function getSettings() {
|
||||
$page = defined( 'WPML_TM_FOLDER' ) ? WPML_TM_FOLDER . '/menu/settings' : WPML_PLUGIN_FOLDER . '/menu/translation-options.php';
|
||||
return 'admin.php?page=' . $page;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UIPage::init();
|
||||
|
||||
44
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Version.php
vendored
Normal file
44
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/Version.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\API;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
/**
|
||||
* Class Version
|
||||
* @package WPML\API
|
||||
*
|
||||
* @method static string firstInstallation()
|
||||
*
|
||||
* It returns the version of WPML which has been used during the first installation.
|
||||
*
|
||||
* @method static callback|bool isHigherThanInstallation( ...$version ) - Curried :: string->bool
|
||||
*
|
||||
* It compares the specified version with the version which has been used during the first installation.
|
||||
*
|
||||
* @method static string current()
|
||||
*
|
||||
* It gets the current WPML version.
|
||||
*/
|
||||
class Version {
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'firstInstallation', [ '\WPML_Installation', 'getStartVersion' ] );
|
||||
|
||||
self::macro( 'isHigherThanInstallation', curryN( 1, function ( $version ) {
|
||||
return version_compare( $version, self::firstInstallation(), '>' );
|
||||
} ) );
|
||||
|
||||
self::macro( 'current', function () {
|
||||
return defined( 'ICL_SITEPRESS_VERSION' ) ? ICL_SITEPRESS_VERSION : false;
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
Version::init();
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_Action_Loader_Factory {
|
||||
/**
|
||||
* @return IWPML_Action|IWPML_Action[]|callable|null
|
||||
*/
|
||||
public function create();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_Action {
|
||||
public function add_hooks();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_AJAX_Action_Loader extends IWPML_Action_Loader_Factory {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_AJAX_Action extends IWPML_Action {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_Backend_Action_Loader extends IWPML_Action_Loader_Factory {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_Backend_Action extends IWPML_Action {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* IWPML_CLI_Action_Loader interface
|
||||
*
|
||||
* @package WPML\Core
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface IWPML_CLI_Action_Loader
|
||||
*
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_CLI_Action_Loader extends IWPML_Action_Loader_Factory {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_CLI_Action extends IWPML_Action {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_Deferred_Action_Loader extends IWPML_Action_Loader_Factory {
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_load_action();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_DIC_Action extends IWPML_Action {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_Frontend_Action_Loader extends IWPML_Action_Loader_Factory {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_Frontend_Action extends IWPML_Action {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_REST_Action_Loader extends IWPML_Action_Loader_Factory {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* @author OnTheGo Systems
|
||||
*/
|
||||
interface IWPML_REST_Action extends IWPML_Action {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Ajax;
|
||||
|
||||
use WPML\Collect\Support\Collection;
|
||||
|
||||
interface IHandler {
|
||||
/**
|
||||
* @param \WPML\Collect\Support\Collection<mixed> $data
|
||||
*
|
||||
* @return \WPML\FP\Either
|
||||
*/
|
||||
public function run( Collection $data );
|
||||
}
|
||||
31
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/media/Option.php
vendored
Normal file
31
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/media/Option.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Media;
|
||||
|
||||
use WPML\FP\Obj;
|
||||
use WPML\LIB\WP\Option as WPOption;
|
||||
|
||||
class Option {
|
||||
const OPTION_KEY = '_wpml_media';
|
||||
|
||||
const SETUP_FINISHED = 'starting_help';
|
||||
|
||||
public static function isSetupFinished() {
|
||||
return self::get( self::SETUP_FINISHED );
|
||||
}
|
||||
|
||||
public static function setSetupFinished( $setupFinished = true ) {
|
||||
self::set( self::SETUP_FINISHED, $setupFinished );
|
||||
}
|
||||
|
||||
private static function get( $name, $default = false ) {
|
||||
return Obj::propOr( $default, $name, WPOption::getOr( self::OPTION_KEY, [] ) );
|
||||
}
|
||||
|
||||
private static function set( $name, $value ) {
|
||||
$data = WPOption::getOr( self::OPTION_KEY, [] );
|
||||
$data[ $name ] = $value;
|
||||
|
||||
WPOption::updateWithoutAutoLoad( self::OPTION_KEY, $data );
|
||||
}
|
||||
}
|
||||
48
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/settings/Automatic.php
vendored
Normal file
48
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/settings/Automatic.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Settings\PostType;
|
||||
|
||||
use WPML\FP\Cast;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\FP\Lst;
|
||||
use WPML\FP\Wrapper;
|
||||
use WPML\Setup\Option;
|
||||
use WPML\WP\OptionManager;
|
||||
|
||||
class Automatic {
|
||||
|
||||
const GROUP = 'post-type';
|
||||
const FROM_CONFIG = 'automatic-config';
|
||||
const OVERRIDE = 'automatic-override';
|
||||
|
||||
public static function saveFromConfig( array $config ) {
|
||||
$getCustomTypes = Obj::pathOr( [], [ 'wpml-config', 'custom-types', 'custom-type' ] );
|
||||
$keyByPostType = Lst::keyBy( 'value' );
|
||||
$getAutomaticSetting = Fns::map( Obj::pathOr( true, [ 'attr', 'automatic' ] ) );
|
||||
|
||||
Wrapper::of( $config )
|
||||
->map( $getCustomTypes )
|
||||
->map( $keyByPostType )
|
||||
->map( $getAutomaticSetting )
|
||||
->map( Fns::map( Cast::toBool() ) )
|
||||
->map( OptionManager::update( self::GROUP, self::FROM_CONFIG ) );
|
||||
}
|
||||
|
||||
public static function isAutomatic( $postType ) {
|
||||
$fromConfig = Obj::propOr( true, $postType, OptionManager::getOr( [], self::GROUP, self::FROM_CONFIG ) );
|
||||
$current = OptionManager::getOr( [], self::GROUP, self::OVERRIDE );
|
||||
|
||||
return Obj::propOr( $fromConfig, $postType, $current );
|
||||
}
|
||||
|
||||
public static function set( $postType, $state ) {
|
||||
$current = OptionManager::getOr( [], self::GROUP, self::OVERRIDE );
|
||||
$current[ $postType ] = $state;
|
||||
OptionManager::update( self::GROUP, self::OVERRIDE, $current );
|
||||
}
|
||||
|
||||
public static function shouldTranslate( $postType ) {
|
||||
return Option::shouldTranslateEverything() && self::isAutomatic( $postType );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Settings;
|
||||
|
||||
class LanguageNegotiation {
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function isDomain() {
|
||||
return constant( 'WPML_LANGUAGE_NEGOTIATION_TYPE_DOMAIN' ) === self::getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function isDir() {
|
||||
return constant( 'WPML_LANGUAGE_NEGOTIATION_TYPE_DIRECTORY' ) === self::getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function isParam() {
|
||||
return constant( 'WPML_LANGUAGE_NEGOTIATION_TYPE_PARAMETER' ) === self::getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
private static function getType() {
|
||||
global $sitepress;
|
||||
|
||||
return (int) $sitepress->get_setting( 'language_negotiation_type' );
|
||||
}
|
||||
}
|
||||
184
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/setup/Option.php
vendored
Normal file
184
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/setup/Option.php
vendored
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Setup;
|
||||
|
||||
use WPML\Element\API\Entity\LanguageMapping;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Lst;
|
||||
use WPML\FP\Relation;
|
||||
use WPML\LIB\WP\PostType;
|
||||
use WPML\WP\OptionManager;
|
||||
|
||||
class Option {
|
||||
const POSTS_LIMIT_FOR_AUTOMATIC_TRANSLATION = 10;
|
||||
|
||||
const OPTION_GROUP = 'setup';
|
||||
const CURRENT_STEP = 'current-step';
|
||||
|
||||
const ORIGINAL_LANG = 'original-lang';
|
||||
const TRANSLATED_LANGS = 'translated-langs';
|
||||
const LANGUAGES_MAPPING = 'languages-mapping';
|
||||
|
||||
const WHO_MODE = 'who-mode';
|
||||
const TRANSLATE_EVERYTHING = 'translate-everything';
|
||||
const TRANSLATE_EVERYTHING_COMPLETED = 'translate-everything-completed';
|
||||
const TM_ALLOWED = 'is-tm-allowed';
|
||||
const REVIEW_MODE = 'review-mode';
|
||||
|
||||
const NO_REVIEW = 'no-review';
|
||||
const PUBLISH_AND_REVIEW = 'publish-and-review';
|
||||
const HOLD_FOR_REVIEW = 'before-publish';
|
||||
|
||||
|
||||
public static function getCurrentStep() {
|
||||
return self::get( self::CURRENT_STEP, 'languages' );
|
||||
}
|
||||
|
||||
public static function saveCurrentStep( $step ) {
|
||||
self::set( self::CURRENT_STEP, $step );
|
||||
}
|
||||
|
||||
public static function getOriginalLang() {
|
||||
return self::get( self::ORIGINAL_LANG );
|
||||
}
|
||||
|
||||
public static function setOriginalLang( $lang ) {
|
||||
self::set( self::ORIGINAL_LANG, $lang );
|
||||
}
|
||||
|
||||
public static function getTranslationLangs() {
|
||||
return self::get( self::TRANSLATED_LANGS, [] );
|
||||
}
|
||||
|
||||
public static function setTranslationLangs( array $langs ) {
|
||||
self::set( self::TRANSLATED_LANGS, $langs );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets service as default translation mode if there's a default Translation Service linked to this instance.
|
||||
*
|
||||
* @param bool $hasPreferredTranslationService
|
||||
*/
|
||||
public static function setDefaultTranslationMode( $hasPreferredTranslationService = false ) {
|
||||
if ( self::get( self::WHO_MODE, null ) === null ) {
|
||||
|
||||
$defaultTranslationMode = $hasPreferredTranslationService ? 'service' : 'myself';
|
||||
self::setTranslationMode( [ $defaultTranslationMode ] );
|
||||
}
|
||||
}
|
||||
|
||||
public static function setOnlyMyselfAsDefault() {
|
||||
if ( self::get( self::WHO_MODE, null ) === null ) {
|
||||
self::setTranslationMode( [ 'myself' ] );
|
||||
}
|
||||
}
|
||||
|
||||
public static function setTranslationMode( array $mode ) {
|
||||
self::set( self::WHO_MODE, $mode );
|
||||
}
|
||||
|
||||
public static function getTranslationMode() {
|
||||
return self::get( self::WHO_MODE, [] );
|
||||
}
|
||||
|
||||
public static function setTranslateEverythingDefault() {
|
||||
if ( self::get( self::TRANSLATE_EVERYTHING, null ) === null ) {
|
||||
self::setTranslateEverything( self::getTranslateEverythingDefaultInSetup() );
|
||||
}
|
||||
}
|
||||
|
||||
public static function shouldTranslateEverything( $default = false ) {
|
||||
return self::get( self::TRANSLATE_EVERYTHING, $default );
|
||||
}
|
||||
|
||||
/** @param bool $state */
|
||||
public static function setTranslateEverything( $state ) {
|
||||
self::set( self::TRANSLATE_EVERYTHING, $state );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function getTranslateEverything() {
|
||||
return self::get( self::TRANSLATE_EVERYTHING, false );
|
||||
}
|
||||
|
||||
public static function setTranslateEverythingCompleted( $completed ) {
|
||||
self::set( self::TRANSLATE_EVERYTHING_COMPLETED, $completed );
|
||||
}
|
||||
|
||||
public static function markPostTypeAsCompleted( $postType, $languages ) {
|
||||
$completed = self::getTranslateEverythingCompleted();
|
||||
$completed[ $postType ] = $languages;
|
||||
|
||||
self::setTranslateEverythingCompleted( $completed );
|
||||
}
|
||||
|
||||
public static function removeLanguageFromCompleted( $language ) {
|
||||
$removeLanguage = Fns::map( Fns::reject( Relation::equals( $language ) ) );
|
||||
|
||||
self::setTranslateEverythingCompleted( $removeLanguage( self::getTranslateEverythingCompleted() ) );
|
||||
}
|
||||
|
||||
public static function getTranslateEverythingCompleted() {
|
||||
return self::get( self::TRANSLATE_EVERYTHING_COMPLETED, [] );
|
||||
}
|
||||
|
||||
public static function isTMAllowed() {
|
||||
return self::get( self::TM_ALLOWED );
|
||||
}
|
||||
|
||||
public static function setTMAllowed( $isTMAllowed ) {
|
||||
self::set( self::TM_ALLOWED, $isTMAllowed );
|
||||
}
|
||||
|
||||
public static function setReviewMode( $mode ) {
|
||||
$allowedOptions = [ self::PUBLISH_AND_REVIEW, self::NO_REVIEW, self::HOLD_FOR_REVIEW ];
|
||||
if ( Lst::includes( $mode, $allowedOptions ) ) {
|
||||
self::set( self::REVIEW_MODE, $mode );
|
||||
}
|
||||
}
|
||||
|
||||
public static function getReviewMode( $default = self::HOLD_FOR_REVIEW ) {
|
||||
return self::get( self::REVIEW_MODE, $default );
|
||||
}
|
||||
|
||||
public static function shouldBeReviewed() {
|
||||
return self::shouldTranslateEverything() && self::getReviewMode() !== self::NO_REVIEW;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LanguageMapping[]
|
||||
*/
|
||||
public static function getLanguageMappings() {
|
||||
return self::get( self::LANGUAGES_MAPPING, [] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LanguageMapping $languageMapping
|
||||
*/
|
||||
public static function addLanguageMapping( LanguageMapping $languageMapping) {
|
||||
self::set( self::LANGUAGES_MAPPING, Lst::append( $languageMapping, self::getLanguageMappings() ) );
|
||||
}
|
||||
|
||||
private static function get( $key, $default = null ) {
|
||||
return ( new OptionManager() )->get( self::OPTION_GROUP, $key, $default );
|
||||
}
|
||||
|
||||
private static function set( $key, $value ) {
|
||||
return ( new OptionManager() )->set( self::OPTION_GROUP, $key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $hasPreferredTranslationService
|
||||
* @return bool
|
||||
*/
|
||||
public static function getTranslateEverythingDefaultInSetup( $hasPreferredTranslationService = false ) {
|
||||
if ( $hasPreferredTranslationService ) {
|
||||
return false;
|
||||
}
|
||||
return PostType::getPublishedCount( 'post' ) + PostType::getPublishedCount( 'page' ) > self::POSTS_LIMIT_FOR_AUTOMATIC_TRANSLATION
|
||||
? false
|
||||
: true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Core;
|
||||
|
||||
use WPML\Core\WP\App\Resources;
|
||||
use WPML\FP\Either;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\LIB\WP\Hooks;
|
||||
|
||||
/**
|
||||
* Class BackgroundTask
|
||||
* @package WPML\Core
|
||||
*
|
||||
* class to add background ajax tasks.
|
||||
* Call the `add` function with the class name of the endpoint and any data that the end point requires.
|
||||
* The Ajax endpoint will then be called on document ready with the data provided.
|
||||
*/
|
||||
class BackgroundTask implements \IWPML_Backend_Action {
|
||||
private static $endpoints = [];
|
||||
|
||||
/**
|
||||
* @param string $endpoint - Class name of the handler usually implementing the IHandler interface
|
||||
* @param null|array $data
|
||||
*/
|
||||
public static function add( $endpoint, $data = null ) {
|
||||
self::$endpoints[ $endpoint ] = $data;
|
||||
}
|
||||
|
||||
public function add_hooks() {
|
||||
Hooks::onAction( 'wp_loaded' )
|
||||
->then( [ self::class, 'getEndpoints' ] )
|
||||
->then( [ self::class, 'localize' ] )
|
||||
->then( Resources::enqueueApp( 'backgroundTask' ) );
|
||||
}
|
||||
|
||||
public static function getEndPoints() {
|
||||
return count( self::$endpoints )
|
||||
? Either::right( self::$endpoints )
|
||||
: Either::left( null );
|
||||
}
|
||||
|
||||
public static function localize( $endpoints ) {
|
||||
return [
|
||||
'name' => 'wpml_background_task',
|
||||
'data' => [
|
||||
'endpoints' => Obj::keys( $endpoints ),
|
||||
'endpointsData' => self::$endpoints,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
9
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/utility/ILock.php
vendored
Normal file
9
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/utility/ILock.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Utilities;
|
||||
|
||||
interface ILock {
|
||||
|
||||
public function create( $release_timeout = null );
|
||||
public function release();
|
||||
}
|
||||
82
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/utility/Lock.php
vendored
Normal file
82
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/utility/Lock.php
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Utilities;
|
||||
|
||||
use function WPML\Container\make;
|
||||
|
||||
class Lock implements ILock {
|
||||
|
||||
/** @var \wpdb */
|
||||
private $wpdb;
|
||||
|
||||
/** @var string */
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Lock constructor.
|
||||
*
|
||||
* @param \wpdb $wpdb
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct( \wpdb $wpdb, $name ) {
|
||||
$this->wpdb = $wpdb;
|
||||
$this->name = 'wpml.' . $name . '.lock';
|
||||
}
|
||||
|
||||
public static function whileLocked( $lockName, $releaseTimeout, callable $fn ) {
|
||||
$lock = make( Lock::class, [ ':name' => $lockName ] );
|
||||
if ( $lock->create( $releaseTimeout ) ) {
|
||||
$fn();
|
||||
$lock->release();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a lock using WordPress options ( Based on WP class WP_Upgrader ).
|
||||
*
|
||||
* @param int $release_timeout Optional. The duration in seconds to respect an existing lock.
|
||||
* Default: 1 hour.
|
||||
* @return bool False if a lock couldn't be created or if the lock is still valid. True otherwise.
|
||||
*/
|
||||
public function create( $release_timeout = null ) {
|
||||
if ( ! $release_timeout ) {
|
||||
$release_timeout = HOUR_IN_SECONDS;
|
||||
}
|
||||
|
||||
// Try to lock.
|
||||
$lock_result = $this->wpdb->query( $this->wpdb->prepare( "INSERT IGNORE INTO {$this->wpdb->options} ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $this->name, time() ) );
|
||||
|
||||
if ( ! $lock_result ) {
|
||||
$lock_result = get_option( $this->name );
|
||||
|
||||
// If a lock couldn't be created, and there isn't a lock, bail.
|
||||
if ( ! $lock_result ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check to see if the lock is still valid. If it is, bail.
|
||||
if ( $lock_result > ( time() - $release_timeout ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// There must exist an expired lock, clear it and re-gain it.
|
||||
$this->release();
|
||||
|
||||
return $this->create( $release_timeout );
|
||||
}
|
||||
|
||||
// Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
|
||||
update_option( $this->name, time() );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases an upgrader lock.
|
||||
*
|
||||
* @return bool True if the lock was successfully released. False on failure.
|
||||
*/
|
||||
public function release() {
|
||||
return delete_option( $this->name );
|
||||
}
|
||||
}
|
||||
100
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/utility/Logger.php
vendored
Normal file
100
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/core-api/core/utility/Logger.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace WPML\Utilities;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Psr\Log\InvalidArgumentException;
|
||||
|
||||
class Logger implements LoggerInterface
|
||||
{
|
||||
|
||||
/** @inheritDoc */
|
||||
public function emergency($message, array $context = [])
|
||||
{
|
||||
$this->log(LogLevel::EMERGENCY, $message, $context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function alert($message, array $context = [])
|
||||
{
|
||||
$this->log(LogLevel::ALERT, $message, $context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function critical($message, array $context = [])
|
||||
{
|
||||
$this->log(LogLevel::CRITICAL, $message, $context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function error($message, array $context = [])
|
||||
{
|
||||
$this->log(LogLevel::ERROR, $message, $context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function warning($message, array $context = [])
|
||||
{
|
||||
$this->log(LogLevel::WARNING, $message, $context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function notice($message, array $context = [])
|
||||
{
|
||||
$this->log(LogLevel::NOTICE, $message, $context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function info($message, array $context = [])
|
||||
{
|
||||
$this->log(LogLevel::INFO, $message, $context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function debug($message, array $context = [])
|
||||
{
|
||||
$this->log(LogLevel::DEBUG, $message, $context);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function log($level, $message, array $context = [])
|
||||
{
|
||||
$levels = [
|
||||
LogLevel::EMERGENCY => true,
|
||||
LogLevel::ALERT => true,
|
||||
LogLevel::CRITICAL => true,
|
||||
LogLevel::ERROR => true,
|
||||
LogLevel::WARNING => true,
|
||||
LogLevel::NOTICE => true,
|
||||
LogLevel::INFO => true,
|
||||
LogLevel::DEBUG => true,
|
||||
];
|
||||
|
||||
if (!isset($levels[$level])) {
|
||||
throw new InvalidArgumentException('Invalid log level.');
|
||||
}
|
||||
|
||||
error_log( $level.' '.$this->interpolate($message, $context)."\n" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Interpolates context values into the message placeholders.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function interpolate($message, array $context = [])
|
||||
{
|
||||
$replace = array();
|
||||
foreach ($context as $key => $val) {
|
||||
if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
|
||||
$replace['{'.$key.'}'] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// interpolate replacement values into the message and return
|
||||
return strtr((string)$message, $replace);
|
||||
}
|
||||
}
|
||||
7
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/README.md
vendored
Normal file
7
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/README.md
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# WPML Functional Programming Library
|
||||
|
||||
Many functional programming resources can be difficult for beginners to understand. Functional programming isn’t exactly a friendly paradigm for new programmers, and maintenance can be difficult during the coding phase. The switch to functional programming requires time, practice, and a change in the approach to writing code and solving problems.
|
||||
Although we reviewed many libraries, several of which were excellent, we weren’t able to find what we needed to write expressive code in a functional style - so we decided to create our own.
|
||||
Take a look at the Functional Programming Library built by our developers to see a collection of functions we’ve used in WPML projects.
|
||||
|
||||
## [Documentation](https://git.onthegosystems.com/wpml-packages/fp/-/blob/develop/docs/README.md)
|
||||
24
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Cast.php
vendored
Normal file
24
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Cast.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable|bool toBool( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|int toInt( mixed ...$v ) - Curried :: mixed->int
|
||||
* @method static callable|string toStr( mixed ...$v ) - Curried :: mixed->string
|
||||
* @method static callable|array toArr( mixed ...$v ) - Curried :: mixed->array
|
||||
*/
|
||||
class Cast {
|
||||
use Macroable;
|
||||
|
||||
public static function init() {
|
||||
self::macro( 'toBool', curryN( 1, function ( $v ) { return (bool) $v; } ) );
|
||||
self::macro( 'toInt', curryN( 1, function ( $v ) { return intval( $v ); } ) );
|
||||
self::macro( 'toStr', curryN( 1, function ( $v ) { return (string) $v; } ) );
|
||||
self::macro( 'toArr', curryN( 1, function ( $v ) { return (array) $v; } ) );
|
||||
}
|
||||
}
|
||||
|
||||
Cast::init();
|
||||
54
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Debug.php
vendored
Normal file
54
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Debug.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable|mixed inspect( mixed ...$input )
|
||||
* @method static callable|mixed log( string ...$label )
|
||||
* @method static callable|mixed logDump( string ...$label, mixed ...$input )
|
||||
* @method static callable|mixed logPrintR( string ...$label, mixed ...$input )
|
||||
* @method static callable|mixed logBacktrace( string ...$label, mixed ...$input )
|
||||
*/
|
||||
class Debug {
|
||||
|
||||
use Macroable;
|
||||
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'inspect', curryN( 1, function( $input ) {
|
||||
$allParameters = func_get_args();
|
||||
function_exists( 'xdebug_break' ) && xdebug_break();
|
||||
return $input;
|
||||
} ) );
|
||||
|
||||
self::macro( 'log', curryN( 2, function( $string, $input ) {
|
||||
error_log( $string );
|
||||
return $input;
|
||||
} ) );
|
||||
|
||||
self::macro( 'logDump', curryN( 2, function( $label, $input ) {
|
||||
ob_start();
|
||||
var_dump( $input );
|
||||
$dumpInput = ob_get_clean();
|
||||
error_log( $label . ': ' . $dumpInput );
|
||||
return $input;
|
||||
} ) );
|
||||
|
||||
self::macro( 'logPrintR', curryN( 2, function( $label, $input ) {
|
||||
error_log( $label . ': ' . print_r( $input, true ) );
|
||||
return $input;
|
||||
} ) );
|
||||
|
||||
self::macro( 'logBacktrace', curryN( 2, function( $label, $input ) {
|
||||
ob_start();
|
||||
debug_print_backtrace();
|
||||
$backtrace = ob_get_clean();
|
||||
error_log( $label . ': ' . PHP_EOL . $backtrace );
|
||||
return $input;
|
||||
} ) );
|
||||
}
|
||||
}
|
||||
|
||||
Debug::init();
|
||||
295
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Either.php
vendored
Normal file
295
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Either.php
vendored
Normal file
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Functor\Functor;
|
||||
use WPML\FP\Functor\Pointed;
|
||||
|
||||
/**
|
||||
* Class Either
|
||||
* @package WPML\FP
|
||||
*
|
||||
* @method static callable|Right of( ...$value ) - Curried :: a → Right a
|
||||
*
|
||||
* @method static callable|Left left( ...$value ) - Curried :: a → Left a
|
||||
*
|
||||
* @method static callable|Right right( ...$value ) - Curried :: a → Right a
|
||||
*
|
||||
* @method static callable|Left|Right fromNullable( ...$value ) - Curried :: a → Either a
|
||||
*
|
||||
* @method static callable|Left|Right fromBool( ...$value ) - Curried :: a → Either a
|
||||
*
|
||||
* @method static Either tryCatch( ...$fn ) - Curried :: a → Either a
|
||||
*
|
||||
* @method static mixed getOrElse( ...$other )
|
||||
*/
|
||||
abstract class Either {
|
||||
use Functor;
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'of', Right::of() );
|
||||
|
||||
self::macro( 'left', Left::of() );
|
||||
|
||||
self::macro( 'right', Right::of() );
|
||||
|
||||
self::macro( 'fromNullable', curryN( 1, function ( $value ) {
|
||||
return is_null( $value ) ? self::left( $value ) : self::right( $value );
|
||||
} ) );
|
||||
|
||||
self::macro( 'fromBool', curryN( 1, function ( $value ) {
|
||||
return (bool) $value ? self::right( $value ) : self::left( $value );
|
||||
} ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Either
|
||||
*/
|
||||
public function join() {
|
||||
if ( ! $this->value instanceof Either ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this->value->join();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function chain( callable $fn );
|
||||
|
||||
/**
|
||||
* @param callable $leftFn
|
||||
* @param callable $rightFn
|
||||
*
|
||||
* @return Either|Left|Right
|
||||
*/
|
||||
abstract public function bichain( callable $leftFn, callable $rightFn);
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function orElse( callable $fn );
|
||||
abstract public function bimap( callable $leftFn, callable $rightFn );
|
||||
abstract public function coalesce( callable $leftFn, callable $rightFn );
|
||||
abstract public function alt( Either $alt );
|
||||
abstract public function filter( callable $fn );
|
||||
|
||||
}
|
||||
|
||||
class Left extends Either {
|
||||
|
||||
use ConstApplicative;
|
||||
use Pointed;
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function map( callable $fn ) {
|
||||
return $this; // noop
|
||||
}
|
||||
|
||||
public function bimap( callable $leftFn, callable $rightFn ) {
|
||||
return Either::left( $leftFn( $this->value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $leftFn
|
||||
* @param callable $rightFn
|
||||
*
|
||||
* @return Right
|
||||
*/
|
||||
public function coalesce( callable $leftFn, callable $rightFn ) {
|
||||
return Either::of( $leftFn( $this->value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get() {
|
||||
throw new \Exception( "Can't extract the value of Left" );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $other
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrElse( $other ) {
|
||||
return $other;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Right
|
||||
*/
|
||||
public function orElse( callable $fn ) {
|
||||
return Either::right( $fn( $this->value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function chain( callable $fn ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $leftFn
|
||||
* @param callable $rightFn
|
||||
*
|
||||
* @return Either|Left|Right
|
||||
*/
|
||||
public function bichain( callable $leftFn, callable $rightFn ) {
|
||||
return $leftFn( $this->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getOrElseThrow( $value ) {
|
||||
throw new \Exception( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function filter( callable $fn ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function tryCatch( callable $fn ) {
|
||||
return $this; // noop
|
||||
}
|
||||
|
||||
public function alt( Either $alt ) {
|
||||
return $alt;
|
||||
}
|
||||
}
|
||||
|
||||
class Right extends Either {
|
||||
|
||||
use Applicative;
|
||||
use Pointed;
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function map( callable $fn ) {
|
||||
return Either::of( $fn( $this->value ) );
|
||||
}
|
||||
|
||||
public function bimap( callable $leftFn, callable $rightFn ) {
|
||||
return $this->map( $rightFn );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $leftFn
|
||||
* @param callable $rightFn
|
||||
*
|
||||
* @return Right
|
||||
*/
|
||||
public function coalesce( callable $leftFn, callable $rightFn ) {
|
||||
return $this->map( $rightFn );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Either $other
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrElse( $other ) {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function orElse( callable $fn ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrElseThrow( $value ) {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function chain( callable $fn ) {
|
||||
return $this->map( $fn )->join();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $leftFn
|
||||
* @param callable $rightFn
|
||||
*
|
||||
* @return Either|Left|Right
|
||||
*/
|
||||
public function bichain( callable $leftFn, callable $rightFn ) {
|
||||
return $rightFn( $this->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function filter( callable $fn ) {
|
||||
return Logic::ifElse( $fn, Either::right(), Either::left(), $this->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
public function tryCatch( callable $fn ) {
|
||||
return tryCatch( function () use ( $fn ) {
|
||||
return $fn( $this->value );
|
||||
} );
|
||||
}
|
||||
|
||||
public function alt( Either $alt ) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Either::init();
|
||||
54
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/FP.php
vendored
Normal file
54
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/FP.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @deprecated Use Fn instead
|
||||
*
|
||||
* @method static callable|mixed map( callable ...$fn, mixed ...$target ) - Curried :: (a -> b) -> f a -> f b
|
||||
* @method static callable|mixed identity( mixed ...$data ) - Curried :: a -> a
|
||||
* @method static callable|mixed always( ...$a, ...$b ) - Curried :: a -> b -> a
|
||||
* @method static callable|mixed reduce( ...$fn, ...$initial, ...$target ) - Curried :: ((a, b) → a) → a → [b] → a
|
||||
* @method static callable\mixed converge( ...$convergingFn, ...$branchingFns, ...$data ) - Curried :: callable -> [callable] -> mixed -> callable
|
||||
*/
|
||||
class FP {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init(){
|
||||
self::macro( 'map', curryN(2, function( $fn, $target ){
|
||||
if ( is_object( $target ) ) {
|
||||
return $target->map( $fn );
|
||||
}
|
||||
if ( is_array( $target ) ) {
|
||||
return array_map( $fn, $target );
|
||||
}
|
||||
throw( new \InvalidArgumentException( 'target should be an object with map method or an array' ) );
|
||||
}));
|
||||
|
||||
self::macro( 'identity', curryN( 1, function( $value ) { return $value; }));
|
||||
|
||||
self::macro( 'always', curryN( 2, function ( $value, $_ ) { return $value; } ) );
|
||||
|
||||
self::macro( 'reduce', curryN( 3, function( $fn, $initial, $target) {
|
||||
if ( is_object( $target ) ) {
|
||||
return $target->reduce( $fn, $initial );
|
||||
}
|
||||
if ( is_array( $target ) ) {
|
||||
return array_reduce( $target, $fn, $initial );
|
||||
}
|
||||
throw( new \InvalidArgumentException( 'target should be an object with reduce method or an array' ) );
|
||||
} ));
|
||||
|
||||
self::macro( 'converge', curryN( 3, function( $convergingFn, array $branchingFns, $data ) {
|
||||
$apply = function ( $fn ) use ( $data ) { return $fn( $data ); };
|
||||
return call_user_func_array( $convergingFn, self::map( $apply, $branchingFns ) );
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
FP::init();
|
||||
65
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Filter.php
vendored
Normal file
65
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Filter.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\System;
|
||||
|
||||
use WPML\Collect\Support\Collection;
|
||||
|
||||
class _Filter {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $key;
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
private $fn;
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $default;
|
||||
|
||||
/**
|
||||
* _Filter constructor.
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function __construct( $key ) {
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return _Filter
|
||||
*/
|
||||
public function using( callable $fn ) {
|
||||
$this->fn = $fn;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return _Filter
|
||||
*/
|
||||
public function defaultTo( $default ) {
|
||||
$this->default = $default;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WPML\Collect\Support\Collection<mixed> $collection
|
||||
*
|
||||
* @return \WPML\Collect\Support\Collection<mixed>
|
||||
*/
|
||||
public function __invoke( Collection $collection ) {
|
||||
$value = $collection->has( $this->key )
|
||||
? call_user_func( $this->fn, $collection->get( $this->key ) )
|
||||
: value( $this->default );
|
||||
|
||||
return $collection->put( $this->key, $value );
|
||||
}
|
||||
}
|
||||
438
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Fns.php
vendored
Normal file
438
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Fns.php
vendored
Normal file
@@ -0,0 +1,438 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable always( ...$a ) Curried :: a → ( * → a )
|
||||
*
|
||||
* Returns a function that always returns the given value.
|
||||
*
|
||||
* ```php
|
||||
* $t = Fns::always( 'Tee' );
|
||||
* $t(); //=> 'Tee'
|
||||
* ```
|
||||
*
|
||||
* @method static callable converge( ...$convergingFn, ...$branchingFns ) - Curried :: ( ( x1, x2, … ) → z ) → [( ( a, b, … ) → x1 ), ( ( a, b, … ) → x2 ), …] → ( a → b → … → z )
|
||||
*
|
||||
* Accepts a converging function and a list of branching functions and returns a new function. The arity of the new function is the same as the arity of the longest branching function. When invoked, this new function is applied to some arguments, and each branching function is applied to those same arguments. The results of each branching function are passed as arguments to the converging function to produce the return value.
|
||||
*
|
||||
* ```php
|
||||
* $divide = curryN( 2, function ( $num, $dom ) { return $num / $dom; } );
|
||||
* $sum = function ( Collection $collection ) { return $collection->sum(); };
|
||||
* $length = function ( Collection $collection ) { return $collection->count(); };
|
||||
*
|
||||
* $average = Fns::converge( $divide, [ $sum, $length ] );
|
||||
* $this->assertEquals( 4, $average( wpml_collect( [ 1, 2, 3, 4, 5, 6, 7 ] ) ) );
|
||||
* ```
|
||||
*
|
||||
* @method static callable|mixed map( ...$fn, ...$target ) - Curried :: ( a→b )→f a→f b
|
||||
*
|
||||
* Takes a function and a *functor*, applies the function to each of the functor's values, and returns a functor of the same shape.
|
||||
*
|
||||
* And array is considered a *functor*
|
||||
*
|
||||
* Dispatches to the *map* method of the second argument, if present
|
||||
*
|
||||
* @method static callable|mixed each ( ...$fn, ...$target ) - Curried :: ( a→b )→f a→f b
|
||||
* @method static callable|mixed identity( mixed ...$data ) - Curried :: a->a
|
||||
* @method static callable|mixed tap( callable ...$fn, mixed ...$data ) - Curried :: fn->data->data
|
||||
* @method static callable|mixed reduce( ...$fn, ...$initial, ...$target ) - Curried :: ( ( a, b ) → a ) → a → [b] → a
|
||||
* @method static callable|mixed reduceRight( ...$fn, ...$initial, ...$target ) - Curried :: ( ( a, b ) → a ) → a → [b] → a
|
||||
*
|
||||
* Takes a function, an initial value and an array and returns the result.
|
||||
*
|
||||
* The function receives two values, the accumulator and the current value, and should return a result.
|
||||
*
|
||||
* The array values are passed to the function in the reverse order.
|
||||
*
|
||||
* ```php
|
||||
* $numbers = [ 1, 2, 3, 4, 5, 8, 19 ];
|
||||
*
|
||||
* $append = function( $acc, $val ) {
|
||||
* $acc[] = $val;
|
||||
* return $acc;
|
||||
* };
|
||||
*
|
||||
* $reducer = Fns::reduceRight( $append, [] );
|
||||
* $result = $reducer( $numbers ); // [ 19, 8, 5, 4, 3, 2, 1 ]
|
||||
*
|
||||
* // Works on collections too.
|
||||
* $result = $reducer( wpml_collect( $numbers ) ); // [ 19, 8, 5, 4, 3, 2, 1 ]
|
||||
* ```
|
||||
*
|
||||
* @method static callable|mixed filter( ...$predicate, ...$target ) - Curried :: ( a → bool ) → [a] → [a]
|
||||
* @method static callable|mixed reject( ...$predicate, ...$target ) - Curried :: ( a → bool ) → [a] → [a]
|
||||
* @method static callable|mixed value( mixed ...$data ) - Curried :: a|( *→a ) → a
|
||||
* @method static callable|object constructN( ...$argCount, ...$className ) - Curried :: int → string → object
|
||||
* @method static callable|int ascend( ...$fn, ...$a, ...$b ) - Curried :: ( a → b ) → a → a → int
|
||||
* @method static callable|int descend( ...$fn, ...$a, ...$b ) - Curried :: ( a → b ) → a → a → int
|
||||
* @method static callable useWith( ...$fn, ...$transformations ) - Curried :: ( ( x1, x2, … ) → z ) → [( a → x1 ), ( b → x2 ), …] → ( a → b → … → z )
|
||||
* @method static callable nthArg( ...$n ) - Curried :: int → *… → *
|
||||
* @method static callable|mixed either( ...$f, ...$g, ...$e ) - Curried:: ( a → b ) → ( b → c ) → Either a b → c
|
||||
* @method static callable|mixed maybe( ...$v, ...$f, ...$m ) - Curried:: b → ( a → b ) → Maybe a → b
|
||||
* @method static callable|bool isRight( ...$e ) - Curried:: e → bool
|
||||
* @method static callable|bool isLeft( ...$e ) - Curried:: e → bool
|
||||
* @method static callable|bool isJust( ...$m ) - Curried:: e → bool
|
||||
* @method static callable|bool isNothing( ...$m ) - Curried:: e → bool
|
||||
* @method static callable|mixed T( ...$_ ) - Curried :: _ → bool
|
||||
* @method static callable|mixed F( ...$_ ) - Curried :: _ → bool
|
||||
* @method static callable|Maybe safe( ...$fn ) - Curried :: ( a → b ) → ( a → Maybe b )
|
||||
* @method static callable|object make( ...$className ) - Curried :: string → object
|
||||
* @method static callable|object makeN( ...$argCount, ...$className ) - Curried :: int → string → object
|
||||
* @method static callable unary( ...$fn ) - Curried:: ( * → b ) → ( a → b )
|
||||
* @method static callable|mixed memorizeWith( ...$cacheKeyFn, ...$fn ) - Curried :: ( *… → String ) → ( *… → a ) → ( *… → a )
|
||||
* @method static callable|mixed memorize( ...$fn ) - Curried :: ( *… → a ) → ( *… → a )
|
||||
* @method static callable|mixed once( ...$fn ) - Curried :: ( *… → a ) → ( *… → a )
|
||||
* @method static callable|mixed withNamedLock( ...$name, ...$returnFn, ...$fn ) - Curried :: String → ( *… → String ) → ( *… → a ) → ( *… → a )
|
||||
*
|
||||
* Creates a new function that is *locked* so that it wont be called recursively. Multiple functions can use the same lock so they are blocked from calling each other recursively
|
||||
*
|
||||
* ```php
|
||||
* $lockName = 'my-lock';
|
||||
* $addOne = Fns::withNamedLock(
|
||||
* $lockName,
|
||||
* Fns::identity(),
|
||||
* function ( $x ) use ( &$addOne ) { return $addOne( $x + 1 ); }
|
||||
* );
|
||||
*
|
||||
* $this->assertEquals( 13, $addOne( 12 ), 'Should not recurse' );
|
||||
*
|
||||
* $addTwo = Fns::withNamedLock(
|
||||
* $lockName,
|
||||
* Fns::identity(),
|
||||
* function ( $x ) use ( $addOne ) { return pipe( $addOne, $addOne) ( $x ); }
|
||||
* );
|
||||
*
|
||||
* $this->assertEquals( 10, $addTwo( 10 ), 'Should return 10 because $addOne is locked by the same name as $addTwo' );
|
||||
* ```
|
||||
*
|
||||
* @method static callable|mixed withoutRecursion( ...$returnFn, ...$fn ) - Curried :: ( *… → String ) → ( *… → a ) → ( *… → a )
|
||||
* @method static callable|mixed liftA2( ...$fn, ...$monadA, ...$monadB ) - Curried :: ( a → b → c ) → m a → m b → m c
|
||||
* @method static callable|mixed liftA3( ...$fn, ...$monadA, ...$monadB, ...$monadC ) - Curried :: ( a → b → c → d ) → m a → m b → m c → m d
|
||||
* @method static callable|mixed liftN( ...$n, ...$fn, ...$monad ) - Curried :: Number->( ( * ) → a ) → ( *m ) → m a
|
||||
*
|
||||
* @method static callable|mixed until( ...$predicate, ...$fns ) - Curried :: ( b → bool ) → [( a → b )] → a → b
|
||||
*
|
||||
* Executes consecutive functions until their $predicate($fn(...$args)) is true. When a result fulfils predicate then it is returned.
|
||||
*
|
||||
* ```
|
||||
* $fns = [
|
||||
* $add(1),
|
||||
* $add(5),
|
||||
* $add(10),
|
||||
* $add(23),
|
||||
* ];
|
||||
*
|
||||
* $this->assertSame( 20, Fns::until( Relation::gt( Fns::__, 18 ), $fns )( 10 ) );
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
class Fns {
|
||||
|
||||
use Macroable;
|
||||
|
||||
const __ = '__CURRIED_PLACEHOLDER__';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'always', function ( $value ) {
|
||||
return function () use ( $value ) { return $value; };
|
||||
} );
|
||||
|
||||
self::macro( 'converge', curryN( 2, function ( $convergingFn, array $branchingFns ) {
|
||||
return function ( $data ) use ( $convergingFn, $branchingFns ) {
|
||||
$apply = function ( $fn ) use ( $data ) { return $fn( $data ); };
|
||||
|
||||
return call_user_func_array( $convergingFn, self::map( $apply, $branchingFns ) );
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'map', curryN( 2, function ( $fn, $target ) {
|
||||
if ( ! Logic::isMappable( $target ) ) {
|
||||
throw( new \InvalidArgumentException( 'target should be an object with map method or an array' ) );
|
||||
}
|
||||
|
||||
if ( is_object( $target ) ) {
|
||||
return $target->map( $fn );
|
||||
} else {
|
||||
$keys = array_keys( $target );
|
||||
|
||||
return array_combine( $keys, array_map( $fn, $target, $keys ) );
|
||||
}
|
||||
} ) );
|
||||
|
||||
self::macro( 'each', curryN( 2, function ( $fn, $target ) {
|
||||
return self::map( self::tap( $fn ), $target );
|
||||
} ) );
|
||||
|
||||
self::macro( 'identity', curryN( 1, function ( $value ) { return $value; } ) );
|
||||
|
||||
self::macro( 'tap', curryN( 2, function ( $fn, $value ) {
|
||||
$fn( $value );
|
||||
|
||||
return $value;
|
||||
} ) );
|
||||
|
||||
self::macro( 'reduce', curryN( 3, function ( $fn, $initial, $target ) {
|
||||
if ( is_object( $target ) ) {
|
||||
return $target->reduce( $fn, $initial );
|
||||
}
|
||||
if ( is_array( $target ) ) {
|
||||
return array_reduce( $target, $fn, $initial );
|
||||
}
|
||||
throw( new \InvalidArgumentException( 'target should be an object with reduce method or an array' ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'reduceRight', curryN( 3, function ( $fn, $initial, $target ) {
|
||||
if ( is_object( $target ) ) {
|
||||
return $target->reverse()->reduce( $fn, $initial );
|
||||
}
|
||||
if ( is_array( $target ) ) {
|
||||
return array_reduce( array_reverse( $target ), $fn, $initial );
|
||||
}
|
||||
throw( new \InvalidArgumentException( 'target should be an object with reduce method or an array' ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'filter', curryN( 2, function ( $predicate, $target ) {
|
||||
if ( is_object( $target ) ) {
|
||||
return $target->filter( $predicate );
|
||||
}
|
||||
if ( is_array( $target ) ) {
|
||||
return array_values( array_filter( $target, $predicate ) );
|
||||
}
|
||||
throw( new \InvalidArgumentException( 'target should be an object with filter method or an array' ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'reject', curryN( 2, function ( $predicate, $target ) {
|
||||
return self::filter( pipe( $predicate, Logic::not() ), $target );
|
||||
} ) );
|
||||
|
||||
self::macro( 'value', curryN( 1, function ( $value ) {
|
||||
return is_callable( $value ) ? $value() : $value;
|
||||
} ) );
|
||||
|
||||
self::macro( 'constructN', curryN( 2, function ( $argCount, $className ) {
|
||||
$maker = function () use ( $className ) {
|
||||
$args = func_get_args();
|
||||
|
||||
return new $className( ...$args );
|
||||
};
|
||||
|
||||
return curryN( $argCount, $maker );
|
||||
} ) );
|
||||
|
||||
self::macro( 'ascend', curryN( 3, function ( $fn, $a, $b ) {
|
||||
$aa = $fn( $a );
|
||||
$bb = $fn( $b );
|
||||
|
||||
return $aa < $bb ? - 1 : ( $aa > $bb ? 1 : 0 );
|
||||
} ) );
|
||||
|
||||
self::macro( 'descend', curryN( 3, function ( $fn, $a, $b ) {
|
||||
return self::ascend( $fn, $b, $a );
|
||||
} ) );
|
||||
|
||||
self::macro( 'useWith', curryN( 2, function ( $fn, $transformations ) {
|
||||
return curryN( count( $transformations ), function () use ( $fn, $transformations ) {
|
||||
$apply = function ( $arg, $transform ) {
|
||||
return $transform( $arg );
|
||||
};
|
||||
|
||||
$args = Fns::map( spreadArgs( $apply ), Lst::zip( func_get_args(), $transformations ) );
|
||||
|
||||
return $fn( ...$args );
|
||||
} );
|
||||
} ) );
|
||||
|
||||
self::macro( 'nthArg', curryN( 1, function ( $n ) {
|
||||
return function () use ( $n ) {
|
||||
return Lst::nth( $n, func_get_args() );
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'either', curryN( 3, function ( callable $f, callable $g, Either $e ) {
|
||||
if ( $e instanceof Left ) {
|
||||
return $e->orElse( $f )->get();
|
||||
}
|
||||
|
||||
return $e->map( $g )->get();
|
||||
} ) );
|
||||
|
||||
self::macro( 'maybe', curryN( 3, function ( $v, callable $f, Maybe $m ) {
|
||||
if ( $m->isNothing() ) {
|
||||
return $v;
|
||||
}
|
||||
|
||||
return $m->map( $f )->get();
|
||||
} ) );
|
||||
|
||||
self::macro( 'isRight', curryN( 1, function ( $e ) {
|
||||
return $e instanceof Right;
|
||||
} ) );
|
||||
|
||||
self::macro( 'isLeft', curryN( 1, function ( $e ) {
|
||||
return $e instanceof Left;
|
||||
} ) );
|
||||
|
||||
self::macro( 'isJust', curryN( 1, function ( $m ) {
|
||||
return $m instanceof Just;
|
||||
} ) );
|
||||
|
||||
self::macro( 'isNothing', curryN( 1, function ( $m ) {
|
||||
return $m instanceof Nothing;
|
||||
} ) );
|
||||
|
||||
self::macro( 'safe', curryN( 1, function ( $fn ) {
|
||||
return pipe( $fn, Maybe::fromNullable() );
|
||||
} ) );
|
||||
|
||||
self::macro( 'make', curryN( 1, function ( $className ) {
|
||||
return \WPML\Container\make( $className );
|
||||
} ) );
|
||||
|
||||
self::macro( 'makeN', curryN( 2, function ( $argCount, $className ) {
|
||||
$maker = spreadArgs( curryN( $argCount, function () use ( $className ) {
|
||||
return \WPML\Container\make( $className, func_get_args() );
|
||||
} ) );
|
||||
|
||||
return $maker( Lst::drop( 2, func_get_args() ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'unary', curryN( 1, function ( $fn ) {
|
||||
return function ( $arg ) use ( $fn ) {
|
||||
return $fn( $arg );
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'memorizeWith', curryN( 2, function ( $cacheKeyFn, $fn ) {
|
||||
return function () use ( $cacheKeyFn, $fn ) {
|
||||
static $cache = [];
|
||||
|
||||
$args = func_get_args();
|
||||
$key = call_user_func_array( $cacheKeyFn, $args );
|
||||
if ( array_key_exists( $key, $cache ) ) {
|
||||
return $cache[ $key ];
|
||||
}
|
||||
|
||||
$result = call_user_func_array( $fn, $args );
|
||||
$cache[ $key ] = $result;
|
||||
|
||||
return $result;
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro(
|
||||
'memorize',
|
||||
self::memorizeWith( gatherArgs( pipe( Fns::map( 'json_encode'), Lst::join('|') ) ) )
|
||||
);
|
||||
|
||||
self::macro( 'once', curryN( 1, function ( $fn ) {
|
||||
return function () use ( $fn ) {
|
||||
static $result = [];
|
||||
if ( array_key_exists( 'data', $result ) ) {
|
||||
return $result['data'];
|
||||
}
|
||||
$result['data'] = call_user_func_array( $fn, func_get_args() );
|
||||
|
||||
return $result['data'];
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'withNamedLock', curryN( 3, function ( $name, $returnFn, $fn ) {
|
||||
static $inProgress = [];
|
||||
|
||||
return function () use ( &$inProgress, $name, $returnFn, $fn ) {
|
||||
|
||||
$args = func_get_args();
|
||||
if ( Obj::prop( $name, $inProgress ) ) {
|
||||
return call_user_func_array( $returnFn, $args );
|
||||
}
|
||||
$inProgress[ $name ] = true;
|
||||
$result = call_user_func_array( $fn, $args );
|
||||
$inProgress[ $name ] = false;
|
||||
|
||||
return $result;
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'withoutRecursion', curryN( 2, function ( $returnFn, $fn ) {
|
||||
return function () use ( $returnFn, $fn ) {
|
||||
static $inProgress = false;
|
||||
|
||||
$args = func_get_args();
|
||||
if ( $inProgress ) {
|
||||
return call_user_func_array( $returnFn, $args );
|
||||
}
|
||||
$inProgress = true;
|
||||
$result = call_user_func_array( $fn, $args );
|
||||
$inProgress = false;
|
||||
|
||||
return $result;
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'liftA2', curryN( 3, function ( $fn, $monadA, $monadB ) {
|
||||
return $monadA->map( $fn )->ap( $monadB );
|
||||
} ) );
|
||||
|
||||
self::macro( 'liftA3', curryN( 4, function ( $fn, $monadA, $monadB, $monadC ) {
|
||||
return $monadA->map( $fn )->ap( $monadB )->ap( $monadC );
|
||||
} ) );
|
||||
|
||||
self::macro( 'liftN', function ( $n, $fn ) {
|
||||
$liftedFn = curryN( $n, function () use ( $n, $fn ) {
|
||||
$args = func_get_args();
|
||||
$result = $args[0]->map( curryN( $n, $fn ) );
|
||||
|
||||
return Fns::reduce(
|
||||
function ( $result, $monad ) { return $result->ap( $monad ); },
|
||||
$result,
|
||||
Lst::drop( 1, $args )
|
||||
);
|
||||
} );
|
||||
|
||||
return call_user_func_array( $liftedFn, Lst::drop( 2, func_get_args() ) );
|
||||
} );
|
||||
|
||||
|
||||
self::macro( 'until', curryN( 3, function ( $predicate, array $fns, ...$args ) {
|
||||
foreach ( $fns as $fn ) {
|
||||
$result = $fn( ...$args );
|
||||
if ( $predicate( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Closure
|
||||
*/
|
||||
public static function noop() {
|
||||
return function () { };
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried function that transforms a Maybe into an Either.
|
||||
*
|
||||
* @param mixed|null $or
|
||||
* @param Maybe|null $maybe
|
||||
*
|
||||
* @return callable|Either
|
||||
*/
|
||||
public static function maybeToEither( $or = null, $maybe = null ) {
|
||||
$toEither = function ( $or, Maybe $maybe ) {
|
||||
return self::isJust( $maybe ) ? Either::right( $maybe->getOrElse( null ) ) : Either::left( $or );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $toEither ), func_get_args() );
|
||||
}
|
||||
}
|
||||
|
||||
Fns::init();
|
||||
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/Applicative.php
vendored
Normal file
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/Applicative.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
trait Applicative {
|
||||
|
||||
/**
|
||||
* @param mixed $otherContainer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function ap( $otherContainer ) {
|
||||
return $otherContainer->map( $this->value );
|
||||
}
|
||||
}
|
||||
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/ConstApplicative.php
vendored
Normal file
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/ConstApplicative.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
trait ConstApplicative {
|
||||
|
||||
/**
|
||||
* @param mixed $otherContainer
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function ap( $otherContainer ) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
17
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/ConstFunctor.php
vendored
Normal file
17
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/ConstFunctor.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Functor;
|
||||
|
||||
class ConstFunctor {
|
||||
use Functor;
|
||||
use Pointed;
|
||||
|
||||
/**
|
||||
* @param callable $callback
|
||||
*
|
||||
* @return ConstFunctor
|
||||
*/
|
||||
public function map( $callback ) {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
31
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/Functor.php
vendored
Normal file
31
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/Functor.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Functor;
|
||||
|
||||
|
||||
trait Functor {
|
||||
/** @var mixed */
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __construct( $value ) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $callback
|
||||
*
|
||||
* @return \WPML\FP\Either
|
||||
*/
|
||||
abstract public function map( callable $callback );
|
||||
|
||||
}
|
||||
17
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/IdentityFunctor.php
vendored
Normal file
17
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/IdentityFunctor.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Functor;
|
||||
|
||||
class IdentityFunctor {
|
||||
use Functor;
|
||||
use Pointed;
|
||||
|
||||
/**
|
||||
* @param callable $callback
|
||||
*
|
||||
* @return IdentityFunctor
|
||||
*/
|
||||
public function map( $callback ) {
|
||||
return new self( $callback( $this->get() ) );
|
||||
}
|
||||
}
|
||||
24
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/Pointed.php
vendored
Normal file
24
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Functor/Pointed.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Functor;
|
||||
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
trait Pointed {
|
||||
|
||||
/**
|
||||
* of :: a -> M a
|
||||
*
|
||||
* Curried function that returns an instance of the derived class
|
||||
* @param mixed $value (optional)
|
||||
*
|
||||
* @return mixed|callable
|
||||
*/
|
||||
public static function of( $value = null ) {
|
||||
$of = function( $value ) { return new static( $value ); };
|
||||
|
||||
return call_user_func_array( curryN(1, $of ), func_get_args() );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
44
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Invoker.php
vendored
Normal file
44
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Invoker.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
class _Invoker {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fnName;
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
private $args = [];
|
||||
|
||||
/**
|
||||
* _Invoker constructor.
|
||||
*
|
||||
* @param string $fnName
|
||||
*/
|
||||
public function __construct( $fnName ) {
|
||||
$this->fnName = $fnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed ...$args
|
||||
*
|
||||
* @return _Invoker
|
||||
*/
|
||||
public function with( ...$args ) {
|
||||
$this->args = $args;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __invoke( $instance ) {
|
||||
return call_user_func_array( [ $instance, $this->fnName ], $this->args );
|
||||
}
|
||||
}
|
||||
|
||||
34
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Json.php
vendored
Normal file
34
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Json.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Collection;
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable|array|null toArray(string ...$str) - Curried :: json -> array
|
||||
* @method static callable|Collection|null toCollection(string ...$str) Curried :: json -> null | Collection
|
||||
*/
|
||||
class Json {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'toArray', curryN( 1, function ( $str ) {
|
||||
return json_decode( $str, true );
|
||||
} ) );
|
||||
|
||||
self::macro( 'toCollection', curryN( 1, function ( $str ) {
|
||||
return Maybe::of( $str )
|
||||
->map( 'stripslashes' )
|
||||
->map( self::toArray() )
|
||||
->map( 'wpml_collect' )
|
||||
->getOrElse( null );
|
||||
} ) );
|
||||
}
|
||||
}
|
||||
|
||||
Json::init();
|
||||
65
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Lens.php
vendored
Normal file
65
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Lens.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable iso( ...$to, ...$from ) - Curried :: callable->callable->callable
|
||||
* @method static callable isoIdentity() :: callable->callable->callable
|
||||
* @method static callable isoUnserialized() :: callable->callable->callable
|
||||
* @method static callable isoJsonDecoded() :: callable->callable->callable
|
||||
* @method static callable isoUrlDecoded() :: callable->callable->callable
|
||||
* @method static callable isoBase64Decoded() :: callable->callable->callable
|
||||
* @method static callable isoParsedUrl() :: callable->callable->callable
|
||||
* @method static callable isoParsedQuery() :: callable->callable->callable
|
||||
*/
|
||||
class Lens {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'iso', curryN( 2, function( $get, $reverseGet ) {
|
||||
return function ( $toFunctorFn ) use ( $get, $reverseGet ) {
|
||||
return function ( $target ) use ( $toFunctorFn, $get, $reverseGet ) {
|
||||
$value = $get( $target ); // Split in 2 lines to prevent VaultPress reports.
|
||||
return Fns::map( $reverseGet, $toFunctorFn( $value ) );
|
||||
};
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'isoIdentity', function() {
|
||||
return self::iso( Fns::identity(), Fns::identity() );
|
||||
} );
|
||||
|
||||
self::macro( 'isoUnserialized', function() {
|
||||
return self::iso( 'unserialize', 'serialize' );
|
||||
} );
|
||||
|
||||
self::macro( 'isoJsonDecoded', function() {
|
||||
return self::iso( 'json_decode', 'json_encode' );
|
||||
} );
|
||||
|
||||
self::macro( 'isoUrlDecoded', function() {
|
||||
return self::iso( 'urldecode', 'urlencode' );
|
||||
} );
|
||||
|
||||
self::macro( 'isoBase64Decoded', function() {
|
||||
return self::iso( 'base64_decode', 'base64_encode' );
|
||||
} );
|
||||
|
||||
self::macro( 'isoParsedUrl', function() {
|
||||
return self::iso( 'parse_url', 'http_build_url' );
|
||||
} );
|
||||
|
||||
self::macro( 'isoParsedQuery', function() {
|
||||
return self::iso( Str::parse(), 'http_build_query' );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
Lens::init();
|
||||
136
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Logic.php
vendored
Normal file
136
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Logic.php
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable|bool not( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isNotNull( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|mixed ifElse( ...$predicate, ...$first, ...$second, ...$data ) - Curried :: ( a->bool )->callable->callable->callable
|
||||
* @method static callable when( ...$predicate, ...$fn ) - Curried :: ( a->bool )->callable->callable
|
||||
* @method static callable unless( ...$predicate, ...$fn ) - Curried :: ( a->bool )->callable->callable
|
||||
* @method static callable cond( ...$conditions, ...$fn ) - Curried :: [( a->bool ), callable]->callable
|
||||
* @method static callable both( ...$a, ...$b, ...$data ) - Curried :: ( a → bool ) → ( a → bool ) → a → bool
|
||||
* @method static callable|bool allPass( ...$predicates, ...$data ) - Curried :: [( *… → bool )] → ( *… → bool )
|
||||
* @method static callable|bool anyPass( ...$predicates, ...$data ) - Curried :: [( *… → bool )] → ( *… → bool )
|
||||
* @method static callable complement( ...$fn ) - Curried :: ( *… → * ) → ( *… → bool )
|
||||
* @method static callable|mixed defaultTo( ...$a, ...$b ) - Curried :: a → b → a | b
|
||||
* @method static callable|bool either( ...$a, ...$b ) - Curried :: ( *… → bool ) → ( *… → bool ) → ( *… → bool )
|
||||
* @method static callable|mixed until ( ...$predicate, ...$transform, ...$data ) - Curried :: ( a → bool ) → ( a → a ) → a → a
|
||||
* @method static callable|bool propSatisfies( ...$predicate, ...$prop, ...$data ) - Curried :: ( a → bool ) → String → [String => a] → bool
|
||||
* @method static callable|bool isArray ( ...$a ) - Curried :: a → bool
|
||||
* @method static callable|bool isMappable ( ...$a ) - Curried :: a → bool
|
||||
* @method static callable|bool isEmpty( ...$a ) - Curried:: a → bool
|
||||
* @method static callable|bool isNotEmpty( ...$a ) - Curried:: a → bool
|
||||
* @method static callable|mixed firstSatisfying( ...$predicate, ...$functions, ...$data ) - Curried:: callable->callable[]->mixed->mixed
|
||||
* @method static callable|bool isTruthy( ...$data ) - Curried:: mixed->bool
|
||||
*/
|
||||
class Logic {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'not', curryN( 1, function ( $v ) { return ! Fns::value( $v ); } ) );
|
||||
self::macro( 'isNotNull', curryN( 1, pipe( 'is_null', self::not() ) ) );
|
||||
self::macro( 'ifElse', curryN( 4, function ( callable $predicate, callable $first, callable $second, $data ) {
|
||||
return $predicate( $data ) ? $first( $data ) : $second( $data );
|
||||
} ) );
|
||||
self::macro( 'when', curryN( 3, function ( callable $predicate, callable $fn, $data ) {
|
||||
return $predicate( $data ) ? $fn( $data ) : $data;
|
||||
} ) );
|
||||
self::macro( 'unless', curryN( 3, function ( callable $predicate, callable $fn, $data ) {
|
||||
return $predicate( $data ) ? $data : $fn( $data );
|
||||
} ) );
|
||||
self::macro( 'cond', curryN( 2, function ( array $conditions, $data ) {
|
||||
foreach ( $conditions as $condition ) {
|
||||
if ( $condition[0]( $data ) ) {
|
||||
return $condition[1]( $data );
|
||||
}
|
||||
}
|
||||
} ) );
|
||||
self::macro( 'both', curryN( 3, function ( callable $a, callable $b, $data ) {
|
||||
return $a( $data ) && $b( $data );
|
||||
} ) );
|
||||
|
||||
self::macro( 'allPass', curryN( 2, function ( array $predicates, $data ) {
|
||||
foreach ( $predicates as $predicate ) {
|
||||
if ( ! $predicate( $data ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} ) );
|
||||
|
||||
self::macro( 'anyPass', curryN( 2, function ( array $predicates, $data ) {
|
||||
foreach ( $predicates as $predicate ) {
|
||||
if ( $predicate( $data ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} ) );
|
||||
|
||||
self::macro( 'complement', curryN( 1, function ( $fn ) {
|
||||
return pipe( $fn, self::not() );
|
||||
} ) );
|
||||
|
||||
self::macro( 'defaultTo', curryN( 2, function ( $default, $v ) {
|
||||
return is_null( $v ) ? $default : $v;
|
||||
} ) );
|
||||
|
||||
self::macro( 'either', curryN( 3, function ( callable $a, callable $b, $data ) {
|
||||
return $a( $data ) || $b( $data );
|
||||
} ) );
|
||||
|
||||
self::macro( 'until', curryN( 3, function ( $predicate, $transform, $data ) {
|
||||
while ( ! $predicate( $data ) ) {
|
||||
$data = $transform( $data );
|
||||
}
|
||||
|
||||
return $data;
|
||||
} ) );
|
||||
|
||||
self::macro( 'propSatisfies', curryN( 3, function ( $predicate, $prop, $data ) {
|
||||
return $predicate( Obj::prop( $prop, $data ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'isArray', Type::isArray() );
|
||||
|
||||
self::macro( 'isMappable', curryN( 1, function( $a ) {
|
||||
return self::isArray( $a ) || ( is_object( $a ) && method_exists( $a, 'map' ) );
|
||||
}));
|
||||
|
||||
self::macro( 'isEmpty', curryN( 1, function ( $arg ) {
|
||||
if ( is_array( $arg ) || $arg instanceof \Countable ) {
|
||||
return count( $arg ) === 0;
|
||||
}
|
||||
|
||||
return empty( $arg );
|
||||
} ) );
|
||||
|
||||
self::macro( 'isNotEmpty', curryN( 1, self::complement( self::isEmpty() ) ) );
|
||||
|
||||
self::macro( 'firstSatisfying', curryN( 3, function ( $predicate, array $conditions, $data ) {
|
||||
foreach ( $conditions as $condition ) {
|
||||
$res = $condition( $data );
|
||||
if ( $predicate( $res ) ) {
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} ) );
|
||||
|
||||
self::macro( 'isTruthy', curryN( 1, function ( $data ) {
|
||||
return $data instanceof \Countable ? count( $data ) > 0 : (bool) $data;
|
||||
} ) );
|
||||
}
|
||||
}
|
||||
|
||||
Logic::init();
|
||||
384
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Lst.php
vendored
Normal file
384
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Lst.php
vendored
Normal file
@@ -0,0 +1,384 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Collection;
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\Collect\Support\Arr;
|
||||
|
||||
/**
|
||||
* Lst class contains functions for working on ordered arrays indexed with numerical keys
|
||||
*
|
||||
* @method static callable|array append( mixed ...$newItem, array ...$data ) - Curried :: mixed->array->array
|
||||
* @method static callable|array fromPairs( array ...$array ) - Curried :: [[a, b]] → [a => b]
|
||||
* @method static callable|array toObj( array ...$array ) - Curried :: array → object
|
||||
* @method static callable|array pluck( ...$prop, ...$array ) - Curried :: string → array → array
|
||||
* @method static callable|array partition( ...$predicate, ...$target ) - Curried :: ( a → bool ) → [a] → [[a], [a]]
|
||||
* @method static callable|array sort( ...$fn, ...$target ) - Curried :: ( ( a, a ) → int ) → [a] → [a]
|
||||
* @method static callable|array unfold( ...$fn, ...$seed ) - Curried :: ( a → [b] ) → * → [b]
|
||||
* @method static callable|array zip( ...$a, ...$b ) - Curried :: [a] → [b] → [[a, b]]
|
||||
* @method static callable|array zipObj( ...$a, ...$b ) - Curried :: [a] → [b] → [a => b]
|
||||
* @method static callable|array zipWith( ...$f, ...$a, ...$b ) - Curried :: ( ( a, b ) → c ) → [a] → [b] → [c]
|
||||
* @method static callable|string join( ...$glue, ...$array ) - Curried :: string → [a] → string
|
||||
* @method static callable|string joinWithCommasAndAnd( ...$array ) - Curried :: [a] → string
|
||||
* @method static callable|array concat( ...$a, ...$b ) - Curried :: [a] → [a] → [a]
|
||||
* @method static callable|array|null find( ...$predicate, ...$array ) - Curried :: ( a → bool ) → [a] → a | null
|
||||
* @method static callable|array flattenToDepth( ...$depth, ...$array ) - Curried :: int → [[a]] → [a]
|
||||
* @method static callable|array flatten( ...$array ) - Curried :: [[a]] → [a]
|
||||
* @method static callable|bool includes( ...$val, ...$array ) - Curried :: a → [a] → bool
|
||||
* @method static callable|bool includesAll( ...$values, ...$array ) - Curried :: [a] → [a] → bool
|
||||
*
|
||||
* Determines if all the values are in the given array
|
||||
*
|
||||
* ```
|
||||
* $includes10and20 = Lst::includesAll( [ 10, 20 ] );
|
||||
*
|
||||
* $this->assertTrue( $includes10and20( [ 5, 10, 15, 20 ] ) );
|
||||
* $this->assertFalse( $includes10and20( [ 5, 15, 20 ] ) );
|
||||
* ```
|
||||
* @method static callable|bool nth( ...$n, ...$array ) - Curried :: int → [a] → a | null
|
||||
* @method static callable|bool first( ...$array ) - Curried :: [a, b] → a | null
|
||||
* @method static callable|bool last( ...$array ) - Curried :: [a, b] → b | null
|
||||
* @method static callable|int length( ...$array ) - Curried :: [a] → int
|
||||
* @method static callable|array take( ...$n, ...$array ) - Curried :: int → [a] → [a]
|
||||
* @method static callable|array takeLast( ...$n, ...$array ) - Curried :: int → [a] → [a]
|
||||
* @method static callable|array slice( ...$offset, ...$limit, ...$array ) - Curried :: int → int->[a] → [a]
|
||||
* @method static callable|array drop( ...$n, ...$array ) - Curried :: int → [a] → [a]
|
||||
* @method static callable|array dropLast( ...$n, ...$array ) - Curried :: int → [a] → [a]
|
||||
* @method static callable|array makePair( ...$a, ...$b ) - Curried :: mixed → mixed → array
|
||||
* @method static callable|array make ( ...$a ) - Curried :: mixed → array
|
||||
* @method static callable|array insert( ...$index, ...$v, ...$array ) - Curried :: int → mixed → array → array
|
||||
* @method static callable|array range( ...$from, ...$to ) - Curried :: int → int → array
|
||||
* @method static callable|array xprod( ...$a, ...$b ) - Curried :: [a]->[b]->[a, b]
|
||||
*
|
||||
* Creates a new list out of the two supplied by creating each possible pair from the lists.
|
||||
*
|
||||
* ```
|
||||
* $a = [ 1, 2, 3 ];
|
||||
* $b = [ 'a', 'b', 'c' ];
|
||||
* $expectedResult = [
|
||||
* [ 1, 'a' ], [ 1, 'b' ], [ 1, 'c' ],
|
||||
* [ 2, 'a' ], [ 2, 'b' ], [ 2, 'c' ],
|
||||
* [ 3, 'a' ], [ 3, 'b' ], [ 3, 'c' ],
|
||||
* ];
|
||||
*
|
||||
* $this->assertEquals( $expectedResult, Lst::xprod( $a, $b ) );
|
||||
* ```
|
||||
* @method static callable|array prepend( ...$val, ...$array ) - Curried:: a → [a] → [a]
|
||||
*
|
||||
* Returns a new array with the given element at the front, followed by the contents of the list.
|
||||
*
|
||||
* @method static callable|array reverse( ...$array ) - Curried:: [a] → [a]
|
||||
*
|
||||
* Returns a new array with the elements reversed.
|
||||
*
|
||||
*/
|
||||
class Lst {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'append', curryN( 2, function ( $newItem, array $data ) {
|
||||
$data[] = $newItem;
|
||||
|
||||
return $data;
|
||||
} ) );
|
||||
|
||||
self::macro( 'fromPairs', curryN( 1, function ( array $data ) {
|
||||
$fromPair = function ( array $result, array $pair ) {
|
||||
$result[ $pair[0] ] = $pair[1];
|
||||
|
||||
return $result;
|
||||
};
|
||||
|
||||
return Fns::reduce( $fromPair, [], $data );
|
||||
} ) );
|
||||
|
||||
self::macro( 'toObj', curryN( 1, function ( array $data ) { return (object) $data; } ) );
|
||||
|
||||
self::macro( 'pluck', curryN( 2, function ( $prop, $data ) {
|
||||
return Fns::map( Obj::prop( $prop ), $data );
|
||||
} ) );
|
||||
|
||||
self::macro( 'partition', curryN( 2, function ( $predicate, $data ) {
|
||||
return [ Fns::filter( $predicate, $data ), Fns::reject( $predicate, $data ) ];
|
||||
} ) );
|
||||
|
||||
self::macro( 'sort', curryN( 2, function ( $compare, $data ) {
|
||||
if ( $data instanceof Collection ) {
|
||||
return wpml_collect( self::sort( $compare, $data->toArray() ) );
|
||||
}
|
||||
usort( $data, $compare );
|
||||
|
||||
return $data;
|
||||
} ) );
|
||||
|
||||
self::macro( 'unfold', curryN( 2, function ( $fn, $seed ) {
|
||||
$result = [];
|
||||
do {
|
||||
$iteratorResult = $fn( $seed );
|
||||
if ( is_array( $iteratorResult ) ) {
|
||||
$result[] = $iteratorResult[0];
|
||||
$seed = $iteratorResult[1];
|
||||
}
|
||||
} while ( $iteratorResult !== false );
|
||||
|
||||
return $result;
|
||||
|
||||
} ) );
|
||||
|
||||
self::macro( 'zip', curryN( 2, function ( $a, $b ) {
|
||||
$result = [];
|
||||
for ( $i = 0; $i < min( count( $a ), count( $b ) ); $i ++ ) {
|
||||
$result[] = [ $a[ $i ], $b[ $i ] ];
|
||||
}
|
||||
|
||||
return $result;
|
||||
} ) );
|
||||
|
||||
self::macro( 'zipObj', curryN( 2, function ( $a, $b ) {
|
||||
$result = [];
|
||||
for ( $i = 0; $i < min( count( $a ), count( $b ) ); $i ++ ) {
|
||||
$result[ $a[ $i ] ] = $b[ $i ];
|
||||
}
|
||||
|
||||
return $result;
|
||||
} ) );
|
||||
|
||||
self::macro( 'zipWith', curryN( 3, function ( $fn, $a, $b ) {
|
||||
$result = [];
|
||||
for ( $i = 0; $i < min( count( $a ), count( $b ) ); $i ++ ) {
|
||||
$result[] = $fn( $a[ $i ], $b[ $i ] );
|
||||
}
|
||||
|
||||
return $result;
|
||||
} ) );
|
||||
|
||||
self::macro( 'join', curryN( 2, 'implode' ) );
|
||||
|
||||
self::macro( 'joinWithCommasAndAnd', curryN( 1, function ( $array ) {
|
||||
$last = Lst::last( $array );
|
||||
if ( $last ) {
|
||||
if ( Lst::length( $array ) > 1 ) {
|
||||
return str_replace( ' ', ' ', Lst::join( ', ', Lst::dropLast( 1, $array ) ) . ' ' . __( ' and ', 'sitepress' ) . ' ' . $last );
|
||||
// TODO Replace above with following (after 4.5.0 release to get 'and' translated):
|
||||
// return Lst::join( ', ', Lst::dropLast( 1, $array ) ) . ' ' . __( 'and', 'sitepress' ) . ' ' . $last;
|
||||
} else {
|
||||
return $last;
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} ) );
|
||||
|
||||
self::macro( 'concat', curryN( 2, 'array_merge' ) );
|
||||
|
||||
self::macro( 'find', curryN( 2, function ( $predicate, $array ) {
|
||||
foreach ( $array as $value ) {
|
||||
if ( $predicate( $value ) ) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} ) );
|
||||
|
||||
self::macro( 'flattenToDepth', curryN( 2, flip( Arr::class . '::flatten' ) ) );
|
||||
|
||||
self::macro( 'flatten', curryN( 1, Arr::class . '::flatten' ) );
|
||||
|
||||
self::macro( 'includes', curryN( 2, function ( $val, $array ) {
|
||||
return in_array( $val, $array, true );
|
||||
} ) );
|
||||
|
||||
self::macro( 'includesAll', curryN( 2, function ( $values, $array ) {
|
||||
foreach ( $values as $val ) {
|
||||
if ( ! in_array( $val, $array, true ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} ) );
|
||||
|
||||
self::macro( 'nth', curryN( 2, function ( $n, $array ) {
|
||||
$count = count( $array );
|
||||
if ( $n < 0 ) {
|
||||
$n += $count;
|
||||
}
|
||||
|
||||
return $n >= 0 && $n < $count ? $array[ $n ] : null;
|
||||
|
||||
} ) );
|
||||
|
||||
self::macro( 'first', self::nth( 0 ) );
|
||||
|
||||
self::macro( 'last', self::nth( - 1 ) );
|
||||
|
||||
self::macro( 'length', curryN( 1, 'count' ) );
|
||||
|
||||
self::macro( 'take', curryN( 2, function ( $n, $array ) {
|
||||
return array_slice( $array, 0, $n );
|
||||
} ) );
|
||||
|
||||
self::macro( 'takeLast', curryN( 2, function ( $n, $array ) {
|
||||
return array_slice( $array, - $n, $n );
|
||||
} ) );
|
||||
|
||||
self::macro( 'slice', curryN( 3, function ( $offset, $limit, $array ) {
|
||||
return array_slice( $array, $offset, $limit );
|
||||
} ) );
|
||||
|
||||
self::macro( 'drop', curryN( 2, self::slice( Fns::__, null ) ) );
|
||||
|
||||
self::macro( 'dropLast', curryN( 2, function ( $n, $array ) {
|
||||
$len = count( $array );
|
||||
|
||||
return self::take( $n < $len ? $len - $n : 0, $array );
|
||||
} ) );
|
||||
|
||||
self::macro( 'makePair', curryN( 2, function ( $a, $b ) {
|
||||
return [ $a, $b ];
|
||||
} ) );
|
||||
|
||||
self::macro( 'make', curryN( 1, function ( ...$args ) {
|
||||
return $args;
|
||||
} ) );
|
||||
|
||||
self::macro( 'insert', curryN( 3, function ( $index, $v, $array ) {
|
||||
$values = array_values( $array );
|
||||
|
||||
array_splice( $values, $index, 0, [ $v ] );
|
||||
|
||||
return $values;
|
||||
} ) );
|
||||
|
||||
self::macro( 'range', curryN( 2, 'range' ) );
|
||||
|
||||
self::macro( 'xprod', curryN( 2, function ( $a, $b ) {
|
||||
$result = [];
|
||||
foreach ( $a as $el1 ) {
|
||||
foreach ( $b as $el2 ) {
|
||||
$result[] = [ $el1, $el2 ];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
} ) );
|
||||
|
||||
self::macro( 'prepend', Lst::insert( 0 ) );
|
||||
|
||||
self::macro( 'reverse', curryN( 1, 'array_reverse' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried function that keys the array by the given key
|
||||
*
|
||||
* keyBy :: string -> array -> array
|
||||
*
|
||||
* ```
|
||||
* $data = [
|
||||
* [ 'x' => 'a', 'y' => 123 ],
|
||||
* [ 'x' => 'b', 'y' => 456 ],
|
||||
* ];
|
||||
*
|
||||
* Lst::keyBy( 'x', $data );
|
||||
* [
|
||||
* 'a' => [ 'x' => 'a', 'y' => 123 ],
|
||||
* 'b' => [ 'x' => 'b', 'y' => 456 ],
|
||||
* ],
|
||||
* ```
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed[] $array
|
||||
*
|
||||
* @return mixed[]|callable
|
||||
*/
|
||||
public static function keyBy( $key = null, $array = null ) {
|
||||
$keyBy = function ( $key, $array ) {
|
||||
$apply = Fns::converge( Lst::zipObj(), [ Lst::pluck( $key ), Fns::identity() ] );
|
||||
|
||||
return $apply( $array );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $keyBy ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried function that wraps each item in array with pair: [$key => $item1]
|
||||
*
|
||||
* keyWith :: string -> array -> array
|
||||
*
|
||||
* ```
|
||||
* $data = [ 1, 2.3, 'some data', - 2, 'a' ];
|
||||
*
|
||||
* Lst::keyWith('myKey', $data);
|
||||
* [ [ 'myKey' => 1 ], [ 'myKey' => 2.3 ], [ 'myKey' => 'some data' ], [ 'myKey' => - 2 ], [ 'myKey' => 'a' ] ]
|
||||
* ```
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed[] $array
|
||||
*
|
||||
* @return mixed[]|callable
|
||||
*/
|
||||
public static function keyWith( $key = null, $array = null ) {
|
||||
$keyWith = function ( $key, $array ) {
|
||||
return Fns::map( function ( $item ) use ( $key ) {
|
||||
return [ $key => $item ];
|
||||
}, $array );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $keyWith ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return the values in the original collection that are not present in the given collection:
|
||||
*
|
||||
* @param array|Collection $array1
|
||||
* @param array|Collection $array2
|
||||
*
|
||||
* @return callable|Collection|array
|
||||
*/
|
||||
public static function diff( $array1 = null, $array2 = null ) {
|
||||
$diff = function( $array1, $array2){
|
||||
if ( is_object( $array1)) {
|
||||
return $array1->diff($array2);
|
||||
} else {
|
||||
return array_diff( $array1, $array2 );
|
||||
}
|
||||
};
|
||||
return call_user_func_array( curryN(2, $diff), func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* It returns array of $val elements repeated $times times.
|
||||
*
|
||||
* @param mixed $val
|
||||
* @param int $times
|
||||
*
|
||||
* @return callable|array[mixed]
|
||||
*/
|
||||
public static function repeat( $val = null, $times = null ) {
|
||||
$repeat = flip( partial( 'array_fill', 0 ) );
|
||||
|
||||
return call_user_func_array( curryN( 2, $repeat ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|Collection $param
|
||||
*
|
||||
* @return callable|int
|
||||
*/
|
||||
public static function sum( $param = null ) {
|
||||
$sum = function ( $param ) {
|
||||
return is_object( $param ) ? $param->sum() : array_sum( $param );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 1, $sum ), func_get_args() );
|
||||
}
|
||||
}
|
||||
|
||||
Lst::init();
|
||||
32
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Math.php
vendored
Normal file
32
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Math.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable|mixed multiply( ...$a, ...$b ) - Curried :: Number → Number → Number
|
||||
* @method static callable|mixed divide( ...$a, ...$b ) - Curried :: Number → Number → Number
|
||||
* @method static callable|mixed add( ...$a, ...$b ) - Curried :: Number → Number → Number
|
||||
* @method static callable|mixed product( ...$array ) - Curried :: [Number] → Number
|
||||
*/
|
||||
class Math {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'multiply', curryN( 2, function ( $a, $b ) { return $a * $b; } ) );
|
||||
|
||||
self::macro( 'divide', curryN( 2, function ( $a, $b ) { return $a / $b; } ) );
|
||||
|
||||
self::macro( 'add', curryN( 2, function ( $a, $b ) { return $a + $b; } ) );
|
||||
|
||||
self::macro( 'product', curryN(1, Fns::reduce( self::multiply(), 1 ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
Math::init();
|
||||
220
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Maybe.php
vendored
Normal file
220
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Maybe.php
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Functor\Functor;
|
||||
use WPML\FP\Functor\Pointed;
|
||||
|
||||
/**
|
||||
* Class Maybe
|
||||
* @package WPML\FP
|
||||
* @method static callable|Just|Nothing fromNullable( ...$value ) - Curried :: a → Nothing | Just a
|
||||
*
|
||||
* if $value is null or false it returns a Nothing otherwise returns a Just containing the value
|
||||
*
|
||||
* @method static callable safe( ...$fn ) - Curried :: ( a → b ) → ( a → Maybe b )
|
||||
*
|
||||
* returns a function that when called will run the passed in function and put the result into a Maybe
|
||||
*
|
||||
* @method static callable safeAfter( ...$predicate, ...$fn ) - Curried :: ( b → bool ) → ( a → b ) → ( a → Maybe b )
|
||||
*
|
||||
* returns a function that when called will run the passed in function and pass the result of the function
|
||||
* to the predicate. If the predicate returns true the result will be a Just containing the result of the function.
|
||||
* Otherwise it returns a Nothing if the predicate returns false.
|
||||
*
|
||||
* @method static callable safeBefore( ...$predicate, ...$fn ) - Curried :: ( a → bool ) → ( a → b ) → ( a → Maybe b )
|
||||
*
|
||||
* returns a function that when called will pass the given value to the predicate.
|
||||
* If the predicate returns true the value will be lifted into a Just instance and
|
||||
* the passed in function will then be mapped.
|
||||
* Otherwise it returns a Nothing if the predicate returns false.
|
||||
*
|
||||
* @method static callable|Just just( ...$value ) - Curried :: a → Just a
|
||||
*
|
||||
* returns a Just containing the value.
|
||||
*
|
||||
* @method static callable|Just of( ...$value ) - Curried :: a → Just a
|
||||
*
|
||||
* returns a Just containing the value.
|
||||
*
|
||||
*/
|
||||
class Maybe {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'just', Just::of() );
|
||||
|
||||
self::macro( 'of', Just::of() );
|
||||
|
||||
self::macro( 'fromNullable', curryN( 1, function( $value ) {
|
||||
return is_null( $value ) || $value === false ? self::nothing() : self::just( $value );
|
||||
} ) );
|
||||
|
||||
Maybe::macro( 'safe', curryN( 1, function( $fn ) {
|
||||
return pipe( $fn, self::fromNullable() );
|
||||
} ) );
|
||||
|
||||
Maybe::macro( 'safeAfter', curryN( 2, function( $predicate, $fn ) {
|
||||
return pipe( $fn, Logic::ifElse( $predicate, self::just(), [ self::class, 'nothing' ] ) );
|
||||
} ) );
|
||||
|
||||
Maybe::macro( 'safeBefore', curryN( 2, function( $predicate, $fn ) {
|
||||
return pipe( Logic::ifElse( $predicate, self::just(), [ self::class, 'nothing' ] ), Fns::map( $fn ) );
|
||||
} ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Nothing
|
||||
*/
|
||||
public static function nothing() {
|
||||
return new Nothing();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isNothing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isJust() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Just extends Maybe {
|
||||
use Functor;
|
||||
use Pointed;
|
||||
use Applicative;
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Just|Nothing
|
||||
*/
|
||||
public function map( callable $fn ) {
|
||||
return Maybe::fromNullable( $fn( $this->value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $other
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrElse( $other ) {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Just|Nothing
|
||||
*/
|
||||
public function filter( $fn = null ) {
|
||||
$fn = $fn ?: Fns::identity();
|
||||
return Maybe::fromNullable( $fn( $this->value ) ? $this->value : null );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Just|Nothing
|
||||
*/
|
||||
public function reject( $fn = null ) {
|
||||
$fn = $fn ?: Fns::identity();
|
||||
return $this->filter( Logic::complement( $fn ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function chain( callable $fn ) {
|
||||
return $fn( $this->value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isJust() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Nothing extends Maybe {
|
||||
use ConstApplicative;
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Nothing
|
||||
*/
|
||||
public function map( callable $fn ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get() {
|
||||
throw new \Exception( "Can't extract the value of Nothing" );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed|callable $other
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOrElse( $other ) {
|
||||
return value( $other );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Nothing
|
||||
*/
|
||||
public function filter( callable $fn ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Nothing
|
||||
*/
|
||||
public function reject( callable $fn ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Nothing
|
||||
*/
|
||||
public function chain( callable $fn ) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isNothing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Maybe::init();
|
||||
454
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Obj.php
vendored
Normal file
454
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Obj.php
vendored
Normal file
@@ -0,0 +1,454 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Collection;
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Functor\ConstFunctor;
|
||||
use WPML\FP\Functor\IdentityFunctor;
|
||||
|
||||
/**
|
||||
* @method static callable|mixed prop( ...$key, ...$obj ) - Curried :: string->Collection|array|object->mixed|null
|
||||
* @method static callable|mixed propOr( ...$default, ...$key, ...$obj ) - Curried :: mixed->string->Collection|array|object->mixed|null
|
||||
* @method static callable|array props( ...$keys, ...$obj ) - Curried :: [keys] → Collection|array|object → [v]
|
||||
* @method static callable|array|\stdClass addProp( ...$key, ...$transformation, ...$obj ) - Curried :: string->callable->object|array->object->array
|
||||
* @method static callable|array|\stdClass removeProp( ...$key, ...$obj ) - Curried :: string->object|array->object->array
|
||||
* @method static callable|array|\stdClass renameProp( ...$key, ...$newKey, ...$obj ) - Curried :: string->string->object|array->object->array
|
||||
* @method static callable|mixed path( ...$path, ...$obj ) - Curried :: array->Collection|array|object->mixed|null
|
||||
* @method static callable|mixed pathOr( ...$default, ...$path, ...$obj ) - Curried :: mixed → array → Collection|array|object → mixed
|
||||
* @method static callable assoc( ...$key, ...$value, ...$item ) - Curried :: string->mixed->Collection|array|object->mixed|null
|
||||
* @method static callable assocPath( ...$path, ...$value, ...$item ) - Curried :: array->mixed->Collection|array|object->mixed|null
|
||||
* @method static callable lens( ...$getter, ...$setter ) - Curried :: callable->callable->callable
|
||||
* @method static callable lensProp( ...$prop ) - Curried :: string->callable
|
||||
* @method static callable lensPath( ...$path ) - Curried :: array->callable
|
||||
* @method static callable lensMapped( ...$toFunctorFn ) - Curried :: callable->callable
|
||||
* @method static callable lensMappedProp( ...$prop ) - Curried :: string->callable
|
||||
* @method static callable view( ...$lens, ...$obj ) - Curried :: callable->Collection|array|object->mixed
|
||||
* @method static callable set( ...$lens, ...$value, ...$obj ) - Curried :: callable->mixed->Collection|array|object->mixed
|
||||
* @method static callable over( ...$lens, ...$transformation, ...$obj ) - Curried :: callable->callable->Collection|array|object->mixed
|
||||
* @method static callable pick( ...$props, ...$obj ) - Curried :: array->Collection|array->Collection|array
|
||||
* @method static callable pickAll( ...$props, ...$obj ) - Curried :: array->Collection|array->Collection|array
|
||||
* @method static callable pickBy( ...$predicate, ...$obj ) - Curried :: ( ( v, k ) → bool ) → Collection|array->Collection|array
|
||||
* @method static callable pickByKey( ...$predicate, ...$obj ) - Curried :: ( ( k ) → bool ) → Collection|array->callable|Collection|array|object
|
||||
* @method static callable project( ...$props, ...$target ) - Curried :: array->Collection|array->Collection|array
|
||||
* @method static callable where( array $condition ) - Curried :: [string → ( * → bool )] → bool
|
||||
* @method static callable|bool has( ...$prop, ...$item ) - Curried :: string → a → bool
|
||||
* @method static callable|bool hasPath( ...$path, ...$item ) - Curried :: array<string> → a → bool
|
||||
* @method static callable|mixed evolve( ...$transformations, ...$item ) - Curried :: array → array → array
|
||||
*
|
||||
* @method static callable|array objOf( ...$key, ...$value ) - Curried :: string->mixed->array
|
||||
*
|
||||
* Creates an object containing a single key:value pair.
|
||||
*
|
||||
* @method static callable|array keys( ...$obj ) - Curried :: object|array->array
|
||||
*
|
||||
* Returns
|
||||
* - keys if argument is an array
|
||||
* - public properties' names if argument is an object
|
||||
* - keys if argument is Collection
|
||||
*
|
||||
* ```
|
||||
* $this->assertEquals( [ 0, 1, 2 ], Obj::keys( [ 'a', 'b', 'c' ] ) );
|
||||
* $this->assertEquals( [ 'a', 'b', 'c' ], Obj::keys( [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) );
|
||||
*
|
||||
* $this->assertEquals( [ 0, 1, 2 ], Obj::keys( \wpml_collect( [ 'a', 'b', 'c' ] ) ) );
|
||||
* $this->assertEquals( [ 'a', 'b', 'c' ], Obj::keys( \wpml_collect( [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) ) );
|
||||
*
|
||||
* $this->assertEquals( [ 'a', 'b', 'c' ], Obj::keys( (object) [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) );
|
||||
* ```
|
||||
*
|
||||
* @method static callable|array values( ...$obj ) - Curried :: object|array->array
|
||||
*
|
||||
* Returns
|
||||
* - values if argument is an array
|
||||
* - public properties' values if argument is an object
|
||||
* - values if argument is Collection
|
||||
*
|
||||
* ```
|
||||
* $this->assertEquals( [ 'a', 'b', 'c' ], Obj::values( [ 'a', 'b', 'c' ] ) );
|
||||
* $this->assertEquals( [ 1, 2, 3 ], Obj::values( [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) );
|
||||
*
|
||||
* $this->assertEquals( [ 'a', 'b', 'c' ], Obj::values( \wpml_collect( [ 'a', 'b', 'c' ] ) ) );
|
||||
* $this->assertEquals( [ 1, 2, 3 ], Obj::values( \wpml_collect( [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) ) );
|
||||
*
|
||||
* $this->assertEquals( [ 1, 2, 3 ], Obj::values( (object) [ 'a' => 1, 'b' => 2, 'c' => 3 ] ) );
|
||||
* ```
|
||||
*
|
||||
* @method static callable|array replaceRecursive( array ...$newValue, ...$target ) - Curried :: array->array->array
|
||||
*
|
||||
* @method static callable|array toArray( Collection|Object ...$item ) - Curried :: Collection|Object->array
|
||||
*/
|
||||
class Obj {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'prop', curryN( 2, function ( $key, $item ) {
|
||||
return self::propOr( null, $key, $item );
|
||||
} ) );
|
||||
|
||||
self::macro( 'propOr', curryN( 3, function ( $default, $key, $item ) {
|
||||
if ( $item instanceof Collection ) {
|
||||
return $item->get( $key, $default );
|
||||
}
|
||||
if ( is_array( $item ) ) {
|
||||
return array_key_exists( $key, $item ) ? $item[ $key ] : $default;
|
||||
}
|
||||
if ( is_object( $item ) ) {
|
||||
if ( property_exists( $item, $key ) || isset( $item->$key ) ) {
|
||||
return $item->$key;
|
||||
} elseif ( is_numeric( $key ) ) {
|
||||
return self::propOr( $default, $key, (array) $item );
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
if ( is_null( $item ) ) {
|
||||
return null;
|
||||
}
|
||||
throw( new \InvalidArgumentException( 'item should be a Collection or an array or an object' ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'props', curryN( 2, function ( array $keys, $item ) {
|
||||
return Fns::map( Obj::prop( Fns::__, $item ), $keys );
|
||||
} ) );
|
||||
|
||||
self::macro( 'addProp', curryN( 3, function ( $key, $transformation, $data ) {
|
||||
return Obj::assoc( $key, $transformation( $data ), $data );
|
||||
} ) );
|
||||
|
||||
self::macro( 'removeProp', curryN( 2, function ( $key, $data ) {
|
||||
if ( is_array( $data ) ) {
|
||||
unset( $data[ $key ] );
|
||||
|
||||
return $data;
|
||||
} elseif ( is_object( $data ) ) {
|
||||
$newData = clone $data;
|
||||
unset( $newData->$key );
|
||||
|
||||
return $newData;
|
||||
}
|
||||
|
||||
return $data;
|
||||
} ) );
|
||||
|
||||
self::macro( 'renameProp', curryN( 3, function ( $key, $newKey, $data ) {
|
||||
$data = self::addProp( $newKey, self::prop( $key ), $data );
|
||||
|
||||
return self::removeProp( $key, $data );
|
||||
} ) );
|
||||
|
||||
self::macro( 'path', curryN( 2, function ( $path, $item ) {
|
||||
return array_reduce( $path, flip( self::prop() ), $item );
|
||||
} ) );
|
||||
|
||||
self::macro( 'pathOr', curryN( 3, function ( $default, $path, $item ) {
|
||||
$result = Either::of( $item )
|
||||
->tryCatch( Obj::path( $path ) )
|
||||
->getOrElse( null );
|
||||
|
||||
return is_null( $result ) ? $default : $result;
|
||||
} ) );
|
||||
|
||||
self::macro( 'assocPath', curryN( 3, function ( $path, $val, $item ) {
|
||||
$split = [ $item ];
|
||||
for ( $i = 0; $i < count( $path ) - 1; $i ++ ) {
|
||||
$split[] = self::prop( $path[ $i ], $split[ $i ] );
|
||||
}
|
||||
|
||||
$split = array_reverse( $split );
|
||||
$reversePath = array_reverse( $path );
|
||||
|
||||
$split[0] = self::assoc( $reversePath[0], $val, $split[0] );
|
||||
|
||||
for ( $i = 1; $i < count( $reversePath ); $i ++ ) {
|
||||
$key = $reversePath[ $i ];
|
||||
$split[ $i ] = self::assoc( $key, $split[ $i - 1 ], $split[ $i ] );
|
||||
}
|
||||
|
||||
return array_pop( $split );
|
||||
} ) );
|
||||
|
||||
self::macro( 'assoc', curryN( 3, function ( $key, $value, $item ) {
|
||||
if ( $item instanceof Collection ) {
|
||||
$item = clone $item;
|
||||
|
||||
return $item->put( $key, $value );
|
||||
}
|
||||
if ( is_array( $item ) ) {
|
||||
$item[ $key ] = $value;
|
||||
|
||||
return $item;
|
||||
}
|
||||
if ( is_object( $item ) ) {
|
||||
$item = clone $item;
|
||||
$item->$key = $value;
|
||||
|
||||
return $item;
|
||||
}
|
||||
if ( is_null( $item ) ) {
|
||||
return null;
|
||||
}
|
||||
throw( new \InvalidArgumentException( 'item should be a Collection or an array or an object' ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'lens', curryN( 2, function ( $getter, $setter ) {
|
||||
return function ( $toFunctorFn ) use ( $getter, $setter ) {
|
||||
return function ( $target ) use ( $toFunctorFn, $getter, $setter ) {
|
||||
$result = $getter( $target );
|
||||
|
||||
return Fns::map( function ( $focus ) use ( $setter, $target ) {
|
||||
return $setter( $focus, $target );
|
||||
}, $toFunctorFn( $result ) );
|
||||
};
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'lensProp', curryN( 1, function ( $prop ) {
|
||||
return self::lens( self::prop( $prop ), self::assoc( $prop ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'lensPath', curryN( 1, function ( $path ) {
|
||||
return self::lens( self::path( $path ), self::assocPath( $path ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'lensMapped', curryN( 1, function ( $toFunctorFn ) {
|
||||
return function ( $target ) use ( $toFunctorFn ) {
|
||||
return IdentityFunctor::of(
|
||||
Logic::isMappable( $target )
|
||||
? Fns::map( pipe( $toFunctorFn, invoke( 'get' ) ), $target )
|
||||
: $target
|
||||
);
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'lensMappedProp', curryN( 1, function ( $prop ) {
|
||||
return compose( Obj::lensProp( $prop ), Obj::lensMapped() );
|
||||
} ) );
|
||||
|
||||
self::macro( 'view', curryN( 2, function ( $lens, $obj ) {
|
||||
$view = $lens( [ ConstFunctor::class, 'of' ] );
|
||||
|
||||
return $view( $obj )->get();
|
||||
} ) );
|
||||
|
||||
self::macro( 'set', curryN( 3, function ( $lens, $value, $obj ) {
|
||||
return self::over( $lens, Fns::always( $value ), $obj );
|
||||
} ) );
|
||||
|
||||
self::macro( 'over', curryN( 3, function ( $lens, $transformation, $obj ) {
|
||||
$over = $lens( function ( $value ) use ( $transformation ) {
|
||||
return IdentityFunctor::of( $transformation( $value ) );
|
||||
} );
|
||||
|
||||
return $over( $obj )->get();
|
||||
} ) );
|
||||
|
||||
self::macro( 'pick', curryN( 2, function ( array $props, $item ) {
|
||||
$find = curryN( 3, function ( $item, $result, $prop ) {
|
||||
$value = self::propOr( new Undefined(), $prop, $item );
|
||||
if ( ! $value instanceof Undefined ) {
|
||||
$result[ $prop ] = $value;
|
||||
}
|
||||
|
||||
return $result;
|
||||
} );
|
||||
|
||||
$result = Fns::reduce( $find( $item ), [], $props );
|
||||
|
||||
return self::matchType( $result, $item );
|
||||
} ) );
|
||||
|
||||
self::macro( 'pickAll', curryN( 2, function ( array $props, $item ) {
|
||||
$find = curryN( 3, function ( $item, $result, $prop ) {
|
||||
$result[ $prop ] = self::prop( $prop, $item );
|
||||
|
||||
return $result;
|
||||
} );
|
||||
|
||||
$result = Fns::reduce( $find( $item ), [], $props );
|
||||
|
||||
return self::matchType( $result, $item );
|
||||
} ) );
|
||||
|
||||
self::macro( 'project', curryN( 2, function ( array $props, $items ) {
|
||||
return Fns::map( Obj::pick( $props ), $items );
|
||||
} ) );
|
||||
|
||||
self::macro( 'where', curryN( 2, function ( array $conditions, $items ) {
|
||||
foreach ( $conditions as $prop => $condition ) {
|
||||
$filter = pipe( Obj::prop( $prop ), Logic::both( Logic::isNotNull(), $condition ) );
|
||||
$items = Fns::filter( $filter, $items );
|
||||
}
|
||||
|
||||
return $items;
|
||||
} ) );
|
||||
|
||||
self::macro( 'pickBy', curryN( 2, function ( callable $predicate, $item ) {
|
||||
$result = array_filter( self::toArray( $item ), $predicate, ARRAY_FILTER_USE_BOTH );
|
||||
|
||||
return self::matchType( $result, $item );
|
||||
} ) );
|
||||
|
||||
self::macro( 'pickByKey', curryN( 2, function ( callable $predicate, $item ) {
|
||||
return self::pickBy( pipe( Fns::nthArg( 1 ), $predicate ), $item );
|
||||
} ) );
|
||||
|
||||
self::macro( 'hasPath', curryN( 2, function ( $path, $item ) {
|
||||
$undefinedValue = new Undefined();
|
||||
$currentElement = $item;
|
||||
|
||||
foreach ( $path as $pathProp ) {
|
||||
$currentElement = Either::of( $currentElement )
|
||||
->tryCatch( self::propOr( $undefinedValue, $pathProp ) )
|
||||
->getOrElse( $undefinedValue );
|
||||
|
||||
if ( $undefinedValue === $currentElement ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} ) );
|
||||
|
||||
self::macro( 'has', curryN( 2, function ( $prop, $item ) {
|
||||
if ( $item instanceof Collection ) {
|
||||
return $item->has( $prop );
|
||||
}
|
||||
if ( is_array( $item ) ) {
|
||||
return isset( $item[ $prop ] );
|
||||
}
|
||||
if ( is_object( $item ) ) {
|
||||
return property_exists( $item, $prop );
|
||||
}
|
||||
throw( new \InvalidArgumentException( 'item should be a Collection or an array or an object' ) );
|
||||
} ) );
|
||||
|
||||
self::macro( 'evolve', curryN( 2, function ( $transformations, $item ) {
|
||||
$temp = self::toArray( $item );
|
||||
|
||||
foreach ( $transformations as $prop => $transformation ) {
|
||||
if ( isset( $temp[ $prop ] ) ) {
|
||||
if ( is_callable( $transformation ) ) {
|
||||
$temp[ $prop ] = $transformation( $temp[ $prop ] );
|
||||
} elseif ( is_array( $transformation ) ) {
|
||||
$temp[ $prop ] = self::evolve( $transformation, $temp[ $prop ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self::matchType( $temp, $item );
|
||||
} ) );
|
||||
|
||||
self::macro( 'keys', curryN( 1, function ( $obj ) {
|
||||
if ( is_array( $obj ) ) {
|
||||
return array_keys( $obj );
|
||||
} elseif ( $obj instanceof Collection ) {
|
||||
return $obj->keys()->toArray();
|
||||
} elseif ( is_object( $obj ) ) {
|
||||
return array_keys( get_object_vars( $obj ) );
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException( 'obj should be either array or object' );
|
||||
} ) );
|
||||
|
||||
self::macro( 'values', curryN( 1, function ( $obj ) {
|
||||
if ( is_array( $obj ) ) {
|
||||
return array_values( $obj );
|
||||
} elseif ( $obj instanceof Collection ) {
|
||||
return $obj->values()->toArray();
|
||||
} elseif ( is_object( $obj ) ) {
|
||||
return array_values( get_object_vars( $obj ) );
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException( 'obj should be either array or object' );
|
||||
} ) );
|
||||
|
||||
self::macro( 'objOf', curryN( 2, function ( $key, $value ) {
|
||||
return [ $key => $value ];
|
||||
} ) );
|
||||
|
||||
self::macro( 'replaceRecursive', curryN( 2, flip( 'array_replace_recursive' ) ) );
|
||||
|
||||
self::macro( 'toArray', curryN( 1, function ( $item ) {
|
||||
$temp = $item;
|
||||
if ( $temp instanceof Collection ) {
|
||||
$temp = $temp->toArray();
|
||||
}
|
||||
if ( is_object( $temp ) ) {
|
||||
$temp = (array) $temp;
|
||||
}
|
||||
|
||||
return $temp;
|
||||
} ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object|Collection $item
|
||||
* @param object|Collection $reference
|
||||
*
|
||||
* @return object|Collection
|
||||
*/
|
||||
private static function matchType( $item, $reference ) {
|
||||
if ( $reference instanceof Collection ) {
|
||||
return wpml_collect( $item );
|
||||
}
|
||||
if ( is_object( $reference ) ) {
|
||||
return (object) $item;
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried :: mixed → array|object|Collection → array|object|Collection
|
||||
* function to remove an item by key from an array.
|
||||
*
|
||||
* @param string|int $key
|
||||
* @param array|object|Collection|null $item
|
||||
*
|
||||
* @return callable|array|object|Collection
|
||||
*/
|
||||
static function without( $key = null, $item = null ) {
|
||||
$without = function ( $key, $item ) {
|
||||
$temp = self::toArray( $item );
|
||||
unset( $temp[ $key ] );
|
||||
|
||||
return self::matchType( $temp, $item );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $without ), func_get_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Curried :: array|object -> array|object -> array|object
|
||||
*
|
||||
* It merges the new data with item.
|
||||
*
|
||||
* @param array|object $newData
|
||||
* @param array|object $item
|
||||
*
|
||||
* @return array|object
|
||||
*/
|
||||
public static function merge( $newData = null, $item = null ) {
|
||||
$merge = function ( $newData, $item ) {
|
||||
$isNested = Logic::anyPass( [ 'is_array', 'is_object' ] );
|
||||
|
||||
foreach ( (array) $newData as $key => $value ) {
|
||||
if ( $isNested( $newData ) && Obj::has( $key, $item ) && $isNested( Obj::prop( $key, $item ) ) ) {
|
||||
$item = Obj::assoc( $key, self::merge( $value, Obj::prop( $key, $item ) ), $item );
|
||||
} else {
|
||||
$item = Obj::assoc( $key, $value, $item );
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $merge ), func_get_args() );
|
||||
}
|
||||
}
|
||||
|
||||
Obj::init();
|
||||
87
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Promise.php
vendored
Normal file
87
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Promise.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
class Promise {
|
||||
|
||||
/** @var callable */
|
||||
private $onResolved;
|
||||
|
||||
/** @var callable */
|
||||
private $onReject;
|
||||
|
||||
/** @var Promise */
|
||||
private $next;
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function resolve( $data ) {
|
||||
if ( $this->onResolved ) {
|
||||
if ( $data instanceof Either ) {
|
||||
$result = $data->chain( $this->onResolved );
|
||||
} else {
|
||||
$result = call_user_func( $this->onResolved, $data );
|
||||
}
|
||||
if ( $this->next ) {
|
||||
if ( $result && ! $result instanceof Left ) {
|
||||
return $this->next->resolve( $result );
|
||||
} else {
|
||||
return $this->next->reject( $result );
|
||||
}
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function reject( $data ) {
|
||||
$result = $data;
|
||||
if ( $this->onReject ) {
|
||||
if ( $data instanceof Either ) {
|
||||
$result = $data->orElse( $this->onReject )->join();
|
||||
} else {
|
||||
$result = call_user_func( $this->onReject, $data );
|
||||
}
|
||||
}
|
||||
if ( $this->next ) {
|
||||
return $this->next->reject( $result );
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Promise
|
||||
*/
|
||||
public function then( callable $fn ) {
|
||||
$this->onResolved = $fn;
|
||||
$this->next = new Promise();
|
||||
|
||||
return $this->next;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Promise
|
||||
*/
|
||||
public function onError( callable $fn ) {
|
||||
$this->onReject = $fn;
|
||||
$this->next = new Promise();
|
||||
|
||||
return $this->next;
|
||||
}
|
||||
|
||||
}
|
||||
69
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Relation.php
vendored
Normal file
69
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Relation.php
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable|bool equals( ...$a, ...$b ) - Curried :: a->b->bool
|
||||
* @method static callable|bool lt( ...$a, ...$b ) - Curried :: a->b->bool
|
||||
* @method static callable|bool lte( ...$a, ...$b ) - Curried :: a->b->bool
|
||||
* @method static callable|bool gt( ...$a, ...$b ) - Curried :: a->b->bool
|
||||
* @method static callable|bool gte( ...$a, ...$b ) - Curried :: a->b->bool
|
||||
* @method static callable|bool propEq( ...$prop, ...$value, ...$obj ) - Curried :: String → a → array → bool
|
||||
* @method static callable|array sortWith( ...$comparators, ...$array ) - Curried :: [(a, a) → int] → [a] → [a]
|
||||
*/
|
||||
class Relation {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'equals', curryN( 2, function ( $a, $b ) {
|
||||
return $a === $b;
|
||||
} ) );
|
||||
|
||||
self::macro( 'lt', curryN( 2, function ( $a, $b ) {
|
||||
if ( is_string( $a ) && is_string( $b ) ) {
|
||||
return strcmp( $a, $b ) < 0;
|
||||
}
|
||||
|
||||
return $a < $b;
|
||||
} ) );
|
||||
|
||||
self::macro( 'gt', curryN( 2, function ( $a, $b ) {
|
||||
return self::lt( $b, $a );
|
||||
} ) );
|
||||
|
||||
self::macro( 'lte', curryN( 2, function ( $a, $b ) {
|
||||
return ! self::gt( $a, $b );
|
||||
} ) );
|
||||
|
||||
self::macro( 'gte', curryN( 2, function ( $a, $b ) {
|
||||
return ! self::lt( $a, $b );
|
||||
} ) );
|
||||
|
||||
self::macro( 'propEq', curryN( 3, function ( $prop, $value, $obj ) {
|
||||
return Obj::prop( $prop, $obj ) === $value;
|
||||
} ) );
|
||||
|
||||
self::macro( 'sortWith', curryN( 2, function ( $comparators, $array ) {
|
||||
$compareFn = function( $a, $b ) use ( $comparators ) {
|
||||
foreach ( $comparators as $comparator ) {
|
||||
$v = $comparator( $a, $b );
|
||||
if ( $v !== 0 ) {
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
return Lst::sort( $compareFn, $array );
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Relation::init();
|
||||
127
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Strings.php
vendored
Normal file
127
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Strings.php
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static string tail( string ...$str ) - Curried :: string->string
|
||||
* @method static array split( ...$delimiter, ...$str ) - Curried :: string->string->string
|
||||
* @method static callable|array parse( ...$string ) - Curried :: string → array
|
||||
* @method static callable|bool includes( ...$needle, ...$str ) - Curried :: string → string → bool
|
||||
* @method static callable|string trim( ...$trim, ...$str ) - Curried :: string → string → string
|
||||
* @method static callable|string trimPrefix( ...$trim, ...$str ) - Curried :: string → string → string
|
||||
*
|
||||
* Trims the prefix from the start of the string if the prefix exists
|
||||
*
|
||||
* ```
|
||||
* $trimmed = Str::trimPrefix( 'prefix-', 'prefix-test' );
|
||||
* ```
|
||||
*
|
||||
* @method static callable|string concat( ...$a, ...$b ) - Curried :: string → string → string
|
||||
* @method static callable|string sub( ...$start, ...$str ) - Curried :: int → string → string
|
||||
* @method static callable|string startsWith( ...$test, ...$str ) - Curried :: string → string → bool
|
||||
* @method static callable|string endsWith( ...$test, ...$str ) - Curried :: string → string → bool
|
||||
* @method static callable|int pos( ...$test, ...$str ) - Curried :: string → string → int
|
||||
* @method static callable|int len( ...$str ) - Curried :: string → int
|
||||
* @method static callable|string replace( ...$find, ...$replace, ...$str ) - Curried :: string → string → string → string
|
||||
* @method static callable|string pregReplace( ...$pattern, ...$replace, ...$str ) - Curried :: string → string → string → string
|
||||
* @method static callable|string match( ...$pattern, ...$str ) - Curried :: string → string → array
|
||||
* @method static callable|string matchAll( ...$pattern, ...$str ) - Curried :: string → string → array
|
||||
* @method static callable|string wrap( ...$before, ...$after, ...$str ) - Curried :: string → string → string
|
||||
* @method static callable|string toUpper( string ...$str ) - Curried :: string → string
|
||||
* @method static callable|string toLower( string ...$str ) - Curried :: string → string
|
||||
*
|
||||
* Wraps a string inside 2 other strings
|
||||
*
|
||||
* ```
|
||||
* $wrapsInDiv = Str::wrap( '<div>', '</div>' );
|
||||
* $wrapsInDiv( 'To be wrapped' ); // '<div>To be wrapped</div>'
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
class Str {
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'split', curryN( 2, 'explode' ) );
|
||||
|
||||
self::macro( 'parse', curryN( 1, function( $string ) {
|
||||
parse_str( $string, $parsedString );
|
||||
return $parsedString;
|
||||
} ) );
|
||||
|
||||
self::macro( 'trim', curryN( 2, flip( 'trim' ) ) );
|
||||
|
||||
self::macro( 'trimPrefix', curryN( 2, function( $prefix, $str ) {
|
||||
return $prefix && self::pos( $prefix, $str ) === 0 ? self::sub( self::len( $prefix ), $str ) : $str;
|
||||
} ) );
|
||||
|
||||
self::macro( 'concat', curryN( 2, function ( $a, $b ) {
|
||||
return $a . $b;
|
||||
} ) );
|
||||
|
||||
self::macro( 'sub', curryN( 2, function( $start, $string ) {
|
||||
if ( function_exists( 'mb_substr' ) ) {
|
||||
return mb_substr( $string, $start );
|
||||
}
|
||||
|
||||
return substr( $string, $start );
|
||||
} ) );
|
||||
|
||||
self::macro( 'tail', self::sub( 1 ) );
|
||||
|
||||
self::macro( 'pos', curryN( 2, function( $needle, $haystack ) {
|
||||
if ( function_exists( 'mb_strpos' ) ) {
|
||||
return mb_strpos( $haystack, $needle );
|
||||
}
|
||||
|
||||
return strpos( $haystack, $needle );
|
||||
} ) );
|
||||
|
||||
self::macro( 'startsWith', curryN( 2, pipe( self::pos(), Relation::equals( 0 ) ) ) );
|
||||
|
||||
self::macro( 'endsWith', curryN( 2, function ( $find, $s ) {
|
||||
return self::sub( - self::len( $find ), $s ) === $find;
|
||||
} ) );
|
||||
|
||||
self::macro( 'includes', curryN( 2, pipe( self::pos(), Logic::complement( Relation::equals( false ) ) ) ) );
|
||||
|
||||
self::macro( 'len', curryN( 1, function_exists( 'mb_strlen' ) ? 'mb_strlen' : 'strlen' ) );
|
||||
|
||||
|
||||
self::macro( 'replace', curryN( 3, function ( $search, $replace, $subject ) {
|
||||
return str_replace( $search, $replace, $subject );
|
||||
} ) );
|
||||
|
||||
self::macro( 'pregReplace', curryN( 3, function ( $pattern, $replace, $subject ) {
|
||||
return preg_replace( $pattern, $replace, $subject );
|
||||
} ) );
|
||||
|
||||
self::macro( 'match', curryN( 2, function ( $pattern, $subject ) {
|
||||
$matches = [];
|
||||
|
||||
return preg_match( $pattern, $subject, $matches ) ? $matches : [];
|
||||
} ) );
|
||||
|
||||
self::macro( 'matchAll', curryN( 2, function ( $pattern, $subject ) {
|
||||
$matches = [];
|
||||
|
||||
return preg_match_all( $pattern, $subject, $matches, PREG_SET_ORDER ) ? $matches : [];
|
||||
} ) );
|
||||
|
||||
self::macro( 'wrap', curryN( 3, function ( $before, $after, $string ) {
|
||||
return $before . $string . $after;
|
||||
} ) );
|
||||
|
||||
self::macro( 'toUpper', curryN( 1, 'strtoupper' ) );
|
||||
|
||||
self::macro( 'toLower', curryN( 1, 'strtolower' ) );
|
||||
}
|
||||
}
|
||||
|
||||
Str::init();
|
||||
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/SystemClass.php
vendored
Normal file
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/SystemClass.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\System;
|
||||
|
||||
use WPML\FP\Either;
|
||||
|
||||
class System {
|
||||
|
||||
/**
|
||||
* @return \Closure
|
||||
*/
|
||||
public static function getPostData() {
|
||||
return function() { return Either::right( wpml_collect( $_POST ) ); };
|
||||
}
|
||||
}
|
||||
107
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Type.php
vendored
Normal file
107
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Type.php
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
|
||||
/**
|
||||
* @method static callable|bool isNull( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isBool( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isInt( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isNumeric( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isFloat( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isString( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isScalar( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isArray( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isObject( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isCallable( mixed ...$v ) - Curried :: mixed->bool
|
||||
*
|
||||
* @method static callable|bool isSerialized( mixed ...$v ) - Curried :: mixed->bool
|
||||
* @method static callable|bool isJson( mixed ...$v ) - Curried :: mixed->bool
|
||||
*/
|
||||
class Type {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
// Built-in PHP functions
|
||||
self::macro( 'isNull', curryN( 1, 'is_null' ) );
|
||||
self::macro( 'isBool', curryN( 1, 'is_bool' ) );
|
||||
self::macro( 'isInt', curryN( 1, 'is_int' ) );
|
||||
self::macro( 'isNumeric', curryN( 1, 'is_numeric' ) );
|
||||
self::macro( 'isFloat', curryN( 1, 'is_float' ) );
|
||||
self::macro( 'isString', curryN( 1, 'is_string' ) );
|
||||
self::macro( 'isScalar', curryN( 1, 'is_scalar' ) );
|
||||
self::macro( 'isArray', curryN( 1, 'is_array' ) );
|
||||
self::macro( 'isObject', curryN( 1, 'is_object' ) );
|
||||
self::macro( 'isCallable', curryN( 1, 'is_callable' ) );
|
||||
|
||||
/**
|
||||
* Inspired by WordPress function `is_serialized`.
|
||||
*
|
||||
* @see is_serialized()
|
||||
*/
|
||||
self::macro( 'isSerialized', curryN( 1, function( $data ) {
|
||||
// If it isn't a string, it isn't serialized.
|
||||
if ( ! is_string( $data ) ) {
|
||||
return false;
|
||||
}
|
||||
$data = trim( $data );
|
||||
if ( 'N;' === $data ) {
|
||||
return true;
|
||||
}
|
||||
if ( strlen( $data ) < 4 ) {
|
||||
return false;
|
||||
}
|
||||
if ( ':' !== $data[1] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lastc = substr( $data, -1 );
|
||||
if ( ';' !== $lastc && '}' !== $lastc ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$token = $data[0];
|
||||
switch ( $token ) {
|
||||
case 's':
|
||||
if ( '"' !== substr( $data, -2, 1 ) ) {
|
||||
return false;
|
||||
}
|
||||
// Or else fall through.
|
||||
case 'a':
|
||||
case 'O':
|
||||
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
|
||||
case 'b':
|
||||
case 'i':
|
||||
case 'd':
|
||||
return (bool) preg_match( "/^{$token}:[0-9.E+-]+;$/", $data );
|
||||
}
|
||||
return false;
|
||||
} ) );
|
||||
|
||||
/**
|
||||
* Inspired by WP-CLI function.
|
||||
*
|
||||
* @see \WP_CLI\Utils\is_json()
|
||||
*/
|
||||
self::macro( 'isJson', curryN( 1, function( $value ) {
|
||||
if ( ! $value || ! is_string( $value ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! in_array( $value[0], [ '{', '[' ], true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
json_decode( $value, true );
|
||||
|
||||
return json_last_error() === JSON_ERROR_NONE;
|
||||
} ) );
|
||||
}
|
||||
}
|
||||
|
||||
Type::init();
|
||||
14
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Undefined.php
vendored
Normal file
14
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Undefined.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
/**
|
||||
* Class Undefined
|
||||
* @package WPML\FP
|
||||
*
|
||||
* Class represents Undefined value. It let us handle correctly expected, but falsy values like null, 0 or false.
|
||||
*/
|
||||
class Undefined {
|
||||
|
||||
}
|
||||
65
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Validator.php
vendored
Normal file
65
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Validator.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\System;
|
||||
|
||||
use WPML\Collect\Support\Collection;
|
||||
use WPML\FP\Either;
|
||||
|
||||
class _Validator {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $key;
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
private $fn;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $error;
|
||||
|
||||
/**
|
||||
* _Validator constructor.
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
public function __construct( $key ) {
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return _Validator
|
||||
*/
|
||||
public function using( callable $fn ) {
|
||||
$this->fn = $fn;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $error
|
||||
*
|
||||
* @return _Validator
|
||||
*/
|
||||
public function error( $error ) {
|
||||
$this->error = $error;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WPML\Collect\Support\Collection<mixed> $collection
|
||||
*
|
||||
* @return callable|\WPML\FP\Either
|
||||
*/
|
||||
public function __invoke( Collection $collection ) {
|
||||
return call_user_func( $this->fn, $collection->get( $this->key ) )
|
||||
? Either::right( $collection )
|
||||
: Either::left( value( $this->error ) );
|
||||
}
|
||||
}
|
||||
|
||||
57
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Wrapper.php
vendored
Normal file
57
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Wrapper.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use WPML\FP\Functor\Functor;
|
||||
use WPML\FP\Functor\Pointed;
|
||||
|
||||
class Wrapper {
|
||||
use Functor;
|
||||
use Pointed;
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Wrapper
|
||||
*/
|
||||
public function map( callable $fn ) {
|
||||
return self::of( $fn( $this->value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function filter( $fn = null ) {
|
||||
$fn = $fn ?: Fns::identity();
|
||||
return $fn( $this->value ) ? $this->value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function join() {
|
||||
if( ! $this->value instanceof Wrapper ) {
|
||||
return $this->value;
|
||||
}
|
||||
return $this->value->join();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Wrapper
|
||||
*/
|
||||
public function ap( $value ) {
|
||||
return self::of( call_user_func( $this->value, $value ) ); // $this->value should be callable and curried
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function get() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
285
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/functions.php
vendored
Normal file
285
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/functions.php
vendored
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
/**
|
||||
* Wraps the given function and returns a function that can take arguments as an array and invokes
|
||||
* the wrapped function with individual arguments
|
||||
*
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function spreadArgs( callable $fn ) {
|
||||
return function ( $args ) use ( $fn ) {
|
||||
return $fn( ...$args );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given function and returns a function that can take individual arguments and invokes
|
||||
* the wrapped function with individual arguments gathered into an array
|
||||
*
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function gatherArgs( callable $fn ) {
|
||||
return function ( ...$args ) use ( $fn ) {
|
||||
return $fn( $args );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new function which applies each given function to the result of another from right to left
|
||||
* compose(f, g, h)(x) is the same as f(g(h(x)))
|
||||
*
|
||||
* @param callable $f
|
||||
* @param callable $g
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function compose( callable $f, callable $g ) {
|
||||
$functions = func_get_args();
|
||||
|
||||
return function () use ( $functions ) {
|
||||
$args = func_get_args();
|
||||
foreach ( array_reverse( $functions ) as $function ) {
|
||||
$args = array( call_user_func_array( $function, $args ) );
|
||||
}
|
||||
|
||||
return current( $args );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new function which applies each given function to the result of another from left to right
|
||||
* pipe(f, g, h)(x) is the same as h(g(f(x)))
|
||||
*
|
||||
* @param callable $f
|
||||
* @param callable $g
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function pipe( callable $f, callable $g ) {
|
||||
return call_user_func_array( 'WPML\FP\compose', array_reverse( func_get_args() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new function which will behave like $function with
|
||||
* predefined left arguments passed to partial
|
||||
*
|
||||
* @param callable $function
|
||||
* @param mixed $arg1
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function partial( callable $function, $arg1 ) {
|
||||
$args = array_slice( func_get_args(), 1 );
|
||||
|
||||
return function () use ( $function, $args ) {
|
||||
return call_user_func_array( $function, array_merge( $args, func_get_args() ) );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new partial function which will behave like $function with
|
||||
* predefined right arguments passed to partialRight
|
||||
*
|
||||
* @param callable $function
|
||||
* @param mixed $arg1
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function partialRight( callable $function, $arg1 ) {
|
||||
$args = array_slice( func_get_args(), 1 );
|
||||
|
||||
return function () use ( $function, $args ) {
|
||||
return call_user_func_array( $function, array_merge( func_get_args(), $args ) );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function tap( callable $fn ) {
|
||||
return function ( $value ) use ( $fn ) {
|
||||
$fn( $value );
|
||||
|
||||
return $value;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $f
|
||||
* @param callable $g
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function either( callable $f, callable $g ) {
|
||||
return function ( $value ) use ( $f, $g ) {
|
||||
return $f( $value ) || $g( $value );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function curryN( $count, Callable $fn ) {
|
||||
$accumulator = function ( array $arguments ) use ( $count, $fn, &$accumulator ) {
|
||||
return function () use ( $count, $fn, $arguments, $accumulator ) {
|
||||
$oldArguments = $arguments;
|
||||
$arguments = array_merge( $arguments, func_get_args() );
|
||||
|
||||
$replacementIndex = count( $oldArguments );
|
||||
for ( $i = 0; $i < $replacementIndex; $i ++ ) {
|
||||
if ( count( $arguments ) <= $replacementIndex ) {
|
||||
break;
|
||||
}
|
||||
if ( $arguments[ $i ] === Fns::__ ) {
|
||||
$arguments[ $i ] = $arguments[ $replacementIndex ];
|
||||
unset( $arguments[ $replacementIndex ] );
|
||||
$arguments = array_values( $arguments );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! in_array( Fns::__, $arguments, true ) && $count <= count( $arguments ) ) {
|
||||
return call_user_func_array( $fn, $arguments );
|
||||
}
|
||||
|
||||
return $accumulator( $arguments );
|
||||
};
|
||||
};
|
||||
|
||||
return $accumulator( [] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
* @param bool $required
|
||||
*
|
||||
* @return \Closure
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
function curry( callable $fn, $required = true ) {
|
||||
if ( is_string( $fn ) && strpos( $fn, '::', 1 ) !== false ) {
|
||||
$reflection = new \ReflectionMethod( $fn );
|
||||
} else if ( is_array( $fn ) && count( $fn ) == 2 ) {
|
||||
$reflection = new \ReflectionMethod( $fn[0], $fn[1] );
|
||||
} else if ( is_object( $fn ) && method_exists( $fn, '__invoke' ) ) {
|
||||
$reflection = new \ReflectionMethod( $fn, '__invoke' );
|
||||
} else {
|
||||
$reflection = new \ReflectionFunction( $fn );
|
||||
}
|
||||
|
||||
$count = $required ? $reflection->getNumberOfRequiredParameters() : $reflection->getNumberOfParameters();
|
||||
|
||||
return curryN( $count, $fn );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fnName
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function apply( $fnName ) {
|
||||
$args = array_slice( func_get_args(), 1 );
|
||||
|
||||
return function ( $container ) use ( $fnName, $args ) {
|
||||
return call_user_func_array( [ $container, $fnName ], $args );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Invoker that runs the member function. Use `with` to set the arguments
|
||||
* of the member function and then invoke with `()`
|
||||
*
|
||||
* eg. give Test class:
|
||||
* class Test {
|
||||
*
|
||||
* private $times;
|
||||
*
|
||||
* public function __construct( $times ) {
|
||||
* $this->times = $times;
|
||||
* }
|
||||
*
|
||||
* public function multiply( $x ) {
|
||||
* return $x * $this->times;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* $invoker = invoke( 'multiply' )->with( 10 );
|
||||
* $result = $invoker( new Test( 2 ) ); // 20
|
||||
*
|
||||
*
|
||||
* @param string $fnName
|
||||
*
|
||||
* @return _Invoker
|
||||
*/
|
||||
function invoke( $fnName ) {
|
||||
return new _Invoker( $fnName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function chain( callable $fn ) {
|
||||
return function ( $container ) use ( $fn ) {
|
||||
if ( method_exists( $container, 'chain' ) ) {
|
||||
return $container->chain( $fn );
|
||||
} elseif ( method_exists( $container, 'flatMap' ) ) {
|
||||
return $container->flatMap( $fn );
|
||||
} elseif ( method_exists( $container, 'join' ) ) {
|
||||
return $container->map( $fn )->join();
|
||||
} else {
|
||||
throw new \Exception( 'chainable method not found' );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function flatMap( callable $fn ) {
|
||||
return chain( $fn );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return Either
|
||||
*/
|
||||
function tryCatch( callable $fn ) {
|
||||
try {
|
||||
return Right::of( $fn() );
|
||||
} catch ( \Exception $e ) {
|
||||
return Either::left( $e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function flip( callable $fn ) {
|
||||
return function () use ( $fn ) {
|
||||
$args = func_get_args();
|
||||
if ( count( $args ) > 1 ) {
|
||||
$temp = $args[0];
|
||||
$args[0] = $args[1];
|
||||
$args[1] = $temp;
|
||||
}
|
||||
|
||||
return call_user_func_array( $fn, $args );
|
||||
};
|
||||
}
|
||||
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/All.php
vendored
Normal file
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/All.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Monoid;
|
||||
|
||||
class All extends Monoid {
|
||||
|
||||
public static function _concat( $a, $b ) {
|
||||
return $a && $b;
|
||||
}
|
||||
|
||||
public static function mempty() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
14
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/Any.php
vendored
Normal file
14
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/Any.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Monoid;
|
||||
|
||||
class Any extends Monoid {
|
||||
|
||||
public static function _concat( $a, $b ) {
|
||||
return $a || $b;
|
||||
}
|
||||
|
||||
public static function mempty() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
17
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/Monoid.php
vendored
Normal file
17
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/Monoid.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Monoid;
|
||||
|
||||
use WPML\FP\Fns;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
abstract class Monoid {
|
||||
|
||||
public static function concat( $a = null, $b = null ) {
|
||||
return call_user_func_array( curryN( 2, [ static::class, '_concat' ] ), func_get_args() );
|
||||
}
|
||||
|
||||
public static function of( array $array = null ) {
|
||||
return call_user_func_array( Fns::reduce( self::concat(), static::mempty() ), func_get_args() );
|
||||
}
|
||||
}
|
||||
14
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/Str.php
vendored
Normal file
14
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/Str.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Monoid;
|
||||
|
||||
class Str extends Monoid {
|
||||
public static function _concat( $a, $b ) {
|
||||
return $a . $b;
|
||||
}
|
||||
|
||||
public static function mempty() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/Sum.php
vendored
Normal file
15
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/monoid/Sum.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Monoid;
|
||||
|
||||
class Sum extends Monoid {
|
||||
|
||||
public static function _concat( $a, $b ) {
|
||||
return $a + $b;
|
||||
}
|
||||
|
||||
public static function mempty() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
59
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/strings_functions.php
vendored
Normal file
59
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/strings_functions.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\Strings;
|
||||
|
||||
use function WPML\FP\partial;
|
||||
use function WPML\FP\partialRight;
|
||||
use function WPML\FP\pipe;
|
||||
|
||||
/**
|
||||
* ltrimWith :: string -> ( string -> string )
|
||||
* @param string $trim
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function ltrimWith( $trim ) {
|
||||
return partialRight( 'ltrim', $trim );
|
||||
}
|
||||
|
||||
/**
|
||||
* rtrimWith :: string -> ( string -> string )
|
||||
* @param string $trim
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function rtrimWith( $trim ) {
|
||||
return partialRight( 'rtrim', $trim );
|
||||
}
|
||||
|
||||
/**
|
||||
* explodeToCollection :: string -> ( string -> Collection )
|
||||
* @param string $delimiter
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function explodeToCollection( $delimiter ) {
|
||||
return pipe( partial( 'explode', $delimiter ), 'wpml_collect' );
|
||||
}
|
||||
|
||||
/**
|
||||
* replace :: string -> string -> ( string -> string )
|
||||
* @param string $search
|
||||
* @param string $replace
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function replace( $search, $replace ) {
|
||||
return partial( 'str_replace', $search, $replace );
|
||||
}
|
||||
|
||||
/**
|
||||
* remove :: string -> ( string -> string )
|
||||
* @param string $remove
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
function remove( $remove ) {
|
||||
return partial( 'str_replace', $remove, '' );
|
||||
}
|
||||
|
||||
64
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/system.php
vendored
Normal file
64
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/system.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\FP\System;
|
||||
|
||||
/**
|
||||
* Returns a filter function to filter a collection by the given key
|
||||
* Use like:
|
||||
* $theCollection->map( getFilterFor( 'my-key' )->using( santatizeString() )->defaultTo( '' ) )
|
||||
* This will filter the collection item with a key of 'my-key' using the 'FILTER_SANITIZE_STRING'.
|
||||
* If the key doesn't exist it defaults to an empty string.
|
||||
*
|
||||
* defaultTo can be a value or a callable that returns a value
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return _Filter
|
||||
*/
|
||||
function getFilterFor( $key ) {
|
||||
return new _Filter( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a function of the defined type that can then be used to map
|
||||
* over a variable.
|
||||
*
|
||||
* @param int $filter - Filter type same as for php filter_var function
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
function filterVar( $filter ) {
|
||||
return function ( $var ) use ( $filter ) {
|
||||
return filter_var( $var, $filter );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a function that will sanitize a string.
|
||||
* @return \Closure
|
||||
*/
|
||||
function sanitizeString( $flags = ENT_QUOTES ) {
|
||||
return function( $value ) use ( $flags ) {
|
||||
return is_string( $value ) || is_numeric( $value )
|
||||
? str_replace( '&', '&', htmlspecialchars( strip_tags( $value ), $flags ) ) : false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a validator function to filter a collection by the given key
|
||||
* Use like:
|
||||
* map( getValidatorFor( 'my-key' )->using( Logic::isNotNull() )->error( 'It was false' ) ), $myCollection)
|
||||
* This will run the validator on the collection item with a key of 'my-key' and return Either::Right
|
||||
* containing the given collection or Either::Left containing the error depending if the supplied
|
||||
* using function returns true or false
|
||||
*
|
||||
* error can be a value or a callable that returns a value
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return _Validator
|
||||
*/
|
||||
function getValidatorFor( $key ) {
|
||||
return new _Validator( $key );
|
||||
}
|
||||
|
||||
106
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/traits/Curryable.php
vendored
Normal file
106
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/traits/Curryable.php
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace WPML\FP;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Closure;
|
||||
|
||||
trait Curryable {
|
||||
/**
|
||||
* The registered string curried methods.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $curried = [];
|
||||
|
||||
/**
|
||||
* Register a custom curried function.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $argCount
|
||||
* @param callable $fn
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function curryN( $name, $argCount, callable $fn ) {
|
||||
static::$curried[ $name ] = [ $argCount, $fn ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if curried function is registered.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasCurry( $name ) {
|
||||
return isset( static::$curried[ $name ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically handle calls to the class.
|
||||
*
|
||||
* @param string $method
|
||||
* @param mixed[] $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public static function __callStatic( $method, $parameters ) {
|
||||
if ( ! static::hasCurry( $method ) ) {
|
||||
throw new BadMethodCallException( "Method {$method} does not exist." );
|
||||
}
|
||||
|
||||
if ( static::$curried[ $method ][1] instanceof Closure ) {
|
||||
return call_user_func_array( self::curryItStaticCall( ...static::$curried[ $method ] ), $parameters );
|
||||
}
|
||||
|
||||
return call_user_func_array( static::$curried[ $method ][1], $parameters );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically handle calls to the class.
|
||||
*
|
||||
* @param string $method
|
||||
* @param mixed[] $parameters
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __call( $method, $parameters ) {
|
||||
throw new BadMethodCallException( "Curryable does not support methods in object scope. This is a limitation of PHP 5.x." );
|
||||
if ( ! static::hasCurry( $method ) ) {
|
||||
throw new BadMethodCallException( "Method {$method} does not exist." );
|
||||
}
|
||||
|
||||
if ( static::$curried[ $method ][1] instanceof Closure ) {
|
||||
return call_user_func_array( $this->curryItCall( ...self::$curried[ $method ] ), $parameters );
|
||||
}
|
||||
|
||||
return call_user_func_array( static::$curried[ $method ][1], $parameters );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @param \Closure $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
private function curryItCall( $count, Closure $fn ) {
|
||||
return curryN( $count, $fn->bindTo( $this, static::class ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @param \Closure $fn
|
||||
*
|
||||
* @return \Closure
|
||||
*/
|
||||
private static function curryItStaticCall( $count, Closure $fn ) {
|
||||
return curryN( $count, Closure::bind( $fn, null, static::class ) );
|
||||
}
|
||||
|
||||
}
|
||||
4132
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/docs/README.md
vendored
Normal file
4132
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/docs/README.md
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/README.md
vendored
Normal file
2
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/README.md
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# WP
|
||||
|
||||
48
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Attachment.php
vendored
Normal file
48
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Attachment.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\FP\Logic;
|
||||
use WPML\FP\Str;
|
||||
use function WPML\FP\pipe;
|
||||
|
||||
class Attachment {
|
||||
|
||||
private static $withOutSizeRegEx = '/-\d+[Xx]\d+\./';
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return int|null The found post ID, or null on failure.
|
||||
*/
|
||||
public static function idFromUrl( $url ) {
|
||||
$removeSize = Str::pregReplace( self::$withOutSizeRegEx, '.' );
|
||||
|
||||
return Logic::firstSatisfying(
|
||||
function ( $id ) { return $id !== 0; },
|
||||
[
|
||||
'attachment_url_to_postid',
|
||||
pipe( $removeSize, 'attachment_url_to_postid' ),
|
||||
[ self::class, 'idByGuid' ],
|
||||
pipe( $removeSize, [ self::class, 'idByGuid' ] ),
|
||||
],
|
||||
$url
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return int The found post ID, or 0 on failure.
|
||||
*/
|
||||
public static function idByGuid( $url ) {
|
||||
global $wpdb;
|
||||
|
||||
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s'", $url ) );
|
||||
|
||||
return $attachment && count( $attachment )
|
||||
? $attachment[0]
|
||||
: 0;
|
||||
}
|
||||
|
||||
}
|
||||
80
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Cache.php
vendored
Normal file
80
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Cache.php
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Maybe;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
/**
|
||||
* Class Cache
|
||||
* @package WPML\LIB\WP
|
||||
* @method static callable|mixed memorize( ...$group, ...$fn ) :: string → callable → mixed
|
||||
* @method static callable|mixed memorizeWithCheck( ...$group, ...$checkingFn, ...$fn ) :: string → callable → callable → mixed
|
||||
* @method static callable|bool set( ...$group, ...$key, ...$value ) :: string → string → mixed → bool
|
||||
* @method static callable|Maybe get( ...$group, ...$key ) :: string → string → Nothing | Just( mixed )
|
||||
*/
|
||||
class Cache {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'get', curryN( 2, [ self::class, 'getInternal' ] ) );
|
||||
self::macro( 'set', curryN( 3, [ self::class, 'setInternal' ] ) );
|
||||
|
||||
self::macro( 'memorizeWithCheck', curryN( 3, function ( $group, $checkingFn, $fn ) {
|
||||
return function () use ( $fn, $group, $checkingFn ) {
|
||||
$args = func_get_args();
|
||||
$key = serialize( $args );
|
||||
|
||||
$result = Cache::get( $group, $key );
|
||||
if ( Fns::isNothing( $result ) || ! $checkingFn( $result->get() ) ) {
|
||||
$result = call_user_func_array( $fn, $args );
|
||||
Cache::set( $group, $key, $result );
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result->get();
|
||||
};
|
||||
} ) );
|
||||
|
||||
self::macro( 'memorize', self::memorizeWithCheck( Fns::__, Fns::always( true ), Fns::__ ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
* @param string $key
|
||||
*
|
||||
* @return \WPML\FP\Just|\WPML\FP\Nothing
|
||||
*/
|
||||
public static function getInternal( $group, $key ) {
|
||||
$found = false;
|
||||
$result = wp_cache_get( $key, $group, false, $found );
|
||||
|
||||
if( $found && is_array( $result ) && array_key_exists( 'data', $result ) ) {
|
||||
return Maybe::just( $result['data'] );
|
||||
}
|
||||
|
||||
return Maybe::nothing();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool|true
|
||||
*/
|
||||
public static function setInternal( $group, $key, $value ) {
|
||||
// Save $value in an array. We need to do this because W3TC and Redis have bug with saving null.
|
||||
return wp_cache_set( $key, [ 'data' => $value ], $group );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Cache::init();
|
||||
30
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Gutenberg.php
vendored
Normal file
30
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Gutenberg.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\FP\Curryable;
|
||||
use WPML\FP\Logic;
|
||||
use WPML\FP\Str;
|
||||
|
||||
/**
|
||||
* @method static callable|bool hasBlock( ...$string ) - Curried :: string → bool
|
||||
* @method static callable|bool doesNotHaveBlock( ...$string ) - Curried :: string → bool
|
||||
* @method static callable|bool stripBlockData( ...$string ) - Curried :: string → string
|
||||
*/
|
||||
class Gutenberg {
|
||||
use Curryable;
|
||||
|
||||
const GUTENBERG_OPENING_START = '<!-- wp:';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::curryN( 'hasBlock', 1, Str::includes( self::GUTENBERG_OPENING_START ) );
|
||||
self::curryN( 'doesNotHaveBlock', 1, Logic::complement( self::hasBlock() ) );
|
||||
self::curryN( 'stripBlockData', 1, Str::pregReplace( '(<!--\s*/?wp:[^<]*-->)', '' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Gutenberg::init();
|
||||
77
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Hooks.php
vendored
Normal file
77
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Hooks.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\FP\Either;
|
||||
use WPML\FP\Lst;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\FP\Promise;
|
||||
use function WPML\FP\pipe;
|
||||
|
||||
class Hooks {
|
||||
|
||||
/**
|
||||
* @param string|string[] $action
|
||||
* @param int $priority
|
||||
* @param int $accepted_args
|
||||
*
|
||||
* @return \WPML\FP\Promise
|
||||
*/
|
||||
public static function onAction( $action, $priority = 10, $accepted_args = 1 ) {
|
||||
return self::onHook( 'add_action', $action, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|string[] $filter
|
||||
* @param int $priority
|
||||
* @param int $accepted_args
|
||||
*
|
||||
* @return \WPML\FP\Promise
|
||||
*/
|
||||
public static function onFilter( $filter, $priority = 10, $accepted_args = 1 ) {
|
||||
return self::onHook( 'add_filter', $filter, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $fn
|
||||
* @param string|string[] $actionOrFilter
|
||||
* @param int $priority
|
||||
* @param int $accepted_args
|
||||
*
|
||||
* @return \WPML\FP\Promise
|
||||
*/
|
||||
public static function onHook( callable $fn, $actionOrFilter, $priority = 10, $accepted_args = 1 ) {
|
||||
|
||||
$actionsOrFilters = is_array( $actionOrFilter ) ? $actionOrFilter : [ $actionOrFilter ];
|
||||
|
||||
$promise = new Promise();
|
||||
|
||||
$callback = function () use ( $promise ) {
|
||||
return $promise->resolve( Either::right( func_get_args() ) )->getOrElse( null );
|
||||
};
|
||||
|
||||
foreach ( $actionsOrFilters as $actionOrFilter ) {
|
||||
$fn( $actionOrFilter, $callback, $priority, $accepted_args );
|
||||
};
|
||||
|
||||
return $promise;
|
||||
}
|
||||
|
||||
public static function callWithFilter( $fn, $name, $filterFn, $priority = 10, $acceptedArgs = 1 ) {
|
||||
add_filter( $name, $filterFn, $priority, $acceptedArgs );
|
||||
$result = $fn();
|
||||
remove_filter( $name, $filterFn, $priority, $acceptedArgs );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getArgs( array $argsLabels ) {
|
||||
return pipe(
|
||||
Obj::pick( Obj::keys( $argsLabels ) ),
|
||||
Obj::values(),
|
||||
Lst::zipObj( Obj::values( $argsLabels ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
29
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Http.php
vendored
Normal file
29
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Http.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Either;
|
||||
use WPML\FP\Fns;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
/**
|
||||
* @method static callable|Either post( ...$url, ...$args ) - Curried :: string → array → Left( WP_Error ) | Right(string)
|
||||
*/
|
||||
class Http {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'post', curryN( 2, function ( $url, $args ) {
|
||||
return WordPress::handleError( Fns::make( \WP_Http::class )->post( $url, $args ) );
|
||||
} ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Http::init();
|
||||
37
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Nonce.php
vendored
Normal file
37
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Nonce.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\Collect\Support\Collection;
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Either;
|
||||
use function WPML\FP\curryN;
|
||||
use function WPML\FP\partial;
|
||||
|
||||
/**
|
||||
* @method static callable|Either verify(string ...$action, Collection ...$data) - Curried :: string -> Collection -> Left('Nonce error') | Right(Collection)
|
||||
* @method static callable|Either verifyEndPoint(Collection ...$data) - Curried :: Collection -> Left('Nonce error') | Right(Collection)
|
||||
* @method static callable|string create(string ...$action ) - Curried :: string -> string
|
||||
*/
|
||||
class Nonce {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'verify', curryN( 2, function ( $action, Collection $postData ) {
|
||||
return wp_verify_nonce( $postData->get( 'nonce' ), $action ?: $postData->get( 'endpoint' ) )
|
||||
? Either::right( $postData )
|
||||
: Either::left( 'Nonce error' );
|
||||
} ) );
|
||||
|
||||
self::macro( 'verifyEndPoint', self::verify( '' ) );
|
||||
|
||||
self::macro( 'create', curryN( 1, function( $str ) { return wp_create_nonce( $str ); } ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Nonce::init();
|
||||
33
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Option.php
vendored
Normal file
33
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Option.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use function WPML\FP\curryN;
|
||||
use function WPML\FP\partialRight;
|
||||
|
||||
/**
|
||||
* @method static callable|mixed get( ...$name ) - Curried :: string → mixed
|
||||
* @method static callable|mixed getOr( ...$name, ...$default ) - Curried :: string → mixed → mixed
|
||||
* @method static callable|bool update( ...$name, ...$value ) - Curried :: string → mixed → bool
|
||||
* @method static callable|bool updateWithoutAutoLoad( ...$name, ...$value ) - Curried :: string → mixed → bool
|
||||
* @method static callable|bool delete( ...$name ) - Curried :: string → bool
|
||||
*/
|
||||
class Option {
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
self::macro( 'get', curryN( 1, 'get_option' ) );
|
||||
self::macro( 'getOr', curryN( 2, 'get_option' ) );
|
||||
|
||||
self::macro( 'update', curryN( 2, 'update_option' ) );
|
||||
self::macro( 'updateWithoutAutoLoad', curryN( 2, partialRight( 'update_option', false ) ) );
|
||||
|
||||
self::macro( 'delete', curryN( 1, 'delete_option' ) );
|
||||
}
|
||||
}
|
||||
|
||||
Option::init();
|
||||
76
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Post.php
vendored
Normal file
76
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Post.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Either;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Logic;
|
||||
use WPML\FP\Lst;
|
||||
use function WPML\FP\curryN;
|
||||
use function WPML\FP\gatherArgs;
|
||||
use function WPML\FP\partialRight;
|
||||
use function WPML\FP\pipe;
|
||||
|
||||
/**
|
||||
* Class Post
|
||||
* @package WPML\LIB\WP
|
||||
* @method static callable|Either getTerms( ...$postId, ...$taxonomy ) - Curried:: int → string → Either false|WP_Error [WP_Term]
|
||||
* @method static callable|mixed getMetaSingle( ...$postId, ...$key ) - Curried :: int → string → mixed
|
||||
* @method static callable|int|bool updateMeta( ...$postId, ...$key, ...$value ) - Curried :: int → string → mixed → int|bool
|
||||
* @method static callable|bool deleteMeta( ...$postId, ...$key ) - Curried :: int → string → bool
|
||||
* @method static callable|string|false getType( ...$postId ) - Curried :: int → string|bool
|
||||
* @method static callable|\WP_Post|null get( ...$postId ) - Curried :: int → \WP_Post|null
|
||||
* @method static callable|string|false getStatus( ...$postId ) - Curried :: int → string|bool
|
||||
* @method static callable|int update(...$data) - Curried :: array -> int
|
||||
* @method static callable|int insert(...$data) - Curried :: array -> int
|
||||
* @method static callable|int setStatus(...$id, ...$status) - Curried :: int -> string -> int
|
||||
* @method static callable|int setStatusWithoutFilters(...$id, ...$status) - Curried :: int -> string -> int
|
||||
* @method static callable|\WP_Post|false|null delete(...$id) - Curried :: int -> \WP_Post|false|null
|
||||
* @method static callable|\WP_Post|false|null trash(...$id) - Curried :: int -> \WP_Post|false|null
|
||||
*/
|
||||
class Post {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'getTerms', curryN( 2, pipe(
|
||||
'get_the_terms',
|
||||
Logic::ifElse( Logic::isArray(), [ Either::class, 'right' ], [ Either::class, 'left' ] )
|
||||
) ) );
|
||||
|
||||
self::macro( 'getMetaSingle', curryN( 2, partialRight( 'get_post_meta', true ) ) );
|
||||
|
||||
self::macro( 'updateMeta', curryN( 3, 'update_post_meta' ) );
|
||||
|
||||
self::macro( 'deleteMeta', curryN( 2, 'delete_post_meta' ) );
|
||||
|
||||
self::macro( 'getType', curryN( 1, 'get_post_type' ) );
|
||||
|
||||
self::macro( 'get', curryN( 1, Fns::unary( 'get_post' ) ) );
|
||||
|
||||
self::macro( 'getStatus', curryN( 1, 'get_post_status' ) );
|
||||
|
||||
self::macro( 'update', curryN( 1, Fns::unary( 'wp_update_post' ) ) );
|
||||
|
||||
self::macro( 'insert', curryN( 1, Fns::unary( 'wp_insert_post' ) ) );
|
||||
|
||||
self::macro( 'setStatus', curryN(2, gatherArgs( pipe( Lst::zipObj( [ 'ID', 'post_status' ] ), self::update() ) ) ) );
|
||||
|
||||
self::macro( 'setStatusWithoutFilters', curryN( 2, function ( $id, $newStatus ) {
|
||||
global $wpdb;
|
||||
|
||||
return $wpdb->update( $wpdb->posts, [ 'post_status' => $newStatus ], [ 'ID' => $id ] ) ? $id : 0;
|
||||
} ) );
|
||||
|
||||
self::macro( 'delete', curryN( 1, partialRight( 'wp_delete_post', true ) ) );
|
||||
|
||||
self::macro( 'trash', curryN( 1, partialRight( 'wp_delete_post', false ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
Post::init();
|
||||
39
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/PostType.php
vendored
Normal file
39
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/PostType.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Just;
|
||||
use WPML\FP\Nothing;
|
||||
use WPML\FP\Maybe;
|
||||
use function WPML\FP\curryN;
|
||||
use WPML\FP\Obj;
|
||||
use function WPML\FP\pipe;
|
||||
|
||||
/**
|
||||
* Class PostType
|
||||
* @package WPML\LIB\WP
|
||||
* @method static callable|int getPublishedCount( ...$postType ) - Curried :: string → int
|
||||
* @method static callable|Just|Nothing getObject( ...$postType ) - Curried :: string → Maybe( WP_Post_Type )|Nothing
|
||||
* @method static callable|Just|Nothing getPluralName( ...$postType ) - Curried :: string → Maybe(string) |Nothing
|
||||
* @method static callable|Just|Nothing getSingularName( ...$postType ) - Curried :: string → Maybe(string) |Nothing
|
||||
*/
|
||||
class PostType {
|
||||
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
|
||||
self::macro( 'getPublishedCount', curryN( 1, pipe( 'wp_count_posts', Obj::propOr( 0, 'publish' ) ) ) );
|
||||
|
||||
self::macro( 'getObject', curryN( 1, pipe( Maybe::of(), Fns::map( 'get_post_type_object' ) ) ) );
|
||||
self::macro( 'getPluralName', curryN( 1, pipe( self::getObject(), Fns::map( Obj::path( [ 'labels', 'name' ] ) ) ) ) );
|
||||
self::macro( 'getSingularName', curryN( 1, pipe( self::getObject(), Fns::map( Obj::path( [ 'labels', 'singular_name' ] ) ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
PostType::init();
|
||||
72
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Resources.php
vendored
Normal file
72
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Resources.php
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP\App;
|
||||
|
||||
use WPML\FP\Fns;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\LIB\WP\Nonce;
|
||||
use WPML\LIB\WP\WordPress;
|
||||
|
||||
class Resources {
|
||||
|
||||
/**
|
||||
* Enqueue a JavaScript application file from the dist directory.
|
||||
*
|
||||
* @param string $app
|
||||
* @param string $pluginBaseUrl
|
||||
* @param string $pluginBasePath
|
||||
* @param string $version
|
||||
* @param null|string $domain
|
||||
* @param null|string[] $localize
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function enqueue( $app, $pluginBaseUrl, $pluginBasePath, $version, $domain = null, $localize = null ) {
|
||||
$handle = "wpml-$app-ui";
|
||||
|
||||
wp_register_script(
|
||||
$handle,
|
||||
"$pluginBaseUrl/dist/js/$app/app.js",
|
||||
[],
|
||||
$version
|
||||
);
|
||||
|
||||
if ( $localize ) {
|
||||
if ( isset( $localize['data']['endpoint'] ) ) {
|
||||
$localize['data']['nonce'] = Nonce::create( $localize['data']['endpoint'] );
|
||||
}
|
||||
if ( isset( $localize['data']['endpoints'] ) ) {
|
||||
$localize = Obj::over(
|
||||
Obj::lensPath( [ 'data', 'endpoints' ] ),
|
||||
Fns::map( function ( $endpoint ) {
|
||||
return [
|
||||
'endpoint' => $endpoint,
|
||||
'nonce' => Nonce::create( $endpoint )
|
||||
];
|
||||
} ),
|
||||
$localize
|
||||
);
|
||||
}
|
||||
wp_localize_script( $handle, $localize['name'], $localize['data'] );
|
||||
}
|
||||
|
||||
wp_enqueue_script( $handle );
|
||||
|
||||
if ( file_exists( "$pluginBasePath/dist/css/$app/styles.css" ) ) {
|
||||
wp_enqueue_style(
|
||||
$handle,
|
||||
"$pluginBaseUrl/dist/css/$app/styles.css",
|
||||
[],
|
||||
$version
|
||||
);
|
||||
}
|
||||
|
||||
if ( $domain && WordPress::versionCompare( '>=', '5.0.0' ) ) {
|
||||
$rootPath = $domain === 'wpml-translation-management' && defined( 'WPML_PLUGIN_PATH' )
|
||||
? WPML_PLUGIN_PATH
|
||||
: $pluginBasePath;
|
||||
|
||||
wp_set_script_translations( $handle, $domain, "$rootPath/locale/jed" );
|
||||
}
|
||||
}
|
||||
}
|
||||
19
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Roles.php
vendored
Normal file
19
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Roles.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\FP\Obj;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
class Roles {
|
||||
|
||||
public static function hasCap( $cap = null, $role = null ) {
|
||||
$hasCap = function ( $cap, $role ) {
|
||||
global $wp_roles;
|
||||
|
||||
return Obj::pathOr( false, [ $role, 'capabilities', $cap ], $wp_roles->roles );
|
||||
};
|
||||
|
||||
return call_user_func_array( curryN( 2, $hasCap ), func_get_args() );
|
||||
}
|
||||
}
|
||||
29
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Transient.php
vendored
Normal file
29
wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/wp/classes/Transient.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\LIB\WP;
|
||||
|
||||
use WPML\Collect\Support\Traits\Macroable;
|
||||
use function WPML\FP\curryN;
|
||||
|
||||
/**
|
||||
* @method static callable|mixed get( ...$name ) - Curried :: string → mixed
|
||||
* @method static callable|mixed getOr( ...$name, ...$default ) - Curried :: string → mixed → mixed
|
||||
* @method static callable|mixed set( ...$name, ...$value, ...$expiration ) - Curried :: string → mixed → int -> mixed
|
||||
* @method static callable|mixed delete( ...$name ) - Curried :: string → mxied
|
||||
*/
|
||||
class Transient {
|
||||
use Macroable;
|
||||
|
||||
public static function init() {
|
||||
self::macro( 'get', curryN( 1, 'get_transient' ) );
|
||||
self::macro( 'getOr', curryN( 2, function ( $key, $default ) {
|
||||
return self::get( $key ) ?: $default;
|
||||
} ) );
|
||||
|
||||
self::macro( 'set', curryN( 3, 'set_transient' ) );
|
||||
self::macro( 'delete', curryN( 1, 'delete_transient' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Transient::init();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user