diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index ab008783d..d6df20130 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -126,6 +126,8 @@ class Item extends \Zotlabs\Web\Controller { $ret = $this->item_check_service_class($uid,(($_REQUEST['webpage'] == ITEM_TYPE_WEBPAGE) ? true : false)); if (!$ret['success']) { notice( t($ret['message']) . EOL) ; + if($api_source) + return ( [ 'success' => false, 'message' => 'service class exception' ] ); if(x($_REQUEST,'return')) goaway(z_root() . "/" . $return_path ); killme(); @@ -180,6 +182,8 @@ class Item extends \Zotlabs\Web\Controller { if(($r === false) || (! count($r))) { notice( t('Unable to locate original post.') . EOL); + if($api_source) + return ( [ 'success' => false, 'message' => 'invalid post id' ] ); if(x($_REQUEST,'return')) goaway(z_root() . "/" . $return_path ); killme(); @@ -214,6 +218,8 @@ class Item extends \Zotlabs\Web\Controller { if(! $can_comment) { notice( t('Permission denied.') . EOL) ; + if($api_source) + return ( [ 'success' => false, 'message' => 'permission denied' ] ); if(x($_REQUEST,'return')) goaway(z_root() . "/" . $return_path ); killme(); @@ -222,6 +228,8 @@ class Item extends \Zotlabs\Web\Controller { else { if(! perm_is_allowed($profile_uid,$observer['xchan_hash'],($webpage) ? 'write_pages' : 'post_wall')) { notice( t('Permission denied.') . EOL) ; + if($api_source) + return ( [ 'success' => false, 'message' => 'permission denied' ] ); if(x($_REQUEST,'return')) goaway(z_root() . "/" . $return_path ); killme(); @@ -276,6 +284,8 @@ class Item extends \Zotlabs\Web\Controller { if(! $channel) { logger("mod_item: no channel."); + if($api_source) + return ( [ 'success' => false, 'message' => 'no channel' ] ); if(x($_REQUEST,'return')) goaway(z_root() . "/" . $return_path ); killme(); @@ -291,6 +301,8 @@ class Item extends \Zotlabs\Web\Controller { } else { logger("mod_item: no owner."); + if($api_source) + return ( [ 'success' => false, 'message' => 'no owner' ] ); if(x($_REQUEST,'return')) goaway(z_root() . "/" . $return_path ); killme(); @@ -433,6 +445,8 @@ class Item extends \Zotlabs\Web\Controller { if($preview) killme(); info( t('Empty post discarded.') . EOL ); + if($api_source) + return ( [ 'success' => false, 'message' => 'no content' ] ); if(x($_REQUEST,'return')) goaway(z_root() . "/" . $return_path ); killme(); @@ -473,6 +487,8 @@ class Item extends \Zotlabs\Web\Controller { } else { notice( t('Executable content type not permitted to this channel.') . EOL); + if($api_source) + return ( [ 'success' => false, 'message' => 'forbidden content type' ] ); if(x($_REQUEST,'return')) goaway(z_root() . "/" . $return_path ); killme(); @@ -863,7 +879,8 @@ class Item extends \Zotlabs\Web\Controller { logger('mod_item: post cancelled by plugin or duplicate suppressed.'); if($return_path) goaway(z_root() . "/" . $return_path); - + if($api_source) + return ( [ 'success' => false, 'message' => 'operation cancelled' ] ); $json = array('cancel' => 1); $json['reload'] = z_root() . '/' . $_REQUEST['jsreload']; echo json_encode($json); @@ -916,6 +933,10 @@ class Item extends \Zotlabs\Web\Controller { if(! $nopush) \Zotlabs\Daemon\Master::Summon(array('Notifier', 'edit_post', $post_id)); + + if($api_source) + return($x); + if((x($_REQUEST,'return')) && strlen($return_path)) { logger('return: ' . $return_path); goaway(z_root() . "/" . $return_path ); @@ -990,8 +1011,11 @@ class Item extends \Zotlabs\Web\Controller { else { logger('mod_item: unable to retrieve post that was just stored.'); notice( t('System error. Post not saved.') . EOL); - goaway(z_root() . "/" . $return_path ); - // NOTREACHED + if($return_path) + goaway(z_root() . "/" . $return_path ); + if($api_source) + return ( [ 'success' => false, 'message' => 'system error' ] ); + killme(); } if(($parent) && ($parent != $post_id)) { diff --git a/Zotlabs/Module/Wiki.php b/Zotlabs/Module/Wiki.php index 5b3c4c1d8..da23d67a2 100644 --- a/Zotlabs/Module/Wiki.php +++ b/Zotlabs/Module/Wiki.php @@ -214,7 +214,7 @@ class Wiki extends \Zotlabs\Web\Controller { $content = ($p['content'] !== '' ? $rawContent : '"# New page\n"'); // Render the Markdown-formatted page content in HTML if($mimeType == 'text/bbcode') { - $renderedContent = bbcode($content); + $renderedContent = wiki_convert_links(bbcode($content),argv(0).'/'.argv(1).'/'.$wikiUrlName); } else { require_once('library/markdown.php'); @@ -314,7 +314,7 @@ class Wiki extends \Zotlabs\Web\Controller { $mimeType = $w['mimeType']; if($mimeType == 'text/bbcode') { - $html = bbcode($content); + $html = wiki_convert_links(bbcode($content),$wikiURL); } else { require_once('library/markdown.php'); diff --git a/doc/api_functions.bb b/doc/api/api_functions.bb similarity index 100% rename from doc/api_functions.bb rename to doc/api/api_functions.bb diff --git a/doc/api/api_group_members.md b/doc/api/api_group_members.md new file mode 100644 index 000000000..f4bcfa4e3 --- /dev/null +++ b/doc/api/api_group_members.md @@ -0,0 +1,16 @@ +API group_members +================= + +GET /api/z/1.0/group_members + + + +Required: + + group_id or group_name + + +Returns: + + abook+xchan (DB join) for each member of the privacy group + diff --git a/doc/api/api_item_update.md b/doc/api/api_item_update.md new file mode 100644 index 000000000..cf1a28044 --- /dev/null +++ b/doc/api/api_item_update.md @@ -0,0 +1,225 @@ +API item/update +=============== + + +Usage: POST /api/z/1.0/item/update + +Description: item/update posts an item (typically a conversation item or post, but can be any item) using form input. + + +Required: + +- body + + text/bbcode contents by default. + + +Optional: + +- $_FILES['media'] + + uploaded media file to include with post + +- title + + title of post/item + +- contact_allow + + array of xchan.xchan_hash allowed to view this item + +- group_allow + + array of group.hash allowed to view this item + +- contact_deny + + array of xchan.xchan_hash not allowed to view this item + +- group_deny + + array of group.hash not allowed to view this item + +- coord + + geographic coordinates + +- location + + freefrom location + +- expire + + datetime this post will expire or be removed + +- mimetype + + mimetype if not text/bbcode + +- parent + + item.id of parent to this post (makes it a comment) + +- parent_mid + + alternate form of parent using message_id + +- remote_xchan + + xchan.xchan_hash of this message author if not the channel owner + +- consensus + + boolean set to true if this is a consensus or voting item (default false) + +- nocomment + + boolean set to true if comments are to be disabled (default false) + +- origin + + do not use this without reading the code + +- namespace + + persistent identity for a remote network or service + +- remote_id + + message_id of this resource on a remote network or service + +- message_id + + message_id of this item (leave unset to generate one) + +- created + + datetime of message creation + +- post_id + + existing item.id if this is an edit operation + +- app + + application or network name to display with item + +- categories + + comma separated categories for this item + +- webpage + + item.page_type if not 0 + +- pagetitle + + for webpage and design elements, the 'page name' + +- layout_mid + + item.mid of layout for this design element + +- plink + + permalink for this item if different than the default + +- verb + + activitystream verb for this item/activity + +- obj_type + + activitystream object type for this item/activity + + + +Example: + +curl -u mychannel:mypassword https://xyz.macgirvin.com/api/z/1.0/item/update -d body="hello world" + + +Returns: + + + { + + "success": true, + "item_id": "2245", + "item": { + "id": "2245", + "mid": "14135cdecf6b8e3891224e4391748722114da6668eebbcb56fe4667b60b88249@xyz.macgirvin.com", + "aid": "1", + "uid": "2", + "parent": "2245", + "parent_mid": "14135cdecf6b8e3891224e4391748722114da6668eebbcb56fe4667b60b88249@xyz.macgirvin.com", + "thr_parent": "14135cdecf6b8e3891224e4391748722114da6668eebbcb56fe4667b60b88249@xyz.macgirvin.com", + "created": "2016-12-03 20:00:12", + "edited": "2016-12-03 20:00:12", + "expires": "0001-01-01 00:00:00", + "commented": "2016-12-03 20:00:12", + "received": "2016-12-03 20:00:12", + "changed": "2016-12-03 20:00:12", + "comments_closed": "0001-01-01 00:00:00", + "owner_xchan": "pgcJx1IQjuPkx8aI9qheJlBMZzJz-oTPjHy3h5pWlOVOriBO_cSiUhhqwhuZ74TYJ8_ECO3pPiRMWC0q8YPCQg", + "author_xchan": "pgcJx1IQjuPkx8aI9qheJlBMZzJz-oTPjHy3h5pWlOVOriBO_cSiUhhqwhuZ74TYJ8_ECO3pPiRMWC0q8YPCQg", + "source_xchan": "", + "mimetype": "text/bbcode", + "title": "", + "body": "hello world", + "html": "", + "app": "", + "lang": "", + "revision": "0", + "verb": "http://activitystrea.ms/schema/1.0/post", + "obj_type": "http://activitystrea.ms/schema/1.0/note", + "obj": "", + "tgt_type": "", + "target": "", + "layout_mid": "", + "postopts": "", + "route": "", + "llink": "https://xyz.macgirvin.com/display/14135cdecf6b8e3891224e4391748722114da6668eebbcb56fe4667b60b88249@xyz.macgirvin.com", + "plink": "https://xyz.macgirvin.com/channel/mychannel/?f=&mid=14135cdecf6b8e3891224e4391748722114da6668eebbcb56fe4667b60b88249@xyz.macgirvin.com", + "resource_id": "", + "resource_type": "", + "attach": "", + "sig": "sa4TOQNfHtV13HDZ1tuQGWNBpZp-nWhT2GMrZEmelXxa_IvEepD2SEsCTWOBqM8OKPJLfNy8_i-ORXjrOIIgAa_aT8cw5vka7Q0C8L9eEb_LegwQ_BtH0CXO5uT30e_8uowkwzh6kmlVg1ntD8QqrGgD5jTET_fMQOIw4gQUBh40GDG9RB4QnPp_MKsgemGrADnRk2vHO7-bR32yQ0JI-8G-eyeqGaaJmIwkHoi0vXsfjZtU7ijSLuKEBWboNjKEDU89-vQ1c5Kh1r0pmjiDk-a5JzZTYShpuhVA-vQgEcADA7wkf4lJZCYNwu3FRwHTvhSMdF0nmyv3aPFglQDky38-SAXZyQSvd7qlABHGCVVDmYrYaiq7Dh4rRENbAUf-UJFHPCVB7NRg34R8HIqmOKq1Su99bIWaoI2zuAQEVma9wLqMoFsluFhxX58KeVtlCZlro7tZ6z619-dthS_fwt0cL_2dZ3QwjG1P36Q4Y4KrCTpntn9ot5osh-HjVQ01h1I9yNCj6XPgYJ8Im3KT_G4hmMDFM7H9RUrYLl2o9XYyiS2nRrf4aJHa0UweBlAY4zcQG34bw2AMGCY53mwsSArf4Hs3rKu5GrGphuwYX0lHa7XEKMglwBWPWHI49q7-oNWr7aWwn1FnfaMfl4cQppCMtKESMNRKm_nb9Dsh5e0", + "diaspora_meta": "", + "location": "", + "coord": "", + "public_policy": "", + "comment_policy": "contacts", + "allow_cid": "", + "allow_gid": "", + "deny_cid": "", + "deny_gid": "", + "item_restrict": "0", + "item_flags": "0", + "item_private": "0", + "item_origin": "1", + "item_unseen": "0", + "item_starred": "0", + "item_uplink": "0", + "item_consensus": "0", + "item_wall": "1", + "item_thread_top": "1", + "item_notshown": "0", + "item_nsfw": "0", + "item_relay": "0", + "item_mentionsme": "0", + "item_nocomment": "0", + "item_obscured": "0", + "item_verified": "1", + "item_retained": "0", + "item_rss": "0", + "item_deleted": "0", + "item_type": "0", + "item_hidden": "0", + "item_unpublished": "0", + "item_delayed": "0", + "item_pending_remove": "0", + "item_blocked": "0" + } + + } \ No newline at end of file diff --git a/doc/api_posting.bb b/doc/api/api_posting.bb similarity index 100% rename from doc/api_posting.bb rename to doc/api/api_posting.bb diff --git a/doc/api/api_xchan.md b/doc/api/api_xchan.md new file mode 100644 index 000000000..d2b15e04c --- /dev/null +++ b/doc/api/api_xchan.md @@ -0,0 +1,44 @@ +API xchan +========= + +An xchan is a global location independent channel and is the primary record for a network +identity. It may refer to channels on other websites, networks, or services. + +GET /api/z/1.0/xchan + +Required: one of [ address, hash, guid ] as GET parameters + +Returns a portable xchan structure + +Example: https://xyz.macgirvin.com/api/z/1.0/xchan?f=&address=mike@macgirvin.com + +Returns: + + { + "hash": "jr54M_y2l5NgHX5wBvP0KqWcAHuW23p1ld-6Vn63_pGTZklrI36LF8vUHMSKJMD8xzzkz7s2xxCx4-BOLNPaVA", + "guid": "sebQ-IC4rmFn9d9iu17m4BXO-kHuNutWo2ySjeV2SIW1LzksUkss12xVo3m3fykYxN5HMcc7gUZVYv26asx-Pg", + "guid_sig": "Llenlbl4zHo6-g4sa63MlQmTP5dRCrsPmXHHFmoCHG63BLq5CUZJRLS1vRrrr_MNxr7zob_Ykt_m5xPKe5H0_i4pDj-UdP8dPZqH2fqhhx00kuYL4YUMJ8gRr5eO17vsZQ3XxTcyKewtgeW0j7ytwMp6-hFVUx_Cq08MrXas429ZrjzaEwgTfxGnbgeQYQ0R5EXpHpEmoERnZx77VaEahftmdjAUx9R4YKAp13pGYadJOX5xnLfqofHQD8DyRHWeMJ4G1OfWPSOlXfRayrV_jhnFlZjMU7vOdQwHoCMoR5TFsRsHuzd-qepbvo3pzvQZRWnTNu6oPucgbf94p13QbalYRpBXKOxdTXJrGdESNhGvhtaZnpT9c1QVqC46jdfP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Q==\n-----END PUBLIC KEY-----\n", + "photo_mimetype": "image/jpeg", + "photo_l": "https://xyz.macgirvin.com/photo/350b74555c04429148f2e12775f6c403-4", + "photo_m": "https://xyz.macgirvin.com/photo/350b74555c04429148f2e12775f6c403-5", + "photo_s": "https://xyz.macgirvin.com/photo/350b74555c04429148f2e12775f6c403-6", + "address": "mike@macgirvin.com", + "url": "https://macgirvin.com/channel/mike", + "connurl": "https://macgirvin.com/poco/mike", + "follow": "https://macgirvin.com/follow?f=&url=%s", + "connpage": "https://macgirvin.com/connect/mike", + "name": "Mike Macgirvin", + "network": "zot", + "instance_url": "", + "flags": "0", + "photo_date": "2012-12-06 05:06:11", + "name_date": "2012-12-06 04:59:13", + "hidden": "1", + "orphan": "0", + "censored": "0", + "selfcensored": "0", + "system": "0", + "pubforum": "0", + "deleted": "0" + } \ No newline at end of file diff --git a/doc/api/group.md b/doc/api/group.md new file mode 100644 index 000000000..76df1c8e6 --- /dev/null +++ b/doc/api/group.md @@ -0,0 +1,12 @@ +API group +========= + +GET /api/z/1.0/group + + +Description: list privacy groups + + +Returns: DB tables of all privacy groups. To use with API group_members, provide group_id from the id element returned in this call, or group_name from the gname returned in this call. + + \ No newline at end of file diff --git a/doc/api_item_store.md b/doc/api_item_store.md deleted file mode 100644 index 26b6db121..000000000 --- a/doc/api_item_store.md +++ /dev/null @@ -1,104 +0,0 @@ -API item/store -============== - -Usage: POST /api/z/1.0/item/store - -Description: item/store posts an item (typically a conversation item or post, but can be any item) using form input. - - -Required: - -- body - - text/bbcode contents by default. - - -Optional: - -- $_FILES['media'] - uploaded media file to include with post - -- title - title of post/item - -- contact_allow - array of xchan.xchan_hash allowed to view this item - -- group_allow - array of group.hash allowed to view this item - -- contact_deny - array of xchan.xchan_hash not allowed to view this item - -- group_deny - array of group.hash not allowed to view this item - -- coord - geographic coordinates - -- location - freefrom location - -- expire - datetime this post will expire or be removed - -- mimetype - mimetype if not text/bbcode - -- parent - item.id of parent to this post (makes it a comment) - -- parent_mid - alternate form of parent using message_id - -- remote_xchan - xchan.xchan_hash of this message author if not the channel owner - -- consensus - boolean set to true if this is a consensus or voting item (default false) - -- nocomment - boolean set to true if comments are to be disabled (default false) - -- origin - do not use this without reading the code - -- namespace - persistent identity for a remote network or service - -- remote_id - message_id of this resource on a remote network or service - -- message_id - message_id of this item (leave unset to generate one) - -- created - datetime of message creation - -- post_id - existing item.id if this is an edit operation - -- app - application or network name to display with item - -- categories - comma separated categories for this item - -- webpage - item.page_type if not 0 - -- pagetitle - for webpage and design elements, the 'page name' - -- layout_mid - item.mid of layout for this design element - -- plink - permalink for this item if different than the default - -- verb - activitystream verb for this item/activity - -- obj_type - activitystream object type for this item/activity - diff --git a/doc/api_zot.md b/doc/api_zot.md new file mode 100644 index 000000000..3ba536550 --- /dev/null +++ b/doc/api_zot.md @@ -0,0 +1,80 @@ +Zot API +======= + + + +api/z/1.0/channel/export/basic + + Export channel data + + + +api/z/1.0/channel/stream + + Fetch conversation items + + +api/z/1.0/files + + List file storage + +api/z/1.0/filemeta + + Export file metadata for any uploaded file + + +api/z/1.0/filedata + + Export file contents for any uploaded file + + +api/z/1.0/file/export + +api/z/1.0/file + +api/z/1.0/albums + + List photo albums + + +api/z/1.0/photos + + list photo metadata + + +api/z/1.0/photo + + +[api/z/1.0/group](help/api/group) + + List privacy groups + +[api/z/1.0/group_members](help/api/group_members) + + List members of a privacy group + + +[api/z/1.0/xchan](help/api/api_xchan) + + Global extended channel (identity) information + +[api/z/1.0/item/update](help/api/api_item_update) + + Create or update an item (post, activity, webpage, etc.) + + +api/z/1.0/item/full + + Get all data associated with an item + +api/z/1.0/abook + + Connections + +api/z/1.0/abconfig + + Connection metadata (such as permissions) + +api/z/1.0/perm_allowed + + Check a permission for a given xchan diff --git a/include/api_zot.php b/include/api_zot.php index 2bbae244c..256339bad 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -28,8 +28,8 @@ api_register_func('api/z/1.0/group','api_group', true); api_register_func('api/red/xchan','api_red_xchan',true); api_register_func('api/z/1.0/xchan','api_red_xchan',true); - api_register_func('api/red/item/store','red_item_store', true); - api_register_func('api/z/1.0/item/store','red_item_store', true); + api_register_func('api/red/item/update','zot_item_update', true); + api_register_func('api/z/1.0/item/update','zot_item_update', true); api_register_func('api/red/item/full','red_item', true); api_register_func('api/z/1.0/item/full','red_item', true); @@ -266,7 +266,7 @@ require_once('include/hubloc.php'); if($_SERVER['REQUEST_METHOD'] === 'POST') { - $r = xchan_store($_REQUEST); + // $r = xchan_store($_REQUEST); } $r = xchan_fetch($_REQUEST); json_return_and_die($r); @@ -341,7 +341,7 @@ } - function red_item_store($type) { + function zot_item_update($type) { if (api_user() === false) { logger('api_red_item_store: no user'); diff --git a/include/bbcode.php b/include/bbcode.php index 6794fca96..396cbcb29 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -824,12 +824,14 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("(\[h6\](.*?)\[\/h6\])ism",'