-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e26e343
Showing
6 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# SilverStripe Facebook Image | ||
|
||
Provides an Image Field for use when sharing pages on facebook. This extension provides fields in both the SiteConfig and on Page. The SiteConfig image is the default fallback for all pages but one can customise which image appears on each individual page by using that page's facebook image field. | ||
|
||
|
||
## Installation (with composer) | ||
|
||
$ composer require heyday/silverstripe-facebookimage | ||
|
||
## Usage | ||
|
||
```html | ||
<head> | ||
$FacebookMetaTags | ||
</head> | ||
``` | ||
|
||
Just use the $FacebookMetaTags variable in your silverstripe template in the <head> section. | ||
|
||
##License | ||
|
||
SilverStripe Facebook Image Extension is licensed under an [MIT license](http://heyday.mit-license.org/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SiteConfig: | ||
extensions: | ||
- SiteConfigFacebookImageExtension | ||
|
||
Page: | ||
extensions: | ||
- PageFacebookImageExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
class PageFacebookImageExtension extends DataExtension | ||
{ | ||
public function extraStatics($class = null, $extension = null) | ||
{ | ||
return array( | ||
'has_one' => array( | ||
'FacebookImage' => 'Image' | ||
) | ||
); | ||
} | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->addFieldToTab('Root.Content.Facebook', $uf = new UploadField('FacebookImage', 'Facebook image for facebook share')); | ||
$uf->setFolderName('FacebookImages/'); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function FacebookImageWithFallback() | ||
{ | ||
return $this->FacebookImageID ? $this->FacebookImage() : SiteConfig::current_site_config()->FacebookImage(); | ||
} | ||
|
||
/** | ||
* @return HTMLText | ||
*/ | ||
public function FacebookMetaTags() | ||
{ | ||
return Controller::curr()->renderWith('FacebookMetaTags'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
class SiteConfigFacebookImageExtension extends DataExtension | ||
{ | ||
public function extraStatics($class = null, $extension = null) | ||
{ | ||
return array( | ||
'has_one' => array( | ||
'FacebookImage' => 'Image' | ||
) | ||
); | ||
} | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->addFieldToTab('Root.Facebook', $uf = new UploadField('FacebookImage', 'Default Facebook image for facebook share')); | ||
$uf->setFolderName('FacebookImages/'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "heyday/silverstripe-facebookimage", | ||
"type": "silverstripe-module", | ||
"description": "Provides an Image Field for use when sharing pages on facebook", | ||
"authors": [ | ||
{ | ||
"name": "Glenn Bautista", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"composer/installers": "~1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<meta property="og:title" content="$Title"> | ||
<meta property="og:type" content="website"> | ||
<meta property="og:url" content="$AbsoluteLink"> | ||
<meta property="og:image" content="$FacebookImageWithFallback.AbsoluteURL"> | ||
<meta property="og:site_name" content="$SiteConfig.Title"> | ||
<% if $MetaDescription %> | ||
<meta property="og:description" content="$MetaDescription"> | ||
<% end_if %> |