La méthode daily digest d'origine incluse dans le fichier lib-common.php expédie les emails au format texte brut et ne remplace place les caractères spéciaux dans le titre de l'email. Pour changer cela vous pouvez faire appel à un nouveau daily digest que nous nommerons daily-digest2
Créez un nouveau fichier pour une exécution cron nommé emailgeeklogstories2.sh qui appellera la fonction COM_emailUserTopics2()
Remplacez le path/to par votre chemin jusqu'à votre daily_digest2.php.
Par exemple /home/domain/public_html/daily_digest2.php'
#!/usr/local/bin/php -q <?php // This code snippet is responsible for emailing Geeklog stories to users // for the topics they select. // // For this script to work you must have compiled PHP so it can also be // used as a shell scripting language. You should call this script from // your crontab (man crontab). You will also need to set the exectuable // flags for this file. // Change this path to point to your daily_digest2.php file include('path/to/daily_digest2.php'); COM_emailUserTopics2(); ?>
Créez le fichier daily_digest2.php et copiez le code si dessous.
Modifiez les 2 chemins d'accès à votre config.php et lib-common.php.
Vous pouvez ajouter des caractères à remplacer en les ajoutant à la fonction COM_undoSpecialChars2.
<?php /* Reminder: always indent with 4 spaces (no tabs). */ // +---------------------------------------------------------------------------+ // | Geeklog 1.4.1 | // +---------------------------------------------------------------------------+ // | daily_digest2.php | // +---------------------------------------------------------------------------+ // | Copyright (C) 2000-2007 by the following authors: | // | | // | Authors: Tony Bibbs - tony AT tonybibbs DOT com | // | Mark Limburg - mlimburg AT users DOT sourceforge DOT net | // | Jason Whittenburg - jwhitten AT securitygeeks DOT com | // | Dirk Haun - dirk AT haun-online DOT de | // | Vincent Furia - vinny01 AT users DOT sourceforge DOT net | // | ::Ben - geeklog.fr | // +---------------------------------------------------------------------------+ // | | // | 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 2 | // | 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, write to the Free Software Foundation, | // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | // | | // +---------------------------------------------------------------------------+ // // $Id: daily_digest2,v 1.12 2008/06/10 ::Ben /** * Configuration Include: You should ONLY have to modify this 2 lines. * Leave the rest of this file intact! * * Make sure to include the name of the config file, * i.e. the path should end in .../config.php */ require_once( '/path/to/config.php' ); require_once( '/path/to/lib-common.php' ); /** * undo function for htmlspecialchars() * * This function translates HTML entities created by htmlspecialchars() back * into their ASCII equivalents. Also handles the entities for $, {, and }. * * @param string $string The string to convert. * @return string The converted string. * */ function COM_undoSpecialChars2( $string ) { $string = str_replace( '$', '$', $string ); $string = str_replace( '{', '{', $string ); $string = str_replace( '}', '}', $string ); $string = str_replace( '>', '>', $string ); $string = str_replace( '<', '<', $string ); $string = str_replace( '"', '"', $string ); $string = str_replace( '“', '"', $string ); $string = str_replace( '”', '"', $string ); $string = str_replace( ' ', ' ', $string ); $string = str_replace( '&', '&', $string ); $string = str_replace( 'À', 'A', $string ); $string = str_replace( 'à', 'à', $string ); $string = str_replace( 'Â', 'A', $string ); $string = str_replace( 'â', 'â', $string ); $string = str_replace( 'Ç', 'C', $string ); $string = str_replace( 'ç', 'ç', $string ); $string = str_replace( 'È', 'E', $string ); $string = str_replace( 'è', 'è', $string ); $string = str_replace( 'É', 'E', $string ); $string = str_replace( 'é', 'é', $string ); $string = str_replace( 'Ê', 'E', $string ); $string = str_replace( 'ê', 'ê', $string ); $string = str_replace( 'Ë', 'E', $string ); $string = str_replace( 'ë', 'ë', $string ); $string = str_replace( 'Î', 'I', $string ); $string = str_replace( 'î', 'î', $string ); $string = str_replace( 'Ï', 'I', $string ); $string = str_replace( 'ï', 'ï', $string ); $string = str_replace( 'Ô', 'O', $string ); $string = str_replace( 'ô', 'ô', $string ); $string = str_replace( 'Œ', 'OE', $string ); $string = str_replace( 'œ', 'oe', $string ); $string = str_replace( 'Ù', 'U', $string ); $string = str_replace( 'ù', 'ù', $string ); $string = str_replace( 'Û', 'U', $string ); $string = str_replace( 'û', 'û', $string ); $string = str_replace( 'Ü', 'U', $string ); $string = str_replace( 'ü', 'ü', $string ); $string = str_replace( 'Ÿ', 'Y', $string ); $string = str_replace( 'ÿ', 'ÿ', $string ); $string = str_replace( '’', '\'', $string ); $string = str_replace( '‘', '\'', $string ); return( $string ); } /** * This will email new stories in the topics that the user is interested in * * In account information the user can specify which topics for which they * will receive any new article for in a daily digest. * * @return void */ function COM_emailUserTopics2() { global $_CONF, $_TABLES, $LANG08, $LANG24; $subject = strip_tags( $_CONF['site_name'] . $LANG08[30] . strftime( '%Y-%m-%d', time() )); $authors = array(); // Get users who want stories emailed to them $usersql = "SELECT username,email,etids,{$_TABLES['users']}.uid AS uuid " . "FROM {$_TABLES['users']}, {$_TABLES['userindex']} " . "WHERE {$_TABLES['users']}.uid > 1 AND {$_TABLES['userindex']}.uid = {$_TABLES['users']}.uid AND (etids <> '-' OR etids IS NULL) ORDER BY {$_TABLES['users']}.uid"; $users = DB_query( $usersql ); $nrows = DB_numRows( $users ); $lastrun = DB_getItem( $_TABLES['vars'], 'value', "name = 'lastemailedstories'" ); // For each user, pull the stories they want and email it to them for( $x = 1; $x <= $nrows; $x++ ) { $U = DB_fetchArray( $users ); $storysql = array(); $storysql['mysql'] = "SELECT sid,uid,date AS day,title,introtext,bodytext"; $storysql['mssql'] = "SELECT sid,uid,date AS day,title,CAST(introtext AS text) AS introtext,CAST(bodytext AS text) AS introtext"; $commonsql = " FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() AND date >= '{$lastrun}'"; $topicsql = "SELECT tid FROM {$_TABLES['topics']}" . COM_getPermSQL( 'WHERE', $U['uuid'] ); $tresult = DB_query( $topicsql ); $trows = DB_numRows( $tresult ); if( $trows == 0 ) { // this user doesn't seem to have access to any topics ... continue; } $TIDS = array(); for( $i = 1; $i <= $trows; $i++ ) { $T = DB_fetchArray( $tresult ); $TIDS[] = $T['tid']; } if( !empty( $U['etids'] )) { $ETIDS = explode( ' ', $U['etids'] ); $TIDS = array_intersect( $TIDS, $ETIDS ); } if( sizeof( $TIDS ) > 0) { $commonsql .= " AND (tid IN ('" . implode( "','", $TIDS ) . "'))"; } $commonsql .= COM_getPermSQL( 'AND', $U['uuid'] ); $commonsql .= ' ORDER BY featured DESC, date DESC'; $storysql['mysql'] .= $commonsql; $storysql['mssql'] .= $commonsql; $stories = DB_query( $storysql ); $nsrows = DB_numRows( $stories ); if( $nsrows == 0 ) { // If no new stories where pulled for this user, continue with next continue; } $mailtext = $LANG08[29] . strftime( $_CONF['shortdate'], time() ) . "\n"; for( $y = 0; $y < $nsrows; $y++ ) { // Loop through stories building the requested email message $S = DB_fetchArray( $stories ); $mailtext .= "\n------------------------------\n\n"; $mailtext .= "$LANG08[31]: " . COM_undoSpecialChars2( stripslashes( $S['title'] )) . "\n"; if( $_CONF['contributedbyline'] == 1 ) { if( empty( $authors[$S['uid']] )) { $storyauthor = COM_getDisplayName ($S['uid']); $authors[$S['uid']] = $storyauthor; } else { $storyauthor = $authors[$S['uid']]; } $mailtext .= "$LANG24[7]: " . $storyauthor . "\n"; } $mailtext .= "$LANG08[32]: " . strftime( $_CONF['date'], strtotime( $S['day' ])) . "\n\n"; if( $_CONF['emailstorieslength'] > 0 ) { $storytext = COM_undoSpecialChars2( strip_tags( PLG_replaceTags( stripslashes( $S['introtext'] )))); if( $_CONF['emailstorieslength'] > 1 ) { $storytext = COM_truncate( $storytext, $_CONF['emailstorieslength'], '...' ); } $mailtext .= $storytext . "\n\n"; } $mailtext .= $LANG08[33] . ' ' . COM_buildUrl( $_CONF['site_url'] . '/article.php?story=' . $S['sid'] ) . "\n"; } $mailtext .= "\n------------------------------\n"; $mailtext .= "\n$LANG08[34]\n"; $mailtext .= "\n------------------------------\n"; $mailto = $U['username'] . ' <' . $U['email'] . '>'; COM_mail( $mailto, $subject, $mailtext ); } DB_query( "UPDATE {$_TABLES['vars']} SET value = NOW() WHERE name = 'lastemailedstories'" ); } ?>