Example #1
0
function api_edit_url_update()
{
    if (!isset($_REQUEST['shorturl'])) {
        return array('statusCode' => 400, 'status' => 'fail', 'simple' => "Need a 'shorturl' parameter", 'message' => 'error: missing param');
    }
    if (!isset($_REQUEST['url'])) {
        return array('statusCode' => 400, 'status' => 'fail', 'simple' => "Need a 'url' parameter", 'message' => 'error: missing param');
    }
    $shorturl = $_REQUEST['shorturl'];
    $url = $_REQUEST['url'];
    if (yourls_get_protocol($shorturl)) {
        $keyword = yourls_get_relative_url($shorturl);
    } else {
        $keyword = $shorturl;
    }
    if (!yourls_is_shorturl($keyword)) {
        return array('statusCode' => 404, 'status' => 'fail', 'simple ' => "Error: keyword {$keyword} not found", 'message' => 'error: not found');
    }
    $title = '';
    if (isset($_REQUEST['title'])) {
        $title = $_REQUEST['title'];
    }
    if (yourls_edit_link($url, $keyword, $keyword, $title)) {
        return array('statusCode' => 200, 'simple' => "Keyword {$keyword} updated to {$url}", 'message' => 'success: updated');
    } else {
        return array('statusCode' => 500, 'status' => 'fail', 'simple' => 'Error: could not edit keyword, not sure why :-/', 'message' => 'error: unknown error');
    }
}
Example #2
0
function clayton_api_action_delete()
{
    // We don't want unauthenticated users deleting links
    // If YOURLS is in public mode, force authentication anyway
    if (!yourls_is_private()) {
        yourls_do_action('require_auth');
        require_once YOURLS_INC . '/auth.php';
    }
    // Need 'shorturl' parameter
    if (!isset($_REQUEST['shorturl'])) {
        return array('statusCode' => 400, 'simple' => "Need a 'shorturl' parameter", 'message' => 'error: missing param');
    }
    $shorturl = $_REQUEST['shorturl'];
    // Check if valid shorturl
    if (!yourls_is_shorturl($shorturl)) {
        return array('statusCode' => 404, 'simple ' => 'Error: short URL not found', 'message' => 'error: not found');
    }
    // Is $shorturl a URL (http://sho.rt/abc) or a keyword (abc) ?
    if (yourls_get_protocol($shorturl)) {
        $keyword = yourls_get_relative_url($shorturl);
    } else {
        $keyword = $shorturl;
    }
    // Delete shorturl
    if (yourls_delete_link_by_keyword($keyword)) {
        return array('statusCode' => 200, 'simple' => "Shorturl {$shorturl} deleted", 'message' => 'success: deleted');
    } else {
        return array('statusCode' => 500, 'simple' => 'Error: could not delete shorturl, not sure why :-/', 'message' => 'error: unknown error');
    }
}
Example #3
0
/**
 * Return YOURLS_SITE or URL under YOURLS setup, with SSL preference
 *
 */
function yourls_site_url($echo = true, $url = '')
{
    $url = yourls_get_relative_url($url);
    $url = trim(YOURLS_SITE . '/' . $url, '/');
    // Do not enforce (checking yourls_need_ssl() ) but check current usage so it won't force SSL on non-admin pages
    if (yourls_is_ssl()) {
        $url = yourls_set_url_scheme($url, 'https');
    }
    $url = yourls_apply_filter('site_url', $url);
    if ($echo) {
        echo $url;
    }
    return $url;
}