Saturday, March 3, 2012

Saturday, November 22, 2008

Full Explanation of Chilipress

Originally first official Chili press magazine was announced almost at the beginning of second World ware – in the middle of the year 1940 in New York. Magazine published successfully weekly till the end of first quarter of the year 1958 (exactly 20 of March 1958). It can be still found in New York State Library NY 88 Rochester 93-32195 under OCLC [Online Computer Library Center] number 10905866.

Nowadays web page aggregator ChiliPress or Chili Press may be a few months old, but this side is trying to continue successful story of quarter century long endeavour of Chili press magazine, therefore the side just keeps getting cooler and cooler. The general ChiliPress‘s service (XML reader) is remarkably feature rich and designed for all web browsers, including newborn Google Chrome. Webpage is trying to organize - “Mashup (web application hybrid)” of all daily news from most popular RSS feeds in to logical topics, such as business or technology.

Users can hover over items for a preview of the whole feeds story from a long list of world most popular news web sites. By clicking on blue arrow, user can save interesting story (actually its link) to his private ScrapBook, which based on HTTP cookie (that means it can be not seen from other computers).

There's also a Mobile web version too, which detects if a browser is mobile and redirect him to adapted mobile version (which is just couple of kB – kilo Byte big and does contain no pictures).

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+

  • Select "Internet Options" from the Tools menu.
    Click on the "Privacy" tab.
    Click the "Default" button (or manually slide the bar down to "Medium") under "Settings".
    Click "OK" to save changes.

  • Microsoft Internet Explorer 5.x

  • Select "Internet Options" from the Tools menu.
    Click on the "Security" tab.
    Click the "Custom Level" button.
    Scroll down to the "Cookies" section.
    To enable:
    Set "Allow cookies that are stored on your computer" to "Enable".
    Set "Allow per-session cookies" to "Enable".
    Click "OK" to save changes.

  • Mozilla Firefox (1.0 final release and earlier)

  • Go to the "Tools" menu.
    Select "Options".
    Select the "Privacy" icon in the left panel.
    Check the box corresponding to "Allow sites to set cookies".
    Click "OK" to save changes.

  • Netscape 7.1 / Mozilla 5.0

  • Select "Preferences" from the Edit menu.
    Click on the arrow next to "Privacy & Security" in the scrolling window to expand.
    Under "Privacy & Security", select "Cookies".
    Select "Enable all cookies".
    Click "OK" to save changes.

  • Netscape Communicator 4.x

  • Select "Preferences" from the Edit menu.
    Find the "Cookies" section in the "Advanced" category.
    To enable:
    Select "Accept all cookies" (or "Enable all cookies").
    Click "OK" to save changes.

Other Resources

Sourced in part to Wikipedia