aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Import/import_diaspora.php5
-rw-r--r--include/api.php49
-rw-r--r--include/attach.php44
-rw-r--r--include/chat.php2
-rw-r--r--include/conversation.php1
-rw-r--r--include/event.php16
-rw-r--r--include/identity.php60
-rw-r--r--include/import.php430
-rwxr-xr-xinclude/items.php38
-rw-r--r--include/menu.php14
-rw-r--r--include/message.php1
-rw-r--r--include/network.php2
-rw-r--r--include/photos.php7
-rw-r--r--include/security.php4
-rw-r--r--include/widgets.php65
-rw-r--r--include/zot.php41
16 files changed, 733 insertions, 46 deletions
diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php
index fca9fa4f2..a0f473b50 100644
--- a/include/Import/import_diaspora.php
+++ b/include/Import/import_diaspora.php
@@ -57,6 +57,10 @@ function import_diaspora($data) {
$channel_id = $c['channel']['channel_id'];
+ // Hubzilla only: Turn on the Diaspora protocol so that follow requests will be sent.
+
+ set_pconfig($channel_id,'system','diaspora_allowed','1');
+
// todo - add auto follow settings, (and strip exif in hubzilla)
$location = escape_tags($data['user']['profile']['location']);
@@ -70,7 +74,6 @@ function import_diaspora($data) {
);
if($data['user']['profile']['nsfw']) {
- // fixme for hubzilla which doesn't use pageflags any more
q("update channel set channel_pageflags = (channel_pageflags | %d) where channel_id = %d",
intval(PAGE_ADULT),
intval($channel_id)
diff --git a/include/api.php b/include/api.php
index 6d71cfc33..a77bf15f7 100644
--- a/include/api.php
+++ b/include/api.php
@@ -896,6 +896,55 @@ require_once('include/items.php');
api_register_func('api/red/item/new','red_item_new', true);
+ function red_item(&$a, $type) {
+
+ if (api_user() === false) {
+ logger('api_red_item_new: no user');
+ return false;
+ }
+
+ if($_REQUEST['mid']) {
+ $arr = array('mid' => $_REQUEST['mid']);
+ }
+ elseif($_REQUEST['item_id']) {
+ $arr = array('item_id' => $_REQUEST['item_id']);
+ }
+ else
+ json_return_and_die(array());
+
+ $arr['start'] = 0;
+ $arr['records'] = 999999;
+ $arr['item_type'] = '*';
+
+ $i = items_fetch($arr,$a->get_channel(),get_observer_hash());
+
+ if(! $i)
+ json_return_and_die(array());
+
+ $ret = array();
+ $tmp = array();
+ $str = '';
+ foreach($i as $ii) {
+ $tmp[] = encode_item($ii,true);
+ if($str)
+ $str .= ',';
+ $str .= $ii['id'];
+ }
+ $ret['item'] = $tmp;
+ if($str) {
+ $r = q("select item_id.*, item.mid from item_id left join item on item_id.iid = item.id where item.id in ( $str ) ");
+
+ if($r)
+ $ret['item_id'] = $r;
+ }
+
+ json_return_and_die($ret);
+ }
+
+ api_register_func('api/red/item/full','red_item', true);
+
+
+
function api_get_status($xchan_hash) {
require_once('include/security.php');
diff --git a/include/attach.php b/include/attach.php
index 620c7620c..513486bfc 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -405,6 +405,9 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
require_once('include/photos.php');
+
+ call_hooks('photo_upload_begin',$arr);
+
$ret = array('success' => false);
$channel_id = $channel['channel_id'];
$sql_options = '';
@@ -451,15 +454,28 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$hash = $arr['resource_id'];
}
elseif($options !== 'update') {
- if(! x($_FILES,'userfile')) {
- $ret['message'] = t('No source file.');
- return $ret;
- }
+ $f = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
- $src = $_FILES['userfile']['tmp_name'];
- $filename = basename($_FILES['userfile']['name']);
- $filesize = intval($_FILES['userfile']['size']);
+ call_hooks('photo_upload_file',$f);
+ call_hooks('attach_upload_file',$f);
+ if (x($f,'src') && x($f,'filesize')) {
+ $src = $f['src'];
+ $filename = $f['filename'];
+ $filesize = $f['filesize'];
+ $type = $f['type'];
+
+ } else {
+
+ if(! x($_FILES,'userfile')) {
+ $ret['message'] = t('No source file.');
+ return $ret;
+ }
+
+ $src = $_FILES['userfile']['tmp_name'];
+ $filename = basename($_FILES['userfile']['name']);
+ $filesize = intval($_FILES['userfile']['size']);
+ }
}
$existing_size = 0;
@@ -615,6 +631,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if(($maxfilesize) && ($filesize > $maxfilesize)) {
$ret['message'] = sprintf( t('File exceeds size limit of %d'), $maxfilesize);
@unlink($src);
+ call_hooks('photo_upload_end',$ret);
return $ret;
}
@@ -627,10 +644,11 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if(($r) && (($r[0]['total'] + $filesize) > ($limit - $existing_size))) {
$ret['message'] = upgrade_message(true) . sprintf(t("You have reached your limit of %1$.0f Mbytes attachment storage."), $limit / 1024000);
@unlink($src);
+ call_hooks('photo_upload_end',$ret);
return $ret;
}
}
- $mimetype = z_mime_content_type($filename);
+ $mimetype = ((isset($type) && $type) ? $type : z_mime_content_type($filename));
}
$os_basepath = 'store/' . $channel['channel_address'] . '/' ;
@@ -658,7 +676,6 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
else
$edited = $created;
-
if($options === 'replace') {
$r = q("update attach set filename = '%s', filetype = '%s', folder = '%s', filesize = %d, os_storage = %d, is_photo = %d, data = '%s', edited = '%s' where id = %d and uid = %d",
dbesc($filename),
@@ -714,6 +731,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
);
}
else {
+
$r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, filetype, folder, filesize, revision, os_storage, is_photo, data, created, edited, allow_cid, allow_gid,deny_cid, deny_gid )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
intval($channel['channel_account_id']),
@@ -738,6 +756,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
}
if($is_photo) {
+
$args = array( 'source' => $source, 'visible' => 0, 'resource_id' => $hash, 'album' => basename($pathname), 'os_path' => $os_basepath . $os_relpath, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct);
if($arr['contact_allow'])
$args['contact_allow'] = $arr['contact_allow'];
@@ -772,6 +791,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if(! $r) {
$ret['message'] = t('File upload failed. Possible system limit or action terminated.');
+ call_hooks('photo_upload_end',$ret);
return $ret;
}
@@ -784,13 +804,17 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if(! $r) {
$ret['message'] = t('Stored file could not be verified. Upload failed.');
+ call_hooks('photo_upload_end',$ret);
return $ret;
}
$ret['success'] = true;
$ret['data'] = $r[0];
-
+ if(! $is_photo) {
+ // This would've been called already with a success result in photos_upload() if it was a photo.
+ call_hooks('photo_upload_end',$ret);
+ }
return $ret;
}
diff --git a/include/chat.php b/include/chat.php
index 05bb02bb9..a0646265a 100644
--- a/include/chat.php
+++ b/include/chat.php
@@ -91,6 +91,8 @@ function chatroom_destroy($channel,$arr) {
return $ret;
}
+ create_sync_packet($channel['channel_id'],array('chatroom' => $r));
+
q("delete from chatroom where cr_id = %d",
intval($r[0]['cr_id'])
);
diff --git a/include/conversation.php b/include/conversation.php
index a3fdf39df..fb8ef8585 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -1137,6 +1137,7 @@ function status_editor($a, $x, $popup = false) {
'$newpost' => 'true',
'$baseurl' => $a->get_baseurl(true),
'$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
+ '$pretext' => ((x($x,'pretext')) ? $x['pretext'] : ''),
'$geotag' => $geotag,
'$nickname' => $x['nickname'],
'$ispublic' => t('Visible to <strong>everybody</strong>'),
diff --git a/include/event.php b/include/event.php
index 6670bc53b..44c172e98 100644
--- a/include/event.php
+++ b/include/event.php
@@ -446,6 +446,20 @@ function event_addtocal($item_id, $uid) {
intval($channel['channel_id'])
);
+ $item['resource_id'] = $event['event_hash'];
+ $item['resource_type'] = 'event';
+
+ $i = array($item);
+ xchan_query($i);
+ $sync_item = fetch_post_tags($i);
+ $z = q("select * from event where event_hash = '%s' and uid = %d limit 1",
+ dbesc($event['event_hash']),
+ intval($channel['channel_id'])
+ );
+ if($z) {
+ build_sync_packet($channel['channel_id'],array('event_item' => array(encode_item($sync_item[0],true)),'event' => $z));
+ }
+
return true;
}
}
@@ -959,4 +973,4 @@ function tasks_fetch($arr) {
return $ret;
-} \ No newline at end of file
+}
diff --git a/include/identity.php b/include/identity.php
index 115baddc1..b5235e7ff 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -5,7 +5,7 @@
require_once('include/zot.php');
require_once('include/crypto.php');
-
+require_once('include/menu.php');
/**
* @brief Called when creating a new channel.
@@ -566,13 +566,57 @@ function identity_basic_export($channel_id, $items = false) {
if($r)
$ret['obj'] = $r;
-
$r = q("select * from app where app_channel = %d",
intval($channel_id)
);
if($r)
$ret['app'] = $r;
+ $r = q("select * from chatroom where cr_uid = %d",
+ intval($channel_id)
+ );
+ if($r)
+ $ret['chatroom'] = $r;
+
+
+ $r = q("select * from event where uid = %d",
+ intval($channel_id)
+ );
+ if($r)
+ $ret['event'] = $r;
+
+ $r = q("select * from item where resource_type = 'event' and uid = %d",
+ intval($channel_id)
+ );
+ if($r) {
+ $ret['event_item'] = array();
+ xchan_query($r);
+ $r = fetch_post_tags($r,true);
+ foreach($r as $rr)
+ $ret['event_item'][] = encode_item($rr,true);
+ }
+
+ $x = menu_list($channel_id);
+ if($x) {
+ $ret['menu'] = array();
+ for($y = 0; $y < count($x); $y ++) {
+ $m = menu_fetch($x[$y]['menu_name'],$channel_id,$ret['channel']['channel_hash']);
+ if($m)
+ $ret['menu'][] = menu_element($m);
+ }
+ }
+
+ $x = menu_list($channel_id);
+ if($x) {
+ $ret['menu'] = array();
+ for($y = 0; $y < count($x); $y ++) {
+ $m = menu_fetch($x[$y]['menu_name'],$channel_id,$ret['channel']['channel_hash']);
+ if($m)
+ $ret['menu'][] = menu_element($m);
+ }
+ }
+
+
if(! $items)
return $ret;
@@ -594,14 +638,17 @@ function identity_basic_export($channel_id, $items = false) {
/** @warning this may run into memory limits on smaller systems */
- /** export one year of posts. If you want to export and import all posts you have to start with
+
+ /** export three months of posts. If you want to export and import all posts you have to start with
* the first year and export/import them in ascending order.
+ *
+ * Don't export linked resource items. we'll have to pull those out separately.
*/
- $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d and created > %s - INTERVAL %s",
+ $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d and created > %s - INTERVAL %s and resource_type = '' order by created",
intval($channel_id),
db_utcnow(),
- db_quoteinterval('1 YEAR')
+ db_quoteinterval('3 MONTH')
);
if($r) {
$ret['item'] = array();
@@ -635,7 +682,7 @@ function identity_export_year($channel_id,$year,$month = 0) {
else
$maxdate = datetime_convert('UTC','UTC',$year+1 . '-01-01 00:00:00');
- $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d and created >= '%s' and created < '%s' order by created",
+ $r = q("select * from item where item_wall = 1 and item_deleted = 0 and uid = %d and created >= '%s' and created < '%s' and resource_type = '' order by created",
intval($channel_id),
dbesc($mindate),
dbesc($maxdate)
@@ -649,7 +696,6 @@ function identity_export_year($channel_id,$year,$month = 0) {
$ret['item'][] = encode_item($rr,true);
}
-
$r = q("select item_id.*, item.mid from item_id left join item on item_id.iid = item.id where item_id.uid = %d
and item.created >= '%s' and item.created < '%s' order by created ",
intval($channel_id),
diff --git a/include/import.php b/include/import.php
index 6ce572ea2..ad8bcd84e 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1,5 +1,6 @@
<?php
+require_once('include/menu.php');
function import_channel($channel) {
@@ -49,6 +50,11 @@ function import_channel($channel) {
unset($channel['channel_id']);
$channel['channel_account_id'] = get_account_id();
$channel['channel_primary'] = (($seize) ? 1 : 0);
+
+ if($channel['channel_pageflags'] & PAGE_ALLOWCODE) {
+ if(! is_site_admin())
+ $channel['channel_pageflags'] = $channel['channel_pageflags'] ^ PAGE_ALLOWCODE;
+ }
dbesc_array($channel);
@@ -349,7 +355,7 @@ function sync_apps($channel,$apps) {
intval($channel['channel_id'])
);
if($x) {
- if($x[0]['app_edited'] >= $obj['app_edited'])
+ if($x[0]['app_edited'] >= $app['app_edited'])
continue;
$exists = true;
}
@@ -377,4 +383,424 @@ function sync_apps($channel,$apps) {
}
}
}
-} \ No newline at end of file
+}
+
+
+
+function import_chatrooms($channel,$chatrooms) {
+
+ if($channel && $chatrooms) {
+ foreach($chatrooms as $chatroom) {
+
+ if(! $chatroom['cr_name'])
+ continue;
+
+ unset($chatroom['cr_id']);
+ unset($chatroom['cr_aid']);
+ unset($chatroom['cr_uid']);
+
+ $chatroom['cr_aid'] = $channel['channel_account_id'];
+ $chatroom['cr_uid'] = $channel['channel_id'];
+
+ dbesc_array($chatroom);
+ $r = dbq("INSERT INTO chatroom (`"
+ . implode("`, `", array_keys($chatroom))
+ . "`) VALUES ('"
+ . implode("', '", array_values($chatroom))
+ . "')"
+ );
+ }
+ }
+}
+
+
+
+function sync_chatrooms($channel,$chatrooms) {
+
+ if($channel && $chatrooms) {
+ foreach($chatrooms as $chatroom) {
+
+ if(! $chatroom['cr_name'])
+ continue;
+
+ if(array_key_exists('cr_deleted',$chatroom) && $chatroom['cr_deleted']) {
+ q("delete from chatroom where cr_name = '%s' and cr_uid = %d limit 1",
+ dbesc($chatroom['cr_name']),
+ intval($channel['channel_id'])
+ );
+ continue;
+ }
+
+
+ unset($chatroom['cr_id']);
+ unset($chatroom['cr_aid']);
+ unset($chatroom['cr_uid']);
+
+ if(! $chatroom['cr_created'] || $chatroom['cr_created'] === NULL_DATE)
+ $chatroom['cr_created'] = datetime_convert();
+ if(! $chatroom['cr_edited'] || $chatroom['cr_edited'] === NULL_DATE)
+ $chatroom['cr_edited'] = datetime_convert();
+
+ $chatroom['cr_aid'] = $channel['channel_account_id'];
+ $chatroom['cr_uid'] = $channel['channel_id'];
+
+ $exists = false;
+
+ $x = q("select * from chatroom where cr_name = '%s' and cr_uid = %d limit 1",
+ dbesc($chatroom['cr_name']),
+ intval($channel['channel_id'])
+ );
+ if($x) {
+ if($x[0]['cr_edited'] >= $chatroom['cr_edited'])
+ continue;
+ $exists = true;
+ }
+ $name = $chatroom['cr_name'];
+
+ if($exists) {
+ foreach($chatroom as $k => $v) {
+ $r = q("UPDATE chatroom SET `%s` = '%s' WHERE cr_name = '%s' AND cr_uid = %d",
+ dbesc($k),
+ dbesc($v),
+ dbesc($name),
+ intval($channel['channel_id'])
+ );
+ }
+ }
+ else {
+ dbesc_array($chatroom);
+ $r = dbq("INSERT INTO chatroom (`"
+ . implode("`, `", array_keys($chatroom))
+ . "`) VALUES ('"
+ . implode("', '", array_values($chatroom))
+ . "')"
+ );
+ }
+ }
+ }
+}
+
+
+
+function import_items($channel,$items) {
+
+ if($channel && $items) {
+ $allow_code = false;
+ $r = q("select account_id, account_roles, channel_pageflags from account left join channel on channel_account_id = account_id
+ where channel_id = %d limit 1",
+ intval($channel['channel_id'])
+ );
+ if($r) {
+ if(($r[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($r[0]['channel_pageflags'] & PAGE_ALLOWCODE)) {
+ $allow_code = true;
+ }
+ }
+
+ foreach($items as $i) {
+ $item = get_item_elements($i,$allow_code);
+ if(! $item)
+ continue;
+
+ $r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
+ dbesc($item['mid']),
+ intval($channel['channel_id'])
+ );
+ if($r) {
+ if($item['edited'] > $r[0]['edited']) {
+ $item['id'] = $r[0]['id'];
+ $item['uid'] = $channel['channel_id'];
+ item_store_update($item);
+ continue;
+ }
+ }
+ else {
+ $item['aid'] = $channel['channel_account_id'];
+ $item['uid'] = $channel['channel_id'];
+ $item_result = item_store($item);
+ }
+
+ }
+ }
+}
+
+
+function sync_items($channel,$items) {
+ import_items($channel,$items);
+}
+
+
+
+function import_item_ids($channel,$itemids) {
+ if($channel && $itemids) {
+ foreach($itemids as $i) {
+ $r = q("select id from item where mid = '%s' and uid = %d limit 1",
+ dbesc($i['mid']),
+ intval($channel['channel_id'])
+ );
+ if(! $r)
+ continue;
+ $z = q("select * from item_id where service = '%s' and sid = '%s' and iid = %d and uid = %d limit 1",
+ dbesc($i['service']),
+ dbesc($i['sid']),
+ intval($r[0]['id']),
+ intval($channel['channel_id'])
+ );
+ if(! $z) {
+ q("insert into item_id (iid,uid,sid,service) values(%d,%d,'%s','%s')",
+ intval($r[0]['id']),
+ intval($channel['channel_id']),
+ dbesc($i['sid']),
+ dbesc($i['service'])
+ );
+ }
+ }
+ }
+}
+
+function import_events($channel,$events) {
+
+ if($channel && $events) {
+ foreach($events as $event) {
+ unset($event['id']);
+ $event['aid'] = $channel['channel_account_id'];
+ $event['uid'] = $channel['channel_id'];
+
+ dbesc_array($event);
+ $r = dbq("INSERT INTO event (`"
+ . implode("`, `", array_keys($event))
+ . "`) VALUES ('"
+ . implode("', '", array_values($event))
+ . "')"
+ );
+ }
+ }
+}
+
+
+function sync_events($channel,$events) {
+
+ if($channel && $events) {
+ foreach($events as $event) {
+
+ if((! $event['event_hash']) || (! $event['start']))
+ continue;
+
+ if($event['event_deleted']) {
+ $r = q("delete from event where event_hash = '%s' and uid = %d limit 1",
+ dbesc($event['event_hash']),
+ intval($channel['channel_id'])
+ );
+ continue;
+ }
+
+ unset($event['id']);
+ $event['aid'] = $channel['channel_account_id'];
+ $event['uid'] = $channel['channel_id'];
+
+ $exists = false;
+
+ $x = q("select * from event where event_hash = '%s' and uid = %d limit 1",
+ dbesc($event['event_hash']),
+ intval($channel['channel_id'])
+ );
+ if($x) {
+ if($x[0]['edited'] >= $event['edited'])
+ continue;
+ $exists = true;
+ }
+
+ if($exists) {
+ foreach($event as $k => $v) {
+ $r = q("UPDATE event SET `%s` = '%s' WHERE event_hash = '%s' AND uid = %d",
+ dbesc($k),
+ dbesc($v),
+ dbesc($event['event_hash']),
+ intval($channel['channel_id'])
+ );
+ }
+ }
+ else {
+ dbesc_array($event);
+ $r = dbq("INSERT INTO event (`"
+ . implode("`, `", array_keys($event))
+ . "`) VALUES ('"
+ . implode("', '", array_values($event))
+ . "')"
+ );
+ }
+ }
+ }
+}
+
+
+function import_menus($channel,$menus) {
+
+ if($channel && $menus) {
+ foreach($menus as $menu) {
+ $m = array();
+ $m['menu_channel_id'] = $channel['channel_id'];
+ $m['menu_name'] = $menu['pagetitle'];
+ $m['menu_desc'] = $menu['desc'];
+ if($menu['created'])
+ $m['menu_created'] = datetime_convert($menu['created']);
+ if($menu['edited'])
+ $m['menu_edited'] = datetime_convert($menu['edited']);
+
+ $m['menu_flags'] = 0;
+ if($menu['flags']) {
+ if(in_array('bookmark',$menu['flags']))
+ $m['menu_flags'] |= MENU_BOOKMARK;
+ if(in_array('system',$menu['flags']))
+ $m['menu_flags'] |= MENU_SYSTEM;
+
+ }
+
+ $menu_id = menu_create($m);
+
+ if($menu_id) {
+ if(is_array($menu['items'])) {
+ foreach($menu['items'] as $it) {
+ $mitem = array();
+
+ $mitem['mitem_link'] = str_replace('[baseurl]',z_root(),$it['link']);
+ $mitem['mitem_desc'] = escape_tags($it['desc']);
+ $mitem['mitem_order'] = intval($it['order']);
+ if(is_array($it['flags'])) {
+ $mitem['mitem_flags'] = 0;
+ if(in_array('zid',$it['flags']))
+ $mitem['mitem_flags'] |= MENU_ITEM_ZID;
+ if(in_array('new-window',$it['flags']))
+ $mitem['mitem_flags'] |= MENU_ITEM_NEWWIN;
+ if(in_array('chatroom',$it['flags']))
+ $mitem['mitem_flags'] |= MENU_ITEM_CHATROOM;
+ }
+ menu_add_item($menu_id,$channel['channel_id'],$mitem);
+ }
+ }
+ }
+ }
+ }
+}
+
+
+function sync_menus($channel,$menus) {
+
+ if($channel && $menus) {
+ foreach($menus as $menu) {
+ $m = array();
+ $m['menu_channel_id'] = $channel['channel_id'];
+ $m['menu_name'] = $menu['pagetitle'];
+ $m['menu_desc'] = $menu['desc'];
+ if($menu['created'])
+ $m['menu_created'] = datetime_convert($menu['created']);
+ if($menu['edited'])
+ $m['menu_edited'] = datetime_convert($menu['edited']);
+
+ $m['menu_flags'] = 0;
+ if($menu['flags']) {
+ if(in_array('bookmark',$menu['flags']))
+ $m['menu_flags'] |= MENU_BOOKMARK;
+ if(in_array('system',$menu['flags']))
+ $m['menu_flags'] |= MENU_SYSTEM;
+
+ }
+
+ $editing = false;
+
+ $r = q("select * from menu where menu_name = '%s' and menu_channel_id = %d limit 1",
+ dbesc($m['menu_name']),
+ intval($channel['channel_id'])
+ );
+ if($r) {
+ if($r[0]['menu_edited'] >= $m['menu_edited'])
+ continue;
+ if($menu['menu_deleted']) {
+ menu_delete_id($r[0]['menu_id'],$channel['channel_id']);
+ continue;
+ }
+ $menu_id = $r[0]['menu_id'];
+ $m['menu_id'] = $r[0]['menu_id'];
+ $x = menu_edit($m);
+ if(! $x)
+ continue;
+ $editing = true;
+ }
+ if(! $editing) {
+ $menu_id = menu_create($m);
+ }
+ if($menu_id) {
+ if($editing) {
+ // don't try syncing - just delete all the entries and start over
+ q("delete from menu_item where mitem_menu_id = %d",
+ intval($menu_id)
+ );
+ }
+
+ if(is_array($menu['items'])) {
+ foreach($menu['items'] as $it) {
+ $mitem = array();
+
+ $mitem['mitem_link'] = str_replace('[baseurl]',z_root(),$it['link']);
+ $mitem['mitem_desc'] = escape_tags($it['desc']);
+ $mitem['mitem_order'] = intval($it['order']);
+ if(is_array($it['flags'])) {
+ $mitem['mitem_flags'] = 0;
+ if(in_array('zid',$it['flags']))
+ $mitem['mitem_flags'] |= MENU_ITEM_ZID;
+ if(in_array('new-window',$it['flags']))
+ $mitem['mitem_flags'] |= MENU_ITEM_NEWWIN;
+ if(in_array('chatroom',$it['flags']))
+ $mitem['mitem_flags'] |= MENU_ITEM_CHATROOM;
+ }
+ menu_add_item($menu_id,$channel['channel_id'],$mitem);
+ }
+ }
+ }
+ }
+ }
+}
+
+
+
+function import_likes($channel,$likes) {
+ if($channel && $likes) {
+ foreach($likes as $like) {
+ if($like['deleted']) {
+ q("delete from likes where liker = '%s' and likee = '%s' and verb = '%s' and target_type = '%s' and target_id = '%s'",
+ dbesc($like['liker']),
+ dbesc($like['likee']),
+ dbesc($like['verb']),
+ dbesc($like['target_type']),
+ dbesc($like['target_id'])
+ );
+ continue;
+ }
+
+ unset($like['id']);
+ unset($like['iid']);
+ $like['channel_id'] = $channel['channel_id'];
+ $r = q("select * from likes where liker = '%s' and likee = '%s' and verb = '%s' and target_type = '%s' and target_id = '%s' and i_mid = '%s'",
+ dbesc($like['liker']),
+ dbesc($like['likee']),
+ dbesc($like['verb']),
+ dbesc($like['target_type']),
+ dbesc($like['target_id']),
+ dbesc($like['i_mid'])
+ );
+ if($r)
+ continue;
+
+ dbesc_array($config);
+ $r = dbq("INSERT INTO likes (`"
+ . implode("`, `", array_keys($like))
+ . "`) VALUES ('"
+ . implode("', '", array_values($like))
+ . "')" );
+ }
+ }
+}
+
+
+
+
+
diff --git a/include/items.php b/include/items.php
index 9807831e3..28fd8502b 100755
--- a/include/items.php
+++ b/include/items.php
@@ -833,10 +833,13 @@ function title_is_body($title, $body) {
}
-function get_item_elements($x) {
+function get_item_elements($x,$allow_code = false) {
$arr = array();
- $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'],ENT_COMPAT,'UTF-8',false) : '');
+ if($allow_code)
+ $arr['body'] = $x['body'];
+ else
+ $arr['body'] = (($x['body']) ? htmlspecialchars($x['body'],ENT_COMPAT,'UTF-8',false) : '');
$key = get_config('system','pubkey');
@@ -1309,7 +1312,7 @@ function encode_item($item,$mirror = false) {
$x['comment_scope'] = $c_scope;
if($item['term'])
- $x['tags'] = encode_item_terms($item['term']);
+ $x['tags'] = encode_item_terms($item['term'],$mirror);
if($item['diaspora_meta']) {
$z = json_decode($item['diaspora_meta'],true);
@@ -1401,11 +1404,16 @@ function encode_item_xchan($xchan) {
return $ret;
}
-function encode_item_terms($terms) {
+function encode_item_terms($terms,$mirror = false) {
$ret = array();
$allowed_export_terms = array( TERM_UNKNOWN, TERM_HASHTAG, TERM_MENTION, TERM_CATEGORY, TERM_BOOKMARK );
+ if($mirror) {
+ $allowed_export_terms[] = TERM_PCATEGORY;
+ $allowed_export_terms[] = TERM_FILE;
+ }
+
if($terms) {
foreach($terms as $term) {
if(in_array($term['type'],$allowed_export_terms))
@@ -3322,7 +3330,7 @@ function start_delivery_chain($channel, $item, $item_id, $parent) {
dbesc($title),
dbesc($body),
intval($item_wall),
- $intval($item_origin),
+ intval($item_origin),
intval($item_id)
);
@@ -4632,10 +4640,12 @@ function zot_feed($uid,$observer_hash,$arr) {
$items = array();
- /** @FIXME fix this part for PostgreSQL */
+ /** @FIXME re-unite these SQL statements. There is no need for them to be separate. The mySQL is convoluted with misuse of group by. As it stands, there is a slight difference where the postgres version doesn't remove the duplicate parents up to 100. In practice this doesn't matter. It could be made to match behavior by adding "distinct on (parent) " to the front of the selection list, at a not-worth-it performance penalty (page temp results to disk). duplicates are still ignored in the in() clause, you just get less than 100 parents if there are many children. */
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
- return array();
+ $groupby = '';
+ } else {
+ $groupby = 'GROUP BY parent';
}
$item_normal = item_normal();
@@ -4645,7 +4655,7 @@ function zot_feed($uid,$observer_hash,$arr) {
WHERE uid != %d
$item_normal
AND item_wall = 1
- and item_private = 0 $sql_extra GROUP BY parent ORDER BY created ASC $limit",
+ and item_private = 0 $sql_extra $groupby ORDER BY created ASC $limit",
intval($uid)
);
}
@@ -4653,7 +4663,7 @@ function zot_feed($uid,$observer_hash,$arr) {
$r = q("SELECT parent, created, postopts from item
WHERE uid = %d $item_normal
AND item_wall = 1
- $sql_extra GROUP BY parent ORDER BY created ASC $limit",
+ $sql_extra $groupby ORDER BY created ASC $limit",
intval($uid)
);
}
@@ -4724,6 +4734,12 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
if($arr['wall'])
$sql_options .= " and item_wall = 1 ";
+
+ if($arr['item_id'])
+ $sql_options .= " and parent = " . intval($arr['item_id']) . " ";
+
+ if($arr['mid'])
+ $sql_options .= " and parent_mid = '" . dbesc($arr['mid']) . "' ";
$sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 $sql_options ) ";
@@ -4850,11 +4866,15 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
require_once('include/security.php');
$sql_extra .= item_permissions_sql($channel['channel_id'],$observer_hash);
+
if($arr['pages'])
$item_restrict = " AND item_type = " . ITEM_TYPE_WEBPAGE . " ";
else
$item_restrict = " AND item_type = 0 ";
+ if($arr['item_type'] === '*')
+ $item_restrict = '';
+
if ($arr['nouveau'] && ($client_mode & CLIENT_MODE_LOAD) && $channel) {
// "New Item View" - show all items unthreaded in reverse created date order
diff --git a/include/menu.php b/include/menu.php
index 7ed931a59..075372515 100644
--- a/include/menu.php
+++ b/include/menu.php
@@ -6,7 +6,7 @@ require_once('include/bbcode.php');
function menu_fetch($name,$uid,$observer_xchan) {
- $sql_options = permissions_sql($uid);
+ $sql_options = permissions_sql($uid,$observer_xchan);
$r = q("select * from menu where menu_channel_id = %d and menu_name = '%s' limit 1",
intval($uid),
@@ -238,7 +238,6 @@ function menu_edit($arr) {
return false;
}
-
$r = q("select * from menu where menu_id = %d and menu_channel_id = %d limit 1",
intval($menu_id),
intval($menu_channel_id)
@@ -388,3 +387,14 @@ function menu_del_item($menu_id,$uid,$item_id) {
return $r;
}
+function menu_sync_packet($uid,$observer_hash,$menu_id,$delete = false) {
+ $r = menu_fetch_id($menu_id,$uid);
+ if($r) {
+ $m = menu_fetch($r['menu_name'],$uid,$observer_hash);
+ if($m) {
+ if($delete)
+ $m['menu_delete'] = 1;
+ build_sync_packet($uid,array('menu' => array(menu_element($m))));
+ }
+ }
+}
diff --git a/include/message.php b/include/message.php
index 396e3162c..efe1a7710 100644
--- a/include/message.php
+++ b/include/message.php
@@ -49,6 +49,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
// look for any existing conversation structure
+
if(strlen($replyto)) {
$r = q("select convid from mail where channel_id = %d and ( mid = '%s' or parent_mid = '%s' ) limit 1",
intval(local_channel()),
diff --git a/include/network.php b/include/network.php
index 75729d6e4..d3320f3ee 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1137,6 +1137,8 @@ function discover_by_webbie($webbie) {
if($hcard) {
$vcard = scrape_vcard($hcard);
$vcard['nick'] = substr($webbie,0,strpos($webbie,'@'));
+ if(! $vcard['fn'])
+ $vcard['fn'] = $webbie;
}
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
diff --git a/include/photos.php b/include/photos.php
index b4129fbf1..49aab6865 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -27,7 +27,7 @@ function photo_upload($channel, $observer, $args) {
return $ret;
}
- call_hooks('photo_upload_begin', $args);
+// call_hooks('photo_upload_begin', $args);
/*
* Determine the album to use
@@ -84,7 +84,7 @@ function photo_upload($channel, $observer, $args) {
} else {
$f = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
- call_hooks('photo_upload_file',$f);
+// call_hooks('photo_upload_file',$f);
if (x($f,'src') && x($f,'filesize')) {
$src = $f['src'];
@@ -226,11 +226,8 @@ function photo_upload($channel, $observer, $args) {
$width_x_height = $ph->getWidth() . 'x' . $ph->getHeight();
- $mid = item_message_id();
-
// Create item container
-
$item_hidden = (($visible) ? 0 : 1 );
$lat = $lon = null;
diff --git a/include/security.php b/include/security.php
index 7cc93fc06..380505a79 100644
--- a/include/security.php
+++ b/include/security.php
@@ -256,7 +256,7 @@ function item_permissions_sql($owner_id, $remote_observer = null) {
$regexop = db_getfunc('REGEXP');
$sql = sprintf(
" AND ( NOT (deny_cid like '%s' OR deny_gid $regexop '%s')
- AND ( allow_cid like '%s' OR allow_gid $regexop '%s' OR ( allow_cid = '' AND allow_gid = '') )
+ AND ( allow_cid like '%s' OR allow_gid $regexop '%s' OR ( allow_cid = '' AND allow_gid = '' AND item_private = 0 ) )
)
",
dbesc(protect_sprintf( '%<' . $observer . '>%')),
@@ -291,7 +291,7 @@ function public_permissions_sql($observer_hash) {
$regexop = db_getfunc('REGEXP');
$sql = sprintf(
" OR (( NOT (deny_cid like '%s' OR deny_gid $regexop '%s')
- AND ( allow_cid like '%s' OR allow_gid $regexop '%s' OR ( allow_cid = '' AND allow_gid = '') )
+ AND ( allow_cid like '%s' OR allow_gid $regexop '%s' OR ( allow_cid = '' AND allow_gid = '' AND item_private = 0 ) )
))
",
dbesc(protect_sprintf( '%<' . $observer_hash . '>%')),
diff --git a/include/widgets.php b/include/widgets.php
index 42d9db19a..5e40bf54a 100644
--- a/include/widgets.php
+++ b/include/widgets.php
@@ -1007,7 +1007,9 @@ function widget_forums($arr) {
$perms_sql = item_permissions_sql(local_channel()) . item_normal();
- $r1 = q("select * from abook left join xchan on abook_xchan = xchan_hash where xchan_pubforum = 1 and abook_channel = %d order by xchan_name $limit ",
+ $r1 = q("select * from abook left join xchan on abook_xchan = xchan_hash where ( xchan_pubforum = 1 or ((abook_their_perms & %d ) != 0 and (abook_their_perms & %d ) = 0) ) and abook_channel = %d order by xchan_name $limit ",
+ intval(PERMS_W_TAGWALL),
+ intval(PERMS_W_STREAM),
intval(local_channel())
);
if(! $r1)
@@ -1034,7 +1036,7 @@ function widget_forums($arr) {
foreach($r1 as $rr) {
if($unseen && (! intval($rr['unseen'])))
continue;
- $o .= '<li><span class="pull-right">' . ((intval($rr['unseen'])) ? intval($rr['unseen']) : '') . '</span><a href="network?f=&cid=' . $rr['abook_id'] . '" ><img src="' . $rr['xchan_photo_s'] . '" style="width: 16px; height: 16px;" /> ' . $rr['xchan_name'] . '</a></li>';
+ $o .= '<li><span class="pull-right">' . ((intval($rr['unseen'])) ? intval($rr['unseen']) : '') . '</span><a href="network?f=&pf=1&cid=' . $rr['abook_id'] . '" ><img src="' . $rr['xchan_photo_s'] . '" style="width: 16px; height: 16px;" /> ' . $rr['xchan_name'] . '</a></li>';
}
$o .= '</ul></div>';
}
@@ -1074,4 +1076,63 @@ function widget_helpindex($arr) {
$o .= '</ul></div>';
return $o;
+}
+
+
+
+function widget_admin($arr) {
+
+ /*
+ * Side bar links
+ */
+
+ if(! is_site_admin()) {
+ return login(false);
+ }
+
+
+ $a = get_app();
+ $o = '';
+
+ // array( url, name, extra css classes )
+
+ $aside = array(
+ 'site' => array(z_root() . '/admin/site/', t('Site'), 'site'),
+ 'users' => array(z_root() . '/admin/users/', t('Accounts'), 'users'),
+ 'channels' => array(z_root() . '/admin/channels/', t('Channels'), 'channels'),
+ 'plugins' => array(z_root() . '/admin/plugins/', t('Plugins'), 'plugins'),
+ 'themes' => array(z_root() . '/admin/themes/', t('Themes'), 'themes'),
+ 'queue' => array(z_root() . '/admin/queue', t('Inspect queue'), 'queue'),
+ 'profs' => array(z_root() . '/admin/profs', t('Profile Config'), 'profs'),
+ 'dbsync' => array(z_root() . '/admin/dbsync/', t('DB updates'), 'dbsync')
+
+ );
+
+ /* get plugins admin page */
+
+ $r = q("SELECT * FROM addon WHERE plugin_admin = 1");
+
+ $aside['plugins_admin'] = array();
+ if($r) {
+ foreach ($r as $h){
+ $plugin = $h['name'];
+ $aside['plugins_admin'][] = array(z_root() . '/admin/plugins/' . $plugin, $plugin, 'plugin');
+ // temp plugins with admin
+ $a->plugins_admin[] = $plugin;
+ }
+ }
+
+ $aside['logs'] = array(z_root() . '/admin/logs/', t('Logs'), 'logs');
+
+ $o .= replace_macros(get_markup_template('admin_aside.tpl'), array(
+ '$admin' => $aside,
+ '$admtxt' => t('Admin'),
+ '$plugadmtxt' => t('Plugin Features'),
+ '$logtxt' => t('Logs'),
+ '$h_pending' => t('User registrations waiting for confirmation'),
+ '$admurl'=> z_root() . '/admin/'
+ ));
+
+ return $o;
+
} \ No newline at end of file
diff --git a/include/zot.php b/include/zot.php
index fecaa7ad2..0e00f39b4 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -294,9 +294,19 @@ function zot_refresh($them, $channel = null, $force = false) {
if ($them['hubloc_url']) {
$url = $them['hubloc_url'];
} else {
- $r = q("select hubloc_url, hubloc_primary from hubloc where hubloc_hash = '%s'",
- dbesc($them['xchan_hash'])
- );
+ $r = null;
+
+ if(array_key_exists('xchan_addr',$them) && $them['xchan_addr']) {
+ $r = q("select hubloc_url, hubloc_primary from hubloc where hubloc_addr = '%s'",
+ dbesc($them['xchan_addr'])
+ );
+ }
+ if(! $r) {
+ $r = q("select hubloc_url, hubloc_primary from hubloc where hubloc_hash = '%s'",
+ dbesc($them['xchan_hash'])
+ );
+ }
+
if ($r) {
foreach ($r as $rr) {
if (intval($rr['hubloc_primary'])) {
@@ -962,7 +972,7 @@ function zot_process_response($hub, $arr, $outq) {
);
}
- logger('zot_process_response: ' . print_r($x,true), LOGGER_DATA);
+ logger('zot_process_response: ' . print_r($x,true), LOGGER_DEBUG);
}
/**
@@ -2226,7 +2236,7 @@ function sync_locations($sender, $arr, $absolute = false) {
// Absolute sync - make sure the current primary is correctly reflected in the xchan
$pr = hubloc_change_primary($r[0]);
if($pr) {
- $what .= 'xchan_primary';
+ $what .= 'xchan_primary ';
$changed = true;
}
}
@@ -2878,9 +2888,30 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
if(array_key_exists('obj',$arr) && $arr['obj'])
sync_objs($channel,$arr['obj']);
+ if(array_key_exists('likes',$arr) && $arr['likes'])
+ import_likes($channel,$arr['likes']);
+
if(array_key_exists('app',$arr) && $arr['app'])
sync_apps($channel,$arr['app']);
+ if(array_key_exists('chatroom',$arr) && $arr['chatroom'])
+ sync_chatrooms($channel,$arr['chatroom']);
+
+ if(array_key_exists('event',$arr) && $arr['event'])
+ sync_events($channel,$arr['event']);
+
+ if(array_key_exists('event_item',$arr) && $arr['event_item'])
+ sync_items($channel,$arr['event_item']);
+
+ if(array_key_exists('item',$arr) && $arr['item'])
+ sync_items($channel,$arr['item']);
+
+ if(array_key_exists('item_id',$arr) && $arr['item_id'])
+ sync_items($channel,$arr['item_id']);
+
+ if(array_key_exists('menu',$arr) && $arr['menu'])
+ sync_menus($channel,$arr['menu']);
+
if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) {
if(array_key_exists('channel_page_flags',$arr['channel']) && intval($arr['channel']['channel_pageflags'])) {
$arr['channel']['channel_removed'] = (($arr['channel']['channel_pageflags'] & 0x8000) ? 1 : 0);