Plugin Directory

Changeset 2411907


Ignore:
Timestamp:
11/03/2020 03:37:53 PM (5 years ago)
Author:
milanmk
Message:

Release 1.17.0

Location:
schema-app-structured-data-for-schemaorg
Files:
28 added
9 edited

Legend:

Unmodified
Added
Removed
  • schema-app-structured-data-for-schemaorg/trunk/hunch-schema.php

    r2367347 r2411907  
    55 * Plugin URI: http://www.schemaapp.com
    66 * Description: This plugin adds http://schema.org structured data to your website
    7  * Version: 1.16.2
     7 * Version: 1.17.0
    88 * Author: Hunch Manifest
    99 * Author URI: https://www.hunchmanifest.com
     
    3333    $HunchSchemaFront = new SchemaFront();
    3434}
     35
     36
     37$hunch_schema_cron = new SchemaCron();
  • schema-app-structured-data-for-schemaorg/trunk/lib/HunchSchema/Post.php

    r2344163 r2411907  
    4444    public function getBreadcrumb( $Pretty = false ) {
    4545        $position                           = 1;
    46         $permalink_structure                = get_option( 'permalink_structure' );
    4746        $this->SchemaBreadcrumb['@context'] = 'https://schema.org/';
    4847        $this->SchemaBreadcrumb['@type']    = 'BreadcrumbList';
    4948
    50         if ( $permalink_structure ) {
     49        if ( get_option( 'permalink_structure' ) ) {
    5150            $permalink_host         = stristr( get_permalink(), parse_url( get_permalink(), PHP_URL_PATH ), true );
    5251            $permalink_path_parts   = array_values( array_filter( explode( '/', parse_url( get_permalink(), PHP_URL_PATH ) ) ) );
  • schema-app-structured-data-for-schemaorg/trunk/lib/HunchSchema/Thing.php

    r2344163 r2411907  
    7474
    7575    public static function getPermalink() {
    76         $permalink = '';
    77 
    78         if ( is_author() ) {
    79             $permalink = get_author_posts_url( get_the_author_meta( 'ID' ) );
    80         } elseif ( is_category() ) {
    81             $permalink = get_category_link(get_query_var( 'cat' ) );
    82         } elseif ( is_singular() ) {
    83             $permalink = get_permalink();
    84         } elseif ( is_front_page() && is_home() || is_front_page() ) {
    85             $permalink = home_url();
    86         } elseif ( is_home() ) {
    87             $permalink = get_permalink( get_option( 'page_for_posts' ) );
     76        global $wp;
     77
     78        // Using home_url instead of site_url as WP directory can be different from homepage
     79        $permalink = home_url( '/' );
     80
     81        if ( $wp->did_permalink ) {
     82        // Pretty permalink
     83            if ( $wp->request ) {
     84            // Non homepage request
     85                if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
     86                // Permalink with directory structure; ends with "/"
     87                    $permalink = trailingslashit( home_url( $wp->request ) );
     88                } else {
     89                    $permalink = home_url( $wp->request );
     90                }
     91            }
     92        } else {
     93        // Plain permalink
     94            if ( $wp->query_string ) {
     95            // Non homepage request
     96                if ( count( $wp->query_vars ) > 1 ) {
     97                // Remove unnecessary query variables
     98                    $permalink = home_url( '/' ) . '?' . urldecode( strstr( $wp->query_string, '&', true ) );
     99                } else {
     100                    $permalink = home_url( '/' ) . '?' . urldecode( $wp->query_string );
     101                }
     102            }
    88103        }
    89104
     
    324339        global $post;
    325340
    326         $featured_video_url = '';
     341        $post_content       = apply_filters( 'the_content', $post->post_content );
     342        $featured_video_url = '';
    327343
    328344        if ( function_exists( 'get_the_post_video_url' ) ) {
     
    331347
    332348        $videos = array();
    333         $urls = wp_extract_urls( $post->post_content . $featured_video_url );
     349        $urls = wp_extract_urls( $post_content . $featured_video_url );
    334350
    335351        if ( count( $urls ) ) {
    336352            foreach ( $urls as $url ) {
    337                 $url = trim( $url );
    338 
    339353                if ( filter_var( $url, FILTER_VALIDATE_URL ) != false  &&  stripos( $url, 'vimeo.com' ) !== false ) {
    340354                    $videos[] = $this->get_vimeo_video( $url );
     
    344358
    345359
    346         $youtube_video_ids = $this->get_youtube_video_ids( $post->post_content . $featured_video_url );
     360        $youtube_video_ids = $this->get_youtube_video_ids( $post_content . $featured_video_url );
    347361
    348362        if ( count( $youtube_video_ids ) ) {
     
    388402    protected function get_youtube_video_ids( $string ) {
    389403        if ( ! empty( $string ) ) {
    390             // https?://(?:[0-9A-Z-]+\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com\S*?[^\w\s-] )([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:[\'"][^<>]*>|</a>) )[?=&+%\w.-]*
    391             // https?://(?:[0-9A-Z-]+\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com\S*?[^\w\s-] )([\w-]{11})(?=[^\w-]|$)[?=&+%\w.-]*
    392             preg_match_all( '~https?://(?:www\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com\S*?[^\w\s-] )([\w-]{11})(?=[^\w-]|$)[?=&+%\w.-]*~im', $string, $matches );
     404            // https?://(?:[0-9A-Z-]+\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com\S*?[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:[\'"][^<>]*>|</a>))[?=&+%\w.-]*
     405            // https?://(?:[0-9A-Z-]+\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com\S*?[^\w\s-])([\w-]{11})(?=[^\w-]|$)[?=&+%\w.-]*
     406            preg_match_all( '~https?://(?:www\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com\S*?[^\w\s-])([\w-]{11})(?=[^\w-]|$)[?=&+%\w.-]*~im', $string, $matches );
    393407
    394408            if ( isset( $matches[1] ) && count( $matches[1] ) ) {
    395                 return $matches[1];
     409                return array_unique( $matches[1] );
    396410            }
    397411        }
  • schema-app-structured-data-for-schemaorg/trunk/lib/SchemaEditor.php

    r2366035 r2411907  
    179179                        </td>
    180180                        <td>
    181                             <?php print $schema_server->page_url; ?>
     181                            <a href="<?php print $schema_server->resource_url; ?>" target="_blank"><?php print $schema_server->resource_url; ?></a>
    182182                        </td>
    183183                    </tr>
  • schema-app-structured-data-for-schemaorg/trunk/lib/SchemaFront.php

    r2366035 r2411907  
    248248            {
    249249                if ( ! empty( $this->Settings['Debug'] ) && is_user_logged_in() ) {
    250                     printf( "\n<!--\nURL: %s\nTransient: %s\nTransient Id: %s\nData Sources:\n", $SchemaServer->page_url, ( $SchemaServer->transient ? 'Yes' : 'No' ), $SchemaServer->transient_id );
     250                    printf( "\n<!--\nURL: %s\nTransient: %s\nTransient Id: %s\nData Sources:\n", $SchemaServer->resource_url, ( $SchemaServer->transient ? 'Yes' : 'No' ), $SchemaServer->transient_id );
    251251
    252252                    foreach ( $SchemaServer->data_sources as $data_source ) {
     
    360360                'id'    => 'Hunch-Schema',
    361361                'title' => 'Test Schema',
    362                 'href'  => 'https://developers.google.com/structured-data/testing-tool?url=' . urlencode( $Permalink ),
     362                'href'  => 'https://search.google.com/structured-data/testing-tool#url=' . urlencode( $Permalink ),
    363363                'meta'  => array
    364364                (
  • schema-app-structured-data-for-schemaorg/trunk/lib/SchemaServer.php

    r2367347 r2411907  
    44
    55/**
    6  * Handle interactions with the http://app.schemaapp,com server
     6 * Handle interactions with the http://app.schemaapp.com server
    77 *
    88 * @author Mark van Berkel
     
    1212        private $options;
    1313        private $resource;
     14        public $resource_url    = '';
    1415        public $transient_id    = '';
    1516        public $transient       = false;
    16         public $page_url        = '';
    1717        public $data_sources    = array();
    1818
    1919        const EDITOR = "https://app.schemaapp.com/editor";
    2020
    21         public function __construct($uri = "") {
     21
     22        public function __construct( $uri = '' ) {
    2223            $this->options = get_option( 'schema_option_name' );
    2324
    2425            if ( ! empty( $uri ) ) {
    2526                $this->resource = $uri;
    26             } elseif ( is_singular() ) {
    27                 $this->resource = get_permalink();
    2827            } else {
    29                 $permalink_structure = get_option( 'permalink_structure' );
    30 
    31                 // If pretty permalink then remove query string from URL
    32                 if ( $permalink_structure ) {
    33                     $request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    34                
    35                     $this->resource = ( is_ssl() ? 'https' : 'http' ) . "://{$_SERVER['HTTP_HOST']}{$request_uri}";
    36                 } else {
    37                     $this->resource = ( is_ssl() ? 'https' : 'http' ) . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    38                 }
     28                $this->resource = HunchSchema_Thing::getPermalink();
    3929            }
    4030        }
    4131
    42         /**
    43          * Get Resource JSON_LD content
    44          *
    45          * @param type $uri
    46          * @return string
    47          */
    48         public function getResource($uri = '', $pretty = false) {
     32
     33        /**
     34         * Get a resource's schema data from transient cache.
     35         *
     36         * @uses get_transient()
     37         * @param string $uri Post/Page permalink.
     38         * @param bool $pretty Whether to prettify JSON data or not.
     39         * @return string JSON encoded schema markup.
     40         */
     41        public function getResource( $uri = '', $pretty = false ) {
    4942            if ( empty( $this->options['graph_uri'] ) ) {
    5043                return '';
     
    6457
    6558            $account_id         = str_replace( array( 'http://schemaapp.com/db/', 'https://schemaapp.com/db/' ), '', $this->options['graph_uri'] );
    66             $resource           = $this->page_url = urldecode( $resource ); // Decode accent characters
    67             $resource_hash      = trim( base64_encode( $resource ), '=' );
    68             $this->data_sources = array( "https://data.schemaapp.com/{$account_id}/{$resource_hash}" );
    69             $this->transient_id = 'HunchSchema-Markup-' . md5( $resource );
     59            $this->resource_url = urldecode( $resource ); // Decode accent characters
     60            $this->data_sources = array( "https://data.schemaapp.com/{$account_id}/" . trim( base64_encode( $this->resource_url ), '=' ) );
     61            $this->transient_id = 'HunchSchema-Markup-' . md5( $this->resource_url );
    7062            $transient          = get_transient( $this->transient_id );
    7163
    7264
    73             $data_sources_additional = ( array ) apply_filters( 'hunch_schema_markup_api_data_source', $account_id, $resource );
     65            $data_sources_additional = ( array ) apply_filters( 'hunch_schema_markup_api_data_source', $account_id, $this->resource_url );
    7466
    7567            if ( ! empty( $data_sources_additional ) ) {
     
    8678                $this->transient = true;
    8779
     80                if ( $pretty && version_compare( phpversion(), '5.4.0', '>=' ) ) {
     81                    $transient = json_encode( json_decode( $transient ), JSON_PRETTY_PRINT );
     82                }
     83
    8884                return $transient;
    8985            }
    9086
    9187
    92             $schemadata = '';
     88            // Check to avoid triggering of schedule event when request is originated from WP Cron
     89            if ( ! defined( 'DOING_CRON' ) || ! DOING_CRON ) {
     90                // Delegate API schema fetching to cron and pass requested resource as argument
     91                wp_schedule_single_event( time(), 'schema_app_cron_resource_from_api', array( $resource ) );
     92            }
     93
     94
     95            return '';
     96        }
     97
     98
     99        /**
     100         * Get a resource's schema data through API.
     101         *
     102         * @uses SchemaServer->getResource()
     103         * @uses wp_remote_get()
     104         * @uses set_transient()
     105         * @param string $uri Post/Page permalink.
     106         * @return string JSON encoded schema markup.
     107         */
     108        public function getResourceFromAPI( $uri = '' ) {
     109            // Prepare necessary resource attributes
     110            $this->getResource( $uri );
     111
     112            $schema_data = '';
    93113
    94114            foreach ( $this->data_sources as $data_source ) {
     
    96116
    97117                if ( ! is_wp_error( $remote_response ) && wp_remote_retrieve_response_code( $remote_response ) == 200 && ! empty( wp_remote_retrieve_body( $remote_response ) ) && wp_remote_retrieve_body( $remote_response ) !== 'null' ) {
    98                     $schemadata = wp_remote_retrieve_body( $remote_response );
     118                    $schema_data = wp_remote_retrieve_body( $remote_response );
    99119
    100120                    // First delete then set; set method only updates expiry time if transient already exists
    101121                    delete_transient( $this->transient_id );
    102                     set_transient( $this->transient_id, $schemadata, 86400 );
    103 
    104                     if ( $pretty && version_compare( phpversion(), '5.4.0', '>=' ) ) {
    105                         $schemadata = json_encode( json_decode( $schemadata ), JSON_PRETTY_PRINT );
    106                     }
     122                    set_transient( $this->transient_id, $schema_data, 86400 ); // Expiry 1 day
    107123
    108124                    break;
     
    110126            }
    111127
    112             return $schemadata;
     128            return $schema_data;
    113129        }
    114130
     
    154170                return array( true, $response_data->status );
    155171            } else {
    156                 return array( false, $response_data->error );
     172                return array( false, "{$response_data->status} : {$response_data->error}" );
    157173            }
    158174        }
  • schema-app-structured-data-for-schemaorg/trunk/lib/SchemaSettings.php

    r2344163 r2411907  
    4747    function PluginActivate()
    4848    {
     49        if ( ! current_user_can( 'activate_plugins' ) ) {
     50            return;
     51        }
     52
    4953        $Settings = get_option( 'schema_option_name' );
    5054
     
    662666
    663667
     668        print '<h3>Scheduled resources from API</h3>';
     669
     670        if ( ! empty( _get_cron_array() ) ) {
     671            print '<ol>';
     672
     673            foreach ( _get_cron_array() as $item ) {
     674                foreach ( $item as $key => $value ) {
     675                    if ( $key != 'schema_app_cron_resource_from_api' ) {
     676                        continue 2;
     677                    }
     678
     679                    $event = reset( $value );
     680                    $argument = reset( $event['args'] );
     681                }
     682
     683                printf( '<li> <p>%s</p> </li>', $argument );
     684            }
     685
     686            print '</ol>';
     687        } else {
     688            print '<p>No scheduled items found.</p>';
     689        }
     690
     691
    664692        $transients = $wpdb->get_col( "SELECT DISTINCT option_name  FROM {$wpdb->options}  WHERE option_name LIKE '_transient_HunchSchema-Markup-%'" );
    665693
    666694
    667         print '<h3>Cached Schema Items</h3>';
     695        print '<br><br> <hr> <h3>Cached schema data</h3>';
    668696
    669697        if ( $transients ) {
     
    685713
    686714
    687         print '<br><br> <hr> <h3>Cache REST API Log</h3>';
     715        print '<br><br> <hr> <h3>Cache REST API log</h3>';
    688716
    689717        if ( file_exists( $rest_api_cache_log_file ) ) {
  • schema-app-structured-data-for-schemaorg/trunk/lib/classmap.php

    r1976919 r2411907  
    1313require_once $baseDir . 'SchemaSettings.php';
    1414require_once $baseDir . 'SchemaFront.php';
     15require_once $baseDir . 'SchemaCron.php';
    1516require_once $baseDir . $schemaDir . 'Thing.php';
    1617require_once $baseDir . $schemaDir . 'Page.php';
  • schema-app-structured-data-for-schemaorg/trunk/readme.txt

    r2367347 r2411907  
    99Requires PHP: 5.4
    1010Tested up to: 5.5
    11 Stable tag: 1.16.2
     11Stable tag: 1.17.0
    1212License: GPL2
    1313License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7575
    7676== Frequently Asked Questions ==
    77 You\'ll find the [FAQ on SchemaApp.com] (https://www.schemaapp.com/wordpress/faq/).
     77
     78You'll find the [FAQ on SchemaApp.com](https://www.schemaapp.com/solutions/wordpress-plugin/faq/).
    7879
    7980== Screenshots ==
     
    8687
    8788== Changelog ==
     89
     90= 1.17.0 =
     91- Feature, Schema data fetching from API is now handled by WP Cron to improve page load time
     92- Improve, License check message for WooCommerce plugin
     93- Improve, Updated get permalink routine to use $wp for detecting correct urls
     94- Improve, Optimized video parsing routine
    8895
    8996= 1.16.2 =
     
    426433== Upgrade Notice ==
    427434
    428 = 1.16.2 =
    429 - Fix archive permalinks for Schema API resource
     435= 1.17.0 =
     436 - Schema data fetching from API is now handled by WP Cron, updated get permalink routine for detecting correct urls
Note: See TracChangeset for help on using the changeset viewer.