Plugin Directory

Changeset 3221380


Ignore:
Timestamp:
01/13/2025 07:57:01 AM (14 months ago)
Author:
quickcreator
Message:

update to 0.1.2

Location:
quickcreator
Files:
8 edited
5 copied

Legend:

Unmodified
Added
Removed
  • quickcreator/tags/0.0.3/includes/quickcreator/class-content-importer.php

    r3142565 r3221380  
    11<?php
     2
    23/**
    34 *  Object that handle importing content from:
     
    1819 * Object that imports data from different sources into WordPress.
    1920 */
    20 class Content_Importer {
     21class Content_Importer
     22{
    2123
    2224    /**
     
    3133     * Basic construct.
    3234     */
    33     public function __construct() {
     35    public function __construct()
     36    {
    3437        $this->content_parser = new Parsers_Controller();
    3538    }
     
    4346     * @return int|WP_Error
    4447     */
    45     public function save_data_into_database( $content, $args = array()) {
    46         $user = get_users()[0];
    47         wp_set_current_user( $user->ID, $user->data->display_name);
    48         if ( 'elementor' === $args['filter'] ) {
     48    public function save_data_into_database($content, $args = array())
     49    {
     50        $user_args  = array(
     51            'role'    => 'Administrator',
     52            'orderby' => 'user_nicename',
     53            'order'   => 'ASC',
     54        );
     55        $user = get_users($user_args)[0];
     56        wp_set_current_user($user->ID, $user->data->display_name);
     57        if ('elementor' === $args['filter']) {
    4958            $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php');
    5059            if ($if_elementor_is_active) {
    5160                $rawContent = "";
    5261            }
    53         } else if ( 'raw' !== $args['filter'] ) {
    54             $rawContent = $this->content_parser->parse_content( $content );
     62        } else if ('raw' !== $args['filter']) {
     63            $rawContent = $this->content_parser->parse_content($content);
    5564        } else {
    5665            $this->content_parser->choose_parser();
    5766            $rawContent = $content;
    5867        }
    59         $title = isset( $args['post_title'] ) && strlen( $args['post_title'] ) > 0 ? $args['post_title'] : $this->content_parser->return_title();
     68        $title = isset($args['post_title']) && strlen($args['post_title']) > 0 ? $args['post_title'] : $this->content_parser->return_title();
    6069
    6170        $data = array(
     
    6473        );
    6574
    66         if ( isset( $args['post_id'] ) && $args['post_id'] > 0 ) {
     75        if (isset($args['post_id']) && $args['post_id'] > 0) {
    6776
    6877            $provided_post_id = $args['post_id'];
     
    7584        }
    7685
    77         $this->resolve_post_author( $args, $data );
    78         $this->resolve_post_status( $args, $data );
    79         $this->resolve_post_type( $args, $data );
    80         $this->resolve_post_permalink( $args, $data );
    81         $this->resolve_post_category( $args, $data );
    82         $this->resolve_post_tags( $args, $data );
    83         $this->resolve_post_meta_details( $args, $data );
    84         $this->resolve_post_excerpt( $args, $data);
    85         $this->resolve_post_parent( $args, $data );
    86 
    87         if ( isset( $post ) && 'published' === $post['post_status'] ) {
     86        $this->resolve_post_author($args, $data);
     87        $this->resolve_post_status($args, $data);
     88        $this->resolve_post_type($args, $data);
     89        $this->resolve_post_permalink($args, $data);
     90        $this->resolve_post_category($args, $data);
     91        $this->resolve_post_tags($args, $data);
     92        $this->resolve_post_meta_details($args, $data);
     93        $this->resolve_post_excerpt($args, $data);
     94        $this->resolve_post_parent($args, $data);
     95
     96        if (isset($post) && 'published' === $post['post_status']) {
    8897            // WordPress set current date as default and we do not want to change publication date.
    8998            $data['post_date'] = $post['post_date'];
    9099        } else {
    91             $this->resolve_post_date( $args, $data );
    92         }
    93        
    94         $post_id = wp_insert_post( $data, true );
    95 
    96         if ( ! is_wp_error( $post_id ) && isset( $args['draft_id'] ) ) {
    97             update_post_meta( $post_id, 'quickcreator_draft_id', $args['draft_id'] );
    98             update_post_meta( $post_id, 'quickcreator_permalink_hash', isset( $args['permalink_hash'] ) ? $args['permalink_hash'] : '' );
    99             update_post_meta( $post_id, 'quickcreator_keywords', $args['keywords'] );
    100             update_post_meta( $post_id, 'quickcreator_location', $args['location'] );
    101             update_post_meta( $post_id, 'quickcreator_scrape_ready', true );
    102             update_post_meta( $post_id, 'quickcreator_last_post_update', round( microtime( true ) * 1000 ) );
    103             update_post_meta( $post_id, 'quickcreator_last_post_update_direction', 'from Quickcreator to WordPress' );
    104         }
    105 
    106         $this->resove_post_meta_after_insert_post( $post_id, $args);
    107 
    108         if ( 'elementor' === $args['filter'] ) {
     100            $this->resolve_post_date($args, $data);
     101        }
     102
     103        $post_id = wp_insert_post($data, true);
     104
     105        if (! is_wp_error($post_id) && isset($args['draft_id'])) {
     106            update_post_meta($post_id, 'quickcreator_draft_id', $args['draft_id']);
     107            update_post_meta($post_id, 'quickcreator_permalink_hash', isset($args['permalink_hash']) ? $args['permalink_hash'] : '');
     108            update_post_meta($post_id, 'quickcreator_keywords', $args['keywords']);
     109            update_post_meta($post_id, 'quickcreator_location', $args['location']);
     110            update_post_meta($post_id, 'quickcreator_scrape_ready', true);
     111            update_post_meta($post_id, 'quickcreator_last_post_update', round(microtime(true) * 1000));
     112            update_post_meta($post_id, 'quickcreator_last_post_update_direction', 'from Quickcreator to WordPress');
     113        }
     114
     115        $this->resove_post_meta_after_insert_post($post_id, $args);
     116
     117        if ('elementor' === $args['filter']) {
    109118            $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php');
    110119            if ($if_elementor_is_active) {
    111                 \Elementor\Plugin::$instance->documents->ajax_save( [
    112                         'editor_post_id' => $post_id,
    113                         'status' => $data["post_status"],
    114                         'elements' => $content['elements'],
    115                       'settings' => $content['settings'],
    116                 ] );
    117             }
    118         } else {
    119             $this->content_parser->run_after_post_insert_actions( $post_id );
     120                \Elementor\Plugin::$instance->documents->ajax_save([
     121                    'editor_post_id' => $post_id,
     122                    'status' => $data["post_status"],
     123                    'elements' => $content['elements'],
     124                    'settings' => $content['settings'],
     125                ]);
     126            }
     127        } else {
     128            $this->content_parser->run_after_post_insert_actions($post_id);
    120129        }
    121130        return $post_id;
     
    129138     * @return array URL to image in media library.
    130139     */
    131     public function upload_img_to_media_library( $image_url, $image_alt ) {
    132         $image_data = $this->content_parser->upload_img_to_media_library( $image_url, $image_alt);
     140    public function upload_img_to_media_library($image_url, $image_alt)
     141    {
     142        $image_data = $this->content_parser->upload_img_to_media_library($image_url, $image_alt);
    133143        $image_url  = $image_data['url'];
    134144        $image_id   = $image_data['id'];
     
    152162     * @return void
    153163     */
    154     private function resolve_post_author( $args, &$data ) {
    155 
    156         if ( isset( $args['post_author'] ) && '' !== $args['post_author'] ) {
     164    private function resolve_post_author($args, &$data)
     165    {
     166
     167        if (isset($args['post_author']) && '' !== $args['post_author']) {
    157168
    158169            $value = $args['post_author'];
    159170
    160             if ( is_numeric( $value ) && $value > 0 ) {
     171            if (is_numeric($value) && $value > 0) {
    161172                $data['post_author'] = $value;
    162173            } else {
    163                 $data['post_author'] = $this->get_user_id_by_login( $value );
    164             }
    165         } else {
    166             $default = Quickcreator()->get_quickcreator_settings()->get_option( 'content-importer', 'default_post_author', false );
    167 
    168             if ( false !== $default ) {
     174                $data['post_author'] = $this->get_user_id_by_login($value);
     175            }
     176        } else {
     177            $default = Quickcreator()->get_quickcreator_settings()->get_option('content-importer', 'default_post_author', false);
     178
     179            if (false !== $default) {
    169180                $data['post_author'] = $default;
    170181            }
    171182        }
    172183    }
    173    
     184
    174185    /**
    175186     * Fill $data array with proper attribute for post_excerpt or leave empty to fill default.
     
    179190     * @return void
    180191     */
    181     private function resolve_post_excerpt( $args, &$data) {
    182         if ( isset( $args['post_excerpt'] ) && '' !== $args['post_excerpt'] ) {
     192    private function resolve_post_excerpt($args, &$data)
     193    {
     194        if (isset($args['post_excerpt']) && '' !== $args['post_excerpt']) {
    183195            $data['post_excerpt'] = $args['post_excerpt'];
    184         }   
     196        }
    185197    }
    186198
     
    192204     * @return void
    193205     */
    194     private function resolve_post_status( $args, &$data ) {
    195 
    196         $allowed_statuses = array( 'publish', 'draft', 'pending', 'future', 'private' );
    197 
    198         if ( isset( $args['post_status'] ) && '' !== $args['post_status'] && in_array( $args['post_status'], $allowed_statuses, true ) ) {
     206    private function resolve_post_status($args, &$data)
     207    {
     208
     209        $allowed_statuses = array('publish', 'draft', 'pending', 'future', 'private');
     210
     211        if (isset($args['post_status']) && '' !== $args['post_status'] && in_array($args['post_status'], $allowed_statuses, true)) {
    199212            $data['post_status'] = $args['post_status'];
    200213        } else {
    201             $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_post_status', false );
    202 
    203             if ( false !== $default ) {
     214            $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_post_status', false);
     215
     216            if (false !== $default) {
    204217                $data['post_status'] = $default;
    205218            }
     
    214227     * @return void
    215228     */
    216     private function resolve_post_type( $args, &$data ) {
     229    private function resolve_post_type($args, &$data)
     230    {
    217231
    218232        $allowed_post_types = quickcreator_return_supported_post_types();
    219233
    220         if ( isset( $args['post_type'] ) && '' !== $args['post_type'] && in_array( $args['post_type'], $allowed_post_types, true ) ) {
     234        if (isset($args['post_type']) && '' !== $args['post_type'] && in_array($args['post_type'], $allowed_post_types, true)) {
    221235            $data['post_type'] = $args['post_type'];
    222236        } else {
     
    232246     * @return void
    233247     */
    234     private function resolve_post_date( $args, &$data ) {
    235 
    236         if ( isset( $args['post_date'] ) && strtotime( $args['post_date'] ) > time() ) {
    237             $data['post_date'] = gmdate( 'Y-m-d H:i:s', strtotime( $args['post_date'] ) );
     248    private function resolve_post_date($args, &$data)
     249    {
     250
     251        if (isset($args['post_date']) && strtotime($args['post_date']) > time()) {
     252            $data['post_date'] = gmdate('Y-m-d H:i:s', strtotime($args['post_date']));
    238253        }
    239254    }
     
    246261     * @return void
    247262     */
    248     private function resolve_post_parent($args, &$data) {
    249 
    250         if ( isset( $args['post_parent'] ) && '' !== $args['post_parent'] ) {
     263    private function resolve_post_parent($args, &$data)
     264    {
     265
     266        if (isset($args['post_parent']) && '' !== $args['post_parent']) {
    251267            $data['post_parent'] = $args['post_parent'];
    252268        }
     
    261277     * @return void
    262278     */
    263     private function resolve_post_permalink( $args, &$data ) {
    264 
    265         if ( isset( $args['post_name'] ) && '' !== $args['post_name'] ) {
     279    private function resolve_post_permalink($args, &$data)
     280    {
     281
     282        if (isset($args['post_name']) && '' !== $args['post_name']) {
    266283            $data['post_name'] = $args['post_name'];
    267284        }
     
    275292     * @return void
    276293     */
    277     private function resolve_post_category( $args, &$data ) {
    278 
    279         if ( isset( $args['post_category'] ) && is_array( $args['post_category'] ) && ! empty( $args['post_category'] ) ) {
     294    private function resolve_post_category($args, &$data)
     295    {
     296
     297        if (isset($args['post_category']) && is_array($args['post_category']) && ! empty($args['post_category'])) {
    280298
    281299            $categories = array();
    282             foreach ( $args['post_category'] as $category ) {
     300            foreach ($args['post_category'] as $category) {
    283301                $categories[] = $category;
    284302            }
     
    286304            $data['post_category'] = $categories;
    287305        } else {
    288             $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_category', false );
    289 
    290             if ( false !== $default ) {
    291                 $data['post_category'] = array( $default );
     306            $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_category', false);
     307
     308            if (false !== $default) {
     309                $data['post_category'] = array($default);
    292310            }
    293311        }
     
    301319     * @return void
    302320     */
    303     private function resolve_post_tags( $args, &$data ) {
    304 
    305         if ( isset( $args['post_tags'] ) && is_array( $args['post_tags'] ) && count( $args['post_tags'] ) > 0 ) {
     321    private function resolve_post_tags($args, &$data)
     322    {
     323
     324        if (isset($args['post_tags']) && is_array($args['post_tags']) && count($args['post_tags']) > 0) {
    306325
    307326            $tags = array();
    308             foreach ( $args['post_tags'] as $tag ) {
     327            foreach ($args['post_tags'] as $tag) {
    309328                $tags[] = $tag;
    310329            }
     
    312331            $data['tags_input'] = $tags;
    313332        } else {
    314             $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_tags', false );
    315 
    316             if ( false !== $default ) {
     333            $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_tags', false);
     334
     335            if (false !== $default) {
    317336                $data['tags_input'] = $default;
    318337            }
     
    327346     * @return void
    328347     */
    329     private function resolve_post_meta_details( $args, &$data ) {
     348    private function resolve_post_meta_details($args, &$data)
     349    {
    330350
    331351        $seo_plugin_is_active = false;
    332352
    333         if ( ! isset( $data['meta_input'] ) ) {
     353        if (! isset($data['meta_input'])) {
    334354            $data['meta_input'] = array();
    335355        }
    336356
    337         if ( isset( $args['meta_input'] ) ) {
    338             foreach ( $args['meta_input'] as $key => $value ) {
    339                 $data['meta_input'][ $key ] = $value;
    340             }
    341         }
    342 
    343         if ( isset( $args['featured_image'] ) && '' !== $args['featured_image'] ) {
    344             if ( is_int($args['featured_image']) ) {
     357        if (isset($args['meta_input'])) {
     358            foreach ($args['meta_input'] as $key => $value) {
     359                $data['meta_input'][$key] = $value;
     360            }
     361        }
     362
     363        if (isset($args['featured_image']) && '' !== $args['featured_image']) {
     364            if (is_int($args['featured_image'])) {
    345365                $data['meta_input']['_thumbnail_id'] = $args['featured_image'];
    346366            } else {
     
    351371
    352372        // Yoast SEO is active.
    353         if ( quickcreator_check_if_plugins_is_active( 'wordpress-seo/wp-seo.php' ) ) {
    354 
    355             if ( isset( $args['meta_title'] ) && '' !== $args['meta_title'] ) {
     373        if (quickcreator_check_if_plugins_is_active('wordpress-seo/wp-seo.php')) {
     374
     375            if (isset($args['meta_title']) && '' !== $args['meta_title']) {
    356376                $data['meta_input']['_yoast_wpseo_title'] = $args['meta_title'];
    357377            }
    358378
    359             if ( isset( $args['meta_description'] ) && '' !== $args['meta_description'] ) {
     379            if (isset($args['meta_description']) && '' !== $args['meta_description']) {
    360380                $data['meta_input']['_yoast_wpseo_metadesc'] = $args['meta_description'];
    361381            }
     
    364384        }
    365385
    366         if ( quickcreator_check_if_plugins_is_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) {   
     386        if (quickcreator_check_if_plugins_is_active('all-in-one-seo-pack/all_in_one_seo_pack.php')) {
    367387            $seo_plugin_is_active = true;
    368388        }
    369389
    370390        // Rank Math SEO.
    371         if ( quickcreator_check_if_plugins_is_active( 'seo-by-rank-math/rank-math.php' ) ) {
    372 
    373             if ( isset( $args['meta_title'] ) && '' !== $args['meta_title'] ) {
     391        if (quickcreator_check_if_plugins_is_active('seo-by-rank-math/rank-math.php')) {
     392
     393            if (isset($args['meta_title']) && '' !== $args['meta_title']) {
    374394                $data['meta_input']['rank_math_title'] = $args['meta_title'];
    375395            }
    376396
    377             if ( isset( $args['meta_description'] ) && '' !== $args['meta_description'] ) {
     397            if (isset($args['meta_description']) && '' !== $args['meta_description']) {
    378398                $data['meta_input']['rank_math_description'] = $args['meta_description'];
    379399            }
     
    383403
    384404        // Save in quickcreator Meta to display.
    385         if ( ! $seo_plugin_is_active ) {
    386 
    387             if ( isset( $args['meta_title'] ) && '' !== $args['meta_title'] ) {
     405        if (! $seo_plugin_is_active) {
     406
     407            if (isset($args['meta_title']) && '' !== $args['meta_title']) {
    388408                $data['meta_input']['_quickcreatorblog_title'] = $args['meta_title'];
    389409            }
    390410
    391             if ( isset( $args['meta_description'] ) && '' !== $args['meta_description'] ) {
     411            if (isset($args['meta_description']) && '' !== $args['meta_description']) {
    392412                $data['meta_input']['_quickcreatorblog_description'] = $args['meta_description'];
    393413            }
     
    395415    }
    396416
    397     private function resove_post_meta_after_insert_post(    $post_id, $args) {
    398         if ( quickcreator_check_if_plugins_is_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) {   
     417    private function resove_post_meta_after_insert_post($post_id, $args)
     418    {
     419        if (quickcreator_check_if_plugins_is_active('all-in-one-seo-pack/all_in_one_seo_pack.php')) {
    399420            $seo_data = [];
    400             if ( isset( $args['meta_title'] ) && '' !== $args['meta_title'] ) {
     421            if (isset($args['meta_title']) && '' !== $args['meta_title']) {
    401422                $seo_data['title'] = $args['meta_title'];
    402423            }
    403424
    404             if ( isset( $args['meta_description'] ) && '' !== $args['meta_description'] ) {
     425            if (isset($args['meta_description']) && '' !== $args['meta_description']) {
    405426                $seo_data['description'] = $args['meta_description'];
    406427            }
    407             \AIOSEO\Plugin\Common\Models\Post::savePost( $post_id, $seo_data);
     428            \AIOSEO\Plugin\Common\Models\Post::savePost($post_id, $seo_data);
    408429        }
    409430    }
     
    416437     * @return int
    417438     */
    418     private function get_user_id_by_login( $login = false ) {
     439    private function get_user_id_by_login($login = false)
     440    {
    419441
    420442        $user_id = 0;
    421         $user    = get_user_by( 'login', $login );
    422 
    423         if ( false !== $user ) {
    424             $user_id = get_option( 'quickcreator_auth_user', 0 );
     443        $user    = get_user_by('login', $login);
     444
     445        if (false !== $user) {
     446            $user_id = get_option('quickcreator_auth_user', 0);
    425447        }
    426448
     
    435457     * @return bool
    436458     */
    437     public function check_if_plugins_is_active( $plugin ) {
    438 
    439         if ( ! function_exists( 'is_plugin_active' ) ) {
    440             return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true );
    441         } else {
    442             return is_plugin_active( $plugin );
     459    public function check_if_plugins_is_active($plugin)
     460    {
     461
     462        if (! function_exists('is_plugin_active')) {
     463            return in_array($plugin, (array) get_option('active_plugins', array()), true);
     464        } else {
     465            return is_plugin_active($plugin);
    443466        }
    444467    }
  • quickcreator/tags/0.1.2/includes/admin/class-quickcreator-admin.php

    r3167391 r3221380  
    130130        // read content from file /dupasrala.txt
    131131        $dupasrala = file_get_contents(Quickcreator()->get_basedir() . '/dupasrala.txt');
     132        $error_log = file_get_contents(Quickcreator()->get_basedir() . '/error.log');
    132133
    133134        $content  = gmdate('d-m-Y H:i:s') . PHP_EOL . PHP_EOL;
     
    139140        $content .= 'QUICKCREATOR VERSION NOW: ' . QUICKCREATOR_BLOG_VERSION . PHP_EOL . PHP_EOL;
    140141        $content .= 'PHP VERSION: ' . phpversion() . PHP_EOL . PHP_EOL;
    141         $content .= 'WordPress VERSION: ' . get_bloginfo('version') . PHP_EOL . PHP_EOL;
    142 
     142        $content .= 'WordPress VERSION: ' . get_bloginfo('version') . PHP_EOL . PHP_EOL . PHP_EOL;
     143        $content .= 'ERROR LOG: ' . PHP_EOL . $error_log . PHP_EOL . PHP_EOL;
    143144        return $content;
    144145    }
  • quickcreator/tags/0.1.2/includes/quickcreator/class-content-importer.php

    r3158668 r3221380  
    4848    public function save_data_into_database($content, $args = array())
    4949    {
    50         $user = get_users()[0];
     50        $user_args  = array(
     51            'role'    => 'Administrator',
     52            'orderby' => 'user_nicename',
     53            'order'   => 'ASC',
     54        );
     55        $user = get_users($user_args)[0];
    5156        wp_set_current_user($user->ID, $user->data->display_name);
    5257        if ('elementor' === $args['filter']) {
     
    109114
    110115        $this->resove_post_meta_after_insert_post($post_id, $args);
    111 
    112         if ('elementor' === $args['filter']) {
    113             $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php');
    114             if ($if_elementor_is_active) {
    115                 \Elementor\Plugin::$instance->documents->ajax_save([
    116                     'editor_post_id' => $post_id,
    117                     'status' => $data["post_status"],
    118                     'elements' => $content['elements'],
    119                     'settings' => $content['settings'],
    120                 ]);
    121                 if (isset($args['meta_input']) && isset($args['meta_input']['_elementor_template_type']) && "kit" === $args['meta_input']['_elementor_template_type']) {
    122                     $kits_manager = \Elementor\Plugin::$instance->kits_manager;
    123                     update_option($kits_manager::OPTION_PREVIOUS, $kits_manager->get_active_id());
    124                     update_option($kits_manager::OPTION_ACTIVE, $post_id);
     116        if (! is_wp_error($post_id)) {
     117            if ('elementor' === $args['filter']) {
     118                $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php');
     119                if ($if_elementor_is_active) {
     120                    \Elementor\Plugin::$instance->documents->ajax_save([
     121                        'editor_post_id' => $post_id,
     122                        'status' => $data["post_status"],
     123                        'elements' => $content['elements'],
     124                        'settings' => $content['settings'],
     125                    ]);
     126                    if (isset($args['meta_input']) && isset($args['meta_input']['_elementor_template_type']) && "kit" === $args['meta_input']['_elementor_template_type']) {
     127                        $kits_manager = \Elementor\Plugin::$instance->kits_manager;
     128                        update_option($kits_manager::OPTION_PREVIOUS, $kits_manager->get_active_id());
     129                        update_option($kits_manager::OPTION_ACTIVE, $post_id);
     130                    }
    125131                }
    126             }
    127         } else {
    128             $this->content_parser->run_after_post_insert_actions($post_id);
     132            } else {
     133                $this->content_parser->run_after_post_insert_actions($post_id);
     134            }
    129135        }
    130136        return $post_id;
  • quickcreator/tags/0.1.2/includes/quickcreator/class-quickcreator.php

    r3173581 r3221380  
    106106        add_action('wp_ajax_disconnect_quickcreator', array($this, 'disconnect_quickcreator_from_wp'));
    107107        add_action('wp_ajax_check_quickcreator_connection_status', array($this, 'check_connection_status'));
     108        add_filter("rest_request_after_callbacks", array($this, 'register_connection_api_filter'), 10, 3);
    108109    }
    109110    /**
     
    136137    //  return $this->quickcreator_privacy_policy;
    137138    // }
     139
     140    public function register_connection_api_filter($response, $handler, $request)
     141    {
     142        // check quickcreatorblog/v1 request
     143        if (strpos($request->get_route(), 'quickcreatorblog/v1') === false) {
     144            $log_data = [];
     145            if (is_wp_error($response)) {
     146                $log_data = [
     147                    'error' => $response->get_error_message(),
     148                    'request' => [
     149                        'route' => $request->get_route(),
     150                        'method' => $request->get_method(),
     151                        'params' => $request->get_params(),
     152                    ]
     153                ];
     154            } else if ($response instanceof WP_REST_Response) {
     155                if ($response->is_error()) {
     156                    $log_data = [
     157                        'error' => 'Response contains an error.',
     158                        'request' => [
     159                            'route' => $request->get_route(),
     160                            'method' => $request->get_method(),
     161                            'params' => $request->get_params(),
     162                        ],
     163                        'response' => $response->get_data(),
     164                    ];
     165                }
     166            }
     167            if (!empty($log_data)) {
     168                file_put_contents(
     169                    Quickcreator()->get_basedir() . '/error.log',
     170                    date('Y-m-d H:i:s') . ' - ' . print_r($log_data, true) . "\n",
     171                    FILE_APPEND
     172                );
     173            }
     174        }
     175
     176        return $response;
     177    }
    138178
    139179    /**
     
    782822    public function quickcreator_import_post($request)
    783823    {
    784         $args    = array();
    785         $content = $request->get_param('content');
    786 
    787         if (empty($content) || '' === $content || (is_string($content) && strlen($content) < 1)) {
     824        try {
     825            $args    = array();
     826            $content = $request->get_param('content');
     827
     828            if (empty($content) || '' === $content || (is_string($content) && strlen($content) < 1)) {
     829                return new WP_REST_Response(
     830                    array(
     831                        'error' => __('Cannot add post with empty content.', 'quickcreator'),
     832                    ),
     833                    422
     834                );
     835            }
     836
     837            // $metadata = $request->get_param( 'metadata' );
     838
     839            // Optional params.
     840            $args['post_id']          = $request->get_param('post_id');
     841            $args['post_title']       = $request->get_param('title') ?? '';
     842            $args['permalink_hash']   = $request->get_param('slug');
     843            $args['post_category']    = $request->get_param('categories') ?? array();
     844            $args['post_tags']        = $request->get_param('tags') ?? array();
     845            $args['post_author']      = $request->get_param('author') ?? '';
     846            $args['post_excerpt']     = $request->get_param('excerpt') ?? '';
     847            $args['meta_title']       = $request->get_param('meta_title');
     848            $args['meta_description'] = $request->get_param('meta_description');
     849            $args['post_status']      = $request->get_param('status');
     850            $args['post_type']        = $request->get_param('post_type') ?? '';
     851            $args["meta_input"]       = $request->get_param('meta') ?? array();
     852            $args['post_parent']      = $request->get_param('post_parent') ?? 0;
     853            $args['filter']           = $request->get_param('filter') ?? '';
     854            $featured_image = $request->get_param('featured_image');
     855            if ($featured_image !== null && $featured_image !== '') {
     856                $args['featured_image']   = $featured_image; # quickcreator_sync_image_to_media_library($request->get_param( 'featured_image' ));
     857            }
     858
     859            // $args['post_date']        = $metadata['publicationDate'] ?? '';
     860            // $args['tags_input']       = $request->get_param( 'tags_input' );
     861
     862            $args['post_name']        = $request->get_param('name');
     863            // $args['draft_id']         = $request->get_param( 'draft_id' );
     864            // $args['keywords']         = $request->get_param( 'keywords' );
     865            // $args['location']         = $request->get_param( 'location' );
     866
     867            $modification_date = gmdate('Y-m-d');
     868            if (isset($args['post_id'])) {
     869                $modification_date = get_the_modified_time('Y-m-d', $args['post_id']);
     870            }
     871
     872            $post_id = $this->content_importer->save_data_into_database($content, $args);
     873
     874            if (! is_wp_error($post_id)) {
     875                return new WP_REST_Response(
     876                    array(
     877                        'post_id'       => $post_id,
     878                        'edit_post_url' => $this->get_edit_post_link($post_id, 'notdisplay'),
     879                        'post_url'      => get_permalink($post_id),
     880                        'post_status'   => get_post_status($post_id),
     881                        'modified_at'   => $modification_date,
     882                        'url'           => site_url(),
     883                    )
     884                );
     885            } else {
     886                return new WP_REST_Response(
     887                    array(
     888                        'error'            => __('There was an error on post adding', 'quickcreator'),
     889                        'wp_error_message' => $post_id->get_error_message(),
     890                    ),
     891                    403
     892                );
     893            }
     894        } catch (\Exception $e) {
    788895            return new WP_REST_Response(
    789896                array(
    790                     'error' => __('Cannot add post with empty content.', 'quickcreator'),
    791                 ),
    792                 422
    793             );
    794         }
    795 
    796         // $metadata = $request->get_param( 'metadata' );
    797 
    798         // Optional params.
    799         $args['post_id']          = $request->get_param('post_id');
    800         $args['post_title']       = $request->get_param('title') ?? '';
    801         $args['permalink_hash']   = $request->get_param('slug');
    802         $args['post_category']    = $request->get_param('categories') ?? array();
    803         $args['post_tags']        = $request->get_param('tags') ?? array();
    804         $args['post_author']      = $request->get_param('author') ?? '';
    805         $args['post_excerpt']     = $request->get_param('excerpt') ?? '';
    806         $args['meta_title']       = $request->get_param('meta_title');
    807         $args['meta_description'] = $request->get_param('meta_description');
    808         $args['post_status']      = $request->get_param('status');
    809         $args['post_type']        = $request->get_param('post_type') ?? '';
    810         $args["meta_input"]       = $request->get_param('meta') ?? array();
    811         $args['post_parent']      = $request->get_param('post_parent') ?? 0;
    812         $args['filter']           = $request->get_param('filter') ?? '';
    813         $featured_image = $request->get_param('featured_image');
    814         if ($featured_image !== null && $featured_image !== '') {
    815             $args['featured_image']   = $featured_image; # quickcreator_sync_image_to_media_library($request->get_param( 'featured_image' ));
    816         }
    817 
    818         // $args['post_date']        = $metadata['publicationDate'] ?? '';
    819         // $args['tags_input']       = $request->get_param( 'tags_input' );
    820 
    821         $args['post_name']        = $request->get_param('name');
    822         // $args['draft_id']         = $request->get_param( 'draft_id' );
    823         // $args['keywords']         = $request->get_param( 'keywords' );
    824         // $args['location']         = $request->get_param( 'location' );
    825 
    826         $modification_date = gmdate('Y-m-d');
    827         if (isset($args['post_id'])) {
    828             $modification_date = get_the_modified_time('Y-m-d', $args['post_id']);
    829         }
    830 
    831         $post_id = $this->content_importer->save_data_into_database($content, $args);
    832 
    833         if (! is_wp_error($post_id)) {
    834             return new WP_REST_Response(
    835                 array(
    836                     'post_id'       => $post_id,
    837                     'edit_post_url' => $this->get_edit_post_link($post_id, 'notdisplay'),
    838                     'post_url'      => get_permalink($post_id),
    839                     'post_status'   => get_post_status($post_id),
    840                     'modified_at'   => $modification_date,
    841                     'url'           => site_url(),
    842                 )
    843             );
    844         } else {
    845             return new WP_REST_Response(
    846                 array(
    847                     'error'            => __('There was an error on post adding', 'quickcreator'),
    848                     'wp_error_message' => $post_id->get_error_message(),
     897                    'error' => $e->getMessage(),
    849898                ),
    850899                403
     
    13481397    public function site_builder_site_init($request)
    13491398    {
    1350         $user = get_users()[0];
     1399        $user_args  = array(
     1400            'role'    => 'Administrator',
     1401            'orderby' => 'user_nicename',
     1402            'order'   => 'ASC',
     1403        );
     1404        $user = get_users($user_args)[0];
    13511405        wp_set_current_user($user->ID, $user->data->display_name);
    13521406        $is_astra_based_theme = defined('ASTRA_THEME_SETTINGS');
  • quickcreator/tags/0.1.2/quickcreator.php

    r3173581 r3221380  
    44 * Plugin URI: https://wordpress.org/plugins/quickcreator/
    55 * Description: Create post with Quickcreator in WordPress
    6  * Version: 0.1.1
     6 * Version: 0.1.2
    77 * Author: Quickcreator
    88 * Author URI: https://quickcreator.io
     
    2222
    2323if ( ! defined( 'QUICKCREATOR_BLOG_VERSION' ) ) {
    24     define( 'QUICKCREATOR_BLOG_VERSION', '0.1.1' );
     24    define( 'QUICKCREATOR_BLOG_VERSION', '0.1.2' );
    2525}
    2626
  • quickcreator/tags/0.1.2/readme.txt

    r3173581 r3221380  
    55Requires PHP: 7.4
    66Tested up to: 6.6
    7 Stable tag: 0.1.1
     7Stable tag: 0.1.2
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • quickcreator/trunk/includes/admin/class-quickcreator-admin.php

    r3167391 r3221380  
    130130        // read content from file /dupasrala.txt
    131131        $dupasrala = file_get_contents(Quickcreator()->get_basedir() . '/dupasrala.txt');
     132        $error_log = file_get_contents(Quickcreator()->get_basedir() . '/error.log');
    132133
    133134        $content  = gmdate('d-m-Y H:i:s') . PHP_EOL . PHP_EOL;
     
    139140        $content .= 'QUICKCREATOR VERSION NOW: ' . QUICKCREATOR_BLOG_VERSION . PHP_EOL . PHP_EOL;
    140141        $content .= 'PHP VERSION: ' . phpversion() . PHP_EOL . PHP_EOL;
    141         $content .= 'WordPress VERSION: ' . get_bloginfo('version') . PHP_EOL . PHP_EOL;
    142 
     142        $content .= 'WordPress VERSION: ' . get_bloginfo('version') . PHP_EOL . PHP_EOL . PHP_EOL;
     143        $content .= 'ERROR LOG: ' . PHP_EOL . $error_log . PHP_EOL . PHP_EOL;
    143144        return $content;
    144145    }
  • quickcreator/trunk/includes/quickcreator/class-content-importer.php

    r3158668 r3221380  
    4848    public function save_data_into_database($content, $args = array())
    4949    {
    50         $user = get_users()[0];
     50        $user_args  = array(
     51            'role'    => 'Administrator',
     52            'orderby' => 'user_nicename',
     53            'order'   => 'ASC',
     54        );
     55        $user = get_users($user_args)[0];
    5156        wp_set_current_user($user->ID, $user->data->display_name);
    5257        if ('elementor' === $args['filter']) {
     
    109114
    110115        $this->resove_post_meta_after_insert_post($post_id, $args);
    111 
    112         if ('elementor' === $args['filter']) {
    113             $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php');
    114             if ($if_elementor_is_active) {
    115                 \Elementor\Plugin::$instance->documents->ajax_save([
    116                     'editor_post_id' => $post_id,
    117                     'status' => $data["post_status"],
    118                     'elements' => $content['elements'],
    119                     'settings' => $content['settings'],
    120                 ]);
    121                 if (isset($args['meta_input']) && isset($args['meta_input']['_elementor_template_type']) && "kit" === $args['meta_input']['_elementor_template_type']) {
    122                     $kits_manager = \Elementor\Plugin::$instance->kits_manager;
    123                     update_option($kits_manager::OPTION_PREVIOUS, $kits_manager->get_active_id());
    124                     update_option($kits_manager::OPTION_ACTIVE, $post_id);
     116        if (! is_wp_error($post_id)) {
     117            if ('elementor' === $args['filter']) {
     118                $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php');
     119                if ($if_elementor_is_active) {
     120                    \Elementor\Plugin::$instance->documents->ajax_save([
     121                        'editor_post_id' => $post_id,
     122                        'status' => $data["post_status"],
     123                        'elements' => $content['elements'],
     124                        'settings' => $content['settings'],
     125                    ]);
     126                    if (isset($args['meta_input']) && isset($args['meta_input']['_elementor_template_type']) && "kit" === $args['meta_input']['_elementor_template_type']) {
     127                        $kits_manager = \Elementor\Plugin::$instance->kits_manager;
     128                        update_option($kits_manager::OPTION_PREVIOUS, $kits_manager->get_active_id());
     129                        update_option($kits_manager::OPTION_ACTIVE, $post_id);
     130                    }
    125131                }
    126             }
    127         } else {
    128             $this->content_parser->run_after_post_insert_actions($post_id);
     132            } else {
     133                $this->content_parser->run_after_post_insert_actions($post_id);
     134            }
    129135        }
    130136        return $post_id;
  • quickcreator/trunk/includes/quickcreator/class-quickcreator.php

    r3173581 r3221380  
    106106        add_action('wp_ajax_disconnect_quickcreator', array($this, 'disconnect_quickcreator_from_wp'));
    107107        add_action('wp_ajax_check_quickcreator_connection_status', array($this, 'check_connection_status'));
     108        add_filter("rest_request_after_callbacks", array($this, 'register_connection_api_filter'), 10, 3);
    108109    }
    109110    /**
     
    136137    //  return $this->quickcreator_privacy_policy;
    137138    // }
     139
     140    public function register_connection_api_filter($response, $handler, $request)
     141    {
     142        // check quickcreatorblog/v1 request
     143        if (strpos($request->get_route(), 'quickcreatorblog/v1') === false) {
     144            $log_data = [];
     145            if (is_wp_error($response)) {
     146                $log_data = [
     147                    'error' => $response->get_error_message(),
     148                    'request' => [
     149                        'route' => $request->get_route(),
     150                        'method' => $request->get_method(),
     151                        'params' => $request->get_params(),
     152                    ]
     153                ];
     154            } else if ($response instanceof WP_REST_Response) {
     155                if ($response->is_error()) {
     156                    $log_data = [
     157                        'error' => 'Response contains an error.',
     158                        'request' => [
     159                            'route' => $request->get_route(),
     160                            'method' => $request->get_method(),
     161                            'params' => $request->get_params(),
     162                        ],
     163                        'response' => $response->get_data(),
     164                    ];
     165                }
     166            }
     167            if (!empty($log_data)) {
     168                file_put_contents(
     169                    Quickcreator()->get_basedir() . '/error.log',
     170                    date('Y-m-d H:i:s') . ' - ' . print_r($log_data, true) . "\n",
     171                    FILE_APPEND
     172                );
     173            }
     174        }
     175
     176        return $response;
     177    }
    138178
    139179    /**
     
    782822    public function quickcreator_import_post($request)
    783823    {
    784         $args    = array();
    785         $content = $request->get_param('content');
    786 
    787         if (empty($content) || '' === $content || (is_string($content) && strlen($content) < 1)) {
     824        try {
     825            $args    = array();
     826            $content = $request->get_param('content');
     827
     828            if (empty($content) || '' === $content || (is_string($content) && strlen($content) < 1)) {
     829                return new WP_REST_Response(
     830                    array(
     831                        'error' => __('Cannot add post with empty content.', 'quickcreator'),
     832                    ),
     833                    422
     834                );
     835            }
     836
     837            // $metadata = $request->get_param( 'metadata' );
     838
     839            // Optional params.
     840            $args['post_id']          = $request->get_param('post_id');
     841            $args['post_title']       = $request->get_param('title') ?? '';
     842            $args['permalink_hash']   = $request->get_param('slug');
     843            $args['post_category']    = $request->get_param('categories') ?? array();
     844            $args['post_tags']        = $request->get_param('tags') ?? array();
     845            $args['post_author']      = $request->get_param('author') ?? '';
     846            $args['post_excerpt']     = $request->get_param('excerpt') ?? '';
     847            $args['meta_title']       = $request->get_param('meta_title');
     848            $args['meta_description'] = $request->get_param('meta_description');
     849            $args['post_status']      = $request->get_param('status');
     850            $args['post_type']        = $request->get_param('post_type') ?? '';
     851            $args["meta_input"]       = $request->get_param('meta') ?? array();
     852            $args['post_parent']      = $request->get_param('post_parent') ?? 0;
     853            $args['filter']           = $request->get_param('filter') ?? '';
     854            $featured_image = $request->get_param('featured_image');
     855            if ($featured_image !== null && $featured_image !== '') {
     856                $args['featured_image']   = $featured_image; # quickcreator_sync_image_to_media_library($request->get_param( 'featured_image' ));
     857            }
     858
     859            // $args['post_date']        = $metadata['publicationDate'] ?? '';
     860            // $args['tags_input']       = $request->get_param( 'tags_input' );
     861
     862            $args['post_name']        = $request->get_param('name');
     863            // $args['draft_id']         = $request->get_param( 'draft_id' );
     864            // $args['keywords']         = $request->get_param( 'keywords' );
     865            // $args['location']         = $request->get_param( 'location' );
     866
     867            $modification_date = gmdate('Y-m-d');
     868            if (isset($args['post_id'])) {
     869                $modification_date = get_the_modified_time('Y-m-d', $args['post_id']);
     870            }
     871
     872            $post_id = $this->content_importer->save_data_into_database($content, $args);
     873
     874            if (! is_wp_error($post_id)) {
     875                return new WP_REST_Response(
     876                    array(
     877                        'post_id'       => $post_id,
     878                        'edit_post_url' => $this->get_edit_post_link($post_id, 'notdisplay'),
     879                        'post_url'      => get_permalink($post_id),
     880                        'post_status'   => get_post_status($post_id),
     881                        'modified_at'   => $modification_date,
     882                        'url'           => site_url(),
     883                    )
     884                );
     885            } else {
     886                return new WP_REST_Response(
     887                    array(
     888                        'error'            => __('There was an error on post adding', 'quickcreator'),
     889                        'wp_error_message' => $post_id->get_error_message(),
     890                    ),
     891                    403
     892                );
     893            }
     894        } catch (\Exception $e) {
    788895            return new WP_REST_Response(
    789896                array(
    790                     'error' => __('Cannot add post with empty content.', 'quickcreator'),
    791                 ),
    792                 422
    793             );
    794         }
    795 
    796         // $metadata = $request->get_param( 'metadata' );
    797 
    798         // Optional params.
    799         $args['post_id']          = $request->get_param('post_id');
    800         $args['post_title']       = $request->get_param('title') ?? '';
    801         $args['permalink_hash']   = $request->get_param('slug');
    802         $args['post_category']    = $request->get_param('categories') ?? array();
    803         $args['post_tags']        = $request->get_param('tags') ?? array();
    804         $args['post_author']      = $request->get_param('author') ?? '';
    805         $args['post_excerpt']     = $request->get_param('excerpt') ?? '';
    806         $args['meta_title']       = $request->get_param('meta_title');
    807         $args['meta_description'] = $request->get_param('meta_description');
    808         $args['post_status']      = $request->get_param('status');
    809         $args['post_type']        = $request->get_param('post_type') ?? '';
    810         $args["meta_input"]       = $request->get_param('meta') ?? array();
    811         $args['post_parent']      = $request->get_param('post_parent') ?? 0;
    812         $args['filter']           = $request->get_param('filter') ?? '';
    813         $featured_image = $request->get_param('featured_image');
    814         if ($featured_image !== null && $featured_image !== '') {
    815             $args['featured_image']   = $featured_image; # quickcreator_sync_image_to_media_library($request->get_param( 'featured_image' ));
    816         }
    817 
    818         // $args['post_date']        = $metadata['publicationDate'] ?? '';
    819         // $args['tags_input']       = $request->get_param( 'tags_input' );
    820 
    821         $args['post_name']        = $request->get_param('name');
    822         // $args['draft_id']         = $request->get_param( 'draft_id' );
    823         // $args['keywords']         = $request->get_param( 'keywords' );
    824         // $args['location']         = $request->get_param( 'location' );
    825 
    826         $modification_date = gmdate('Y-m-d');
    827         if (isset($args['post_id'])) {
    828             $modification_date = get_the_modified_time('Y-m-d', $args['post_id']);
    829         }
    830 
    831         $post_id = $this->content_importer->save_data_into_database($content, $args);
    832 
    833         if (! is_wp_error($post_id)) {
    834             return new WP_REST_Response(
    835                 array(
    836                     'post_id'       => $post_id,
    837                     'edit_post_url' => $this->get_edit_post_link($post_id, 'notdisplay'),
    838                     'post_url'      => get_permalink($post_id),
    839                     'post_status'   => get_post_status($post_id),
    840                     'modified_at'   => $modification_date,
    841                     'url'           => site_url(),
    842                 )
    843             );
    844         } else {
    845             return new WP_REST_Response(
    846                 array(
    847                     'error'            => __('There was an error on post adding', 'quickcreator'),
    848                     'wp_error_message' => $post_id->get_error_message(),
     897                    'error' => $e->getMessage(),
    849898                ),
    850899                403
     
    13481397    public function site_builder_site_init($request)
    13491398    {
    1350         $user = get_users()[0];
     1399        $user_args  = array(
     1400            'role'    => 'Administrator',
     1401            'orderby' => 'user_nicename',
     1402            'order'   => 'ASC',
     1403        );
     1404        $user = get_users($user_args)[0];
    13511405        wp_set_current_user($user->ID, $user->data->display_name);
    13521406        $is_astra_based_theme = defined('ASTRA_THEME_SETTINGS');
  • quickcreator/trunk/quickcreator.php

    r3173581 r3221380  
    44 * Plugin URI: https://wordpress.org/plugins/quickcreator/
    55 * Description: Create post with Quickcreator in WordPress
    6  * Version: 0.1.1
     6 * Version: 0.1.2
    77 * Author: Quickcreator
    88 * Author URI: https://quickcreator.io
     
    2222
    2323if ( ! defined( 'QUICKCREATOR_BLOG_VERSION' ) ) {
    24     define( 'QUICKCREATOR_BLOG_VERSION', '0.1.1' );
     24    define( 'QUICKCREATOR_BLOG_VERSION', '0.1.2' );
    2525}
    2626
  • quickcreator/trunk/readme.txt

    r3173581 r3221380  
    55Requires PHP: 7.4
    66Tested up to: 6.6
    7 Stable tag: 0.1.1
     7Stable tag: 0.1.2
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.