Crear plugin gracias basico
Hola a todos bueno ando en busca de un plugin de agradecimiento super pero super basico :D jaja solo necesito que abajo de cada post salga un boton q...

Hola a todos bueno ando en busca de un plugin de agradecimiento super pero super basico Big Grin jaja solo necesito que abajo de cada post salga un boton que diga gracias y abajo salgan las personas que agradecieron el post.

si aguien tiene una mini idea jaja que la agrege y yo me encargo de lo demas jaja Smile solo necesito la base Smile

gracias ...
puedes usar el de SaeedGh http://mods.mybb.com/view/thanks y quitar todas las funciones que no necesites
:)
mmm gracias vere que puedo lograr Smile
Ya hay muchos, por ejemplo el de Cluster, el de G33K, y otros que no se actualizan pero segun funcionan.
Omar G.
$plugins->add_hook("postbit", "thx");
$plugins->add_hook("xmlhttp", "do_action");
$plugins->add_hook("showthread_start", "direct_action");
$plugins->add_hook("class_moderation_delete_post", "deletepost_edit");
$plugins->add_hook('admin_tools_action_handler', 'thx_admin_action');
$plugins->add_hook('admin_tools_menu', 'thx_admin_menu');
$plugins->add_hook('admin_tools_permissions', 'thx_admin_permissions');
$plugins->add_hook('admin_load', 'thx_admin');

para que sirven y donde los encuentro?
Son las HOOKS que los plugins usan.
  1. Usado para los mensajes.
  2. Usado para cuando se usa el AJAX o actualizacion silenciosa como le digo.
  3. Para contenido en los temas (no mensajes, pero la pagina de tema)
  4. Cuando se borra un mensaje.
  5. Para insertar nuestra accion en el ACP area de herramientas.
  6. Para insertar nuestro menu en el area de herramientas en ACP.
  7. Para insertar los permisos en el ACP.
  8. Para insertar nuestra pagina o informacion en el ACP.

Para saber usalos necesitas minimo saber como funcionan los plugins.
Omar G.
muchas gracias Smile de vdd son pequeñas dudas que tengo si sabia mas o menos pero no tenia claro su real uso gracias ahora intentare ir probando.

<?php
/**
  * Thank you 3.0.2
  * written by Arash.j13@gmail.com
  * website  WWW.CodeCorona.com
  * **************************
  * Thank you 3.0.6
  * Upgrade for MyBB 1.4 : AmirH Hassaneini,Hamed Arfaee
  * w w w . i r a n v i g . c o m
  * ***************************
  * Thank you 2.0
  * Upgrade for MyBB 1.6.x (actually 1.6.6)
  * www.soportemybb.com
*/

if(!defined("IN_MYBB"))
{
	die("No se permite la inicialización directa de este archivo.");
}

if(isset($GLOBALS['templatelist']))
{
	$GLOBALS['templatelist'] .= ", thanks_postbit_count";
}

$plugins->add_hook("postbit", "thx");
$plugins->add_hook("parse_message", "thx_code");
$plugins->add_hook("parse_quoted_message", "thx_quote");
$plugins->add_hook("xmlhttp", "do_action");
$plugins->add_hook("showthread_start", "direct_action");
$plugins->add_hook("class_moderation_delete_post", "deletepost_edit");
$plugins->add_hook('admin_tools_action_handler', 'thx_admin_action');
$plugins->add_hook('admin_tools_menu', 'thx_admin_menu');
$plugins->add_hook('admin_tools_permissions', 'thx_admin_permissions');
$plugins->add_hook('admin_load', 'thx_admin');

function thx_info()
{
	return array(
		'name'			=>	'Sistema de Agradecimientos',
		'description'	=>	'Agregar boton de agradecimiento a los temas de usuarios.',
		'website'		=>	'http://www.soportemybb.com',
		'author'		=>	'Dark Neo',
		'authorsite'	=>	'http://darkneo.com.ar',
		'version'		=>	'2.0',
		'guid'		    =>	'',
        'compatibility' =>	'16*'
	);
}


function thx_install()
{
	global $db;
	
	$db->query("CREATE TABLE IF NOT EXISTS ".TABLE_PREFIX."thx (
		txid INT UNSIGNED NOT NULL AUTO_INCREMENT, 
		uid int(10) UNSIGNED NOT NULL, 
		adduid int(10) UNSIGNED NOT NULL, 
		pid int(10) UNSIGNED NOT NULL, 
		time bigint(30) NOT NULL DEFAULT '0', 
		PRIMARY KEY (`txid`), 
		INDEX (`adduid`, `pid`, `time`) 
		);"
	);
	
	if(!$db->field_exists("thx", "users"))
	{
		$sq[] = "ALTER TABLE ".TABLE_PREFIX."users ADD `thx` INT NOT NULL, ADD `thxcount` INT NOT NULL, ADD `thxpost` INT NOT NULL";
	}
	elseif (!$db->field_exists("thxpost", "users"))		
	{
		$sq[] = "ALTER TABLE ".TABLE_PREFIX."users ADD `thxpost` INT NOT NULL";
	}
	
	if($db->field_exists("thx", "posts"))
	{
		$sq[] = "ALTER TABLE ".TABLE_PREFIX."posts DROP thx";
	}
	
	if(!$db->field_exists("pthx", "posts"))
	{
		$sq[] = "ALTER TABLE ".TABLE_PREFIX."posts ADD `pthx` INT(10) NOT NULL DEFAULT '0'";
	}
	
	if(is_array($sq))
	{
		foreach($sq as $q)
		{
			$db->query($q);
		}
	}
}


