Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.1' into 3
Browse files Browse the repository at this point in the history
# Conflicts:
#	code/Extensions/OpenGraphObjectExtension.php
Damian Mooyman committed Feb 26, 2018
2 parents 56abe3b + b61b1a0 commit b2efdb2
Showing 5 changed files with 33 additions and 30 deletions.
4 changes: 2 additions & 2 deletions code/Constants/OGTypes.php
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
/**
* Defines the list of standard opengraph object types.
* User types may be substitude in place of any of these for the og:type property,
* as long as the namespace is correctly implemented
* as long as the namespace is correctly implemented
*/
class OGTypes
{
@@ -23,7 +23,7 @@ class OGTypes
const Website = 'website';

/**
* @link http://developers.facebook.com/docs/opengraph/music/
* @link http://developers.facebook.com/docs/opengraph/music/
*/
const MetaData = 'metadata';

34 changes: 16 additions & 18 deletions code/Extensions/OpenGraphObjectExtension.php
Original file line number Diff line number Diff line change
@@ -17,28 +17,26 @@ class OpenGraphObjectExtension extends SiteTreeExtension implements IOGObjectExp
public function getOGNS()
{
// todo : Should custom namespace be injected here, or left up to user code?
$ns = ' xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml"';
$ns = ' prefix="og: http://ogp.me/ns# fb: http://www.facebook.com/2008/fbml';
if ($this->owner instanceof IOGMusic) {
$ns .= ' xmlns:music="http://ogp.me/ns/music#"';
$ns .= ' music: http://ogp.me/ns/music#';
}
if ($this->owner instanceof IOGVideo) {
$ns .= ' xmlns:video="http://ogp.me/ns/video#"';
$ns .= ' video: http://ogp.me/ns/video#';
}
if ($this->owner instanceof IOGArticle) {
$ns .= ' xmlns:article="http://ogp.me/ns/article#"';
$ns .= ' article: http://ogp.me/ns/article#';
}
if ($this->owner instanceof IOGBook) {
$ns .= ' xmlns:book="http://ogp.me/ns/book#"';
$ns .= ' book: http://ogp.me/ns/book#';
}
if ($this->owner instanceof IOGProfile) {
$ns .= ' xmlns:profile="http://ogp.me/ns/profile#"';
$ns .= ' profile: http://ogp.me/ns/profile#';
}

// Since the default type is website we should make sure that the correct namespace is applied in the default case
if ($this->owner instanceof IOGWebsite || $this->owner->getOGType() == OGTypes::DefaultType) {
$ns .= ' xmlns:website="http://ogp.me/ns/website#"';
$ns .= ' website: http://ogp.me/ns/website#';
}
$ns .= '"';

return $ns;
}
@@ -52,20 +50,20 @@ protected function getTagBuilder()
{
// Determine type
$type = $this->owner->getOGType();

// Case for non-types
if (empty($type)) {
return null;
}

// Determine type, if configured
$prototype = OpenGraph::get_prototype($type);
if (!empty($prototype['tagbuilder'])) {
$class = $prototype['tagbuilder'];
} else {
$class = OpenGraph::get_default_tagbuilder();
}

// Construct instance from type
return new $class();
}
@@ -77,7 +75,7 @@ public function MetaTags(&$tags)
if (!$builder) {
return;
}

$config = SiteConfig::current_site_config();
// Default tags
$builder->BuildTags($tags, $this->owner, $config);
@@ -142,11 +140,11 @@ public function getOGDescription()
return $description;
}
}

// Intelligent fallback for SiteTree instances
$contentField = $this->owner->dbObject('Content');
if ($contentField instanceof Text) {
return $contentField->FirstParagraph();
return $contentField->Summary(100);
}
}

@@ -159,12 +157,12 @@ public function getOGLocales()
{
// Use current locale
$locale = i18n::get_locale();

// Check locale is valid
if (OpenGraph::is_locale_valid($locale)) {
return $locale;
}

// Return default
return OpenGraph::get_default_locale();
}
15 changes: 10 additions & 5 deletions code/ObjectBuilders/OpenGraphBuilder.php
Original file line number Diff line number Diff line change
@@ -49,8 +49,11 @@ public function AppendTag(&$tags, $name, $content)

// check tag type
if (is_scalar($content)) {
return $tags .= sprintf("<meta property=\"%s\" content=\"%s\" />\n", Convert::raw2att($name),
Convert::raw2att($content));
return $tags .= sprintf(
"<meta property=\"%s\" content=\"%s\" />\n",
Convert::raw2att($name),
Convert::raw2att($content)
);
}

trigger_error('Invalid tag type: ' . gettype($content), E_USER_ERROR);
@@ -83,9 +86,11 @@ protected function appendLink(&$tags, $rel, $link, $type = null)
if (empty($rel) || empty($link)) {
return;
}
$tags .= sprintf("<link rel=\"%s\" href=\"%s\" type=\"%s\" />\n", Convert::raw2att($rel),
Convert::raw2att($link),
$type
$tags .= sprintf(
"<link rel=\"%s\" href=\"%s\" type=\"%s\" />\n",
Convert::raw2att($rel),
Convert::raw2att($link),
$type
? $type
: $this->getMimeType($link)
);
8 changes: 4 additions & 4 deletions code/OpenGraph.php
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ public static function get_config($field)
* Configure the site to use a specified value for a field. Specifying 'SiteConfig'
* will cause the value for this field to be managed via the SiteConfig
* @param string $field
* @param string $value
* @param string $value
*/
public static function set_config($field, $value = 'SiteConfig')
{
@@ -77,7 +77,7 @@ public static function set_config($field, $value = 'SiteConfig')

/**
* Sets the application ID of this site, or 'SiteConfig' to manage in CMS
* @param string $value
* @param string $value
*/
public static function set_application($value)
{
@@ -86,7 +86,7 @@ public static function set_application($value)

/**
* Sets the admin ID of this site, or 'SiteConfig' to manage in CMS
* @param string $value
* @param string $value
*/
public static function set_admin($value)
{
@@ -95,7 +95,7 @@ public static function set_admin($value)

/**
* Retrieves the default class used to build tags
* @return type
* @return type
*/
public static function get_default_tagbuilder()
{
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"issues": "http://github.com/tractorcow/silverstripe-opengraph/issues"
},
"require": {
"silverstripe/framework": ">=3.1",
"silverstripe/framework": "^3.1",
"composer/installers": "*"
},
"extra": {

0 comments on commit b2efdb2

Please sign in to comment.