Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 10:05 am EST
Geeklog Forums
Help with submissions block
Status: offline
casper
Forum User
Full Member
Registered: 02/11/04
Posts: 142
Location:Skien, Norway
Ive tried to make a phpblock that returns a count for the table storysubmission, to make submissions be more visible for story admins as a reminder to approve new submissions.
Lifted some code used to make count in the adminmenu, but couldent make it work.
Has anyone some suggestions/code to help me with?
Lifted some code used to make count in the adminmenu, but couldent make it work.
Has anyone some suggestions/code to help me with?
23
23
Quote
Status: offline
jmucchiello
Forum User
Full Member
Registered: 08/29/05
Posts: 985
Off the top of my head:
{
global $_TABLES, $_CONF;
if (!SEC_hasRights('story.moderate,story.edit', 'OR')) {
return ''; // no block for folks without permission
}
$res = DB_query("SELECT title FROM {$_TABLES['storysubmission']} "
. COM_getTopicSql() . " ORDER BY DATE desc");
$num = DB_numRows($res);
$list = '';
// make a list of waiting stories so when there's a backlog, it's more noticeable.
for ($i = 0; $i < 5 AND $row = DB_fetchArray($res); ++$i) {
$list .= "<li>{$row['title']}</li>\n";
}
$display = '';
if (!empty($list)) {
$display = "Last $i of $num waiting "
. "<a href=\"{$_CONF['site_admin_url']}/moderation.php\">story submissions</a>"
. "<ul>$list</ul>";
}
return $display;
}
Text Formatted Code
function phpblock_storysubmissions(){
global $_TABLES, $_CONF;
if (!SEC_hasRights('story.moderate,story.edit', 'OR')) {
return ''; // no block for folks without permission
}
$res = DB_query("SELECT title FROM {$_TABLES['storysubmission']} "
. COM_getTopicSql() . " ORDER BY DATE desc");
$num = DB_numRows($res);
$list = '';
// make a list of waiting stories so when there's a backlog, it's more noticeable.
for ($i = 0; $i < 5 AND $row = DB_fetchArray($res); ++$i) {
$list .= "<li>{$row['title']}</li>\n";
}
$display = '';
if (!empty($list)) {
$display = "Last $i of $num waiting "
. "<a href=\"{$_CONF['site_admin_url']}/moderation.php\">story submissions</a>"
. "<ul>$list</ul>";
}
return $display;
}
20
22
Quote
Status: offline
casper
Forum User
Full Member
Registered: 02/11/04
Posts: 142
Location:Skien, Norway
Thanks so much jmucchiello!
Just what I tried to achieve!
For others who may want to use this nice code, remember to add a missing ")" in the db-query.
From this: . COM_getTopicSql() . " ORDER BY DATE desc";
To this: . COM_getTopicSql() . " ORDER BY DATE desc");
21
16
Quote
Status: offline
jmucchiello
Forum User
Full Member
Registered: 08/29/05
Posts: 985
Only one typo? Wow, I'm usually much worse than that when it comes to parentheses. I fixed the code above for anyone who needs it.
15
19
Quote
ironmax
Anonymous
This is a nice handle little block that shows when there is something and then it disappears when there is nothing to show. Excellent!
Michael
Michael
18
12
Quote
Status: offline
worldfooty
Forum User
Full Member
Registered: 01/13/09
Posts: 162
Location:Mostly Adelaide, South Australia, Australia
Just wanted to say this pretty handy and I've put it to use.
glmenu makes my site look much nicer and saves real estate, but meant story submissions weren't "in the face" or the editors. With this little block they now are. I'll have to extend it to other submissions too.
25
18
Quote
Status: offline
worldfooty
Forum User
Full Member
Registered: 01/13/09
Posts: 162
Location:Mostly Adelaide, South Australia, Australia
So my version of the above now looks like (note the function name changed slightly):
{
global $_TABLES, $_CONF;
if (!SEC_hasRights('story.moderate,story.edit', 'OR')) {
return ''; // no block for folks without permission
}
$res = DB_query("SELECT title FROM {$_TABLES['storysubmission']} "
. COM_getTopicSql() . " ORDER BY DATE desc");
$num = DB_numRows($res);
$res = DB_query("SELECT title FROM {$_TABLES['linksubmission']} "
. COM_getTopicSql() . " ORDER BY DATE desc");
$num_link = DB_numRows($res);
$res = DB_query("SELECT title FROM {$_TABLES['eventsubmission']} "
. COM_getTopicSql() . " ORDER BY DATESTART desc");
$num_event = DB_numRows($res);
$sql = "SELECT uid as id,username,fullname,email FROM {$_TABLES['users']} WHERE status = 2";
$res = DB_query ($sql);
$num_user = DB_numRows($res);
$display = "$num stories, $num_link links, $num_event events and $num_user new users in "
. "<a href=\"{$_CONF['site_admin_url']}/moderation.php\">submissions</a>";
return $display;
}
So it borrows bits from here and there and has more sorting and fields than needed. Basically it will always show a block to admin users which looks something like this:
Submissions
1 stories, 0 links, 0 events and 3 new users in submissions
Even if all categories are empty I like to show it, just to reassure myself that it's still working and visible.
Text Formatted Code
function phpblock_submissions(){
global $_TABLES, $_CONF;
if (!SEC_hasRights('story.moderate,story.edit', 'OR')) {
return ''; // no block for folks without permission
}
$res = DB_query("SELECT title FROM {$_TABLES['storysubmission']} "
. COM_getTopicSql() . " ORDER BY DATE desc");
$num = DB_numRows($res);
$res = DB_query("SELECT title FROM {$_TABLES['linksubmission']} "
. COM_getTopicSql() . " ORDER BY DATE desc");
$num_link = DB_numRows($res);
$res = DB_query("SELECT title FROM {$_TABLES['eventsubmission']} "
. COM_getTopicSql() . " ORDER BY DATESTART desc");
$num_event = DB_numRows($res);
$sql = "SELECT uid as id,username,fullname,email FROM {$_TABLES['users']} WHERE status = 2";
$res = DB_query ($sql);
$num_user = DB_numRows($res);
$display = "$num stories, $num_link links, $num_event events and $num_user new users in "
. "<a href=\"{$_CONF['site_admin_url']}/moderation.php\">submissions</a>";
return $display;
}
So it borrows bits from here and there and has more sorting and fields than needed. Basically it will always show a block to admin users which looks something like this:
Submissions
1 stories, 0 links, 0 events and 3 new users in submissions
Even if all categories are empty I like to show it, just to reassure myself that it's still working and visible.
21
19
Quote
Status: offline
worldfooty
Forum User
Full Member
Registered: 01/13/09
Posts: 162
Location:Mostly Adelaide, South Australia, Australia
Actually, that only works if you have full admin control - stuffs up when I log in with limited access, so don't trust my code above!!!
16
20
Quote
Status: offline
worldfooty
Forum User
Full Member
Registered: 01/13/09
Posts: 162
Location:Mostly Adelaide, South Australia, Australia
OK, this works a bit better. Not tarted up perfectly but does the job for me and the typical rights I allocate to users, i.e. story, links, events and for full admin, also user moderation.
So I could check the rights on each step if this was production code, but for now I've just checked if they have story rights, and if so assume they have links and events too. If they also have user mod rights then the number of new user submissions is shown, else just a ? to indicate that the person isn't logged in with enough privilege to check (I have editors who generally have some rights but only log in as full admin occasionally).
So my new version is:
{
global $_TABLES, $_CONF;
$display = '';
if (!SEC_hasRights('story.moderate,story.edit', 'OR')) {
return $display; // no block for folks without permission
}
$res = DB_query("SELECT title FROM {$_TABLES['storysubmission']} "
. COM_getTopicSql() . " ORDER BY DATE desc");
$num = DB_numRows($res);
$res = DB_query("SELECT title FROM {$_TABLES['linksubmission']} ");
$num_link = DB_numRows($res);
$res = DB_query("SELECT title FROM {$_TABLES['eventsubmission']}");
$num_event = DB_numRows($res);
$num_user = "?";
if (SEC_hasRights('user.edit')) {
$sql = "SELECT uid as id,username,fullname,email FROM {$_TABLES['users']} WHERE status = 2";
$result = DB_query ($sql);
$num_user = DB_numRows($result);
}
$display = "$num stories, $num_link links, $num_event events and $num_user new users in "
. "<a href=\"{$_CONF['site_admin_url']}/moderation.php\">submissions</a>";
return $display;
}
So I simply paste that into lib-custom.php and create a block that calls that php. Another 20 years and I'll really know what I'm doing!
So I could check the rights on each step if this was production code, but for now I've just checked if they have story rights, and if so assume they have links and events too. If they also have user mod rights then the number of new user submissions is shown, else just a ? to indicate that the person isn't logged in with enough privilege to check (I have editors who generally have some rights but only log in as full admin occasionally).
So my new version is:
Text Formatted Code
function phpblock_submissions(){
global $_TABLES, $_CONF;
$display = '';
if (!SEC_hasRights('story.moderate,story.edit', 'OR')) {
return $display; // no block for folks without permission
}
$res = DB_query("SELECT title FROM {$_TABLES['storysubmission']} "
. COM_getTopicSql() . " ORDER BY DATE desc");
$num = DB_numRows($res);
$res = DB_query("SELECT title FROM {$_TABLES['linksubmission']} ");
$num_link = DB_numRows($res);
$res = DB_query("SELECT title FROM {$_TABLES['eventsubmission']}");
$num_event = DB_numRows($res);
$num_user = "?";
if (SEC_hasRights('user.edit')) {
$sql = "SELECT uid as id,username,fullname,email FROM {$_TABLES['users']} WHERE status = 2";
$result = DB_query ($sql);
$num_user = DB_numRows($result);
}
$display = "$num stories, $num_link links, $num_event events and $num_user new users in "
. "<a href=\"{$_CONF['site_admin_url']}/moderation.php\">submissions</a>";
return $display;
}
So I simply paste that into lib-custom.php and create a block that calls that php. Another 20 years and I'll really know what I'm doing!
18
15
Quote
All times are EST. The time is now 10:05 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content