View | Details | Raw Unified | Return to bug 6225
Collapse All | Expand All

(-)a/classes/install/Install.inc.php (+13 lines)
 Lines 65-70   class Install extends PKPInstall { Link Here 
65
			$this->executeSQL(sprintf('INSERT INTO users (user_id, username, first_name, last_name, password, email, date_registered, date_last_login) VALUES (%d, \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', 1, $this->getParam('adminUsername'), $this->getParam('adminUsername'), $this->getParam('adminUsername'), Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')), $this->getParam('adminEmail'), Core::getCurrentDate(), Core::getCurrentDate()));
65
			$this->executeSQL(sprintf('INSERT INTO users (user_id, username, first_name, last_name, password, email, date_registered, date_last_login) VALUES (%d, \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', 1, $this->getParam('adminUsername'), $this->getParam('adminUsername'), $this->getParam('adminUsername'), Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')), $this->getParam('adminEmail'), Core::getCurrentDate(), Core::getCurrentDate()));
66
			$this->executeSQL(sprintf('INSERT INTO roles (user_id, role_id) VALUES (%d, %d)', 0, 1, ROLE_ID_SITE_ADMIN));
66
			$this->executeSQL(sprintf('INSERT INTO roles (user_id, role_id) VALUES (%d, %d)', 0, 1, ROLE_ID_SITE_ADMIN));
67
67
68
			// Install email template list and data for each locale
69
			$emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
70
			$this->executeSQL($emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), true));
71
			foreach ($this->installedLocales as $locale) {
72
				$this->executeSQL($emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale), true));
73
			}
68
		} else {
74
		} else {
69
			// Add initial site data
75
			// Add initial site data
70
			$locale = $this->getParam('locale');
76
			$locale = $this->getParam('locale');
 Lines 80-85   class Install extends PKPInstall { Link Here 
80
				return false;
86
				return false;
81
			}
87
			}
82
88
89
			// Install email template list and data for each locale
90
			$emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
91
			$emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
92
			foreach ($this->installedLocales as $locale) {
93
				$emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
94
			}
95
83
			// Install site settings
96
			// Install site settings
84
			$siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
97
			$siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
