diff --git a/assets/img/screenshot-12.png b/assets/img/screenshot-12.png new file mode 100644 index 000000000..3cfd50873 Binary files /dev/null and b/assets/img/screenshot-12.png differ diff --git a/autoload.php b/autoload.php index f76ca3d4e..8f2cb4fbf 100644 --- a/autoload.php +++ b/autoload.php @@ -111,9 +111,7 @@ protected function load_mapped_file( $prefix, $relative_class ) { // replace the namespace prefix with the base directory, // replace namespace separators with directory separators // in the relative class name, append with .php - $file = $base_dir - . str_replace( '\\', '/', $relative_class ) - . '.php'; + $file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php'; // if the mapped file exists, require it if ( $this->require_file( $file ) ) { diff --git a/classifai.php b/classifai.php index db6c1d15f..427b98352 100644 --- a/classifai.php +++ b/classifai.php @@ -4,8 +4,8 @@ * Plugin URI: https://github.com/10up/classifai * Update URI: https://classifaiplugin.com * Description: Enhance your WordPress content with Artificial Intelligence and Machine Learning services. - * Version: 2.2.3 - * Requires at least: 5.7 + * Version: 2.3.0 + * Requires at least: 5.8 * Requires PHP: 7.4 * Author: 10up * Author URI: https://10up.com @@ -16,30 +16,47 @@ */ /** - * Require PHP version 7.4+ - throw an error if the plugin is activated on an older version. + * Get the minimum version of PHP required by this plugin. * - * Note that this itself is only PHP5.3+ compatible because of the anonymous callback. + * @return string Minimum version required. */ -register_activation_hook( - __FILE__, - function() { - if ( version_compare( PHP_VERSION, '7.4.0', '<' ) ) { - wp_die( - sprintf( - wp_kses( - /* translators: PHP Update guide URL */ - __( 'ClassifAI requires PHP version 7.4. Click here to learn how to update your PHP version.', 'classifai' ), - array( - 'a' => array( 'href' => array() ), +function classifai_minimum_php_requirement() { + return '7.4'; +} + +/** + * Whether PHP installation meets the minimum requirements + * + * @return bool True if meets minimum requirements, false otherwise. + */ +function classifai_site_meets_php_requirements() { + return version_compare( phpversion(), classifai_minimum_php_requirement(), '>=' ); +} + +// Ensuring our PHP version requirement is met first before loading plugin. +if ( ! classifai_site_meets_php_requirements() ) { + add_action( + 'admin_notices', + function() { + ?> +
+

+ +

+
+ array(), 'version' => 'bebd517578e28722f510'); + array(), 'version' => 'b88da674f852dcc57e0e'); diff --git a/dist/admin.css b/dist/admin.css index 57ef7df3d..d066c8fe7 100644 --- a/dist/admin.css +++ b/dist/admin.css @@ -1,3 +1,3 @@ -:root{--classifai-admin-theme-color:#007cba;--classifai-admin-theme-color--rgb:0,124,186;--classifai-admin-theme-color-darker-10:#006ba1}body.admin-color-light{--classifai-admin-theme-color:#0085ba;--classifai-admin-theme-color--rgb:0,133,186;--classifai-admin-theme-color-darker-10:#0073a1}body.admin-color-modern{--classifai-admin-theme-color:#3858e9;--classifai-admin-theme-color--rgb:56,88,233;--classifai-admin-theme-color-darker-10:#2145e6}body.admin-color-blue{--classifai-admin-theme-color:#096484;--classifai-admin-theme-color--rgb:9,100,132;--classifai-admin-theme-color-darker-10:#07526c}body.admin-color-coffee{--classifai-admin-theme-color:#46403c;--classifai-admin-theme-color--rgb:70,64,60;--classifai-admin-theme-color-darker-10:#383330}body.admin-color-ectoplasm{--classifai-admin-theme-color:#523f6d;--classifai-admin-theme-color--rgb:82,63,109;--classifai-admin-theme-color-darker-10:#46365d}body.admin-color-midnight{--classifai-admin-theme-color:#e14d43;--classifai-admin-theme-color--rgb:225,77,67;--classifai-admin-theme-color-darker-10:#dd382d}body.admin-color-ocean{--classifai-admin-theme-color:#627c83;--classifai-admin-theme-color--rgb:98,124,131;--classifai-admin-theme-color-darker-10:#576e74}body.admin-color-sunrise{--classifai-admin-theme-color:#dd823b;--classifai-admin-theme-color--rgb:221,130,59;--classifai-admin-theme-color-darker-10:#d97426}#classifai-activation-notice{padding:24px}#classifai-activation-notice .classifai-logo{line-height:0}#classifai-activation-notice .classifai-logo img{width:180px}#classifai-activation-notice h3.classifai-activation-message{font-size:1.6em;font-weight:400;line-height:1.3;margin:8px 0 18px}a.classifai-button,input.classifai-button{background:var(--classifai-admin-theme-color);border-color:var(--classifai-admin-theme-color);border-radius:4px;border-style:solid;border-width:1px;box-sizing:border-box;color:#fff;cursor:pointer;display:inline-block;font-size:14px;font-style:normal;font-weight:400;padding:8px 16px;text-decoration:none;text-shadow:none;text-transform:uppercase;white-space:nowrap}a.classifai-button:active,a.classifai-button:focus,a.classifai-button:hover,input.classifai-button:active,input.classifai-button:focus,input.classifai-button:hover{background:var(--classifai-admin-theme-color-darker-10);border-color:var(--classifai-admin-theme-color-darker-10);color:#fff}a.classifai-button:focus,input.classifai-button:focus{box-shadow:0 0 0 1px #fff,0 0 0 3px var(--classifai-admin-theme-color-darker-10)}a.classifai-button:active,input.classifai-button:active{box-shadow:none}a.classifai-button.disabled,a.classifai-button:disabled,input.classifai-button.disabled,input.classifai-button:disabled{background:#9ea3a8;box-shadow:none;color:#fff;cursor:not-allowed}#classifai-header{background-color:#fff;box-shadow:0 10px 10px 0 #f0f0f1;box-sizing:border-box;display:block;left:0;margin-left:-20px;padding:0 10px;position:sticky;right:0;top:0;z-index:1001}@media screen and (max-width:782px){#classifai-header{margin-left:-10px;padding:0 5px}}@media(min-width:601px){body.admin-bar #classifai-header{top:46px}}@media(min-width:783px){body.admin-bar #classifai-header{top:32px}}.classifai-setup-page #classifai-header{position:relative}@media(min-width:601px){body.admin-bar .classifai-setup-page #classifai-header{top:0}}@media(min-width:783px){body.admin-bar .classifai-setup-page #classifai-header{top:0}}#classifai-header .classifai-header-layout{align-items:center;display:flex;justify-content:space-between;padding:18px}#classifai-header #classifai-logo{line-height:0}#classifai-header #classifai-logo img{max-width:180px}#classifai-header #classifai-header-controls{align-items:center;display:flex;flex-direction:row}#classifai-header #classifai-header-controls .header-control-item{align-items:center;cursor:pointer;display:flex;flex-direction:column;justify-content:center;margin-left:24px;outline:none;position:relative}#classifai-header #classifai-header-controls a.classifai-help-links{color:#757575;text-align:center;text-decoration:none}#classifai-header #classifai-header-controls a.classifai-help-links:hover,#classifai-header #classifai-header-controls a.classifai-help-links[aria-expanded=true]{color:var(--classifai-admin-theme-color)}#classifai-header #classifai-header-controls a.classifai-help-links span.control-item-text{display:block}#classifai-header .classifai-help-menu{display:block;width:200px}#classifai-header .classifai-help-menu__menu-item{color:#757575;display:block;padding:8px 12px;text-decoration:none}#classifai-header .classifai-help-menu__menu-item:hover{color:var(--classifai-admin-theme-color)}.admin_page_classifai_setup #classifai-header{box-shadow:none}.classifai-content .classifai-wrap{background-color:#fff;border-radius:4px;margin:0 20px 0 0;padding:24px}.classifai-content .classifai-wrap .form-table td fieldset p{margin-bottom:12px}.classifai-content input[type=password],.classifai-content input[type=text]{font-size:14px;height:38px;margin-bottom:4px}.classifai-content h2.nav-tab-wrapper.classifai-nav-wrapper{border-color:transparent;margin-right:20px;margin-top:20px;padding-top:0}.classifai-content a.nav-tab{background:transparent;border:none;margin-left:0;padding:10px 12px;position:relative}.classifai-content a.nav-tab:after{background:var(--classifai-admin-theme-color);border-radius:3px 3px 0 0;bottom:0;box-shadow:0 4px 10px 3px rgba(var(--classifai-admin-theme-color--rgb),.15);content:"";height:3px;left:0;opacity:0;position:absolute;right:0;transform:scaleX(0);transition:all .3s cubic-bezier(1,0,0,1);will-change:transform,box-shadow,opacity}.classifai-content a.nav-tab.nav-tab-active,.classifai-content a.nav-tab:hover{color:var(--classifai-admin-theme-color);font-weight:600}.classifai-content a.nav-tab.nav-tab-active:after,.classifai-content a.nav-tab:hover:after{opacity:1;transform:scale(1)}.classifai-setup{margin-left:-20px}.classifai-setup__header{align-items:center;background:#fff;border-bottom:1px solid #dcdcde;border-top:1px solid #dcdcde;display:flex;height:60px;justify-content:center}.classifai-setup__step-wrapper{margin:0 16px;max-width:980px;width:100%}.classifai-setup__steps{display:flex;justify-content:space-around}.classifai-setup__step{font-weight:400;padding:8px;position:relative}.classifai-setup__step__label{align-items:center;display:inline-flex;font-size:16px;justify-content:center}.classifai-setup__step__label span.step-count{background:#f0f0f0;border-radius:50%;color:#757575;height:24px;margin-right:8px;min-width:24px;width:24px}.classifai-setup__step__label span.step-count,.classifai-setup__step__label span.step-title{align-items:center;display:inline-flex;justify-content:center}.classifai-setup__step__label a,.classifai-setup__step__label a:active,.classifai-setup__step__label a:focus,.classifai-setup__step__label a:hover{color:#3c434a;display:inherit;text-decoration:none}@media screen and (max-width:480px){.classifai-setup__step__label{font-size:14px}}.classifai-setup__step.is-complete span.step-count{background:var(--classifai-admin-theme-color);color:#fff}.classifai-setup__step.is-active span.step-title{font-weight:600}.classifai-setup__step.is-active span.step-count{background:var(--classifai-admin-theme-color);color:#fff}.classifai-setup__step-divider{align-self:flex-start;border-bottom:1px solid #f0f0f0;flex-grow:1;margin-top:20px}.classifai-setup__step-label{font-size:1.2em}@media screen and (max-width:782px){.classifai-setup{margin-left:-10px}}.classifai-setup__wrapper{margin:0 auto;max-width:1232px}.classifai-setup__content{background-color:#fff;border-radius:4px;box-sizing:border-box;display:block;margin:20px;padding:24px 24px 48px}.classifai-setup__content__row{display:flex;flex-direction:row;flex-wrap:wrap;width:100%}.classifai-setup__content__row__column{display:flex;flex-basis:100%;flex-direction:column}.classifai-setup__content__row__column img{max-width:400px;width:100%}@media screen and (min-width:767px){.classifai-setup__content__row__column{flex:1;padding:0 10px}}.classifai-setup__content h1.classifai-setup-heading{font-size:22px;font-weight:600;margin:24px 0;text-align:center}.classifai-setup__content .classifai-setup-image{margin-top:20px;text-align:center}.classifai-setup__content h2.classifai-setup-title{font-size:22px;font-weight:400;margin:0;padding:0}.classifai-setup__content .classifai-step1-content,.classifai-setup__content .classifai-step4-content{margin-top:20px;max-width:400px}.classifai-setup__content .classifai-step2-content{margin:0 auto;max-width:480px}.classifai-setup__content .classifai-setup-footer{margin-top:40px}.classifai-setup__content .classifai-feature-box{margin:40px 0}.classifai-setup__content .classifai-feature-box-title{font-weight:700;text-transform:uppercase}.classifai-setup__content li.classifai-enable-feature{clear:both;display:block;list-style:none;margin-top:14px;width:100%}.classifai-setup__content li.classifai-enable-feature span.dashicons.dashicons-yes-alt{color:#48be1e}.classifai-setup__content li.classifai-enable-feature span.dashicons.dashicons-dismiss{color:#c00}.classifai-setup__content .classifai-feature-box-divider{border:1px solid #ddd}.classifai-setup__content label.classifai-feature-text,.classifai-setup__content span.classifai-feature-text{color:#707070;font-size:14px}.classifai-setup__content span.classifai-feature-text{float:left}.classifai-setup__content .classifai-setup-footer{text-align:right}.classifai-setup__content a.classifai-setup-skip-link{color:#000;font-weight:400;text-decoration:none}.classifai-setup__content .classifai-setup-footer__right{margin-left:40px}@media screen and (max-width:767px){.classifai-setup__content .classifai-step1-content,.classifai-setup__content .classifai-step4-content{margin-top:20px;max-width:100%}.classifai-setup__content h2.classifai-setup-title{text-align:center}}.classifai-step3-content .classifai-setup__content .classifai-setup-form{margin:0 auto;max-width:480px}.classifai-setup__content .classifai-setup-form .classifai-setup-form-field{margin-top:40px}.classifai-setup__content .classifai-setup-form label{display:block;font-weight:700;margin-bottom:20px;text-transform:uppercase}.classifai-setup__content .classifai-setup-form input[type=password],.classifai-setup__content .classifai-setup-form input[type=text]{font-size:14px;height:38px;margin-bottom:4px;width:100%}.classifai-setup__content .classifai-setup-form .classifai-setup-footer{margin-top:40px}.classifai-setup__content .classifai-step3-content{margin:0 auto}.classifai-setup__content .classifai-step3-content .classifai-setup-title{margin-bottom:12px;text-align:center}.classifai-setup__content .classifai-step3-content .classifai-setup-footer,.classifai-setup__content .classifai-step3-content .classifai-setup-form{margin:0 auto;max-width:480px}.classifai-setup__content .classifai-step3-content .classifai-setup-footer{margin-top:40px}.classifai-setup__content .classifai-tabs{display:block}.classifai-setup__content .classifai-tabs.tabs-center{margin:auto auto 24px}.classifai-setup__content .classifai-tabs.tabs-justify{table-layout:fixed;width:100%}.classifai-setup__content .classifai-tabs a.tab{color:#1d2327;cursor:pointer;display:inline-block;font-size:14px;padding:16px 12px;position:relative;text-decoration:none;transform:translateZ(0);transition:all .3s ease;white-space:nowrap}.classifai-setup__content .classifai-tabs a.tab:focus{box-shadow:none}.classifai-setup__content .classifai-tabs a.tab:hover{color:var(--classifai-admin-theme-color)}.classifai-setup__content .classifai-tabs a.tab:after{background:var(--classifai-admin-theme-color);border-radius:3px 3px 0 0;bottom:0;box-shadow:0 4px 10px 3px rgba(var(--classifai-admin-theme-color--rgb),.15);content:"";height:3px;left:0;opacity:0;position:absolute;right:0;transform:scaleX(0);transition:all .3s cubic-bezier(1,0,0,1);will-change:transform,box-shadow,opacity}.classifai-setup__content .classifai-tabs a.tab.active{color:var(--classifai-admin-theme-color);font-weight:600}.classifai-setup__content .classifai-tabs a.tab.active:after{opacity:1;transform:scale(1)}.classifai-setup__content p.classifai-setup-error{color:red;text-align:center}.classifai-setup__content span.classifai-input-description{font-size:12px}.classifai-toggle{cursor:pointer;display:inline-block;text-align:right;width:100%}.classifai-toggle-switch{background:transparent;border:1px solid #1e1e1e;border-radius:9px;box-sizing:border-box;display:inline-block;height:18px;position:relative;transition:background .25s;vertical-align:middle;width:36px}.classifai-toggle-switch:after,.classifai-toggle-switch:before{content:""}.classifai-toggle-switch:before{background:#1e1e1e;border-radius:50%;box-sizing:border-box;display:block;height:12px;left:2px;position:absolute;top:2px;transition:left .25s;width:12px}.classifai-toggle-checkbox:checked+.classifai-toggle-switch{background:var(--classifai-admin-theme-color);border-color:var(--classifai-admin-theme-color)}.classifai-toggle-checkbox:checked+.classifai-toggle-switch:before{background-color:#fff;left:20px}.classifai-toggle-checkbox{position:absolute;visibility:hidden} +:root{--classifai-admin-theme-color:#007cba;--classifai-admin-theme-color--rgb:0,124,186;--classifai-admin-theme-color-darker-10:#006ba1}body.admin-color-light{--classifai-admin-theme-color:#0085ba;--classifai-admin-theme-color--rgb:0,133,186;--classifai-admin-theme-color-darker-10:#0073a1}body.admin-color-modern{--classifai-admin-theme-color:#3858e9;--classifai-admin-theme-color--rgb:56,88,233;--classifai-admin-theme-color-darker-10:#2145e6}body.admin-color-blue{--classifai-admin-theme-color:#096484;--classifai-admin-theme-color--rgb:9,100,132;--classifai-admin-theme-color-darker-10:#07526c}body.admin-color-coffee{--classifai-admin-theme-color:#46403c;--classifai-admin-theme-color--rgb:70,64,60;--classifai-admin-theme-color-darker-10:#383330}body.admin-color-ectoplasm{--classifai-admin-theme-color:#523f6d;--classifai-admin-theme-color--rgb:82,63,109;--classifai-admin-theme-color-darker-10:#46365d}body.admin-color-midnight{--classifai-admin-theme-color:#e14d43;--classifai-admin-theme-color--rgb:225,77,67;--classifai-admin-theme-color-darker-10:#dd382d}body.admin-color-ocean{--classifai-admin-theme-color:#627c83;--classifai-admin-theme-color--rgb:98,124,131;--classifai-admin-theme-color-darker-10:#576e74}body.admin-color-sunrise{--classifai-admin-theme-color:#dd823b;--classifai-admin-theme-color--rgb:221,130,59;--classifai-admin-theme-color-darker-10:#d97426}#classifai-activation-notice{padding:24px}#classifai-activation-notice .classifai-logo{line-height:0}#classifai-activation-notice .classifai-logo img{width:180px}#classifai-activation-notice h3.classifai-activation-message{font-size:1.6em;font-weight:400;line-height:1.3;margin:8px 0 18px}a.classifai-button,input.classifai-button{background:var(--classifai-admin-theme-color);border-color:var(--classifai-admin-theme-color);border-radius:4px;border-style:solid;border-width:1px;box-sizing:border-box;color:#fff;cursor:pointer;display:inline-block;font-size:14px;font-style:normal;font-weight:400;padding:8px 16px;text-decoration:none;text-shadow:none;text-transform:uppercase;white-space:nowrap}a.classifai-button:active,a.classifai-button:focus,a.classifai-button:hover,input.classifai-button:active,input.classifai-button:focus,input.classifai-button:hover{background:var(--classifai-admin-theme-color-darker-10);border-color:var(--classifai-admin-theme-color-darker-10);color:#fff}a.classifai-button:focus,input.classifai-button:focus{box-shadow:0 0 0 1px #fff,0 0 0 3px var(--classifai-admin-theme-color-darker-10)}a.classifai-button:active,input.classifai-button:active{box-shadow:none}a.classifai-button.disabled,a.classifai-button:disabled,input.classifai-button.disabled,input.classifai-button:disabled{background:#9ea3a8;box-shadow:none;color:#fff;cursor:not-allowed}#classifai-header{background-color:#fff;box-shadow:0 10px 10px 0 #f0f0f1;box-sizing:border-box;display:block;left:0;margin-left:-20px;padding:0 10px;position:sticky;right:0;top:0;z-index:1001}@media screen and (max-width:782px){#classifai-header{margin-left:-10px;padding:0 5px}}@media(min-width:601px){body.admin-bar #classifai-header{top:46px}}@media(min-width:783px){body.admin-bar #classifai-header{top:32px}}.classifai-setup-page #classifai-header{position:relative}@media(min-width:601px){body.admin-bar .classifai-setup-page #classifai-header{top:0}}@media(min-width:783px){body.admin-bar .classifai-setup-page #classifai-header{top:0}}#classifai-header .classifai-header-layout{align-items:center;display:flex;justify-content:space-between;padding:18px}#classifai-header #classifai-logo{line-height:0}#classifai-header #classifai-logo img{max-width:180px}#classifai-header #classifai-header-controls{align-items:center;display:flex;flex-direction:row}#classifai-header #classifai-header-controls .header-control-item{align-items:center;cursor:pointer;display:flex;flex-direction:column;justify-content:center;margin-left:24px;outline:none;position:relative}#classifai-header #classifai-header-controls a.classifai-help-links{color:#757575;text-align:center;text-decoration:none}#classifai-header #classifai-header-controls a.classifai-help-links:hover,#classifai-header #classifai-header-controls a.classifai-help-links[aria-expanded=true]{color:var(--classifai-admin-theme-color)}#classifai-header #classifai-header-controls a.classifai-help-links span.control-item-text{display:block}#classifai-header .classifai-help-menu{display:block;width:200px}#classifai-header .classifai-help-menu__menu-item{color:#757575;display:block;padding:8px 12px;text-decoration:none}#classifai-header .classifai-help-menu__menu-item:hover{color:var(--classifai-admin-theme-color)}.admin_page_classifai_setup #classifai-header{box-shadow:none}.classifai-content .classifai-wrap{background-color:#fff;border-radius:4px;margin:0 20px 0 0;padding:24px}.classifai-content .classifai-wrap .form-table td fieldset p{margin-bottom:12px}.classifai-content input[type=password],.classifai-content input[type=text]{font-size:14px;height:38px;margin-bottom:4px}.classifai-content h2.nav-tab-wrapper.classifai-nav-wrapper{border-color:transparent;margin-right:20px;margin-top:20px;padding-top:0}.classifai-content a.nav-tab{background:transparent;border:none;margin-left:0;padding:10px 12px;position:relative}.classifai-content a.nav-tab:after{background:var(--classifai-admin-theme-color);border-radius:3px 3px 0 0;bottom:0;box-shadow:0 4px 10px 3px rgba(var(--classifai-admin-theme-color--rgb),.15);content:"";height:3px;left:0;opacity:0;position:absolute;right:0;transform:scaleX(0);transition:all .3s cubic-bezier(1,0,0,1);will-change:transform,box-shadow,opacity}.classifai-content a.nav-tab.nav-tab-active,.classifai-content a.nav-tab:hover{color:var(--classifai-admin-theme-color);font-weight:600}.classifai-content a.nav-tab.nav-tab-active:after,.classifai-content a.nav-tab:hover:after{opacity:1;transform:scale(1)}.classifai-setup{margin-left:-20px}.classifai-setup__header{align-items:center;background:#fff;border-bottom:1px solid #dcdcde;border-top:1px solid #dcdcde;display:flex;height:60px;justify-content:center}.classifai-setup__step-wrapper{margin:0 16px;max-width:980px;width:100%}.classifai-setup__steps{display:flex;justify-content:space-around}.classifai-setup__step{font-weight:400;padding:8px;position:relative}.classifai-setup__step__label{align-items:center;display:inline-flex;font-size:16px;justify-content:center}.classifai-setup__step__label span.step-count{background:#f0f0f0;border-radius:50%;color:#757575;height:24px;margin-right:8px;min-width:24px;width:24px}.classifai-setup__step__label span.step-count,.classifai-setup__step__label span.step-title{align-items:center;display:inline-flex;justify-content:center}.classifai-setup__step__label a,.classifai-setup__step__label a:active,.classifai-setup__step__label a:focus,.classifai-setup__step__label a:hover{color:#3c434a;display:inherit;text-decoration:none}@media screen and (max-width:480px){.classifai-setup__step__label{font-size:14px}}.classifai-setup__step.is-complete span.step-count{background:var(--classifai-admin-theme-color);color:#fff}.classifai-setup__step.is-active span.step-title{font-weight:600}.classifai-setup__step.is-active span.step-count{background:var(--classifai-admin-theme-color);color:#fff}.classifai-setup__step-divider{align-self:flex-start;border-bottom:1px solid #f0f0f0;flex-grow:1;margin-top:20px}.classifai-setup__step-label{font-size:1.2em}@media screen and (max-width:782px){.classifai-setup{margin-left:-10px}}.classifai-setup__wrapper{margin:0 auto;max-width:1232px}.classifai-setup__content{background-color:#fff;border-radius:4px;box-sizing:border-box;display:block;margin:20px;padding:24px 24px 48px}.classifai-setup__content__row{display:flex;flex-direction:row;flex-wrap:wrap;width:100%}.classifai-setup__content__row__column{display:flex;flex-basis:100%;flex-direction:column}.classifai-setup__content__row__column img{max-width:400px;width:100%}@media screen and (min-width:767px){.classifai-setup__content__row__column{flex:1;padding:0 10px}}.classifai-setup__content h1.classifai-setup-heading{font-size:22px;font-weight:600;margin:24px 0;text-align:center}.classifai-setup__content .classifai-setup-image{margin-top:20px;text-align:center}.classifai-setup__content h2.classifai-setup-title{font-size:22px;font-weight:400;margin:0;padding:0}.classifai-setup__content .classifai-step1-content,.classifai-setup__content .classifai-step4-content{margin-top:20px;max-width:400px}.classifai-setup__content .classifai-step2-content{margin:0 auto;max-width:480px}.classifai-setup__content .classifai-setup-footer{margin-top:40px}.classifai-setup__content .classifai-feature-box{margin:40px 0}.classifai-setup__content .classifai-feature-box-title{font-weight:700;text-transform:uppercase}.classifai-setup__content li.classifai-enable-feature{clear:both;display:block;list-style:none;margin-top:14px;width:100%}.classifai-setup__content li.classifai-enable-feature span.dashicons.dashicons-yes-alt{color:#48be1e}.classifai-setup__content li.classifai-enable-feature span.dashicons.dashicons-dismiss{color:#c00}.classifai-setup__content .classifai-feature-box-divider{border:1px solid #ddd}.classifai-setup__content label.classifai-feature-text,.classifai-setup__content span.classifai-feature-text{color:#707070;font-size:14px}.classifai-setup__content span.classifai-feature-text{float:left}.classifai-setup__content .classifai-setup-footer{text-align:right}.classifai-setup__content a.classifai-setup-skip-link{color:#000;font-weight:400;text-decoration:none}.classifai-setup__content .classifai-setup-footer__right{margin-left:40px}@media screen and (max-width:767px){.classifai-setup__content .classifai-step1-content,.classifai-setup__content .classifai-step4-content{margin-top:20px;max-width:100%}.classifai-setup__content h2.classifai-setup-title{text-align:center}}.classifai-step3-content .classifai-setup__content .classifai-setup-form{margin:0 auto;max-width:480px}.classifai-setup__content .classifai-setup-form .classifai-setup-form-field{margin-top:40px}.classifai-setup__content .classifai-setup-form label{display:block;font-weight:700;margin-bottom:20px;text-transform:uppercase}.classifai-setup__content .classifai-setup-form input[type=password],.classifai-setup__content .classifai-setup-form input[type=text]{font-size:14px;height:38px;margin-bottom:4px;width:100%}.classifai-setup__content .classifai-setup-form .classifai-setup-footer{margin-top:40px}.classifai-setup__content .classifai-step3-content{margin:0 auto}.classifai-setup__content .classifai-step3-content .classifai-setup-title{margin-bottom:12px;text-align:center}.classifai-setup__content .classifai-step3-content .classifai-setup-footer,.classifai-setup__content .classifai-step3-content .classifai-setup-form{margin:0 auto;max-width:480px}.classifai-setup__content .classifai-step3-content .classifai-setup-footer{margin-top:40px}.classifai-setup__content .classifai-tabs{display:block}.classifai-setup__content .classifai-tabs.tabs-center{margin:auto auto 24px}.classifai-setup__content .classifai-tabs.tabs-justify{table-layout:fixed;width:100%}.classifai-setup__content .classifai-tabs a.tab{color:#1d2327;cursor:pointer;display:inline-block;font-size:14px;padding:16px 12px;position:relative;text-decoration:none;transform:translateZ(0);transition:all .3s ease;white-space:nowrap}.classifai-setup__content .classifai-tabs a.tab:focus{box-shadow:none}.classifai-setup__content .classifai-tabs a.tab:hover{color:var(--classifai-admin-theme-color)}.classifai-setup__content .classifai-tabs a.tab:after{background:var(--classifai-admin-theme-color);border-radius:3px 3px 0 0;bottom:0;box-shadow:0 4px 10px 3px rgba(var(--classifai-admin-theme-color--rgb),.15);content:"";height:3px;left:0;opacity:0;position:absolute;right:0;transform:scaleX(0);transition:all .3s cubic-bezier(1,0,0,1);will-change:transform,box-shadow,opacity}.classifai-setup__content .classifai-tabs a.tab.active{color:var(--classifai-admin-theme-color);font-weight:600}.classifai-setup__content .classifai-tabs a.tab.active:after{opacity:1;transform:scale(1)}.classifai-setup__content p.classifai-setup-error{color:red;text-align:center}.classifai-setup__content span.classifai-input-description{font-size:12px}.classifai-toggle{cursor:pointer;display:inline-block;text-align:right;width:100%}.classifai-toggle-switch{background:transparent;border:1px solid #1e1e1e;border-radius:9px;box-sizing:border-box;display:inline-block;height:18px;position:relative;transition:background .25s;vertical-align:middle;width:36px}.classifai-toggle-switch:after,.classifai-toggle-switch:before{content:""}.classifai-toggle-switch:before{background:#1e1e1e;border-radius:50%;box-sizing:border-box;display:block;height:12px;left:2px;position:absolute;top:2px;transition:left .25s;width:12px}.classifai-toggle-checkbox:checked+.classifai-toggle-switch{background:var(--classifai-admin-theme-color);border-color:var(--classifai-admin-theme-color)}.classifai-toggle-checkbox:checked+.classifai-toggle-switch:before{background-color:#fff;left:20px}.classifai-toggle-checkbox{position:absolute;visibility:hidden}#classifai-generate-excerpt{position:absolute;right:12px;top:70px} .tippy-box[data-animation=fade][data-state=hidden]{opacity:0}[data-tippy-root]{max-width:calc(100vw - 10px)}.tippy-box{background-color:#333;border-radius:4px;color:#fff;font-size:14px;line-height:1.4;outline:0;position:relative;transition-property:transform,visibility,opacity;white-space:normal}.tippy-box[data-placement^=top]>.tippy-arrow{bottom:0}.tippy-box[data-placement^=top]>.tippy-arrow:before{border-top-color:initial;border-width:8px 8px 0;bottom:-7px;left:0;transform-origin:center top}.tippy-box[data-placement^=bottom]>.tippy-arrow{top:0}.tippy-box[data-placement^=bottom]>.tippy-arrow:before{border-bottom-color:initial;border-width:0 8px 8px;left:0;top:-7px;transform-origin:center bottom}.tippy-box[data-placement^=left]>.tippy-arrow{right:0}.tippy-box[data-placement^=left]>.tippy-arrow:before{border-left-color:initial;border-width:8px 0 8px 8px;right:-7px;transform-origin:center left}.tippy-box[data-placement^=right]>.tippy-arrow{left:0}.tippy-box[data-placement^=right]>.tippy-arrow:before{border-right-color:initial;border-width:8px 8px 8px 0;left:-7px;transform-origin:center right}.tippy-box[data-inertia][data-state=visible]{transition-timing-function:cubic-bezier(.54,1.5,.38,1.11)}.tippy-arrow{color:#333;height:16px;width:16px}.tippy-arrow:before{border-color:transparent;border-style:solid;content:"";position:absolute}.tippy-content{padding:5px 9px;position:relative;z-index:1} .tippy-box[data-theme~=light]{background-color:#fff;box-shadow:0 0 20px 4px rgba(154,161,177,.15),0 4px 80px -8px rgba(36,40,47,.25),0 4px 4px -2px rgba(91,94,105,.15);color:#26323d}.tippy-box[data-theme~=light][data-placement^=top]>.tippy-arrow:before{border-top-color:#fff}.tippy-box[data-theme~=light][data-placement^=bottom]>.tippy-arrow:before{border-bottom-color:#fff}.tippy-box[data-theme~=light][data-placement^=left]>.tippy-arrow:before{border-left-color:#fff}.tippy-box[data-theme~=light][data-placement^=right]>.tippy-arrow:before{border-right-color:#fff}.tippy-box[data-theme~=light]>.tippy-backdrop{background-color:#fff}.tippy-box[data-theme~=light]>.tippy-svg-arrow{fill:#fff} diff --git a/dist/commands.asset.php b/dist/commands.asset.php new file mode 100644 index 000000000..942cfc7f6 --- /dev/null +++ b/dist/commands.asset.php @@ -0,0 +1 @@ + array('wp-commands', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives'), 'version' => '29252950274641f22357'); diff --git a/dist/commands.js b/dist/commands.js new file mode 100644 index 000000000..db108b161 --- /dev/null +++ b/dist/commands.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.commands,a=window.wp.element,c=window.wp.primitives,s=(0,a.createElement)(c.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(c.Path,{d:"M14.5 13.8c-1.1 0-2.1.7-2.4 1.8H4V17h8.1c.3 1 1.3 1.8 2.4 1.8s2.1-.7 2.4-1.8H20v-1.5h-3.1c-.3-1-1.3-1.7-2.4-1.7zM11.9 7c-.3-1-1.3-1.8-2.4-1.8S7.4 6 7.1 7H4v1.5h3.1c.3 1 1.3 1.8 2.4 1.8s2.1-.7 2.4-1.8H20V7h-8.1z"})),t=(0,a.createElement)(c.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(c.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})),l=(0,a.createElement)(c.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)(c.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM5 4.5h14c.3 0 .5.2.5.5v8.4l-3-2.9c-.3-.3-.8-.3-1 0L11.9 14 9 12c-.3-.2-.6-.2-.8 0l-3.6 2.6V5c-.1-.3.1-.5.4-.5zm14 15H5c-.3 0-.5-.2-.5-.5v-2.4l4.1-3 3 1.9c.3.2.7.2.9-.1L16 12l3.5 3.4V19c0 .3-.2.5-.5.5z"})),i=window.wp.i18n,n=window.wp.plugins;"function"==typeof e.useCommandLoader&&(0,n.registerPlugin)("classifai-commands",{render:()=>((0,e.useCommandLoader)({name:"classifai",hook:()=>{const e=[],a=document.querySelector(".editor-post-excerpt button.classifai-post-excerpt"),c=document.querySelector(".classifai-post-status button.title");return e.push({name:"classifai/settings",label:(0,i.__)("ClassifAI settings","classifai"),icon:s,callback:()=>{document.location.href="tools.php?page=classifai"}}),a&&e.push({name:"classifai/generate-excerpt",label:(0,i.__)("ClassifAI: Generate excerpt","classifai"),icon:t,callback:({close:e})=>{e(),a.scrollIntoView({block:"center"}),a.click()}}),c&&e.push({name:"classifai/generate-titles",label:(0,i.__)("ClassifAI: Generate titles","classifai"),icon:t,callback:({close:e})=>{e(),c.scrollIntoView({block:"center"}),c.click()}}),"undefined"!=typeof classifaiDalleData&&e.push({name:"classifai/generate-image",label:(0,i.__)("ClassifAI: Generate image","classifai"),icon:l,callback:()=>{document.location.href="upload.php?action=classifai-generate-image"}}),{commands:e}}}),null)})})(); \ No newline at end of file diff --git a/dist/content-resizing-plugin.asset.php b/dist/content-resizing-plugin.asset.php new file mode 100644 index 000000000..ed1f73547 --- /dev/null +++ b/dist/content-resizing-plugin.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-wordcount'), 'version' => 'bc2e64ef6385d5eae7f7'); diff --git a/dist/content-resizing-plugin.css b/dist/content-resizing-plugin.css new file mode 100644 index 000000000..8439bed8d --- /dev/null +++ b/dist/content-resizing-plugin.css @@ -0,0 +1 @@ +.classifai-content-resize__stat-header{width:130px}.classifai-content-resize__grow-stat strong,.classifai-content-resize__shrink-stat strong{font-family:monospace}.classifai-content-resize__shrink-stat{color:#dc3232}.classifai-content-resize__grow-stat{color:#46b450}.classifai-content-resize__result-wrapper{max-width:700px}.classifai-content-resize__result-table{border:1px solid #e4e4e4;border-collapse:collapse;width:100%}.classifai-content-resize__result-table td,.classifai-content-resize__result-table th{border:1px solid #e4e4e4;border-collapse:collapse;padding:.75rem .5rem}.classifai-content-resize__result-table tr{cursor:pointer}.classifai-content-resize__result-table tr:hover{background-color:#f3f3f3}.classifai-content-resize__modal-close-btn{position:absolute;right:1rem;top:1rem;z-index:10}.classifai-content-resize__overlay{align-items:center;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);background-color:rgba(0,0,0,.2);border-radius:8px;display:flex;height:calc(100% + 1.6rem);justify-content:center;left:-.8rem;position:absolute;top:-.8rem;width:calc(100% + 1.6rem);z-index:10}.classifai-content-resize__overlay-text{background-color:rgba(0,0,0,.5);border-radius:5px;color:#fff;font-size:1rem;padding:.5rem}.classifai-content-resize__blot{animation:blotIn .75s ease-in;background-color:#000;color:rgba(0,0,0,.5)}@keyframes blotIn{95%{background-color:inherit}to{background-color:transparent}}#classifai-content-resize__mock-content{background-color:#fff;height:100%;left:0;position:absolute;top:0;width:100%;z-index:9} diff --git a/dist/content-resizing-plugin.js b/dist/content-resizing-plugin.js new file mode 100644 index 000000000..3bc304200 --- /dev/null +++ b/dist/content-resizing-plugin.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.element,t=window.wp.plugins,n=window.wp.blockEditor,i=window.wp.editor,s=window.wp.data,c=window.wp.dom,l=window.wp.compose,a=window.wp.components,r=window.wp.wordcount,o=window.wp.i18n,d=(0,e.createElement)("svg",{width:"20",height:"15",viewBox:"0 0 61 46",fill:"none",xmlns:"http://www.w3.org/2000/svg"},(0,e.createElement)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3.51922 0C1.57575 0 0 1.5842 0 3.53846V42.4615C0 44.4158 1.57575 46 3.51922 46H57.4808C59.4243 46 61 44.4158 61 42.4615V3.53846C61 1.5842 59.4243 0 57.4808 0H3.51922ZM16.709 8.13836H21.4478L33.58 39.5542H27.524L24.0318 30.5144H13.9699L10.5169 39.5542H4.55669L16.709 8.13836ZM19.0894 16.7007C18.9846 17.041 18.878 17.3735 18.7702 17.698L18.7582 17.7344L15.9976 25.1398H22.1464L19.4013 17.6851L19.0894 16.7007ZM40.3164 8.13836H52.9056V12.1528L49.4929 12.9715V34.6306L52.9056 35.41V39.4338H40.3164V35.41L43.7291 34.6306V12.9715L40.3164 12.1528V8.13836Z"})),u={clientId:"",resizingType:null,isResizing:!1},g=(0,s.createReduxStore)("resize-content-store",{reducer(e=u,t){switch(t.type){case"SET_CLIENT_ID":return{...e,clientId:t.clientId};case"SET_RESIZING_TYPE":return{...e,resizingType:t.resizingType};case"SET_IS_RESIZING":return{...e,isResizing:t.isResizing}}return e},actions:{setClientId:e=>({type:"SET_CLIENT_ID",clientId:e}),setResizingType:e=>({type:"SET_RESIZING_TYPE",resizingType:e}),setIsResizing:e=>({type:"SET_IS_RESIZING",isResizing:e})},selectors:{getClientId:e=>e.clientId,getResizingType:e=>e.resizingType,getIsResizing:e=>e.isResizing}});(0,s.register)(g);const p=({count:t=0,countEntity:n="word"})=>0===t?(0,e.createElement)("div",null,"word"===n?(0,o.__)("No change in word count.","classifai"):(0,o.__)("No change in character count.","classifai")):t<0?(0,e.createElement)("div",{className:"classifai-content-resize__shrink-stat"},"word"===n?(0,e.createElement)(e.Fragment,null,(0,e.createElement)("strong",null,t)," ",(0,o.__)("words","classifai")):(0,e.createElement)(e.Fragment,null,(0,e.createElement)("strong",null,t)," ",(0,o.__)("characters","classifai"))):(0,e.createElement)("div",{className:"classifai-content-resize__grow-stat"},"word"===n?(0,e.createElement)(e.Fragment,null,(0,e.createElement)("strong",null,"+",t)," ",(0,o.__)("words","classifai")):(0,e.createElement)(e.Fragment,null,(0,e.createElement)("strong",null,"+",t)," ",(0,o.__)("characters","classifai")));function m(e){return e=e.replace(/
/g,"\n"),(0,c.__unstableStripHTML)(e).trim().replace(/\n\n+/g,"\n\n")}(0,t.registerPlugin)("tenup-openai-expand-reduce-content",{render:()=>{const[t,c]=(0,e.useState)(""),[l,d]=(0,e.useState)(null),[u,_]=(0,e.useState)([]),[E,w]=(0,e.useState)(!1),{isMultiBlocksSelected:h,resizingType:f,isResizing:z}=(0,s.useSelect)((e=>({isMultiBlocksSelected:e(n.store).hasMultiSelection(),resizingType:e(g).getResizingType(),isResizing:e(g).getIsResizing()})));function I(){d(null),_([]),w(!1),(0,s.dispatch)(g).setResizingType(null)}return(0,e.useEffect)((()=>{f&&(async()=>{await async function(){var e;const t=(0,s.select)(n.store).getSelectedBlock(),i=null!==(e=t.attributes.content)&&void 0!==e?e:"";d(t),c(m(i)),(0,s.dispatch)(g).setIsResizing(!0)}()})()}),[f]),(0,e.useEffect)((()=>{z&&l&&(async()=>{const e=await async function(){let e=[];const n=`${wpApiSettings.root}classifai/v1/openai/resize-content`,c=(0,s.select)(i.store).getCurrentPostId(),a=new FormData;a.append("id",c),a.append("content",t),a.append("resize_type",f),(0,s.dispatch)(g).setClientId(l.clientId);const r=await fetch(n,{method:"POST",body:a,headers:new Headers({"X-WP-Nonce":wpApiSettings.nonce})});return 200===r.status?e=await r.json():((0,s.dispatch)(g).setIsResizing(!1),(0,s.dispatch)(g).setClientId(""),I()),(0,s.dispatch)(g).setIsResizing(!1),(0,s.dispatch)(g).setClientId(""),e}();_(e),w(!0)})()}),[z,l]),h||z?null:!z&&u.length&&E&&(0,e.createElement)(a.Modal,{title:(0,o.__)("Select a suggestion","classifai"),isFullScreen:!1,className:"classifai-content-resize__suggestion-modal",onRequestClose:()=>{w(!1),I()}},(0,e.createElement)("div",{className:"classifai-content-resize__result-wrapper"},(0,e.createElement)("table",{className:"classifai-content-resize__result-table"},(0,e.createElement)("thead",null,(0,e.createElement)("tr",null,(0,e.createElement)("th",null,(0,o.__)("Suggestion","classifai")),(0,e.createElement)("th",{className:"classifai-content-resize__stat-header"},(0,o.__)("Stats","classifai")),(0,e.createElement)("th",null,(0,o.__)("Action","classifai")))),(0,e.createElement)("tbody",null,u.map(((i,c)=>{const d=(0,r.count)(t,"words"),u=(0,r.count)(t,"characters_including_spaces"),g=(0,r.count)(i,"words")-d,m=(0,r.count)(i,"characters_including_spaces")-u;return(0,e.createElement)("tr",{key:c},(0,e.createElement)("td",null,i),(0,e.createElement)("td",null,(0,e.createElement)(p,{count:g}),(0,e.createElement)(p,{count:m,countEntity:"character"})),(0,e.createElement)("td",null,(0,e.createElement)(a.Button,{text:(0,o.__)("Select","classifai"),variant:"secondary",onClick:()=>{return e=i,(0,s.dispatch)(n.store).updateBlockAttributes(l.clientId,{content:e}),(0,s.dispatch)(n.store).selectionChange(l.clientId,"content",0,e.length),void I();var e},tabIndex:"0"})))}))))))}});const _=["#8c2525","#ca4444","#303030"];let E=0;function w(e="",t){if(!t)return;if(!(0,s.select)(g).getIsResizing())return void clearTimeout(E);const n=e.split(" "),i=function(e=[],t=10){const n=Array.from({length:e.length},((e,t)=>t)),i=[];for(;i.length{if(i.includes(t)){const t=Math.floor(5*Math.random());return`${e}`}return e}));t.current.innerHTML=c.join(" "),E=setTimeout((()=>{requestAnimationFrame((()=>w(e,t)))}),1e3/1.35)}const h=(0,l.createHigherOrderComponent)((t=>n=>{const{currentClientId:i}=(0,s.useSelect)((e=>({currentClientId:e(g).getClientId()}))),c=(0,e.useRef)();if(i!==n.clientId)return(0,e.createElement)(t,n);if("core/paragraph"!==n.name)return(0,e.createElement)(t,n);const l=m(n.attributes.content);return(0,s.select)(g).getIsResizing()&&requestAnimationFrame((()=>w(l,c))),(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{style:{position:"relative"}},(0,e.createElement)("div",{className:"classifai-content-resize__overlay"},(0,e.createElement)("div",{className:"classifai-content-resize__overlay-text"},(0,o.__)("Processing data…","classifai"))),(0,e.createElement)("div",{id:"classifai-content-resize__mock-content",ref:c},l),(0,e.createElement)(t,n)))}),"withInspectorControl");wp.hooks.addFilter("editor.BlockEdit","resize-content/lock-block-editing",h);const f=(0,l.createHigherOrderComponent)((t=>i=>{const{isMultiBlocksSelected:c,resizingType:l}=(0,s.useSelect)((e=>({isMultiBlocksSelected:e(n.store).hasMultiSelection(),currentClientId:e(g).getClientId(),resizingType:e(g).getResizingType()})));return"core/paragraph"!==i.name?(0,e.createElement)(t,i):(0,e.createElement)(e.Fragment,null,l||c?null:(0,e.createElement)(n.BlockControls,{group:"other"},(0,e.createElement)(a.ToolbarDropdownMenu,{icon:d,className:"classifai-resize-content-btn",controls:[{title:(0,o.__)("Expand this text","classifai"),onClick:()=>{(0,s.dispatch)(g).setResizingType("grow")}},{title:(0,o.__)("Condense this text","classifai"),onClick:()=>{(0,s.dispatch)(g).setResizingType("shrink")}}]})),(0,e.createElement)(t,i))}),"withBlockControl");wp.hooks.addFilter("editor.BlockEdit","resize-content/lock-block-editing",f)})(); \ No newline at end of file diff --git a/dist/generate-excerpt-classic.asset.php b/dist/generate-excerpt-classic.asset.php new file mode 100644 index 000000000..887f9cfbb --- /dev/null +++ b/dist/generate-excerpt-classic.asset.php @@ -0,0 +1 @@ + array('wp-api-fetch'), 'version' => '284bc067245a0a71d7c5'); diff --git a/dist/generate-excerpt-classic.css b/dist/generate-excerpt-classic.css new file mode 100644 index 000000000..3f1040c55 --- /dev/null +++ b/dist/generate-excerpt-classic.css @@ -0,0 +1 @@ +#titlewrap{display:flex}#titlewrap #classifai-openai__title-generate-btn{height:2.348rem;line-height:2.348rem;margin-left:.5rem;position:relative}#titlewrap #classifai-openai__title-generate-btn>.classifai-openai__title-generate-btn--spinner{display:none;left:50%;line-height:29px;position:absolute;top:50%;transform:translate(-50%,-50%)}#postexcerpt #classifai-openai__excerpt-generate-btn{display:block;margin:1em 0 0 auto;max-width:100%;position:relative;text-align:center;width:160px}#postexcerpt #classifai-openai__excerpt-generate-btn>.classifai-openai__excerpt-generate-btn--spinner{display:none;left:50%;line-height:29px;position:absolute;top:50%;transform:translate(-50%,-50%)}#classifai-openai__overlay{background:rgba(0,0,0,.35);height:100%;left:0;top:0;z-index:99998}#classifai-openai__modal,#classifai-openai__overlay{position:fixed;transition:opacity .3s ease!important;width:100%}#classifai-openai__modal{background:#fff;border:1px solid;box-shadow:0 .7px 1px rgba(0,0,0,.15),0 2.7px 3.8px -.2px rgba(0,0,0,.15),0 5.5px 7.8px -.3px rgba(0,0,0,.15),.1px 11.5px 16.4px -.5px rgba(0,0,0,.15);left:50%;margin:0 1rem;max-width:900px;top:100px;transform:translate(-50%,-10%);z-index:99999}#classifai-openai__results-title{font-size:1.5rem!important;padding-top:1.5rem!important}#classifai-openai__results-content{display:flex;flex-flow:row wrap;gap:1rem;padding:1rem 1rem 1.5rem}#classifai-openai__close-modal-button{cursor:pointer;height:40px;position:fixed;right:.5rem;top:.5rem;width:40px}#classifai-openai__close-modal-button:before{content:"";display:block;font-family:dashicons;font-size:3rem;position:relative;right:0;top:.5rem}.classifai-openai__result-item{flex-basis:0;flex-grow:1;min-width:25%}.classifai-openai__result-item textarea{display:block;height:80px;width:100%}.classifai-openai__select-title{margin-top:1rem!important}.classifai-openai--fade-in #classifai-openai__overlay{opacity:1!important;transition:opacity .3s ease!important}.classifai-openai--fade-in #classifai-openai__modal{opacity:1!important;transform:translate(-50%)!important;transition:opacity .3s ease,transform .3s ease!important}.classifai-openai__excerpt-generate-btn--spinner:before,.classifai-openai__title-generate-btn--spinner:before{animation:rotation 2s linear infinite;content:"";display:block;font-family:dashicons;font-size:1.75rem;height:1.75rem;width:1.75rem}@keyframes rotation{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}} diff --git a/dist/generate-excerpt-classic.js b/dist/generate-excerpt-classic.js new file mode 100644 index 000000000..aab9096fa --- /dev/null +++ b/dist/generate-excerpt-classic.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.apiFetch;var n=e.n(t);const a=window.classifaiGenerateExcerpt||{};var r;(r=jQuery)(document).ready((()=>{document.getElementById("postexcerpt")&&function(){var e,t;const i=document.getElementById("excerpt");let s=!1;r("",{text:i.value?null!==(e=a?.regenerateText)&&void 0!==e?e:"":null!==(t=a?.buttonText)&&void 0!==t?t:"",class:"classifai-openai__excerpt-generate-btn--text"}).wrap('
').parent().append(r("",{class:"classifai-openai__excerpt-generate-btn--spinner"})).insertAfter(i);const c=r("#post_ID").val();r(document).on("click","#classifai-openai__excerpt-generate-btn",(()=>{if(s)return;const e=r(".classifai-openai__excerpt-generate-btn--text"),t=r(".classifai-openai__excerpt-generate-btn--spinner");e.css("opacity","0"),t.show(),s=!0;const o=a?.path+c;n()({path:o}).then((n=>{var c;e.css("opacity","1"),t.hide(),s=!1,r(i).val(n).trigger("input"),e.text(null!==(c=a?.regenerateText)&&void 0!==c?c:"")}))}))}()}))})(); \ No newline at end of file diff --git a/dist/generate-image-media-upload.asset.php b/dist/generate-image-media-upload.asset.php new file mode 100644 index 000000000..a9a60e7d7 --- /dev/null +++ b/dist/generate-image-media-upload.asset.php @@ -0,0 +1 @@ + array('wp-i18n'), 'version' => '5cb5eef05c879e06dcd5'); diff --git a/dist/generate-image-media-upload.js b/dist/generate-image-media-upload.js new file mode 100644 index 000000000..99de9f32e --- /dev/null +++ b/dist/generate-image-media-upload.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.wp.i18n;document.addEventListener("DOMContentLoaded",(function(){if(wp.media){const i=wp.media({title:(0,e.__)("Generate images","classifai"),button:{text:(0,e.__)("View details","classifai")},multiple:!1,frame:"select"});i.on("open",(function(){const e=i.$el.find(".media-menu-item#menu-item-upload"),t=i.$el.find(".media-menu-item#menu-item-generate");e.length&&e.hide(),t.length&&t.trigger("click")})),i.on("close",(function(){classifaiGenerateImages&&(window.location.href=classifaiGenerateImages.upload_url)})),i.on("select",(function(){if(classifaiGenerateImages){const e=i.state().get("selection").first().toJSON();window.location.href=`${classifaiGenerateImages.upload_url}?item=${e.id}`}})),i.open()}}))})(); \ No newline at end of file diff --git a/dist/generate-title-classic.asset.php b/dist/generate-title-classic.asset.php index 15741a669..2d0287b71 100644 --- a/dist/generate-title-classic.asset.php +++ b/dist/generate-title-classic.asset.php @@ -1 +1 @@ - array('wp-api-fetch'), 'version' => '86c7a3e0ce047dd248e3'); + array('wp-api-fetch'), 'version' => '6f8009d31b5c3b9d753c'); diff --git a/dist/generate-title-classic.css b/dist/generate-title-classic.css index 1ae13889c..3f1040c55 100644 --- a/dist/generate-title-classic.css +++ b/dist/generate-title-classic.css @@ -1 +1 @@ -#titlewrap{display:flex}#titlewrap #classifai-openai__title-generate-btn{height:2.348rem;line-height:2.348rem;margin-left:.5rem;position:relative}#titlewrap #classifai-openai__title-generate-btn>.classifai-openai__title-generate-btn--spinner{display:none;left:50%;line-height:29px;position:absolute;top:50%;transform:translate(-50%,-50%)}#classifai-openai__overlay{background:rgba(0,0,0,.35);height:100%;left:0;top:0;z-index:99998}#classifai-openai__modal,#classifai-openai__overlay{position:fixed;transition:opacity .3s ease!important;width:100%}#classifai-openai__modal{background:#fff;border:1px solid;box-shadow:0 .7px 1px rgba(0,0,0,.15),0 2.7px 3.8px -.2px rgba(0,0,0,.15),0 5.5px 7.8px -.3px rgba(0,0,0,.15),.1px 11.5px 16.4px -.5px rgba(0,0,0,.15);left:50%;margin:0 1rem;max-width:900px;top:100px;transform:translate(-50%,-10%);z-index:99999}#classifai-openai__results-title{font-size:1.5rem!important;padding-top:1.5rem!important}#classifai-openai__results-content{display:flex;flex-flow:row wrap;gap:1rem;padding:1rem 1rem 1.5rem}#classifai-openai__close-modal-button{cursor:pointer;height:40px;position:fixed;right:.5rem;top:.5rem;width:40px}#classifai-openai__close-modal-button:before{content:"";display:block;font-family:dashicons;font-size:3rem;position:relative;right:0;top:.5rem}.classifai-openai__result-item{flex-basis:0;flex-grow:1;min-width:25%}.classifai-openai__result-item textarea{display:block;height:80px;width:100%}.classifai-openai__select-title{margin-top:1rem!important}.classifai-openai--fade-in #classifai-openai__overlay{opacity:1!important;transition:opacity .3s ease!important}.classifai-openai--fade-in #classifai-openai__modal{opacity:1!important;transform:translate(-50%)!important;transition:opacity .3s ease,transform .3s ease!important}.classifai-openai__title-generate-btn--spinner:before{animation:rotation 2s linear infinite;content:"";display:block;font-family:dashicons;font-size:1.75rem;height:1.75rem;width:1.75rem}@keyframes rotation{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}} +#titlewrap{display:flex}#titlewrap #classifai-openai__title-generate-btn{height:2.348rem;line-height:2.348rem;margin-left:.5rem;position:relative}#titlewrap #classifai-openai__title-generate-btn>.classifai-openai__title-generate-btn--spinner{display:none;left:50%;line-height:29px;position:absolute;top:50%;transform:translate(-50%,-50%)}#postexcerpt #classifai-openai__excerpt-generate-btn{display:block;margin:1em 0 0 auto;max-width:100%;position:relative;text-align:center;width:160px}#postexcerpt #classifai-openai__excerpt-generate-btn>.classifai-openai__excerpt-generate-btn--spinner{display:none;left:50%;line-height:29px;position:absolute;top:50%;transform:translate(-50%,-50%)}#classifai-openai__overlay{background:rgba(0,0,0,.35);height:100%;left:0;top:0;z-index:99998}#classifai-openai__modal,#classifai-openai__overlay{position:fixed;transition:opacity .3s ease!important;width:100%}#classifai-openai__modal{background:#fff;border:1px solid;box-shadow:0 .7px 1px rgba(0,0,0,.15),0 2.7px 3.8px -.2px rgba(0,0,0,.15),0 5.5px 7.8px -.3px rgba(0,0,0,.15),.1px 11.5px 16.4px -.5px rgba(0,0,0,.15);left:50%;margin:0 1rem;max-width:900px;top:100px;transform:translate(-50%,-10%);z-index:99999}#classifai-openai__results-title{font-size:1.5rem!important;padding-top:1.5rem!important}#classifai-openai__results-content{display:flex;flex-flow:row wrap;gap:1rem;padding:1rem 1rem 1.5rem}#classifai-openai__close-modal-button{cursor:pointer;height:40px;position:fixed;right:.5rem;top:.5rem;width:40px}#classifai-openai__close-modal-button:before{content:"";display:block;font-family:dashicons;font-size:3rem;position:relative;right:0;top:.5rem}.classifai-openai__result-item{flex-basis:0;flex-grow:1;min-width:25%}.classifai-openai__result-item textarea{display:block;height:80px;width:100%}.classifai-openai__select-title{margin-top:1rem!important}.classifai-openai--fade-in #classifai-openai__overlay{opacity:1!important;transition:opacity .3s ease!important}.classifai-openai--fade-in #classifai-openai__modal{opacity:1!important;transform:translate(-50%)!important;transition:opacity .3s ease,transform .3s ease!important}.classifai-openai__excerpt-generate-btn--spinner:before,.classifai-openai__title-generate-btn--spinner:before{animation:rotation 2s linear infinite;content:"";display:block;font-family:dashicons;font-size:1.75rem;height:1.75rem;width:1.75rem}@keyframes rotation{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}} diff --git a/dist/gutenberg-plugin.asset.php b/dist/gutenberg-plugin.asset.php index f42c732be..796ca2a26 100644 --- a/dist/gutenberg-plugin.asset.php +++ b/dist/gutenberg-plugin.asset.php @@ -1 +1 @@ - array('react', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-plugins'), 'version' => '8a4bc513cdeb0113e497'); + array('react', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'eaf02626032e72db78d7'); diff --git a/dist/gutenberg-plugin.js b/dist/gutenberg-plugin.js index 63705bb7d..ba7d5f6b1 100644 --- a/dist/gutenberg-plugin.js +++ b/dist/gutenberg-plugin.js @@ -1,3 +1,4 @@ -(()=>{"use strict";const e=window.wp.element,t=window.React;var s;function i(){return i=Object.assign?Object.assign.bind():function(e){for(var t=1;t({type:"SET_AUDIO_ID",id:e}),setIsProcessing:e=>({type:"SET_PROCESSING_STATUS",status:e})},selectors:{getAudioId:e=>e.audioId,getIsProcessing:e=>e.isProcessing}});(0,r.register)(g);const{classifaiEmbeddingData:f,classifaiPostData:y}=window,_=()=>(0,e.createElement)(l.Icon,{className:"components-panel__icon",icon:o,size:24}),m=()=>{const t=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_process_content"))),{editPost:s}=(0,r.useDispatch)("core/editor"),i="no"===t?"no":"yes";return(0,e.createElement)(l.ToggleControl,{label:(0,a.__)("Process content on update","classifai"),help:"yes"===i?(0,a.__)("ClassifAI language processing is enabled","classifai"):(0,a.__)("ClassifAI language processing is disabled","classifai"),checked:"yes"===i,onChange:e=>{s({classifai_process_content:e?"yes":"no"})}})},w=async e=>{const{select:t,dispatch:s}=wp.data,i=t("core/editor").getCurrentPostId(),o=t("core/editor").getCurrentPostType(),n=t("core/editor").getPostTypeLabel()||(0,a.__)("Post","classifai");if(e&&e.terms){let r=!1;const c=Object.keys(e.terms),l={};if(c.forEach((s=>{let i=s;"post_tag"===s&&(i="tags"),"category"===s&&(i="categories");const o=[...t("core/editor").getEditedPostAttribute(s)||[],...e.terms[s].map((e=>Number.parseInt(e)))].filter(((e,t,s)=>s.indexOf(e)===t));o&&o.length&&(r=!0,l[i]=o)})),r){const e=await t("core/editor").isEditedPostDirty();await s("core").editEntityRecord("postType",o,i,l),e||await s("core").saveEditedEntityRecord("postType",o,i),s("core/notices").createSuccessNotice((0,a.sprintf)(/** translators: %s is post type label. */ -(0,a.__)("%s classified successfully.","classifai"),n),{type:"snackbar"})}}},P=()=>{if("yes"==("no"===(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_process_content")))?"no":"yes"))return null;const t=wp.data.select("core/editor").getCurrentPostId(),s=wp.data.select("core/editor").getPostTypeLabel()||(0,a.__)("Post","classifai"),i=(0,a.sprintf)(/** translators: %s Post type label */ -(0,a.__)("Classify %s","classifai"),s);return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(l.Button,{variant:"secondary","data-id":t,onClick:e=>(({button:e,endpoint:t,callback:s=!1,buttonText:i=(0,a.__)("Rescan","classifai")})=>{const o=e.getAttribute("data-id"),[r]=e.parentNode.getElementsByClassName("spinner"),[c]=e.parentNode.getElementsByClassName("error"),l=`${t}${o}`;e.setAttribute("disabled","disabled"),r.style.display="inline-block",r.classList.add("is-active"),c.style.display="none",wp.apiRequest({path:l}).then((t=>{e.removeAttribute("disabled"),r.style.display="none",r.classList.remove("is-active"),e.textContent=i,s&&s(t)}),(t=>{const s=n(t,"responseJSON",{code:"unknown_error",message:(0,a.__)("An unknown error occurred.","classifai")});r.style.display="none",r.classList.remove("is-active"),e.removeAttribute("disabled"),e.textContent=i,c.style.display="inline-block",c.textContent=`Error: ${s.message}`}))})({button:e.target,endpoint:"/classifai/v1/generate-tags/",callback:w,buttonText:i})},i),(0,e.createElement)("span",{className:"spinner",style:{display:"none",float:"none"}}),(0,e.createElement)("span",{className:"error",style:{display:"none",color:"#bc0b0b",padding:"5px"}}))};let h="";const b=t=>{const[s,i]=(0,e.useState)(!1),[o,n]=(0,e.useState)((new Date).getTime());let c=!1;const d="yes"===(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_synthesize_speech"))),u=(0,r.useSelect)((e=>e("core/editor").getCurrentPostType())),p=(0,r.useSelect)((e=>e(g).getIsProcessing()));"undefined"!=typeof classifaiTextToSpeechData&&classifaiTextToSpeechData.supportedPostTypes.includes(u)&&(c=!0);const f=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_post_audio_id"))),y=t.audioId||f,_=(0,r.useSelect)((e=>e("core").getEntityRecords("postType","attachment",{include:[y]}))),m=_&&_.length>0&&_[0].source_url,w=(0,e.useRef)(!1);(0,e.useEffect)((()=>{const e=document.getElementById("classifai-audio-preview");e&&(s?e.play():e.pause())}),[s]),(0,e.useEffect)((()=>{p&&(w.current=!0),w.current&&!p&&n((new Date).getTime())}),[p]);const P=`${m}?ver=${o}`;let h="controls-play";return p?h="format-audio":s&&(h="controls-pause"),(0,e.createElement)(e.Fragment,null,(0,e.createElement)(l.ToggleControl,{label:(0,a.__)("Enable audio generation","classifai"),help:c?(0,a.__)("ClassifAI will generate audio for the post when it is published or updated.","classifai"):(0,a.__)("Text to Speech generation is disabled for this post type.","classifai"),checked:c&&d,onChange:e=>{wp.data.dispatch("core/editor").editPost({classifai_synthesize_speech:e?"yes":"no"})},disabled:!c}),m&&(0,e.createElement)("audio",{id:"classifai-audio-preview",src:P,onEnded:()=>i(!1)}),m&&d&&(0,e.createElement)(l.BaseControl,{id:"classifai-audio-controls",help:p?"":(0,a.__)("Preview the generated audio.","classifai")},(0,e.createElement)(l.Button,{id:"classifai-audio-controls__preview-btn",icon:(0,e.createElement)(l.Icon,{icon:h}),variant:"secondary",onClick:()=>i(!s),disabled:p,isBusy:p},p?(0,a.__)("Generating audio..","classifai"):(0,a.__)("Preview","classifai"))))};let E=!1;wp.data.subscribe((function(){const{select:e}=wp.data;if("yes"!==e("core/editor").getEditedPostAttribute("classifai_synthesize_speech"))return;let t=e("core/editor").isSavingPost();const s=e("core/editor").isAutosavingPost(),i=e("core/editor").getCurrentPostId();t=t&&!s,t&&!E&&(E=!0),!t&&E&&((async e=>{const{select:t,dispatch:s}=wp.data,i=`${wpApiSettings.root}classifai/v1/synthesize-speech/${e}`;if(t(g).getIsProcessing())return;s(g).setIsProcessing(!0);const o=await fetch(i,{headers:new Headers({"X-WP-Nonce":wpApiSettings.nonce})});if(200!==o.status)return s(g).setIsProcessing(!1),!1;const a=await o.json();if(a.success)return s(g).setAudioId(a.audio_id),s(g).setIsProcessing(!1),h&&(s(u.store).removeNotice(h),h=""),!0;h=a.code,s("core/notices").createErrorNotice(a.message,{id:h}),s(g).setIsProcessing(!1)})(i),E=!1)})),(0,d.registerPlugin)("classifai-plugin",{render:()=>{const t=(0,r.useSelect)((e=>e("core/editor").getCurrentPostType())),s=(0,r.useSelect)((e=>e("core/editor").getCurrentPostAttribute("status"))),i=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_post_audio_id"))),o=(0,r.useSelect)((e=>e(g).getAudioId()))||i,n=y&&y.NLUEnabled,l=f&&f.enabled,d=y&&y.supportedPostTypes&&y.supportedPostTypes.includes(t),u=f&&f.supportedPostTypes&&f.supportedPostTypes.includes(t),p=y&&y.supportedPostStatues&&y.supportedPostStatues.includes(s),w=f&&f.supportedPostStatues&&f.supportedPostStatues.includes(s),h=y&&!(y.noPermissions&&1===parseInt(y.noPermissions))&&n&&d&&p,E=f&&!(f.noPermissions&&1===parseInt(f.noPermissions))&&l&&u&&w;return(0,e.createElement)(c.PluginDocumentSettingPanel,{title:(0,a.__)("ClassifAI","classifai"),icon:_,className:"classifai-panel"},(0,e.createElement)(e.Fragment,null,(h||E)&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)(m,null),h&&(0,e.createElement)(P,null))),(0,e.createElement)(b,{audioId:o}))}})})(); \ No newline at end of file +(()=>{"use strict";const e=window.wp.element,t=window.React;var s;function i(){return i=Object.assign?Object.assign.bind():function(e){for(var t=1;t({type:"SET_AUDIO_ID",id:e}),setIsProcessing:e=>({type:"SET_PROCESSING_STATUS",status:e})},selectors:{getAudioId:e=>e.audioId,getIsProcessing:e=>e.isProcessing}});(0,r.register)(p);const{classifaiEmbeddingData:g,classifaiPostData:f,classifaiTTSEnabled:_}=window,y=()=>(0,e.createElement)(l.Icon,{className:"components-panel__icon",icon:a,size:24}),m=()=>{const t=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_process_content"))),{editPost:s}=(0,r.useDispatch)("core/editor"),i="no"===t?"no":"yes";return(0,e.createElement)(l.ToggleControl,{label:(0,o.__)("Process content on update","classifai"),help:"yes"===i?(0,o.__)("ClassifAI language processing is enabled","classifai"):(0,o.__)("ClassifAI language processing is disabled","classifai"),checked:"yes"===i,onChange:e=>{s({classifai_process_content:e?"yes":"no"})}})},P=async e=>{const{select:t,dispatch:s}=wp.data,i=t("core/editor").getCurrentPostId(),a=t("core/editor").getCurrentPostType(),n=t("core/editor").getPostTypeLabel()||(0,o.__)("Post","classifai");if(e&&e.terms){let r=!1;const c=Object.keys(e.terms),l={};if(c.forEach((s=>{let i=s;"post_tag"===s&&(i="tags"),"category"===s&&(i="categories");const a=[...t("core/editor").getEditedPostAttribute(s)||[],...e.terms[s].map((e=>Number.parseInt(e)))].filter(((e,t,s)=>s.indexOf(e)===t));a&&a.length&&(r=!0,l[i]=a)})),r){const e=await t("core/editor").isEditedPostDirty();await s("core").editEntityRecord("postType",a,i,l),e||await s("core").saveEditedEntityRecord("postType",a,i),s("core/notices").createSuccessNotice((0,o.sprintf)(/** translators: %s is post type label. */ +(0,o.__)("%s classified successfully.","classifai"),n),{type:"snackbar"})}}},w=()=>{if("yes"==("no"===(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_process_content")))?"no":"yes"))return null;const t=wp.data.select("core/editor").getCurrentPostId(),s=wp.data.select("core/editor").getPostTypeLabel()||(0,o.__)("Post","classifai"),i=(0,o.sprintf)(/** translators: %s Post type label */ +(0,o.__)("Classify %s","classifai"),s);return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(l.Button,{variant:"secondary","data-id":t,onClick:e=>(({button:e,endpoint:t,callback:s=!1,buttonText:i=(0,o.__)("Rescan","classifai")})=>{const a=e.getAttribute("data-id"),[r]=e.parentNode.getElementsByClassName("spinner"),[c]=e.parentNode.getElementsByClassName("error"),l=`${t}${a}`;e.setAttribute("disabled","disabled"),r.style.display="inline-block",r.classList.add("is-active"),c.style.display="none",wp.apiRequest({path:l}).then((t=>{e.removeAttribute("disabled"),r.style.display="none",r.classList.remove("is-active"),e.textContent=i,s&&s(t)}),(t=>{const s=n(t,"responseJSON",{code:"unknown_error",message:(0,o.__)("An unknown error occurred.","classifai")});r.style.display="none",r.classList.remove("is-active"),e.removeAttribute("disabled"),e.textContent=i,c.style.display="inline-block",c.textContent=`Error: ${s.message}`}))})({button:e.target,endpoint:"/classifai/v1/generate-tags/",callback:P,buttonText:i})},i),(0,e.createElement)("span",{className:"spinner",style:{display:"none",float:"none"}}),(0,e.createElement)("span",{className:"error",style:{display:"none",color:"#bc0b0b",padding:"5px"}}))},b=()=>{const[t,s]=(0,e.useState)(!1),[i,a]=(0,e.useState)((new Date).getTime()),n=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_synthesize_speech"))),c=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_display_generated_audio"))),d=(0,r.useSelect)((e=>void 0!==e("core/editor").getPostTypeLabel&&e("core/editor").getPostTypeLabel()||(0,o.__)("Post","classifai"))),u=(0,r.useSelect)((e=>e(p).getIsProcessing())),g=(0,r.useSelect)((e=>e("core/editor").getEditedPostAttribute("classifai_post_audio_id"))),f=(0,r.useSelect)((e=>e(p).getAudioId()))||g,_=(0,r.useSelect)((e=>e("core").getEntityRecords("postType","attachment",{include:[f]}))),y=_&&_.length>0&&_[0].source_url,m=(0,e.useRef)(!1),P=(0,e.useRef)(!1),{isSavingPost:w}=(0,r.useSelect)((e=>({isSavingPost:e("core/editor").isSavingPost()}))),{isAutosavingPost:b}=(0,r.useSelect)((e=>({isSavingPost:e("core/editor").isAutosavingPost()})));(0,e.useEffect)((()=>{const e=document.getElementById("classifai-audio-preview");e&&(t?e.play():e.pause())}),[t]),(0,e.useEffect)((()=>{u&&(m.current=!0),m.current&&!u&&a((new Date).getTime())}),[u]),(0,e.useEffect)((()=>{!w||b||P.current||(P.current=!0,n&&wp.data.dispatch(p).setIsProcessing(!0)),w||b||!P.current||(P.current=!1,wp.data.dispatch(p).setIsProcessing(!1))}),[w,b,n]);const E=`${y}?ver=${i}`;let h="controls-play";return u?h="format-audio":t&&(h="controls-pause"),(0,e.createElement)(e.Fragment,null,(0,e.createElement)(l.ToggleControl,{label:(0,o.__)("Enable audio generation","classifai"),help:(0,o.sprintf)(/** translators: %s is post type label. */ +(0,o.__)("ClassifAI will generate audio for this %s when it is published or updated.","classifai"),d),checked:n,onChange:e=>{wp.data.dispatch("core/editor").editPost({classifai_synthesize_speech:e})},disabled:u,isBusy:u}),y&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)(l.ToggleControl,{label:(0,o.__)("Display audio controls","classifai"),help:(0,o.__)("Controls the display of the audio player on the front-end.","classifai"),checked:c,onChange:e=>{wp.data.dispatch("core/editor").editPost({classifai_display_generated_audio:e})},disabled:u,isBusy:u}),(0,e.createElement)(l.BaseControl,{id:"classifai-audio-preview-controls",help:u?"":(0,o.__)("Preview the generated audio.","classifai")},(0,e.createElement)(l.Button,{id:"classifai-audio-controls__preview-btn",icon:(0,e.createElement)(l.Icon,{icon:h}),variant:"secondary",onClick:()=>s(!t),disabled:u,isBusy:u},u?(0,o.__)("Generating audio..","classifai"):(0,o.__)("Preview","classifai")))),y&&(0,e.createElement)("audio",{id:"classifai-audio-preview",src:E,onEnded:()=>s(!1)}))};(0,d.registerPlugin)("classifai-plugin",{render:()=>{const t=(0,r.useSelect)((e=>e("core/editor").getCurrentPostType())),s=(0,r.useSelect)((e=>e("core/editor").getCurrentPostAttribute("status"))),i=f&&f.NLUEnabled,a=g&&g.enabled,n=f&&f.supportedPostTypes&&f.supportedPostTypes.includes(t),l=g&&g.supportedPostTypes&&g.supportedPostTypes.includes(t),d=f&&f.supportedPostStatues&&f.supportedPostStatues.includes(s),u=g&&g.supportedPostStatues&&g.supportedPostStatues.includes(s),p=f&&!(f.noPermissions&&1===parseInt(f.noPermissions))&&i&&n&&d,P=g&&!(g.noPermissions&&1===parseInt(g.noPermissions))&&a&&l&&u;return(0,e.createElement)(c.PluginDocumentSettingPanel,{title:(0,o.__)("ClassifAI","classifai"),icon:y,className:"classifai-panel"},(0,e.createElement)(e.Fragment,null,(p||P)&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)(m,null),p&&(0,e.createElement)(w,null)),_&&(0,e.createElement)(b,null)))}})})(); \ No newline at end of file diff --git a/dist/inserter-media-category.asset.php b/dist/inserter-media-category.asset.php new file mode 100644 index 000000000..2fd2e6803 --- /dev/null +++ b/dist/inserter-media-category.asset.php @@ -0,0 +1 @@ + array('wp-api-fetch', 'wp-data', 'wp-i18n', 'wp-url'), 'version' => 'e89ccec876ea48c1cb71'); diff --git a/dist/inserter-media-category.js b/dist/inserter-media-category.js new file mode 100644 index 000000000..c27fed701 --- /dev/null +++ b/dist/inserter-media-category.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.apiFetch;var a=e.n(t);const r=window.wp.data,i=window.wp.i18n,s=window.wp.url,{classifaiDalleData:n}=window;(async e=>new Promise((e=>{const t=(0,r.subscribe)((()=>{((0,r.select)("core/edit-post")?.isInserterOpened()||(0,r.select)("core/edit-site")?.isInserterOpened()||(0,r.select)("core/edit-widgets")?.isInserterOpened?.())&&(t(),e())}))})))().then((()=>(0,r.dispatch)("core/block-editor")?.registerInserterMediaCategory?.(d())));const o=(e,t=250)=>{let a;return(...r)=>(clearTimeout(a),new Promise((i=>{a=setTimeout((()=>{i(e.apply(void 0,r))}),t)})))},c=async({search:e=""})=>e?await a()({path:(0,s.addQueryArgs)(n.endpoint,{prompt:e,format:"b64_json"}),method:"GET"}).then((t=>t.map((t=>({title:e,url:`data:image/png;base64,${t.url}`,previewUrl:`data:image/png;base64,${t.url}`,id:void 0,alt:e,caption:n.caption}))))).catch((()=>[])):[],d=()=>({name:"classifai-generate-image",labels:{name:n.tabText,search_items:(0,i.__)("Enter a prompt","classifai")},mediaType:"image",fetch:o(c,2500),isExternalResource:!0})})(); \ No newline at end of file diff --git a/dist/post-excerpt.asset.php b/dist/post-excerpt.asset.php index d81ef3d97..1fe21fb0d 100644 --- a/dist/post-excerpt.asset.php +++ b/dist/post-excerpt.asset.php @@ -1 +1 @@ - array('wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '764b402ecd2a2c3902c6'); + array('wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '62fd488cabc3d26e57c7'); diff --git a/dist/post-excerpt.js b/dist/post-excerpt.js index 927d8cf79..053deb3aa 100644 --- a/dist/post-excerpt.js +++ b/dist/post-excerpt.js @@ -1 +1 @@ -(()=>{"use strict";const e=window.wp.element,t=window.wp.i18n,n=window.wp.data,s=window.wp.editPost,r=window.wp.editor,a=window.wp.plugins,i=window.wp.components,o=window.wp.compose,{get:l}=lodash,c=(0,o.compose)([(0,n.withSelect)((e=>({excerpt:e("core/editor").getEditedPostAttribute("excerpt")}))),(0,n.withDispatch)((e=>({onUpdateExcerpt(t){e("core/editor").editPost({excerpt:t})}})))])((function({excerpt:n,onUpdateExcerpt:s}){const{select:r}=wp.data,a=r("core/editor").getCurrentPostId(),o=""===n?(0,t.__)("Generate excerpt","classifai"):(0,t.__)("Re-generate excerpt","classifai"),c=r("core/edit-post").isPublishSidebarOpened();return(0,e.createElement)("div",{className:"editor-post-excerpt"},(0,e.createElement)(i.TextareaControl,{__nextHasNoMarginBottom:!0,label:c?null:(0,t.__)("Write an excerpt (optional)"),className:"editor-post-excerpt__textarea",onChange:e=>s(e),value:n}),!c&&(0,e.createElement)(i.ExternalLink,{href:(0,t.__)("https://wordpress.org/support/article/settings-sidebar/#excerpt")},(0,t.__)("Learn more about manual excerpts")),(0,e.createElement)(i.Button,{variant:"secondary","data-id":a,onClick:e=>(({button:e,endpoint:n,callback:s=!1,buttonText:r=(0,t.__)("Rescan","classifai")})=>{const a=e.getAttribute("data-id"),[i]=e.parentNode.getElementsByClassName("spinner"),[o]=e.parentNode.getElementsByClassName("error"),c=`${n}${a}`;e.setAttribute("disabled","disabled"),i.style.display="inline-block",i.classList.add("is-active"),o.style.display="none",wp.apiRequest({path:c}).then((t=>{e.removeAttribute("disabled"),i.style.display="none",i.classList.remove("is-active"),e.textContent=r,s&&s(t)}),(n=>{const s=l(n,"responseJSON",{code:"unknown_error",message:(0,t.__)("An unknown error occurred.","classifai")});i.style.display="none",i.classList.remove("is-active"),e.removeAttribute("disabled"),e.textContent=r,o.style.display="inline-block",o.textContent=`Error: ${s.message}`}))})({button:e.target,endpoint:"/classifai/v1/openai/generate-excerpt/",callback:s,buttonText:o})},o),(0,e.createElement)("span",{className:"spinner",style:{display:"none",float:"none"}}),(0,e.createElement)("span",{className:"error",style:{display:"none",color:"#bc0b0b",paddingTop:"5px"}}))})),p=({children:n})=>{const r=[(0,t.__)("Suggestion:"),(0,e.createElement)("span",{className:"editor-post-publish-panel__link",key:"label"},(0,t.__)("Generate excerpt","classifai"))];return(0,e.createElement)(s.PluginPrePublishPanel,{title:r,icon:"aside",initialOpen:!0},n)};class d extends e.Component{constructor(e){super(e),this.state={hadExcerptWhenOpeningThePanel:""!==e.excerpt}}componentDidUpdate(e){this.props.isPublishPanelOpen&&e.isPublishPanelOpen!==this.props.isPublishPanelOpen&&this.setState({hadExcerptWhenOpeningThePanel:""!==this.props.excerpt})}render(){return this.state.hadExcerptWhenOpeningThePanel?null:(0,e.createElement)(p,null,this.props.children)}}const u=(0,n.withSelect)((e=>({excerpt:e("core/editor").getEditedPostAttribute("excerpt"),isPublishPanelOpen:e("core/edit-post").isPublishSidebarOpened()})))(d);(0,n.dispatch)("core/edit-post").removeEditorPanel("post-excerpt"),(0,a.registerPlugin)("post-excerpt",{render:()=>(0,e.createElement)(r.PostExcerptCheck,null,(0,e.createElement)(s.PluginDocumentSettingPanel,{title:(0,t.__)("Excerpt")},(0,e.createElement)(c,null)),(0,e.createElement)(u,null,(0,e.createElement)(c,null)))})})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,n=window.wp.i18n,r=window.wp.data,a=window.wp.editPost,i=window.wp.editor,s=window.wp.plugins,o=window.wp.components,c=window.wp.compose,l=window.wp.apiFetch;var p=e.n(l);const d=(0,c.compose)([(0,r.withSelect)((e=>({excerpt:e("core/editor").getEditedPostAttribute("excerpt")}))),(0,r.withDispatch)((e=>({onUpdateExcerpt(t){e("core/editor").editPost({excerpt:t})}})))])((function({excerpt:e,onUpdateExcerpt:r}){const[a,i]=(0,t.useState)(!1),[s,c]=(0,t.useState)(!1),{select:l}=wp.data,d=l("core/editor").getCurrentPostId(),u=l("core/editor").getEditedPostAttribute("content"),h=l("core/editor").getEditedPostAttribute("title"),m=""===e?(0,n.__)("Generate excerpt","classifai"):(0,n.__)("Re-generate excerpt","classifai"),w=l("core/edit-post").isPublishSidebarOpened();return(0,t.createElement)("div",{className:"editor-post-excerpt"},(0,t.createElement)(o.TextareaControl,{__nextHasNoMarginBottom:!0,label:w?null:(0,n.__)("Write an excerpt (optional)"),className:"editor-post-excerpt__textarea",onChange:e=>r(e),value:e}),!w&&(0,t.createElement)(o.ExternalLink,{href:(0,n.__)("https://wordpress.org/support/article/settings-sidebar/#excerpt")},(0,n.__)("Learn more about manual excerpts")),(0,t.createElement)(o.Button,{className:"classifai-post-excerpt",variant:"secondary",disabled:a,"data-id":d,onClick:()=>(async e=>{i(!0),p()({path:"/classifai/v1/openai/generate-excerpt/",method:"POST",data:{id:d,content:u,title:h}}).then((e=>{r(e),c(!1),i(!1)}),(e=>{c(e?.message),i(!1)}))})()},m),a&&(0,t.createElement)("span",{className:"spinner is-active",style:{float:"none"}}),s&&!a&&(0,t.createElement)("span",{className:"error",style:{color:"#bc0b0b",display:"inline-block",paddingTop:"5px"}},s))})),u=({children:e})=>{const r=[(0,n.__)("Suggestion:"),(0,t.createElement)("span",{className:"editor-post-publish-panel__link",key:"label"},(0,n.__)("Generate excerpt","classifai"))];return(0,t.createElement)(a.PluginPrePublishPanel,{title:r,icon:"aside",initialOpen:!0},e)};class h extends t.Component{constructor(e){super(e),this.state={hadExcerptWhenOpeningThePanel:""!==e.excerpt}}componentDidUpdate(e){this.props.isPublishPanelOpen&&e.isPublishPanelOpen!==this.props.isPublishPanelOpen&&this.setState({hadExcerptWhenOpeningThePanel:""!==this.props.excerpt})}render(){return this.state.hadExcerptWhenOpeningThePanel?null:(0,t.createElement)(u,null,this.props.children)}}const m=(0,r.withSelect)((e=>({excerpt:e("core/editor").getEditedPostAttribute("excerpt"),isPublishPanelOpen:e("core/edit-post").isPublishSidebarOpened()})))(h);(0,r.dispatch)("core/edit-post").removeEditorPanel("post-excerpt"),(0,s.registerPlugin)("post-excerpt",{render:()=>(0,t.createElement)(i.PostExcerptCheck,null,(0,t.createElement)(a.PluginDocumentSettingPanel,{title:(0,n.__)("Excerpt")},(0,t.createElement)(d,null)),(0,t.createElement)(m,null,(0,t.createElement)(d,null)))})})(); \ No newline at end of file diff --git a/dist/post-status-info.asset.php b/dist/post-status-info.asset.php index 8a3b0d7fb..42aaecebc 100644 --- a/dist/post-status-info.asset.php +++ b/dist/post-status-info.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '4e017814ec22614f285d'); + array('wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'bfb28730ba8a02436042'); diff --git a/dist/post-status-info.js b/dist/post-status-info.js index 104f63198..63944da2e 100644 --- a/dist/post-status-info.js +++ b/dist/post-status-info.js @@ -1 +1 @@ -(()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var n in a)e.o(a,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:a[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,a=window.wp.data,n=window.wp.editPost,r=window.wp.editor,s=window.wp.components,l=window.wp.i18n,o=window.wp.plugins,i=window.wp.apiFetch;var c=e.n(i);const{classifaiChatGPTData:u}=window,d=({error:e})=>e?(0,t.createElement)("div",{className:"error"},e):null;(0,o.registerPlugin)("classifai-status-info",{render:()=>{const[e,o]=(0,t.useState)(!1),[i,p]=(0,t.useState)(!1),[w,m]=(0,t.useState)(!1),[f,E]=(0,t.useState)([]);if(!u||!u.enabledFeatures)return null;if(u.noPermissions&&1===parseInt(u.noPermissions))return null;const P=(0,a.select)("core/editor").getCurrentPostId(),g=()=>p(!1)&&E([])&&m(!1);return(0,t.createElement)(n.PluginPostStatusInfo,{className:"classifai-post-status"},i&&(0,t.createElement)(s.Modal,{title:(0,l.__)("Select a title","classifai"),onRequestClose:g,isFullScreen:!1,className:"title-modal"},e&&(0,t.createElement)(s.Spinner,null),!e&&f&&(0,t.createElement)((({data:e})=>e?(0,t.createElement)(t.Fragment,null,e.map(((n,r)=>(0,t.createElement)("div",{className:"classifai-title",key:r},(0,t.createElement)("textarea",{rows:"5",onChange:t=>{e[r]=t.target.value,E(e)}},n),(0,t.createElement)(s.Button,{variant:"secondary",onClick:()=>{(0,a.dispatch)("core/editor").editPost({title:f[r]}),g()}},(0,l.__)("Select","classifai")))))):null),{data:f}),!e&&w&&(0,t.createElement)(d,{error:w})),u.enabledFeatures.map((e=>{const a=e?.path+P;return(0,t.createElement)(r.PostTypeSupportCheck,{key:e?.feature,supportKeys:e?.feature},(0,t.createElement)(s.Button,{className:e?.feature,variant:"secondary",onClick:()=>(async e=>{o(!0),p(!0),c()({path:e}).then((e=>{E(e),m(!1),o(!1)}),(e=>{m(e?.message),E([]),o(!1)}))})(a)},e?.buttonText))})))}})})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var n in a)e.o(a,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:a[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,a=window.wp.data,n=window.wp.editPost,r=window.wp.editor,s=window.wp.components,o=window.wp.i18n,l=window.wp.plugins,i=window.wp.apiFetch;var c=e.n(i);const{classifaiChatGPTData:u}=window,d=({error:e})=>e?(0,t.createElement)("div",{className:"error"},e):null;(0,l.registerPlugin)("classifai-status-info",{render:()=>{const[e,l]=(0,t.useState)(!1),[i,m]=(0,t.useState)(!1),[p,w]=(0,t.useState)(!1),[f,P]=(0,t.useState)([]);if(!u||!u.enabledFeatures)return null;if(u.noPermissions&&1===parseInt(u.noPermissions))return null;const E=(0,a.select)("core/editor").getCurrentPostId(),g=(0,a.select)("core/editor").getEditedPostAttribute("content"),S=()=>m(!1)&&P([])&&w(!1);return(0,t.createElement)(n.PluginPostStatusInfo,{className:"classifai-post-status"},i&&(0,t.createElement)(s.Modal,{title:(0,o.__)("Select a title","classifai"),onRequestClose:S,isFullScreen:!1,className:"title-modal"},e&&(0,t.createElement)(s.Spinner,null),!e&&f&&(0,t.createElement)((({data:e})=>e?(0,t.createElement)(t.Fragment,null,e.map(((n,r)=>(0,t.createElement)("div",{className:"classifai-title",key:r},(0,t.createElement)("textarea",{rows:"5",onChange:t=>{e[r]=t.target.value,P(e)}},n),(0,t.createElement)(s.Button,{variant:"secondary",onClick:()=>{(0,a.dispatch)("core/editor").editPost({title:f[r]}),S()}},(0,o.__)("Select","classifai")))))):null),{data:f}),!e&&p&&(0,t.createElement)(d,{error:p})),u.enabledFeatures.map((e=>{const a=e?.path;return(0,t.createElement)(r.PostTypeSupportCheck,{key:e?.feature,supportKeys:e?.feature},(0,t.createElement)(s.Button,{className:e?.feature,variant:"secondary",onClick:()=>(async e=>{l(!0),m(!0),c()({path:e,method:"POST",data:{id:E,content:g}}).then((e=>{P(e),w(!1),l(!1)}),(e=>{w(e?.message),P([]),l(!1)}))})(a)},e?.buttonText))})))}})})(); \ No newline at end of file diff --git a/dist/recommended-content-block.asset.php b/dist/recommended-content-block.asset.php index 2b06451fa..a7320a747 100644 --- a/dist/recommended-content-block.asset.php +++ b/dist/recommended-content-block.asset.php @@ -1 +1 @@ - array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => '501cbbd0d2fb22ad2bfc'); + array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => '5c1e6b67447be750d260'); diff --git a/dist/recommended-content-block.js b/dist/recommended-content-block.js index d67f06d7a..bbefe7417 100644 --- a/dist/recommended-content-block.js +++ b/dist/recommended-content-block.js @@ -1 +1 @@ -(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,n=window.wp.blocks,a=window.wp.element,l=window.wp.components,o=window.wp.blockEditor,s=window.wp.primitives,r=(0,a.createElement)(s.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)(s.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),i=(0,a.createElement)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(s.Path,{d:"m3 5c0-1.10457.89543-2 2-2h13.5c1.1046 0 2 .89543 2 2v13.5c0 1.1046-.8954 2-2 2h-13.5c-1.10457 0-2-.8954-2-2zm2-.5h6v6.5h-6.5v-6c0-.27614.22386-.5.5-.5zm-.5 8v6c0 .2761.22386.5.5.5h6v-6.5zm8 0v6.5h6c.2761 0 .5-.2239.5-.5v-6zm0-8v6.5h6.5v-6c0-.27614-.2239-.5-.5-.5z",fillRule:"evenodd",clipRule:"evenodd"})),c=window.wp.data,d=window.wp.serverSideRender;var m=e.n(d);const u=window.wp.coreData,p=e=>{const t=e?.reduce(((e,t)=>{const{mapById:n,mapByName:a,names:l}=e;return n[t.id]=t,a[t.name]=t,l.push(t.name),e}),{mapById:{},mapByName:{},names:[]});return{entities:e,...t}},g=({onChange:e,query:t})=>{const n=(o=t.contentPostType,(0,c.useSelect)((e=>{const{getTaxonomies:t}=e(u.store);return t({type:o,per_page:-1,context:"view"})}),[o]));var o;const s=(0,c.useSelect)((e=>{const{getEntityRecords:t}=e(u.store),a={per_page:100},l=n?.map((({slug:e,name:n})=>{const l=t("taxonomy",e,a);return{slug:e,name:n,terms:p(l)}}));return l}),[n]),r=e=>{const n=s.find((({slug:t})=>t===e));return n?(t.taxQuery?.[e]||[]).reduce(((e,t)=>{const a=n.terms.mapById[t];return a&&e.push({id:t,value:a.name}),e}),[]):[]};return(0,a.createElement)(a.Fragment,null,!!s?.length&&s.map((({slug:n,name:o,terms:i})=>{return i?.names?.length?(0,a.createElement)(l.FormTokenField,{key:n,label:o,value:r(n),suggestions:i.names,onChange:(c=n,n=>{const a=s.find((({slug:e})=>e===c));if(!a)return;const l=Array.from(n.reduce(((e,t)=>{const n=((e,t)=>{const n=t?.id||e[t]?.id;if(n)return n;const a=t.toLocaleLowerCase();for(const t in e)if(t.toLocaleLowerCase()===a)return e[t].id})(a.terms.mapByName,t);return n&&e.add(n),e}),new Set)),o={...t.taxQuery,[c]:l};e({taxQuery:o})})}):null;var c})))},y=JSON.parse('{"u2":"classifai/recommended-content-block"}'),h=window.React;var w;function v(){return v=Object.assign?Object.assign.bind():function(e){for(var t=1;t{const{attributes:n,setAttributes:s}=e,{columns:d=3,displayLayout:p="grid",numberOfItems:y=3,contentPostType:h,taxQuery:w,displayAuthor:v,displayFeaturedImage:f,displayPostDate:_,displayPostExcerpt:b,addLinkToFeaturedImage:C}=n,E=(0,c.useSelect)((e=>e("core/editor").getCurrentPostId())),P=(0,o.useBlockProps)(),{postTypesTaxonomiesMap:x,postTypesSelectOptions:k}=(()=>{const e=(0,c.useSelect)((e=>{const{getPostTypes:t}=e(u.store),n=["attachment"],a=t({per_page:-1})?.filter((({viewable:e,slug:t})=>e&&!n.includes(t)));return a}),[]);return{postTypesTaxonomiesMap:(0,a.useMemo)((()=>{if(e?.length)return e.reduce(((e,t)=>(e[t.slug]=t.taxonomies,e)),{})}),[e]),postTypesSelectOptions:(0,a.useMemo)((()=>(e||[]).map((({labels:e,slug:t})=>({label:e.singular_name,value:t})))),[e])}})(),T=[{icon:r,title:(0,t.__)("List view","classifai"),onClick:()=>s({displayLayout:"list"}),isActive:"list"===p},{icon:i,title:(0,t.__)("Grid view"),onClick:()=>s({displayLayout:"grid"}),isActive:"grid"===p}];return(0,a.createElement)("div",P,(0,a.createElement)(o.BlockControls,null,(0,a.createElement)(l.ToolbarGroup,{controls:T})),(0,a.createElement)(o.InspectorControls,null,(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Recommended Content Filters","classifai")},k&&(0,a.createElement)(l.SelectControl,{label:(0,t.__)("Post type","classifai"),value:h,options:k,onChange:e=>{const t={contentPostType:e},n=x[e],a=Object.entries(w||{}).reduce(((e,[t,a])=>(n.includes(t)&&(e[t]=a),e)),{});t.taxQuery=Object.keys(a).length?a:void 0,s(t)}}),k&&(0,a.createElement)(g,{onChange:s,query:n})),(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Settings","classifai")},(0,a.createElement)(l.RangeControl,{label:(0,t.__)("Number of items","classifai"),value:y,onChange:e=>s({numberOfItems:e}),min:1,max:50,required:!0}),"grid"===p&&(0,a.createElement)(l.RangeControl,{label:(0,t.__)("Columns","classifai"),value:d,onChange:e=>s({columns:e}),min:2,max:6,required:!0})),(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Post content settings","classifai")},(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Post excerpt","classifai"),checked:b,onChange:e=>s({displayPostExcerpt:e})})),(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Post meta settings","classifai")},(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Display author name","classifai"),checked:v,onChange:e=>s({displayAuthor:e})}),(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Display post date","classifai"),checked:_,onChange:e=>s({displayPostDate:e})})),(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Featured image settings","classifai")},(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Display featured image","classifai"),checked:f,onChange:e=>s({displayFeaturedImage:e})}),f&&(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Add link to featured image","classifai"),checked:C,onChange:e=>s({addLinkToFeaturedImage:e})}))),!h&&(0,a.createElement)(l.Placeholder,{label:(0,t.__)("ClassifAI Recommended Content","classifai")},(0,a.createElement)("p",null,(0,t.__)("Please select Post type for this Recommended Content block on the sidebar settings.","classifai"))),h&&(0,a.createElement)(m(),{block:"classifai/recommended-content-block",attributes:{addLinkToFeaturedImage:C,columns:d,contentPostType:h,displayAuthor:v,displayFeaturedImage:f,displayLayout:p,displayPostDate:_,displayPostExcerpt:b,numberOfItems:y,taxQuery:w,excludeId:E||0}}))},save:()=>null,icon:function(e){return h.createElement("svg",v({width:20,height:15,viewBox:"0 0 61 46",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),w||(w=h.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3.52 0C1.575 0 0 1.584 0 3.538v38.924C0 44.416 1.576 46 3.52 46h53.96c1.944 0 3.52-1.584 3.52-3.538V3.538C61 1.584 59.424 0 57.48 0H3.52Zm13.189 8.138h4.739L33.58 39.554h-6.056l-3.492-9.04H13.97l-3.453 9.04h-5.96L16.709 8.138Zm2.38 8.563c-.104.34-.211.672-.319.997l-.012.036-2.76 7.406h6.148l-2.745-7.455-.312-.984Zm21.227-8.563h12.59v4.015l-3.413.819V34.63l3.413.779v4.024h-12.59V35.41l3.413-.78V12.972l-3.413-.818V8.138Z",fill:"#1e1e1e"})))}})})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.i18n,n=window.wp.blocks,a=window.wp.element,l=window.wp.components,o=window.wp.blockEditor,s=window.wp.primitives,r=(0,a.createElement)(s.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,a.createElement)(s.Path,{d:"M4 4v1.5h16V4H4zm8 8.5h8V11h-8v1.5zM4 20h16v-1.5H4V20zm4-8c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2z"})),i=(0,a.createElement)(s.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(s.Path,{d:"m3 5c0-1.10457.89543-2 2-2h13.5c1.1046 0 2 .89543 2 2v13.5c0 1.1046-.8954 2-2 2h-13.5c-1.10457 0-2-.8954-2-2zm2-.5h6v6.5h-6.5v-6c0-.27614.22386-.5.5-.5zm-.5 8v6c0 .2761.22386.5.5.5h6v-6.5zm8 0v6.5h6c.2761 0 .5-.2239.5-.5v-6zm0-8v6.5h6.5v-6c0-.27614-.2239-.5-.5-.5z",fillRule:"evenodd",clipRule:"evenodd"})),c=window.wp.data,d=window.wp.serverSideRender;var m=e.n(d);const u=window.wp.coreData,p=e=>{const t=e?.reduce(((e,t)=>{const{mapById:n,mapByName:a,names:l}=e;return n[t.id]=t,a[t.name]=t,l.push(t.name),e}),{mapById:{},mapByName:{},names:[]});return{entities:e,...t}},g=({onChange:e,query:t})=>{const n=(o=t.contentPostType,(0,c.useSelect)((e=>{const{getTaxonomies:t}=e(u.store);return t({type:o,per_page:-1,context:"view"})}),[o]));var o;const s=(0,c.useSelect)((e=>{const{getEntityRecords:t}=e(u.store),a={per_page:100},l=n?.map((({slug:e,name:n})=>{const l=t("taxonomy",e,a);return{slug:e,name:n,terms:p(l)}}));return l}),[n]),r=e=>{const n=s.find((({slug:t})=>t===e));return n?(t.taxQuery?.[e]||[]).reduce(((e,t)=>{const a=n.terms.mapById[t];return a&&e.push({id:t,value:a.name}),e}),[]):[]};return(0,a.createElement)(a.Fragment,null,!!s?.length&&s.map((({slug:n,name:o,terms:i})=>{return i?.names?.length?(0,a.createElement)(l.FormTokenField,{key:n,label:o,value:r(n),suggestions:i.names,onChange:(c=n,n=>{const a=s.find((({slug:e})=>e===c));if(!a)return;const l=Array.from(n.reduce(((e,t)=>{const n=((e,t)=>{const n=t?.id||e[t]?.id;if(n)return n;const a=t.toLocaleLowerCase();for(const t in e)if(t.toLocaleLowerCase()===a)return e[t].id})(a.terms.mapByName,t);return n&&e.add(n),e}),new Set)),o={...t.taxQuery,[c]:l};e({taxQuery:o})})}):null;var c})))},y=JSON.parse('{"u2":"classifai/recommended-content-block"}'),h=window.React;var w;function v(){return v=Object.assign?Object.assign.bind():function(e){for(var t=1;t{const{attributes:n,setAttributes:s}=e,{columns:d=3,displayLayout:p="grid",numberOfItems:y=3,contentPostType:h,taxQuery:w,displayAuthor:v,displayFeaturedImage:f,displayPostDate:_,displayPostExcerpt:b,addLinkToFeaturedImage:C}=n,E=(0,c.useSelect)((e=>e("core/editor").getCurrentPostId())),P=(0,o.useBlockProps)(),{postTypesTaxonomiesMap:x,postTypesSelectOptions:k}=(()=>{const e=(0,c.useSelect)((e=>{const{getPostTypes:t}=e(u.store),n=["attachment"],a=t({per_page:-1})?.filter((({viewable:e,slug:t})=>e&&!n.includes(t)));return a}),[]);return{postTypesTaxonomiesMap:(0,a.useMemo)((()=>{if(e?.length)return e.reduce(((e,t)=>(e[t.slug]=t.taxonomies,e)),{})}),[e]),postTypesSelectOptions:(0,a.useMemo)((()=>(e||[]).map((({labels:e,slug:t})=>({label:e.singular_name,value:t})))),[e])}})(),T=[{icon:r,title:(0,t.__)("List view","classifai"),onClick:()=>s({displayLayout:"list"}),isActive:"list"===p},{icon:i,title:(0,t.__)("Grid view"),onClick:()=>s({displayLayout:"grid"}),isActive:"grid"===p}];return(0,a.createElement)("div",P,(0,a.createElement)(o.BlockControls,null,(0,a.createElement)(l.ToolbarGroup,{controls:T})),(0,a.createElement)(o.InspectorControls,null,(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Recommended Content Filters","classifai")},k&&(0,a.createElement)(l.SelectControl,{label:(0,t.__)("Post type","classifai"),value:h,options:k,onChange:e=>{const t={contentPostType:e},n=x[e],a=Object.entries(w||{}).reduce(((e,[t,a])=>(n.includes(t)&&(e[t]=a),e)),{});t.taxQuery=Object.keys(a).length?a:void 0,s(t)}}),k&&(0,a.createElement)(g,{onChange:s,query:n})),(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Settings","classifai")},(0,a.createElement)(l.RangeControl,{label:(0,t.__)("Number of items","classifai"),value:y,onChange:e=>s({numberOfItems:e}),min:1,max:50,required:!0}),"grid"===p&&(0,a.createElement)(l.RangeControl,{label:(0,t.__)("Columns","classifai"),value:d,onChange:e=>s({columns:e}),min:2,max:6,required:!0})),(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Post content settings","classifai")},(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Post excerpt","classifai"),checked:b,onChange:e=>s({displayPostExcerpt:e})})),(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Post meta settings","classifai")},(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Display author name","classifai"),checked:v,onChange:e=>s({displayAuthor:e})}),(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Display post date","classifai"),checked:_,onChange:e=>s({displayPostDate:e})})),(0,a.createElement)(l.PanelBody,{title:(0,t.__)("Featured image settings","classifai")},(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Display featured image","classifai"),checked:f,onChange:e=>s({displayFeaturedImage:e})}),f&&(0,a.createElement)(l.ToggleControl,{label:(0,t.__)("Add link to featured image","classifai"),checked:C,onChange:e=>s({addLinkToFeaturedImage:e})}))),!h&&(0,a.createElement)(l.Placeholder,{label:(0,t.__)("ClassifAI Recommended Content","classifai")},(0,a.createElement)("p",null,(0,t.__)("Please select Post type for this Recommended Content block on the sidebar settings.","classifai"))),h&&(0,a.createElement)(m(),{block:"classifai/recommended-content-block",attributes:{addLinkToFeaturedImage:C,columns:d,contentPostType:h,displayAuthor:v,displayFeaturedImage:f,displayLayout:p,displayPostDate:_,displayPostExcerpt:b,numberOfItems:y,taxQuery:w,excludeId:E||0}}))},save:()=>null,icon:function(e){return h.createElement("svg",v({width:20,height:15,viewBox:"0 0 61 46",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),w||(w=h.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3.52 0C1.575 0 0 1.584 0 3.538v38.924C0 44.416 1.576 46 3.52 46h53.96c1.944 0 3.52-1.584 3.52-3.538V3.538C61 1.584 59.424 0 57.48 0H3.52Zm13.189 8.138h4.739L33.58 39.554h-6.056l-3.492-9.04H13.97l-3.453 9.04h-5.96L16.709 8.138Zm2.38 8.563c-.104.34-.211.672-.319.997l-.012.036-2.76 7.406h6.148l-2.745-7.455-.312-.984Zm21.227-8.563h12.59v4.015l-3.413.819V34.63l3.413.779v4.024h-12.59V35.41l3.413-.78V12.972l-3.413-.818V8.138Z",fill:"#1e1e1e"})))}})})(); \ No newline at end of file diff --git a/includes/Classifai/Admin/BulkActions.php b/includes/Classifai/Admin/BulkActions.php index c6bc730b3..e01e75f9d 100644 --- a/includes/Classifai/Admin/BulkActions.php +++ b/includes/Classifai/Admin/BulkActions.php @@ -9,6 +9,7 @@ use Classifai\Providers\OpenAI\Whisper\Transcribe; use function Classifai\get_post_types_for_language_settings; use function Classifai\get_supported_post_types; +use function Classifai\get_tts_supported_post_types; /** * Handle bulk actions. @@ -68,15 +69,14 @@ public function register() { * Register bulk actions for language processing. */ public function register_language_processing_hooks() { - $this->chat_gpt = new ChatGPT( false ); - $this->embeddings = new Embeddings( false ); - $this->text_to_speech = new TextToSpeech( false ); + $this->chat_gpt = new ChatGPT( false ); + $this->embeddings = new Embeddings( false ); $user_roles = wp_get_current_user()->roles ?? []; $embedding_settings = $this->embeddings->get_settings(); $embeddings_post_types = []; $nlu_post_types = get_supported_post_types(); - $text_to_speech_post_types = $this->text_to_speech->get_supported_post_types(); + $text_to_speech_post_types = get_tts_supported_post_types(); $chat_gpt_post_types = []; $chat_gpt_settings = $this->chat_gpt->get_settings(); @@ -104,11 +104,6 @@ public function register_language_processing_hooks() { $this->embeddings = null; } - // Clear our TextToSpeech handler if no post types are set up. - if ( empty( $text_to_speech_post_types ) ) { - $this->text_to_speech = null; - } - // Merge our post types together and make them unique. $post_types = array_unique( array_merge( $chat_gpt_post_types, $embeddings_post_types, $nlu_post_types, $text_to_speech_post_types ) ); diff --git a/includes/Classifai/Admin/Onboarding.php b/includes/Classifai/Admin/Onboarding.php index b96ebc2cb..be329cca8 100644 --- a/includes/Classifai/Admin/Onboarding.php +++ b/includes/Classifai/Admin/Onboarding.php @@ -170,7 +170,7 @@ public function handle_step_submission() { switch ( $step ) { case 1: // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - $enabled_features = isset( $_POST['classifai-features'] ) ? $this->classifai_sanitize( $_POST['classifai-features'] ) : array(); + $enabled_features = isset( $_POST['classifai-features'] ) ? $this->classifai_sanitize( wp_unslash( $_POST['classifai-features'] ) ) : array(); if ( empty( $enabled_features ) ) { add_settings_error( @@ -228,7 +228,7 @@ public function handle_step_submission() { case 2: // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - $classifai_settings = isset( $_POST['classifai_settings'] ) ? $this->classifai_sanitize( $_POST['classifai_settings'] ) : array(); + $classifai_settings = isset( $_POST['classifai_settings'] ) ? $this->classifai_sanitize( wp_unslash( $_POST['classifai_settings'] ) ) : array(); // Save the ClassifAI settings. update_option( 'classifai_settings', $classifai_settings ); @@ -256,7 +256,7 @@ public function handle_step_submission() { } // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - $form_data = isset( $_POST[ $provider_option ] ) ? $this->classifai_sanitize( $_POST[ $provider_option ] ) : array(); + $form_data = isset( $_POST[ $provider_option ] ) ? $this->classifai_sanitize( wp_unslash( $_POST[ $provider_option ] ) ) : array(); $settings = $provider->get_settings(); $options = self::get_onboarding_options(); @@ -543,7 +543,7 @@ public function update_onboarding_options( $options ) { * Handle skip setup step. */ public function handle_skip_setup_step() { - if ( ! empty( $_GET['classifai_skip_step_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_GET['classifai_skip_step_nonce'] ), 'classifai_skip_step_action' ) ) { + if ( ! empty( $_GET['classifai_skip_step_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['classifai_skip_step_nonce'] ) ), 'classifai_skip_step_action' ) ) { $step = isset( $_GET['step'] ) ? absint( $_GET['step'] ) : 1; $onboarding_options = array( diff --git a/includes/Classifai/Admin/PreviewClassifierData.php b/includes/Classifai/Admin/PreviewClassifierData.php index e643f3c0f..d5cfa0973 100644 --- a/includes/Classifai/Admin/PreviewClassifierData.php +++ b/includes/Classifai/Admin/PreviewClassifierData.php @@ -18,7 +18,7 @@ public function __construct() { * Returns classifier data for previewing. */ public function get_post_classifier_preview_data() { - $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : false; + $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : false; if ( ! $nonce || ! wp_verify_nonce( $nonce, 'classifai-previewer-action' ) ) { wp_send_json_error( esc_html__( 'Failed nonce check.', 'classifai' ) ); @@ -42,15 +42,15 @@ public function get_post_classifier_preview_data() { * Searches and returns posts. */ public function get_post_search_results() { - $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : false; + $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : false; if ( ! $nonce || ! wp_verify_nonce( $nonce, 'classifai-previewer-action' ) ) { wp_send_json_error( esc_html__( 'Failed nonce check.', 'classifai' ) ); } - $search_term = isset( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : ''; - $post_types = isset( $_POST['post_types'] ) ? explode( ',', sanitize_text_field( $_POST['post_types'] ) ) : 'post'; - $post_statuses = isset( $_POST['post_status'] ) ? explode( ',', sanitize_text_field( $_POST['post_status'] ) ) : 'publish'; + $search_term = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : ''; + $post_types = isset( $_POST['post_types'] ) ? explode( ',', sanitize_text_field( wp_unslash( $_POST['post_types'] ) ) ) : 'post'; + $post_statuses = isset( $_POST['post_status'] ) ? explode( ',', sanitize_text_field( wp_unslash( $_POST['post_status'] ) ) ) : 'publish'; $posts = get_posts( array( diff --git a/includes/Classifai/Admin/SavePostHandler.php b/includes/Classifai/Admin/SavePostHandler.php index 0cf6ddb68..6a8df50fe 100644 --- a/includes/Classifai/Admin/SavePostHandler.php +++ b/includes/Classifai/Admin/SavePostHandler.php @@ -418,7 +418,7 @@ public function is_rest_route() { $rest_bases = apply_filters( 'classifai_rest_bases', array( 'posts', 'pages' ) ); foreach ( $rest_bases as $rest_base ) { - if ( false !== strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), 'wp-json/wp/v2/' . $rest_base ) ) { + if ( false !== strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-json/wp/v2/' . $rest_base ) ) { return true; } } @@ -432,7 +432,7 @@ public function is_rest_route() { * @return void */ public function classifai_classify_post() { - if ( ! empty( $_GET['classifai_classify_post_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_GET['classifai_classify_post_nonce'] ), 'classifai_classify_post_action' ) ) { + if ( ! empty( $_GET['classifai_classify_post_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['classifai_classify_post_nonce'] ) ), 'classifai_classify_post_action' ) ) { $post_id = isset( $_GET['post_id'] ) ? absint( $_GET['post_id'] ) : 0; if ( $post_id ) { $result = $this->classify( $post_id ); diff --git a/includes/Classifai/Admin/Update.php b/includes/Classifai/Admin/Update.php index dee70034f..69b0d2530 100644 --- a/includes/Classifai/Admin/Update.php +++ b/includes/Classifai/Admin/Update.php @@ -7,7 +7,7 @@ namespace Classifai\Admin; -use Puc_v4_Factory; +use YahnisElsts\PluginUpdateChecker\v5\PucFactory; /** * Plugin update class. @@ -24,7 +24,7 @@ class Update { /** * The update checker object. * - * @var Puc_v4p13_Plugin_UpdateChecker + * @var YahnisElsts\PluginUpdateChecker\v5p1\Vcs\PluginUpdateChecker */ protected $updater; @@ -34,7 +34,7 @@ class Update { * @return bool */ public function can_register() { - return class_exists( '\Puc_v4_Factory' ) && self::license_check(); + return class_exists( '\YahnisElsts\PluginUpdateChecker\v5\PucFactory' ) && self::license_check(); } /** @@ -52,7 +52,7 @@ public function register() { * @return void */ public function init() { - $this->updater = Puc_v4_Factory::buildUpdateChecker( + $this->updater = PucFactory::buildUpdateChecker( self::$repo_url, CLASSIFAI_PLUGIN, 'classifai' @@ -87,7 +87,9 @@ public function maybe_update( $transient ) { // Adding the plugin info to the `no_update` property is required // for the enable/disable auto-update links to appear correctly in the UI. - $transient->no_update[ $update->filename ] = $update; + if ( $update ) { + $transient->no_update[ $update->filename ] = $update; + } } return $transient; diff --git a/includes/Classifai/Blocks/recommended-content-block/block.json b/includes/Classifai/Blocks/recommended-content-block/block.json index 611821ec9..925350880 100644 --- a/includes/Classifai/Blocks/recommended-content-block/block.json +++ b/includes/Classifai/Blocks/recommended-content-block/block.json @@ -2,7 +2,7 @@ "$schema": "https://schemas.wp.org/trunk/block.json", "apiVersion": 2, "title": "Recommended Content", - "description": "Display content recommended by Azure Personalizer", + "description": "Display content recommended by Azure AI Personalizer", "textdomain": "classifai", "name": "classifai/recommended-content-block", "category": "classifai-blocks", diff --git a/includes/Classifai/Blocks/recommended-content-block/index.js b/includes/Classifai/Blocks/recommended-content-block/index.js index 51a29d7b3..0f67973af 100644 --- a/includes/Classifai/Blocks/recommended-content-block/index.js +++ b/includes/Classifai/Blocks/recommended-content-block/index.js @@ -26,7 +26,7 @@ import { ReactComponent as icon } from '../../../../assets/img/block-icon.svg'; registerBlockType( block.name, { title: __( 'Recommended Content', 'classifai' ), description: __( - 'Display content recommended by Azure Personalizer', + 'Display content recommended by Azure AI Personalizer', 'classifai' ), edit, diff --git a/includes/Classifai/Command/ClassifaiCommand.php b/includes/Classifai/Command/ClassifaiCommand.php index 7c9047fe2..fb6050b8a 100644 --- a/includes/Classifai/Command/ClassifaiCommand.php +++ b/includes/Classifai/Command/ClassifaiCommand.php @@ -164,7 +164,7 @@ public function text( $args = [], $opts = [] ) { } if ( ! empty( $opts['input'] ) ) { - $text = file_get_contents( $opts['input'] ); + $text = file_get_contents( $opts['input'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents } elseif ( ! empty( $args ) ) { $text = $args[0]; } else { @@ -1156,7 +1156,7 @@ private function get_posts_to_classify( $opts = [] ) { 'post_type' => ! empty( $opts['post_type'] ) ? $opts['post_type'] : 'any', 'post_status' => 'publish', 'fields' => 'ids', - 'posts_per_page' => -1, + 'posts_per_page' => -1, // phpcs:ignore WordPress.WP.PostsPerPageNoUnlimited.posts_per_page_posts_per_page ]; \WP_CLI::log( 'Fetching posts to classify ...' ); diff --git a/includes/Classifai/Command/RSSImporterCommand.php b/includes/Classifai/Command/RSSImporterCommand.php index 4678334c6..a841f43af 100644 --- a/includes/Classifai/Command/RSSImporterCommand.php +++ b/includes/Classifai/Command/RSSImporterCommand.php @@ -203,7 +203,7 @@ public function get_url_meta( $url ) { $options['headers']['x-api-key'] = MERCURY_PARSER_API_KEY; $options['timeout'] = 60; // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout - $request_url = 'https://mercury.postlight.com/parser?url=' . urlencode( $url ); + $request_url = 'https://mercury.postlight.com/parser?url=' . rawurlencode( $url ); $response = wp_remote_get( $request_url, $options ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get if ( ! is_wp_error( $response ) ) { diff --git a/includes/Classifai/Helpers.php b/includes/Classifai/Helpers.php index 734bf1db6..47f47e3f1 100644 --- a/includes/Classifai/Helpers.php +++ b/includes/Classifai/Helpers.php @@ -3,6 +3,7 @@ namespace Classifai; use Classifai\Providers\Provider; +use Classifai\Providers\Azure; use Classifai\Services\Service; use Classifai\Services\ServicesManager; use WP_Error; @@ -275,6 +276,28 @@ function get_supported_post_types() { return $post_types; } +/** + * The list of post types that TTS supports. + * + * @return array Supported Post Types. + */ +function get_tts_supported_post_types() { + $classifai_settings = get_plugin_settings( 'language_processing', Azure\TextToSpeech::FEATURE_NAME ); + + if ( empty( $classifai_settings ) ) { + $post_types = []; + } else { + $post_types = []; + foreach ( $classifai_settings['post_types'] as $post_type => $enabled ) { + if ( ! empty( $enabled ) ) { + $post_types[] = $post_type; + } + } + } + + return $post_types; +} + /** * The list of post statuses that get the ClassifAI taxonomies. Defaults * to 'publish'. diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index 4587dfa18..d9aad7b04 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -188,6 +188,16 @@ public function enqueue_admin_assets() { 'ajax_nonce' => wp_create_nonce( 'classifai' ), ] ); + + if ( wp_script_is( 'wp-commands', 'registered' ) ) { + wp_enqueue_script( + 'classifai-commands', + CLASSIFAI_PLUGIN_URL . 'dist/commands.js', + get_asset_info( 'commands', 'dependencies' ), + get_asset_info( 'commands', 'version' ), + true + ); + } } /** diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index 00ee86901..5fdabe5e3 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -31,14 +31,14 @@ class ComputerVision extends Provider { public function __construct( $service ) { parent::__construct( 'Microsoft Azure', - 'Computer Vision', + 'AI Vision', 'computer_vision', $service ); // Set the onboarding options. $this->onboarding_options = array( - 'title' => __( 'Microsoft Azure Computer Vision', 'classifai' ), + 'title' => __( 'Microsoft Azure AI Vision', 'classifai' ), 'fields' => array( 'url', 'api-key' ), 'features' => array( 'enable_image_captions' => __( 'Automatically add alt-text to images', 'classifai' ), @@ -62,7 +62,7 @@ public function reset_settings() { * * @return array */ - private function get_default_settings() { + public function get_default_settings() { return [ 'valid' => false, 'url' => '', @@ -1053,7 +1053,7 @@ public function setup_fields_sections() { 'input_type' => 'checkbox', 'default_value' => $default_settings['enable_smart_cropping'], 'description' => __( - 'ComputerVision detects and saves the most visually interesting part of your image (i.e., faces, animals, notable text).', + 'AI Vision detects and saves the most visually interesting part of your image (i.e., faces, animals, notable text).', 'classifai' ), ] diff --git a/includes/Classifai/Providers/Azure/Personalizer.php b/includes/Classifai/Providers/Azure/Personalizer.php index e9600cef6..3a6775917 100644 --- a/includes/Classifai/Providers/Azure/Personalizer.php +++ b/includes/Classifai/Providers/Azure/Personalizer.php @@ -1,6 +1,6 @@ onboarding_options = array( - 'title' => __( 'Microsoft Azure Personalizer', 'classifai' ), + 'title' => __( 'Microsoft Azure AI Personalizer', 'classifai' ), 'fields' => array( 'url', 'api-key' ), 'features' => array( 'authenticated' => __( 'Recommended content block', 'classifai' ), @@ -62,7 +62,7 @@ public function reset_settings() { * * @return array */ - private function get_default_settings() { + public function get_default_settings() { return [ 'authenticated' => false, 'url' => '', @@ -97,7 +97,7 @@ public function setup_fields_sections() { 'description' => sprintf( wp_kses( // translators: 1 - link to create a Personalizer resource. - __( 'Azure Cognitive Service Personalizer Endpoint, create a Personalizer resource in the Azure portal to get your key and endpoint.', 'classifai' ), + __( 'Azure AI Personalizer Endpoint, create a Personalizer resource in the Azure portal to get your key and endpoint.', 'classifai' ), array( 'a' => array( 'href' => array(), @@ -119,7 +119,7 @@ public function setup_fields_sections() { 'label_for' => 'api_key', 'input_type' => 'password', 'default_value' => $default_settings['api_key'], - 'description' => __( 'Azure Cognitive Service Personalizer Key.', 'classifai' ), + 'description' => __( 'Azure AI Personalizer Key.', 'classifai' ), ] ); } @@ -310,7 +310,7 @@ function( $ele ) { if ( is_wp_error( $response ) ) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log - error_log( __( 'Failed to contact Azure Cognitive Service Personalizer: ', 'classifai' ) . $response->get_error_message() ); + error_log( __( 'Failed to contact Azure AI Personalizer: ', 'classifai' ) . $response->get_error_message() ); return array( 'response' => (object) array(), 'actions' => $action_ids, @@ -605,7 +605,7 @@ protected function get_string_words( $string ) { } /** - * Get Ranked action by sending request to Azure Personalizer. + * Get Ranked action by sending request to Azure AI Personalizer. * * @param array $rank_request Prepared Request data. * @return object|string diff --git a/includes/Classifai/Providers/Azure/Read.php b/includes/Classifai/Providers/Azure/Read.php index b7b9ed49e..dfb45a4d6 100644 --- a/includes/Classifai/Providers/Azure/Read.php +++ b/includes/Classifai/Providers/Azure/Read.php @@ -268,13 +268,10 @@ public function check_read_result( $operation_url ) { break; case 'failed': return $this->log_error( new WP_Error( 'failed_read_request', esc_html__( 'The Read operation has failed.', 'classifai' ) ) ); - break; case 'succeeded': return $this->update_document_description( $body ); - break; default: return $this->log_error( new WP_Error( 'invalid_read_result_status', esc_html__( 'Invalid Read result status.', 'classifai' ) ) ); - break; } } } diff --git a/includes/Classifai/Providers/Azure/TextToSpeech.php b/includes/Classifai/Providers/Azure/TextToSpeech.php index 8ceeffba1..d978f89a7 100644 --- a/includes/Classifai/Providers/Azure/TextToSpeech.php +++ b/includes/Classifai/Providers/Azure/TextToSpeech.php @@ -11,6 +11,7 @@ use WP_Http; use function Classifai\get_post_types_for_language_settings; +use function Classifai\get_tts_supported_post_types; use function Classifai\get_asset_info; class TextToSpeech extends Provider { @@ -30,12 +31,11 @@ class TextToSpeech extends Provider { const API_PATH = 'cognitiveservices/v1'; /** - * Meta key to store data indicating whether Text to Speech is enabled for - * the current post. + * Meta key to hide/unhide already generated audio file. * * @var string */ - const SYNTHESIZE_SPEECH_KEY = '_classifai_synthesize_speech'; + const DISPLAY_GENERATED_AUDIO = '_classifai_display_generated_audio'; /** * Meta key to get/set the ID of the speech audio file. @@ -87,21 +87,13 @@ public function __construct( $service ) { * Enqueue the editor scripts. */ public function enqueue_editor_assets() { - global $post; - - wp_enqueue_script( - 'classifai-editor', // Handle. - CLASSIFAI_PLUGIN_URL . 'dist/editor.js', - array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-edit-post' ), - CLASSIFAI_PLUGIN_VERSION, - true - ); + $post = get_post(); if ( empty( $post ) ) { return; } - $supported_post_types = self::get_supported_post_types(); + $supported_post_types = get_tts_supported_post_types(); if ( ! in_array( $post->post_type, $supported_post_types, true ) ) { return; @@ -115,13 +107,13 @@ public function enqueue_editor_assets() { true ); - wp_localize_script( + wp_add_inline_script( 'classifai-gutenberg-plugin', - 'classifaiTextToSpeechData', - [ - 'supportedPostTypes' => self::get_supported_post_types(), - 'noPermissions' => ! is_user_logged_in() || ! current_user_can( 'edit_post', $post->ID ), - ] + sprintf( + 'var classifaiTTSEnabled = %d;', + true + ), + 'before' ); } @@ -133,11 +125,17 @@ public function register() { add_action( 'rest_api_init', [ $this, 'add_synthesize_speech_meta_to_rest_api' ] ); add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] ); add_action( 'save_post', [ $this, 'save_post_metadata' ], 5 ); + + $supported_post_type = get_tts_supported_post_types(); + foreach ( get_tts_supported_post_types() as $post_type ) { + add_action( 'rest_insert_' . $post_type, [ $this, 'rest_handle_audio' ], 10, 2 ); + } + add_filter( 'the_content', [ $this, 'render_post_audio_controls' ] ); } /** - * Resets settings for the Personalizer provider. + * Resets settings for the TextToSpeech provider. */ public function reset_settings() { update_option( $this->get_option_name(), $this->get_default_settings() ); @@ -190,7 +188,7 @@ public function setup_fields_sections() { 'label_for' => 'post_types', 'option_index' => 'post_types', 'options' => $this->get_post_types_select_options(), - 'default_values' => $default_settings['post-types'], + 'default_values' => $default_settings['post_types'], ] ); @@ -240,6 +238,9 @@ public function sanitize_settings( $settings ) { if ( ! empty( $current_settings['voices'] ) ) { $current_settings['authenticated'] = true; + } else { + $current_settings['voices'] = []; + $current_settings['authenticated'] = false; } } } else { @@ -267,8 +268,6 @@ public function sanitize_settings( $settings ) { if ( isset( $settings['voice'] ) && ! empty( $settings['voice'] ) ) { $current_settings['voice'] = sanitize_text_field( $settings['voice'] ); - } else { - $current_settings['voice'] = ''; } return $current_settings; @@ -427,7 +426,7 @@ public function get_provider_debug_information( $settings = null, $configured = /** * Returns the default settings. */ - private function get_default_settings() { + public function get_default_settings() { return [ 'credentials' => array( 'url' => '', @@ -436,44 +435,108 @@ private function get_default_settings() { 'voices' => array(), 'voice' => '', 'authenticated' => false, - 'post-types' => array(), + 'post_types' => array(), ]; } /** - * Add `classifai_synthesize_speech` to rest API for view/edit. + * Initial audio generation state. + * + * Fetch the initial state of audio generation prior to the audio existing for the post. + * + * @param int|WP_Post|null $post Optional. Post ID or post object. `null`, `false`, `0` and other PHP falsey values + * return the current global post inside the loop. A numerically valid post ID that + * points to a non-existent post returns `null`. Defaults to global $post. + * @return bool The initial state of audio generation. Default true. + */ + public function get_audio_generation_initial_state( $post = null ) { + /** + * Initial state of the audio generation toggle when no audio already exists for the post. + * + * @since 2.3.0 + * @hook classifai_audio_generation_initial_state + * + * @param {bool} $state Initial state of audio generation toggle on a post. Default true. + * @param {WP_Post} $post The current Post object. + * + * @return {bool} Initial state the audio generation toggle should be set to when no audio exists. + */ + return apply_filters( 'classifai_audio_generation_initial_state', true, get_post( $post ) ); + } + + /** + * Subsequent audio generation state. + * + * Fetch the subsequent state of audio generation once audio is generated for the post. + * + * @param int|WP_Post|null $post Optional. Post ID or post object. `null`, `false`, `0` and other PHP falsey values + * return the current global post inside the loop. A numerically valid post ID that + * points to a non-existent post returns `null`. Defaults to global $post. + * @return bool The subsequent state of audio generation. Default false. + */ + public function get_audio_generation_subsequent_state( $post = null ) { + /** + * Subsequent state of the audio generation toggle when audio exists for the post. + * + * @since 2.3.0 + * @hook classifai_audio_generation_subsequent_state + * + * @param {bool} $state Subsequent state of audio generation toggle on a post. Default false. + * @param {WP_Post} $post The current Post object. + * + * @return {bool} Subsequent state the audio generation toggle should be set to when audio exists. + */ + return apply_filters( 'classifai_audio_generation_subsequent_state', false, get_post( $post ) ); + } + + /** + * Add audio related fields to rest API for view/edit. */ public function add_synthesize_speech_meta_to_rest_api() { - $settings = $this->get_settings(); - $supported_post_types = $settings['post_types'] ?? array(); - - $supported_post_types = array_keys( - array_filter( - $supported_post_types, - function( $post_type ) { - return ! is_null( $post_type ); - } + $supported_post_types = get_tts_supported_post_types(); + + register_rest_field( + $supported_post_types, + 'classifai_synthesize_speech', + array( + 'get_callback' => function( $object ) { + $audio_id = get_post_meta( $object['id'], self::AUDIO_ID_KEY, true ); + if ( + ( $this->get_audio_generation_initial_state( $object['id'] ) && ! $audio_id ) || + ( $this->get_audio_generation_subsequent_state( $object['id'] ) && $audio_id ) + ) { + return true; + } else { + return false; + } + }, + 'schema' => [ + 'type' => 'boolean', + 'context' => [ 'view', 'edit' ], + ], ) ); - if ( empty( $supported_post_types ) ) { - return; - } - register_rest_field( $supported_post_types, - 'classifai_synthesize_speech', + 'classifai_display_generated_audio', array( 'get_callback' => function( $object ) { - $process_content = get_post_meta( $object['id'], self::SYNTHESIZE_SPEECH_KEY, true ); - return ( 'no' === $process_content ) ? 'no' : 'yes'; + // Default to display the audio if available. + if ( metadata_exists( 'post', $object['id'], self::DISPLAY_GENERATED_AUDIO ) ) { + return (bool) get_post_meta( $object['id'], self::DISPLAY_GENERATED_AUDIO, true ); + } + return true; }, - 'update_callback' => function ( $value, $object ) { - $value = ( 'no' === $value ) ? 'no' : 'yes'; - return update_post_meta( $object->ID, self::SYNTHESIZE_SPEECH_KEY, $value ); + 'update_callback' => function( $value, $object ) { + if ( $value ) { + delete_post_meta( $object->ID, self::DISPLAY_GENERATED_AUDIO ); + } else { + update_post_meta( $object->ID, self::DISPLAY_GENERATED_AUDIO, false ); + } }, 'schema' => [ - 'type' => 'string', + 'type' => 'boolean', 'context' => [ 'view', 'edit' ], ], ) @@ -495,13 +558,42 @@ function( $post_type ) { ); } + /** + * Handles audio generation on rest updates / inserts. + * + * @param WP_Post $post Inserted or updated post object. + * @param WP_REST_Request $request Request object. + */ + public function rest_handle_audio( $post, $request ) { + + $audio_id = get_post_meta( $request->get_param( 'id' ), self::AUDIO_ID_KEY, true ); + + // Since we have dynamic generation option agnostic to meta saves we need a flag to differentiate audio generation accurately + $process_content = false; + if ( + ( $this->get_audio_generation_initial_state( $post ) && ! $audio_id ) || + ( $this->get_audio_generation_subsequent_state( $post ) && $audio_id ) + ) { + $process_content = true; + } + + // Add/Update audio if it was requested. + if ( + ( $process_content && null === $request->get_param( 'classifai_synthesize_speech' ) ) || + true === $request->get_param( 'classifai_synthesize_speech' ) + ) { + $save_post_handler = new SavePostHandler(); + $save_post_handler->synthesize_speech( $request->get_param( 'id' ) ); + } + } + /** * Add meta box to post types that support speech synthesis. * * @param string $post_type Post type. */ public function add_meta_box( $post_type ) { - if ( ! in_array( $post_type, $this->get_supported_post_types(), true ) ) { + if ( ! in_array( $post_type, get_tts_supported_post_types(), true ) ) { return; } @@ -511,7 +603,7 @@ public function add_meta_box( $post_type ) { [ $this, 'render_meta_box' ], null, 'side', - 'low', + 'high', array( '__back_compat_meta_box' => true ) ); } @@ -524,38 +616,65 @@ public function add_meta_box( $post_type ) { public function render_meta_box( $post ) { wp_nonce_field( 'classifai_text_to_speech_meta_action', 'classifai_text_to_speech_meta' ); - $process_content = get_post_meta( $post->ID, self::SYNTHESIZE_SPEECH_KEY, true ); - $process_content = ( 'no' === $process_content ) ? 'no' : 'yes'; + $source_url = false; + $audio_id = get_post_meta( $post->ID, self::AUDIO_ID_KEY, true ); + if ( $audio_id ) { + $source_url = wp_get_attachment_url( $audio_id ); + } + + $process_content = false; + if ( + ( $this->get_audio_generation_initial_state( $post ) && ! $audio_id ) || + ( $this->get_audio_generation_subsequent_state( $post ) && $audio_id ) + ) { + $process_content = true; + } + + $display_audio = true; + if ( metadata_exists( 'post', $post->ID, self::DISPLAY_GENERATED_AUDIO ) && + ! (bool) get_post_meta( $post->ID, self::DISPLAY_GENERATED_AUDIO, true ) ) { + $display_audio = false; + } - $post_type = get_post_type_object( get_post_type( $post ) ); $post_type_label = esc_html__( 'Post', 'classifai' ); + $post_type = get_post_type_object( get_post_type( $post ) ); if ( $post_type ) { $post_type_label = $post_type->labels->singular_name; } - $audio_id = get_post_meta( $post->ID, self::AUDIO_ID_KEY, true ); ?> -

+ +

+ +