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');
    }
}
Exemple #2
0
// Pick action
$action = $_REQUEST['action'];
switch ($action) {
    case 'add':
        yourls_verify_nonce('add_url', $_REQUEST['nonce'], false, 'omg error');
        $return = yourls_add_new_link($_REQUEST['url'], $_REQUEST['keyword']);
        echo json_encode($return);
        break;
    case 'edit_display':
        yourls_verify_nonce('edit-link_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error');
        $row = yourls_table_edit_row($_REQUEST['keyword']);
        echo json_encode(array('html' => $row));
        break;
    case 'edit_save':
        yourls_verify_nonce('edit-save_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error');
        $return = yourls_edit_link($_REQUEST['url'], $_REQUEST['keyword'], $_REQUEST['newkeyword'], $_REQUEST['title']);
        echo json_encode($return);
        break;
    case 'delete':
        yourls_verify_nonce('delete-link_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error');
        $query = yourls_delete_link_by_keyword($_REQUEST['keyword']);
        echo json_encode(array('success' => $query));
        break;
    case 'logout':
        // unused for the moment
        yourls_logout();
        break;
    default:
        yourls_do_action('yourls_ajax_' . $action);
}
die;