##############################################################
## MOD Title: Email Digests
## MOD Author: MarkDHamill < mhamill@computer.org > (Mark D. Hamill) http://www.potomactavern.org
## MOD Author, Secondary: Indemmity83 < Indemnity83@dormlife.us > (Kyle D. Klaus) http://www.dormlife.us
## MOD Author, Secondary: david63 < david.wood@pear-tree.org.uk > (David Wood) n/a
## MOD Description: Sends customized email digests of forum messages to subscribers
## MOD Version: 1.3.4
##
## Installation Level: Advanced
## Installation Time: 60 Minutes to several days, depending on whether you need to set up SSH and
##                    your skills at the server operating system command line.
##
## Files To Edit:	bbcode.php,
##			functions.php,
##			constants.php,
##			admin_forums.php,
##			groupcp_info_body.tpl,
##
## Included Files:	digests.php,
##			digests_common.php,
##			digests_user_cp.php,
##			install_digests.php,
##			mail_digests.php,
##			admin_digests_management.php,
##			admin_digests_add_users.php,
##			admin_digests_add_groups.php,
##			admin_digests_config.php,
##			admin_digests_confirm.php,
##			admin_digests_dump.php,
##			admin_digests_log.php,
##			admin_digests_mail.php,
##			admin_digests_verify.php,
##			digest_times.php,
##			functions_digests.php,
##			functions_digests_selects.php,
##			lang_digests.php,
##			mail_digests_confirm.tpl,
##			mail_digests_html.tpl,
##			mail_digests_text.tpl,
##			digests.tpl,
##			digests_management.tpl,
##			digests_config_body.tpl,
##			digests_confirm.tpl,
##			digests_dump.tpl,
##			digests_dump_body.tpl,
##			digests_log.tpl,
##			digests_mail.tpl,
##			digest_times.tpl,
##			digests_user_cp.tpl,
##			digests_verify.tpl,
##			digests_verify_body.tpl,
##			mail_digests.tpl,
##			digest_user_select_body.tpl,
##			icon_mini_digest.gif,
##			logo_digests.gif,
##			batch_scheduling.txt
##
############################################################################################################# 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the latest version of this MOD.
## Downloading this MOD from other sites could cause malicious code to enter into your phpBB Forum. As such,
## phpBB will not offer support for MOD's not offered in our MOD-Database, located at: http://www.phpbb.com/mods/ 
##############################################################
## Author Notes:
##
############################################################## 
## MOD History: 
## 
##   (Look at install_digests_132.txt for MOD History.)
##
## 
############################################################################################################# 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
#############################################################################################################
# 
#-----[ COPY ]------------------------------------------
#
copy digests.php to digests.php
copy digests_common.php to digests_common.php
copy digests_user_cp.php to digests_user_cp.php
copy install_digests.php to install_digests.php
copy admin/admin_digests_management.php to admin/admin_digests_management.php
copy admin/admin_digests_add_users.php to admin/admin_digests_add_users.php
copy admin/admin_digests_add_groups.php to admin/admin_digests_add_groups.php
copy admin/admin_digests_config.php to admin/admin_digests_config.php
copy admin/admin_digests_confirm.php to admin/admin_digests_confirm.php
copy admin/admin_digests_dump.php to admin/admin_digests_dump.php
copy admin/admin_digests_log.php to admin/admin_digests_log.php
copy admin/admin_digests_mail.php to admin/admin_digests_mail.php
copy admin/admin_digests_verify.php to admin/admin_digests_verify.php
copy admin/digest_times.php to admin/digest_times.php
copy admin/mail_digests.php to admin/mail_digests.php
copy includes/functions_digests.php to includes/functions_digests.php
copy language/lang_english/lang_digests.php to language/lang_english/lang_digests.php
copy language/lang_english/email/mail_digests_confirm.tpl to language/lang_english/email/mail_digests_confirm.tpl
copy language/lang_english/email/mail_digests_html.tpl to language/lang_english/email/mail_digests_html.tpl
copy language/lang_english/email/mail_digests_text.tpl to language/lang_english/email/mail_digests_text.tpl
copy templates/subSilver/digests.tpl to templates/subSilver/digests.tpl
copy templates/subSilver/digests_user_cp.tpl to templates/subSilver/digests_user_cp.tpl
copy templates/subSilver/admin/digests_management.tpl to templates/subSilver/admin/digests_management.tpl
copy templates/subSilver/admin/digests_config_body.tpl to templates/subSilver/admin/digests_config_body.tpl
copy templates/subSilver/admin/digests_confirm.tpl to templates/subSilver/admin/digests_confirm.tpl
copy templates/subSilver/admin/digests_dump.tpl to templates/subSilver/admin/digests_dump.tpl
copy templates/subSilver/admin/digests_dump_body.tpl to templates/subSilver/admin/digests_dump_body.tpl
copy templates/subSilver/admin/digests_log.tpl to templates/subSilver/admin/digests_log.tpl
copy templates/subSilver/admin/digests_mail.tpl to templates/subSilver/admin/digests_mail.tpl
copy templates/subSilver/admin/digest_times.tpl to templates/subSilver/admin/digest_times.tpl
copy templates/subSilver/admin/digests_verify.tpl to templates/subSilver/admin/digests_verify.tpl
copy templates/subSilver/admin/digests_verify_body.tpl to templates/subSilver/admin/digests_verify_body.tpl
copy templates/subSilver/admin/digests_user_select_body.tpl to templates/subSilver/admin/digests_user_select_body.tpl
copy templates/subSilver/admin/mail_digests.tpl to templates/subSilver/admin/mail_digests.tpl
copy templates/subSilver/admin/digests_user_lookup_body.tpl to templates/subSilver/admin/digests_user_lookup_body.tpl
copy templates/subSilver/images/icon_mini_digest.gif to templates/subSilver/images/icon_mini_digest.gif
copy templates/subSilver/images/logo_digests.gif to templates/subSilver/images/logo_digests.gif
#
#-----[ SQL ]--------
#
UPDATE phpbb_digests_config SET config_value = '1.3.4' WHERE config_name = 'digest_version';

