MyBB Community Forums

Full Version: Plugin does not work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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:
and the file is called overview.php?
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...
change

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

to

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

global $db, $mybb, $cache, $templates, $lang, $overview;
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 -->
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")."\";");
}
?>
Got it! Thanks a lot! :lol:

You can see it here: http://forum.mybboard.de
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!
Pages: 1 2