2011-03-17 02:36:59 +00:00
|
|
|
<?php
|
|
|
|
|
2013-10-28 04:16:28 +00:00
|
|
|
require_once('include/security.php');
|
2011-03-17 02:36:59 +00:00
|
|
|
require_once('bbcode.php');
|
|
|
|
|
|
|
|
function share_init(&$a) {
|
|
|
|
|
2012-11-03 10:54:19 +00:00
|
|
|
$post_id = ((argc() > 1) ? intval(argv(1)) : 0);
|
2013-10-28 04:16:28 +00:00
|
|
|
|
|
|
|
if(! $post_id)
|
|
|
|
killme();
|
|
|
|
|
2015-01-29 04:58:59 +00:00
|
|
|
if(! (local_channel() || remote_channel()))
|
2011-03-17 02:36:59 +00:00
|
|
|
killme();
|
|
|
|
|
2014-09-03 00:21:12 +00:00
|
|
|
$r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
|
2013-10-28 04:18:33 +00:00
|
|
|
intval($post_id)
|
2011-03-17 02:36:59 +00:00
|
|
|
);
|
2014-09-03 00:21:12 +00:00
|
|
|
if(! $r)
|
|
|
|
killme();
|
|
|
|
if(($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss'))
|
2011-03-17 02:36:59 +00:00
|
|
|
killme();
|
|
|
|
|
2013-10-28 04:16:28 +00:00
|
|
|
$sql_extra = item_permissions_sql($r[0]['uid']);
|
|
|
|
|
|
|
|
$r = q("select * from item where id = %d $sql_extra",
|
|
|
|
intval($post_id)
|
|
|
|
);
|
|
|
|
if(! $r)
|
|
|
|
killme();
|
|
|
|
|
2015-03-21 23:06:08 +00:00
|
|
|
/** @FIXME we only share bbcode */
|
2013-10-28 04:16:28 +00:00
|
|
|
|
|
|
|
if($r[0]['mimetype'] !== 'text/bbcode')
|
|
|
|
killme();
|
|
|
|
|
2015-03-21 23:06:08 +00:00
|
|
|
/** @FIXME eventually we want to post remotely via rpost on your home site */
|
2013-10-28 04:16:28 +00:00
|
|
|
// When that works remove this next bit:
|
|
|
|
|
2015-01-29 04:56:04 +00:00
|
|
|
if(! local_channel())
|
2013-10-28 04:16:28 +00:00
|
|
|
killme();
|
|
|
|
|
2012-11-03 10:54:19 +00:00
|
|
|
xchan_query($r);
|
|
|
|
|
2015-10-27 10:07:40 +00:00
|
|
|
$is_photo = (($r[0]['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false);
|
|
|
|
if($is_photo) {
|
|
|
|
$object = json_decode($r[0]['object'],true);
|
2016-01-13 10:23:40 +00:00
|
|
|
$photo_bb = $object['body'];
|
2015-10-27 10:07:40 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 03:06:31 +00:00
|
|
|
if (strpos($r[0]['body'], "[/share]") !== false) {
|
|
|
|
$pos = strpos($r[0]['body'], "[share");
|
|
|
|
$o = substr($r[0]['body'], $pos);
|
|
|
|
} else {
|
2013-09-06 12:25:10 +00:00
|
|
|
$o = "[share author='".urlencode($r[0]['author']['xchan_name']).
|
2013-02-26 03:06:31 +00:00
|
|
|
"' profile='".$r[0]['author']['xchan_url'] .
|
|
|
|
"' avatar='".$r[0]['author']['xchan_photo_s'].
|
|
|
|
"' link='".$r[0]['plink'].
|
2014-05-05 23:16:32 +00:00
|
|
|
"' posted='".$r[0]['created'].
|
2015-01-28 07:56:56 +00:00
|
|
|
"' message_id='".$r[0]['mid']."']";
|
2013-02-26 03:06:31 +00:00
|
|
|
if($r[0]['title'])
|
2015-10-27 10:07:40 +00:00
|
|
|
$o .= '[b]'.$r[0]['title'].'[/b]'."\r\n";
|
2015-10-27 10:26:48 +00:00
|
|
|
$o .= (($is_photo) ? $photo_bb . "\r\n" . $r[0]['body'] : $r[0]['body']);
|
2015-10-27 10:07:40 +00:00
|
|
|
$o .= "[/share]";
|
2013-02-26 03:06:31 +00:00
|
|
|
}
|
2012-06-23 10:25:11 +00:00
|
|
|
|
2015-01-29 04:56:04 +00:00
|
|
|
if(local_channel()) {
|
2013-10-28 04:16:28 +00:00
|
|
|
echo $o;
|
|
|
|
killme();
|
|
|
|
}
|
2015-03-21 23:06:08 +00:00
|
|
|
|
2013-10-28 04:16:28 +00:00
|
|
|
$observer = $a->get_observer();
|
|
|
|
$parsed = $observer['xchan_url'];
|
|
|
|
if($parsed) {
|
|
|
|
$post_url = $parsed['scheme'] . ':' . $parsed['host'] . (($parsed['port']) ? ':' . $parsed['port'] : '')
|
|
|
|
. '/rpost';
|
2015-03-21 23:06:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @FIXME we were probably called from JS so we don't know the return page.
|
|
|
|
* In fact we won't be able to load the remote page.
|
|
|
|
* we might need an iframe
|
|
|
|
*/
|
2013-10-28 04:16:28 +00:00
|
|
|
|
|
|
|
$x = z_post_url($post_url, array('f' => '', 'body' => $o ));
|
|
|
|
killme();
|
|
|
|
}
|
2011-04-10 10:36:12 +00:00
|
|
|
}
|