aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module
diff options
context:
space:
mode:
authorMax Kostikov <max@kostikov.co>2019-12-04 03:44:24 +0100
committerM. Dent <dentm42@gmail.com>2019-12-04 03:44:24 +0100
commit21b398252aaf28d9ff8045fbe3e9fcb162a6f447 (patch)
tree2c18404f4315d46c8d01fd0f8899062a4f9e50d6 /Zotlabs/Module
parentc1aa96ebf70fd5b6426d96bf7d7e771dfc4ca9ab (diff)
downloadvolse-hubzilla-21b398252aaf28d9ff8045fbe3e9fcb162a6f447.tar.gz
volse-hubzilla-21b398252aaf28d9ff8045fbe3e9fcb162a6f447.tar.bz2
volse-hubzilla-21b398252aaf28d9ff8045fbe3e9fcb162a6f447.zip
Add content pinning support
Diffstat (limited to 'Zotlabs/Module')
-rw-r--r--Zotlabs/Module/Channel.php7
-rw-r--r--Zotlabs/Module/Pin.php68
2 files changed, 75 insertions, 0 deletions
diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php
index d975ac1bf..20a5418c2 100644
--- a/Zotlabs/Module/Channel.php
+++ b/Zotlabs/Module/Channel.php
@@ -468,6 +468,13 @@ class Channel extends Controller {
);
}
}
+
+ // Add pinned content
+ if(! $decoded && ! $search) {
+ $pinned = new \Zotlabs\Widget\Pinned;
+ $r = $pinned->widget(intval(App::$profile['profile_uid']), [ITEM_TYPE_POST]);
+ $o .= $r['html'];
+ }
$mode = (($search) ? 'search' : 'channel');
diff --git a/Zotlabs/Module/Pin.php b/Zotlabs/Module/Pin.php
new file mode 100644
index 000000000..74297aa7c
--- /dev/null
+++ b/Zotlabs/Module/Pin.php
@@ -0,0 +1,68 @@
+<?php
+namespace Zotlabs\Module;
+
+/*
+ * Pinned post processing
+ */
+
+use App;
+
+class Pin extends \Zotlabs\Web\Controller {
+
+
+ function init() {
+
+ if(argc() !== 2)
+ http_status_exit(400, 'Bad request');
+ }
+
+
+ function post() {
+
+ $item_id = intval($_POST['id']);
+
+ if ($item_id <= 0)
+ http_status_exit(404, 'Not found');
+
+ $observer = \App::get_observer();
+ if(! $observer)
+ http_status_exit(403, 'Forbidden');
+
+ $r = q("SELECT * FROM item WHERE id = %d AND id = parent AND item_private = 0 LIMIT 1",
+ $item_id
+ );
+ if(! $r) {
+ notice(t('Unable to locate original post.'));
+ http_status_exit(404, 'Not found');
+ }
+
+ $midb64 = 'b64.' . base64url_encode($r[0]['mid']);
+ $pinned = (in_array($midb64, get_pconfig($r[0]['uid'], 'pinned', $r[0]['item_type'], [])) ? true : false);
+
+ switch(argv(1)) {
+
+ case 'pin':
+ if(! local_channel() || local_channel() != $r[0]['uid'])
+ http_status_exit(403, 'Forbidden');
+ // Currently allow only one pinned item for each type
+ set_pconfig($r[0]['uid'], 'pinned', $r[0]['item_type'], ($pinned ? [] : [ $midb64 ]));
+ if($pinned)
+ del_pconfig($r[0]['uid'], 'pinned_hide', $midb64);
+ break;
+
+ case 'hide':
+ if($pinned) {
+ $hidden = get_pconfig($r[0]['uid'], 'pinned_hide', $midb64, []);
+ if(! in_array($observer['xchan_hash'], $hidden)) {
+ $hidden[] = $observer['xchan_hash'];
+ set_pconfig($r[0]['uid'], 'pinned_hide', $midb64, $hidden);
+ }
+ }
+
+ default:
+ http_status_exit(404, 'Not found');
+ }
+
+ build_sync_packet($r[0]['uid'], [ 'config' ]);
+ }
+}