streams/Zotlabs/Widget/Pinned.php

109 lines
2.1 KiB
PHP
Raw Normal View History

2019-12-03 02:44:32 +00:00
<?php
namespace Zotlabs\Widget;
/*
* Show pinned content
*
*/
use App;
class Pinned {
private $allowed_types = 0;
private $uid = 0;
/*
* @brief Displays pinned items
*
*/
function widget($args) {
$ret = '';
$this->allowed_types = get_config('system', 'pin_types', [ ITEM_TYPE_POST ]);
2019-12-03 05:08:06 +00:00
$this->uid = App::$profile_uid;
$types = (($args['types']) ?: [ ITEM_TYPE_POST ]);
2019-12-03 02:44:32 +00:00
$id_list = $this->list($types);
2019-12-03 05:08:06 +00:00
//logger('id_list: ' . print_r($id_list,true));
if (empty($id_list)) {
2019-12-03 02:44:32 +00:00
return $ret;
2019-12-03 05:08:06 +00:00
}
2019-12-03 02:44:32 +00:00
2019-12-03 05:08:06 +00:00
$o = conversation($id_list,'network-new',0,'traditional');
2019-12-03 02:44:32 +00:00
2019-12-03 05:08:06 +00:00
// change some id and class names so that auto-update doesn't stumble over them
2019-12-03 02:44:32 +00:00
2019-12-03 05:08:06 +00:00
$o = str_replace('<div id="threads-begin">','<div id="pins-begin">', $o);
$o = str_replace('<div id="threads-end">','<div id="pins-end">', $o);
$o = str_replace('<div id="conversation-end">','<div id="pin-widget-end">', $o);
$o = str_replace('class="thread-wrapper ','class="pin-thread-wrapper ', $o);
2019-12-03 02:44:32 +00:00
2019-12-03 05:08:06 +00:00
logger('output: ' . $o);
return $o;
2019-12-03 02:44:32 +00:00
}
/*
* @brief List pinned items depend on type
*
* @param $types
* @return array of pinned items
*
*/
private function list($types) {
2019-12-03 05:08:06 +00:00
if (empty($types) || (! is_array($types))) {
2019-12-03 02:44:32 +00:00
return [];
2019-12-03 05:08:06 +00:00
}
2019-12-03 02:44:32 +00:00
$item_types = array_intersect($this->allowed_types, $types);
2019-12-03 05:08:06 +00:00
if (empty($item_types)) {
2019-12-03 02:44:32 +00:00
return [];
2019-12-03 05:08:06 +00:00
}
2019-12-03 02:44:32 +00:00
$mids_list = [];
2019-12-03 05:08:06 +00:00
foreach ($item_types as $type) {
2019-12-03 02:44:32 +00:00
$mids = get_pconfig($this->uid, 'pinned', $type, []);
2019-12-03 05:08:06 +00:00
if ($mids) {
foreach($mids as $mid) {
if ($mid) {
$mids_list[] = $mid;
}
}
2019-12-03 02:44:32 +00:00
}
}
2019-12-03 05:08:06 +00:00
if (empty($mids_list)) {
2019-12-03 02:44:32 +00:00
return [];
2019-12-03 05:08:06 +00:00
}
$item_normal = item_normal();
$sql_extra = item_permissions_sql($this->uid);
2019-12-03 02:44:32 +00:00
2019-12-03 05:08:06 +00:00
$r = q("SELECT *, id as item_id FROM item WHERE parent_mid IN (" . protect_sprintf(stringify_array($mids_list,true)) . ") AND uid = %d AND id = parent $item_normal $sql_extra ORDER BY created DESC",
2019-12-03 02:44:32 +00:00
intval($this->uid)
);
2019-12-03 05:08:06 +00:00
if ($r) {
xchan_query($r,true);
$items = fetch_post_tags($r,true);
for ($x = 0; $x < count($items); $x ++) {
$items[$x]['item_id'] = 'pin-' . $items[$x]['item_id'];
}
return $items;
}
2019-12-03 02:44:32 +00:00
return [];
}
}