Yesterday's News Archive

Custom Search

News Finder

Enter topic, city or zip or try our Advanced Search
 
DSC00733 - Nature - Clouds
DSC00733 - Nature - Clouds
Nature - Clouds Photos - DSC00733
World Photos - www.worldinphotos.com             World Photos - www.worldinphotos.com
 
Featured Services at www.worldofnews.com
Stock Quotes
Stock Quotes www.stockquoteusa.com
Eg. MSFT, GOOG, YHOO
Symbol Lookup
Jobs and careers - www.ejobwizard.com
Jobs, Careers www.jobsncareers.com
Over 500 job sites
WHAT

Job title, keywords or company name
WHERE(optional)

city, state or zip
Coupons, online coupons, internet coupons, discount coupons
Coupons, online coupons,
internet coupons,
discount coupons

Local classifieds, Local jobs, Local Business
Local classifieds,
Local jobs,
Local Business

Real Estate Web Design, Hosting, and Promotion with The Real Estate Listing Manager
Real Estate Web Design,
Hosting, and Promotion.

Web design, Custom WebSites, Content Manager, eCommerce, SEO.
Web design, Custom WebSites,
Content Manager,
eCommerce, SEO.

Indian news, headlines - www.indiasnews.com
Indian News

India, India News, Hotels, Tourism - www.india.tm
India, India News, Hotels, Tourism
Online Profiles, Personal Profiles Create Your Search Engine Profile - www.whataboutu.com
Online Profiles, Personal Profiles Create Your Search Engine Profile
People Profiles, Celebrity Profiles Create Your Profile - www.peopleandprofiles.com
People Profiles, Celebrity Profiles Create Your Profile
Local Merchants Stay Local Deal Global with MerchantSpan.com - www.merchantspan.com
Local Merchants Stay Local Deal Global with MerchantSpan.com


More

X-Powered-By: PHP/5.2.9 Content-type: text/html ###!c:/perl/bin/perl.exe BEGIN { push( @INC, "libs" ); } print "Content-Type: text/html\n\n"; #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # Test CPU load use strict; #use warnings; use CGI; use Sys::CpuLoad; my $q = new CGI(); my $skip_cache = $q->param( "skipcache" ); if ( ($ENV{'HTTP_USER_AGENT'} !~ /Googlebot/) && ($ENV{'HTTP_USER_AGENT'} !~ /msnbot/) && ($ENV{'HTTP_USER_AGENT'} !~ /Yahoo\! Slurp/) && ($ENV{'HTTP_USER_AGENT'} !~ /Twiceler/) && ($skip_cache ne 'y') ){ my $min_cpu_load = 2; my $max_cpu_load = 5; my @cpu_load_array = Sys::CpuLoad::load(); # Prevent CPU overloading my $tmp_title = $q->param('title'); $tmp_title =~ s/\-/ /g; if ($cpu_load_array[0] > $max_cpu_load) { print_server_busy_message($tmp_title); } if ($ENV{'HTTP_USER_AGENT'} =~ /(bot[^t]|bot$)/){ if ($cpu_load_array[0] > $min_cpu_load) { print_server_busy_message($tmp_title); } } } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: use DBI; use Data::Dumper; use HTML::Entities; use common_libs; use Switch; use PHP::Serialization qw(serialize unserialize); use Time::Local; use POSIX qw(ceil); # Define main variables my $option = $q->param( "option" ); # Debug message #if ($skip_cache ne 'y') { print("Server under maintenance !"); exit(); } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #NOTE: #the public_html directory must have 0751 rights (not 0777) my $worldnewxRootFolder = "/home/worldnew/public_html"; #my $worldnewxRootFolder = "e:/inetpub/wwwroot/worldnewx.com/"; my $worldofnewsRoot = "http://worldofnews.com/index.pl"; my $cache_dir = "/usr/local/cache/won"; #my $cache_dir = "e:/inetpub/wwwroot/worldnewx/cache"; my $config_file_path = "config.xml"; my $template_index = "index.tpl"; my $news_search_link = "http://wssearch.worldnewx.com/ws_search.pl?apikey=worldnewx.com-1277066279"; my $source_list_link = "http://wssearch.worldnewx.com/gapi/index.php?option=exp_slst"; my $category_list_link = "http://wssearch.worldnewx.com/gapi/index.php?option=exp_clst"; my @current_time = localtime(); my $ch = $current_time[ 2 ]; my $cm = $current_time[ 1 ]; my $cs = $current_time[ 0 ]; my $time_in_minutes = $ch * 60 + $cm; my %aArchiveIndex = ( "a" => 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5, "f" => 6, "g" => 7, "h" => 8, "i" => 9, "j" => 10, "k" => 11, "l" => 12, "m" => 13, "n" => 14, "o" => 15, "p" => 16, "q" => 17, "r" => 18, "s" => 19, "t" => 20, "u" => 21, "v" => 22, "w" => 23, "x" => 24, "y" => 25, "z" => 26 ); #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #Create and initialize debug object my $DBG = new DEBUG(); $DBG->set_flag( 0 ); #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ my $keyword = $q->param( "keyword" ); my $cat = $q->param( "cat" ); my $bottom_menu_id = $q->param( 'bottom_menu_id' ); my $start_record = $q->param( "s" ); my $news_id = $q->param( "nid" ); $keyword = '' unless defined $keyword; $cat = "Top Stories" unless defined $cat; $option = '' unless defined $option; $bottom_menu_id = '' unless defined $bottom_menu_id; $start_record = 0 unless defined $start_record; $start_record = ( $start_record < 0 ) ? 0 : $start_record; $skip_cache = 'n' unless defined $skip_cache; my $is_first_page = get_first_page_flag( $q ); #Define global script variables for sql queries my $dbh = init_database( $config_file_path ); my $sql; my $sth; my $pps = 18; #pages per sheet #Normalize the time my $step = int( $time_in_minutes / 5 ); my $exact_time = $step * 5; my $show_nav_bar = 0; my $cache_file_name = create_cache_file_name( $cat, $keyword, $news_id, $option, $start_record, $bottom_menu_id ); my $tmp_cache_file_name = ""; #used for hold a temporary unique cache file name #............................................. my $cache_content = ""; my $is_collecting_cache = 'n'; # #Try to get content from cache # my $cache_time = 600; if ( $option eq 'view' ) { $cache_time = 3600 * 24 * 30; visit_news( $news_id ); #$skip_cache = 'y'; } if ( $option eq 'search' ) { $skip_cache = 'y'; } #if ($option eq 'site_map') { $skip_cache = 'y'; } #if ($option eq 'google') { $skip_cache = 'y'; } if ( $skip_cache eq 'n' ) { $DBG->show( "" ); #debug hidden text ( Get From Cache : ) $cache_content = try_to_get_cache( $cache_file_name ); if ( $cache_content ne '' ) { $cache_content = add_comments( $cache_content ); $cache_content = add_visiads( $cache_content, $option ); $cache_content = add_ad_manager( $cache_content, $option ); print $cache_content; $DBG->show( "" ); #debug hidden text ( No ) exit(); } } $DBG->show( "" ); #debug hidden text ( No ) $tmp_cache_file_name = start_collect_cache( $cache_file_name ); $is_collecting_cache = 'y'; ################################################################################ ################################################################################ my @category_array = get_categories_array( $dbh, 1 ); my $wnl_tpl = HTML::Template->new( filename => "templates/$template_index", global_vars => 1 ); $wnl_tpl->param( "first_page_flag" => $is_first_page ); # #Get the image from WorldInPhotos.com # my $WIP_Img = ""; eval { $WIP_Img = get_worldinphotos_image(); $wnl_tpl->param( WIP_Link => $WIP_Img->{ 'images_list' }[ 0 ]{ 'link' } ); $wnl_tpl->param( WIP_Photo => $WIP_Img->{ 'images_list' }[ 0 ]{ 'photo' } ); $wnl_tpl->param( WIP_Title => $WIP_Img->{ 'images_list' }[ 0 ]{ 'title' } ); $wnl_tpl->param( WIP_Category => $WIP_Img->{ 'images_list' }[ 0 ]{ 'category' } ); }; if ( $@ ) { } # #Get the list of channels for World Channels # # - construct the categories arrays for two rows display (right side) my @category_array_l = (); my @category_array_r = (); my $half_way = int( $#category_array / 2 ); for ( my $i = 0 ; $i <= $#category_array ; $i++ ) { if ( $i <= $half_way ) { push( @category_array_l, $category_array[ $i ] ); } else { push( @category_array_r, $category_array[ $i ] ); } } #Assign variables to template $wnl_tpl->param( 'category_array_l' => \@category_array_l ); $wnl_tpl->param( 'category_array_r' => \@category_array_r ); # #Create main menu # my $news_vlist_content = ""; my $ticketnetwork_ads = HTML::Template->new( filename => "templates/ticketnetwork.tpl" ); # $wnl_tpl->param( 'ticketnetwork_ads' => $ticketnetwork_ads->output() ); ########################################################## switch ( $option ) { case 'search' { my $keywords = $q->param( "keywords" ); my $category = $q->param( "category" ); my $source = $q->param( "source" ); my @tmp_news_aray = (); my @news_array; my $nav_bar = ""; if ( $keywords ne '' ) { #Search by keyword @news_array = get_and_unserialize( $news_search_link . "&opt=kwd&nr=$pps&k=$keywords&start=$start_record" ); if ( !$news_array[ 0 ]->{ Error } ) { @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; $news_vlist_content = create_news_list_content( \@tmp_news_aray ); } #Calculate the number of pages if ( $#tmp_news_aray > -1 ) { $nav_bar = get_nav_bar( $start_record, $pps, $news_array[ 0 ]->{ total_estimated } ); $show_nav_bar = 1; } else { $show_nav_bar = 0; } } elsif ( ( $category ne '' ) || ( $source ne '' ) ) { #Search by category and source @news_array = get_and_unserialize( $news_search_link . "&opt=mix&nr=$pps&c=$category&s=$source&start=$start_record" ); @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; $news_vlist_content = create_news_list_content( \@tmp_news_aray ); #Calculate the number of pages if ( $#tmp_news_aray > -1 ) { $nav_bar = get_nav_bar( $start_record, $pps, $news_array[ 0 ]->{ total_estimated } ); $show_nav_bar = 1; } else { $show_nav_bar = 0; } } else { #Display advanced search box #Get sources list my @source_name_array = get_and_unserialize( $source_list_link ); #Get categories list my @category_name_array = get_and_unserialize( $category_list_link ); #echo(Dumper(@source_name_array));exit(); #Assign to template my $search_tpl = HTML::Template->new( filename => "templates/search.tpl", global_vars => 1 ); $search_tpl->param( source_name_array => \@{ $source_name_array[ 0 ] } ); $search_tpl->param( category_name_array => \@{ $category_name_array[ 0 ] } ); $news_vlist_content = $search_tpl->output(); $tmp_news_aray[ 0 ]->{ title } = "Advanced Search"; $tmp_news_aray[ 0 ]->{ description } = "WorldOfNews.com Advanced Search"; } $wnl_tpl->param( page_title => "Advanced Search"); $wnl_tpl->param( page_keywords => get_keywords( $tmp_news_aray[ 0 ]->{ description } ) ); $wnl_tpl->param( page_description => get_description( $tmp_news_aray[ 0 ]->{ description } ) ); $wnl_tpl->param( navigation_bar => $nav_bar ); $wnl_tpl->param( show_nav_bar => $show_nav_bar ); $wnl_tpl->param( topstories_content => $news_vlist_content ); } case 'clst' { #Category list #Find out category code my $category_id = CategoryName2Id( $cat ); =debug select (STDOUT); print $news_search_link . "&opt=cat&nr=$pps&c=$category_id&start=$start_record\n"; exit(); =cut my @news_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=$pps&c=$category_id&start=$start_record" ); eval { my @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; $news_vlist_content = create_news_list_content( \@tmp_news_aray ); #Calculate the number of pages my $nav_bar = ""; if ( $#tmp_news_aray > -1 ) { $nav_bar = get_nav_bar( $start_record, $pps, $news_array[ 0 ]->{ total_estimated } ); $show_nav_bar = 1; } else { $show_nav_bar = 0; } $wnl_tpl->param( navigation_bar => $nav_bar ); }; if ( $@ ) { } $wnl_tpl->param( page_title => "$cat News, World $cat News" ); $wnl_tpl->param( page_keywords => get_keywords( "$cat News, World $cat News" ) ); $wnl_tpl->param( page_description => get_description( "$cat News, World $cat News" ) ); $wnl_tpl->param( topstories_content => $news_vlist_content ); $wnl_tpl->param( show_nav_bar => $show_nav_bar ); } case 'view' { #Item view visit_news( $news_id ); #Display the news my @tmp_arr = get_and_unserialize( $news_search_link . "&opt=arh&permaid=$news_id" ); @tmp_arr = @{ $tmp_arr[ 0 ]->{ records } }; #For option = view we need publication date not and for this we apply the following algorithm # - save the old pubdate my $tmp_pub_date = $tmp_arr[ 0 ]->{ pub_date }; # - process the record my $news_details = adjust_news_object_fields( $tmp_arr[ 0 ], 'n' ); # - process the saved date in the format we need # - restore the date property #echo($tmp_pub_date);exit(); $tmp_arr[ 0 ]->{ pub_date } = decode_mysql_date( $tmp_pub_date ); #Get news by category my $category_id = $news_details->{ cat_id }; my @news_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=6&c=$category_id" ); my @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; my $aux_topic_content = ""; foreach my $row ( @tmp_news_aray ) { $row = adjust_news_object_fields( $row, 'n' ); my $news_content = HTML::Template->new( filename => "templates/newsheadlines_layout.tpl" ); $news_content->param( 'won_link' => $row->{ won_link } ); $news_content->param( 'title' => $row->{ title } ); $news_content->param( 'source_name' => $row->{ source_name } ); $aux_topic_content .= $news_content->output(); } #Get news by source my $source = $news_details->{ source_name }; @news_array = get_and_unserialize( $news_search_link . "&opt=src&nr=6&s=$source" ); @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; my $aux_source_content = ""; foreach my $row ( @tmp_news_aray ) { my $news_content = HTML::Template->new( filename => "templates/newsheadlines_layout.tpl" ); $row = adjust_news_object_fields( $row, 'n' ); $news_content->param( 'won_link' => $row->{ won_link } ); $news_content->param( 'title' => $row->{ title } ); $news_content->param( 'source_name' => $row->{ source_name } ); $aux_source_content .= $news_content->output(); } my $newsitem_template = HTML::Template->new( filename => "templates/newsdetails_layout.tpl" ); $newsitem_template->param( id => $news_details->{ permaid } ); $newsitem_template->param( title => $news_details->{ title } ); $newsitem_template->param( description => $news_details->{ description } ); $newsitem_template->param( cname => $news_details->{ cname } ); $newsitem_template->param( enc_category => $news_details->{ enc_category } ); $newsitem_template->param( link => $news_details->{ link } ); $newsitem_template->param( won_link => $news_details->{ won_link } ); $newsitem_template->param( source_name => $news_details->{ source_name } ); $newsitem_template->param( pub_date => $news_details->{ pub_date } ); $newsitem_template->param( aux_topic_content => $aux_topic_content ); $newsitem_template->param( aux_source_content => $aux_source_content ); $wnl_tpl->param( page_title => $news_details->{ title } ); $wnl_tpl->param( page_keywords => get_keywords( $news_details->{ description } ) ); $wnl_tpl->param( page_description => get_description( $news_details->{ description } ) ); $news_vlist_content = $newsitem_template->output(); $wnl_tpl->param( topstories_content => $news_vlist_content ); } case 'site_map' { #construct site map #Get categories list my @category_name_array = get_and_unserialize( $category_list_link ); my @tmp_category_name_array = @{ $category_name_array[ 0 ] }; @category_name_array = (); foreach ( @tmp_category_name_array ) { # echo($_->{name}); $_->{ link } = $_->{ name }; $_->{ link } =~ s/^([\\__]+)//g; $_->{ link } =~ s/( +)/\+/g; push( @category_name_array, $_ ); } my $sitemap_tpl = HTML::Template->new( filename => "templates/site_map.tpl", global_vars => 1 ); $sitemap_tpl->param( tree => \@category_name_array ); $news_vlist_content = $sitemap_tpl->output(); $wnl_tpl->param( page_title => "Site Map" ); $wnl_tpl->param( page_keywords => "WorldOfNews.com Site Map" ); $wnl_tpl->param( page_description => "WorldOfNews.com Site Map" ); $wnl_tpl->param( topstories_content => $news_vlist_content ); =start echo(\@category_name_array); exit(); =cut } case 'rss' { my $category = $q->param( "cat" ); #Find out category code my $category_id = CategoryName2Id( $category ); my @tmp_news_aray = (); my @news_array = (); @news_array = get_and_unserialize( $news_search_link . "&opt=mix&nr=$pps&c=$category_id" ); @news_array = @{ $news_array[ 0 ]->{ records } }; #Workaround to not finish the output here: $wnl_tpl = HTML::Template->new( filename => "templates/rss.tpl" ); foreach ( @news_array ) { #if ( length( $_->{ description } ) > 200 ) { $_->{ description } = substr( $_->{ description }, 0, 200 ) . "..."; } if ( length( $_->{ description } ) > 200 ) { $_->{ description } = get_short_description($_->{ description }); } push( @tmp_news_aray, { 'title' => $_->{ title }, 'won_link' => $_->{ won_link }, 'description' => strip_slashes($_->{ description }), 'source_name' => $_->{ source_name }, 'pub_date' => $_->{ pub_date }, 'img' => $_->{ img }, 'cname' => $_->{ cname } } ); } $wnl_tpl->param( current_content => \@tmp_news_aray ); $wnl_tpl->param( title => $category ); my $clink = $category; $clink =~ s/( +)/\+/g; $wnl_tpl->param( 'link' => "http://www.worldofnews.com/rss/$clink" ); $wnl_tpl->param( 'description' => "$category News, World News, Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( 'logo' => 'http://www.worldofnews.com/images/logo.gif' ); $wnl_tpl->param( 'now_date_time' => ( scalar localtime( time() ) ) ); } case 'google' { my $google_tpl = HTML::Template->new( filename => "templates/google.tpl" ); $wnl_tpl->param( page_title => "World News, Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( page_keywords => "World News, Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( page_description => "World News, Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( google_page => 1 ); $wnl_tpl->param( topstories_content => $google_tpl->output() ); } case 'about_us' { my $about_us_tpl = HTML::Template->new( filename => "templates/about_us.tpl" ); $wnl_tpl->param( topstories_content => $about_us_tpl->output() ); $wnl_tpl->param( page_title => "About Us" ); } case 'terms_of_service' { my $tos_tpl = HTML::Template->new( filename => "templates/terms_of_service.tpl" ); $wnl_tpl->param( topstories_content => $tos_tpl->output() ); $wnl_tpl->param( page_title => "Terms of Service" ); } case 'privacy_policy' { my $privacy_policy_tpl = HTML::Template->new( filename => "templates/privacy_policy.tpl" ); $wnl_tpl->param( topstories_content => $privacy_policy_tpl->output() ); $wnl_tpl->param( page_title => "Privacy Policy" ); } case 'contact_us' { my $contact_us_tpl = HTML::Template->new( filename => "templates/contact_us.tpl" ); $wnl_tpl->param( topstories_content => $contact_us_tpl->output() ); $wnl_tpl->param( page_title => "Contact Us" ); } else { #Home page #Get Frontbox content my $frontbox_content .= file_get_contents( "$worldnewxRootFolder/frontbox/feeds/wnl_frontbox.htm" ); #Get Top Stories list my @news_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=$pps&c=2684354584" ); =start select(STDOUT); #print ($news_search_link . "&opt=cat&nr=$pps&c=2684354584");exit(); print Dumper(@news_array);exit(); =cut my @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; #Calculate the number of pages my $nav_bar = ""; if ( $#tmp_news_aray > -1 ) { $nav_bar = get_nav_bar( $start_record, $pps, $news_array[ 0 ]->{ total_estimated } ); $show_nav_bar = 1; } else { $show_nav_bar = 0; } $wnl_tpl->param( show_nav_bar => $show_nav_bar ); $wnl_tpl->param( navigation_bar => $nav_bar ); $news_vlist_content = create_news_list_content( \@tmp_news_aray ); #Create right section $wnl_tpl->param( 'news_by_cat' => create_right_section( $dbh ) ); $wnl_tpl->param( page_title => $tmp_news_aray[ 0 ]->{ title } ); # $wnl_tpl->param( page_keywords => get_keywords($tmp_news_aray[0]->{description}) ); # $wnl_tpl->param( page_description => get_description($tmp_news_aray[0]->{description}) ); $wnl_tpl->param( page_keywords => "Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( page_description => "Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( frontbox_content => $frontbox_content ); $wnl_tpl->param( topstories_content => $news_vlist_content ); $wnl_tpl->param( homepage => 1 ); #Create news array for bottom boxes #'Top Stories', 'Business', 'Education', 'Entertainment', 'Health', 'Law', 'Movie', 'Music', 'Sport', 'Technology', 'US', 'World' my @newscateg = ( 'topstories', 'business', 'education', 'entertainment', 'health', 'law', 'movie', 'music', 'sport', 'technology', 'us', 'world' ); foreach my $categ ( @newscateg ) { my $newsbox_tmpl = HTML::Template->new( filename => "$worldnewxRootFolder/newsbox/feeds/" . $categ . "_newsbox.htm" ); $wnl_tpl->param( $categ . "_newsbox" => $newsbox_tmpl->output() ); } } } # Calculate current date for the archive my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-86400); $year += 1900; $mon += 1; my $current_date = "$year-$mon-$mday"; $wnl_tpl->param('current_date' => $current_date); my $temporary_content = $wnl_tpl->output; =SEO FIX: Teporary took out # FIX: October 27, 2007. # Updated: 22 Aug 2008 # Reason: SEO optimization (add title on all links) # Remove all 'titles' from links $temporary_content =~ s/]+?)title ?= ?["']?([^<>]+?)(['"]|([> ]))/]+?)title ?= ?["']?([^<>]+?)['" >]/]+?)>([^<>]+?)<\/a>/$2<\/a>/gmi; # @TODO: Add 'alt' to all images =cut print $temporary_content; #print to screen but captured by cache if ( $is_collecting_cache eq 'y' ) { save_to_cache( $tmp_cache_file_name, $cache_file_name ); $temporary_content = add_comments( $temporary_content ); # $temporary_content = add_visiads( $temporary_content, $option ); # $temporary_content = add_ad_manager( $temporary_content, $option ); print $temporary_content; #print to screen } ################################################################################ ################################################################################ #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: sub add_comments { my $content = shift(); my $comments_list = get_comments_list(); $content =~ s/__ALREADY_EXISTING_COMMENTS__/$comments_list/; return $content; } sub add_visiads { my $content = shift(); my $option = shift(); my $visiads_content = ""; my @visiads_output = (); if ($option ne '') { #avoid processing for the home page # Process Visiads.com ads # catch output of PHP code my $time_processing = time(); @visiads_output = `php /home/worldofn/www/visiads/interface.php`; $visiads_content = join( "\n", @visiads_output ); $time_processing = time() - $time_processing; $visiads_content .= "\n"; } $content =~ s/__VISIADS_ADS__/$visiads_content/; return $content; } sub add_ad_manager { my $content = shift(); my $option = shift(); my $ad_manager_content = ""; my @ad_manager_output = (); if ($option ne '') { #avoid processing for the home page # Process ad manager ads # catch output of PHP code my $time_processing = time(); @ad_manager_output = `php /home/worldofn/www/adClient/interface.php`; $ad_manager_content = join( "\n", @ad_manager_output ); $time_processing = time() - $time_processing; $ad_manager_content .= "\n"; } $content =~ s/X-Powered-By: PHP/5.2.9 Content-type: text/html ###!c:/perl/bin/perl.exe BEGIN { push( @INC, "libs" ); } print "Content-Type: text/html\n\n"; #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # Test CPU load use strict; #use warnings; use CGI; use Sys::CpuLoad; my $q = new CGI(); my $skip_cache = $q->param( "skipcache" ); if ( ($ENV{'HTTP_USER_AGENT'} !~ /Googlebot/) && ($ENV{'HTTP_USER_AGENT'} !~ /msnbot/) && ($ENV{'HTTP_USER_AGENT'} !~ /Yahoo\! Slurp/) && ($ENV{'HTTP_USER_AGENT'} !~ /Twiceler/) && ($skip_cache ne 'y') ){ my $min_cpu_load = 2; my $max_cpu_load = 5; my @cpu_load_array = Sys::CpuLoad::load(); # Prevent CPU overloading my $tmp_title = $q->param('title'); $tmp_title =~ s/\-/ /g; if ($cpu_load_array[0] > $max_cpu_load) { print_server_busy_message($tmp_title); } if ($ENV{'HTTP_USER_AGENT'} =~ /(bot[^t]|bot$)/){ if ($cpu_load_array[0] > $min_cpu_load) { print_server_busy_message($tmp_title); } } } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: use DBI; use Data::Dumper; use HTML::Entities; use common_libs; use Switch; use PHP::Serialization qw(serialize unserialize); use Time::Local; use POSIX qw(ceil); # Define main variables my $option = $q->param( "option" ); # Debug message #if ($skip_cache ne 'y') { print("Server under maintenance !"); exit(); } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #NOTE: #the public_html directory must have 0751 rights (not 0777) my $worldnewxRootFolder = "/home/worldnew/public_html"; #my $worldnewxRootFolder = "e:/inetpub/wwwroot/worldnewx.com/"; my $worldofnewsRoot = "http://worldofnews.com/index.pl"; my $cache_dir = "/usr/local/cache/won"; #my $cache_dir = "e:/inetpub/wwwroot/worldnewx/cache"; my $config_file_path = "config.xml"; my $template_index = "index.tpl"; my $news_search_link = "http://wssearch.worldnewx.com/ws_search.pl?apikey=worldnewx.com-1277066279"; my $source_list_link = "http://wssearch.worldnewx.com/gapi/index.php?option=exp_slst"; my $category_list_link = "http://wssearch.worldnewx.com/gapi/index.php?option=exp_clst"; my @current_time = localtime(); my $ch = $current_time[ 2 ]; my $cm = $current_time[ 1 ]; my $cs = $current_time[ 0 ]; my $time_in_minutes = $ch * 60 + $cm; my %aArchiveIndex = ( "a" => 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5, "f" => 6, "g" => 7, "h" => 8, "i" => 9, "j" => 10, "k" => 11, "l" => 12, "m" => 13, "n" => 14, "o" => 15, "p" => 16, "q" => 17, "r" => 18, "s" => 19, "t" => 20, "u" => 21, "v" => 22, "w" => 23, "x" => 24, "y" => 25, "z" => 26 ); #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #Create and initialize debug object my $DBG = new DEBUG(); $DBG->set_flag( 0 ); #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ my $keyword = $q->param( "keyword" ); my $cat = $q->param( "cat" ); my $bottom_menu_id = $q->param( 'bottom_menu_id' ); my $start_record = $q->param( "s" ); my $news_id = $q->param( "nid" ); $keyword = '' unless defined $keyword; $cat = "Top Stories" unless defined $cat; $option = '' unless defined $option; $bottom_menu_id = '' unless defined $bottom_menu_id; $start_record = 0 unless defined $start_record; $start_record = ( $start_record < 0 ) ? 0 : $start_record; $skip_cache = 'n' unless defined $skip_cache; my $is_first_page = get_first_page_flag( $q ); #Define global script variables for sql queries my $dbh = init_database( $config_file_path ); my $sql; my $sth; my $pps = 18; #pages per sheet #Normalize the time my $step = int( $time_in_minutes / 5 ); my $exact_time = $step * 5; my $show_nav_bar = 0; my $cache_file_name = create_cache_file_name( $cat, $keyword, $news_id, $option, $start_record, $bottom_menu_id ); my $tmp_cache_file_name = ""; #used for hold a temporary unique cache file name #............................................. my $cache_content = ""; my $is_collecting_cache = 'n'; # #Try to get content from cache # my $cache_time = 600; if ( $option eq 'view' ) { $cache_time = 3600 * 24 * 30; visit_news( $news_id ); #$skip_cache = 'y'; } if ( $option eq 'search' ) { $skip_cache = 'y'; } #if ($option eq 'site_map') { $skip_cache = 'y'; } #if ($option eq 'google') { $skip_cache = 'y'; } if ( $skip_cache eq 'n' ) { $DBG->show( "" ); #debug hidden text ( Get From Cache : ) $cache_content = try_to_get_cache( $cache_file_name ); if ( $cache_content ne '' ) { $cache_content = add_comments( $cache_content ); $cache_content = add_visiads( $cache_content, $option ); $cache_content = add_ad_manager( $cache_content, $option ); print $cache_content; $DBG->show( "" ); #debug hidden text ( No ) exit(); } } $DBG->show( "" ); #debug hidden text ( No ) $tmp_cache_file_name = start_collect_cache( $cache_file_name ); $is_collecting_cache = 'y'; ################################################################################ ################################################################################ my @category_array = get_categories_array( $dbh, 1 ); my $wnl_tpl = HTML::Template->new( filename => "templates/$template_index", global_vars => 1 ); $wnl_tpl->param( "first_page_flag" => $is_first_page ); # #Get the image from WorldInPhotos.com # my $WIP_Img = ""; eval { $WIP_Img = get_worldinphotos_image(); $wnl_tpl->param( WIP_Link => $WIP_Img->{ 'images_list' }[ 0 ]{ 'link' } ); $wnl_tpl->param( WIP_Photo => $WIP_Img->{ 'images_list' }[ 0 ]{ 'photo' } ); $wnl_tpl->param( WIP_Title => $WIP_Img->{ 'images_list' }[ 0 ]{ 'title' } ); $wnl_tpl->param( WIP_Category => $WIP_Img->{ 'images_list' }[ 0 ]{ 'category' } ); }; if ( $@ ) { } # #Get the list of channels for World Channels # # - construct the categories arrays for two rows display (right side) my @category_array_l = (); my @category_array_r = (); my $half_way = int( $#category_array / 2 ); for ( my $i = 0 ; $i <= $#category_array ; $i++ ) { if ( $i <= $half_way ) { push( @category_array_l, $category_array[ $i ] ); } else { push( @category_array_r, $category_array[ $i ] ); } } #Assign variables to template $wnl_tpl->param( 'category_array_l' => \@category_array_l ); $wnl_tpl->param( 'category_array_r' => \@category_array_r ); # #Create main menu # my $news_vlist_content = ""; my $ticketnetwork_ads = HTML::Template->new( filename => "templates/ticketnetwork.tpl" ); # $wnl_tpl->param( 'ticketnetwork_ads' => $ticketnetwork_ads->output() ); ########################################################## switch ( $option ) { case 'search' { my $keywords = $q->param( "keywords" ); my $category = $q->param( "category" ); my $source = $q->param( "source" ); my @tmp_news_aray = (); my @news_array; my $nav_bar = ""; if ( $keywords ne '' ) { #Search by keyword @news_array = get_and_unserialize( $news_search_link . "&opt=kwd&nr=$pps&k=$keywords&start=$start_record" ); if ( !$news_array[ 0 ]->{ Error } ) { @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; $news_vlist_content = create_news_list_content( \@tmp_news_aray ); } #Calculate the number of pages if ( $#tmp_news_aray > -1 ) { $nav_bar = get_nav_bar( $start_record, $pps, $news_array[ 0 ]->{ total_estimated } ); $show_nav_bar = 1; } else { $show_nav_bar = 0; } } elsif ( ( $category ne '' ) || ( $source ne '' ) ) { #Search by category and source @news_array = get_and_unserialize( $news_search_link . "&opt=mix&nr=$pps&c=$category&s=$source&start=$start_record" ); @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; $news_vlist_content = create_news_list_content( \@tmp_news_aray ); #Calculate the number of pages if ( $#tmp_news_aray > -1 ) { $nav_bar = get_nav_bar( $start_record, $pps, $news_array[ 0 ]->{ total_estimated } ); $show_nav_bar = 1; } else { $show_nav_bar = 0; } } else { #Display advanced search box #Get sources list my @source_name_array = get_and_unserialize( $source_list_link ); #Get categories list my @category_name_array = get_and_unserialize( $category_list_link ); #echo(Dumper(@source_name_array));exit(); #Assign to template my $search_tpl = HTML::Template->new( filename => "templates/search.tpl", global_vars => 1 ); $search_tpl->param( source_name_array => \@{ $source_name_array[ 0 ] } ); $search_tpl->param( category_name_array => \@{ $category_name_array[ 0 ] } ); $news_vlist_content = $search_tpl->output(); $tmp_news_aray[ 0 ]->{ title } = "Advanced Search"; $tmp_news_aray[ 0 ]->{ description } = "WorldOfNews.com Advanced Search"; } $wnl_tpl->param( page_title => "Advanced Search"); $wnl_tpl->param( page_keywords => get_keywords( $tmp_news_aray[ 0 ]->{ description } ) ); $wnl_tpl->param( page_description => get_description( $tmp_news_aray[ 0 ]->{ description } ) ); $wnl_tpl->param( navigation_bar => $nav_bar ); $wnl_tpl->param( show_nav_bar => $show_nav_bar ); $wnl_tpl->param( topstories_content => $news_vlist_content ); } case 'clst' { #Category list #Find out category code my $category_id = CategoryName2Id( $cat ); =debug select (STDOUT); print $news_search_link . "&opt=cat&nr=$pps&c=$category_id&start=$start_record\n"; exit(); =cut my @news_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=$pps&c=$category_id&start=$start_record" ); eval { my @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; $news_vlist_content = create_news_list_content( \@tmp_news_aray ); #Calculate the number of pages my $nav_bar = ""; if ( $#tmp_news_aray > -1 ) { $nav_bar = get_nav_bar( $start_record, $pps, $news_array[ 0 ]->{ total_estimated } ); $show_nav_bar = 1; } else { $show_nav_bar = 0; } $wnl_tpl->param( navigation_bar => $nav_bar ); }; if ( $@ ) { } $wnl_tpl->param( page_title => "$cat News, World $cat News" ); $wnl_tpl->param( page_keywords => get_keywords( "$cat News, World $cat News" ) ); $wnl_tpl->param( page_description => get_description( "$cat News, World $cat News" ) ); $wnl_tpl->param( topstories_content => $news_vlist_content ); $wnl_tpl->param( show_nav_bar => $show_nav_bar ); } case 'view' { #Item view visit_news( $news_id ); #Display the news my @tmp_arr = get_and_unserialize( $news_search_link . "&opt=arh&permaid=$news_id" ); @tmp_arr = @{ $tmp_arr[ 0 ]->{ records } }; #For option = view we need publication date not and for this we apply the following algorithm # - save the old pubdate my $tmp_pub_date = $tmp_arr[ 0 ]->{ pub_date }; # - process the record my $news_details = adjust_news_object_fields( $tmp_arr[ 0 ], 'n' ); # - process the saved date in the format we need # - restore the date property #echo($tmp_pub_date);exit(); $tmp_arr[ 0 ]->{ pub_date } = decode_mysql_date( $tmp_pub_date ); #Get news by category my $category_id = $news_details->{ cat_id }; my @news_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=6&c=$category_id" ); my @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; my $aux_topic_content = ""; foreach my $row ( @tmp_news_aray ) { $row = adjust_news_object_fields( $row, 'n' ); my $news_content = HTML::Template->new( filename => "templates/newsheadlines_layout.tpl" ); $news_content->param( 'won_link' => $row->{ won_link } ); $news_content->param( 'title' => $row->{ title } ); $news_content->param( 'source_name' => $row->{ source_name } ); $aux_topic_content .= $news_content->output(); } #Get news by source my $source = $news_details->{ source_name }; @news_array = get_and_unserialize( $news_search_link . "&opt=src&nr=6&s=$source" ); @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; my $aux_source_content = ""; foreach my $row ( @tmp_news_aray ) { my $news_content = HTML::Template->new( filename => "templates/newsheadlines_layout.tpl" ); $row = adjust_news_object_fields( $row, 'n' ); $news_content->param( 'won_link' => $row->{ won_link } ); $news_content->param( 'title' => $row->{ title } ); $news_content->param( 'source_name' => $row->{ source_name } ); $aux_source_content .= $news_content->output(); } my $newsitem_template = HTML::Template->new( filename => "templates/newsdetails_layout.tpl" ); $newsitem_template->param( id => $news_details->{ permaid } ); $newsitem_template->param( title => $news_details->{ title } ); $newsitem_template->param( description => $news_details->{ description } ); $newsitem_template->param( cname => $news_details->{ cname } ); $newsitem_template->param( enc_category => $news_details->{ enc_category } ); $newsitem_template->param( link => $news_details->{ link } ); $newsitem_template->param( won_link => $news_details->{ won_link } ); $newsitem_template->param( source_name => $news_details->{ source_name } ); $newsitem_template->param( pub_date => $news_details->{ pub_date } ); $newsitem_template->param( aux_topic_content => $aux_topic_content ); $newsitem_template->param( aux_source_content => $aux_source_content ); $wnl_tpl->param( page_title => $news_details->{ title } ); $wnl_tpl->param( page_keywords => get_keywords( $news_details->{ description } ) ); $wnl_tpl->param( page_description => get_description( $news_details->{ description } ) ); $news_vlist_content = $newsitem_template->output(); $wnl_tpl->param( topstories_content => $news_vlist_content ); } case 'site_map' { #construct site map #Get categories list my @category_name_array = get_and_unserialize( $category_list_link ); my @tmp_category_name_array = @{ $category_name_array[ 0 ] }; @category_name_array = (); foreach ( @tmp_category_name_array ) { # echo($_->{name}); $_->{ link } = $_->{ name }; $_->{ link } =~ s/^([\\__]+)//g; $_->{ link } =~ s/( +)/\+/g; push( @category_name_array, $_ ); } my $sitemap_tpl = HTML::Template->new( filename => "templates/site_map.tpl", global_vars => 1 ); $sitemap_tpl->param( tree => \@category_name_array ); $news_vlist_content = $sitemap_tpl->output(); $wnl_tpl->param( page_title => "Site Map" ); $wnl_tpl->param( page_keywords => "WorldOfNews.com Site Map" ); $wnl_tpl->param( page_description => "WorldOfNews.com Site Map" ); $wnl_tpl->param( topstories_content => $news_vlist_content ); =start echo(\@category_name_array); exit(); =cut } case 'rss' { my $category = $q->param( "cat" ); #Find out category code my $category_id = CategoryName2Id( $category ); my @tmp_news_aray = (); my @news_array = (); @news_array = get_and_unserialize( $news_search_link . "&opt=mix&nr=$pps&c=$category_id" ); @news_array = @{ $news_array[ 0 ]->{ records } }; #Workaround to not finish the output here: $wnl_tpl = HTML::Template->new( filename => "templates/rss.tpl" ); foreach ( @news_array ) { #if ( length( $_->{ description } ) > 200 ) { $_->{ description } = substr( $_->{ description }, 0, 200 ) . "..."; } if ( length( $_->{ description } ) > 200 ) { $_->{ description } = get_short_description($_->{ description }); } push( @tmp_news_aray, { 'title' => $_->{ title }, 'won_link' => $_->{ won_link }, 'description' => strip_slashes($_->{ description }), 'source_name' => $_->{ source_name }, 'pub_date' => $_->{ pub_date }, 'img' => $_->{ img }, 'cname' => $_->{ cname } } ); } $wnl_tpl->param( current_content => \@tmp_news_aray ); $wnl_tpl->param( title => $category ); my $clink = $category; $clink =~ s/( +)/\+/g; $wnl_tpl->param( 'link' => "http://www.worldofnews.com/rss/$clink" ); $wnl_tpl->param( 'description' => "$category News, World News, Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( 'logo' => 'http://www.worldofnews.com/images/logo.gif' ); $wnl_tpl->param( 'now_date_time' => ( scalar localtime( time() ) ) ); } case 'google' { my $google_tpl = HTML::Template->new( filename => "templates/google.tpl" ); $wnl_tpl->param( page_title => "World News, Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( page_keywords => "World News, Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( page_description => "World News, Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( google_page => 1 ); $wnl_tpl->param( topstories_content => $google_tpl->output() ); } case 'about_us' { my $about_us_tpl = HTML::Template->new( filename => "templates/about_us.tpl" ); $wnl_tpl->param( topstories_content => $about_us_tpl->output() ); $wnl_tpl->param( page_title => "About Us" ); } case 'terms_of_service' { my $tos_tpl = HTML::Template->new( filename => "templates/terms_of_service.tpl" ); $wnl_tpl->param( topstories_content => $tos_tpl->output() ); $wnl_tpl->param( page_title => "Terms of Service" ); } case 'privacy_policy' { my $privacy_policy_tpl = HTML::Template->new( filename => "templates/privacy_policy.tpl" ); $wnl_tpl->param( topstories_content => $privacy_policy_tpl->output() ); $wnl_tpl->param( page_title => "Privacy Policy" ); } case 'contact_us' { my $contact_us_tpl = HTML::Template->new( filename => "templates/contact_us.tpl" ); $wnl_tpl->param( topstories_content => $contact_us_tpl->output() ); $wnl_tpl->param( page_title => "Contact Us" ); } else { #Home page #Get Frontbox content my $frontbox_content .= file_get_contents( "$worldnewxRootFolder/frontbox/feeds/wnl_frontbox.htm" ); #Get Top Stories list my @news_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=$pps&c=2684354584" ); =start select(STDOUT); #print ($news_search_link . "&opt=cat&nr=$pps&c=2684354584");exit(); print Dumper(@news_array);exit(); =cut my @tmp_news_aray = @{ $news_array[ 0 ]->{ records } }; #Calculate the number of pages my $nav_bar = ""; if ( $#tmp_news_aray > -1 ) { $nav_bar = get_nav_bar( $start_record, $pps, $news_array[ 0 ]->{ total_estimated } ); $show_nav_bar = 1; } else { $show_nav_bar = 0; } $wnl_tpl->param( show_nav_bar => $show_nav_bar ); $wnl_tpl->param( navigation_bar => $nav_bar ); $news_vlist_content = create_news_list_content( \@tmp_news_aray ); #Create right section $wnl_tpl->param( 'news_by_cat' => create_right_section( $dbh ) ); $wnl_tpl->param( page_title => $tmp_news_aray[ 0 ]->{ title } ); # $wnl_tpl->param( page_keywords => get_keywords($tmp_news_aray[0]->{description}) ); # $wnl_tpl->param( page_description => get_description($tmp_news_aray[0]->{description}) ); $wnl_tpl->param( page_keywords => "Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( page_description => "Breaking Stories, News Head Lines, Top Stories, Newspapers, Worldwide News" ); $wnl_tpl->param( frontbox_content => $frontbox_content ); $wnl_tpl->param( topstories_content => $news_vlist_content ); $wnl_tpl->param( homepage => 1 ); #Create news array for bottom boxes #'Top Stories', 'Business', 'Education', 'Entertainment', 'Health', 'Law', 'Movie', 'Music', 'Sport', 'Technology', 'US', 'World' my @newscateg = ( 'topstories', 'business', 'education', 'entertainment', 'health', 'law', 'movie', 'music', 'sport', 'technology', 'us', 'world' ); foreach my $categ ( @newscateg ) { my $newsbox_tmpl = HTML::Template->new( filename => "$worldnewxRootFolder/newsbox/feeds/" . $categ . "_newsbox.htm" ); $wnl_tpl->param( $categ . "_newsbox" => $newsbox_tmpl->output() ); } } } # Calculate current date for the archive my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-86400); $year += 1900; $mon += 1; my $current_date = "$year-$mon-$mday"; $wnl_tpl->param('current_date' => $current_date); my $temporary_content = $wnl_tpl->output; =SEO FIX: Teporary took out # FIX: October 27, 2007. # Updated: 22 Aug 2008 # Reason: SEO optimization (add title on all links) # Remove all 'titles' from links $temporary_content =~ s/]+?)title ?= ?["']?([^<>]+?)(['"]|([> ]))/]+?)title ?= ?["']?([^<>]+?)['" >]/]+?)>([^<>]+?)<\/a>/$2<\/a>/gmi; # @TODO: Add 'alt' to all images =cut print $temporary_content; #print to screen but captured by cache if ( $is_collecting_cache eq 'y' ) { save_to_cache( $tmp_cache_file_name, $cache_file_name ); $temporary_content = add_comments( $temporary_content ); # $temporary_content = add_visiads( $temporary_content, $option ); # $temporary_content = add_ad_manager( $temporary_content, $option ); print $temporary_content; #print to screen } ################################################################################ ################################################################################ #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: sub add_comments { my $content = shift(); my $comments_list = get_comments_list(); $content =~ s/__ALREADY_EXISTING_COMMENTS__/$comments_list/; return $content; } sub add_visiads { my $content = shift(); my $option = shift(); my $visiads_content = ""; my @visiads_output = (); if ($option ne '') { #avoid processing for the home page # Process Visiads.com ads # catch output of PHP code my $time_processing = time(); @visiads_output = `php /home/worldofn/www/visiads/interface.php`; $visiads_content = join( "\n", @visiads_output ); $time_processing = time() - $time_processing; $visiads_content .= "\n"; } $content =~ s/__VISIADS_ADS__/$visiads_content/; return $content; } sub add_ad_manager { my $content = shift(); my $option = shift(); my $ad_manager_content = ""; my @ad_manager_output = (); if ($option ne '') { #avoid processing for the home page # Process ad manager ads # catch output of PHP code my $time_processing = time(); @ad_manager_output = `php /home/worldofn/www/adClient/interface.php`; $ad_manager_content = join( "\n", @ad_manager_output ); $time_processing = time() - $time_processing; $ad_manager_content .= "\n"; } $content =~ s/__AD_MANAGER_ADS__/$ad_manager_content/; return $content; } sub get_and_unserialize { my $url = shift(); my $serialized_news = get( $url ); my @news_array = (); eval { @news_array = unserialize( $serialized_news ); }; if ( $@ ) { print( "\n\n Error: $serialized_news \n\n" ); print Dumper( $@ ); exit(); } return @news_array; } sub get_worldinphotos_image { my $url = "http://www.worldinphotos.com/ws_export/300x250/tags/world.jpg"; return unserialize( get( $url ) ); } #Returns the array for the right section sub create_right_section { my $dbh = shift(); my @special_category_array = ( 268435469, # Business 671088651, # Education 671088644, # Entertainment 1073741831, # Health 1610612742, # Law 1744830518, # Movie News 1744830569, # Music 2550136844, # Sports 2684354563, # Technology 2818572289, # Us 3087007746 # World ); my $return_content = ""; foreach my $category ( @special_category_array ) { my $section_tpl = HTML::Template->new( filename => "templates/news_section.tpl" ); my @tmp_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=2&c=$category" ); my @tmp_data_arr = @{ $tmp_array[ 0 ]->{ records } }; @tmp_array = (); foreach ( @tmp_data_arr ) { $_->{ enc_category } = url_encode( $_->{ cname } ); $_->{ img } = ""; if ( length( $_->{ description } ) > 55 ) { my $break_char_index = index($_->{ description }, '', 55); if ($break_char_index > -1) { $break_char_index += 4; # Also add the length of $_->{ description } = substr( $_->{ description }, 0, $break_char_index ) . "..."; } # $_->{ description } = substr( $_->{ description }, 0, 55 ) . " ..."; } $_->{ description } = strip_slashes($_->{ description }); $_->{ pub_date } = format_pub_date( $_->{ pub_date } ); push( @tmp_array, $_ ); } $section_tpl->param( enc_category_name => $tmp_array[ 0 ]->{ enc_category } ); $section_tpl->param( category_name => $tmp_array[ 0 ]->{ cname } ); $section_tpl->param( news_section => \@tmp_array ); $return_content .= $section_tpl->output(); } return $return_content; } sub get_news_array { my $cat_id = shift(); my @tmp_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=5&c=$cat_id" ); return @{ $tmp_array[ 0 ]->{ records } }; } sub create_news_list_content { my @news_list = @{ shift() }; my $news_vlist_content = ''; if ( $#news_list > -1 ) { foreach my $row ( @news_list ) { $news_vlist_content .= format_story( $row ); } } else { $news_vlist_content .= format_story( 0 ); } return $news_vlist_content; } sub format_story { my $row = shift(); my $news_vlist_content = ''; ################################################### my $news_content = HTML::Template->new( filename => "templates/news_body.tpl" ); if ( $row ) { $row = adjust_news_object_fields( $row ); $news_content->param( 'id' => $row->{ permaid } ); $news_content->param( 'link' => $row->{ link } ); $news_content->param( 'won_link' => $row->{ won_link } ); $news_content->param( 'title' => $row->{ title } ); $news_content->param( 'description' => $row->{ description } ); $news_content->param( 'site_name' => $row->{ source_name } ); $news_content->param( 'pub_date' => $row->{ pub_date } ); $news_content->param( 'topic' => $row->{ cname } ); $news_content->param( 'img' => $row->{ img } ); $news_content->param( 'visits' => $row->{ visits } ); } else { $news_content->param( 'no_records' => 1 ); } $news_vlist_content .= $news_content->output(); #push ( @topstories_array, { 'title' => $rows[2], 'description' => $rows[3]}); return $news_vlist_content; } =start /** * @param object $row * @param character $limit_description_length * * @return object */ =cut sub adjust_news_object_fields { my $row = shift(); my $limit_description_length = shift(); $limit_description_length = 'y' unless defined $limit_description_length; $row->{ cat_id } = int( $row->{ cat_id } ); $row->{ geo_id } = int( $row->{ geo_id } ); $row->{ permaid } = int( $row->{ permaid } ); #$row->{won_link} = "/view-" . $row->{permaid} . ".html"; =start $row->{description} = decode_entities($row->{description}); $row->{description} =~ s/<([^<]+?)>//g; $row->{title} =~ s/<([^<]+?)>//g; =cut if ( ( length( $row->{ description } ) > 200 ) && ( $limit_description_length eq 'y' ) ) { $row->{ description } = get_short_description($row->{ description }); } $row->{ description } = strip_slashes($row->{ description }); if ( ( $row->{ source_name } eq 'aniin.com' ) || ( $row->{ source_name } eq 'IANS.in' ) ) { my $encoded_title = $row->{ title }; $encoded_title =~ s/[^a-zA-Z0-9]/-/g; $encoded_title =~ s/\-(\-+)/-/g; $encoded_title =~ s/^(\-+)//g; $encoded_title =~ s/(\-+)$//g; $row->{ won_link } = "http://www.indiasnews.com/News-" . $row->{ permaid } . "-$encoded_title.html"; $row->{ link } = $row->{ won_link }; } #Trick: if 0 views generate random between 0 and 10; if ( $row->{ votes } eq 0 ) { $row->{ votes } = int( rand( 10 ) ); } $row->{ pub_date } = format_pub_date( $row->{ pub_date } ); $row->{ enc_category } = encode_entities( $row->{ cname } ); return $row; } sub get_short_description{ my $description = shift(); $description = strip_slashes($description); my $break_char_index = index($description, '', 200); if ($break_char_index > -1) { $break_char_index += 4; # Also add the length of }else{ $break_char_index = index($description, ' ', 200); } $description = substr( $description, 0, $break_char_index ) . "..."; return $description; } sub format_pub_date { my $pub_date = shift(); #2008-04-13 21:12:38 => 1210702358 my @date_time = split / /, $pub_date; my ( $year, $month, $day ) = split /\-/, $date_time[ 0 ]; my ( $hour, $minute, $second ) = split /\:/, $date_time[ 1 ]; if ( $day == 0 ) { $day = 1; } =debug select (STDOUT); print "$pub_date \n"; print "$second, $minute, $hour, $day, $month, $year \n\n"; =cut $pub_date = time() - timelocal( $second, $minute, $hour, $day, $month - 1, $year ); my $tmp_time = $pub_date; my ( $s, $mi, $h, $d ); if ( $tmp_time > 60 ) { $mi = int( $tmp_time / 60 ); $s = $tmp_time % 60; if ( $mi > 60 ) { $h = int( $mi / 60 ); $mi = $mi % 60; if ( $h > 24 ) { $d = int( $h / 24 ); $h = $h % 24; } } } else { $mi = $tmp_time; } $pub_date = ''; if ( abs( "$d" ) > 0 ) { $pub_date = $d . " days ago"; } else { if ( $h > 0 ) { $pub_date .= $h . " hours and "; } $pub_date .= $mi . " minutes ago"; } return $pub_date; } sub decode_mysql_date { my $pub_date = shift(); #2008-04-13 21:12:38 my @date_time = split / /, $pub_date; my ( $year, $month, $day ) = split /\-/, $date_time[ 0 ]; my ( $hour, $minute, $second ) = split /\:/, $date_time[ 1 ]; my $ret_val = ""; if ( ( $year > 0 ) && ( $day > 0 ) ) { $pub_date = timelocal( $second, $minute, $hour, $day, $month - 1, $year ); $pub_date = scalar localtime( $pub_date ); $pub_date =~ s/( +)/ /g; my @date_array = split / /, $pub_date; my @time_array = split /:/, $date_array[ 3 ]; $ret_val = sprintf( "%s %s, %s %s:%s", $date_array[ 1 ], $date_array[ 2 ], $date_array[ 4 ], $time_array[ 0 ], $time_array[ 1 ] ); } else { $ret_val = $pub_date; } return $ret_val; } #Creates a database connection and returns databasehandler sub init_database { my $config_file_path = shift(); my $config_xml = XMLin( $config_file_path ); my $db_host = $config_xml->{ parserSettings }{ db_host }; my $db_name = $config_xml->{ parserSettings }{ db_name }; my $db_user = $config_xml->{ parserSettings }{ db_user }; my $db_password = $config_xml->{ parserSettings }{ db_password }; if ( $db_password eq "''" ) { $db_password = ''; } my $dbh = DBI->connect( "dbi:mysql:$db_name:$db_host", "$db_user", "$db_password" ) or die( "Cannot connect to the database" ); return $dbh; } sub create_cache_file_name { my ( $cat, $keyword, $news_id, $option, $start_record, $bottom_menu_id ) = @_; # #Create cache file name # my $cache_file_name = ''; if ( $cat ) { $cache_file_name = $cat; } if ( $keyword ) { $cache_file_name = $keyword; } $cache_file_name .= $news_id . $option . $start_record . $bottom_menu_id; $cache_file_name =~ s/[^a-z0-9A-Z]//g; # #Treate cache # #Split the cache in subdirectories in order to be retreived quickly #In this case will be implemented a three level cache mechanism for ( my $i = 0 ; $i < 3 ; $i++ ) { my $cache_dirLi = substr( $cache_file_name, $i, 1 ); $cache_dir = "$cache_dir/$cache_dirLi"; #$cache_dir is global if ( !( -e "$cache_dir" && -d "$cache_dir" ) ) { mkdir( "$cache_dir" ); chmod 0777, "$cache_dir"; } } $cache_file_name = $cache_dir . "/" . $cache_file_name; return $cache_file_name; } sub try_to_get_cache { my $cache_file_name = shift(); my @cache_stat = stat( "$cache_file_name.ch" ); my $cache_mtime = $cache_stat[ 9 ]; my $cache_size = $cache_stat[ 7 ]; my $current_time = time(); my $return_value = ""; if ( ( !$cache_mtime ) ) { $cache_mtime = 0; open CFH, "> $cache_file_name.ch"; close CFH; $DBG->show( "Closing CFH on checkTheCache function" ); } $DBG->show( "Cache Data \n CacheSize:$cache_size \n CacheModifiedTime:$cache_mtime \n CacheLife:" . ( $current_time - $cache_mtime ) . " \n Keyword:$keyword \n Option:$option " ); if ( ( $cache_size > 1000 ) && ( $cache_mtime > 0 ) && ( $current_time - $cache_mtime < $cache_time ) ) { $return_value = file_get_contents( "$cache_file_name.ch" ); $return_value .= "\n"; $return_value .= "\n"; } else { $return_value = ''; } return $return_value; } sub save_to_cache { my $tmp_cache_file_name = shift(); my $cache_file_name = shift(); if ( $tmp_cache_file_name ne "" ) { close( FH ); $DBG->show( "Closing FH on save_to_cache function" ); chmod 0777, "$tmp_cache_file_name.ch"; select( STDOUT ); my @cacheStat = stat( "$tmp_cache_file_name.ch" ); if ( $cacheStat[ 7 ] > 1000 ) { #stat[7] = filesize if ( unlink "$cache_file_name.ch" ) { $DBG->show( "File $cache_file_name.ch deleted ...\n" ); } else { $DBG->show( "File $cache_file_name.ch can not be deleted ...\n" ); } if ( rename "$tmp_cache_file_name.ch", "$cache_file_name.ch" ) { $DBG->show( "$tmp_cache_file_name.ch renamed to $cache_file_name.ch...\n" ); } else { $DBG->show( "$tmp_cache_file_name.ch can not be renamed to $cache_file_name.ch...\n" ); } } } } #Include a file sub include { my $fileName = shift(); open IFH, "<" . $fileName; while ( ) { print $_; } close( IFH ); $DBG->show( "Closing IFH on include function" ); } #Initiates tho collect the content to be saved into the cache sub start_collect_cache { my $cache_file_name = shift(); #Open cache file handler my $tmp_cache_file_name = $cache_file_name . time(); open FH, "> " . $tmp_cache_file_name . ".ch"; select( FH ); return $tmp_cache_file_name; } #Gets content from a file sub file_get_contents { my $file_name = shift(); my @content_lines = (); open( TMPFH, $file_name ); @content_lines = ; close TMPFH; return join( "\n", @content_lines ); } #Returh the is_homepage glag sub get_first_page_flag { my $q = shift(); my $ret_val = 0; if ( !$q->param( 'cat' ) && ( ( !$q->param( 'option' ) ) || ( $q->param( 'option' ) eq 'specops' ) ) && !$q->param( 'keyword' ) ) { $ret_val = 1; } return $ret_val; } #Visit a news sub visit_news { my $id = shift(); get( "http://wssearch.worldnewx.com/ws_status.pl?apikey=worldnewx.com-1277066279&opt=vis&permaid=$id" ); } #Vote for a news sub vote_news { my $id = shift(); get( "http://wssearch.worldnewx.com/ws_status.pl?apikey=worldnewx.com-1277066279&opt=vot&permaid=$id" ); } sub select_STDOUT { close( FH ); select( STDOUT ); $DBG->show( "Closing FH and selecting STDOUT on select_STDOUT function" ); } sub mysql_query { my $sql = shift(); my $dbh = shift(); my $sth = $dbh->prepare( $sql ); $sth->execute() or die( "Invalid query ($sql) !!!" ); $sth->finish(); } #Returns the categories array sub get_categories_array { my $dbh = shift(); my $clevel = shift(); my $sql = "SELECT * FROM `category`"; if ( $clevel > 0 ) { $sql .= " WHERE `clevel`=$clevel"; } $sql .= " ORDER BY `weight` DESC, `title` ASC"; my $sth = $dbh->prepare( $sql ); $sth->execute() || die( "Could not execute sql !!!" ); my @category_array = (); while ( my $cat_rows = $sth->fetchrow_hashref ) { push( @category_array, { 'id' => $cat_rows->{ 'id' }, 'title' => $cat_rows->{ 'title' }, 'link' => url_encode( $cat_rows->{ 'title' } ) } ); } $sth->finish(); return @category_array; } sub CategoryName2Id { my $category_name = shift(); my $sql = "SELECT `alias` FROM `category` WHERE `title`='$category_name'"; my $sth = $dbh->prepare( $sql ); $sth->execute() || die( "Could not execute sql !!!" ); my $cat_row = $sth->fetchrow_hashref; return ( ( $aArchiveIndex{ lc( substr( $category_name, 0, 1 ) ) } << 27 ) + $cat_row->{ alias } ); } sub url_encode { my ( $string ) = @_; $string =~ s/(\W)/"%" . unpack("H2", $1)/ge; #$string# =~ tr/.//; return $string; } sub url_decode { my ( $string ) = @_; $string =~ tr/+/ /; $string =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; return $string; } sub get_description { my $content = shift(); return strip_slashes(strip_tags($content)); } sub strip_tags{ my $content = shift(); $content =~ s/\<([^>]+?)\>/ /g; $content =~ s/ +/ /g; return $content; } sub strip_slashes{ my $content = shift(); $content =~ s/\\//g; return $content; } sub get_keywords { my $content = shift(); my $commonWordsArray = "able|about|after|again|all|almost|already|also|although|am|an|and|another|any|are|are|around|as|at|based|be|because|been|before|being|between|both|bring|but|by|came|can|com|come|comes|could|did|do|does|doing|done|each|eight|else|etc|even|every|five|for|four|from|get|gets|getting|go|going|got|had|has|have|he|he|her|here|him|himself|his|how|however|href|http|if|in|including|into|is|it|it|its|just|kb|know|like|looks|mailto|make|making|many|may|mb|me|means|might|more|more|most|move|mr|much|must|my|need|needs|never|nice|nine|no|not|now|of|often|oh|ok|on|on|one|only|or|org|other|our|out|over|own|piece|rather|re|really|said|same|say|says|see|seven|several|she|should|since|single|six|so|some|something|still|stuff|such|take|ten|than|that|the|their|them|them|then|there|there|these|they|they|thing|things|this|those|three|through|to|too|took|two|under|up|us|use|used|using|usual|ve|very|via|want|was|way|we|we|well|were|what|when|where|whether|which|while|whilst|who|why|will|with|within|would|yes|yet|you|your"; $content =~ s/\b($commonWordsArray)\b//g; $content =~ s/<([^>]+?)>//g; $content =~ s/(\s+)/,/g; $content =~ s/,(,+)/,/g; return $content; } =start /** * Creates the navigation bar * @param int $start_record, * @param int $pps, * @param int $total_estimated * *@return string */ =cut sub get_nav_bar { my ( $start_record, $pps, $no_of_records ) = @_; my $uri = $ENV{ REQUEST_URI }; #Get $uri like prefix-Title-s00?p1=v1&p2=v2 $uri =~ s/\-s(\d+?)\b//; #Format $uri like prefix-Title?p1=v1&p2=v2 my $request_uri = $uri; my $total_pages = ceil( $no_of_records / $pps ); my $current_page = ceil( $start_record / $pps ); my $navbar_tpl = HTML::Template->new( filename => "templates/nav_bar.tpl" ); #Construct PREV link my $prev_link = $uri; if ( $start_record > 0 ) { my $start = 0; if ( $start_record - $pps >= 0 ) { $start = $start_record - $pps; } $prev_link =~ s/(\?|$)/-s$start$1/; } my $show_prev = 0; if ( $start_record > 0 ) { $show_prev = 1; } $navbar_tpl->param( show_prev => $show_prev ); $navbar_tpl->param( link_prev => $prev_link ); #Construct NEXT link my $next_link = $uri; if ( $start_record < $no_of_records ) { my $start = $no_of_records; if ( $start_record + $pps <= $no_of_records ) { $start = $start_record + $pps; } $next_link =~ s/(\?|$)/-s$start$1/; } my $show_next = 0; if ( $start_record < $no_of_records ) { $show_next = 1; } $navbar_tpl->param( show_next => $show_next ); $navbar_tpl->param( link_next => $next_link ); #return ""; my $tmp_page; my @pages_array = (); my @progress = ( 1000, 100, 10, 5, 4, 3, 2, 1 ); if ( $request_uri eq '/index.pl?skipcache=y') { $request_uri = 'Top+Stories'; =start my $OLD_FH = select(); select (STDOUT); print ""; select ($OLD_FH); =cut } my $page_link = ""; my $page_nr; foreach $step ( @progress ) { $page_link = $request_uri; my $start = 0; if ( $start_record - $step * $pps >= 0 ) { $start = $start_record - $step * $pps; $page_nr = ceil( $start / $pps ) + 1; $page_link =~ s/(\?|$)/-s$start$1/; push( @pages_array, { 'link_number' => $page_link, 'number' => $page_nr, 'selected' => 0 } ); } } $page_nr = ceil( $start_record / $pps ) + 1; push( @pages_array, { 'link_number' => $request_uri, 'number' => $page_nr, 'selected' => 1 } ); @progress = reverse @progress; foreach $step ( @progress ) { $page_link = $request_uri; my $start = 0; if ( $start_record + $step * $pps <= $no_of_records ) { $start = $start_record + $step * $pps; $page_nr = ceil( $start / $pps ) + 1; $page_link =~ s/(\?|$)/-s$start$1/; push( @pages_array, { 'link_number' => $page_link, 'number' => $page_nr, 'selected' => 0 } ); } } $navbar_tpl->param( pages_array => \@pages_array ); return $navbar_tpl->output(); } sub echo { my $OLD_FH = select(); select( STDOUT ); print Dumper( \@_ ); select( $OLD_FH ); } sub get_comments_list { # Get the comments list my $comments_base_url = "http://wssearch.worldnewx.com/ws_comments.pl?apikey=worldofnews.com-1495998270"; my $comments_list_url = $comments_base_url . "&opt=get&id=0&docid=$news_id"; my @tmp_comments_array = get_and_unserialize( $comments_list_url ); @tmp_comments_array = @{ $tmp_comments_array[ 0 ][ 1 ] }; my @comments_array = (); my $iterator = 0; foreach ( @tmp_comments_array ) { if ( $_->{ pending_delete } eq 'n' ) { $_->{ pending_delete } = 0; } #pending delete $_->{ usermail } = ''; #Hide email $_->{ apikey } = ''; #Hide api key $_->{ bg_color } = ( $iterator % 2 == 0 ) ? '#FFFFFF' : '#FFFF99'; #Add background color push( @comments_array, $_ ); $iterator++; } my $comments_list = ""; if ( $#comments_array > -1 ) { my $tpl_comment_list = HTML::Template->new( filename => "templates/comment_body.tpl", global_vars => 1 ); $tpl_comment_list->param( 'comments_array' => \@comments_array ); $comments_list = $tpl_comment_list->output(); } return $comments_list; } sub print_server_busy_message{ my $message = shift(); print "

$message

\n
\n"; print "Server busy! Please try again in a few seconds !"; exit(); } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #::::::::::: CLASS DEBUG ::::::::::::::::::::::::::::::::: #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: package DEBUG; use Data::Dumper; my $flag = 0; #1 = debug activated my $__START_TIME__; sub new() { $__START_TIME__ = time(); bless {}, shift(); } #Gets the start time of the debug sub get_start_time { return $__START_TIME__; } #Show the debug message according with the flag sub show { my $this = shift(); my $message = shift(); if ( $flag == 1 ) { my $hash = shift(); my $OLD_FH = select(); select( STDOUT ); print Dumper( $message ); select( $OLD_FH ); } } #Sets a value for the flag sub set_flag { my $this = shift(); my $newVal = shift(); $flag = $newVal; } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1; /$ad_manager_content/; return $content; } sub get_and_unserialize { my $url = shift(); my $serialized_news = get( $url ); my @news_array = (); eval { @news_array = unserialize( $serialized_news ); }; if ( $@ ) { print( "\n\n Error: $serialized_news \n\n" ); print Dumper( $@ ); exit(); } return @news_array; } sub get_worldinphotos_image { my $url = "http://www.worldinphotos.com/ws_export/300x250/tags/world.jpg"; return unserialize( get( $url ) ); } #Returns the array for the right section sub create_right_section { my $dbh = shift(); my @special_category_array = ( 268435469, # Business 671088651, # Education 671088644, # Entertainment 1073741831, # Health 1610612742, # Law 1744830518, # Movie News 1744830569, # Music 2550136844, # Sports 2684354563, # Technology 2818572289, # Us 3087007746 # World ); my $return_content = ""; foreach my $category ( @special_category_array ) { my $section_tpl = HTML::Template->new( filename => "templates/news_section.tpl" ); my @tmp_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=2&c=$category" ); my @tmp_data_arr = @{ $tmp_array[ 0 ]->{ records } }; @tmp_array = (); foreach ( @tmp_data_arr ) { $_->{ enc_category } = url_encode( $_->{ cname } ); $_->{ img } = ""; if ( length( $_->{ description } ) > 55 ) { my $break_char_index = index($_->{ description }, '', 55); if ($break_char_index > -1) { $break_char_index += 4; # Also add the length of $_->{ description } = substr( $_->{ description }, 0, $break_char_index ) . "..."; } # $_->{ description } = substr( $_->{ description }, 0, 55 ) . " ..."; } $_->{ description } = strip_slashes($_->{ description }); $_->{ pub_date } = format_pub_date( $_->{ pub_date } ); push( @tmp_array, $_ ); } $section_tpl->param( enc_category_name => $tmp_array[ 0 ]->{ enc_category } ); $section_tpl->param( category_name => $tmp_array[ 0 ]->{ cname } ); $section_tpl->param( news_section => \@tmp_array ); $return_content .= $section_tpl->output(); } return $return_content; } sub get_news_array { my $cat_id = shift(); my @tmp_array = get_and_unserialize( $news_search_link . "&opt=cat&nr=5&c=$cat_id" ); return @{ $tmp_array[ 0 ]->{ records } }; } sub create_news_list_content { my @news_list = @{ shift() }; my $news_vlist_content = ''; if ( $#news_list > -1 ) { foreach my $row ( @news_list ) { $news_vlist_content .= format_story( $row ); } } else { $news_vlist_content .= format_story( 0 ); } return $news_vlist_content; } sub format_story { my $row = shift(); my $news_vlist_content = ''; ################################################### my $news_content = HTML::Template->new( filename => "templates/news_body.tpl" ); if ( $row ) { $row = adjust_news_object_fields( $row ); $news_content->param( 'id' => $row->{ permaid } ); $news_content->param( 'link' => $row->{ link } ); $news_content->param( 'won_link' => $row->{ won_link } ); $news_content->param( 'title' => $row->{ title } ); $news_content->param( 'description' => $row->{ description } ); $news_content->param( 'site_name' => $row->{ source_name } ); $news_content->param( 'pub_date' => $row->{ pub_date } ); $news_content->param( 'topic' => $row->{ cname } ); $news_content->param( 'img' => $row->{ img } ); $news_content->param( 'visits' => $row->{ visits } ); } else { $news_content->param( 'no_records' => 1 ); } $news_vlist_content .= $news_content->output(); #push ( @topstories_array, { 'title' => $rows[2], 'description' => $rows[3]}); return $news_vlist_content; } =start /** * @param object $row * @param character $limit_description_length * * @return object */ =cut sub adjust_news_object_fields { my $row = shift(); my $limit_description_length = shift(); $limit_description_length = 'y' unless defined $limit_description_length; $row->{ cat_id } = int( $row->{ cat_id } ); $row->{ geo_id } = int( $row->{ geo_id } ); $row->{ permaid } = int( $row->{ permaid } ); #$row->{won_link} = "/view-" . $row->{permaid} . ".html"; =start $row->{description} = decode_entities($row->{description}); $row->{description} =~ s/<([^<]+?)>//g; $row->{title} =~ s/<([^<]+?)>//g; =cut if ( ( length( $row->{ description } ) > 200 ) && ( $limit_description_length eq 'y' ) ) { $row->{ description } = get_short_description($row->{ description }); } $row->{ description } = strip_slashes($row->{ description }); if ( ( $row->{ source_name } eq 'aniin.com' ) || ( $row->{ source_name } eq 'IANS.in' ) ) { my $encoded_title = $row->{ title }; $encoded_title =~ s/[^a-zA-Z0-9]/-/g; $encoded_title =~ s/\-(\-+)/-/g; $encoded_title =~ s/^(\-+)//g; $encoded_title =~ s/(\-+)$//g; $row->{ won_link } = "http://www.indiasnews.com/News-" . $row->{ permaid } . "-$encoded_title.html"; $row->{ link } = $row->{ won_link }; } #Trick: if 0 views generate random between 0 and 10; if ( $row->{ votes } eq 0 ) { $row->{ votes } = int( rand( 10 ) ); } $row->{ pub_date } = format_pub_date( $row->{ pub_date } ); $row->{ enc_category } = encode_entities( $row->{ cname } ); return $row; } sub get_short_description{ my $description = shift(); $description = strip_slashes($description); my $break_char_index = index($description, '', 200); if ($break_char_index > -1) { $break_char_index += 4; # Also add the length of }else{ $break_char_index = index($description, ' ', 200); } $description = substr( $description, 0, $break_char_index ) . "..."; return $description; } sub format_pub_date { my $pub_date = shift(); #2008-04-13 21:12:38 => 1210702358 my @date_time = split / /, $pub_date; my ( $year, $month, $day ) = split /\-/, $date_time[ 0 ]; my ( $hour, $minute, $second ) = split /\:/, $date_time[ 1 ]; if ( $day == 0 ) { $day = 1; } =debug select (STDOUT); print "$pub_date \n"; print "$second, $minute, $hour, $day, $month, $year \n\n"; =cut $pub_date = time() - timelocal( $second, $minute, $hour, $day, $month - 1, $year ); my $tmp_time = $pub_date; my ( $s, $mi, $h, $d ); if ( $tmp_time > 60 ) { $mi = int( $tmp_time / 60 ); $s = $tmp_time % 60; if ( $mi > 60 ) { $h = int( $mi / 60 ); $mi = $mi % 60; if ( $h > 24 ) { $d = int( $h / 24 ); $h = $h % 24; } } } else { $mi = $tmp_time; } $pub_date = ''; if ( abs( "$d" ) > 0 ) { $pub_date = $d . " days ago"; } else { if ( $h > 0 ) { $pub_date .= $h . " hours and "; } $pub_date .= $mi . " minutes ago"; } return $pub_date; } sub decode_mysql_date { my $pub_date = shift(); #2008-04-13 21:12:38 my @date_time = split / /, $pub_date; my ( $year, $month, $day ) = split /\-/, $date_time[ 0 ]; my ( $hour, $minute, $second ) = split /\:/, $date_time[ 1 ]; my $ret_val = ""; if ( ( $year > 0 ) && ( $day > 0 ) ) { $pub_date = timelocal( $second, $minute, $hour, $day, $month - 1, $year ); $pub_date = scalar localtime( $pub_date ); $pub_date =~ s/( +)/ /g; my @date_array = split / /, $pub_date; my @time_array = split /:/, $date_array[ 3 ]; $ret_val = sprintf( "%s %s, %s %s:%s", $date_array[ 1 ], $date_array[ 2 ], $date_array[ 4 ], $time_array[ 0 ], $time_array[ 1 ] ); } else { $ret_val = $pub_date; } return $ret_val; } #Creates a database connection and returns databasehandler sub init_database { my $config_file_path = shift(); my $config_xml = XMLin( $config_file_path ); my $db_host = $config_xml->{ parserSettings }{ db_host }; my $db_name = $config_xml->{ parserSettings }{ db_name }; my $db_user = $config_xml->{ parserSettings }{ db_user }; my $db_password = $config_xml->{ parserSettings }{ db_password }; if ( $db_password eq "''" ) { $db_password = ''; } my $dbh = DBI->connect( "dbi:mysql:$db_name:$db_host", "$db_user", "$db_password" ) or die( "Cannot connect to the database" ); return $dbh; } sub create_cache_file_name { my ( $cat, $keyword, $news_id, $option, $start_record, $bottom_menu_id ) = @_; # #Create cache file name # my $cache_file_name = ''; if ( $cat ) { $cache_file_name = $cat; } if ( $keyword ) { $cache_file_name = $keyword; } $cache_file_name .= $news_id . $option . $start_record . $bottom_menu_id; $cache_file_name =~ s/[^a-z0-9A-Z]//g; # #Treate cache # #Split the cache in subdirectories in order to be retreived quickly #In this case will be implemented a three level cache mechanism for ( my $i = 0 ; $i < 3 ; $i++ ) { my $cache_dirLi = substr( $cache_file_name, $i, 1 ); $cache_dir = "$cache_dir/$cache_dirLi"; #$cache_dir is global if ( !( -e "$cache_dir" && -d "$cache_dir" ) ) { mkdir( "$cache_dir" ); chmod 0777, "$cache_dir"; } } $cache_file_name = $cache_dir . "/" . $cache_file_name; return $cache_file_name; } sub try_to_get_cache { my $cache_file_name = shift(); my @cache_stat = stat( "$cache_file_name.ch" ); my $cache_mtime = $cache_stat[ 9 ]; my $cache_size = $cache_stat[ 7 ]; my $current_time = time(); my $return_value = ""; if ( ( !$cache_mtime ) ) { $cache_mtime = 0; open CFH, "> $cache_file_name.ch"; close CFH; $DBG->show( "Closing CFH on checkTheCache function" ); } $DBG->show( "Cache Data \n CacheSize:$cache_size \n CacheModifiedTime:$cache_mtime \n CacheLife:" . ( $current_time - $cache_mtime ) . " \n Keyword:$keyword \n Option:$option " ); if ( ( $cache_size > 1000 ) && ( $cache_mtime > 0 ) && ( $current_time - $cache_mtime < $cache_time ) ) { $return_value = file_get_contents( "$cache_file_name.ch" ); $return_value .= "\n"; $return_value .= "\n"; } else { $return_value = ''; } return $return_value; } sub save_to_cache { my $tmp_cache_file_name = shift(); my $cache_file_name = shift(); if ( $tmp_cache_file_name ne "" ) { close( FH ); $DBG->show( "Closing FH on save_to_cache function" ); chmod 0777, "$tmp_cache_file_name.ch"; select( STDOUT ); my @cacheStat = stat( "$tmp_cache_file_name.ch" ); if ( $cacheStat[ 7 ] > 1000 ) { #stat[7] = filesize if ( unlink "$cache_file_name.ch" ) { $DBG->show( "File $cache_file_name.ch deleted ...\n" ); } else { $DBG->show( "File $cache_file_name.ch can not be deleted ...\n" ); } if ( rename "$tmp_cache_file_name.ch", "$cache_file_name.ch" ) { $DBG->show( "$tmp_cache_file_name.ch renamed to $cache_file_name.ch...\n" ); } else { $DBG->show( "$tmp_cache_file_name.ch can not be renamed to $cache_file_name.ch...\n" ); } } } } #Include a file sub include { my $fileName = shift(); open IFH, "<" . $fileName; while ( ) { print $_; } close( IFH ); $DBG->show( "Closing IFH on include function" ); } #Initiates tho collect the content to be saved into the cache sub start_collect_cache { my $cache_file_name = shift(); #Open cache file handler my $tmp_cache_file_name = $cache_file_name . time(); open FH, "> " . $tmp_cache_file_name . ".ch"; select( FH ); return $tmp_cache_file_name; } #Gets content from a file sub file_get_contents { my $file_name = shift(); my @content_lines = (); open( TMPFH, $file_name ); @content_lines = ; close TMPFH; return join( "\n", @content_lines ); } #Returh the is_homepage glag sub get_first_page_flag { my $q = shift(); my $ret_val = 0; if ( !$q->param( 'cat' ) && ( ( !$q->param( 'option' ) ) || ( $q->param( 'option' ) eq 'specops' ) ) && !$q->param( 'keyword' ) ) { $ret_val = 1; } return $ret_val; } #Visit a news sub visit_news { my $id = shift(); get( "http://wssearch.worldnewx.com/ws_status.pl?apikey=worldnewx.com-1277066279&opt=vis&permaid=$id" ); } #Vote for a news sub vote_news { my $id = shift(); get( "http://wssearch.worldnewx.com/ws_status.pl?apikey=worldnewx.com-1277066279&opt=vot&permaid=$id" ); } sub select_STDOUT { close( FH ); select( STDOUT ); $DBG->show( "Closing FH and selecting STDOUT on select_STDOUT function" ); } sub mysql_query { my $sql = shift(); my $dbh = shift(); my $sth = $dbh->prepare( $sql ); $sth->execute() or die( "Invalid query ($sql) !!!" ); $sth->finish(); } #Returns the categories array sub get_categories_array { my $dbh = shift(); my $clevel = shift(); my $sql = "SELECT * FROM `category`"; if ( $clevel > 0 ) { $sql .= " WHERE `clevel`=$clevel"; } $sql .= " ORDER BY `weight` DESC, `title` ASC"; my $sth = $dbh->prepare( $sql ); $sth->execute() || die( "Could not execute sql !!!" ); my @category_array = (); while ( my $cat_rows = $sth->fetchrow_hashref ) { push( @category_array, { 'id' => $cat_rows->{ 'id' }, 'title' => $cat_rows->{ 'title' }, 'link' => url_encode( $cat_rows->{ 'title' } ) } ); } $sth->finish(); return @category_array; } sub CategoryName2Id { my $category_name = shift(); my $sql = "SELECT `alias` FROM `category` WHERE `title`='$category_name'"; my $sth = $dbh->prepare( $sql ); $sth->execute() || die( "Could not execute sql !!!" ); my $cat_row = $sth->fetchrow_hashref; return ( ( $aArchiveIndex{ lc( substr( $category_name, 0, 1 ) ) } << 27 ) + $cat_row->{ alias } ); } sub url_encode { my ( $string ) = @_; $string =~ s/(\W)/"%" . unpack("H2", $1)/ge; #$string# =~ tr/.//; return $string; } sub url_decode { my ( $string ) = @_; $string =~ tr/+/ /; $string =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; return $string; } sub get_description { my $content = shift(); return strip_slashes(strip_tags($content)); } sub strip_tags{ my $content = shift(); $content =~ s/\<([^>]+?)\>/ /g; $content =~ s/ +/ /g; return $content; } sub strip_slashes{ my $content = shift(); $content =~ s/\\//g; return $content; } sub get_keywords { my $content = shift(); my $commonWordsArray = "able|about|after|again|all|almost|already|also|although|am|an|and|another|any|are|are|around|as|at|based|be|because|been|before|being|between|both|bring|but|by|came|can|com|come|comes|could|did|do|does|doing|done|each|eight|else|etc|even|every|five|for|four|from|get|gets|getting|go|going|got|had|has|have|he|he|her|here|him|himself|his|how|however|href|http|if|in|including|into|is|it|it|its|just|kb|know|like|looks|mailto|make|making|many|may|mb|me|means|might|more|more|most|move|mr|much|must|my|need|needs|never|nice|nine|no|not|now|of|often|oh|ok|on|on|one|only|or|org|other|our|out|over|own|piece|rather|re|really|said|same|say|says|see|seven|several|she|should|since|single|six|so|some|something|still|stuff|such|take|ten|than|that|the|their|them|them|then|there|there|these|they|they|thing|things|this|those|three|through|to|too|took|two|under|up|us|use|used|using|usual|ve|very|via|want|was|way|we|we|well|were|what|when|where|whether|which|while|whilst|who|why|will|with|within|would|yes|yet|you|your"; $content =~ s/\b($commonWordsArray)\b//g; $content =~ s/<([^>]+?)>//g; $content =~ s/(\s+)/,/g; $content =~ s/,(,+)/,/g; return $content; } =start /** * Creates the navigation bar * @param int $start_record, * @param int $pps, * @param int $total_estimated * *@return string */ =cut sub get_nav_bar { my ( $start_record, $pps, $no_of_records ) = @_; my $uri = $ENV{ REQUEST_URI }; #Get $uri like prefix-Title-s00?p1=v1&p2=v2 $uri =~ s/\-s(\d+?)\b//; #Format $uri like prefix-Title?p1=v1&p2=v2 my $request_uri = $uri; my $total_pages = ceil( $no_of_records / $pps ); my $current_page = ceil( $start_record / $pps ); my $navbar_tpl = HTML::Template->new( filename => "templates/nav_bar.tpl" ); #Construct PREV link my $prev_link = $uri; if ( $start_record > 0 ) { my $start = 0; if ( $start_record - $pps >= 0 ) { $start = $start_record - $pps; } $prev_link =~ s/(\?|$)/-s$start$1/; } my $show_prev = 0; if ( $start_record > 0 ) { $show_prev = 1; } $navbar_tpl->param( show_prev => $show_prev ); $navbar_tpl->param( link_prev => $prev_link ); #Construct NEXT link my $next_link = $uri; if ( $start_record < $no_of_records ) { my $start = $no_of_records; if ( $start_record + $pps <= $no_of_records ) { $start = $start_record + $pps; } $next_link =~ s/(\?|$)/-s$start$1/; } my $show_next = 0; if ( $start_record < $no_of_records ) { $show_next = 1; } $navbar_tpl->param( show_next => $show_next ); $navbar_tpl->param( link_next => $next_link ); #return ""; my $tmp_page; my @pages_array = (); my @progress = ( 1000, 100, 10, 5, 4, 3, 2, 1 ); if ( $request_uri eq '/index.pl?skipcache=y') { $request_uri = 'Top+Stories'; =start my $OLD_FH = select(); select (STDOUT); print ""; select ($OLD_FH); =cut } my $page_link = ""; my $page_nr; foreach $step ( @progress ) { $page_link = $request_uri; my $start = 0; if ( $start_record - $step * $pps >= 0 ) { $start = $start_record - $step * $pps; $page_nr = ceil( $start / $pps ) + 1; $page_link =~ s/(\?|$)/-s$start$1/; push( @pages_array, { 'link_number' => $page_link, 'number' => $page_nr, 'selected' => 0 } ); } } $page_nr = ceil( $start_record / $pps ) + 1; push( @pages_array, { 'link_number' => $request_uri, 'number' => $page_nr, 'selected' => 1 } ); @progress = reverse @progress; foreach $step ( @progress ) { $page_link = $request_uri; my $start = 0; if ( $start_record + $step * $pps <= $no_of_records ) { $start = $start_record + $step * $pps; $page_nr = ceil( $start / $pps ) + 1; $page_link =~ s/(\?|$)/-s$start$1/; push( @pages_array, { 'link_number' => $page_link, 'number' => $page_nr, 'selected' => 0 } ); } } $navbar_tpl->param( pages_array => \@pages_array ); return $navbar_tpl->output(); } sub echo { my $OLD_FH = select(); select( STDOUT ); print Dumper( \@_ ); select( $OLD_FH ); } sub get_comments_list { # Get the comments list my $comments_base_url = "http://wssearch.worldnewx.com/ws_comments.pl?apikey=worldofnews.com-1495998270"; my $comments_list_url = $comments_base_url . "&opt=get&id=0&docid=$news_id"; my @tmp_comments_array = get_and_unserialize( $comments_list_url ); @tmp_comments_array = @{ $tmp_comments_array[ 0 ][ 1 ] }; my @comments_array = (); my $iterator = 0; foreach ( @tmp_comments_array ) { if ( $_->{ pending_delete } eq 'n' ) { $_->{ pending_delete } = 0; } #pending delete $_->{ usermail } = ''; #Hide email $_->{ apikey } = ''; #Hide api key $_->{ bg_color } = ( $iterator % 2 == 0 ) ? '#FFFFFF' : '#FFFF99'; #Add background color push( @comments_array, $_ ); $iterator++; } my $comments_list = ""; if ( $#comments_array > -1 ) { my $tpl_comment_list = HTML::Template->new( filename => "templates/comment_body.tpl", global_vars => 1 ); $tpl_comment_list->param( 'comments_array' => \@comments_array ); $comments_list = $tpl_comment_list->output(); } return $comments_list; } sub print_server_busy_message{ my $message = shift(); print "

$message

\n
\n"; print "Server busy! Please try again in a few seconds !"; exit(); } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #::::::::::: CLASS DEBUG ::::::::::::::::::::::::::::::::: #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: package DEBUG; use Data::Dumper; my $flag = 0; #1 = debug activated my $__START_TIME__; sub new() { $__START_TIME__ = time(); bless {}, shift(); } #Gets the start time of the debug sub get_start_time { return $__START_TIME__; } #Show the debug message according with the flag sub show { my $this = shift(); my $message = shift(); if ( $flag == 1 ) { my $hash = shift(); my $OLD_FH = select(); select( STDOUT ); print Dumper( $message ); select( $OLD_FH ); } } #Sets a value for the flag sub set_flag { my $this = shift(); my $newVal = shift(); $flag = $newVal; } #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1;
__AD_MANAGER_ADS__

 
Top Stories

Gallery: Measuring the History of Electricity
Aug 14, 2008 05:00
&ltimg src='http://www.wired.com/images/slideshow/2008/08/gallery_electrical_meter/antique_light_bulb_t.jpg'>: Photo:&lta href="http://flickr.com/photos/mtowber/2367979423/"> mtowber/flickr&ltp&gtThe invention of the electric meter made it possible to bill customers for electricity, creating the incentive to build out the nation's first network for moving electrons. The Grid, the system of dumb, buzzing wires that allows power to move across the country, is so important, it topped the National Academy of Engineering's &lta href="http://www.greatachievements.org/id=2949"&gttop 20 triumphs of the 20th century. &ltp>This gallery tours the history -- and future -- of making you pay for juice. Some time within the next few years, you're likely to get a new type of so-called "smart meter" that will mark the first real upgrade to electrical billing since your grandparents were born. &ltp>Until the 1870s, electrical power wasn't used for much aside from telegraphs and telephones. But after the Edison's improvement of the incandescent light bulb, power was suddenly much more useful. The problem was, the few metering systems that tinkerers had built up until that time didn't actually work. &ltp>So Edison resorted to a low-tech method: He charged for electricity on a per-lamp basis. In modern business model terms, Edison was giving away the blades to sell the razor. He would not have received venture capital for that idea. &ltimg src='http://www.wired.com/images/slideshow/2008/08/gallery_electrical_meter/dunking_bird_t.jpg'>: Photo: &lta href="http://www.flickr.com/photos/tonyjcase/2734224070/"&gtGreat Beyond/Flickr&ltp>Throughout the 1880s, various inventors thought hard about the problem of how to measure the flow of electrons through time. Edison himself tried a two-electrode chemical system in which your charge was determined by how much zinc moved from one electrode to another. Workers actually had to weigh the electrodes to determine the price you paid. &ltp>Elihu Thomson developed a &lta href="http://watthourmeters.com/others/thomson.html"&gtwalking-beam meter that functioned quite like toy dunking birds left. The heating and cooling of alcohol inside a pair of bottles caused a periodic liquid exchange that caused the bottles to rock back and forth. And that mechanical motion is what the meter measured. It was an excellent hack, but it couldn't scale. &ltimg src='http://www.wired.com/images/slideshow/2008/08/gallery_electrical_meter/shallenberger_t.jpg'>: Iimage: Library of Congress&ltp>By 1888, a major, long-lasting dispute within the power industry was on the verge of getting settled. Edison had been promoting the use of direct-current power, despite the difficulty that the technology encountered transmitting electricity over long distances and changing the voltage. Both problems limited the uses of electricity. &ltp>George Westinghouse, meanwhile, purchased a patent for a transformer that could increase the voltage of alternating-current power. With a working transformer, his company, Westinghouse Electric, was able to send power over long distances, allowing for larger, centralized power-generating stations. These stations could power factories as well as your great-grandfather's school reading lamp. &ltp>But they needed to bill for it. And that's where Westinghouse employee &lta href=" /science/discoveries/news/2008/08/dayintech_0814"&gtOliver Shallenberger came in. His design left paved the way for Westinghouse to purchase a patent from Nikola Tesla for an improved AC system. The modern electrical grid was about to take root.&ltimg src='http://www.wired.com/images/slideshow/2008/08/gallery_electrical_meter/1a35247v_t.jpg'>: Photo: Library of Congress&ltp>With early success fueling investment in the electrical sector, a variety of new technologies began to converge to create the standard model for electrical generation and distribution in the United States. &ltp>Through the 1890s, various iterations of the induction watt-hour meter were becoming standard technology. These meters measure the number of rotations that a metal disk makes in response to magnetic flux within the meter. The amount of power is proportional to the speed of the disk's revolution, so the meter can accurately measure a range of energy usage levels. In most places, this is still how your company knows how much power your home or business is drawing. &ltp>Meanwhile, transmission-line technologists were steadily upping the voltage of the power lines running from ever-large power plants, like this one, to increasingly large cities filled with more and more electricity users. The higher the voltage, the better the quality of transmission over distance. &ltp>By the 1920s, the percentage of &lta href=" http://www.historynow.org/06_2008/print/historian5.html"&gttwo-thirds of American homes had electricity, and &lta href=" http://www.theobjectivestandard.com/issues/2008-summer/property-rights-electric-grid.asp"&gtthree-quarters of factories used electricity to power their motors. &ltimg src='http://www.wired.com/images/slideshow/2008/08/gallery_electrical_meter/edison_t.jpg'>: Image: Edison Electric Institute &ltp>During the Great Depression, the government began to regulate private utilities and push for getting electricity to rural areas far from urban centers through agencies like the Rural Electrification Administration and Tennessee Valley Authority. &ltp>The &ltcite&gtEdison Electric Institute Bulletin had a special issue in 1942 on "entering the seventh decade of electric power." By this time, almost all Americans had access to cheap and reliable electric power, but many could remember a time when they didn't. &ltp>The horsepower available to factory workers had increased from about 3 in 1914 to 6.5 in 1942, with most of the increase coming from purchased electrical power. As one professor chillingly put it, engineering advances had made 6 billion "manpower" available to the country, "equivalent to 50 slaves for each man, woman, and child." &ltimg src='http://www.wired.com/images/slideshow/2008/08/gallery_electrical_meter/8d07569u_t.jpg'>: Photo: Library of Congress&ltp&gtWith most of the metering and transmission infrastructure in place, all electrical companies had to do was make as much power as cheaply as possible. And that's all they did. Innovation in transmission and metering largely stopped. This 1940s meter technician would probably understand most meters in use today.&ltp>Most capital investment went to building power plants that could exploit the nation's ready source of cheap energy: coal. In 1949, only 84 million tons of coal wer used for electrical power production. By 1970, &lta href=" http://www.eia.doe.gov/emeu/aer/txt/ptb0703.html"&gtcoal consumption by the power industry had nearly quadrupled to 320 million tons per year. Last year, American utilities burned about 1.05 billion tons of coal to make electricity. &ltimg src='http://www.wired.com/images/slideshow/2008/08/gallery_electrical_meter/meter_3_t.jpg'>: Photo: &lta href="http://www.flickr.com/photos/slightlynorth/2395968752/"&gtSlightlynorth/flickr&ltp&gtThe golden age of cheap power came to an end some time in the last decade. Coal, which made electricity cheap and abundant, also happens to generate massive amounts of carbon dioxide, which is the greenhouse gas responsible for climate change. It's widely expected that the next president will sign a law that will tax carbon dioxide emissions, as is already the case in many places around the world. &ltp>The specter of energy regulation and rising natural gas, coal and petroleum prices has raised interest in new emission-free technologies like wind turbines and solar power. But the adoption of these technologies isn't as simple as it sounds. Both wind and solar -- which are abundant and clean -- will require substantial changes to the nation's transmission and billing systems. &ltp>Wind and solar, unlike coal, do not produce power at the same rate at all times. If they are adopted at scale, the grid infrastructure and the meters like this one will have to be much more flexible than what we built 100 years ago.&ltp>Power generation has been centralized since the very early days of the industry, but now, wind and solar open the possibility to generate power right on or near your home. But to make economic sense, we need meters and grid tie-ins that can easily accomplish this type of "reverse billing". &ltimg src='http://www.wired.com/images/slideshow/2008/08/gallery_electrical_meter/Tendril_10_t.jpg'>: Photo: Jon Snyder/Wired.com&ltp&gtSo, we find ourselves in a new era of electric meter innovation. A host of companies is trying to find just the right mix of features that will satisfy utilities and provide consumers with more flexibility in how they make, buy and use power. &ltp>Like everything else in the internet age, electricity-billing systems are about to make the transition from a centralized, one-way mode of operation to two-way systems that are connected to the internet. In addition to the back-end differences, the next generation of meters has received a facelift that will let consumers see their energy usage in near real-time. &ltp>Of course, people have been talking about "smart meters" for years. But after years of delayed rollouts, utilities finally appear ready to scale them up. &ltp>This &lta href="http://www.tendrilinc.com/consumers/"&gtelectronic meter from Tendril is slated for a massive rollout with five major utilities that the company says will reach 2 million homes. &ltbr style="clear: both;"/> &lta style='font-size: 10px; color: maroon;' href='http://www.pheedo.com/hostedMorselClick.phphfmm=v2:599d09fd9204df45c3248f64bb1d482e:EW+HbA7mN4hnjDJ0KkHYMgWbRMl4ZZI3YrcH56BP1Mq7u169U5/NDGlEAFhTtcAjgHQMpFitajcrFOBggt9KL3EvH1EDJdKN1Tzkg/yzth8='>&ltimg border='0' title='Add to Facebook' alt='Add to Facebook' src='http://www.pheedo.com/images/mm/facebook.gif'/> &lta style='font-size: 10px; color: maroon;' href='http://www.pheedo.com/hostedMorselClick.phphfmm=v2:4cac25661529f967d17c1e112a02035e:oP8sMhz9tCg3BMS25RF5cYA67i/cTzn0R6zdHhClbIUiC5ikdXaA99i466t9+chsdje8DT0owY6TCOccxCt6j/cH4q0WnmQmBD1JrsL/J+E='>&ltimg border='0' title='Add to Reddit' alt='Add to Reddit' src='http://www.pheedo.com/images/mm/reddit.png'/> &lta style='font-size: 10px; color: maroon;' href='http://www.pheedo.com/hostedMorselClick.phphfmm=v2:b13a62f4f64cffe0b0d3237184d7415d:ToKvRCMIxy0KSB/fkyXEVVjuSVfCEO7qMdns9p/wL8yRiV56kDaZXqI/58o88zups8NF00sLYWMGrhYxVt2BLB3UvFIDfeviWgQzxSTqC40='>&ltimg border='0' title='Add to digg' alt='Add to digg' src='http://www.pheedo.com/images/mm/digg.gif'/> &lta style='font-size: 10px; color: maroon;' href='http://www.pheedo.com/hostedMorselClick.phphfmm=v2:d7e1f2069f4a1eb12a64e8b749a252ec:bhDhxTbphMt3MT76kI/TTZGxgvzsIg+Ik4RWbZIDmZxGe6ay/1CpwA1UNk8iRJYcqb4d5nPeECgyQ3040+2BD2iXPfO2Sioy26ipR8wl9ec='>&ltimg border='0' title='Add to Google' alt='Add to Google' src='http://www.pheedo.com/images/mm/google.png'/>&ltbr style="clear: both;"/> &ltimg alt="" style="border: 0; height:1px; width:1px;" border="0" src="http://www.pheedo.com/img.phdoi=78ed3c8886fdd219d79c480b6d29a65d" height="1" />&ltimg src="http://www.pheedo.com/feeds/tracker.phpi=78ed3c8886fdd219d79c480b6d29a65d" style="display: none;" border="0" height="1" alt=""/>&ltp>&lta href="http://feeds.wired.com/~a/wired/indexa=4y1diN">&ltimg src="http://feeds.wired.com/~a/wired/indexi=4y1diN" border="0">&ltimg src="http://feeds.wired.com/~r/wired/index/~4/364419896" height="1" />



