Skip to content

Commit

Permalink
Change og:image to take cdn-image over cdn-name from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
anagh-p committed Jan 4, 2017
1 parent 8d85306 commit 714bf94
Showing 1 changed file with 120 additions and 106 deletions.
226 changes: 120 additions & 106 deletions src/Quintype/Seo/Story.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,121 +4,135 @@

class Story extends Base
{
function __construct($config, $pageType, $story){
parent::__construct($config, $pageType);
$this->story = $story;
}
public function __construct($config, $pageType, $story)
{
parent::__construct($config, $pageType);
$this->story = $story;
}

function prepareTags() {
if (sizeof($this->story)>0){
return [
'title' => trim($this->getTitle()),
'description' => trim($this->getDescription()),
'keywords' => trim($this->getKeywords()),
'og' => $this->getOgAttributes(),
'twitter' => $this->getTwitterAttributes(),
'msvalidate.01' => $this->getBingId(),
'fb' => [
'app_id' => $this->getFacebookData('app-id'),
'pages' => $this->getFacebookData('pages')
],
'article' => [
'publisher' => $this->getPublisher()
],
'rel:canonical' => $this->getCanonicalUrl(),
'al:android:package' => $this->getAndroidData('al:android:package'),
'al:android:app-name' => $this->getAndroidData('al:android:app-name'),
'al:android:url' => "quintypefb://" . $this->config['sketches-host'] . "/". $this->story['slug']
];
} else {
return ['title' => $this->getPageTitle()];
}
}
public function prepareTags()
{
if (sizeof($this->story) > 0) {
return [
'title' => trim($this->getTitle()),
'description' => trim($this->getDescription()),
'keywords' => trim($this->getKeywords()),
'og' => $this->getOgAttributes(),
'twitter' => $this->getTwitterAttributes(),
'msvalidate.01' => $this->getBingId(),
'fb' => [
'app_id' => $this->getFacebookData('app-id'),
'pages' => $this->getFacebookData('pages'),
],
'article' => [
'publisher' => $this->getPublisher(),
],
'rel:canonical' => $this->getCanonicalUrl(),
'al:android:package' => $this->getAndroidData('al:android:package'),
'al:android:app-name' => $this->getAndroidData('al:android:app-name'),
'al:android:url' => 'quintypefb://'.$this->config['sketches-host'].'/'.$this->story['slug'],
];
} else {
return ['title' => $this->getPageTitle()];
}
}

protected function getDescription(){
if(isset($this->story['summary'])){
return $this->story['summary'];
} else {
return '';
}
}
protected function getDescription()
{
if (isset($this->story['summary'])) {
return $this->story['summary'];
} else {
return '';
}
}

protected function getTitle(){
if(isset($this->story['headline'])){
return $this->story['headline'];
} else {
return $this->config['title'];
}
}
protected function getTitle()
{
if (isset($this->story['headline'])) {
return $this->story['headline'];
} else {
return $this->config['title'];
}
}

private function getOgAttributes(){
$attributes = [
'title' => trim($this->getTitle()),
'type' => 'article',
'url' => $this->getCanonicalUrl(),
'site-name' => trim($this->config['title']),
'description' => trim($this->getDescription()),
'image' => $this->getHeroImageUrl()
private function getOgAttributes()
{
$attributes = [
'title' => trim($this->getTitle()),
'type' => 'article',
'url' => $this->getCanonicalUrl(),
'site-name' => trim($this->config['title']),
'description' => trim($this->getDescription()),
'image' => $this->getHeroImageUrl(),
];

if(isset($this->story['hero-image-metadata'])){
$imageProperties=[];
if(isset($this->story['hero-image-metadata']['width'])){
$imageProperties['image:width']=$this->story['hero-image-metadata']['width'];
}
if(isset($this->story['hero-image-metadata']['height'])){
$imageProperties['image:height']=$this->story['hero-image-metadata']['height'];
}
$attributes = array_merge($attributes, $imageProperties);
}
return $attributes;
}
if (isset($this->story['hero-image-metadata'])) {
$imageProperties = [];
if (isset($this->story['hero-image-metadata']['width'])) {
$imageProperties['image:width'] = $this->story['hero-image-metadata']['width'];
}
if (isset($this->story['hero-image-metadata']['height'])) {
$imageProperties['image:height'] = $this->story['hero-image-metadata']['height'];
}
$attributes = array_merge($attributes, $imageProperties);
}

private function getTwitterAttributes(){
$attributes = [
'title' => trim($this->getTitle()),
'description' => trim($this->getDescription()),
'card' => 'summary_large_image',
'site' => $this->getTwitterSite(),
'image' => [
'src' => $this->getHeroImageUrl()
]
];
return $attributes;
}
return $attributes;
}

private function getTwitterSite(){
if(isset($this->config['social-app-credentials'])){
if(isset($this->config['social-app-credentials']['twitter'])){
return $this->config['social-app-credentials']['twitter']['username'];
}else{
return '';
}
}else{
return '';
}
}
private function getTwitterAttributes()
{
$attributes = [
'title' => trim($this->getTitle()),
'description' => trim($this->getDescription()),
'card' => 'summary_large_image',
'site' => $this->getTwitterSite(),
'image' => [
'src' => $this->getHeroImageUrl(),
],
];

private function getPublisher(){
if(isset($this->config['social-links'])){
return $this->config['social-links']['facebook-url'];
}
}
return $attributes;
}

private function getAndroidData($element){
if(isset($this->config['apps-data'])){
if(isset($this->config['apps-data'][$element])){
return $this->config['apps-data'][$element];
}
}
}
private function getTwitterSite()
{
if (isset($this->config['social-app-credentials'])) {
if (isset($this->config['social-app-credentials']['twitter'])) {
return $this->config['social-app-credentials']['twitter']['username'];
} else {
return '';
}
} else {
return '';
}
}

private function getHeroImageUrl(){
if(isset($this->config['cdn-name']) && isset($this->story['hero-image-s3-key'])){
$imageUrl = $this->config['cdn-name'].$this->story['hero-image-s3-key'];
return str_replace(" ", "%20", $imageUrl);
}else{
return '';
}
}
private function getPublisher()
{
if (isset($this->config['social-links'])) {
return $this->config['social-links']['facebook-url'];
}
}

private function getAndroidData($element)
{
if (isset($this->config['apps-data'])) {
if (isset($this->config['apps-data'][$element])) {
return $this->config['apps-data'][$element];
}
}
}

private function getHeroImageUrl()
{
if (isset($this->config['cdn-name']) || isset($this->config['cdn-image'])) {
$cdn = isset($this->config['cdn-image']) ? $this->config['cdn-image'] : $this->config['cdn-name'];
$imageUrl = trim($cdn, '/').'/'.$this->story['hero-image-s3-key'];

return str_replace(' ', '%20', $imageUrl);
} else {
return '';
}
}
}

0 comments on commit 714bf94

Please sign in to comment.