Changeset 3651508 for social-engine/trunk/classes/core.php
- Timestamp:
- 08/17/2026 05:42:52 PM (2 months ago)
- File:
-
- 1 edited
-
social-engine/trunk/classes/core.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
social-engine/trunk/classes/core.php
r3628743 r3651508 207 207 208 208 $use_featured_image = $this->get_option( 'use_featured_image', true ); 209 209 210 $thumbnails = []; 210 211 $thumbnail_ids = []; … … 308 309 } 309 310 311 // Returns the unique and valid URLs found in a text. 312 public function extract_urls( $content ) 313 { 314 if ( empty( $content ) || !preg_match_all( '#\bhttps?://[^\s<>"\'\)\]]+#i', $content, $matches ) ) { 315 return []; 316 } 317 $urls = []; 318 foreach ( $matches[0] as $url ) { 319 // Trailing punctuation is usually part of the sentence, not of the URL. 320 $url = rtrim( $url, '.,;:!?' ); 321 if ( filter_var( $url, FILTER_VALIDATE_URL ) && !in_array( $url, $urls, true ) ) { 322 $urls[] = $url; 323 } 324 } 325 return $urls; 326 } 327 328 public function resolve_post_link( $post_link, $content ) 329 { 330 $valid_url = filter_var( $post_link, FILTER_VALIDATE_URL ); 331 332 if ( $valid_url ) { 333 return $post_link; 334 } else { 335 $this->log( "The link is not valid: $post_link. It will be ignored." ); 336 } 337 338 $use_post_link = $this->get_option( 'use_post_link', false ); 339 if( $use_post_link ) { 340 $urls = $this->extract_urls( $content ); 341 if ( count( $urls ) === 1 ) { 342 $this->log( "The link was extracted from the content: {$urls[0]}." ); 343 return $urls[0]; 344 } 345 } 346 347 return null; 348 } 349 310 350 public function post( $post_id ) 311 351 { … … 323 363 } 324 364 325 $post_link = get_post_meta( $post_id, 'sclegn_post_link', true ); 365 $post_link = $this->resolve_post_link( 366 get_post_meta( $post_id, 'sclegn_post_link', true ), 367 $post->post_content 368 ); 326 369 $thumbnail_ids = json_decode( get_post_meta( $post->ID, 'sclegn_thumbnails', true ) ) ?? []; 327 370 $thumbnail_paths = [];
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)