diff --git a/README.md b/README.md new file mode 100644 index 0000000..0682786 --- /dev/null +++ b/README.md @@ -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 +
+$FacebookMetaTags + +``` + +Just use the $FacebookMetaTags variable in your silverstripe template in the section. + +##License + +SilverStripe Facebook Image Extension is licensed under an [MIT license](http://heyday.mit-license.org/) diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 0000000..e631e25 --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,7 @@ +SiteConfig: + extensions: + - SiteConfigFacebookImageExtension + +Page: + extensions: + - PageFacebookImageExtension \ No newline at end of file diff --git a/code/PageFacebookImageExtension.php b/code/PageFacebookImageExtension.php new file mode 100644 index 0000000..87bcf5b --- /dev/null +++ b/code/PageFacebookImageExtension.php @@ -0,0 +1,35 @@ + 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'); + } +} \ No newline at end of file diff --git a/code/SiteConfigFacebookImageExtension.php b/code/SiteConfigFacebookImageExtension.php new file mode 100644 index 0000000..e617265 --- /dev/null +++ b/code/SiteConfigFacebookImageExtension.php @@ -0,0 +1,20 @@ + 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/'); + } + +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..699600a --- /dev/null +++ b/composer.json @@ -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": "glenn@heyday.co.nz" + } + ], + "require": { + "composer/installers": "~1.0" + } +} diff --git a/templates/Includes/FacebookMetaTags.ss b/templates/Includes/FacebookMetaTags.ss new file mode 100644 index 0000000..ec779b6 --- /dev/null +++ b/templates/Includes/FacebookMetaTags.ss @@ -0,0 +1,8 @@ + + + + + +<% if $MetaDescription %> + +<% end_if %> \ No newline at end of file