-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 'LinkedIn' social network and small code refactoring
- Loading branch information
Showing
6 changed files
with
82 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,12 @@ | |
|
||
/** | ||
* @author Vladimir Kuprienko <[email protected]> | ||
* | ||
* @property string $label | ||
* @property array $attributes | ||
*/ | ||
abstract class SocialNetwork extends Object | ||
{ | ||
/** | ||
* Link to the social network | ||
* @var string $_link | ||
*/ | ||
protected $_link; | ||
/** | ||
* Social network link label | ||
* @var string $label | ||
|
@@ -26,18 +24,39 @@ abstract class SocialNetwork extends Object | |
* @var array $attributes | ||
*/ | ||
public $attributes = []; | ||
/** | ||
* Link to the social network | ||
* @var string $_link | ||
*/ | ||
protected $_link; | ||
|
||
/** | ||
* Method for adding meta tags to <head> from array | ||
* | ||
* @param array $metaTags | ||
*/ | ||
protected function addMetaTags($metaTags = []) { | ||
protected function addMetaTags($metaTags = []) | ||
{ | ||
foreach($metaTags as $tagOptions) { | ||
Yii::$app->view->registerMetaTag($tagOptions); | ||
} | ||
} | ||
|
||
/** | ||
* 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 getting link to the social network | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
namespace bl\socialShare\classes; | ||
|
||
use yii\helpers\Html; | ||
|
||
use bl\socialShare\base\SocialNetwork; | ||
|
||
/** | ||
* @author Vladimir Kuprienko <[email protected]> | ||
* | ||
* @property string $_link | ||
* @property string $label | ||
* @property array $attributes | ||
* | ||
* @property string $siteName | ||
*/ | ||
class LinkedIn extends SocialNetwork | ||
{ | ||
/** | ||
* @var string Title of your website | ||
*/ | ||
public $siteName; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLink($url, $title, $description, $image, $htmlAttrs) | ||
{ | ||
$this->_link = "https://www.linkedin.com/shareArticle?mini=true" | ||
."&url=$url" | ||
."&title=$title" | ||
."&summary=$description" | ||
."&source=$this->siteName"; | ||
|
||
$this->addCustomAttributes($htmlAttrs); | ||
|
||
return Html::a($this->label, $this->_link, $this->attributes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters