/dev/null 2>/dev/null"); $file = fopen($out, "r"); $line = fgets($file); $oastyles = explode(",", $line); $line = fgets($file); $oavalues = explode(",", $line); fclose($file); for ($ii = 0; $ii < sizeof($oavalues); ++$ii) { $unquoted = ereg_replace('"', '', $oavalues[$ii]); if ($unquoted == "") { continue; } if ($oastyles[$ii] == "PolarityMeanName") { $polarity = $unquoted; } elseif ($oastyles[$ii] == "SlangName") { $slang = $unquoted; } elseif ($oastyles[$ii] == "FlamboyanceName") { $flamboyant = $unquoted; } elseif ($oastyles[$ii] == "OfferingGuidanceName") { $offerguide = $unquoted; } elseif ($oastyles[$ii] == "RequestingGuidanceName") { $requestguide = $unquoted; } elseif ($oastyles[$ii] == "DecisivenessName") { $decisive = $unquoted; } elseif ($oastyles[$ii] == "ControversyName") { $controversy = $unquoted; } } findopenamplify(); } function processargs() { global $mail; putenv("http_proxy=noauthproxy.serc.iisc.ernet.in:3128"); if ($_POST['mode'] == "sendmail") { $mail = $_POST['mail']; processsendmail(); } } function showtodo() { print "TODO:\n"; print "\n"; print "\n"; } function showfooter() { print "  Home\n"; } function showform() { global $search, $mail; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "\n"; for ($ii = 0; $ii < 50; ++$ii) { print " "; } print "Examples: one | two | three.\n"; print "
\n"; print "
\n"; print " "; print "\n"; showtodo(); print "
\n"; showfooter(); } function process() { } function getlinks($mail) { $delim = ":::"; $mail = ereg_replace("http://", "http://$delim", $mail); $tokens = explode("http://", $mail); for ($ii = 0; $ii < sizeof($tokens); ++$ii) { if (preg_match("/$delim/", $tokens[$ii])) { $tokens[$ii] = ereg_replace(".*$delim([^ \t\n\r]*).*", "http://\\1", $tokens[$ii]); } else { $tokens[$ii] = ""; } } return $tokens; } function extractinfo($line) { $delim = ":::"; $line = ereg_replace(".*", "\\1$delim", $line); $line = ereg_replace("<\/a>.*", "", $line); return explode($delim, $line); } function storehotlinks() { global $hotlinks, $hottitles; $descriptionon = false; $ii = 0; $file = fopen("../hotlinks/feed/daily.IN.xml", "r"); $line = fgets($file); while (!feof($file)) { if (preg_match("//", $line) && !preg_match("/<\/description>/", $line)) { $descriptionon = true; $hottitles[] = array(); $hotlinks[] = array(); list($hotlinks[$ii][], $hottitles[$ii][]) = extractinfo($line); } elseif (preg_match("/<\/description>/", $line) && !preg_match("//", $line)) { $descriptionon = false; ++$ii; } elseif ($descriptionon) { list($hotlinks[$ii][], $hottitles[$ii][]) = extractinfo($line); } $line = fgets($file); } fclose($file); /*for ($ii = 0; $ii < sizeof($hotlinks); ++$ii) { for ($jj = 0; $jj < sizeof($hotlinks[$ii]); ++$jj) { print "link[$ii][$jj] = ".$hotlinks[$ii][$jj].", title[$ii][$jj] = ".$hottitles[$ii][$jj].".
\n"; } }*/ } function getmorehotlinks($link) { global $hotlinks, $hottitles; $morehotlinks = array(); $morehottitles = array(); $found = false; for ($ii = 0; $ii < sizeof($hotlinks); ++$ii) { $iilinks = $hotlinks[$ii]; for ($jj = 0; $jj < sizeof($iilinks); ++$jj) { if ($iilinks[$jj] == $link) { $found = true; break; } } if ($found) { for ($jj = 0; $jj < sizeof($iilinks); ++$jj) { if ($iilinks[$jj] != $link) { $morehotlinks[] = $iilinks[$jj]; $morehottitles[] = $hottitles[$ii][$jj]; } } break; } } return array($morehotlinks, $morehottitles); } function processlinks($links) { $morelinks = array(); for ($ii = 0; $ii < sizeof($links); ++$ii) { list($morehotlinks, $morehottitles) = getmorehotlinks($links[$ii]); for ($jj = 0; $jj < sizeof($morehotlinks); ++$jj) { $morelinks[] = "
$morehottitles[$jj]"; } } return implode("\n", $morelinks); } function getkeywords($mailmod) { $delim = ":::"; $keywords = array(); $out = "out"; $query = "wget --post-data=\"context=$mailmod&appid=Hub-Finder\" http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction -O $out >/dev/null 2>/dev/null"; system($query); $file = fopen($out, "r"); $line = fgets($file); while (!feof($file)) { if (preg_match("//", $line)) { $line = ereg_replace("", "$delim", $line); $allkey = explode($delim, $line); for ($ii = 0; $ii < sizeof($allkey); ++$ii) { $line = $allkey[$ii]; $line = ereg_replace(".*", "", $line); $line = ereg_replace("<\/Result>.*", "", $line); $keywords[] = $line; } break; } $line = fgets($file); } fclose($file); return $keywords; } function extractimages($out) { $images = array(); $file = fopen($out, "r"); $line = fgets($file); while (!feof($file)) { if (preg_match("/photo_container pc_t/", $line)) { $img = ereg_replace(".*).*", " 2 ? 2 : sizeof($keywords)); for ($ii = 0; $ii < $min && $ii < sizeof($keywords); ++$ii) { $key = urlencode($keywords[$ii]); $query = "wget http://www.flickr.com/photos/tags/$key -O $out >/dev/null 2>/dev/null"; system($query); $images[] = extractimages($out); if (sizeof($images[$ii]) == 0) { ++$min; } } $imagesstr = ""; $imagesstr .= ""; $nimages = 0; for ($ii = 0; $ii < sizeof($images); ++$ii) { $minjj = (sizeof($images[$ii]) > 2 ? 2 : sizeof($images[$ii])); for ($jj = 0; $jj < $minjj; ++$jj) { $imagesstr .= ""; if (++$nimages > 4) { $nimages = 0; $imagesstr .= ""; } } } for (; $nimages < 4; ++$nimages) { $imagesstr .= ""; } $imagesstr .= "
"; $imagesstr .= $images[$ii][$jj]; $imagesstr .= "
 
\n"; return $imagesstr; } function getmailheaders() { $mailheaders = ""; $mailheaders .= "From: Rupesh Nasre.\r\n"; $mailheaders .= "Reply-To: Rupesh Nasre.\r\n"; $mailheaders .= "Content-Type: multipart/alternative\r\n"; return $mailheaders; } function findopenamplify() { global $polarity, $slang, $flamboyant, $offerguide, $requestguide, $decisive, $controversy; global $levelpolarity, $levelslang, $levelflamboyant, $levelofferguide, $levelrequestguide, $leveldecisive, $levelcontroversy; if ($polarity == "Negative") { $levelpolarity = 0; } elseif ($polarity == "Positive") { $levelpolarity = 2; } if ($slang == "Slang") { $levelslang = 1; } if ($flamboyant == "Not Very Flamboyant") { $levelflamboyant = 1; } elseif ($flamboyant == "Somewhat Flamboyant") { $levelflamboyant = 2; } elseif ($flamboyant == "Flamboyant") { $levelflamboyant = 3; } elseif ($flamboyant == "Very Flamboyant") { $levelflamboyant = 4; } if ($offerguide == "To Some Extent") { $levelofferguide = 1; } elseif ($offerguide == "A Lot") { $levelofferguide = 2; } if ($requestguide == "To Some Extent") { $levelrequestguide = 1; } elseif ($requestguide == "A Lot") { $levelrequestguide = 2; } if ($decisive == "Low") { $leveldecisive = 1; } elseif ($decisive == "Medium Low") { $leveldecisive = 2; } elseif ($decisive == "Medium") { $leveldecisive = 3; } elseif ($decisive == "Medium High") { $leveldecisive = 4; } elseif ($decisive == "High") { $leveldecisive = 5; } if ($controversy == "To Some Extent") { $levelcontroversy = 1; } elseif ($controversy == "A Lot") { $levelcontroversy = 2; } } function printlevels($nlevels, $tag, $level) { print "\n"; for ($ii = $nlevels - 1; $ii >= 0; --$ii) { if ($level == $ii) { print "\n"; } else { print "\n"; } } print "
 $tag 
 
\n"; } function printopenamplify() { global $polarity, $slang, $flamboyant, $offerguide, $requestguide, $decisive, $controversy; // 3 2 5 3 3 6 3 global $levelpolarity, $levelslang, $levelflamboyant, $levelofferguide, $levelrequestguide, $leveldecisive, $levelcontroversy; print "
\n"; print "\n"; print "\n"; printlevels(3, $polarity, $levelpolarity); printlevels(2, $slang, $levelslang); printlevels(5, $flamboyant, $levelflamboyant); printlevels(3, $offerguide, $levelofferguide); printlevels(3, $requestguide, $levelrequestguide); printlevels(6, $decisive, $leveldecisive); printlevels(3, $controversy, $levelcontroversy); print "
PolaritySlangFlamboyantOffer GuidanceRequest GuidanceDecisiveControversial
\n"; } function gettwitter() { $tweets = array(); $out = "out"; system("wget -O $out http://twitter.com/Sudhira >/dev/null 2>/dev/null"); $file = fopen($out, "r"); $line = fgets($file); while (!feof($file)) { if (preg_match('/class="entry-content"/', $line)) { $tweets[] = $line; } $line = fgets($file); } fclose($file); return $tweets; } function printtwitter() { $tweets = gettwitter(); print "Receiver's Tweets.\n"; print "
    \n"; $maxii = sizeof($tweets); if ($maxii > 5) { $maxii = 5; } for ($ii = 0; $ii < $maxii; ++$ii) { print "
  • $tweets[$ii]\n"; } print "
\n"; } function savemail() { global $mail; $filename = "data/".date('Ymd-His'); $remoteaddr = $_SERVER['REMOTE_ADDR']; $file = fopen($filename, "w"); fputs($file, $remoteaddr."\n"); fputs($file, $mail); fclose($file); } function processsendmail() { global $mail; savemail(); print "
\n"; print "\n"; print "\n"; print "
Mail preview
\n"; storehotlinks(); $mailmod = $mail; $links = getlinks($mailmod); /*for ($ii = 0; $ii < sizeof($links); ++$ii) { print "links[$ii] = $links[$ii].
\n"; }*/ $mailmod .= "\n".processlinks($links)."\n"; $mailmod .= processkeywords($mailmod); $mailhtml = ereg_replace("\n", "
\n", $mailmod); print "$mailhtml"; //mail("nasre@csa.iisc.ernet.in", "Test Enrich.", $mailhtml, getmailheaders()); print "
\n"; getopenamplify(); printopenamplify(); print "
\n"; printtwitter(); print "
\n"; } function showhead() { print "

Enrich Email Experience.

\n"; print "Enter some text and get photos relevant to your email. Further, get 'mood' of the mail (courtesy:
OpenAmplify). Winning entry at Yahoo! University Hack 2010 at IISc.
\n"; } function main() { showhead(); processargs(); showform(); process(); } main(); ?>