function thx_is_installed()
{
	global $db;
	if($db->field_exists('thxpost', "users"))
	{
		return true;
	}
	return false;
}


function thx_activate()
{
	global $db;
	
	//Update from v3.8
	$thx_tbl_keys = $db->query("SHOW KEYS FROM ".TABLE_PREFIX."thx WHERE Key_name='adduid'");
	
	if(!$db->fetch_field($thx_tbl_keys, "Key_name"))
	{
		$db->query("ALTER TABLE ".TABLE_PREFIX."thx ADD INDEX (`adduid`, `pid`, `time`)");
	}
	
	//Adding templates
	require MYBB_ROOT."inc/adminfunctions_templates.php";
	
	if(!find_replace_templatesets("postbit", '#'.preg_quote('{$seperator}').'#', '{$post[\'thxdsp_inline\']}{$seperator}{$post[\'thxdsp_outline\']}'))
	{
		find_replace_templatesets("postbit", '#button_delete_pm(.*)<\/tr>(.*)<\/table>#is', 'button_delete_pm$1</tr>{\$post[\'thxdsp_inline\']}$2</table>{$post[\'thxdsp_outline\']}');
	}
	find_replace_templatesets("postbit", '#'.preg_quote('{$post[\'button_rep\']}').'#', '{$post[\'thanks\']}');
	find_replace_templatesets("postbit_classic", '#button_delete_pm(.*)<\/tr>(.*)<\/table>#is', 'button_delete_pm$1</tr>{\$post[\'thxdsp_inline\']}$2</table>{$post[\'thxdsp_outline\']}');
	find_replace_templatesets("postbit_classic", '#'.preg_quote('{$post[\'button_rep\']}').'#', '{$post[\'thanks\']}');
		
	find_replace_templatesets("headerinclude", "#".preg_quote('{$newpmmsg}').'#',
		'<script type="text/javascript" src="jscripts/thx.js"></script>{$newpmmsg}');
	
	$templatearray = array(
		'title' => 'thanks_postbit_count',
		'template' => "<div><span class=\"smalltext\">{\$lang->thx_thank} {\$post[\'thank_count\']}<br />
	{\$post[\'thanked_count\']}<br /></span></div>",
		'sid' => '-1',
		);
	$db->insert_query("templates", $templatearray);

	$templatearray = array(
		'title' => 'thanks_postbit_inline',
		'template' => "<tr id=\"thx{\$post[\'pid\']}\" style=\"{\$display_style}\" class=\"trow2 tnx_style tnx_newstl\"><td><span class=\"smalltext\">{\$lang->thx_givenby}</span>&nbsp;<span id=\"thx_list{\$post[\'pid\']}\">\$entries</span></td></tr>",
		'sid' => '-1',
		);	
	$db->insert_query("templates", $templatearray);
	
	$templatearray = array(
		'title' => 'thanks_postbit_inline_classic',
		'template' => "<tr id=\"thx{\$post[\'pid\']}\" style=\"{\$display_style}\" class=\"trow2 tnx_style tnx_classic\"><td><span class=\"smalltext\">{\$lang->thx_givenby}</span></td><td class=\"trow2 tnx_style\" id=\"thx_list{\$post[\'pid\']}\">\$entries</td></tr>",
		'sid' => '-1',
		);	
	$db->insert_query("templates", $templatearray);

	$templatearray = array(
		'title' => 'thanks_postbit_outline',
		'template' => "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" id=\"thx{\$post[\'pid\']}\" style=\"{\$display_style};margin-top:5px;\"><tr><td>
        <div id=\"dn_thx_list{\$post[\'pid\']}\"><div class=\"smallfont\" align=\"center\"><input type=\"button\" value=\"Mostrar Agradecimientos\" style=\"background-color:#f5f5f5; background-image:linear-gradient(top,#f5f5f5,#f1f1f1); background-image:-o-linear-gradient(top,#f5f5f5,#f1f1f1); border:1px solid #dcdcdc;border:1px solid rgba(0, 0, 0, 0.1); border-radius:2px; color:#666; cursor:default; font-family:arial,sans-serif; font-size:11px; font-weight:bold; height:29px; line-height:27px; margin:11px 6px; min-width:54px; padding:0 8px; text-align:center\" onClick=\"if (this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display != \'\') { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'\'; this.innerText = \'\'; this.value = \'Ocultar Agradecimientos\'; } else { this.parentNode.parentNode.getElementsByTagName(\'div\')[1].getElementsByTagName(\'div\')[0].style.display = \'none\'; this.innerText = \'\'; this.value = \'Mostrar Agradecimientos\'; }\"></div><div class=\"alt2\"><div style=\"display: none;\">
        <table border=\"0\" cellspacing=\"{\$theme[\'borderwidth\']}\" cellpadding=\"{\$theme[\'tablespace\']}\" class=\"tborder thxdsp_outline\"><tr class=\"trow1 tnx_style\"><td valign=\"top\" width=\"1%\" nowrap=\"nowrap\"><img src=\"{\$mybb->settings[\'bburl\']}/images/gracias.gif\" align=\"absmiddle\" /> &nbsp;<span class=\"smalltext\">{\$lang->thx_givenby}</span></td><td class=\"trow2 tnx_style\" id=\"thx_list{\$post[\'pid\']}\" align=\"left\">\$entries</td></tr></table></div></div></div>
        </td></tr></table>",
		'sid' => '-1',
		);
	$db->insert_query("templates", $templatearray);
	
	$thx_group = array(
		"name"			=> "Gracias",
		"title"			=> "[Plugin] Sistema de Agradecimientos",
		"description"	=> "Configurar Plugin.",
		"disporder"		=> "3",
		"isdefault"		=> "1"
	);	
	$db->insert_query("settinggroups", $thx_group);
	$gid = $db->insert_id();
	
	$thx[]= array(
		"name"			=> "thx_active",
		"title"			=> "Activar/Desactivar plugin",
		"description"	=> "Activar o desactivar el plugin <u>No elimina la tabla</u>",
		"optionscode" 	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '1',
		"gid"			=> intval($gid),
	);
	
	$thx[] = array(
		"name"			=> "thx_count",
		"title"			=> "Mostrar conteo de agradecimientos",
		"description"	=> "Muestra el conteo de los agradecimientos dados en cada tema",
		"optionscode" 	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '2',
		"gid"			=> intval($gid),
	);
	
	$thx[] = array(
		"name"			=> "thx_del",
		"title"			=> "Los usuarios pueden eliminar sus agradecimientos",
		"description"	=> "Cada usuario puede eliminar los agradecimientos que haya dado",
		"optionscode" 	=> "onoff",
		"value"			=> '0',
		"disporder"		=> '3',
		"gid"			=> intval($gid),
	);
	
	$thx[] = array(
		"name"			=> "thx_hidemode",
		"title"			=> "Mostrar fecha al alejar el raton",
		"description"	=> "Muestra la fecha del agradecimiento, cuando el raton paso por encima del texto",
		"optionscode" 	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '4',
		"gid"			=> intval($gid),
	);
	
	$thx[] = array(
		"name"			=> "thx_autolayout",
		"title"			=> "Auto deteccion de plantillas",
		"description"	=> "Detectar plantilla del postbit relacionando el codigo HTML! (solo funciona si \"Separar tablas\" esta Habilitado)",
		"optionscode" 	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '5',
		"gid"			=> intval($gid),
	);

	$thx[] = array(
		"name"			=> "thx_outline",
		"title"			=> "Separar tablas",
		"description"	=> "Si quiere mostrar los agradecimientos entre los mensajes (no al final del mensaje), active esta opcion.",
		"optionscode"	=> "onoff",
		"value"			=> '1',
		"disporder"		=> '6',
		"gid"			=> intval($gid),
	);

	$thx[] = array(
		"name"			=> "thx_hidesystem",
		"title"			=> "Utilizar etiqueta [oculto]",
		'description'   => 'Oculta los contenidos entre la etiqueta [oculto], hasta agradecer al tema. <div style="float:right;"><a href="http://www.myposs.com" target="_blank">MyPoss</a></div>',
		"optionscode" 	=> "yesno",
		"value"			=> '1',
		"disporder"		=> '7',
		"gid"			=> intval($gid),
	);
	
	foreach($thx as $t)
	{
		$db->insert_query("settings", $t);
	}
	
	rebuild_settings();
}


function thx_deactivate()
{
	global $db;
	require '../inc/adminfunctions_templates.php';
	
	find_replace_templatesets("postbit", '#'.preg_quote('{$post[\'thxdsp_inline\']}').'#', '', 0);
	find_replace_templatesets("postbit", '#'.preg_quote('{$post[\'thxdsp_outline\']}').'#', '', 0);
	find_replace_templatesets("postbit", '#'.preg_quote('{$post[\'thanks\']}').'#', '{$post[\'button_rep\']}', 0);
	find_replace_templatesets("postbit_classic", '#'.preg_quote('{$post[\'thxdsp_inline\']}').'#', '', 0);
	find_replace_templatesets("postbit_classic", '#'.preg_quote('{$post[\'thxdsp_outline\']}').'#', '', 0);
	find_replace_templatesets("postbit_classic", '#'.preg_quote('{$post[\'thanks\']}').'#', '{$post[\'button_rep\']}', 0);
	find_replace_templatesets("headerinclude", "#".preg_quote('<script type="text/javascript" src="jscripts/thx.js"></script>').'#', '', 0);

	$db->delete_query("settings", "name IN ('thx_active', 'thx_count', 'thx_del', 'thx_hidemode', 'thx_autolayout', 'thx_outline', 'thx_hidesystem')");
	$db->delete_query("settinggroups", "name='Gracias'");
	$db->delete_query("templates", "title='thanks_postbit_count'");
	$db->delete_query("templates", "title='thanks_postbit_inline'");
	$db->delete_query("templates", "title='thanks_postbit_inline_classic'");
	$db->delete_query("templates", "title='thanks_postbit_outline'");
	
	rebuild_settings();
}


function thx_uninstall()
{
	global $db;

	if($db->field_exists("thx", "users"))
	{
		$db->query("ALTER TABLE ".TABLE_PREFIX."users DROP thx, DROP thxcount, DROP thxpost");
	}
	
	if($db->field_exists("pthx", "posts"))
	{
		$db->query("ALTER TABLE ".TABLE_PREFIX."posts DROP pthx");
	}
}

function thx_code(&$message)
{
    global $db, $post, $mybb, $lang ,$session, $theme, $altbg, $templates, $thx_cache;

    if (!$mybb->settings['thx_hidesystem']  || !empty($session->is_spider))
        {
          return false;
        }

     // Si es invitado, esperando activacion o bloqueado no mostramos nada.
     if ($mybb->usergroup['gid'] == "1" || $mybb->usergroup['gid'] == "5" || $mybb->usergroup['gid'] == "7")
      {
        $message = preg_replace("#\[oculto\](.*?)\[/oculto\]#is","<div style=\"padding: 5px; padding-top: 8px; border: 1px solid #000080; background: #f5f5f5; color:#B22222; border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; webkit-border-radius: 4px\"><center><b>Debes agradecer para ver el Contenido...</b></center></div>",$message);
      }
     // Si eres el creador del tema mostramos el contenido
     if ($mybb->user['uid'] == "$post[uid]")
       {
       $message = preg_replace("#\[oculto\](.*?)\[/oculto\]#si","<div style=\"padding: 5px; padding-top: 8px; border: 1px solid #000080; background: #f5f5f5; color:#B22222; border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; webkit-border-radius: 4px\"><b>Contenido: </b><Font Color=\"Black\">$1</Font></div>",$message);
       }
     // Si no eres el creador del tema, pero has iniciado sesion...
     if($mybb->user['uid'] != $post['uid'])
       {

    $thx_user = $mybb->user['uid'];

	$query=$db->query("SELECT th.txid, th.uid, th.adduid, th.pid, th.time, u.username, u.usergroup, u.displaygroup, u.avatar
		FROM ".TABLE_PREFIX."thx th
		JOIN ".TABLE_PREFIX."users u
		ON th.adduid=u.uid
		WHERE th.pid='$post[pid]' AND th.adduid ='$thx_user'
		ORDER BY th.time ASC"
	);

	while($record = $db->fetch_array($query))
	{
	if($record['adduid'] == $mybb->user['uid'])
	{
    // Si no eres el autor del tema pero has agradecido
    $message = preg_replace("#\[oculto\](.*?)\[/oculto\]#is","<div style=\"padding: 5px; padding-top: 8px; border: 1px solid #000080; background: #f5f5f5; color:#B22222; border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; webkit-border-radius: 4px\"><b>Contenido: </b><Font Color=\"Black\">$1</Font></div>",$message);
	}
	else
	{
    // Si aun no agradeces, ni eres el autor del tema, ni nada....
    $message = preg_replace("#\[oculto\](.*?)\[/oculto\]#is","<div style=\"padding: 5px; padding-top: 8px; border: 1px solid #000080; background: #f5f5f5; color:#B22222; border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; webkit-border-radius: 4px\"><center><b>Debes agradecer para ver el Contenido</b></center></div>",$message);
	}
    }
    // Si no eres el autor del tema, aun no as agradecido.
    $message = preg_replace("#\[oculto\](.*?)\[/oculto\]#is","<div style=\"padding: 5px; padding-top: 8px; border: 1px solid #000080; background: #f5f5f5; color:#B22222; border-radius: 4px; -moz-border-radius: 4px; -ms-border-radius: 4px; webkit-border-radius: 4px\"><center><b>Debes agradecer para ver el Contenido</b></center></div>",$message);
    }

}

function thx_quote(&$quoted_post)
{

    global $mybb, $session, $templates, $lang;

    if (!$mybb->settings['thx_hidesystem']  || !empty($session->is_spider))
        {
          return false;
        }

    $quoted_post['message'] = preg_replace('#(http://)([a-zA-Z0-9-]+)\.(([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]{2,})#i', "", $quoted_post['message']);
    $quoted_post['message'] = preg_replace("#\[oculto\](.*?)\[/oculto\]#is", "", $quoted_post['message']);

}

function thx(&$post)
{
	global $db, $mybb, $lang ,$session, $theme, $altbg, $templates, $thx_cache;
	
	if(!$mybb->settings['thx_active'] || !empty($session->is_spider))
	{
		return false;
	}

	if ($mybb->settings['thx_hidesystem'] != 0)

	{

	$lang->load("thx");

	if($b = $post['pthx'])
	{
		$entries = build_thank($post['pid'], $b);
	}
	else
	{
		$entries = "";
	}

 	if($mybb->user['uid'] != 0 && $mybb->user['uid'] != $post['uid'])
	{
		if(!$b)
		{
			$post['thanks'] = "<span class=\"botones\"><a id=\"a{$post['pid']}\" onclick=\"javascript:return thx({$post['pid']});\" href=\"showthread.php?action=thank&tid={$post['tid']}&pid={$post['pid']}\" class=\"positivo\">
			<img src=\"{$mybb->settings['bburl']}/{$theme['imgdir']}/postbit_thx.gif\" border=\"0\" alt=\"$lang->thx_main\" title=\"$lang->thx_main\" id=\"i{$post['pid']}\" /></a></span>";
		}
		else if($mybb->settings['thx_del'] == "1")
		{
			$post['thanks'] = "<span class=\"botones\"><a id=\"a{$post['pid']}\" onclick=\"javascript:return rthx({$post['pid']});\" href=\"showthread.php?action=remove_thank&tid={$post['tid']}&pid={$post['pid']}\" class=\"negativo\">
			<img src=\"{$mybb->settings['bburl']}/{$theme['imgdir']}/postbit_rthx.gif\" border=\"0\" alt=\"$lang->thx_remove\" title=\"$lang->thx_remove\" id=\"i{$post['pid']}\" /></a></span>";
		}
		else
		{
			$post['thanks'] = "<!-- No se permiten remover agradecimientos por el administrador del foro -->";
		}
	}
    }
	
	$display_style = $entries ?  "" : "display:none; border:0;";
	$playout = $mybb->settings['postlayout'];
	
	if(!$mybb->settings['thx_outline'])
	{
		eval("\$post['thxdsp_inline'] .= \"".$templates->get("thanks_postbit_inline")."\";");
									
		if($mybb->settings['thx_autolayout'] && $playout == "classic")
		{
			eval("\$post['thxdsp_inline'] .= \"".$templates->get("thanks_postbit_inline_classic")."\";");
		}
	}
	else
	{	
		eval("\$post['thxdsp_outline'] .= \"".$templates->get("thanks_postbit_outline")."\";");
	}
	
	if($mybb->settings['thx_count'] == "1")
	{
		if(!isset($thx_cache['postbit'][$post['uid']]))
		{
			$post['thank_count'] = $post['thx'];
			$post['thanked_count'] = $lang->sprintf($lang->thx_thanked_count, $post['thxcount'], $post['thxpost']);
			eval("\$x = \"".$templates->get("thanks_postbit_count")."\";");
			$thx_cache['postbit'][$post['uid']] = $x;
		}
		
		$post['user_details'] .= $thx_cache['postbit'][$post['uid']];
	}
}

function do_action()
{
	global $mybb, $lang, $theme;
	
	if(($mybb->input['action'] != "thankyou"  &&  $mybb->input['action'] != "remove_thankyou") || $mybb->request_method != "post")
	{
		return false;
	}
		
	if(file_exists($lang->path."/".$lang->language."/thx.lang.php"))	
	{
		$lang->load("thx");
	}
	else 
	{
		$l = $lang->language;
		$lang->set_language();
		$lang->load("thx");
		$lang->set_language($l);
	}
	
	$pid = intval($mybb->input['pid']);
	
	if ($mybb->input['action'] == "thankyou" )
	{
		do_thank($pid);
	}
	else if($mybb->settings['thx_del'] == "1")
	{
		del_thank($pid);
	}
	
	$nonead = 0;
	$list = build_thank($pid, $nonead);
	header('Content-Type: text/xml');
	$output = "<thankyou>
				<list><![CDATA[$list]]></list>
				<display>".($list ? "1" : "0")."</display>
				<image>{$mybb->settings['bburl']}/{$theme['imgdir']}/";
	
	if($mybb->input['action'] == "thankyou")
	{
		$output .= "postbit_rthx.gif";
	}
	else
	{
		$output .= "postbit_thx.gif";
	}
	
	$output .= "</image>
			  <del>{$mybb->settings['thx_del']}</del>	
			 </thankyou>";
	echo $output;
}

function direct_action()
{
	global $mybb, $lang;
	
	if($mybb->input['action'] != "thank"  &&  $mybb->input['action'] != "remove_thank")
	{
		return false;
	}
		
	if(file_exists($lang->path."/".$lang->language."/thx.lang.php"))	
	{
		$lang->load("thx");
	}
	else 
	{
		$l = $lang->language;
		$lang->set_language();
		$lang->load("thx");
		$lang->set_language($l);
	}
	$pid=intval($mybb->input['pid']);
	
	if($mybb->input['action'] == "thank" )
	{
		do_thank($pid);
	}
	else if($mybb->settings['thx_del'] == "1")
	{
		del_thank($pid);
	}
	redirect($_SERVER['HTTP_REFERER']);
}

function build_thank(&$pid, &$is_thx)
{
	global $db, $mybb, $lang, $thx_cache, $message;
	$is_thx = 0;
	
	$pid = intval($pid);
	
	if(file_exists($lang->path."/".$lang->language."/thx.lang.php"))
	{
		$lang->load("thx");
	}
	else
	{
		$l=$lang->language;
		$lang->set_language();
		$lang->load("thx");
		$lang->set_language($l);
	}
	$dir = $lang->thx_dir;
	
	$query=$db->query("SELECT th.txid, th.uid, th.adduid, th.pid, th.time, u.username, u.usergroup, u.displaygroup, u.avatar
		FROM ".TABLE_PREFIX."thx th
		JOIN ".TABLE_PREFIX."users u
		ON th.adduid=u.uid
		WHERE th.pid='$pid'
		ORDER BY th.time ASC"
	);

	while($record = $db->fetch_array($query))
	{
		if($record['adduid'] == $mybb->user['uid'])
		{
			$is_thx++;
		}
		$date = my_date($mybb->settings['dateformat'].' '.$mybb->settings['timeformat'], $record['time']);
		if(!isset($thx_cache['showname'][$record['username']]))
		{
			$url = get_profile_link($record['adduid']);
			$name = format_name($record['username'], $record['usergroup'], $record['displaygroup']);
            $avatar = $record['avatar'];
            if($avatar != '')
            {
			$thx_cache['showname'][$record['username']] = "<a href=\"$url\" dir=\"$dir\"><img src=\"$avatar\" style=\"width: 19px; height: 19px; border-style: double; color: #D8DFEA; padding: 2px; background-color: #FCFDFD; border-radius: 4px; -ms-border-radius: 4px; -moz-border-radius: 4px; webkit-border-radius: 4px;\"> $name</a>";
            }
            else
            {
            $thx_cache['showname'][$record['username']] = "<a href=\"$url\" dir=\"$dir\"><img src=\"images/default_avatar.gif\" style=\"width: 19px; height: 19px; border-style: double; color: #D8DFEA; padding: 2px; background-color: #FCFDFD; border-radius: 4px; -ms-border-radius: 4px; -moz-border-radius: 4px; webkit-border-radius: 4px;\">$name</a>";
            }
		}

		if($mybb->settings['thx_hidemode'])
		{
			$entries .= $r1comma." <span title=\"".$date."\">".$thx_cache['showname'][$record['username']]."</span>";
		}
		else
		{
			$entries .= $r1comma.$thx_cache['showname'][$record['username']]." <span class=\"smalltext\">(".$date.")</span>";
		}
		
		$r1comma = $lang->thx_comma;
	}
	
	return $entries;
}

function do_thank(&$pid)
{
	global $db, $mybb;
	
	$pid = intval($pid);
	
	$check_query = $db->simple_select("thx", "count(*) as c" ,"adduid='{$mybb->user['uid']}' AND pid='$pid'", array("limit"=>"1"));
			
	$tmp=$db->fetch_array($check_query);
	if($tmp['c'] != 0)
	{
		return false;
	}
		
	$check_query = $db->simple_select("posts", "uid", "pid='$pid'", array("limit"=>1));
	if($db->num_rows($check_query) == 1)
	{
		
		$tmp=$db->fetch_array($check_query);
		
		if($tmp['uid'] == $mybb->user['uid'])
		{
			return false;
		}		
			
		$database = array (
			"uid" =>$tmp['uid'],
			"adduid" => $mybb->user['uid'],
			"pid" => $pid,
			"time" => time()
		);
		
		$time = time();		
		
		$sq = array (
			"UPDATE ".TABLE_PREFIX."users SET thx=thx+1 WHERE uid='{$mybb->user['uid']}' LIMIT 1",
			"UPDATE ".TABLE_PREFIX."users SET thxcount=thxcount+1, reputation = reputation+1,thxpost=CASE( SELECT COUNT(*) FROM ".TABLE_PREFIX."thx WHERE pid='{$pid}' LIMIT 1) WHEN 0 THEN thxpost+1 ELSE thxpost END WHERE uid='{$database['uid']}' LIMIT 1",			
			"UPDATE ".TABLE_PREFIX."posts SET pthx=pthx+1 WHERE pid='{$pid}' LIMIT 1",
            "INSERT INTO ".TABLE_PREFIX."reputation (uid, adduid, pid, reputation, dateline, comments) VALUES ('{$tmp['uid']}', '{$mybb->user['uid']}', '{$pid}', 1, '{$time}', 'Gracias por el aporte')"
		);
			
		
	    unset($tmp);
				  
		foreach($sq as $q)
		{
			$db->query($q);
		}
		$db->insert_query("thx", $database);
	}	
}

function del_thank(&$pid)
{
	global $mybb, $db;
	
	$pid = intval($pid);
	if($mybb->settings['thx_del'] != "1")
	{
		return false;
	}

	$check_query = $db->simple_select("thx", "`uid`, `txid`" ,"adduid='{$mybb->user['uid']}' AND pid='$pid'", array("limit"=>"1"));		
	
	if($db->num_rows($check_query))
	{
		$data = $db->fetch_array($check_query);
		$uid = intval($data['uid']);
		$thxid = intval($data['txid']);
		unset($data);
		
		$time = time();
		
		$sq = array (
			"UPDATE ".TABLE_PREFIX."users SET thx=thx-1 WHERE uid='{$mybb->user['uid']}' LIMIT 1",
			"UPDATE ".TABLE_PREFIX."users SET thxcount=thxcount-1, reputation=reputation-1, thxpost=CASE(SELECT COUNT(*) FROM ".TABLE_PREFIX."thx WHERE pid='{$pid}' LIMIT 1) WHEN 0 THEN thxpost-1 ELSE thxpost END WHERE uid='{$uid}' LIMIT 1",
			"UPDATE ".TABLE_PREFIX."reputation SET reputation='0', dateline='{$time}', comments='Desagradecer el aporte' WHERE adduid='{$mybb->user['uid']}' && pid='{$pid}' LIMIT 1",			
			"UPDATE ".TABLE_PREFIX."posts SET pthx=pthx-1 WHERE pid='{$pid}' LIMIT 1"
		);
		
		$db->delete_query("thx", "txid='{$thxid}'", "1");
		
		foreach($sq as $q)
		{
			$db->query($q);
		}
	}
}

function deletepost_edit(&$pid)
{
	global $db;
	
	$pid = intval($pid);
	$q = $db->simple_select("thx", "uid, adduid", "pid='{$pid}'");
	
	$postnum = $db->num_rows($q);
	if($postnum <= 0)
	{
		return false;
	}
	
	$adduids = array();
	
	while($r = $db->fetch_array($q))
	{
		$uid = intval($r['uid']);
		$adduids[] = $r['adduid'];
	}
	
	$adduids = implode(", ", $adduids);
	
	$sq = array();
	$sq[] = "UPDATE ".TABLE_PREFIX."users SET thxcount=thxcount-1, thxpost=thxpost-1 WHERE uid='{$uid}'";
	$sq[] = "UPDATE ".TABLE_PREFIX."users SET thx=thx-1 WHERE uid IN ({$adduids})";
	
	foreach($sq as $q)
	{
		$db->query($q);
	}
	
	$db->delete_query("thx", "pid={$pid}", $postnum);
	
}

function thx_admin_action(&$action)
{
	$action['recount_thanks'] = array ('active'=>'recount_thanks');
}

function thx_admin_menu(&$sub_menu)
{
	$sub_menu['45'] = array	(
		'id'	=> 'recount_thanks',
		'title'	=> 'Recontar Agradecimientos',
		'link'	=> 'index.php?module=tools/recount_thanks'
	);
}

function thx_admin_permissions(&$admin_permissions)
{
	$admin_permissions['recount_thanks'] = 'Puede recontar agradecimientos';
}

function thx_admin()
{
	global $mybb, $page, $db;
	require_once MYBB_ROOT.'inc/functions_rebuild.php';
	if($page->active_action != 'recount_thanks')
	{
		return false;
	}

	if($mybb->request_method == "post")
	{
		if(!isset($mybb->input['page']) || intval($mybb->input['page']) < 1)
		{
			$mybb->input['page'] = 1;
		}
		if(isset($mybb->input['do_recountthanks']))
		{
			if(!intval($mybb->input['thx_chunk_size']))
			{
				$mybb->input['thx_chunk_size'] = 500;
			}

			do_recount();
		}
		else if(isset($mybb->input['do_recountposts']))
		{
			if(!intval($mybb->input['post_chunk_size']))
			{
				$mybb->input['post_chunk_size'] = 500;
			}

			do_recount_post();
		}
	}

	$page->add_breadcrumb_item('Recount thanks', "index.php?module=tools/recount_thanks");
	$page->output_header('Reconteo de Agradecimientos');

	$sub_tabs['thankyoulike_recount'] = array(
		'title'			=> 'Recontar Agradecimientos',
		'link'			=> "index.php?module=tools/recount_thanks",
		'description'	=> 'Actualizar el conteo de los agradecimientos'
	);

	$page->output_nav_tabs($sub_tabs, 'thankyoulike_recount');

	$form = new Form("index.php?module=tools/recount_thanks", "post");

	$form_container = new FormContainer('Recontar Agradecimientos');
	$form_container->output_row_header('Tarea');
	$form_container->output_row_header('Env&iacute;os/Ciclo', array('width' => 50));
	$form_container->output_row_header("&nbsp;");

	$form_container->output_cell("<label>Actualizar contador de agradecimientos</label>
	<div class=\"description\">Actualiza los agradecimientos dados/recibidos por los usuarios individuales y por temas.</div>");
	$form_container->output_cell($form->generate_text_box("thx_chunk_size", 100, array('style' => 'width: 150px;')));
	$form_container->output_cell($form->generate_submit_button('Actualizar', array("name" => "do_recountthanks")));
	$form_container->construct_row();

	$form_container->output_cell("<label>Actualizar contadores</label>
	<div class=\"description\">Actualiza los temas donde se han recibido agradecimientos.</div>");
	$form_container->output_cell($form->generate_text_box("post_chunk_size", 500, array('style' => 'width: 150px;')));
	$form_container->output_cell($form->generate_submit_button('Actualizar', array("name" => "do_recountposts")));
	$form_container->construct_row();

	$form_container->end();

	$form->end();

	$page->output_footer();

	exit;
}

function do_recount()
{
	global $db, $mybb;

	$cur_page = intval($mybb->input['page']);
	$per_page = intval($mybb->input['thx_chunk_size']);
	$start = ($cur_page-1) * $per_page;
	$end = $start + $per_page;

	if ($cur_page == 1)
	{
		$db->write_query("UPDATE ".TABLE_PREFIX."users SET thx='0', thxcount='0'");
		$db->write_query("UPDATE ".TABLE_PREFIX."posts SET pthx='0'");
	}

	$query = $db->simple_select("thx", "COUNT(txid) AS thx_count");
	$thx_count = $db->fetch_field($query, 'thx_count');

	$query = $db->query("
		SELECT uid, adduid, pid
		FROM ".TABLE_PREFIX."thx
		ORDER BY time ASC
		LIMIT $start, $per_page
	");

	$post_thx = array();
	$user_thx = array();
	$user_thx_to = array();

	while($thx = $db->fetch_array($query))
	{
		if($post_thx[$thx['pid']])
		{
			$post_thx[$thx['pid']]++;
		}
		else
		{
			$post_thx[$thx['pid']] = 1;
		}
		if($user_thx[$thx['adduid']])
		{
			$user_thx[$thx['adduid']]++;
		}
		else
		{
			$user_thx[$thx['adduid']] = 1;
		}
		if($user_thx_to[$thx['uid']])
		{
			$user_thx_to[$thx['uid']]++;
		}
		else
		{
			$user_thx_to[$thx['uid']] = 1;
		}
	}

	if(is_array(&$post_thx))
	{
		foreach($post_thx as $pid => $change)
		{
			$db->write_query("UPDATE ".TABLE_PREFIX."posts SET pthx=pthx+$change WHERE pid='$pid'");
		}
	}
	if(is_array(&$user_thx))
	{
		foreach($user_thx as $adduid => $change)
		{
			$db->write_query("UPDATE ".TABLE_PREFIX."users SET thx=thx+$change WHERE uid='$adduid'");
		}
	}
	if(is_array(&$user_thx_to))
	{
		foreach($user_thx_to as $uid => $change)
		{
			$db->write_query("UPDATE ".TABLE_PREFIX."users SET thxcount=thxcount+$change WHERE uid='$uid'");
		}
	}
	my_check_proceed($thx_count, $end, $cur_page+1, $per_page, "thx_chunk_size", "do_recountthanks", "Se ha actualizado el conteo de agradecimientos con exito");
}

function do_recount_post()
{
	global $db, $mybb;

	$cur_page = intval($mybb->input['page']);
	$per_page = intval($mybb->input['post_chunk_size']);
	$start = ($cur_page-1) * $per_page;
	$end = $start + $per_page;

	if ($cur_page == 1)
	{
		$db->write_query("UPDATE ".TABLE_PREFIX."users SET thxpost='0'");
	}

	$query = $db->simple_select("thx", "COUNT(distinct pid) AS post_count");
	$post_count = $db->fetch_field($query, 'post_count');

	$query = $db->query("
		SELECT uid, pid
		FROM ".TABLE_PREFIX."thx
		GROUP BY pid
		ORDER BY pid ASC
		LIMIT $start, $per_page
	");

	while($thx = $db->fetch_array($query))
	{
		$db->write_query("UPDATE ".TABLE_PREFIX."users SET thxpost=thxpost+1 WHERE uid='{$thx['uid']}'");
	}

	my_check_proceed($post_count, $end, $cur_page+1, $per_page, "post_chunk_size", "do_recountposts", "Se ha actualizado el conteo de agradecimientos en temas");
}

function my_check_proceed($current, $finish, $next_page, $per_page, $name_chunk, $name_submit, $message)
{
	global $page;

	if($finish >= $current)
	{
		flash_message($message, 'success');
		admin_redirect("index.php?module=tools/recount_thanks");
	}
	else
	{
		$page->output_header();

		$form = new Form("index.php?module=tools/recount_thanks", 'post');

		echo $form->generate_hidden_field("pag", $next_page);
		echo $form->generate_hidden_field($name_chunk, $per_page);
		echo $form->generate_hidden_field($name_submit, "Actualizar");
		echo "<div class=\"confirm_action\">\n";
		echo "<p>Clic en \"Continuar\"para hacer el conteo de los agradecimientos.</p>\n";
		echo "<p>Despues de haber cargado la pagina por completo de clic de nuevo en continuar para ver su consulta con exito.</p>\n";
		echo "<br />\n";
		echo "<p class=\"buttons\">\n";
		echo $form->generate_submit_button("Continuar", array('class' => 'button_yes'));
		echo "</p>\n";
		echo "</div>\n";

		$form->end();

		$page->output_footer();
		exit;
	}
}

?>


me ayudas a reducir el codigo Smile quitar eso del hide y todo eso
Última modificación: 3 May, 2012, 1:09 pm por Lectro.
Que es exactamente lo que quiere? Que los usuarios den gracias en los mensajes (con permisos para foro y grupos) y que se muestre debajo de cada mensaje la lista de usuarios que han dado gracias?

Sin ajax, sin caracteristicas de perfil, etc...?

En ese caso seria mejor y quizas mas facil escribir tu propio plugin.
Omar G.
hola bueno aclaro lo que qero Smile

[Imagen: foto.jpg]

en el plugin download quiero agregar un sistema basico de agradecimiento por archivo subido.

qe sea como en la imagen nada mas Smile

mira para ser mas especifico no qero hacer spam o nose pero la pagina --- tiene un sistema de gracias en cada post eso qero ponerlo en el plugin download Big Grin seria el mas feliz llevo dos dias intentando jaaj
para hacer la modificacion necesitas mas que una simple ayuda si eres novato en PHP perdoname pero la verdad veo imposible que lo hagas peus debes saber subir datos a la DB, mostrarlos y de MINIMO concimientos basicos en lenguaje PHP... porque no pides alguien que sepa que lo haga por ti? (sama, himura, cluster, yo) claro... estando consiente que podrian cobrarte por ello pues es algo como 'privado' para tu foro!
Colaboradores
Omar G. Edson Ordaz Cluster
This forum uses Lukasz Tkacz MyBB addons.