umanskyi31/opengraph 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

umanskyi31/opengraph

Composer 安装命令:

composer require umanskyi31/opengraph

包简介

Created a new component for Yii2. The Open Graph component for your website

README 文档

README

Yii2.x Open Graph

Build Status StyleCI Total Downloads Latest Stable Version License: MIT

Created a new component for Yii2. The Open Graph component for your website

Installation

composer require umanskyi31/opengraph

or add

"umanskyi31/opengraph": "^3.0.0"

to the require section of your composer.json file.

Configuration

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

Usage

You should add component to controller before rendering view.

Example:

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

How to use

Add basic attributes:

/**
 * @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:

/**
 * @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:

/**
 * @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:

/**
 * @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:

/**
 * @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:

/**
 * @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:

/**
 * @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:

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

Add video attribute:

/**
 * @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

/**
 * @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

If you have any issue please let me know.

umanskyi31/opengraph 适用场景与选型建议

umanskyi31/opengraph 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.82k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2018 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「extension」 「facebook」 「seo」 「component」 「opengraph」 「open-graph」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 umanskyi31/opengraph 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 umanskyi31/opengraph 我们能提供哪些服务?
定制开发 / 二次开发

基于 umanskyi31/opengraph 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9.82k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-19