Beispiel #1
0
 public function priv_bash($line, $args)
 {
     $channel = $line['to'];
     $random = false;
     if (strpos($channel, "#") === false) {
         return;
     }
     if ($this->ircClass->getStatusRaw() != STATUS_CONNECTED_REGISTERED) {
         return;
     }
     if (time() < $this->delay) {
         $this->ircClass->notice($line['fromNick'], "Please wait " . ($this->delay - time()) . " seconds before using this function again.", 0);
         return;
     }
     //?search=test&sort=0&show=25
     if ($args['nargs'] > 0) {
         if ($args['arg1'] == "+") {
             $random = true;
             $query = "random1&show=1";
         } else {
             if ($args['arg1'] == "-") {
                 $this->ircClass->notice($line['fromNick'], "This is an unsupported function.");
                 return;
             } else {
                 $num = $args['arg1'];
                 if (substr($num, 0, 1) == "#") {
                     $num = substr($num, 1);
                 }
                 $num = intval($num);
                 if ($num <= 0) {
                     $search = urlencode($args['query']);
                     $random = true;
                     $query = "search=" . $search . "&show=1&sort=0";
                 } else {
                     $query = "{$num}";
                 }
             }
         }
     } else {
         $random = true;
         $query = "random&show=1";
     }
     $line['channel'] = $channel;
     $line['random'] = $random;
     $host = "www.bash.org";
     $port = 80;
     $path = "/";
     $getQuery = socket::generateGetQuery($query, $host, $path, "1.0");
     $this->ircClass->addQuery($host, $port, $getQuery, $line, $this, "priv_bash_stageTwo");
 }
Beispiel #2
0
 public function search_response($line, $args, $result, $site)
 {
     if ($result == QUERY_ERROR) {
         $this->ircClass->notice($line['fromNick'], "Error: " . $site);
         return;
     }
     $site = str_replace("&#160;", ";", $site);
     $site = str_replace("\r", "", $site);
     $site = html_entity_decode($site);
     preg_match_all("/<li>\\s*<a href=\"\\/title\\/(.+?)\\/.+?>(.+?)<\\/a>\\s*(\\(.+?\\)){1}?(\\s)?(.+?)*?<\\/li>/i", $site, $matches, PREG_PATTERN_ORDER);
     $topTen = array();
     for ($i = 0; $i < count($matches[1]); $i++) {
         if ($matches[4][$i] == " ") {
             continue;
         }
         $link = trim($matches[1][$i]);
         $title = trim($matches[2][$i]);
         $date = trim($matches[3][$i]);
         $lTitle = strtolower($title);
         if (!isset($this->cache[$lTitle])) {
             $this->cache[$lTitle] = array();
             $this->cache[$lTitle][$date] = $link;
         } else {
             if (!isset($this->cache[$lTitle][$date])) {
                 $this->cache[$lTitle][$date] = $link;
                 krsort($this->cache[$lTitle]);
             }
         }
         $topTen[] = $title . " " . $date;
     }
     $tkey = strtolower($args["query"]);
     $lArgs = explode(chr(32), $tkey);
     $tCount = count($lArgs);
     if ($tCount > 0) {
         $date = $lArgs[count($lArgs) - 1];
         $title = trim(str_replace($date, "", $tkey));
     }
     if (isset($this->cache[$tkey])) {
         foreach ($this->cache[$tkey] as $date => $link) {
             break;
         }
         $line["link"] = $link;
         $line["title"] = $tkey;
         $line["date"] = $date;
         $search = socket::generateGetQuery("", "www.imdb.com", "/title/" . $link . "/", "1.0");
         $this->ircClass->addQuery("www.imdb.com", 80, $search, $line, $this, "title_response");
     } else {
         if ($tCount > 0 && isset($this->cache[$title]) && isset($this->cache[$title][$date])) {
             $link = $this->cache[$title][$date];
             $line["link"] = $link;
             $line["title"] = $title;
             $line["date"] = $date;
             $search = socket::generateGetQuery("", "www.imdb.com", "/title/" . $link . "/", "1.0");
             $this->ircClass->addQuery("www.imdb.com", 80, $search, $line, $this, "title_response");
         } else {
             $total = count($topTen);
             $total = $total > 10 ? 10 : $total;
             if ($total <= 0) {
                 $this->ircClass->notice($line['fromNick'], "No responses from server.  Try broadening your search.  If you included a date, remove it and try again.");
                 return;
             }
             $this->ircClass->notice($line['fromNick'], "Top " . $total . " responses from www.imdb.com");
             $resp = "";
             for ($i = 0; $i < $total; $i++) {
                 $resp .= DARK . "[" . BRIGHT . $topTen[$i] . DARK . "] - ";
             }
             $multi = irc::multiLine($resp);
             foreach ($multi as $mult) {
                 $this->ircClass->notice($line['fromNick'], $mult);
             }
         }
     }
 }
