2011-04-04, 07:59 PM
Well as the subject says, im creating my first mybb plugin.
Its a very simple plugin that im needing in my forum but i haven't found anything like this in all mybb directory.
The script gets a random menssage from the DB to be shown in the forum index.
But Im having some problems when i activate the plugin, and i have no idea why let me show you some images:
This happens in the ACP:
http://img222.imageshack.us/img222/5913/capturayuf.jpg
If im logged in, the plugin have no warnings in the index forum and works perfectly:
http://img651.imageshack.us/img651/2291/captura2u.jpg
But if i try to log out:
http://img222.imageshack.us/img222/253/captura3b.jpg
And this when im a guess:
http://img12.imageshack.us/img12/8135/captura4n.jpg
I dont know how to fix this problem, this is my source:
Hope you can help me =( i really want to finish this one.
Its a very simple plugin that im needing in my forum but i haven't found anything like this in all mybb directory.
The script gets a random menssage from the DB to be shown in the forum index.
But Im having some problems when i activate the plugin, and i have no idea why let me show you some images:
This happens in the ACP:
http://img222.imageshack.us/img222/5913/capturayuf.jpg
If im logged in, the plugin have no warnings in the index forum and works perfectly:
http://img651.imageshack.us/img651/2291/captura2u.jpg
But if i try to log out:
http://img222.imageshack.us/img222/253/captura3b.jpg
And this when im a guess:
http://img12.imageshack.us/img12/8135/captura4n.jpg
I dont know how to fix this problem, this is my source:
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
* MADE BY NILORD - LAST UPDATE 03/04/11
*/
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook('global_start', 'sabias_que_mostrar_mensaje');
/*Información sobre el plugin - Plugin Information*/
function sabias_que_info()
{
return array(
"name" => "¿Sabías qué?",
"description" => "Muestra un mensaje aleatorio a los usuarios registrados.",
"website" => "",
"author" => "NiLord",
"authorsite" => "http://www.sheikav.com",
"version" => "1.0",
"guid" => "",
"compatibility" => "16*"
);
}
/*Función de activación del plugin - Activation Function*/
function sabias_que_activate()
{
global $db;
// Crear el grupo de opciones - Crete the option group
$query = $db->simple_select("settinggroups", "COUNT(*) as rows");
$rows = $db->fetch_field($query, "rows");
$new_groupconfig = array(
'name' => 'sabias_que',
'title' => '¿Sabías qué?',
'description' => 'Opciones para la configuración del sabías qué.',
'disporder' => $rows+1,
'isdefault' => 0
);
$group['gid'] = $db->insert_query("settinggroups", $new_groupconfig);
// Crear las opciones - Create options
$new_config = array();
$new_config[] = array(
'name' => 'sabias_que_active',
'title' => 'Activar plugin',
'description' => 'Selecciona si deseas activar el plugin.',
'optionscode' => 'yesno',
'value' => '1',
'disporder' => 10,
'gid' => $group['gid']
);
foreach($new_config as $array => $content)
{
$db->insert_query("settings", $content);
}
//Creo la tabla en la base de datos - Create the data base
$db->write_query("CREATE TABLE `".TABLE_PREFIX."mensajes` (
`ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`mensaje` LONGTEXT NOT NULL
) ENGINE = MYISAM");
//Necesitamos al menos 1 mensaje para que el plugin funcione, por ello lo añadimos
//We need at least 1 menssage in the db for show the plugin
$db->write_query("INSERT INTO `".TABLE_PREFIX."mensajes` (`ID` ,`mensaje`)
VALUES (NULL , 'Necesitamos al menos 1 mensaje para que el plugin sea mostrado, aquí está')");
// Editar el template index - Edit the index template
require MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets('index', '#{\$header}#', '{$header}<!-- Sabíasque -->{$mostrar}<!-- /Sabíasque -->');
// rebuild settings...
rebuild_settings();
return TRUE;
}
/*Funcion que desactiva el plugin - Desactivate Function*/
function sabias_que_deactivate()
{
global $db;
// Borrar el grupo de opciones - Delete the Option Group
$query = $db->simple_select("settinggroups", "gid", "name = \"sabias_que\"");
$rows = $db->fetch_field($query, "gid");
$db->delete_query("settinggroups", "gid = {$rows}");
// Borrar las opciones - Delete the Options
$db->delete_query("settings", "gid = {$rows}");
//borro la tabla en la base de datos - Drop the table in the DB
$db->write_query("DROP TABLE ".TABLE_PREFIX."mensajes");
// Borrar la Edición del template / index - Delete the template/index edition
require MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets('index', '#' . preg_quote('<!-- Sabíasque -->{$mostrar}<!-- /Sabíasque -->') . '#', '');
// rebuild settings...
rebuild_settings();
return TRUE;
}
/*Muestra el mensaje - show mensage*/
function sabias_que_mostrar_mensaje()
{
global $mybb, $mostrar, $db;
// Si el plugin se encuentra desactivado o es un invitado, no hacemos nada
//If the plugin is desactivated or the user is a guess, it doesnt do anything
if($mybb->settings['sabias_que_active'] == '0' || $mybb->user['uid'] == 0)
{
return FALSE;
}
// Comprobamos si el usuario esta logueado - We check if the user is not a guess
else if($mybb->user['uid'] != 0)
{
// Si el uid del usuario es indistinto a cero, el usuario se encuentra identificado
//If the uid is not 0, the user is loged
$query = $db->simple_select("mensajes ORDER BY RAND() LIMIT 0,1");
while($q = $db->fetch_array($query))
{
$trow = alt_trow();
$mostrar=$q['mensaje'];
break;
}
}
}
?>
Hope you can help me =( i really want to finish this one.