diff options
Diffstat (limited to 'Zotlabs')
29 files changed, 261 insertions, 3042 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9b3cab9d0..8e24dde41 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -670,24 +670,36 @@ class Activity { return $ret; } - static function decode_attachment($item) { + public static function decode_attachment($item) { $ret = []; if (array_key_exists('attachment', $item) && is_array($item['attachment'])) { - foreach ($item['attachment'] as $att) { + $ptr = $item['attachment']; + if (!array_key_exists(0, $ptr)) { + $ptr = [$ptr]; + } + foreach ($ptr as $att) { $entry = []; - if (array_key_exists('href', $att)) + if (array_key_exists('href', $att) && $att['href']) { $entry['href'] = $att['href']; - elseif (array_key_exists('url', $att)) + } elseif (array_key_exists('url', $att) && $att['url']) { $entry['href'] = $att['url']; - if (array_key_exists('mediaType', $att)) + } + if (array_key_exists('mediaType', $att) && $att['mediaType']) { $entry['type'] = $att['mediaType']; - elseif (array_key_exists('type', $att) && $att['type'] === 'Image') + } elseif (array_key_exists('type', $att) && $att['type'] === 'Image') { $entry['type'] = 'image/jpeg'; - if ($entry) + } + if (array_key_exists('name', $att) && $att['name']) { + $entry['name'] = html2plain(purify_html($att['name']), 256); + } + if ($entry) { $ret[] = $entry; + } } + } elseif (isset($item['attachment']) && is_string($item['attachment'])) { + btlogger('not an array: ' . $item['attachment']); } return $ret; @@ -1013,7 +1025,7 @@ class Activity { 'type' => 'Image', 'mediaType' => (($p['xchan_photo_mimetype']) ? $p['xchan_photo_mimetype'] : 'image/png'), 'updated' => datetime_convert('UTC', 'UTC', $p['xchan_photo_date'], ATOM_TIME), - 'url' => $p['xchan_photo_l'], + 'url' => $p['xchan_photo_l'] . '?rev=' . strtotime($p['xchan_photo_date']), 'height' => 300, 'width' => 300, ]; @@ -2195,20 +2207,20 @@ class Activity { $s['created'] = datetime_convert('UTC', 'UTC', $act->data['published']); $s['commented'] = $s['created']; } - elseif (array_key_exists('published', $act->obj)) { + elseif (is_array($act->obj) && array_key_exists('published', $act->obj)) { $s['created'] = datetime_convert('UTC', 'UTC', $act->obj['published']); $s['commented'] = $s['created']; } if (array_key_exists('updated', $act->data)) { $s['edited'] = datetime_convert('UTC', 'UTC', $act->data['updated']); } - elseif (array_key_exists('updated', $act->obj)) { + elseif (is_array($act->obj) && array_key_exists('updated', $act->obj)) { $s['edited'] = datetime_convert('UTC', 'UTC', $act->obj['updated']); } if (array_key_exists('expires', $act->data)) { $s['expires'] = datetime_convert('UTC', 'UTC', $act->data['expires']); } - elseif (array_key_exists('expires', $act->obj)) { + elseif (is_array($act->obj) && array_key_exists('expires', $act->obj)) { $s['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expires']); } @@ -2270,9 +2282,18 @@ class Activity { $s['mid'] = $act->obj['id']; $s['parent_mid'] = $act->obj['id']; } + if ($act->type === 'emojiReaction') { $content['content'] = (($act->tgt && $act->tgt['type'] === 'Image') ? '[img=32x32]' . $act->tgt['url'] . '[/img]' : '&#x' . $act->tgt['name'] . ';'); } + + if (in_array($act->type, ['EmojiReaction', 'EmojiReact'])) { + // Pleroma reactions + $t = trim(self::get_textfield($act->data, 'content')); + if (mb_strlen($t) === 1) { + $content['content'] = $t; + } + } } $s['item_thread_top'] = 0; @@ -2408,7 +2429,6 @@ class Activity { } } } - } $a = self::decode_attachment($act->obj); @@ -2423,8 +2443,11 @@ class Activity { if (array_key_exists('type', $act->obj)) { - if ($act->obj['type'] === 'Note' && $s['attach']) { - $s['body'] = self::bb_attach($s['attach'], $s['body']) . $s['body']; + // Objects that might have media attachments which aren't already provided in the content element. + // We'll check specific media objects separately. + + if (in_array($act->obj['type'], ['Article', 'Document', 'Event', 'Note', 'Page', 'Place', 'Question']) && isset($s['attach']) && $s['attach']) { + $s = self::bb_attach($s); } if ($act->obj['type'] === 'Question' && in_array($act->type, ['Create', 'Update'])) { @@ -2513,13 +2536,13 @@ class Activity { usort($mps,[ '\Zotlabs\Lib\Activity', 'vid_sort' ]); foreach ($mps as $m) { if (intval($m['height']) < 500 && Activity::media_not_in_body($m['href'],$s['body'])) { - $s['body'] = $tag . $m['href'] . '[/video]' . "\n\n" . $s['body']; + $s['body'] = $tag . $m['href'] . '[/video]' . "\r\n" . $s['body']; break; } } } elseif (is_string($act->obj['url']) && Activity::media_not_in_body($act->obj['url'],$s['body'])) { - $s['body'] = $tag . $act->obj['url'] . '[/video]' . "\n\n" . $s['body']; + $s['body'] = $tag . $act->obj['url'] . '[/video]' . "\r\n" . $s['body']; } } @@ -2545,13 +2568,13 @@ class Activity { } foreach ($ptr as $vurl) { if (in_array($vurl['mediaType'], $atypes) && self::media_not_in_body($vurl['href'], $s['body'])) { - $s['body'] = '[audio]' . $vurl['href'] . '[/audio]' . "\n\n" . $s['body']; + $s['body'] = '[audio]' . $vurl['href'] . '[/audio]' . "\r\n" . $s['body']; break; } } } elseif (is_string($act->obj['url']) && self::media_not_in_body($act->obj['url'], $s['body'])) { - $s['body'] = '[audio]' . $act->obj['url'] . '[/audio]' . "\n\n" . $s['body']; + $s['body'] = '[audio]' . $act->obj['url'] . '[/audio]' . "\r\n" . $s['body']; } } @@ -2571,7 +2594,7 @@ class Activity { } foreach ($ptr as $vurl) { if (strpos($s['body'], $vurl['href']) === false) { - $bb_imgs = '[zmg]' . $vurl['href'] . '[/zmg]' . "\n\n"; + $bb_imgs = '[zmg]' . $vurl['href'] . '[/zmg]' . "\r\n"; break; } } @@ -2579,7 +2602,7 @@ class Activity { } elseif (is_string($act->obj['url'])) { if (strpos($s['body'], $act->obj['url']) === false) { - $s['body'] .= '[zmg]' . $act->obj['url'] . '[/zmg]' . "\n\n" . $s['body']; + $s['body'] .= '[zmg]' . $act->obj['url'] . '[/zmg]' . "\r\n" . $s['body']; } } } @@ -2616,10 +2639,10 @@ class Activity { if ($purl) { $li = z_fetch_url(z_root() . '/linkinfo?binurl=' . bin2hex($purl)); if ($li['success'] && $li['body']) { - $s['body'] .= "\n" . $li['body']; + $s['body'] .= "\r\n" . $li['body']; } else { - $s['body'] .= "\n\n" . $purl; + $s['body'] .= "\r\n" . $purl; } } } @@ -3574,38 +3597,76 @@ class Activity { return; } - static function bb_attach($attach, $body) { + public static function bb_attach($item) { $ret = false; - foreach ($attach as $a) { + if (!(is_array($item['attach']) && $item['attach'])) { + return $item; + } + + foreach ($item['attach'] as $a) { + if (array_key_exists('type', $a) && stripos($a['type'], 'image') !== false) { - if (self::media_not_in_body($a['href'], $body)) { - $ret .= "\n\n" . '[img]' . $a['href'] . '[/img]'; + // don't add inline image if it's an svg and we already have an inline svg + if ($a['type'] === 'image/svg+xml' && strpos($item['body'], '[/svg]')) { + continue; + } + if (self::media_not_in_body($a['href'], $item['body'])) { + if (isset($a['name']) && $a['name']) { + $alt = htmlspecialchars($a['name'], ENT_QUOTES); + $item['body'] = '[img=' . $a['href'] . ']' . $alt . '[/img]' . "\r\n" . $item['body']; + } else { + $item['body'] = '[img]' . $a['href'] . '[/img]' . "\r\n" . $item['body']; + } } } + if (array_key_exists('type', $a) && stripos($a['type'], 'video') !== false) { - if (self::media_not_in_body($a['href'], $body)) { - $ret .= "\n\n" . '[video]' . $a['href'] . '[/video]'; + if (self::media_not_in_body($a['href'], $item['body'])) { + $item['body'] = '[video]' . $a['href'] . '[/video]' . "\r\n" . $item['body']; } } if (array_key_exists('type', $a) && stripos($a['type'], 'audio') !== false) { - if (self::media_not_in_body($a['href'], $body)) { - $ret .= "\n\n" . '[audio]' . $a['href'] . '[/audio]'; + if (self::media_not_in_body($a['href'], $item['body'])) { + $item['body'] = '[audio]' . $a['href'] . '[/audio]' . "\r\n" . $item['body']; } } + //if (array_key_exists('type', $a) && stripos($a['type'], 'activity') !== false) { + //if (self::media_not_in_body($a['href'], $item['body'])) { + //$item = self::get_quote($a['href'], $item); + //} + //} } - return $ret; + return $item; } + // check for the existence of existing media link in body - static function media_not_in_body($s, $body) { - if ((strpos($body, ']' . $s . '[/img]') === false) && + public static function media_not_in_body($s, $body) { + + $s_alt = htmlspecialchars($s, ENT_QUOTES, 'UTF-8'); + + if ( + (strpos($body, ']' . $s . '[/img]') === false) && + (strpos($body, '[img=' . $s . ']') === false) && (strpos($body, ']' . $s . '[/zmg]') === false) && + (strpos($body, '[zmg=' . $s . ']') === false) && (strpos($body, ']' . $s . '[/video]') === false) && - (strpos($body, ']' . $s . '[/audio]') === false)) { + (strpos($body, ']' . $s . '[/zvideo]') === false) && + (strpos($body, ']' . $s . '[/audio]') === false) && + (strpos($body, ']' . $s . '[/zaudio]') === false) && + (strpos($body, ']' . $s_alt . '[/img]') === false) && + (strpos($body, '[img=' . $s_alt . ']') === false) && + (strpos($body, ']' . $s_alt . '[/zmg]') === false) && + (strpos($body, '[zmg=' . $s_alt . ']') === false) && + (strpos($body, ']' . $s_alt . '[/video]') === false) && + (strpos($body, ']' . $s_alt . '[/zvideo]') === false) && + (strpos($body, ']' . $s_alt . '[/audio]') === false) && + (strpos($body, ']' . $s_alt . '[/zaudio]') === false) + ) { return true; } return false; diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index 1c278f2ee..e77b501b3 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -70,9 +70,12 @@ class ActivityStreams { } } + // This indicates only that we have sucessfully decoded JSON. $this->valid = true; - if (array_key_exists('type', $this->data) && array_key_exists('actor', $this->data) && array_key_exists('object', $this->data)) { + // Special handling for Mastodon "delete actor" activities which will often fail to verify + // because the key cannot be fetched. We will catch this condition elsewhere. + if (is_array($this->data) && array_key_exists('type', $this->data) && array_key_exists('actor', $this->data) && array_key_exists('object', $this->data)) { if ($this->data['type'] === 'Delete' && $this->data['actor'] === $this->data['object']) { $this->deleted = $this->data['actor']; $this->valid = false; @@ -81,6 +84,7 @@ class ActivityStreams { } + // Attempt to assemble an Activity from what we were given. if ($this->is_valid()) { $this->id = $this->get_property_obj('id'); $this->type = $this->get_primary_type(); diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 1421c72ae..59e4d9a4e 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -256,8 +256,8 @@ class Enotify { $itemlink = $params['link']; - if (array_key_exists('item',$params) && activity_match($params['item']['verb'],ACTIVITY_LIKE)) { - if(! $always_show_in_notices || !($vnotify & VNOTIFY_LIKE)) { + if (array_key_exists('item',$params) && (activity_match($params['item']['verb'], ACTIVITY_LIKE) || activity_match($params['item']['verb'], ACTIVITY_DISLIKE))) { + if(! $always_show_in_notices || !($vnotify & VNOTIFY_LIKE) || !feature_enabled($recip['channel_id'], 'dislike')) { logger('notification: not a visible activity. Ignoring.'); pop_lang(); return; @@ -291,22 +291,29 @@ class Enotify { ); } + if (!$p) { + pop_lang(); + return; + } + xchan_query($p); -//@@FIXME $p can be null (line 285) $item_post_type = item_post_type($p[0]); // $private = $p[0]['item_private']; $parent_id = $p[0]['id']; $parent_item = $p[0]; + $verb = ((activity_match($params['item']['verb'], ACTIVITY_DISLIKE)) ? t('disliked') : t('liked')); // "your post" if($p[0]['owner']['xchan_name'] === $p[0]['author']['xchan_name'] && intval($p[0]['item_wall'])) - $dest_str = sprintf(t('%1$s liked [zrl=%2$s]your %3$s[/zrl]'), + $dest_str = sprintf(t('%1$s %2$s [zrl=%3$s]your %4$s[/zrl]'), '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $verb, $itemlink, - $item_post_type); + $item_post_type + ); else { pop_lang(); return; @@ -824,6 +831,14 @@ class Enotify { $itemem_text = sprintf( t('repeated %s\'s post'), '[bdi]' . $item['author']['xchan_name'] . '[/bdi]'); } + if($item['verb'] === ACTIVITY_LIKE) { + $itemem_text = sprintf( t('liked %s\'s post'), '[bdi]' . $item['author']['xchan_name'] . '[/bdi]'); + } + + if($item['verb'] === ACTIVITY_DISLIKE) { + $itemem_text = sprintf( t('disliked %s\'s post'), '[bdi]' . $item['author']['xchan_name'] . '[/bdi]'); + } + if(in_array($item['obj_type'], ['Document', 'Video', 'Audio', 'Image'])) { $itemem_text = t('shared a file with you'); } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 379b329c7..8eb5ce647 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1627,7 +1627,7 @@ class Libzot { // doesn't exist. if ($perm === 'send_stream') { - if ($force || get_pconfig($channel['channel_id'], 'system', 'hyperdrive', false) || $arr['verb'] === ACTIVITY_SHARE) { + if ($force || get_pconfig($channel['channel_id'], 'system', 'hyperdrive', false)) { $allowed = true; } } @@ -1673,6 +1673,10 @@ class Libzot { $DR->update('comment parent not found'); $result[] = $DR->get(); + if ($relay || $request || $local_public) { + continue; + } + // We don't seem to have a copy of this conversation or at least the parent // - so request a copy of the entire conversation to date. // Don't do this if it's a relay post as we're the ones who are supposed to @@ -1684,10 +1688,10 @@ class Libzot { // the top level post is unlikely to be imported and // this is just an exercise in futility. - if ((!$relay) && (!$request) && (!$local_public) - && perm_is_allowed($channel['channel_id'], $sender, 'send_stream')) { + if (perm_is_allowed($channel['channel_id'], $sender, 'send_stream')) { self::fetch_conversation($channel, $arr['parent_mid']); } + continue; } diff --git a/Zotlabs/Lib/MessageFilter.php b/Zotlabs/Lib/MessageFilter.php index 95721e7c7..70b0188c4 100644 --- a/Zotlabs/Lib/MessageFilter.php +++ b/Zotlabs/Lib/MessageFilter.php @@ -8,7 +8,7 @@ class MessageFilter { public static function evaluate($item, $incl, $excl) { - $text = prepare_text($item['body'],((isset($item['mimetype'])) ? $item['mimetype'] : 'text/x-multicode')); + $text = prepare_text($item['body'],((isset($item['mimetype'])) ? $item['mimetype'] : 'text/bbcode')); $text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text); $lang = null; diff --git a/Zotlabs/Lib/NativeWiki.php b/Zotlabs/Lib/NativeWiki.php deleted file mode 100644 index bf4ac8e87..000000000 --- a/Zotlabs/Lib/NativeWiki.php +++ /dev/null @@ -1,322 +0,0 @@ -<?php - -namespace Zotlabs\Lib; - -use Zotlabs\Lib\Libsync; - -define ( 'NWIKI_ITEM_RESOURCE_TYPE', 'nwiki' ); - -class NativeWiki { - - - public static function listwikis($channel, $observer_hash) { - - $sql_extra = item_permissions_sql($channel['channel_id'], $observer_hash); - $wikis = q("SELECT * FROM item - WHERE resource_type = '%s' AND mid = parent_mid AND uid = %d AND item_deleted = 0 $sql_extra", - dbesc(NWIKI_ITEM_RESOURCE_TYPE), - intval($channel['channel_id']) - ); - - if($wikis) { - foreach($wikis as &$w) { - - $w['json_allow_cid'] = acl2json($w['allow_cid']); - $w['json_allow_gid'] = acl2json($w['allow_gid']); - $w['json_deny_cid'] = acl2json($w['deny_cid']); - $w['json_deny_gid'] = acl2json($w['deny_gid']); - - $w['rawName'] = get_iconfig($w, 'wiki', 'rawName'); - $w['htmlName'] = escape_tags($w['rawName']); - //$w['urlName'] = urlencode(urlencode($w['rawName'])); - $w['urlName'] = self::name_encode($w['rawName']); - $w['mimeType'] = get_iconfig($w, 'wiki', 'mimeType'); - $w['typelock'] = get_iconfig($w, 'wiki', 'typelock'); - $w['lockstate'] = (($w['allow_cid'] || $w['allow_gid'] || $w['deny_cid'] || $w['deny_gid']) ? 'lock' : 'unlock'); - } - } - // TODO: query db for wikis the observer can access. Return with two lists, for read and write access - return array('wikis' => $wikis); - } - - - public static function create_wiki($channel, $observer_hash, $wiki, $acl) { - - $resource_id = new_uuid(); - $uuid = new_uuid(); - - $ac = $acl->get(); - $mid = z_root() . '/item/' . $uuid; - - $arr = array(); // Initialize the array of parameters for the post - $item_hidden = ((intval($wiki['postVisible']) === 0) ? 1 : 0); - $wiki_url = z_root() . '/wiki/' . $channel['channel_address'] . '/' . $wiki['urlName']; - $arr['aid'] = $channel['channel_account_id']; - $arr['uuid'] = $uuid; - $arr['uid'] = $channel['channel_id']; - $arr['mid'] = $mid; - $arr['parent_mid'] = $mid; - $arr['item_hidden'] = $item_hidden; - $arr['resource_type'] = NWIKI_ITEM_RESOURCE_TYPE; - $arr['resource_id'] = $resource_id; - $arr['owner_xchan'] = $channel['channel_hash']; - $arr['author_xchan'] = $observer_hash; - $arr['plink'] = $mid; - $arr['llink'] = z_root() . '/display/' . gen_link_id($mid); - $arr['title'] = $wiki['htmlName']; // name of new wiki; - $arr['allow_cid'] = $ac['allow_cid']; - $arr['allow_gid'] = $ac['allow_gid']; - $arr['deny_cid'] = $ac['deny_cid']; - $arr['deny_gid'] = $ac['deny_gid']; - $arr['item_wall'] = 1; - $arr['item_origin'] = 1; - $arr['item_thread_top'] = 1; - $arr['item_private'] = intval($acl->is_private()); - $arr['verb'] = ACTIVITY_CREATE; - $arr['obj_type'] = 'Document'; - $arr['body'] = '[table][tr][td][h1]New Wiki[/h1][/td][/tr][tr][td][zrl=' . $wiki_url . ']' . $wiki['htmlName'] . '[/zrl][/td][/tr][/table]'; - - $arr['public_policy'] = map_scope(\Zotlabs\Access\PermissionLimits::Get($channel['channel_id'],'view_wiki'),true); - - // Save the wiki name information using iconfig. This is shareable. - if(! set_iconfig($arr, 'wiki', 'rawName', $wiki['rawName'], true)) { - return array('item' => null, 'success' => false); - } - if(! set_iconfig($arr, 'wiki', 'mimeType', $wiki['mimeType'], true)) { - return array('item' => null, 'success' => false); - } - - set_iconfig($arr,'wiki','typelock',$wiki['typelock'],true); - - $post = item_store($arr); - - $item_id = $post['item_id']; - - if($item_id) { - \Zotlabs\Daemon\Master::Summon(array('Notifier', 'activity', $item_id)); - return array('item' => $post['item'], 'item_id' => $item_id, 'success' => true); - } - else { - return array('item' => null, 'success' => false); - } - } - - - public static function update_wiki($channel_id, $observer_hash, $arr, $acl) { - - $w = self::get_wiki($channel_id, $observer_hash, $arr['resource_id']); - $item = $w['wiki']; - - if(! $item) { - return array('item' => null, 'success' => false); - } - - $x = $acl->get(); - - $item['allow_cid'] = $x['allow_cid']; - $item['allow_gid'] = $x['allow_gid']; - $item['deny_cid'] = $x['deny_cid']; - $item['deny_gid'] = $x['deny_gid']; - $item['item_private'] = intval($acl->is_private()); - - $update_title = false; - - if($item['title'] !== $arr['updateRawName']) { - $update_title = true; - $item['title'] = $arr['updateRawName']; - } - - $update = item_store_update($item); - - $item_id = $update['item_id']; - - // update acl for any existing wiki pages - - q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d where resource_type = 'nwikipage' and resource_id = '%s'", - dbesc($item['allow_cid']), - dbesc($item['allow_gid']), - dbesc($item['deny_cid']), - dbesc($item['deny_gid']), - dbesc($item['item_private']), - dbesc($arr['resource_id']) - ); - - - if($update['item_id']) { - info( t('Wiki updated successfully')); - if($update_title) { - // Update the wiki name information using iconfig. - if(! set_iconfig($update['item_id'], 'wiki', 'rawName', $arr['updateRawName'], true)) { - return array('item' => null, 'success' => false); - } - } - return array('item' => $update['item'], 'item_id' => $update['item_id'], 'success' => $update['success']); - } - else { - return array('item' => null, 'success' => false); - } - } - - - public static function sync_a_wiki_item($uid,$id,$resource_id) { - - $r = q("SELECT * from item WHERE uid = %d AND ( id = %d OR ( resource_type = '%s' and resource_id = '%s' )) ", - intval($uid), - intval($id), - dbesc(NWIKI_ITEM_RESOURCE_TYPE), - dbesc($resource_id) - ); - if($r) { - - $q = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s'", - dbesc($r[0]['resource_id']) - ); - if($q) { - $r = array_merge($r,$q); - } - xchan_query($r); - $sync_item = fetch_post_tags($r); - if($sync_item) { - $pkt = []; - foreach($sync_item as $w) { - $pkt[] = encode_item($w,true); - } - Libsync::build_sync_packet($uid,array('wiki' => $pkt)); - } - } - } - - - public static function delete_wiki($channel_id,$observer_hash,$resource_id) { - - $w = self::get_wiki($channel_id,$observer_hash,$resource_id); - if(! $w['wiki']) { - return [ 'success' => false ]; - } - else { - - $r = q("SELECT id FROM item WHERE uid = %s AND resource_id = '%s'", - intval($channel_id), - dbesc($resource_id) - ); - - $ids = array_column($r, 'id'); - drop_items($ids, true, DROPITEM_PHASE1); - - info(t('Wiki files deleted successfully')); - - return [ 'success' => true ]; - } - } - - - public static function get_wiki($channel_id, $observer_hash, $resource_id) { - - $sql_extra = item_permissions_sql($channel_id,$observer_hash); - - $item = q("SELECT * FROM item WHERE uid = %d AND resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 - $sql_extra ORDER BY id LIMIT 1", - intval($channel_id), - dbesc(NWIKI_ITEM_RESOURCE_TYPE), - dbesc($resource_id) - ); - if(! $item) { - return [ 'wiki' => null ]; - } - else { - - $w = $item[0]; // wiki item table record - // Get wiki metadata - $rawName = get_iconfig($w, 'wiki', 'rawName'); - $mimeType = get_iconfig($w, 'wiki', 'mimeType'); - $typelock = get_iconfig($w, 'wiki', 'typelock'); - - return array( - 'wiki' => $w, - 'rawName' => $rawName, - 'htmlName' => escape_tags($rawName), - //'urlName' => urlencode(urlencode($rawName)), - 'urlName' => self::name_encode($rawName), - 'mimeType' => $mimeType, - 'typelock' => $typelock - ); - } - } - - - public static function exists_by_name($uid, $urlName) { - - $sql_extra = item_permissions_sql($uid); - - $item = q("SELECT item.id, resource_id FROM item left join iconfig on iconfig.iid = item.id - WHERE resource_type = '%s' AND iconfig.v = '%s' AND uid = %d - AND item_deleted = 0 $sql_extra limit 1", - dbesc(NWIKI_ITEM_RESOURCE_TYPE), - //dbesc(urldecode($urlName)), - dbesc(self::name_decode($urlName)), - intval($uid) - ); - - if($item) { - return array('id' => $item[0]['id'], 'resource_id' => $item[0]['resource_id']); - } - else { - return array('id' => null, 'resource_id' => null); - } - } - - - public static function get_permissions($resource_id, $owner_id, $observer_hash) { - - // TODO: For now, only the owner can edit - $sql_extra = item_permissions_sql($owner_id, $observer_hash); - - if(local_channel() && local_channel() == $owner_id) { - return [ 'read' => true, 'write' => true, 'success' => true ]; - } - - $r = q("SELECT * FROM item WHERE uid = %d and resource_type = '%s' AND resource_id = '%s' $sql_extra LIMIT 1", - intval($owner_id), - dbesc(NWIKI_ITEM_RESOURCE_TYPE), - dbesc($resource_id) - ); - - if(! $r) { - return array('read' => false, 'write' => false, 'success' => true); - } - else { - $write = perm_is_allowed($owner_id, $observer_hash,'write_wiki'); - return array('read' => true, 'write' => $write, 'success' => true); - } - } - - - public static function name_encode ($string) { - - $string = html_entity_decode($string); - $encoding = mb_internal_encoding(); - mb_internal_encoding("UTF-8"); - $ret = mb_ereg_replace_callback ('[^A-Za-z0-9\-\_\.\~]',function ($char) { - $charhex = unpack('H*',$char[0]); - $ret = '('.$charhex[1].')'; - return $ret; - } - ,$string); - mb_internal_encoding($encoding); - return $ret; - } - - - public static function name_decode ($string) { - - $encoding = mb_internal_encoding(); - mb_internal_encoding("UTF-8"); - $ret = mb_ereg_replace_callback ('(\(([0-9a-f]+)\))',function ($chars) { - return pack('H*',$chars[2]); - } - ,$string); - mb_internal_encoding($encoding); - return $ret; - } - -} diff --git a/Zotlabs/Lib/NativeWikiPage.php b/Zotlabs/Lib/NativeWikiPage.php deleted file mode 100644 index 1e944f7ac..000000000 --- a/Zotlabs/Lib/NativeWikiPage.php +++ /dev/null @@ -1,725 +0,0 @@ -<?php - -namespace Zotlabs\Lib; - -use App; -use Zotlabs\Access\PermissionLimits; - -class NativeWikiPage { - - static public function page_list($channel_id, $observer_hash, $resource_id) { - - // TODO: Create item table records for pages so that metadata like title can be applied - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - - $pages[] = [ - 'resource_id' => '', - 'title' => 'Home', - 'url' => 'Home', - 'link_id' => 'id_wiki_home_0' - ]; - - $sql_extra = item_permissions_sql($channel_id, $observer_hash); - - $r = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s' and uid = %d and item_deleted = 0 - $sql_extra order by title asc", - dbesc($resource_id), - intval($channel_id) - ); - if ($r) { - $x = []; - $y = []; - - foreach ($r as $rv) { - if (!in_array($rv['mid'], $x)) { - $y[] = $rv; - $x[] = $rv['mid']; - } - } - - $items = fetch_post_tags($y, true); - - foreach ($items as $page_item) { - $title = get_iconfig($page_item['id'], 'nwikipage', 'pagetitle', t('(No Title)')); - if (urldecode($title) !== 'Home') { - $pages[] = [ - 'resource_id' => $resource_id, - 'title' => escape_tags($title), - //'url' => str_replace('%2F','/',urlencode(str_replace('%2F','/',urlencode($title)))), - 'url' => NativeWiki::name_encode($title), - 'link_id' => 'id_' . substr($resource_id, 0, 10) . '_' . $page_item['id'] - ]; - } - } - } - - return ['pages' => $pages, 'wiki' => $w]; - } - - - static public function create_page($channel, $observer_hash, $name, $resource_id, $mimetype = 'text/bbcode') { - - logger('mimetype: ' . $mimetype); - - if (!in_array($mimetype, ['text/markdown', 'text/bbcode', 'text/plain', 'text/html'])) - $mimetype = 'text/markdown'; - - $w = NativeWiki::get_wiki($channel['channel_id'], $observer_hash, $resource_id); - - if (!$w['wiki']) { - return ['content' => null, 'message' => 'Error reading wiki', 'success' => false]; - } - - // backslashes won't work well in the javascript functions - $name = str_replace('\\', '', $name); - - $uuid = new_uuid(); - $mid = z_root() . '/item/' . $uuid; - - // create an empty activity - $arr = []; - $arr['aid'] = $channel['channel_account_id']; - $arr['uid'] = $channel['channel_id']; - $arr['mid'] = $mid; - $arr['parent_mid'] = $w['wiki']['mid']; - $arr['parent'] = $w['wiki']['parent']; - $arr['uuid'] = $uuid; - $arr['item_hidden'] = $w['wiki']['item_hidden']; - $arr['plink'] = $mid; - $arr['llink'] = z_root() . '/display/' . gen_link_id($mid); - $arr['author_xchan'] = $observer_hash; - $arr['mimetype'] = $mimetype; - $arr['title'] = $name; - $arr['resource_type'] = 'nwikipage'; - $arr['resource_id'] = $resource_id; - $arr['allow_cid'] = $w['wiki']['allow_cid']; - $arr['allow_gid'] = $w['wiki']['allow_gid']; - $arr['deny_cid'] = $w['wiki']['deny_cid']; - $arr['deny_gid'] = $w['wiki']['deny_gid']; - $arr['item_private'] = $w['wiki']['item_private']; - $arr['item_wall'] = 1; - $arr['item_origin'] = 1; - $arr['item_thread_top'] = 1; - $arr['verb'] = ACTIVITY_CREATE; - $arr['obj_type'] = 'Document'; - // TODO: add an object? - $arr['public_policy'] = map_scope(PermissionLimits::Get($channel['channel_id'], 'view_wiki'), true); - - // We may wish to change this some day. - $arr['item_unpublished'] = 1; - - set_iconfig($arr, 'nwikipage', 'pagetitle', (($name) ? $name : t('(No Title)')), true); - $p = item_store($arr, false, false); - - if ($p['item_id']) { - $page = [ - 'rawName' => $name, - 'htmlName' => escape_tags($name), - //'urlName' => urlencode($name), - 'urlName' => NativeWiki::name_encode($name) - - ]; - - return ['page' => $page, 'item_id' => $p['item_id'], 'item' => $p['activity'], 'wiki' => $w, 'message' => '', 'success' => true]; - } - return ['success' => false, 'message' => t('Wiki page create failed.')]; - } - - - static public function rename_page($arr) { - - $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); - $pageNewName = ((array_key_exists('pageNewName', $arr)) ? $arr['pageNewName'] : ''); - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? $arr['channel_id'] : 0); - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - if (!$w['wiki']) { - return ['message' => t('Wiki not found.'), 'success' => false]; - } - - - $ic = q("select * from iconfig left join item on iconfig.iid = item.id - where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'", - intval($channel_id), - dbesc($pageNewName) - ); - - if ($ic) { - return ['success' => false, 'message' => t('Destination name already exists')]; - } - - - $ids = []; - - $ic = q("select *, item.id as item_id from iconfig left join item on iconfig.iid = item.id - where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'", - intval($channel_id), - dbesc($pageUrlName) - ); - - if ($ic) { - foreach ($ic as $c) { - set_iconfig($c['item_id'], 'nwikipage', 'pagetitle', $pageNewName); - $ids[] = $c['item_id']; - } - - $str_ids = implode(',', $ids); - q("update item set title = '%s' where id in ($str_ids)", - dbesc($pageNewName) - ); - - $page = [ - 'rawName' => $pageNewName, - 'htmlName' => escape_tags($pageNewName), - //'urlName' => urlencode(escape_tags($pageNewName)) - 'urlName' => NativeWiki::name_encode($pageNewName) - ]; - - return ['success' => true, 'page' => $page]; - } - - return ['success' => false, 'message' => t('Page not found')]; - - } - - - static public function get_page_content($arr) { - - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? intval($arr['channel_id']) : 0); - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - if (!$w['wiki']) { - return ['content' => null, 'message' => 'Error reading wiki', 'success' => false]; - } - - $item = self::load_page($arr); - - if ($item) { - $content = $item['body']; - - return [ - 'content' => $content, - 'mimeType' => $w['mimeType'], - 'pageMimeType' => $item['mimetype'], - 'message' => '', - 'success' => true - ]; - } - - return ['content' => null, 'message' => t('Error reading page content'), 'success' => false]; - - } - - - static public function page_history($arr) { - - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? $arr['channel_id'] : 0); - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - if (!$w['wiki']) { - return ['history' => null, 'message' => 'Error reading wiki', 'success' => false]; - } - - $items = self::load_page_history($arr); - - $history = []; - - if ($items) { - $processed = 0; - foreach ($items as $item) { - if ($processed > 1000) - break; - $processed++; - $history[] = [ - 'revision' => $item['revision'], - 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited']), - 'name' => $item['author']['xchan_name'], - 'title' => get_iconfig($item, 'nwikipage', 'commit_msg') - ]; - - } - - return ['success' => true, 'history' => $history]; - } - - return ['success' => false]; - - } - - - static public function load_page($arr) { - - $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? $arr['channel_id'] : 0); - $revision = ((array_key_exists('revision', $arr)) ? $arr['revision'] : (-1)); - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - - if (!$w['wiki']) { - return ['content' => null, 'message' => 'Error reading wiki', 'success' => false]; - } - - $ids = ''; - - $ic = q("select * from iconfig left join item on iconfig.iid = item.id where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'", - intval($channel_id), - dbesc($pageUrlName) - ); - - if ($ic) { - foreach ($ic as $c) { - if ($ids) - $ids .= ','; - $ids .= intval($c['iid']); - } - } - - $sql_extra = item_permissions_sql($channel_id, $observer_hash); - - if ($revision == (-1)) - $sql_extra .= " order by revision desc "; - elseif ($revision) - $sql_extra .= " and revision = " . intval($revision) . " "; - - $r = null; - - - if ($ids) { - $r = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s' and uid = %d and id in ( $ids ) $sql_extra limit 1", - dbesc($resource_id), - intval($channel_id) - ); - - if ($r) { - $items = fetch_post_tags($r, true); - return $items[0]; - } - } - - return null; - } - - - static public function load_page_history($arr) { - - $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? $arr['channel_id'] : 0); - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - if (!$w['wiki']) { - return ['content' => null, 'message' => 'Error reading wiki', 'success' => false]; - } - - $ids = ''; - - $ic = q("select * from iconfig left join item on iconfig.iid = item.id where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'", - intval($channel_id), - dbesc($pageUrlName) - ); - - if ($ic) { - foreach ($ic as $c) { - if ($ids) - $ids .= ','; - $ids .= intval($c['iid']); - } - } - - $sql_extra = item_permissions_sql($channel_id, $observer_hash); - - $sql_extra .= " order by revision desc "; - - $r = null; - if ($ids) { - $r = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s' and uid = %d and id in ( $ids ) and item_deleted = 0 $sql_extra", - dbesc($resource_id), - intval($channel_id) - ); - if ($r) { - xchan_query($r); - $items = fetch_post_tags($r, true); - return $items; - } - } - - return null; - } - - - static public function save_page($arr) { - $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); - $content = ((array_key_exists('content', $arr)) ? $arr['content'] : ''); - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? $arr['channel_id'] : 0); - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - - if (!$w['wiki']) { - return ['message' => t('Error reading wiki'), 'success' => false]; - } - - - // fetch the most recently saved revision. - - $item = self::load_page($arr); - - if (!$item) { - return ['message' => t('Page not found'), 'success' => false]; - } - - $mimetype = $item['mimetype']; - - // change just the fields we need to change to create a revision; - - unset($item['id']); - unset($item['author']); - $item['parent'] = 0; - $item['body'] = $content; - $item['author_xchan'] = $observer_hash; - $item['revision'] = (($arr['revision']) ? intval($arr['revision']) + 1 : intval($item['revision']) + 1); - $item['edited'] = datetime_convert(); - $item['mimetype'] = $mimetype; - - if ($item['iconfig'] && is_array($item['iconfig']) && count($item['iconfig'])) { - for ($x = 0; $x < count($item['iconfig']); $x++) { - unset($item['iconfig'][$x]['id']); - unset($item['iconfig'][$x]['iid']); - } - } - - $ret = item_store($item, false, false); - - if ($ret['item_id']) - return ['message' => '', 'item_id' => $ret['item_id'], 'filename' => $pageUrlName, 'success' => true]; - else - return ['message' => t('Page update failed.'), 'success' => false]; - } - - - static public function delete_page($arr) { - - $pageUrlName = (array_key_exists('pageUrlName', $arr) ? $arr['pageUrlName'] : ''); - $resource_id = (array_key_exists('resource_id', $arr) ? $arr['resource_id'] : ''); - $observer_hash = (array_key_exists('observer_hash', $arr) ? $arr['observer_hash'] : ''); - $channel_id = (array_key_exists('channel_id', $arr) ? $arr['channel_id'] : 0); - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - if (!$w['wiki']) { - return ['success' => false, 'message' => t('Error reading wiki')]; - } - - $ids = []; - - $ic = q("select * from iconfig left join item on iconfig.iid = item.id - where uid = %d and cat = 'nwikipage' and k = 'pagetitle' and v = '%s'", - intval($channel_id), - dbesc($pageUrlName) - ); - - if ($ic) { - foreach ($ic as $c) { - $ids[] = intval($c['iid']); - } - } - - if ($ids) { - drop_items($ids, true, DROPITEM_PHASE1); - return ['success' => true]; - } - - return ['success' => false, 'message' => t('Nothing deleted')]; - } - - - static public function revert_page($arr) { - - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $commitHash = ((array_key_exists('commitHash', $arr)) ? $arr['commitHash'] : null); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? $arr['channel_id'] : 0); - - if (!$commitHash) { - return ['message' => 'No commit was provided', 'success' => false]; - } - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - if (!$w['wiki']) { - return ['message' => 'Error reading wiki', 'success' => false]; - } - - $x = $arr; - - if (intval($commitHash) > 0) { - unset($x['commitHash']); - $x['revision'] = intval($commitHash) - 1; - $loaded = self::load_page($x); - - if ($loaded) { - $content = $loaded['body']; - return ['content' => $content, 'success' => true]; - } - return ['success' => false]; - } - } - - - static public function compare_page($arr) { - - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - $compareCommit = ((array_key_exists('compareCommit', $arr)) ? $arr['compareCommit'] : 0); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? $arr['channel_id'] : 0); - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - - if (!$w['wiki']) { - return ['message' => t('Error reading wiki'), 'success' => false]; - } - - $x = $arr; - $x['revision'] = (-1); - - $currpage = self::load_page($x); - if ($currpage) - $currentContent = $currpage['body']; - - $x['revision'] = $compareCommit; - $comppage = self::load_page($x); - if ($comppage) - $compareContent = $comppage['body']; - - if ($currpage && $comppage) { - require_once('library/class.Diff.php'); - $diff = \Diff::toTable(\Diff::compare($currentContent, $compareContent)); - - return ['success' => true, 'diff' => $diff]; - } - return ['success' => false, 'message' => t('Compare: object not found.')]; - - } - - - static public function commit($arr) { - - $commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : t('Page updated')); - $observer_hash = ((array_key_exists('observer_hash', $arr)) ? $arr['observer_hash'] : ''); - $channel_id = ((array_key_exists('channel_id', $arr)) ? $arr['channel_id'] : 0); - - if (array_key_exists('resource_id', $arr)) { - $resource_id = $arr['resource_id']; - } - else { - return ['message' => t('Wiki resource_id required for git commit'), 'success' => false]; - } - - $w = NativeWiki::get_wiki($channel_id, $observer_hash, $resource_id); - if (!$w['wiki']) { - return ['message' => t('Error reading wiki'), 'success' => false]; - } - - - $page = self::load_page($arr); - - if ($page) { - set_iconfig($page['id'], 'nwikipage', 'commit_msg', escape_tags($commit_msg), true); - return ['success' => true, 'item_id' => $page['id'], 'page' => $page]; - } - - return ['success' => false, 'message' => t('Page not found.')]; - - } - - static public function convert_links($s, $wikiURL) { - - if (strpos($s, '[[') !== false) { - preg_match_all("/\[\[(.*?)\]\]/", $s, $match); - $pages = $pageURLs = []; - foreach ($match[1] as $m) { - // TODO: Why do we need to double urlencode for this to work? - //$pageURLs[] = urlencode(urlencode(escape_tags($m))); - $titleUri = explode('|', $m); - $page = $titleUri[0] ?? ''; - $title = $titleUri[1] ?? $page; - $pageURLs[] = NativeWiki::name_encode(escape_tags($page)); - $pages[] = $title; - } - $idx = 0; - while (strpos($s, '[[') !== false) { - $replace = '<a href="' . $wikiURL . '/' . $pageURLs[$idx] . '">' . $pages[$idx] . '</a>'; - $s = preg_replace("/\[\[(.*?)\]\]/", $replace, $s, 1); - $idx++; - } - } - return $s; - } - - static public function render_page_history($arr) { - - $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - - $pageHistory = self::page_history([ - 'channel_id' => App::$profile_uid, - 'observer_hash' => get_observer_hash(), - 'resource_id' => $resource_id, - 'pageUrlName' => $pageUrlName - ]); - - return replace_macros(get_markup_template('nwiki_page_history.tpl'), [ - '$pageHistory' => $pageHistory['history'], - '$permsWrite' => $arr['permsWrite'], - '$name_lbl' => t('Name'), - '$msg_label' => t('Message', 'wiki_history'), - '$date_lbl' => t('Date'), - '$revert_btn' => t('Revert'), - '$compare_btn' => t('Compare') - ]); - - } - - - /** - * Replace the instances of the string [toc] with a list element that will be populated by - * a table of contents by the JavaScript library - * @param string $s - * @return string - */ - static public function generate_toc($s) { - if (strpos($s, '[toc]') !== false) { - //$toc_md = wiki_toc($s); // Generate Markdown-formatted list prior to HTML render - $toc_md = '<ul id="wiki-toc"></ul>'; // use the available jQuery plugin http://ndabas.github.io/toc/ - $s = preg_replace("/\[toc\]/", $toc_md, $s, -1); - } - return $s; - } - - - /** - * Converts a select set of bbcode tags. Much of the code is copied from include/bbcode.php - * @param string $s - * @return string - */ - static public function bbcode($s) { - - $s = str_replace(['[baseurl]', '[sitename]'], [z_root(), get_config('system', 'sitename')], $s); - - $s = preg_replace_callback("/\[observer\.language\=(.*?)\](.*?)\[\/observer\]/ism", 'oblanguage_callback', $s); - - $s = preg_replace_callback("/\[observer\.language\!\=(.*?)\](.*?)\[\/observer\]/ism", 'oblanguage_necallback', $s); - - - $observer = App::get_observer(); - if ($observer) { - $s1 = '<span class="bb_observer" title="' . t('Different viewers will see this text differently') . '">'; - $s2 = '</span>'; - $obsBaseURL = $observer['xchan_connurl']; - $obsBaseURL = preg_replace("/\/poco\/.*$/", '', $obsBaseURL); - $s = str_replace('[observer.baseurl]', $obsBaseURL, $s); - $s = str_replace('[observer.url]', $observer['xchan_url'], $s); - $s = str_replace('[observer.name]', $s1 . $observer['xchan_name'] . $s2, $s); - $s = str_replace('[observer.address]', $s1 . $observer['xchan_addr'] . $s2, $s); - $s = str_replace('[observer.webname]', substr($observer['xchan_addr'], 0, strpos($observer['xchan_addr'], '@')), $s); - $s = str_replace('[observer.photo]', '', $s); - } - else { - $s = str_replace('[observer.baseurl]', '', $s); - $s = str_replace('[observer.url]', '', $s); - $s = str_replace('[observer.name]', '', $s); - $s = str_replace('[observer.address]', '', $s); - $s = str_replace('[observer.webname]', '', $s); - $s = str_replace('[observer.photo]', '', $s); - } - - return $s; - } - - - static public function get_file_ext($arr) { - - if ($arr['mimetype'] === 'text/bbcode') - return '.bb'; - elseif ($arr['mimetype'] === 'text/markdown') - return '.md'; - elseif ($arr['mimetype'] === 'text/plain') - return '.txt'; - - } - - // This function is derived from - // http://stackoverflow.com/questions/32068537/generate-table-of-contents-from-markdown-in-php - static public function toc($content) { - // ensure using only "\n" as line-break - $source = str_replace(["\r\n", "\r"], "\n", $content); - - // look for markdown TOC items - preg_match_all( - '/^(?:=|-|#).*$/m', - $source, - $matches, - PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE - ); - - // preprocess: iterate matched lines to create an array of items - // where each item is an array(level, text) - $file_size = strlen($source); - foreach ($matches[0] as $item) { - $found_mark = substr($item[0], 0, 1); - if ($found_mark == '#') { - // text is the found item - $item_text = $item[0]; - $item_level = strrpos($item_text, '#') + 1; - $item_text = substr($item_text, $item_level); - } - else { - // text is the previous line (empty if <hr>) - $item_offset = $item[1]; - $prev_line_offset = strrpos($source, "\n", -($file_size - $item_offset + 2)); - $item_text = - substr($source, $prev_line_offset, $item_offset - $prev_line_offset - 1); - $item_text = trim($item_text); - $item_level = $found_mark == '=' ? 1 : 2; - } - if (!trim($item_text) or strpos($item_text, '|') !== FALSE) { - // item is an horizontal separator or a table header, don't mind - continue; - } - $raw_toc[] = ['level' => $item_level, 'text' => trim($item_text)]; - } - $o = ''; - foreach ($raw_toc as $t) { - $level = intval($t['level']); - $text = $t['text']; - switch ($level) { - case 1: - $li = '* '; - break; - case 2: - $li = ' * '; - break; - case 3: - $li = ' * '; - break; - case 4: - $li = ' * '; - break; - default: - $li = '* '; - break; - } - $o .= $li . $text . "\n"; - } - return $o; - } - -} diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 8d20935a1..a02c1415e 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -162,24 +162,11 @@ class ThreadItem { $mode = $conv->get_mode(); - switch($item['item_type']) { - case ITEM_TYPE_CARD: - $edlink = 'card_edit'; - break; - case ITEM_TYPE_ARTICLE: - $edlink = 'article_edit'; - break; - default: - $edlink = 'editpost'; - break; - } - if(local_channel() && $observer['xchan_hash'] === $item['author_xchan']) - $edpost = array(z_root() . '/' . $edlink . '/' . $item['id'], t('Edit')); + $edpost = array(z_root() . '/editpost/' . $item['id'], t('Edit')); else $edpost = false; - if($observer && $observer['xchan_hash'] && ($observer['xchan_hash'] == $this->get_data_value('author_xchan') || $observer['xchan_hash'] == $this->get_data_value('owner_xchan') @@ -297,7 +284,7 @@ class ThreadItem { if($this->is_toplevel()) { // FIXME check this permission - if(($conv->get_profile_owner() == local_channel()) && (! array_key_exists('real_uid',$item))) { + if($conv->get_profile_owner() === local_channel() || intval($item['item_private']) === 0) { $star = array( 'toggle' => t("Toggle Star Status"), diff --git a/Zotlabs/Lib/ThreadStream.php b/Zotlabs/Lib/ThreadStream.php index 7fe8fcc2e..2ad24a690 100644 --- a/Zotlabs/Lib/ThreadStream.php +++ b/Zotlabs/Lib/ThreadStream.php @@ -69,12 +69,12 @@ class ThreadStream { case 'cards': $this->profile_owner = \App::$profile['profile_uid']; $this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments'); - $this->reload = $_SESSION['return_url']; + //$this->reload = $_SESSION['return_url']; break; case 'articles': $this->profile_owner = \App::$profile['profile_uid']; $this->writable = perm_is_allowed($this->profile_owner,$ob_hash,'post_comments'); - $this->reload = $_SESSION['return_url']; + //$this->reload = $_SESSION['return_url']; break; case 'display': // in this mode we set profile_owner after initialisation (from conversation()) and then diff --git a/Zotlabs/Module/Article_edit.php b/Zotlabs/Module/Article_edit.php deleted file mode 100644 index 97c87f2ba..000000000 --- a/Zotlabs/Module/Article_edit.php +++ /dev/null @@ -1,138 +0,0 @@ -<?php -namespace Zotlabs\Module; - -require_once('include/channel.php'); -require_once('include/acl_selectors.php'); -require_once('include/conversation.php'); - -class Article_edit extends \Zotlabs\Web\Controller { - - - function get() { - - // Figure out which post we're editing - $post_id = ((argc() > 1) ? intval(argv(1)) : 0); - - if(! $post_id) { - notice( t('Item not found') . EOL); - return; - } - - $itm = q("SELECT * FROM item WHERE id = %d and item_type = %d LIMIT 1", - intval($post_id), - intval(ITEM_TYPE_ARTICLE) - ); - if($itm) { - $item_id = q("select * from iconfig where cat = 'system' and k = 'ARTICLE' and iid = %d limit 1", - intval($itm[0]['id']) - ); - if($item_id) - $card_title = $item_id[0]['v']; - } - else { - notice( t('Item not found') . EOL); - return; - } - - $owner = $itm[0]['uid']; - $uid = local_channel(); - - $observer = \App::get_observer(); - - $channel = channelx_by_n($owner); - if(! $channel) { - notice( t('Channel not found.') . EOL); - return; - } - - $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); - - if(! perm_is_allowed($owner,$ob_hash,'write_pages')) { - notice( t('Permission denied.') . EOL); - return; - } - - $is_owner = (($uid && $uid == $owner) ? true : false); - - $o = ''; - - - - $category = ''; - $catsenabled = ((feature_enabled($owner,'categories')) ? 'categories' : ''); - - if ($catsenabled){ - $itm = fetch_post_tags($itm); - - $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY); - - foreach ($cats as $cat) { - if (strlen($category)) - $category .= ', '; - $category .= $cat['term']; - } - } - - if($itm[0]['attach']) { - $j = json_decode($itm[0]['attach'],true); - if($j) { - foreach($j as $jj) { - $itm[0]['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n"; - } - } - } - - - $mimetype = $itm[0]['mimetype']; - - $content = $itm[0]['body']; - - $rp = 'articles/' . $channel['channel_address']; - - $x = array( - 'nickname' => $channel['channel_address'], - 'bbco_autocomplete'=> 'bbcode', - 'return_path' => $rp, - 'webpage' => ITEM_TYPE_ARTICLE, - 'button' => t('Edit'), - 'writefiles' => perm_is_allowed($owner, get_observer_hash(), 'write_pages'), - 'weblink' => t('Insert web link'), - 'hide_voting' => false, - 'hide_future' => false, - 'hide_location' => false, - 'hide_expire' => false, - 'showacl' => true, - 'acl' => populate_acl($itm[0],false,\Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_pages')), - 'permissions' => $itm[0], - 'lockstate' => (($itm[0]['allow_cid'] || $itm[0]['allow_gid'] || $itm[0]['deny_cid'] || $itm[0]['deny_gid']) ? 'lock' : 'unlock'), - 'ptyp' => $itm[0]['type'], - 'mimeselect' => false, - 'mimetype' => $itm[0]['mimetype'], - 'body' => undo_post_tagging($content), - 'post_id' => $post_id, - 'visitor' => true, - 'title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'), - 'summary' => htmlspecialchars($itm[0]['summary'],ENT_COMPAT,'UTF-8'), - 'placeholdertitle' => t('Title (optional)'), - 'pagetitle' => $card_title, - 'profile_uid' => (intval($channel['channel_id'])), - 'catsenabled' => $catsenabled, - 'category' => $category, - 'bbcode' => (($mimetype == 'text/bbcode') ? true : false) - ); - - $editor = status_editor($a, $x, false, 'Article_edit'); - - $o .= replace_macros(get_markup_template('edpost_head.tpl'), array( - '$title' => t('Edit Article'), - '$delete' => ((($itm[0]['author_xchan'] === $ob_hash) || ($itm[0]['owner_xchan'] === $ob_hash)) ? t('Delete') : false), - '$id' => $itm[0]['id'], - '$cancel' => t('Cancel'), - '$editor' => $editor - )); - - return $o; - - } - -} diff --git a/Zotlabs/Module/Articles.php b/Zotlabs/Module/Articles.php deleted file mode 100644 index 0db098a31..000000000 --- a/Zotlabs/Module/Articles.php +++ /dev/null @@ -1,232 +0,0 @@ -<?php -namespace Zotlabs\Module; - -use App; -use Zotlabs\Lib\Apps; -use Zotlabs\Web\Controller; -use Zotlabs\Lib\PermissionDescription; - -require_once('include/channel.php'); -require_once('include/conversation.php'); -require_once('include/acl_selectors.php'); -require_once('include/opengraph.php'); - - -class Articles extends Controller { - - function init() { - - if(argc() > 1) - $which = argv(1); - - if(! $which) { - if(local_channel()) { - $channel = App::get_channel(); - if($channel && $channel['channel_address']) - $which = $channel['channel_address']; - } else { - return; - } - } - - profile_load($which); - - } - - function get($update = 0, $load = false) { - - if(observer_prohibited(true)) { - return login(); - } - - if(! App::$profile) { - notice( t('Requested profile is not available.') . EOL ); - App::$error = 404; - return; - } - - if(! Apps::system_app_installed(App::$profile_uid, 'Articles')) { - //Do not display any associated widgets at this point - App::$pdl = ''; - $papp = Apps::get_papp('Articles'); - return Apps::app_render($papp, 'module'); - } - - nav_set_selected('Articles'); - - head_add_link([ - 'rel' => 'alternate', - 'type' => 'application/json+oembed', - 'href' => z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . App::$query_string), - 'title' => 'oembed' - ]); - - - $category = (($_REQUEST['cat']) ? escape_tags(trim($_REQUEST['cat'])) : ''); - - if($category) { - $sql_extra2 .= protect_sprintf(term_item_parent_query(App::$profile['profile_uid'],'item', $category, TERM_CATEGORY)); - } - - $datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : ''); - $datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : ''); - - $which = argv(1); - - $selected_card = ((argc() > 2) ? argv(2) : ''); - - $_SESSION['return_url'] = App::$query_string; - - $uid = local_channel(); - $owner = App::$profile_uid; - $observer = App::get_observer(); - - $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); - - if(! perm_is_allowed($owner,$ob_hash,'view_pages')) { - notice( t('Permission denied.') . EOL); - return; - } - - $is_owner = ($uid && $uid == $owner); - - $channel = channelx_by_n($owner); - - if($channel) { - $channel_acl = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); - } - else { - $channel_acl = [ 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ]; - } - - - - if(perm_is_allowed($owner,$ob_hash,'write_pages')) { - - $x = [ - 'webpage' => ITEM_TYPE_ARTICLE, - 'is_owner' => true, - 'content_label' => t('Add Article'), - 'button' => t('Save'), - 'nickname' => $channel['channel_address'], - 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] - || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), - 'acl' => (($is_owner) ? populate_acl($channel_acl, false, - PermissionDescription::fromGlobalPermission('view_pages')) : ''), - 'permissions' => $channel_acl, - 'showacl' => (($is_owner) ? true : false), - 'visitor' => true, - 'hide_location' => false, - 'hide_voting' => false, - 'profile_uid' => intval($owner), - 'mimetype' => 'text/bbcode', - 'mimeselect' => false, - 'layoutselect' => false, - 'expanded' => false, - 'novoting' => false, - 'catsenabled' => feature_enabled($owner,'categories'), - 'bbco_autocomplete' => 'bbcode', - 'bbcode' => true - ]; - - if($_REQUEST['title']) - $x['title'] = $_REQUEST['title']; - if($_REQUEST['body']) - $x['body'] = $_REQUEST['body']; - $editor = status_editor($a,$x,false,'Articles'); - - } - else { - $editor = ''; - } - - $itemspage = get_pconfig(local_channel(),'system','itemspage'); - App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 10)); - $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); - - - $sql_extra = item_permissions_sql($owner); - $sql_item = ''; - - if($selected_card) { - $r = q("select * from iconfig where iconfig.cat = 'system' and iconfig.k = 'ARTICLE' and iconfig.v = '%s' limit 1", - dbesc($selected_card) - ); - if($r) { - $sql_item = "and item.id = " . intval($r[0]['iid']) . " "; - } - } - if($datequery) { - $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); - $order = 'post'; - } - if($datequery2) { - $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); - } - - if($datequery || $datequery2) { - $sql_extra2 .= " and item.item_thread_top != 0 "; - } - - $r = q("select * from item - where item.uid = %d and item_type = %d - $sql_extra $sql_extra2 $sql_item order by item.created desc $pager_sql", - intval($owner), - intval(ITEM_TYPE_ARTICLE) - ); - - $item_normal = " and item.item_hidden = 0 and item.item_type in (0,7) and item.item_deleted = 0 - and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0 - and item.item_blocked = 0 "; - - if($r) { - - $pager_total = count($r); - - $parents_str = ids_to_querystr($r,'id'); - - $r = q("SELECT item.*, item.id AS item_id - FROM item - WHERE item.uid = %d $item_normal - AND item.parent IN ( %s ) - $sql_extra $sql_extra2 ", - intval(App::$profile['profile_uid']), - dbesc($parents_str) - ); - if($r) { - xchan_query($r); - $items = fetch_post_tags($r, true); - $items = conv_sort($items,'updated'); - } - else - $items = []; - } - - // Add Opengraph markup - opengraph_add_meta((! empty($items) ? $r[0] : []), $channel); - - $mode = 'articles'; - - if(get_pconfig(local_channel(),'system','articles_list_mode') && (! $selected_card)) - $page_mode = 'pager_list'; - else - $page_mode = 'traditional'; - - $content = conversation($items,$mode,false,$page_mode); - - $o = replace_macros(get_markup_template('cards.tpl'), [ - '$title' => t('Articles'), - '$editor' => $editor, - '$content' => $content, - '$pager' => alt_pager($pager_total) - ]); - - return $o; - } - -} diff --git a/Zotlabs/Module/Card_edit.php b/Zotlabs/Module/Card_edit.php deleted file mode 100644 index c57a0f043..000000000 --- a/Zotlabs/Module/Card_edit.php +++ /dev/null @@ -1,140 +0,0 @@ -<?php -namespace Zotlabs\Module; - -require_once('include/channel.php'); -require_once('include/acl_selectors.php'); -require_once('include/conversation.php'); - -class Card_edit extends \Zotlabs\Web\Controller { - - - function get() { - - // Figure out which post we're editing - $post_id = ((argc() > 1) ? intval(argv(1)) : 0); - - if(! $post_id) { - notice( t('Item not found') . EOL); - return; - } - - $itm = q("SELECT * FROM item WHERE id = %d and item_type = %d LIMIT 1", - intval($post_id), - intval(ITEM_TYPE_CARD) - ); - if($itm) { - $item_id = q("select * from iconfig where cat = 'system' and k = 'CARD' and iid = %d limit 1", - intval($itm[0]['id']) - ); - if($item_id) - $card_title = $item_id[0]['v']; - } - else { - notice( t('Item not found') . EOL); - return; - } - - $owner = $itm[0]['uid']; - $uid = local_channel(); - - $observer = \App::get_observer(); - - $channel = channelx_by_n($owner); - if(! $channel) { - notice( t('Channel not found.') . EOL); - return; - } - - $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); - - if(! perm_is_allowed($owner,$ob_hash,'write_pages')) { - notice( t('Permission denied.') . EOL); - return; - } - - $is_owner = (($uid && $uid == $owner) ? true : false); - - $o = ''; - - - - $category = ''; - $catsenabled = ((feature_enabled($owner,'categories')) ? 'categories' : ''); - - if ($catsenabled){ - $itm = fetch_post_tags($itm); - - $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY); - - foreach ($cats as $cat) { - if (strlen($category)) - $category .= ', '; - $category .= $cat['term']; - } - } - - if($itm[0]['attach']) { - $j = json_decode($itm[0]['attach'],true); - if($j) { - foreach($j as $jj) { - $itm[0]['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n"; - } - } - } - - - $mimetype = $itm[0]['mimetype']; - - $content = $itm[0]['body']; - - - - $rp = 'cards/' . $channel['channel_address']; - - $x = array( - 'nickname' => $channel['channel_address'], - 'bbco_autocomplete'=> 'bbcode', - 'return_path' => $rp, - 'webpage' => ITEM_TYPE_CARD, - 'button' => t('Edit'), - 'writefiles' => perm_is_allowed($owner, get_observer_hash(), 'write_pages'), - 'weblink' => t('Insert web link'), - 'hide_voting' => false, - 'hide_future' => false, - 'hide_location' => false, - 'hide_expire' => false, - 'showacl' => true, - 'acl' => populate_acl($itm[0],false,\Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_pages')), - 'permissions' => $itm[0], - 'lockstate' => (($itm[0]['allow_cid'] || $itm[0]['allow_gid'] || $itm[0]['deny_cid'] || $itm[0]['deny_gid']) ? 'lock' : 'unlock'), - 'ptyp' => $itm[0]['type'], - 'mimeselect' => false, - 'mimetype' => $itm[0]['mimetype'], - 'body' => undo_post_tagging($content), - 'post_id' => $post_id, - 'visitor' => true, - 'title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'), - 'summary' => htmlspecialchars($itm[0]['summary'],ENT_COMPAT,'UTF-8'), - 'placeholdertitle' => t('Title (optional)'), - 'pagetitle' => $card_title, - 'profile_uid' => (intval($channel['channel_id'])), - 'catsenabled' => $catsenabled, - 'category' => $category, - 'bbcode' => (($mimetype == 'text/bbcode') ? true : false) - ); - - $editor = status_editor($a, $x, false, 'Card_edit'); - - $o .= replace_macros(get_markup_template('edpost_head.tpl'), array( - '$title' => t('Edit Card'), - '$delete' => ((($itm[0]['author_xchan'] === $ob_hash) || ($itm[0]['owner_xchan'] === $ob_hash)) ? t('Delete') : false), - '$id' => $itm[0]['id'], - '$cancel' => t('Cancel'), - '$editor' => $editor - )); - - return $o; - - } - -} diff --git a/Zotlabs/Module/Cards.php b/Zotlabs/Module/Cards.php deleted file mode 100644 index b71af6044..000000000 --- a/Zotlabs/Module/Cards.php +++ /dev/null @@ -1,214 +0,0 @@ -<?php -namespace Zotlabs\Module; - -use App; -use Zotlabs\Lib\Apps; -use Zotlabs\Web\Controller; -use Zotlabs\Lib\PermissionDescription; - -require_once('include/channel.php'); -require_once('include/conversation.php'); -require_once('include/acl_selectors.php'); - -/** - * @brief Provides the Cards module. - * - */ -class Cards extends Controller { - - public function init() { - - if(argc() > 1) - $which = argv(1); - else - return; - - profile_load($which); - } - - /** - * {@inheritDoc} - * @see \\Zotlabs\\Web\\Controller::get() - * - * @return string Parsed HTML from template 'cards.tpl' - */ - public function get($update = 0, $load = false) { - - if(observer_prohibited(true)) { - return login(); - } - - if(! App::$profile) { - notice( t('Requested profile is not available.') . EOL ); - App::$error = 404; - return; - } - - if(! Apps::system_app_installed(App::$profile_uid, 'Cards')) { - //Do not display any associated widgets at this point - App::$pdl = ''; - $papp = Apps::get_papp('Cards'); - return Apps::app_render($papp, 'module'); - } - - nav_set_selected('Cards'); - - head_add_link([ - 'rel' => 'alternate', - 'type' => 'application/json+oembed', - 'href' => z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . App::$query_string), - 'title' => 'oembed' - ]); - - - $category = (($_REQUEST['cat']) ? escape_tags(trim($_REQUEST['cat'])) : ''); - - if($category) { - $sql_extra2 .= protect_sprintf(term_item_parent_query(App::$profile['profile_uid'], 'item', $category, TERM_CATEGORY)); - } - - - $which = argv(1); - - $selected_card = ((argc() > 2) ? argv(2) : ''); - - $_SESSION['return_url'] = App::$query_string; - - $uid = local_channel(); - $owner = App::$profile_uid; - $observer = App::get_observer(); - - $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); - - if(! perm_is_allowed($owner, $ob_hash, 'view_pages')) { - notice( t('Permission denied.') . EOL); - return; - } - - $is_owner = ($uid && $uid == $owner); - - $channel = channelx_by_n($owner); - - if($channel) { - $channel_acl = [ - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ]; - } - else { - $channel_acl = [ 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ]; - } - - - if(perm_is_allowed($owner, $ob_hash, 'write_pages')) { - - $x = [ - 'webpage' => ITEM_TYPE_CARD, - 'is_owner' => true, - 'content_label' => t('Add Card'), - 'button' => t('Save'), - 'nickname' => $channel['channel_address'], - 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] - || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), - 'acl' => (($is_owner) ? populate_acl($channel_acl, false, - PermissionDescription::fromGlobalPermission('view_pages')) : ''), - 'permissions' => $channel_acl, - 'showacl' => (($is_owner) ? true : false), - 'visitor' => true, - 'hide_location' => false, - 'hide_voting' => false, - 'profile_uid' => intval($owner), - 'mimetype' => 'text/bbcode', - 'mimeselect' => false, - 'layoutselect' => false, - 'expanded' => false, - 'novoting' => false, - 'catsenabled' => feature_enabled($owner, 'categories'), - 'bbco_autocomplete' => 'bbcode', - 'bbcode' => true - ]; - - if($_REQUEST['title']) - $x['title'] = $_REQUEST['title']; - if($_REQUEST['body']) - $x['body'] = $_REQUEST['body']; - - $editor = status_editor($a, $x, false, 'Cards'); - } - else { - $editor = ''; - } - - - $itemspage = get_pconfig(local_channel(),'system','itemspage'); - App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 10)); - $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); - - - $sql_extra = item_permissions_sql($owner); - $sql_item = ''; - - if($selected_card) { - $r = q("select * from iconfig where iconfig.cat = 'system' and iconfig.k = 'CARD' and iconfig.v = '%s' limit 1", - dbesc($selected_card) - ); - if($r) { - $sql_item = "and item.id = " . intval($r[0]['iid']) . " "; - } - } - - $r = q("select * from item - where uid = %d and item_type = %d - $sql_extra $sql_item order by item.created desc $pager_sql", - intval($owner), - intval(ITEM_TYPE_CARD) - ); - - $item_normal = " and item.item_hidden = 0 and item.item_type in (0,6) and item.item_deleted = 0 - and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0 - and item.item_blocked = 0 "; - - $items_result = []; - if($r) { - - $pager_total = count($r); - - $parents_str = ids_to_querystr($r, 'id'); - - $items = q("SELECT item.*, item.id AS item_id - FROM item - WHERE item.uid = %d $item_normal - AND item.parent IN ( %s ) - $sql_extra $sql_extra2 ", - intval(App::$profile['profile_uid']), - dbesc($parents_str) - ); - if($items) { - xchan_query($items); - $items = fetch_post_tags($items, true); - $items_result = conv_sort($items, 'updated'); - } - } - - $mode = 'cards'; - - if(get_pconfig(local_channel(),'system','articles_list_mode') && (! $selected_card)) - $page_mode = 'pager_list'; - else - $page_mode = 'traditional'; - - $content = conversation($items_result, $mode, false, $page_mode); - - $o = replace_macros(get_markup_template('cards.tpl'), [ - '$title' => t('Cards'), - '$editor' => $editor, - '$content' => $content, - '$pager' => alt_pager($pager_total) - ]); - - return $o; - } - -} diff --git a/Zotlabs/Module/Display.php b/Zotlabs/Module/Display.php index 02a79f854..0d29c3451 100644 --- a/Zotlabs/Module/Display.php +++ b/Zotlabs/Module/Display.php @@ -143,48 +143,8 @@ class Display extends \Zotlabs\Web\Controller { return ''; } } - if($target_item['item_type'] == ITEM_TYPE_ARTICLE) { - $x = q("select * from channel where channel_id = %d limit 1", - intval($target_item['uid']) - ); - $y = q("select * from iconfig left join item on iconfig.iid = item.id - where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'ARTICLE' and item.id = %d limit 1", - intval($target_item['uid']), - intval($target_item['parent']) - ); - if($x && $y) { - goaway(z_root() . '/articles/' . $x[0]['channel_address'] . '/' . $y[0]['v']); - } - else { - notice( t('Page not found.') . EOL); - return ''; - } - } - if($target_item['item_type'] == ITEM_TYPE_CARD) { - $x = q("select * from channel where channel_id = %d limit 1", - intval($target_item['uid']) - ); - - $y = q("select * from iconfig left join item on iconfig.iid = item.id - where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'CARD' and item.id = %d limit 1", - intval($target_item['uid']), - intval($target_item['parent']) - ); - - if($x && $y) { - goaway(z_root() . '/cards/' . $x[0]['channel_address'] . '/' . $y[0]['v']); - } - else { - notice( t('Page not found.') . EOL); - return ''; - } - } - if ($target_item['item_type'] == ITEM_TYPE_CUSTOM) { - call_hooks('item_custom_display',$target_item); - notice( t('Page not found.') . EOL); - return ''; - } + call_hooks('item_custom_display', $target_item); $simple_update = ''; if($update && $_SESSION['loadtime']) diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 574a90c1a..e1ba2b2f0 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -743,6 +743,8 @@ class Item extends Controller { $webpage = $parent_item['item_type']; } + + if ((!$allow_empty) && (!strlen($body))) { if ($preview) killme(); @@ -807,7 +809,6 @@ class Item extends Controller { $post_tags = []; - if ($mimetype === 'text/bbcode') { require_once('include/text.php'); @@ -919,15 +920,7 @@ class Item extends Controller { $cats = explode(',', $categories); foreach ($cats as $cat) { - if ($webpage == ITEM_TYPE_CARD) { - $catlink = z_root() . '/cards/' . $channel['channel_address'] . '?f=&cat=' . urlencode(trim($cat)); - } - elseif ($webpage == ITEM_TYPE_ARTICLE) { - $catlink = z_root() . '/articles/' . $channel['channel_address'] . '?f=&cat=' . urlencode(trim($cat)); - } - else { - $catlink = $owner_xchan['xchan_url'] . '?f=&cat=' . urlencode(trim($cat)); - } + $catlink = $owner_xchan['xchan_url'] . '?f=&cat=' . urlencode(trim($cat)); $post_tags[] = [ 'uid' => $profile_uid, @@ -1040,7 +1033,7 @@ class Item extends Controller { $parent_mid = $parent_item['mid']; - // Fallback so that we alway have a thr_parent + // Fallback so that we always have a thr_parent if (!$thr_parent) $thr_parent = $mid; @@ -1048,36 +1041,7 @@ class Item extends Controller { $item_thread_top = ((!$parent) ? 1 : 0); - - // fix permalinks for cards - - if ($webpage == ITEM_TYPE_CARD) { - $plink = z_root() . '/cards/' . $channel['channel_address'] . '/' . (($pagetitle) ? $pagetitle : $uuid); - } - if (($parent_item) && ($parent_item['item_type'] == ITEM_TYPE_CARD)) { - $r = q("select v from iconfig where iconfig.cat = 'system' and iconfig.k = 'CARD' and iconfig.iid = %d limit 1", - intval($parent_item['id']) - ); - if ($r) { - $plink = z_root() . '/cards/' . $channel['channel_address'] . '/' . $r[0]['v']; - } - } - - if ($webpage == ITEM_TYPE_ARTICLE) { - $plink = z_root() . '/articles/' . $channel['channel_address'] . '/' . (($pagetitle) ? $pagetitle : $uuid); - } - if (($parent_item) && ($parent_item['item_type'] == ITEM_TYPE_ARTICLE)) { - $r = q("select v from iconfig where iconfig.cat = 'system' and iconfig.k = 'ARTICLE' and iconfig.iid = %d limit 1", - intval($parent_item['id']) - ); - if ($r) { - $plink = z_root() . '/articles/' . $channel['channel_address'] . '/' . $r[0]['v']; - } - } - if ((!$plink) && ($item_thread_top)) { - // $plink = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . gen_link_id($mid); - // $plink = substr($plink,0,190); $plink = $mid; } diff --git a/Zotlabs/Module/Search.php b/Zotlabs/Module/Search.php index fdc251b07..efea7bbdd 100644 --- a/Zotlabs/Module/Search.php +++ b/Zotlabs/Module/Search.php @@ -177,49 +177,46 @@ class Search extends Controller { } - $item_normal = item_normal_search(); - $pub_sql = public_permissions_sql($observer_hash); - - require_once('include/channel.php'); - - $sys = get_sys_channel(); - if (($update) && ($load)) { $itemspage = get_pconfig(local_channel(), 'system', 'itemspage'); App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 10)); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); - // in case somebody turned off public access to sys channel content with permissions + $item_normal = item_normal_search(); + $pub_sql = item_permissions_sql(0, $observer_hash); - if (!perm_is_allowed($sys['channel_id'], $observer_hash, 'view_stream')) - $sys['xchan_hash'] .= 'disabled'; + $sys = get_sys_channel(); + + // in case somebody turned off public access to sys channel content using permissions + // make that content unsearchable by ensuring the owner uid can't match + $sys_id = perm_is_allowed($sys['channel_id'], $observer_hash, 'view_stream') ? $sys['channel_id'] : 0; if ($load) { $r = null; if (local_channel()) { - $r = q("SELECT mid, MAX(id) as item_id from item - WHERE ((( item.allow_cid = '' AND item.allow_gid = '' AND item.deny_cid = '' AND item.deny_gid = '' AND item_private = 0 ) - OR ( item.uid = %d )) OR item.owner_xchan = '%s' ) + $r = q("SELECT mid, MAX(id) AS item_id FROM item + WHERE (( item.allow_cid = '' AND item.allow_gid = '' AND item.deny_cid = '' AND item.deny_gid = '' AND item.item_private = 0 ) + OR ( item.uid = %d )) $item_normal $sql_extra - group by mid, created order by created desc $pager_sql ", - intval(local_channel()), - dbesc($sys['xchan_hash']) + GROUP BY mid, created ORDER BY created DESC $pager_sql ", + intval(local_channel()) ); } - if ($r === null) { - $r = q("SELECT mid, MAX(id) as item_id from item - WHERE (((( item.allow_cid = '' AND item.allow_gid = '' AND item.deny_cid = '' - AND item.deny_gid = '' AND item_private = 0 ) - and owner_xchan in ( " . stream_perms_xchans(($observer) ? (PERMS_NETWORK | PERMS_PUBLIC) : PERMS_PUBLIC) . " )) - $pub_sql ) OR owner_xchan = '%s') + + if (!$r) { + $r = q("SELECT mid, MAX(id) AS item_id FROM item + WHERE (((( item.allow_cid = '' AND item.allow_gid = '' AND item.deny_cid = '' AND item.deny_gid = '' AND item.item_private = 0 ) + AND item.uid IN ( " . stream_perms_api_uids(($observer_hash) ? (PERMS_NETWORK | PERMS_PUBLIC) : PERMS_PUBLIC) . " )) + $pub_sql ) OR item.uid = %d) $item_normal $sql_extra - group by mid, created order by created desc $pager_sql", - dbesc($sys['xchan_hash']) + GROUP BY mid, created ORDER BY created DESC $pager_sql", + intval($sys_id) ); } + if ($r) { $str = ids_to_querystr($r, 'item_id'); $r = dbq("select *, id as item_id from item where id in ( " . $str . ") order by created desc"); @@ -232,13 +229,12 @@ class Search extends Controller { } + $items = []; + if ($r) { xchan_query($r); $items = fetch_post_tags($r, true); } - else { - $items = []; - } if ($format === 'json') { $result = []; diff --git a/Zotlabs/Module/Setup.php b/Zotlabs/Module/Setup.php index f068cbef8..3a188d9ce 100644 --- a/Zotlabs/Module/Setup.php +++ b/Zotlabs/Module/Setup.php @@ -387,8 +387,8 @@ class Setup extends \Zotlabs\Web\Controller { function check_php(&$phpath, &$checks) { $help = ''; - if(version_compare(PHP_VERSION, '7.1') < 0) { - $help .= t('PHP version 7.1 or greater is required.'); + if(version_compare(PHP_VERSION, '8.0') < 0) { + $help .= t('PHP version 8.0 or greater is required.'); $this->check_add($checks, t('PHP version'), false, true, $help); } diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php index 3a13b0a6f..ad9be0938 100644 --- a/Zotlabs/Module/Sse_bs.php +++ b/Zotlabs/Module/Sse_bs.php @@ -160,8 +160,12 @@ class Sse_bs extends Controller { $offset = self::$offset; $sql_extra = ''; - if(! (self::$vnotify & VNOTIFY_LIKE)) + if (!(self::$vnotify & VNOTIFY_LIKE)) { $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; + } + elseif (!feature_enabled(self::$uid, 'dislike')) { + $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; + } $sql_extra2 = ''; if(self::$xchans) @@ -236,8 +240,12 @@ class Sse_bs extends Controller { $offset = self::$offset; $sql_extra = ''; - if(! (self::$vnotify & VNOTIFY_LIKE)) + if (!(self::$vnotify & VNOTIFY_LIKE)) { $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; + } + elseif (!feature_enabled(self::$uid, 'dislike')) { + $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; + } $sql_extra2 = ''; if(self::$xchans) @@ -311,8 +319,12 @@ class Sse_bs extends Controller { $offset = self::$offset; $sql_extra = ''; - if(! (self::$vnotify & VNOTIFY_LIKE)) + if (!(self::$vnotify & VNOTIFY_LIKE)) { $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; + } + elseif (!feature_enabled(self::$uid, 'dislike')) { + $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; + } $sql_extra2 = ''; if(self::$xchans) @@ -398,8 +410,12 @@ class Sse_bs extends Controller { $sys = get_sys_channel(); $sql_extra = ''; - if(! (self::$vnotify & VNOTIFY_LIKE)) + if (!(self::$vnotify & VNOTIFY_LIKE)) { $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; + } + elseif (!feature_enabled(self::$uid, 'dislike')) { + $sql_extra = " AND verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; + } $sql_extra2 = ''; if(self::$xchans) diff --git a/Zotlabs/Module/Starred.php b/Zotlabs/Module/Starred.php index 2d7063669..a9542f590 100644 --- a/Zotlabs/Module/Starred.php +++ b/Zotlabs/Module/Starred.php @@ -1,31 +1,46 @@ <?php namespace Zotlabs\Module; +use App; use Zotlabs\Lib\Libsync; - class Starred extends \Zotlabs\Web\Controller { function init() { - + $starred = 0; - + if(! local_channel()) killme(); if(argc() > 1) $message_id = intval(argv(1)); if(! $message_id) killme(); - - $r = q("SELECT item_starred FROM item WHERE uid = %d AND id = %d LIMIT 1", + + $sys = get_sys_channel(); + + $r = q("SELECT * FROM item WHERE (uid = %d OR uid = %d) AND id = %d + and item_type in (0,6,7) and item_deleted = 0 and item_unpublished = 0 + and item_delayed = 0 and item_pending_remove = 0 and item_blocked = 0 LIMIT 1", intval(local_channel()), + intval($sys['channel_id']), intval($message_id) ); - if(! count($r)) + + if ($r) { + if ($r[0]['uid'] === $sys['channel_id']) { + $r = [ copy_of_pubitem(App::get_channel(), $r[0]['mid']) ]; + } + } + + if(!$r) killme(); - + + // reset $message_id to the fetched copy of message if applicable + $message_id = $r[0]['id']; + $item_starred = (intval($r[0]['item_starred']) ? 0 : 1); - + $r = q("UPDATE item SET item_starred = %d WHERE uid = %d and id = %d", intval($item_starred), intval(local_channel()), @@ -38,8 +53,8 @@ class Starred extends \Zotlabs\Web\Controller { if($r) { xchan_query($r); $sync_item = fetch_post_tags($r); - Libsync::build_sync_packet(local_channel(),[ - 'item' => [ + Libsync::build_sync_packet(local_channel(),[ + 'item' => [ encode_item($sync_item[0],true) ] ]); @@ -49,5 +64,5 @@ class Starred extends \Zotlabs\Web\Controller { echo json_encode(array('result' => $item_starred)); killme(); } - + } diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php deleted file mode 100644 index 3d0c07492..000000000 --- a/Zotlabs/Module/Wiki.php +++ /dev/null @@ -1,873 +0,0 @@ -<?php /** @file */ - -namespace Zotlabs\Module; - -use App; -use Zotlabs\Web\Controller; -use Zotlabs\Lib\Apps; -use Zotlabs\Lib\PermissionDescription; -use Zotlabs\Lib\NativeWiki; -use Zotlabs\Lib\NativeWikiPage; -use Zotlabs\Lib\MarkdownSoap; -use Michelf\MarkdownExtra; - -require_once('include/acl_selectors.php'); -require_once('include/conversation.php'); -require_once('include/bbcode.php'); - -class Wiki extends Controller { - - private $wiki = null; - - function init() { - // Determine which channel's wikis to display to the observer - $nick = null; - if (argc() > 1) - $nick = argv(1); // if the channel name is in the URL, use that - if (! $nick && local_channel()) { // if no channel name was provided, assume the current logged in channel - $channel = \App::get_channel(); - if ($channel && $channel['channel_address']) { - $nick = $channel['channel_address']; - goaway(z_root() . '/wiki/' . $nick); - } - } - if (! $nick) { - notice( t('Profile Unavailable.') . EOL); - goaway(z_root()); - } - - profile_load($nick); - } - - function get() { - - if(observer_prohibited(true)) { - return login(); - } - - if(! Apps::system_app_installed(App::$profile_uid, 'Wiki')) { - //Do not display any associated widgets at this point - App::$pdl = ''; - $papp = Apps::get_papp('Wiki'); - return Apps::app_render($papp, 'module'); - } - - - if(! perm_is_allowed(\App::$profile_uid,get_observer_hash(),'view_wiki')) { - notice( t('Permission denied.') . EOL); - return; - } - - // TODO: Combine the interface configuration into a unified object - // Something like $interface = array('new_page_button' => false, 'new_wiki_button' => false, ...) - - $wiki_owner = false; - $showNewWikiButton = false; - $pageHistory = array(); - $local_observer = null; - $resource_id = ''; - - // init() should have forced the URL to redirect to /wiki/channel so assume argc() > 1 - - $nick = argv(1); - $owner = channelx_by_nick($nick); // The channel who owns the wikis being viewed - if(! $owner) { - notice( t('Invalid channel') . EOL); - goaway('/' . argv(0)); - } - - $observer_hash = get_observer_hash(); - - // Determine if the observer is the channel owner so the ACL dialog can be populated - if (local_channel() === intval($owner['channel_id'])) { - - $wiki_owner = true; - - nav_set_selected('Wiki'); - - // Obtain the default permission settings of the channel - $owner_acl = array( - 'allow_cid' => $owner['channel_allow_cid'], - 'allow_gid' => $owner['channel_allow_gid'], - 'deny_cid' => $owner['channel_deny_cid'], - 'deny_gid' => $owner['channel_deny_gid'] - ); - - // Initialize the ACL to the channel default permissions - - $x = array( - 'lockstate' => (( $owner['channel_allow_cid'] || - $owner['channel_allow_gid'] || - $owner['channel_deny_cid'] || - $owner['channel_deny_gid']) - ? 'lock' : 'unlock' - ), - 'acl' => populate_acl($owner_acl, false, PermissionDescription::fromGlobalPermission('view_wiki')), - 'allow_cid' => acl2json($owner_acl['allow_cid']), - 'allow_gid' => acl2json($owner_acl['allow_gid']), - 'deny_cid' => acl2json($owner_acl['deny_cid']), - 'deny_gid' => acl2json($owner_acl['deny_gid']), - 'bang' => '' - ); - } - else { - // Not the channel owner - $owner_acl = $x = array(); - } - - $is_owner = ((local_channel()) && (local_channel() == \App::$profile['profile_uid']) ? true : false); - - $o = ''; - - // Download a wiki - - if((argc() > 3) && (argv(2) === 'download') && (argv(3) === 'wiki')) { - - $resource_id = argv(4); - $w = NativeWiki::get_wiki($owner['channel_id'],$observer_hash,$resource_id); -// $w = NativeWiki::get_wiki($owner,$observer_hash,$resource_id); - if(! $w['htmlName']) { - notice(t('Error retrieving wiki') . EOL); - } - - $zip_folder_name = random_string(10); - $zip_folderpath = '/tmp/' . $zip_folder_name; - if(!mkdir($zip_folderpath, 0770, false)) { - logger('Error creating zip file export folder: ' . $zip_folderpath, LOGGER_NORMAL); - notice(t('Error creating zip file export folder') . EOL); - } - - $zip_filename = $w['urlName']; - $zip_filepath = '/tmp/' . $zip_folder_name . '/' . $zip_filename; - - - // Generate the zip file - - $zip = new \ZipArchive; - $r = $zip->open($zip_filepath, \ZipArchive::CREATE); - if($r === true) { - $pages = []; - $i = q("select * from item where resource_type = 'nwikipage' and resource_id = '%s' order by revision desc", - dbesc($resource_id) - ); - - if($i) { - foreach($i as $iv) { - if(in_array($iv['mid'],$pages)) - continue; - - if($iv['mimetype'] === 'text/plain') { - $content = html_entity_decode($iv['body'],ENT_COMPAT,'UTF-8'); - } - elseif($iv['mimetype'] === 'text/bbcode') { - $content = html_entity_decode($iv['body'],ENT_COMPAT,'UTF-8'); - } - elseif($iv['mimetype'] === 'text/markdown') { - $content = html_entity_decode(MarkdownSoap::unescape($iv['body']),ENT_COMPAT,'UTF-8'); - } - $fname = get_iconfig($iv['id'],'nwikipage','pagetitle') . NativeWikiPage::get_file_ext($iv); - $zip->addFromString($fname,$content); - $pages[] = $iv['mid']; - } - - - } - - } - $zip->close(); - - // Output the file for download - - header('Content-disposition: attachment; filename="' . $zip_filename . '.zip"'); - header('Content-Type: application/zip'); - - $success = readfile($zip_filepath); - - if(!$success) { - logger('Error downloading wiki: ' . $resource_id); - notice(t('Error downloading wiki: ' . $resource_id) . EOL); - } - - // delete temporary files - rrmdir($zip_folderpath); - killme(); - - } - - switch(argc()) { - case 2: - $wikis = NativeWiki::listwikis($owner, get_observer_hash()); - - if($wikis) { - $o .= replace_macros(get_markup_template('wikilist.tpl'), array( - '$header' => t('Wikis'), - '$channel' => $owner['channel_address'], - '$wikis' => $wikis['wikis'], - // If the observer is the local channel owner, show the wiki controls - '$owner' => ((local_channel() && local_channel() === intval(\App::$profile['uid'])) ? true : false), - '$edit' => t('Edit'), - '$download' => t('Download'), - '$view' => t('View'), - '$create' => t('Create New'), - '$submit' => t('Submit'), - '$wikiName' => array('wikiName', t('Wiki name')), - '$mimeType' => array('mimeType', t('Content type'), '', '', ['text/markdown' => t('Markdown'), 'text/bbcode' => t('BBcode'), 'text/plain' => t('Text') ]), - '$name' => t('Name'), - '$type' => t('Type'), - '$unlocked' => t('Any type'), - '$lockstate' => (x($x,'lockstate') ? $x['lockstate'] : ''), - '$acl' => (x($x,'acl') ? $x['acl'] : ''), - '$allow_cid' => (x($x,'allow_cid') ? $x['allow_cid'] : ''), - '$allow_gid' => (x($x,'allow_gid') ? $x['allow_gid'] : ''), - '$deny_cid' => (x($x,'deny_cid') ? $x['deny_cid'] : ''), - '$deny_gid' => (x($x,'deny_gid') ? $x['deny_gid'] : ''), - '$typelock' => array('typelock', t('Lock content type'), '', '', array(t('No'), t('Yes'))), - '$notify' => array('postVisible', t('Create a status post for this wiki'), '', '', array(t('No'), t('Yes'))), - '$edit_wiki_name' => t('Edit Wiki Name') - )); - - return $o; - } - break; - - case 3: - - // /wiki/channel/wiki -> No page was specified, so redirect to Home.md - - //$wikiUrlName = urlencode(argv(2)); - $wikiUrlName = NativeWiki::name_encode(argv(2)); - goaway(z_root() . '/' . argv(0) . '/' . argv(1) . '/' . $wikiUrlName . '/Home'); - - case 4: - default: - - // GET /wiki/channel/wiki/page - // Fetch the wiki info and determine observer permissions - - //$wikiUrlName = urldecode(argv(2)); - $wikiUrlName = NativeWiki::name_decode(argv(2)); - - $page_name = ''; - $ignore_language = false; - - for($x = 3; $x < argc(); $x ++) { - if($page_name === '' && argv($x) === '-') { - $ignore_language = true; - continue; - } - if($page_name) { - $page_name .= '/'; - } - $page_name .= argv($x); - } - - //$pageUrlName = urldecode($page_name); - $pageUrlName = NativeWiki::name_decode($page_name); - $langPageUrlName = \App::$language . '/' . $pageUrlName; - - $w = NativeWiki::exists_by_name($owner['channel_id'], $wikiUrlName); - - if(! $w['resource_id']) { - notice(t('Wiki not found') . EOL); - goaway(z_root() . '/' . argv(0) . '/' . argv(1)); - } - - $resource_id = $w['resource_id']; - - if(! $wiki_owner) { - // Check for observer permissions - $observer_hash = get_observer_hash(); - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(! $perms['read']) { - notice(t('Permission denied.') . EOL); - goaway(z_root() . '/' . argv(0) . '/' . argv(1)); - return; //not reached - } - $wiki_editor = (($perms['write']) ? true : false); - } - else { - $wiki_editor = true; - } - - //$wikiheaderName = urldecode($wikiUrlName); - $wikiheaderName = escape_tags(NativeWiki::name_decode($wikiUrlName)); - //$wikiheaderPage = urldecode($pageUrlName); - $wikiheaderPage = escape_tags(NativeWiki::name_decode($pageUrlName)); - - $renamePage = (($wikiheaderPage === 'Home') ? '' : t('Rename page')); - $sharePage = t('Share'); - - $p = []; - - if(! $ignore_language) { - $p = NativeWikiPage::get_page_content(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'resource_id' => $resource_id, 'pageUrlName' => $langPageUrlName)); - } - if(! ($p && $p['success'])) { - $p = NativeWikiPage::get_page_content(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); - } - if(! ($p && $p['success'])) { - $x = new \Zotlabs\Widget\Wiki_pages(); - - $html = $x->create_missing_page([ - 'resource_id' => $resource_id, - 'channel_id' => $owner['channel_id'], - 'channel_address' => $owner['channel_address'], - 'refresh' => true - ]); - //json_return_and_die(array('pages' => $page_list_html, 'message' => '', 'success' => true)); - notice( t('Error retrieving page content') . EOL); - //goaway(z_root() . '/' . argv(0) . '/' . argv(1) ); - $renderedContent = NativeWikiPage::convert_links($html, argv(0) . '/' . argv(1) . '/' . NativeWiki::name_encode($wikiUrlName)); - $showPageControls = $wiki_editor; - } - else { - $mimeType = $p['pageMimeType']; - - $sampleContent = (($mimeType == 'text/bbcode') ? '[h3]' . t('New page') . '[/h3]' : '### ' . t('New page')); - if($mimeType === 'text/plain') - $sampleContent = t('New page'); - - $content = (($p['content'] == '') ? $sampleContent : $p['content']); - - $hookinfo = ['content' => $content, 'mimetype' => $mimeType]; - call_hooks('wiki_preprocess',$hookinfo); - $content = $hookinfo['content']; - - // Render the Markdown-formatted page content in HTML - if($mimeType == 'text/bbcode') { - $renderedContent = zidify_links(smilies(bbcode($content))); - $renderedContent = NativeWikiPage::convert_links($renderedContent,argv(0) . '/' . argv(1) . '/' . NativeWiki::name_encode($wikiUrlName)); - } - elseif($mimeType === 'text/plain') { - $renderedContent = str_replace(["\n",' ',"\t"],[EOL,' ',' '],htmlentities($content,ENT_COMPAT,'UTF-8',false)); - } - elseif($mimeType === 'text/markdown') { - $content = MarkdownSoap::unescape($content); - //$html = NativeWikiPage::generate_toc(zidify_text(MarkdownExtra::defaultTransform(NativeWikiPage::bbcode($content)))); - //$renderedContent = NativeWikiPage::convert_links($html, argv(0) . '/' . argv(1) . '/' . $wikiUrlName); - $html = NativeWikiPage::convert_links($content, argv(0) . '/' . argv(1) . '/' . NativeWiki::name_encode($wikiUrlName)); - $renderedContent = NativeWikiPage::generate_toc(zidify_text(MarkdownExtra::defaultTransform(NativeWikiPage::bbcode($html)))); - } - $showPageControls = $wiki_editor; - } - break; -// default: // Strip the extraneous URL components -// goaway('/' . argv(0) . '/' . argv(1) . '/' . NativeWiki::name_encode($wikiUrlName) . '/' . $pageUrlName); - } - - - $wikiModalID = random_string(3); - - $wikiModal = replace_macros(get_markup_template('generic_modal.tpl'), array( - '$id' => $wikiModalID, - '$title' => t('Revision Comparison'), - '$ok' => (($showPageControls) ? t('Revert') : ''), - '$cancel' => t('Cancel') - )); - - $types = [ 'text/bbcode' => t('BBcode'), 'text/markdown' => t('Markdown'), 'text/plain' => 'Text' ]; - $currenttype = $types[$mimeType]; - - $placeholder = t('Short description of your changes (optional)'); - - $zrl = z_root() . '/wiki/' . argv(1) . '/' . NativeWiki::name_encode($wikiUrlName) . '/' . NativeWiki::name_encode($pageUrlName); - $o .= replace_macros(get_markup_template('wiki.tpl'),array( - '$wikiheaderName' => $wikiheaderName, - '$wikiheaderPage' => $wikiheaderPage, - '$renamePage' => $renamePage, - '$sharePage' => $sharePage, - '$shareLink' => urlencode('#^[zrl=' . $zrl . ']' . '[ ' . $owner['channel_name'] . ' ] ' . $wikiheaderName . ' - ' . $wikiheaderPage . '[/zrl]'), - '$showPageControls' => $showPageControls, - '$editOrSourceLabel' => (($showPageControls) ? t('Edit') : t('Source')), - '$tools_label' => 'Page Tools', - '$channel_address' => $owner['channel_address'], - '$channel_id' => $owner['channel_id'], - '$resource_id' => $resource_id, - '$page' => $pageUrlName, - '$mimeType' => $mimeType, - '$typename' => $currenttype, - '$content' => $content, - '$renderedContent' => $renderedContent, - '$pageRename' => array('pageRename', t('New page name'), '', ''), - '$commitMsg' => array('commitMsg', '', '', '', '', 'placeholder="' . $placeholder . '"'), - '$wikiModal' => $wikiModal, - '$wikiModalID' => $wikiModalID, - '$commit' => 'HEAD', - '$embedPhotos' => t('Embed image from photo albums'), - '$embedPhotosModalTitle' => t('Embed an image from your albums'), - '$embedPhotosModalCancel' => t('Cancel'), - '$embedPhotosModalOK' => t('OK'), - '$modalchooseimages' => t('Choose images to embed'), - '$modalchoosealbum' => t('Choose an album'), - '$modaldiffalbum' => t('Choose a different album'), - '$modalerrorlist' => t('Error getting album list'), - '$modalerrorlink' => t('Error getting photo link'), - '$modalerroralbum' => t('Error getting album'), - '$view_lbl' => t('View'), - '$history_lbl' => t('History') - )); - - if($p['pageMimeType'] === 'text/markdown') - head_add_js('/library/ace/ace.js'); // Ace Code Editor - - return $o; - } - - function post() { - - require_once('include/bbcode.php'); - - $nick = argv(1); - $owner = channelx_by_nick($nick); - $observer_hash = get_observer_hash(); - - if(! $owner) { - notice( t('Permission denied.') . EOL); - return; - } - - // /wiki/channel/preview - // Render mardown-formatted text in HTML for preview - if((argc() > 2) && (argv(2) === 'preview')) { - $content = $_POST['content']; - $resource_id = $_POST['resource_id']; - - $w = NativeWiki::get_wiki($owner['channel_id'],$observer_hash,$resource_id); - - $wikiURL = argv(0) . '/' . argv(1) . '/' . $w['urlName']; - - $mimeType = $_POST['mimetype']; - - if($mimeType === 'text/bbcode') { - $html = zidify_links(smilies(bbcode($content))); - $html = NativeWikiPage::convert_links($html,$wikiURL); - } - elseif($mimeType === 'text/markdown') { - $linkconverted = NativeWikiPage::convert_links($content,$wikiURL); - $bb = NativeWikiPage::bbcode($linkconverted); - $x = new MarkdownSoap($bb); - $md = $x->clean(); - $md = MarkdownSoap::unescape($md); - $html = MarkdownExtra::defaultTransform($md); - $html = NativeWikiPage::generate_toc(zidify_text($html)); - } - elseif($mimeType === 'text/plain') { - $html = str_replace(["\n",' ',"\t"],[EOL,' ',' '],htmlentities($content,ENT_COMPAT,'UTF-8',false)); - } - json_return_and_die(array('html' => $html, 'success' => true)); - } - - // Create a new wiki - // /wiki/channel/create/wiki - if ((argc() > 3) && (argv(2) === 'create') && (argv(3) === 'wiki')) { - - // Only the channel owner can create a wiki, at least until we create a - // more detail permissions framework - - if (local_channel() !== intval($owner['channel_id'])) { - goaway('/' . argv(0) . '/' . $nick . '/'); - } - $wiki = array(); - - // backslashes won't work well in the javascript functions - $name = str_replace('\\','',$_POST['wikiName']); - - // Generate new wiki info from input name - $wiki['postVisible'] = ((intval($_POST['postVisible'])) ? 1 : 0); - $wiki['rawName'] = $name; - $wiki['htmlName'] = escape_tags($name); - //$wiki['urlName'] = urlencode(urlencode($name)); - $wiki['urlName'] = NativeWiki::name_encode($name); - $wiki['mimeType'] = $_POST['mimeType']; - $wiki['typelock'] = $_POST['typelock']; - - if($wiki['urlName'] === '') { - notice( t('Error creating wiki. Invalid name.') . EOL); - goaway('/wiki'); - return; //not reached - } - - $exists = NativeWiki::exists_by_name($owner['channel_id'], $wiki['urlName']); - if($exists['id']) { - notice( t('A wiki with this name already exists.') . EOL); - goaway('/wiki'); - return; //not reached - } - - // Get ACL for permissions - $acl = new \Zotlabs\Access\AccessList($owner); - $acl->set_from_array($_POST); - $r = NativeWiki::create_wiki($owner, $observer_hash, $wiki, $acl); - if($r['success']) { - NativeWiki::sync_a_wiki_item($owner['channel_id'],$r['item_id'],$r['item']['resource_id']); - $homePage = NativeWikiPage::create_page($owner, $observer_hash, 'Home', $r['item']['resource_id'], $wiki['mimeType']); - if(! $homePage['success']) { - notice( t('Wiki created, but error creating Home page.')); - goaway(z_root() . '/wiki/' . $nick . '/' . NativeWiki::name_encode($wiki['urlName'])); - } - NativeWiki::sync_a_wiki_item($owner['channel_id'], $homePage['item_id'], $r['item']['resource_id']); - goaway(z_root() . '/wiki/' . $nick . '/' . NativeWiki::name_encode($wiki['urlName']) . '/' . NativeWiki::name_encode($homePage['page']['urlName'])); - } - else { - notice( t('Error creating wiki')); - goaway(z_root() . '/wiki'); - } - } - - // Update a wiki - // /wiki/channel/update/wiki - if ((argc() > 3) && (argv(2) === 'update') && (argv(3) === 'wiki')) { - // Only the channel owner can update a wiki, at least until we create a - // more detail permissions framework - - if (local_channel() !== intval($owner['channel_id'])) { - goaway('/' . argv(0) . '/' . $nick . '/'); - } - - $arr = []; - - //$arr['urlName'] = urlencode(urlencode($_POST['origRawName'])); - $arr['urlName'] = NativeWiki::name_encode($_POST['origRawName']); - - if($_POST['updateRawName']) - $arr['updateRawName'] = $_POST['updateRawName']; - - if(($arr['urlName'] || $arr['updateRawName']) === '') { - notice( t('Error updating wiki. Invalid name.') . EOL); - goaway('/wiki'); - return; //not reached - } - - $wiki = NativeWiki::exists_by_name($owner['channel_id'], $arr['urlName']); - if($wiki['resource_id']) { - - $arr['resource_id'] = $wiki['resource_id']; - - $acl = new \Zotlabs\Access\AccessList($owner); - $acl->set_from_array($_POST); - - $r = NativeWiki::update_wiki($owner['channel_id'], $observer_hash, $arr, $acl); - if($r['success']) { - NativeWiki::sync_a_wiki_item($owner['channel_id'], $r['item_id'], $r['item']['resource_id']); - goaway(z_root() . '/wiki/' . $nick); - } - else { - notice( t('Error updating wiki')); - goaway(z_root() . '/wiki'); - } - - } - goaway(z_root() . '/wiki'); - } - - // Delete a wiki - if ((argc() > 3) && (argv(2) === 'delete') && (argv(3) === 'wiki')) { - - // Only the channel owner can delete a wiki, at least until we create a - // more detail permissions framework - if (local_channel() !== intval($owner['channel_id'])) { - logger('Wiki delete permission denied.'); - json_return_and_die(array('message' => t('Wiki delete permission denied.'), 'success' => false)); - } - $resource_id = $_POST['resource_id']; - $deleted = NativeWiki::delete_wiki($owner['channel_id'],$observer_hash,$resource_id); - if ($deleted['success']) { - NativeWiki::sync_a_wiki_item($owner['channel_id'], 0, $resource_id); - json_return_and_die(array('message' => '', 'success' => true)); - } - else { - logger('Error deleting wiki: ' . $resource_id . ' ' . $deleted['message']); - json_return_and_die(array('message' => t('Error deleting wiki'), 'success' => false)); - } - } - - - // Create a page - if ((argc() === 4) && (argv(2) === 'create') && (argv(3) === 'page')) { - - $mimetype = $_POST['mimetype']; - - $resource_id = $_POST['resource_id']; - // Determine if observer has permission to create a page - - - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(! $perms['write']) { - logger('Wiki write permission denied. ' . EOL); - json_return_and_die(array('success' => false)); - } - - $name = isset($_POST['pageName']) ? $_POST['pageName'] : $_POST['missingPageName']; //Get new page name - - // backslashes won't work well in the javascript functions - $name = str_replace('\\','',$name); - - if(NativeWiki::name_encode(escape_tags($name)) === '') { - json_return_and_die(array('message' => 'Error creating page. Invalid name (' . print_r($_POST,true) . ').', 'success' => false)); - } - - $page = NativeWikiPage::create_page($owner, $observer_hash, $name, $resource_id, $mimetype); - if($page['item_id']) { - - $commit = NativeWikiPage::commit([ - 'commit_msg' => t('New page created'), - 'resource_id' => $resource_id, - 'channel_id' => $owner['channel_id'], - 'observer_hash' => $observer_hash, - 'pageUrlName' => $name - ]); - if($commit['success']) { - NativeWiki::sync_a_wiki_item($owner['channel_id'], $commit['item_id'], $resource_id); - //json_return_and_die(array('url' => '/' . argv(0) . '/' . argv(1) . '/' . urlencode($page['wiki']['urlName']) . '/' . urlencode($page['page']['urlName']), 'success' => true)); - json_return_and_die(array('url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . $page['page']['urlName'], 'success' => true)); - } - else { - json_return_and_die(array('message' => 'Error making git commit','url' => '/' . argv(0) . '/' . argv(1) . '/' . NativeWiki::name_encode($page['wiki']['urlName']) . '/' . NativeWiki::name_encode($page['page']['urlName']),'success' => false)); - } - - - } - else { - logger('Error creating page'); - json_return_and_die(array('message' => 'Error creating page.', 'success' => false)); - } - } - - // Fetch page list for a wiki - if((argc() === 5) && (argv(2) === 'get') && (argv(3) === 'page') && (argv(4) === 'list')) { - $resource_id = $_POST['resource_id']; // resource_id for wiki in db - - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(!$perms['read']) { - logger('Wiki read permission denied.' . EOL); - json_return_and_die(array('pages' => null, 'message' => 'Permission denied.', 'success' => false)); - } - - // @FIXME - we shouldn't invoke this if it isn't in the PDL or has been over-ridden - - $x = new \Zotlabs\Widget\Wiki_pages(); - - $page_list_html = $x->widget([ - 'resource_id' => $resource_id, - 'channel_id' => $owner['channel_id'], - 'channel_address' => $owner['channel_address'], - 'refresh' => true - ]); - json_return_and_die(array('pages' => $page_list_html, 'message' => '', 'success' => true)); - } - - // Save a page - if ((argc() === 4) && (argv(2) === 'save') && (argv(3) === 'page')) { - - $resource_id = $_POST['resource_id']; - $pageUrlName = $_POST['name']; - $pageHtmlName = escape_tags($_POST['name']); - $content = $_POST['content']; //Get new content - $commitMsg = $_POST['commitMsg']; - if ($commitMsg === '') { - $commitMsg = 'Updated ' . $pageHtmlName; - } - - // Determine if observer has permission to save content - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(! $perms['write']) { - logger('Wiki write permission denied. ' . EOL); - json_return_and_die(array('success' => false)); - } - - $saved = NativeWikiPage::save_page([ - 'channel_id' => $owner['channel_id'], - 'observer_hash' => $observer_hash, - 'resource_id' => $resource_id, - 'pageUrlName' => $pageUrlName, - 'content' => $content - ]); - if($saved['success']) { - - $commit = NativeWikiPage::commit([ - 'commit_msg' => $commitMsg, - 'pageUrlName' => $pageUrlName, - 'resource_id' => $resource_id, - 'channel_id' => $owner['channel_id'], - 'observer_hash' => $observer_hash, - 'revision' => (-1) - ]); - if($commit['success']) { - NativeWiki::sync_a_wiki_item($owner['channel_id'], $commit['item_id'], $resource_id); - json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true , 'content' => $content)); - } - else { - json_return_and_die(array('message' => 'Error making git commit','success' => false)); - } - } - else { - json_return_and_die(array('message' => 'Error saving page', 'success' => false)); - } - } - - // Update page history - // /wiki/channel/history/page - if ((argc() === 4) && (argv(2) === 'history') && (argv(3) === 'page')) { - - $resource_id = $_POST['resource_id']; - $pageUrlName = $_POST['name']; - - // Determine if observer has permission to read content - - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(! $perms['read']) { - logger('Wiki read permission denied.' . EOL); - json_return_and_die(array('historyHTML' => '', 'message' => 'Permission denied.', 'success' => false)); - } - - $historyHTML = \Zotlabs\Lib\NativeWikiPage::render_page_history(array( - 'resource_id' => $resource_id, - 'pageUrlName' => $pageUrlName, - 'permsWrite' => $perms['write'] - )); - - json_return_and_die(array('historyHTML' => $historyHTML, 'message' => '', 'success' => true)); - } - - // Delete a page - if ((argc() === 4) && (argv(2) === 'delete') && (argv(3) === 'page')) { - - $resource_id = $_POST['resource_id']; - $pageUrlName = $_POST['name']; - - if ($pageUrlName === 'Home') { - json_return_and_die(array('message' => t('Cannot delete Home'),'success' => false)); - } - - // Determine if observer has permission to delete pages - // currently just allow page owner - if((! local_channel()) || (local_channel() != $owner['channel_id'])) { - logger('Wiki write permission denied. ' . EOL); - json_return_and_die(array('success' => false)); - } - - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(! $perms['write']) { - logger('Wiki write permission denied. ' . EOL); - json_return_and_die(array('success' => false)); - } - - $deleted = NativeWikiPage::delete_page([ - 'channel_id' => $owner['channel_id'], - 'observer_hash' => $observer_hash, - 'resource_id' => $resource_id, - 'pageUrlName' => $pageUrlName - ]); - if($deleted['success']) { - NativeWiki::sync_a_wiki_item($owner['channel_id'], 0, $resource_id); - json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true)); - } - else { - json_return_and_die(array('message' => 'Error deleting page', 'success' => false)); - } - } - - // Revert a page - if ((argc() === 4) && (argv(2) === 'revert') && (argv(3) === 'page')) { - - $resource_id = $_POST['resource_id']; - $pageUrlName = $_POST['name']; - $commitHash = $_POST['commitHash']; - - // Determine if observer has permission to revert pages - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(! $perms['write']) { - logger('Wiki write permission denied.' . EOL); - json_return_and_die(array('success' => false)); - } - - $reverted = NativeWikiPage::revert_page([ - 'channel_id' => $owner['channel_id'], - 'observer_hash' => $observer_hash, - 'commitHash' => $commitHash, - 'resource_id' => $resource_id, - 'pageUrlName' => $pageUrlName - ]); - if($reverted['success']) { - json_return_and_die(array('content' => $reverted['content'], 'message' => '', 'success' => true)); - } - else { - json_return_and_die(array('content' => '', 'message' => 'Error reverting page', 'success' => false)); - } - } - - // Compare page revisions - if ((argc() === 4) && (argv(2) === 'compare') && (argv(3) === 'page')) { - $resource_id = $_POST['resource_id']; - $pageUrlName = $_POST['name']; - $compareCommit = $_POST['compareCommit']; - $currentCommit = $_POST['currentCommit']; - // Determine if observer has permission to revert pages - - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(!$perms['read']) { - logger('Wiki read permission denied.' . EOL); - json_return_and_die(array('success' => false)); - } - - $compare = NativeWikiPage::compare_page(array('channel_id' => $owner['channel_id'], 'observer_hash' => $observer_hash, 'currentCommit' => $currentCommit, 'compareCommit' => $compareCommit, 'resource_id' => $resource_id, 'pageUrlName' => $pageUrlName)); - if($compare['success']) { - $diffHTML = '<table class="text-center" width="100%"><tr><td class="lead" width="50%">' . t('Current Revision') . '</td><td class="lead" width="50%">' . t('Selected Revision') . '</td></tr></table>' . $compare['diff']; - json_return_and_die(array('diff' => $diffHTML, 'message' => '', 'success' => true)); - } else { - json_return_and_die(array('diff' => '', 'message' => 'Error comparing page', 'success' => false)); - } - } - - // Rename a page - if ((argc() === 4) && (argv(2) === 'rename') && (argv(3) === 'page')) { - $resource_id = $_POST['resource_id']; - $pageUrlName = $_POST['oldName']; - $pageNewName = str_replace('\\','',$_POST['newName']); - if ($pageUrlName === 'Home') { - json_return_and_die(array('message' => 'Cannot rename Home','success' => false)); - } - if(NativeWiki::name_encode(escape_tags($pageNewName)) === '') { - json_return_and_die(array('message' => 'Error renaming page. Invalid name.', 'success' => false)); - } - // Determine if observer has permission to rename pages - - $perms = NativeWiki::get_permissions($resource_id, intval($owner['channel_id']), $observer_hash); - if(! $perms['write']) { - logger('Wiki write permission denied. ' . EOL); - json_return_and_die(array('success' => false)); - } - - $renamed = NativeWikiPage::rename_page([ - 'channel_id' => $owner['channel_id'], - 'observer_hash' => $observer_hash, - 'resource_id' => $resource_id, - 'pageUrlName' => $pageUrlName, - 'pageNewName' => $pageNewName - ]); - if($renamed['success']) { - $commit = NativeWikiPage::commit([ - 'channel_id' => $owner['channel_id'], - 'commit_msg' => 'Renamed ' . NativeWiki::name_decode($pageUrlName) . ' to ' . $renamed['page']['htmlName'], - 'resource_id' => $resource_id, - 'observer_hash' => $observer_hash, - 'pageUrlName' => $pageNewName - ]); - if($commit['success']) { - NativeWiki::sync_a_wiki_item($owner['channel_id'], $commit['item_id'], $resource_id); - json_return_and_die(array('name' => $renamed['page'], 'message' => 'Wiki git repo commit made', 'success' => true)); - } - else { - json_return_and_die(array('message' => 'Error making git commit','success' => false)); - } - } - else { - json_return_and_die(array('message' => 'Error renaming page', 'success' => false)); - } - } - - //notice( t('You must be authenticated.')); - json_return_and_die(array('message' => t('You must be authenticated.'), 'success' => false)); - - } -} diff --git a/Zotlabs/Photo/PhotoDriver.php b/Zotlabs/Photo/PhotoDriver.php index 6bdb89ab1..f50ef17ae 100644 --- a/Zotlabs/Photo/PhotoDriver.php +++ b/Zotlabs/Photo/PhotoDriver.php @@ -344,19 +344,13 @@ abstract class PhotoDriver { return false; } - /* - * PHP 7.2 allows you to use a stream resource, which should reduce/avoid - * memory exhaustion on large images. - */ - - if(version_compare(PHP_VERSION, '7.2.0') >= 0) { - $f = @fopen($filename, 'rb'); - } else { - $f = $filename; - } + $f = @fopen($filename, 'rb'); if($f) { - return @exif_read_data($f, null, true); + // exif_read_data accepts a stream resource in php > 7.2 + $x = @exif_read_data($f, null, true); + fclose($f); + return $x; } return false; diff --git a/Zotlabs/Update/_1253.php b/Zotlabs/Update/_1253.php new file mode 100644 index 000000000..3b0e6899a --- /dev/null +++ b/Zotlabs/Update/_1253.php @@ -0,0 +1,23 @@ +<?php + +namespace Zotlabs\Update; + +class _1253 { + + function run() { + + dbq("START TRANSACTION"); + + $r = dbq("DELETE FROM app WHERE app_name IN ('Wiki', 'Cards', 'Articles') AND app_plugin = ''"); + + if($r) { + dbq("COMMIT"); + return UPDATE_SUCCESS; + } + + dbq("ROLLBACK"); + return UPDATE_FAILED; + + } + +} diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index 4177477a1..cb41c2b7d 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -502,8 +502,11 @@ class HTTPSig { $x = self::sign($head, $prvkey, $alg); - // TODO: should we default to hs2019? - // $headerval = 'keyId="' . $keyid . '",algorithm="' . (($algorithm === 'rsa-sha256') ? 'hs2019' : $algorithm) . '",headers="' . $x['headers'] . '",signature="' . $x['signature'] . '"'; + // TODO: should we default to hs2019? cavage-http-signatures-12 is not very wide spread yet + + if (get_config('system', 'use_hs2019', false) && $algorithm === 'rsa-sha256') { + $algorithm = 'hs2019'; + } $headerval = 'keyId="' . $keyid . '",algorithm="' . $algorithm . '",headers="' . $x['headers'] . '",signature="' . $x['signature'] . '"'; diff --git a/Zotlabs/Widget/Categories.php b/Zotlabs/Widget/Categories.php index 0c6996d55..0a1c80061 100644 --- a/Zotlabs/Widget/Categories.php +++ b/Zotlabs/Widget/Categories.php @@ -17,36 +17,22 @@ class Categories { function widget($arr) { - $cards = ((array_key_exists('cards',$arr) && $arr['cards']) ? true : false); - - if(($cards) && (! Apps::system_app_installed(App::$profile['profile_uid'], 'Cards'))) - return ''; - - $articles = ((array_key_exists('articles',$arr) && $arr['articles']) ? true : false); - - if(($articles) && (! Apps::system_app_installed(App::$profile['profile_uid'],'Articles'))) - return ''; - $files = ((array_key_exists('files',$arr) && $arr['files']) ? true : false); - if((! App::$profile['profile_uid']) - || (! perm_is_allowed(App::$profile['profile_uid'],get_observer_hash(),(($cards || $articles) ? 'view_pages' : 'view_stream')))) { + if(!App::$profile['profile_uid'] || !perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_stream')) { return ''; } - $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat'],ENT_COMPAT,'UTF-8') : ''); - $srchurl = (($cards) ? App::$argv[0] . '/' . App::$argv[1] : App::$query_string); - $srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is','',$srchurl),'&'); - $srchurl = str_replace(array('?f=','&f=', '/?'),array('', '', ''),$srchurl); + $cat = ((x($_REQUEST, 'cat')) ? htmlspecialchars($_REQUEST['cat'], ENT_COMPAT, 'UTF-8') : ''); + $srchurl = App::$query_string; + $srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is', '', $srchurl), '&'); + $srchurl = str_replace(['?f=','&f=', '/?'], ['', '', ''], $srchurl); - if($cards) - return cardcategories_widget($srchurl, $cat); - elseif($articles) - return articlecategories_widget($srchurl, $cat); - elseif($files) + if($files) { return filecategories_widget($srchurl, $cat); - else - return categories_widget($srchurl, $cat); + } + + return categories_widget($srchurl, $cat); } } diff --git a/Zotlabs/Widget/Notes.php b/Zotlabs/Widget/Notes.php index 2e8e04e93..c9d08c6b7 100644 --- a/Zotlabs/Widget/Notes.php +++ b/Zotlabs/Widget/Notes.php @@ -10,6 +10,7 @@ namespace Zotlabs\Widget; +use App; use Zotlabs\Lib\Apps; class Notes { @@ -18,6 +19,9 @@ class Notes { if(! local_channel()) return EMPTY_STR; + if(App::$profile_uid !== local_channel()) + return EMPTY_STR; + if(! Apps::system_app_installed(local_channel(), 'Notes')) return EMPTY_STR; diff --git a/Zotlabs/Widget/Tasklist.php b/Zotlabs/Widget/Tasklist.php index 5ecfd5a27..96b70af15 100644 --- a/Zotlabs/Widget/Tasklist.php +++ b/Zotlabs/Widget/Tasklist.php @@ -7,12 +7,17 @@ namespace Zotlabs\Widget; +use App; + class Tasklist { function widget($arr) { - if (! local_channel()) - return; + if(! local_channel()) + return EMPTY_STR; + + if(App::$profile_uid !== local_channel()) + return EMPTY_STR; $o .= '<script>var tasksShowAll = 0; $(document).ready(function() { tasksFetch(); $("#tasklist-new-form").submit(function(event) { event.preventDefault(); $.post( "tasks/new", $("#tasklist-new-form").serialize(), function(data) { tasksFetch(); $("#tasklist-new-summary").val(""); } ); return false; } )});</script>'; $o .= '<script>function taskComplete(id) { $.post("tasks/complete/"+id, function(data) { tasksFetch();}); } diff --git a/Zotlabs/Widget/Wiki_list.php b/Zotlabs/Widget/Wiki_list.php deleted file mode 100644 index 217ab8706..000000000 --- a/Zotlabs/Widget/Wiki_list.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -/** - * * Name: Wiki list - * * Description: A list of existing wikis - */ - -namespace Zotlabs\Widget; - -class Wiki_list { - - function widget($arr) { - - $channel = channelx_by_n(\App::$profile_uid); - - $wikis = \Zotlabs\Lib\NativeWiki::listwikis($channel,get_observer_hash()); - - if($wikis) { - return replace_macros(get_markup_template('wikilist_widget.tpl'), array( - '$header' => t('Wikis'), - '$channel' => $channel['channel_address'], - '$wikis' => $wikis['wikis'] - )); - } - return ''; - } - -} diff --git a/Zotlabs/Widget/Wiki_page_history.php b/Zotlabs/Widget/Wiki_page_history.php deleted file mode 100644 index 3c9f5ed1a..000000000 --- a/Zotlabs/Widget/Wiki_page_history.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -/** - * * Name: Wiki page history - * * Description: History of an existing wiki page - * * Requires: wiki - */ - -namespace Zotlabs\Widget; - -class Wiki_page_history { - - function widget($arr) { - - $pageUrlName = ((array_key_exists('pageUrlName', $arr)) ? $arr['pageUrlName'] : ''); - $resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : ''); - - $pageHistory = \Zotlabs\Lib\NativeWikiPage::page_history([ - 'channel_id' => \App::$profile_uid, - 'observer_hash' => get_observer_hash(), - 'resource_id' => $resource_id, - 'pageUrlName' => $pageUrlName - ]); - - return replace_macros(get_markup_template('nwiki_page_history.tpl'), array( - '$pageHistory' => $pageHistory['history'], - '$permsWrite' => $arr['permsWrite'], - '$name_lbl' => t('Name'), - '$msg_label' => t('Message','wiki_history'), - '$date_lbl' => t('Date'), - '$revert_btn' => t('Revert'), - '$compare_btn' => t('Compare') - )); - - } -} diff --git a/Zotlabs/Widget/Wiki_pages.php b/Zotlabs/Widget/Wiki_pages.php deleted file mode 100644 index ece712334..000000000 --- a/Zotlabs/Widget/Wiki_pages.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php - -/** - * * Name: Wiki pages - * * Description: A list of existing pages of a wiki - * * Requires: wiki - */ - -namespace Zotlabs\Widget; - -use Zotlabs\Lib\NativeWiki; - -class Wiki_pages { - - function create_missing_page($arr) { - if(argc() < 4) - return; - - $c = channelx_by_nick(argv(1)); - $w = \Zotlabs\Lib\NativeWiki::exists_by_name($c['channel_id'],NativeWiki::name_decode(argv(2))); - $arr = array( - 'resource_id' => $w['resource_id'], - 'channel_id' => $c['channel_id'], - 'channel_address' => $c['channel_address'], - 'refresh' => false - ); - - $can_create = perm_is_allowed(\App::$profile['uid'],get_observer_hash(),'write_wiki'); - - $can_delete = ((local_channel() && (local_channel() == \App::$profile['uid'])) ? true : false); - $pageName = NativeWiki::name_decode(escape_tags(argv(3))); - - $wikiname = $w['urlName']; - return replace_macros(get_markup_template('wiki_page_not_found.tpl'), array( - '$resource_id' => $arr['resource_id'], - '$channel_address' => $arr['channel_address'], - '$wikiname' => $wikiname, - '$canadd' => $can_create, - '$candel' => $can_delete, - '$addnew' => t('Add new page'), - '$typelock' => $typelock, - '$lockedtype' => $w['mimeType'], - '$mimetype' => mimetype_select(0,$w['mimeType'], - [ 'text/markdown' => t('Markdown'), 'text/bbcode' => t('BBcode'), 'text/plain' => t('Text') ]), - '$pageName' => array('missingPageName', 'Create Page' , $pageName), - '$refresh' => $arr['refresh'], - '$options' => t('Options'), - '$submit' => t('Submit') - )); - } - - function widget($arr) { - - if(argc() < 3) - return; - - if(! $arr['resource_id']) { - $c = channelx_by_nick(argv(1)); - $w = \Zotlabs\Lib\NativeWiki::exists_by_name($c['channel_id'],NativeWiki::name_decode(argv(2))); - $arr = array( - 'resource_id' => $w['resource_id'], - 'channel_id' => $c['channel_id'], - 'channel_address' => $c['channel_address'], - 'refresh' => false - ); - } - - $wikiname = ''; - - $pages = array(); - - $p = \Zotlabs\Lib\NativeWikiPage::page_list($arr['channel_id'],get_observer_hash(),$arr['resource_id']); - - if($p['pages']) { - $pages = $p['pages']; - $w = $p['wiki']; - // Wiki item record is $w['wiki'] - $wikiname = $w['urlName']; - if (!$wikiname) { - $wikiname = ''; - } - $typelock = $w['typelock']; - } - - $can_create = perm_is_allowed(\App::$profile['uid'],get_observer_hash(),'write_wiki'); - - $can_delete = ((local_channel() && (local_channel() == \App::$profile['uid'])) ? true : false); - - return replace_macros(get_markup_template('wiki_page_list.tpl'), array( - '$resource_id' => $arr['resource_id'], - '$header' => t('Wiki Pages'), - '$channel_address' => $arr['channel_address'], - '$wikiname' => $wikiname, - '$pages' => $pages, - '$canadd' => $can_create, - '$candel' => $can_delete, - '$addnew' => t('Add new page'), - '$typelock' => $typelock, - '$lockedtype' => $w['mimeType'], - '$mimetype' => mimetype_select(0,$w['mimeType'], - [ 'text/markdown' => t('Markdown'), 'text/bbcode' => t('BBcode'), 'text/plain' => t('Text') ]), - '$pageName' => array('pageName', t('Page name')), - '$refresh' => $arr['refresh'], - '$options' => t('Options'), - '$submit' => t('Submit') - )); - } -} - - |