Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

View File

@@ -0,0 +1,17 @@
<svg viewBox="0 0 70 70" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="el_DttXTgxDPwm">
<style>
@-webkit-keyframes el_c3n8-4winuw_Animation{50%{opacity: 1;}75%{opacity: 0.3;}100%{opacity: 1;}0%{opacity: 1;}}@keyframes el_c3n8-4winuw_Animation{50%{opacity: 1;}75%{opacity: 0.3;}100%{opacity: 1;}0%{opacity: 1;}}@-webkit-keyframes el_k-XrnU9m-jB_Animation{25%{opacity: 1;}50%{opacity: 0.3;}75%{opacity: 1;}0%{opacity: 1;}100%{opacity: 1;}}@keyframes el_k-XrnU9m-jB_Animation{25%{opacity: 1;}50%{opacity: 0.3;}75%{opacity: 1;}0%{opacity: 1;}100%{opacity: 1;}}@-webkit-keyframes el_3ChrFp8Efar_Animation{0%{opacity: 1;}25%{opacity: 0.3;}50%{opacity: 1;}100%{opacity: 1;}}@keyframes el_3ChrFp8Efar_Animation{0%{opacity: 1;}25%{opacity: 0.3;}50%{opacity: 1;}100%{opacity: 1;}}@-webkit-keyframes el_JD9bPe92Qle_Animation{0%{opacity: 0.3;}25%{opacity: 1;}75%{opacity: 1;}100%{opacity: 0.3;}}@keyframes el_JD9bPe92Qle_Animation{0%{opacity: 0.3;}25%{opacity: 1;}75%{opacity: 1;}100%{opacity: 0.3;}}#el_DttXTgxDPwm *{-webkit-animation-duration: 1.2s;animation-duration:
1.2s;-webkit-animation-iteration-count: infinite;animation-iteration-count: infinite;-webkit-animation-timing-function: cubic-bezier(0, 0, 1, 1);animation-timing-function: cubic-bezier(0, 0, 1, 1);}#el_VLtTzDvculp{stroke: none;stroke-width: 1;fill: none;}#el_19zNp8S1ydt{-webkit-transform: translate(-740px, -457px);transform: translate(-740px, -457px);fill: #869CA1;}#el__jmjTr2Ncfr{-webkit-transform: translate(740px, 457px);transform: translate(740px, 457px);}#el_JD9bPe92Qle{-webkit-animation-name: el_JD9bPe92Qle_Animation;animation-name: el_JD9bPe92Qle_Animation;opacity: 0.3;}#el_3ChrFp8Efar{-webkit-animation-name: el_3ChrFp8Efar_Animation;animation-name: el_3ChrFp8Efar_Animation;opacity: 1;}#el_k-XrnU9m-jB{-webkit-animation-name: el_k-XrnU9m-jB_Animation;animation-name: el_k-XrnU9m-jB_Animation;opacity: 1;}#el_c3n8-4winuw{-webkit-animation-name: el_c3n8-4winuw_Animation;animation-name: el_c3n8-4winuw_Animation;opacity: 1;}
</style>
<defs/>
<g id="el_VLtTzDvculp" fill-rule="evenodd">
<g id="el_19zNp8S1ydt" fill-rule="nonzero">
<g id="el__jmjTr2Ncfr">
<rect id="el_JD9bPe92Qle" x="0" y="0" width="30" height="30"/>
<rect id="el_3ChrFp8Efar" x="40" y="0" width="30" height="30"/>
<rect id="el_k-XrnU9m-jB" x="40" y="40" width="30" height="30"/>
<rect id="el_c3n8-4winuw" x="0" y="40" width="30" height="30"/>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,141 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Design_Packs;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Handle the available data for the export
* Prepare queries for data edited with TAr to be used in the export
*/
class Data {
/**
* Get the default data for the items query
*
* @param array $extra_args
*
* @return array
*/
public static function default_query_args( array $extra_args = [] ): array {
$pagination = $extra_args['pagination'] ?? 0;
$limit = $extra_args['limit'] ?? Main::PER_PAGE_LIMIT;
return [
's' => $extra_args['search'],
'posts_per_page' => $limit,
'post_status' => [ 'draft', 'publish' ],
'offset' => $limit * $pagination,
'fields' => 'ids',
'post__not_in' => [ get_option( 'page_for_posts' ) ],
'update_post_meta_cache' => false,
];
}
/**
* Get the title of the post
*
* @param array $posts
*
* @return array
*/
public static function prepare_posts( array $posts ): array {
$data = [];
foreach ( $posts as $post_id ) {
$data[] = [
'id' => $post_id,
'name' => htmlspecialchars_decode( get_the_title( $post_id ) ),
];
}
return $data;
}
/**
* Get the title of the landing page
*
* @param array $extra_args
*
* @return array
*/
public static function get_landing_pages( array $extra_args = [] ): array {
$posts = get_posts(
array_merge(
static::default_query_args( $extra_args ),
[
'post_type' => 'any',
'meta_query' => [
[
'key' => 'tve_landing_page',
'compare' => '!=',
'value' => '',
],
],
] )
);
$posts = static::prepare_posts( $posts );
$upload = tve_filter_landing_page_preview_location( wp_upload_dir() );
foreach ( $posts as &$post ) {
$lp_name = '/lp-' . $post['id'] . '.png';
if ( file_exists( $upload['path'] . $lp_name ) ) {
$src = $upload['url'] . $lp_name;
$sizes = getimagesize( $src );
if ( ! empty( $sizes ) ) {
$post['width'] = $sizes[0];
$post['height'] = $sizes[1];
}
} else {
$src = TVE_DASH_URL . '/inc/design-packs/assets/img/lp-placeholder.png';
$post['width'] = 602;
$post['height'] = 1004;
}
$post['thumbnail'] = $src;
}
return $posts;
}
/**
* Get posts with the given post type that are edited with TAr
*
* @param string $post_type
* @param array $extra_args
*
* @return array
*/
public static function get_tar_posts( string $post_type = 'post', array $extra_args = [] ): array {
$posts = get_posts(
array_merge(
static::default_query_args( $extra_args ),
[
'post_type' => $post_type,
'category' => $extra_args['categories'] ?? [],
'tag__in' => $extra_args['tags'] ?? [],
'meta_query' => [
[
'key' => 'tcb_editor_enabled',
'compare' => 'EXISTS',
],
[
'key' => 'tve_landing_page',
'compare' => 'NOT EXISTS',
],
],
] )
);
return static::prepare_posts( $posts );
}
}

