Plugin Directory

Changeset 3199387


Ignore:
Timestamp:
11/29/2024 11:27:25 AM (16 months ago)
Author:
xmic
Message:

Update to version 1.10.0 from GitHub

Location:
timestamps
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • timestamps/tags/1.10.0/includes/classes/Feature/Timestamp/Timestamp.php

    r3129719 r3199387  
    7272        add_filter( 'is_protected_meta', array( $this, 'is_protected_meta' ), 10, 3 );
    7373        add_shortcode( 'timestamps', array( $this, 'shortcode' ) );
     74
     75        // Oxygen Builder.
     76        add_action( 'save_post', array( $this, 'save_post_meta_oxygenbuilder' ), 10, 2 );
    7477    }
    7578
     
    406409
    407410    /**
     411     * Save post meta data during an Oxygen Builder request.
     412     *
     413     * @param int     $post_id The post ID.
     414     * @param WP_Post $post The post object.
     415     * @since 1.10.0
     416     * @since Oxygen Builder 4.9
     417     * @return void
     418     * @throws \Exception If an error occurs during the process.
     419     */
     420    public function save_post_meta_oxygenbuilder( $post_id, $post ) {
     421
     422        if ( ! isset( $_GET['action'] ) || $_GET['action'] !== 'ct_save_components_tree' ) {
     423            return;
     424        }
     425
     426        $nonce   = isset( $_REQUEST['nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ) : '';
     427        $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
     428
     429        // Check nonce.
     430        if ( ! isset( $nonce, $post_id ) || ! wp_verify_nonce( $nonce, 'oxygen-nonce-' . $post_id ) ) {
     431            // This nonce is not valid.
     432            die( 'Security check' );
     433        }
     434
     435        // Check if user can edit this post.
     436        if ( ! oxygen_vsb_current_user_can_access() ) {
     437            die( 'Security check' );
     438        }
     439
     440        $sdcom_timestamp_post = get_post_meta( $post_id, 'sdcom_timestamp_post', true );
     441
     442        $_ct_builder_json = get_post_meta( $post_id, '_ct_builder_json', true );
     443
     444        if ( ! empty( $sdcom_timestamp_post ) && ! empty( $_ct_builder_json ) ) {
     445            try {
     446                update_post_meta( $post_id, 'sdcom_timestamp_post', true );
     447
     448                $create_certificate = $this->create_certificate_post( $post, $_ct_builder_json );
     449
     450                // Handle the case where the method returned false.
     451                if ( $create_certificate === false ) {
     452                    throw new \Exception( 'Create certificate failed.' );
     453                }
     454
     455                $certificate_id = ! empty( $create_certificate->{'certificate'}->{'id'} ) ? $create_certificate->{'certificate'}->{'id'} : '';
     456
     457                // Handle the case where the certificate id is empty.
     458                if ( empty( $certificate_id ) ) {
     459                    throw new \Exception( 'Certificate id is empty.' );
     460                }
     461
     462                $update_certificate = $this->update_certificate_post( $post, $certificate_id, $_ct_builder_json );
     463
     464                // Handle the case where the method returned false.
     465                if ( $update_certificate === false ) {
     466                    throw new \Exception( 'Update certificate failed.' );
     467                }
     468
     469                // Bail early if the certificate id is empty.
     470                if ( empty( $certificate_id ) ) {
     471                    throw new \Exception( 'Certificate id is empty.' );
     472                }
     473
     474                // Update the post meta with the new certificate id.
     475                update_post_meta( $post_id, 'sdcom_previous_certificate_id', $certificate_id );
     476            } catch ( \Exception $e ) {
     477                // Handle the exception
     478                error_log( 'An error occurred: ' . $e->getMessage() );
     479            }
     480        } else {
     481            delete_post_meta( $post_id, 'sdcom_timestamp_post' );
     482        }
     483    }
     484
     485    /**
    408486     * Creates a certificate for a post.
    409487     *
    410488     * @param WP_Post $post The post to create a certificate for.
     489     * @param string  $post_content The post content. If empty, the post content will be used.
    411490     * @return object|false The data returned by the API on success, or false on failure.
    412491     * @throws \Throwable If an exception occurs during the process.
    413492     * @throws \Exception If the options, post content, or API key is empty.
    414493     */
    415     private function create_certificate_post( $post ) {
     494    private function create_certificate_post( $post, $post_content = null ) {
    416495        try {
    417496            $post_id                       = $post->ID;
    418             $post_content                  = $post->post_content;
     497            $post_content                  = ! empty( $post_content ) ? $post_content : $post->post_content;
    419498            $sdcom_timestamps              = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    420499            $sdcom_previous_certificate_id = get_post_meta( $post_id, 'sdcom_previous_certificate_id', true );
     
    508587     * @param WP_Post $post The post to update a certificate for.
    509588     * @param string  $certificate_id The id of the certificate to update.
     589     * @param string  $post_content The post content. If empty, the post content will be used.
    510590     * @return object|false The data returned by the API on success, or false on failure.
    511591     * @throws \Exception If the certificate id, options, post content, or API key is empty.
    512592     * @throws \Throwable If an exception occurs during the process.
    513593     */
    514     private function update_certificate_post( $post, $certificate_id ) {
     594    private function update_certificate_post( $post, $certificate_id, $post_content = null ) {
    515595        try {
    516             $post_content     = $post->post_content;
     596            $post_content     = ! empty( $post_content ) ? $post_content : $post->post_content;
    517597            $sdcom_timestamps = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    518598
  • timestamps/tags/1.10.0/package-lock.json

    r3179723 r3199387  
    11{
    22  "name": "timestamps-plugin",
    3   "version": "1.9.0",
     3  "version": "1.10.0",
    44  "lockfileVersion": 3,
    55  "requires": true,
     
    77    "": {
    88      "name": "timestamps-plugin",
    9       "version": "1.9.0",
     9      "version": "1.10.0",
    1010      "dependencies": {
    1111        "@supabase/supabase-js": "^2.39.3",
  • timestamps/tags/1.10.0/package.json

    r3179723 r3199387  
    11{
    22  "name": "timestamps-plugin",
    3   "version": "1.9.0",
     3  "version": "1.10.0",
    44  "description": "Timestamp your WordPress content to empower your content authenticity and increase user trust with our blockchain timestamping solution.",
    55  "homepage": "https://www.scoredetect.com/",
  • timestamps/tags/1.10.0/readme.txt

    r3179723 r3199387  
    55Tested up to: 6.7
    66Requires PHP: 7.4
    7 Stable tag: 1.9.0
     7Stable tag: 1.10.0
    88License: AGPL-3.0-only
    99License URI: https://spdx.org/licenses/AGPL-3.0-only.html
  • timestamps/tags/1.10.0/timestamps.php

    r3179723 r3199387  
    99 *
    1010 * @link              https://www.scoredetect.com/
    11  * @since             1.9.0
     11 * @since             1.10.0
    1212 * @package           SDCOM_Timestamps
    1313 *
     
    1515 * Plugin Name:       Timestamps
    1616 * Description:       Timestamp your WordPress content to empower your content authenticity and increase user trust. No blockchain skills needed.
    17  * Version:           1.9.0
     17 * Version:           1.10.0
    1818 * Author:            ScoreDetect.com
    1919 * Author URI:        https://www.scoredetect.com/
     
    3434
    3535// Useful global constants.
    36 define( 'SDCOM_TIMESTAMPS_VERSION', '1.9.0' );
     36define( 'SDCOM_TIMESTAMPS_VERSION', '1.10.0' );
    3737define( 'SDCOM_TIMESTAMPS_OPTIONS', 'sdcom_timestamps' );
    3838define( 'SDCOM_TIMESTAMPS_URL', plugin_dir_url( __FILE__ ) );
  • timestamps/trunk/includes/classes/Feature/Timestamp/Timestamp.php

    r3129719 r3199387  
    7272        add_filter( 'is_protected_meta', array( $this, 'is_protected_meta' ), 10, 3 );
    7373        add_shortcode( 'timestamps', array( $this, 'shortcode' ) );
     74
     75        // Oxygen Builder.
     76        add_action( 'save_post', array( $this, 'save_post_meta_oxygenbuilder' ), 10, 2 );
    7477    }
    7578
     
    406409
    407410    /**
     411     * Save post meta data during an Oxygen Builder request.
     412     *
     413     * @param int     $post_id The post ID.
     414     * @param WP_Post $post The post object.
     415     * @since 1.10.0
     416     * @since Oxygen Builder 4.9
     417     * @return void
     418     * @throws \Exception If an error occurs during the process.
     419     */
     420    public function save_post_meta_oxygenbuilder( $post_id, $post ) {
     421
     422        if ( ! isset( $_GET['action'] ) || $_GET['action'] !== 'ct_save_components_tree' ) {
     423            return;
     424        }
     425
     426        $nonce   = isset( $_REQUEST['nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ) : '';
     427        $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
     428
     429        // Check nonce.
     430        if ( ! isset( $nonce, $post_id ) || ! wp_verify_nonce( $nonce, 'oxygen-nonce-' . $post_id ) ) {
     431            // This nonce is not valid.
     432            die( 'Security check' );
     433        }
     434
     435        // Check if user can edit this post.
     436        if ( ! oxygen_vsb_current_user_can_access() ) {
     437            die( 'Security check' );
     438        }
     439
     440        $sdcom_timestamp_post = get_post_meta( $post_id, 'sdcom_timestamp_post', true );
     441
     442        $_ct_builder_json = get_post_meta( $post_id, '_ct_builder_json', true );
     443
     444        if ( ! empty( $sdcom_timestamp_post ) && ! empty( $_ct_builder_json ) ) {
     445            try {
     446                update_post_meta( $post_id, 'sdcom_timestamp_post', true );
     447
     448                $create_certificate = $this->create_certificate_post( $post, $_ct_builder_json );
     449
     450                // Handle the case where the method returned false.
     451                if ( $create_certificate === false ) {
     452                    throw new \Exception( 'Create certificate failed.' );
     453                }
     454
     455                $certificate_id = ! empty( $create_certificate->{'certificate'}->{'id'} ) ? $create_certificate->{'certificate'}->{'id'} : '';
     456
     457                // Handle the case where the certificate id is empty.
     458                if ( empty( $certificate_id ) ) {
     459                    throw new \Exception( 'Certificate id is empty.' );
     460                }
     461
     462                $update_certificate = $this->update_certificate_post( $post, $certificate_id, $_ct_builder_json );
     463
     464                // Handle the case where the method returned false.
     465                if ( $update_certificate === false ) {
     466                    throw new \Exception( 'Update certificate failed.' );
     467                }
     468
     469                // Bail early if the certificate id is empty.
     470                if ( empty( $certificate_id ) ) {
     471                    throw new \Exception( 'Certificate id is empty.' );
     472                }
     473
     474                // Update the post meta with the new certificate id.
     475                update_post_meta( $post_id, 'sdcom_previous_certificate_id', $certificate_id );
     476            } catch ( \Exception $e ) {
     477                // Handle the exception
     478                error_log( 'An error occurred: ' . $e->getMessage() );
     479            }
     480        } else {
     481            delete_post_meta( $post_id, 'sdcom_timestamp_post' );
     482        }
     483    }
     484
     485    /**
    408486     * Creates a certificate for a post.
    409487     *
    410488     * @param WP_Post $post The post to create a certificate for.
     489     * @param string  $post_content The post content. If empty, the post content will be used.
    411490     * @return object|false The data returned by the API on success, or false on failure.
    412491     * @throws \Throwable If an exception occurs during the process.
    413492     * @throws \Exception If the options, post content, or API key is empty.
    414493     */
    415     private function create_certificate_post( $post ) {
     494    private function create_certificate_post( $post, $post_content = null ) {
    416495        try {
    417496            $post_id                       = $post->ID;
    418             $post_content                  = $post->post_content;
     497            $post_content                  = ! empty( $post_content ) ? $post_content : $post->post_content;
    419498            $sdcom_timestamps              = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    420499            $sdcom_previous_certificate_id = get_post_meta( $post_id, 'sdcom_previous_certificate_id', true );
     
    508587     * @param WP_Post $post The post to update a certificate for.
    509588     * @param string  $certificate_id The id of the certificate to update.
     589     * @param string  $post_content The post content. If empty, the post content will be used.
    510590     * @return object|false The data returned by the API on success, or false on failure.
    511591     * @throws \Exception If the certificate id, options, post content, or API key is empty.
    512592     * @throws \Throwable If an exception occurs during the process.
    513593     */
    514     private function update_certificate_post( $post, $certificate_id ) {
     594    private function update_certificate_post( $post, $certificate_id, $post_content = null ) {
    515595        try {
    516             $post_content     = $post->post_content;
     596            $post_content     = ! empty( $post_content ) ? $post_content : $post->post_content;
    517597            $sdcom_timestamps = get_option( SDCOM_TIMESTAMPS_OPTIONS );
    518598
  • timestamps/trunk/package-lock.json

    r3179723 r3199387  
    11{
    22  "name": "timestamps-plugin",
    3   "version": "1.9.0",
     3  "version": "1.10.0",
    44  "lockfileVersion": 3,
    55  "requires": true,
     
    77    "": {
    88      "name": "timestamps-plugin",
    9       "version": "1.9.0",
     9      "version": "1.10.0",
    1010      "dependencies": {
    1111        "@supabase/supabase-js": "^2.39.3",
  • timestamps/trunk/package.json

    r3179723 r3199387  
    11{
    22  "name": "timestamps-plugin",
    3   "version": "1.9.0",
     3  "version": "1.10.0",
    44  "description": "Timestamp your WordPress content to empower your content authenticity and increase user trust with our blockchain timestamping solution.",
    55  "homepage": "https://www.scoredetect.com/",
  • timestamps/trunk/readme.txt

    r3179723 r3199387  
    55Tested up to: 6.7
    66Requires PHP: 7.4
    7 Stable tag: 1.9.0
     7Stable tag: 1.10.0
    88License: AGPL-3.0-only
    99License URI: https://spdx.org/licenses/AGPL-3.0-only.html
  • timestamps/trunk/timestamps.php

    r3179723 r3199387  
    99 *
    1010 * @link              https://www.scoredetect.com/
    11  * @since             1.9.0
     11 * @since             1.10.0
    1212 * @package           SDCOM_Timestamps
    1313 *
     
    1515 * Plugin Name:       Timestamps
    1616 * Description:       Timestamp your WordPress content to empower your content authenticity and increase user trust. No blockchain skills needed.
    17  * Version:           1.9.0
     17 * Version:           1.10.0
    1818 * Author:            ScoreDetect.com
    1919 * Author URI:        https://www.scoredetect.com/
     
    3434
    3535// Useful global constants.
    36 define( 'SDCOM_TIMESTAMPS_VERSION', '1.9.0' );
     36define( 'SDCOM_TIMESTAMPS_VERSION', '1.10.0' );
    3737define( 'SDCOM_TIMESTAMPS_OPTIONS', 'sdcom_timestamps' );
    3838define( 'SDCOM_TIMESTAMPS_URL', plugin_dir_url( __FILE__ ) );
Note: See TracChangeset for help on using the changeset viewer.