Example #1
0
/**
 * Loads a custom translation file (for a plugin, a theme, a public interface...) if locale is defined
 *
 * The .mo file should be named based on the domain with a dash, and then the locale exactly,
 * eg 'myplugin-pt_BR.mo'
 *
 * @since 1.6
 *
 * @param string $domain Unique identifier (the "domain") for retrieving translated strings
 * @param string $path Full path to directory containing MO files.
 * @return mixed Returns nothing if locale undefined, otherwise return bool: true on success, false on failure
 */
function yourls_load_custom_textdomain($domain, $path)
{
    $locale = yourls_apply_filter('load_custom_textdomain', yourls_get_locale(), $domain);
    if (!empty($locale)) {
        $mofile = rtrim($path, '/') . '/' . $domain . '-' . $locale . '.mo';
        return yourls_load_textdomain($domain, $mofile);
    }
}
Example #2
0
/**
 * Display the language attributes for the HTML tag.
 *
 * Builds up a set of html attributes containing the text direction and language
 * information for the page. Stolen from WP.
 *
 * @since 1.6
 */
function yourls_html_language_attributes()
{
    $attributes = array();
    $output = '';
    $attributes[] = yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"';
    $doctype = yourls_apply_filter('html_language_attributes_doctype', 'html');
    // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR
    if ($lang = str_replace('_', '-', yourls_get_locale())) {
        if ($doctype == 'xhtml') {
            $attributes[] = "xml:lang=\"{$lang}\"";
        } else {
            $attributes[] = "lang=\"{$lang}\"";
        }
    }
    $output = implode(' ', $attributes);
    $output = yourls_apply_filter('html_language_attributes', $output);
    echo $output;
}
Example #3
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;
}