function clayton_api_action_delete() { // We don't want unauthenticated users deleting links // If YOURLS is in public mode, force authentication anyway if (!yourls_is_private()) { yourls_do_action('require_auth'); require_once YOURLS_INC . '/auth.php'; } // Need 'shorturl' parameter if (!isset($_REQUEST['shorturl'])) { return array('statusCode' => 400, 'simple' => "Need a 'shorturl' parameter", 'message' => 'error: missing param'); } $shorturl = $_REQUEST['shorturl']; // Check if valid shorturl if (!yourls_is_shorturl($shorturl)) { return array('statusCode' => 404, 'simple ' => 'Error: short URL not found', 'message' => 'error: not found'); } // Is $shorturl a URL (http://sho.rt/abc) or a keyword (abc) ? if (yourls_get_protocol($shorturl)) { $keyword = yourls_get_relative_url($shorturl); } else { $keyword = $shorturl; } // Delete shorturl if (yourls_delete_link_by_keyword($keyword)) { return array('statusCode' => 200, 'simple' => "Shorturl {$shorturl} deleted", 'message' => 'success: deleted'); } else { return array('statusCode' => 500, 'simple' => 'Error: could not delete shorturl, not sure why :-/', 'message' => 'error: unknown error'); } }
/** * Pick the right DB class and return an instance * * @since 1.7 * @param string $extension Optional: user defined choice * @return class $ydb DB class instance */ function yourls_set_DB_driver() { // Auto-pick the driver. Priority: user defined, then PDO, then mysqli, then mysql if (defined('YOURLS_DB_DRIVER')) { $driver = strtolower(YOURLS_DB_DRIVER); // accept 'MySQL', 'mySQL', etc } elseif (extension_loaded('pdo_mysql')) { $driver = 'pdo'; } elseif (extension_loaded('mysqli')) { $driver = 'mysqli'; } elseif (extension_loaded('mysql')) { $driver = 'mysql'; } else { $driver = ''; } // Set the new driver if (in_array($driver, array('mysql', 'mysqli', 'pdo'))) { $class = yourls_require_db_files($driver); } global $ydb; if (!class_exists($class, false)) { $ydb = new stdClass(); yourls_die(yourls__('YOURLS requires the mysql, mysqli or pdo_mysql PHP extension. No extension found. Check your server config, or contact your host.'), yourls__('Fatal error'), 503); } yourls_do_action('set_DB_driver', $driver); $ydb = new $class(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST); $ydb->DB_driver = $driver; yourls_debug_log("DB driver: {$driver}"); }
function abdulrauf_adminreCaptcha_validatereCaptcha() { include 'captcha.php'; if ($resp != null && $resp->success) { //reCaptcha validated return true; } else { yourls_do_action('login_failed'); yourls_login_screen($error_msg = 'reCaptcha validation failed'); die; return false; } }
function allow_aliases() { yourls_do_action('pre_get_request'); // Ignore protocol & www. prefix $root = str_replace(array('https://', 'http://', 'https://www.', 'http://www.'), '', YOURLS_SITE); // Use the configured domain instead of $_SERVER['HTTP_HOST'] $root_host = parse_url(YOURLS_SITE); // Case insensitive comparison of the YOURLS root to match both http://Sho.rt/blah and http://sho.rt/blah $request = preg_replace("!{$root}/!i", '', $root_host['host'] . $_SERVER['REQUEST_URI'], 1); // Unless request looks like a full URL (ie request is a simple keyword) strip query string if (!preg_match("@^[a-zA-Z]+://.+@", $request)) { $request = current(explode('?', $request)); } return yourls_apply_filter('get_request', $request); }
/** * Check for valid user. Returns true or an error message * */ function yourls_is_valid_user() { static $valid = false; if ($valid) { return true; } $unfiltered_valid = false; // Logout request if (isset($_GET['action']) && $_GET['action'] == 'logout') { yourls_do_action('logout'); yourls_store_cookie(null); return yourls__('Logged out successfully'); } // Check cookies or login request. Login form has precedence. global $yourls_user_passwords; yourls_do_action('pre_login'); // Determine auth method and check credentials if (yourls_is_API() && isset($_REQUEST['timestamp']) && !empty($_REQUEST['timestamp']) && isset($_REQUEST['signature']) && !empty($_REQUEST['signature'])) { yourls_do_action('pre_login_signature_timestamp'); $unfiltered_valid = yourls_check_signature_timestamp(); } elseif (yourls_is_API() && !isset($_REQUEST['timestamp']) && isset($_REQUEST['signature']) && !empty($_REQUEST['signature'])) { yourls_do_action('pre_login_signature'); $unfiltered_valid = yourls_check_signature(); } elseif (isset($_REQUEST['username']) && isset($_REQUEST['password']) && !empty($_REQUEST['username']) && !empty($_REQUEST['password'])) { yourls_do_action('pre_login_username_password'); $unfiltered_valid = yourls_check_username_password(); } elseif (!yourls_is_API() && isset($_COOKIE['yourls_username']) && isset($_COOKIE['yourls_password'])) { yourls_do_action('pre_login_cookie'); $unfiltered_valid = yourls_check_auth_cookie(); } $valid = yourls_apply_filter('is_valid_user', $unfiltered_valid); // Login for the win! if ($valid) { yourls_do_action('login'); // (Re)store encrypted cookie if needed and tell it's ok if (!yourls_is_API() && $unfiltered_valid) { yourls_store_cookie(YOURLS_USER); } return true; } // Login failed yourls_do_action('login_failed'); if (isset($_REQUEST['username']) || isset($_REQUEST['password'])) { return yourls__('Invalid username or password'); } else { return yourls__('Please log in'); } }
function insensitive_get_keyword_infos($keyword, $use_cache = true) { global $ydb; $keyword = yourls_sanitize_string($keyword); yourls_do_action('pre_get_keyword', $keyword, $use_cache); if (isset($ydb->infos[$keyword]) && $use_cache == true) { return yourls_apply_filter('get_keyword_infos', $ydb->infos[$keyword], $keyword); } yourls_do_action('get_keyword_not_cached', $keyword); $table = YOURLS_DB_TABLE_URL; $infos = $ydb->get_row("SELECT * FROM `{$table}` WHERE LOWER(`keyword`) = LOWER('{$keyword}')"); if ($infos) { $infos = (array) $infos; $ydb->infos[$keyword] = $infos; } else { $ydb->infos[$keyword] = false; } return yourls_apply_filter('get_keyword_infos', $ydb->infos[$keyword], $keyword); }
function yourls_stats_countries_map($countries) { yourls_do_action('stats_countries_map'); // Echo static map. Will be hidden if JS $map = array('cht' => 't', 'chs' => '440x220', 'chtm' => 'world', 'chco' => 'FFFFFF,88C0EB,2A85B3,1F669C', 'chld' => join('', array_keys($countries)), 'chd' => 't:' . join(',', $countries), 'chf' => 'bg,s,EAF7FE'); $map_src = 'http://chart.apis.google.com/chart?' . http_build_query($map); echo "<img id='yourls_stat_countries_static' class='hide-if-js' src='{$map_src}' width='440' height='220' border='0' />"; // Echo dynamic map. Will be hidden if no JS echo <<<MAP <script type='text/javascript' src='http://www.google.com/jsapi'></script> <script type='text/javascript'> google.load('visualization', '1', {'packages': ['geomap']}); google.setOnLoadCallback(drawMap); function drawMap() { var data = new google.visualization.DataTable(); MAP; echo ' data.addRows(' . count($countries) . '); '; echo "\n\tdata.addColumn('string', 'Country');\n\tdata.addColumn('number', 'Hits');\n\t"; $i = 0; foreach ($countries as $c => $v) { echo "\n\t\t data.setValue({$i}, 0, '{$c}');\n\t\t data.setValue({$i}, 1, {$v});\n\t\t"; $i++; } echo <<<MAP var options = {}; options['dataMode'] = 'regions'; options['width'] = '550px'; options['height'] = '340px'; options['colors'] = [0x88C0EB,0x2A85B3,0x1F669C]; var container = document.getElementById('yourls_stat_countries'); var geomap = new google.visualization.GeoMap(container); geomap.draw(data, options); }; </script> <div id="yourls_stat_countries"></div> MAP; }
<?php // No direct call if (!defined('YOURLS_ABSPATH')) { die; } $auth = yourls_is_valid_user(); if ($auth !== true) { // API mode, if (yourls_is_API()) { $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'xml'; $callback = isset($_REQUEST['callback']) ? $_REQUEST['callback'] : ''; yourls_api_output($format, array('simple' => $auth, 'message' => $auth, 'errorCode' => 403, 'callback' => $callback)); // Regular mode } else { yourls_login_screen($auth); } die; } yourls_do_action('auth_successful');
$keyword = $_GET['id']; } $keyword = yourls_sanitize_string($keyword); // First possible exit: if (!isset($keyword)) { yourls_do_action('redirect_no_keyword'); yourls_redirect(YOURLS_SITE, 301); } // Get URL From Database $url = yourls_get_keyword_longurl($keyword); // URL found if (!empty($url)) { yourls_do_action('redirect_shorturl', $url, $keyword); // Update click count in main table $update_clicks = yourls_update_clicks($keyword); // Update detailed log for stats $log_redirect = yourls_log_redirect($keyword); yourls_redirect($url, 301); // URL not found. Either reserved, or page, or doesn't exist } else { // Do we have a page? if (file_exists(YOURLS_PAGEDIR . "/{$keyword}.php")) { yourls_page($keyword); // Either reserved id, or no such id } else { yourls_do_action('redirect_keyword_not_found', $keyword); yourls_redirect(YOURLS_SITE, 302); // no 404 to tell browser this might change, and also to not pollute logs } } exit;
try { throw ('ozhismygod'); } catch (z) { a = function () { if (!w.open(u,'Share','width=450,height=450,left=430','_blank')) l = u; }; if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a(); } void(0); TUMBLR; yourls_bookmarklet_link(yourls_make_bookmarklet($js_code), yourls__('YOURLS & Tumblr')); ?> <?php yourls_do_action('social_bookmarklet_buttons_after'); ?> </p> <h2><?php yourls_e('Prefix-n-Shorten'); ?> </h2> <p><?php yourls_se("When viewing a page, you can also prefix its full URL: just head to your browser's address bar, add \"<span>%s</span>\" to the beginning of the current URL (right before its 'http://' part) and hit enter.", preg_replace('@https?://@', '', YOURLS_SITE) . '/'); ?> </p> <p><?php
/** * Handle plugin administration page * */ function yourls_plugin_admin_page($plugin_page) { global $ydb; // Check the plugin page is actually registered if (!isset($ydb->plugin_pages[$plugin_page])) { yourls_die('This page does not exist. Maybe a plugin you thought was activated is inactive?', 'Invalid link'); } // Draw the page itself yourls_do_action('load-' . $plugin_page); yourls_html_head('plugin_page_' . $plugin_page, $ydb->plugin_pages[$plugin_page]['title']); yourls_html_logo(); yourls_html_menu(); call_user_func($ydb->plugin_pages[$plugin_page]['function']); yourls_html_footer(); die; }
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; } } // Past this point this is a request the loader could not understand yourls_do_action('loader_failed', $request); yourls_redirect(YOURLS_SITE, 302); exit;
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'); yourls_redirect(YOURLS_SITE, 302); } 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}' );"); } else { // Fetch information for current keyword only $hits = $ydb->get_results("SELECT `click_time`, `referrer`, `user_agent`, `country_code` FROM `{$table}` WHERE `shorturl` = '{$keyword}';"); }
function yourls_check_IP_flood($ip = '') { yourls_do_action('pre_check_ip_flood', $ip); // at this point $ip can be '', check it if your plugin hooks in here if (defined('YOURLS_FLOOD_DELAY_SECONDS') && YOURLS_FLOOD_DELAY_SECONDS === 0 || !defined('YOURLS_FLOOD_DELAY_SECONDS')) { return true; } $ip = $ip ? yourls_sanitize_ip($ip) : yourls_get_IP(); // Don't throttle whitelist IPs if (defined('YOURLS_FLOOD_IP_WHITELIST' && YOURLS_FLOOD_IP_WHITELIST)) { $whitelist_ips = explode(',', YOURLS_FLOOD_IP_WHITELIST); foreach ((array) $whitelist_ips as $whitelist_ip) { $whitelist_ip = trim($whitelist_ip); if ($whitelist_ip == $ip) { return true; } } } // Don't throttle logged in users if (yourls_is_private()) { if (yourls_is_valid_user() === true) { return true; } } yourls_do_action('check_ip_flood', $ip); global $ydb; $table = YOURLS_DB_TABLE_URL; $lasttime = $ydb->get_var("SELECT `timestamp` FROM {$table} WHERE `ip` = '{$ip}' ORDER BY `timestamp` DESC LIMIT 1"); if ($lasttime) { $now = date('U'); $then = date('U', strtotime($lasttime)); if ($now - $then <= YOURLS_FLOOD_DELAY_SECONDS) { // Flood! yourls_do_action('ip_flood', $ip, $now - $then); yourls_die('Too many URLs added too fast. Slow down please.', 'Forbidden', 403); } } return true; }
/** * 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) { yourls_do_action('content_type_header', $type); if (!headers_sent()) { $charset = yourls_apply_filter('content_type_header_charset', 'utf-8'); header("Content-Type: {$type}; charset={$charset}"); return true; } return false; }
yourls_db_connect(); } // Allow early inclusion of a cache layer if (file_exists(YOURLS_USERDIR . '/cache.php')) { require_once YOURLS_USERDIR . '/cache.php'; } // Read options right from start yourls_get_all_options(); // Register shutdown function register_shutdown_function('yourls_shutdown'); // Core now loaded yourls_do_action('init'); // plugins can't see this, not loaded yet // Check if need to redirect to install procedure if (!yourls_is_installed() && !yourls_is_installing()) { yourls_redirect(yourls_admin_url('install.php'), 302); } // Check if upgrade is needed (bypassed if upgrading or installing) if (!yourls_is_upgrading() && !yourls_is_installing()) { if (yourls_upgrade_is_needed()) { yourls_redirect(YOURLS_SITE . '/admin/upgrade.php', 302); } } // Init all plugins yourls_load_plugins(); yourls_do_action('plugins_loaded'); // Is there a new version of YOURLS ? yourls_new_core_version_notice(); if (yourls_is_admin()) { yourls_do_action('admin_init'); }
/** * Echoes an image tag of Google Charts line graph from array of values (eg 'number of clicks'). * * $legend1_list & legend2_list are values used for the 2 x-axis labels. $id is an HTML/JS id * */ function yourls_stats_line($values, $id = null) { yourls_do_action('pre_stats_line'); // if $id is null then assign a random string if ($id === null) { $id = uniqid('yourls_stats_line_'); } // If we have only 1 day of data, prepend a fake day with 0 hits for a prettier graph if (count($values) == 1) { array_unshift($values, 0); } // Keep only a subset of values to keep graph smooth $values = yourls_array_granularity($values, 30); $data = array_merge(array('Time' => 'Hits'), $values); $data = yourls_google_array_to_data_table($data); $options = array("legend" => "none", "pointSize" => "3", "theme" => "maximized", "curveType" => "function", "width" => 430, "height" => 220, "hAxis" => "{minTextSpacing: 80, maxTextLines: 1, maxAlternation: 1}", "vAxis" => "{minValue: -0.5, format: '#'}", "colors" => "['#2a85b3']"); $options = yourls_apply_filter('stats_line_options', $options); $lineChart = yourls_google_viz_code('LineChart', $data, $options, $id); echo yourls_apply_filter('stats_line', $lineChart, $values, $options, $id); }
yourls_html_tfooter($params); } yourls_table_tbody_start(); // Main Query $where = yourls_apply_filter('admin_list_where', $where); $url_results = $ydb->get_results("SELECT * FROM `{$table_url}` WHERE 1=1 {$where} ORDER BY `{$sort_by}` {$sort_order} LIMIT {$offset}, {$perpage};"); $found_rows = false; if ($url_results) { $found_rows = true; foreach ($url_results as $url_result) { $keyword = yourls_sanitize_string($url_result->keyword); $timestamp = strtotime($url_result->timestamp); $url = stripslashes($url_result->url); $ip = $url_result->ip; $title = $url_result->title ? $url_result->title : ''; $clicks = $url_result->clicks; echo yourls_table_add_row($keyword, $url, $title, $ip, $clicks, $timestamp); } } $display = $found_rows ? 'display:none' : ''; echo '<tr id="nourl_found" style="' . $display . '"><td colspan="6">' . yourls__('No URL') . '</td></tr>'; yourls_table_tbody_end(); yourls_table_end(); yourls_do_action('admin_page_after_table'); if ($is_bookmark) { yourls_share_box($url, $return['shorturl'], $title, $text); } ?> <?php yourls_html_footer();
/** * Output and return API result * * This function will echo (or only return if asked) an array as JSON, JSONP or XML. If the array has a * 'simple' key, it can also output that key as unformatted text if expected output mode is 'simple' * * Most likely, script should not do anything after outputting this * * @since 1.6 * * @param string $mode Expected output mode ('json', 'jsonp', 'xml', 'simple') * @param array $output Array of things to output * @param bool $send_headers Optional, default true: Whether a headers (status, content type) should be sent or not * @param bool $echo Optional, default true: Whether the output should be outputted or just returned * @return string API output, as an XML / JSON / JSONP / raw text string */ function yourls_api_output($mode, $output, $send_headers = true, $echo = true) { if (isset($output['simple'])) { $simple = $output['simple']; unset($output['simple']); } yourls_do_action('pre_api_output', $mode, $output, $send_headers, $echo); if ($send_headers) { if (isset($output['statusCode'])) { $code = $output['statusCode']; } elseif (isset($output['errorCode'])) { $code = $output['errorCode']; } else { $code = 200; } yourls_status_header($code); } $result = ''; switch ($mode) { case 'jsonp': if ($send_headers) { yourls_content_type_header('application/javascript'); } $callback = isset($output['callback']) ? $output['callback'] : ''; $result = $callback . '(' . json_encode($output) . ')'; break; case 'json': if ($send_headers) { yourls_content_type_header('application/json'); } $result = json_encode($output); break; case 'xml': if ($send_headers) { yourls_content_type_header('application/xml'); } $result = yourls_xml_encode($output); break; case 'simple': default: if ($send_headers) { yourls_content_type_header('text/plain'); } $result = isset($simple) ? $simple : ''; break; } if ($echo) { echo $result; } yourls_do_action('api_output', $mode, $output, $send_headers, $echo); return $result; }
/** * Display a page * */ function yourls_page($page) { $include = YOURLS_ABSPATH . "/pages/{$page}.php"; if (!file_exists($include)) { yourls_die("Page '{$page}' not found", 'Not found', 404); } yourls_do_action('pre_page', $page); include_once $include; yourls_do_action('post_page', $page); die; }
/** * 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}"); } }
/** * Unloads translations for a domain * * @since 1.6 * @param string $domain Textdomain to be unloaded * @return bool Whether textdomain was unloaded */ function yourls_unload_textdomain($domain) { global $yourls_l10n; $plugin_override = yourls_apply_filter('override_unload_textdomain', false, $domain); if ($plugin_override) { return true; } yourls_do_action('unload_textdomain', $domain); if (isset($yourls_l10n[$domain])) { unset($yourls_l10n[$domain]); return true; } return false; }
// Pick action $action = $_REQUEST['action']; switch ($action) { case 'add': yourls_verify_nonce('add_url', $_REQUEST['nonce'], false, 'omg error'); $return = yourls_add_new_link($_REQUEST['url'], $_REQUEST['keyword']); echo json_encode($return); break; case 'edit_display': yourls_verify_nonce('edit-link_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error'); $row = yourls_table_edit_row($_REQUEST['keyword']); echo json_encode(array('html' => $row)); break; case 'edit_save': yourls_verify_nonce('edit-save_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error'); $return = yourls_edit_link($_REQUEST['url'], $_REQUEST['keyword'], $_REQUEST['newkeyword'], $_REQUEST['title']); echo json_encode($return); break; case 'delete': yourls_verify_nonce('delete-link_' . $_REQUEST['id'], $_REQUEST['nonce'], false, 'omg error'); $query = yourls_delete_link_by_keyword($_REQUEST['keyword']); echo json_encode(array('success' => $query)); break; case 'logout': // unused for the moment yourls_logout(); break; default: yourls_do_action('yourls_ajax_' . $action); } die;
function yourls_html_menu() { ?> <ul id="admin_menu"> <?php if (yourls_is_private()) { ?> <li>Hello <strong><?php echo YOURLS_USER; ?> </strong> (<a href="?action=logout" title="Logout">Logout</a>)</li> <?php } ?> <li><a href="<?php echo yourls_admin_url('index.php'); ?> ">Admin Interface</a></li> <?php if (yourls_is_admin()) { ?> <li><a href="<?php echo yourls_admin_url('tools.php'); ?> ">Tools</a></li> <li><a href="<?php echo yourls_admin_url('plugins.php'); ?> ">Plugins</a></li> <?php yourls_list_plugin_admin_pages(); ?> <li><a href="<?php yourls_site_url(); ?> /readme.html">Help</a></li> <?php yourls_do_action('admin_menu'); ?> <?php } ?> </ul> <?php yourls_do_action('admin_notices'); yourls_do_action('admin_notice'); // because I never remember if it's 'notices' or 'notice' /* To display a notice: $message = "<div>OMG, dude, I mean!</div>" ); yourls_add_action('admin_notices', create_function( '', "echo '$message';" ) ); */ }
<?php 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); switch ($action) { // Shorten a URL case 'shorturl': $url = isset($_REQUEST['url']) ? $_REQUEST['url'] : ''; $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : ''; $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : ''; $return = yourls_add_new_link($url, $keyword, $title); $return['simple'] = isset($return['shorturl']) ? $return['shorturl'] : ''; // This one will be used in case output mode is 'simple' unset($return['html']); // in API mode, no need for our internal HTML output break; // Global stats // Global stats case 'stats': $filter = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : ''; $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : ''; $return = yourls_api_stats($filter, $limit); break; // Stats for a shorturl // Stats for a shorturl case 'url-stats': $shorturl = isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : ''; $return = yourls_api_url_stats($shorturl);
/** * 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_e('Direct traffic:'); echo ' ' . sprintf(yourls_n('<strong>%s</strong> hit', '<strong>%s</strong> hits', $direct), $direct); ?> </p> <p><?php yourls_e('Referrer traffic:'); echo ' ' . sprintf(yourls_n('<strong>%s</strong> hit', '<strong>%s</strong> hits', $notdirect), $notdirect); ?> </p> </td> </tr> </table> <?php yourls_do_action('post_yourls_info_sources', $keyword); ?> <?php } else { echo '<p>' . yourls__('No referrer data.') . '</p>'; } ?> </div> </div><!--/panel-body --> </div><!--/panel --> <?php } // endif do log redirect
/** * Return API result. Dies after this * */ function yourls_api_output($mode, $return) { if (isset($return['simple'])) { $simple = $return['simple']; unset($return['simple']); } yourls_do_action('pre_api_output', $mode, $return); if (isset($return['statusCode'])) { $code = $return['statusCode']; } elseif (isset($return['errorCode'])) { $code = $return['errorCode']; } else { $code = 200; } yourls_status_header($code); switch ($mode) { case 'jsonp': yourls_content_type_header('application/javascript'); echo $return['callback'] . '(' . json_encode($return) . ')'; break; case 'json': yourls_content_type_header('application/json'); echo json_encode($return); break; case 'xml': yourls_content_type_header('application/xml'); echo yourls_xml_encode($return); break; case 'simple': default: yourls_content_type_header('text/plain'); if (isset($simple)) { echo $simple; } break; } yourls_do_action('api_output', $mode, $return); die; }