Example #1
0
function fetchTooltip($uri)
{
    $js = fetchPage($uri . '&power');
    $escapedJs = str_replace('\\\'', '%QUOTE%', $js);
    $values = array();
    if (preg_match_all('/(\\w+):\\s*\'(.+)\'/', $escapedJs, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $groups) {
            $values[$groups[1]] = str_replace('%QUOTE%', '\'', $groups[2]);
        }
    }
    return $values;
}
Example #2
0
 public function load()
 {
     if (!is_cli()) {
         return;
     }
     for ($i = 1345; $i < 1409; $i++) {
         $json = fetchPage($i);
         if ($json) {
             $error = NULL;
             if (!$this->loadStandardJson($json, $error)) {
                 var_dump($error);
             }
         }
     }
 }
function importPage($title)
{
    global $usercache;
    echo "\n<!-- Importing page " . xmlCommentSafe($title) . " -->\n";
    $page = fetchPage($title);
    $newtitle = xmlsafe(str_replace('_', ' ', recodeText($title)));
    $munged = mungeFormat($page->text);
    if ($munged != $page->text) {
        /**
         * Save a *new* revision with the conversion, and put the
         * previous last version into the history.
         */
        $next = array2object(array('text' => $munged, 'minor' => 1, 'username' => 'Conversion script', 'host' => '127.0.0.1', 'ts' => time(), 'summary' => 'link fix'));
        $revisions = array($page, $next);
    } else {
        /**
         * Current revision:
         */
        $revisions = array($page);
    }
    $xml = <<<END
\t<page>
\t\t<title>{$newtitle}</title>

END;
    # History
    $revisions = array_merge($revisions, fetchKeptPages($title));
    if (count($revisions) == 0) {
        return $sql;
    }
    foreach ($revisions as $rev) {
        $text = xmlsafe(recodeText($rev->text));
        $minor = $rev->minor ? '<minor/>' : '';
        list($userid, $username) = checkUserCache($rev->username, $rev->host);
        $username = xmlsafe(recodeText($username));
        $timestamp = xmlsafe(timestamp2ISO8601($rev->ts));
        $comment = xmlsafe(recodeText($rev->summary));
        $xml .= <<<END
\t\t<revision>
\t\t\t<timestamp>{$timestamp}</timestamp>
\t\t\t<contributor><username>{$username}</username></contributor>
\t\t\t{$minor}
\t\t\t<comment>{$comment}</comment>
\t\t\t<text>{$text}</text>
\t\t</revision>

END;
    }
    $xml .= "</page>\n\n";
    return $xml;
}
Example #4
0
function doAction($params = NULL)
{
    global $ikariam, $island_names, $debug;
    //Make sure the simple dom parser is loaded
    if (!function_exists('str_get_html')) {
        die("str_get_html() does not exist.");
    }
    //Set some variables
    $url = $ikariam['session']['base_url'];
    $cookie = $ikariam['session']['cookie'];
    //Add the action request in get requests
    if (isset($params['get']['actionRequest']) && $params['get']['actionRequest'] === TRUE) {
        $params['get']['actionRequest'] = $ikariam['hidden_inputs']['actionRequest'];
    }
    //Add the action request in post requests
    if (isset($params['post'])) {
        if (!isset($ikariam['hidden_inputs']['actionRequest'])) {
            return false;
        }
        $params['post']['actionRequest'] = $ikariam['hidden_inputs']['actionRequest'];
    }
    if ($debug) {
        echo "<pre>";
    }
    if ($debug) {
        print_r($params);
    }
    //Perform the page fetch
    $response = fetchPage($url, $cookie, $params);
    //Make sure cookie's valid
    if (!checkCookie($response['header'])) {
        die("Cookie expired!");
    }
    if ($debug > 1) {
        echo "<pre>";
        print_r($response['body']);
    }
    //Get the html object for the response
    $html_obj = str_get_html($response['body']);
    //Check for errors
    if (checkResponseForErrors($html_obj)) {
        if ($debug) {
            echo "<pre>";
            print_r(debug_backtrace());
            foreach ($ikariam['errors']['messages'] as $error) {
                echo $error . "<br />\n";
            }
            die;
        } else {
            return $html_obj;
        }
    }
    //Update the hidden input variables
    $ikariam['hidden_inputs'] = getHiddenInputs($html_obj);
    //Get the city names
    $ikariam['cities']['names'] = getCityNames($html_obj);
    //Get the current city name and id
    $ikariam['current_city_id'] = getCurrentCityID($html_obj);
    $ikariam['current_city'] = $ikariam['cities']['names'][$ikariam['current_city_id']];
    $ikariam['current_island_id'] = getCurrentIslandID($html_obj);
    $ikariam['current_island'] = $island_names[$ikariam['current_island_id']];
    //Get the global resources
    $ikariam['cities']['global']['resources']['ships'] = getShips($html_obj);
    //Get ships
    $ikariam['cities']['global']['resources']['ambrosia'] = getAmbrosia($html_obj);
    //Get the ambrosia
    $ikariam['cities']['global']['resources']['gold'] = getGold($html_obj);
    //Get the gold
    //Fetch the current resources if they exist
    $current_city_resources = getCityInfo($html_obj);
    if ($current_city_resources != NULL && $current_city_resources != FALSE) {
        $ikariam['cities'][$ikariam['current_city_id']] = $current_city_resources;
    }
    setIkariamFile();
    //Return
    return $html_obj;
}
    # START
    #<h3>
    #2.183 million tonnes CO
    #<sub style="font-size: 60%;">2</sub>
    #e
    #</h3>
    # END
    $pattern = "/<h3\\b[^>]*>([0-9]+)\\.?([0-9]?)/i";
    #$pattern = "/(<h3\b[^>]*)>/i";
    $subject = $HTMLChunk;
    if (preg_match($pattern, $subject, $matches)) {
        echo "A match was found.";
        print "\n" . $matches[0] . "\n";
        return $matches[0];
    }
}
function saveIt($c02E_YTD, $c02E_thisWeek, $state)
{
    // save the record in the db
    $record = array('year' => date('Y'), 'state' => $state, 'week' => date('W'), 'date' => date('j/m/Y'), 'c02E_this_week' => $c02E_thisWeek, 'c02E_year_to_date' => $c02E_YTD);
    scraperwiki::save(array('state', 'week'), $record);
}
foreach ($stateCode as $key => $value) {
    // fetch page
    $page = fetchPage($value);
    // get tonnes of carbon this year to date
    $carbontonnes_ytd = parsePage_thisYearToDate($page);
    $carbontonnes_thisWeek = parsePage_thisWeek($page);
    // save the data
    saveIt($carbontonnes_ytd, $carbontonnes_thisWeek, $key);
}
Example #6
0
    echo '<script src="base64.js"></script>' . "\n";
    echo '<script src="browser.js"></script>' . "\n";
    echo '<script>';
    echo "var f = '" . $h . "';" . "\n";
    echo 'var host = Base64.decode(reverseString("' . $rawRequest . '"));' . "\n";
    echo 'window.fetcherUrl = f;window.hostUrl = host;';
    echo "fetch(host);" . "\n";
    echo "</script>";
} else {
    if ($reqmode == "p2get_p") {
        if (strstr($req, "?")) {
            $query = "";
        } else {
            $query = "?";
        }
        foreach ($_POST as $k => $v) {
            $kv = $k . "=" . $v . '&';
            $query .= $kv;
        }
        $redir = $req . $query;
        $rs = encodeString(urlsafe_b64encode($redir));
        echo "<script>window.location = 'fetch.php?mode=loader&url=" . $rs . "';</script>";
    } else {
        if (file_exists($fn) && $reqm == "get") {
            readCache($fn, $reqmode);
            checkCache();
        } else {
            fetchPage($req, $fn, $reqm, $reqmode);
        }
    }
}
Example #7
0
<?php

