Esempio n. 1
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;
}
Esempio n. 2
0
/**
 * Check api.yourls.org if there's a newer version of YOURLS
 *
 * This function collects various stats to help us improve YOURLS. See the blog post about it:
 * http://blog.yourls.org/2014/01/on-yourls-1-7-and-api-yourls-org/
 * Results of requests sent to api.yourls.org are stored in option 'core_version_checks' and is an object
 * with the following properties:
 *    - failed_attempts : number of consecutive failed attempts
 *    - last_attempt    : time() of last attempt
 *    - last_result     : content retrieved from api.yourls.org during previous check
 *    - version_checked : installed YOURLS version that was last checked
 *
 * @since 1.7
 * @return mixed JSON data if api.yourls.org successfully requested, false otherwise
 */
function yourls_check_core_version()
{
    global $ydb, $yourls_user_passwords;
    $checks = yourls_get_option('core_version_checks');
    // Invalidate check data when YOURLS version changes
    if (is_object($checks) && YOURLS_VERSION != $checks->version_checked) {
        $checks = false;
    }
    if (!is_object($checks)) {
        $checks = new stdClass();
        $checks->failed_attempts = 0;
        $checks->last_attempt = 0;
        $checks->last_result = '';
        $checks->version_checked = YOURLS_VERSION;
    }
    // Config file location ('u' for '/user' or 'i' for '/includes')
    $conf_loc = str_replace(YOURLS_ABSPATH, '', YOURLS_CONFIGFILE);
    $conf_loc = str_replace('/config.php', '', $conf_loc);
    $conf_loc = $conf_loc == '/user' ? 'u' : 'i';
    // The collection of stuff to report
    $stuff = array('md5' => md5(YOURLS_SITE . YOURLS_ABSPATH), 'failed_attempts' => $checks->failed_attempts, 'yourls_site' => defined('YOURLS_SITE') ? YOURLS_SITE : 'unknown', 'yourls_version' => defined('YOURLS_VERSION') ? YOURLS_VERSION : 'unknown', 'php_version' => phpversion(), 'mysql_version' => $ydb->mysql_version(), 'locale' => yourls_get_locale(), 'db_driver' => defined('YOURLS_DB_DRIVER') ? YOURLS_DB_DRIVER : 'unset', 'db_ext_pdo' => extension_loaded('pdo_mysql') ? 1 : 0, 'db_ext_mysql' => extension_loaded('mysql') ? 1 : 0, 'db_ext_mysqli' => extension_loaded('mysqli') ? 1 : 0, 'ext_curl' => extension_loaded('curl') ? 1 : 0, 'num_users' => count($yourls_user_passwords), 'config_location' => $conf_loc, 'yourls_private' => defined('YOURLS_PRIVATE') && YOURLS_PRIVATE ? 1 : 0, 'yourls_unique' => defined('YOURLS_UNIQUE_URLS') && YOURLS_UNIQUE_URLS ? 1 : 0, 'yourls_url_convert' => defined('YOURLS_URL_CONVERT') ? YOURLS_URL_CONVERT : 'unknown', 'num_active_plugins' => yourls_has_active_plugins(), 'num_pages' => defined('YOURLS_PAGEDIR') ? count((array) glob(YOURLS_PAGEDIR . '/*.php')) : 0);
    $stuff = yourls_apply_filter('version_check_stuff', $stuff);
    // Send it in
    $url = 'http://api.yourls.org/core/version/1.0/';
    if (yourls_can_http_over_ssl()) {
        $url = yourls_set_url_scheme($url, 'https');
    }
    $req = yourls_http_post($url, array(), $stuff);
    $checks->last_attempt = time();
    $checks->version_checked = YOURLS_VERSION;
    // Unexpected results ?
    if (is_string($req) or !$req->success) {
        $checks->failed_attempts = $checks->failed_attempts + 1;
        yourls_update_option('core_version_checks', $checks);
        return false;
    }
    // Parse response
    $json = json_decode(trim($req->body));
    if (isset($json->latest) && isset($json->zipurl)) {
        // All went OK - mark this down
        $checks->failed_attempts = 0;
        $checks->last_result = $json;
        yourls_update_option('core_version_checks', $checks);
        return $json;
    }
    // Request returned actual result, but not what we expected
    return false;
}