dorsetdigital/silverstripe-simpleinstagram

获取特定用户的Instagram动态,以便在模板中嵌入

安装次数: 7,125

依赖: 0

建议者: 0

安全: 0

星标: 4

关注者: 2

分支: 0

开放问题: 5

类型:silverstripe-vendormodule

v1.0.1 2018-07-03 22:28 UTC

This package is auto-updated.

Last update: 2024-09-06 23:57:01 UTC


README

获取特定用户的Instagram动态,以便在SilverStripe模板中嵌入

Scrutinizer Code Quality Build Status License Version

此模块是Instagram用户动态PHP库的一个简单包装器

要求

  • Silverstripe 4.x
  • pgrimaud/instagram-user-feed 5.x

安装

  • 使用 composer require dorsetdigital/silverstripe-simpleinstagram 安装代码
  • 运行 dev/build?flush 更新您的项目

使用方法

要使用此模块,您需要在模板及其关联的模型中添加一些代码。Instagram用户名在实例化类时作为(必需)参数传递。例如,如果您想为'natgeo' Instagram账户添加一个动态到您的HomePage类中

<?php

use DorsetDigital\SimpleInstagram\InstagramHelper;

class HomePage extends Page
{

 public function getInstagramFeed()
 {
  $insta = InstagramHelper::create('natgeo');
  return $insta->getFeed();  
 }
}

然后,在您的HomePage.ss文件中,您可以使用以下语法来显示数据

 <% with $InstagramFeed %>   
 <h2 class="instagram__username">$FullName ($UserName)</h2>
 <a href="$Link">
  <img src="$ProfileImage" alt="Profile Image"/>
 </a>
 <p class="instagram__biotext">$Bio</p>
 <p class="instagram__stats">Followers: $Followers  /  Following: $Following</p>
 <% loop $Items %>
  <div class="instagram__post-holder">
  <a href="$Link" target="_blank" title="Link to Instagram post">
   <img src="$ThumbURL" alt="$Caption" class="$Type instagram__postimage"/>
   <p class="instagram__caption">$Caption</p>
   <p class="instagram__likes">Liked: $Likes</p>
   <p class="instagram__date">Posted: $Date</p>
  </a>
 </div>
 <% end_loop %>
 <% end_with %>

上面的标记仅用于示例目的。您可以根据项目需求对其进行格式化/样式设计。

性能

为了减少对外部服务的依赖并提高效率,该模块支持通过标准的SilverStripe机制进行缓存。缓存默认禁用,但可以通过向项目中添加yml配置来启用,例如

---
Name: instagramcache
---

DorsetDigital\SimpleInstagram\InstagramHelper:
  enable_cache: true
  cache_time: 900

通过将 enable_cache 设置为 true 启用缓存。使用 cache_time 设置缓存时间(以秒为单位)