aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-09-08 17:51:48 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-09-08 17:52:39 -0700
commit75d521d42affbafa34e87752deeb1961367de1d5 (patch)
treeae068699ab0372837d35f73146745accb6f0ce2d /include
parentc6bdf7e891f3c0b49a1e9c40622e05aef590e2b6 (diff)
downloadvolse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.tar.gz
volse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.tar.bz2
volse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.zip
menu import and sync
Diffstat (limited to 'include')
-rw-r--r--include/Import/import_diaspora.php5
-rw-r--r--include/identity.php11
-rw-r--r--include/import.php124
-rw-r--r--include/menu.php13
-rw-r--r--include/zot.php3
5 files changed, 154 insertions, 2 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/identity.php b/include/identity.php
index 211832d51..f68b1fe4a 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -5,6 +5,7 @@
require_once('include/zot.php');
require_once('include/crypto.php');
+require_once('include/menu.php');
/**
@@ -595,6 +596,16 @@ function identity_basic_export($channel_id, $items = false) {
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);
+ }
+ }
if(! $items)
diff --git a/include/import.php b/include/import.php
index 616ee4987..7b2f574d9 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1,5 +1,6 @@
<?php
+require_once('include/menu.php');
function import_channel($channel) {
@@ -616,7 +617,130 @@ function sync_events($channel,$events) {
}
+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'];
+ $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);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/include/menu.php b/include/menu.php
index 7ed931a59..32d8630a6 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),
@@ -388,3 +388,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[0]['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/zot.php b/include/zot.php
index 285668209..9fac4d40e 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -2896,6 +2896,9 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
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);