PluginProbe
ZIP AI – AI Website Builder & AI Agent / 0.0.10
ZIP AI – AI Website Builder & AI Agent v0.0.10
0.0.13 0.0.12 0.0.11 0.0.10 0.0.9 trunk 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8
zip-ai / inc / core / import-impact.php

import-impact.php in ZIP AI – AI Website Builder & AI Agent 0.0.10, at inc/core/import-impact.php

118 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Import Impact — the ONE source of truth for "what will this import change?".
4 *
5 * Two surfaces consume it and must never disagree:
6 * - the `zipai/import-html` MCP ability, which returns the list to an AI
7 * client and refuses to write until the client comes back with a token;
8 * - the in-panel import wizard, which renders it under the layout options
9 * (via `ZIPAI_CONFIG.importImpact`, so there is no second copy in JSX).
10 *
11 * The wording is derived from what `@bsf/wp-importer`'s committer ACTUALLY
12 * writes per mode — shared template parts (`writeSiteChrome`), the global Global
13 * Styles store, the Style Guide colour + font push, and the front-page flip. If
14 * the committer's per-mode writes change, this file changes with it.
15 *
16 * @since 0.0.8
17 * @package zip-ai
18 */
19
20 namespace ZipAI\MCP\Classes\Core;
21
22 defined( 'ABSPATH' ) || exit;
23
24 /**
25 * Truthful per-layout impact statements for an HTML import.
26 */
27 class Import_Impact {
28
29 /**
30 * Layouts that change state beyond the new page. `match_site` only adds a
31 * page, so it is absent by design.
32 */
33 const CONFIRMABLE = array( 'standalone', 'replace_site' );
34
35 /**
36 * Layouts that overwrite state which existed before the import — their
37 * consent copy must say the old design is not saved. `standalone` writes
38 * only its OWN page-scoped chrome.
39 */
40 const OVERWRITES_SITE = array( 'replace_site' );
41
42 /**
43 * The impact of one layout choice.
44 *
45 * @param string $layout One of match_site|standalone|replace_site.
46 * @param bool $set_homepage Whether the front page would change too.
47 * @return array{change: string[], keep: string[], reversible: string}
48 */
49 public static function for_layout( string $layout, bool $set_homepage = false ) {
50 $change = array();
51
52 if ( 'replace_site' === $layout ) {
53 $change[] = __( 'Your site header will be REPLACED on every page.', 'zip-ai' );
54 $change[] = __( 'Your site footer will be REPLACED on every page.', 'zip-ai' );
55 $change[] = __( 'Your brand colours will change on every page.', 'zip-ai' );
56 $change[] = __( 'Your site fonts will change on every page.', 'zip-ai' );
57 } elseif ( 'standalone' === $layout ) {
58 $change[] = __( 'The new page gets its OWN header and footer instead of your site\'s.', 'zip-ai' );
59 $change[] = __( 'Only this page is affected. Your other pages keep your current header and footer.', 'zip-ai' );
60 } else {
61 $change[] = __( 'A new page is added. Your existing design is kept exactly as it is.', 'zip-ai' );
62 }
63
64 if ( $set_homepage ) {
65 $change[] = __( 'This page becomes your front page: it is what visitors see first.', 'zip-ai' );
66 }
67
68 return array(
69 'change' => $change,
70 'keep' => array(
71 __( 'Your existing pages and posts stay exactly as they are.', 'zip-ai' ),
72 __( 'Your plugins, users and site settings are not touched.', 'zip-ai' ),
73 __( 'Nothing is deleted from your media library.', 'zip-ai' ),
74 ),
75 'reversible' => self::overwrites_site_state( $layout, $set_homepage )
76 ? __( 'Not automatically. The design being replaced is not saved, and deleting the new page will not bring it back.', 'zip-ai' )
77 : __( 'Yes. The new page can be deleted; nothing else changes.', 'zip-ai' ),
78 );
79 }
80
81 /**
82 * Every layout's impact, for handing to the panel in one payload. Avoids a
83 * per-selection request and keeps the copy in exactly one place.
84 *
85 * @return array<string,array{change: string[], keep: string[], reversible: string}>
86 */
87 public static function all() {
88 $all = array();
89 foreach ( array( 'match_site', 'standalone', 'replace_site' ) as $layout ) {
90 $all[ $layout ] = self::for_layout( $layout );
91 }
92 return $all;
93 }
94
95 /**
96 * Whether a request needs explicit confirmation before it may write.
97 *
98 * @param string $layout Requested layout.
99 * @param bool $set_homepage Whether the front page would change.
100 * @return bool
101 */
102 public static function needs_confirmation( string $layout, bool $set_homepage = false ) {
103 return in_array( $layout, self::CONFIRMABLE, true ) || $set_homepage;
104 }
105
106 /**
107 * Whether a request overwrites pre-existing site state (its consent copy
108 * must warn the old design is not saved).
109 *
110 * @param string $layout Requested layout.
111 * @param bool $set_homepage Whether the front page would change.
112 * @return bool
113 */
114 public static function overwrites_site_state( string $layout, bool $set_homepage = false ) {
115 return in_array( $layout, self::OVERWRITES_SITE, true ) || $set_homepage;
116 }
117 }
118