Example #1
0
function create_repost(&$user, $url)
{
    $micropub_request = array('repost-of' => $url);
    $r = micropub_post_for_user($user, $micropub_request);
    $tweet_id = false;
    if ($user->twitter_access_token && preg_match('/https?:\\/\\/(?:www\\.)?twitter\\.com\\/[^\\/]+\\/status(?:es)?\\/(\\d+)/', $url, $match)) {
        $tweet_id = $match[1];
        $twitter = new \TwitterOAuth\Api(Config::$twitterClientID, Config::$twitterClientSecret, $user->twitter_access_token, $user->twitter_token_secret);
        $result = $twitter->post('statuses/retweet/' . $tweet_id);
    }
    return $r;
}
Example #2
0
        if ($tags) {
            if ($user->send_category_as_array != 1) {
                $data['category'] = $tags;
            } else {
                $data['category'] = implode(',', $tags);
            }
        }
    }
    // Handle attachments
    $filename = false;
    foreach ($_FILES as $file) {
        // If a photo was included, set the filename to the downloaded file
        if (preg_match('/image/', $file['type'])) {
            $filename = $file['tmp_name'];
        }
        // Sometimes MMSs are sent with a txt file attached instead of in the body
        if (preg_match('/text\\/plain/', $file['type'])) {
            $content = trim(file_get_contents($file['tmp_name']));
            if ($content) {
                $data['content'] = $content;
            }
        }
    }
    $r = micropub_post_for_user($user, $data, $filename);
    if (k($r, 'location')) {
        $result = 'created post at ' . $r['location'];
    } else {
        $result = 'error creating post';
    }
    $app->response()->body($result);
});
Example #3
0
<?php

$app->get('/editor', function () use($app) {
    // Don't require login because appcache caches the whole page
    $html = $app->render('editor.php');
    $app->response()->body($html);
});
$app->post('/editor/publish', function () use($app) {
    if ($user = require_login($app)) {
        $params = $app->request()->params();
        $micropub_request = array('h' => 'entry', 'name' => $params['name'], 'content' => $params['body']);
        $r = micropub_post_for_user($user, $micropub_request);
        $app->response()['Content-type'] = 'application/json';
        $app->response()->body(json_encode(['location' => $r['location'], 'response' => trim(htmlspecialchars($r['response']))]));
    }
});
$app->post('/editor/upload', function () use($app) {
    // Fake a file uploader by echo'ing back the data URI
    $fn = $_FILES['files']['tmp_name'][0];
    $imageData = base64_encode(file_get_contents($fn));
    $src = 'data:' . mime_content_type($fn) . ';base64,' . $imageData;
    $app->response()['Content-type'] = 'application/json';
    $app->response()->body(json_encode(['files' => [['url' => $src]]]));
});
$app->post('/editor/delete-file', function () use($app) {
    $app->response()['Content-type'] = 'application/json';
    $app->response()->body(json_encode(['result' => 'deleted']));
});
$app->get('/editor/oembed', function () use($app) {
    $url = 'http://medium.iframe.ly/api/oembed?iframe=1&url=' . urlencode($app->request()->params()['url']);
    $json = file_get_contents($url);