update plugins

This commit is contained in:
Tony Volpe
2024-06-17 14:42:23 -04:00
parent a00f379f7f
commit 38e314323c
9467 changed files with 2032414 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Template_Library\Templates;
use Gravity_Forms\Gravity_Forms\Template_Library\Templates\GF_Templates_Store;
use Unirest\Exception;
/**
* Class GF_Template_Library_Array_Store
*
* Loads the templates' library data from an array.
*
* @package Gravity_Forms\Gravity_Forms\Template_Library;
*/
class GF_Template_Library_Array_Store implements GF_Templates_Store {
/**
* The templates array.
*
* @since 2.7
*
* @var array $templates The templates array.
*/
protected $templates;
/**
* The store configurations array.
*
* @since 2.7
*
* @var array $config The store configurations array.
*/
protected $config;
/**
* Store constructor.
*
* @param array $config The store configurations array.
*/
public function __construct( $config ) {
$this->config = $config;
}
/**
* Retrieves raw data and decodes it, returns an array of templates.
*
* @since 2.7
*
* @return array
*/
public function get_templates() {
if ( is_array( $this->templates ) ) {
return $this->templates;
}
$uri = rgar( $this->config, 'uri' );
$this->templates = include_once $uri;
return $this->templates;
}
/**
* Returns a template by its ID.
*
* @since 2.7
*
* @param string $id The id of the template.
*
* @return GF_Template_Library_Template|false
*/
public function get( $id ) {
$template_data = rgar( $this->get_templates(), $id );
if ( ! $template_data ) {
return false;
}
return new GF_Template_Library_Template( $template_data );
}
/**
* Returns all the templates, optionally including the form meta.
*
* @since 2.7
*
* @param bool $include_meta whether to include the template form meta or not.
*
* @return array
*/
public function all( $include_meta = false ) {
if ( $include_meta ) {
return $this->get_templates();
}
$templates_data = array_map(
function( $template_data ) {
unset( $template_data['form_meta'] );
unset( $template_data['version'] );
return $template_data;
},
$this->get_templates()
);
return $templates_data;
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Template_Library\Templates;
use Gravity_Forms\Gravity_Forms\Template_Library\Templates\GF_Templates_Store;
use Unirest\Exception;
/**
* Class GF_Template_Library_File_Store
*
* Loads the templates' library data from a JSON file.
*
* @package Gravity_Forms\Gravity_Forms\Template_Library;
*/
class GF_Template_Library_File_Store implements GF_Templates_Store {
/**
* The templates.
*
* @since 2.7
*
* @var mixed $data The templates.
*/
protected $templates;
/**
* The raw data returned from the source.
*
* @since 2.7
*
* @var array $raw_data The raw data returned from the data source.
*/
protected $raw_data;
/**
* The store configurations array.
*
* @since 2.7
*
* @var array $config The store configurations array.
*/
protected $config;
/**
* Store constructor.
*
* @param array $config The store configurations array.
*/
public function __construct( $config ) {
$this->config = $config;
}
/**
* Retrieves raw data and decodes it, returns an array of templates.
*
* @since 2.7
*
* @return array
*/
public function get_templates() {
if ( is_array( $this->templates ) ) {
return $this->templates;
}
$uri = rgar( $this->config, 'uri' );
try {
$this->raw_data = @file_get_contents( $uri );
} catch ( Exception $e ) {
return array();
}
$this->templates = json_decode( $this->raw_data, true );
if ( ! is_array( $this->templates ) ) {
return array();
}
return $this->templates;
}
/**
* Returns a template by its ID.
*
* @since 2.7
*
* @param string $id The id of the template.
*
* @return GF_Template_Library_Template|false
*/
public function get( $id ) {
$template_data = rgar( $this->get_templates(), $id );
if ( ! $template_data ) {
return false;
}
return new GF_Template_Library_Template( $template_data );
}
/**
* Returns the all the templates as an array.
*
* @since 2.7
*
* @param bool $include_meta whether to include the template form meta or not.
*
* @return array
*/
public function all( $include_meta = false ) {
if ( $include_meta ) {
return $this->get_templates();
}
$templates_data = array_map(
function( $template_data ) {
unset( $template_data['form_meta'] );
unset( $template_data['version'] );
return $template_data;
},
$this->get_templates()
);
return $templates_data;
}
}

View File

@@ -0,0 +1,170 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Template_Library\Templates;
/**
* Class GF_Template_Library_Template
*
* Represents Template library.
*
* @package Gravity_Forms\Gravity_Forms\Template_Library;
*/
class GF_Template_Library_Template {
/**
* The template data.
*
* @since 2.7
*
* @var array $data The template raw data.
*/
protected $data;
/**
* The template ID.
*
* @since 2.7
*
* @var string $id The id of the template.
*/
protected $id;
/**
* The template name.
*
* @since 2.7
*
* @var string $name The name of the template.
*/
protected $title;
/**
* The template description.
*
* @since 2.7
*
* @var string $description The description of the template.
*/
protected $description;
/**
* The template form meta data.
*
* @since 2.7
*
* @var array $form_meta The form meta data.
*/
protected $form_meta;
/**
* Template constructor.
*
* @sine 2.7
*
* @param array $data The template data.
*/
public function __construct( $data ) {
$this->data = $data;
}
/**
* Returns the template title.
*
* @sine 2.7
*
* @return string
*/
public function get_title() {
if ( ! isset( $this->title ) ) {
$this->title = rgar( $this->data, 'title' );
}
return $this->title;
}
/**
* Returns the template description.
*
* @sine 2.7
*
* @return string
*/
public function get_description() {
if ( ! isset( $this->description ) ) {
$this->description = rgar( $this->data, 'description' );
}
return $this->description;
}
/**
* Returns the template form meta.
*
* @sine 2.7
*
* @return array
*/
public function get_form_meta() {
if ( ! isset( $this->form_meta ) ) {
$this->form_meta = $this->cleanup_form_meta();
}
return $this->form_meta;
}
/**
* Returns the template ID.
*
* @sine 2.7
*
* @return string
*/
public function get_id() {
if ( ! isset( $this->id ) ) {
$this->id = rgar( $this->data, 'id' );
}
return $this->id;
}
/**
* Cleans up the form meta JSON.
*
* Some form exports will have the form id as one of the keys of the form fields, also some escaped characters cause some issues.
*
* @since 2.7
*
* @return array
*/
protected function cleanup_form_meta() {
$form_meta = rgar( $this->data, 'form_meta' );
if ( isset( $form_meta['id'] ) ) {
unset( $form_meta['id'] );
}
// Unset form IDs left from exporting a form.
$fields = rgar( $form_meta, 'fields' );
if ( is_array( $fields ) && count( $fields ) > 0 ) {
foreach ( $fields as &$field ) {
if ( isset( $field['formId'] ) ) {
unset( $field['formId'] );
}
}
$form_meta['fields'] = $fields;
}
// Some forms don't have this set, which causes some notices.
if ( ! isset( $form_meta['button'] ) ) {
$form_meta['button'] = array(
'type' => 'text',
'text' => '',
'imageUrl' => '',
);
}
// escaping double quotes this way messes things up.
$meta_json = str_replace( '\"', "'", wp_json_encode( $form_meta ) );
return json_decode( $meta_json, true );
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Gravity_Forms\Gravity_Forms\Template_Library\Templates;
use Gravity_Forms\Gravity_Forms\Template_Library\Templates\GF_Template_Library_Template;
interface GF_Templates_Store {
/**
* Retrieves raw data and store it in memory, returns it if it already exists.
*
* @since 2.7
*
* @return array
*/
public function get_templates();
/**
* Return a template by its ID.
*
* @since 2.7
*
* @param string $id The id of the template.
*
* @return GF_Template_Library_Template
*/
public function get( $id );
/**
* Returns all the templates as an array.
*
* @since 2.7
*
* @param bool $include_meta whether to include the template form meta or not.
*
* @return array
*/
public function all( $include_meta );
}