mpalourdio/twitter-widgets

PHP library that helps rendering twitter embedded timelines

0.2.0 2017-04-08 19:48 UTC

This package is not auto-updated.

Last update: 2024-11-09 17:14:14 UTC


README

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

TwitterWidgets

PHP library that helps rendering twitter embedded timelines

Requirements

PHP 7.0+ - Only Composer installation supported

Installation

Run the command below to install via Composer

composer require mpalourdio/twitter-widgets

Usage

$widgetOptions = new WidgetOptions($options);
$userTimeline  = new TimelineBuilder($widgetOptions);
echo $userTimeline->renderWidget();

$options can handle these parameters : https://dev.twitter.com/web/embedded-timelines#options

Their PHP equivalent as array keys to use in the $options array are :

'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',

The TimelineBuilder#renderWidget() method accepts a boolean to disable the javascript code added to each widget. Useful if you have more that one widget to avoid JS overhead.

When disabled, to add only once the needed javascript to your HTML code, use OneTimeJsProvider#getOneTimeWidgetJs() just before your </body>

More information here : https://dev.twitter.com/web/javascript/loading

ZF2

A ZF2 view helper is available here : https://github.com/mpalourdio/zf2-twitter-widget

TWIG

A twig extension is available here : https://github.com/mpalourdio/TwitterWidgetBundle