Пример #1
0
require_once YOURLS_INC . '/functions-compat.php';
require_once YOURLS_INC . '/functions-html.php';
require_once YOURLS_INC . '/functions-http.php';
require_once YOURLS_INC . '/functions-infos.php';
// Load auth functions if needed
if (yourls_is_private()) {
    require_once YOURLS_INC . '/functions-auth.php';
}
// Load locale
yourls_load_default_textdomain();
// Check if we are in maintenance mode - if yes, it will die here.
yourls_check_maintenance_mode();
// Fix REQUEST_URI for IIS
yourls_fix_request_uri();
// If request for an admin page is http:// and SSL is required, redirect
if (yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl()) {
    if (0 === strpos($_SERVER['REQUEST_URI'], 'http')) {
        yourls_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
        exit;
    } else {
        yourls_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
        exit;
    }
}
// Create the YOURLS object $ydb that will contain everything we globally need
global $ydb;
// Allow drop-in replacement for the DB engine
if (file_exists(YOURLS_USERDIR . '/db.php')) {
    require_once YOURLS_USERDIR . '/db.php';
} else {
    require_once YOURLS_INC . '/class-mysql.php';
Пример #2
0
function mu_table_add_row($keyword, $url, $title = '', $ip, $clicks, $timestamp)
{
    $keyword = yourls_sanitize_string($keyword);
    $display_keyword = htmlentities($keyword);
    $url = yourls_sanitize_url($url);
    $display_url = htmlentities(yourls_trim_long_string($url));
    $title_url = htmlspecialchars($url);
    $title = yourls_sanitize_title($title);
    $display_title = yourls_trim_long_string($title);
    $title = htmlspecialchars($title);
    $id = yourls_string2htmlid($keyword);
    // used as HTML #id
    $date = date('M d, Y H:i', $timestamp + YOURLS_HOURS_OFFSET * 3600);
    $clicks = number_format($clicks, 0, '', '');
    $shorturl = YOURLS_SITE . '/' . $keyword;
    $statlink = $shorturl . '+';
    if (yourls_is_ssl()) {
        $statlink = str_replace('http://', 'https://', $statlink);
    }
    if ($title) {
        $display_link = "<a href=\"{$url}\" title=\"{$title}\">{$display_title}</a><br/><small><a href=\"{$url}\" title=\"{$title_url}\">{$display_url}</a></small>";
    } else {
        $display_link = "<a href=\"{$url}\" title=\"{$title_url}\">{$display_url}</a>";
    }
    $delete_link = yourls_nonce_url('delete-link_' . $id, yourls_add_query_arg(array('id' => $id, 'action' => 'delete', 'keyword' => $keyword), muAdminUrl('admin-ajax.php')));
    $edit_link = yourls_nonce_url('edit-link_' . $id, yourls_add_query_arg(array('id' => $id, 'action' => 'edit', 'keyword' => $keyword), muAdminUrl('admin-ajax.php')));
    $actions = <<<ACTION
<a href="{$statlink}" id="statlink-{$id}" title="Stats" class="button button_stats">Stats</a><a href="" id="share-button-{$id}" name="share-button" title="Share" class="button button_share" onclick="toggle_share('{$id}');return false;">Share</a><a href="{$edit_link}" id="edit-button-{$id}" name="edit-button" title="Edit" class="button button_edit" onclick="edit('{$id}');return false;">Edit</a><a href="{$delete_link}" id="delete-button-{$id}" name="delete-button" title="Delete" class="button button_delete" onclick="remove('{$id}');return false;">Delete</a>
ACTION;
    $actions = yourls_apply_filter('action_links', $actions, $keyword, $url, $ip, $clicks, $timestamp);
    $row = <<<ROW
<tr id="id-{$id}"><td id="keyword-{$id}" class="keyword"><a href="{$shorturl}">{$display_keyword}</a></td><td id="url-{$id}" class="url">{$display_link}</td><td id="timestamp-{$id}" class="timestamp">{$date}</td><td id="ip-{$id}" class="ip">{$ip}</td><td id="clicks-{$id}" class="clicks">{$clicks}</td><td class="actions" id="actions-{$id}">{$actions}<input type="hidden" id="keyword_{$id}" value="{$keyword}"/></td></tr>
ROW;
    $row = yourls_apply_filter('table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp);
    return $row;
}
Пример #3
0
/**
 * Return the URL of the directory a plugin
 */
function yourls_plugin_url($file)
{
    $url = YOURLS_PLUGINURL . '/' . yourls_plugin_basename($file);
    if (yourls_is_ssl() or yourls_needs_ssl()) {
        $url = str_replace('http://', 'https://', $url);
    }
    return yourls_apply_filter('plugin_url', $url, $file);
}
Пример #4
0
/**
 * Change protocol to match current scheme used (http or https)
 *
 */
function yourls_match_current_protocol($url, $normal = 'http://', $ssl = 'https://')
{
    if (yourls_is_ssl()) {
        $url = str_replace($normal, $ssl, $url);
    }
    return yourls_apply_filter('match_current_protocol', $url);
}
Пример #5
0
/**
 * Store new cookie. No $user will delete the cookie.
 *
 */
function yourls_store_cookie($user = null)
{
    if (!$user) {
        $pass = null;
        $time = time() - 3600;
    } else {
        global $yourls_user_passwords;
        if (isset($yourls_user_passwords[$user])) {
            $pass = $yourls_user_passwords[$user];
        } else {
            die('Stealing cookies?');
            // This should never happen
        }
        $time = time() + YOURLS_COOKIE_LIFE;
    }
    $domain = yourls_apply_filter('setcookie_domain', parse_url(YOURLS_SITE, 1));
    $secure = yourls_apply_filter('setcookie_secure', yourls_is_ssl());
    $httponly = yourls_apply_filter('setcookie_httponly', true);
    // Some browsers refuse to store localhost cookie
    if ($domain == 'localhost') {
        $domain = '';
    }
    if (!headers_sent($filename, $linenum)) {
        // Set httponly if the php version is >= 5.2.0
        if (version_compare(phpversion(), '5.2.0', 'ge')) {
            setcookie(yourls_cookie_name(), yourls_salt($user), $time, '/', $domain, $secure, $httponly);
        } else {
            setcookie(yourls_cookie_name(), yourls_salt($user), $time, '/', $domain, $secure);
        }
    } else {
        // For some reason cookies were not stored: action to be able to debug that
        yourls_do_action('setcookie_failed', $user);
        yourls_debug_log("Could not store cookie: headers already sent in {$filename} on line {$linenum}");
    }
}
Пример #6
0
function yourls_store_cookie($user = null)
{
    if (!$user) {
        $pass = null;
        $time = time() - 3600;
    } else {
        global $yourls_user_passwords;
        if (isset($yourls_user_passwords[$user])) {
            $pass = $yourls_user_passwords[$user];
        } else {
            die('Stealing cookies?');
            // This should never happen
        }
        $time = time() + YOURLS_COOKIE_LIFE;
    }
    $domain = yourls_apply_filter('setcookie_domain', parse_url(YOURLS_SITE, 1));
    $secure = yourls_apply_filter('setcookie_secure', yourls_is_ssl());
    $httponly = yourls_apply_filter('setcookie_httponly', true);
    if (!headers_sent()) {
        // Set httponly if the php version is >= 5.2.0
        if (version_compare(phpversion(), '5.2.0', 'ge')) {
            setcookie('yourls_username', yourls_salt($user), $time, '/', $domain, $secure, $httponly);
            setcookie('yourls_password', yourls_salt($pass), $time, '/', $domain, $secure, $httponly);
        } else {
            setcookie('yourls_username', yourls_salt($user), $time, '/', $domain, $secure);
            setcookie('yourls_password', yourls_salt($pass), $time, '/', $domain, $secure);
        }
    }
}
Пример #7
0
function yourls_site_url($echo = true)
{
    $site = YOURLS_SITE;
    // 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()) {
        $site = str_replace('http://', 'https://', $site);
    }
    $site = yourls_apply_filter('site_url', $site);
    if ($echo) {
        echo $site;
    }
    return $site;
}