Como instalar en Foro PHPbb la opcion suscribirme a Foro šŸ„‡ Foros Webmasters

Foros de discusiĆ³nPortal DragonFlyCMS, CPGNuke

#1:  Como instalar en Foro PHPbb la opcion suscribirme a Foro  Autor: Aforo Enlaces Publicado: Sab Ene 10, 2009 3:52 am
    ----
Para un moderador puede ser interesante mantenerse alerta de todos los nuevos temas de un foro y no solo de los que esta suscrito. Recibir un email cada vez que alguien escriba en su foro.

Lo que vamos a intentar aqui es, de un modo sencillo y en 10 minutos, adaptar un Foro Dragonfly cms (phpbb2) para que notifique a los moderadores que asi lo desen cualquier cosa que se escriba en el foro.

En principio es una herramienta peligrosa si la abrimos a todos los usuarios de un gran portal, pues puede colapsar el servidor de correo.

El moderador o usuario (segun decida el administrador) se podra suscribir o dessuscribir a un foro cuando lo desee, y recibira notificacion de todo lo que se escriba en ese foro.

La suscripcion se hara mediante un enlace:



ƚltima ediciĆ³n por Aforo el Sab Ene 10, 2009 3:59 am, editado 3 veces

#2:  Creacion de la Tabla en la base de datos  Autor: Aforo Enlaces Publicado: Sab Ene 10, 2009 3:53 am
    ----
Creacion de la Tabla base de datos

Lo primero que vamos a hacer es crear una tabla en nuestra base de datos para guardar que usuario esta observando cada foro:

Quote::
--- Create Forum Notify table -------

CREATE TABLE nuke_bbforums_watch (
forum_id smallint(5) unsigned NOT NULL default '0',
user_id mediumint(8) NOT NULL default '0',
notify_status tinyint(1) NOT NULL default '0',
KEY forum_id (forum_id),
KEY user_id (user_id),
KEY notify_status (notify_status)
);

#3:  Re: Como instalar en Foro PHPbb la opcion suscribirme a Foro  Autor: Aforo Enlaces Publicado: Sab Ene 10, 2009 4:02 am
    ----
Ahora actuamos sobre dos ficheros importantes:


######### --- ADD to includes/constants.php -- #######
AƱadimos las siguientes dos lineas en includes/constants.php:

Quote::
// Forum Watch:
define('FORUMS_WATCH_TABLE', $prefix.'_bbforums_watch');

######--- ADD three variables in languages/[lang]/forums.php -- #######
Y tres variables en los ficheros de Lenguas (tres en cada lengua):

Quote::
'Forum_watch_subject' => 'Forum Watch',
'Forum_watch' => 'Forum Watch',
'Forum_unwatch' => 'Forum Unwatch',

#4:  Re: Como instalar en Foro PHPbb la opcion suscribirme a Foro  Autor: Aforo Enlaces Publicado: Sab Ene 10, 2009 4:06 am
    ----
Ahora tocamos un fichero crucial... el que manda los mensajes a los usuarios suscritos a un tema: includes/functions_post.php

Adjuntaremos al final este fichero modificado para mas comodidad del webmaster.

######### --- includes/functions_post.php ---- #########

---------- Add this line at the end of function "function user_notification" --- line 432

Quote::
user_forum_notification($mode, $post_data, $topic_title, $forum_id, $topic_id, $post_id, $notify_user);


----------- Create new function --------

Creamos una nueva Funcion:

