]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - user/plugins/sample-page/plugin.php
Prevent full path disclosure in case of direct calls. Fixes issue 646.
[Github/YOURLS.git] / user / plugins / sample-page / plugin.php
1 <?php\r
2 /*\r
3 Plugin Name: Sample Admin Page\r
4 Plugin URI: http://yourls.org/\r
5 Description: A example of a plugin administration page to save user defined option\r
6 Version: 1.0\r
7 Author: Ozh\r
8 Author URI: http://ozh.org/\r
9 */\r
10 \r
11 // No direct call\r
12 if( !defined( 'YOURLS_ABSPATH' ) ) die();\r
13 \r
14 // Register our plugin admin page\r
15 yourls_add_action( 'plugins_loaded', 'ozh_yourls_samplepage_add_page' );\r
16 function ozh_yourls_samplepage_add_page() {\r
17         yourls_register_plugin_page( 'sample_page', 'Sample Admin Page', 'ozh_yourls_samplepage_do_page' );\r
18         // parameters: page slug, page title, and function that will display the page itself\r
19 }\r
20 \r
21 // Display admin page\r
22 function ozh_yourls_samplepage_do_page() {\r
23 \r
24         // Check if a form was submitted\r
25         if( isset( $_POST['test_option'] ) )\r
26                 ozh_yourls_samplepage_update_option();\r
27 \r
28         // Get value from database\r
29         $test_option = yourls_get_option( 'test_option' );\r
30 \r
31         echo <<<HTML\r
32                 <h2>Sample Plugin Administration Page</h2>\r
33                 <p>This plugin stores an integer in the option database</p>\r
34                 <form method="post">\r
35                 <p><label for="test_option">Enter an integer</label> <input type="text" id="test_option" name="test_option" value="$test_option" /></p>\r
36                 <p><input type="submit" value="Update value" /></p>\r
37                 </form>\r
38 HTML;\r
39 }\r
40 \r
41 // Update option in database\r
42 function ozh_yourls_samplepage_update_option() {\r
43         $in = $_POST['test_option'];\r
44         \r
45         if( $in ) {\r
46                 // Validate test_option. ALWAYS validate and sanitize user input.\r
47                 // Here, we want an integer\r
48                 $in = intval( $in);\r
49                 \r
50                 // Update value in database\r
51                 yourls_update_option( 'test_option', $in );\r
52         }\r
53 }