function jd_expand_yourl($short_url, $remote) { if ($remote == 6) { $short_url = urlencode($short_url); $yourl_api = get_option('yourlsurl'); $user = get_option('yourlslogin'); $pass = stripcslashes(get_option('yourlsapi')); $decoded = jd_remote_json($yourl_api . "?action=expand&shorturl={$short_url}&format=json&username={$user}&password={$pass}"); $url = $decoded['longurl']; return $url; } else { global $yourls_reserved_URL; define('YOURLS_INSTALLING', true); // Pretend we're installing YOURLS to bypass test for install or upgrade define('YOURLS_FLOOD_DELAY_SECONDS', 0); // Disable flood check if (file_exists(dirname(get_option('yourlspath')) . '/load-yourls.php')) { // YOURLS 1.4 global $ydb; require_once dirname(get_option('yourlspath')) . '/load-yourls.php'; $yourls_result = yourls_api_expand($short_url); } else { // YOURLS 1.3 if (file_exists(get_option('yourlspath'))) { require_once get_option('yourlspath'); $yourls_db = new wpdb(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST); $yourls_result = yourls_api_expand($short_url); } } $url = $yourls_result['longurl']; return $url; } }
// This one will be used in case output mode is 'simple' unset($return['html']); // in API mode, no need for our internal HTML output break; // Global stats // Global stats case 'stats': $filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : ''; $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : ''; $return = yourls_api_stats($filter, $limit); break; // Stats for a shorturl // Stats for a shorturl case 'url-stats': $shorturl = isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : ''; $return = yourls_api_url_stats($shorturl); break; // Expand a short link // Expand a short link case 'expand': $shorturl = isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : ''; $return = yourls_api_expand($shorturl); break; // Missing or incorrect action parameter // Missing or incorrect action parameter default: $return = array('errorCode' => 400, 'message' => 'Unknown or missing "action" parameter', 'simple' => 'Unknown or missing "action" parameter'); } $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'xml'; yourls_api_output($format, $return); die;
/** * API function wrapper: Expand a short link * * @since 1.6 * @return array Result of API call */ function yourls_api_action_expand() { $shorturl = isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : ''; return yourls_apply_filter('api_result_expand', yourls_api_expand($shorturl)); }