gaim/www

346b3deef05b
Storing the new plugins code in a safe branch where nothing can get it.
<?php
require "base.inc.php";
function build_plugin_list_nav()
{
global $session, $users, $PHP_SELF;
global $action, $keywords;
if ($action == "listall" || $action == "") {
$buffer = "<b>All Plugins</b>";
}
else {
$buffer = "<a href=\"" . $session->localUrl($PHP_SELF) .
"?action=listall\">All Plugins</a>";
}
$buffer .= " &nbsp;&nbsp;";
if ($action == "listpopular")
$buffer .= "<b>Popular Plugins</b>";
else
$buffer .= "<a href=\"" . $session->localUrl($PHP_SELF) .
"?action=listpopular\">Popular Plugins</a>";
$buffer .= " &nbsp;";
$buffer .= "<b>&middot;</b> &nbsp;";
if ($action == "search" && !isset($keywords))
$buffer .= "<b>Search</b>";
else
$buffer .= "<a href=\"plugins.php?action=search\">Search</a>";
$buffer .= " &nbsp;";
$buffer .= "<b>&middot;</b> &nbsp;";
if ($users->logged_in())
{
if ($action == "addplugin")
$buffer .= "<b>Add Plugin</b>";
else
$buffer .= "<a href=\"" . $session->localUrl($PHP_SELF) .
"?action=addplugin\">Add Plugin</a>";
$buffer .= " &nbsp;";
$buffer .= "<b>&middot;</b> &nbsp;";
$buffer .= "<a href=\"" . $session->localUrl("logout.php") .
"\">Log Out</a>";
}
else
{
$buffer .= "<a href=\"" . $session->localUrl("login.php") .
"\">Log In</a> &nbsp;&nbsp;";
$buffer .= "<a href=\"" . $session->localUrl("register.php") .
"\">Register Account</a>";
}
return $buffer;
}
function display_unknown_plugin()
{
setup_site("Unknown Plugin");
start_section("Unknown Plugin", build_plugin_list_nav(), false);
?>
<p>
The plugin specified does not exist in the database.
</p>
<?php
end_section();
site_shutdown();
}
function display_permission_denied($type)
{
setup_site("Permission Denied");
start_section("Permission Denied", build_plugin_list_nav(), false);
?>
<p>
You do not have permission to <?php print $type ?> this plugin. This incident
has been reported to the FBI.
</p>
<?php
end_section();
site_shutdown();
}
function display_add_plugin()
{
global $users, $plugins;
global $name, $version, $url, $homepage, $filesize, $brief;
global $description;
global $step;
$missinginfo = false;
if ($step == 2)
{
$requiredinfo = array(
"name", "version", "url", "filesize", "brief", "description"
);
for ($i = 0; $i < count($requiredinfo); $i++) {
if (empty($GLOBALS[$requiredinfo[$i]])) {
$GLOBALS[$requiredinfo[$i]] = -1;
$missinginfo = true;
}
}
if (!is_numeric($filesize))
{
$missinginfo = true;
}
if ($missinginfo == false)
{
$plugins->add_plugin($users->get_active_user_id(),
$name, $version, $url, $homepage, $filesize, $brief,
$description);
header("Location: plugins.php");
exit;
}
}
setup_site("Add Plugin");
start_section("Add Plugin", build_plugin_list_nav(), false);
if ($missinginfo):
if (!is_numeric($filesize)):
?>
<b>Error:</b> The file size field must be an integer!
<?php
endif;
?>
<p>
You must enter in all the required information. Please fill in the information
in <font color="#FF0000">red</font>, as well as your password again, to
register.
</p>
<?php
endif;
?>
<p>
To add a plugin to the database, please fill out the form below.
</p>
<p>
<b>Note:</b> If you don't want to host your own plugin, you can add it to the
<a href="http://sourceforge.net/tracker/?atid=390395&group_id=235&func=browse">tracker</a>
on SourceForge, and use the resulting URL in the Download URL field below.
</p>
<p>
Please note that all fields marked with a red asterisk
(<font color="#FF0000">*</font>) must be filled in!
</p>
<br />
<form method="post" action="plugins.php">
<input type="hidden" name="action" value="addplugin" />
<input type="hidden" name="step" value="2" />
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<?php
form_item("Name", "name", $name, true, 16, 128);
form_item("Version", "version", $version, true, 16, 16);
form_item("Brief Description", "brief", $brief, true, 30, 255);
form_item("Download URL", "url", $url, true, 30, 255);
form_item("Home Page", "homepage", $homepage, false, 30, 255);
form_item("File Size", "filesize", $filesize, true, 15, 255);
print "<tr><td align=\"right\"><small>(Specify in bytes)</small></td>";
print "<td>&nbsp;</td></tr>\n";
if ($description == -1)
$description = "";
?>
<tr>
<td colspan="2">
<br />
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><font color="#FF0000">*</font><?php start_font(); ?><b>Description:</b><br />
<textarea rows="10" cols="50" name="description"><?php print $description; ?></textarea></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<br />
<input type="submit" value="Submit" />&nbsp;&nbsp;
<input type="reset" />
</td>
</tr>
</table>
</form>
<?php
end_section();
}
function show_plugin()
{
global $plugins, $users, $session;
global $id;
$plugins->update_view_count($id);
$plugin = $plugins->get_plugin($id);
setup_site($plugin["NAME"] . " v" . $plugin["VERSION"]);
start_section($plugin["NAME"] . " v" . $plugin["VERSION"],
build_plugin_list_nav(), false);
?>
<table border="0" width="100%">
<tr>
<td width="100%" align="center" valign="top">
<table width="100%" border="0">
<tr>
<td width="50%" align="right"><b>Name:</b>&nbsp;</td>
<td width="50%"><?php print $plugin["NAME"] ?></td>
</tr>
<tr>
<td align="right"><b>Version:</b>&nbsp;</td>
<td><?php print $plugin["VERSION"] ?></td>
</tr>
<tr>
<td align="right" valign="top"><b>Brief Description:</b>&nbsp;</td>
<td><?php print $plugin["BRIEF"] ?></td>
</tr>
<tr>
<td align="right"><b>Author:</b>&nbsp;</td>
<td><?php print $plugin["USERNAME"] ?></td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr>
<td align="right"><b>Created:</b>&nbsp;</td>
<td><?php print $plugin["CREATED"] ?></td>
</tr>
<tr>
<td align="right"><b>Last Updated:</b>&nbsp;</td>
<td><?php print $plugin["UPDATED"] ?></td>
</tr>
</table>
<br />
<table border="0" awidth="400" align="center">
<tr><td><b>Description:</b></td></tr>
<tr><td><?php print $plugin["DESCRIPTION"] ?></td></tr>
</table>
</td>
<td nowrap="nowrap" valign="top">
<?php if ($plugin["USER_ID"] == $users->get_active_user_id()): ?>
<table border="0" width="100%">
<tr>
<td><a href="plugins.php?action=editplugin&id=<?php print $id; ?>">Edit Plugin</a></td>
</tr>
<tr>
<td><a href="plugins.php?action=deleteplugin&id=<?php print $id; ?>">Delete Plugin</a></td>
</tr>
</table>
<br />
<?php endif; ?>
<table border="0" width="100%">
<?php if ($plugin["HOMEPAGE"] != ""): ?>
<tr>
<td nowrap="nowrap"><a href="<?php print $plugin["HOMEPAGE"] ?>">Home Page</a></td>
</tr>
<?php endif; ?>
<tr>
<td nowrap="nowrap"><a href="<?php print $PHP_SELF ?>?action=download&id=<?php print $id ?>">Download</a></td>
</tr>
</table>
<br />
<table border="0" width="100%">
<tr>
<td nowrap="nowrap"><b>File Size:</b> <?php print $plugin["FILESIZE"] ?> bytes</td>
</tr>
<tr>
<td nowrap="nowrap"><b>Page Views:</b> <?php print $plugin["VIEW_COUNT"] ?></td>
</tr>
<tr>
<td nowrap="nowrap"><b>Download Count:</b> <?php print $plugin["DOWNLOAD_COUNT"] ?></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
end_section();
}
function download_plugin()
{
global $plugins, $users;
global $id;
$plugin = $plugins->get_plugin($id);
if ($plugin == NULL)
display_unknown_plugin();
else
{
$plugins->update_download_count($id);
header("Location: " . $plugin["URL"]);
exit;
}
}
function display_plugins()
{
global $plugins, $action, $start; $limit;
if (!isset($start))
$start = 0;
if (!isset($limit))
$limit = 25;
if ($action == "listpopular")
{
$plugin_list = $plugins->get_popular_plugins();
$title = "Popular Plugins";
}
else
{
$plugin_list = $plugins->get_all_plugins($start, $limit);
$title = "Plugins";
}
$plugin_count = $plugins->get_plugin_count();
setup_site($title);
start_section($title, build_plugin_list_nav(), false);
if ($plugin_list == NULL)
{
?>
<p><i>There are no plugins!</i></p>
<?php
}
else
{
?>
<table border="0" cellspacing="0" cellpadding="1" width="100%">
<tr>
<td bgcolor="#000000">
<table border="0" cellspacing="0" cellpadding="3" width="100%">
<tr>
<td width="20%" bgcolor="#f7c871"><b>Name</b></td>
<td width="50%" bgcolor="#f7c871"><b>Brief Description</b></td>
<td width="10%" bgcolor="#f7c871"><b>Version</b></td>
<td width="10%" bgcolor="#f7c871"><b>Author</b></td>
<td width="10%" bgcolor="#f7c871"><b>Downloads</b></td>
</tr>
<?php
$oddrow = true;
while (list($id, $plugin) = each($plugin_list))
{
if ($oddrow)
$bgatts = "bgcolor=\"#E6E6E6\" ";
else
$bgatts = "bgcolor=\"#FFFFFF\" ";
$oddrow = !$oddrow;
?>
<tr>
<td <?php print $bgatts; ?>valign="top"><a href="plugins.php?action=showplugin&id=<?php print $id ?>"><?php print $plugin["NAME"] ?></a></td>
<td <?php print $bgatts; ?> valign="top"><?php print $plugin["BRIEF"] ?></td>
<td <?php print $bgatts; ?> valign="top" align="right"><?php print $plugin["VERSION"] ?></td>
<td <?php print $bgatts; ?> valign="top" align="right"><?php print $plugin["USERNAME"] ?></td>
<td <?php print $bgatts; ?> valign="top" align="right"><?php print $plugin["DOWNLOAD_COUNT"] ?></td>
</tr>
<?php
}
?>
</table>
</td></tr></table>
<?php if ($action != "listpopular" && $limit < $plugin_count): ?>
<br />
<div align="center">
<?php
if ($start > 0)
{
print "<a href=\"plugins.php?action=$action";
print "&start=" . ($start - $limit) . "&limit=" . $limit . "\">";
print "Previous</a>";
}
else
print "Previous";
print "&nbsp;&nbsp; ";
for ($i = 0; $i < ($plugin_count / $limit); $i++)
{
if (($i * $limit) == $start)
print "<b>$i</b> ";
else
{
print "<a href=\"plugins.php?action=$action";
print "&start=" . ($i * $limit) . "&limit=" . $limit . "\">";
print $i . "</a> ";
}
}
print "&nbsp;&nbsp;";
if ($start + $limit < $plugin_count)
{
print "<a href=\"plugins.php?action=$action";
print "&start=" . ($start + $limit) . "&limit=" . $limit . "\">";
print "Next</a>";
}
else
print "Next";
?>
</div>
<?php
endif;
}
end_section();
}
function display_edit_plugin()
{
global $users, $session, $plugins;
global $id, $step;
global $name, $version, $url, $homepage, $filesize, $brief;
global $description;
$plugin = $plugins->get_plugin($id);
if ($plugin == NULL)
display_unknown_plugin();
elseif ($plugin["USER_ID"] != $users->get_active_user_id())
display_permission_denied("edit");
$missinginfo = false;
if ($step == 2)
{
$requiredname = array(
"name", "version", "url", "filesize", "brief", "description"
);
for ($i = 0; $i < count($requiredinfo); $i++) {
if (empty($GLOBALS[$requiredinfo[$i]])) {
$GLOBALS[$requiredinfo[$i]] = -1;
$missinginfo = true;
}
}
if (!is_numeric($filesize))
{
$missinginfo = true;
}
if ($missinginfo == false)
{
$plugins->update_plugin($id, $name, $version, $url,
$homepage, $filesize, $brief, $description);
header("Location: plugins.php");
exit;
}
}
else
{
$name = $plugin["NAME"];
$version = $plugin["VERSION"];
$url = $plugin["URL"];
$homepage = $plugin["HOMEPAGE"];
$filesize = $plugin["FILESIZE"];
$brief = $plugin["BRIEF"];
$description = $plugin["DESCRIPTION"];
}
setup_site("Edit Plugin");
start_section("Edit Plugin", build_plugin_list_nav(), false);
if ($missinginfo):
if (!is_numeric($filesize)):
?>
<b>Error:</b> The file size field must be an integer!
<?php
endif;
?>
<p>
You must enter in all the required information. Please fill in the information
in <font color="#FF0000">red</font>, as well as your password again, to
register.
</p>
<?php
endif;
?>
<p>
To add a plugin to the database, please fill out the form below.
</p>
<p>
<b>Note:</b> If you don't want to host your own plugin, you can add it to the
<a href="http://sourceforge.net/tracker/?atid=390395&group_id=235&func=browse">tracker</a>
on SourceForge, and use the resulting URL in the Download URL field below.
</p>
<p>
Please note that all fields marked with a red asterisk
(<font color="#FF0000">*</font>) must be filled in!
</p>
<br />
<form method="post" action="plugins.php">
<input type="hidden" name="action" value="editplugin" />
<input type="hidden" name="step" value="2" />
<input type="hidden" name="id" value="<?php print $id; ?>" />
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<?php
form_item("Name", "name", $name, true, 16, 128);
form_item("Version", "version", $version, true, 16, 16);
form_item("Brief Description", "brief", $brief, true, 30, 255);
form_item("Download URL", "url", $url, true, 30, 255);
form_item("Home Page", "homepage", $homepage, false, 30, 255);
form_item("File Size", "filesize", $filesize, true, 15, 255);
print "<tr><td align=\"right\"><small>(Specify in bytes)</small></td>";
print "<td>&nbsp;</td></tr>\n";
if ($description == -1)
$description = "";
?>
<tr>
<td colspan="2">
<br />
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><font color="#FF0000">*</font><?php start_font(); ?><b>Description:</b><br />
<textarea rows="10" cols="50" name="description"><?php print $description; ?></textarea></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<br />
<input type="submit" value="Submit" />&nbsp;&nbsp;
<input type="reset" />
</td>
</tr>
</table>
</form>
<?php
end_section();
}
function display_delete_plugin()
{
global $users, $session, $plugins;
global $id, $confirm;
$plugin = $plugins->get_plugin($id);
if ($plugin == NULL)
display_unknown_plugin();
elseif ($plugin["USER_ID"] != $users->get_active_user_id())
display_permission_denied("edit");
if (isset($confirm))
{
if ($confirm == "yes")
$plugins->delete_plugin($id);
header("Location: plugins.php");
exit;
}
setup_site("Delete Plugin");
start_section("Delete Plugin", build_plugin_list_nav(), false);
?>
<p align="center">
Are you sure you want to delete this plugin?
</p>
<div align="center">
<form method="post" action="plugins.php">
<input type="hidden" name="action" value="deleteplugin" />
<input type="hidden" name="id" value="<?php print $id; ?>" />
<input type="submit" name="confirm" value="yes" />&nbsp;&nbsp;
<input type="submit" name="confirm" value="no" />
</form>
</div>
<?php
end_section();
}
function display_search()
{
global $users, $session, $plugins;
global $type, $keywords, $start, $limit;
if ($keywords == "" || !isset($keywords)):
setup_site("Search Plugins");
start_section("Search Plugins", build_plugin_list_nav(), false);
?>
<p>
Enter as many keywords as you like. They must be separated by spaces, and
we don't support fancy schmancy logical searches!
</p>
<br />
<div align="center">
<form method="get" action="plugins.php">
<input type="hidden" name="action" value="search" />
<input type="hidden" name="start" value="0" />
<input type="hidden" name="limit" value="25" />
<b>Keywords:</b> <input type="text" name="keywords" value="" size="40" />
<br />
<br />
<input type="radio" name="type" value="name" /> Search names
&nbsp;
<input type="radio" name="type" value="description" checked="checked" /> Search descriptions
<br />
<br />
<input type="submit" value="Search" />&nbsp;&nbsp;
<input type="reset" />
</form>
</div>
<?php
else:
setup_site("Search Results");
start_section("Search Results", build_plugin_list_nav(), false);
$plugin_count = $plugins->get_search_count($keywords, $type);
$results = $plugins->search_plugins($keywords, $type, $start,
$limit);
if ($results == NULL):
?>
<p><i>No plugins matched those keywords!</i></p>
<?php
else:
?>
<table border="0" cellspacing="0" cellpadding="1" width="100%">
<tr>
<td bgcolor="#000000">
<table border="0" cellspacing="0" cellpadding="3" width="100%">
<tr>
<td width="20%" bgcolor="#f7c871"><b>Name</b></td>
<td width="50%" bgcolor="#f7c871"><b>Brief Description</b></td>
<td width="10%" bgcolor="#f7c871"><b>Version</b></td>
<td width="10%" bgcolor="#f7c871"><b>Author</b></td>
<td width="10%" bgcolor="#f7c871"><b>Downloads</b></td>
</tr>
<?php
$oddrow = true;
while (list($id, $plugin) = each($results))
{
if ($oddrow)
$bgatts = "bgcolor=\"#E6E6E6\" ";
else
$bgatts = "bgcolor=\"#FFFFFF\" ";
$oddrow = !$oddrow;
?>
<tr>
<td <?php print $bgatts; ?>valign="top"><a href="plugins.php?action=showplugin&id=<?php print $id ?>"><?php print $plugin["NAME"] ?></a></td>
<td <?php print $bgatts; ?>valign="top"><?php print $plugin["BRIEF"] ?></td>
<td <?php print $bgatts; ?>valign="top" align="right"><?php print $plugin["VERSION"] ?></td>
<td <?php print $bgatts; ?>valign="top" align="right"><?php print $plugin["USERNAME"] ?></td>
<td <?php print $bgatts; ?>valign="top" align="right"><?php print $plugin["DOWNLOAD_COUNT"] ?></td>
</tr>
<?php
}
?>
</table>
</td></tr></table>
<?php if ($limit < $plugin_count): ?>
<br />
<div align="center">
<?php
if ($start > 0)
{
print "<a href=\"plugins.php?action=search&keywords=";
print rawurlencode($keywords);
print "&type=" . $type . "&start=" . ($start - $limit);
print "&limit=" . $limit . "\">Previous</a>";
}
else
print "Previous";
print "&nbsp;&nbsp; ";
for ($i = 0; $i < ($plugin_count / $limit); $i++)
{
if (($i * $limit) == $start)
print "<b>$i</b> ";
else
{
print "<a href=\"plugins.php?action=search";
print "&keywords=" . rawurlencode($keywords);
print "&type=$type&start=" . ($i * $limit);
print "&limit=" . $limit . "\">$i</a> ";
}
}
print "&nbsp;&nbsp;";
if ($start + $limit < $plugin_count)
{
print "<a href=\"plugins.php?action=search&keywords=";
print rawurlencode($keywords);
print "&type=" . $type . "&start=" . ($start + $limit);
print "&limit=" . $limit . "\">Next</a>";
}
else
print "Next";
?>
</div>
<?php
endif;
endif;
endif;
end_section();
}
/* Beginning of the main code. */
setup_site(-1);
/* Make sure the user isn't trying to trick us. */
if (!$users->logged_in() && ($action == "addplugin" ||
$action == "editplugin" || $action == "deleteplugin"))
{
header("Location: login.php");
exit;
}
$plugins = new Plugins();
/* Figure out what to do. */
if ($action == "addplugin") {
display_add_plugin();
}
elseif ($action == "showplugin") {
show_plugin();
}
elseif ($action == "download") {
download_plugin();
}
elseif ($action == "editplugin") {
display_edit_plugin();
}
elseif ($action == "deleteplugin") {
display_delete_plugin();
}
elseif ($action == "search") {
display_search();
}
else {
display_plugins();
}
site_shutdown();
?>