📜 ⬆️ ⬇️

TwittReader - Tweets on your site


I spread my bike with:


Requirements: PHP5, cURL, DOMDocument.

In essence, this is a wrapper class for an individual twitter twitter user.

Class properties


')
PropertyDefault valueDescription
cacheFiletwitter.txtthe file where the class will store the cache
cachePeriod1800the time after which the cache will expire and the tweets will be updated (in seconds)
timeoutfivetime in seconds after which it will be considered that the server is unavailable
twittsMaxCount9the number of tweets that display
twittWrapper<li> <p> [status] </ p> <p> <a href= \" [link \ \> [date] </a> </ p> </ li> \ n
Tweet template with [status], [link] and [date] variables
dateFormatdmY H: i: sdate format
errorNotAvailableService not available.message that is displayed when the server is unavailable and there is no cache
errorNoStatusesNo statuses found for this user.message that is displayed when a user has no tweets detected
curlOptionsarray (), that is, an empty arrayif you want to set additional properties for CURL, for example work through a proxy
charsetFALSE, that is, UTF-8 encoding remainsif set, then the tweet will be encoded into the appropriate encoding
highlightUrlsFALSEhighlight links
highlightEmailsFALSEhighlight the e-mail (I do not recommend, of course, because of the spammers, but maybe someone will come in handy :)
highlightUsersFALSEHighlight Twitter users like
highlightHashtagsFALSEhighlight the so-called hashtags like #tag


Examples of using



We display the last 9 user statuses:

$ tr = new TwittReader ( 'user' ) ;
echo '<ul>' . $ tr -> getTwitts ( ) . '</ ul>' ;


Now we will adjust a little under ourselves:

$ tr = new TwittReader ( 'user' ) ;

$ tr -> dateFormat = 'H: i' ; // show only tweet time
$ tr -> twittWrapper = "<li> <strong> [date] </ strong> [status] </ li>" ; // change the tweet template
$ tr -> twittsMaxCount = 3 ; // display the last three tweets
$ tr -> cachePeriod = 60 ; // cache expires after one minute
$ tr -> highlightUsers = TRUE ; // highlight users
$ tr -> highlightUrls = TRUE ; // highlight links
$ tr -> highlightHashtags = TRUE ; // highlight hashtags

$ tr -> charset = 'windows-1251' ; // encoding

// possible mistakes
$ tr -> errorNotAvailable = '<span class = "error"> Server is not available. </ span>' ;
$ tr -> errorNoStatuses = '<span class = "error"> No tweets. </ span>' ;

// use proxy
$ tr -> curlOptions = array (
CURLOPT_PROXY => "127.0.0.1 ل128 "
) ;

echo '<ul>' . $ tr -> getTwitts ( ) . '</ ul>' ;


Download (2.8 KB)
Google Code Project

Source: https://habr.com/ru/post/72144/


All Articles