| 1 |
<?php |
| 2 |
/* |
| 3 |
* SOFTWARE LICENSE INFORMATION |
| 4 |
* |
| 5 |
* Copyright (c) 2017 Buttonizer, all rights reserved. |
| 6 |
* |
| 7 |
* This file is part of Buttonizer |
| 8 |
* |
| 9 |
* For detailed information regarding to the licensing of |
| 10 |
* this software, please review the license.txt or visit: |
| 11 |
* https://buttonizer.pro/license/ |
| 12 |
*/ |
| 13 |
|
| 14 |
namespace Buttonizer\Migration; |
| 15 |
|
| 16 |
# No script kiddies |
| 17 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 18 |
|
| 19 |
/** |
| 20 |
* Registry of plugins Buttonizer can absorb. |
| 21 |
* |
| 22 |
* Adding a newly acquired plugin means adding one entry here. |
| 23 |
*/ |
| 24 |
class SourcePlugins |
| 25 |
{ |
| 26 |
/** |
| 27 |
* @var SourcePlugin[]|null |
| 28 |
*/ |
| 29 |
private static $plugins = null; |
| 30 |
|
| 31 |
/** |
| 32 |
* All registered source plugins. |
| 33 |
* |
| 34 |
* @return SourcePlugin[] |
| 35 |
*/ |
| 36 |
public static function all(): array |
| 37 |
{ |
| 38 |
if (self::$plugins !== null) { |
| 39 |
return self::$plugins; |
| 40 |
} |
| 41 |
|
| 42 |
self::$plugins = array_map(function ($config) { |
| 43 |
return new SourcePlugin($config); |
| 44 |
}, self::definitions()); |
| 45 |
|
| 46 |
return self::$plugins; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Get a single source plugin by id. |
| 51 |
* |
| 52 |
* @param string $id Module identifier. |
| 53 |
* |
| 54 |
* @return SourcePlugin|null |
| 55 |
*/ |
| 56 |
public static function get(string $id) |
| 57 |
{ |
| 58 |
foreach (self::all() as $plugin) { |
| 59 |
if ($plugin->id() === $id) { |
| 60 |
return $plugin; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
return null; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Raw descriptors. |
| 69 |
* |
| 70 |
* @return array[] |
| 71 |
*/ |
| 72 |
private static function definitions(): array |
| 73 |
{ |
| 74 |
return [ |
| 75 |
[ |
| 76 |
'id' => 'chat-button', |
| 77 |
'label' => 'Chat Button', |
| 78 |
// What the same plugin calls itself while its old system is |
| 79 |
// the one running: that menu entry is all these users have |
| 80 |
// ever seen of it. |
| 81 |
'legacy_label' => 'Button contact', |
| 82 |
'option_prefix' => 'bz_contact_button', |
| 83 |
'page_slug' => 'bz_button_contact', |
| 84 |
'text_domain' => 'button-contact-vr', |
| 85 |
|
| 86 |
// Development checkout first, wordpress.org build second |
| 87 |
'base_name_candidates' => [ |
| 88 |
'button-contact-for-wordpress/button-contact-vr.php', |
| 89 |
'button-contact-vr/button-contact-vr.php', |
| 90 |
], |
| 91 |
|
| 92 |
// The acquired plugin's own pre-Buttonizer system, copied in |
| 93 |
// verbatim under modules/. Loaded only for installs that still |
| 94 |
// run it, and only once the source plugin is out of the way. |
| 95 |
'module_bootstrap' => 'chat-button/plugin.php', |
| 96 |
'module_page_slug' => 'contact_vr', |
| 97 |
'module_adapter' => \Buttonizer\Migration\Adapters\ChatButton::class, |
| 98 |
'module_guard_class' => 'PZF', |
| 99 |
'module_guard_constant' => 'PZF_FILE', |
| 100 |
|
| 101 |
// Pre-Buttonizer system of the acquired plugin ("Button contact VR") |
| 102 |
'legacy_flag_option' => 'button_contact_legacy', |
| 103 |
'legacy_flag_value' => 'yes', |
| 104 |
'legacy_options' => [ |
| 105 |
'pzf_phone', |
| 106 |
'pzf_phone2', |
| 107 |
'pzf_phone3', |
| 108 |
'pzf_linkfanpage', |
| 109 |
'pzf_linkmessenger', |
| 110 |
'pzf_whatsapp', |
| 111 |
'pzf_zalo', |
| 112 |
'pzf_telegram', |
| 113 |
'pzf_instagram', |
| 114 |
'pzf_youtube', |
| 115 |
'pzf_tiktok', |
| 116 |
'pzf_viber', |
| 117 |
'pzf_linkggmap', |
| 118 |
'pzf_contact_link', |
| 119 |
], |
| 120 |
|
| 121 |
// Settings the user configured in the source plugin that must |
| 122 |
// survive the move. The connection itself (finished_setup, |
| 123 |
// installed_at, last_synced_at, site_id) is always copied. |
| 124 |
'settings_to_carry_over' => [ |
| 125 |
'include_page_data', |
| 126 |
'wait_until_consent', |
| 127 |
'additional_permissions', |
| 128 |
'admin_top_bar_show_button', |
| 129 |
'can_send_errors', |
| 130 |
'site_licensed', |
| 131 |
], |
| 132 |
], |
| 133 |
]; |
| 134 |
} |
| 135 |
} |
| 136 |
|