diff options
Diffstat (limited to 'user')
41 files changed, 741 insertions, 0 deletions
diff --git a/user/config-sample.php b/user/config-sample.php new file mode 100644 index 0000000..a886c5a --- /dev/null +++ b/user/config-sample.php @@ -0,0 +1,95 @@ +<?php +/* This is a sample config file. + * Edit this file with your own settings and save it as "config.php" + * + * IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or + * Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file. + */ + +/* + ** MySQL settings - You can get this info from your web host + */ + +/** MySQL database username */ +define( 'YOURLS_DB_USER', 'your db user name' ); + +/** MySQL database password */ +define( 'YOURLS_DB_PASS', 'your db password' ); + +/** The name of the database for YOURLS */ +define( 'YOURLS_DB_NAME', 'yourls' ); + +/** MySQL hostname. + ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */ +define( 'YOURLS_DB_HOST', 'localhost' ); + +/** MySQL tables prefix */ +define( 'YOURLS_DB_PREFIX', 'yourls_' ); + +/* + ** Site options + */ + +/** YOURLS installation URL -- all lowercase, no trailing slash at the end. + ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */ +define( 'YOURLS_SITE', 'http://your-own-domain-here.com' ); + +/** Server timezone GMT offset */ +define( 'YOURLS_HOURS_OFFSET', 0 ); + +/** YOURLS language + ** Change this setting to use a translation file for your language, instead of the default English. + ** That translation file (a .mo file) must be installed in the user/language directory. + ** See http://yourls.org/translations for more information */ +define( 'YOURLS_LANG', '' ); + +/** Allow multiple short URLs for a same long URL + ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior) + ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */ +define( 'YOURLS_UNIQUE_URLS', true ); + +/** Private means the Admin area will be protected with login/pass as defined below. + ** Set to false for public usage (eg on a restricted intranet or for test setups) + ** Read http://yourls.org/privatepublic for more details if you're unsure */ +define( 'YOURLS_PRIVATE', true ); + +/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/ +define( 'YOURLS_COOKIEKEY', 'modify this text with something random' ); + +/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes + ** YOURLS will auto encrypt plain text passwords in this file + ** Read http://yourls.org/userpassword for more information */ +$yourls_user_passwords = array( + 'username' => 'password', + // 'username2' => 'password2', + // You can have one or more 'login'=>'password' lines + ); + +/** Debug mode to output some internal information + ** Default is false for live site. Enable when coding or before submitting a new issue */ +define( 'YOURLS_DEBUG', false ); + +/* + ** URL Shortening settings + */ + +/** URL shortening method: 36 or 62 */ +define( 'YOURLS_URL_CONVERT', 36 ); +/* + * 36: generates all lowercase keywords (ie: 13jkm) + * 62: generates mixed case keywords (ie: 13jKm or 13JKm) + * Stick to one setting. It's best not to change after you've started creating links. + */ + +/** +* Reserved keywords (so that generated URLs won't match them) +* Define here negative, unwanted or potentially misleading keywords. +*/ +$yourls_reserved_URL = array( + 'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', +); + +/* + ** Personal settings would go after here. + */ + diff --git a/user/config.php b/user/config.php new file mode 100644 index 0000000..0f5749f --- /dev/null +++ b/user/config.php @@ -0,0 +1,95 @@ +<?php +/* This is a sample config file. + * Edit this file with your own settings and save it as "config.php" + * + * IMPORTANT: edit and save this file as plain ASCII text, using a text editor, for instance TextEdit on Mac OS or + * Notepad on Windows. Make sure there is no character before the opening <?php at the beginning of this file. + */ + +/* + ** MySQL settings - You can get this info from your web host + */ + +/** MySQL database username */ +define( 'YOURLS_DB_USER', '25333140_3' ); + +/** MySQL database password */ +define( 'YOURLS_DB_PASS', '11]pSlk9]0' ); + +/** The name of the database for YOURLS */ +define( 'YOURLS_DB_NAME', 'epiz_25333140_69' ); + +/** MySQL hostname. + ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */ +define( 'YOURLS_DB_HOST', 'sql104.byetcluster.com' ); + +/** MySQL tables prefix */ +define( 'YOURLS_DB_PREFIX', 'ypreox_' ); + +/* + ** Site options + */ + +/** YOURLS installation URL -- all lowercase, no trailing slash at the end. + ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */ +define( 'YOURLS_SITE', 'http://crack.cf' ); + +/** Server timezone GMT offset */ +define( 'YOURLS_HOURS_OFFSET', 0 ); + +/** YOURLS language + ** Change this setting to use a translation file for your language, instead of the default English. + ** That translation file (a .mo file) must be installed in the user/language directory. + ** See http://yourls.org/translations for more information */ +define( 'YOURLS_LANG', '' ); + +/** Allow multiple short URLs for a same long URL + ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior) + ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */ +define( 'YOURLS_UNIQUE_URLS', true ); + +/** Private means the Admin area will be protected with login/pass as defined below. + ** Set to false for public usage (eg on a restricted intranet or for test setups) + ** Read http://yourls.org/privatepublic for more details if you're unsure */ +define( 'YOURLS_PRIVATE', true ); + +/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from http://yourls.org/cookie **/ +define( 'YOURLS_COOKIEKEY', 'd6ztus7jlhqsrwm6ukk35eoljckavxez' ); + +/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes + ** YOURLS will auto encrypt plain text passwords in this file + ** Read http://yourls.org/userpassword for more information */ +$yourls_user_passwords = array( + 'sin' => 'phpass:!2a!08!z2cgx83iehgJwBFiuLhdqusPLM2k1KtkbqrIr9Mgp8pjPBJSptVMO' /* Password encrypted by YOURLS */ , + // 'username2' => 'password2', + // You can have one or more 'login'=>'password' lines + ); + +/** Debug mode to output some internal information + ** Default is false for live site. Enable when coding or before submitting a new issue */ +define( 'YOURLS_DEBUG', false ); + +/* + ** URL Shortening settings + */ + +/** URL shortening method: 36 or 62 */ +define( 'YOURLS_URL_CONVERT', 36 ); +/* + * 36: generates all lowercase keywords (ie: 13jkm) + * 62: generates mixed case keywords (ie: 13jKm or 13JKm) + * Stick to one setting. It's best not to change after you've started creating links. + */ + +/** +* Reserved keywords (so that generated URLs won't match them) +* Define here negative, unwanted or potentially misleading keywords. +*/ +$yourls_reserved_URL = array( + 'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', +); + +/* + ** Personal settings would go after here. + */ + diff --git a/user/index.html b/user/index.html new file mode 100644 index 0000000..cfce37c --- /dev/null +++ b/user/index.html @@ -0,0 +1,8 @@ +<!-- This page hides the content of the /pages/ directory and sends to YOURLS root --> +<html> +<head> +<meta http-equiv="refresh" content="0;url=../"></head> +<body> +YOURLS has nothing for you to see here. +</body> +</html>
\ No newline at end of file diff --git a/user/languages/index.html b/user/languages/index.html new file mode 100644 index 0000000..7116f76 --- /dev/null +++ b/user/languages/index.html @@ -0,0 +1,8 @@ +<!-- This page hides the content of the directory and sends to YOURLS root --> +<html> +<head> +<meta http-equiv="refresh" content="0;url=../"></head> +<body> +YOURLS has nothing for you to see here. +</body> +</html>
\ No newline at end of file diff --git a/user/plugins/hyphens-in-urls/README.md b/user/plugins/hyphens-in-urls/README.md new file mode 100644 index 0000000..ba72883 --- /dev/null +++ b/user/plugins/hyphens-in-urls/README.md @@ -0,0 +1,6 @@ +Hyphens in URLs +=============== +This is a core plugin, bundled with YOURLS. +Don't modify this plugin. Instead, copy its folder +and modify your own copy. This way, your code won't +be overwritten when you upgrade YOURLS.
\ No newline at end of file diff --git a/user/plugins/hyphens-in-urls/plugin.php b/user/plugins/hyphens-in-urls/plugin.php new file mode 100644 index 0000000..3803412 --- /dev/null +++ b/user/plugins/hyphens-in-urls/plugin.php @@ -0,0 +1,19 @@ +<?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/ +*/ + +// No direct call +if( !defined( 'YOURLS_ABSPATH' ) ) die(); + +yourls_add_filter( 'get_shorturl_charset', 'ozh_hyphen_in_charset' ); +function ozh_hyphen_in_charset( $in ) { + return $in.'-'; +} + + diff --git a/user/plugins/index.html b/user/plugins/index.html new file mode 100644 index 0000000..cfce37c --- /dev/null +++ b/user/plugins/index.html @@ -0,0 +1,8 @@ +<!-- This page hides the content of the /pages/ directory and sends to YOURLS root --> +<html> +<head> +<meta http-equiv="refresh" content="0;url=../"></head> +<body> +YOURLS has nothing for you to see here. +</body> +</html>
\ No newline at end of file diff --git a/user/plugins/random-bg/README.md b/user/plugins/random-bg/README.md new file mode 100644 index 0000000..f3867fa --- /dev/null +++ b/user/plugins/random-bg/README.md @@ -0,0 +1,6 @@ +Random Background +================= +This is a sample plugin, for illustration purpose. +Don't modify this plugin. Instead, copy its folder +and modify your own copy. This way, your code won't +be overwritten when you upgrade YOURLS.
\ No newline at end of file diff --git a/user/plugins/random-bg/img/backup/bg_ants.png b/user/plugins/random-bg/img/backup/bg_ants.png Binary files differnew file mode 100644 index 0000000..1b736b0 --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_ants.png diff --git a/user/plugins/random-bg/img/backup/bg_boobs.png b/user/plugins/random-bg/img/backup/bg_boobs.png Binary files differnew file mode 100644 index 0000000..09d2dd4 --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_boobs.png diff --git a/user/plugins/random-bg/img/backup/bg_circles.png b/user/plugins/random-bg/img/backup/bg_circles.png Binary files differnew file mode 100644 index 0000000..27c2884 --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_circles.png diff --git a/user/plugins/random-bg/img/backup/bg_cross.png b/user/plugins/random-bg/img/backup/bg_cross.png Binary files differnew file mode 100644 index 0000000..3129cdd --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_cross.png diff --git a/user/plugins/random-bg/img/backup/bg_diag.png b/user/plugins/random-bg/img/backup/bg_diag.png Binary files differnew file mode 100644 index 0000000..f3c5fb7 --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_diag.png diff --git a/user/plugins/random-bg/img/backup/bg_fuzzy.png b/user/plugins/random-bg/img/backup/bg_fuzzy.png Binary files differnew file mode 100644 index 0000000..6850ca4 --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_fuzzy.png diff --git a/user/plugins/random-bg/img/backup/bg_fuzzy_bits.png b/user/plugins/random-bg/img/backup/bg_fuzzy_bits.png Binary files differnew file mode 100644 index 0000000..91ff805 --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_fuzzy_bits.png diff --git a/user/plugins/random-bg/img/backup/bg_life.png b/user/plugins/random-bg/img/backup/bg_life.png Binary files differnew file mode 100644 index 0000000..7d3e54f --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_life.png diff --git a/user/plugins/random-bg/img/backup/bg_yourls.png b/user/plugins/random-bg/img/backup/bg_yourls.png Binary files differnew file mode 100644 index 0000000..d96cde8 --- /dev/null +++ b/user/plugins/random-bg/img/backup/bg_yourls.png diff --git a/user/plugins/random-bg/img/bg_ants.gif b/user/plugins/random-bg/img/bg_ants.gif Binary files differnew file mode 100644 index 0000000..70b64c2 --- /dev/null +++ b/user/plugins/random-bg/img/bg_ants.gif diff --git a/user/plugins/random-bg/img/bg_boots.gif b/user/plugins/random-bg/img/bg_boots.gif Binary files differnew file mode 100644 index 0000000..2241ebc --- /dev/null +++ b/user/plugins/random-bg/img/bg_boots.gif diff --git a/user/plugins/random-bg/img/bg_circles.gif b/user/plugins/random-bg/img/bg_circles.gif Binary files differnew file mode 100644 index 0000000..ff57a16 --- /dev/null +++ b/user/plugins/random-bg/img/bg_circles.gif diff --git a/user/plugins/random-bg/img/bg_cross.gif b/user/plugins/random-bg/img/bg_cross.gif Binary files differnew file mode 100644 index 0000000..8cf785a --- /dev/null +++ b/user/plugins/random-bg/img/bg_cross.gif diff --git a/user/plugins/random-bg/img/bg_diag.gif b/user/plugins/random-bg/img/bg_diag.gif Binary files differnew file mode 100644 index 0000000..6996606 --- /dev/null +++ b/user/plugins/random-bg/img/bg_diag.gif diff --git a/user/plugins/random-bg/img/bg_fuzzy.gif b/user/plugins/random-bg/img/bg_fuzzy.gif Binary files differnew file mode 100644 index 0000000..a7709b2 --- /dev/null +++ b/user/plugins/random-bg/img/bg_fuzzy.gif diff --git a/user/plugins/random-bg/img/bg_fuzzy_bits.gif b/user/plugins/random-bg/img/bg_fuzzy_bits.gif Binary files differnew file mode 100644 index 0000000..e663faf --- /dev/null +++ b/user/plugins/random-bg/img/bg_fuzzy_bits.gif diff --git a/user/plugins/random-bg/img/bg_life.gif b/user/plugins/random-bg/img/bg_life.gif Binary files differnew file mode 100644 index 0000000..e32d025 --- /dev/null +++ b/user/plugins/random-bg/img/bg_life.gif diff --git a/user/plugins/random-bg/img/bg_yourls.gif b/user/plugins/random-bg/img/bg_yourls.gif Binary files differnew file mode 100644 index 0000000..107ecf4 --- /dev/null +++ b/user/plugins/random-bg/img/bg_yourls.gif diff --git a/user/plugins/random-bg/plugin.php b/user/plugins/random-bg/plugin.php new file mode 100644 index 0000000..c249637 --- /dev/null +++ b/user/plugins/random-bg/plugin.php @@ -0,0 +1,27 @@ +<?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( __DIR__.'/img/*gif' ); + $url = yourls_plugin_url( __DIR__ ); + $rnd = yourls_plugin_url( $bg[ mt_rand( 0, count( $bg ) - 1 ) ] ); + echo <<<CSS +<style type="text/css"> + body {background:#e3f3ff url($rnd); background-size: cover;} + </style> + +CSS; +} + diff --git a/user/plugins/random-shorturls/README.md b/user/plugins/random-shorturls/README.md new file mode 100644 index 0000000..78d49be --- /dev/null +++ b/user/plugins/random-shorturls/README.md @@ -0,0 +1,7 @@ +Random ShortURLs +================ + +This is a core plugin, bundled with YOURLS. +Don't modify this plugin. Instead, copy its folder +and modify your own copy. This way, your code won't +be overwritten when you upgrade YOURLS. diff --git a/user/plugins/random-shorturls/plugin.php b/user/plugins/random-shorturls/plugin.php new file mode 100644 index 0000000..4f381af --- /dev/null +++ b/user/plugins/random-shorturls/plugin.php @@ -0,0 +1,93 @@ +<?php +/* +Plugin Name: Random ShortURLs +Plugin URI: https://yourls.org/ +Description: Assign random keywords to shorturls, like bitly (sho.rt/hJudjK) +Version: 1.2 +Author: Ozh +Author URI: https://ozh.org/ +*/ + +/* Release History: +* +* 1.0 Initial release +* 1.1 Added: don't increment sequential keyword counter & save one SQL query +* Fixed: plugin now complies to character set defined in config.php +* 1.2 Adopted as YOURLS core plugin under a new name +* Now configured via YOURLS options instead of editing plugin file +*/ + +// No direct call +if( !defined( 'YOURLS_ABSPATH' ) ) die(); + +// Only register things if the old third-party plugin is not present +if( function_exists('ozh_random_keyword') ) { + yourls_add_notice( "<b>Random ShortURLs</b> plugin cannot function unless <b>Random Keywords</b> is removed first." ); +} else { + // filter registration happens conditionally, to avoid conflicts + // settings action is left out here, as it allows checking settings before deleting the old plugin + yourls_add_filter( 'random_keyword', 'ozh_random_shorturl' ); + yourls_add_filter( 'get_next_decimal', 'ozh_random_shorturl_next_decimal' ); +} + +// Generate a random keyword +function ozh_random_shorturl() { + $possible = yourls_get_shorturl_charset() ; + $str=''; + while( strlen( $str ) < yourls_get_option( 'random_shorturls_length', 5 ) ) { + $str .= substr($possible, rand( 0, strlen( $possible ) - 1 ), 1 ); + } + return $str; +} + +// Don't increment sequential keyword tracker +function ozh_random_shorturl_next_decimal( $next ) { + return ( $next - 1 ); +} + +// Plugin settings page etc. +yourls_add_action( 'plugins_loaded', 'ozh_random_shorturl_add_settings' ); +function ozh_random_shorturl_add_settings() { + yourls_register_plugin_page( 'random_shorturl_settings', 'Random ShortURLs Settings', 'ozh_random_shorturl_settings_page' ); +} + +function ozh_random_shorturl_settings_page() { + // Check if form was submitted + if( isset( $_POST['random_length'] ) ) { + // If so, verify nonce + yourls_verify_nonce( 'random_shorturl_settings' ); + // and process submission if nonce is valid + ozh_random_shorturl_settings_update(); + } + + $random_length = yourls_get_option('random_shorturls_length'); + $nonce = yourls_create_nonce( 'random_shorturl_settings' ); + + echo <<<HTML + <main> + <h2>Random ShortURLs Settings</h2> + <form method="post"> + <input type="hidden" name="nonce" value="$nonce" /> + <p> + <label>Random Keyword Length</label> + <input type="number" name="random_length" min="1" max="128" value="$random_length" /> + </p> + <p><input type="submit" value="Save" class="button" /></p> + </form> + </main> +HTML; +} + +function ozh_random_shorturl_settings_update() { + $random_length = $_POST['random_length']; + + if( $random_length ) { + if( is_numeric( $random_length ) ) { + yourls_update_option( 'random_shorturls_length', intval( $random_length ) ); + } else { + echo "Error: Length given was not a number."; + } + } else { + echo "Error: No length value given."; + } +} diff --git a/user/plugins/sample-page/README.md b/user/plugins/sample-page/README.md new file mode 100644 index 0000000..5bba6de --- /dev/null +++ b/user/plugins/sample-page/README.md @@ -0,0 +1,6 @@ +Sample Page +=========== +This is a sample plugin, for illustration purpose. +Don't modify this plugin. Instead, copy its folder +and modify your own copy. This way, your code won't +be overwritten when you upgrade YOURLS.
\ No newline at end of file diff --git a/user/plugins/sample-page/plugin.php b/user/plugins/sample-page/plugin.php new file mode 100644 index 0000000..717961d --- /dev/null +++ b/user/plugins/sample-page/plugin.php @@ -0,0 +1,63 @@ +<?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/ +*/ + +// No direct call +if( !defined( 'YOURLS_ABSPATH' ) ) die(); + +// 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'] ) ) { + // Check nonce + yourls_verify_nonce( 'sample_page' ); + + // Process form + ozh_yourls_samplepage_update_option(); + } + + // Get value from database + $test_option = yourls_get_option( 'test_option' ); + + // Create nonce + $nonce = yourls_create_nonce( 'sample_page' ); + + echo <<<HTML + <h2>Sample Plugin Administration Page</h2> + <p>This plugin stores an integer in the option database</p> + <form method="post"> + <input type="hidden" name="nonce" value="$nonce" /> + <p><label for="test_option">Enter an integer</label> <input type="text" id="test_option" name="test_option" value="$test_option" /></p> + <p><input type="submit" value="Update value" /></p> + </form> + +HTML; +} + +// Update option in database +function ozh_yourls_samplepage_update_option() { + $in = $_POST['test_option']; + + if( $in ) { + // Validate test_option. ALWAYS validate and sanitize user input. + // Here, we want an integer + $in = intval( $in); + + // Update value in database + yourls_update_option( 'test_option', $in ); + } +}
\ No newline at end of file diff --git a/user/plugins/sample-plugin/README.md b/user/plugins/sample-plugin/README.md new file mode 100644 index 0000000..720c698 --- /dev/null +++ b/user/plugins/sample-plugin/README.md @@ -0,0 +1,6 @@ +Sample Plugin +============= +This is a sample plugin, for illustration purpose. +Don't modify this plugin. Instead, copy its folder +and modify your own copy. This way, your code won't +be overwritten when you upgrade YOURLS.
\ No newline at end of file diff --git a/user/plugins/sample-plugin/plugin.php b/user/plugins/sample-plugin/plugin.php new file mode 100644 index 0000000..345e5ee --- /dev/null +++ b/user/plugins/sample-plugin/plugin.php @@ -0,0 +1,61 @@ +<?php +/* +Plugin Name: Sample Plugin +Plugin URI: http://yourls.org/ +Description: Sample plugin to illustrate how actions and filters work. Read its source. Refer to the <a href="http://yourls.org/pluginapi">Plugin API documentation</a> for more details. +Version: 0.1 +Author: Ozh +Author URI: http://ozh.org/ +*/ + +// No direct call +if( !defined( 'YOURLS_ABSPATH' ) ) die(); + +/* 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="https://cyne.cf">Main Site</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 . ' -- the sample plugin is activated'; + return $value; // a filter *always* has to return a value +} +/* And that's it. Activate the plugin and notice how the page title changes */ + diff --git a/user/plugins/sample-toolbar/README.md b/user/plugins/sample-toolbar/README.md new file mode 100644 index 0000000..a7bae40 --- /dev/null +++ b/user/plugins/sample-toolbar/README.md @@ -0,0 +1,6 @@ +Sample Toolbar +============== +This is a sample plugin, for illustration purpose. +Don't modify this plugin. Instead, copy its folder +and modify your own copy. This way, your code won't +be overwritten when you upgrade YOURLS.
\ No newline at end of file diff --git a/user/plugins/sample-toolbar/css/toolbar.css b/user/plugins/sample-toolbar/css/toolbar.css new file mode 100644 index 0000000..59c7607 --- /dev/null +++ b/user/plugins/sample-toolbar/css/toolbar.css @@ -0,0 +1,79 @@ +body { + margin:0; + overflow:hidden; + background-color:#fff; + font-size:12px; + font-family: Verdana, Arial; + padding:35px 0 0; +} + +#yourls-frame { + width: 100%; + height:100%; + z-index: 1; +} + +#yourls-bar { + font-family: Verdana, Arial; + font-size: 12px; + position:absolute; + top:0; + height:35px; + width:100%; + background:#e3f3ff url(../img/toolbar_bg.png) repeat-x bottom center; + color:#2A85B3; + -moz-box-shadow: 0 1px 5px rgba(0,0,0,0.5); + -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.5); + z-index: 900000; +} + +#yourls-bar a { + text-decoration:none; + color:#2A85B3; +} + +#yourls-bar a:hover { + text-decoration:underline; +} + +#yourls-about, #yourls-topsy, #yourls-delicious, #yourls-selfclose { + margin-left:10px; + float:left; + display:block; + top:5px; + position:relative; +} + +#yourls-about a { + background:transparent url(../img/favicon.gif) center left no-repeat; + padding-left:20px; + color:inherit; + font-weight:bold; +} + +#yourls-topsy { + width:300px; +} + +#yourls-selfclose { + float:right; + margin-right:10px; +} + +#yourls-once { + display:block; + text-indent:-9999px; + background:transparent url(../img/close_button.gif) center center no-repeat; + width:20px; + height:20px; + float:left; +} + +#yourls-always { + display:none; + text-indent:-9999px; + background:transparent url(../img/close_button_red.gif) center center no-repeat; + width:20px; + height:20px; + float:left; +} diff --git a/user/plugins/sample-toolbar/img/close_button.gif b/user/plugins/sample-toolbar/img/close_button.gif Binary files differnew file mode 100644 index 0000000..95d286c --- /dev/null +++ b/user/plugins/sample-toolbar/img/close_button.gif diff --git a/user/plugins/sample-toolbar/img/close_button_red.gif b/user/plugins/sample-toolbar/img/close_button_red.gif Binary files differnew file mode 100644 index 0000000..b443f12 --- /dev/null +++ b/user/plugins/sample-toolbar/img/close_button_red.gif diff --git a/user/plugins/sample-toolbar/img/favicon.gif b/user/plugins/sample-toolbar/img/favicon.gif Binary files differnew file mode 100644 index 0000000..8681802 --- /dev/null +++ b/user/plugins/sample-toolbar/img/favicon.gif diff --git a/user/plugins/sample-toolbar/img/toolbar_bg.png b/user/plugins/sample-toolbar/img/toolbar_bg.png Binary files differnew file mode 100644 index 0000000..0fb3cec --- /dev/null +++ b/user/plugins/sample-toolbar/img/toolbar_bg.png diff --git a/user/plugins/sample-toolbar/js/toolbar.js b/user/plugins/sample-toolbar/js/toolbar.js new file mode 100644 index 0000000..bfa249a --- /dev/null +++ b/user/plugins/sample-toolbar/js/toolbar.js @@ -0,0 +1,22 @@ + +// If javascript is enabled, display the button +document.getElementById('yourls-always').style.display = 'block'; + +// When button clicked, store a cookie that says the user doesn't want a toolbar +document.getElementById('yourls-always').onclick = yourls_cookie_no_toolbar_please; +function yourls_cookie_no_toolbar_please() { + var exdate=new Date(); + exdate.setDate( exdate.getDate()+365 ); // store 365 days + document.cookie = "yourls_no_toolbar=1;expires="+exdate.toUTCString() ; +} + +// Get the number of delicious bookmarks +function yourls_get_books(json) { + if( json.length ) { + var books = json[0].total_posts.toString(); + if( books ) { + document.getElementById('yourls-delicious-link').innerHTML = ' <b>'+books+'</b> bookmarks'; + } + } +} + diff --git a/user/plugins/sample-toolbar/plugin.php b/user/plugins/sample-toolbar/plugin.php new file mode 100644 index 0000000..2467bb9 --- /dev/null +++ b/user/plugins/sample-toolbar/plugin.php @@ -0,0 +1,126 @@ +<?php +/* +Plugin Name: YOURLS Toolbar +Plugin URI: http://yourls.org/ +Description: Add a social toolbar to your redirected short URLs. Fork this plugin if you want to make your own toolbar. +Version: 1.0 +Author: Ozh +Author URI: http://ozh.org/ +Disclaimer: Toolbars ruin the user experience. Be warned. +*/ + +// No direct call +if( !defined( 'YOURLS_ABSPATH' ) ) die(); + +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 + if( $pagetitle == '' ) { + $pagetitle = yourls_get_remote_title( $url ); + yourls_edit_link_title( $ozh_toolbar['keyword'], $pagetitle ); + } + $_pagetitle = htmlentities( yourls_get_remote_title( $url ) ); + + $www = YOURLS_SITE; + $ver = YOURLS_VERSION; + $md5 = md5( $url ); + $sql = yourls_get_num_queries(); + + // When was the link created (in days) + $diff = abs( time() - strtotime( yourls_get_keyword_timestamp( $ozh_toolbar['keyword'] ) ) ); + $days = floor( $diff / (60*60*24) ); + if( $days == 0 ) { + $created = 'today'; + } else { + $created = $days . ' ' . yourls_n( 'day', 'days', $days ) . ' ago'; + } + + // How many hits on the page + $hits = 1 + yourls_get_keyword_clicks( $ozh_toolbar['keyword'] ); + $hits = $hits . ' ' . yourls_n( 'view', 'views', $hits ); + + // Plugin URL (no URL is hardcoded) + $pluginurl = YOURLS_PLUGINURL . '/'.yourls_plugin_basename( __DIR__ ); + + // All set. Draw the toolbar itself. + echo <<<PAGE +<html> +<head> + <title>$pagetitle — YOURLS</title> + <link rel="icon" type="image/gif" href="$www/images/favicon.gif" /> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <meta http-equiv="X-UA-Compatible" content="IE-9"/> + <meta name="generator" content="YOURLS v$ver" /> + <meta name="ROBOTS" content="NOINDEX, FOLLOW" /> + <link rel="stylesheet" href="$pluginurl/css/toolbar.css" type="text/css" media="all" /> +</head> +<body> +<div id="yourls-bar"> + <div id="yourls-about"> + Short link powered by <a href="http://yourls.org/">YOURLS</a> and created $created. $hits. + <!-- $sql queries --> + </div> + + <div id="yourls-delicious"> + <img src="http://static.delicious.com/img/delicious.small.gif" height="10" width="10" alt="Delicious" /> + <a id="yourls-delicious-link" title="Bookmark on delicious" href="http://delicious.com/save" onclick="window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"> Bookmark on Delicious</a> + </div> + + <script type="text/javascript" id="topsy_global_settings"> + var topsy_theme = "light-blue"; + var topsy_nick = " "; + var topsy_style = "small"; + var topsy_order = "count,retweet,badge"; + </script> + <div id="yourls-topsy" class="topsy_widget_data"> + <!--{ + "url": "$www/{$ozh_toolbar['keyword']}", + "title": "$_pagetitle", + }--> + </div> + + <div id="yourls-selfclose"> + <a id="yourls-once" href="$url" title="Close this toolbar">close</a> + <a id="yourls-always" href="$url" title="Never show me this toolbar again">close</a> + + </div> +</div> + +<iframe id="yourls-frame" frameborder="0" noresize="noresize" src="$url" name="yourlsFrame"></iframe> +<script type="text/javascript" src="$pluginurl/js/toolbar.js"></script> +<script type="text/javascript" src="http://cdn.topsy.com/topsy.js?init=topsyWidgetCreator"></script> +<script type="text/javascript" src="http://feeds.delicious.com/v2/json/urlinfo/$md5?callback=yourls_get_books"></script> +</body> +</html> +PAGE; + + // Don't forget to die, to interrupt the flow of normal events (ie redirecting to long URL) + die(); +}
\ No newline at end of file |