85
			$siteSettingsDao->installSettings('registry/siteSettings.xml', array(
98
			$siteSettingsDao->installSettings('registry/siteSettings.xml', array(
(-)a/classes/mail/EmailTemplate.inc.php (-193 lines)
 Lines 1-193    Link Here 
1
<?php
2
3
/**
4
 * @file EmailTemplate.inc.php
5
 *
6
 * Copyright (c) 2005-2010 Alec Smecher and John Willinsky
7
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8
 *
9
 * BaseEmailTemplate, EmailTemplate classes implemented here; these
10
 * describe basic email template properties.
11
 *
12
 * @package mail
13
 *
14
 * $Id$
15
 */
16
17
/**
18
 * Email template base class.
19
 */
20
class BaseEmailTemplate extends DataObject {
21
22
	/**
23
	 * Constructor.
24
	 */
25
	function BaseEmailTemplate() {
26
		parent::DataObject();
27
	}
28
29
	//
30
	// Get/set methods
31
	//
32
33
	/**
34
	 * Get ID of email template.
35
	 * @return int
36
	 */
37
	function getEmailId() {
38
		return $this->getData('emailId');
39
	}
40
41
	/**
42
	 * Set ID of email template.
43
	 * @param $emailId int
44
	 */
45
	function setEmailId($emailId) {
46
		return $this->setData('emailId', $emailId);
47
	}
48
49
	/**
50
	 * Get key of email template.
51
	 * @return string
52
	 */
53
	function getEmailKey() {
54
		return $this->getData('emailKey');
55
	}
56
57
	/**
58
	 * Set key of email template.
59
	 * @param $emailKey string
60
	 */
61
	function setEmailKey($emailKey) {
62
		return $this->setData('emailKey', $emailKey);
63
	}
64
65
	/**
66
	 * Get the enabled setting of email template.
67
	 * @return boolean
68
	 */
69
	function getEnabled() {
70
		return $this->getData('enabled');
71
	}
72
73
	/**
74
	 * Set the enabled setting of email template.
75
	 * @param $enabled boolean
76
	 */
77
	function setEnabled($enabled) {
78
		return $this->setData('enabled', $enabled);
79
	}
80
81
	/**
82
	 * Check if email template is allowed to be disabled.
83
	 * @return boolean
84
	 */
85
	function getCanDisable() {
86
		return $this->getData('canDisable');
87
	}
88
89
	/**
90
	 * Set whether or not email template is allowed to be disabled.
91
	 * @param $canDisable boolean
92
	 */
93
	function setCanDisable($canDisable) {
94
		return $this->setData('canDisable', $canDisable);
95
	}
96
97
}
98
99
100
/**
101
 * Email template with data for all supported locales.
102
 */
103
class EmailTemplate extends BaseEmailTemplate {
104
105
	/** @var $localeData array of localized email template data */
106
	var $localeData;
107
108
	/**
109
	 * Constructor.
110
	 */
111
	function EmailTemplate() {
112
		parent::BaseEmailTemplate();
113
		$this->localeData = array();
114
	}
115
116
	/**
117
	 * Add a new locale to store data for.
118
	 * @param $locale string
119
	 */
120
	function addLocale($locale) {
121
		$this->localeData[$locale] = array();
122
	}
123
124
	/**
125
	 * Get set of supported locales for this template.
126
	 * @return array
127
	 */
128
	function getLocales() {
129
		return array_keys($this->localeData);
130
	}
131
132
	//
133
	// Get/set methods
134
	//
135
136
	/**
137
	 * Get description of email template.
138
	 * @param $locale string
139
	 * @return string
140
	 */
141
	function getDescription($locale) {
142
		return isset($this->localeData[$locale]['description']) ? $this->localeData[$locale]['description'] : '';
143
	}
144
145
	/**
146
	 * Set description of email template.
147
	 * @param $locale string
148
	 * @param $description string
149
	 */
150
	function setDescription($locale, $description) {
151
		$this->localeData[$locale]['description'] = $description;
152
	}
153
154
	/**
155
	 * Get subject of email template.
156
	 * @param $locale string
157
	 * @return string
158
	 */
159
	function getSubject($locale = null) {
160
		if ($locale === null) $locale = Locale::getLocale();
161
		return isset($this->localeData[$locale]['subject']) ? $this->localeData[$locale]['subject'] : '';
162
	}
163
164
	/**
165
	 * Set subject of email template.
166
	 * @param $locale string
167
	 * @param $subject string
168
	 */
169
	function setSubject($locale, $subject) {
170
		$this->localeData[$locale]['subject'] = $subject;
171
	}
172
173
	/**
174
	 * Get body of email template.
175
	 * @param $locale string
176
	 * @return string
177
	 */
178
	function getBody($locale = null) {
179
		if ($locale === null) $locale = Locale::getLocale();
180
		return isset($this->localeData[$locale]['body']) ? $this->localeData[$locale]['body'] : '';
181
	}
182
183
	/**
184
	 * Set body of email template.
185
	 * @param $locale string
186
	 * @param $body string
187
	 */
188
	function setBody($locale, $body) {
189
		$this->localeData[$locale]['body'] = $body;
190
	}
191
}
192
193
?>
(-)a/classes/mail/EmailTemplateDAO.inc.php (-156 / +41 lines)
 Lines 1-167    Link Here 
1
<?php
1
<?php
2
2
3
/**
3
/**
4
 * @file EmailTemplateDAO.inc.php
4
 * @file classes/mail/EmailTemplateDAO.inc.php
5
 *
5
 *
6
 * Copyright (c) 2005-2010 Alec Smecher and John Willinsky
6
 * Copyright (c) 2005-2010 Alec Smecher and John Willinsky
7
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
7
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8
 *
8
 *
9
 * @package mail
10
 * @class EmailTemplateDAO
9
 * @class EmailTemplateDAO
10
 * @ingroup mail
11
 * @see EmailTemplate
11
 *
12
 *
12
 * Class for Email Template DAO.
13
 * @brief Operations for retrieving and modifying Email Template objects.
13
 * Operations for retrieving and modifying Email Template objects.
14
 *
15
 * $Id$
16
 */
14
 */
17
15
18
import('classes.mail.EmailTemplate');
16
// $Id$
19
17
20
class EmailTemplateDAO extends DAO {
21
18
22
	/**
19
import('lib.pkp.classes.mail.PKPEmailTemplateDAO');
23
	 * Constructor.
20
import('lib.pkp.classes.mail.EmailTemplate');
24
	 */
25
	function EmailTemplateDAO() {
26
		parent::DAO();
27
	}
28
21
22
class EmailTemplateDAO extends PKPEmailTemplateDAO {
29
	/**
23
	/**
30
	 * Retrieve a base email template by key.
24
	 * Retrieve a base email template by key.
31
	 * @param $emailKey string
25
	 * @param $emailKey string
32
	 * @return BaseEmailTemplate
26
	 * @return BaseEmailTemplate
33
	 */
27
	 */
34
	function &getEmailTemplate($emailKey) {
28
	function &getBaseEmailTemplate($emailKey) {
35
		$result =& $this->retrieve(
29
		$returner =& parent::getBaseEmailTemplate($emailKey, 0, 0);
36
			'SELECT d.email_key, d.can_edit, d.can_disable, d.enabled
37
			FROM email_templates AS d
38
			WHERE d.email_key = ?',
39
			$emailKey
40
		);
41
42
		$returner = null;
43
		if ($result->RecordCount() != 0) {
44
			$returner =& $this->_returnEmailTemplateFromRow($result->GetRowAssoc(false));
45
		}
46
47
		$result->Close();
48
		unset($result);
49
50
		return $returner;
30
		return $returner;
51
	}
31
	}
52
32
53
	/**
33
	/**
54
	 * Internal function to return an email template object from a row.
34
	 * Retrieve localized email template by key.
55
	 * @param $row array
35
	 * @param $emailKey string
56
	 * @return EmailTemplate
36
	 * @return LocaleEmailTemplate
57
	 */
58
	function &_returnEmailTemplateFromRow(&$row) {
59
		$emailTemplate = new EmailTemplate();
60
		$emailTemplate->setEmailKey($row['email_key']);
61
		$emailTemplate->setEnabled($row['enabled']);
62
		$emailTemplate->setCanDisable($row['can_disable']);
63
64
		if (!HookRegistry::call('EmailTemplateDAO::_returnEmailTemplateFromRow', array(&$emailTemplate, &$row))) {
65
			$result =& $this->retrieve(
66
				'SELECT d.locale, d.description, d.subject, d.body
67
				FROM email_templates_data AS d
68
				WHERE d.email_key = ?',
69
				$row['email_key']
70
			);
71
72
			while (!$result->EOF) {
73
				$dataRow =& $result->GetRowAssoc(false);
74
				$emailTemplate->addLocale($dataRow['locale']);
75
				$emailTemplate->setSubject($dataRow['locale'], $dataRow['subject']);
76
				$emailTemplate->setBody($dataRow['locale'], $dataRow['body']);
77
				$emailTemplate->setDescription($dataRow['locale'], $dataRow['description']);
78
				$result->MoveNext();
79
			}
80
			$result->Close();
81
			unset($result);
82
		}
83
84
		return $emailTemplate;
85
	}
86
87
	/**
88
	 * Insert a new base email template.
89
	 * @param $emailTemplate BaseEmailTemplate
90
	 */	
91
	function insertBaseEmailTemplate(&$emailTemplate) {
92
		return $this->update(
93
			'INSERT INTO email_templates
94
				(email_key, enabled)
95
				VALUES
96
				(?, ?)',
97
			array(
98
				$emailTemplate->getEmailKey(),
99
				$emailTemplate->getEnabled() == null ? 0 : 1
100
			)
101
		);
102
		$emailTemplate->setEmailId($this->getInsertEmailId());
103
		return $emailTemplate->getEmailId();
104
	}
105
106
	/**
107
	 * Update an existing base email template.
108
	 * @param $emailTemplate BaseEmailTemplate
109
	 */
37
	 */
110
	function updateBaseEmailTemplate(&$emailTemplate) {
38
	function &getLocaleEmailTemplate($emailKey) {
111
		return $this->update(
39
		$returner =& parent::getLocaleEmailTemplate($emailKey, 0, 0);
112
			'UPDATE email_templates
40
		return $returner;
113
				SET	enabled = ?
114
				WHERE email_key = ?',
115
			array(
116
				$emailTemplate->getEnabled() == null ? 0 : 1,
117
				$emailTemplate->getEmailKey()
118
			)
119
		);
120
	}
121
122
	/**
123
	 * Insert a new localized email template.
124
	 * @param $emailTemplate EmailTemplate
125
	 */	
126
	function insertEmailTemplate(&$emailTemplate) {
127
		$this->insertBaseEmailTemplate($emailTemplate);
128
		return $this->updateEmailTemplateData($emailTemplate);
129
	}
41
	}
130
42
131
	/**
43
	/**
132
	 * Insert/update locale-specific email template data.
44
	 * Retrieve an email template by key.
133
	 * @param $emailTemplate LocaleEmailTemplate
45
	 * @param $emailKey string
46
	 * @param $locale string
47
	 * @return EmailTemplate
134
	 */
48
	 */
135
	function updateEmailTemplateData(&$emailTemplate) {
49
	function &getEmailTemplate($emailKey, $locale) {
136
		foreach ($emailTemplate->getLocales() as $locale) {
50
		$returner =& parent::getEmailTemplate($emailKey, $locale, 0, 0);
137
			$result =& $this->retrieve(
51
		return $returner;
138
				'SELECT COUNT(*) FROM email_templates_data
139
				WHERE email_key = ? AND locale = ?',
140
				array($emailTemplate->getEmailKey(), $locale)
141
			);
142
143
			if ($result->fields[0] == 0) {
144
				$this->update(
145
					'INSERT INTO email_templates_data
146
					(email_key, locale, subject, body)
147
					VALUES
148
					(?, ?, ?, ?)',
149
					array($emailTemplate->getEmailKey(), $locale, $emailTemplate->getSubject($locale), $emailTemplate->getBody($locale))
150
				);
151
152
			} else {
153
				$this->update(
154
					'UPDATE email_templates_data
155
					SET subject = ?,
156
						body = ?
157
					WHERE email_key = ? AND locale = ?',
158
					array($emailTemplate->getSubject($locale), $emailTemplate->getBody($locale), $emailTemplate->getEmailKey(), $locale)
159
				);
160
			}
161
162
			$result->Close();
163
			unset($result);
164
		}
165
	}
52
	}
166
53
167
	/**
54
	/**
 Lines 169-206   class EmailTemplateDAO extends DAO { Link Here 
169
	 * @param $emailKey string
56
	 * @param $emailKey string
170
	 */
57
	 */
171
	function deleteEmailTemplateByKey($emailKey) {
58
	function deleteEmailTemplateByKey($emailKey) {
172
		return $this->update(
59
		return parent::deleteEmailTemplateByKey($emailKey, 0, 0);
173
			'DELETE FROM email_templates WHERE email_key = ?',
174
			$emailKey
175
		);
176
	}
60
	}
177
61
178
	/**
62
	/**
179
	 * Get the ID of the last inserted email template.
63
	 * Retrieve all email templates.
180
	 * @return int
64
	 * @param $locale string
65
	 * @param $rangeInfo object optional
66
	 * @return array Email templates
181
	 */
67
	 */
182
	function getInsertEmailId() {
68
	function &getEmailTemplates($locale, $rangeInfo = null) {
183
		return $this->getInsertId('email_templates', 'emailId');
69
		$returner =& parent::getEmailTemplates($locale, 0, 0, $rangeInfo);
70
		return $returner;
184
	}
71
	}
185
72
186
	/**
73
	/**
187
	 * Delete all email templates for a specific locale.
74
	 * Check if a template exists with the given email key.
188
	 * @param $locale string
75
	 * @param $emailKey string
76
	 * @return boolean
189
	 */
77
	 */
190
	function deleteEmailTemplatesByLocale($locale) {
78
	function templateExistsByKey($emailKey) {
191
		$this->update(
79
		return parent::templateExistsByKey($emailKey, 0, 0);
192
			'DELETE FROM email_templates_data WHERE locale = ?', $locale
193
		);
194
	}
80
	}
195
81
196
	/**
82
	/**
197
	 * Delete all default email templates for a specific locale.
83
	 * Check if a custom template exists with the given email key for a journal.
198
	 * @param $locale string
84
	 * @param $emailKey string
85
	 * @return boolean
199
	 */
86
	 */
200
	function deleteDefaultEmailTemplatesByLocale($locale) {
87
	function customTemplateExistsByKey($emailKey) {
201
		/*$this->update(
88
		return parent::customTemplateExistsByKey($emailKey, 0, 0);
202
			'DELETE FROM email_templates_default_data WHERE locale = ?', $locale
203
		);*/ // Not used in Harvester, but called from PKP. FIXME
204
	}
89
	}
205
}
90
}
206
91
(-)a/dbscripts/xml/data/locale/en_US/email_templates_data.xml (-81 lines)
 Lines 1-81    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE data SYSTEM "../../../../../lib/pkp/dtd/xmlData.dtd">
3
4
<!--
5
  * email_templates_data.xml
6
  *
7
  * Copyright (c) 2005-2010 Alec Smecher and John Willinsky
8
  * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9
  *
10
  * Email templates data XML file (English).
11
  *
12
  * $Id$
13
  -->
14
15
<data>
16
	<table name="email_templates_data">
17
		<field_default name="locale">en_US</field_default>
18
19
		<!--
20
		  *
21
		  * General
22
		  *
23
		  -->
24
		<row>
25
			<field name="email_key">PASSWORD_RESET_CONFIRM</field>
26
			<field name="subject">Password Reset Confirmation</field>
27
			<field name="body">We have received a request to reset your password for the {$siteTitle} web site.
28
29
If you did not make this request, please ignore this email and your password will not be changed. If you wish to reset your password, click on the below URL.
30
31
Reset my password: {$url}
32
33
{$principalContactSignature}</field>
34
			<field name="description">This email is sent to a registered user when they indicate that they have forgotten their password or are unable to login. It provides a URL they can follow to reset their password.</field>
35
		</row>
36
		<row>
37
			<field name="email_key">PASSWORD_RESET</field>
38
			<field name="subject">Password Reset</field>
39
			<field name="body">Your password has been successfully reset for use with the {$siteTitle} web site. Please retain this username and password, as it is necessary for all work with the site.
40
41
Your username: {$username}
42
Your new password: {$password}
43
44
{$principalContactSignature}</field>
45
			<field name="description">This email is sent to a registered user when they have successfully reset their password following the process described in the PASSWORD_RESET_CONFIRM email.</field>
46
		</row>
47
		<row>
48
			<field name="email_key">USER_REGISTER</field>
49
			<field name="subject">Journal Registration</field>
50
			<field name="body">{$userFullName}
51
52
You have now been registered as a user. We have included your username and password in this email, which are needed for all work with this website. At any point, you can ask to be removed from the list of users by contacting me.
53
54
Username: {$username}
55
Password: {$password}
56
57
Thank you,
58
{$principalContactSignature}</field>
59
			<field name="description">This email is sent to a newly registered user to welcome them to the system and provide them with a record of their username and password.</field>
60
		</row>
61
		<row>
62
			<field name="email_key">USER_VALIDATE</field>
63
			<field name="subject">Validate Your Account</field>
64
			<field name="body">{$userFullName}
65
66
You have created an account, but before you can start using it, you need to validate your email account. To do this, simply follow the link below:
67
68
{$activateUrl}
69
70
Thank you,
71
{$principalContactSignature}</field>
72
			<field name="description">This email is sent to a newly registered user to welcome them to the system and provide them with a record of their username and password.</field>
73
		</row>
74
		<row>
75
			<field name="email_key">NEW_ARCHIVE_NOTIFY</field>
76
			<field name="subject">Archive Added: {$archiveTitle}</field>
77
			<field name="body">A new archive, "{$archiveTitle}", has been submitted for addition to {$siteTitle}. To index this archive, log in at {$loginUrl} or use the command-line harvester tool.</field>
78
			<field name="description">This email is sent to the site administrator to notify them about a new archive submission that needs to be indexed.</field>
79
		</row>
80
	</table>
81
</data>
(-)a/dbscripts/xml/data/locale/te_ST/email_templates_data.xml (-31 lines)
 Lines 1-31    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE data SYSTEM "../../../../../lib/pkp/dtd/xmlData.dtd">
3
4
<!--
5
  * email_templates_data.xml
6
  *
7
  * Copyright (c) 2005-2010 Alec Smecher and John Willinsky
8
  * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9
  *
10
  * Email templates data XML file (English).
11
  *
12
  * $Id$
13
  -->
14
15
<data>
16
	<table name="email_templates_data">
17
		<field_default name="locale">en_US</field_default>
18
19
		<!--
20
		  *
21
		  * General
22
		  *
23
		  -->
24
		<row>
25
			<field name="email_key">NEW_ARCHIVE_NOTIFY</field>
26
			<field name="subject">Archive Added: {$archiveTitle}</field>
27
			<field name="body">A new archive, "{$archiveTitle}", has been submitted for addition to {$siteTitle}. To index this archive, log in at {$loginUrl} or use the command-line harvester tool.</field>
28
			<field name="description">This email is sent to the site administrator to notify them about a new archive submission that needs to be indexed.</field>
29
		</row>
30
	</table>
31
</data>
(-)a/dbscripts/xml/harvester2_schema.xml (-55 lines)
 Lines 212-272    Link Here 
212
	
212
	
213
	<!--
213
	<!--
214
	  *
214
	  *
215
	  * TABLE email_templates
216
	  *
217
	  -->
218
	<table name="email_templates">
219
		<field name="email_id" type="I4">
220
			<KEY/>
221
			<AUTOINCREMENT/>
222
		</field>
223
		<field name="email_key" type="C2" size="30">
224
			<NOTNULL/>
225
			<descr>Unique identifier for this email.</descr>
226
		</field>
227
		<field name="enabled" type="I1">
228
			<NOTNULL/>
229
			<DEFAULT VALUE="1"/>
230
		</field>
231
		<field name="can_disable" type="I1">
232
			<NOTNULL/>
233
			<DEFAULT VALUE="1"/>
234
		</field>
235
		<field name="can_edit" type="I1">
236
			<NOTNULL/>
237
			<DEFAULT VALUE="1"/>
238
		</field>
239
		<descr>Email templates.</descr>
240
		<index name="email_templates_default_email_key">
241
			<col>email_key</col>
242
			<UNIQUE/>
243
		</index>
244
	</table>
245
	
246
	<!--
247
	  *
248
	  * TABLE email_templates_data
249
	  *
250
	  -->
251
	<table name="email_templates_data">
252
		<field name="email_key" type="C2" size="30">
253
			<KEY/>
254
			<descr>Unique identifier for this email.</descr>
255
		</field>
256
		<field name="locale" type="C2" size="5">
257
			<KEY/>
258
			<DEFAULT VALUE="en_US"/>
259
		</field>
260
		<field name="subject" type="C2" size="120">
261
			<NOTNULL/>
262
		</field>
263
		<field name="body" type="X"/>
264
		<field name="description" type="X"/>
265
		<descr>Default data for email templates.</descr>
266
	</table>
267
	
268
	<!--
269
	  *
270
	  * TABLE rt_versions
215
	  * TABLE rt_versions
271
	  *
216
	  *
272
	 -->
217
	 -->
(-)a/dbscripts/xml/install.xml (-2 lines)
 Lines 23-30    Link Here 
23
	<schema file="dbscripts/xml/harvester2_schema.xml" />
23
	<schema file="dbscripts/xml/harvester2_schema.xml" />
24
24
25
	<!-- Other install tasks -->
25
	<!-- Other install tasks -->
26
	<data file="dbscripts/xml/data/email_templates.xml" />
27
	<data file="dbscripts/xml/data/locale/{$installedLocale}/email_templates_data.xml" />
28
	<code function="createData" />
26
	<code function="createData" />
29
	<code function="createConfig" />
27
	<code function="createConfig" />
30
</install>
28
</install>
(-)a/locale/en_US/emailTemplates.xml (+64 lines)
Line 0    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE email_texts SYSTEM "../../lib/pkp/dtd/emailTemplateData.dtd">
3
<!--
4
  * locale/en_US/emailTemplateData.xml
5
  *
6
  * Copyright (c) 2005-2010 Alec Smecher and John Willinsky
7
  * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8
  *
9
  * Localized email templates XML file.
10
  *
11
  -->
12
<email_texts locale="en_US">
13
	<email_text key="PASSWORD_RESET_CONFIRM">
14
		<subject>Password Reset Confirmation</subject>
15
		<body>We have received a request to reset your password for the {$siteTitle} web site.
16
17
If you did not make this request, please ignore this email and your password will not be changed. If you wish to reset your password, click on the below URL.
18
19
Reset my password: {$url}
20
21
{$principalContactSignature}</body>
22
		<description>This email is sent to a registered user when they indicate that they have forgotten their password or are unable to login. It provides a URL they can follow to reset their password.</description>
23
	</email_text>
24
	<email_text key="PASSWORD_RESET">
25
		<subject>Password Reset</subject>
26
		<body>Your password has been successfully reset for use with the {$siteTitle} web site. Please retain this username and password, as it is necessary for all work with the site.
27
28
Your username: {$username}
29
Your new password: {$password}
30
31
{$principalContactSignature}</body>
32
		<description>This email is sent to a registered user when they have successfully reset their password following the process described in the PASSWORD_RESET_CONFIRM email.</description>
33
	</email_text>
34
	<email_text key="USER_REGISTER">
35
		<subject>Journal Registration</subject>
36
		<body>{$userFullName}
37
38
You have now been registered as a user. We have included your username and password in this email, which are needed for all work with this website. At any point, you can ask to be removed from the list of users by contacting me.
39
40
Username: {$username}
41
Password: {$password}
42
43
Thank you,
44
{$principalContactSignature}</body>
45
		<description>This email is sent to a newly registered user to welcome them to the system and provide them with a record of their username and password.</description>
46
	</email_text>
47
	<email_text key="USER_VALIDATE">
48
		<subject>Validate Your Account</subject>
49
		<body>{$userFullName}
50
51
You have created an account, but before you can start using it, you need to validate your email account. To do this, simply follow the link below:
52
53
{$activateUrl}
54
55
Thank you,
56
{$principalContactSignature}</body>
57
		<description>This email is sent to a newly registered user to welcome them to the system and provide them with a record of their username and password.</description>
58
	</email_text>
59
	<email_text key="NEW_ARCHIVE_NOTIFY">
60
		<subject>Archive Added: {$archiveTitle}</subject>
61
		<body>A new archive, "{$archiveTitle}", has been submitted for addition to {$siteTitle}. To index this archive, log in at {$loginUrl} or use the command-line harvester tool.</body>
62
		<description>This email is sent to the site administrator to notify them about a new archive submission that needs to be indexed.</description>
63
	</email_text>
64
</email_texts>
(-)a/registry/emailTemplates.xml (+18 lines)
Line 0    Link Here 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE emails SYSTEM "../../lib/pkp/dtd/emailTemplates.dtd">
3
<!--
4
  * registry/emailTemplates.xml
5
  *
6
  * Copyright (c) 2005-2010 Alec Smecher and John Willinsky
7
  * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8
  *
9
  * Email templates XML file.
10
  *
11
  -->
12
<emails>
13
	<email key="PASSWORD_RESET_CONFIRM" can_edit="1" can_disable="0"/>
14
	<email key="PASSWORD_RESET" can_edit="1" can_disable="0"/>
15
	<email key="USER_REGISTER" can_edit="1" can_disable="0"/>
16
	<email key="USER_VALIDATE" can_edit="1" can_disable="0"/>
17
	<email key="NEW_ARCHIVE_NOTIFY" can_edit="1" can_disable="1"/>
18
</emails>
(-)a/tools/localeCheck.php (-331 lines)
 Lines 1-331    Link Here 
1
<?php
2
3
/**
4
 * @file tools/localeCheck.php
5
 *
6
 * Copyright (c) 2005-2010 Alec Smecher and John Willinsky
7
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
8
 *
9
 * @class localeCheck
10
 * @ingroup tools
11
 *
12
 * @brief CLI tool to check the various locales for consistency.
13
 *
14
 */
15
16
// $Id$
17
18
19
require(dirname(__FILE__) . '/bootstrap.inc.php');
20
21
define('MASTER_LOCALE', 'en_US');
22
23
define('LOCALE_ERROR_MISSING_KEY',		0x0000001);
24
define('LOCALE_ERROR_EXTRA_KEY',		0x0000002);
25
define('LOCALE_ERROR_SUSPICIOUS_LENGTH',	0x0000003);
26
define('LOCALE_ERROR_DIFFERING_PARAMS',		0x0000004);
27
28
define('EMAIL_ERROR_MISSING_EMAIL',		0x0000005);
29
define('EMAIL_ERROR_EXTRA_EMAIL',		0x0000006);
30
define('EMAIL_ERROR_DIFFERING_PARAMS',		0x0000007);
31
32
class localeCheck extends CommandLineTool {
33
	/** @var $locales List of locales to check */
34
	var $locales;
35
36
	function localeCheck($args) {
37
		parent::CommandLineTool($args);
38
		array_shift($args); // Knock the tool name off the list
39
		$this->locales = $args;
40
	}
41
42
	/**
43
	 * Print command usage information.
44
	 */
45
	function usage() {
46
		echo "Script to test locales for consistency\n"
47
			. "Usage: {$this->scriptName} [localeName (optional)] ...\n";
48
	}
49
50
	/**
51
	 * Test locales.
52
	 */
53
	function execute() {
54
		// Flush the file cache just to be certain we're using
55
		// the most recent stuff
56
		import('lib.pkp.classes.cache.CacheManager');
57
		$cacheManager =& CacheManager::getManager();
58
		$cacheManager->flush('locale');
59
60
		// Load plugins so that their locale data is included too
61
		$plugins = array();
62
		foreach (PluginRegistry::getCategories() as $category) {
63
			echo "Loading plugin category \"$category\"...\n";
64
			$morePlugins = PluginRegistry::loadCategory($category);
65
			if (is_array($morePlugins)) $plugins += $morePlugins;
66
		}
67
68
		foreach (Locale::getAllLocales() as $locale => $name) {
69
			if (!empty($this->locales) && !in_array($locale, $this->locales)) continue;
70
			if ($locale != MASTER_LOCALE) {
71
				echo "Testing locale \"$name\" ($locale) against reference locale " . MASTER_LOCALE . ".\n";
72
				$this->testLocale($locale, MASTER_LOCALE, $plugins);
73
				$this->testEmails($locale, MASTER_LOCALE);
74
			}
75
		}
76
	}
77
78
	function testEmails($locale, $referenceLocale) {
79
		import('lib.pkp.classes.install.Installer'); // Bring in data dir
80
81
		$errors = array(
82
		);
83
84
		$xmlParser = new XMLParser();
85
		$referenceEmails =& $xmlParser->parse(
86
			INSTALLER_DATA_DIR . "/data/locale/$referenceLocale/email_templates_data.xml"
87
		);
88
		$emails =& $xmlParser->parse(
89
			INSTALLER_DATA_DIR . "/data/locale/$locale/email_templates_data.xml"
90
		);
91
		$emailsTable =& $emails->getChildByName('table');
92
		$referenceEmailsTable =& $referenceEmails->getChildByName('table');
93
		$matchedReferenceEmails = array();
94
95
		// Pass 1: For all translated emails, check that they match
96
		// against reference translations.
97
		for ($emailIndex = 0; ($email =& $emailsTable->getChildByName('row', $emailIndex)) !== null; $emailIndex++) {
98
			// Extract the fields from the email to be tested.
99
			$fields = $this->extractFields($email);
100
101
			// Locate the reference email and extract its fields.
102
			for ($referenceEmailIndex = 0; ($referenceEmail =& $referenceEmailsTable->getChildByName('row', $referenceEmailIndex)) !== null; $referenceEmailIndex++) {
103
				$referenceFields = $this->extractFields($referenceEmail);
104
				if ($referenceFields['email_key'] == $fields['email_key']) break;
105
			}
106
107
			// Check if a matching reference email was found.
108
			if (!isset($referenceEmail) || $referenceEmail === null) {
109
				$errors[EMAIL_ERROR_EXTRA_EMAIL][] = array(
110
					'key' => $fields['email_key']
111
				);
112
				continue;
113
			}
114
115
			// We've successfully found a matching reference email.
116
			// Compare it against the translation.
117
			$bodyParams = $this->getParameterNames($fields['body']);
118
			$referenceBodyParams = $this->getParameterNames($referenceFields['body']);
119
			if ($bodyParams !== $referenceBodyParams) {
120
				$errors[EMAIL_ERROR_DIFFERING_PARAMS][] = array(
121
					'key' => $fields['email_key'],
122
					'mismatch' => array_diff($bodyParams, $referenceBodyParams)
123
				);
124
			}
125
126
			$subjectParams = $this->getParameterNames($fields['subject']);
127
			$referenceSubjectParams = $this->getParameterNames($referenceFields['subject']);
128
129
			if ($subjectParams !== $referenceSubjectParams) {
130
				$errors[EMAIL_ERROR_DIFFERING_PARAMS][] = array(
131
					'key' => $fields['email_key'],
132
					'mismatch' => array_diff($subjectParams, $referenceSubjectParams)
133
				);
134
			}
135
136
			$matchedReferenceEmails[] = $fields['email_key'];
137
138
			unset($email);
139
			unset($referenceEmail);
140
		}
141
142
		// Pass 2: Make sure that there are no missing translations.
143
		for ($referenceEmailIndex = 0; ($referenceEmail =& $referenceEmailsTable->getChildByName('row', $referenceEmailIndex)) !== null; $referenceEmailIndex++) {
144
			// Extract the fields from the email to be tested.
145
			$referenceFields = $this->extractFields($referenceEmail);
146
			if (!in_array($referenceFields['email_key'], $matchedReferenceEmails)) {
147
				$errors[EMAIL_ERROR_MISSING_EMAIL][] = array(
148
					'key' => $referenceFields['email_key']
149
				);
150
			}
151
		}
152
153
		$this->displayEmailErrors($locale, $errors);
154
	}
155
156
	function extractFields(&$node) {
157
		$returner = array();
158
		foreach ($node->getChildren() as $field) if ($field->getName() === 'field') {
159
			$returner[$field->getAttribute('name')] = $field->getValue();
160
		}
161
		return $returner;
162
	}
163
164
	function displayEmailErrors($locale, $errors) {
165
		ksort($errors);
166
		echo "\nERROR REPORT FOR EMAILS IN \"$locale\":\n";
167
		echo "-----------------------------------\n";
168
		foreach ($errors as $type => $errorList) {
169
			if (!empty($errorList)) switch ($type) {
170
				case EMAIL_ERROR_MISSING_EMAIL:
171
					echo "The following messages are missing from the emails file and need translation.\n";
172
					foreach ($errorList as $error) echo " - " . $error['key'] . "\n";
173
					break;
174
				case EMAIL_ERROR_EXTRA_EMAIL:
175
					echo "\nThe following emails are not in the master translation and may be deleted:\n";
176
					foreach ($errorList as $error) echo " - " . $error['key'] . "\n";
177
					break;
178
				case EMAIL_ERROR_DIFFERING_PARAMS:
179
					echo "\nThe following emails are missing parameters or have extra parameters and need\n";
180
					echo "correcting against the master translation:\n";
181
					foreach ($errorList as $error) {
182
						echo " - " . $error['key'] . "\n";
183
						echo "   Mismatching parameter(s): " . implode(', ', $error['mismatch']) . "\n";
184
					}
185
					break;
186
				default: die("Unknown error type \"$type\"!\n");
187
			}
188
		}
189
	}
190
191
	function testLocale($locale, $referenceLocale, $plugins) {
192
		$errors = array(
193
			LOCALE_ERROR_MISSING_KEY => array(),
194
			LOCALE_ERROR_EXTRA_KEY => array(),
195
			LOCALE_ERROR_SUSPICIOUS_LENGTH => array(),
196
			LOCALE_ERROR_DIFFERING_PARAMS => array()
197
		);
198
199
		$localeCache =& Locale::_getCache($locale);
200
		$referenceLocaleCache =& Locale::_getCache($referenceLocale);
201
202
		$localeContents =& $localeCache->getContents();
203
		$referenceContents =& $referenceLocaleCache->getContents();
204
205
		// Add locale data for plugins
206
		foreach ($plugins as $plugin) {
207
			$pluginCache = $plugin->_getCache($locale);
208
			$referencePluginCache = $plugin->_getCache($referenceLocale);
209
			$localeContents += $pluginCache->getContents();
210
			$referenceContents += $referencePluginCache->getContents();
211
		}
212
213
		foreach ($referenceContents as $key => $referenceValue) {
214
			if (!isset($localeContents[$key])) {
215
				$errors[LOCALE_ERROR_MISSING_KEY][] = array(
216
					'key' => $key,
217
					'locale' => $locale
218
				);
219
				continue;
220
			}
221
			$value = $localeContents[$key];
222
223
			// Watch for suspicious lengths.
224
			if (!$this->checkLengths($referenceValue, $value)) {
225
				$errors[LOCALE_ERROR_SUSPICIOUS_LENGTH][] = array(
226
					'key' => $key,
227
					'locale' => $locale,
228
					'reference' => $referenceValue,
229
					'value' => $value
230
				);
231
			}
232
233
			$referenceParams = $this->getParameterNames($referenceValue);
234
			$params = $this->getParameterNames($value);
235
			if ($referenceParams !== $params) {
236
				$errors[LOCALE_ERROR_DIFFERING_PARAMS][] = array(
237
					'key' => $key,
238
					'locale' => $locale,
239
					'mismatch' => array_diff($referenceParams, $params)
240
				);
241
			}
242
			// After processing a key, remove it from the list;
243
			// this way, the remainder at the end of the loop
244
			// will be extra unnecessary keys.
245
			unset($localeContents[$key]);
246
		}
247
248
		// Leftover keys are extraneous.
249
		foreach ($localeContents as $key => $value) {
250
			$errors[LOCALE_ERROR_EXTRA_KEY][] = array(
251
				'key' => $key,
252
				'locale' => $locale
253
			);
254
		}
255
256
		$this->displayLocaleErrors($locale, $errors);
257
	}
258
259
	function displayLocaleErrors($locale, $errors) {
260
		ksort($errors);
261
		echo "\nERROR REPORT FOR LOCALE STRINGS IN \"$locale\":\n";
262
		echo "---------------------------------------\n";
263
		foreach ($errors as $type => $errorList) {
264
			if (!empty($errorList)) switch ($type) {
265
				case LOCALE_ERROR_MISSING_KEY:
266
					echo "The following keys are missing from a locale file and need to be translated.\n";
267
					foreach ($errorList as $error) echo " - " . $error['key'] . "\n";
268
					break;
269
				case LOCALE_ERROR_EXTRA_KEY:
270
					echo "\nThe following keys are not in the master translation and may be deleted:\n";
271
					foreach ($errorList as $error) echo " - " . $error['key'] . "\n";
272
					break;
273
				case LOCALE_ERROR_SUSPICIOUS_LENGTH:
274
					echo "\nThe following keys have suspicious lengths compared with the master translation\n";
275
					echo "and may need checking:\n";
276
					foreach ($errorList as $error) {
277
						$reference = $this->truncate($error['reference'], 65);
278
						$value = $this->truncate($error['value'], 65);
279
						echo " - " . $error['key'] . "\n";
280
						echo "   \"" . $reference . "\" vs.\n";
281
						echo "   \"" . $value . "\" ($locale)\n";
282
					}
283
					break;
284
				case LOCALE_ERROR_DIFFERING_PARAMS:
285
					echo "\nThe following keys are missing parameters or have extra parameters and need\n";
286
					echo "correcting against the master translation:\n";
287
					foreach ($errorList as $error) {
288
						echo " - " . $error['key'] . "\n";
289
						echo "   Mismatching parameter(s): " . implode(', ', $error['mismatch']) . "\n";
290
					}
291
					break;
292
				default: die("Unknown error type \"$type\"!\n");
293
			}
294
		}
295
	}
296
297
	function truncate($value, $length = 80, $ellipsis = '...') {
298
		if (String::strlen($value) > $length) {
299
			$value = String::substr($value, 0, $length - String::strlen($ellipsis));
300
			return $value . $ellipsis;
301
		}
302
		return $value;
303
	}
304
305
	function checkLengths($reference, $value) {
306
		$referenceLength = String::strlen($reference);
307
		$length = String::strlen($value);
308
		$lengthDifference = abs($referenceLength - $length);
309
		if ($referenceLength == 0) return false;
310
		if ($lengthDifference / $referenceLength > 1 && $lengthDifference > 10) return false;
311
		return true;
312
	}
313
314
	/**
315
	 * Given a locale string, get the list of parameter references of the
316
	 * form {$myParameterName}.
317
	 * @param $source string
318
	 * @return array
319
	 */
320
	function getParameterNames($source) {
321
		$matches = null;
322
		String::regexp_match_get('/({\$[^}]+})/' /* '/{\$[^}]+})/' */, $source, $matches);
323
		array_shift($matches); // Knock the top element off the array
324
		return $matches;
325
	}
326
}
327
328
$tool = new localeCheck(isset($argv) ? $argv : array());
329
$tool->execute();
330
331
?>

Return to bug 6225