Plugin Directory

Changeset 3112420


Ignore:
Timestamp:
07/04/2024 11:42:22 AM (21 months ago)
Author:
seowriting
Message:

New version of plugin: 1.7.0

Location:
seowriting
Files:
5 edited
11 copied

Legend:

Unmodified
Added
Removed
  • seowriting/tags/1.7.0/assets/js/settings.js

    r3056072 r3112420  
    7575                if (d.success) {
    7676                    if ('auth_url' in d) {
    77                         window.location.assign(d.auth_url);
     77                        var a = document.createElement('a');
     78                        a.href = d.auth_url;
     79                        a.target = '_blank';
     80                        a.dispatchEvent(new MouseEvent('click', {
     81                            view: window,
     82                            bubbles: true,
     83                            cancelable: true
     84                        }));
     85                        //window.location.assign(d.auth_url);
    7886                    }
    7987                    else {
     
    8391                        }
    8492                    }
    85                     if(type == 'disconnect'){
     93                    if(type === 'disconnect'){
    8694                        disableBtn(conection_button, false);
    8795                        $('.conection-blok').removeClass('connected');
  • seowriting/tags/1.7.0/classes/api-client.php

    r3056086 r3112420  
    7979
    8080        return wp_remote_request($url, $args);
     81    }
     82
     83    /**
     84     * @param string $newVersion
     85     * @return bool
     86     */
     87    public function update($newVersion)
     88    {
     89        $settings = $this->plugin->getSettings();
     90        $this->request('update', [
     91            'api_key' => $settings['api_key'],
     92            'new_version' => $newVersion,
     93        ]);
     94
     95        return true;
    8196    }
    8297
     
    132147            'error' => $this->error,
    133148        ];
     149    }
     150
     151    /**
     152     * @param $status string
     153     * @param $data
     154     */
     155    public function changePostStatus($status, $data)
     156    {
     157        return $this->request('post_' . $status, $data);
    134158    }
    135159
  • seowriting/tags/1.7.0/readme.txt

    r3102248 r3112420  
    55Requires at least: 4.9
    66Requires PHP: 5.6.20
    7 Stable tag: 1.6.2
     7Stable tag: 1.7.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2222
    2323== Changelog ==
     24
     25= 1.7.0 (2024/07/04) =
     26
     27Feature:
     28* Export posts to create knowledge base.
     29* Authorization on the [https://seowriting.ai/](https://seowriting.ai/?utm_source=wp_plugin_changelog) website is performed in a new tab.
    2430
    2531= 1.6.2 (2024/06/13) =
  • seowriting/tags/1.7.0/seowriting.php

    r3102248 r3112420  
    99 * Plugin Name:       SEOWriting
    1010 * Description:       SEOWriting - AI Writing Tool Plugin For Text Generation
    11  * Version:           1.6.2
     11 * Version:           1.7.0
    1212 * Author:            SEOWriting
    1313 * Author URI:        https://seowriting.ai/?utm_source=wp_plugin
     
    2828        public $plugin_slug;
    2929        public $plugin_path;
    30         public $version = '1.6.2';
     30        public $version = '1.7.0';
    3131        /**
    3232         * @var \SEOWriting\APIClient|null
     
    4343        const SCHEMA_TYPE_MICRODATA = 'microdata';
    4444        const SCHEMA_TYPE_OFF = 'off';
     45
     46        const SEOWRITING_PHP = 'seowriting.php';
    4547
    4648        public function __construct()
     
    8385            if (is_admin()) {
    8486                $this->adminPages();
    85                 add_filter('plugin_action_links_' . plugin_basename($this->plugin_path . 'seowriting.php'), [$this, 'adminSettingsLink']);
     87                add_filter('plugin_action_links_' . plugin_basename($this->plugin_path . self::SEOWRITING_PHP), [$this, 'adminSettingsLink']);
    8688
    8789                register_deactivation_hook(__FILE__, [$this, 'deactivate']);
     
    98100            add_filter('the_content', [$this, 'restoreSchemaSection'], 20);
    99101            add_action("wp_head", [$this, 'printJSONLD'], 20);
     102
     103            add_action('transition_post_status', [$this, 'onChangePostStatus'], 10, 3);
     104            add_action('upgrader_process_complete', [$this, 'onUpdate'], 10, 2);
     105
     106        }
     107
     108        /**
     109         * @param $new_status string
     110         * @param $old_status string
     111         * @param $post WP_Post
     112         * @return bool
     113         */
     114        public function onChangePostStatus($new_status, $old_status, $post)
     115        {
     116            $status = '';
     117            if (
     118                ($old_status === 'auto-draft' && $new_status === 'publish')
     119                || ($old_status === 'pending' && $new_status === 'publish')
     120                || ($old_status === 'draft' && $new_status === 'publish')
     121                || ($old_status === 'publish' && $new_status === 'publish')
     122            ) {
     123                $status = 'update';
     124            } else if (
     125                ($old_status === 'publish' && $new_status === 'pending')
     126                || ($old_status === 'publish' && $new_status === 'draft')
     127                || ($old_status === 'publish' && $new_status === 'trash')
     128            ) {
     129                $status = 'delete';
     130            }
     131            if ($status === '') {
     132                return false;
     133            }
     134            $settings = $this->getSettings();
     135            $this->getAPIClient()->changePostStatus($status, [
     136                'post_id' => $post->ID,
     137                'api_key' => $settings['api_key'],
     138            ]);
     139
     140            return true;
     141        }
     142
     143        /**
     144         * @param $upgrader_object
     145         * @param $options
     146         * @return bool
     147         */
     148        public function onUpdate($upgrader_object, $options)
     149        {
     150            return $this->getAPIClient()->update($this->version);
    100151        }
    101152
     
    369420                            'authors' => $this->getAuthors()
    370421                        ];
     422                    } elseif ($action === 'get_posts') {
     423                        $rs = [
     424                            'result' => 1,
     425                            'posts' => $this->getPosts()
     426                        ];
     427                    } elseif ($action === 'get_post') {
     428                        $rs = [
     429                            'result' => 1,
     430                            'post' => $this->getPost(isset($post['post_id']) ? sanitize_text_field($post['post_id']) : '')
     431                        ];
     432                    } elseif ($action === 'get_version') {
     433                        $rs = [
     434                            'result' => 1,
     435                            'version' => $this->getVersion()
     436                        ];
    371437                    } else {
    372438                        $rs = [
     
    379445            }
    380446            return null;
     447        }
     448
     449        private function isDisabledSchema()
     450        {
     451            return get_option('sw_shema_type') === self::SCHEMA_TYPE_OFF;
    381452        }
    382453
     
    405476
    406477            return $content;
    407         }
    408 
    409         /**
    410          * @return bool
    411          */
    412         private function isDisabledSchema()
    413         {
    414             return get_option('sw_shema_type') === self::SCHEMA_TYPE_OFF;
    415478        }
    416479
     
    515578
    516579            $isDisabled = !$this->isMicrodataSchema() && $this->isDisabledSchema();
    517             $out = '<section'.($isDisabled ? '' : ' itemscope itemtype="https://schema.org/FAQPage"').'>';
     580            $out = '<section' . ($isDisabled ? '' : ' itemscope itemtype="https://schema.org/FAQPage"') . '>';
    518581            $out .= '<h2>' . $title . '</h2>';
    519582            for ($i = 0; $i < $count; $i++) {
    520583                if (isset($answers[$i]) && isset($questions[$i])) {
    521                     $out .= '<div'.($isDisabled ? '' : ' itemscope itemprop="mainEntity" itemtype="https://schema.org/Question"').'>'
    522                         . '<h3'.($isDisabled ? '' : ' itemprop="name"').'>' . $questions[$i] . '</h3>'
    523                         . '<div'.($isDisabled ? '' : ' itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer"').'>'
    524                         . '<div'.($isDisabled ? '' : ' itemprop="text"').'>' . $answers[$i] . '</div>'
     584                    $out .= '<div' . ($isDisabled ? '' : ' itemscope itemprop="mainEntity" itemtype="https://schema.org/Question"') . '>'
     585                        . '<h3' . ($isDisabled ? '' : ' itemprop="name"') . '>' . $questions[$i] . '</h3>'
     586                        . '<div' . ($isDisabled ? '' : ' itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer"') . '>'
     587                        . '<div' . ($isDisabled ? '' : ' itemprop="text"') . '>' . $answers[$i] . '</div>'
    525588                        . '</div>'
    526589                        . '</div>';
     
    715778        }
    716779
     780        public function getVersion()
     781        {
     782            return $this->version;
     783        }
     784
     785        public function getPost($post_id)
     786        {
     787            $post = get_post($post_id);
     788            if (!$post || !($post instanceof WP_Post) || $post->post_status !== 'publish') {
     789                return false;
     790            }
     791            return [
     792                'id' => (int)$post->ID,
     793                'content' => $post->post_content,
     794                'title' => $post->post_title,
     795                'url' => get_permalink($post->ID),
     796            ];
     797        }
     798
     799        public function getPosts()
     800        {
     801            $pages = get_pages();
     802            $posts = array_merge(get_posts([
     803                'numberposts' => -1,
     804                'post_type' => 'post',
     805            ]), $pages === false ? [] : $pages);
     806
     807            $result = [];
     808            foreach ($posts as $post) {
     809                if (!($post instanceof WP_Post) || $post->post_status !== 'publish') {
     810                    continue;
     811                }
     812                /** @var WP_Post $post */
     813                $result[] = [
     814                    'id' => (int)$post->ID,
     815                    'content' => $post->post_content,
     816                    'title' => $post->post_title,
     817                    'url' => get_permalink($post->ID),
     818                ];
     819            }
     820
     821            return $result;
     822        }
     823
    717824        /**
    718825         * @return array<array<string, int|string>>
     
    749856            ]);
    750857
    751             $array = [];
     858            $result = [];
    752859            foreach ($categories as $category) {
    753860                /** @var WP_Term $category */
    754                 $array[] = [
     861                $result[] = [
    755862                    'id' => (int)$category->term_id,
    756863                    'name' => $category->name,
     
    759866            }
    760867
    761             return $array;
     868            return $result;
    762869        }
    763870
  • seowriting/trunk/assets/js/settings.js

    r3056072 r3112420  
    7575                if (d.success) {
    7676                    if ('auth_url' in d) {
    77                         window.location.assign(d.auth_url);
     77                        var a = document.createElement('a');
     78                        a.href = d.auth_url;
     79                        a.target = '_blank';
     80                        a.dispatchEvent(new MouseEvent('click', {
     81                            view: window,
     82                            bubbles: true,
     83                            cancelable: true
     84                        }));
     85                        //window.location.assign(d.auth_url);
    7886                    }
    7987                    else {
     
    8391                        }
    8492                    }
    85                     if(type == 'disconnect'){
     93                    if(type === 'disconnect'){
    8694                        disableBtn(conection_button, false);
    8795                        $('.conection-blok').removeClass('connected');
  • seowriting/trunk/classes/api-client.php

    r3056086 r3112420  
    7979
    8080        return wp_remote_request($url, $args);
     81    }
     82
     83    /**
     84     * @param string $newVersion
     85     * @return bool
     86     */
     87    public function update($newVersion)
     88    {
     89        $settings = $this->plugin->getSettings();
     90        $this->request('update', [
     91            'api_key' => $settings['api_key'],
     92            'new_version' => $newVersion,
     93        ]);
     94
     95        return true;
    8196    }
    8297
     
    132147            'error' => $this->error,
    133148        ];
     149    }
     150
     151    /**
     152     * @param $status string
     153     * @param $data
     154     */
     155    public function changePostStatus($status, $data)
     156    {
     157        return $this->request('post_' . $status, $data);
    134158    }
    135159
  • seowriting/trunk/readme.txt

    r3102248 r3112420  
    55Requires at least: 4.9
    66Requires PHP: 5.6.20
    7 Stable tag: 1.6.2
     7Stable tag: 1.7.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2222
    2323== Changelog ==
     24
     25= 1.7.0 (2024/07/04) =
     26
     27Feature:
     28* Export posts to create knowledge base.
     29* Authorization on the [https://seowriting.ai/](https://seowriting.ai/?utm_source=wp_plugin_changelog) website is performed in a new tab.
    2430
    2531= 1.6.2 (2024/06/13) =
  • seowriting/trunk/seowriting.php

    r3102248 r3112420  
    99 * Plugin Name:       SEOWriting
    1010 * Description:       SEOWriting - AI Writing Tool Plugin For Text Generation
    11  * Version:           1.6.2
     11 * Version:           1.7.0
    1212 * Author:            SEOWriting
    1313 * Author URI:        https://seowriting.ai/?utm_source=wp_plugin
     
    2828        public $plugin_slug;
    2929        public $plugin_path;
    30         public $version = '1.6.2';
     30        public $version = '1.7.0';
    3131        /**
    3232         * @var \SEOWriting\APIClient|null
     
    4343        const SCHEMA_TYPE_MICRODATA = 'microdata';
    4444        const SCHEMA_TYPE_OFF = 'off';
     45
     46        const SEOWRITING_PHP = 'seowriting.php';
    4547
    4648        public function __construct()
     
    8385            if (is_admin()) {
    8486                $this->adminPages();
    85                 add_filter('plugin_action_links_' . plugin_basename($this->plugin_path . 'seowriting.php'), [$this, 'adminSettingsLink']);
     87                add_filter('plugin_action_links_' . plugin_basename($this->plugin_path . self::SEOWRITING_PHP), [$this, 'adminSettingsLink']);
    8688
    8789                register_deactivation_hook(__FILE__, [$this, 'deactivate']);
     
    98100            add_filter('the_content', [$this, 'restoreSchemaSection'], 20);
    99101            add_action("wp_head", [$this, 'printJSONLD'], 20);
     102
     103            add_action('transition_post_status', [$this, 'onChangePostStatus'], 10, 3);
     104            add_action('upgrader_process_complete', [$this, 'onUpdate'], 10, 2);
     105
     106        }
     107
     108        /**
     109         * @param $new_status string
     110         * @param $old_status string
     111         * @param $post WP_Post
     112         * @return bool
     113         */
     114        public function onChangePostStatus($new_status, $old_status, $post)
     115        {
     116            $status = '';
     117            if (
     118                ($old_status === 'auto-draft' && $new_status === 'publish')
     119                || ($old_status === 'pending' && $new_status === 'publish')
     120                || ($old_status === 'draft' && $new_status === 'publish')
     121                || ($old_status === 'publish' && $new_status === 'publish')
     122            ) {
     123                $status = 'update';
     124            } else if (
     125                ($old_status === 'publish' && $new_status === 'pending')
     126                || ($old_status === 'publish' && $new_status === 'draft')
     127                || ($old_status === 'publish' && $new_status === 'trash')
     128            ) {
     129                $status = 'delete';
     130            }
     131            if ($status === '') {
     132                return false;
     133            }
     134            $settings = $this->getSettings();
     135            $this->getAPIClient()->changePostStatus($status, [
     136                'post_id' => $post->ID,
     137                'api_key' => $settings['api_key'],
     138            ]);
     139
     140            return true;
     141        }
     142
     143        /**
     144         * @param $upgrader_object
     145         * @param $options
     146         * @return bool
     147         */
     148        public function onUpdate($upgrader_object, $options)
     149        {
     150            return $this->getAPIClient()->update($this->version);
    100151        }
    101152
     
    369420                            'authors' => $this->getAuthors()
    370421                        ];
     422                    } elseif ($action === 'get_posts') {
     423                        $rs = [
     424                            'result' => 1,
     425                            'posts' => $this->getPosts()
     426                        ];
     427                    } elseif ($action === 'get_post') {
     428                        $rs = [
     429                            'result' => 1,
     430                            'post' => $this->getPost(isset($post['post_id']) ? sanitize_text_field($post['post_id']) : '')
     431                        ];
     432                    } elseif ($action === 'get_version') {
     433                        $rs = [
     434                            'result' => 1,
     435                            'version' => $this->getVersion()
     436                        ];
    371437                    } else {
    372438                        $rs = [
     
    379445            }
    380446            return null;
     447        }
     448
     449        private function isDisabledSchema()
     450        {
     451            return get_option('sw_shema_type') === self::SCHEMA_TYPE_OFF;
    381452        }
    382453
     
    405476
    406477            return $content;
    407         }
    408 
    409         /**
    410          * @return bool
    411          */
    412         private function isDisabledSchema()
    413         {
    414             return get_option('sw_shema_type') === self::SCHEMA_TYPE_OFF;
    415478        }
    416479
     
    515578
    516579            $isDisabled = !$this->isMicrodataSchema() && $this->isDisabledSchema();
    517             $out = '<section'.($isDisabled ? '' : ' itemscope itemtype="https://schema.org/FAQPage"').'>';
     580            $out = '<section' . ($isDisabled ? '' : ' itemscope itemtype="https://schema.org/FAQPage"') . '>';
    518581            $out .= '<h2>' . $title . '</h2>';
    519582            for ($i = 0; $i < $count; $i++) {
    520583                if (isset($answers[$i]) && isset($questions[$i])) {
    521                     $out .= '<div'.($isDisabled ? '' : ' itemscope itemprop="mainEntity" itemtype="https://schema.org/Question"').'>'
    522                         . '<h3'.($isDisabled ? '' : ' itemprop="name"').'>' . $questions[$i] . '</h3>'
    523                         . '<div'.($isDisabled ? '' : ' itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer"').'>'
    524                         . '<div'.($isDisabled ? '' : ' itemprop="text"').'>' . $answers[$i] . '</div>'
     584                    $out .= '<div' . ($isDisabled ? '' : ' itemscope itemprop="mainEntity" itemtype="https://schema.org/Question"') . '>'
     585                        . '<h3' . ($isDisabled ? '' : ' itemprop="name"') . '>' . $questions[$i] . '</h3>'
     586                        . '<div' . ($isDisabled ? '' : ' itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer"') . '>'
     587                        . '<div' . ($isDisabled ? '' : ' itemprop="text"') . '>' . $answers[$i] . '</div>'
    525588                        . '</div>'
    526589                        . '</div>';
     
    715778        }
    716779
     780        public function getVersion()
     781        {
     782            return $this->version;
     783        }
     784
     785        public function getPost($post_id)
     786        {
     787            $post = get_post($post_id);
     788            if (!$post || !($post instanceof WP_Post) || $post->post_status !== 'publish') {
     789                return false;
     790            }
     791            return [
     792                'id' => (int)$post->ID,
     793                'content' => $post->post_content,
     794                'title' => $post->post_title,
     795                'url' => get_permalink($post->ID),
     796            ];
     797        }
     798
     799        public function getPosts()
     800        {
     801            $pages = get_pages();
     802            $posts = array_merge(get_posts([
     803                'numberposts' => -1,
     804                'post_type' => 'post',
     805            ]), $pages === false ? [] : $pages);
     806
     807            $result = [];
     808            foreach ($posts as $post) {
     809                if (!($post instanceof WP_Post) || $post->post_status !== 'publish') {
     810                    continue;
     811                }
     812                /** @var WP_Post $post */
     813                $result[] = [
     814                    'id' => (int)$post->ID,
     815                    'content' => $post->post_content,
     816                    'title' => $post->post_title,
     817                    'url' => get_permalink($post->ID),
     818                ];
     819            }
     820
     821            return $result;
     822        }
     823
    717824        /**
    718825         * @return array<array<string, int|string>>
     
    749856            ]);
    750857
    751             $array = [];
     858            $result = [];
    752859            foreach ($categories as $category) {
    753860                /** @var WP_Term $category */
    754                 $array[] = [
     861                $result[] = [
    755862                    'id' => (int)$category->term_id,
    756863                    'name' => $category->name,
     
    759866            }
    760867
    761             return $array;
     868            return $result;
    762869        }
    763870
Note: See TracChangeset for help on using the changeset viewer.