Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-bautista committed Jul 15, 2014
0 parents commit e26e343
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
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/)
7 changes: 7 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SiteConfig:
extensions:
- SiteConfigFacebookImageExtension

Page:
extensions:
- PageFacebookImageExtension
35 changes: 35 additions & 0 deletions code/PageFacebookImageExtension.php
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');
}
}
20 changes: 20 additions & 0 deletions code/SiteConfigFacebookImageExtension.php
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/');
}

}
14 changes: 14 additions & 0 deletions composer.json
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"
}
}
8 changes: 8 additions & 0 deletions templates/Includes/FacebookMetaTags.ss
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 %>

0 comments on commit e26e343

Please sign in to comment.