mpalourdio/zf2-twitter-widget

ZF2 视图助手,用于轻松显示 Twitter 时间线小部件

0.2.0 2017-04-08 20:08 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:13:31 UTC


README

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight PHP 7.0+ MIT Licensed

zf2-twitter-widget

ZF2 视图助手,用于在 ZF2 项目中轻松显示嵌入的 Twitter 时间线小部件。基于此库: https://github.com/mpalourdio/TwitterWidgets

需求

PHP 7.0+ - 仅支持 Composer 安装

安装

运行以下命令通过 Composer 安装

composer require mpalourdio/zf2-twitter-widget

将 "ZfTwitterWidget" 添加到 application.config.php 中的 模块列表

使用方法

    1. 在此处创建时间线小部件: https://twitter.com/settings/widgets/new
    1. 在生成的 JavaScript 代码中,获取 URL 和 data-widget-id(所需的最小信息)
    1. 最后,在视图中使用以下方式
echo $this->tw(
        [
            'dataWidgetId' => '1245687955000', => the id must be a string (quotes), because of long integer converted to float
            'href'         => 'https://twitter.com/NickName',
            'hrefText'     => 'Here type a title'
        ],
        true/false (true is default)
    );

以下所有选项都受处理: https://dev.twitter.com/web/embedded-timelines#options

它们的 PHP 相当于数组键,用于在视图助手中使用

'class'           => 'A css class, by default it will be twitter-timeline',
'href'            => 'The link to the timeline',
'hrefText'        => 'A title for your timeline to display',
'dataWidgetId'    => 'Your data widget ID : must be a string (!)',
'dataTheme'       => 'ex: dark',
'dataLinkColor'   => 'ex: #cc0000',
'width'           => 300 (integer),
'height'          => 400 (integer),
'dataChrome'      => 'noheader nofooter noborders noscrollbar transparent', => a string with options separated by a single space
'dataBorderColor' => 'border color used by the widget',
'language'        => 'The widget language detected from the page, based on the HTML lang attribute of your content. You can also set the HTML lang attribute on the embed code itself.',
'dataTweetLimit'  => 20,
'dataRelated'     => 'benward,endform',
'dataAriaPolite'  => 'polite or assertive',

您可以提供一个 TwitterWidgets\Options\WidgetOptions 实例,而不是数组(或任何 TwitterWidgets\Timeline\WidgetOptionsInterface 的实现)。

$options = new TwitterWidgets\Options\WidgetOptions();
$options->setDataWidgetId('1245687955000');
$options->setHref('https://twitter.com/NickName');
$options->setHrefText('Here type a title');
echo $this->tw($options);

视图助手的第二个参数是布尔值(默认为 true),表示您是否必须渲染小部件的 JavaScript 代码。如果您在页面上有多个小部件,请使用 OneTimeJsViewHelper 来只添加一次 JavaScript 代码,就在 </body> 之前。这将避免一些开销。请参阅 https://dev.twitter.com/web/javascript/loading

$this->inlineScript()->captureStart();
echo $this->twJS();
$this->inlineScript()->captureEnd();