Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Award system
Browse files Browse the repository at this point in the history
This is a major rewrite of an existing plugin.
Awards are stored inside the awards table, so users can get multiple ones.

The description for an award is displayed beneath the original post.

All moderators and administrators can add or delete awards.
  • Loading branch information
lichtmetzger committed Oct 19, 2016
1 parent f37b890 commit 693a5cc
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 2 deletions.
Binary file added img/awards/Datenretter_100x20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/awards/GoldenerKirin_100x20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions lang/English/admin_image_award.php
@@ -0,0 +1,27 @@
<?php

// Language definitions used in Image Award Plugin
$lang_admin_image_award = array(

'plugin_desc' => 'This plugin handles the image awards. Golden Kirin for real!',
'options' => 'Options',
'give_award' => 'Give a user an award',
'user_id' => 'User id:',
'user_id_desc' => 'The user id of the user you want to assign or remove an award on.',
'award' => 'Award:',
'validate' => 'Submit',
'validate_desc' => 'The award the user is to be assigned (or select **Remove Awards** to completely troll the user)',
'remove' => '**Remove Awards**',
'award_added' => 'Award added or deleted successfully',
'award_user_id' => 'You must assign the award to a user!',

'award_post_id' => 'You must assign the award to a post!',
'post_id' => 'Post id',
'post_id_desc' => 'The id of the post you want to assign or remove an award for.',
'award_reason' => 'You have to enter a reason!',
'reason' => 'Reason:',
'reason_desc' => 'A short reason. Please enter which award is given and why. Will be displayed beneath the post.',
'choose' => 'Choose',
'award_choose' => 'You have to choose an award.'

);
3 changes: 2 additions & 1 deletion lang/English/topic.php
Expand Up @@ -28,6 +28,7 @@
'Mod controls' => 'Moderator controls',
'New icon' => 'New post',
'Re' => 'Re:',
'Preview' => 'Preview'
'Preview' => 'Preview',
'Award' => 'Award'

);
27 changes: 27 additions & 0 deletions lang/German/admin_image_award.php
@@ -0,0 +1,27 @@
<?php

// Language definitions used in Image Award Plugin
$lang_admin_image_award = array(

'plugin_desc' => 'Diese Erweiterung dient dazu, Awards an Nutzer zu verleihen. Goldener Kirin for real!',
'options' => 'Optionen',
'give_award' => 'Verleihe einen Award',
'user_id' => 'Benutzer-ID:',
'user_id_desc' => 'Die ID des Benutzers, dem du einen Avatar verleihen oder aberkennen willst.',
'award' => 'Award:',
'validate' => 'Absenden',
'validate_desc' => 'Der Award, den der Nutzer erhalten soll (oder wähle **Awards entfernen** um den Nutzer komplett zu trollen)',
'remove' => '**Awards entfernen**',
'award_added' => 'Award erfolgreich gelöscht oder hinzugefügt',
'award_user_id' => 'Du musst auch einen Nutzer angeben...',

'award_post_id' => 'Du musst auch einen Beitrag angeben...',
'post_id' => 'Beitrags-ID:',
'post_id_desc' => 'Die ID des Beitrags, für den du einen Avatar verleihen oder aberkennen willst.',
'award_reason' => 'Du musst auch einen Grund angeben...',
'reason' => 'Grund:',
'reason_desc' => 'Eine kurze Begründung, welchen Award du verleihst und warum. Wird unter dem Beitrag angezeigt.',
'choose' => 'Wählen',
'award_choose' => 'Du musst auch einen Award angeben...'

);
3 changes: 2 additions & 1 deletion lang/German/topic.php
Expand Up @@ -28,6 +28,7 @@
'Mod controls' => 'Moderatorkontrollen',
'New icon' => 'Neuer Beitrag',
'Re' => 'Re:',
'Preview' => 'Vorschau'
'Preview' => 'Vorschau',
'Award' => 'Award'

);
199 changes: 199 additions & 0 deletions plugins/AMP_Image_Award.php
@@ -0,0 +1,199 @@
<?php
/***********************************************************************
Copyright (C) 2008-2010 FluxBB
based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
This file is not part of FluxBB.
FluxBB is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
FluxBB is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
************************************************************************/