Beispiel #3
0
 public function priv_video($line, $args)
 {
     if ($args['nargs'] < 1) {
         $this->sendMsg($line, $args, 'You need to supply a search string');
         return;
     }
     $getQuery = socket::generateGetQuery('q=' . urlencode($args['query']) . '&hl=en', 'video.google.' . $this->extension, '/videosearch');
     $this->ircClass->addQuery('video.google.' . $this->extension, 80, $getQuery, $line, $this, 'sendVideoResults');
 }
Beispiel #4
0
 public function priv_leo($line, $args)
 {
     if ($args['nargs'] < 1) {
         $this->sendMsg($line, $args, 'You need to supply a search string');
         return;
     }
     $cmdLower = irc::myStrToLower($args['cmd']);
     switch ($cmdLower) {
         case '!fra':
             $query = 'lp=frde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search=' . urlencode($args['query']) . '&relink=off';
             $getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/frde');
             break;
         case '!esp':
             $query = 'lp=esde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search=' . urlencode($args['query']) . '&relink=off';
             $getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/esde');
             break;
         case '!ita':
             $query = 'lp=itde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search=' . urlencode($args['query']) . '&relink=off';
             $getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/itde');
             break;
             // skip chinese, output is garbage only anyway
             //case '!chn':
             //	$query = 'lp=chde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search='.urlencode($args['query']).'&relink=off';
             //	$getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/chde');
             //	break;
         // skip chinese, output is garbage only anyway
         //case '!chn':
         //	$query = 'lp=chde&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=off&spellToler=on&search='.urlencode($args['query']).'&relink=off';
         //	$getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/chde');
         //	break;
         default:
             $query = 'lp=ende&lang=de&searchLoc=0&cmpType=relaxes&sectHdr=off&spellToler=on&search=' . urlencode($args['query']) . '&relink=off';
             $getQuery = socket::generateGetQuery($query, 'dict.leo.org', '/ende');
     }
     // switch
     $this->ircClass->addQuery('dict.leo.org', 80, $getQuery, $line, $this, 'sendLeoResults');
 }
