aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Module')
-rw-r--r--Zotlabs/Module/Api.php54
-rw-r--r--Zotlabs/Module/Like.php9
-rw-r--r--Zotlabs/Module/Thing.php104
3 files changed, 89 insertions, 78 deletions
diff --git a/Zotlabs/Module/Api.php b/Zotlabs/Module/Api.php
index aa0fca54d..5b835ac51 100644
--- a/Zotlabs/Module/Api.php
+++ b/Zotlabs/Module/Api.php
@@ -24,42 +24,42 @@ class Api extends \Zotlabs\Web\Controller {
notice( t('Permission denied.') . EOL);
return;
}
-
+
}
-
+
function get() {
if(\App::$cmd === 'api/oauth/authorize'){
-
- /*
+
+ /*
* api/oauth/authorize interact with the user. return a standard page
*/
-
+
\App::$page['template'] = 'minimal';
-
+
// get consumer/client from request token
try {
$request = \OAuth1Request::from_request();
}
catch(\Exception $e) {
logger('OAuth exception: ' . print_r($e,true));
- // echo "<pre>"; var_dump($e);
+ // echo "<pre>"; var_dump($e);
killme();
}
-
-
+
+
if(x($_POST,'oauth_yes')){
-
+
$app = $this->oauth_get_client($request);
- if (is_null($app))
+ if (is_null($app))
return "Invalid request. Unknown token.";
$consumer = new \OAuth1Consumer($app['client_id'], $app['pw'], $app['redirect_uri']);
-
+
$verifier = md5($app['secret'] . local_channel());
set_config('oauth', $verifier, local_channel());
-
-
+
+
if($consumer->callback_url != null) {
$params = $request->get_parameters();
$glue = '?';
@@ -68,28 +68,28 @@ class Api extends \Zotlabs\Web\Controller {
goaway($consumer->callback_url . $glue . "oauth_token=" . \OAuth1Util::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . \OAuth1Util::urlencode_rfc3986($verifier));
killme();
}
-
+
$tpl = get_markup_template("oauth_authorize_done.tpl");
$o = replace_macros($tpl, array(
'$title' => t('Authorize application connection'),
'$info' => t('Return to your app and insert this Security Code:'),
'$code' => $verifier,
));
-
+
return $o;
}
-
-
+
+
if(! local_channel()) {
//TODO: we need login form to redirect to this page
notice( t('Please login to continue.') . EOL );
return login(false,'api-login',$request->get_parameters());
}
-
+
$app = $this->oauth_get_client($request);
if (is_null($app))
return "Invalid request. Unknown token.";
-
+
$tpl = get_markup_template('oauth_authorize.tpl');
$o = replace_macros($tpl, array(
'$title' => t('Authorize application connection'),
@@ -98,12 +98,12 @@ class Api extends \Zotlabs\Web\Controller {
'$yes' => t('Yes'),
'$no' => t('No'),
));
-
+
//echo "<pre>"; var_dump($app); killme();
-
+
return $o;
}
-
+
echo api_call();
killme();
}
@@ -112,8 +112,8 @@ class Api extends \Zotlabs\Web\Controller {
$params = $request->get_parameters();
$token = $params['oauth_token'];
-
- $r = q("SELECT clients.* FROM clients, tokens WHERE clients.client_id = tokens.client_id
+
+ $r = q("SELECT clients.* FROM clients, tokens WHERE clients.client_id = tokens.client_id
AND tokens.id = '%s' AND tokens.auth_scope = 'request' ",
dbesc($token)
);
@@ -121,7 +121,7 @@ class Api extends \Zotlabs\Web\Controller {
return $r[0];
return null;
-
+
}
-
+
}
diff --git a/Zotlabs/Module/Like.php b/Zotlabs/Module/Like.php
index 86ae48365..4460900a8 100644
--- a/Zotlabs/Module/Like.php
+++ b/Zotlabs/Module/Like.php
@@ -211,7 +211,7 @@ class Like extends Controller {
$post_type = t('thing');
$obj_type = 'Profile';
- $tgttype = ACTIVITY_OBJ_THING;
+ $tgttype = 'Page';
$links = array();
$links[] = array('rel' => 'alternate', 'type' => 'text/html',
@@ -219,12 +219,7 @@ class Like extends Controller {
if ($r[0]['imgurl'])
$links[] = array('rel' => 'photo', 'href' => $r[0]['obj_imgurl']);
- $target = json_encode(array(
- 'type' => $tgttype,
- 'title' => $r[0]['obj_term'],
- 'id' => z_root() . '/thing/' . $r[0]['obj_obj'],
- 'link' => $links
- ));
+ $target = Activity::fetch_thing(['id' => $r[0]['obj_obj']]);
$plink = '[zrl=' . z_root() . '/thing/' . $r[0]['obj_obj'] . ']' . $r[0]['obj_term'] . '[/zrl]';
diff --git a/Zotlabs/Module/Thing.php b/Zotlabs/Module/Thing.php
index b065b0022..d51310b3a 100644
--- a/Zotlabs/Module/Thing.php
+++ b/Zotlabs/Module/Thing.php
@@ -6,26 +6,45 @@
namespace Zotlabs\Module;
use Zotlabs\Lib\Libsync;
-
-require_once('include/items.php');
-require_once('include/security.php');
-require_once('include/selectors.php');
-require_once('include/acl_selectors.php');
+use Zotlabs\Lib\Activity;
+use Zotlabs\Lib\ActivityStreams;
+use Zotlabs\Lib\Libzot;
class Thing extends \Zotlabs\Web\Controller {
function init() {
+ if (argv(1) && ActivityStreams::is_as_request()) {
+ $r = q("select obj_channel from obj where obj_type = %d and obj_obj = '%s' limit 1",
+ intval(TERM_OBJ_THING),
+ dbesc(argv(1))
+ );
- if(! local_channel())
- return;
+ if($r) {
+ $sql_extra = permissions_sql($r[0]['obj_channel']);
+ }
- $channel = \App::get_channel();
+ $r = q("select * from obj where obj_type = %d and obj_obj = '%s' $sql_extra limit 1",
+ intval(TERM_OBJ_THING),
+ dbesc(argv(1))
+ );
- if($_SERVER['REQUEST_METHOD'] === 'GET' && argc() < 2) {
- profile_load($channel['channel_address']);
+ if ($r) {
+ $channel = channelx_by_n($r[0]['obj_channel']);
+ as_return_and_die(Activity::fetch_thing(['id' => $r[0]['obj_obj']]), $channel);
+ }
+
+ http_status_exit(404, 'Not found');
}
+ }
+
+ function post() {
+
+ if(! local_channel())
+ return;
+
+ $channel = \App::get_channel();
$term_hash = (($_REQUEST['term_hash']) ? $_REQUEST['term_hash'] : '');
@@ -36,7 +55,7 @@ class Thing extends \Zotlabs\Web\Controller {
$url = $_REQUEST['url'];
$photo = $_REQUEST['img'];
- $hash = random_string();
+ $hash = new_uuid();
$verbs = obj_verbs();
@@ -77,13 +96,7 @@ class Thing extends \Zotlabs\Web\Controller {
return;
$acl = new \Zotlabs\Access\AccessList($channel);
-
- if(array_key_exists('contact_allow',$_REQUEST)
- || array_key_exists('group_allow',$_REQUEST)
- || array_key_exists('contact_deny',$_REQUEST)
- || array_key_exists('group_deny',$_REQUEST)) {
- $acl->set_from_array($_REQUEST);
- }
+ $acl->set_from_array($_REQUEST);
$x = $acl->get();
@@ -181,28 +194,20 @@ class Thing extends \Zotlabs\Web\Controller {
intval(local_channel()),
dbesc($hash)
);
+
if($r) {
Libsync::build_sync_packet(0, array('obj' => $r));
}
if($activity) {
- $arr = array();
- $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $url));
- if($local_photo)
- $links[] = array('rel' => 'photo', 'type' => $local_photo_type, 'href' => $local_photo);
- $objtype = ACTIVITY_OBJ_THING;
-
- $obj = json_encode(array(
- 'type' => $objtype,
- 'id' => $url,
- 'link' => $links,
- 'title' => $name,
- 'content' => $name
- ));
+ $obj = Activity::fetch_thing(['id' => $r[0]['obj_obj']]);
$bodyverb = str_replace('OBJ: ', '',t('OBJ: %1$s %2$s %3$s'));
+ $arr['uuid'] = $r[0]['obj_obj'];
+ $arr['mid'] = z_root() . '/thing/' . $arr['uuid'];
+
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['author_xchan'] = $channel['channel_hash'];
@@ -213,29 +218,37 @@ class Thing extends \Zotlabs\Web\Controller {
$ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]';
$plink = '[zrl=' . $url . ']' . $name . '[/zrl]';
- $arr['body'] = sprintf( $bodyverb, $ulink, $translated_verb, $plink );
+ $arr['body'] = sprintf($bodyverb, $ulink, $translated_verb, $plink);
if($local_photo)
- $arr['body'] .= "\n\n[zmg]" . $local_photo . "[/zmg]";
+ $arr['body'] .= "\n\n" . '[zmg]' . $local_photo . '[/zmg]';
- $arr['verb'] = $verb;
- $arr['obj_type'] = $objtype;
+ $arr['verb'] = 'Create';
+ $arr['obj_type'] = 'Page';
$arr['obj'] = $obj;
- if(! $profile['is_default']) {
+ $arr['allow_cid'] = $x['allow_cid'];
+ $arr['allow_gid'] = $x['allow_gid'];
+ $arr['deny_cid'] = $x['deny_cid'];
+ $arr['deny_gid'] = $x['deny_gid'];
+
+ if (!$profile['is_default']) {
$arr['item_private'] = true;
- $str = '';
+
$r = q("select abook_xchan from abook where abook_channel = %d and abook_profile = '%s'",
intval(local_channel()),
dbesc($profile_guid)
);
+
if($r) {
$arr['allow_cid'] = '';
- foreach($r as $rr)
+ foreach($r as $rr) {
$arr['allow_cid'] .= '<' . $rr['abook_xchan'] . '>';
+ }
}
- else
+ else {
$arr['allow_cid'] = '<' . get_observer_hash() . '>';
+ }
}
$ret = post_activity_item($arr);
@@ -263,12 +276,16 @@ class Thing extends \Zotlabs\Web\Controller {
);
if($r) {
+ $channel = channelx_by_n($r[0]['obj_channel']);
+ profile_load($channel['channel_address']);
+
return replace_macros(get_markup_template('show_thing.tpl'), array(
- '$header' => t('Show Thing'),
+ '$header' => $channel['xchan_name'] . ' ' . $r[0]['obj_verb'],
'$edit' => t('Edit'),
'$delete' => t('Delete'),
'$canedit' => ((local_channel() && local_channel() == $r[0]['obj_channel']) ? true : false),
- '$thing' => $r[0] ));
+ '$thing' => $r[0]
+ ));
}
else {
notice( t('item not found.') . EOL);
@@ -319,7 +336,7 @@ class Thing extends \Zotlabs\Web\Controller {
'$img_lbl' => t('URL for photo of thing (optional)'),
'$imgurl' => $r[0]['obj_imgurl'],
'$permissions' => t('Permissions'),
- '$aclselect' => populate_acl($channel_acl,false),
+ '$aclselect' => populate_acl($channel_acl, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_pages')),
'$allow_cid' => acl2json($channel_acl['allow_cid']),
'$allow_gid' => acl2json($channel_acl['allow_gid']),
'$deny_cid' => acl2json($channel_acl['deny_cid']),
@@ -344,7 +361,6 @@ class Thing extends \Zotlabs\Web\Controller {
return '';
}
-
delete_thing_photo($r[0]['obj_imgurl'],get_observer_hash());
$x = q("delete from obj where obj_obj = '%s' and obj_type = %d and obj_channel = %d",
@@ -372,7 +388,7 @@ class Thing extends \Zotlabs\Web\Controller {
'$url_lbl' => t('URL of thing (optional)'),
'$img_lbl' => t('URL for photo of thing (optional)'),
'$permissions' => t('Permissions'),
- '$aclselect' => populate_acl($channel_acl,false),
+ '$aclselect' => populate_acl($channel_acl, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_pages')),
'$allow_cid' => acl2json($channel_acl['allow_cid']),
'$allow_gid' => acl2json($channel_acl['allow_gid']),
'$deny_cid' => acl2json($channel_acl['deny_cid']),