my $num_items = 20; my $apos = '&' . 'apos;'; my $output = < ThinkGeek: What${apos}s New http://www.thinkgeek.com/?cpg=wnrdf Stuff for Smart Masses EOF my $c = sql_select("news_item.*","news,news_item","news.active='y' AND " . "news_item.news_id=news.news_id AND news_item.active='y' AND " . "news_item.on_rdf='y'", "ORDER BY news.news_date DESC,news_item.weight DESC"); my $i = 0; my ($cur, $ret); while ($cur = $c->fetchrow_hashref) { last unless $i < $num_items; if ($cur->{'type'} eq 'generic') { $ret = _item_generic($cur); } else { $ret = _item_product($cur); } next unless $ret =~ /\/; $output .= $ret; $i++; } $output .= " \n\n"; return $output; sub _item_generic ($) { my $cur = shift; return -1 unless $cur->{'url_target'} =~ /\w+/; return -1 unless $cur->{'description'} =~ /\w+/; my $loc = $cur->{'url_target'}; my $name = $cur->{'description'}; $loc = '/' . $loc unless $loc =~ /^\//; $loc .= $loc =~ /\?/ ? '&cpg=wnrdf' : '?cpg=wnrdf'; $name = _escape($name); my $ret = " \n"; $ret .= " $name\n"; $ret .= " http://www.thinkgeek.com$loc\n"; $ret .= " \n"; return $ret; } sub _item_product ($) { my $cur = shift; my ($d, $dur, $code, $name, $loc, $cat_id, @cats); $d = sql_select("name","products","item_id=?? AND discont='n'",undef,[$cur->{'owner'}]); return -1 if $d->rows < 1; $dur = $d->fetchrow_arrayref; $name = $dur->[0]; $d = sql_select("cat_links.cat_id","pages,cat_links","pages.type='product' AND " . "pages.owner=?? AND pages.active='y' AND pages.prod_def='y' AND " . "cat_links.child_type='page' AND cat_links.child=pages.page_id AND " . "cat_links.active='y'", "ORDER BY cat_links.child_def,cat_links.weight DESC LIMIT 1", [$cur->{'owner'}]); return -1 if $d->rows < 1; $dur = $d->fetchrow_arrayref; @cats = cont_cat_parent_list($dur->[0], 1); $cat_id = $cats[0]; $d = sql_select("name","categories","cat_id=??",undef,[$cat_id]); if ($d->rows > 0) { $dur = $d->fetchrow_arrayref; $name = $dur->[0] . ': ' . $name; } $name = _escape($name); $loc = '/'; foreach $cat_id (@cats) { $d = sql_select("name_url","categories","cat_id=??",undef,[$cat_id]); $dur = $d->fetchrow_arrayref; $loc .= $dur->[0] . '/'; } $loc .= $cur->{'owner'} . '/' . '?cpg=wnrdf'; my $ret = " \n"; $ret .= " $name\n"; $ret .= " http://www.thinkgeek.com$loc\n"; $ret .= " \n"; return $ret; } sub _escape($) { my %esc_chars = ( chr(34) => '&' . 'quot;', # chr(38) => '&' . 'amp;', chr(39) => '&' . 'apos;', chr(60) => '&' . 'lt;', chr(62) => '&' . 'gt;', ); my $amp = '&' . 'amp;'; my $str = shift; $str =~ s/\&/$amp/gs; my ($chr); foreach $chr (keys %esc_chars) { $str =~ s/$chr/$esc_chars{$chr}/gs; } return $str; }