Customization > Blocks and Modifications

[Block] Announce new registered users awaiting for account approval

(1/3) > >>

Chen Zhen:
Custom PHP Block: Announce new registered users awaiting for account approval


Features:

* Displays latest members awaiting account approval
* Uses pages for lengthy lists
* Allows option to adjust list length & character length (at top of block code)
* Links to user profiles & registration
* Option to externally check if IP is flagged as spam
* Visible only to Administrators
Note: Adjust the language where necessary.


Recommended settings:

* Permissions: Custom - Admin Only (logic is set up for this anyway - not mandatory)
* Display Options: Show block Everywhere
* Style Options: No title & No body
* Set up for Top/Bottom or Header/Footer display

SMF 2.0 PHP Block Code:

--- Code: ---/* 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;
}

--- End code ---


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. 

Chen Zhen:

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.

Chen Zhen:
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.
 

killernos:
this is a great block can you add approve or deny to the very right?
please and great work.

player.samp:
I get this message when I try to create that block:

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

:(

Navigation

[0] Message Index

[#] Next page

Go to full version