Send notifications for each new post of a contact, option for creating a summary for a feed post
This commit is contained in:
parent
fa431e84c2
commit
28df35052a
6
boot.php
6
boot.php
|
@ -14,7 +14,7 @@ require_once('include/features.php');
|
|||
define ( 'FRIENDICA_PLATFORM', 'Friendica');
|
||||
define ( 'FRIENDICA_VERSION', '3.2.1745' );
|
||||
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
|
||||
define ( 'DB_UPDATE_VERSION', 1167 );
|
||||
define ( 'DB_UPDATE_VERSION', 1169 );
|
||||
define ( 'EOL', "<br />\r\n" );
|
||||
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
|
||||
|
||||
|
@ -197,6 +197,7 @@ define ( 'NOTIFY_PROFILE', 0x0040 );
|
|||
define ( 'NOTIFY_TAGSELF', 0x0080 );
|
||||
define ( 'NOTIFY_TAGSHARE', 0x0100 );
|
||||
define ( 'NOTIFY_POKE', 0x0200 );
|
||||
define ( 'NOTIFY_SHARE', 0x0400 );
|
||||
|
||||
define ( 'NOTIFY_SYSTEM', 0x8000 );
|
||||
|
||||
|
@ -395,6 +396,9 @@ if(! class_exists('App')) {
|
|||
// array of instanced template engines ('name'=>'instance')
|
||||
public $template_engine_instance = array();
|
||||
|
||||
// Used for reducing load to the ostatus completion
|
||||
public $last_ostatus_conversation_url;
|
||||
|
||||
private $ldelim = array(
|
||||
'internal' => '',
|
||||
'smarty3' => '{{'
|
||||
|
|
|
@ -60,9 +60,10 @@ function notification($params) {
|
|||
// If so don't create a second notification
|
||||
|
||||
$p = null;
|
||||
$p = q("select id from notify where ( type = %d or type = %d ) and link = '%s' and uid = %d limit 1",
|
||||
$p = q("select id from notify where (type = %d or type = %d or type = %d) and link = '%s' and uid = %d limit 1",
|
||||
intval(NOTIFY_TAGSELF),
|
||||
intval(NOTIFY_COMMENT),
|
||||
intval(NOTIFY_SHARE),
|
||||
dbesc($params['link']),
|
||||
intval($params['uid'])
|
||||
);
|
||||
|
@ -150,6 +151,19 @@ function notification($params) {
|
|||
$itemlink = $params['link'];
|
||||
}
|
||||
|
||||
if($params['type'] == NOTIFY_SHARE) {
|
||||
$subject = sprintf( t('[Friendica:Notify] %s shared a new post') , $params['source_name']);
|
||||
$preamble = sprintf( t('%1$s shared a new post at %2$s') , $params['source_name'], $sitename);
|
||||
$epreamble = sprintf( t('%1$s [url=%2$s]shared a post[/url].') ,
|
||||
'[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]',
|
||||
$params['link']);
|
||||
|
||||
$sitelink = t('Please visit %s to view and/or reply to the conversation.');
|
||||
$tsitelink = sprintf( $sitelink, $siteurl );
|
||||
$hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
|
||||
$itemlink = $params['link'];
|
||||
}
|
||||
|
||||
if($params['type'] == NOTIFY_POKE) {
|
||||
|
||||
$subject = sprintf( t('[Friendica:Notify] %1$s poked you') , $params['source_name']);
|
||||
|
|
|
@ -406,7 +406,7 @@ function title_is_body($title, $body) {
|
|||
|
||||
|
||||
|
||||
function get_atom_elements($feed,$item) {
|
||||
function get_atom_elements($feed, $item, $contact = array()) {
|
||||
|
||||
require_once('library/HTMLPurifier.auto.php');
|
||||
require_once('include/html2bbcode.php');
|
||||
|
@ -846,6 +846,11 @@ function get_atom_elements($feed,$item) {
|
|||
};
|
||||
}
|
||||
|
||||
if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND $contact['fetch_further_information']) {
|
||||
$res["body"] = $res["title"]."\n\n[class=type-link]".fetch_siteinfo($res['plink'])."[/class]";
|
||||
$res["title"] = "";
|
||||
}
|
||||
|
||||
$arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
|
||||
|
||||
call_hooks('parse_atom', $arr);
|
||||
|
@ -860,6 +865,31 @@ function get_atom_elements($feed,$item) {
|
|||
return $res;
|
||||
}
|
||||
|
||||
function fetch_siteinfo($url) {
|
||||
require_once("mod/parse_url.php");
|
||||
|
||||
// Fetch site infos - but only from the meta data
|
||||
$data = parseurl_getsiteinfo($url, true);
|
||||
|
||||
$text = "";
|
||||
|
||||
if (!is_string($data["text"]) AND (sizeof($data["images"]) == 0) AND ($data["title"] == $url))
|
||||
return("");
|
||||
|
||||
if (is_string($data["title"]))
|
||||
$text .= "[bookmark=".$url."]".trim($data["title"])."[/bookmark]\n";
|
||||
|
||||
if (sizeof($data["images"]) > 0) {
|
||||
$imagedata = $data["images"][0];
|
||||
$text .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]' . "\n";
|
||||
}
|
||||
|
||||
if (is_string($data["text"]))
|
||||
$text .= "[quote]".$data["text"]."[/quote]";
|
||||
|
||||
return($text);
|
||||
}
|
||||
|
||||
function encode_rel_links($links) {
|
||||
$o = '';
|
||||
if(! ((is_array($links)) && (count($links))))
|
||||
|
@ -1117,6 +1147,49 @@ function item_store($arr,$force_parent = false) {
|
|||
$current_post = $r[0]['id'];
|
||||
logger('item_store: created item ' . $current_post);
|
||||
create_tags_from_item($r[0]['id']);
|
||||
|
||||
// Only check for notifications on start posts
|
||||
if ($arr['parent-uri'] === $arr['uri']) {
|
||||
logger('item_store: Check notification for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG);
|
||||
|
||||
// Send a notification for every new post?
|
||||
$r = q("SELECT `notify_new_posts` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `notify_new_posts` LIMIT 1",
|
||||
intval($arr['contact-id']),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
|
||||
if(count($r)) {
|
||||
logger('item_store: Send notification for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG);
|
||||
$u = q("SELECT * FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($arr['uid']));
|
||||
|
||||
$item = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d",
|
||||
intval($current_post),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
|
||||
$a = get_app();
|
||||
|
||||
require_once('include/enotify.php');
|
||||
notification(array(
|
||||
'type' => NOTIFY_SHARE,
|
||||
'notify_flags' => $u[0]['notify-flags'],
|
||||
'language' => $u[0]['language'],
|
||||
'to_name' => $u[0]['username'],
|
||||
'to_email' => $u[0]['email'],
|
||||
'uid' => $u[0]['uid'],
|
||||
'item' => $item[0],
|
||||
'link' => $a->get_baseurl().'/display/'.$u[0]['nickname'].'/'.$current_post,
|
||||
'source_name' => $item[0]['author-name'],
|
||||
'source_link' => $item[0]['author-link'],
|
||||
'source_photo' => $item[0]['author-avatar'],
|
||||
'verb' => ACTIVITY_TAG,
|
||||
'otype' => 'item'
|
||||
));
|
||||
logger('item_store: Notification sent for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
logger('item_store: could not locate created item');
|
||||
return 0;
|
||||
|
@ -1138,7 +1211,7 @@ function item_store($arr,$force_parent = false) {
|
|||
else
|
||||
$private = $arr['private'];
|
||||
|
||||
// Set parent id - and also make sure to inherit the parent's ACL's.
|
||||
// Set parent id - and also make sure to inherit the parent's ACLs.
|
||||
|
||||
$r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
|
||||
`deny_cid` = '%s', `deny_gid` = '%s', `private` = %d, `deleted` = %d WHERE `id` = %d",
|
||||
|
@ -2023,7 +2096,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
|
|||
// Have we seen it? If not, import it.
|
||||
|
||||
$item_id = $item->get_id();
|
||||
$datarray = get_atom_elements($feed,$item);
|
||||
$datarray = get_atom_elements($feed, $item, $contact);
|
||||
|
||||
if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN))
|
||||
$datarray['author-name'] = $contact['name'];
|
||||
|
@ -2164,7 +2237,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
|
|||
|
||||
$item_id = $item->get_id();
|
||||
|
||||
$datarray = get_atom_elements($feed,$item);
|
||||
$datarray = get_atom_elements($feed, $item, $contact);
|
||||
|
||||
if(is_array($contact)) {
|
||||
if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN))
|
||||
|
@ -2961,7 +3034,7 @@ function local_delivery($importer,$data) {
|
|||
$is_like = false;
|
||||
// remote reply to our post. Import and then notify everybody else.
|
||||
|
||||
$datarray = get_atom_elements($feed,$item);
|
||||
$datarray = get_atom_elements($feed, $item);
|
||||
|
||||
$r = q("SELECT `id`, `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($item_id),
|
||||
|
|
|
@ -103,6 +103,10 @@ function contacts_post(&$a) {
|
|||
|
||||
$hidden = intval($_POST['hidden']);
|
||||
|
||||
$notify = intval($_POST['notify']);
|
||||
|
||||
$fetch_further_information = intval($_POST['fetch_further_information']);
|
||||
|
||||
$priority = intval($_POST['poll']);
|
||||
if($priority > 5 || $priority < 0)
|
||||
$priority = 0;
|
||||
|
@ -110,11 +114,13 @@ function contacts_post(&$a) {
|
|||
$info = fix_mce_lf(escape_tags(trim($_POST['info'])));
|
||||
|
||||
$r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
|
||||
`hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
`hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($profile_id),
|
||||
intval($priority),
|
||||
dbesc($info),
|
||||
intval($hidden),
|
||||
intval($notify),
|
||||
intval($fetch_further_information),
|
||||
intval($contact_id),
|
||||
intval(local_user())
|
||||
);
|
||||
|
@ -417,6 +423,8 @@ function contacts_content(&$a) {
|
|||
'$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
|
||||
'$archived' => (($contact['archive']) ? t('Currently archived') : ''),
|
||||
'$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
|
||||
'$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
|
||||
'$fetch_further_information' => array('fetch_further_information', t('Fetch further information for feeds'), ($contact['fetch_further_information'] == 1), t('Fetch further information for feeds')),
|
||||
'$photo' => $contact['photo'],
|
||||
'$name' => $contact['name'],
|
||||
'$dir_icon' => $dir_icon,
|
||||
|
|
|
@ -59,8 +59,9 @@ function crepair_post(&$a) {
|
|||
$poll = ((x($_POST,'poll')) ? $_POST['poll'] : '');
|
||||
$attag = ((x($_POST,'attag')) ? $_POST['attag'] : '');
|
||||
$photo = ((x($_POST,'photo')) ? $_POST['photo'] : '');
|
||||
$remote_self = ((x($_POST,'remote_self')) ? $_POST['remote_self'] : false);
|
||||
|
||||
$r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s'
|
||||
$r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' , `remote_self` = %d
|
||||
WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
dbesc($name),
|
||||
dbesc($nick),
|
||||
|
@ -70,6 +71,7 @@ function crepair_post(&$a) {
|
|||
dbesc($notify),
|
||||
dbesc($poll),
|
||||
dbesc($attag),
|
||||
intval($remote_self),
|
||||
intval($contact['id']),
|
||||
local_user()
|
||||
);
|
||||
|
@ -154,6 +156,7 @@ function crepair_content(&$a) {
|
|||
'$label_notify' => t('Notification Endpoint URL'),
|
||||
'$label_poll' => t('Poll/Feed URL'),
|
||||
'$label_photo' => t('New photo from this URL'),
|
||||
'$label_self' => t('Mirror all posts to the wall?'),
|
||||
'$contact_name' => $contact['name'],
|
||||
'$contact_nick' => $contact['nick'],
|
||||
'$contact_id' => $contact['id'],
|
||||
|
@ -163,6 +166,8 @@ function crepair_content(&$a) {
|
|||
'$notify' => $contact['notify'],
|
||||
'$poll' => $contact['poll'],
|
||||
'$contact_attag' => $contact['attag'],
|
||||
'$contact_self' => array('remote_self', t('Mirror all posts to the wall?'), $contact['remote_self'],
|
||||
t('Shall all posts from this contact posted like your own posts?')),
|
||||
'$lbl_submit' => t('Submit')
|
||||
));
|
||||
|
||||
|
|
18
update.php
18
update.php
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
define( 'UPDATE_VERSION' , 1167 );
|
||||
define( 'UPDATE_VERSION' , 1169 );
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -1541,3 +1541,19 @@ function update_1166() {
|
|||
|
||||
return UPDATE_SUCCESS;
|
||||
}
|
||||
|
||||
function update_1167() {
|
||||
$r = q("ALTER TABLE `contact` ADD `notify_new_posts` TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
if (!$r)
|
||||
return UPDATE_FAILED;
|
||||
|
||||
return UPDATE_SUCCESS;
|
||||
}
|
||||
|
||||
function update_1168() {
|
||||
$r = q("ALTER TABLE `contact` ADD `fetch_further_information` TINYINT(1) NOT NULL DEFAULT '0'");
|
||||
if (!$r)
|
||||
return UPDATE_FAILED;
|
||||
|
||||
return UPDATE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@
|
|||
</div>
|
||||
{{/if}}
|
||||
<div id="contact-edit-end" ></div>
|
||||
|
||||
{{include file="field_checkbox.tpl" field=$notify}}
|
||||
{{include file="field_checkbox.tpl" field=$fetch_further_information}}
|
||||
{{include file="field_checkbox.tpl" field=$hidden}}
|
||||
|
||||
<div id="contact-edit-info-wrapper">
|
||||
|
|
|
@ -44,6 +44,8 @@
|
|||
<input type="text" id="crepair-photo" class="crepair-input" name="photo" value="" />
|
||||
<div class="clear"></div>
|
||||
|
||||
{{include file="field_checkbox.tpl" field=$contact_self}}
|
||||
|
||||
<input type="submit" name="submit" value="{{$lbl_submit}}" />
|
||||
|
||||
</form>
|
||||
|
|
Loading…
Reference in a new issue