예제 #1
0
 public function priv_findquote($line, $args)
 {
     $channel = $line['to'];
     if ($channel == $this->ircClass->getNick()) {
         return;
     }
     $cqDB = $this->openDatabase($channel);
     if (!$cqDB) {
         $this->ircClass->notice($line['fromNick'], "Error attempting to access quotes database!");
         return;
     }
     if ($args['nargs'] == 0) {
         $this->ircClass->notice($line['fromNick'], "Usage: " . $args['cmd'] . " <search>");
     } else {
         if (strlen($args['query']) <= 2) {
             $this->ircClass->notice($line['fromNick'], "Query must be more than 2 characters.");
             return;
         }
         $type = "author";
         if ($args['cmd'] == "!findquote") {
             $type = "quote";
         }
         $results = $cqDB->searchSectionsByVar($type, $args['query'], CONTAINS_MATCH);
         $count = count($results);
         if ($count > 0) {
             $this->ircClass->notice($line['fromNick'], "There are " . $count . " quotes matching your query:");
             sort($results);
             $resultArray = irc::multiLine(implode(" ", $results));
             foreach ($resultArray as $quoteLine) {
                 $this->ircClass->notice($line['fromNick'], $quoteLine);
             }
             $this->ircClass->notice($line['fromNick'], "End of results.");
         } else {
             $this->ircClass->notice($line['fromNick'], "No quotes matching your query.");
         }
     }
 }
예제 #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);
             }
         }
     }
 }