aboutsummaryrefslogtreecommitdiffstats
path: root/mod/thing.php
diff options
context:
space:
mode:
Diffstat (limited to 'mod/thing.php')
-rw-r--r--mod/thing.php240
1 files changed, 188 insertions, 52 deletions
diff --git a/mod/thing.php b/mod/thing.php
index 91bdca78a..cbf83fdf8 100644
--- a/mod/thing.php
+++ b/mod/thing.php
@@ -1,6 +1,7 @@
<?php /** @file */
require_once('include/items.php');
+require_once('include/contact_selectors.php');
function thing_init(&$a) {
@@ -8,15 +9,20 @@ function thing_init(&$a) {
if(! local_user())
return;
+
+
+
$account_id = $a->get_account();
$channel = $a->get_channel();
+ $term_hash = (($_REQUEST['term_hash']) ? $_REQUEST['term_hash'] : '');
$name = escape_tags($_REQUEST['term']);
$verb = escape_tags($_REQUEST['verb']);
- $profile_guid = escape_tags($_REQUEST['profile']);
+ $activity = intval($_REQUEST['activity']);
+ $profile_guid = escape_tags($_REQUEST['profile_assign']);
$url = $_REQUEST['link'];
- $photo = $_REQUEST['photo'];
+ $photo = $_REQUEST['img'];
$hash = random_string();
@@ -59,15 +65,58 @@ function thing_init(&$a) {
if((! $name) || (! $translated_verb))
return;
+
+
+
+
+ if($term_hash) {
+ $t = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1",
+ intval(TERM_OBJ_THING),
+ dbesc($term_hash)
+ );
+ if(! $t) {
+ notice( t('Item not found.') . EOL);
+ return;
+ }
+ $orig_record = $t[0];
+ if($photo != $orig_record['imgurl']) {
+ $arr = import_profile_photo($photo,get_observer_hash(),true);
+ $local_photo = $arr[0];
+ $local_photo_type = $arr[3];
+ }
+ else
+ $local_photo = $orig_record['imgurl'];
+
+ $r = q("update term set term = '%s', url = '%s', imgurl = '%s' where term_hash = '%s' and uid = %d limit 1",
+ dbesc($name),
+ dbesc(($url) ? $url : z_root() . '/thing/' . $term_hash),
+ dbesc($local_photo),
+ dbesc($term_hash),
+ intval(local_user())
+ );
+
+ info( t('Thing updated') . EOL);
+ return;
+ }
+
$sql = (($profile_guid) ? " and profile_guid = '" . dbesc($profile_guid) . "' " : " and is_default = 1 ");
$p = q("select profile_guid, is_default from profile where uid = %d $sql limit 1",
intval(local_user())
);
+
if($p)
$profile = $p[0];
else
return;
+ $local_photo = null;
+
+ if($photo) {
+ $arr = import_profile_photo($photo,get_observer_hash(),true);
+ $local_photo = $arr[0];
+ $local_photo_type = $arr[3];
+ }
+
$r = q("select * from term where uid = %d and otype = %d and type = %d and term = '%s' limit 1",
intval(local_user()),
@@ -85,7 +134,7 @@ function thing_init(&$a) {
intval(TERM_THING),
dbesc($name),
dbesc(($url) ? $url : z_root() . '/thing/' . $hash),
- dbesc(($photo) ? $photo : ''),
+ dbesc(($photo) ? $local_photo : ''),
dbesc($hash)
);
$r = q("select * from term where uid = %d and otype = %d and type = %d and term = '%s' limit 1",
@@ -110,83 +159,170 @@ function thing_init(&$a) {
return;
}
- info( t('thing/stuff added'));
+ info( t('Thing added'));
- $arr = array();
- $links = array(array('rel' => 'alternate','type' => 'text/html',
- 'href' => $term['url']));
- $objtype = ACTIVITY_OBJ_THING;
+ if($activity) {
+ $arr = array();
+ $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $term['url']));
+ if($local_photo)
+ $links[] = array('rel' => 'photo', 'type' => $local_photo_type, 'href' => $local_photo);
- $obj = json_encode(array(
- 'type' => $objtype,
- 'id' => $term['url'],
- 'link' => $links,
- 'title' => $term['term'],
- 'content' => $term['term']
- ));
- $bodyverb = str_replace('OBJ: ', '',t('OBJ: %1$s %2$s %3$s'));
+ $objtype = ACTIVITY_OBJ_THING;
- $arr['owner_xchan'] = $channel['channel_hash'];
- $arr['author_xchan'] = $channel['channel_hash'];
+ $obj = json_encode(array(
+ 'type' => $objtype,
+ 'id' => $term['url'],
+ 'link' => $links,
+ 'title' => $term['term'],
+ 'content' => $term['term']
+ ));
+ $bodyverb = str_replace('OBJ: ', '',t('OBJ: %1$s %2$s %3$s'));
- $arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL|ITEM_THREAD_TOP;
+ $arr['owner_xchan'] = $channel['channel_hash'];
+ $arr['author_xchan'] = $channel['channel_hash'];
+
+
+ $arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL|ITEM_THREAD_TOP;
+
+ $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]';
+ $plink = '[zrl=' . $term['url'] . ']' . $term['term'] . '[/zrl]';
+
+ $arr['body'] = sprintf( $bodyverb, $ulink, $translated_verb, $plink );
+
+ if($local_photo)
+ $arr['body'] .= "\n\n[zmg]" . $local_photo . "[/zmg]";
+
+ $arr['verb'] = $verb;
+ $arr['obj_type'] = $objtype;
+ $arr['object'] = $obj;
+
+ 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_user()),
+ dbesc($profile_guid)
+ );
+ if($r) {
+ $arr['allow_cid'] = '';
+ foreach($r as $rr)
+ $arr['allow_cid'] .= '<' . $rr['abook_xchan'] . '>';
+ }
+ else
+ $arr['allow_cid'] = '<' . get_observer_hash() . '>';
+ }
- $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]';
- $plink = '[zrl=' . $term['url'] . ']' . $term['term'] . '[/zrl]';
+ $ret = post_activity_item($arr);
+ }
+}
- $arr['body'] = sprintf( $bodyverb, $ulink, $translated_verb, $plink );
- $arr['verb'] = $verb;
- $arr['obj_type'] = $objtype;
- $arr['object'] = $obj;
+function thing_content(&$a) {
+
+ if(argc() == 2) {
- if(! $profile['is_default']) {
- $arr['item_private'] = true;
- $str = '';
- $r = q("select abook_hash from abook where abook_channel = %d and abook_profile = '%s'",
- intval(local_user()),
- dbesc($profile_guid)
+ $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1",
+ intval(TERM_OBJ_THING),
+ dbesc(argv(1))
);
+
if($r) {
- $arr['allow_cid'] = '';
- foreach($r as $rr)
- $arr['allow_cid'] .= '<' . $rr['abook_hash'] . '>';
+ return replace_macros(get_markup_template('show_thing.tpl'), array(
+ '$header' => t('Show Thing'),
+ '$edit' => t('Edit'),
+ '$delete' => t('Delete'),
+ '$canedit' => ((local_user() && local_user() == $r[0]['obj_channel']) ? true : false),
+ '$thing' => $r[0] ));
+ }
+ else {
+ notice( t('item not found.') . EOL);
+ return;
}
- else
- $arr['allow_cid'] = '<' . get_observer_hash() . '>';
}
-
- $ret = post_activity_item($arr);
- if($ret['success'])
- proc_run('php','include/notifier.php','tag',$ret['activity']['id']);
-
-}
+ if(! local_user()) {
+ notice( t('Permission denied.') . EOL);
+ return;
+ }
+ $thing_hash = '';
+
+ if(argc() == 3 && argv(1) === 'edit') {
+ $thing_hash = argv(2);
-function thing_content(&$a) {
-
- /* placeholders */
- if(argc() > 1) {
- return t('not yet implemented.');
+ $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1",
+ intval(TERM_OBJ_THING),
+ dbesc($thing_hash)
+ );
+
+ if((! $r) || ($r[0]['obj_channel'] != local_user())) {
+ notice( t('Permission denied.') . EOL);
+ return '';
+ }
+
+
+ $o .= replace_macros(get_markup_template('thing_edit.tpl'),array(
+ '$thing_hdr' => t('Edit Thing'),
+ '$multiprof' => feature_enabled(local_user(),'multi_profiles'),
+ '$profile_lbl' => t('Select a profile'),
+ '$profile_select' => contact_profile_assign($r[0]['obj_page']),
+ '$verb_lbl' => t('Select a category of stuff. e.g. I ______ something'),
+ '$verb_select' => obj_verb_selector($r[0]['obj_verb']),
+ '$activity' => array('activity',t('Post an activity'),true,t('Only sends to viewers of the applicable profile')),
+ '$thing_hash' => $thing_hash,
+ '$thing_lbl' => t('Name of thing e.g. something'),
+ '$thething' => $r[0]['term'],
+ '$url_lbl' => t('URL of thing (optional)'),
+ '$theurl' => $r[0]['url'],
+ '$img_lbl' => t('URL for photo of thing (optional)'),
+ '$imgurl' => $r[0]['imgurl'],
+ '$submit' => t('Submit')
+ ));
+
+ return $o;
}
- require_once('include/contact_selectors.php');
+ if(argc() == 3 && argv(1) === 'drop') {
+ $thing_hash = argv(2);
+
+ $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1",
+ intval(TERM_OBJ_THING),
+ dbesc($thing_hash)
+ );
+
+ if((! $r) || ($r[0]['obj_channel'] != local_user())) {
+ notice( t('Permission denied.') . EOL);
+ return '';
+ }
+
+
+ $x = q("delete from obj where obj_obj = '%s' and obj_type = %d and obj_channel = %d limit 1",
+ dbesc($thing_hash),
+ intval(TERM_OBJ_THING),
+ intval(local_user())
+ );
+ $x = q("delete from term where term_hash = '%s' and uid = %d limit 1",
+ dbesc($thing_hash),
+ intval(local_user())
+ );
+ return $o;
+ }
$o .= replace_macros(get_markup_template('thing_input.tpl'),array(
- '$thing_hdr' => t('Add Stuff to your Profile'),
+ '$thing_hdr' => t('Add Thing to your Profile'),
'$multiprof' => feature_enabled(local_user(),'multi_profiles'),
'$profile_lbl' => t('Select a profile'),
'$profile_select' => contact_profile_assign(''),
'$verb_lbl' => t('Select a category of stuff. e.g. I ______ something'),
+ '$activity' => array('activity',t('Post an activity'),true,t('Only sends to viewers of the applicable profile')),
'$verb_select' => obj_verb_selector(),
- '$thing_lbl' => t('Name of thing or stuff e.g. something'),
- '$url_lbl' => t('URL of thing or stuff (optional)'),
- '$img_lbl' => t('URL for photo of thing or stuff (optional)'),
+ '$thing_lbl' => t('Name of thing e.g. something'),
+ '$url_lbl' => t('URL of thing (optional)'),
+ '$img_lbl' => t('URL for photo of thing (optional)'),
'$submit' => t('Submit')
));