Exemple #1
0
/**
 * Callback function: Sort plugins 
 *
 * @link http://php.net/uasort
 *
 * @param array $plugin_a
 * @param array $plugin_b
 * @return int 0, 1 or -1, see uasort()
 */
function yourls_plugins_sort_callback($plugin_a, $plugin_b)
{
    $orderby = yourls_apply_filters('plugins_sort_callback', 'Plugin Name');
    $order = yourls_apply_filters('plugins_sort_callback', 'ASC');
    $a = $plugin_a[$orderby];
    $b = $plugin_b[$orderby];
    if ($a == $b) {
        return 0;
    }
    if ('DESC' == $order) {
        return $a < $b ? 1 : -1;
    } else {
        return $a < $b ? -1 : 1;
    }
}
/**
 * Escaping for textarea values. Stolen from WP.
 *
 * @since 1.6
 *
 * @param string $text
 * @return string
 */
function yourls_esc_textarea($text)
{
    $safe_text = htmlspecialchars($text, ENT_QUOTES);
    return yourls_apply_filters('esc_textarea', $safe_text, $text);
}
Exemple #3
0
/**
 * Marks a function as deprecated and informs when it has been used. Stolen from WP.
 *
 * There is a hook deprecated_function that will be called that can be used
 * to get the backtrace up to what file and function called the deprecated
 * function.
 *
 * The current behavior is to trigger a user error if YOURLS_DEBUG is true.
 *
 * This function is to be used in every function that is deprecated.
 *
 * @since 1.6
 * @uses yourls_do_action() Calls 'deprecated_function' and passes the function name, what to use instead,
 *   and the version the function was deprecated in.
 * @uses yourls_apply_filters() Calls 'deprecated_function_trigger_error' and expects boolean value of true to do
 *   trigger or false to not trigger error.
 *
 * @param string $function The function that was called
 * @param string $version The version of WordPress that deprecated the function
 * @param string $replacement Optional. The function that should have been called
 */
function yourls_deprecated_function($function, $version, $replacement = null)
{
    yourls_do_action('deprecated_function', $function, $replacement, $version);
    // Allow plugin to filter the output error trigger
    if (YOURLS_DEBUG && yourls_apply_filters('deprecated_function_trigger_error', true)) {
        if (!is_null($replacement)) {
            trigger_error(sprintf(yourls__('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement));
        } else {
            trigger_error(sprintf(yourls__('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version));
        }
    }
}
/*
 * YOURLS API
 *
 * Note about translation : this file should NOT be translation ready
 * API messages and returns are supposed to be programmatically tested, so default English is expected
 *
 */
define('YOURLS_API', true);
require_once dirname(__FILE__) . '/includes/load-yourls.php';
yourls_maybe_require_auth();
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
yourls_do_action('api', $action);
// Define standard API actions
$api_actions = array('shorturl' => 'yourls_api_action_shorturl', 'stats' => 'yourls_api_action_stats', 'db-stats' => 'yourls_api_action_db_stats', 'url-stats' => 'yourls_api_action_url_stats', 'expand' => 'yourls_api_action_expand', 'version' => 'yourls_api_action_version');
$api_actions = yourls_apply_filters('api_actions', $api_actions);
// Register API actions
foreach ((array) $api_actions as $_action => $_callback) {
    yourls_add_filter('api_action_' . $_action, $_callback, 99);
}
// Try requested API method. Properly registered actions should return an array.
$return = yourls_apply_filter('api_action_' . $action, false);
if (false === $return) {
    $return = array('errorCode' => 400, 'message' => 'Unknown or missing "action" parameter', 'simple' => 'Unknown or missing "action" parameter');
}
if (isset($_REQUEST['callback'])) {
    $return['callback'] = $_REQUEST['callback'];
}
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'xml';
yourls_api_output($format, $return);
die;
/**
 * Send a filerable content type header
 *
 * @since 1.7
 * @param string $type content type ('text/html', 'application/json', ...)
 * @return bool whether header was sent
 */
function yourls_content_type_header($type)
{
    if (!headers_sent()) {
        $charset = yourls_apply_filters('content_type_header_charset', 'utf-8');
        header("Content-Type: {$type}; charset={$charset}");
        return true;
    }
    return false;
}
/**
 * Loads a custom translation file (for a plugin, a theme, a public interface...)
 *
 * 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 bool True on success, false on failure
 */
function yourls_load_custom_textdomain($domain, $path)
{
    $locale = yourls_apply_filters('load_custom_textdomain', yourls_get_locale(), $domain);
    $mofile = trim($path, '/') . '/' . $domain . '-' . $locale . '.mo';
    return yourls_load_textdomain($domain, $mofile);
}
Exemple #7
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_filters('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_filters('html_language_attributes', $output);
    echo $output;
}