forked from friendica/friendica-addons
Merge pull request #111 from mexon/mailstream
* Fix typos in database schema
This commit is contained in:
commit
61083eddb7
BIN
mailstream.tgz
BIN
mailstream.tgz
Binary file not shown.
|
@ -4,10 +4,10 @@ CREATE TABLE IF NOT EXISTS `mailstream_item` (
|
||||||
`contact-id` int(11) NOT NULL,
|
`contact-id` int(11) NOT NULL,
|
||||||
`uri` char(255) NOT NULL,
|
`uri` char(255) NOT NULL,
|
||||||
`message-id` char(255) NOT NULL,
|
`message-id` char(255) NOT NULL,
|
||||||
`created` timestamp NOT NULL DEFAULT now()',
|
`created` timestamp NOT NULL DEFAULT now(),
|
||||||
`completed` timestamp NULL DEFAULT NULL,
|
`completed` timestamp NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `message-id` (`message-id`),
|
KEY `message-id` (`message-id`),
|
||||||
KEY `created` (`created`),
|
KEY `created` (`created`),
|
||||||
KEY `completed` (`completed`)
|
KEY `completed` (`completed`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATION=utf8_bin;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* Name: Mail Stream
|
* Name: Mail Stream
|
||||||
* Description: Mail all items coming into your network feed to an email address
|
* Description: Mail all items coming into your network feed to an email address
|
||||||
* Version: 0.1
|
* Version: 0.2
|
||||||
* Author: Matthew Exon <http://mat.exon.name>
|
* Author: Matthew Exon <http://mat.exon.name>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -74,29 +74,46 @@ function mailstream_generate_id($a, $uri) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mailstream_post_remote_hook(&$a, &$item) {
|
function mailstream_post_remote_hook(&$a, &$item) {
|
||||||
if (get_pconfig($item['uid'], 'mailstream', 'enabled') === 'on') {
|
if (get_pconfig($item['uid'], 'mailstream', 'enabled') !== 'on') {
|
||||||
if ($item['uid'] && $item['contact-id'] && $item['uri']) {
|
return;
|
||||||
q("INSERT INTO `mailstream_item` (`uid`, `contact-id`, `uri`, `message-id`) " .
|
|
||||||
"VALUES (%d, '%s', '%s', '%s')", intval($item['uid']),
|
|
||||||
intval($item['contact-id']), dbesc($item['uri']), dbesc(mailstream_generate_id($a, $item['uri'])));
|
|
||||||
$r = q('SELECT * FROM `mailstream_item` WHERE `uid` = %d AND `contact-id` = %d AND `uri` = "%s"', intval($item['uid']), intval($item['contact-id']), dbesc($item['uri']));
|
|
||||||
if (count($r) != 1) {
|
|
||||||
logger('mailstream_post_remote_hook: Unexpected number of items returned from mailstream_item', LOGGER_NORMAL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$ms_item = $r[0];
|
|
||||||
logger('mailstream_post_remote_hook: created mailstream_item '
|
|
||||||
. $ms_item['id'] . ' for item ' . $item['uri'] . ' '
|
|
||||||
. $item['uid'] . ' ' . $item['contact-id'], LOGGER_DATA);
|
|
||||||
$r = q('SELECT * FROM `user` WHERE `uid` = %d', intval($item['uid']));
|
|
||||||
if (count($r) != 1) {
|
|
||||||
logger('mailstream_post_remote_hook: Unexpected number of users returned', LOGGER_NORMAL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$user = $r[0];
|
|
||||||
mailstream_send($a, $ms_item, $item, $user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (!$item['uid']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!$item['contact-id']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!$item['uri']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
q("INSERT INTO `mailstream_item` (`uid`, `contact-id`, `uri`, `message-id`) " .
|
||||||
|
"VALUES (%d, '%s', '%s', '%s')", intval($item['uid']),
|
||||||
|
intval($item['contact-id']), dbesc($item['uri']), dbesc(mailstream_generate_id($a, $item['uri'])));
|
||||||
|
$r = q('SELECT * FROM `mailstream_item` WHERE `uid` = %d AND `contact-id` = %d AND `uri` = "%s"', intval($item['uid']), intval($item['contact-id']), dbesc($item['uri']));
|
||||||
|
if (count($r) != 1) {
|
||||||
|
logger('mailstream_post_remote_hook: Unexpected number of items returned from mailstream_item', LOGGER_NORMAL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$ms_item = $r[0];
|
||||||
|
logger('mailstream_post_remote_hook: created mailstream_item '
|
||||||
|
. $ms_item['id'] . ' for item ' . $item['uri'] . ' '
|
||||||
|
. $item['uid'] . ' ' . $item['contact-id'], LOGGER_DATA);
|
||||||
|
$user = mailstream_get_user($item['uid']);
|
||||||
|
if (!$user) {
|
||||||
|
logger('mailstream_post_remote_hook: no user ' . $item['uid'], LOGGER_NORMAL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mailstream_send($a, $ms_item, $item, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
function mailstream_get_user($uid) {
|
||||||
|
$r = q('SELECT * FROM `user` WHERE `uid` = %d', intval($uid));
|
||||||
|
if (count($r) != 1) {
|
||||||
|
logger('mailstream_post_remote_hook: Unexpected number of users returned', LOGGER_NORMAL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return $r[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function mailstream_do_images($a, &$item, &$attachments) {
|
function mailstream_do_images($a, &$item, &$attachments) {
|
||||||
|
@ -183,12 +200,15 @@ function mailstream_send($a, $ms_item, $item, $user) {
|
||||||
if ($frommail == "") {
|
if ($frommail == "") {
|
||||||
$frommail = 'friendica@localhost.local';
|
$frommail = 'friendica@localhost.local';
|
||||||
}
|
}
|
||||||
$email = get_pconfig($item['uid'], 'mailstream', 'address');
|
$address = get_pconfig($item['uid'], 'mailstream', 'address');
|
||||||
|
if (!$address) {
|
||||||
|
$address = $user['email'];
|
||||||
|
}
|
||||||
$mail = new PHPmailer;
|
$mail = new PHPmailer;
|
||||||
try {
|
try {
|
||||||
$mail->XMailer = 'Friendica Mailstream Plugin';
|
$mail->XMailer = 'Friendica Mailstream Plugin';
|
||||||
$mail->SetFrom($frommail, $item['author-name']);
|
$mail->SetFrom($frommail, $item['author-name']);
|
||||||
$mail->AddAddress($email, $user['username']);
|
$mail->AddAddress($address, $user['username']);
|
||||||
$mail->MessageID = $ms_item['message-id'];
|
$mail->MessageID = $ms_item['message-id'];
|
||||||
$mail->Subject = mailstream_subject($item);
|
$mail->Subject = mailstream_subject($item);
|
||||||
if ($item['thr-parent'] != $item['uri']) {
|
if ($item['thr-parent'] != $item['uri']) {
|
||||||
|
@ -248,20 +268,28 @@ function mailstream_plugin_settings(&$a,&$s) {
|
||||||
$enabled = get_pconfig(local_user(), 'mailstream', 'enabled');
|
$enabled = get_pconfig(local_user(), 'mailstream', 'enabled');
|
||||||
$enabled_mu = ($enabled === 'on') ? ' checked="true"' : '';
|
$enabled_mu = ($enabled === 'on') ? ' checked="true"' : '';
|
||||||
$address = get_pconfig(local_user(), 'mailstream', 'address');
|
$address = get_pconfig(local_user(), 'mailstream', 'address');
|
||||||
$address_mu = $address ? (' value="' . $address . '"') : '';
|
|
||||||
$template = get_markup_template('settings.tpl', 'addon/mailstream/');
|
$template = get_markup_template('settings.tpl', 'addon/mailstream/');
|
||||||
$s .= replace_macros($template, array(
|
$s .= replace_macros($template, array(
|
||||||
'$submit' => t('Submit'),
|
'$address' => array(
|
||||||
'$address' => $address_mu,
|
'mailstream_address',
|
||||||
'$address_caption' => t('Address:'),
|
t('Email Address'),
|
||||||
'$enabled' => $enabled_mu,
|
$address,
|
||||||
'$enabled_caption' => t('Enabled:')));
|
t("Leave blank to use your account email address")),
|
||||||
|
'$enabled' => array(
|
||||||
|
'mailstream_enabled',
|
||||||
|
t('Enabled'),
|
||||||
|
$enabled),
|
||||||
|
'$title' => t('Mail Stream Settings'),
|
||||||
|
'$submit' => t('Submit')));
|
||||||
}
|
}
|
||||||
|
|
||||||
function mailstream_plugin_settings_post($a,$post) {
|
function mailstream_plugin_settings_post($a,$post) {
|
||||||
if ($_POST['address'] != "") {
|
if ($_POST['address'] != "") {
|
||||||
set_pconfig(local_user(), 'mailstream', 'address', $_POST['address']);
|
set_pconfig(local_user(), 'mailstream', 'address', $_POST['address']);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
del_pconfig(local_user(), 'mailstream', 'address');
|
||||||
|
}
|
||||||
if ($_POST['enabled']) {
|
if ($_POST['enabled']) {
|
||||||
set_pconfig(local_user(), 'mailstream', 'enabled', $_POST['enabled']);
|
set_pconfig(local_user(), 'mailstream', 'enabled', $_POST['enabled']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,6 @@
|
||||||
<div class="settings-block">
|
<div class="settings-block">
|
||||||
<h3>Mail Stream Settings</h3>
|
<h3>$title</h3>
|
||||||
<table>
|
{{ inc field_input.tpl with $field=$address }}{{ endinc }}
|
||||||
<tbody>
|
{{ inc field_checkbox.tpl with $field=$enabled }}{{ endinc }}
|
||||||
<tr>
|
<input type="submit" value="$submit">
|
||||||
<td>$enabled_caption</td>
|
|
||||||
<td><input class="checkbox" type="checkbox" name="enabled" $enabled></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>$address_caption</td>
|
|
||||||
<td><input class="input" size="70" name="address"$address></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan="2"><input type="submit" value="$submit"></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,20 +4,8 @@
|
||||||
*
|
*
|
||||||
*}}
|
*}}
|
||||||
<div class="settings-block">
|
<div class="settings-block">
|
||||||
<h3>Mail Stream Settings</h3>
|
<h3>{{$title}}</h3>
|
||||||
<table>
|
{{include file="field_input.tpl" field=$address}}
|
||||||
<tbody>
|
{{include file="field_checkbox.tpl" field=$enabled}}
|
||||||
<tr>
|
<input type="submit" value="{{$submit}}">
|
||||||
<td>{{$enabled_caption}}</td>
|
|
||||||
<td><input class="checkbox" type="checkbox" name="enabled" {{$enabled}}></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>{{$address_caption}}</td>
|
|
||||||
<td><input class="input" size="70" name="address"{{$address}}></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan="2"><input type="submit" value="{{$submit}}"></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue