@Maadinsh
Es varu dabūt html no https://coding.lv/read/jaunakie-tviti-no-twitter-com demo?
SuPeRgOvS miniblogs
- 0
SuPeRgOvS 07.01.2013. 17:29
- 0
Nesapratu... tev vajag tās lapas html kodu?
- 0
Nafig?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Random site</title>
<link rel="stylesheet" href="Web.css" type="text/css" />
<ul id="menu">
<li>
<a href="Web.html">
<strong>Home</strong>
</a>
</li>
<li>
<a href="#">
<strong>Junk</strong>
</a>
</li>
<li>
<a href="Twitter.html">
<strong>Twitter</strong>
</a>
</li>
<li>
<a href="#">
<strong>Noder</strong>
</a>
</li>
</ul>
</head>
<body>
<?php
/*
* Nolasa jaunakos lietotaja tvitus no twitter.com un uzgenere HTML listu ar kešošanu faila.
*
* Argumenti:
* username - twitter lietotajs (obligats)
* count - cik tvitus radit
* cache_dir - mape, kura rakstit kešu, jabut rakstamai
* cache_time - intervals starp cache atjaunošanu, sekundes
* title_sufx - teksts pec username, virsraksta
*
* Autors Maadinsh, 2011 - https://coding.lv
*
* Lieto kur un ka gribi, uz savu galvu ;)
*
*/
function get_twitter_list($username, $count = 10, $cache_dir = 'cache/', $cache_time = 300, $title_sufx = 'jaunakie tviti') {
$cache_file = $cache_dir . 'twitter-' . md5($username);
$cache_created = filemtime($cache_file);
/*ja kešs ir vecaks par $cache_time, updatojam*/
if (!$cache_created or (time() - $cache_created) > $cache_time) {
/*lasa no twitter*/
$xml = simplexml_load_file('https://api.twitter.com/1/statuses/user_timeline/' . $username . '.xml?count=' . $count);
if ($xml) {
/*ja sanak nolasit twitter feedu, taisa html*/
$out = '<h3 class="twitter-title">' . htmlspecialchars($username) . ' ' . $title_sufx . '</h3><ul class="twitter-posts">';
foreach ($xml->status as $tweet) {
$out .= '<li>' . $tweet->text . '</li>';
}
$out .= '</ul>';
/*ieraksta html faila, lai nakamreiz nav jatramda twitteri*/
$cache_handle = fopen($cache_file, 'wb');
fwrite($cache_handle, $out);
fclose($cache_handle);
} else {
if ($cache_created) {
/*ja nesanak nolasit no twitter (parslodze vai citi gluki), rada veco kešu*/
$out = file_get_contents($cache_file);
} else {
/*nu ir dimba, nav ne keša, ne twittera*/
$out = '<!-- Opa! Kads saplesa twitteri :o -->';
}
}
} else {
/*ielasa gatavu html no keša*/
$out = file_get_contents($cache_file);
}
return $out;
}
echo get_twitter_list('Maadinsh');
</body>
</html>
http://supergovs.comuf.com/Twitter.php
Ielogojies vai izveido profilu, lai komentētu!