Changeset 2411907
- Timestamp:
- 11/03/2020 03:37:53 PM (5 years ago)
- Location:
- schema-app-structured-data-for-schemaorg
- Files:
-
- 28 added
- 9 edited
-
tags/1.17.0 (added)
-
tags/1.17.0/css (added)
-
tags/1.17.0/css/schemaStyle.css (added)
-
tags/1.17.0/data (added)
-
tags/1.17.0/data/tree.jsonld (added)
-
tags/1.17.0/hunch-schema.php (added)
-
tags/1.17.0/js (added)
-
tags/1.17.0/js/schema.js (added)
-
tags/1.17.0/js/schemaAdmin.js (added)
-
tags/1.17.0/js/schemaEditor.js (added)
-
tags/1.17.0/lib (added)
-
tags/1.17.0/lib/HunchSchema (added)
-
tags/1.17.0/lib/HunchSchema/Author.php (added)
-
tags/1.17.0/lib/HunchSchema/Blog.php (added)
-
tags/1.17.0/lib/HunchSchema/Category.php (added)
-
tags/1.17.0/lib/HunchSchema/Page.php (added)
-
tags/1.17.0/lib/HunchSchema/Post.php (added)
-
tags/1.17.0/lib/HunchSchema/Search.php (added)
-
tags/1.17.0/lib/HunchSchema/Tag.php (added)
-
tags/1.17.0/lib/HunchSchema/Thing.php (added)
-
tags/1.17.0/lib/SchemaCron.php (added)
-
tags/1.17.0/lib/SchemaEditor.php (added)
-
tags/1.17.0/lib/SchemaFront.php (added)
-
tags/1.17.0/lib/SchemaServer.php (added)
-
tags/1.17.0/lib/SchemaSettings.php (added)
-
tags/1.17.0/lib/classmap.php (added)
-
tags/1.17.0/readme.txt (added)
-
trunk/hunch-schema.php (modified) (2 diffs)
-
trunk/lib/HunchSchema/Post.php (modified) (1 diff)
-
trunk/lib/HunchSchema/Thing.php (modified) (5 diffs)
-
trunk/lib/SchemaCron.php (added)
-
trunk/lib/SchemaEditor.php (modified) (1 diff)
-
trunk/lib/SchemaFront.php (modified) (2 diffs)
-
trunk/lib/SchemaServer.php (modified) (7 diffs)
-
trunk/lib/SchemaSettings.php (modified) (3 diffs)
-
trunk/lib/classmap.php (modified) (1 diff)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
schema-app-structured-data-for-schemaorg/trunk/hunch-schema.php
r2367347 r2411907 5 5 * Plugin URI: http://www.schemaapp.com 6 6 * Description: This plugin adds http://schema.org structured data to your website 7 * Version: 1.1 6.27 * Version: 1.17.0 8 8 * Author: Hunch Manifest 9 9 * Author URI: https://www.hunchmanifest.com … … 33 33 $HunchSchemaFront = new SchemaFront(); 34 34 } 35 36 37 $hunch_schema_cron = new SchemaCron(); -
schema-app-structured-data-for-schemaorg/trunk/lib/HunchSchema/Post.php
r2344163 r2411907 44 44 public function getBreadcrumb( $Pretty = false ) { 45 45 $position = 1; 46 $permalink_structure = get_option( 'permalink_structure' );47 46 $this->SchemaBreadcrumb['@context'] = 'https://schema.org/'; 48 47 $this->SchemaBreadcrumb['@type'] = 'BreadcrumbList'; 49 48 50 if ( $permalink_structure) {49 if ( get_option( 'permalink_structure' ) ) { 51 50 $permalink_host = stristr( get_permalink(), parse_url( get_permalink(), PHP_URL_PATH ), true ); 52 51 $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 74 74 75 75 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 } 88 103 } 89 104 … … 324 339 global $post; 325 340 326 $featured_video_url = ''; 341 $post_content = apply_filters( 'the_content', $post->post_content ); 342 $featured_video_url = ''; 327 343 328 344 if ( function_exists( 'get_the_post_video_url' ) ) { … … 331 347 332 348 $videos = array(); 333 $urls = wp_extract_urls( $post ->post_content . $featured_video_url );349 $urls = wp_extract_urls( $post_content . $featured_video_url ); 334 350 335 351 if ( count( $urls ) ) { 336 352 foreach ( $urls as $url ) { 337 $url = trim( $url );338 339 353 if ( filter_var( $url, FILTER_VALIDATE_URL ) != false && stripos( $url, 'vimeo.com' ) !== false ) { 340 354 $videos[] = $this->get_vimeo_video( $url ); … … 344 358 345 359 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 ); 347 361 348 362 if ( count( $youtube_video_ids ) ) { … … 388 402 protected function get_youtube_video_ids( $string ) { 389 403 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 ); 393 407 394 408 if ( isset( $matches[1] ) && count( $matches[1] ) ) { 395 return $matches[1];409 return array_unique( $matches[1] ); 396 410 } 397 411 } -
schema-app-structured-data-for-schemaorg/trunk/lib/SchemaEditor.php
r2366035 r2411907 179 179 </td> 180 180 <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> 182 182 </td> 183 183 </tr> -
schema-app-structured-data-for-schemaorg/trunk/lib/SchemaFront.php
r2366035 r2411907 248 248 { 249 249 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 ); 251 251 252 252 foreach ( $SchemaServer->data_sources as $data_source ) { … … 360 360 'id' => 'Hunch-Schema', 361 361 '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 ), 363 363 'meta' => array 364 364 ( -
schema-app-structured-data-for-schemaorg/trunk/lib/SchemaServer.php
r2367347 r2411907 4 4 5 5 /** 6 * Handle interactions with the http://app.schemaapp ,com server6 * Handle interactions with the http://app.schemaapp.com server 7 7 * 8 8 * @author Mark van Berkel … … 12 12 private $options; 13 13 private $resource; 14 public $resource_url = ''; 14 15 public $transient_id = ''; 15 16 public $transient = false; 16 public $page_url = '';17 17 public $data_sources = array(); 18 18 19 19 const EDITOR = "https://app.schemaapp.com/editor"; 20 20 21 public function __construct($uri = "") { 21 22 public function __construct( $uri = '' ) { 22 23 $this->options = get_option( 'schema_option_name' ); 23 24 24 25 if ( ! empty( $uri ) ) { 25 26 $this->resource = $uri; 26 } elseif ( is_singular() ) {27 $this->resource = get_permalink();28 27 } 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(); 39 29 } 40 30 } 41 31 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 ) { 49 42 if ( empty( $this->options['graph_uri'] ) ) { 50 43 return ''; … … 64 57 65 58 $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 ); 70 62 $transient = get_transient( $this->transient_id ); 71 63 72 64 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 ); 74 66 75 67 if ( ! empty( $data_sources_additional ) ) { … … 86 78 $this->transient = true; 87 79 80 if ( $pretty && version_compare( phpversion(), '5.4.0', '>=' ) ) { 81 $transient = json_encode( json_decode( $transient ), JSON_PRETTY_PRINT ); 82 } 83 88 84 return $transient; 89 85 } 90 86 91 87 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 = ''; 93 113 94 114 foreach ( $this->data_sources as $data_source ) { … … 96 116 97 117 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 $schema data = wp_remote_retrieve_body( $remote_response );118 $schema_data = wp_remote_retrieve_body( $remote_response ); 99 119 100 120 // First delete then set; set method only updates expiry time if transient already exists 101 121 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 107 123 108 124 break; … … 110 126 } 111 127 112 return $schema data;128 return $schema_data; 113 129 } 114 130 … … 154 170 return array( true, $response_data->status ); 155 171 } else { 156 return array( false, $response_data->error);172 return array( false, "{$response_data->status} : {$response_data->error}" ); 157 173 } 158 174 } -
schema-app-structured-data-for-schemaorg/trunk/lib/SchemaSettings.php
r2344163 r2411907 47 47 function PluginActivate() 48 48 { 49 if ( ! current_user_can( 'activate_plugins' ) ) { 50 return; 51 } 52 49 53 $Settings = get_option( 'schema_option_name' ); 50 54 … … 662 666 663 667 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 664 692 $transients = $wpdb->get_col( "SELECT DISTINCT option_name FROM {$wpdb->options} WHERE option_name LIKE '_transient_HunchSchema-Markup-%'" ); 665 693 666 694 667 print '< h3>Cached Schema Items</h3>';695 print '<br><br> <hr> <h3>Cached schema data</h3>'; 668 696 669 697 if ( $transients ) { … … 685 713 686 714 687 print '<br><br> <hr> <h3>Cache REST API Log</h3>';715 print '<br><br> <hr> <h3>Cache REST API log</h3>'; 688 716 689 717 if ( file_exists( $rest_api_cache_log_file ) ) { -
schema-app-structured-data-for-schemaorg/trunk/lib/classmap.php
r1976919 r2411907 13 13 require_once $baseDir . 'SchemaSettings.php'; 14 14 require_once $baseDir . 'SchemaFront.php'; 15 require_once $baseDir . 'SchemaCron.php'; 15 16 require_once $baseDir . $schemaDir . 'Thing.php'; 16 17 require_once $baseDir . $schemaDir . 'Page.php'; -
schema-app-structured-data-for-schemaorg/trunk/readme.txt
r2367347 r2411907 9 9 Requires PHP: 5.4 10 10 Tested up to: 5.5 11 Stable tag: 1.1 6.211 Stable tag: 1.17.0 12 12 License: GPL2 13 13 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 75 75 76 76 == Frequently Asked Questions == 77 You\'ll find the [FAQ on SchemaApp.com] (https://www.schemaapp.com/wordpress/faq/). 77 78 You'll find the [FAQ on SchemaApp.com](https://www.schemaapp.com/solutions/wordpress-plugin/faq/). 78 79 79 80 == Screenshots == … … 86 87 87 88 == 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 88 95 89 96 = 1.16.2 = … … 426 433 == Upgrade Notice == 427 434 428 = 1.1 6.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.