Les archives de FluxBB.fr
Vous n'êtes pas identifié(e).
Pages : 1
Bonjour,
Voici une autre mod. Elle permet à un administrateur ou un modérateur de pouvoir créer des messages qui seront postés automatiquement à une date ultérieure.
Ça se présente comme ceci: aperçu
La discussion sera postée dès qu'une page de votre forum sera chargée après cette date.
Nouvelle table à créer (remplacer PREFIX par le préfixe adéquat):
CREATE TABLE IF NOT EXISTS `PREFIXdelayed_posts` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`poster` varchar(200) NOT NULL DEFAULT '',
`poster_id` int(10) unsigned NOT NULL DEFAULT '1',
`poster_ip` varchar(15) DEFAULT NULL,
`message` text,
`timetopost` int(10) unsigned NOT NULL DEFAULT '0',
`topic_id` int(10) unsigned NOT NULL DEFAULT '0',
`forum_id` int(10) unsigned NOT NULL DEFAULT '0',
`subject` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;Les modifications dans les fichiers (les lignes indiquées correspondent à un fluxbb1.2.24 vierge de tte mod):
include/common.php
A la fin du fichier, ajouter:
$req = 'SELECT * FROM '.$db->prefix.'delayed_posts WHERE timetopost<'.time();
$sql = $db->query($req) or error('Unable to run delayed_posts', __FILE__, __LINE__, $db->error());;
if($db->num_rows($sql))
{
differe_post();
}include/functions.php
A la fin du fichier, ajouter:
function differe_post()
{
global $db, $pun_config, $lang_common;
$now = time();
require_once PUN_ROOT.'include/search_idx.php';
// 1 à la fois
$req = 'SELECT * FROM '.$db->prefix.'delayed_posts WHERE timetopost<'.$now.' ORDER BY id ASC LIMIT 1';
$sql = $db->query($req) or error('Error 1 differe_post', __FILE__, __LINE__, $db->error());;
if($db->num_rows($sql))
{
while($data=$db->fetch_assoc($sql))
{
$req = 'DELETE FROM '.$db->prefix.'delayed_posts WHERE id='.$data['id'];
$db->query($req) or error('Error 2 differe_post', __FILE__, __LINE__, $db->error());;
// id poster poster_id poster_ip message timetopost topic_id forum_id subject
if($data['topic_id'] > 0)
{
// reply
$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, posted, topic_id) VALUES(\''.$db->escape($data['poster']).'\', '.$data['poster_id'].', \''.$data['poster_ip'].'\', \''.$db->escape($data['message']).'\', '.$now.', '.$data['topic_id'].')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
$new_pid = $db->insert_id();
// To subscribe or not to subscribe, that ...
// on s'abonne pas en créant un message diff
// Count number of replies in the topic
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'posts WHERE topic_id='.$data['topic_id']) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $db->error());
$num_replies = $db->result($result, 0) - 1;
// Update topic
$db->query('UPDATE '.$db->prefix.'topics SET num_replies='.$num_replies.', last_post='.$now.', last_post_id='.$new_pid.', last_poster=\''.$db->escape($data['poster']).'\' WHERE id='.$data['topic_id']) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
update_search_index('post', $new_pid, $data['message']);
update_forum($data['forum_id']);
// Should we send out notifications?
if ($pun_config['o_subscriptions'] == '1')
{
// Get the post time for the previous post in this topic
$result = $db->query('SELECT posted FROM '.$db->prefix.'posts WHERE topic_id='.$data['topic_id'].' ORDER BY id DESC LIMIT 1, 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
$previous_post_time = $db->result($result);
// Get any subscribed users that should be notified (banned users are excluded)
$result = $db->query('SELECT u.id, u.email, u.notify_with_post, u.language FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'subscriptions AS s ON u.id=s.user_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id='.$data['forum_id'].' AND fp.group_id=u.group_id) LEFT JOIN '.$db->prefix.'online AS o ON u.id=o.user_id LEFT JOIN '.$db->prefix.'bans AS b ON u.username=b.username WHERE b.username IS NULL AND COALESCE(o.logged, u.last_visit)>'.$previous_post_time.' AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id='.$data['topic_id'].' AND u.id!='.intval($data['poster_id'])) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result))
{
require_once PUN_ROOT.'include/email.php';
$notification_emails = array();
// Loop through subscribed users and send e-mails
while ($cur_subscriber = $db->fetch_assoc($result))
{
// Is the subscription e-mail for $cur_subscriber['language'] cached or not?
if (!isset($notification_emails[$cur_subscriber['language']]))
{
if (file_exists(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl'))
{
// Load the "new reply" template
$mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply.tpl'));
// Load the "new reply full" template (with post included)
$mail_tpl_full = trim(file_get_contents(PUN_ROOT.'lang/'.$cur_subscriber['language'].'/mail_templates/new_reply_full.tpl'));
// The first row contains the subject (it also starts with "Subject:")
$first_crlf = strpos($mail_tpl, "\n");
$mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));
$mail_message = trim(substr($mail_tpl, $first_crlf));
$first_crlf = strpos($mail_tpl_full, "\n");
$mail_subject_full = trim(substr($mail_tpl_full, 8, $first_crlf-8));
$mail_message_full = trim(substr($mail_tpl_full, $first_crlf));
$mail_subject = str_replace('<topic_subject>', '\''.$data['subject'].'\'', $mail_subject);
$mail_message = str_replace('<topic_subject>', '\''.$data['subject'].'\'', $mail_message);
$mail_message = str_replace('<replier>', $data['poster'], $mail_message);
$mail_message = str_replace('<post_url>', $pun_config['o_base_url'].'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message);
$mail_message = str_replace('<unsubscribe_url>', $pun_config['o_base_url'].'/misc.php?unsubscribe='.$data['topic_id'], $mail_message);
$mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message);
$mail_subject_full = str_replace('<topic_subject>', '\''.$data['subject'].'\'', $mail_subject_full);
$mail_message_full = str_replace('<topic_subject>', '\''.$data['subject'].'\'', $mail_message_full);
$mail_message_full = str_replace('<replier>', $data['poster'], $mail_message_full);
$mail_message_full = str_replace('<message>', $data['message'], $mail_message_full);
$mail_message_full = str_replace('<post_url>', $pun_config['o_base_url'].'/viewtopic.php?pid='.$new_pid.'#p'.$new_pid, $mail_message_full);
$mail_message_full = str_replace('<unsubscribe_url>', $pun_config['o_base_url'].'/misc.php?unsubscribe='.$data['topic_id'], $mail_message_full);
$mail_message_full = str_replace('<board_mailer>', $pun_config['o_board_title'].' '.$lang_common['Mailer'], $mail_message_full);
$notification_emails[$cur_subscriber['language']][0] = $mail_subject;
$notification_emails[$cur_subscriber['language']][1] = $mail_message;
$notification_emails[$cur_subscriber['language']][2] = $mail_subject_full;
$notification_emails[$cur_subscriber['language']][3] = $mail_message_full;
$mail_subject = $mail_message = $mail_subject_full = $mail_message_full = null;
}
}
// We have to double check here because the templates could be missing
if (isset($notification_emails[$cur_subscriber['language']]))
{
if ($cur_subscriber['notify_with_post'] == '0')
pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][0], $notification_emails[$cur_subscriber['language']][1]);
else
pun_mail($cur_subscriber['email'], $notification_emails[$cur_subscriber['language']][2], $notification_emails[$cur_subscriber['language']][3]);
}
}
}
}
}
else
{
// Create the topic
$db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(\''.$db->escape($data['poster']).'\', \''.$db->escape($data['subject']).'\', '.$now.', '.$now.', \''.$db->escape($data['poster']).'\', '.$data['forum_id'].')') or error('Unable to create topic', __FILE__, __LINE__, $db->error());
$new_tid = $db->insert_id();
// To subscribe or not to subscribe, that ...
// pas d'abonnement non plus
// Create the post ("topic post")
$db->query('INSERT INTO '.$db->prefix.'posts (poster, poster_id, poster_ip, message, posted, topic_id) VALUES(\''.$db->escape($data['poster']).'\', '.$data['poster_id'].', \''.$data['poster_ip'].'\', \''.$db->escape($data['message']).'\', '.$now.', '.$new_tid.')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
$new_pid = $db->insert_id();
// Update the topic with last_post_id
$db->query('UPDATE '.$db->prefix.'topics SET last_post_id='.$new_pid.' WHERE id='.$new_tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
update_search_index('post', $new_pid, $data['message'], $data['subject']);
update_forum($data['forum_id']);
$db->query('UPDATE '.$db->prefix.'users SET num_posts=num_posts+1, last_post='.$now.' WHERE id='.$data['poster_id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
}
}
}
}post.php
chercher L65:
// Load the post.php language file
ajouter avant:
$differe = 0; // -1 = erreur, 1 = ok, 0 = pas différé
chercher L181:
$now = time();
ajouter après:
$differe = isset($_POST['differe']) ? 1 : 0;
if($is_admmod)
{
if($differe == 1)
{
$differe = -1;
if (isset($_POST['form_date']))
{
$form = array_map("intval", $_POST['form_date']);
$mois = $form['m'];
$jour = $form['d'];
$annee = $form['y'];
$heure = $form['h'];
$minute = $form['mn'];
$differedate = mktime ($heure, $minute, 0, $mois, $jour, $annee);
if($differedate > $now)
{
// au moins dans le futur...
$differe = 1;
}
}
}
if($differe == -1)
{
$errors[] = 'Un message différé doit être prévu pour une date future.';
}
}
chercher L184:
if (empty($errors) && !isset($_POST['preview']))
remplacer:
if (empty($errors) && !isset($_POST['preview']) && ($differe > -1))
chercher L186:
// If it's a reply
ajouter avant:
if(($is_admmod) && ($differe == 1))
{
if ($tid)
{
/*poster, poster_id, poster_ip, message, timetopost, topic_id*/
$db->query('INSERT INTO '.$db->prefix.'delayed_posts (poster, poster_id, poster_ip, message, timetopost, topic_id, forum_id, subject) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].', \''.get_remote_address().'\', \''.$db->escape($message).'\', '.$differedate.', '.$tid.', '.$cur_posting['id'].', \''.$db->escape($cur_posting['subject']).'\')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
}
else if ($fid)
{
/*poster, poster_id, poster_ip, message, timetopost, forum_id, subject*/
$db->query('INSERT INTO '.$db->prefix.'delayed_posts (poster, poster_id, poster_ip, message, timetopost, forum_id, subject) VALUES(\''.$db->escape($username).'\', '.$pun_user['id'].', \''.get_remote_address().'\', \''.$db->escape($message).'\', '.$differedate.', '.$fid.', \''.$db->escape($subject).'\')') or error('Unable to create post', __FILE__, __LINE__, $db->error());
}
redirect('viewforum.php?id='.$cur_posting['id'], 'Message différé - '.$lang_post['Post redirect']);
}
else
{
chercher L349:
// If a topic id was specified in the url (it's a reply).
ajouter avant:
}
chercher L532:
$checkboxes[] = '<label><input type="checkbox" name="subscribe" value="1" tabindex="'.($cur_index++).'"'.(isset($_POST['subscribe']) ? ' checked="checked"' : '').' />'.$lang_post['Subscribe'];
ajouter après:
if($is_admmod)
{
?>
<script type="text/javascript">
function Check2(checkbox)
{
if(! checkbox.checked)
{
document.getElementById('form_date').style.display='none';
}
else
{
document.getElementById('form_date').style.display='inline';
}
}
</script>
<?php
$str = '<label>';
$str .= '<input type="checkbox" name="differe" value="1" onclick="Check2(this)" tabindex="'.($cur_index++).'"'.(isset($_POST['differe']) ? ' checked="checked"' : '').' />Message différé';
$str .= '';
$checkboxes[] = $str;
}
chercher L547:
<?php echo implode('<br /></label>'."\n\t\t\t\t", $checkboxes).'<br /></label>'."\n" ?>
remplacer:
<?php echo implode('<br /></label>'."\n\t\t\t\t", $checkboxes).'<br /></label>'."\n";
if($is_admmod)
{
echo '<div id="form_date"';
if($differe == 0)
echo ' style="display:none;"';
echo '>';
?><label>Date de post<?php
if(isset($_POST['form_date']))
{
$form = array_map("intval", $_POST['form_date']);
$mois = $form['m'];
$jour = $form['d'];
$annee = $form['y'];
$heure = $form['h'];
$minute = $form['mn'];
}
else
{
$now = time();
$mois = date("m", $now);
$jour = date("d", $now);
$annee = date("Y", $now);
$heure = date("H", $now);
$minute = date("i", $now);
} ?></label>
<select name="form_date[d]">
<?php for($i=1;$i<32;$i++) { ?>
<option value="<?php echo $i; ?>"<?php if ($jour==$i) echo ' selected="selected"' ?>><?php echo str_pad($i, 2, '0', STR_PAD_LEFT); ?></option>
<?php } ?>
</select>
<select name="form_date[m]">
<?php for($i=1;$i<13;$i++) { ?>
<option value="<?php echo $i; ?>"<?php if ($mois==$i) echo ' selected="selected"' ?>><?php echo str_pad($i, 2, '0', STR_PAD_LEFT); ?></option>
<?php } ?>
</select>
<select name="form_date[y]">
<?php $thisyear = date("Y");
for($i=$thisyear;$i<($thisyear+2);$i++) { ?>
<option value="<?php echo $i; ?>"<?php if ($annee==$i) echo ' selected="selected"' ?>><?php echo $i; ?></option>
<?php } ?>
</select>
<select name="form_date[h]">
<?php for($i=0;$i<24;$i++) { ?>
<option value="<?php echo $i; ?>"<?php if ($heure==$i) echo ' selected="selected"' ?>><?php echo str_pad($i, 2, '0', STR_PAD_LEFT); ?></option>
<?php } ?>
</select>
<select name="form_date[mn]">
<?php for($i=0;$i<60;$i++) { ?>
<option value="<?php echo $i; ?>"<?php if ($minute==$i) echo ' selected="selected"' ?>><?php echo str_pad($i, 2, '0', STR_PAD_LEFT); ?></option>
<?php } ?>
</select>
<?php
echo '</div>';
}
?>plugins/AMP_Messages_Differes.php (nouveau fichier à créer pour éditer un message ou en supprimer un)
<?php
/***********************************************************************
Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
This file is part of PunBB.
PunBB 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 2 of the License,
or (at your option) any later version.
PunBB 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
************************************************************************/
/***********************************************************************
PascL (kokoala2k3@free.fr)
************************************************************************/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
define('PLUGIN_URL', 'admin_loader.php?plugin=AMP_Messages_Differes.php');
$now = time();
if (isset($_GET['edit']))
{
$id = intval($_GET['edit']);
if(isset($_POST['form_sent']))
{
confirm_referrer(PLUGIN_URL.'&edit='.$id);
$subj = '';
$bSubject = false;
if(isset($_POST['subject_title']))
{
$subj = trim($_POST['subject_title']);
$bSubject = true;
}
$message = trim($_POST['content_message']);
if($message == null)
message('Le message ne peut être vide.');
$req = 'UPDATE '.$db->prefix.'delayed_posts SET message=\''.$db->escape($message).'\''.(($bSubject) ? ', subject=\''.$db->escape($subj).'\'' : '').' WHERE id='.$id;
$db->query($req) or error('Unable to update delayed pos', __FILE__, __LINE__, $db->error());
redirect(PLUGIN_URL, 'Message différé édité. Redirection ...');
}
$result2 = $db->query('SELECT * FROM '.$db->prefix.'delayed_posts WHERE id='.$id) or error('Unable to fetch list', __FILE__, __LINE__, $db->error());
if(!$db->num_rows($result2))
message('Cet id existe pas');
// Display the admin navigation menu
generate_admin_menu($plugin);
$data = $db->fetch_assoc($result2);
$newAnswer = false;
$subject = '';
$newTopic = false;
$auteur_id = $data['poster_id'];
$auteur_name = pun_htmlspecialchars($data['poster']);
$texte = pun_htmlspecialchars($data['message']);
$message_date = format_time($data['timetopost']);
$pollTopic = false;
if($data['topic_id'] > 0)
{
// réponse à un topic
$newAnswer = true;
}
else
if($data['forum_id'] > 0)
{
// nouveau topic
$newTopic = true;
$subject = pun_htmlspecialchars($data['subject']);
if($data['ptype'] > 0)
{
$pollTopic = true;
}
}
else
{
// cas impossible, on s'arrête si on arrive ici
message('Message indéterminé');
}
?>
<div class="blockform blocktable">
<h2><span>Message</span></h2>
<div class="box">
<form id="groups2" method="post" action="<?php echo PLUGIN_URL.'&edit='.$id; ?>" onsubmit="return process_form(this)">
<p class="submittop"><input type="submit" name="form_sent" value=" Envoyer " /></p>
<div class="inform">
<input type="hidden" name="diff_id" value="<?php echo $id ?>" />
<fieldset>
<legend>Edition</legend>
<div class="infldset">
<p>
Editer un message différé
</p>
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Etat</th>
<td>
<?php
if($newAnswer)
{
echo 'Réponse au sujet '.$data['topic_id'];
}
else
if($newTopic)
{
echo 'Nouveau sujet dans le forum '.$data['forum_id'];
if($pollTopic)
{
echo ' (avec sondage)';
}
}
?>
</td>
</tr>
<tr>
<th scope="row">Date d'envoi</th>
<td>
<?php
echo $message_date;
?>
</td>
</tr>
<tr>
<th scope="row">Auteur</th>
<td>
<?php
echo $auteur_name.' ['.$auteur_id.']';
?>
</td>
</tr>
<?php
if($newTopic)
{
?>
<tr>
<th scope="row">Titre du Sujet</th>
<td>
<input type="text" name="subject_title" size="25" maxlength="255" value="<?php echo $subject ?>" />
</td>
</tr>
<?php
}
?>
<tr>
<th scope="row">Message</th>
<td>
<textarea id="content_message" name="content_message" rows="10" cols="60"><?php echo $texte; ?></textarea>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="form_sent" value=" Envoyer " tabindex="3" /></p>
</form>
</div>
</div>
<?php
}
else if (isset($_GET['del']))
{
confirm_referrer(PLUGIN_URL);
$id = intval($_GET['del']);
if($id > 0) // on verifie que c'est positif...
{
$db->query('DELETE FROM '.$db->prefix.'delayed_posts WHERE id='.$id) or error('Unable to delete delayed message', __FILE__, __LINE__, $db->error());
}
redirect(PLUGIN_URL, 'Message différé supprimé. Redirection ...');
}
else // If not, we show the "Show text" form
{
// Display the admin navigation menu
generate_admin_menu($plugin);
?>
<div id="pollplugin" class="blockform blocktable">
<h2><span>Messages différés</span></h2>
<div class="box">
<div class="inbox">
<p>Ce plugin permet d'éditer, supprimer des messages différés.</p>
</div>
</div>
<h2 class="block2"><span>Editer un message</span></h2>
<div class="box">
<div class="fakeform">
<div class="inform">
<fieldset>
<legend>Modifier/supprimer les messages différés</legend>
<div class="infldset">
<p>Cliquez sur le lien souhaité.</p>
<?php
// Fetch count
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'delayed_posts') or error('Unable to fetch delayed posts count', __FILE__, __LINE__, $db->error());
$num_msg = $db->result($result);
// Determine the poll offset (based on $_GET['p'])
$num_pages = ceil($num_msg / 20);
$p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
$start_from = 20 * ($p - 1);
// Generate paging links
$paging_links = paginate($num_pages, $p, PLUGIN_URL);
?>
<p class="pagelink conl"><?php echo $paging_links ?></p>
<table cellspacing="0">
<?php
$result2 = $db->query('SELECT p.id, p.poster, p.topic_id, p.forum_id, p.question, p.subject, p.timetopost, f.forum_name FROM '.$db->prefix.'delayed_posts AS p INNER JOIN '.$db->prefix.'forums AS f ON f.id=p.forum_id ORDER BY p.timetopost ASC, p.id ASC LIMIT '.$start_from.',20') or error('Unable to fetch list', __FILE__, __LINE__, $db->error());
if($db->num_rows($result2))
{
while ($current = $db->fetch_assoc($result2))
{
echo "\t\t\t\t\t\t\t\t".'<tr><th scope="row">';
echo '<a href="'.PLUGIN_URL.'&edit='.$current['id'].'">Editer</a>';
echo ' - <a href="'.PLUGIN_URL.'&del='.$current['id'].'">Supprimer</a>';
echo '</th><td>';
if($current['topic_id'] > 0)
{
echo 'Réponse à <a href="viewtopic.php?id='.$current['topic_id'].'">'.pun_htmlspecialchars($current['subject']).'</a>';
}
else
{
echo 'Nouveau sujet dans <a href="viewforum.php?id='.$current['forum_id'].'">'.pun_htmlspecialchars($current['forum_name']).'</a>';
echo ':'.pun_htmlspecialchars($current['subject']);
if($current['ptype'] > 0)
{
echo ' avec sondage';
}
}
echo '</td>';
echo '<td>'.format_time($current['timetopost']);
echo '</td>';
echo '</tr>'."\n";
}
}
else
{
echo '<tr><td><strong>Aucun message différé dans la base de données.</strong></td></tr>';
}
?>
</table>
</div>
</fieldset>
</div>
</div>
</div>
</div>
<?php
}
// Note that the script just ends here. The footer will be included by admin_loader.php.subject
Bouh !
StarShip Renaissance
Hors ligne
Pages : 1