Add content with limiting function
This example will prevent a user from adding more than 10 stories, and will show how many the user has been added. You can edit the parameters $type and $contentmax and other parameters so it will fit your needs. It simply shows and hide a link and does not prevent a "cheating" user from entering content anyway by entering a link in the adress field in the browser. You should also delete all links on other places that allows a user to add this type of content. This can sometimes be tricky for some content elements.
<?php
// Add content by shine ------------------------------------------
//edit these values: ---------------------------
$type = 'story'; // type of content
$contentmax=10; // how many of this content allowed
//too much content message:
$mess = "max $contentmax allowed";
//message - not logged in message, leave blank if non:
$notlogg = 'Please log in to insert content';
$insertad = 'Insert content'; //message insert content
$show = 1; //0 = hide numbers 1 = show numbers
$pre = 'You have'; //if show is 1 premessage
$post = 'stories'; // if show is 1 postmessage
//start ------------------------------------------------
unset($output);
global $user;
//--- message for not logged in
if ($user->uid == 0 AND $notlogg<>""){
print $notlogg;
print '<BR><BR>';
}
// show only for logged in
if ($user->uid>0){
//sql ------------------------------------------------------------
$sql = "SELECT COUNT(*) as number
FROM {node}
WHERE status = 1 AND uid = %d AND type = '";
$sql .= $type;
$sql .= "' GROUP BY uid";
$contentan = db_result(db_query($sql, $user->uid, $node->type));
//draw ---------------------------------------------------------
$output='';
$output .= '<TABLE BORDER="1" CELLPADDING="1" CELLSPACING="3" WIDTH="100%"><TR><TD BGCOLOR="#f5f4f4">
';
if ($contentan<$contentmax){
$output .= l($insertad, "node/add/$type");
$output .= '<BR>';
}
if ($contentan>0 AND $show==1){
$output .= "$pre $contentan / $contentmax $post";
$output .= '<BR>';
}
if ($contentan>=$contentmax){
$output .= $mess;
$output .= "<BR>";
}
$output .= '</TD></TR></TABLE><BR>';
print $output;
unset ($output);
}
?>