function get_help($cmd) { $title = "IRC:exec aliases"; $section = $cmd; if (login(True) == False) { return False; } $result = ""; $text = get_text($title, $section, True, True); if ($text !== False) { for ($i = 0; $i < min(count($text), 3); $i++) { bot_ignore_next(); privmsg(trim($text[$i])); } if ($cmd[0] == "~") { $cmd = ".7E" . substr($cmd, 1); } privmsg("http://wiki.soylentnews.org/wiki/IRC:exec_aliases#{$cmd}"); $result = True; } logout(True); return $result; }
function get_text($title, $section, $return = False, $return_lines_array = False) { if ($title == "") { wiki_privmsg($return, "wiki: get_text=invalid title"); return False; } $index = -1; $title = str_replace(" ", "_", $title); if ($section != "") { $uri = "/w/api.php?action=parse&format=php&page=" . urlencode($title) . "&prop=sections"; $response = wget(WIKI_HOST, $uri, 80, WIKI_USER_AGENT); $data = unserialize(strip_headers($response)); if (isset($data["parse"]["sections"]) == False) { wiki_privmsg($return, "wiki: get_text=error getting sections for page \"" . $title . "\""); return False; } $sections = $data["parse"]["sections"]; for ($i = 0; $i < count($sections); $i++) { $line = $sections[$i]["line"]; if (strtolower($section) == strtolower($line)) { $index = $sections[$i]["index"]; break; } } } $uri = "/w/api.php?action=parse&format=php&page=" . urlencode($title) . "&prop=text"; if ($index > 0) { $uri = $uri . "§ion={$index}"; } /*$url="http://".WIKI_HOST.$uri; $url=get_redirected_url($url); if (get_host_and_uri($url,&$host,&$uri,&$port)==False) { wiki_privmsg($return,"wiki: get_text=url parse failed"); return False; }*/ $response = wget(WIKI_HOST, $uri, 80, WIKI_USER_AGENT); $data = unserialize(strip_headers($response)); if (isset($data["parse"]["text"]["*"]) == True) { $text = $data["parse"]["text"]["*"]; if ($section != "") { $id = str_replace(" ", "_", $section); $id = str_replace("~", ".7E", $id); $id = str_replace("(", ".28", $id); $id = str_replace(")", ".29", $id); $head = "<span class=\"mw-headline\" id=\"{$id}\">{$section}</span>"; if (strpos($text, $head) === False) { wiki_privmsg($return, "wiki: get_text=section span not found"); return False; } } } else { wiki_privmsg($return, "wiki: get_text=section not found"); return False; } strip_comments($text); strip_all_tag($text, "h2"); strip_all_tag($text, "h3"); $text = strip_tags($text); $text = trim($text, " \t\n\r\v\""); $br = random_string(30); $text = str_replace("\n", $br, $text); $text = replace_ctrl_chars($text, " "); $text = html_decode($text); $text = clean_text($text); $url = "http://wiki.soylentnews.org/wiki/" . urlencode($title); if ($section != "") { $url = $url . "#{$id}"; } if ($return_lines_array == False) { $text = str_replace($br, " ", $text); $text = clean_text($text); if (strlen($text) > 400) { $text = trim(substr($text, 0, 400)) . "..."; } bot_ignore_next(); wiki_privmsg($return, $text); wiki_privmsg($return, $url); $result = $text; } else { $result = explode($br, $text); for ($i = 0; $i < count($result); $i++) { $result[$i] = trim($result[$i]); if (strlen($result[$i]) > 300) { $result[$i] = trim(substr($result[$i], 0, 300)) . "..."; } } delete_empty_elements($result); $result[] = $url; } return $result; }