View File

@@ -0,0 +1,248 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Design_Packs;
use Exception;
use ZipArchive;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Handle the export of each item type
*/
class Export {
const DEFAULT_NAME = 'thrive-design-pack-archive';
const EXPORT_SUFFIX = 'tve_exp_';
/**
* Name of the archive
*
* @var
*/
public $zip_filename;
/**
* Path of the archive
*
* @var
*/
public $zip_path;
/**
* Keeps the umask
*
* @var
*/
private $umask;
/**
* The archive where the export will be saved
*
* @var ZipArchive
*/
public $zip;
/**
* Exported item data
*
* @var
*/
public $item_id;
public $item_type;
public $item_name;
/**
* @throws Exception
*/
public function __construct( $zip_filename, $ensure_filename = true ) {
$this->set_zip_name( $zip_filename, $ensure_filename );
$this->open_zip();
}
/**
* Open the export zip archive
*
* @throws Exception
*/
public function open_zip() {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
WP_Filesystem();
$this->umask = umask( 0 );
$this->zip = new ZipArchive();
if ( $this->zip->open( $this->zip_path, ZipArchive::CREATE ) !== true ) {
throw new Exception( 'Could not create zip archive' );
}
}
/**
* Close the archive and returns the url
*
* @return string
* @throws Exception
*/
public function close_archive() {
try {
if ( ! $this->zip->close() ) {
throw new Exception( 'Could not write the zip file' );
}
} catch ( Exception $e ) {
throw new Exception( $e->getMessage() );
}
umask( $this->umask );
return Main::get_exported_dir_url() . $this->zip_filename;
}
/**
* Get the exported name of an item
*
* @param $name
*
* @return string
*/
public function get_item_export_name( $name ) {
$name = htmlspecialchars_decode( $name );
return $name . ' ' . uniqid( static::EXPORT_SUFFIX );
}
/**
* Handle an item export
*
* @param $id
* @param $type
*
* @return mixed
* @throws Exception
*/
public function export_item( $id, $type ) {
$this->set_item_data( $id, $type );
$fn = 'export_' . $type;
if ( ! method_exists( $this, $fn ) ) {
$fn = 'export_content';
}
$item_data = $this->{$fn}( $id );
$this->write_archive( $item_data );
return $this->close_archive();
}
/**
* Set the item data
*
* @param $id
* @param $type
*
* @return void
*/
public function set_item_data( $id, $type ) {
$this->item_id = $id;
$this->item_type = $type;
if ( $type === 'skin' ) {
$term = get_term( $id );
$this->item_name = $this->get_item_export_name( $term->name );
} else {
$_REQUEST['post_id'] = $id;
$_POST['post_id'] = $id;
$_GET['post_id'] = $id;
$_REQUEST['id'] = $id;
$_POST['id'] = $id;
$_GET['id'] = $id;
$this->item_name = $this->get_item_export_name( htmlspecialchars_decode( get_the_title( $id ) ) );
}
}
/**
* Add a file to the archive
*
* @param $content_data
*
* @return void
*/
public function write_archive( $content_data ) {
if ( $this->zip->locateName( $this->item_type . '/' ) !== false ) {
$this->zip->addEmptyDir( $this->item_type );
}
$config = [];
/**
* If files exists use it
*/
if ( $this->zip->locateName( Main::CFG_NAME ) !== false ) {
$config = json_decode( $this->zip->getFromName( Main::CFG_NAME ), true );
}
/**
* Add each item to the archive's config
*/
$config[ $this->item_type ] = $config[ $this->item_type ] ?? [];
$config[ $this->item_type ][] = $this->item_name;
$this->zip->addFromString( Main::CFG_NAME, json_encode( $config ) );
if ( ! empty( $content_data['path'] ) ) {
$this->zip->addFile( $content_data['path'], $this->item_type . '/' . $this->item_name . '.zip' );
}
}
/**
* Export a page/post
*
* @throws Exception
*/
public function export_content( $id ) {
return ( new \TCB_Content_Handler() )->export( $id, $this->item_name );
}
/**
* Export a landing page
*
* @throws Exception
*/
public function export_landing_page( $id ) {
return ( new \TCB_Landing_Page_Transfer() )->export( $id, $this->item_name );
}
/**
* @throws Exception
*/
public function export_skin( $id ) {
return ( new \Thrive_Transfer_Export( $this->item_name ) )->export( 'skin', $id );
}
/**
* Set the name of the archive
*
* @param $name
* @param bool $ensure_filename - if true the name will be sanitized & suffixed with date
*
* @return void
*/
public function set_zip_name( $name, bool $ensure_filename = true ) {
if ( $ensure_filename ) {
$name = sanitize_file_name( $name );
$name = $name ?: static::DEFAULT_NAME;
$this->zip_filename = str_replace( ' ', '-', $name ) . '-' . gmdate( 'Y-m-d-H-i-s' ) . '.zip';
} else {
$this->zip_filename = $name;
}
$this->zip_path = Main::get_exported_dir_path() . $this->zip_filename;
}
}