Quote::
function user_forum_notification($mode, &$post_data, &$topic_title, &$forum_id, &$topic_id, &$post_id, &$notify_user)
{
global $board_config, $lang, $db, $phpbb_root_path, $MAIN_CFG;
global $userdata;

$current_time = gmtime();
////// mio - Observar Foro - Forum Watch //////
if(!$topic_title || $topic_title == "" ){
$row = $db->sql_fetchrow( $db->sql_query('SELECT topic_title FROM '.TOPICS_TABLE.' WHERE topic_id ='.$topic_id ));
$topic_title = $row['topic_title'];
}

if ($mode == 'reply' || $mode == 'newtopic' ) {
$result = $db->sql_query('SELECT user_id FROM '.USERS_TABLE.' WHERE user_level<1');
$user_id_sql = '';
while ($row = $db->sql_fetchrow($result)) { $user_id_sql .= ', '.$row['user_id']; }

$sql = "SELECT u.user_id, u.user_email, u.user_lang
FROM ".FORUMS_WATCH_TABLE." tw, ".USERS_TABLE." u
WHERE tw.forum_id = $forum_id
AND tw.user_id NOT IN (".$userdata['user_id'].", ".ANONYMOUS.$user_id_sql.")
AND u.user_id = tw.user_id";
$result = $db->sql_query($sql);

$update_watched_sql = '';
$bcc_list_ary = array();

if ($row = $db->sql_fetchrow($result)) {
// Sixty second limit
set_time_limit(0);
do {
if ($row['user_email'] != '') {
$bcc_list_ary[$row['user_lang']][] = $row['user_email'];
}
$update_watched_sql .= ($update_watched_sql != '') ? ', ' . $row['user_id'] : $row['user_id'];
}
while ($row = $db->sql_fetchrow($result));

if (sizeof($bcc_list_ary)) {
include("includes/phpBB/emailer.php");
$emailer = new emailer();

$orig_word = array();
$replacement_word = array();
obtain_word_list($orig_word, $replacement_word);

$emailer->from($board_config['board_email']);
$emailer->replyto($board_config['board_email']);

$topic_title = (count($orig_word)) ? preg_replace($orig_word, $replacement_word, htmlunprepare($topic_title)) : htmlunprepare($topic_title);

reset($bcc_list_ary);
while (list($user_lang, $bcc_list) = each($bcc_list_ary))
{
$emailer->use_template('topic_notify', $user_lang);
for ($i = 0; $i < count($bcc_list); $i++) {
$emailer->bcc($bcc_list[$i]);
}
// The Topic_reply_notification lang string below will be used
// if for some reason the mail template subject cannot be read
// ... note it will not necessarily be in the posters own language!
// modificacion importante
$emailer->set_subject($lang['Forum_watch_subject'].": $forum_id: - ".$topic_title);
// translators update their templates
$emailer->msg = preg_replace('#[ ]?{USERNAME}#', '', $emailer->msg);
$emailer->assign_vars(array(
'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',
'SITENAME' => $board_config['sitename'],
// Important Modify
'TOPIC_TITLE' => $lang['Forum_watch_subject'].": $forum_id: - ".$topic_title,

'U_TOPIC' => getlink('&file=viewtopic&' . POST_POST_URL . "=$post_id", true, true)."#$post_id",
'U_STOP_WATCHING_TOPIC' => getlink("&file=viewforum&f=$forum_id&unwatch=forum", true, true))
);
$emailer->send();
$emailer->reset();
}
}
}
$db->sql_freeresult($result);
}

////// Fin Observar Foro - End of Forum Watch //////

}

//
// Fill smiley templates (or just the variables) with smileys
// Either in a window or inline
//

#5:  Re: Como instalar en Foro PHPbb la opcion suscribirme a Foro  Autor: Aforo Enlaces Publicado: Sab Ene 10, 2009 4:16 am
    ----
Modificamos viewforum.php

Nos vamos al fichero: modules/Forums/viewforum.php

He marcado en rojo "(is_user() && $is_auth['auth_mod'])" porque si quisiesemos abrir la opcion atodos los usuarios, solo tendriamos que tocar aqui:. Sustituyendolo por (is_user())----- go to "End of forum prune" and add the next lines ---

Y detras de la funcion Prune aƱadimos:

Quote::

//
// End of forum prune
//

