Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/mybb-es.com/html/inc/class_language.php on line 201
Hooks
pipotalamo   5 May, 2012, 12:39 pm
#1
hola bueno vengo con una nueva preguntita Smile bueno e estado estudiando php y por lo que e visto en mybb los hooks son los ganchos repartidos por todo los archivos del foro que sirven para modificar alguna funcion.

mi pregunta es la siguiente:

como crear hooks o cual es el codigo basico para empezar con uno.
Cluster   5 May, 2012, 12:48 pm
#2
en la wiki de MyBB esta una lista de TODOS los hooks comunes (los del sistema)
http://wiki.mybb.com/index.php/MyBB_Plugin_Hooks

para armar un hook necesitas saber en que archivo y en que parte se reproducira tu funcion y despues armas asi por ejemplo
Código PHP:
<?php 
$plugins
->add_hook("showthread_start", "elnombredemifuncion");

y la funcion se llamaria
Código PHP:
<?php 
function elnombredemifuncion()
{
aqui el contenido de mi funcion
}


espero haya quedado entendible Wink

:)
Edson Ordaz   5 May, 2012, 1:00 pm
#3
creo que dste la respuesta equivocada cluster...
te lodigo porque recuerdo que el usuario quiere thanks en downloads y le dijieron que el downloads no crea hooks entonces por tanto quiere crear hooks en el para usarlos desde un plugin entonces es igual de facil...

por ejemplo para crear un simple hook es de la siguiente forma
Código PHP:
<?php 
$plugins
->run_hooks("nombre_del_hook");

y tambien otro que es asi
Código PHP:
<?php 
$plugins
->run_hooks("nombre_del_hook", $variable_o_array);

cuando es asi regularmente en un array tienes que llamar a tu funcion de la siguiente forma

Código PHP:
<?php 
function nombre_del_hook(&$variable_o_array)
{
}

y dentro de la funcion manejas $variable_o_array como quieras (cuando es array)!!!
pipotalamo   5 May, 2012, 3:04 pm
#4
muchas gracias por las respuestas como dice Edson yo agrege:
a download.php

Código PHP:
<?php 
$plugins
->run_hooks("download_archive", $archive);

y en thx del plugin agrege:

Código PHP:
<?php 
$plugins
->add_hook("download_archive", "thx");

y luego en el plugin thanx deje abajo la funcion:

Código PHP:
<?php 
function thx(&$archive)
{
global
$db, $mybb, $lang ,$session, $theme, $altbg, $templates, $thx_cache;

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

$lang->load("thx");

if(
$b = $archive['dthx'])
{
$entries = build_thank($archive['did'], $b);
}
else
{
$entries = "";
}

if(
$mybb->user['uid'] != 0 && $mybb->user['uid'] != $archive['uid'])
{
if(!
$b)
{
$archive['thanks'] = "<a id=\"a{$archive['did']}\" onclick=\"javascript:return thx({$archive['did']});\" href=\"showthread.php?action=thank&did={$archive['did']}\">
<img src=\"
{$mybb->settings['bburl']}/{$theme['imgdir']}/postbit_thx.gif\" border=\"0\" alt=\"$lang->thx_main\" title=\"$lang->thx_main\" id=\"i{$archive['did']}\" /></a>";
}
else if(
$mybb->settings['thx_del'] == "1")
{
$archive['thanks'] = "<a id=\"a{$archive['did']}\" onclick=\"javascript:return rthx({$archive['did']});\" href=\"showthread.php?action=remove_thank&did={$archive['did']}\">
<img src=\"
{$mybb->settings['bburl']}/{$theme['imgdir']}/postbit_rthx.gif\" border=\"0\" alt=\"$lang->thx_remove\" title=\"$lang->thx_remove\" id=\"i{$archive['did']}\" /></a>";
}
else
{
$archive['thanks'] = "<!-- remove thanks disabled by administrator -->";
}
}

$display_style = $entries ? "" : "display:none; border:0;";
$playout = $mybb->settings['postlayout'];

if(!
$mybb->settings['thx_outline'])
{
eval(
"\$archive['thxdsp_inline'] .= \"".$templates->get("thanks_postbit_inline")."\";");

}
else
{
eval(
"\$archive['thxdsp_outline'] .= \"".$templates->get("thanks_postbit_outline")."\";");
}

if(
$mybb->settings['thx_count'] == "1")
{
if(!isset(
$thx_cache['postbit'][$archive['uid']]))
{
$archive['thank_count'] = $archive['thx'];
$archive['thanked_count'] = $lang->sprintf($lang->thx_thanked_count, $archive['thxcount'], $archive['thxdownload']);
eval(
"\$x = \"".$templates->get("thanks_postbit_count")."\";");
$thx_cache['postbit'][$archive['uid']] = $x;
}

$archive['user_details'] .= $thx_cache['postbit'][$archive['uid']];
}
}



pero no aparece nada Sad bueno les dejo el thx plugin como lo modifique:

Código PHP:
<?php
/*

Plugin Thanks 3.9.1
(c) 2008-2011 by Huji Lee, SaeedGh (SaeehGhMail@Gmail.com)
Last edit: 11-26-2011

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/>.

*/

if(!defined("IN_MYBB"))
{
die(
"Direct initialization of this file is not allowed.");
}

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

$plugins->add_hook("download_archive", "thx");
$plugins->add_hook("xmlhttp", "do_action");
$plugins->add_hook("download", "direct_action");

function
thx_info()
{
return array(
'name' => '<img border="0" src="../images/Thanks.gif" align="absbottom" alt="" /> Thanks',
'description' => 'Add a Thanks button to user posts.',
'website' => 'http://www.mybb.com',
'author' => 'Huji Lee, SaeedGh',
'authorsite' => 'mailto:SaeedGhMail@Gmail.com',
'version' => '3.9.1',
'guid' => 'd82cb3ceedd7eafa8954449cd02a449f',
'compatibility' => '14*,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,
did int(10) UNSIGNED NOT NULL,
time bigint(30) NOT NULL DEFAULT '0',
PRIMARY KEY (`txid`),
INDEX (`adduid`, `did`, `time`)
);"
);

if(!
$db->field_exists("thx", "users"))
{
$sq[] = "ALTER TABLE ".TABLE_PREFIX."users ADD `thx` INT NOT NULL, ADD `thxcount` INT NOT NULL, ADD `thxdownload` INT NOT NULL";
}
elseif (!
$db->field_exists("thxdownload", "users"))
{
$sq[] = "ALTER TABLE ".TABLE_PREFIX."users ADD `thxdownload` INT NOT NULL";
}

