JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
namespace Elementor\Modules\Components;
use Elementor\Core\Utils\Collection;
use Elementor\Modules\Components\Documents\Component as Component_Document;
use Elementor\Plugin;
use Elementor\Core\Base\Document;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Components_Repository {
public static function make(): Components_Repository {
return new self();
}
public function all(): Collection {
// Components count is limited to 100, if we increase this number, we need to iterate the posts in batches.
$posts = get_posts( [
'post_type' => Component_Document::TYPE,
'post_status' => 'any',
'posts_per_page' => Components_REST_API::MAX_COMPONENTS,
] );
$components = [];
foreach ( $posts as $post ) {
$component = $this->get( $post->ID );
if ( ! $component ) {
continue;
}
$components[] = [
'id' => $component->get_main_id(),
'title' => $component->get_post()->post_title,
'uid' => $component->get_component_uid(),
'is_archived' => $component->get_is_archived(),
'styles' => $this->extract_styles( $component->get_elements_data() ),
];
}
return Collection::make( $components );
}
public function get( $id, bool $include_autosave = true ) {
$doc = $include_autosave
? Plugin::$instance->documents->get_doc_or_auto_save( $id, get_current_user_id() )
: Plugin::$instance->documents->get( $id );
if ( ! $doc instanceof Component_Document ) {
return null;
}
return $doc;
}
public function create( string $title, array $content, string $status, string $uid, array $settings = [] ) {
$document = Plugin::$instance->documents->create(
Component_Document::get_type(),
[
'post_title' => $title,
'post_status' => $status,
],
[
Component_Document::COMPONENT_UID_META_KEY => $uid,
]
);
try {
$saved = $document->save( [
'elements' => $content,
'settings' => $settings,
] );
} catch ( \Exception $e ) {
$document->force_delete();
throw $e;
}
if ( ! $saved ) {
$document->force_delete();
throw new \Exception( 'Failed to create component' );
}
return $document->get_main_id();
}
private function extract_styles( array $elements, array $styles = [] ) {
foreach ( $elements as $element ) {
if ( isset( $element['styles'] ) ) {
$styles = array_merge( $styles, $element['styles'] );
}
if ( isset( $element['elements'] ) ) {
$styles = $this->extract_styles( $element['elements'], $styles );
}
}
return $styles;
}
public function archive( array $ids, string $status ) {
$failed_ids = [];
$success_ids = [];
foreach ( $ids as $id ) {
try {
$component = $this->get_component_for_edit( $id, $status );
if ( ! $component ) {
$failed_ids[] = $id;
continue;
}
$component->archive();
$success_ids[] = $id;
} catch ( \Exception $e ) {
$failed_ids[] = $id;
}
}
return [
'failedIds' => $failed_ids,
'successIds' => $success_ids,
];
}
public function update_title( int $component_id, string $title, string $status ): bool {
$component = $this->get_component_for_edit( $component_id, $status );
if ( ! $component ) {
return false;
}
return $component->update_title( $title );
}
/**
* Get the component for edit.
*
* @param int $component_id The component ID.
* @param string $target_status The target status, means the status the component should be saved as.
* @return ?Component_Document The component document for edit.
*
* If target status is an autosave / draft:
* - If the component main document is autosave / draft, it will return the main document.
* - If the component main document is published, it will create a new autosave document and return it.
* If target status is publish:
* - Will return the main document. If it's an autosave, it will be published later by the publish_component method.
*/
private function get_component_for_edit( int $component_id, string $target_status ): ?Component_Document {
$component = $this->get( $component_id );
if ( ! $component ) {
return null;
}
$autosave_statuses = [ Document::STATUS_AUTOSAVE, Document::STATUS_DRAFT ];
$autosave_exists = $component->is_autosave();
$should_create_autosave = in_array( $target_status, $autosave_statuses, true ) && ! $autosave_exists;
if ( ! $should_create_autosave ) {
return $component;
}
// Create a new autosave document, based on the published version.
return $component->get_autosave( 0, true );
}
public function publish_component( Component_Document $component ): bool {
try {
$main_id = $component->get_main_id();
$main_component = $this->get( $main_id, false );
$autosave = $main_component->get_newer_autosave();
if ( $autosave ) {
$success = $this->copy_autosave_data_to_main_component_document_and_publish( $autosave, $main_component, $main_id );
} else {
$success = $main_component->update_status( Document::STATUS_PUBLISH );
}
if ( ! $success ) {
throw new \Exception( 'Failed to publish component' );
}
} catch ( \Exception $e ) {
return false;
}
return true;
}
private function copy_autosave_data_to_main_component_document_and_publish( Component_Document $autosave, Component_Document $main_component_document, int $main_id ): bool {
$autosave_id = $autosave->get_post()->ID;
// Copy component custom meta keys from the autosave to the main component.
Plugin::$instance->db->copy_elementor_meta( $autosave_id, $main_id, Component_Document::COMPONENT_CUSTOM_META_KEYS );
$autosave_elements = $autosave->get_elements_data();
$autosave_title = $autosave->get_post()->post_title;
return $main_component_document->save( [
'elements' => $autosave_elements,
'settings' => [
'post_status' => Document::STATUS_PUBLISH,
'post_title' => $autosave_title,
],
] );
}
}