View File

@@ -0,0 +1,227 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Design_Packs;
use Exception;
use function unzip_file;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Handle the import of each item type
*/
class Import {
/**
* Get zip and open it
*
* @param $data
*
* @return \ZipArchive|null
*/
public static function get_zip( $data ) {
$attachment = get_attached_file( $data['zip_id'], true );
$zip = new \ZipArchive();
return $zip->open( $attachment ) ? $zip : null;
}
/**
* Validate the uploaded file and get its configuration
*
* @param $data
*
* @return array|mixed
* @throws Exception
*/
public static function validate( $data ) {
$config = [];
if ( isset( $data['zip_id'] ) ) {
$zip = static::get_zip( $data );
if ( $zip && $zip->locateName( Main::CFG_NAME ) !== false ) {
static::unzip_archive( $zip );
$config = json_decode( $zip->getFromName( Main::CFG_NAME ), true );
}
}
return $config;
}
/**
* Get the path to the unzipped archive
*
* @param $zip
*
* @return string
*/
public static function get_unzipped_name( $zip ) {
$wp_uploads_dir = Main::get_imported_dir_path();
defined( 'FS_METHOD' ) || define( 'FS_METHOD', 'direct' );
if ( FS_METHOD !== 'ssh2' ) {
$wp_uploads_dir = str_replace( ABSPATH, '', $wp_uploads_dir );
}
return $wp_uploads_dir . basename( $zip->filename );
}
/**
* @throws Exception
*/
public static function unzip_archive( $zip ) {
if ( ! function_exists( '\WP_Filesystem' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
}
global $wp_filesystem;
defined( 'FS_METHOD' ) || define( 'FS_METHOD', 'direct' );
if ( FS_METHOD !== 'direct' ) {
\WP_Filesystem( array(
'hostname' => defined( 'FTP_HOST' ) ? FTP_HOST : '',
'username' => defined( 'FTP_USER' ) ? FTP_USER : '',
'password' => defined( 'FTP_PASS' ) ? FTP_PASS : '',
) );
} else {
\WP_Filesystem();
}
if ( $wp_filesystem->errors instanceof WP_Error && ! $wp_filesystem->connect() ) {
throw new Exception( $wp_filesystem->errors->get_error_message() );
}
return unzip_file( $zip->filename, static::get_unzipped_name( $zip ) );
}
/**
* Clear the folder once the import is done
*
* @param $data
*
* @return bool
*/
public static function remove_data( $data ): bool {
$zip = static::get_zip( $data );
$folder = static::get_unzipped_name( $zip );
return static::delete_directory( $folder );
}
/**
* Delete a directory and all its content
*
* @param $dir
*
* @return bool
*/
public static function delete_directory( $dir ): bool {
$deleted = false;
if ( is_dir( $dir ) ) {
if ( substr( $dir, strlen( $dir ) - 1, 1 ) !== '/' ) {
$dir .= '/';
}
$files = glob( $dir . '*', GLOB_MARK );
foreach ( $files as $file ) {
if ( is_dir( $file ) ) {
static::delete_directory( $file );
} else {
unlink( $file );
}
}
$deleted = rmdir( $dir );
}
return $deleted;
}
/**
* generic handle for the import
*
* @param $data
*
* @return array
*/
public static function handle_import( $data ) {
$zip = static::get_zip( $data );
$imported = [];
/**
* Use an existing symbol map
*/
if ( ! empty( $data['tcb_symbol_map'] ) ) {
$GLOBALS['tcb_symbol_map'] = $data['tcb_symbol_map'];
}
if ( $zip ) {
$content_file = static::get_unzipped_name( $zip ) . '/' . $data['file_type'] . '/' . $data['filename'] . '.zip';
$fn = 'import_' . $data['file_type'];
if ( ! method_exists( __CLASS__, $fn ) ) {
$fn = 'import_content';
}
$response = static::{$fn}( $content_file );
if ( is_array( $response ) ) {
$imported = array_merge( $imported, $response );
}
$zip->close();
}
/**
* Preserve the symbol map
*/
if ( isset( $GLOBALS['tcb_symbol_map'] ) ) {
$imported['tcb_symbol_map'] = $GLOBALS['tcb_symbol_map'];
}
return $imported;
}
/**
* Import a skin
*
* @param $content_file
*
* @return false|\WP_Term
* @throws \Exception
*/
public static function import_skin( $content_file ) {
return ( new \Thrive_Transfer_Import( $content_file ) )->import( 'skin' );
}
/**
* Import a template
*
* @param $content_file
*
* @return array
* @throws \Exception
*/
public static function import_content( $content_file ) {
return ( new \TCB_Content_Handler() )->import( $content_file, 0 );
}
/**
* Import a landing page
*
* @param $content_file
*
* @return array
* @throws \Exception
*/
public static function import_landing_page( $content_file ) {
$lp_data = ( new \TCB_Landing_Page_Transfer() )->import( $content_file, 0 );
/**
* So we know if the template is an imported one or not
*/
if ( isset( $lp_data['template_id'] ) ) {
update_post_meta( $lp_data['template_id'], 'tve_kit_imported', 1 );
}
return $lp_data;
}
}

View File

@@ -0,0 +1,291 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Design_Packs;
use function preg_replace;
use function str_ireplace;
use function strpos;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Main class of design packs
* Handles the file logic, actions & filters and generic functions
*/
class Main {
const SLUG = 'thrive_design_packs';
const TITLE = 'Design Packs';
const PAGE_SLUG = 'admin_page_thrive_design_packs';
const DESIGN_PACKS_FOLDER = 'thrive-design-packs';
const PER_PAGE_LIMIT = 100;
const CFG_NAME = 'tve-design-pack-config.json';
public static function init() {
$has_ttb = \tve_dash_is_ttb_active();
$has_tar = defined( 'TVE_PLUGIN_FILE' );
if ( PHP_VERSION_ID >= 70000 && class_exists( 'ZipArchive' ) && ( $has_ttb || $has_tar ) && static::has_access() ) {
try {
static::ensure_folders();
static::require_extra_files( __DIR__ );
static::add_hooks();
} catch ( \Exception $e ) {
add_action( 'admin_notices', static function () use ( $e ) {
echo sprintf( '<div class="notice notice-error is-dismissible"><p>%s</p></div>', esc_html( $e->getMessage() ) );
} );
}
}
}
public static function get_rest_string_arg_data() {
return [
'type' => 'string',
'required' => true,
'validate_callback' => static function ( $param ) {
return ! empty( $param );
},
];
}
public static function get_rest_optional_string_arg_data() {
return [
'type' => 'string',
'required' => false,
];
}
public static function get_rest_integer_arg_data( $required = true ) {
return [
'type' => 'integer',
'required' => $required,
];
}
/**
* load the files needed for the design packs
*
* @param $path
*
* @return void
*/
public static function require_extra_files( $path ) {
$items = array_diff( scandir( $path ), [ '.', '..' ] );
foreach ( $items as $item ) {
$item_path = $path . '/' . $item;
if ( is_dir( $item_path ) ) {
static::require_extra_files( $item_path );
}
if ( is_file( $item_path ) && substr( $item_path, - 3 ) === 'php' ) {
require_once $item_path;
}
}
}
public static function add_hooks() {
static::add_filters();
static::add_actions();
}
public static function add_actions() {
add_action( 'admin_menu', [ __CLASS__, 'admin_menu' ] );
add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_enqueue_scripts' ] );
add_action( 'rest_api_init', [ __CLASS__, 'rest_api_init' ] );
}
public static function add_filters() {
add_filter( 'tve_dash_filter_features', [ __CLASS__, 'add_dash_feature' ] );
add_filter( 'thrive_theme_imported_skin_name', [ __CLASS__, 'rename_imported_file' ] );
add_filter( 'tve_imported_content_name', [ __CLASS__, 'rename_imported_file' ] );
add_filter( 'tve_imported_lp_name', [ __CLASS__, 'rename_imported_file' ] );
}
public static function rest_api_init() {
$rest = new Rest();
$rest->register_routes();
}
public static function admin_menu() {
add_submenu_page(
'options.php',
static::TITLE,
static::TITLE,
'manage_options',
static::SLUG,
static function () {
echo '<div id="thrive-design-packs"></div>';
}
);
}
/**
* Add the feature to dashboard
*
* @param $features
*
* @return mixed
*/
public static function add_dash_feature( $features ) {
$features[ static::SLUG ] = array(
'icon' => 'tvd-thrive-design-packs',
'title' => static::TITLE,
'description' => __( 'All of your Thrive Suite designs (Theme Templates, Landing Pages, Page/Post Content) gathered in one place, available for you to quickly export or import.', 'thrive-dash' ),
'btn_link' => add_query_arg( 'page', static::SLUG, admin_url( 'admin.php' ) ),
'btn_text' => __( 'Manage Design Packs', 'thrive-dash' ),
);
return $features;
}
/**
* Setup basic permission callback
*/
public static function has_access() {
return current_user_can( TVE_DASH_CAPABILITY );
}
public static function admin_enqueue_scripts( $screen ) {
if ( ! empty( $screen ) && $screen === static::PAGE_SLUG ) {
tve_dash_enqueue_vue();
tve_dash_enqueue_script( static::SLUG, TVE_DASH_URL . '/assets/dist/js/design-packs.js', [], TVE_DASH_VERSION, true );
if ( is_file( TVE_DASH_PATH . '/assets/dist/css/design-packs.css' ) ) {
tve_dash_enqueue_style( static::SLUG, TVE_DASH_URL . '/assets/dist/css/design-packs.css' );
}
wp_localize_script( static::SLUG, 'TD_DesignPacks', static::localize_data() );
}
}
public static function localize_data() {
$has_ttb = tve_dash_is_ttb_active();
$types = [
[
'type' => 'skin',
'name' => 'Thrive Theme Builder Themes',
'accessible' => $has_ttb,
'error_export_message' => sprintf(
__( 'In order to use this feature, please <a href="%s" target="_blank" class="error-export-message-link">Activate Thrive Theme Builder</a>', 'thrive-dash' ),
admin_url( 'admin.php?page=thrive_product_manager' ) ),
'error_import_message' => __( 'This Thrive Design Pack contains some themes. In order for themes to be imported Thrive Theme Builder needs to be active.', 'thrive-dash' ),
'displayedName' => 'theme',
'redirect_message' => 'Go to Thrive Theme Builder',
'redirect_link' => admin_url( 'admin.php?page=thrive-theme-dashboard&tab=other#skins' ),
],
[
'type' => 'landing_page',
'name' => 'Landing Pages',
'import_name' => 'Landing Page Templates',
'accessible' => true,
'displayedName' => 'landing page',
'redirect_message' => 'Learn more',
'redirect_link' => 'https://help.thrivethemes.com/en/articles/6353871-where-can-i-find-my-page-post-content-and-landing-pages-after-importing-a-design-kit',
],
[
'type' => 'page',
'name' => 'Pages',
'import_name' => 'Page Content Templates',
'accessible' => true,
'displayedName' => 'page',
'redirect_message' => 'Learn more',
'redirect_link' => 'https://help.thrivethemes.com/en/articles/6353871-where-can-i-find-my-page-post-content-and-landing-pages-after-importing-a-design-kit',
],
[
'type' => 'post',
'name' => 'Posts',
'import_name' => 'Post Content Templates',
'accessible' => true,
'displayedName' => 'post',
'redirect_message' => 'Learn more',
'redirect_link' => 'https://help.thrivethemes.com/en/articles/6353871-where-can-i-find-my-page-post-content-and-landing-pages-after-importing-a-design-kit',
],
];
/**
* Filter the types of content that can be imported/exported
*/
$types = apply_filters( 'tve_dash_design_packs_types', $types );
return [
'routes' => get_rest_url( get_current_blog_id(), Rest::REST_NAMESPACE ),
'wp_routes' => get_rest_url( get_current_blog_id(), 'wp/v2' ),
'has_ttb' => $has_ttb,
'has_tar' => tve_dash_is_plugin_active( 'thrive-visual-editor' ),
'page_limit' => static::PER_PAGE_LIMIT,
'export_types' => $types,
'placeholder_image' => TVE_DASH_URL . '/inc/design-packs/assets/img/lp-placeholder.png',
'spinner_image' => TVE_DASH_URL . '/inc/design-packs/assets/img/spinner.svg',
];
}
public static function get_exported_dir_url() {
return wp_upload_dir()['baseurl'] . '/' . static::DESIGN_PACKS_FOLDER . '/exported/';
}
public static function get_exported_dir_path() {
return wp_upload_dir()['basedir'] . '/' . static::DESIGN_PACKS_FOLDER . '/exported/';
}
public static function get_imported_dir_url() {
return wp_upload_dir()['baseurl'] . '/' . static::DESIGN_PACKS_FOLDER . '/imported/';
}
public static function get_imported_dir_path() {
return wp_upload_dir()['basedir'] . '/' . static::DESIGN_PACKS_FOLDER . '/imported/';
}
/**
* Ensure the folders in which we will save the archive exists
*
* @throws \Exception
*/
public static function ensure_folders() {
/**
* first make sure we can save the archive
*/
$upload = wp_upload_dir();
if ( ! empty( $upload['error'] ) ) {
throw new \Exception( $upload['error'] );
}
$base = trailingslashit( $upload['basedir'] ) . static::DESIGN_PACKS_FOLDER . '/imported';
if ( ! is_dir( $base ) && ! mkdir( $base, 0777, true ) && ! is_dir( $base ) ) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', $base ) );
}
$base = trailingslashit( $upload['basedir'] ) . static::DESIGN_PACKS_FOLDER . '/exported';
if ( ! is_dir( $base ) && ! mkdir( $base, 0777, true ) && ! is_dir( $base ) ) {
throw new \RuntimeException( sprintf( 'Directory "%s" was not created', $base ) );
}
}
/**
* Make sure that imported data name doesn't contain export naming
*
* @param $name
*
* @return string
*/
public static function rename_imported_file( $name ) {
if ( strpos( $name, Export::EXPORT_SUFFIX ) !== false ) {
$name = str_ireplace( '.zip', '', $name );
$name = preg_replace( '#tve_exp_[A-Za-z\d]*$#', ' (imported)', $name );
}
return $name;
}
}

