PHP code example of umanskyi31 / opengraph

1. Go to this page and download the library: Download umanskyi31/opengraph library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

umanskyi31 / opengraph example snippets


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

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

/**
 * @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();

/**
 * @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();

/**
 * @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();
       

/**
 * @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();

/**
 * @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();

/**
 * @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();

/**
 * @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();

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;
    
 $openGraph->getProfile()
      ->setGender('Male')
      ->setFirstName('Vlad')
      ->setLastName('Umanskyi')
      ->setUsername('vlad.umanskyi')
      ->render();   
            

/**
 * @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();

/**
 * @var OpenGraph $openGraph
 */
 $openGraph = Yii::$app->opengraph;
        
 $openGraph->useTwitterCard()
    ->setCard('summary')
    ->setSite('https://umanskyi.com')
    ->setCreator('Vlad Umanskyi')
    ->render();