INSERT INTO phpbb_digests_config (config_name, config_value) VALUES ('allow_direct_run', '0');
INSERT INTO phpbb_digests_config (config_name, config_value) VALUES ('allow_exclude', '0');
INSERT INTO phpbb_digests_config (config_name, config_value) VALUES ('direct_password', '');
INSERT INTO phpbb_digests_config (config_name, config_value) VALUES ('show_ip', '0');
INSERT INTO phpbb_digests_config (config_name, config_value) VALUES ('theme_type', '0');

ALTER TABLE phpbb_digests ADD digest_include_forum TINYINT(1) DEFAULT '1' NOT NULL ;

ALTER TABLE phpbb_groups ADD group_digest tinyint(1) default '0' NOT NULL;

ALTER TABLE phpbb_digests_forums DROP include_forum; 

ALTER TABLE phpbb_posts CHANGE urgent_post urgent_post TINYINT( 1 ) NOT NULL DEFAULT 0;

ALTER TABLE phpbb_digests_log ADD log_posts int(11) NULL DEFAULT 0;

UPDATE phpbb_digests_log SET log_status = 4 WHERE log_status = 0;
#
#-----[ OPEN ]------------------------------------------
#
groupcp.php
#
#
#-----[ FIND ]------------------------------------------
#
if ( !($group_info = $db->sql_fetchrow($result)) )
	{
		message_die(GENERAL_MESSAGE, $lang['Group_not_exist']); 
	}
#
#-----[ AFTER, ADD ]------------------------------------------
#

	$group_digest = $group_info['group_digest'];
#
#-----[ FIND ]------------------------------------------
#
if ( $is_moderator )
	{
		$template->assign_block_vars('switch_mod_option', array());
		$template->assign_block_vars('switch_add_member', array());
#
#-----[ AFTER, ADD ]------------------------------------------
#

		if ($group_digest == TRUE)
		{
			$template->assign_block_vars('switch_digest_option', array());
		}
#
#-----[ OPEN ]------------------------------------------
#
admin/admin_forums.php
#
#-----[ FIND ]------------------------------------------
#
$sql = "DELETE FROM " . PRUNE_TABLE . "
				WHERE forum_id = $from_id";
			if( !$result = $db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "Couldn't delete forum prune information!", "", __LINE__, __FILE__, $sql);
			}
#
#-----[ AFTER, ADD ]------------------------------------------
#

			$sql = "DELETE FROM " . DIGEST_FORUMS_TABLE . "
				WHERE forum_id = $from_id";
			if( !$result = $db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "Couldn't delete digest forum data", "", __LINE__, __FILE__, $sql);
			}
