| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Beyondwords\Wordpress\Compatibility\Elementor\ControlsSections; |
| 6 |
|
| 7 |
use Elementor\Controls_Manager; |
| 8 |
use Elementor\Core\DocumentTypes\PageBase as PageBase; |
| 9 |
|
| 10 |
use WP_Post; |
| 11 |
|
| 12 |
use Beyondwords\Wordpress\Compatibility\Elementor\Controls\InspectText; |
| 13 |
use Beyondwords\Wordpress\Compatibility\Elementor\Controls\InspectTextarea; |
| 14 |
use Beyondwords\Wordpress\Component\Post\PostMetaUtils; |
| 15 |
|
| 16 |
/** |
| 17 |
* Inspect Controls Section |
| 18 |
* |
| 19 |
* @codeCoverageIgnore |
| 20 |
* |
| 21 |
* @since 3.10.0 |
| 22 |
*/ |
| 23 |
class Inspect |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Register additional document controls. |
| 27 |
* |
| 28 |
* @todo replace with `$post = get_post();` with `$document->get_post();`? |
| 29 |
* |
| 30 |
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 31 |
* |
| 32 |
* @param PageBase $document The PageBase document. |
| 33 |
* @param string $tab The Elementor tab. |
| 34 |
*/ |
| 35 |
public static function registerControls(&$document, $tab) |
| 36 |
{ |
| 37 |
// PageBase is the base class for documents like `post` `page` and etc. |
| 38 |
if (! $document instanceof PageBase || ! $document::get_property('has_elements')) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
$post = get_post(); |
| 43 |
|
| 44 |
if (!($post instanceof \WP_Post)) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$contentId = PostMetaUtils::getContentId($post->ID); |
| 49 |
$languageId = PostMetaUtils::getLanguageId($post->ID); |
| 50 |
$projectId = PostMetaUtils::getProjectId($post->ID); |
| 51 |
$bodyVoiceId = PostMetaUtils::getBodyVoiceId($post->ID); |
| 52 |
$titleVoiceId = PostMetaUtils::getTitleVoiceId($post->ID); |
| 53 |
$summaryVoiceId = PostMetaUtils::getSummaryVoiceId($post->ID); |
| 54 |
|
| 55 |
$document->start_controls_section( |
| 56 |
'beyondwords_inspect_section', |
| 57 |
[ |
| 58 |
'label' => __('Inspect', 'speechkit'), |
| 59 |
'tab' => $tab, |
| 60 |
] |
| 61 |
); |
| 62 |
|
| 63 |
// post_id |
| 64 |
$document->add_control( |
| 65 |
'inspect_post_id', |
| 66 |
[ |
| 67 |
'label' => 'post_id', |
| 68 |
'label_block' => true, |
| 69 |
'default' => $post->ID, |
| 70 |
'type' => Controls_Manager::TEXT, |
| 71 |
] |
| 72 |
); |
| 73 |
|
| 74 |
// beyondwords_generate_audio |
| 75 |
$document->add_control( |
| 76 |
'inspect_beyondwords_generate_audio', |
| 77 |
[ |
| 78 |
'label' => 'beyondwords_generate_audio', |
| 79 |
'label_block' => true, |
| 80 |
'default' => get_post_meta($post->ID, 'beyondwords_generate_audio', true), |
| 81 |
'type' => Controls_Manager::TEXT, |
| 82 |
] |
| 83 |
); |
| 84 |
|
| 85 |
// beyondwords_project_id |
| 86 |
$document->add_control( |
| 87 |
'inspect_beyondwords_project_id', |
| 88 |
[ |
| 89 |
'label' => 'beyondwords_project_id', |
| 90 |
'label_block' => true, |
| 91 |
'default' => $projectId, |
| 92 |
'type' => Controls_Manager::TEXT, |
| 93 |
] |
| 94 |
); |
| 95 |
|
| 96 |
// beyondwords_content_id |
| 97 |
$document->add_control( |
| 98 |
'inspect_beyondwords_content_id', |
| 99 |
[ |
| 100 |
'label' => 'beyondwords_content_id', |
| 101 |
'label_block' => true, |
| 102 |
'default' => $contentId, |
| 103 |
'type' => Controls_Manager::TEXT, |
| 104 |
] |
| 105 |
); |
| 106 |
|
| 107 |
// beyondwords_language_id |
| 108 |
$document->add_control( |
| 109 |
'inspect_beyondwords_language_id', |
| 110 |
[ |
| 111 |
'label' => 'beyondwords_language_id', |
| 112 |
'label_block' => true, |
| 113 |
'default' => $languageId, |
| 114 |
'type' => Controls_Manager::TEXT, |
| 115 |
] |
| 116 |
); |
| 117 |
|
| 118 |
// beyondwords_body_voice_id |
| 119 |
$document->add_control( |
| 120 |
'inspect_beyondwords_body_voice_id', |
| 121 |
[ |
| 122 |
'label' => 'beyondwords_body_voice_id', |
| 123 |
'label_block' => true, |
| 124 |
'default' => $bodyVoiceId, |
| 125 |
'type' => Controls_Manager::TEXT, |
| 126 |
] |
| 127 |
); |
| 128 |
|
| 129 |
// beyondwords_title_voice_id |
| 130 |
$document->add_control( |
| 131 |
'inspect_beyondwords_title_voice_id', |
| 132 |
[ |
| 133 |
'label' => 'beyondwords_title_voice_id', |
| 134 |
'label_block' => true, |
| 135 |
'default' => $titleVoiceId, |
| 136 |
'type' => Controls_Manager::TEXT, |
| 137 |
] |
| 138 |
); |
| 139 |
|
| 140 |
// beyondwords_summary_voice_id |
| 141 |
$document->add_control( |
| 142 |
'inspect_beyondwords_summary_voice_id', |
| 143 |
[ |
| 144 |
'label' => 'beyondwords_summary_voice_id', |
| 145 |
'label_block' => true, |
| 146 |
'default' => $summaryVoiceId, |
| 147 |
'type' => Controls_Manager::TEXT, |
| 148 |
] |
| 149 |
); |
| 150 |
|
| 151 |
// beyondwords_access_key |
| 152 |
$document->add_control( |
| 153 |
'inspect_beyondwords_access_key', |
| 154 |
[ |
| 155 |
'label' => 'beyondwords_access_key', |
| 156 |
'label_block' => true, |
| 157 |
'default' => get_post_meta($post->ID, 'beyondwords_access_key', true), |
| 158 |
'type' => Controls_Manager::TEXT, |
| 159 |
] |
| 160 |
); |
| 161 |
|
| 162 |
// beyondwords_error_message |
| 163 |
$document->add_control( |
| 164 |
'inspect_beyondwords_error_message', |
| 165 |
[ |
| 166 |
'label' => 'beyondwords_error_message', |
| 167 |
'label_block' => true, |
| 168 |
'default' => get_post_meta($post->ID, 'beyondwords_error_message', true), |
| 169 |
'type' => Controls_Manager::TEXT, |
| 170 |
] |
| 171 |
); |
| 172 |
|
| 173 |
// beyondwords_disabled |
| 174 |
$document->add_control( |
| 175 |
'inspect_beyondwords_disabled', |
| 176 |
[ |
| 177 |
'label' => 'beyondwords_disabled', |
| 178 |
'label_block' => true, |
| 179 |
'default' => get_post_meta($post->ID, 'beyondwords_disabled', true), |
| 180 |
'type' => Controls_Manager::TEXT, |
| 181 |
] |
| 182 |
); |
| 183 |
|
| 184 |
$document->add_control( |
| 185 |
'inspect_beyondwords_inspect_html_deprecated', |
| 186 |
[ |
| 187 |
'raw' => '<h3>' . __('Deprecated', 'speechkit') . '</h3>', |
| 188 |
'type' => Controls_Manager::RAW_HTML, |
| 189 |
] |
| 190 |
); |
| 191 |
|
| 192 |
// publish_post_to_speechkit |
| 193 |
$document->add_control( |
| 194 |
'inspect_publish_post_to_speechkit', |
| 195 |
[ |
| 196 |
'label' => 'publish_post_to_speechkit', |
| 197 |
'label_block' => true, |
| 198 |
'default' => get_post_meta($post->ID, 'publish_post_to_speechkit', true), |
| 199 |
'type' => Controls_Manager::TEXT, |
| 200 |
] |
| 201 |
); |
| 202 |
|
| 203 |
// speechkit_error |
| 204 |
$document->add_control( |
| 205 |
'inspect_speechkit_error', |
| 206 |
[ |
| 207 |
'label' => 'speechkit_error', |
| 208 |
'label_block' => true, |
| 209 |
'default' => PostMetaUtils::getHttpResponseBodyFromPostMeta($post->ID, 'speechkit_error'), |
| 210 |
'type' => Controls_Manager::TEXTAREA, |
| 211 |
] |
| 212 |
); |
| 213 |
|
| 214 |
// speechkit_info |
| 215 |
$document->add_control( |
| 216 |
'inspect_speechkit_info', |
| 217 |
[ |
| 218 |
'label' => 'speechkit_info', |
| 219 |
'label_block' => true, |
| 220 |
'default' => get_post_meta($post->ID, 'speechkit_info', true), |
| 221 |
'type' => Controls_Manager::TEXTAREA, |
| 222 |
] |
| 223 |
); |
| 224 |
|
| 225 |
// speechkit_response |
| 226 |
$document->add_control( |
| 227 |
'inspect_speechkit_response', |
| 228 |
[ |
| 229 |
'label' => 'speechkit_response', |
| 230 |
'label_block' => true, |
| 231 |
'default' => PostMetaUtils::getHttpResponseBodyFromPostMeta($post->ID, 'speechkit_response'), |
| 232 |
'type' => Controls_Manager::TEXTAREA, |
| 233 |
] |
| 234 |
); |
| 235 |
|
| 236 |
// speechkit_retries |
| 237 |
$document->add_control( |
| 238 |
'inspect_speechkit_retries', |
| 239 |
[ |
| 240 |
'label' => 'speechkit_retries', |
| 241 |
'label_block' => true, |
| 242 |
'default' => get_post_meta($post->ID, 'speechkit_retries', true), |
| 243 |
'type' => Controls_Manager::TEXT, |
| 244 |
] |
| 245 |
); |
| 246 |
|
| 247 |
// speechkit_status |
| 248 |
$document->add_control( |
| 249 |
'inspect_speechkit_status', |
| 250 |
[ |
| 251 |
'label' => 'speechkit_status', |
| 252 |
'label_block' => true, |
| 253 |
'default' => get_post_meta($post->ID, 'speechkit_status', true), |
| 254 |
'type' => Controls_Manager::TEXT, |
| 255 |
] |
| 256 |
); |
| 257 |
|
| 258 |
// _speechkit_link |
| 259 |
$document->add_control( |
| 260 |
'inspect_speechkit_link', |
| 261 |
[ |
| 262 |
'label' => '_speechkit_link', |
| 263 |
'label_block' => true, |
| 264 |
'default' => get_post_meta($post->ID, '_speechkit_link', true), |
| 265 |
'type' => Controls_Manager::TEXT, |
| 266 |
] |
| 267 |
); |
| 268 |
|
| 269 |
// _speechkit_text |
| 270 |
$document->add_control( |
| 271 |
'inspect_speechkit_text', |
| 272 |
[ |
| 273 |
'label' => '_speechkit_text', |
| 274 |
'label_block' => true, |
| 275 |
'default' => get_post_meta($post->ID, '_speechkit_text', true), |
| 276 |
'type' => Controls_Manager::TEXTAREA, |
| 277 |
] |
| 278 |
); |
| 279 |
|
| 280 |
$document->add_control( |
| 281 |
'inspect_copy_data', |
| 282 |
[ |
| 283 |
'text' => __('Copy', 'speechkit'), |
| 284 |
'type' => Controls_Manager::BUTTON, |
| 285 |
'event' => 'beyondwords:copy-inspect-data' |
| 286 |
] |
| 287 |
); |
| 288 |
$document->end_controls_section(); |
| 289 |
} |
| 290 |
} |
| 291 |
|