Plugin does not work
#1
Question 
Hi,

I made a small script that shows an overview with the last 5 threads and the 5 newest members. It worked and now I want to turn it into a plugin but it's not working because it isn't displayed in the plugin-list in the admin-cp.

Here's the code:
PHP Code:
<?php
// Benötigte Daten für das Plugin-System
$plugins->add_hook("index_start""overview");

function 
overview_info()
{
    return array(
        
"name"        => "&Uuml;bersicht",
        
"description" => "F&uuml;gt eine Überichtsbox auf der Startseite ein, die &uuml;ber neueste Mitglieder und letzte Themen informiert.",
        
"website"     => "http://www.mybboard.de",
        
"author"      => "MyBBoard.de",
        
"authorsite"  => "http://www.mybboard.de",
        
"version"     => "1.0",
        );
}

function 
overview_activate() {
global 
$db;
    
// Variablen für dieses Plugin einfügen
    
require "./inc/adminfunctions_templates.php";
    
find_replace_templatesets("index"'#\$header(\r?)\n#'"\$header\n\$overview\n");
    
    
// Templates für dieses Plugin einfügen
    
$templatearray = array(
        
"tid" => "NULL",
        
"title" => "index_overwiew",
        
"template" => "<table width=\"100%\" class=\"tborder\">
<tr><td colspan=\"2\" class=\"thead\"><strong>\$overview_overview</strong></td></tr>
<tr><td class=\"tcat\" width=\"33%\"><strong>\$overview_newest_members</strong></td>
<td class=\"tcat\" width=\"67%\"><strong>\$overview_newest_threads</strong></td></tr>
<tr>
<td class=\"trow1\"><table width=\"100%\">
<tr><td><strong>\$overview_username</strong></td><td align=\"right\"><strong>\$overview_posts</strong></td></tr>
\$newmembers
</table></td><td class=\"trow2\">
<table width=\"100%\"><tr>
<td><strong>\$overview_topic</strong></td>
<td><strong>\$overview_author</strong></td></tr>
\$newthreads
</table></td></tr>
</table><br />"
,
        
"sid" => "-1",
        );
        
$db->insert_query(TABLE_PREFIX."templates"$templatearray);
}

function 
overview_deactivate() {
global 
$db;
    
// Variablen von dieses Plugin entfernen
    
require "./inc/adminfunctions_templates.php";
    
find_replace_templatesets("index"'#\$overview(\r?)\n#'""0);
    
    
// Templates von dieses Plugin entfernen
    
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='index_overwiew'");
}

function 
overview()
{

global 
$db$mybb$cache$templates$lang$index_overwiew;

//Lang-Variablen
$lang->overview_overview "&Uuml;bersicht";
$lang->overview_newest_members "Neueste Mitglieder";
$lang->overview_newest_threads "Neueste Themen";
$lang->overview_username "Benutzername";
$lang->overview_posts "Beitr&auml;ge";
$lang->overview_topic "Thema";
$lang->overview_author "Verfasser";

// Lang-Variablen in Template einfügen
$overview_overview $lang->overview_overview;
$overview_newest_members $lang->overview_newest_members;
$overview_newest_threads $lang->overview_newest_threads;
$overview_username $lang->overview_username;
$overview_posts $lang->overview_posts;
$overview_topic $lang->overview_topic;
$overview_author $lang->overview_author;

// Daten aus Datenbank auslesen
$last_users mysql_query ("SELECT * FROM ".TABLE_PREFIX."users ORDER BY uid DESC LIMIT 0,5");
while (
$row mysql_fetch_array($last_users)) {

// Daten ausgeben
$newmembers = ("<tr><td><div class=\"smalltext\"><a href=\"member.php?action=profile&amp;uid=$row[uid]\">".$row[username]."</a><div class=\"smalltext\"></td><td align=\"right\"><div class=\"smalltext\">".$row[postnum]."</div></td></tr>");
}

// Daten aus Datenbank auslesen
$last_threads mysql_query ("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY tid DESC LIMIT 0,5");
while (
$row mysql_fetch_array($last_threads)) {

// Daten ausgeben
$newthreads = ("<tr><td><div class=\"smalltext\"><a href=\"showthread.php?tid=$row[tid]\">".$row[subject]."</a></div></td><td><div class=\"smalltext\"><a href=\"member.php?action=profile&amp;uid=$row[uid]\">".$row[username]."</a></div></td></tr>");
}
// Template laden
eval("\$overview = \"".$templates->get("index_overview")."\";");
}
?>
Hope anybody finds a reason. :neautral:
Reply
#2
and the file is called overview.php?
Reply
#3
Hi k776,

that was it. Now I can activate and deactivate it. But there's another problem: Nothing is shown on the forums index. The templates get inserted/changed correctly...
Reply
#4
change

global $db, $mybb, $cache, $templates, $lang, $index_overwiew;

to

global $db, $mybb, $cache, $templates, $lang, $overwiew;
Reply
#5
No, still nothing. :neautral:
Reply
#6
opps. You have $overwiew and $overview multiple times. Gets confusing. I meant replace with this:

global $db, $mybb, $cache, $templates, $lang, $overview;
Reply
#7
Still not working. Attached you find the actual code.

When I look at the source code of the site there's only
<!-- start: index_overview -->

