403Webshell
Server IP : 38.190.208.107  /  Your IP : 216.73.217.169
Web Server : nginx/1.28.1
System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64
User : root ( 0)
PHP Version : 8.2.28
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /www/wwwroot/wp.10/wp-content/plugins/clarity-seo/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/wwwroot/wp.10/wp-content/plugins/clarity-seo/includes/schema.php
<?php

/**

 * Add Schema.org JSON-LD markup

 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

function clarity_seo_add_schema() {

    if ( ! is_singular() ) {

        return;

    }



    global $post;



    // === Per-page values + fallbacks ===

    $meta_description = get_post_meta( $post->ID, '_clarity_seo_meta_description', true );

    $schema_type      = get_post_meta( $post->ID, '_clarity_seo_type', true ) ?: 'WebPage';

    $schema_service   = get_post_meta( $post->ID, '_clarity_seo_service', true );



    if ( empty( $meta_description ) ) {

        $meta_description = wp_trim_words( get_the_excerpt( $post->ID ), 25, '...' );

        if ( empty( $meta_description ) && is_front_page() ) {

            $meta_description = get_bloginfo( 'description' );

        }

    }



    if ( empty( $schema_service ) ) {

        $schema_service = wp_trim_words( get_the_excerpt( $post->ID ), 50, '...' );

        if ( empty( $schema_service ) ) {

            foreach ( parse_blocks( $post->post_content ) as $block ) {

                if ( isset( $block['blockName'] ) && in_array( $block['blockName'], [ 'core/paragraph', 'core/html' ], true ) ) {

                    $content = $block['innerContent'][0] ?? $block['attrs']['content'] ?? '';

                    if ( $content ) {

                        $schema_service = wp_trim_words( wp_strip_all_tags( $content ), 50, '...' );

                        break;

                    }

                }

            }

        }

        if ( empty( $schema_service ) && is_front_page() ) {

            $schema_service = get_option( 'clarity_seo_organization_description', get_bloginfo( 'description' ) );

        }

    }



    // OG image fallback

    $og_image = get_post_meta( $post->ID, '_clarity_seo_og_image', true );

    if ( ! $og_image && has_post_thumbnail( $post->ID ) ) {

        $og_image = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );

    }



    // === Global options ===

    $logo_url        = get_option( 'clarity_seo_logo_url', '' );

    $org_description = get_option( 'clarity_seo_organization_description', get_bloginfo( 'description' ) );

    $contact_phone   = get_option( 'clarity_seo_contact_phone', '' );

    $contact_type    = get_option( 'clarity_seo_contact_type', 'Customer Service' );

    $social_links    = get_option( 'clarity_seo_social_links', '' );

    $social_array    = array_filter( array_map( 'trim', explode( ',', $social_links ) ) );

    $local_address   = get_option( 'clarity_seo_local_address', '' );

    $local_geo       = get_option( 'clarity_seo_local_geo', '' );

    $geo_array       = $local_geo ? array_filter( array_map( 'trim', explode( ',', $local_geo ) ) ) : [];



    // === Safe JSON-LD output helper ===
$output_schema = function( array $data ) {
    echo '<script type="application/ld+json">' . wp_json_encode( $data ) . "</script>\n";
};


    // === 1. Organization Schema ===

    if ( get_option( 'clarity_seo_enable_organization', 'on' ) === 'on' && ( is_front_page() || get_post_meta( $post->ID, '_clarity_seo_include_org', true ) ) ) {

        $org = [

            '@context' => 'https://schema.org',

            '@type'    => 'Organization',

            'name'     => get_bloginfo( 'name' ),

            'url'      => home_url( '/' ),

        ];



        if ( $logo_url )        $org['logo']       = esc_url_raw( $logo_url );

        if ( $org_description ) $org['description'] = $org_description;

        if ( $contact_phone ) {

            $org['contactPoint'] = [

                '@type'       => 'ContactPoint',

                'telephone'   => $contact_phone,

                'contactType' => $contact_type,

            ];

        }

        if ( $social_array ) {

            $org['sameAs'] = array_map( 'esc_url_raw', $social_array );

        }

        if ( $local_address && $schema_type !== 'LocalBusiness' ) {

            $org['address'] = [

                '@type'         => 'PostalAddress',

                'streetAddress' => $local_address,

            ];

        }

        if ( $geo_array && count( $geo_array ) === 2 ) {

            $org['geo'] = [

                '@type'     => 'GeoCoordinates',

                'latitude'  => $geo_array[0],

                'longitude' => $geo_array[1],

            ];

        }



        $output_schema( $org );

    }



    // === 2. Main Page Schema ===

    $main = [

        '@context'    => 'https://schema.org',

        '@type'       => $schema_type,

        'name'         => get_the_title( $post->ID ),

        'url'         => get_permalink( $post->ID ),

        'description' => $meta_description,

    ];

    if ( $og_image ) {

        $main['image'] = esc_url( $og_image );

    }

    $output_schema( $main );



    // === 3. FAQ Schema ===

    if ( get_option( 'clarity_seo_enable_faq', 'on' ) === 'on' ) {

        $blocks     = parse_blocks( $post->post_content );

        $faq_items  = [];



        for ( $i = 0; $i < count( $blocks ) - 1; $i++ ) {   // ← fixed: ; not ,

            $block = $blocks[ $i ];

            $next  = $blocks[ $i + 1 ] ?? false;



            if ( $block['blockName'] === 'core/heading'

                && in_array( $block['attrs']['level'] ?? 2, [2,3,4], true )

                && $next && $next['blockName'] === 'core/paragraph' ) {



                $question = wp_strip_all_tags( $block['innerContent'][0] ?? '' );

                $answer   = wp_strip_all_tags( $next['innerContent'][0] ?? '' );



                if ( $question && $answer ) {

                    $faq_items[] = [

                        '@type' => 'Question',

                        'name'  => $question,

                        'acceptedAnswer' => [

                            '@type' => 'Answer',

                            'text'  => $answer,

                        ],

                    ];

                    $i++; // skip paragraph block

                }

            }

        }



        if ( $faq_items ) {

            $output_schema( [

                '@context'   => 'https://schema.org',

                '@type'      => 'FAQPage',

                'mainEntity' => $faq_items,

            ] );

        }

    }



    // === 4. VideoObject Schema ===

    if ( get_option( 'clarity_seo_enable_video', 'on' ) === 'on' ) {

        $has_video = false;

        foreach ( parse_blocks( $post->post_content ) as $block ) {

            if ( ( $block['blockName'] ?? '' ) === 'core/video' || strpos( $block['innerHTML'] ?? '', '<video' ) !== false ) {

                $has_video = true;

                break;

            }

        }



        if ( $has_video ) {

            $output_schema( [

                '@context'     => 'https://schema.org',

                '@type'        => 'VideoObject',

                'name'         => get_the_title( $post->ID ),

                'description'  => $meta_description,

                'thumbnailUrl' => $og_image ? esc_url( $og_image ) : '',

                'uploadDate'   => get_the_date( 'c', $post->ID ),

                'contentUrl'   => get_permalink( $post->ID ),

            ] );

        }

    }



    // === 5. Extra schema types from comma list ===

    if ( get_option( 'clarity_seo_enable_multiple', 'on' ) === 'on' && strpos( $schema_type, ',' ) !== false ) {

        $extra_types = array_slice( array_filter( array_map( 'trim', explode( ',', $schema_type ) ) ), 0, 3 );



        foreach ( $extra_types as $type ) {

            $type = trim( $type );

            if ( $type === $schema_type ) {

                continue;

            }

            $output_schema( [

                '@context'    => 'https://schema.org',

                '@type'       => $type,

                'name'        => get_the_title( $post->ID ),

                'url'         => get_permalink( $post->ID ),

                'description' => $meta_description,

            ] );

        }

    }

}

add_action( 'wp_head', 'clarity_seo_add_schema', 1 );

Youez - 2016 - github.com/yon3zu
LinuXploit