Skip to content

Commit

Permalink
Added SEO support
Browse files Browse the repository at this point in the history
  • Loading branch information
greeflas committed Oct 29, 2016
1 parent e6b7a42 commit a23c7ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ In this component you need to add and configure social network classes
|networks|array|-|Array of social networks classes configuration|
|attributes|array|-|HTML attributes for all share links|
|defaultIcons|boolean|false|Use default font-icons instead text labels or not|
|enableSeo|boolean|true|Enable or disable appending SEO attributes from `seoAttributes` array for links|
|seoAttributes|array|['target' => '_blank', 'rel' => 'nofollow']|Array of SEO attributes for links|

#### Social network class configuration properties
| Option | Type | Default |
Expand Down
27 changes: 26 additions & 1 deletion SocialShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @property array $networks
* @property array $attributes
* @property boolean $defaultIcons
* @property boolean $enableSeo
* @property array $seoAttributes
*
* @see SocialShareWidget
*
Expand Down Expand Up @@ -63,6 +65,20 @@ class SocialShare extends Object
*/
public $defaultIcons = false;

/**
* @var boolean If set `true` for all links will be appended
* SEO attributes from $seoAttributes array
*/
public $enableSeo = true;

/**
* @var array of SEO attributes for link
*/
public $seoAttributes = [
'target' => '_blank',
'rel' => 'nofollow'
];

/**
* Getter for $networks
* @return array
Expand All @@ -73,11 +89,20 @@ public function getNetworks()
}

/**
* Getter fot attributes
* Getter for $attributes
* @return array
*/
public function getAttributes()
{
return $this->attributes;
}

/**
* Getter for $seoAttributes
* @return array
*/
public function getSeoAttributes()
{
return $this->seoAttributes;
}
}
22 changes: 6 additions & 16 deletions base/SocialNetwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ protected function addMetaTags($metaTags = [])
}
}

/**
* Method for adding custom HTML attributes to the social share link
*
* @param array $htmlAttrs
*/
protected function addCustomAttributes($htmlAttrs)
{
$this->attributes['target'] = '_blank';
if(!empty($htmlAttrs)) {
foreach ($htmlAttrs as $name => $value) {
$this->attributes[$name] = $value;
}
}
}

/**
* Method for initialize link to the social network
*
Expand All @@ -67,8 +52,13 @@ protected function addCustomAttributes($htmlAttrs)
protected function initLink($component = null)
{
if($component !== null && $this->_route !== null) {
$this->attributes['target'] = '_blank';
// init seo attributes
$seoAttributes = $component->getSeoAttributes();
if($component->enableSeo && !empty($seoAttributes)) {
$this->attributes = array_merge($this->attributes, $seoAttributes);
}

// init global and custom attributes
$attributes = $component->getAttributes();
if(!empty($attributes)) {
foreach ($attributes as $name => $value) {
Expand Down

0 comments on commit a23c7ed

Please sign in to comment.