Créez un nouveau fichier pour une exécution cron nommé emailgeeklogstories_html.sh
#!/usr/local/bin/php -q <?php include('path/to/daily_digest_html.php'); COM_emailUserTopics_html(); ?>
Créez le fichier daily_digest_html.php
<?php /* Reminder: always indent with 4 spaces (no tabs). */ // +---------------------------------------------------------------------------+ // | Geeklog 1.4.1 | // +---------------------------------------------------------------------------+ // | daily_digest_html.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_digest_html, v 1.00 2007/12/14 ::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/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( 'À', '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 ); return( $string ); } /** * Send an email. * * All emails sent by Geeklog are sent through this function now. * * @param string $to recipients name and email address * @param string $subject subject of the email * @param string $message the text of the email * @param string $from (optional) sender of the the email * @param boolean $html (optional) true if to be sent as HTML email * @param int $priority (optional) add X-Priority header, if > 0 * @param string $cc (optional) other recipients (name + email) * @return boolean true if successful, otherwise false * * @note Please note that using the $cc parameter will expose the email addresses * of all recipients. Use with care. * */ function COM_mail2( $to, $subject, $message, $from = '', $html = true, $priority = 0, $cc = '' ) { global $_CONF, $LANG_CHARSET; static $mailobj; if( empty( $from )) { $from = COM_formatEmailAddress( $_CONF['site_name'], $_CONF['site_mail']); } $to = substr( $to, 0, strcspn( $to, "\r\n" )); $cc = substr( $cc, 0, strcspn( $cc, "\r\n" )); $from = substr( $from, 0, strcspn( $from, "\r\n" )); $subject = substr( $subject, 0, strcspn( $subject, "\r\n" )); $subject = COM_emailEscape( $subject ); if( function_exists( 'CUSTOM_mail' )) { return CUSTOM_mail( $to, $subject, $message, $from, $html, $priority, $cc ); } include_once( 'Mail.php' ); include_once( 'Mail/RFC822.php' ); $method = $_CONF['mail_settings']['backend']; if( !isset( $mailobj )) { if(( $method == 'sendmail' ) || ( $method == 'smtp' )) { $mailobj =& Mail::factory( $method, $_CONF['mail_settings'] ); } else { $method = 'mail'; $mailobj =& Mail::factory( $method ); } } if( empty( $LANG_CHARSET )) { $charset = $_CONF['default_charset']; if( empty( $charset )) { $charset = 'iso-8859-1'; } } else { $charset = $LANG_CHARSET; } $headers = array(); $headers['From'] = $from; if( $method != 'mail' ) { $headers['To'] = $to; } if( !empty( $cc )) { $headers['Cc'] = $cc; } $headers['Date'] = date( 'r' ); // RFC822 formatted date if( $method == 'smtp' ) { list( $usec, $sec ) = explode( ' ', microtime()); $m = substr( $usec, 2, 5 ); $headers['Message-Id'] = '<' . date( 'YmdHis' ) . '.' . $m . '@' . $_CONF['mail_settings']['host'] . '>'; } if( $html ) { $headers['Content-Type'] = 'text/html; charset=' . $charset; $headers['Content-Transfer-Encoding'] = '8bit'; } else { $headers['Content-Type'] = 'text/plain; charset=' . $charset; } $headers['Subject'] = $subject; if( $priority > 0 ) { $headers['X-Priority'] = $priority; } $headers['X-Mailer'] = 'GeekLog ' . VERSION; $retval = $mailobj->send( $to, $headers, $message ); if( $retval !== true ) { COM_errorLog( $retval->toString(), 1 ); } return( $retval === true ? true : false ); } /** * 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_emailUserTopics_html() { 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() ) . "<br />"; for( $y = 0; $y < $nsrows; $y++ ) { // Loop through stories building the requested email message $S = DB_fetchArray( $stories ); $mailtext .= "<br />------------------------------<br /><br />"; $mailtext .= "$LANG08[31]: " . COM_undoSpecialChars2( stripslashes( $S['title'] )) . "<br />"; 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 . "<br />"; } $mailtext .= "$LANG08[32]: " . strftime( $_CONF['date'], strtotime( $S['day' ])) . "<br /><br />"; if( $_CONF['emailstorieslength'] > 0 ) { $storytext = $S['introtext'] ; if( $_CONF['emailstorieslength'] > 1 ) { $storytext = $S['introtext'] . "<br /><br />" . $S['bodytext'] ; } $mailtext .= $storytext . "<br /><br />"; } $mailtext .= $LANG08[33] . ' ' . COM_buildUrl( $_CONF['site_url'] . '/article.php?story=' . $S['sid'] ) . "<br />"; } $mailtext .= "<br />------------------------------<br />"; $mailtext .= "<br />$LANG08[34]<br />"; $mailtext .= "<br />------------------------------<br />"; $mailto = $U['username'] . ' <' . $U['email'] . '>'; COM_mail2( $mailto, $subject, $mailtext ); } DB_query( "UPDATE {$_TABLES['vars']} SET value = NOW() WHERE name = 'lastemailedstories'" ); } ?>