Example #1
0
function my_theme_api_call($def, $action, $args)
{
    global $theme_base, $api_url, $theme_version, $api_url;
    if ($args->slug != $theme_base) {
        return false;
    }
    // Get the current version
    $args->version = $theme_version;
    $request_string = prepare_request($action, $args);
    $request = wp_remote_post($api_url, $request_string);
    if (is_wp_error($request)) {
        $res = new WP_Error('themes_api_failed', __('Uh-Oh! An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message());
    } else {
        $res = unserialize($request['body']);
        if ($res === false) {
            $res = new WP_Error('themes_api_failed', __('An unknown error occurred'), $request['body']);
        }
    }
    return $res;
}
Example #2
0
function my_theme_api_call($def, $action, $args)
{
    global $theme_base, $theme_version;
    if ($args->slug != $theme_base) {
        return false;
    }
    // Get the current version
    $args->version = $theme_version;
    $request_string = prepare_request($action, $args);
    $request = wp_remote_post(API_URL, $request_string);
    if (is_wp_error($request)) {
        $res = new WP_Error('themes_api_failed', theme_locals("themes_api_failed"), $request->get_error_message());
    } else {
        $res = unserialize($request['body']);
        if ($res === false) {
            $res = new WP_Error('themes_api_failed', theme_locals("themes_api_failed_2"), $request['body']);
        }
    }
    return $res;
}
function my_plugin_api_call($def, $action, $args)
{
    global $plugin_slug, $api_url;
    if ($args->slug != $plugin_slug) {
        return false;
    }
    // Get the current version
    $plugin_info = get_site_transient('update_plugins');
    $current_version = $plugin_info->checked[$plugin_slug . '/' . $plugin_slug . '.php'];
    $args->version = $current_version;
    $request_string = prepare_request($action, $args);
    $request = wp_remote_post($api_url, $request_string);
    if (is_wp_error($request)) {
        $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message());
    } else {
        $res = unserialize($request['body']);
        if ($res === false) {
            $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
        }
    }
    return $res;
}
 *
 * @author themattharris
 */
require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array('consumer_key' => 'YOUR_CONSUMER_KEY', 'consumer_secret' => 'YOUR_CONSUMER_SECRET', 'user_token' => 'A_USER_TOKEN', 'user_secret' => 'A_USER_SECRET'));
// we're using a hardcoded image path here. You can easily replace this with
// an uploaded image - see images.php in the examples folder for how to do this
// 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
// this is the image to upload. It should be in the same directory as this file.
$image = 'image.png';
$mime = 'image/png';
$delegator = 'http://posterous.com/api2/upload.json';
$x_auth_service_provider = 'https://api.twitter.com/1/account/verify_credentials.json';
generate_verify_header($tmhOAuth, $x_auth_service_provider);
$params = prepare_request($tmhOAuth, $x_auth_service_provider, $image, $mime);
// post to OAuth Echo provider
$code = make_request($tmhOAuth, $delegator, $params, false, true);
if ($code != 200) {
    tmhUtilities::pr('There was an error communicating with the delegator.');
    tmhUtilities::pr($tmhOAuth);
    die;
}
$resp = json_decode($tmhOAuth->response['response']);
$params = array('status' => 'I just OAuth echoed a picture: ' . $resp->url);
$code = make_request($tmhOAuth, $tmhOAuth->url('1/statuses/update'), $params, true, false);
if ($code == 200) {
    tmhUtilities::pr('Picture OAuth Echo\'d!');
    tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
    tmhUtilities::pr('There was an error from Twitter.');
Example #5
0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
require_once 'includes/functions.php';
if ($_REQUEST['r'] == 'btl') {
    build_all_toplists();
    return;
}
// Recompile templates on first access
if (!isset($C['base_url'])) {
    recompile_templates();
}
headers_no_cache();
prepare_request();
if (file_exists('reset-access.php') || file_exists('../auto-install.php')) {
    echo '<div style="font-weight: bold; color: red; font-size: 14pt; text-align: center;">' . 'The auto-install.php and cp/reset-access.php files must be removed from your server before you can access the control panel' . '</div>';
    exit;
}
if (($auth_error = cp_authenticate()) === true) {
    cp_exec($_REQUEST['r'], '_xStatsOverallShow');
} else {
    include 'login.php';
}
function _xIndexShow()
{
    _xStatsOverallShow();
}
function _xUpdateShow()
{
Example #6
0
$user->is_logged = false;
$user->id = false;
$user->info = new stdClass();
$user->info->is_network_admin = 0;
$user->info->id = false;
$uri = $this->param('more');
$api_session->resource = isset($uri[0]) ? $uri[0] : 'invalid';
$api_session->resource_option = isset($uri[1]) ? $uri[1] : false;
unset($uri);
$api_session->not_in_groups = '';
$api_session->oauth_status = false;
$api_session->rate_status = false;
$api_session->bauth_status = false;
$api_session->available_resources = array('ids');
$api_session->oauth_error = '';
if (($auth = prepare_request()) || ($auth = prepare_header())) {
    if (isset($auth['oauth_version']) && $auth['oauth_version'] != '1.0') {
        $api_session->oauth_error = 'Not supported OAuth version';
    } elseif (isset($auth['oauth_consumer_key'], $auth['oauth_nonce'], $auth['oauth_token'], $auth['oauth_signature_method'], $auth['oauth_signature'], $auth['oauth_timestamp'])) {
        $ares = isset($api_session->resource_option) ? '/' . $api_session->resource_option : '';
        $resource = isset($api_session->resource) ? 'favorites/' . $api_session->resource . $ares : 'favorites';
        $oauth_client = new OAuth($auth['oauth_consumer_key'], $auth['oauth_nonce'], $auth['oauth_token'], $auth['oauth_timestamp'], $auth['oauth_signature']);
        $oauth_client->set_variable('stage_url', $C->SITE_URL . '1/' . $resource . '.' . $api_session->format);
        if (isset($auth['oauth_version'])) {
            $oauth_client->set_variable('version', '1.0');
        }
        if ($oauth_client->is_valid_get_resource_request()) {
            if ($auth['oauth_signature_method'] != 'HMAC-SHA1') {
                $api_session->oauth_error = 'Unsupported signature method';
            } elseif (!$oauth_client->decrypt_hmac_sha1()) {
                $api_session->oauth_error = 'Invalid signature';
}
function make_request($tmhOAuth, $url, $params, $auth, $multipart)
{
    // make the request, no auth, multipart, custom headers
    $tmhOAuth->request('POST', $url, $params, $auth, $multipart);
    // Posterous liked it or not?
    if ($tmhOAuth->response['code'] == 200) {
        return json_decode($tmhOAuth->response['response']);
    }
    return false;
}
if (!empty($_FILES)) {
    // IMPORTANT: Posterous requires the host be https://api.twitter.com
    // versions 0.11+ of tmhOAuth default to SSL so do not need changing
    generate_verify_header($tmhOAuth);
    $params = prepare_request($tmhOAuth);
    // post to OAuth Echo provider
    $resp = make_request($tmhOAuth, 'http://posterous.com/api2/upload.json', $params, false, true);
    // post Tweet to Twitter
    if ($resp !== false) {
        $params = array('status' => 'I just OAuth echoed a picture: ' . $resp->url);
        $resp = make_request($tmhOAuth, $tmhOAuth->url('1/statuses/update'), $params, true, false);
        if ($resp) {
            $tmhOAuth->pr(json_decode($tmhOAuth->response['response']));
        } else {
            echo 'Error: ' . htmlentities($tmhOAuth->response['response']);
        }
    }
}
?>