##
##
## A few notes of interest for aspiring plugin authors:
##
## 1. If you want to display a message via the message() function, you
## must do so before calling generate_admin_menu($plugin).
##
## 2. Plugins are loaded by admin_loader.php and must not be
## terminated (e.g. by calling exit()). After the plugin script has
## finished, the loader script displays the footer, so don't worry
## about that. Please note that terminating a plugin by calling
## message() or redirect() is fine though.
##
## 3. The action attribute of any and all <form> tags and the target
## URL for the redirect() function must be set to the value of
## $_SERVER['REQUEST_URI']. This URL can however be extended to
## include extra variables (like the addition of &amp;foo=bar in
## the form of this example plugin).
##
## 4. If your plugin is for administrators only, the filename must
## have the prefix "AP_". If it is for both administrators and
## moderators, use the prefix "AMP_". This example plugin has the
## prefix "AMP_" and is therefore available for both admins and
## moderators in the navigation menu.
##
## 5. Use _ instead of spaces in the file name.
##
## 6. Since plugin scripts are included from the FluxBB script
## admin_loader.php, you have access to all FluxBB functions and
## global variables (e.g. $db, $pun_config, $pun_user etc).
##
## 7. Do your best to keep the look and feel of your plugins' user
## interface similar to the rest of the admin scripts. Feel free to
## borrow markup and code from the admin scripts to use in your
## plugins. If you create your own styles they need to be added to
## the "base_admin" style sheet.
##
## 8. Plugins must be released under the GNU General Public License or
## a GPL compatible license. Copy the GPL preamble at the top of
## this file into your plugin script and alter the copyright notice
## to refrect the author of the plugin (i.e. you).
##
##


// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
// Load this plugins language file
if (file_exists(PUN_ROOT.'/lang/'.$pun_user['language'].'/admin_image_award.php'))
require PUN_ROOT.'/lang/'.$pun_user['language'].'/admin_image_award.php';
else
require PUN_ROOT.'/lang/English/admin_image_award.php';
//
// The rest is up to you!
//

// If the "Show text" button was clicked
if (isset($_POST['assign_award']))
{

// When the delete option is chosen, we want to delete all awards
if (trim($_POST['award_filename']) == 'deleteall') {

$db->query('DELETE FROM '.$db->prefix.'awards WHERE uid = "'.intval($_POST['award_user_id']).'"') or error('Error when assigning new image award to user.',__FILE__,__LINE__,$db->error());
}
// Otherwise, add a new award
else
{
// Make sure something was entered
if (trim($_POST['award_user_id']) == '')
message($lang_admin_image_award['award_user_id']);
if (trim($_POST['award_post_id']) == '')
message($lang_admin_image_award['award_post_id']);
if (trim($_POST['award_reason']) == '')
message($lang_admin_image_award['award_reason']);
if (trim($_POST['award_filename']) == '')
message($lang_admin_image_award['award_choose']);

//assign the reason to a variable so we can escape it later
$reason = $_POST['award_reason'];

$db->query('INSERT INTO '.$db->prefix.'awards (award,uid,pid,reason) VALUES ("'.$db->escape($_POST['award_filename']).'","'.intval($_POST['award_user_id']).'","'.intval($_POST['award_post_id']).'","'.$db->escape($reason).'")') or error('Error when assigning new image award to user.',__FILE__,__LINE__,$db->error());
}

message($lang_admin_image_award['award_added']);

}
else // If not, we show the "Show text" form
{


// Generate a dropdown for all the awards ...
$awardmod_dropdown = '<select name="award_filename" tabindex="2"><option value="">'.$lang_admin_image_award['choose'].'</option>';
// figure out what files we have ...
$awardmod_directory = dir('./img/awards');

// Add delete as an extra option, opt-in is always better
$awardmod_dropdown .= '<option value="deleteall">'.$lang_admin_image_award['remove'].'</option>';
while(($awardmod_temp = $awardmod_directory->read()) != false)
{
if(!is_dir($awardmod_temp) && $awardmod_temp != 'index.html')
{
$awardmod_dropdown .= '<option value="'.$awardmod_temp.'">'.str_replace('_',' ',substr($awardmod_temp,0,strrpos($awardmod_temp,'_'))).'</option>';
}
}
$awardmod_directory->close();
$awardmod_dropdown .= '</select>';



// Display the admin navigation menu
generate_admin_menu($plugin);

?>
<div id="exampleplugin" class="plugin blockform">
<h2><span>Image Award administration plugin</span></h2>
<div class="box">
<div class="inbox">
<p><?php echo $lang_admin_image_award['plugin_desc'] ?></p>
</div>
</div>

<h2 class="block2"><span><?php echo $lang_admin_image_award['options'] ?></span></h2>
<div class="box">
<form id="new" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend><?php echo $lang_admin_image_award['give_award'] ?></legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row"><?php echo $lang_admin_image_award['user_id'] ?></th>
<td>
<input type="text" name="award_user_id" size="5" tabindex="1" <?php if (isset($_GET['id'])) { echo 'value="'.$_GET['id'].'"'; }?> />
<span><?php echo $lang_admin_image_award['user_id_desc'] ?></span>
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_admin_image_award['post_id'] ?></th>
<td>
<input type="text" name="award_post_id" size="5" tabindex="1" <?php if (isset($_GET['pid'])) { echo 'value="'.$_GET['pid'].'"'; }?> />
<span><?php echo $lang_admin_image_award['post_id_desc'] ?></span>
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_admin_image_award['reason'] ?></th>
<td>
<textarea name="award_reason" rows="5" cols="50" tabindex="1"></textarea>
<span><?php echo $lang_admin_image_award['reason_desc'] ?></span>
</td>
</tr>
<tr>
<th scope="row"><?php echo $lang_admin_image_award['award'] ?><div><input type="submit" name="assign_award" value="<?php echo $lang_admin_image_award['validate'] ?>" tabindex="3" /></div></th>
<td>
<?php echo $awardmod_dropdown; ?>
<span><?php echo $lang_admin_image_award['validate_desc'] ?></span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
</form>
</div>
</div>
<?php

}

