diff options
author | Mario <mario@mariovavti.com> | 2022-06-01 07:00:21 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2022-06-01 07:00:21 +0000 |
commit | e63f0438415bb364f3085286ca2f199e83ab187b (patch) | |
tree | b107429276ebfc92dc9b4f78e302a4967e5bf0a6 /Zotlabs/Module | |
parent | c5f33baf27d80e2a7ad7307eacd3137609eeb089 (diff) | |
parent | 33dd0c83e377b8adf00559337d13784ec136cecb (diff) | |
download | volse-hubzilla-e63f0438415bb364f3085286ca2f199e83ab187b.tar.gz volse-hubzilla-e63f0438415bb364f3085286ca2f199e83ab187b.tar.bz2 volse-hubzilla-e63f0438415bb364f3085286ca2f199e83ab187b.zip |
Merge branch '7.4RC'7.4
Diffstat (limited to 'Zotlabs/Module')
-rw-r--r-- | Zotlabs/Module/Article_edit.php | 138 | ||||
-rw-r--r-- | Zotlabs/Module/Articles.php | 232 | ||||
-rw-r--r-- | Zotlabs/Module/Card_edit.php | 140 | ||||
-rw-r--r-- | Zotlabs/Module/Cards.php | 214 | ||||
-rw-r--r-- | Zotlabs/Module/Display.php | 42 | ||||
-rw-r--r-- | Zotlabs/Module/Item.php | 44 | ||||
-rw-r--r-- | Zotlabs/Module/Search.php | 50 | ||||
-rw-r--r-- | Zotlabs/Module/Setup.php | 4 | ||||
-rw-r--r-- | Zotlabs/Module/Sse_bs.php | 24 | ||||
-rw-r--r-- | Zotlabs/Module/Starred.php | 37 | ||||
-rw-r--r-- | Zotlabs/Module/Wiki.php | 873 |
11 files changed, 76 insertions, 1722 deletions
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)); - - } -} |