punbb/plugins/AMP_Example.php
author Dan
Thu, 12 Jul 2007 01:04:01 -0400
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
permissions -rw-r--r--
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
##  A few notes of interest for aspiring plugin authors:
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    29
##  1. If you want to display a message via the message() function, you
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    30
##     must do so before calling generate_admin_menu($plugin).
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    31
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    32
##  2. Plugins are loaded by admin_loader.php and must not be
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    33
##     terminated (e.g. by calling exit()). After the plugin script has
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
##     finished, the loader script displays the footer, so don't worry
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
##     about that. Please note that terminating a plugin by calling
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    36
##     message() or pun_redirect() is fine though.
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    37
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    38
##  3. The action attribute of any and all <form> tags and the target
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    39
##     URL for the pun_redirect() function must be set to the value of
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
##     $_SERVER['REQUEST_URI']. This URL can however be extended to
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    41
##     include extra variables (like the addition of &amp;foo=bar in
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    42
##     the form of this example plugin).
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    43
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
##  4. If your plugin is for administrators only, the filename must
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
##     have the prefix "AP_". If it is for both administrators and
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    46
##     moderators, use the prefix "AMP_". This example plugin has the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
##     prefix "AMP_" and is therefore available for both admins and
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    48
##     moderators in the navigation menu.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    50
##  5. Use _ instead of spaces in the file name.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    51
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    52
##  6. Since plugin scripts are included from the PunBB script
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    53
##     admin_loader.php, you have access to all PunBB functions and
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    54
##     global variables (e.g. $pun_db, $pun_config, $pun_user etc).
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    55
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    56
##  7. Do your best to keep the look and feel of your plugins' user
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    57
##     interface similar to the rest of the admin scripts. Feel free to
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
##     borrow markup and code from the admin scripts to use in your
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
##     plugins. If you create your own styles they need to be added to
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
##     the "base_admin" style sheet.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
##  8. Plugins must be released under the GNU General Public License or
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
##     a GPL compatible license. Copy the GPL preamble at the top of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
##     this file into your plugin script and alter the copyright notice
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
##     to refrect the author of the plugin (i.e. you).
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
##
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
// Make sure no one attempts to run this script "directly"
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
if (!defined('PUN'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
	exit;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
// Tell admin_loader.php that this is indeed a plugin and that it is loaded
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
define('PUN_PLUGIN_LOADED', 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
// The rest is up to you!
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
// If the "Show text" button was clicked
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    82
if (isset($_POST['show_text']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    83
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
	// Make sure something something was entered
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
	if (trim($_POST['text_to_show']) == '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
		message('You didn\'t enter anything!');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
	// Display the admin navigation menu
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
	generate_admin_menu($plugin);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    91
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    92
	<div class="block">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
		<h2><span>Example plugin</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    94
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    95
			<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    96
				<p>You said "<?php echo pun_htmlspecialchars($_POST['text_to_show']) ?>". Great stuff.</p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
				<p><a href="javascript: history.go(-1)">Go back</a></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
			</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
else	// If not, we show the "Show text" form
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   105
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   106
	// Display the admin navigation menu
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
	generate_admin_menu($plugin);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
	<div id="exampleplugin" class="blockform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
		<h2><span>Example plugin</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   112
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
			<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
				<p>This plugin doesn't do anything useful. Hence the name "Example".</p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
				<p>This would be a good spot to talk a little about your plugin. Describe what it does and how it should be used. Be brief, but informative.</p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
			</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
		<h2 class="block2"><span>An example form</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   120
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
			<form id="example" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>&amp;foo=bar">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
				<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
					<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
						<legend>Enter a piece of text and hit "Show text"!</legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
						<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
						<table class="aligntop" cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
							<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
								<th scope="row">Text to show<div><input type="submit" name="show_text" value="Show text" tabindex="2" /></div></th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   129
								<td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
									<input type="text" name="text_to_show" size="25" tabindex="1" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   131
									<span>The text you want to display.</span>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   132
								</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   133
							</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   134
						</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   135
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   136
					</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   137
				</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   138
			</form>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   139
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   140
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   141
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   142
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   143
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   144
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   145
// Note that the script just ends here. The footer will be included by admin_loader.php.