Changeset 3789736 for mega-ai/trunk/mega.php
- Timestamp:
- 11/07/2026 02:25:46 PM (less than one hour ago)
- File:
-
- 1 edited
-
mega-ai/trunk/mega.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mega-ai/trunk/mega.php
r3788788 r3789736 3 3 Plugin Name: MEGA AI 4 4 Description: Connect your WordPress website to MEGA for automated SEO optimization and content management. 5 Version: 2.3 3.05 Version: 2.34.0 6 6 Author: MEGA 7 7 Author URI: https://gomega.ai … … 102 102 class MegaPlugin { 103 103 private static $namespace = 'mega'; 104 private static $version = '2.3 3.0';104 private static $version = '2.34.0'; 105 105 106 106 // Editor (widget) endpoints. … … 4000 4000 $draft_doc = MegaEditorBlocks::parse('nodes', $draft[0], $kind); 4001 4001 $same_bytes = !\is_wp_error($draft_doc) && MegaEditorBlocks::encode($draft_doc['source']) === MegaEditorBlocks::encode($doc['source']); 4002 if (!$same_bytes && !$this->beaver_draft_matches_published($raw, $draft[0])) { 4003 return $this->editor_error('BUILDER_DRAFT_PENDING', 'This page has unpublished Beaver Builder changes (its draft differs from the published layout). Publish or discard them in Beaver first; nothing was written.', 409); 4002 if (!$same_bytes) { 4003 $draft_check = $this->beaver_draft_comparison($raw, $draft[0]); 4004 if (!$draft_check['same']) { 4005 return $this->editor_error('BUILDER_DRAFT_PENDING', 'This page has unpublished Beaver Builder changes (its draft differs from the published layout). Publish or discard them in Beaver first; nothing was written.', 409, $draft_check['details']); 4006 } 4004 4007 } 4005 4008 $writes['_fl_builder_draft'] = $encoded; … … 4018 4021 * never refresh it, so a long-lived process would compare a stale layout. Without Beaver loaded 4019 4022 * there is no way to ask, and the caller keeps refusing. 4020 */ 4021 private function beaver_draft_matches_published($published_raw, $draft_raw) { 4022 if (!\class_exists('FLBuilderModel') || !\is_callable(array('FLBuilderModel', 'clean_layout_data'))) { 4023 return false; 4024 } 4025 $clean = static function ($raw) { 4026 $data = \FLBuilderModel::clean_layout_data(\maybe_unserialize($raw)); 4027 if (\class_exists('FLBuilderSettingsCompat') && \is_callable(array('FLBuilderSettingsCompat', 'filter_layout_data'))) { 4028 $data = \FLBuilderSettingsCompat::filter_layout_data($data); 4029 } 4030 return $data; 4023 * 4024 * Returns array('same' => bool, 'details' => array) where the details say why a refusal was made 4025 * without any page content: whether Beaver was loaded, both rows' byte length and sha256, and up 4026 * to 10 nodes that differ with what differs (only in one, type, parent, position, or the names of 4027 * up to 5 settings). 4028 */ 4029 private function beaver_draft_comparison($published_raw, $draft_raw) { 4030 $details = array( 4031 'beaver_loaded' => \class_exists('FLBuilderModel') && \is_callable(array('FLBuilderModel', 'clean_layout_data')), 4032 'published_bytes' => strlen((string) $published_raw), 4033 'draft_bytes' => strlen((string) $draft_raw), 4034 'published_sha256' => hash('sha256', (string) $published_raw), 4035 'draft_sha256' => hash('sha256', (string) $draft_raw), 4036 'clean_failed' => false, 4037 ); 4038 $published = \maybe_unserialize($published_raw); 4039 $draft = \maybe_unserialize($draft_raw); 4040 $same = false; 4041 if ($details['beaver_loaded']) { 4042 $clean = static function ($data) { 4043 $data = \FLBuilderModel::clean_layout_data($data); 4044 if (\class_exists('FLBuilderSettingsCompat') && \is_callable(array('FLBuilderSettingsCompat', 'filter_layout_data'))) { 4045 $data = \FLBuilderSettingsCompat::filter_layout_data($data); 4046 } 4047 return $data; 4048 }; 4049 try { 4050 $published = $clean($published); 4051 $draft = $clean($draft); 4052 $same = !empty($published) && serialize($published) === serialize($draft); 4053 } catch (\Throwable $e) { 4054 $details['clean_failed'] = true; 4055 } 4056 } 4057 if (!$same) { 4058 $nodes = self::beaver_node_differences($published, $draft); 4059 $details['differing_node_count'] = count($nodes); 4060 $details['differing_nodes'] = array_slice($nodes, 0, 10); 4061 } 4062 return array('same' => $same, 'details' => $details); 4063 } 4064 4065 /** "<node id>: <what differs>" for each node that is not the same in both Beaver layouts. */ 4066 private static function beaver_node_differences($published, $draft) { 4067 $as_map = static function ($layout) { 4068 $out = array(); 4069 if (is_array($layout) || is_object($layout)) { 4070 foreach ((array) $layout as $id => $node) { 4071 $out[(string) $id] = is_object($node) ? (array) $node : (is_array($node) ? $node : array()); 4072 } 4073 } 4074 return $out; 4031 4075 }; 4032 try { 4033 $published = $clean($published_raw); 4034 $draft = $clean($draft_raw); 4035 } catch (\Throwable $e) { 4036 return false; 4037 } 4038 return !empty($published) && serialize($published) === serialize($draft); 4076 $a = $as_map($published); 4077 $b = $as_map($draft); 4078 $out = array(); 4079 foreach (array_unique(array_merge(array_keys($a), array_keys($b))) as $id) { 4080 if (!isset($b[$id])) { 4081 $out[] = $id . ': published only'; 4082 continue; 4083 } 4084 if (!isset($a[$id])) { 4085 $out[] = $id . ': draft only'; 4086 continue; 4087 } 4088 $what = array(); 4089 foreach (array('type', 'parent', 'position') as $field) { 4090 $x = isset($a[$id][$field]) ? $a[$id][$field] : null; 4091 $y = isset($b[$id][$field]) ? $b[$id][$field] : null; 4092 if ($x !== $y) $what[] = $field; 4093 } 4094 $sa = isset($a[$id]['settings']) ? (array) $a[$id]['settings'] : array(); 4095 $sb = isset($b[$id]['settings']) ? (array) $b[$id]['settings'] : array(); 4096 $keys = array(); 4097 foreach (array_unique(array_merge(array_keys($sa), array_keys($sb))) as $key) { 4098 $x = array_key_exists($key, $sa) ? serialize($sa[$key]) : null; 4099 $y = array_key_exists($key, $sb) ? serialize($sb[$key]) : null; 4100 if ($x !== $y) $keys[] = (string) $key; 4101 } 4102 if ($keys !== array()) $what[] = 'settings ' . implode(',', array_slice($keys, 0, 5)) . (count($keys) > 5 ? ',...' : ''); 4103 $rest_a = $a[$id]; 4104 $rest_b = $b[$id]; 4105 unset($rest_a['type'], $rest_a['parent'], $rest_a['position'], $rest_a['settings'], $rest_b['type'], $rest_b['parent'], $rest_b['position'], $rest_b['settings']); 4106 if (serialize($rest_a) !== serialize($rest_b)) $what[] = 'other fields'; 4107 if ($what !== array()) $out[] = $id . ': ' . implode('; ', $what); 4108 } 4109 return $out; 4039 4110 } 4040 4111
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)