<!-- end: index_overview -->


Attached Files
.php   overview.php (Size: 3.68 KB / Downloads: 125)
Reply
#8
Found it! Now there's a new problem: The plugin only displays one thread and one member and not 5...Here's the actual code:
PHP Code:
<?php
/*
Plugin Overview
(c) 2005 by MyBBoard.de
Website: http://www.mybboard.de
*/

// Benötigte Daten für das Plugin-System
$plugins->add_hook("index_start""overview");

function 
overview_info()
{
    return array(
        
"name"        => "&Uuml;bersicht",
        
"description" => "F&uuml;gt eine Überichtsbox auf der Startseite ein, die &uuml;ber neueste Mitglieder und letzte Themen informiert.",
        
"website"     => "http://www.mybboard.de",
        
"author"      => "MyBBoard.de",
        
"authorsite"  => "http://www.mybboard.de",
        
"version"     => "1.0",
        );
}

function 
overview_activate() {
global 
$db;
    
// Variablen für dieses Plugin einfügen
    
require "./inc/adminfunctions_templates.php";
    
find_replace_templatesets("index"'#\$header(\r?)\n#'"\$header\n\$overview\n");
    
    
// Templates für dieses Plugin einfügen
    
$templatearray = array(
        
"tid" => "NULL",
        
"title" => "index_overview",
        
"template" => "<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"3\" class=\"tborder\">
<tr><td colspan=\"2\" class=\"thead\"><strong>\$overview_overview</strong></td></tr>
<tr><td class=\"tcat\" width=\"33%\"><strong>\$overview_newest_members</strong></td>
<td class=\"tcat\" width=\"67%\"><strong>\$overview_newest_threads</strong></td></tr>
<tr>
<td class=\"trow1\"><table width=\"100%\">
<tr><td><strong>\$overview_username</strong></td><td align=\"right\"><strong>\$overview_posts</strong></td></tr>
\$newmembers
</table></td><td class=\"trow2\">
<table width=\"100%\"><tr>
<td width=\"67%\"><strong>\$overview_topic</strong></td>
<td width=\"33%\"><strong>\$overview_author</strong></td></tr>
\$newthreads
</table></td></tr>
</table>\$overview_copyright<br />"
,
        
"sid" => "-1",
        );
        
$db->insert_query(TABLE_PREFIX."templates"$templatearray);
}

function 
overview_deactivate() {
global 
$db;
    
// Variablen von dieses Plugin entfernen
    
require "./inc/adminfunctions_templates.php";
    
find_replace_templatesets("index"'#\$overview(\r?)\n#'""0);
    
    
// Templates von dieses Plugin entfernen
    
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='index_overview'");
}

function 
overview()
{

global 
$db$mybb$cache$templates$lang$overview;

//Lang-Variablen
$lang->overview_overview "&Uuml;bersicht";
$lang->overview_newest_members "Neueste Mitglieder";
$lang->overview_newest_threads "Neueste Themen";
$lang->overview_username "Benutzername";
$lang->overview_posts "Beitr&auml;ge";
$lang->overview_topic "Thema";
$lang->overview_author "Verfasser";

// Lang-Variablen in Template einfügen
$overview_overview $lang->overview_overview;
$overview_newest_members $lang->overview_newest_members;
$overview_newest_threads $lang->overview_newest_threads;
$overview_username $lang->overview_username;
$overview_posts $lang->overview_posts;
$overview_topic $lang->overview_topic;
$overview_author $lang->overview_author;

//Copyright für Template
$overview_copyright "<!-- Plugin Overview (c) 2005 by MyBBoard.de (http://www.mybboard.de) -->";

// Daten für neueste Benutzer aus Datenbank auslesen
$last_users mysql_query ("SELECT * FROM ".TABLE_PREFIX."users ORDER BY uid DESC LIMIT 0,5");
while (
$row mysql_fetch_array($last_users)) {

// Daten ausgeben
$newmembers_output = ("<tr><td><div class=\"smalltext\"><a href=\"member.php?action=profile&amp;uid=$row[uid]\">".$row[username]."</a><div class=\"smalltext\"></td><td align=\"right\"><div class=\"smalltext\">".$row[postnum]."</div></td></tr>");
}

$newmembers $newmembers_output;

// Daten für neueste Themen aus Datenbank auslesen
$last_threads mysql_query ("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY tid DESC LIMIT 0,5");
while (
$row mysql_fetch_array($last_threads)) {

// Daten ausgeben
$newthreads_output = ("<tr><td><div class=\"smalltext\"><a href=\"showthread.php?tid=$row[tid]\">".$row[subject]."</a></div></td><td><div class=\"smalltext\"><a href=\"member.php?action=profile&amp;uid=$row[uid]\">".$row[username]."</a></div></td></tr>");
}

$newthreads $newthreads_output;

// Template laden
eval("\$overview = \"".$templates->get("index_overview")."\";");
}
?>
Reply
#9
Got it! Thanks a lot! :lol:

You can see it here: http://forum.mybboard.de
Reply
#10
Another little question: How can I hide threads from the list that are in hidden forums? For example that threads from the staff forums are only visible for the staff in the list?

I looked into the code of the welcome panel plugin because it also shows the latest thread but I couldn't find it!?

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)