// Note that the script just ends here. The footer will be included by admin_loader.php.
30 changes: 30 additions & 0 deletions viewtopic.php
Expand Up @@ -264,10 +264,35 @@
$post_actions = array();
$is_online = '';
$signature = '';
$user_image_award = ''; // [Mod] Image Award added

// If the poster is a registered user
if ($cur_post['poster_id'] > 1)
{

// [Mod] Image Award
if (file_exists(PUN_ROOT.'/lang/'.$pun_user['language'].'/admin_image_award.php'))
require PUN_ROOT.'/lang/'.$pun_user['language'].'/admin_image_award.php';
else
require PUN_ROOT.'/lang/English/admin_image_award.php';

// Query the awards table for shiny medals
$result3 = $db->query('SELECT award, pid, reason FROM '.$db->prefix.'awards WHERE uid='.$cur_post['poster_id']) or error('Unable to fetch awards', __FILE__, __LINE__, $db->error());

// Cycle through multiple avatars
while ($award = $db->fetch_assoc($result3))
{
if(strlen($award['pid']) > 0){ // if we have something there, figure out what to output...
$user_image_award .= "\t\t\t\t\t\t".'<dd class="award"><a href="/forum/viewtopic.php?pid='.$award['pid'].'#p'.$award['pid'].'"><img src="img/awards/'.$award['award'].'" width="100px" height="20px" /></a></dd>'."\n";

//When the displayed post is also the awarded post, show the reason for the award! :)
if ($award['pid'] == $cur_post['id']) {
$user_image_reason .= '<dd class="reason" style="border:3px dashed green;padding:5px;">'.pun_htmlspecialchars($award['reason']).'</dd>';
}
}
}
// [Mod] End Image Award

if ($pun_user['g_view_users'] == '1')
$username = '<a href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['username']).'</a>';
else
Expand Down Expand Up @@ -385,6 +410,9 @@
else
{
$post_actions[] = '<li class="postreport"><span><a href="misc.php?report='.$cur_post['id'].'">'.$lang_topic['Report'].'</a></span></li>';
//ability to give an award
$post_actions[] = '<li class="postaward"><span><a href="admin_loader.php?plugin=AMP_Image_Award.php&id='.$cur_post['poster_id'].'&pid='.$cur_post['id'].'">'.$lang_topic['Award'].'</a></span></li>';

if ($pun_user['g_id'] == PUN_ADMIN || !in_array($cur_post['poster_id'], $admin_ids))
{
$post_actions[] = '<li class="postdelete"><span><a href="delete.php?id='.$cur_post['id'].'">'.$lang_topic['Delete'].'</a></span></li>';
Expand Down Expand Up @@ -426,13 +454,15 @@
<?php if ($user_avatar != '') echo "\t\t\t\t\t\t".'<dd class="postavatar">'.$user_avatar.'</dd>'."\n"; ?>
<?php if (count($user_info)) echo "\t\t\t\t\t\t".implode("\n\t\t\t\t\t\t", $user_info)."\n"; ?>
<?php if (count($user_contacts)) echo "\t\t\t\t\t\t".'<dd class="usercontacts">'.implode(' ', $user_contacts).'</dd>'."\n"; ?>
<?php if (strlen($user_image_award)>0) echo $user_image_award; // [Mod] Image Award added ?>
</dl>
</div>
<div class="postright">
<h3><?php if ($cur_post['id'] != $cur_topic['first_post_id']) echo $lang_topic['Re'].' '; ?><?php echo pun_htmlspecialchars($cur_topic['subject']) ?></h3>
<div class="postmsg">
<?php echo $cur_post['message']."\n" ?>
<?php if ($cur_post['edited'] != '') echo "\t\t\t\t\t\t".'<p class="postedit"><em>'.$lang_topic['Last edit'].' '.pun_htmlspecialchars($cur_post['edited_by']).' ('.format_time($cur_post['edited']).')</em></p>'."\n"; ?>
<?php if (strlen($user_image_reason)>0) echo $user_image_reason; // [Mod] Image Award reason added ?>
</div>
<?php if ($signature != '') echo "\t\t\t\t\t".'<div class="postsignature postmsg"><hr />'.$signature.'</div>'."\n"; ?>
</div>
Expand Down

0 comments on commit 693a5cc

Please sign in to comment.