Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/YOURLS/YOURLS.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
authorozhozh <ozhozh@12232710-3e20-11de-b438-597f59cd7555>2010-07-02 00:48:59 +0400
committerozhozh <ozhozh@12232710-3e20-11de-b438-597f59cd7555>2010-07-02 00:48:59 +0400
commitbd5916789cbc2c6218d3e336730cb347288e0f5a (patch)
tree01cb7b8adcc5db06c165f4d7b712db51d3378900 /user
parent732d7668c1a5370b4c17a582d3e8a8b23080af86 (diff)
Core sample plugin: administration page
git-svn-id: http://yourls.googlecode.com/svn/trunk@451 12232710-3e20-11de-b438-597f59cd7555
Diffstat (limited to 'user')
-rw-r--r--user/plugins/sample-page/plugin.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/user/plugins/sample-page/plugin.php b/user/plugins/sample-page/plugin.php
new file mode 100644
index 00000000..1001a89c
--- /dev/null
+++ b/user/plugins/sample-page/plugin.php
@@ -0,0 +1,50 @@
+<?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
+ <h2>Sample Plugin Administration Page</h2>
+ <p>This plugin stores an integer in the option database</p>
+ <form method="post">
+ <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