コード例 #1
0
/**
 * Return list of all shorturls associated to the same long URL. Returns NULL or array of keywords.
 *
 */
function yourls_get_duplicate_keywords($longurl)
{
    yourls_deprecated_function(__FUNCTION__, '1.7', 'yourls_get_longurl_keywords');
    if (!yourls_allow_duplicate_longurls()) {
        return NULL;
    }
    return yourls_apply_filter('get_duplicate_keywords', yourls_get_longurl_keywords($longurl), $longurl);
}
コード例 #2
0
<?php

// TODO: make things cleaner. This file is an awful HTML/PHP soup.
define('YOURLS_INFOS', true);
require_once dirname(__FILE__) . '/includes/load-yourls.php';
require_once YOURLS_INC . '/functions-infos.php';
yourls_maybe_require_auth();
// Variables should be defined in yourls-loader.php, if not try GET request (old behavior of yourls-infos.php)
if (!isset($keyword) && isset($_GET['id'])) {
    $keyword = $_GET['id'];
}
if (!isset($aggregate) && isset($_GET['all']) && $_GET['all'] == 1 && yourls_allow_duplicate_longurls()) {
    $aggregate = true;
}
if (!isset($keyword)) {
    yourls_do_action('infos_no_keyword');
    yourls_redirect(YOURLS_SITE, 302);
}
// Get basic infos for this shortened URL
$keyword = yourls_sanitize_string($keyword);
$longurl = yourls_get_keyword_longurl($keyword);
$clicks = yourls_get_keyword_clicks($keyword);
$timestamp = yourls_get_keyword_timestamp($keyword);
$title = yourls_get_keyword_title($keyword);
// Update title if it hasn't been stored yet
if ($title == '') {
    $title = yourls_get_remote_title($longurl);
    yourls_edit_link_title($keyword, $title);
}
if ($longurl === false) {
    yourls_do_action('infos_keyword_not_found');
コード例 #3
0
// Now load required template and exit
yourls_do_action('pre_load_template', $request);
// At this point, $request is not sanitized. Sanitize in loaded template.
// Redirection:
if (preg_match("@^([{$pattern}]+)/?\$@", $request, $matches)) {
    $keyword = isset($matches[1]) ? $matches[1] : '';
    $keyword = yourls_sanitize_keyword($keyword);
    yourls_do_action('load_template_go', $keyword);
    require_once YOURLS_ABSPATH . '/yourls-go.php';
    exit;
}
// Stats:
if (preg_match("@^([{$pattern}]+)\\+(all)?/?\$@", $request, $matches)) {
    $keyword = isset($matches[1]) ? $matches[1] : '';
    $keyword = yourls_sanitize_keyword($keyword);
    $aggregate = isset($matches[2]) ? (bool) $matches[2] && yourls_allow_duplicate_longurls() : false;
    yourls_do_action('load_template_infos', $keyword);
    require_once YOURLS_ABSPATH . '/yourls-infos.php';
    exit;
}
// Prefix-n-Shorten sends to bookmarklet (doesn't work on Windows)
if (preg_match("@^[a-zA-Z]+://.+@", $request, $matches)) {
    $url = yourls_sanitize_url($matches[0]);
    if ($parse = yourls_get_protocol_slashes_and_rest($url, array('up', 'us', 'ur'))) {
        yourls_do_action('load_template_redirect_admin', $url);
        $parse = array_map('rawurlencode', $parse);
        // Redirect to /admin/index.php?up=<url protocol>&us=<url slashes>&ur=<url rest>
        yourls_redirect(yourls_add_query_arg($parse, yourls_admin_url('index.php')), 302);
        exit;
    }
}
コード例 #4
0
ファイル: functions.php プロジェクト: steenhulthin/hult.in
/**
 * Edit a link
 *
 */
function yourls_edit_link($url, $keyword, $newkeyword = '', $title = '')
{
    // Allow plugins to short-circuit the whole function
    $pre = yourls_apply_filter('shunt_edit_link', null, $keyword, $url, $keyword, $newkeyword, $title);
    if (null !== $pre) {
        return $pre;
    }
    global $ydb;
    $table = YOURLS_DB_TABLE_URL;
    $url = yourls_escape(yourls_sanitize_url($url));
    $keyword = yourls_escape(yourls_sanitize_string($keyword));
    $title = yourls_escape(yourls_sanitize_title($title));
    $newkeyword = yourls_escape(yourls_sanitize_string($newkeyword));
    $strip_url = stripslashes($url);
    $strip_title = stripslashes($title);
    $old_url = $ydb->get_var("SELECT `url` FROM `{$table}` WHERE `keyword` = '{$keyword}';");
    // Check if new URL is not here already
    if ($old_url != $url && !yourls_allow_duplicate_longurls()) {
        $new_url_already_there = intval($ydb->get_var("SELECT COUNT(keyword) FROM `{$table}` WHERE `url` = '{$url}';"));
    } else {
        $new_url_already_there = false;
    }
    // Check if the new keyword is not here already
    if ($newkeyword != $keyword) {
        $keyword_is_ok = yourls_keyword_is_free($newkeyword);
    } else {
        $keyword_is_ok = true;
    }
    yourls_do_action('pre_edit_link', $url, $keyword, $newkeyword, $new_url_already_there, $keyword_is_ok);
    // All clear, update
    if ((!$new_url_already_there || yourls_allow_duplicate_longurls()) && $keyword_is_ok) {
        $update_url = $ydb->query("UPDATE `{$table}` SET `url` = '{$url}', `keyword` = '{$newkeyword}', `title` = '{$title}' WHERE `keyword` = '{$keyword}';");
        if ($update_url) {
            $return['url'] = array('keyword' => $newkeyword, 'shorturl' => YOURLS_SITE . '/' . $newkeyword, 'url' => $strip_url, 'display_url' => yourls_trim_long_string($strip_url), 'title' => $strip_title, 'display_title' => yourls_trim_long_string($strip_title));
            $return['status'] = 'success';
            $return['message'] = yourls__('Link updated in database');
        } else {
            $return['status'] = 'fail';
            $return['message'] = yourls_s('Error updating %s (Short URL: %s)', yourls_trim_long_string($strip_url), $keyword);
        }
        // Nope
    } else {
        $return['status'] = 'fail';
        $return['message'] = yourls__('URL or keyword already exists in database');
    }
    return yourls_apply_filter('edit_link', $return, $url, $keyword, $newkeyword, $title, $new_url_already_there, $keyword_is_ok);
}
コード例 #5
0
ファイル: functions.php プロジェクト: momoim/momo-api
function yourls_get_duplicate_keywords($longurl)
{
    if (!yourls_allow_duplicate_longurls()) {
        return NULL;
    }
    global $ydb;
    $longurl = yourls_escape(yourls_sanitize_url($longurl));
    $table = YOURLS_DB_TABLE_URL;
    return $ydb->get_col("SELECT `keyword` FROM `{$table}` WHERE `url` = '{$longurl}'");
}
コード例 #6
0
ファイル: yourls-infos.php プロジェクト: yourls/yourls
if ($longurl === false) {
    yourls_do_action('infos_keyword_not_found');
    yourls_redirect(YOURLS_SITE, 302);
}
yourls_do_action('pre_yourls_infos', $keyword);
if (yourls_do_log_redirect()) {
    $table = YOURLS_DB_TABLE_LOG;
    $referrers = array();
    $direct = $notdirect = 0;
    $countries = array();
    $dates = array();
    $list_of_days = array();
    $list_of_months = array();
    $list_of_years = array();
    $last_24h = array();
    if (yourls_allow_duplicate_longurls()) {
        $keyword_list = yourls_get_longurl_keywords($longurl);
    }
    // Define keyword query range : either a single keyword or a list of keywords
    if ($aggregate) {
        $keyword_range = "IN ( '" . join("', '", $keyword_list) . "' )";
        // IN ( 'blah', 'bleh', 'bloh' )
    } else {
        $keyword_range = sprintf("= '%s'", yourls_escape($keyword));
    }
    // *** Referrers ***
    $query = "SELECT `referrer`, COUNT(*) AS `count` FROM `{$table}` WHERE `shorturl` {$keyword_range} GROUP BY `referrer`;";
    $rows = $ydb->get_results(yourls_apply_filter('stat_query_referrer', $query));
    // Loop through all results and build list of referrers, countries and hits per day
    foreach ((array) $rows as $row) {
        if ($row->referrer == 'direct') {
コード例 #7
0
ファイル: yourls-infos.php プロジェクト: momoim/momo-api
<?php

// TODO: make things cleaner. This file is an awful HTML/PHP soup.
// Require Files
require_once dirname(__FILE__) . '/includes/load-yourls.php';
require_once dirname(__FILE__) . '/includes/functions-infos.php';
yourls_maybe_require_auth();
if (!isset($_GET['id'])) {
    yourls_redirect(YOURLS_SITE, 307);
}
$aggregate = false;
if (isset($_GET['all']) && $_GET['all'] == 1 && yourls_allow_duplicate_longurls()) {
    $aggregate = true;
}
// Get basic infos for this shortened URL
$keyword = yourls_sanitize_string($_GET['id']);
$longurl = yourls_get_keyword_longurl($keyword);
$clicks = yourls_get_keyword_clicks($keyword);
$timestamp = yourls_get_keyword_timestamp($keyword);
if ($longurl === false) {
    yourls_redirect(YOURLS_SITE, 307);
}
if (yourls_do_log_redirect()) {
    // Duplicate keywords, if applicable
    $keyword_list = yourls_get_duplicate_keywords($longurl);
    // Fetch all information from the table log
    $table = YOURLS_DB_TABLE_LOG;
    if ($aggregate) {
        $keywords = join("', '", $keyword_list);
        // Fetch information for all keywords pointing to $longurl
        $hits = $ydb->get_results("SELECT `shorturl`, `click_time`, `referrer`, `user_agent`, `country_code` FROM `{$table}` WHERE `shorturl` IN ( '{$keywords}' );");
コード例 #8
0
 /**
  * Filter edit_link
  *
  * @return mixed
  * @throws \Exception
  */
 public function filter_edit_link()
 {
     list($return, $url, $keyword, $newkeyword, $title, $new_url_already_there, $keyword_is_ok) = func_get_args();
     if ((!$new_url_already_there || yourls_allow_duplicate_longurls()) && $keyword_is_ok) {
         $this->updateUrlSetting([self::SETTING_URL_USER_UPDATE => YOURLS_USER, self::SETTING_URL_TIMESTAMP_UPDATE => $this->getDateTime()->format('c')], $newkeyword ? $newkeyword : $keyword);
     }
     return $return;
 }