Example #1
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;
}
Example #2
0
<?php

include 'header.php';
$url = isset($_REQUEST['url']) ? yourls_sanitize_url($_REQUEST['url']) : '';
$keyword = isset($_REQUEST['keyword']) ? yourls_sanitize_keyword($_REQUEST['keyword']) : '';
$title = isset($_REQUEST['title']) ? yourls_sanitize_title($_REQUEST['title']) : '';
?>

<div class="content">
	<h2><?php 
yourls_e('Enter a new URL to shorten', 'isq_translation');
?>
</h2>
	<form method="post" action="result.php" class="newurl">
		<div class="form-item full-width">
			<p><label for="url" class="primary"><?php 
yourls_e('Long URL', 'isq_translation');
?>
</label></p>
			<p><label for="url" class="secondary"><?php 
yourls_e('Paste the long URL here. This is required.', 'isq_translation');
?>
</label></p>
			<input type="url" id="url" name="url" value="<?php 
echo $url;
?>
" autofocus>
		</div>

		<div class="halves">
Example #3
0
/**
 * Get a remote page title
 *
 * This function returns a string: either the page title as defined in HTML, or the URL if not found
 * The function tries to convert funky characters found in titles to UTF8, from the detected charset.
 * Charset in use is guessed from HTML meta tag, or if not found, from server's 'content-type' response.
 *
 * @param string $url URL
 * @return string Title (sanitized) or the URL if no title found
 */
function yourls_get_remote_title($url)
{
    // Allow plugins to short-circuit the whole function
    $pre = yourls_apply_filter('shunt_get_remote_title', false, $url);
    if (false !== $pre) {
        return $pre;
    }
    $url = yourls_sanitize_url($url);
    // Only deal with http(s)://
    if (!in_array(yourls_get_protocol($url), array('http://', 'https://'))) {
        return $url;
    }
    $title = $charset = false;
    $response = yourls_http_get($url);
    // can be a Request object or an error string
    if (is_string($response)) {
        return $url;
    }
    // Page content. No content? Return the URL
    $content = $response->body;
    if (!$content) {
        return $url;
    }
    // look for <title>. No title found? Return the URL
    if (preg_match('/<title>(.*?)<\\/title>/is', $content, $found)) {
        $title = $found[1];
        unset($found);
    }
    if (!$title) {
        return $url;
    }
    // Now we have a title. We'll try to get proper utf8 from it.
    // Get charset as (and if) defined by the HTML meta tag. We should match
    // <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    // or <meta charset='utf-8'> and all possible variations: see https://gist.github.com/ozh/7951236
    if (preg_match('/<meta[^>]*charset\\s*=["\' ]*([a-zA-Z0-9\\-_]+)/is', $content, $found)) {
        $charset = $found[1];
        unset($found);
    } else {
        // No charset found in HTML. Get charset as (and if) defined by the server response
        $_charset = current($response->headers->getValues('content-type'));
        if (preg_match('/charset=(\\S+)/', $_charset, $found)) {
            $charset = trim($found[1], ';');
            unset($found);
        }
    }
    // Conversion to utf-8 if what we have is not utf8 already
    if (strtolower($charset) != 'utf-8' && function_exists('mb_convert_encoding')) {
        // We use @ to remove warnings because mb_ functions are easily bitching about illegal chars
        if ($charset) {
            $title = @mb_convert_encoding($title, 'UTF-8', $charset);
        } else {
            $title = @mb_convert_encoding($title, 'UTF-8');
        }
    }
    // Remove HTML entities
    $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
    // Strip out evil things
    $title = yourls_sanitize_title($title);
    return yourls_apply_filter('get_remote_title', $title, $url);
}
Example #4
0
    }
}
// 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'])) {
    $is_bookmark = true;
    $url = yourls_sanitize_url($_GET['u']);
    $keyword = isset($_GET['k']) ? yourls_sanitize_keyword($_GET['k']) : '';
    $title = isset($_GET['t']) ? yourls_sanitize_title($_GET['t']) : '';
    $return = yourls_add_new_link($url, $keyword, $title);
    // If fails because keyword already exist, retry with no keyword
    if (isset($return['status']) && $return['status'] == 'fail' && isset($return['code']) && $return['code'] == 'error:keyword') {
        $msg = $return['message'];
        $return = yourls_add_new_link($url, '', $ydb);
        $return['message'] .= ' (' . $msg . ')';
    }
    // Stop here if bookmarklet with a JSON callback function
    if (isset($_GET['jsonp']) && $_GET['jsonp'] == 'yourls') {
        $short = $return['shorturl'] ? $return['shorturl'] : '';
        $message = $return['message'];
        header('Content-type: application/json');
        echo "yourls_callback({'short_url':'{$short}','message':'{$message}'});";
        die;
    }
