##
##
##           Mod title:  Plugile
##
##         Mod version:  1.2
##      Works on PunBB:  1.2.x
##        Release date:  28/03/2007
##            Date 1.1:  17/03/2007
##            Date 1.0:  02/03/2007
##
##              Author:  BN [bnmaster@la-bnbox.info] - [http://la-bnbox.info]
##
##         Description:  This mod had plugin system in profile page.
##                       It's like admin plugin but for members.
##
##      Affected files:  include/functions.php
##                       profile.php
##
##          Affects DB:  non
##
##
##          DISCLAIMER:  Please note that "mods" are not officially supported by
##                       PunBB. Installation of this modification is done at your
##                       own risk. Backup your forum database and any and all
##                       applicable files before proceeding.
##

#
#---------[ 0. UPDATE ]-------------------------------------
#

To update the 1.1 version, follow the current points 1,4,5,6,11,12,13,14


#
#---------[ 1. UPGRADE ]-------------------------------------
#

lang/LANG/plugile.php in lang/LANG
upload/plugins/AP_Plugile.php in /plugins/
upload/plugins/UP_Exemple.php in /plugins/
upload/plugins/UPP_Exemple.php in /plugins/ 
(UP_Exemple and UPP_Exemple are just examples, delete them after test)

#
#---------[ 2. OPEN ]-------------------------------------------------------
#

include/functions.php


#
#---------[ 3. FIND ]-----------------------------------------------------
#

<div id="profile" class="block2col">
	<div class="blockmenu">
		<h2><span><?php echo $lang_profile['Profile menu'] ?></span></h2>
		<div class="box">
			<div class="inbox">
				<ul>
					<li<?php if ($page == 'essentials') echo ' class="isactive"'; ?>><a href="profile.php?section=essentials&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section essentials'] ?></a></li>
					<li<?php if ($page == 'personal') echo ' class="isactive"'; ?>><a href="profile.php?section=personal&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section personal'] ?></a></li>
					<li<?php if ($page == 'messaging') echo ' class="isactive"'; ?>><a href="profile.php?section=messaging&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section messaging'] ?></a></li>
					<li<?php if ($page == 'personality') echo ' class="isactive"'; ?>><a href="profile.php?section=personality&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section personality'] ?></a></li>
					<li<?php if ($page == 'display') echo ' class="isactive"'; ?>><a href="profile.php?section=display&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section display'] ?></a></li>
					<li<?php if ($page == 'privacy') echo ' class="isactive"'; ?>><a href="profile.php?section=privacy&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section privacy'] ?></a></li>
					<?php if ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '1')): ?>					<li<?php if ($page == 'admin') echo ' class="isactive"'; ?>><a href="profile.php?section=admin&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section admin'] ?></a></li>
					<?php endif; ?>

#
#---------[ 4. AFTER ADD ]-----------------------------------------
#

					<?php
					// See if there are any plugins
					$plugins = array();
					$d = dir(PUN_ROOT.'plugins');
					while (($entry = $d->read()) !== false)
					{
						$prefix = substr($entry, 0, strpos($entry, '_'));
						$suffix = substr($entry, strlen($entry) - 4);

						// UP <=> User Plugin (all people can see it) - UPP <=> User Private Plugin (just the member et the admins can see it)
						if ($suffix == '.php' && ($prefix == 'UP' || $prefix == 'UPP'))
							$plugins[] = array(substr(substr($entry, strpos($entry, '_') + 1), 0, -4), $entry);
					}
					$d->close();

					// Did we find any plugins?
					if (!empty($plugins))
					{
						if($pun_config['o_plugile_menu'] == '1')
						{
										?>
									</ul>
								</div>
							</div>
							

							<h2><span><?php echo $pun_config['o_plugile'] ?></span></h2>
							<div class="box">
								<div class="inbox">
									<ul>
										<?php
						}
					while (list(, $cur_plugin) = @each($plugins))
						echo "\t\t\t\t\t".'<li'.(($page == $cur_plugin[1]) ? ' class="isactive"' : '').'><a href="profile.php?plugin='.$cur_plugin[1].'&amp;id='.$id.'">'.str_replace('_', ' ', $cur_plugin[0]).'</a></li>'."\n";
					?>
				</ul>
			</div>
		</div>
	<?php
	}
	?>

#
#---------[ 5. DELETE ]-------------------------------------------------------
#

				?>
				</ul>
			</div>
		</div>
	<?php


#
#---------[ 6. OPEN ]-------------------------------------------------------
#