if (is_user() && $is_auth['auth_mod']){

$can_watch_forum = TRUE;
$sql = "SELECT notify_status
FROM ".FORUMS_WATCH_TABLE."
WHERE forum_id = $forum_id
AND user_id = ".$userdata['user_id'];
$result = $db->sql_query($sql);

if ( $row = $db->sql_fetchrow($result) ) {
// user watching
if ( isset($_GET['unwatch']) ) {
if ( $_GET['unwatch'] == 'forum' ) {
// user tring to "unwatch"
$sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$db->sql_query("DELETE $sql_priority FROM ".FORUMS_WATCH_TABLE."
WHERE forum_id = $forum_id
AND user_id = ".$userdata['user_id']);
}
url_refresh(getlink("&amp;file=viewforum&amp;f=$forum_id"));
$message = $lang['No_longer_watching'].'<br /><br />'.sprintf($lang['Click_return_topic'], '<a href="'.getlink("&amp;file=viewforum&amp;f=$forum_id").'">', '</a>');
message_die(GENERAL_MESSAGE, $message);
} else {
// user not ask for "unwatch"
$is_watching_forum = TRUE;
}
} else {
if ( isset($_GET['watch']) ) {
if ( $_GET['watch'] == 'forum' ) {
$is_watching_forum = TRUE;
$sql_priority = (SQL_LAYER == "mysql") ? "LOW_PRIORITY" : '';
$sql = "INSERT $sql_priority INTO ".FORUMS_WATCH_TABLE." (user_id, forum_id, notify_status)
VALUES (".$userdata['user_id'].", $forum_id, 0)";
$result = $db->sql_query($sql);
}
url_refresh(getlink("&amp;file=viewforum&amp;f=$forum_id"));
$message = $lang['You_are_watching'].'<br /><br />'.sprintf($lang['Click_return_topic'], '<a href="'.getlink("&amp;file=viewforum&amp;f=$forum_id").'">', '</a>');
message_die(GENERAL_MESSAGE, $message);
}
}
} else {

// no user but try to unwatch

if ( isset($_GET['unwatch']) ) {
if ( $_GET['unwatch'] == 'forum' ) {
url_redirect(getlink('Your_Account'), true);
}
}
}


//
// End of forum watching
//


//
// Forum watch link
//
$s_watching_forum ='';
if ( $can_watch_forum ) {
if ( $is_watching_forum ) {
$s_watching_forum = ' <a href="'.getlink("&amp;file=viewforum&amp;f=$forum_id&amp;unwatch=forum").'">'.$lang['Forum_unwatch'].'</a> ';
} else {
$s_watching_forum = ' <a href="'.getlink("&amp;file=viewforum&amp;f=$forum_id&amp;watch=forum").'">'.$lang['Forum_watch'].'</a> ';
}
}

//
// End Forum watch link
//

--------- go to U_POST_NEW_TOPIC and add SERV_LINE

Por ultimo, buscamos la linea donde pone U_POST_NEW_TOPIC y detras aƱadimos una variable.

En nuestro caso esa variable se usa para mandar tambien el enlace de RSS del foro y otros sevicios.

Quote::
'U_POST_NEW_TOPIC' => getlink("&amp;file=posting&amp;mode=newtopic&amp;".POST_FORUM_URL."=$forum_id"),
// (rss, igoogle, watch forums...)
'SERV_LINE' => '<a href="rss/forums.php?f='.$forum_id.'"><img src="images/rss2.gif" alt="RSS: '.$forum_row['forum_name'].'" style="vertical-align:middle;" /></a> RSS'.$s_watching_forum,


ƚltima ediciĆ³n por Aforo el Sab Ene 10, 2009 4:35 am, editado 2 veces

#6:  Re: Como instalar en Foro PHPbb la opcion suscribirme a Foro  Autor: Aforo Enlaces Publicado: Sab Ene 10, 2009 4:22 am
    ----
Por ultimo hay que ir al Template de nuestro Tema:

themes/[Theme_name]/template/forums/viewforum_body.html

E insertar la variable 'SERV_LINE'

En nuestro caso esta insertada del siguiente modo en la linea 165 de nuestro tema:

Quote::
<tr>
<td colspan="8" class="gensmall">{SERV_LINE}</td>
</tr>

#7:  Re: Como instalar en Foro PHPbb la opcion suscribirme a Foro  Autor: Aforo Enlaces Publicado: Sab Ene 10, 2009 4:31 am
    ----
Adjuntos que pueden ayudar...




Foros de discusiĆ³nPortal DragonFlyCMS, CPGNuke

Todas las horas son GMT + 1 Hora

PƔgina 1 de 1 - Tema con 7 Mensajes y 28617 Lecturas

DiseƱo web, bases de datos, lenguajes de programaciĆ³n, comunidades... todo lo necesario para construir tu sitio web.
The logos and trademarks used on this site are the property of their respective owners. We are not responsible for comments posted by our users, as they are the property of the poster.
Aviso Legal - Privacidad Construyendo la web 2.0
The logos and trademarks used on this site are the property of their respective owners. We are not responsible for comments posted by our users, as they are the property of the poster.
Aviso Legal - Privacidad