News related by topic - Top Stories:
Your pictures: Black - BBC
U.S. Marines launch major Afghan assault Reuters - Yahoo
Gay sex decriminalised in India - BBC
Mail U-turn pressure on ministers - BBC
Memorial Bad timing - TheTelegraph(Calcutta,India)
Petrol up Rs 4 in slick push - TheTelegraph(Calcutta,India)


News related by source - WiredNews:
Court Stiffs Veterans Caught in Privacy Breach - WiredNews
Jury Slaps $2 Million Fine on Jammie Thomas - WiredNews
How Science Fiction Writers Can Help, or Hurt, Homeland Security - WiredNews
Facebook, Google Go Persian, Helping Iran's Activists - WiredNews
How-To Wiki: How to Open a Beer Bottle With a Lighter - WiredNews
You Might Be Married to a GeekDad If ... - WiredNews



 
casino
News, World News, News Headlines, Top Stories, Breaking News, Globals News at www.worldofnews.com
Indian News, News from India, India News, Indian News Headlines, Indian breaking news, News, World news at www.indiasnews.com
UK News, British News, English News, News from UK, UK headlines, UK top stores, England News, Britain news, world news at www.worldofnews.co.uk
Home | About Us | Get News Feeds | Advertise Here | Terms of Service | Privacy Policy | Contact Us | Site Map