2017 © Pedro PelĂĄez
 

symfony-bundle knp-last-tweets-bundle

Symfony2 bundle to easily add a widget with the latest tweets of a Twitter user to a page.

image

knplabs/knp-last-tweets-bundle

Symfony2 bundle to easily add a widget with the latest tweets of a Twitter user to a page.

  • Monday, July 18, 2016
  • by Knplabs
  • Repository
  • 26 Watchers
  • 34 Stars
  • 11,031 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 16 Forks
  • 5 Open issues
  • 4 Versions
  • 3 % Grown

The README.md

DEPRECATED

Unfortunately we decided to not maintain this project anymore (see why). If you want to mark another package as a replacement for this one please send an email to hello@knplabs.com., (*1)

KnpLastTweetsBundles

Warning

the bundle is working only with OAuth driver because of twitter api v.1 retirement old users needs update abraham/twitteroauth using composer update abraham/twitteroauth, (*2)

This Symfony2 bundle will allow you to easily add a visual widget with the last tweets of the Twitter users to your page., (*3)

Build Status, (*4)

Note that tweets are transformed so that links are clickable., (*5)

Installation

Add KnpLastTweetsBundle in your composer.json, (*6)

{
    "require": {
        "knplabs/knp-last-tweets-bundle": "*"
    }
}

Register the bundle in your app/AppKernel.php:, (*7)

<?php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Knp\Bundle\LastTweetsBundle\KnpLastTweetsBundle(),
    );
)

Buzz is required to use this bundle., (*8)

Usage

After installing the bundle, just do:, (*9)

{% render "KnpLastTweetsBundle:Twitter:lastTweets" with {'username': 'knplabs'} %}

Or if you want use combined feed:, (*10)

{% render "KnpLastTweetsBundle:Twitter:lastTweets" with {'username': ['knplabs', 'knplabsru']} %}

In that case tweets will be sorted by date., (*11)

Configuration

You will now have to configure the bundle to use one of the three available drivers., (*12)

Api driver

The simplest driver is the api driver: it calls twitter API at each request., (*13)

# app/config.yml
knp_last_tweets:
    fetcher:
        driver: api

This is the default - you don't even have to add the previous config to app/config.yml.
But it's obviously not peformant in production., (*14)

OAuth driver

The oauth_driver uses InoriTwitterAppBundle. First you should configure and install it., (*15)

Then you are freely to set it in config:, (*16)

# app/config.yml
knp_last_tweets:
    fetcher:
        driver: oauth

Doctrine Cache driver

The doctrine_driver uses DoctrineCache. First you should configure and install it., (*17)

Then you are freely to set it in config:, (*18)

# app/config.yml
knp_last_tweets:
    fetcher:
        driver: doctrine_cache
        options:
            cache_service: my_doctrine_cache_service #must be a valid doctrine cache

you could use LiipDoctrineCacheBundle for configuring your caches., (*19)

Zend_Cache driver

The zend_cache driver uses Zend_Cache to cache the last tweets in a Zend_Cache_Backend (file, APC, memcached
)., (*20)

You will need to install KnpZendCacheBundle first and configure it:, (*21)

# app/config.yml
knp_zend_cache:
    templates:
        knp_last_tweets:
            frontend:
                name: Core
                options:
                    lifetime: 300
                    automatic_serialization: true
            backend:
                name: File
                options:
                    cache_dir: %kernel.root_dir%/cache/%kernel.environment%

knp_last_tweets:
    fetcher:
        driver: zend_cache
        options:
            cache_name: knp_last_tweets
            method: api # or oauth

This will only call the twitter api after a minimum of 300 seconds., (*22)

The force-fetch command

Caching is good. But once in a while (well one every 5 minutes in the previous case and if you have a continuous flow a visits), one of your visitor will have to wait 2 unnecessary seconds while the server calls twitter API., (*23)

To avoid that, you should launch a cron job every 4 minutes which will force the fetching and caching of the new tweets, (*24)

php app/console knp-last-tweets:force-fetch knplabs

This way, you will never make your visitors wait!, (*25)

Array driver

The array driver uses dummy data and does not call the twitter API., (*26)

It will return you 10 fake tweets - perfect in development., (*27)

# app/config.yml
knp_last_tweets:
    fetcher:
        driver: array

Recommendations

  • Use the array driver in development (edit your app/config_dev.yml file)
  • Use the zend_cache or doctrine_cache driver in production (edit your app/config.yml file)
  • Use the force-fetch command in a cron job in production
  • Use HTTP caching if you know what this is about and if performance is really important to you!
  • Use the oauth driver if you have problems with limits.

Advanced usage: HTTP caching

Please note that the following is not necessary: you should be perfectly fine without it., (*28)

You can use HTTP caching and ESI if you want the lastTweets action to be rendered as an ESI tag., (*29)

This will improve performance by using a cached version of the whole rendered block - even in a dynamic page., (*30)

Follow the instructions on symfony.com and use the following code in your templates:, (*31)

{% render "KnpLastTweetsBundle:Twitter:lastTweets" with {'username': ['knplabs', 'knplabsru'], 'age': 5}, {'standalone': true} %}

Credits

  • Initial work has been done by KnpLabs

License

KnpLastTweetsBundle is released under the MIT License. See the bundled LICENSE file for details., (*32)

The Versions

18/07 2016

dev-master

9999999-dev http://github.com/KnpLabs/KnpLastTweetsBundle

Symfony2 bundle to easily add a widget with the latest tweets of a Twitter user to a page.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle knplabs twitter tweets knp

22/04 2015

dev-feature/add-mit-license

dev-feature/add-mit-license http://github.com/KnpLabs/KnpLastTweetsBundle

Symfony2 bundle to easily add a widget with the latest tweets of a Twitter user to a page.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle knplabs twitter tweets knp

14/03 2013

dev-feature/refactoring

dev-feature/refactoring http://github.com/KnpLabs/KnpLastTweetsBundle

Symfony2 bundle to easily add a widget with the latest tweets of a Twitter user to a page.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle knplabs twitter tweets knp

25/07 2012

1.0

1.0.0.0 http://github.com/KnpLabs/KnpLastTweetsBundle

Symfony2 bundle to easily add a widget with the latest tweets of a Twitter user to a page.

  Sources   Download

MIT

The Requires

 

The Development Requires

bundle knplabs twitter tweets knp