Beispiel #5
0
 public function function_response($line, $args, $result, $site)
 {
     if ($result == QUERY_ERROR) {
         $this->ircClass->notice($line['fromNick'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - Error: " . $site);
         return;
     }
     $location = $this->checkLocation($site);
     if (count($location) >= 3) {
         $domain = $location['scheme'] . '://' . $location['host'] . $location['path'];
         if (isset($location['query'])) {
             $domain .= '?' . $location['query'];
             $query = $location['query'];
         } else {
             $query = "";
         }
         $search = socket::generateGetQuery($query, $location['host'], $location['path'], "1.0");
         $this->ircClass->addQuery($location['host'], 80, $search, $line, $this, "function_response");
     } else {
         //$site = html_entity_decode($site);
         $site = str_replace("\n", "", $site);
         $site = str_replace("\r", "", $site);
         preg_match_all('/<base href="(.*?)" \\/>/is', $site, $matches);
         // TODO: Fix the page url, seems to contain HTML ONLY SEEMS TO HAPPEN WHEN YOU CALL A FUNCTION THAT RETURNS A SEARCH
         $page_url = isset($matches[1][0]) ? $this->parse_php_url($matches[1][0]) : null;
         $response = array('query' => $this->query, 'fromWho' => $line['fromNick'], 'toWho' => '', 'mask' => $line['fromHost'], 'channel' => $line['to'], 'function' => '', 'versions' => '', 'defenition' => '', 'description' => '', 'url' => $page_url, 'matches' => '', 'library' => '', 'hits' => 1, 'timestamp' => time());
         if (isset($line['toWho'])) {
             $response['toWho'] = $line['toWho'];
         }
         if (preg_match('/<li class="header up"><a href="funcref.php">Function Reference<\\/a><\\/li>/is', $site)) {
             // found a function reference page
             preg_match_all('/<li class="active"><a href="(.*?)">(.*?)<\\/a><\\/li>/is', $site, $matches, PREG_PATTERN_ORDER);
             $response['library'] = $matches[2][0];
             $this->doCacheCheck($response);
             if ($line['toOther'] === TRUE) {
                 $this->ircClass->notice($line['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $line['fromNick'] . " wants you to know about " . $this->query . DARK);
             }
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - php.net response for " . $this->query . DARK);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['library'] . " Function Reference" . DARK);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['url'] . DARK);
         } elseif (preg_match('/Sorry, but the function <b>' . $this->query . '<\\/b> is not in the online manual/is', $site)) {
             // parse out the closest matches if there are any
             preg_match_all('/<a href="\\/manual\\/en\\/function.(.*?)"><b>(.*?)<\\/b><\\/a><br \\/>/is', $site, $matches);
             if (isset($matches[2]) && $matches[2] != "") {
                 $response['matches'] = serialize($matches[2]);
                 $response['matchCount'] = count($matches[2]);
             } else {
                 $response['matches'] = serialize(array());
                 $response['matchCount'] = 0;
             }
             $this->doCacheCheck($response);
             $message = DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - Could not find a perfect match for " . $this->query . ".";
             if ($response['matchCount'] > 0) {
                 $message .= " Maybe one of the following (" . $response['matchCount'] . ") suggestions: " . implode(', ', unserialize($response['matches'])) . "." . DARK;
             } else {
                 $message .= " I am unable to come up with any close matches, sorry." . DARK;
             }
             $this->ircClass->notice($line['toWho'], $message);
         } else {
             // Grab the rest of the info from the page
             preg_match_all("/<\\/A><P>(.*?)\\((.*?)\\)<\\/P>(.*?)--(.*?)<\\/DIV><DIVCLASS=\"(.*?)\"><ANAME=\"(.*?)\"><\\/A><H2>Description<\\/H2>(.*?)<BR>/is", $site, $matches, PREG_PATTERN_ORDER);
             $response['versions'] = isset($matches[2][0]) ? html_entity_decode($matches[2][0]) : null;
             $response['function'] = isset($matches[3][0]) ? trim(str_replace('&nbsp;', '', strip_tags($matches[3][0]))) : null;
             $response['description'] = isset($matches[4][0]) ? trim(str_replace('&nbsp;', '', strip_tags($matches[4][0]))) : null;
             $response['defenition'] = isset($matches[7][0]) ? trim(str_replace('&nbsp;', '', strip_tags($matches[7][0]))) : null;
             //$response['url'] = $this->parse_php_url($page_url);
             $this->doCacheCheck($response);
             if ($line['toOther'] === TRUE) {
                 $this->ircClass->notice($line['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $line['fromNick'] . " wants you to know about " . $this->query . DARK);
             }
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - php.net response for " . $this->query . DARK);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['function'] . ' -- ' . $response['description']);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['versions']);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['defenition']);
             $this->ircClass->notice($response['toWho'], DARK . "[" . BRIGHT . 'iPHP' . DARK . "] - " . $response['url']);
         }
     }
 }