profile.php


#
#---------[ 7. FIND ]-----------------------------------
#

	<div class="inform">
				<fieldset>
				<legend><?php echo $lang_profile['User activity'] ?></legend>
					<div class="infldset">
						<dl>
<?php if ($posts_field != ''): ?>							<dt><?php echo $lang_common['Posts'] ?>: </dt>
							<dd><?php echo $posts_field ?></dd>
<?php endif; ?>							<dt><?php echo $lang_common['Last post'] ?>: </dt>
							<dd><?php echo $last_post ?></dd>
							<dt><?php echo $lang_common['Registered'] ?>: </dt>
							<dd><?php echo format_time($user['registered'], true) ?></dd>
						</dl>
						<div class="clearer"></div>
					</div>
				</fieldset>
			</div>


#
#---------[ 8. AFTER ADD ]------------------------------------------
#

			<?php
			// See if there are any plugiles
			$plugins = array();
			$d = dir(PUN_ROOT.'plugins');
			while (($entry = $d->read()) !== false)
			{
				$prefix = substr($entry, 0, strpos($entry, '_'));
				$suffix = substr($entry, strlen($entry) - 4);

				if ($suffix == '.php' && $prefix == 'UP')
					$plugins[] = array(substr(substr($entry, strpos($entry, '_') + 1), 0, -4), $entry);
			}
			$d->close();

			// Did we find any plugins?
			if (!empty($plugins))
			{
				while (list(, $cur_plugin) = @each($plugins))
				{
					// Make sure the file actually exists
					if (!file_exists(PUN_ROOT.'plugins/'.$cur_plugin[1]))
						message('There is no plugin \''.$cur_plugin[0].'\' in /plugin.');
					// Construct REQUEST_URI if it isn't set
					if (!isset($_SERVER['REQUEST_URI']))
						$_SERVER['REQUEST_URI'] = (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '').'?'.(isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '');
					?>
					<div class="inform">
						<fieldset>
						<legend><?php echo str_replace('_', ' ', $cur_plugin[0]); ?></legend>
							<div class="infldset">
							<?php
							include PUN_ROOT.'plugins/'.$cur_plugin[1];
							?>
							<div class="clearer"></div>
							</div>
						</fieldset>
					</div>
					<?php
					if (!defined('PUN_PLUGIN_LOADED'))
						message('Plugile loading \''.$cur_plugin[0].'\' had a problem.');
				}
			}
			?>

			
#
#---------[ 9. FIND ]-----------------------------------
#

if (!$section || $section == 'essentials')


#
#---------[ 10. REPLACE BY ]------------------------------------------
#

if ((!$section AND !$_GET['plugin']) || $section == 'essentials')


#
#---------[ 11. FIND (at the end) ]------------------------------------------------
#

?>
	<div class="clearer"></div>
</div>
<?php

	require PUN_ROOT.'footer.php';
}


#
#---------[ 12. BEFORE ADD ]-------------------------------------
#

	elseif(!isset($section) AND isset($_GET['plugin']))
	{
		// The plugin to load should be supplied via GET
		$plugin = isset($_GET['plugin']) ? $_GET['plugin'] : '';
		if (!preg_match('/^UP?P_(\w*?)\.php$/i', $plugin))
					message($lang_common['Bad request']);

		// UP_ == User plugin
		$prefix = substr($plugin, 0, strpos($plugin, '_'));

		// Make sure the file actually exists
		if (!file_exists(PUN_ROOT.'plugins/'.$plugin))
					message('There is no plugile \''.$plugin.'\' in /plugin.');

		// Construct REQUEST_URI if it isn't set
		if (!isset($_SERVER['REQUEST_URI']))
			$_SERVER['REQUEST_URI'] = (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '').'?'.(isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '');

		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Profil / '.$plugin;
		require PUN_ROOT.'header.php';
		
		// Attempt to load the plugin. We don't use @ here to supress error messages,
		// because if we did and a parse error occurred in the plugin, we would only
		// get the "blank page of death".
		include PUN_ROOT.'plugins/'.$plugin;
		if (!defined('PUN_PLUGIN_LOADED'))
			message('Plugile loading \''.$plugin.'\' had a problem.');
	}


#
#---------[ 13. SAVE/UPLOAD ]----------------------------
#

include/functions.php
profile.php


#
#---------[ 14. END AND CONFIGURATION ]----------------------------------------------
#

To end the installation, you must go in administration plugin file. You can modify 
the look too.
To create a new plugile: read example plugin UP_Exemple.php
