| Server IP : 43.130.17.34 / Your IP : 216.73.217.6 Web Server : nginx/1.28.0 System : Linux VM-4-12-opencloudos 6.6.92-34.1.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 25 21:32:13 CST 2025 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/yespkg.com/wp-content/plugins/elementor/modules/global-classes/ |
Upload File : |
<?php
namespace Elementor\Modules\GlobalClasses;
use Elementor\Core\Kits\Documents\Kit;
use Elementor\Modules\AtomicWidgets\Styles\Utils as Atomic_Styles_Utils;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Repository {
const META_KEY = '_elementor_global_classes';
private Kit $kit;
public function __construct( Kit $kit ) {
$this->kit = $kit;
}
public function all() {
$all = $this->kit->get_json_meta( self::META_KEY );
return Global_Classes::make( $all['items'] ?? [], $all['order'] ?? [] );
}
public function get( string $id ) {
return $this->all()->get_items()->get( $id );
}
public function delete( string $id ) {
$all = $this->all();
if ( ! isset( $all->get_items()[ $id ] ) ) {
throw new \Exception( "Global class with id ${id} not found" );
}
$this->kit->update_json_meta( self::META_KEY, [
'items' => $all->get_items()->except( [ $id ] )->all(),
'order' => $all->get_order()->filter( fn( $item ) => $item !== $id )->all(),
] );
}
public function patch( string $id, array $value ) {
$all = $this->all();
unset( $value['id'] );
if ( ! isset( $all->get_items()[ $id ] ) ) {
throw new \Exception( "Global class with id ${id} not found" );
}
$value = $this->kit->update_json_meta( self::META_KEY, [
'items' => $all->get_items()->merge( [ $id => $value ] )->all(),
'order' => $all->get_order()->all(),
] );
if ( ! $value ) {
throw new \Exception( 'Failed to update global class' );
}
return $this->get( $id );
}
public function create( array $value ) {
$all = $this->all();
$id = $this->generate_global_class_id();
$value['id'] = $id;
$updated = $this->kit->update_json_meta( self::META_KEY, [
'items' => $all->get_items()->merge( [ $id => $value ] )->all(),
'order' => $all->get_order()->push( $id )->all(),
] );
if ( ! $updated ) {
throw new \Exception( 'Failed to create global class' );
}
return $this->get( $id );
}
public function arrange( array $value ) {
$all = $this->all();
$updated = $this->kit->update_json_meta( self::META_KEY, [
'items' => $all->get_items()->all(),
'order' => $value,
] );
if ( ! $updated ) {
throw new \Exception( 'Failed to arrange global classes' );
}
return $this->all()->get_order()->all();
}
private function generate_global_class_id() {
$existing_ids = $this->all()->get_items()->keys();
$kit_id = $this->kit->get_id();
return Atomic_Styles_Utils::generate_id( 'g-' . $kit_id . '-', $existing_ids );
}
}