#
#-----[ OPEN ]------------------------------------------
#
includes/bbcode.php
#
#-----[ FIND ]------------------------------------------
#
define("BBCODE_UID_LEN", 10);
#
#-----[ AFTER, ADD ]------------------------------------------
#
include_once($phpbb_root_path . 'includes/functions_digests.'.$phpEx);
#
#-----[ FIND ]------------------------------------------
#
function smilies_pass($message)
{
	static $orig, $repl;
#
#-----[ AFTER, ADD ]------------------------------------------
#
	$siteURL = get_site_url();
#
#-----[ FIND ]------------------------------------------
#
$repl[] = '<img src="'. $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="' . $smilies[$i]['emoticon'] . '" border="0" />';
#
#-----[ REPLACE WITH ]------------------------------------------
#
$repl[] = '<img src="' . $siteURL . '/' . $board_config['smilies_path'] . '/' . $smilies[$i]['smile_url'] . '" alt="' . $smilies[$i]['emoticon'] . '" border="0" />';
#
#-----[ OPEN ]------------------------------------------
#
includes/constants.php
#
#-----[ FIND ]------------------------------------------
#
define('PAGE_DIGEST', -2500);
#
#-----[ REPLACE WITH ]------------------------------------------
#
define('PAGE_DIGEST', -2025);
#
#-----[ OPEN ]------------------------------------------
#
includes/emailer.php
#
#-----[ FIND ]------------------------------------------
#
function send()
#
#-----[ REPLACE WITH ]------------------------------------------
#
function send($is_html = '')
#
#-----[ FIND ]------------------------------------------
#
$this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\nMessage-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By phpBB2\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '')  . (($bcc != '') ? "Bcc: $bcc\n" : '');
#
#-----[ REPLACE WITH ]------------------------------------------
#
if ($is_html)
		{
 			$this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\nMessage-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By phpBB2\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '')  . (($bcc != '') ? "Bcc: $bcc\n" : '');
		}
		else 
		{
			$this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\nMessage-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By phpBB2\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '')  . (($bcc != '') ? "Bcc: $bcc\n" : '');
		}
#
#-----[ OPEN ]------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------
#
function init_userprefs($userdata)
{
	global $board_config, $theme, $images;
	global $template, $lang, $phpEx, $phpbb_root_path;
	global $nav_links;
#
#-----[ REPLACE WITH ]------------------------------------------
#
function init_userprefs($userdata, $mode = '')
{
	global $board_config, $theme, $images;
	global $lang, $phpEx, $phpbb_root_path;
	global $nav_links;

	if ($mode != 'digest')
	{
		global $template;
	}
#
#-----[ FIND ]------------------------------------------
#
if ( $theme = setup_style($userdata['user_style']) )
#
#-----[ REPLACE WITH ]------------------------------------------
#
if ( $theme = setup_style($userdata['user_style'], $mode) )
#
#-----[ FIND ]------------------------------------------
#
$theme = setup_style($board_config['default_style']);
#
#-----[ REPLACE WITH ]------------------------------------------
#
$theme = setup_style($board_config['default_style'], $mode);
#
#-----[ FIND ]------------------------------------------
#
function setup_style($style)
{
	global $db, $board_config, $template, $images, $phpbb_root_path;
#
#-----[ REPLACE WITH ]------------------------------------------
#
function setup_style($style, $mode = '')
{
	global $db, $board_config, $images, $phpbb_root_path;

	if ($mode != 'digest')
	{
		global $template;
	}
#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_faq.php
#
#
#-----[ FIND ]------------------------------------------
#
$faq[] = array("How do I get started?", "Just click on the Digests link near the top right part of any page. Or if you prefer <a href=\"./digests.php\">click here</a>.");
#
#-----[ REPLACE WITH ]------------------------------------------
#
$faq[] = array("How do I get started?", "Just click on the Digests link near the top right part of any page. Or if you prefer <a href=\"./digests_user_cp.php\">click here</a>.");
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/groupcp_info_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<td class="row2"><span class="gen"><span class="gen"><input type="radio" name="group_type" value="{S_GROUP_OPEN_TYPE}" {S_GROUP_OPEN_CHECKED} /> {L_GROUP_OPEN} &nbsp;&nbsp;<input type="radio" name="group_type" value="{S_GROUP_CLOSED_TYPE}" {S_GROUP_CLOSED_CHECKED} />	{L_GROUP_CLOSED} &nbsp;&nbsp;<input type="radio" name="group_type" value="{S_GROUP_HIDDEN_TYPE}" {S_GROUP_HIDDEN_CHECKED} />	{L_GROUP_HIDDEN} &nbsp;&nbsp; <input class="mainoption" type="submit" name="groupstatus" value="{L_UPDATE}" />&nbsp;&nbsp;<input class="mainoption" type="submit" name="digest_options" value="{L_DIGEST_OPTIONS}" />
#
#-----[ REPLACE WITH ]------------------------------------------
#
<td class="row2"><span class="gen"><span class="gen"><input type="radio" name="group_type" value="{S_GROUP_OPEN_TYPE}" {S_GROUP_OPEN_CHECKED} /> {L_GROUP_OPEN} &nbsp;&nbsp;<input type="radio" name="group_type" value="{S_GROUP_CLOSED_TYPE}" {S_GROUP_CLOSED_CHECKED} />	{L_GROUP_CLOSED} &nbsp;&nbsp;<input type="radio" name="group_type" value="{S_GROUP_HIDDEN_TYPE}" {S_GROUP_HIDDEN_CHECKED} />	{L_GROUP_HIDDEN} &nbsp;&nbsp; <input class="mainoption" type="submit" name="groupstatus" value="{L_UPDATE}" />
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
# 
# EoM 