Exemple #1
0
        query_redirect("DELETE" . limit1("FROM " . table($TABLE), " WHERE {$where}"), $location, array(lang('Item has been deleted.'), 'success'));
    } else {
        $set = array();
        foreach ($fields as $name => $field) {
            $val = process_input($field);
            if ($val !== false && $val !== null) {
                $set[idf_escape($name)] = $update ? "\n" . idf_escape($name) . " = {$val}" : $val;
            }
        }
        if ($update) {
            if (!$set) {
                redirect($location);
            }
            query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set), "\nWHERE {$where}"), $location, array(lang('Item has been updated.'), 'success'));
        } else {
            $result = insert_into($TABLE, $set);
            $last_id = $result ? last_id() : 0;
            queries_redirect($location, array(lang('Item%s has been inserted.', $last_id ? " {$last_id}" : ""), 'success'), $result);
            //! link
        }
    }
}
$table_name = $adminer->tableName(table_status($TABLE));
page_header($update ? lang('Edit') : lang('Insert'), $error, array("select" => array($TABLE, $table_name)), $table_name);
$adminer->selectLinks($table_status, '');
// @todo are params OK?
$row = null;
if ($_POST["save"]) {
    $row = (array) $_POST["fields"];
} elseif ($where) {
    $select = array();
function get_url($url, $cache_hard = true)
{
    global $http_cache_timeout;
    global $api_calls;
    global $cached_api_calls;
    # Check whether we have a cached response for this URL
    # Note there are two cache timestamps: fetched_on_server is tied to the
    # server (mothership)'s clock and fetched_on is tied to the local clock.
    # We are careful to compare the local now() against fetched_on and the
    # server's "Date:" header values against fetched_on_server.
    if (!$http_cache_timeout) {
        throw new Exception("\$http_cache_timeout not set");
    }
    # Expire old cache entries.
    mysql_query('delete from http_cache where fetched_on < now() - ' . $http_cache_timeout);
    # Load a valid cache element, if any.
    $sql = 'select content, fetched_on_server from http_cache where url = \'' . mysql_real_escape_string($url) . '\' and fetched_on >= now() - ' . $http_cache_timeout;
    $q = mysql_query($sql);
    if (!$q) {
        throw new Exception("Getting cache, got database error: " . mysql_error());
    }
    require_once 'HTTP/Request.php';
    if ($row = mysql_fetch_row($q)) {
        list($content, $fetched_on) = $row;
        # Under "hard" caching, return the cached data without talking to server.
        if ($cache_hard) {
            message("Hard cache hit at {$url}");
            return $content;
        }
        # Under "soft" caching, we make a request to ask the server if the resource
        # has changed since our copy.
        $fetched_on_http_date = date(DATE_RFC1123, from_mysql_date($fetched_on));
        $req = new HTTP_Request($url);
        $req->addHeader('If-Modified-Since', $fetched_on_http_date);
        $request_timer -= microtime(true);
        $ok = $req->sendRequest();
        $request_timer += microtime(true);
        $cached_api_calls = $cached_api_calls + 1;
        if (!PEAR::isError($ok)) {
            $respCode = $req->getResponseCode();
            if (304 == $respCode) {
                # 304 Not Modified; we can use the cached copy.
                message('Cache hit at ' . $url . ' using If-Modified-Since: ' . $fetched_on_http_date . "Request timer: {$request_timer}" . 's');
                return $content;
            } elseif (200 <= $respCode && $respCode < 300) {
                # Got an OK response, use the data.
                message('Cache refresh at ' . $url . ' If-Modified-Since: ' . $fetched_on_http_date . '. Request timer: ' . $request_timer . 's');
                $content = $req->getResponseBody();
                $fetched_on_server = mysql_date(from_http_date($req->getResponseHeader('Date')));
                mysql_query('delete from http_cache where url = \'' . mysql_real_escape_string($url) . '\'');
                if (!insert_into('http_cache', array('url' => $url, 'content' => $content, 'fetched_on_server' => $fetched_on_server))) {
                    throw new Exception("Database error writing to HTTP cache: " . mysql_error());
                }
                return $content;
            }
        } else {
            throw new Exception("Error while GETing {$url} ({$ok})");
        }
    } else {
        $req = new HTTP_Request($url);
        $request_timer -= microtime(true);
        $ok = $req->sendRequest();
        $request_timer += microtime(true);
        $api_calls = $api_calls + 1;
        message("Cache miss at {$url} Request timer: " . $request_timer . "s");
        if (PEAR::isError($ok)) {
            throw new Exception("Unknown error trying GET {$url}");
        }
        $respCode = $req->getResponseCode();
        if (200 <= $respCode && $respCode < 300) {
            # Got an OK response, use it.
            $content = $req->getResponseBody();
            $fetched_on_server = mysql_date(from_http_date($req->getResponseHeader('Date')));
            mysql_query('delete from http_cache where url = \'' . mysql_real_escape_string($url) . '\'');
            if (!insert_into('http_cache', array('url' => $url, 'content' => $content, 'fetched_on_server' => $fetched_on_server))) {
                throw new Exception("Database error writing to HTTP cache: " . mysql_error());
            }
            return $content;
        } else {
            error("GET {$url} returned {$respCode}");
            return null;
        }
    }
}
Exemple #3
0
 function set_site_links($links)
 {
     mysql_query('delete from site_links');
     foreach ($links as $link) {
         insert_into('site_links', array('text' => $link['text'], 'url' => $link['url']));
     }
 }
<?php

try {
    require_once 'Sprinkles.php';
    require_once 'HTTP_Request_Oauth.php';
    $sprink = new Sprinkles();
    $return = request_param('return');
    $consumer_data = $sprink->oauth_consumer_data();
    if (!$consumer_data['key'] || !$consumer_data['secret']) {
        die("The OAuth consumer data was missing from the Instant-On Help " . "Center database! Perhaps something went wrong during installation " . "and setup.");
    }
    list($token, $secret) = get_oauth_request_token($consumer_data);
    if (!$token || !$secret) {
        error("Failed to fetch OAuth request token " . "(Result token: '{$token}'; Token secret: '{$token_secret}')");
        die("Failed to fetch OAuth request token from getsatisfaction.com.");
    }
    $result = insert_into('sessions', array('token' => $token, 'token_secret' => $secret));
    if (!$result) {
        die("Error inserting OAuth tokens into database.");
    }
    $first_login = request_param('first_login');
    $callback_url = $sprink->sprinkles_root_url() . 'handle-oauth-return.php?' . ($first_login ? 'first_login=true&' : '') . 'return=' . urlencode($return);
    redirect(oauth_authorization_url($token, $callback_url));
    exit(0);
} catch (Exception $e) {
    error_log("Exception thrown while preparing page: " . $e->getMessage());
    $smarty->display('error.t');
}
Exemple #5
0
<?php

/*
* Handling the form data for the Login page > index.php
* Project : Secure Login Module - Udemy PHP Basics
* Date : Feb 2016
* Author : Carl Simpson
* Version : 1.0
*
*/
include '_includes/db_connect.php';
include '_includes/db_functions.php';
if (isset($_POST['submit'])) {
    insert_into();
} else {
    echo 'there has been an error';
}