SimplePortal

Customization => Blocks and Modifications => Topic started by: Chen Zhen on February 08, 2012, 02:13:40 AM

Title: [Block] Announce new registered users awaiting for account approval
Post by: Chen Zhen on February 08, 2012, 02:13:40 AM
Custom PHP Block: Announce new registered users awaiting for account approval



Features:

Note: Adjust the language where necessary.



Recommended settings:



SMF 2.0 PHP Block Code:
Code: [Select]
/* block:sp-aru3 <-----> c/o Underdog */
/* SMF 2.0x version */
/* Announce new registers waiting for account approval block */
global $context, $scripturl, $settings, $smcFunc;

$check_ip = true; /* Check if IP's are flagged as spam from external sources */
$show_data = true; /* true: show registers info  /  false: only show number of registers */
$h3_format = 'titlebg'; /* catbg/titlebg  - css title style  */
$h3top = true; /* true = show bar above info  /  false = show bar below info  */
$char_length = 30; /* max character length */
$rows = 3; /* visibile rows */
$prev = 'Prev'; /* Previous text */
$next = 'Next'; /* Next text */
$highlight = '#FEE333'; /* Stress color for flagged IP's */

if ($context['user']['is_admin'])
{

$total = 0;
$offset = (int)$rows;
$needed_data = array('id_member', 'member_name', 'email_address', 'date_registered', 'member_ip');


/* Some js to control the pages */
echo '<script type="text/javascript">
function Pager(tableName, itemsPerPage) {
this.tableName = tableName;
this.itemsPerPage = itemsPerPage;
this.currentPage = 1;
this.pages = 0;
this.inited = false;

this.showRecords = function(from, to) {
var rows = document.getElementById(tableName).rows;
// i starts from 1 to skip table header row';
echo "
for (var i = 1; i < rows.length; i++) {
if (i < from || i > to)
rows[i].style.display = 'none';
else
rows[i].style.display = '';
}";
echo '
}

this.showPage = function(pageNumber) {
if (! this.inited) {
alert("not inited");
return;
}';
echo "
var oldPageAnchor = document.getElementById('pg'+this.currentPage);
oldPageAnchor.className = 'pg-normal';

this.currentPage = pageNumber;
var newPageAnchor = document.getElementById('pg'+this.currentPage);
newPageAnchor.className = 'pg-selected';

var from = (pageNumber - 1) * itemsPerPage + 1;
var to = from + itemsPerPage - 1;
this.showRecords(from, to);
}

this.prev = function() {
if (this.currentPage > 1)
this.showPage(this.currentPage - 1);
}

this.next = function() {
if (this.currentPage < this.pages) {
this.showPage(this.currentPage + 1);
}
}

this.init = function() {
var rows = document.getElementById(tableName).rows;
var records = (rows.length - 1);
this.pages = Math.ceil(records / itemsPerPage);
this.inited = true;
}";
echo '
this.showPageNav = function(pagerName, positionId) {
if (! this.inited) {
alert("not inited");
return;
}
var element = document.getElementById(positionId);';
echo "
var pagerHtml = '<span onclick=";
echo '"';
echo "' + pagerName + '.prev();";
echo '" class="pg-normal"> &#8920; ', $prev, ' </span> | ';
echo "';
for (var page = 1; page <= this.pages; page++)
pagerHtml += '<span id=";
echo '"';
echo "pg' + page + '";
echo '" class="pg-normal" onclick="';
echo "' + pagerName + '.showPage(' + page + ');";
echo '">';
echo "' + page + '</span> | ';
pagerHtml += '<span onclick=";
echo '"';
echo "'+pagerName+'.next();";
echo '" class="pg-normal"> ', $next,' &#8921;</span>';
echo "';

element.innerHTML = pagerHtml;
}
}
function RegsRegenerate()
{
window.location.reload()
}

function RegsRegenerator()
{
if (document.layers)
{
appear()
setTimeout(";
echo '"window.onresize=RegsRegenerate",450)
}
}

function changetext(whichcontent)
{
if (document.all||document.getElementById)
{
cross_el=document.getElementById? document.getElementById("descriptions"):document.all.descriptions
cross_el.innerHTML=';
echo "'<div style=";
echo '"font-family:Arial Narrow Bold;font-size:small;">';
echo "'+whichcontent+'</div>'
}
else if (document.layers)
{
document.d1.document.d2.document.write('<div style=";
echo '"font-family:Arial Narrow Bold;font-size:small;">';
echo "'+whichcontent+'</div>')
document.d1.document.d2.document.close()
}

}

function appear()
{
document.d1.visibility='show'
}
</script>";
/* end of js controller */

$pages = '<script type="text/javascript"><!--
        var pager = new Pager("UserRegSP", '.(int)$rows.');
        pager.init();
        pager.showPageNav("pager", "RegsPagePosition");
        pager.showPage(1);
    //--></script>';

$result = $smcFunc['db_query']('', "SELECT id_member, member_name, date_registered, is_activated, email_address, member_ip FROM {db_prefix}members WHERE (is_activated = 3)");
while ($val = $smcFunc['db_fetch_assoc']($result))
{
foreach ($needed_data as $data)
$registers[$total][$data] = strlen($val[$data]) >= ((int)$char_length) ? $val[$data] = substr($val[$data],0,((int)$char_length - 1)).'...':$val[$data];

$total++;
}
$smcFunc['db_free_result']($result);

if ((int)$total > 0 && $show_data)
{
echo '
<script type="text/javascript">
<!--
window.onload=RegsRegenerator
//-->
</script>';
if ($h3top)
{
echo '
<h3 class="'.$h3_format.' centertext" style="border-radius:10px;-webkit-border-radius:10px;-moz-border-radius:10px;">
<span class="left"></span>
<span style="float:left;overflow:hidden;padding-left:10px;vertical-align:middle;">Members pending approval: ',$total,'</span>';
if ((int)$total > (int)$rows)
echo '
<span id="RegsPagePosition" style="text-align:center;overflow:hidden;margin-left:auto;margin-right:auto;vertical-align:middle;"></span>';

echo '
<span style="float:right;overflow:hidden;padding-right:10px;vertical-align:middle;">
<a href="'. $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve;'.$context['session_var'] . '=' . $context['session_id'].'">
Approve Members
</a>
</span>
</h3>';
}
echo '
<table border="0" style="border-collapse: collapse;width:100%;overflow:hidden;">
<tr class="catbg smalltext">
<td class="catbg" style="border:0px;height: 18px;background: url(',$settings['actual_theme_url'],'/images/theme/main_block.png) no-repeat 0 -160px;text-align:left;width:10%;">ID#</td>
<td class="catbg" style="text-align:left;background: url(',$settings['actual_theme_url'],'/images/theme/main_block.png) no-repeat 50% -160px;height: 18px;width:25%;">Name</td>
<td class="catbg" style="text-align:left;background: url(',$settings['actual_theme_url'],'/images/theme/main_block.png) no-repeat 50% -160px;height: 18px;width:25%;">Email Address</td>
<td class="catbg" style="text-align:left;background: url(',$settings['actual_theme_url'],'/images/theme/main_block.png) no-repeat 50% -160px;height: 18px;width:25%;">Date Registered</td>
<td class="catbg" style="text-align:right;border:0px;background: url(',$settings['actual_theme_url'],'/images/theme/main_block.png) no-repeat 100% -160px;height: 18px;line-height: 10px;width:15%;">
IP Address
</td>
</tr>
</table>
<table border="0" style="border-collapse: collapse;width:100%;overflow:hidden;" id="UserRegSP">
<tr class="catbg">
<td colspan="5"><hr /></td></tr>';
foreach ($registers as $new_member)
{
if (empty($new_member['id_member']))
continue;

$new_member['date_registered'] = date("D M j, Y \a\\t g:m a", $new_member['date_registered']);
echo '
<tr class="windowbg">';
foreach ($needed_data as $data)
{
if ($data == 'member_ip')
{
if (($check_ip) && ip_spamcheck(trim($new_member[$data])))
echo '
<td style="text-align:right;width:15%;background-color: '.$highlight.';">';
else
echo '
<td style="text-align:right;width:15%;">';

}
elseif ($data == 'id_member')
echo '
<td style="text-align:left;width:10%;">';
else
echo '
<td style="text-align:left;width:25%;position:relative;left:-6px;">';

echo '
<a href="',$scripturl,'?action=profile;u=',$new_member['id_member'],'">',$new_member[$data],'</a>
</td>';
}
echo '
</tr>';
}

while (((int)$offset - $total%$rows) != ((int)$rows+1))
{
echo '
<tr class="windowbg">
<td style="width: 96%" colspan="5">&nbsp;</td>
</tr>';
$offset++;
}
echo '
</table>
<table border="0" style="padding:0px;border-collapse: collapse;width:100%;overflow:hidden;">
<tr>
<td class="catbg" colspan="5" style="border:0px;height:18px;">
<span class="botslice"></span>
</td>
</tr>
</table>';
if (!$h3top)
{
echo '
<h3 class="'.$h3_format.' centertext" style="border-radius:10px;-webkit-border-radius:10px;-moz-border-radius:10px;">
<span class="left"></span>
<span style="float:left;overflow:hidden;padding-left:10px;vertical-align:middle;">Members pending approval: ',$total,'</span>';
if ((int)$total > 3)
echo '
<span id="RegsPagePosition" style="text-align:center;overflow:hidden;margin-left:auto;margin-right:auto;vertical-align:middle;"></span>';

echo '
<span style="float:right;overflow:hidden;padding-right:10px;vertical-align:middle;">
<a href="'. $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve;'.$context['session_var'] . '=' . $context['session_id'].'">
Approve Members
</a>
</span>
</h3>';
}
echo '
<span style="text-align:center;overflow:hidden;padding-left:20%;">', $pages, '</span>';
}
elseif ((int)$total > 0)
{
echo '
<h3 class="'.$h3_format.'">
<span class="left"></span>
<span style="float:left;overflow:hidden;padding-left:10px;vertical-align:middle;">';
if ((int)$total > 1)
echo '<< You have a total of ',$total,' members waiting for their account to be approved >>';
else
echo '<< You have 1 member waiting for their account to be approved >>';

echo '
</span>
<span style="float:right;overflow:hidden;padding-right:10px;vertical-align:middle;">
<a href="'. $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve;'.$context['session_var'] . '=' . $context['session_id'].'">
Approve Members
</a>
</span>
</h3>';
}
}

/* Check if IP is on spam lists */
function ip_spamcheck($ip = '0.0.0.0')
{
/* This array contains spam search urls & their pass flags */
  $feeds = array('IP Blacklist Lookup' => array('http://www.find-ip-address.org/ip-blacklist-lookup.php?ip='.$ip, 'IP address <b>'.$ip.'</b> is NOT listed in RBL (Real-time Blackhole List) database<br /> and it is not on any Spam Blacklist'), 'Honeypot' => array('http://www.projecthoneypot.org/ip_'.$ip, 'We don\'t have data on this IP currently.'));

foreach ($feeds as $feed => $data)
{
/* Use cURL to get the url file contents ... close the session first! */
session_write_close();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$data[0]);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
$html = curl_exec($ch);
curl_close($ch);

/* Check for a timeout else check the html */
if ((empty($html)) || !$html)
$spamflag = false;
elseif (strpos($html, $data[1]))
$spamflag = false;
else
$spamflag = true;
}

return $spamflag;
}



Some theme's do not readily display data for this in the SMF navigation bar.
This block will enable forum Admins to be notified when registered account approvals are pending.
Submitted upon request. 
Title: Re: Custom PHP Block: Announce new registered users awaiting for account approval
Post by: Chen Zhen on February 10, 2012, 01:17:45 PM

For anyone interested in using this block:

  I tested this & found the css I used seems to work for its appearance on an assortment of themes.
If anyone has issues with it (appearance wise) then let me know in this thread with reference to the theme being used.

Thank you.

Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: Chen Zhen on December 21, 2012, 11:55:21 PM
The block in the first post has been updated which now includes the option of externally checking if the IP's have been flagged as spam. These IP's will be highlighted (stressed) on the list of pending users.

Options to enable/disable this feature & the highlight color can be opted at the top of the block code.
The rounded corners for the left part of the title bar has also been fixed/adjusted.
 
Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: killernos on January 25, 2014, 04:19:06 PM
this is a great block can you add approve or deny to the very right?
please and great work.
Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: player.samp on April 08, 2014, 11:16:08 AM
I get this message when I try to create that block:

"Database error in block code. Please check the code."

:(
Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: Chen Zhen on April 11, 2014, 12:04:33 AM
player.samp,

  I edited the block code shown in the first post. Please try it out and let me know if it works for you this time.

Regards.
 
Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: player.samp on April 11, 2014, 08:16:12 AM
Still error in the database and when I check the preview I don't see anything except from the title of the block... No content. :/
Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: Chen Zhen on April 11, 2014, 08:39:33 AM
player.samp,

This works fine for me when tested on a default SimplePortal installation.
You will not see anything unless you have your forum set to admin approval for registration and only if there are people that have registered pending approval.
Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: player.samp on April 11, 2014, 09:31:47 AM
player.samp,

This works fine for me when tested on a default SimplePortal installation.
You will not see anything unless you have your forum set to admin approval for registration and only if there are people that have registered pending approval.

Okay, so maybe there is a database problem right now because no user tried to register.

So I will try to make it when a user will try to register and then see if it works.
Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: Chen Zhen on April 11, 2014, 11:00:32 AM
player.samp,,

  It should still allow you to save the block code no matter what. It checks db columns that exist for SMF by default so there should be no database error. Also the block should have the settings of no body and no title checked because you do not want the body & title to appear for users without permission to view such data. Also it will not appear at all if no users are pending approval that way. It has its own style layout that does not require the block title & body style attributes.
 
Title: Re: [Block] Announce new registered users awaiting for account approval
Post by: player.samp on June 21, 2014, 07:32:15 PM
When I click now on preview I am redirected to this link:

"data:,"

And I am trying it on SMF 2.0.6.
SimplePortal 2.3.8 © 2008-2024, SimplePortal