if(
$db->field_exists("thx", "downloads"))
{
$sq[] = "ALTER TABLE ".TABLE_PREFIX."downloads DROP thx";
}

if(!
$db->field_exists("dthx", "downloads"))
{
$sq[] = "ALTER TABLE ".TABLE_PREFIX."downloads ADD `dthx` 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('thxdownload', "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`, `did`, `time`)");
}

//Adding templates
require MYBB_ROOT."inc/adminfunctions_templates.php";

find_replace_templatesets("downloads_archives_view", '#'.preg_quote('{$archive[\'downloads\']}</span></td>').'#', '{$archive[\'downloads\']}</span></td><!-- Downloads -->{\$archive[\'thxdsp_inline\']}{$archive[\'thxdsp_outline\']}<!-- /Downloads -->');
find_replace_templatesets("downloads_archives_view", '#'.preg_quote('{$username}').'#', '{$username}{$archive[\'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} {\$archive[\'thank_count\']}<br />
{\$archive[\'thanked_count\']}<br /></span></div>"
,
'sid' => '-1',
);
$db->insert_query("templates", $templatearray);

$templatearray = array(
'title' => 'thanks_postbit_inline',
'template' => "<table><tr id=\"thx{\$archive[\'did\']}\" 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{\$archive[\'did\']}\">\$entries</td></tr></table>",
'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{\$archive[\'did\']}\" style=\"{\$display_style};margin-top:5px;\"><tr><td>
<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/rose.gif\" align=\"absmiddle\" /> &nbsp;<span class=\"smalltext\">{\$lang->thx_givenby}</span></td><td class=\"trow2 tnx_style\" id=\"thx_list{\$archive[\'did\']}\">\$entries</td></tr></table>
</td></tr></table>"
,
'sid' => '-1',
);
$db->insert_query("templates", $templatearray);

$thx_group = array(
"name" => "Thanks",
"title" => "Thanks",
"description" => "Displays thank you note below each post.",
"disporder" => "3",
"isdefault" => "1"
);
$db->insert_query("settinggroups", $thx_group);
$gid = $db->insert_id();

$thx[]= array(
"name" => "thx_active",
"title" => "Activate/Deactivate this plugin",
"description" => "Activate or deactivate plugin but no delete table",
"optionscode" => "onoff",
"value" => '1',
"disporder" => '1',
"gid" => intval($gid),
);

$thx[] = array(
"name" => "thx_count",
"title" => "Show count thanks",
"description" => "Show count thanks in any post",
"optionscode" => "onoff",
"value" => '1',
"disporder" => '2',
"gid" => intval($gid),
);

$thx[] = array(
"name" => "thx_del",
"title" => "Users can remove their thanks",
"description" => "Every one can delete his thanks",
"optionscode" => "onoff",
"value" => '1',
"disporder" => '3',
"gid" => intval($gid),
);

$thx[] = array(
"name" => "thx_hidemode",
"title" => "Show date on mouse over",
"description" => "Show date of thanks just when mouse is over it",
"optionscode" => "onoff",
"value" => '1',
"disporder" => '4',
"gid" => intval($gid),
);

$thx[] = array(
"name" => "thx_autolayout",
"title" => "Auto detect layout",
"description" => "Detect postbit layout and try to correct related HTML code! (just works if \"Separate table\" is ON)",
"optionscode" => "onoff",
"value" => '1',
"disporder" => '5',
"gid" => intval($gid),
);

$thx[] = array(
"name" => "thx_outline",
"title" => "Separate table",
"description" => "If you want to show thanks between of tow post (not in end of a post), switch this option on.",
"optionscode" => "onoff",
"value" => '1',
"disporder" => '6',
"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('{$archive[\'thxdsp_inline\']}').'#', '', 0);
find_replace_templatesets("postbit", '#'.preg_quote('{$archive[\'thxdsp_outline\']}').'#', '', 0);
find_replace_templatesets("postbit", '#'.preg_quote('{$archive[\'thanks\']}').'#', '', 0);
find_replace_templatesets("postbit_classic", '#'.preg_quote('{$archive[\'thxdsp_inline\']}').'#', '', 0);
find_replace_templatesets("postbit_classic", '#'.preg_quote('{$archive[\'thxdsp_outline\']}').'#', '', 0);
find_replace_templatesets("postbit_classic", '#'.preg_quote('{$archive[\'thanks\']}').'#', '', 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')");
$db->delete_query("settinggroups", "name='Thanks'");
$db->delete_query("templates", "title='thanks_postbit_count'");
$db->delete_query("templates", "title='thanks_postbit_inline'");
$db->delete_query("templates", "title='thanks_postbit_outline'");

rebuild_settings();
}


function
thx_uninstall()
{
global
$db;

/*$db->query("drop TABLE ".TABLE_PREFIX."thx");*/

if($db->table_exists("thx"))
{
$db->drop_table("thx");
}
if(
$db->field_exists("thx", "users"))
{
$db->query("ALTER TABLE ".TABLE_PREFIX."users DROP thx, DROP thxcount, DROP thxdownload");
}

if(
$db->field_exists("dthx", "downloads"))
{
$db->query("ALTER TABLE ".TABLE_PREFIX."downloads DROP dthx");
}
}


function
thx(&$archive)
{
global
$db, $mybb, $lang ,$session, $theme, $altbg, $templates, $thx_cache;

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

$lang->load("thx");

if(
$b = $archive['dthx'])
{
$entries = build_thank($archive['did'], $b);
}
else
{
$entries = "";
}

if(
$mybb->user['uid'] != 0 && $mybb->user['uid'] != $archive['uid'])
{
if(!
$b)
{
$archive['thanks'] = "<a id=\"a{$archive['did']}\" onclick=\"javascript:return thx({$archive['did']});\" href=\"showthread.php?action=thank&did={$archive['did']}\">
<img src=\"
{$mybb->settings['bburl']}/{$theme['imgdir']}/postbit_thx.gif\" border=\"0\" alt=\"$lang->thx_main\" title=\"$lang->thx_main\" id=\"i{$archive['did']}\" /></a>";
}
else if(
$mybb->settings['thx_del'] == "1")
{
$archive['thanks'] = "<a id=\"a{$archive['did']}\" onclick=\"javascript:return rthx({$archive['did']});\" href=\"showthread.php?action=remove_thank&did={$archive['did']}\">
<img src=\"
{$mybb->settings['bburl']}/{$theme['imgdir']}/postbit_rthx.gif\" border=\"0\" alt=\"$lang->thx_remove\" title=\"$lang->thx_remove\" id=\"i{$archive['did']}\" /></a>";
}
else
{
$archive['thanks'] = "<!-- remove thanks disabled by administrator -->";
}
}

$display_style = $entries ? "" : "display:none; border:0;";
$playout = $mybb->settings['postlayout'];

if(!
$mybb->settings['thx_outline'])
{
eval(
"\$archive['thxdsp_inline'] .= \"".$templates->get("thanks_postbit_inline")."\";");

}
else
{
eval(
"\$archive['thxdsp_outline'] .= \"".$templates->get("thanks_postbit_outline")."\";");
}

if(
$mybb->settings['thx_count'] == "1")
{
if(!isset(
$thx_cache['postbit'][$archive['uid']]))
{
$archive['thank_count'] = $archive['thx'];
$archive['thanked_count'] = $lang->sprintf($lang->thx_thanked_count, $archive['thxcount'], $archive['thxdownload']);
eval(
"\$x = \"".$templates->get("thanks_postbit_count")."\";");
$thx_cache['postbit'][$archive['uid']] = $x;
}

$archive['user_details'] .= $thx_cache['postbit'][$archive['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);
}

$did = intval($mybb->input['did']);

if (
$mybb->input['action'] == "thankyou" )
{
do_thank($did);
}
else if(
$mybb->settings['thx_del'] == "1")
{
del_thank($did);
}

$nonead = 0;
$list = build_thank($did, $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);
}
$did=intval($mybb->input['did']);

if(
$mybb->input['action'] == "thank" )
{
do_thank($did);
}
else if(
$mybb->settings['thx_del'] == "1")
{
del_thank($did);
}
redirect($_SERVER['HTTP_REFERER']);
}

function
build_thank($did, &$is_thx)
{
global
$db, $mybb, $lang, $thx_cache;
$is_thx = 0;

$did = intval($did);

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.did, th.time, u.username, u.usergroup, u.displaygroup
FROM "
.TABLE_PREFIX."thx th
JOIN "
.TABLE_PREFIX."users u
ON th.adduid=u.uid
WHERE th.did='
$did'
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']);
$thx_cache['showname'][$record['username']] = "<a href=\"$url\" dir=\"$dir\">$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($did)
{
global
$db, $mybb;

$did = intval($did);

$check_query = $db->simple_select("thx", "count(*) as c" ,"adduid='{$mybb->user['uid']}' AND did='$did'", array("limit"=>"1"));

$tmp=$db->fetch_array($check_query);
if(
$tmp['c'] != 0)
{
return
false;
}

$check_query = $db->simple_select("downloads", "uid", "did='$did'", 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'],
"did" => $did,
"time" => time()
);

unset(
$tmp);

$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, thxdownload=CASE( SELECT COUNT(*) FROM ".TABLE_PREFIX."thx WHERE did='{$did}' LIMIT 1) WHEN 0 THEN thxdownload+1 ELSE thxdownload END WHERE uid='{$database['uid']}' LIMIT 1",
"UPDATE ".TABLE_PREFIX."downloads SET dthx=dthx+1 WHERE did='{$did}' LIMIT 1"
);

foreach(
$sq as $q)
{
$db->query($q);
}
$db->insert_query("thx", $database);
}
}

function
del_thank($did)
{
global
$mybb, $db;

$did = intval($did);
if(
$mybb->settings['thx_del'] != "1")
{
return
false;
}

$check_query = $db->simple_select("thx", "`uid`, `txid`" ,"adduid='{$mybb->user['uid']}' AND did='$did'", 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);

$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, thxdownload=CASE(SELECT COUNT(*) FROM ".TABLE_PREFIX."thx WHERE did='{$did}' LIMIT 1) WHEN 0 THEN thxdownload-1 ELSE thxdownload END WHERE uid='{$uid}' LIMIT 1",
"UPDATE ".TABLE_PREFIX."downloads SET dthx=dthx-1 WHERE did='{$did}' LIMIT 1"
);

$db->delete_query("thx", "txid='{$thxid}'", "1");

foreach(
$sq as $q)
{
$db->query($q);
}
}
}



?>
Edson Ordaz   5 May, 2012, 6:55 pm
#5
porque tu problema es este...
Código PHP:
<?php 
$plugins
->run_hooks("download_archive", $archive);

el archive para empezar existe en downloads?? porque ay lo que estas haciendo es tomar una variable ($archive) del downloads para poder usarla en la funcion...
pipotalamo   6 May, 2012, 5:33 pm
#6
mmm osea segun el plugin download la variable $archive (se le agrega siempre en los templates del plugin download y van asi ejemplo:$archive['image']}) si existe


yo solo agrege a downloads.php

Código PHP:
<?php 
$plugins
->run_hooks("download_archive", $archive);


y supuse que hay el hook estaba correcto para enganchar al thx

y asi

al agregar a la plantilla archive_view:

Código:
{$archive['thanks']}

saliera el thx pero no aparece Sad
Edson Ordaz   6 May, 2012, 6:58 pm
#7
Puedes poner el codigo donde corres el hook en el download?
pipotalamo   6 May, 2012, 7:34 pm
#8
el codigo de downloads.php

Código PHP:
<?php
/**
* MyBB 1.6
* Copyright 2011 Edson Ordaz, All Rights Reserved
*
* Email: nicedo_eeos@hotmail.com
* Downloads V2.0.1
*
* $Id: downloads.php 2011-06-22 Edson Ordaz $
*/

define("IN_MYBB", 1);
define('THIS_SCRIPT', 'downloads.php');
define('TABLE', 'downloads_');
define("KILL_GLOBALS", 1);
require_once
"./global.php";
$lang->load("downloads");

add_breadcrumb($lang->downloads, THIS_SCRIPT);

if(
$mybb->settings['downloads_active'] == 0)
{
error_no_permission();
exit;
}

if(
$mybb->input['newimages'])
{
$qdownloads = $db->simple_select('downloads', '*', 'did="'.$mybb->input['newimages'].'"');
$archive = $db->fetch_array($qdownloads);
$qcategory = $db->simple_select(TABLE.'cat', '*', 'dcid="'.$archive['category'].'"');
$category = $db->fetch_array($qcategory);
if(!
$archive['did'])
{
error_no_permission();
}
if(
$archive['uid'] != $mybb->user['uid'])
{
error_no_permission();
}
if(!empty(
$archive['pics']))
{
error_no_permission();
}
if(
$mybb->settings['downloads_usercreatedownloads'] == 0)
{
error_no_permission();
exit;
}
if(!
in_array($mybb->user['usergroup'],explode(",",$mybb->settings['downloads_groupscreatedownloads'])))
{
error_no_permission();
}
if(
$mybb->input['images'] < 1 || $mybb->input['images'] > 10)
{
error_no_permission();
}
$lang->title_category = $lang->sprintf($lang->title_category, $category['name']);
add_breadcrumb($lang->title_category, THIS_SCRIPT.'?category='.$category['dcid']);
add_breadcrumb($archive['name'], THIS_SCRIPT.'?archive='.$archive['did']);
add_breadcrumb($lang->addimages);
$did = intval($archive['did']);
$images = $mybb->input['images'];
if(
$mybb->request_method == "post")
{
for(
$i = 1; ; $i++)
{
if (
$i > intval($mybb->input['images']))
{
break;
}
if(
strlen($mybb->input['image_'.$i]) < 4)
{
$lang->imagerrorfor = $lang->sprintf($lang->image_error_for, $i);
$errors[] = $lang->imagerrorfor;
}
}
if(!
$errors)
{
for(
$i = 1; ; $i++)
{
if (
$i > intval($mybb->input['images']))
{
break;
}
$insert = array(
"did" => $did,
"dcid" => intval($archive['category']),
"image" => $mybb->input['image_'.$i],
"orden" => $i
);
$diid = $db->insert_id();
$db->insert_query("downloads_images", $insert);
}
$edit_update = array(
"pics" => intval($mybb->input['images'])
);
$db->update_query("downloads", $edit_update,"did=".$did);
$db->query("DELETE FROM ".TABLE_PREFIX."datacache WHERE title='downloads_cache'");
if(
$mybb->settings['downloads_validatedownloads'] == 0)
{
redirect(THIS_SCRIPT.'?archive='.$did, $lang->imagesaddsuccess);
}
else
{
redirect(THIS_SCRIPT, $lang->imagesaddsuccess_validate);
}
}
}
if(
$errors)
{
$image_errors = inline_error($errors);
}
for(
$number = 1; ; $number++)
{
if (
$number > $mybb->input['images'])
{
break;
}
$color = alt_trow();
$image .= $mybb->input['image_'.$number];
eval(
"\$imagesbox .= \"".$templates->get("downloads_newdownload_addimages_box")."\";");
unset(
$image);
}
eval(
"\$add_images = \"".$templates->get("downloads_newdownload_addimages")."\";");
output_page($add_images);
return
false;
}
elseif(
$mybb->input['newlinks'])
{
$qdownloads = $db->simple_select('downloads', '*', 'did="'.$mybb->input['newlinks'].'"');
$download = $db->fetch_array($qdownloads);
$qcategory = $db->simple_select(TABLE.'cat', '*', 'dcid="'.$download['category'].'"');
$category = $db->fetch_array($qcategory);
if(!
$download['did'])
{
error_no_permission();
}
if(
$download['uid'] != $mybb->user['uid'])
{
error_no_permission();
}
if(
$mybb->settings['downloads_usercreatedownloads'] == 0)
{
error_no_permission();
exit;
}
if(!
in_array($mybb->user['usergroup'],explode(",",$mybb->settings['downloads_groupscreatedownloads'])))
{
error_no_permission();
}
if(
$mybb->input['images'] < 1 || $mybb->input['images'] > 10)
{
error_no_permission();
}
$lang->title_category = $lang->sprintf($lang->title_category, $category['name']);
add_breadcrumb($lang->title_category, THIS_SCRIPT.'?category='.$category['dcid']);
add_breadcrumb($download['name'], THIS_SCRIPT.'?archive='.$download['did']);
add_breadcrumb($lang->addlinks);
$did = intval($download['did']);
if(
$mybb->request_method == "post")
{
for(
$i = 1; ; $i++)
{
if (
$i > intval($mybb->input['urls']))
{
break;
}
if(
strlen($mybb->input['url_'.$i]) < 4)
{
$lang->urlrrorfor = $lang->sprintf($lang->url_error_for, $i);
$errors[] = $lang->urlrrorfor;
}
if(
strlen($mybb->input['name_'.$i]) < 3)
{
$lang->urlrrorforname = $lang->sprintf($lang->url_errorname_for, $i);
$errors[] = $lang->urlrrorforname;
}
}
if(!
$errors)
{
for(
$i = 1; ; $i++)
{
if (
$i > intval($mybb->input['urls']))
{
break;
}
$insert_urls = array(
"did" => $did,
"dcid" => intval($download['category']),
"url" => $db->escape_string($mybb->input['url_'.$i]),
"text" => $db->escape_string($mybb->input['name_'.$i]),
"generate" => random_str(10),
"orden" => $i
);
$duid = $db->insert_id();
$db->insert_query("downloads_urls", $insert_urls);
}
$edit_update = array(
"urls" => intval($mybb->input['urls'])
);
$db->update_query("downloads", $edit_update,"did=".$did);
if(
$mybb->input['boximg'] == 1)
{
$numimages = intval($mybb->input['images']);
$edit_update = array(
"pics" => 0
);
$db->update_query("downloads", $edit_update,"did=".$download['did']);
redirect("downloads.php?newimages=".$download['did']."&images=".$numimages, $lang->downloadcreateimages);
}
else
{
$edit_update = array(
"pics" => intval(0)
);
$db->update_query("downloads", $edit_update,"did=".$download['did']);
$db->query("DELETE FROM ".TABLE_PREFIX."datacache WHERE title='downloads_cache'");
if(
$mybb->settings['downloads_validatedownloads'] == 1)
{
redirect(THIS_SCRIPT, $lang->successcreatewaitval);
}
else
{
redirect(THIS_SCRIPT.'?archive='.$download['did'], $lang->successcreateredirectdown);
}
}
}
}
if(
$errors)
{
$image_errors = inline_error($errors);
}
for(
$number = 1; ; $number++)
{
if (
$number > $mybb->input['urls'])
{
break;
}
$color = alt_trow();
$url .= $mybb->input['url_'.$number];
$name .= $mybb->input['name_'.$number];
eval(
"\$linksbox .= \"".$templates->get("downloads_newdownload_addlinks_box")."\";");
unset(
$url);
unset(
$name);
}
eval(
"\$add_images = \"".$templates->get("downloads_newdownload_addlinks")."\";");
output_page($add_images);
return
false;
}
elseif(
$mybb->input['newdownload'])
{
if(
$mybb->settings['downloads_usercreatedownloads'] == 0)
{
error_no_permission();
exit;
}
if(!
in_array($mybb->user['usergroup'],explode(",",$mybb->settings['downloads_groupscreatedownloads'])))
{
error_no_permission();
}
if(!empty(
$mybb->settings['downloads_maxcreated']) && $mybb->settings['downloads_maxcreated'] <= $mybb->user['downloads'] && $mybb->user['usergroup'] != 4)
{
error_no_permission();
}
$qcategory = $db->simple_select(TABLE.'cat', '*', 'dcid="'.$mybb->input['newdownload'].'"');
$category = $db->fetch_array($qcategory);
if(!
$category['dcid'])
{
error_no_permission();
}
$dcid = intval($category['dcid']);
$lang->title_category = $lang->sprintf($lang->title_category, $category['name']);
add_breadcrumb($lang->title_category, THIS_SCRIPT."?category=".$category['dcid']);
add_breadcrumb($lang->newdownloads);
if(
$mybb->request_method == "post")
{
$query = $db->simple_select("downloads", "*", "name=\"".$mybb->input['name']."\"");
$download_name = $db->fetch_array($query);

if(
$download_name['name'])
{
$errors[] = $lang->existdownloadname;
}
$db->free_result($query);
unset(
$query);
unset(
$download_name);
if(
strlen($mybb->input['name']) < 2)
{
$errors[] = $lang->namedownloadshort;
}
if(
strlen($mybb->input['shortdesc']) < 5)
{
$errors[] = $lang->shortdescisshort;
}
if(
strlen($mybb->input['description']) < 10)
{
$errors[] = $lang->descdownloadshort;
}
if(empty(
$mybb->input['image']))
{
$errors[] = $lang->frondownloadempty;
}
$mybb->input['url'] = intval($mybb->input['url']);
if(empty(
$mybb->input['url']) || $mybb->input['url'] < 1)
{
$errors[] = $lang->urldownloadempty;
}
if(
$mybb->input['chekimages'] == 1)
{
$numimages = intval($mybb->input['numimages']);
if(
$numimages < 1)
{
$errors[] = $lang->enternumberimagesvalidate;
}
if(
$numimages > 10)
{
$errors[] = $lang->notmoretenimages;
}
}
if(!
$errors)
{
$db->query("DELETE FROM ".TABLE_PREFIX."datacache WHERE title='downloads_cache'");
if(
$mybb->settings['downloads_validatedownloads'] == 1)
{
$validate = 1;
}else{
$validate = 0;
$edit_user = array(
"downloads" => intval(++$mybb->user['downloads'])
);
$db->update_query("users", $edit_user,"uid=".$mybb->user['uid']);
}
$query_order = $db->simple_select("downloads", "orden", "category=\"".$dcid."\"", array('order_by' => 'orden', 'order_dir' => 'DESC'));
$orden = $db->fetch_array($query_order);
$insert = array(
"name" => $db->escape_string($mybb->input['name']),
"orden" => intval(++$orden['orden']),
"uid" => intval($mybb->user['uid']),
"shortdesc" => $db->escape_string($mybb->input['shortdesc']),
"description" => $db->escape_string($mybb->input['description']),
"image" => $db->escape_string($mybb->input['image']),
"comments" => 1,
"dateline" => TIME_NOW,
"urls" => 0,
"active" => 1,
"groups" => "1,5,7",
"category" => $dcid,
"bbcode" => 1,
"validate" => $validate
);
$did = $db->insert_id();
$update_cache = array(
"name" => $db->escape_string($mybb->input['name']),
"code" => $generate
);
unset(
$orden);
$db->free_result($query_order);
$cache->update("downloads_cache", $update_cache);
$db->insert_query("downloads", $insert);
if(
$mybb->settings['downloads_validatedownloads'] == 1)
{
$validatecache = $cache->read("downloads_validate");
$update_cache = array(
"name" => "Validate",
"code" => ++$validatecache['code']
);
$cache->update("downloads_validate", $update_cache);
}
$boximg = intval($mybb->input['chekimages']);
$numimages = intval($mybb->input['numimages']);
$cache_read = $cache->read("downloads_cache");
$query = $db->simple_select("downloads", "*", "name=\"".$cache_read['name']."\"");
$download = $db->fetch_array($query);
redirect("downloads.php?newlinks=".$download['did']."&urls=".$mybb->input['url']."&boximg=".$boximg."&images=".$numimages, $lang->downloadcreatelinks);
}
}
$name = $mybb->input['name'];
$shortdesc = $mybb->input['shortdesc'];
$description = $mybb->input['description'];
$image = $mybb->input['image'];
$url = $mybb->input['url'];
if(
$errors)
{
$downloads_errors = inline_error($errors);
}
$codebuttons = build_mycode_inserter();
$smilieinserter = build_clickable_smilies();
eval(
"\$category_view = \"".$templates->get("downloads_newdownload")."\";");
output_page($category_view);
return
false;
}
elseif(
$mybb->input['download'])
{
$qdownlink = $db->simple_select('downloads_urls', '*', 'generate="'.$mybb->input['download'].'"');
$link = $db->fetch_array($qdownlink);
$qdown = $db->simple_select('downloads', '*', 'did="'.$link['did'].'"');
$archive = $db->fetch_array($qdown);
if(!
$archive['did'])
{
error_no_permission();
}
if(
$archive['active'] == 0)
{
error_no_permission();
}
if(
$archive['validate'] == 1)
{
error_no_permission();
}
if(
in_array($mybb->user['usergroup'],explode(",",$archive['groups'])))
{
error_no_permission();
}
$db->update_query("downloads", array("downloads" => ++$archive['downloads']),"did=".$archive['did']);
$lang->downloadarchive = $lang->sprintf($lang->downloadarchive, $archive['name']);
eval(
"\$exitpage = \"".$templates->get("downloads_download")."\";");
output_page($exitpage);
return
false;
}
elseif(
$mybb->input['action'] == "do_comment" && $mybb->request_method == "post")
{
if(!
$uid)
{
$uid = intval($mybb->user['uid']);
}
$Q = $db->simple_select('downloads', '*', 'did='.$mybb->input['did']);
$archive = $db->fetch_array($Q);
if(
$archive['comments'] == 0)
{
error_no_permission();
}
$insert_comment = array(
"did" => $mybb->input['did'],
"category" => $mybb->input['category'],
"uid" => $uid,
"comment" => $db->escape_string($mybb->input['message']),
"dateline" => TIME_NOW
);
$dcid = $db->insert_id();
$db->insert_query("downloads_comments", $insert_comment);
redirect("downloads.php?archive=".$mybb->input['did']."#comments", $lang->addcommentssuccess);
}
elseif(
$mybb->input['action'] == "comment")
{
if(
$mybb->input['manage'] == "do_editcomment" && $mybb->request_method == "post")
{
$edit_comments = array(
"comment" => $db->escape_string($mybb->input['message'])
);
$db->update_query(TABLE.'comments', $edit_comments,"dcid=".$mybb->input['dcid']);
redirect("downloads.php?archive=".$mybb->input['did'], $lang->editcommentssuccess);
}
elseif(
$mybb->input['manage'] == "edit")
{
$query_comments = $db->simple_select(TABLE.'comments', '*', 'dcid='.$mybb->input['dcid']);
$comments = $db->fetch_array($query_comments);
if(!
$comments['dcid'])
{
error_no_permission();
}
if(
$mybb->user['uid'] != $comments['uid'])
{
$usergroup = $cache->read("usergroups");
if(
$usergroup[$mybb->user['usergroup']]['canmodcp'] == 0)
{
error_no_permission();
}
}
$query_archive = $db->simple_select('downloads', '*', 'did='.$comments['did']);
$archive = $db->fetch_array($query_archive);
$qcat = $db->simple_select(TABLE.'cat', '*', 'dcid='.$archive['category']);
$category = $db->fetch_array($qcat);
$lang->title_category = $lang->sprintf($lang->title_category, $category['name']);
add_breadcrumb($lang->title_category, THIS_SCRIPT."?category=".$category['dcid']);
add_breadcrumb($archive['name'], THIS_SCRIPT."?archive=".$archive['did']);
add_breadcrumb($lang->editcomment);
if(
$mybb->settings['downloads_showeditor'] == 1)
{
$codebuttons = build_mycode_inserter();
}
$lang->edicomentsby = $lang->sprintf($lang->edicomentsby, $archive['name']);
eval(
"\$comments_edit_form = \"".$templates->get("downloads_comments_edit")."\";");
output_page($comments_edit_form);
return
false;
}
elseif(
$mybb->input['manage'] == "delete")
{
$query_comments = $db->simple_select(TABLE.'comments', '*', 'dcid='.$mybb->input['dcid']);
$comments = $db->fetch_array($query_comments);
if(!
$comments['dcid'])
{
error_no_permission();
}
if(
$mybb->user['uid'] != $comments['uid'])
{
$usergroup = $cache->read("usergroups");
if(
$usergroup[$mybb->user['usergroup']]['canmodcp'] == 0)
{
error_no_permission();
}
}
$db->query("DELETE FROM ".TABLE_PREFIX.TABLE."comments WHERE dcid='".intval($mybb->input['dcid'])."'");
redirect("downloads.php?archive=".$comments['did'], $lang->deletecommentssuccess);
}
else
{
error_no_permission();
}
}
elseif(
$mybb->input['category'])
{
$category_id = intval($mybb->input['category']);
$query_category = $db->simple_select(TABLE.'cat', '*', 'active="1" AND dcid="'.$category_id.'"');
$category = $db->fetch_array($query_category);
if(!
$category['dcid'])
{
error_no_permission();
}
$query_counts = $db->simple_select('downloads', 'COUNT(did) AS dids', 'active="1" AND validate="0" AND category='.intval($category_id), array('limit' => 1));
$quantity = $db->fetch_field($query_counts, "dids");
$pagina = intval($mybb->input['page']);
$perpage = $mybb->settings['downloads_paginationarchive'];
if(
$pagina > 0)
{
$start = ($pagina - 1) * $perpage;
$pages = $quantity / $perpage;
$pages = ceil($pages);
if(
$pagina > $pages || $pagina <= 0)
{
$start = 0;
$pagina = 1;
}
}
else
{
$start = 0;
$pagina = 1;
}
$pageurl = "downloads.php?category=".$mybb->input['category'];
$query_archives = $db->simple_select('downloads', '*', 'active="1" AND validate="0" AND category="'.$category_id.'"' ,array('order_by' => 'orden', 'order_dir' => 'ASC', 'limit' => "{$start}, {$perpage}"));
while(
$archive = $db->fetch_array($query_archives))
{
if(!
in_array($mybb->user['usergroup'],explode(",",$archive['groups'])))
{
if(
$archive['posts'] <= $mybb->user['postnum'] && $archive['threads'] <= $mybb->user['threads'] && $archive['reputation'] <= $mybb->user['reputation'] && $archive['timeonline'] <= $mybb->user['timeonline'])
{
$user = get_user($archive['uid']);
$username = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
$username = build_profile_link($username, $user['uid'], "_blank");
$color = alt_trow();
if(
$mybb->settings['downloads_showportada'] == 1)
{
$colspan = 5;
$tcatimage = "<td class=\"tcat\" align=\"center\"><span class=\"smalltext\"><strong>{$lang->image}</strong></span></td>";
list(
$width, $height) = @explode("x", $mybb->settings['downloads_portadacategory']);
eval(
"\$archives_list .= \"".$templates->get("downloads_archives_list_front")."\";");
}
else
{
$colspan = 4;
eval(
"\$archives_list .= \"".$templates->get("downloads_archives_list")."\";");
}
}
}
}

$plugins->run_hooks("download_archive", $archive);

if(!
$archives_list)
{
$archives_list = "<td class=\"trow1\" colspan=\"100\" align=\"center\">{$lang->dontdownloadtable}</td>";
}
if(!
$colspan && !$tcatimage)
{
$colspan = 4;
if(
$mybb->settings['downloads_showportada'] == 1)
{
$colspan = 5;
$tcatimage = "<td class=\"tcat\" align=\"center\"><strong>{$lang->image}</strong></td>";
}
}
$pagination = multipage($quantity, (int)$perpage, (int)$pagina, $pageurl);
$lang->title_category = $lang->sprintf($lang->title_category, $category['name']);
add_breadcrumb($lang->title_category);
if(
$mybb->settings['downloads_usercreatedownloads'] == 1)
{
if(
in_array($mybb->user['usergroup'],explode(",",$mybb->settings['downloads_groupscreatedownloads'])))
{
if(
$mybb->settings['downloads_postsrequest'] <= $mybb->user['postnum'] && $mybb->settings['downloads_threadsrequest'] <= $mybb->user['threads'] && $mybb->settings['downloads_reputationrequest'] <= $mybb->user['reputation'] && $mybb->settings['downloads_timeonlinerequest'] <= $mybb->user['timeonline'])
{
if(
$mybb->user['downloads'] < $mybb->settings['downloads_maxcreated'] || empty($mybb->settings['downloads_maxcreated']))
{
eval(
"\$newdownload = \"".$templates->get("downloads_newdownload_button")."\";");
}
}
}
}
$lang->title_category = $lang->sprintf($lang->title_category, $category['name']);
eval(
"\$category_view = \"".$templates->get("downloads_archives")."\";");
output_page($category_view);
return
false;
}
elseif(
$mybb->input['archive'])
{
$archive_id = intval($mybb->input['archive']);
$query_archive = $db->simple_select('downloads', '*', 'active="1" AND validate="0" AND did="'.$archive_id.'"');
$archive = $db->fetch_array($query_archive);
$query_cat = $db->simple_select(TABLE."cat", '*', "dcid='{$archive['category']}'");
$category = $db->fetch_array($query_cat);
$lang->title_category = $lang->sprintf($lang->title_category, $category['name']);
add_breadcrumb($lang->title_category, THIS_SCRIPT."?category=".$category['dcid']);
add_breadcrumb($archive['name']);
if(!
$archive['did'])
{
error_no_permission();
}
if(
in_array($mybb->user['usergroup'],explode(",",$archive['groups'])))
{
error_no_permission();
}
if(
$archive['posts'] > $mybb->user['postnum'] || $archive['threads'] > $mybb->user['threads'] || $archive['reputation'] > $mybb->user['reputation'] || $archive['timeonline'] > $mybb->user['timeonline'])
{
error_no_permission();
}
$user = get_user($archive['uid']);
$username = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
$username = build_profile_link($username, $user['uid'], "_blank");
$avatar = "<img src=\"".$user['avatar']."\" class=\"avatar_view\" alt=\"".$user['username']."\" title=\"".$user['username']."\" />";
$time = my_date($mybb->settings['timeformat'], $archive['dateline']);
$date = my_date($mybb->settings['dateformat'], $archive['dateline']);
$register = my_date($mybb->settings['regdateformat'], $user['regdate']);
$reputation = get_reputation($user['reputation'], $user['uid']);
if(
$archive['pics'])
{
static
$images_screenshots;
$query_images = $db->simple_select(TABLE.'images', '*', 'did="'.$archive['did'].'"');
while(
$image = $db->fetch_array($query_images))
{
$images_screenshots[$archive['did']][$image['orden']] = $image['image'];
}
for(
$i = 1; $i <= intval($archive['pics']); $i++)
{
//resize image front
list($width, $height) = @getimagesize($images_screenshots[$archive['did']][$i]);
if(
$width && $height)
{
list(
$max_width, $max_height) = explode("x", my_strtolower($mybb->settings['downloads_sizeimages']));
if(
$width > $max_width || $height > $max_height)
{
require_once
MYBB_ROOT."inc/functions_image.php";
$scaled_dimensions = scale_image($width, $height, $max_width, $max_height);
$images_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\"";
}
else
{
$images_width_height = "width=\"{$width}\" height=\"{$height}\"";
}
}
$images .= "<img src=\"".$images_screenshots[$archive['did']][$i]."\" {$images_width_height}/> ";
}
eval(
"\$screenshots = \"".$templates->get("downloads_archives_screenshots")."\";");
}
$db->update_query("downloads", array("views" => ++$archive['views']),"did=".$archive_id);

//resize image front
list($width, $height) = @getimagesize($archive['image']);
if(
$width && $height)
{
list(
$max_width, $max_height) = explode("x", my_strtolower($mybb->settings['downloads_sizeportada']));
if(
$width > $max_width || $height > $max_height)
{
require_once
MYBB_ROOT."inc/functions_image.php";
$scaled_dimensions = scale_image($width, $height, $max_width, $max_height);
$front_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\"";
}
else
{
$front_width_height = "width=\"{$width}\" height=\"{$height}\"";
}
}
if(
$archive['comments'] == 1)
{
if(
$mybb->settings['downloads_showeditor'] == 1)
{
$codebuttons = build_mycode_inserter();
}
$query_counts = $db->simple_select(TABLE.'comments', 'COUNT(dcid) AS dcids', 'did='.intval($archive['did']), array('limit' => 1));
$quantity = $db->fetch_field($query_counts, "dcids");
$pagina = intval($mybb->input['page']);
$perpage = 4;
if(
$pagina > 0)
{
$start = ($pagina - 1) * $perpage;
$pages = $quantity / $perpage;
$pages = ceil($pages);
if(
$pagina > $pages || $pagina <= 0)
{
$start = 0;
$pagina = 1;
}
}
else
{
$start = 0;
$pagina = 1;
}
$pageurl = "downloads.php?archive=".$archive['did'];
$query_comments = $db->simple_select(TABLE.'comments', '*', 'did="'.$archive['did'].'"',array('order_by' => 'dcid', 'order_dir' => 'DESC', 'limit' => "{$start}, {$perpage}"));
while(
$comment = $db->fetch_array($query_comments))
{
$color = alt_trow();
$user = get_user($comment['uid']);
$username = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
$username = build_profile_link($username, $user['uid'], "_blank");
$time = my_date($mybb->settings['timeformat'], $comment['dateline']);
$date = my_date($mybb->settings['dateformat'], $comment['dateline']);
$user['avatar'] = (!empty($user['avatar'])) ? $user['avatar'] : "images/avatars/invalid_url.gif";
$text = parse_text($comment['comment'],$mybb->settings['downloads_canhtmlcomments'], $mybb->settings['downloads_canbbcodecomments'], $mybb->settings['downloads_cansmiliescomments'], $mybb->settings['downloads_canimgcomments'], $mybb->settings['downloads_canbadwordcomments']);
$usergroup = $cache->read("usergroups");
if(
$usergroup[$mybb->user['usergroup']]['canmodcp'] == 1 || $mybb->user['uid'] == $comment['uid'])
{
eval(
"\$comment_manage = \"".$templates->get("downloads_archives_comments_moderation")."\";");
}
eval(
"\$comments_list .= \"".$templates->get("downloads_archives_comments_list")."\";");
unset(
$comment_manage);
}
$pagination = multipage($quantity, (int)$perpage, (int)$pagina, $pageurl);
$lang->edicomentsby = $lang->sprintf($lang->edicomentsby, $archive['name']);
eval(
"\$comments = \"".$templates->get("downloads_archives_comments")."\";");
}
if(
$archive['bbcode'] == 1)
{
$archive['description'] = parse_text($archive['description'],0,1,1,1,1);
}
$query_links = $db->simple_select(TABLE.'urls', '*', 'did="'.$archive['did'].'"',array('order_by' => 'duid', 'order_dir' => 'ASC'));
while(
$link = $db->fetch_array($query_links))
{
eval(
"\$downloadslinks .= \"".$templates->get("downloads_archives_links")."\";");
}
eval(
"\$archives_page = \"".$templates->get("downloads_archives_view")."\";");
output_page($archives_page);
}
else
{
$query_counts = $db->simple_select(TABLE.'cat', 'COUNT(dcid) AS dcids', 'active="1"', array('limit' => 1));
$quantity = $db->fetch_field($query_counts, "dcids");
$pagina = intval($mybb->input['page']);
$perpage = $mybb->settings['downloads_paginationcategorys'];
if(
$pagina > 0)
{
$start = ($pagina - 1) * $perpage;
$pages = $quantity / $perpage;
$pages = ceil($pages);
if(
$pagina > $pages || $pagina <= 0)
{
$start = 0;
$pagina = 1;
}
}
else
{
$start = 0;
$pagina = 1;
}
$pageurl = "downloads.php";
$query = $db->simple_select(TABLE.'cat', '*', 'active="1"',array('order_by' => 'orden', 'order_dir' => 'ASC', 'limit' => "{$start}, {$perpage}"));
while(
$category = $db->fetch_array($query))
{
$color = alt_trow();
$qnthread = $db->simple_select('downloads', 'COUNT(did) AS dids', 'category="'.$category['dcid'].'"', array('limit' => 1));
$numthreads = $db->fetch_field($qnthread, "dids");
$qdown = $db->simple_select('downloads', '*', 'active="1" and validate="0" and category="'.$category['dcid'].'"', array('order_by' => 'did', 'order_dir' => 'DESC'));
$download = $db->fetch_array($qdown);
$countn = strlen($download['name']);
if(
intval($countn) > 24)
{
$lastdownload = substr($download['name'], 0, 25)."...";
}
else
{
$lastdownload = $download['name'];
}
$time = my_date($mybb->settings['timeformat'], $download['dateline']);
$date = my_date($mybb->settings['dateformat'], $download['dateline']);
$user = get_user($download['uid']);
$username = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
$username = build_profile_link($username, $user['uid'], "_blank");
if(!
$download['did'])
{
$lastdownloadbox .= "<td class=\"".$color."\" align=\"center\" width=\"22%\">".$lang->never."</td>";
}
else
{
eval(
"\$lastdownloadbox .= \"".$templates->get("downloads_category_lastdownload")."\";");
}
eval(
"\$categorys .= \"".$templates->get("downloads_category")."\";");
unset(
$lastdownloadbox);
}
if(!
$categorys)
{
$categorys = "<td class='trow1' align='center' colspan='100'>{$lang->dontcategorystable}</td>";
}
$pagination = multipage($quantity, (int)$perpage, (int)$pagina, $pageurl);
eval(
"\$page = \"".$templates->get("downloads_home")."\";");
output_page($page);
}

$plugins->run_hooks("download");

function
parse_text($text,$html,$bbcode,$smilies)
{
global
$mybb;
require_once
MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
$parser_options = array(
'allow_html' => $html,
'allow_mycode' => $mybb->settings['downloads_canbbcodecomments'],
'allow_smilies' => $mybb->settings['downloads_cansmiliescomments'],
'allow_imgcode' => $mybb->settings['downloads_canimgcomments'],
'filter_badwords' => $mybb->settings['downloads_canbadwordcomments']
);
$text = $parser->parse_message($text, $parser_options);
return
$text;
}

exit;
?>


??
Edson Ordaz   6 May, 2012, 7:52 pm
#9
el problema esque no revisas el codigo solo lo agregaste por agregarlo... para empezar el hook ni sikiera esta al ver la descarga esta en las categorias....
para que pueda funcionar debes ponerlo donde esta esto:
Código PHP:
<?php 
eval("\$archives_page = \"".$templates->get("downloads_archives_view")."\";");
de modo que quede asi
Código PHP:
<?php 
$plugins
->run_hooks("download_archive", $archive);
eval(
"\$archives_page = \"".$templates->get("downloads_archives_view")."\";");

aparte debes agregar un return en la funcion donde useseste hook para que muestre el botno gracias por ejemplo en la funcion debes agregar $archive['thanks'] = XXX; y al final de la funcion un return $archive;
con eso mostraria el boton de gracias y para dar gracias (sin ajax porque seria mucho mas rollo tendrias que crear otro JS solo para ello o modificar el ya creado) para dar gracias deberias hacerlo por medio del MISC_START y en la funcion poner por ejemplo

if($mybb->input['action'] == "thanks_downloads")
{
//verificar que este bien lo de gracias y agregarlo a la DB
}

para ello en el $archive['thanks']; debes agregar el link hacia MYBB_ROOT."misc.php?action=thanks_downloads" entiendes?? com dije al principio no es facil aunque no es nada del otro mundo debes tener conocimientos en PHP y claro en MyBB..
La verdad ya te hemos ayudado con esto que dije debe funciona al 100% solo falta que crees tus funciones BIEN y bueno pues la verdad ya no podre ayudarte porque como dije si quieres que lo haga mejor te lo programo peor tendria un costo Wink (y con ajax Wink)
  
Powered By MyBB, © 2002-2024 MyBB Group.
Made with by Curves UI.