Compare commits

...

10 commits

Author SHA1 Message Date
Matthew Exon
bbc2632a93 adaptation for 2024.03 2024-04-03 18:32:58 +08:00
Matthew Exon
450fac395f trying to get phototrack to work 2024-04-03 18:32:04 +08:00
Matthew Exon
3c4cfc7a9c some more robust mailstream stuff 2024-04-03 18:32:04 +08:00
Matthew Exon
7a655564a8 debugging some issues 2024-04-03 18:32:04 +08:00
Matthew Exon
2cf1076d5c more overdue adaptations 2024-04-03 18:32:04 +08:00
Matthew Exon
f783b4857d some changes that were long overdue 2024-04-03 18:32:04 +08:00
Matthew Exon
511271ba37 more adaption to latest release 2024-04-03 18:32:04 +08:00
Matthew Exon
1d75a40d63 adapt to latest release 2024-04-03 18:32:04 +08:00
Matthew Exon
7cf4adaf53 log uid but ignore results 2024-04-03 18:32:04 +08:00
Matthew Exon
15776a8959 remove duplicate use directive 2024-04-03 18:32:04 +08:00
4 changed files with 104 additions and 88 deletions

View file

@ -118,9 +118,28 @@ function mailstream_send_hook(array $data)
return; return;
} }
if ($item['deleted']) {
Logger::debug('mailstream_send_hook skipping deleted item', ['guid' => $item['guid']]);
return;
}
$user = User::getById($item['uid']); $user = User::getById($item['uid']);
if (empty($user)) { if (empty($user)) {
Logger::error('mailstream_send_hook could not fund user', ['uid' => $item['uid']]); Logger::error('mailstream_send_hook could not find user', ['uid' => $item['uid']]);
return;
}
$contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'self' => false]);
if (!DBA::isResult($contact)) {
Logger::error('mailstream_send_hook could not find contact', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
return;
}
if ($contact['blocked']) {
Logger::error('mailstream_send_hook contact is blocked', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
return;
}
if (array_key_exists('ignored', $contact) && $contact['ignored']) {
Logger::error('mailstream_send_hook contact is ignored', ['guid' => $item['guid'], 'contact-id' => $item['contact-id']]);
return; return;
} }
@ -145,8 +164,8 @@ function mailstream_post_hook(array &$item)
mailstream_check_version(); mailstream_check_version();
if (!DI::pConfig()->get($item['uid'], 'mailstream', 'enabled')) { if (!DI::pConfig()->get($item['uid'], 'mailstream', 'enabled')) {
Logger::debug('mailstream: not enabled.', ['item' => $item['id'], ' uid ' => $item['uid']]); Logger::debug('mailstream: not enabled for item ' . $item['id'] . ' uid ' . $item['uid']);
return; // return;
} }
if (!$item['uid']) { if (!$item['uid']) {
Logger::debug('mailstream: no uid for item ' . $item['id']); Logger::debug('mailstream: no uid for item ' . $item['id']);

View file

@ -102,8 +102,8 @@ function phototrack_photo_use($photo, $table, $field, $id) {
} }
} }
function phototrack_check_field_url($a, $table, $field, $id, $url) { function phototrack_check_field_url($a, $table, $id_field, $field, $id, $url) {
Logger::info('@@@ phototrack_check_field_url table ' . $table . ' field ' . $field . ' id ' . $id . ' url ' . $url); Logger::info('@@@ phototrack_check_field_url table ' . $table . ' id_field ' . $id_field . ' field ' . $field . ' id ' . $id . ' url ' . $url);
$baseurl = DI::baseUrl()->get(true); $baseurl = DI::baseUrl()->get(true);
if (strpos($url, $baseurl) === FALSE) { if (strpos($url, $baseurl) === FALSE) {
return; return;
@ -126,35 +126,32 @@ function phototrack_check_field_url($a, $table, $field, $id, $url) {
} }
} }
function phototrack_check_field_bbcode($a, $table, $field, $id, $value) { function phototrack_check_field_bbcode($a, $table, $id_field, $field, $id, $value) {
Logger::info('@@@ phototrack_check_field_url table ' . $table . ' id_field ' . $id_field . ' field ' . $field . ' id ' . $id . ' value ' . $value);
$baseurl = DI::baseUrl()->get(true); $baseurl = DI::baseUrl()->get(true);
$matches = array(); $matches = array();
preg_match_all("/\[img(\=([0-9]*)x([0-9]*))?\](.*?)\[\/img\]/ism", $value, $matches); preg_match_all("/\[img(\=([0-9]*)x([0-9]*))?\](.*?)\[\/img\]/ism", $value, $matches);
foreach ($matches[4] as $url) { foreach ($matches[4] as $url) {
phototrack_check_field_url($a, $table, $field, $id, $url); phototrack_check_field_url($a, $table, $id_field, $field, $id, $url);
} }
} }
function phototrack_post_local_end(&$a, &$item) { function phototrack_post_local_end(&$a, &$item) {
phototrack_check_row($a, 'item', $item); phototrack_check_row($a, 'item', 'id', $item);
phototrack_check_row($a, 'item-content', $item); phototrack_check_row($a, 'item-content', 'id', $item);
} }
function phototrack_post_remote_end(&$a, &$item) { function phototrack_post_remote_end(&$a, &$item) {
phototrack_check_row($a, 'item', $item); phototrack_check_row($a, 'item', 'id', $item);
phototrack_check_row($a, 'item-content', $item); phototrack_check_row($a, 'item-content', 'id', $item);
} }
function phototrack_notifier_end($item) { function phototrack_notifier_end($item) {
} }
function phototrack_check_row($a, $table, $row) { function phototrack_check_row($a, $table, $id_field, $row) {
switch ($table) { switch ($table) {
case 'item': case 'post-content':
$fields = array(
'body' => 'bbcode');
break;
case 'item-content':
$fields = array( $fields = array(
'body' => 'bbcode'); 'body' => 'bbcode');
break; break;
@ -182,8 +179,8 @@ function phototrack_check_row($a, $table, $row) {
} }
foreach ($fields as $field => $type) { foreach ($fields as $field => $type) {
switch ($type) { switch ($type) {
case 'bbcode': phototrack_check_field_bbcode($a, $table, $field, $row['id'], $row[$field]); break; case 'bbcode': phototrack_check_field_bbcode($a, $table, $id_field, $field, $row['id'], $row[$field]); break;
case 'url': phototrack_check_field_url($a, $table, $field, $row['id'], $row[$field]); break; case 'url': phototrack_check_field_url($a, $table, $id_field, $field, $row['id'], $row[$field]); break;
} }
} }
phototrack_finished_row($table, $row['id']); phototrack_finished_row($table, $row['id']);
@ -197,15 +194,15 @@ function phototrack_batch_size() {
return PHOTOTRACK_DEFAULT_BATCH_SIZE; return PHOTOTRACK_DEFAULT_BATCH_SIZE;
} }
function phototrack_search_table($a, $table) { function phototrack_search_table($a, $table, $id_field) {
$batch_size = phototrack_batch_size(); $batch_size = phototrack_batch_size();
$rows = DBA::p("SELECT `$table`.* FROM `$table` LEFT OUTER JOIN phototrack_row_check ON ( phototrack_row_check.`table` = '$table' AND phototrack_row_check.`row-id` = `$table`.id ) WHERE ( ( phototrack_row_check.checked IS NULL ) OR ( phototrack_row_check.checked < DATE_SUB(NOW(), INTERVAL 1 MONTH) ) ) ORDER BY phototrack_row_check.checked LIMIT $batch_size"); $rows = DBA::p("SELECT `$table`.* FROM `$table` LEFT OUTER JOIN phototrack_row_check ON ( phototrack_row_check.`table` = '$table' AND phototrack_row_check.`row-id` = `$table`.$id_field ) WHERE ( ( phototrack_row_check.checked IS NULL ) OR ( phototrack_row_check.checked < DATE_SUB(NOW(), INTERVAL 1 MONTH) ) ) ORDER BY phototrack_row_check.checked LIMIT $batch_size");
if (DBA::isResult($rows)) { if (DBA::isResult($rows)) {
while ($row = DBA::fetch($rows)) { while ($row = DBA::fetch($rows)) {
phototrack_check_row($a, $table, $row); phototrack_check_row($a, $table, $id_field, $row);
} }
} }
$r = DBA::p("SELECT COUNT(*) FROM `$table` LEFT OUTER JOIN phototrack_row_check ON ( phototrack_row_check.`table` = '$table' AND phototrack_row_check.`row-id` = `$table`.id ) WHERE ( ( phototrack_row_check.checked IS NULL ) OR ( phototrack_row_check.checked < DATE_SUB(NOW(), INTERVAL 1 MONTH) ) )"); $r = DBA::p("SELECT COUNT(*) FROM `$table` LEFT OUTER JOIN phototrack_row_check ON ( phototrack_row_check.`table` = '$table' AND phototrack_row_check.`row-id` = `$table`.$id_field ) WHERE ( ( phototrack_row_check.checked IS NULL ) OR ( phototrack_row_check.checked < DATE_SUB(NOW(), INTERVAL 1 MONTH) ) )");
Logger::info("@@@ phototrack_search_table " . print_r(DBA::fetch($r))); Logger::info("@@@ phototrack_search_table " . print_r(DBA::fetch($r)));
$remaining = DBA::fetch($r)['count']; $remaining = DBA::fetch($r)['count'];
Logger::info('phototrack: searched ' . DBA::numRows($rows) . ' rows in table ' . $table . ', ' . $remaining . ' still remaining to search'); Logger::info('phototrack: searched ' . DBA::numRows($rows) . ' rows in table ' . $table . ', ' . $remaining . ' still remaining to search');
@ -230,22 +227,23 @@ function phototrack_cron_time() {
return false; return false;
} }
} }
Logger::debug('@@@ phototrack: search interval reached last ' . $last . ' search interval ' . $search_interval);
return true; return true;
} }
function phototrack_cron($a, $b) { function phototrack_cron($a, $b) {
return; // @@@ something is broken
if (!phototrack_cron_time()) { if (!phototrack_cron_time()) {
return; return;
} }
DI::config()->set('phototrack', 'last_search', time()); DI::config()->set('phototrack', 'last_search', time());
$remaining = 0; $remaining = 0;
$remaining += phototrack_search_table($a, 'item'); $remaining += phototrack_search_table($a, 'post-content', 'uri-id');
$remaining += phototrack_search_table($a, 'item-content'); $remaining += phototrack_search_table($a, 'contact', 'id');
$remaining += phototrack_search_table($a, 'contact'); $remaining += phototrack_search_table($a, 'fcontact', 'id');
$remaining += phototrack_search_table($a, 'fcontact'); $remaining += phototrack_search_table($a, 'fsuggest', 'id');
$remaining += phototrack_search_table($a, 'fsuggest'); $remaining += phototrack_search_table($a, 'gcontact', 'id');
$remaining += phototrack_search_table($a, 'gcontact');
DI::config()->set('phototrack', 'remaining_items', $remaining); DI::config()->set('phototrack', 'remaining_items', $remaining);
if ($remaining === 0) { if ($remaining === 0) {
@ -266,7 +264,7 @@ function phototrack_tidy() {
Logger::info('phototrack_tidy: deleted ' . DBA::numRows($rows) . ' photos'); Logger::info('phototrack_tidy: deleted ' . DBA::numRows($rows) . ' photos');
} }
DBA::e('DROP TABLE `phototrack-temp`'); DBA::e('DROP TABLE `phototrack-temp`');
$rows = DBA::p('SELECT id FROM phototrack_photo_use WHERE checked < DATE_SUB(NOW(), INTERVAL 14 DAY)'); $rows = DBA::p('SELECT id FROM phototrack_photo_use WHERE checked < DATE_SUB(NOW(), INTERVAL 2 MONTH)');
foreach ($rows as $row) { foreach ($rows as $row) {
DBA::e( 'DELETE FROM phototrack_photo_use WHERE id = ' . $row['id']); DBA::e( 'DELETE FROM phototrack_photo_use WHERE id = ' . $row['id']);
} }

View file

@ -24,7 +24,6 @@ use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\DI; use Friendica\DI;
use Friendica\App;
/** /**
* @brief Installation hook for retriever plugin * @brief Installation hook for retriever plugin
@ -89,10 +88,9 @@ function retriever_module() {}
/** /**
* @brief Admin page hook for retriever plugin * @brief Admin page hook for retriever plugin
* *
* @param App $a App object (unused)
* @param string $o HTML to append content to (by ref) * @param string $o HTML to append content to (by ref)
*/ */
function retriever_addon_admin(App $a, string &$o) { function retriever_addon_admin(string &$o) {
$template = Renderer::getMarkupTemplate('admin.tpl', 'addon/retriever/'); $template = Renderer::getMarkupTemplate('admin.tpl', 'addon/retriever/');
$downloads_per_cron = DI::config()->get('retriever', 'downloads_per_cron'); $downloads_per_cron = DI::config()->get('retriever', 'downloads_per_cron');
@ -127,12 +125,12 @@ function retriever_addon_admin_post () {
* @brief Cron jobs for retriever plugin * @brief Cron jobs for retriever plugin
*/ */
function retriever_cron() { function retriever_cron() {
$downloads_per_cron = DI::config()->get('retriever', 'downloads_per_cron'); $downloads_per_cron = DI::config()->get('retriever', 'downloads_per_cron', '100');
// Do this first, otherwise it can interfere with retriever_retrieve_items // Do this first, otherwise it can interfere with retriever_retrieve_items
retriever_clean_up_completed_resources($downloads_per_cron); retriever_clean_up_completed_resources((int)$downloads_per_cron);
retriever_retrieve_items($downloads_per_cron); retriever_retrieve_items((int)$downloads_per_cron);
retriever_tidy(); retriever_tidy();
} }
@ -145,6 +143,7 @@ $retriever_item_count = 0;
* @param int $max_items Maximum number of items to retrieve in this call * @param int $max_items Maximum number of items to retrieve in this call
*/ */
function retriever_retrieve_items(int $max_items) { function retriever_retrieve_items(int $max_items) {
Logger::debug('@@@ retriever_retrieve_items started');
global $retriever_item_count; global $retriever_item_count;
$retriever_schedule = array(array(1,'minute'), $retriever_schedule = array(array(1,'minute'),
@ -183,6 +182,7 @@ function retriever_retrieve_items(int $max_items) {
} }
while ($retrieve_items > 0); while ($retrieve_items > 0);
Logger::debug('retriever_retrieve_items: finished retrieving items'); Logger::debug('retriever_retrieve_items: finished retrieving items');
Logger::debug('@@@ retriever_retrieve_items finished');
} }
/** /**
@ -191,9 +191,11 @@ function retriever_retrieve_items(int $max_items) {
* @param int $max_items Maximum number of items to retrieve in this call * @param int $max_items Maximum number of items to retrieve in this call
*/ */
function retriever_clean_up_completed_resources(int $max_items) { function retriever_clean_up_completed_resources(int $max_items) {
Logger::debug('@@@ retriever_clean_up_completed_resources started');
// TODO: figure out how to do this with DBA module // TODO: figure out how to do this with DBA module
$r = DBA::p("SELECT retriever_resource.`id` as resource, retriever_item.`id` as item FROM retriever_resource, retriever_item, retriever_rule WHERE retriever_item.`finished` = 0 AND retriever_item.`resource` = retriever_resource.`id` AND retriever_resource.`completed` IS NOT NULL AND retriever_item.`contact-id` = retriever_rule.`contact-id` AND retriever_item.`item-uid` = retriever_rule.`uid` LIMIT $max_items"); $r = DBA::p("SELECT retriever_resource.`id` as resource, retriever_item.`id` as item FROM retriever_resource, retriever_item, retriever_rule WHERE retriever_item.`finished` = 0 AND retriever_item.`resource` = retriever_resource.`id` AND retriever_resource.`completed` IS NOT NULL AND retriever_item.`contact-id` = retriever_rule.`contact-id` AND retriever_item.`item-uid` = retriever_rule.`uid` LIMIT $max_items");
if (!DBA::isResult($r)) { if (!DBA::isResult($r)) {
Logger::debug('@@@ retriever_clean_up_completed_resources nothing to do');
return; return;
} }
Logger::debug('retriever_clean_up_completed_resources: items waiting even though resource has completed: ' . DBA::numRows($r)); Logger::debug('retriever_clean_up_completed_resources: items waiting even though resource has completed: ' . DBA::numRows($r));
@ -219,6 +221,7 @@ function retriever_clean_up_completed_resources(int $max_items) {
DBA::update('retriever_item', ['finished' => 1], ['id' => intval($retriever_item['id'])], ['finished' => 0]); DBA::update('retriever_item', ['finished' => 1], ['id' => intval($retriever_item['id'])], ['finished' => 0]);
retriever_check_item_completed($item); retriever_check_item_completed($item);
} }
Logger::debug('@@@ retriever_clean_up_completed_resources finished');
} }
/** /**
@ -305,7 +308,7 @@ function retrieve_resource(array $resource) {
DBA::update('retriever_rule', ['data' => json_encode($retriever_rule['data'])], ['id' => intval($retriever_rule["id"])], $retriever_rule); DBA::update('retriever_rule', ['data' => json_encode($retriever_rule['data'])], ['id' => intval($retriever_rule["id"])], $retriever_rule);
unlink($cookiejar); unlink($cookiejar);
} }
$resource['data'] = $fetch_result->getBody(); $resource['data'] = $fetch_result->getBodyString();
$resource['http-code'] = $fetch_result->getReturnCode(); $resource['http-code'] = $fetch_result->getReturnCode();
$resource['type'] = $fetch_result->getContentType(); $resource['type'] = $fetch_result->getContentType();
$resource['redirect-url'] = $fetch_result->getRedirectUrl(); $resource['redirect-url'] = $fetch_result->getRedirectUrl();
@ -378,7 +381,9 @@ function retriever_item_completed(string $retriever_item_id, array $resource) {
// Note: the retriever might be null. Doesn't matter. // Note: the retriever might be null. Doesn't matter.
$retriever_rule = get_retriever_rule($retriever_item['contact-id'], $retriever_item['item-uid'], false); $retriever_rule = get_retriever_rule($retriever_item['contact-id'], $retriever_item['item-uid'], false);
retriever_apply_completed_resource_to_item($retriever_rule, $item, $resource); if ($retriever_rule) {
retriever_apply_completed_resource_to_item($retriever_rule, $item, $resource);
}
DBA::update('retriever_item', ['finished' => 1], ['id' => intval($retriever_item['id'])], ['finished' => 0]); DBA::update('retriever_item', ['finished' => 1], ['id' => intval($retriever_item['id'])], ['finished' => 0]);
retriever_check_item_completed($item); retriever_check_item_completed($item);
@ -478,7 +483,7 @@ function add_retriever_resource(string $url, string $uid, string $cid, bool $bin
return $resource; return $resource;
} }
DBA::insert('retriever_resource', ['item-uid' => intval($uid), 'contact-id' => intval($cid), 'type' => $type, 'binary' => ($binary ? 1 : 0), 'url' => $url, 'completed' => DateTimeFormat::utcNow(), 'data' => $data]); DBA::insert('retriever_resource', ['item-uid' => intval($uid), 'contact-id' => intval($cid), 'type' => $type, 'binary' => ($binary ? 1 : 0), 'url' => $url, 'completed' => DateTimeFormat::utcNow(), 'data' => $data, 'redirect-url' => '']);
$resource = DBA::selectFirst('retriever_resource', [], ['url' => $url, 'item-uid' => intval($uid), 'contact-id' => intval($cid)]); $resource = DBA::selectFirst('retriever_resource', [], ['url' => $url, 'item-uid' => intval($uid), 'contact-id' => intval($cid)]);
if ($resource) { if ($resource) {
retriever_resource_completed($resource); retriever_resource_completed($resource);
@ -497,7 +502,7 @@ function add_retriever_resource(string $url, string $uid, string $cid, bool $bin
return $resource; return $resource;
} }
DBA::insert('retriever_resource', ['item-uid' => intval($uid), 'contact-id' => intval($cid), 'binary' => ($binary ? 1 : 0), 'url' => $url]); DBA::insert('retriever_resource', ['item-uid' => intval($uid), 'contact-id' => intval($cid), 'binary' => ($binary ? 1 : 0), 'url' => $url, 'redirect-url' => '']);
return DBA::selectFirst('retriever_resource', [], ['url' => $url, 'item-uid' => intval($uid), 'contact-id' => intval($cid)]); return DBA::selectFirst('retriever_resource', [], ['url' => $url, 'item-uid' => intval($uid), 'contact-id' => intval($cid)]);
} }
@ -741,7 +746,7 @@ function retrieve_images(array &$item) {
if (!$url) { if (!$url) {
continue; continue;
} }
if (strpos($url, DI::baseUrl()->get(true)) === FALSE) { if (strpos($url, (string)(DI::baseUrl())) === FALSE) {
$resource = add_retriever_resource($url, $item['uid'], $item['contact-id'], true); $resource = add_retriever_resource($url, $item['uid'], $item['contact-id'], true);
if (!$resource['completed']) { if (!$resource['completed']) {
add_retriever_item($item, $resource); add_retriever_item($item, $resource);
@ -826,8 +831,13 @@ function retriever_transform_images(array &$item, array $resource) {
Logger::warning('retriever_transform_images: invalid image found at URL ' . $resource['url'] . ' for item ' . $item['id']); Logger::warning('retriever_transform_images: invalid image found at URL ' . $resource['url'] . ' for item ' . $item['id']);
return; return;
} }
$photo = Photo::store($image, $uid, $cid, $rid, $filename, $album, 0, 0, "", "", "", "", $desc); try {
$new_url = DI::baseUrl()->get(true) . '/photo/' . $rid . '-0.' . $image->getExt(); $photo = Photo::store($image, $uid, $cid, $rid, $filename, $album, 0, 0, "", "", "", "", $desc);
} catch (Exception $e) {
Logger::error('retriever_transform_images: unable to store photo ' . $resource['url'] . ' error: ' . $e->getMessage());
return;
}
$new_url = DI::baseUrl() . '/photo/' . $rid . '-0.' . $image->getExt();
if (!strlen($new_url)) { if (!strlen($new_url)) {
Logger::warning('retriever_transform_images: no replacement URL for image ' . $resource['url']); Logger::warning('retriever_transform_images: no replacement URL for image ' . $resource['url']);
return; return;
@ -842,35 +852,33 @@ function retriever_transform_images(array &$item, array $resource) {
/** /**
* @brief Displays the retriever configuration page for a contact. Alternatively, if the user clicked the "help" button, display the help content. * @brief Displays the retriever configuration page for a contact. Alternatively, if the user clicked the "help" button, display the help content.
*
* @param App $a The App object
*/ */
function retriever_content(App $a) { function retriever_content() {
if (!Session::getLocalUser()) { if (!DI::userSession()->getLocalUserId()) {
$a->page['content'] .= "<p>Please log in</p>"; DI::page()['content'] .= "<p>Please log in</p>";
return; return;
} }
if (isset(DI::args()->getArgv()[1]) and DI::args()->getArgv()[1] === 'help') { if (isset(DI::args()->getArgv()[1]) and DI::args()->getArgv()[1] === 'help') {
$feeds = DBA::selectToArray('contact', ['id', 'name', 'thumb'], ['uid' => Session::getLocalUser(), 'network' => 'feed']); $feeds = DBA::selectToArray('contact', ['id', 'name', 'thumb'], ['uid' => DI::userSession()->getLocalUserId(), 'network' => 'feed']);
for ($i = 0; $i < count($feeds); ++$i) { for ($i = 0; $i < count($feeds); ++$i) {
$feeds[$i]['url'] = DI::baseUrl()->get(true) . '/retriever/' . $feeds[$i]['id']; $feeds[$i]['url'] = DI::baseUrl() . '/retriever/' . $feeds[$i]['id'];
} }
$template = Renderer::getMarkupTemplate('/help.tpl', 'addon/retriever/'); $template = Renderer::getMarkupTemplate('/help.tpl', 'addon/retriever/');
$a->page['content'] .= Renderer::replaceMacros($template, array( DI::page()['content'] .= Renderer::replaceMacros($template, array(
'$config' => DI::baseUrl()->get(true) . '/settings/addon', '$config' => DI::baseUrl() . '/settings/addon',
'$allow_images' => DI::config()->get('retriever', 'allow_images'), '$allow_images' => DI::config()->get('retriever', 'allow_images'),
'$feeds' => $feeds)); '$feeds' => $feeds));
return; return;
} }
if (isset(DI::args()->getArgv()[1])) { if (isset(DI::args()->getArgv()[1])) {
$arg1 = DI::args()->getArgv()[1]; $arg1 = DI::args()->getArgv()[1];
$retriever_rule = get_retriever_rule($arg1, Session::getLocalUser(), false); $retriever_rule = get_retriever_rule($arg1, DI::userSession()->getLocalUserId(), false);
if (!$retriever_rule) { if (!$retriever_rule) {
$retriever_rule = ['id' => 0, 'data' => ['enable' => 0, 'modurl' => '', 'pattern' => '', 'replace' => '', 'images' => 0, 'storecookies' => 0, 'cookiedata' => '', 'customxslt' => '', 'include' => '', 'exclude' => '']]; $retriever_rule = ['id' => 0, 'data' => ['enable' => 0, 'modurl' => '', 'pattern' => '', 'replace' => '', 'images' => 0, 'storecookies' => 0, 'cookiedata' => '', 'customxslt' => '', 'include' => '', 'exclude' => '']];
} }
if (!empty($_POST["id"])) { if (!empty($_POST["id"])) {
$retriever_rule = get_retriever_rule($arg1, Session::getLocalUser(), true); $retriever_rule = get_retriever_rule($arg1, DI::userSession()->getLocalUserId(), true);
$retriever_rule['data'] = array(); $retriever_rule['data'] = array();
foreach (array('modurl', 'pattern', 'replace', 'enable', 'images', 'customxslt', 'storecookies', 'cookiedata') as $setting) { foreach (array('modurl', 'pattern', 'replace', 'enable', 'images', 'customxslt', 'storecookies', 'cookiedata') as $setting) {
if (empty($_POST['retriever_' . $setting])) { if (empty($_POST['retriever_' . $setting])) {
@ -897,12 +905,12 @@ function retriever_content(App $a) {
} }
} }
DBA::update('retriever_rule', ['data' => json_encode($retriever_rule['data'])], ['id' => intval($retriever_rule["id"])], ['data' => '']); DBA::update('retriever_rule', ['data' => json_encode($retriever_rule['data'])], ['id' => intval($retriever_rule["id"])], ['data' => '']);
$a->page['content'] .= "<p><b>Settings Updated"; DI::page()['content'] .= "<p><b>Settings Updated";
if (!empty($_POST["retriever_retrospective"])) { if (!empty($_POST["retriever_retrospective"])) {
apply_retrospective($retriever_rule, $_POST["retriever_retrospective"]); apply_retrospective($retriever_rule, $_POST["retriever_retrospective"]);
$a->page['content'] .= " and retrospectively applied to " . $_POST["retriever_retrospective"] . " posts"; DI::page()['content'] .= " and retrospectively applied to " . $_POST["retriever_retrospective"] . " posts";
} }
$a->page['content'] .= ".</p></b>"; DI::page()['content'] .= ".</p></b>";
} }
$template = Renderer::getMarkupTemplate('/rule-config.tpl', 'addon/retriever/'); $template = Renderer::getMarkupTemplate('/rule-config.tpl', 'addon/retriever/');
@ -952,7 +960,7 @@ function retriever_content(App $a) {
$retriever_rule['data']['customxslt'], $retriever_rule['data']['customxslt'],
DI::l10n()->t("When standard rules aren't enough, apply custom XSLT to the article")), DI::l10n()->t("When standard rules aren't enough, apply custom XSLT to the article")),
'$title' => DI::l10n()->t('Retrieve Feed Content'), '$title' => DI::l10n()->t('Retrieve Feed Content'),
'$help' => DI::baseUrl()->get(true) . '/retriever/help', '$help' => DI::baseUrl() . '/retriever/help',
'$help_t' => DI::l10n()->t('Get Help'), '$help_t' => DI::l10n()->t('Get Help'),
'$submit_t' => DI::l10n()->t('Submit'), '$submit_t' => DI::l10n()->t('Submit'),
'$submit' => DI::l10n()->t('Save Settings'), '$submit' => DI::l10n()->t('Save Settings'),
@ -973,25 +981,23 @@ function retriever_content(App $a) {
/** /**
* @brief Hook that adds the retriever option to the contact menu * @brief Hook that adds the retriever option to the contact menu
* *
* @param App $a The App object (by ref)
* @param array $args Contact menu details to be filled in (by ref) * @param array $args Contact menu details to be filled in (by ref)
*/ */
function retriever_contact_photo_menu(App &$a, array &$args) { function retriever_contact_photo_menu(array &$args) {
if (!$args) { if (!$args) {
return; return;
} }
if ($args["contact"]["network"] == "feed") { if ($args["contact"]["network"] == "feed") {
$args["menu"]['retriever'] = array(DI::l10n()->t('Retriever'), DI::baseUrl()->get(true) . '/retriever/' . $args["contact"]['id']); $args["menu"]['retriever'] = array(DI::l10n()->t('Retriever'), DI::baseUrl() . '/retriever/' . $args["contact"]['id']);
} }
} }
/** /**
* @brief Hook for processing new incoming items * @brief Hook for processing new incoming items
* *
* @param App $a The App object (by ref)
* @param array $item New item, which has not yet been inserted into database (by ref) * @param array $item New item, which has not yet been inserted into database (by ref)
*/ */
function retriever_post_remote_hook(App &$a, array &$item) { function retriever_post_remote_hook(array &$item) {
Logger::info('retriever_post_remote_hook: ' . $item['uri'] . ' ' . $item['uid'] . ' ' . $item['contact-id']); Logger::info('retriever_post_remote_hook: ' . $item['uri'] . ' ' . $item['uid'] . ' ' . $item['contact-id']);
$retriever_rule = get_retriever_rule($item['contact-id'], $item["uid"], false); $retriever_rule = get_retriever_rule($item['contact-id'], $item["uid"], false);
@ -1015,16 +1021,15 @@ function retriever_post_remote_hook(App &$a, array &$item) {
/** /**
* @brief Hook for adding per-user retriever settings to the user's settings page * @brief Hook for adding per-user retriever settings to the user's settings page
* *
* @param App $a The App object (by ref) * @param array $data Hook data array
* @param string $s HTML string to which to append settings content (by ref)
*/ */
function retriever_addon_settings(App &$a, string &$s) { function retriever_addon_settings(array &$data) {
$all_photos = DI::config()->get(Session::getLocalUser(), 'retriever', 'all_photos'); $all_photos = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos');
$oembed = DI::config()->get(Session::getLocalUser(), 'retriever', 'oembed'); $oembed = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'retriever', 'oembed');
$template = Renderer::getMarkupTemplate('/settings.tpl', 'addon/retriever/'); $template = Renderer::getMarkupTemplate('/settings.tpl', 'addon/retriever/');
$config = array('$submit' => DI::l10n()->t('Save Settings'), $config = array('$submit' => DI::l10n()->t('Save Settings'),
'$title' => DI::l10n()->t('Retriever Settings'), '$title' => DI::l10n()->t('Retriever Settings'),
'$help' => DI::baseUrl()->get(true) . '/retriever/help', '$help' => DI::baseUrl() . '/retriever/help',
'$allow_images' => DI::config()->get('retriever', 'allow_images')); '$allow_images' => DI::config()->get('retriever', 'allow_images'));
$config['$allphotos'] = array('retriever_all_photos', $config['$allphotos'] = array('retriever_all_photos',
DI::l10n()->t('All Photos'), DI::l10n()->t('All Photos'),
@ -1034,26 +1039,31 @@ function retriever_addon_settings(App &$a, string &$s) {
DI::l10n()->t('Resolve OEmbed'), DI::l10n()->t('Resolve OEmbed'),
$oembed, $oembed,
DI::l10n()->t('Check this to attempt to retrieve embedded content for all posts')); DI::l10n()->t('Check this to attempt to retrieve embedded content for all posts'));
$s .= Renderer::replaceMacros($template, $config); $html = Renderer::replaceMacros($template, $config);
$data = [
'addon' => 'retriever',
'title' => DI::l10n()->t('Retriever Settings'),
'html' => $html,
];
} }
/** /**
* @brief Hook for processing post results from user's settings page * @brief Hook for processing post results from user's settings page
* *
* @param App $a The App object
* @param array $post Posted content * @param array $post Posted content
* @return void
*/ */
function retriever_addon_settings_post(App $a, array $post) { function retriever_addon_settings_post(array $post) {
if ($post['retriever_all_photos']) { if ($post['retriever_all_photos']) {
DI::config()->set(Session::getLocalUser(), 'retriever', 'all_photos', $post['retriever_all_photos']); DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos', $post['retriever_all_photos']);
} }
else { else {
DI::config()->delete(Session::getLocalUser(), 'retriever', 'all_photos'); DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'retriever', 'all_photos');
} }
if ($post['retriever_oembed']) { if ($post['retriever_oembed']) {
DI::config()->set(Session::getLocalUser(), 'retriever', 'oembed', $post['retriever_oembed']); DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'retriever', 'oembed', $post['retriever_oembed']);
} }
else { else {
DI::config()->delete(Session::getLocalUser(), 'retriever', 'oembed'); DI::pConfig()->delete(DI::userSession()->getLocalUserId(), 'retriever', 'oembed');
} }
} }

View file

@ -1,16 +1,5 @@
<span id="settings_retriever_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose('settings_retriever_expanded'); openClose('settings_retriever_inflated');"> <p><a href="{{$help}}">Get Help</a></p>
<h3>{{$title}}</h3>
</span>
<div id="settings_retriever_expanded" class="settings-block" style="display: none;">
<span class="fakelink" onclick="openClose('settings_retriever_expanded'); openClose('settings_retriever_inflated');">
<h3>{{$title}}</h3>
</span>
<p>
<a href="{{$help}}">Get Help</a>
</p>
{{if $allow_images}} {{if $allow_images}}
{{include file="field_checkbox.tpl" field=$allphotos}} {{include file="field_checkbox.tpl" field=$allphotos}}
{{/if}} {{/if}}
{{include file="field_checkbox.tpl" field=$oembed}} {{include file="field_checkbox.tpl" field=$oembed}}
<input type="submit" value="{{$submit}}">
</div>