Permalink
Browse files

[Open Graph] Introduce function OpenGraphArticleObject::setImageFromT…

…ext() (currently unimplemented)
  • Loading branch information...
1 parent e251a6b commit 872148078faaf1d49616d32a2c1f1e1aa89cc9a1 @garbear committed May 22, 2012
Showing with 15 additions and 3 deletions.
  1. +6 −2 Facebook/FacebookHooks.php
  2. +9 −1 Facebook/FacebookOpenGraph.php
@@ -424,8 +424,12 @@ public static function ParserAfterTidy(&$parser, &$text) {
$object = FacebookOpenGraph::newObjectFromTitle( $parser->getTitle() );
if ( $object ) {
- if ($object instanceof OpenGraphArticleObject && $object->needsDescription()) {
- $object->setDescriptionFromText( $text );
+ if ( $object instanceof OpenGraphArticleObject ) {
+ if ( $object->needsDescription() )
+ $object->setDescriptionFromText( $text );
+ // Always search the page for an image. If one isn't found,
+ // the fallback is the site logo.
+ $object->setImageFromText( $text );
}
foreach ( $object->getProperties() as $property => $content ) {
$parser->mOutput->addHeadItem("<meta property=\"$property\" content=\"$content\" />\n", $property);
@@ -501,7 +501,7 @@ function __construct( $title, $override = array() ) {
// og:image
if ( !isset( $override['og:image'] ) ) {
- // TODO: attempt to use first image on page, otherwise default to $wgLogo
+ // Default to $wgLogo. This can be overridden with setImageFromText().
global $wgServer, $wgLogo;
$this->properties['og:image'] = $wgServer . $wgLogo;
}
@@ -599,6 +599,14 @@ public function setDescriptionFromText($text) {
public function needsDescription() {
return empty( $this->properties['og:description'] );
}
+
+ /**
+ * Extracts the first linked image from the article's text.
+ */
+ public function setImageFromText($text) {
+ // TODO: parse page text for the URL of the first <img> tag
+ // $this->properties['og:image'] = $absolute_url;
+ }
}
class OpenGraphFileObject extends OpenGraphObject {

0 comments on commit 8721480

Please sign in to comment.