예제 #1
0
파일: index.php 프로젝트: yourls/yourls
            $sort_by = 'clicks';
            break;
    }
    switch ($_GET['sort_order']) {
        case 'asc':
            $sort_order = 'asc';
            break;
        case 'desc':
            $sort_order = 'desc';
            break;
    }
}
// Get URLs Count for current filter, total links in DB & total clicks
list($total_urls, $total_clicks) = array_values(yourls_get_db_stats());
if ($where) {
    list($total_items, $total_items_clicks) = array_values(yourls_get_db_stats($where));
} else {
    $total_items = $total_urls;
    $total_items_clicks = false;
}
// This is a bookmarklet
if (isset($_GET['u']) or isset($_GET['up'])) {
    $is_bookmark = true;
    yourls_do_action('bookmarklet');
    // No sanitization needed here: everything happens in yourls_add_new_link()
    if (isset($_GET['u'])) {
        // Old school bookmarklet: ?u=<url>
        $url = rawurldecode($_GET['u']);
    } else {
        // New style bookmarklet: ?up=<url protocol>&us=<url slashes>&ur=<url rest>
        $url = rawurldecode($_GET['up'] . $_GET['us'] . $_GET['ur']);
예제 #2
0
function yourls_update_table_to_14()
{
    global $ydb;
    $table = YOURLS_DB_TABLE_URL;
    // Modify each link to reflect new structure
    $chunk = 45;
    $from = isset($_GET['from']) ? intval($_GET['from']) : 0;
    $total = yourls_get_db_stats();
    $total = $total['total_links'];
    $sql = "SELECT `keyword`,`url` FROM `{$table}` WHERE 1=1 ORDER BY `url` ASC LIMIT {$from}, {$chunk} ;";
    $rows = $ydb->get_results($sql);
    $count = 0;
    $queries = 0;
    foreach ($rows as $row) {
        $keyword = $row->keyword;
        $url = $row->url;
        $newkeyword = yourls_int2string($keyword);
        $ydb->query("UPDATE `{$table}` SET `keyword` = '{$newkeyword}' WHERE `url` = '{$url}';");
        if ($ydb->result === true) {
            $queries++;
        } else {
            echo "<p>Huho... Could not update rown with url='{$url}', from keyword '{$keyword}' to keyword '{$newkeyword}'</p>";
            // Find what went wrong :/
        }
        $count++;
    }
    // All done for this chunk of queries, did it all go as expected?
    $success = true;
    if ($count != $queries) {
        $success = false;
        $num = $count - $queries;
        echo "<p>{$num} error(s) occured while updating the URL table :(</p>";
    }
    if ($count == $chunk) {
        // there are probably other rows to convert
        $from = $from + $chunk;
        $remain = $total - $from;
        echo "<p>Converted {$chunk} database rows ({$remain} remaining). Continuing... Please do not close this window until it's finished!</p>";
        yourls_redirect_javascript(yourls_admin_url("upgrade.php?step=2&oldver=1.3&newver=1.4&oldsql=100&newsql=200&from={$from}"), $success);
    } else {
        // All done
        echo '<p>All rows converted! Please wait...</p>';
        yourls_redirect_javascript(yourls_admin_url("upgrade.php?step=3&oldver=1.3&newver=1.4&oldsql=100&newsql=200"), $success);
    }
}
예제 #3
0
/**
 * Return array of stats. (string)$filter is 'bottom', 'last', 'rand' or 'top'. (int)$limit is the number of links to return
 *
 */
function yourls_get_stats($filter = 'top', $limit = 10, $start = 0)
{
    global $ydb;
    switch ($filter) {
        case 'bottom':
            $sort_by = 'clicks';
            $sort_order = 'asc';
            break;
        case 'last':
            $sort_by = 'timestamp';
            $sort_order = 'desc';
            break;
        case 'rand':
        case 'random':
            $sort_by = 'RAND()';
            $sort_order = '';
            break;
        case 'top':
        default:
            $sort_by = 'clicks';
            $sort_order = 'desc';
            break;
    }
    // Fetch links
    $limit = intval($limit);
    $start = intval($start);
    if ($limit > 0) {
        $table_url = YOURLS_DB_TABLE_URL;
        $results = $ydb->get_results("SELECT * FROM `{$table_url}` WHERE 1=1 ORDER BY `{$sort_by}` {$sort_order} LIMIT {$start}, {$limit};");
        $return = array();
        $i = 1;
        foreach ((array) $results as $res) {
            $return['links']['link_' . $i++] = array('shorturl' => YOURLS_SITE . '/' . $res->keyword, 'url' => $res->url, 'title' => $res->title, 'timestamp' => $res->timestamp, 'ip' => $res->ip, 'clicks' => $res->clicks);
        }
    }
    $return['stats'] = yourls_get_db_stats();
    $return['statusCode'] = 200;
    return yourls_apply_filter('get_stats', $return, $filter, $limit, $start);
}
예제 #4
0
/**
 * Return array for counts of shorturls and clicks
 *
 */
function yourls_api_db_stats()
{
    $return = array('db-stats' => yourls_get_db_stats(), 'statusCode' => 200, 'simple' => 'Need either XML or JSON format for stats', 'message' => 'success');
    return yourls_apply_filter('api_db_stats', $return);
}
예제 #5
0
				<dl>
					<dt>MySQL-Server</dt>
					<dd><?php 
echo constant('YOURLS_DB_HOST');
?>
</dd>

					<dt>MySQL-Datenbank</dt>
					<dd><?php 
echo constant('YOURLS_DB_NAME');
?>
</dd>

					<?php 
$stats = yourls_get_db_stats();
?>
					<dt>Anzahl gespeicherter Kurz-URLs</dt>
					<dd><?php 
echo $stats['total_links'];
?>
</dd>

					<dt>Anzahl aller Klicks</dt>
					<dd><?php 
echo $stats['total_clicks'];
?>
</dd>
				</dl>
			</div></div>
		</div>