<?php
/*
*
*
*	Dile no a la ley SOPA y Similares, que busquen proteger los interes de las grandes corporaciones y matar al pueblo
*	A pesar de ser pobre te doy mi trabajo gratis y con derechos, porque ellos no pueden buscar una forma mejor de hacer negocios 
*	y prefieren explotar al pueblo... y controlar a los politicos con dinero, gracias por todos estos aņos y visitanos en mybb-es.com
*	mientras sigamos siendo libres...
*
*	Actulizacion 1.3 - proteccion contra sql injection...
*
*
*/
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("postbit", "tedsc_thpost");
$plugins->add_hook("postbit_prev", "tedsc_thpostprev");
$plugins->add_hook("newthread_start", "tedsc_newthread");
$plugins->add_hook("newthread_do_newthread_start", "tedsc_send");
$plugins->add_hook("datahandler_post_insert_thread_post", "tedsc_insert");
$plugins->add_hook("editpost_start", "tedsc_edit");
$plugins->add_hook("editpost_do_editpost_start", "tedsc_do_edit");
function tedsc_info()
{
global $lang;
	$lang->load("tedsc");
	return array(
		"name"			=> $lang->name,
		"description"	=> $lang->desc,
		"website"		=> "http://mybb-es.com",
		"author"		=> "Himura",
		"authorsite"	=> "http://mybb-es.com/member.php?action=profile&uid=501",
		"version"		=> "1.3",
		"guid" 			=> "112457de63fecb2ea90f939c8f83e942",
		"compatibility" => "*"
	);
}
function tedsc_activate()
{
global $db, $mybb;
$db->query("ALTER TABLE ".TABLE_PREFIX."threads ADD threadsdesc VARCHAR(101) NOT NULL default ''");
require_once MYBB_ROOT.'/inc/adminfunctions_templates.php';
$reemplase1='tabindex="1" /></td>
</tr><tr><td class="trow2" width="20%"><strong>{$lang->descbox}</strong></td>
<td class="trow2"><input type="text" class="textbox" name="threadsdesc" size="57" maxlength="100" value="{$descr}" /></td></tr>';
find_replace_templatesets('newthread','#tabindex="1" /></td>\n</tr>#i',$reemplase1);
find_replace_templatesets("editpost", '#tabindex="1" /></td>\n</tr>#i', 'tabindex="1" /></td>
</tr>{$tdescbox}');
find_replace_templatesets("forumdisplay_thread", '#'.preg_quote('{$thread[\'multipage\']}</span>').'#', '{$thread[\'multipage\']}</span><div><span class="smalltext">{$thread[\'threadsdesc\']}</span></div>');
find_replace_templatesets("search_results_threads_thread", '#'.preg_quote('{$thread[\'multipage\']}</span>').'#', '{$thread[\'multipage\']}</span><div><span class="smalltext">{$thread[\'threadsdesc\']}</span></div>');
find_replace_templatesets("postbit", '#'.preg_quote('{$post[\'subject_extra\']}</strong></span>').'#', '{$post[\'subject_extra\']}</strong>{$post[\'threadsdesc\']}</span>');
find_replace_templatesets("postbit_classic", '#'.preg_quote('{$post[\'subject_extra\']}</strong></span>').'#', '{$post[\'subject_extra\']}</strong>{$post[\'threadsdesc\']}</span>');
}
function tedsc_deactivate()
{
global $db, $mybb;
$db->query("ALTER TABLE ".TABLE_PREFIX."threads DROP threadsdesc");
require_once MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets('newthread','#<tr><td class="trow2" width="20%"><strong>{\$lang->descbox}</strong></td>\n<td class="trow2"><input type="text" class="textbox" name="threadsdesc" size="57" maxlength="100" value="{\$descr}" /></td></tr>#i','');
find_replace_templatesets('editpost','#{\$tdescbox}#i','');
find_replace_templatesets("forumdisplay_thread", '#'.preg_quote('<div><span class="smalltext">{$thread[\'threadsdesc\']}</span></div>').'#', '', 0);
find_replace_templatesets("search_results_threads_thread", '#'.preg_quote('<div><span class="smalltext">{$thread[\'threadsdesc\']}</span></div>').'#', '', 0);
find_replace_templatesets("postbit", '#'.preg_quote('{$post[\'threadsdesc\']}').'#', '', 0);
find_replace_templatesets("postbit_classic", '#'.preg_quote('{$post[\'threadsdesc\']}').'#', '', 0);
}
function tedsc_thpostprev(&$post)
{
global $mybb;
$post['threadsdesc']=" - ".$mybb->input['threadsdesc']."";
}
function tedsc_thpost(&$post)
{
global $db;
if($post['replyto']==0)
{
$consulta=$db->query("SELECT threadsdesc FROM ".TABLE_PREFIX."threads WHERE tid=".$post[tid]."");
$tdesc=$db->fetch_array($consulta);
if($tdesc['threadsdesc'])
{
$post['threadsdesc']=" - ".$tdesc['threadsdesc']."<meta name='description' content='".$tdesc['threadsdesc']."' />";
}
$db->free_result($consulta);
}
}
function tedsc_newthread()
{
global $mybb, $descr, $lang;
$lang->load("tedsc");
$descr = $mybb->input['threadsdesc'];
}
function tedsc_send()
{
global $mybb, $cache;
$cache->update("threadsdesc_".$mybb->user['uid']."", $mybb->input['threadsdesc']);
}
function tedsc_insert(&$insert)
{
    global $db, $mybb, $cache;    
	$threadsdesc=$db->escape_string($cache->read("threadsdesc_".$mybb->user['uid'].""));
	$threadsdesc=$cache->read("threadsdesc_".$mybb->user['uid']."");
	$db->query("UPDATE ".TABLE_PREFIX."threads SET threadsdesc='".$threadsdesc."' WHERE tid=".$insert->tid."");
	$db->query("DELETE FROM ".TABLE_PREFIX."datacache WHERE title='threadsdesc_".$mybb->user['uid']."'");
}
function tedsc_edit()
{
global $descr, $db, $tdescbox, $lang, $mybb;
$lang->load("tedsc");
$consulta=$db->query("SELECT tid, replyto, pid FROM ".TABLE_PREFIX."posts WHERE pid='".$mybb->input['pid']."'");
$result=$db->fetch_array($consulta);
if($result['replyto']==0)
{
$consulta2=$db->query("SELECT tid, threadsdesc FROM ".TABLE_PREFIX."threads WHERE tid='".$result['tid']."'");
$res=$db->fetch_array($consulta2);
$descr=$res['threadsdesc'];
if($mybb->input['processed']==1)
{
$descr=$mybb->input['threadsdesc'];
}
$tdescbox="<tr><td class='trow2' width='20%'><strong>{$lang->descbox}</strong></td>
<td class='trow2'><input type='text' class='textbox' name='threadsdesc' size='57' maxlength='100' value='{$descr}' /></td></tr>";
$db->free_result($consulta2);
}
$db->free_result($consulta);
}
function tedsc_do_edit()
{
global $mybb, $post, $db;
if($post['replyto']==0)
{
$db->query("UPDATE ".TABLE_PREFIX."threads SET threadsdesc='".$db->escape_string($mybb->input['threadsdesc'])."' WHERE tid='".$post['tid']."'");
}
}
?>