Esempio n. 1
0
function youtube_search($query)
{
    $agent = ICEWEASEL_UA;
    $host = "www.youtube.com";
    $uri = "/results";
    $port = 443;
    $params = array();
    $params["search_query"] = $query;
    $response = wpost($host, $uri, $port, $agent, $params);
    $html = strip_headers($response);
    strip_all_tag($html, "head");
    strip_all_tag($html, "script");
    strip_all_tag($html, "style");
    $delim1 = "class=\"item-section\">";
    $delim2 = "</ol>";
    $html = extract_text_nofalse($html, $delim1, $delim2);
    $results = explode("<li><div class=\"yt-lockup yt-lockup-tile yt-lockup-video vve-check clearfix yt-uix-tile\"", $html);
    array_shift($results);
    if (count($results) == 0) {
        return False;
    }
    for ($i = 0; $i < count($results); $i++) {
        $parts = explode(">", $results[$i]);
        array_shift($parts);
        $results[$i] = implode(">", $parts);
        $delim1 = "<h3 class=\"yt-lockup-title \">";
        $delim2 = "</h3>";
        $results[$i] = extract_text_nofalse($results[$i], $delim1, $delim2);
        $delim1 = "<a href=\"";
        $delim2 = "\" ";
        $url = "https://www.youtube.com" . extract_text_nofalse($results[$i], $delim1, $delim2);
        $delim1 = "dir=\"ltr\">";
        $delim2 = "</a>";
        $title = extract_text_nofalse($results[$i], $delim1, $delim2);
        $title = html_decode($title);
        $title = html_decode($title);
        $delim1 = "> - Duration: ";
        $delim2 = ".</span>";
        $time = extract_text_nofalse($results[$i], $delim1, $delim2);
        $results[$i] = $url . " - " . $title . " - " . $time;
    }
    return $results;
}
Esempio n. 2
0
function wiki_autospamctl($nick, $trailing)
{
    $spam_user_list = array();
    $safe_user_list = array();
    $spam_rule_list = array();
    if (file_exists(DATA_PATH . "wiki_spam_users") == True) {
        $spam_user_list = explode(PHP_EOL, file_get_contents(DATA_PATH . "wiki_spam_users"));
        delete_empty_elements($spam_user_list, True);
    }
    if (file_exists(DATA_PATH . "wiki_safe_users") == True) {
        $safe_user_list = explode(PHP_EOL, file_get_contents(DATA_PATH . "wiki_safe_users"));
        delete_empty_elements($safe_user_list, True);
    }
    if (file_exists(DATA_PATH . "wiki_spam_rules") == True) {
        $spam_rule_list = explode(PHP_EOL, file_get_contents(DATA_PATH . "wiki_spam_rules"));
        delete_empty_elements($spam_rule_list, True);
    }
    $test_title = trim(extract_text_nofalse($trailing, "14[[07", "14]]"));
    $test_nick = trim(extract_text_nofalse($trailing, " 5* 03", " 5*"));
    if ($test_title == "" or $test_nick == "") {
        return;
    }
    if (in_array($test_nick, $safe_user_list) == True) {
        return;
    }
    $prefix = "Special:";
    if (substr($test_title, 0, strlen($prefix)) == $prefix) {
        return;
    }
    $rule_match = False;
    for ($i = 0; $i < count($spam_rule_list); $i++) {
        if (preg_match($spam_rule_list[$i], $test_nick) == 1) {
            $rule_match = True;
            break;
        }
    }
    if ($rule_match == False) {
        if (in_array($test_nick, $spam_user_list) == False) {
            return;
        }
    }
    privmsg("auto-spamctl for article \"{$test_title}\" by spam user \"{$test_nick}\"");
    wiki_spamctl($nick, ".spamctl {$test_title}");
}
Esempio n. 3
0
$amount = $parts[0];
$from_unit = $parts[1];
$to_unit = $parts[2];
$func_name = "convert_" . strtolower($from_unit) . "_" . strtolower($to_unit);
if (function_exists($func_name) == True) {
    call_user_func($func_name, $amount);
}
$func_name = "convert_" . strtolower($to_unit) . "_" . strtolower($from_unit);
if (function_exists($func_name) == True) {
    call_user_func($func_name, $amount, True);
}
$response = wget("www.google.com", "/finance/converter?a=" . $amount . "&from=" . $from_unit . "&to=" . $to_unit, 80);
$html = strip_headers($response);
$delim1 = "<div id=currency_converter_result>";
$delim2 = "</div>";
$result = extract_text_nofalse($html, $delim1, $delim2);
$result = trim(strip_tags($result));
if ($result == "") {
    convert_privmsg($syntax);
}
convert_privmsg($result);
#####################################################################################################
function convert_privmsg($msg)
{
    privmsg(chr(3) . "03" . $msg);
    die;
}
#####################################################################################################
function convert_result($amount, $result, $from_unit, $to_unit, $space = True)
{
    if ($space == True) {
Esempio n. 4
0
$delim1 = "<h2 ";
$delim2 = "</h2>";
$name = extract_text_nofalse($html, $delim1, $delim2);
$name = strip_tags("<" . $name);
$name = clean_text($name);
$name = html_decode($name);
$name = html_decode($name);
$delim1 = "<div class=\"highlight\"><pre>";
$delim2 = "</pre></div>";
$example = extract_text_nofalse($html, $delim1, $delim2);
$example = strip_tags($example);
$example = clean_text($example);
$example = html_decode($example);
$example = html_decode($example);
$delim1 = "</pre></div>";
$delim2 = "</p>";
$description = extract_text_nofalse($html, $delim1, $delim2);
$description = strip_tags($description);
$description = clean_text($description);
$description = html_decode($description);
$description = html_decode($description);
if ($name != "" and $example != "" and $description != "") {
    privmsg(chr(3) . "07" . $name);
    privmsg(chr(3) . "07" . $description);
    privmsg(chr(3) . "07" . $example);
    privmsg(chr(3) . "07" . "http://doc.perl6.org/routine/" . urlencode($trailing));
} else {
    privmsg(chr(3) . "07" . "error/not found");
    privmsg(chr(3) . "07" . "http://doc.perl6.org/routine/" . urlencode($trailing));
}
#####################################################################################################
Esempio n. 5
0
function process_weather(&$location, $nick, $getdata = False)
{
    $loc = get_location($location, $nick);
    term_echo("*** WEATHER LOCATION LOOKUP: {$loc}");
    if ($loc === False) {
        if ($location == "") {
            return False;
        }
        $loc = $location;
    }
    $location = $loc;
    $loc_query = filter($loc, VALID_UPPERCASE . VALID_LOWERCASE . VALID_NUMERIC . " ");
    $prefs = get_prefs($nick);
    $fheit = "1";
    $use_unit_pref = False;
    if (isset($prefs["unit"]) == True and $getdata == False) {
        if ($prefs["unit"] == "metric") {
            $use_unit_pref = True;
            $fheit = "0";
        }
        if ($prefs["unit"] == "imperial") {
            $use_unit_pref = True;
        }
    }
    # https://www.google.com/search?gbv=1&q=weather+traralgon
    $url = "http://www.google.com.au/search?gbv=1&fheit={$fheit}&q=weather+" . urlencode($loc_query);
    term_echo($url);
    $response = wget("www.google.com.au", "/search?gbv=1&fheit={$fheit}&q=weather+" . urlencode($loc_query), 80, ICEWEASEL_UA, "", 60);
    $html = strip_headers($response);
    $delim1 = "<div class=\"e\">";
    $delim2 = "</table>";
    $html = extract_text($html, $delim1, $delim2);
    if ($html === False) {
        return False;
    }
    $html = replace_ctrl_chars($html, " ");
    $html = str_replace("  ", " ", $html);
    $html = html_decode($html);
    $html = html_decode($html);
    $location = trim(strip_tags(extract_raw_tag($html, "h3")));
    if (substr($location, 0, 12) == "Weather for ") {
        $location = substr($location, 12);
    }
    $wind = trim(strip_tags(extract_text_nofalse($html, "style=\"white-space:nowrap;padding-right:15px;color:#666\">Wind: ", "</span>")));
    $humidity = extract_text($html, "style=\"white-space:nowrap;padding-right:0px;vertical-align:top;color:#666\">Humidity: ", "</td>");
    $parts = explode("<td", $html);
    $temps = array();
    $tempsC = array();
    $conds = array();
    $days = array();
    for ($i = 1; $i < count($parts); $i++) {
        $cond = extract_text($parts[$i], "alt=\"", "\"");
        $temp = extract_text($parts[$i], "<span class=\"wob_t\" style=\"display:inline\">", "</span>");
        $day = extract_text($parts[$i], "colspan=\"2\" style=\"vertical-align:top;text-align:center\">", "</td>");
        if ($cond !== False) {
            $conds[] = strtolower($cond);
        }
        if ($temp !== False) {
            $temps[] = $temp;
            $tempsC[] = sprintf("%.0f", (substr($temp, 0, strlen($temp) - 2) - 32) * 5 / 9) . "°C";
        }
        if ($day !== False) {
            $days[] = $day;
        }
    }
    $offset = 0;
    $wind_caption = ", wind " . $wind;
    if ($wind == "") {
        $offset = 1;
        $wind_caption = "";
    }
    if (count($conds) != 5 or count($temps) != 10 - $offset or count($tempsC) != 10 - $offset or count($days) != 4) {
        return False;
    }
    if ($use_unit_pref == False) {
        $result = $location . " - currently " . $temps[0] . " / " . $tempsC[0] . ", " . $conds[0] . $wind_caption . ", humidity " . $humidity . " - ";
    } else {
        $result = $location . " - currently " . $temps[0] . ", " . $conds[0] . $wind_caption . ", humidity " . $humidity . " - ";
    }
    $fulldays = array("Sun." => "Sunday", "Mon." => "Monday", "Tue." => "Tuesday", "Wed." => "Wednesday", "Thu." => "Thursday", "Fri." => "Friday", "Sat." => "Saturday");
    for ($i = 1; $i <= 4; $i++) {
        $day = $days[$i - 1];
        $day = $fulldays[$day];
        if ($use_unit_pref == False) {
            $result = $result . $day . " " . $conds[$i] . " (" . $temps[$i * 2 + 1 - $offset] . ":" . $temps[$i * 2 - $offset] . " / " . $tempsC[$i * 2 + 1 - $offset] . ":" . $tempsC[$i * 2 - $offset] . ")";
        } else {
            $result = $result . $day . " " . $conds[$i] . " (" . $temps[$i * 2 + 1 - $offset] . ":" . $temps[$i * 2 - $offset] . ")";
        }
        if ($i < 4) {
            $result = $result . ", ";
        }
    }
    $color = "10";
    if (isset($prefs["color"]) == True) {
        $color = $prefs["color"];
    }
    $result = chr(3) . $color . $result;
    if ($getdata != False) {
        $data = array();
        $data["tempF"] = $temps[0];
        $data["tempC"] = $tempsC[0];
        $data["cond"] = $conds[0];
        $data["wind"] = $wind_caption;
        $data["humidity"] = $humidity;
        $data["location"] = $location;
        return $data;
    }
    return $result;
}