if ($_SESSION['phrase'] != $correctAdminPhrase) {
    exit;
}
$pageID = $URI[0];
$page = fetchPage($pageID);
$fp = fopen('deleted_pages.txt', 'a');
fwrite($fp, "\n\n##################################################\n");
fwrite($fp, print_r($page, TRUE));
fwrite($fp, "##################################################\n");
fclose($fp);
$delete = "DELETE FROM pages WHERE id='" . $pageID . "';";
#echo $delete . '<br>';
mysql_query($delete) or die(mysql_error());
?>
<a href="/admin/pages">&lt;&lt;&lt; Back to Page Management</a><br><br>
Page Deleted. Data saved in backup text file.
Example #8
0
    if ($second_resource === "new") {
        ?>
<a href="/admin/pages">&lt;&lt;&lt; Back to Page Management</a><br><br>
<form action="/admin/newpage" method="post">
<table cellspacing=0>
    <tr><td>Title:</td><td><input type="text" name="title"></td></tr>
    <tr><td>ID:</td><td><input type="text" name="id"></td></tr>
    <tr><td>Content:</td><td><textarea name="content"></textarea></td></tr>
</table>
<br>
<input type="submit" value="Create Page">
</form>
<?php 
    } else {
        if ($second_resource === "edit") {
            $page = fetchPage($third_resource);
            ?>
<a href="/admin/pages">&lt;&lt;&lt; Back to Page Management</a><br><br>
<form action="/admin/editpage" method="post">
<table cellspacing=0>
    <tr><td>Title:</td><td><input type="text" name="title" value="<?php 
            echo $page['title'];
            ?>
"></td></tr>
    <tr><td>ID:</td><td><input type="text" name="id" value="<?php 
            echo $page['id'];
            ?>
"></td></tr>
    <tr><td>Content:</td><td><textarea name="content"><?php 
            echo unParse($page['content']);
            ?>