2017 © Pedro Peláez
 

yii2-extension opengraph

Create implementation for Yii2. Generate Open Graph protocol for your website

image

umanskyi31/opengraph

Create implementation for Yii2. Generate Open Graph protocol for your website

  • Sunday, May 27, 2018
  • by Vlad Umanskyi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 4 Versions
  • 180 % Grown

The README.md

, (*1)


Yii2.x Open Graph

Build Status StyleCI Total Downloads Latest Stable Version License: MIT, (*2)

Created a new component for Yii2. The Open Graph component for your website, (*3)

Installation

composer require umanskyi31/opengraph

or add, (*4)

"umanskyi31/opengraph": "^3.0.0"

to the require section of your composer.json file., (*5)

Configuration

'components' => [
     'opengraph' => [
        'class' => 'umanskyi31\opengraph\OpenGraph',
     ],
     // ...
]

Usage

You should add component to controller before rendering view., (*6)

Example:, (*7)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

How to use

Add basic attributes:, (*8)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getBasic()
       ->setUrl('https://umanskyi.com') 
       ->setTitle('My_Article_Title')
       ->setDescription('My_Article_Description')
       ->setSiteName('My_Site_Name')
       ->setLocale('pl_PL')
       ->setLocalAlternate(['fr_FR', 'en_US'])
       ->render();

Add image attributes:, (*9)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getImage()
       ->setUrl('https://umanskyi.com/logo.png')
       ->setAttributes([
           'secure_url' => 'https://umanskyi.com/logo.png',
           'width'      => 100,
           'height'     => 100,
           'alt'        => "Logo",
       ])
       ->render();

If necessary, an array of images also possible to add the next code:, (*10)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getImage()
       ->setUrl('https://umanskyi.com/logo.png')
       ->setAttributes([
           'secure_url' => 'https://umanskyi.com/logo.png',
           'width'      => 100,
           'height'     => 100,
           'alt'        => "Logo",
       ])
       ->render();     

 $openGraph->getImage()
       ->setUrl('https://umanskyi.com/small_logo.png')
       ->setAttributes([
           'secure_url' => 'https://umanskyi.com/small_logo.png',
           'width'      => 50,
           'height'     => 50,
           'alt'        => "small logo",
       ])
       ->render();

Add article attribute:, (*11)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getArticle()
       ->setAuthor(['http://examples.opengraphprotocol.us/profile.html'])
       ->setTag(['Test_TAG'])
       ->setSection('Front page')
       ->setPublishTime(new \DateTime('2010-10-11'))
       ->render();

Add audio attribute:, (*12)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getAudio()
       ->setAttributes([
         'secure_url' => 'https://umanskyi.com/media/audio/250hz.mp3',
         'type' => 'audio/mpeg'
       ])
       ->setUrl('https://d72cgtgi6hvvl.cloudfront.net/media/audio/250hz.mp3')
       ->render();

Add book attribute:, (*13)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getBook()
      ->setReleaseDate(new \DateTime('2011-10-10'))
      ->setTag(['Apple', 'New'])
      ->setAuthor(['http://umanskyi.com/profile.html'])
      ->setIsbn(1451648537)
      ->render();

Add music attribute:, (*14)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getMusic()
      ->setReleaseDate(new \DateTime('2016-01-16'))
      ->setDuration(236)
      ->setAttrAlbum([
          'album:track' => 2
      ])
      ->setMusician([
          'http://open.spotify.com/artist/1dfeR4HaWDbWqFHLkxsg1d',
          'http://open.spotify.com/artist/1dfeR4HaWDbWqFirlsag1d'
      ])
      ->render();

Add profile attribute:, (*15)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getProfile()
      ->setGender('Male')
      ->setFirstName('Vlad')
      ->setLastName('Umanskyi')
      ->setUsername('vlad.umanskyi')
      ->render();   

Add video attribute:, (*16)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->getVideo()
      ->setUrl('https://umanskyi.com/strobe/FlashMediaPlayback.swf')
      ->setAttributes([
          'width' => 450,
          'height' => 350,
          'secure_url' => 'https://umanskyi.com/strobe/FlashMediaPlayback.swf',
          'type' => 'application/x-shockwave-flash'
      ])
      ->setAdditionalAttributes([
          'tag' => 'train',
          'release_date' => '1980-10-02'
      ])
      ->render();

The current version also has a configuration Twitter Card, (*17)

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;

 $openGraph->useTwitterCard()
    ->setCard('summary')
    ->setSite('https://umanskyi.com')
    ->setCreator('Vlad Umanskyi')
    ->render();

If you want to add own configuration or override some tag, you must implement umanskyi31\opengraph\Configuration and add to Yii container. Some example you can find here umanskyi31\opengraph\OpenGraphConfiguration, (*18)


If you have any issue please let me know., (*19)

The Versions

27/05 2018

dev-master

9999999-dev https://github.com/umanskyi31/yii2-opengraph

Create implementation for Yii2. Generate Open Graph protocol for your website

  Sources   Download

MIT

The Requires

 

by Avatar Vlad Umanskyi

extension yii2 facebook seo open-graph twitter-card

27/05 2018

v1.1

1.1.0.0 https://github.com/umanskyi31/yii2-opengraph

Create implementation for Yii2. Generate Open Graph protocol for your website

  Sources   Download

MIT

The Requires

 

by Avatar Vlad Umanskyi

extension yii2 facebook seo open-graph twitter-card

11/04 2018

dev-tests

dev-tests https://github.com/umanskyi31/yii2-opengraph

Create implementation for Yii2. Generate Open Graph protocol for your website

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar Vlad Umanskyi

extension yii2 facebook seo open-graph twitter-card

20/02 2018

dev-vu-add-travis

dev-vu-add-travis https://github.com/umanskyi31/yii2-opengraph

Create implementation for Yii2. Generate Open Graph protocol for your website

  Sources   Download

MIT

The Requires

 

by Avatar Vlad Umanskyi

extension yii2 facebook seo open-graph twitter-card