Saturday, March 3, 2012
Pick a video, Find a video
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
Saturday, November 22, 2008
Full Explanation of Chilipress
How does it works
Saving external RSS feeds to local database Web page automatically downloads all required RSS feeds to its local RSS feeds database once in less than every hour. With this decision web page reduced unnecessary internet traffic and relieve both web servers (local and remote one – which offers RSS feeds).This is done with so called Cronjob (a Linux time-based scheduling service), which runs once every 40 minutes every day in every day of the year and has following syntax:
*/40 * * * * wget -r chilipress/cronjob>/dev/null 2>&1
These Cronjob runs PHP scrip which downloads all required external RSS feeds (e.i.: Reuters feed, or CNN feed) to local RSS database. PHP script is also able sending information to an Email if an error during receiving or saving remote RSS feeds occurred (if there is some problem with database or RSS feeds attainability):
if (@fopen($array[$i],"r")) { $rss_external_feed = file_get_contents($array[$i]); if (is_writable($filename)) { if (!$handle = fopen($filename, 'w')) { mail("email@domain.com", "Databse read error.", "From: email@domain.com"); exit; } if (fwrite($handle, $rss_external_feed) === FALSE) { mail("email@domain.com", "Databse write error.", "From: email@domain.com"); exit; } } else { mail("email@domain.com", "RSS feed unreachable.", "From: email@domain.com"); exit; }
Quick explanation:
- $array[$i] is array of all RSS feeds links and
- $filename is the name of database.
The good and very important thing by this script is that if a PHP error occurred, this script will not stop and will just hop over current error. This is done with following syntax:
- if (fwrite($handle, $rss_external_feed) === FALSE) and
- exit; .
Transform RSS feed to HTML page
When visitor opens any webpage (Technology Topics) quite complexes PHP script starts. This script has to reorder RSS feed in-to logic shape, remove unimportant data and add all important and appropriate HTML code.
Here is an brief and very shorten example for CNet RSS feeds:
$limit = count($rss_channel["ITEMS"]); for($i < $limit) ; $i++) { $rss_text = html_entity_decode($rss_channel["ITEMS"][$i]["DESCRIPTION"]); $rss_date = html_entity_decode($rss_channel["ITEMS"][$i]["PUBDATE"]); $rss_link = $rss_channel["ITEMS"][$i]["LINK"]; $rss_title = $rss_channel["ITEMS"][$i]["TITLE"]; echo "$rss_title $rss_text Published on: $rss_date"; }
Quick explanation:
- for($i < $limit) ; $i++) { … } with this for loop we achieve reading of RSS feed items (unique stories of feed) so many times as there the number of items in current RSS feed is,
- $rss_channel is whole RSS feed, which you have to put in array for further handling and
- $limit is the number of items in RSS feed.
Detecting and redirecting mobile users
Detecting if visitor is using Mobile_phone or an ordinary Web browser is sometimes not so easy. Following script is not flawless but for detecting majority of mobile browsers it will work entirely.
function detect_mobile_device(){ if(stristr($_SERVER['HTTP_USER_AGENT'],'windows')&&!stristr($_SERVER['HTTP_USER_AGENT'],'windows ce')) { return false; } if(eregi('up.browser|up.link|windows ce|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp',$_SERVER['HTTP_USER_AGENT'])) { return true; } if(stristr($_SERVER['HTTP_ACCEPT'],'text/vnd.wap.wml')||stristr($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml')) { return false; } if(isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])||isset($_SERVER['X-OperaMini-Features'])||isset($_SERVER['UA-pixels'])) { return false; } $a = array('acs-','alav','alca','amoi','audi','aste','avan','benq','bird','blac','blaz','brew','cell', 'cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c', 'lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp', 'nec','newt','noki','opwv','palm','pana','pant','pdxg','phil','play','pluc','port','prox', 'qtek','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie','siem','smal', 'smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda', 'w3c ','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-'); if(isset($a[substr($_SERVER['HTTP_USER_AGENT'],0,4)])) { return false; } } }
Quick explanation:
- detect_mobile_device() in this function is written down if detected Web browser is mobile or not; if this function returns value ‘true’ it means that the visitor is using mobile browser and for an ordinary web browser it will returns value ‘false’.
Your personal Scrapbook
User can save any RSS feed to his private Scrapbook. This can be simple done with just one click and without any annoying registration and/or email verification. Next to every RSS feed’s title there is small blue arrow. If you click on it once, your favorite story (its link and title) will be saved to your private Scrapbook. The only think which must be enabled in your browser is cookies.
Important: cookie has its limitations; therefore you can save up to 20 famous stories.
Tip - how to enable cookies in your web browser
Enable cookies in your web browser, please follow the instructions below. Enabling cookies in your web browser will not harm your computer or make it sensitive for viruses or spam.- Microsoft Internet Explorer 6.0+ / 7.0+
- Microsoft Internet Explorer 5.x
- Mozilla Firefox (1.0 final release and earlier)
- Netscape 7.1 / Mozilla 5.0
- Netscape Communicator 4.x