/** * Init Bootstrap Theme */ function lc_full_bootstrap_init() { yourls_add_filter('template_content', 'lc_full_bootstrap_template'); lc_full_bootstrap_add_css(); yourls_add_filter('admin_menu_start', 'lc_full_bootstrap_menu_start'); yourls_add_filter('admin_menu_end', 'lc_full_bootstrap_menu_end'); yourls_add_filter('logout_link', 'lc_full_bootstrap_logout_link'); }
function dgw_dont_track_admins_init() { /* If user is logged in to yourls... */ if (yourls_is_valid_user() === true) { /* ...then filter the tracking routines */ # first the click tracker yourls_add_filter('shunt_update_clicks', 'dgw_dont_track_admins'); # then the detailed logger yourls_add_filter('shunt_log_redirect', 'dgw_dont_track_admins'); } }
Version: 1.0 Author: Suguru Hirahara Author URI: http://www.philosophyguides.org **/ function dlb_is_crawler() { //set to 1 to be more agressive in filtering //adds 'curl', wget', 'ruby' and 'bot' $dont_log_aggressive = 0; // Get current User-Agent $current = strtolower($_SERVER['HTTP_USER_AGENT']); $crawlers = array('200please.com/bot', '360spider', '80legs.com/webcrawler', 'a6-indexer', 'aboundex', 'aboutusbot', 'addsearchbot', 'addthis.com', 'adressendeutschland.de', 'adsbot-google', 'ahrefsbot', 'aihitbot', 'alexa site audit', 'amznkassocbot', 'analyticsseo.com', 'applebot', 'antbot', 'arabot', 'archive.org_bot', 'archive.orgbot', 'askpeterbot', 'backlinkcrawler', 'baidu.com/search/spider.html', 'baiduspider', 'begunadvertising', 'bingbot', 'bingpreview', 'bitlybot', 'bixocrawler', 'blekkobot', 'blexbot', 'brainbrubot', 'browsershots', 'bubing', 'butterfly', 'bufferbot', 'careerbot', 'catchbot', 'ccbot', 'cert figleafbot', 'changedetection.com/bot.html', 'chilkat', 'claritybot', 'classbot', 'cliqzbot', 'cms crawler', 'coccoc', 'compspybot', 'crawler4j', 'crowsnest', 'crystalsemanticsbot', 'dataminr.com', 'daumoa', 'digg', 'easouspider', 'exabot', 'exb language crawler', 'ezooms', 'facebookexternalhit', 'facebookplatform', 'fairshare', 'feedfetcher', 'feedly.com/fetcher.html', 'feedlybot', 'fetch', 'flipboardproxy', 'fyberspider', 'genieo', 'gigabot', 'google page speed insights', 'googlebot', 'grapeshot', 'hatena-useragent', 'hubspot connect', 'hubspot links crawler', 'hosttracker.com', 'ia_archiver', 'icc-crawler', 'ichiro', 'immediatenet.com', 'iltrovatore-setaccio', 'infohelfer', 'instapaper', 'ixebot', 'jabse.com crawler', 'james bot', 'jikespider', 'jyxobot', 'linkdex', 'linkfluence', 'loadimpactpageanalyzer', 'longurl', 'luminate.com', 'lycosa', 'magpie-crawler', 'mail.ru_bot', 'meanpathbot', 'mediapartners-google', 'metageneratorcrawler', 'metajobbot', 'metauri', 'mj12bot', 'mojeekbot', 'msai.in', 'msnbot-media', 'musobot', 'najdi.si', 'nalezenczbot', 'nekstbot', 'netcraftsurveyagent', 'netestate ne crawler', 'netseer crawler', 'nuhk', 'obot', 'omgilibot', 'openwebspider', 'panscient.com', 'parsijoo', 'plukkie', 'proximic', 'psbot', 'qirina hurdler', 'qualidator.com', 'queryseekerspider', 'readability', 'rogerbot', 'sbsearch', 'scrapy', 'search.kumkie.com', 'searchbot', 'searchmetricsbot', 'semrushbot', 'seocheckbot', 'seoengworldbot', 'seokicks-robot', 'seznambot', 'shareaholic.com/bot', 'shopwiki.com/wiki/help:bot', 'showyoubot', 'sistrix', 'sitechecker', 'siteexplorer', 'speedy spider', 'socialbm_bot', 'sogou web spider', 'sogou', 'sosospider', 'spbot', 'special_archiver', 'spiderling', 'spinn3r', 'spreadtrum', 'ssl-crawler', 'steeler', 'suma spider', 'surveybot', 'suggybot', 'svenska-webbsido', 'teoma', 'thumbshots', 'tineye.com', 'trendiction.com', 'trendiction.de/bot', 'turnitinbot', 'tweetedtimes', 'tweetmeme', 'twitterbot', 'uaslinkchecker', 'umbot', 'undrip bot', 'unisterbot', 'unwindfetchor', 'urlappendbot', 'vedma', 'vkshare', 'voilabot', 'wbsearchbot', 'wch web spider', 'webcookies', 'webcrawler at wise-guys dot nl', 'webthumbnail', 'wesee:search', 'woko', 'woobot', 'woriobot', 'wotbox', 'y!j-bri', 'y!j-bro', 'y!j-brw', 'y!j-bsc', 'yacybot', 'yahoo! slurp', 'yahooysmcm', 'yandexbot', 'yats', 'yeti', 'yioopbot', 'yodaobot', 'youdaobot', 'zb-1', 'zeerch.com/bot.php', 'zing-bottabot', 'zumbot', 'ning/1.0', 'yahoo:linkexpander:slingstone', 'google-http-java-client/1.17.0-rc (gzip)', 'js-kit url resolver', 'htmlparser', 'paperlibot', 'xenu link sleuth'); if ($dont_log_aggressive == 1) { $crawlers[] = 'bot'; $crawlers[] = 'ruby'; $crawlers[] = 'curl'; $crawlers[] = 'wget'; } // Check if the UA string contains any strings listed above $is_crawler = str_replace($crawlers, '', $current) != $current; return $is_crawler; } // Hook stuff in yourls_add_filter('shunt_update_clicks', 'dlb_skip_if_crawler'); yourls_add_filter('shunt_log_redirect', 'dlb_skip_if_crawler'); // Skip if crawler function dlb_skip_if_crawler() { return dlb_is_crawler(); // if anything but false is returned, functions using the two shunt_* filters will be short-circuited }
<?php /* Plugin Name: Allow aliases Plugin URI: http://mysite.com/yourls-sample-plugin/ Description: This plugin allows YOURLS to work with alias hostnames for the server Version: 1.0 Author: Aylwin Author URI: http://adigitalife.net/ */ // Hook our custom function into the 'shunt_get_request' filter yourls_add_filter('shunt_get_request', 'allow_aliases'); // Our custom function that will be triggered when the event occurs 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); }
* There should be a good collision avoidance algorithm by just incrementing * $osz_random_keyword['length'] by one when a collision takes place. */ global $ozh_random_keyword; /* * CONFIG: EDIT THIS */ /* Length of random keyword */ $ozh_random_keyword['length'] = 4; # was 5 /* * yourls_rnd_string $types: * '0' = yourls_get_shorturl_charset(), derzeit Base62 = Lower+Uppercase * '1' = only lowercase, no vowels, no confusion with 0/o, 1/l * etc. * I think we stick to '1' which gives friendly random keys. */ $ozh_random_keyword['type'] = '1'; // Generate a random keyword yourls_add_filter('random_keyword', 'ozh_random_keyword'); function ozh_random_keyword() { global $ozh_random_keyword; return yourls_rnd_string($ozh_random_keyword['length'], $ozh_random_keyword['type']); } // Don't increment sequential keyword tracker yourls_add_filter('get_next_decimal', 'ozh_random_keyword_next_decimal'); function ozh_random_keyword_next_decimal($next) { return $next - 1; }
<?php /* Plugin Name: Custom Protocols Plugin URI: http://yourls.org/ Description: Add custom protocol <code>blah://</code> for trusted users, blacklist all but <code>http</code> and <code>https</code> for others Version: 1.0 Author: Ozh Author URI: http://ozh.org/ */ // Hook into 'kses_allowed_protocols' to modify array. See functions-kses.php/yourls_kses_init() yourls_add_filter('kses_allowed_protocols', 'customproto_allowed_protocols'); // Whitelist or blacklist protocols depending on user context function customproto_allowed_protocols($protocols) { if (yourls_is_valid_user() && yourls_is_admin()) { // if user is logged in, or valid cookie exists on the computer, and we're in admin area: // add custom protocol 'blah://' to authorized protocols $protocols[] = 'blah://'; } else { // if no known user: remove all protocols except http & https $protocols = array('http://', 'https://'); } return $protocols; }
<?php /* Plugin Name: Allow Hyphens in Short URLs Plugin URI: http://yourls.org/ Description: Allow hyphens in short URLs (like <tt>http://sho.rt/hello-world</tt>) Version: 1.0 Author: Ozh Author URI: http://ozh.org/ */ yourls_add_filter('get_shorturl_charset', 'ozh_hyphen_in_charset'); function ozh_hyphen_in_charset($in) { return $in . '-'; }
} /******************** ROLE TEST AND ENUMERATION ***********************/ /* * Determine whether a specific user has a role. */ function authmgr_user_has_role($username, $rolename) { return yourls_apply_filter(AUTHMGR_HASROLE, false, $username, $rolename); } // ******************* FILTERS THAT GRANT ROLE MEMBERSHIP ********************* // By filtering AUTHMGR_HASROLE, you can connect internal roles to something else. // Any filter handlers should execute as quickly as possible. /* * What role memberships are defined for the user in user/config.php? */ yourls_add_filter(AUTHMGR_HASROLE, 'authmgr_user_has_role_in_config'); function authmgr_user_has_role_in_config($original, $username, $rolename) { global $authmgr_role_assignment; // if no role assignments are created, grant everything // so the site still works even if stuff is configured wrong if (empty($authmgr_role_assignment)) { return true; } // do this the case-insensitive way // the entire array was made lowercase in environment check $username = strtolower($username); $rolename = strtolower($rolename); // if the role doesn't exist, give up now. if (!in_array($rolename, array_keys($authmgr_role_assignment))) { return false;
<?php /* Plugin Name: Random number url Plugin URI: http://savikin.me/ Description: Assign random numberss to shorturls Version: 1.0 Author: Sava Author URI: http://savikin.me/ */ yourls_add_filter('random_keyword', 'random_number'); function random_number() { return rand(1, 9999); } yourls_add_filter('get_next_decimal', 'random_next_decimal'); function random_next_decimal($next) { return $next - 1; }
<?php /* Plugin Name: Fix Long URL Plugin URI: https://github.com/adigitalife/yourls-fix-long-url/ Description: This plugin fixes links with %20 and other similar encodings in them Version: 2.0 Author: Aylwin Author URI: http://adigitalife.net/ */ // Hook our custom function into the 'sanitize_url' filter yourls_add_filter('sanitize_url', 'fix_long_url'); // Replace '%2520' with '%20' in the URL function fix_long_url($url, $unsafe_url) { $search = array('%2520', '%2521', '%2522', '%2523', '%2524', '%2525', '%2526', '%2527', '%2528', '%2529', '%252A', '%252B', '%252C', '%252D', '%252E', '%252F', '%253A', '%253D', '%253F', '%255C', '%255F'); $replace = array('%20', '%21', '%22', '%23', '%24', '%25', '%26', '%27', '%28', '%29', '%2A', '%2B', '%2C', '%2D', '%2E', '%2F', '%3A', '%3D', '%3F', '%5C', '%5F'); $url = str_ireplace($search, $replace, $url); // Remove any trailing spaces from the long URL while (substr($url, -strlen('%20')) == '%20') { $url = preg_replace('/%20$/', '', $url); } return yourls_apply_filter('after_fix_long_url', $url, $unsafe_url); }
<?php /* Plugin Name: Allow _$! in Short URLs Plugin URI: http://yourls.org/ Description: Allow _#! in short URLs (like <tt>http://sho.rt/#!hello_world</tt>) Version: 1.0 Author: Jesse Author URI: http://blog.caiwangqin.com/ */ yourls_add_filter('get_shorturl_charset', 'underscore_in_charset'); function underscore_in_charset($in) { return $in . '_'; } yourls_add_filter('get_shorturl_charset', 'symbol1_in_charset'); function symbol1_in_charset($in) { return $in . '$'; } yourls_add_filter('get_shorturl_charset', 'symbol2_in_charset'); function symbol2_in_charset($in) { return $in . '!'; }
$solvemediaHKey = $_POST['spb_recaptcha_solvemediaHKey']; if (yourls_get_option('spb_recaptcha_pub_key') !== false) { yourls_update_option('spb_recaptcha_pub_key', $pubkey); } else { yourls_add_option('spb_recaptcha_pub_key', $pubkey); } if (yourls_get_option('spb_recaptcha_priv_key') !== false) { yourls_update_option('spb_recaptcha_priv_key', $privkey); } else { yourls_add_option('spb_recaptcha_priv_key', $privkey); } if (yourls_get_option('spb_recaptcha_solvemediaCKey') !== false) { yourls_update_option('spb_recaptcha_solvemediaCKey', $solvemediaCKey); } else { yourls_add_option('spb_recaptcha_solvemediaCKey', $solvemediaCKey); } if (yourls_get_option('spb_recaptcha_solvemediaVKey') !== false) { yourls_update_option('spb_recaptcha_solvemediaVKey', $solvemediaVKey); } else { yourls_add_option('spb_recaptcha_solvemediaVKey', $solvemediaVKey); } if (yourls_get_option('spb_recaptcha_solvemediaHKey') !== false) { yourls_update_option('spb_recaptcha_solvemediaHKey', $solvemediaHKey); } else { yourls_add_option('spb_recaptcha_solvemediaHKey', $solvemediaHKey); } echo "Saved"; } yourls_add_action('plugins_loaded', 'spb_recaptcha_plugin_init'); yourls_add_filter('shunt_add_new_link', 'spb_recaptcha_check_Captcha');
/** * Add filter function * * @param $name */ protected function addFilter($name) { // $hook, $function_name, $priority = 10, $accepted_args = NULL, $type = 'filter' // yourls_add_filter(substr($name, 7), [$this, $name], 10, NULL, 'filter'); yourls_add_filter(substr($name, 7), [$this, $name]); }
<?php /* Plugin Name: Anti spam Plugin URI: http://yourls.org/ Description: Absolute anti-spam plugin. Checks URL against major black lists and removes all crap. Might OR MIGHT NOT work for you. Read the readme. Version: 1.0.3 Author: Ozh Author URI: http://ozh.org/ */ // Check for spam when someone adds a new link yourls_add_filter('shunt_add_new_link', 'ozh_yourls_antispam_check_add'); function ozh_yourls_antispam_check_add($false, $url) { // Sanitize URL and make sure there's a protocol $url = yourls_sanitize_url($url); // only check for 'http(s)' if (!in_array(yourls_get_protocol($url), array('http://', 'https://'))) { return false; } if (ozh_yourls_antispam_is_blacklisted($url) != false) { return array('status' => 'fail', 'code' => 'error:spam', 'message' => 'This domain is blacklisted', 'errorCode' => '403'); } // All clear, not interrupting the normal flow of events return false; } // Has the remote link become compromised lately? Check on redirection yourls_add_action('redirect_shorturl', 'ozh_yourls_antispam_check_redirect'); function ozh_yourls_antispam_check_redirect($url, $keyword = false) { if (is_array($url) && $keyword == false) {
<?php /* Plugin Name: API Action - Delete Plugin URI: http://www.claytondaley.com/ Description: Adds a "delete" action to the API. This action requires authentication even if the site is public. This action accepts either a shorturl or keyword passed using the "shorturl" parameter. Version: 1.0 Author: Clayton Daley (derived from API-Action by Ozh) Author URI: http://www.claytondaley.com/ */ // Define custom action "delete" yourls_add_filter('api_action_delete', 'clayton_api_action_delete'); // Actually delete 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) ?
<?php /* Plugin Name: Check URL Plugin URI: http://code.google.com/p/yourls-check-url/ Description: This plugin checks the reachability of an entered URL before creating the short link for it. An error is then returned if the entered URL is unreachable. Version: 1.5 Author: Aylwin Author URI: http://adigitalife.net/ */ // Hook our custom function into the 'shunt_add_new_link' filter yourls_add_filter('shunt_add_new_link', 'churl_reachability', 1); // Add a new link in the DB, either with custom keyword, or find one function churl_reachability($churl_reachable, $url, $keyword = '') { global $ydb; preg_match('!^[a-zA-Z0-9\\+\\.-]+:(//)?!', $url, $matches); $protocol = isset($matches[0]) ? $matches[0] : ''; $different_protocols = array('http://', 'https://'); if ($protocol == '') { $protocol = 'http://'; $url = 'http://' . $url; } $check_url = in_array($protocol, $different_protocols); // Return to normal routine if non-http(s) protocol is valid if ($check_url == false) { return false; } // Check if the long URL is reachable $resURL = curl_init(); curl_setopt($resURL, CURLOPT_URL, $url);
/* Plugin Name: Case insensitive YOURLS Plugin URI: http://code.google.com/p/yourls-case-insensitive/ Description: Makes YOURLS case insensitive Version: 1.0 Author: Aylwin Author URI: http://adigitalife.net/ */ // No direct call if (!defined('YOURLS_ABSPATH')) { die; } // Hook our custom function into the 'add_new_link' filter yourls_add_filter('shunt_keyword_is_taken', 'insensitive_keyword_is_taken'); yourls_add_filter('shunt_get_keyword_info', 'insensitive_get_keyword_info'); // If the keyword exists, display the long URL in the error message function insensitive_keyword_is_taken($return, $keyword) { global $ydb; $keyword = yourls_sanitize_keyword($keyword); $taken = false; $table = YOURLS_DB_TABLE_URL; $already_exists = $ydb->get_var("SELECT COUNT(`keyword`) FROM `{$table}` WHERE LOWER(`keyword`) = LOWER('{$keyword}');"); if ($already_exists) { $taken = true; } return yourls_apply_filter('keyword_is_taken', $taken, $keyword); } function insensitive_get_keyword_info($return, $keyword, $field, $notfound) {
<?php /* Plugin Name: Update Shortened URL Plugin URI: https://github.com/timcrockford/yourls-api-edit-url Description: Define a custom API action 'update' and 'geturl' Version: 0.2.2 Author: Tim Crockford Author URI: http://codearoundcorners.com/ */ yourls_add_filter('api_action_update', 'api_edit_url_update'); yourls_add_filter('api_action_geturl', 'api_edit_url_get'); function api_edit_url_update() { if (!isset($_REQUEST['shorturl'])) { return array('statusCode' => 400, 'status' => 'fail', 'simple' => "Need a 'shorturl' parameter", 'message' => 'error: missing param'); } if (!isset($_REQUEST['url'])) { return array('statusCode' => 400, 'status' => 'fail', 'simple' => "Need a 'url' parameter", 'message' => 'error: missing param'); } $shorturl = $_REQUEST['shorturl']; $url = $_REQUEST['url']; if (yourls_get_protocol($shorturl)) { $keyword = yourls_get_relative_url($shorturl); } else { $keyword = $shorturl; } if (!yourls_is_shorturl($keyword)) { return array('statusCode' => 404, 'status' => 'fail', 'simple ' => "Error: keyword {$keyword} not found", 'message' => 'error: not found'); } $title = '';
* @return array $return return information + metadata if request was successfully otherwise just the already created error message */ function audiomark_api_get_metadata($return) { global $ydb; if ($return['message'] == 'success') { $keyword = $return['keyword']; $table = YOURLS_AUDIOMARK_TABLE_URL; $metadata = $ydb->get_row("SELECT * FROM `{$table}` WHERE `keyword` = '{$keyword}';"); // add metadata to return message $return['station_name'] = $metadata->station_name; $return['station_uri'] = $metadata->station_uri; $return['item_title'] = $metadata->item_title; $return['item_subtitle'] = $metadata->item_subtitle; $return['item_abstract'] = $metadata->item_abstract; } return $return; } // add filter yourls_add_filter('random_keyword', 'audiomark_create_keyword'); /* * Use our own keyword generator instead of the existing one. * * @param string $keyword * @return string $return created keyword */ function audiomark_create_keyword($keyword) { // Use URL instead the handed over keyword (unfortuately yourls does not hand it over) return create_short_url(yourls_sanitize_url($_REQUEST['url'])); }
<?php /* Plugin Name: YunoHost Auth plugin Plugin URI: http://yourls.org/ Description: Authentification plugin for YunoHost Version: 0.1 Author: ju Author URI: http://github.com/julienmalik */ // No direct call if (!defined('YOURLS_ABSPATH')) { die; } yourls_add_filter('shunt_is_valid_user', 'yunohost_auth_is_valid_user'); function yunohost_auth_is_valid_user($value) { return $_SERVER['PHP_AUTH_USER'] == YOURLS_YUNOHOST_AUTH_ADMIN; } /* And that's it. Activate the plugin and notice how the page title changes */
/* * YOURLS API * * Note about translation : this file should NOT be translation ready * API messages and returns are supposed to be programmatically tested, so default English is expected * */ 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); // Define standard API actions $api_actions = array('shorturl' => 'yourls_api_action_shorturl', 'stats' => 'yourls_api_action_stats', 'db-stats' => 'yourls_api_action_db_stats', 'url-stats' => 'yourls_api_action_url_stats', 'expand' => 'yourls_api_action_expand', 'version' => 'yourls_api_action_version'); $api_actions = yourls_apply_filters('api_actions', $api_actions); // Register API actions foreach ((array) $api_actions as $_action => $_callback) { yourls_add_filter('api_action_' . $_action, $_callback, 99); } // Try requested API method. Properly registered actions should return an array. $return = yourls_apply_filter('api_action_' . $action, false); if (false === $return) { $return = array('errorCode' => 400, 'message' => 'Unknown or missing "action" parameter', 'simple' => 'Unknown or missing "action" parameter'); } if (isset($_REQUEST['callback'])) { $return['callback'] = $_REQUEST['callback']; } $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'xml'; yourls_api_output($format, $return); die;
<?php /* Plugin Name: Whitelist Domains Plugin URI: Description: Allow URLs based on whitelisted Domain list Author: Sven Koeppel Author URI: https://th.physik.uni-frankfurt.de/~koeppel */ // No direct call if (!defined('YOURLS_ABSPATH')) { die; } // Hook the custom function into the 'shunt_add_new_link' event yourls_add_filter('shunt_add_new_link', 'svenk_check_whitelisted_domain'); // Get whitelisted domains from YOURLS options feature and compare with current domain address function svenk_check_whitelisted_domain($success, $url, $keyword, $title) { /* This filter works like that: Return $success if everything is fine, return something else or die if not. Unfortunately the filter is called *before* the URL is escaped properly, so we have to do this twice (https://github.com/YOURLS/YOURLS/blob/master/includes/functions.php#L185). */ $url = yourls_escape(yourls_sanitize_url(yourls_encodeURI($url))); $url_host = parse_url($url, PHP_URL_HOST); if (!$url_host) { // we cannot even determine the host part of the $url, fail silently. // This more or less replaces Line191 in the functions.php file. # yourls_die('During Whitelist check, cannot determine host of URL', 'Forbidden', 403); return array('status' => 'fail', 'code' => 'error:nourl', 'message' => 'During whitelist check, cannot determine host of URL. Probably missing or malformed URL', 'errorCode' => 400); } /* make sure this is present: The configuration of whitelisted domains */
Plugin Name: Geo API plugin Plugin URI: https://github.com/boxedfish/yourls-Geo-API-plugin Description: Geo API plugin to look up country code from a 3rdparty API if you find the local look up to be hit and miss or as in my case not working at all Version: 1.0 Author: alexjakass Author URI: http://boxed-rocket.com/ */ if (!defined('YOURLS_ABSPATH')) { die; } function aa_shunt_geo_ip_to_countrycode($location = '', $ip = '', $default = '') { if ($ip == '') { $ip = yourls_get_IP(); } $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, "http://geoiplookup.net/geoapi.php?output=json&ipaddress=" . $ip); curl_setopt($c, CURLOPT_TIMEOUT, 2); $contents = curl_exec($c); curl_close($c); if ($contents && $contents != "") { $location = JSON_DECODE($contents); } if (is_object($location) && isset($location->countryCode)) { return $location->countryCode; } return false; } yourls_add_filter('shunt_geo_ip_to_countrycode', 'aa_shunt_geo_ip_to_countrycode');
Author URI: http://matbra.com */ // No direct call if (!defined('YOURLS_ABSPATH')) { die; } if (YOURLS_PRIVATE === true) { // Add Event Handlers yourls_add_action('api', 'trapApi'); yourls_add_action('post_add_new_link', "updateLinkInsert"); yourls_add_action('load_template_infos', "trapLoadTemplateInfos"); yourls_add_action('pre_edit_link', "updateLinkEdit"); yourls_add_action('delete_link', "updateLinkDelete"); yourls_add_action('activated_multi-user/plugin.php', 'tryToInstall'); yourls_add_action('pre_add_new_link', "preAddLink"); yourls_add_filter('is_valid_user', "muIsValidUser"); } function muIsValidUser($str) { if (yourls_is_API()) { return true; } return $str; } function preAddLink($args) { if (YOURLS_MULTIUSER_ANONYMOUS === true) { return; } else { $token = isset($_REQUEST['token']) ? yourls_sanitize_string($_REQUEST['token']) : ''; $user = getUserIdByToken($token);
/** * Hooks a function on to a specific action. * * Actions are the hooks that YOURLS launches at specific points * during execution, or when specific events occur. Plugins can specify that * one or more of its PHP functions are executed at these points, using the * Action API. * * @param string $hook The name of the action to which the $function_to_add is hooked. * @param callback $function_name The name of the function you wish to be called. * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. * @param int $accepted_args optional. The number of arguments the function accept (default 1). */ function yourls_add_action($hook, $function_name, $priority = 10, $accepted_args = 1) { return yourls_add_filter($hook, $function_name, $priority, $accepted_args); }
<?php /* Plugin Name: Allow Forward Slashes in Short URLs Plugin URI: http://williambargent.co.uk Description: Allow Forward Slashes in Short URLs Version: 1.0 Author: <a href="http://williambargent.co.uk">William Bargent</a> */ if (!defined('YOURLS_ABSPATH')) { die; } yourls_add_filter('get_shorturl_charset', 'slash_in_charset'); function slash_in_charset($in) { return $in . '/'; } //This plugin will not work with URL forwarding plugins active
/* This says: when YOURLS does action 'admin_menu', call function 'ozh_sample_add_menu' */ function ozh_sample_add_menu() { echo '<li><a href="http://ozh.org/">Ozh</a></li>'; } /* And that's it. Activate the plugin and notice the new menu entry. */ /* Example of a filter * * We're going to modify the <title> of pages in the admin area * * The <title> tag is generated by function yourls_html_head() in includes/functions-html.php * Notice the following function call: * $title = yourls_apply_filter( 'html_title', 'YOURLS: Your Own URL Shortener' ); * This function means: give $title the value "YOURLS: Your Own URL Shortener", unless a * filter modifies this value. * * We're going to hook into this filter and modify this value. */ yourls_add_filter('html_title', 'ozh_sample_change_title'); /* This says: when filter 'html_title' is triggered, send its value to function 'ozh_sample_change_title' * and use what this function will return. */ function ozh_sample_change_title($value) { $value = $value . ' (we have hacked this title)'; return $value; // a filter *always* has to return a value } /* And that's it. Activate the plugin and notice how the page title changes */
<?php /* Plugin Name: Query String Forward Plugin URI: https://github.com/llonchj/yourls_plugins Description: Pushes the Short URL Query String into the Destination URL Version: 1.0 Author: Jordi Llonch Author URI: https://github.com/llonchj */ // Hook our custom function into the 'pre_redirect' event yourls_add_filter('redirect', 'qs_forward_redirect'); // Our custom function that will be triggered when the event occurs function qs_forward_redirect($url, $code) { $parsed_url = parse_url($url); parse_str($_SERVER['QUERY_STRING'], $query); parse_str($parsed_url["query"], $url_query); $a = array_merge($query, $url_query); $parsed_url["query"] = http_build_query($a); $new_url = $parsed_url["scheme"] . "://" . $parsed_url["host"]; if (isset($parsed_url["port"]) && $parsed_url["port"] != "") { $new_url = $new_url . ":" . $parsed_url["port"]; } $new_url = $new_url . $parsed_url["path"]; if (isset($parsed_url["query"]) && $parsed_url["query"] != "") { $new_url = "{$new_url}?" . $parsed_url["query"]; } return $new_url; }
<?php /* Plugin Name: GA-Measurement-Protocol Plugin URI: https://github.com/powerthazan/YOURS-GA-MP-Tracking Description: Tracks clicks using Google Analytics Measurement Protocol. Version: 1.1 Author: Powerthazan Author URI: https://www.twitter.com/powerthazan License: Creative Commons Attribution 3.0 Unported: https://creativecommons.org/licenses/by/3.0/ */ yourls_add_action('pre_redirect', 'power_ga_mp'); yourls_add_filter('shunt_update_clicks', 'power_ga_mp_trackCurrent'); function power_ga_mp_trackCurrent($unused) { global $keyword; power_ga_mp($keyword, yourls_get_keyword_title($keyword), $_SERVER['HTTP_REFERER']); return $unused; } // Handle the retrieval of the GA Measurment Protocol via curl instead of file_get_contents function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); // Don't bother checking the peer. This may imply a MIM can happen though... curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); return $response;
} if (!defined('VVA_CHANGE_PASSWORD_USE_DIGITS')) { define('VVA_CHANGE_PASSWORD_USE_DIGITS', FALSE); } if (!defined('VVA_CHANGE_PASSWORD_USE_SPECIAL')) { define('VVA_CHANGE_PASSWORD_USE_SPECIAL', FALSE); } if (!defined('VVA_CHANGE_PASSWORD_USE_UPPERCASE')) { define('VVA_CHANGE_PASSWORD_USE_UPPERCASE', FALSE); } /** * Add hooks required for plugin */ yourls_add_action('plugins_loaded', 'vva_change_password_register_page'); yourls_add_filter('logout_link', 'vva_change_password_logout_link'); yourls_add_filter('admin_sublinks', 'vva_change_password_admin_sublinks'); /** * Register the change password page */ function vva_change_password_register_page() { yourls_register_plugin_page('change_password', 'Change Password', 'vva_change_password_display_page'); } /** * Add the change password link next to logout so it makes sense in the UI * * @param string $logout_link * @return string $logout_link */ function vva_change_password_logout_link($logout_link) {