Example #5
0
/**
 * Get a remote page <title>, return a string (either title or url)
 *
 */
function yourls_get_remote_title($url)
{
    // Allow plugins to short-circuit the whole function
    $pre = yourls_apply_filter('shunt_get_remote_title', false, $url);
    if (false !== $pre) {
        return $pre;
    }
    require_once YOURLS_INC . '/functions-http.php';
    $url = yourls_sanitize_url($url);
    $title = $charset = false;
    $content = yourls_get_remote_content($url);
    // If false, return url as title.
    // Todo: improve this with temporary title when shorturl_meta available?
    if (false === $content) {
        return $url;
    }
    if ($content !== false) {
        // look for <title>
        if (preg_match('/<title>(.*?)<\\/title>/is', $content, $found)) {
            $title = $found[1];
            unset($found);
        }
        // look for charset
        // <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        if (preg_match('/<meta[^>]*?charset=([^>]*?)\\/?>/is', $content, $found)) {
            $charset = trim($found[1], '"\' ');
            unset($found);
        }
    }
    // if title not found, guess if returned content was actually an error message
    if ($title == false && strpos($content, 'Error') === 0) {
        $title = $content;
    }
    if ($title == false) {
        $title = $url;
    }
    /*
    if( !yourls_seems_utf8( $title ) )
    	$title = utf8_encode( $title );
    */
    // Charset conversion. We use @ to remove warnings (mb_ functions are easily bitching about illegal chars)
    if (function_exists('mb_convert_encoding')) {
        if ($charset) {
            $title = @mb_convert_encoding($title, 'UTF-8', $charset);
        } else {
            $title = @mb_convert_encoding($title, 'UTF-8');
        }
    }
    // Remove HTML entities
    $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
    // Strip out evil things
    $title = yourls_sanitize_title($title);
    return yourls_apply_filter('get_remote_title', $title, $url);
}
Example #6
0
/**
 * Updates the configuration in the YOURLS database
 */
function itfs_piwik_admin_settings_update()
{
    //We make sure we've received a configuration update
    if (isset($_POST['piwik_config'])) {
        $piwik_config = array();
        /**
         * There will be 2 additional modules. One for people who have donated above a certain amount and a professional version
         */
        if (file_exists(dirname(__FILE__) . '/donations.php')) {
            $piwik_config[SKU] = 'donations';
        } else {
            if (file_exists(dirname(__FILE__) . '/pro.php')) {
                $piwik_config[SKU] = 'pro';
            } else {
                $piwik_config[SKU] = 'free';
            }
        }
        // We sanitize each parameter.
        if (is_array($_POST['piwik_config'])) {
            foreach ($_POST['piwik_config'] as $k => $v) {
                if ($k == 'site_id') {
                    $piwik_config[$k] = @intval($v);
                } else {
                    if ($k == 'piwik_url') {
                        // Site URL must end with a slash. Stolen as-is from wp-piwik
                        if (substr($v, -1, 1) != '/' && substr($v, -10, 10) != '/index.php') {
                            $v .= '/';
                        }
                        $piwik_config[$k] = yourls_sanitize_url($v);
                    } else {
                        $piwik_config[$k] = yourls_sanitize_title($v);
                    }
                }
            }
            try {
                yourls_update_option('piwik_config', $piwik_config);
            } catch (Exception $e) {
                $message = "ITFS_PIWIK: Error when trying to save settings. " . $e->getMessage();
                error_log($message, 0);
                echo yourls_add_notice($message, 'message_error');
                return false;
            }
        }
    }
}