Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .editorconfig
100755 → 100644
Empty file.
Empty file modified LICENSE.md
100755 → 100644
Empty file.
1 change: 0 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<?php

define('TOAST_OG_DIR', basename(__DIR__));
5 changes: 3 additions & 2 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Before:
---
SilverStripe\CMS\Model\SiteTree:
extensions:
- OpenGraphMeta
- ToastNZ\OpenGraphMeta\Extensions\OpenGraphMeta

SilverStripe\SiteConfig\SiteConfig:
extensions:
- OpenGraphSiteConfigExtension
- ToastNZ\OpenGraphMeta\Extensions\OpenGraphSiteConfigExtension
Empty file modified changelog.md
100755 → 100644
Empty file.
File renamed without changes
16 changes: 14 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "toastnz/open-graph-meta",
"description": "Silverstripe Open Graph Module",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"keywords": [
"silverstripe",
"open graph",
Expand All @@ -22,8 +22,20 @@
}
],
"require": {
"composer/installers": "*",
"composer/installers": "~1.0",
"silverstripe/cms": "~4.0",
"silverstripe/framework": "~4.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"ToastNZ\\OpenGraphMeta\\": "src/"
}
},
"extra": {
"expose": [
"client"
]
}
}
Empty file modified contributing.md
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace ToastNZ\OpenGraphMeta\Extensions;

use SilverStripe\Assets\Image;
use SilverStripe\Forms\FieldList;
use SilverStripe\Control\Director;
Expand All @@ -12,6 +14,7 @@
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Core\Manifest\ModuleResourceLoader;

/**
* Class OpenGraphMeta
Expand Down Expand Up @@ -45,27 +48,45 @@ class OpenGraphMeta extends DataExtension
*/
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab('Root.Main', ToggleCompositeField::create('OpenGraph', 'Open Graph',
[
LiteralField::create('', '<h2>&nbsp;&nbsp;&nbsp;Open Graph Information <img style="position:relative;top:8px;" src="' .
Director::absoluteBaseURL() . 'open-graph-meta/images/opengraph.png"></h2>'),
TextField::create('OGTitle', '')
->setAttribute('placeholder', 'e.g My Website')
->setRightTitle('Page title goes here, automatically defaults to the page title'),
DropdownField::create('OGContent', 'Content Type', $this->owner->dbObject('OGContent')->enumValues())
->setRightTitle('Will default to website (the most common open graph object type'),
TextareaField::create('OGDescription', '')
->setRightTitle('Page description goes here, automatically defaults to the content summary'),
UploadField::create('OGImage', 'Open Graph Image')
->setDescription('Ideal size: 1200px * 630px')
]
));
$imageUrl = ModuleResourceLoader::singleton()
->resolveUrl('toastnz/open-graph-meta:client/images/opengraph.png');

$headerHtml = sprintf(
'<h2>&nbsp;&nbsp;&nbsp;Open Graph Information <img style="position:relative;top:8px;" src="%s"></h2>',
$imageUrl
);

$fields->addFieldToTab(
'Root.Main',
ToggleCompositeField::create(
'OpenGraph',
'Open Graph',
[
LiteralField::create('', $headerHtml),
TextField::create('OGTitle', '')
->setAttribute('placeholder', 'e.g My Website')
->setRightTitle('Page title goes here, automatically defaults to the page title'),
DropdownField::create(
'OGContent',
'Content Type',
$this->owner->dbObject('OGContent')->enumValues()
)->setRightTitle('Will default to website (the most common open graph object type'),
TextareaField::create('OGDescription', '')
->setRightTitle(
'Page description goes here, automatically defaults to the content summary'
),
UploadField::create('OGImage', 'Open Graph Image')
->setDescription('Ideal size: 1200px * 630px')
]
)
);
}

public function FirstImage()
{
$pattern = ' /<img[^>]+ src[\\s = \'"]';
$pattern .= '+([^"\'>\\s]+)/is';

if (preg_match_all($pattern, $this->owner->Content, $match)) {
$imageLink = preg_replace('/_resampled\/resizedimage[0-9]*-/', '', $match[1][0]);
return (string)$imageLink;
Expand Down Expand Up @@ -129,7 +150,10 @@ public function MetaTags(&$tags)
if (trim($this->owner->OGDescription)) {
$tags .= sprintf('<meta name="og:description" content="%s">', $this->owner->OGDescription) . "\n";
} elseif ($this->owner->Content) {
$tags .= sprintf('<meta name="og:description" content="%s">', $this->owner->dbObject('Content')->FirstParagraph()) . "\n";
$tags .= sprintf(
'<meta name="og:description" content="%s">',
$this->owner->dbObject('Content')->FirstParagraph()
) . "\n";
}

// Image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace ToastNZ\OpenGraphMeta\Extensions;

use SilverStripe\Assets\Image;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TabSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php

namespace ToastNZ\OpenGraphMeta\Tasks;

use SilverStripe\Control\Director;
use SilverStripe\ORM\DB;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\BuildTask;
use Page;

/**
* Class MigrateSiteTreeOpenGraphTask
Expand Down Expand Up @@ -40,7 +43,7 @@ public function __construct()
}

/**
* @param SS_HTTPRequest $request
* @param HTTPRequest $request
*/
public function run($request)
{
Expand All @@ -65,16 +68,20 @@ public function run($request)
echo 'Updating page: ' . $page->Title . $this->eol;

foreach ($this->fields_to_update as $fieldName) {
$oldData = DB::query("SELECT {$fieldName} FROM Page WHERE ID = {$id}")->column($fieldName);
$oldData = DB::query("SELECT {$fieldName} FROM Page WHERE ID = {$id}")
->column($fieldName);

$newData = DB::query("SELECT {$fieldName} FROM SiteTree WHERE ID = {$id}")->column($fieldName);
$newData = DB::query("SELECT {$fieldName} FROM SiteTree WHERE ID = {$id}")
->column($fieldName);

if (!empty($oldData)) {
// If new data has been saved and we don't want to overwrite, exit the loop
if (!empty($newData) && !$overwrite) {
continue;
}

$data = Convert::raw2sql($oldData[0]);

DB::query("UPDATE SiteTree SET {$fieldName} = '{$data}' WHERE ID = {$id}");
DB::query("UPDATE SiteTree_Live SET {$fieldName} = '{$data}' WHERE ID = {$id}");
} else {
Expand Down