<?php /* Plugin Name: Bulk URL shortener Plugin URI: https://github.com/tdakanalis/bulk_api_bulkshortener Description: Shorten URLs in bulk (a single request with many URLs to shorten). Version: 1.0 Author: Stelios Mavromichalis Author URI: http://www.cytech.gr */ yourls_add_action('api', 'bulk_api_bulkshortener'); function bulk_api_bulkshortener($action) { if ($action[0] != 'bulkshortener') { return; } if (!isset($_REQUEST['urls'])) { $return = array('errorCode' => 400, 'message' => 'bulkshortener: missing URLS parameter', 'simple' => 'bulkshortener: missing URLS parameter'); echo $return['errorCode'] . ": " . $return['simple']; die; } $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : ''; $title = isset($_REQUEST['title']) ? $_REQUEST['title'] : ''; $urls = isset($_REQUEST['urls']) ? $_REQUEST['urls'] : array(); foreach ($urls as $url) { $return = yourls_add_new_link($url, $keyword, $title); echo $return['shorturl'] . "\n"; } die; }
// No direct call. if (!defined('YOURLS_ABSPATH')) { die; } // Change to true to get extra debugging info on-screen. Must be true or false, cannot be undefined. define("PCE_DEBUG", false); // Define the separator between bits of information. define("PCE_SEP", ' | '); // Some version details, same as at the top of this file, for use in the page footer. define("PCE_REL_VER", '0.1'); define("PCE_REL_DATE", '2014-07-16'); // Repository URL. define("PCE_REPO", 'https://github.com/vaughany/yourls-popular-clicks-extended'); // Get the GMT offset if it is set define("PCE_OFFSET", defined('YOURLS_HOURS_OFFSET') ? YOURLS_HOURS_OFFSET * 60 * 60 : 0); yourls_add_action('plugins_loaded', 'vaughany_popularclicksextended_add_page'); function vaughany_popularclicksextended_add_page() { yourls_register_plugin_page('popularclicksextended', 'Popular Clicks Extended', 'vaughany_popularclicksextended_display_page'); } function vaughany_popularclicksextended_display_page() { echo '<h2>Popular Clicks Extended</h2>' . "\n"; echo '<p>This report shows the most popular clicks for the selected time periods as of ' . date('jS F Y, g:ia', time()) . '.</p>' . "\n"; echo '<p>Legend: <em>Position. Clicks' . PCE_SEP . 'Short URL' . PCE_SEP . 'Page</em></p>' . "\n"; /** * vaughany_show_last_period(): queries the database for the number of clicks per link since n seconds ago, * e.g. 'time() - 300' to 'time()' * e.g. '2014-07-15 14:52:27' to '2014-07-15 14:57:27' * * $period: integer: The number of seconds to look back.
<?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;
/** * Wrapper function to display admin notices * */ function yourls_add_notice($message, $style = 'notice') { // Escape single quotes in $message to avoid breaking the anonymous function $message = yourls_notice_box(strtr($message, array("'" => "\\'")), $style); yourls_add_action('admin_notices', create_function('', "echo '{$message}';")); }
Version: 0.1 Author: Ozh Author URI: http://ozh.org/ */ /* Example of an action * * We're going to add an entry to the menu. * * The menu is drawn by function yourls_html_menu() in file includes/functions-html.php. * Right before the function outputs the closing </ul>, notice the following function call: * yourls_do_action( 'admin_menu' ); * This function says: "hey, for your information, I've just done something called 'admin menu', thought I'd let you know..." * * We're going to hook into this action and add our menu entry */ yourls_add_action('admin_menu', 'ozh_sample_add_menu'); /* 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' );
<?php /* Plugin Name: Protected URLS Plugin URI: http://yourls.org/ Description: Show password page for Protected Urls Version: 1.0 Author: ID Author URI: http://demirel.ws/ */ // Hook our custom function into the 'pre_redirect' event yourls_add_action('redirect_shorturl', 'gural_yourls_protected_keyword'); // Our custom function that will be triggered when the event occurs function gural_yourls_protected_keyword($args) { require_once YOURLS_INC . '/functions.php'; $longurl = $args[0]; $keyword = $args[1]; $pass = yourls_get_keyword_pass($keyword); //echo "Pass : "******" <br>";die(); if (isset($pass) && $pass != "") { $postedPass = $_POST['pass']; if (!$postedPass || $pass != $postedPass) { echo GetPasswordForm(); die; } else { $update_clicks = yourls_update_clicks($keyword); } } else { echo "Not Protected"; die;
} // Update option in database function gmo_domain_swap_update_option() { $in = $_POST['domain_swap_values']; if (!empty($in)) { $in = preg_split('/(\\r?\\n)+/', trim($in)); array_walk($in, "gmo_domain_trim_value"); $arr = array('domains' => $in); $json = json_encode($arr); yourls_update_option('domain_swap_values', $json); } } /** * User action */ if (basename($_SERVER['PHP_SELF']) == 'index.php') { yourls_add_action('admin_menu', 'gmo_domain_swap_add_menu'); } function gmo_domain_swap_add_menu() { echo '<li>'; echo 'Active domain: <select onchange="window.location.hostname = this.value;">'; $domain_swap_values = json_decode(yourls_get_option('domain_swap_values')); foreach ($domain_swap_values->domains as $domain) { $selected = $_SERVER["SERVER_NAME"] == $domain ? 'selected' : ''; echo '<option ' . $selected . ' value="' . $domain . '"/>//' . $domain . '/'; } echo '</select>'; echo '</li>'; }
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) { $keyword = $url[1]; $url = $url[0]; } // Check when the link was added // If shorturl is fresh (ie probably clicked more often?) check once every 15 times, otherwise once every 5 times // Define fresh = 3 days = 259200 secondes // TODO: when there's a shorturl_meta table, store last check date to allow checking every 2 or 3 days $now = date('U'); $then = date('U', strtotime(yourls_get_keyword_timestamp($keyword))); $chances = $now - $then > 259200 ? 15 : 5; if ($chances == mt_rand(1, $chances)) { if (ozh_yourls_antispam_is_blacklisted($url) != false) {
/** * Add action function * * @param $name */ protected function addAction($name) { // $hook, $function_name, $priority = 10, $accepted_args = 1, $type = 'action' // yourls_add_filter(substr($name, 7), [$this, $name], 10, 1, 'action'); yourls_add_action(substr($name, 7), [$this, $name]); }
<?php /* Plugin Name: iTunes Affiliate Plugin URI: https://github.com/floschliep/YOURLS-iTunes-Affiliate Description: Add your iTunes Affiliate-Token to all iTunes URLs before redirection Version: 1.0.1 Author: Florian Schliep Author URI: http://floschliep.com */ yourls_add_action('pre_redirect', 'flo_addToken'); function flo_addToken($args) { $token = 'YOUR_TOKEN_HERE'; $url = $args[0]; // check if URL is an iTunes URL if (preg_match("/(itunes\\.apple\\.com\\/)([a-z]{2,3}\\/)|([a-z].+\\/)id[0-9]+/ui", $url) == true) { // check if last char is an "/" (in case it is, remove it) if (substr($url, -1) == "/") { $url = substr($url, 0, -1); } // remove existing affiliate token if needed $existingToken; if (preg_match("/(\\?|&)ign-mpt=.+\\&/ui", $url, $matches) == true) { // first way affiliate tokens can appear (encoded and not at end of string) $existingToken = $matches[0]; $existingToken = substr($existingToken, 0, -1); // last char is an "&" } else { if (preg_match("/(\\?|&)ign-mpt=.+/uim", $url, $matches) == true) { // second way affiliate tokens can appear (encoded and at end of string)
<?php /* Plugin Name: 404 if no short URL Plugin URI: Description: Modified after https://github.com/YOURLS/YOURLS/issues/1869 Author: Sven Koeppel */ yourls_add_action('redirect_keyword_not_found', 'my404'); function my404($data) { $shorturl = $data[0]; include_once dirname(__FILE__) . '/../../404.php'; show404($shorturl); exit; }
/* Plugin Name: Upload & Shorten Plugin URI: https://github.com/fredl99/YOURLS-Upload-and-Shorten Description: Upload a file and create a short-YOURL for it in one step. Based on: "Share Files" by Matt Temple Forked from: http://www.mattytemple.com/projects/yourls-share-files Version: 1.2 Author: Fredl Author URI: https://github.com/fredl99 */ // No direct call if (!defined('YOURLS_ABSPATH')) { die; } // Register our plugin admin page yourls_add_action('plugins_loaded', 'my_upload_and_shorten_add_page'); function my_upload_and_shorten_add_page() { // load custom text domain yourls_load_custom_textdomain('upload-and-shorten', dirname(__FILE__) . '/i18n/'); // create entry in the admin's plugin menu yourls_register_plugin_page('upload-and-shorten', 'Upload & Shorten', 'my_upload_and_shorten_do_page'); // parameters: page slug, page title, and function that will display the page itself } // Display admin page function my_upload_and_shorten_do_page() { // Check if a form was submitted if (isset($_POST['submit'])) { $my_save_files_message = my_upload_and_shorten_save_files(); }
<?php /* Plugin Name: Popular Clicks Plugin URI: hhttps://github.com/miconda/yourls Description: Shows an admin page with the top of last clicked links Version: 1.0 Author: miconda Author URI: http://miconda.blogspot.com/ */ yourls_add_action('plugins_loaded', 'popularclicks_add_page'); function popularclicks_add_page() { yourls_register_plugin_page('popular_clicks', 'Popular Clicks', 'popularclicks_do_page'); } // Display popular clicks function popularclicks_do_page() { $nonce = yourls_create_nonce('popular_clickks'); echo '<h2>Popular Clicks</h2>'; function show_top($numdays, $numrows) { global $ydb; $base = YOURLS_SITE; $table_url = YOURLS_DB_TABLE_URL; $table_log = YOURLS_DB_TABLE_LOG; $outdata = ''; /** SELECT a.shorturl AS shorturl, count(*) AS clicks, b.url AS longurl FROM yourls_log a, yourls_url b WHERE a.shorturl=b.keyword AND DATE_SUB(NOW(), INTERVAL 30 DAY)<a.click_time GROUP BY a.shorturl ORDER BY count(*) DESC LIMIT 20;
if (!defined('VVA_CHANGE_PASSWORD_MINIMUM_LENGTH')) { define('VVA_CHANGE_PASSWORD_MINIMUM_LENGTH', 6); } 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 */
Author URI: http://ozh.org/ Disclaimer: Toolbars ruin the user experience. Be warned. */ global $ozh_toolbar; $ozh_toolbar['do'] = false; $ozh_toolbar['keyword'] = ''; // When a redirection to a shorturl is about to happen, register variables yourls_add_action('redirect_shorturl', 'ozh_toolbar_add'); function ozh_toolbar_add($args) { global $ozh_toolbar; $ozh_toolbar['do'] = true; $ozh_toolbar['keyword'] = $args[1]; } // On redirection, check if this is a toolbar and draw it if needed yourls_add_action('pre_redirect', 'ozh_toolbar_do'); function ozh_toolbar_do($args) { global $ozh_toolbar; // Does this redirection need a toolbar? if (!$ozh_toolbar['do']) { return; } // Do we have a cookie stating the user doesn't want a toolbar? if (isset($_COOKIE['yourls_no_toolbar']) && $_COOKIE['yourls_no_toolbar'] == 1) { return; } // Get URL and page title $url = $args[0]; $pagetitle = yourls_get_keyword_title($ozh_toolbar['keyword']); // Update title if it hasn't been stored yet
$solvemediaVKey = $_POST['spb_recaptcha_solvemediaVKey']; $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');
<?php /* Plugin Name: Redirect with GET Plugin URI: https://ge1.me/yourls-redirect-with-get Description: Redirect with all GET parameters. Version: 2.0 Author: fnkr Author URI: https://www.fnkr.net License: Creative Commons Attribution 3.0 Unported: https://creativecommons.org/licenses/by/3.0/ */ yourls_add_action('redirect_shorturl', 'fnkr_redirect_with_get'); function fnkr_redirect_with_get($url) { $parsed_url = parse_url($url[0]); 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']; } global $url; $url = $new_url; }
# if the test fails (due to lack of a levenshtein() function or incorrect results), return a message. # this output is captured by yourls and prevents module activation if (!$levenshtein_test_pass) { ?> ERROR: MySQL "LEVENSHTEIN()" function not present or could not be verified.<br> See the following pages for potential solutions: <ul><li><a href="https://github.com/jmcejuela/Levenshtein-MySQL-UDF" target="_blank">GitHub user jmcejuela's User-Defined Function (UDF)</a></li> <li><a href="http://stackoverflow.com/questions/12617348/mysql-levenshtein" target="_blank">Create a function within MySQL</a><br> (Also see the <tt>mysql_levenshtein_function.sql</tt> file included with this plugin.)</li></ul> <strong>Note</strong>: UDF module has shown 500-1000x faster performance than the SQL function. Plugin failed to activate.<br> <?php } # TODO: end code that needs only-run-on-activation conditional yourls_add_action('redirect_keyword_not_found', 'ltc_fuzzy_suggest'); yourls_add_action('loader_failed', 'ltc_fuzzy_suggest'); function ltc_fuzzy_suggest($ltc_request) { if ($_SERVER['REQUEST_URI'] == '/') { # homepage redirect $keyword_supplied = FALSE; } else { $keyword_supplied = TRUE; header('X-PHP-Response-Code: 404', true, 404); global $ydb; $table_url = YOURLS_DB_TABLE_URL; $ltc_keyword = yourls_sanitize_keyword($ltc_request[0]); $query = $ydb->get_results("SELECT keyword, url, title, LEVENSHTEIN('{$ltc_keyword}', keyword) AS `lev_dist` FROM `{$table_url}` HAVING `lev_dist` < 3 ORDER BY `lev_dist` DESC"); if ($query) { $suggested_results = TRUE; } else {
<?php /* Plugin Name: Audiomark extension Plugin URI: http://mysite.com/yourls-sample-plugin/ Description: Different features to support audiomark (Add Metatags, Retrieve them via API, new Keyword Shortener algorithm etc.) Version: 0.3 Author: Jens Lukas Author URI: http://jenslukas.com/ */ require_once dirname(__FILE__) . '/config.inc.php'; require_once dirname(__FILE__) . '/functions.php'; // add action yourls_add_action('audiomark_add_metadata', 'audiomark_add_metadata_to_db'); /* * Add additional specified metadata to database * Function is executed when a URL is added successfully * * @param array $args contains the metadata */ function audiomark_add_metadata_to_db($args) { global $ydb; $keyword = $args[0]; $radio = $args[1]; $portal = $args[2]; $title = $args[3]; $sub_title = $args[4]; $desc = $args[5]; $audiomark = $args[6]; // create audiomark
Author: Matheus (X-warrior) - matheusbrat@gmail.com 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']) : '';
function yourls_add_notice($message) { $message = yourls_notice_box($message); yourls_add_action('admin_notices', create_function('', "echo '{$message}';")); }
<?php /** * Bootstrap Theme for YOURLS * * @author Leo Colombaro * @package YOURLS */ // Is there things to display? If so, let's add our stuff yourls_add_action('init_theme', 'lc_full_bootstrap_init'); /** * 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'); } /** * Rewrite template * * @param array $elements Default template * @return array New structure */ function lc_full_bootstrap_template($elements) { lc_full_bootstrap_replace_in_array($elements, 'yourls_sidebar_start', 'lc_full_bootstrap_nav_start'); lc_full_bootstrap_remove_from_array($elements, 'yourls_html_global_stats');
<?php /* Plugin Name: Random Backgrounds Plugin URI: http://yourls.org/ Description: Pretty random background patterns Version: 1.0 Author: Ozh Author URI: http://ozh.org/ */ // No direct call if (!defined('YOURLS_ABSPATH')) { die; } // Add the inline style yourls_add_action('html_head', 'ozh_yourls_randombg'); function ozh_yourls_randombg() { $bg = glob(dirname(__FILE__) . '/img/*png'); $url = yourls_plugin_url(dirname(__FILE__)); $rnd = yourls_plugin_url($bg[mt_rand(0, count($bg) - 1)]); echo <<<CSS <style type="text/css"> \t\tbody {background:#e3f3ff url({$rnd}) repeat;} \t</style> CSS; }
$pubkey = $_POST['abdulrauf_adminreCaptcha_public_key']; $privkey = $_POST['abdulrauf_adminreCaptcha_private_key']; if (yourls_get_option('abdulrauf_adminreCaptcha_pub_key') !== false) { yourls_update_option('abdulrauf_adminreCaptcha_pub_key', $pubkey); } else { yourls_add_option('abdulrauf_adminreCaptcha_pub_key', $pubkey); } if (yourls_get_option('abdulrauf_adminreCaptcha_priv_key') !== false) { yourls_update_option('abdulrauf_adminreCaptcha_priv_key', $privkey); } else { yourls_add_option('abdulrauf_adminreCaptcha_priv_key', $privkey); } echo "Saved"; } // Add the JavaScript for reCaptcha widget yourls_add_action('html_head', 'abdulrauf_adminreCaptcha_addjs'); function abdulrauf_adminreCaptcha_addjs() { $siteKey = yourls_get_option('abdulrauf_adminreCaptcha_pub_key'); ?> <script type="text/javascript"> //JQuery function to add div for reCaptcha widget and load js only on login screen $(document).ready(function() { var logindiv = document.getElementById('login'); if (logindiv != null) { //check if we are on login screen //getting reCaptcha script by jquery only on login screen $.getScript( "https://www.google.com/recaptcha/api.js?onload=loadCaptcha&render=explicit"); var form = logindiv.innerHTML; var index = form.indexOf('<p style="text-align: right;">'); //finding tag before which reCaptcha widget should appear document.getElementById('login').innerHTML = form.slice(0, index) + '<div id="captcha_container"></div>' + form.slice(index); }
<?php /* Plugin Name: Sample Admin Page Plugin URI: http://yourls.org/ Description: A example of a plugin administration page to save user defined option Version: 1.0 Author: Ozh Author URI: http://ozh.org/ */ // Register our plugin admin page yourls_add_action('plugins_loaded', 'ozh_yourls_samplepage_add_page'); function ozh_yourls_samplepage_add_page() { yourls_register_plugin_page('sample_page', 'Sample Admin Page', 'ozh_yourls_samplepage_do_page'); // parameters: page slug, page title, and function that will display the page itself } // Display admin page function ozh_yourls_samplepage_do_page() { // Check if a form was submitted if (isset($_POST['test_option'])) { ozh_yourls_samplepage_update_option(); } // Get value from database $test_option = yourls_get_option('test_option'); echo <<<HTML \t\t<h2>Sample Plugin Administration Page</h2> \t\t<p>This plugin stores an integer in the option database</p> \t\t<form method="post"> \t\t<p><label for="test_option">Enter an integer</label> <input type="text" id="test_option" name="test_option" value="{$test_option}" /></p>
const ManagePlugins = 'ManagePlugins'; const API = 'API'; const ViewStats = 'ViewStats'; } /********** Add hooks to intercept functionality in CORE ********/ yourls_add_action('load_template_infos', 'authmgr_intercept_stats'); function authmgr_intercept_stats() { authmgr_require_capability(AuthmgrCapability::ViewStats); } yourls_add_action('api', 'authmgr_intercept_api'); function authmgr_intercept_api() { authmgr_require_capability(AuthmgrCapability::API); } yourls_add_action('admin_init', 'authmgr_intercept_admin'); function authmgr_intercept_admin() { authmgr_require_capability(AuthmgrCapability::ShowAdmin); // we use this GET param to send up a feedback notice to user if (isset($_GET['access']) && $_GET['access'] == 'denied') { yourls_add_notice('Access Denied'); } $action_capability_map = array('add' => AuthmgrCapability::AddURL, 'delete' => AuthmgrCapability::DeleteURL, 'edit_display' => AuthmgrCapability::EditURL, 'edit_save' => AuthmgrCapability::EditURL, 'activate' => AuthmgrCapability::ManagePlugins, 'deactivate' => AuthmgrCapability::ManagePlugins); // intercept requests for plugin management if (isset($_REQUEST['plugin'])) { $action_keyword = $_REQUEST['action']; $cap_needed = $action_capability_map[$action_keyword]; if ($cap_needed !== NULL && authmgr_have_capability($cap_needed) !== true) { yourls_redirect(yourls_admin_url('?access=denied'), 302); }
* * You should have received a copy of the GNU General Public License along * with this program. If not, see <http://www.gnu.org/licenses/>. **/ /* Short out click tracker for logged-in users * * @uses filter shunt_update_clicks * * We're going to hook into this filter and modify this value. */ function dgw_dont_track_admins($unusedvar) { // If we've gotten here... return true; // ...we want to short-circuit the click updater. } /* Initialize the filters AFTER all the plugins have been loaded. This allows other plugins to register hooks related to authorization before calling yourls_is_valid_user(). */ yourls_add_action('plugins_loaded', 'dgw_dont_track_admins_init'); 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'); } }
// Set campaign params from the URL $query = parse_url($url); parse_str($query); if (isset($utm_name)) { $analytics->setCampaignName($utm_name); } if (isset($utm_source)) { $analytics->setCampaignSource($utm_source); } if (isset($utm_medium)) { $analytics->setCampaignMedium($utm_medium); } } // Before we send the redirect to the client, notify GA of the click yourls_add_action('redirect_shorturl', function ($url, $keyword) { // Get a client Id $cid = get_client_id(); // Instantiate the Analytics object, true means use HTTPS $analytics = new Analytics(true); // Build the required hit parameters $analytics->setProtocolVersion('1')->setTrackingId($gaid)->setCacheBuster(rand(100000000000.0, 999999999999.0))->setClientId($cid); set_campaign_props($url, $analytics); // Set the referer url if (isset($_SERVER['HTTP_REFERER'])) { $analytics->setDocumentReferer($_SERVER['HTTP_REFERER']); } // Set optional parameters $analytics->setDataSource('godot'); // Send it to GA $analytics->setAsyncRequest(true)->sendPageview(); });
* @copyright (C) 2002, 2003, 2005 * @author Ulf Harnhammar <http://advogato.org/person/metaur/> * * @package External * @subpackage KSES * */ /* NOTE ABOUT GLOBALS * Two globals are defined: $yourls_allowedentitynames and $yourls_allowedprotocols * - $yourls_allowedentitynames is used internally in KSES functions to sanitize HTML entities * - $yourls_allowedprotocols is used in various parts of YOURLS, not just in KSES, albeit being defined here * Two globals are not defined and unused at this moment: $yourls_allowedtags_all and $yourls_allowedtags * The code for these vars is here and ready for any future use */ // Populate after plugins have loaded to allow user defined values yourls_add_action('plugins_loaded', 'yourls_kses_init'); /** * Init KSES globals if not already defined (by a plugin) * * @since 1.6 * */ function yourls_kses_init() { global $yourls_allowedentitynames, $yourls_allowedprotocols; if (!$yourls_allowedentitynames) { $yourls_allowedentitynames = yourls_apply_filter('kses_allowed_entities', yourls_kses_allowed_entities()); } if (!$yourls_allowedprotocols) { $yourls_allowedprotocols = yourls_apply_filter('kses_allowed_protocols', yourls_kses_allowed_protocols()); }
$piwik_config = yourls_get_option('piwik_config'); // If we don't log stats locally if ($piwik_config[disable_stats]) { // If we're not using the free version of the plugin if ($piwik_config[SKU] !== "free") { // Replace each link with a link to the Piwik installation foreach ($actions as $k => &$action) { if ($k == "stats") { $action['href'] = $piwik_config[piwik_url]; } } } } return $actions; } yourls_add_action('load_template_infos', 'itfs_piwik_disable_stats'); /** * Disables the stats page and redirects the user to the long URL instead * @param array $keyword */ function itfs_piwik_disable_stats($keyword) { // Get current configuration from database $piwik_config = yourls_get_option('piwik_config'); // We don't display the stats page in the free version if you don't log locally if ($piwik_config[disable_stats] && $piwik_config[SKU] === "free") { $keyword = $keyword[0]; // This redirects users to the destination url instead of the stats page include YOURLS_ABSPATH . '/yourls-go.php'; exit; }