View File

@@ -0,0 +1,213 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Design_Packs;
use WP_REST_Response;
use WP_REST_Server;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
class Rest extends \WP_REST_Controller {
const REST_NAMESPACE = 'thrive-design-packs/v1';
public function register_routes() {
register_rest_route( static::REST_NAMESPACE, '/export_item', [
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => [ __CLASS__, 'export_item' ],
'permission_callback' => [ Main::class, 'has_access' ],
'args' => [
'zip' => Main::get_rest_optional_string_arg_data(),
'content_id' => Main::get_rest_integer_arg_data(),
'content_type' => Main::get_rest_string_arg_data(),
],
],
] );
register_rest_route( static::REST_NAMESPACE, '/import',
[
[
'methods' => WP_REST_Server::ALLMETHODS,
'callback' => [ __CLASS__, 'handle_import' ],
'permission_callback' => [ Main::class, 'has_access' ],
'args' => [
'id' => Main::get_rest_integer_arg_data(),
'action' => Main::get_rest_string_arg_data(),
],
],
]
);
$pages_args = [
'p' => Main::get_rest_integer_arg_data( false ),
'limit' => Main::get_rest_integer_arg_data( false ),
'search' => Main::get_rest_optional_string_arg_data(),
];
register_rest_route( static::REST_NAMESPACE, '/landing_pages', [
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ __CLASS__, 'get_landing_pages' ],
'permission_callback' => [ Main::class, 'has_access' ],
'args' => $pages_args,
],
] );
register_rest_route( static::REST_NAMESPACE, '/pages', [
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ __CLASS__, 'get_pages' ],
'permission_callback' => [ Main::class, 'has_access' ],
'args' => $pages_args,
],
] );
register_rest_route( static::REST_NAMESPACE, '/posts', [
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ __CLASS__, 'get_posts' ],
'permission_callback' => [ Main::class, 'has_access' ],
'args' => [
'p' => Main::get_rest_integer_arg_data( false ),
'limit' => Main::get_rest_integer_arg_data( false ),
'cat' => [
'type' => 'array',
'required' => false,
],
'tags' => [
'type' => 'array',
'required' => false,
],
'search' => Main::get_rest_optional_string_arg_data(),
],
],
] );
register_rest_route( static::REST_NAMESPACE, '/skins', [
[
'methods' => WP_REST_Server::READABLE,
'callback' => [ __CLASS__, 'get_skins' ],
'permission_callback' => [ Main::class, 'has_access' ],
],
] );
}
/**
* Export an item
*
* @throws \Exception
*/
public static function export_item( $request ): WP_REST_Response {
/**
* @param $zip - use an existing zip file
* @param $content_id - item id that should be exported
* @param $content_type - item's type, so we know how to handle the export properly
*/
$zip = $request->get_param( 'zip' ) ?? '';
$content_id = $request->get_param( 'content_id' );
$content_type = $request->get_param( 'content_type' );
$handler = new Export( $zip, empty( $zip ) );
$download_url = $handler->export_item( $content_id, $content_type );
return new WP_REST_Response( [ 'zip' => $handler->zip_filename, 'download_url' => $download_url ] );
}
/**
* @param $request
*
* @return WP_REST_Response
*/
public static function get_landing_pages( $request ): WP_REST_Response {
/**
* @param $pagination - page number
* @param $limit - query limit
*/
header( 'Content-type: text/html' );
$pagination = $request->get_param( 'pag' ) ?: 0;
$limit = $request->get_param( 'limit' ) ?: null;
$search = $request->get_param( 'search' ) ?: '';
$args = compact( 'pagination', 'limit', 'search' );
return new WP_REST_Response( Data::get_landing_pages( $args ), 200 );
}
/**
* @param \WP_REST_Request $request
*
* @return WP_REST_Response
*/
public static function get_pages( \WP_REST_Request $request ): WP_REST_Response {
/**
* @param $pagination - page number
* @param $limit - query limit
*/
header( 'Content-type: text/html' );
$pagination = $request->get_param( 'pag' ) ?: 0;
$limit = $request->get_param( 'limit' ) ?: null;
$search = $request->get_param( 'search' ) ?: '';
$args = compact( 'pagination', 'limit', 'search' );
return new WP_REST_Response( Data::get_tar_posts( 'page', $args ) );
}
/**
* @param $request
*
* @return WP_REST_Response
*/
public static function get_posts( $request ): WP_REST_Response {
/**
* @param $pagination - page number
* @param $categories - categories which a post should belong to
* @param $tags - tags which a post should have
* @param $limit - query limit
*/
header( 'Content-type: text/html' );
$pagination = $request->get_param( 'pag' ) ?: 0;
$categories = $request->get_param( 'cat' ) ?: [];
$tags = $request->get_param( 'tags' ) ?: [];
$limit = $request->get_param( 'limit' ) ?: null;
$search = $request->get_param( 'search' ) ?: '';
$args = compact( 'pagination', 'categories', 'tags', 'limit', 'search' );
return new WP_REST_Response( Data::get_tar_posts( 'post', $args ) );
}
/**
* @return WP_REST_Response
*/
public static function get_skins(): WP_REST_Response {
return new WP_REST_Response( \Thrive_Skin_Taxonomy::get_all() );
}
public static function handle_import( $request ): WP_REST_Response {
/**
* @param $zip_id - zip attachment id
* @param $action - what should we do with the zip
* @param $filename - which subitem we should import
* @param $file_type - type of the subitem we are importing
*/
$zip_id = $request->get_param( 'id' ) ?: 0;
$action = $request->get_param( 'action' ) ?: 'validate';
$filename = $request->get_param( 'filename' ) ?: '';
$file_type = $request->get_param( 'file_type' ) ?: '';
$tcb_symbol_map = $request->get_param( 'tcb_symbol_map' ) ?: [];
$data = compact( 'zip_id', 'filename', 'file_type', 'tcb_symbol_map' );
return new WP_REST_Response( Import::{$action}( $data ) );
}
}