From 04b4897dd86d862957d95a5d6090af7a026dd82c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 27 Aug 2015 18:55:30 -0700 Subject: First attempt to turn access control into an object class. The access control manipulation is getting too complex and this will help keep it manageable and reduce a lot of code duplication. --- mod/item.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mod') diff --git a/mod/item.php b/mod/item.php index ff6a834e6..254904c9f 100644 --- a/mod/item.php +++ b/mod/item.php @@ -19,6 +19,7 @@ require_once('include/crypto.php'); require_once('include/enotify.php'); require_once('include/items.php'); require_once('include/attach.php'); +require_once('include/AccessList.php'); function item_post(&$a) { @@ -305,6 +306,8 @@ function item_post(&$a) { } } + $ACL = new AccessList($channel); + $public_policy = ((x($_REQUEST,'public_policy')) ? escape_tags($_REQUEST['public_policy']) : map_scope($channel['channel_r_stream'],true)); if($webpage) -- cgit v1.2.3 From 3fbb955cf23c5f92ba96086841ac6a2c510d4870 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 27 Aug 2015 21:22:59 -0700 Subject: start conversion to AccessList object --- mod/mitem.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'mod') diff --git a/mod/mitem.php b/mod/mitem.php index bc93165ac..3959da032 100644 --- a/mod/mitem.php +++ b/mod/mitem.php @@ -2,6 +2,7 @@ require_once('include/menu.php'); require_once('include/acl_selectors.php'); +require_once('include/AccessList.php'); function mitem_init(&$a) { @@ -125,12 +126,7 @@ function mitem_content(&$a) { $menu_names[] = $menus['menu_name']; } - $perm_defaults = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); $lockstate = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'); @@ -151,7 +147,7 @@ function mitem_content(&$a) { '$menu_id' => $a->data['menu']['menu_id'], '$permissions' => t('Menu Item Permissions'), '$permdesc' => t("\x28click to open/close\x29"), - '$aclselect' => populate_acl($perm_defaults,false), + '$aclselect' => populate_acl($acl->get(),false), '$mitem_desc' => array('mitem_desc', t('Link Name'), '', 'Visible name of the link','*'), '$mitem_link' => array('mitem_link', t('Link or Submenu Target'), '', t('Enter URL of the link or select a menu name to create a submenu'), '*', 'list="menu-names"'), '$usezid' => array('usezid', t('Use magic-auth if available'), true, '', array(t('No'), t('Yes'))), -- cgit v1.2.3 From ca0bc2bb7bc2b9e7d81a356a394d47bcb688004c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 27 Aug 2015 22:20:30 -0700 Subject: more work on AccessList integration --- mod/chat.php | 24 ++++++++++-------------- mod/events.php | 52 +++++++++++++++------------------------------------- mod/item.php | 1 - mod/mitem.php | 1 - mod/photos.php | 53 +++++++++++++++++++++++++---------------------------- 5 files changed, 50 insertions(+), 81 deletions(-) (limited to 'mod') diff --git a/mod/chat.php b/mod/chat.php index c54d29313..c2c11d0ab 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -54,12 +54,11 @@ function chat_post(&$a) { goaway(z_root() . '/chat/' . $channel['channel_address']); } + $acl = new AccessList($channel); + $acl->set_from_array($_REQUEST); - $arr = array('name' => $room); - $arr['allow_gid'] = perms2str($_REQUEST['group_allow']); - $arr['allow_cid'] = perms2str($_REQUEST['contact_allow']); - $arr['deny_gid'] = perms2str($_REQUEST['group_deny']); - $arr['deny_cid'] = perms2str($_REQUEST['contact_deny']); + $arr = $acl->get(); + $arr['name'] = $room; chatroom_create($channel,$arr); @@ -158,7 +157,10 @@ function chat_content(&$a) { intval($a->profile['profile_uid']) ); if($x) { - $private = ((($x[0]['allow_cid']) || ($x[0]['allow_gid']) || ($x[0]['deny_cid']) || ($x[0]['deny_gid'])) ? true : false); + $acl = new AccessList(false); + $acl->set($x[0]); + + $private = $acl->is_private(); $room_name = $x[0]['cr_name']; if($bookmark_link) $bookmark_link .= '&url=' . z_root() . '/chat/' . argv(1) . '/' . argv(2) . '&title=' . urlencode($x[0]['cr_name']) . (($private) ? '&private=1' : '') . '&ischat=1'; @@ -192,14 +194,8 @@ function chat_content(&$a) { if(local_channel() && argc() > 2 && argv(2) === 'new') { - - - $channel_acl = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); + $channel_acl = $acl->get(); require_once('include/acl_selectors.php'); diff --git a/mod/events.php b/mod/events.php index edb61a6cd..9120f8713 100755 --- a/mod/events.php +++ b/mod/events.php @@ -41,16 +41,11 @@ function events_post(&$a) { $categories = escape_tags(trim($_POST['category'])); - - // only allow editing your own events. if(($xchan) && ($xchan !== get_observer_hash())) return; - // The default setting for the `private` field in event_store() is false, so mirror that - $private_event = false; - if($start_text) { $start = $start_text; } @@ -119,6 +114,8 @@ function events_post(&$a) { $channel = $a->get_channel(); + $acl = new AccessList(false); + if($event_id) { $x = q("select * from event where id = %d and uid = %d limit 1", intval($event_id), @@ -133,6 +130,8 @@ function events_post(&$a) { return; } + $acl->set($x[0]); + $created = $x[0]['created']; $edited = datetime_convert(); @@ -142,39 +141,21 @@ function events_post(&$a) { } else { $share = true; - $str_group_allow = $x[0]['allow_gid']; - $str_contact_allow = $x[0]['allow_cid']; - $str_group_deny = $x[0]['deny_gid']; - $str_contact_deny = $x[0]['deny_cid']; - - if(strlen($str_group_allow) || strlen($str_contact_allow) - || strlen($str_group_deny) || strlen($str_contact_deny)) { - $private_event = true; - } } } else { $created = $edited = datetime_convert(); if($share) { - $str_group_allow = perms2str($_POST['group_allow']); - $str_contact_allow = perms2str($_POST['contact_allow']); - $str_group_deny = perms2str($_POST['group_deny']); - $str_contact_deny = perms2str($_POST['contact_deny']); - - if(strlen($str_group_allow) || strlen($str_contact_allow) - || strlen($str_group_deny) || strlen($str_contact_deny)) { - $private_event = true; - } + $acl->set_from_array($_POST); } else { - $str_contact_allow = '<' . $channel['channel_hash'] . '>'; - $str_group_allow = $str_contact_deny = $str_group_deny = ''; - $private_event = true; + $acl->set(array('allow_cid' => '<' . $channel['channel_hash'] . '>', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '')); } } $post_tags = array(); $channel = $a->get_channel(); + $ac = $acl->get(); if(strlen($categories)) { $cats = explode(',',$categories); @@ -201,11 +182,11 @@ function events_post(&$a) { $datarray['uid'] = local_channel(); $datarray['account'] = get_account_id(); $datarray['event_xchan'] = $channel['channel_hash']; - $datarray['allow_cid'] = $str_contact_allow; - $datarray['allow_gid'] = $str_group_allow; - $datarray['deny_cid'] = $str_contact_deny; - $datarray['deny_gid'] = $str_group_deny; - $datarray['private'] = (($private_event) ? 1 : 0); + $datarray['allow_cid'] = $ac['allow_cid']; + $datarray['allow_gid'] = $ac['allow_gid']; + $datarray['deny_cid'] = $ac['deny_cid']; + $datarray['deny_gid'] = $ac['deny_gid']; + $datarray['private'] = (($acl->is_private()) ? 1 : 0); $datarray['id'] = $event_id; $datarray['created'] = $created; $datarray['edited'] = $edited; @@ -660,12 +641,9 @@ function events_content(&$a) { require_once('include/acl_selectors.php'); - $perm_defaults = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); + $perm_defaults = $acl->get(); + $tpl = get_markup_template('event_form.tpl'); diff --git a/mod/item.php b/mod/item.php index 254904c9f..750512bcf 100644 --- a/mod/item.php +++ b/mod/item.php @@ -19,7 +19,6 @@ require_once('include/crypto.php'); require_once('include/enotify.php'); require_once('include/items.php'); require_once('include/attach.php'); -require_once('include/AccessList.php'); function item_post(&$a) { diff --git a/mod/mitem.php b/mod/mitem.php index 3959da032..0fadd1548 100644 --- a/mod/mitem.php +++ b/mod/mitem.php @@ -2,7 +2,6 @@ require_once('include/menu.php'); require_once('include/acl_selectors.php'); -require_once('include/AccessList.php'); function mitem_init(&$a) { diff --git a/mod/photos.php b/mod/photos.php index dc70e4f90..d06a8e69c 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -85,6 +85,7 @@ function photos_post(&$a) { $owner_record = $s[0]; + $acl = AccessList($a->data['channel']); if((argc() > 3) && (argv(2) === 'album')) { @@ -200,6 +201,7 @@ function photos_post(&$a) { goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . $_SESSION['album_return']); } + if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) { @@ -208,10 +210,9 @@ function photos_post(&$a) { $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0); $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : ''); $is_nsfw = ((x($_POST,'adult')) ? intval($_POST['adult']) : 0); - $str_group_allow = perms2str($_POST['group_allow']); - $str_contact_allow = perms2str($_POST['contact_allow']); - $str_group_deny = perms2str($_POST['group_deny']); - $str_contact_deny = perms2str($_POST['contact_deny']); + + $acl->set_from_array($_POST); + $perm = $acl->get(); $resource_id = $a->argv[2]; @@ -284,10 +285,10 @@ function photos_post(&$a) { $r = q("UPDATE `photo` SET `description` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource_id` = '%s' AND `uid` = %d", dbesc($desc), - dbesc($str_contact_allow), - dbesc($str_group_allow), - dbesc($str_contact_deny), - dbesc($str_group_deny), + dbesc($perm['allow_cid']), + dbesc($perm['allow_gid']), + dbesc($perm['deny_cid']), + dbesc($perm['deny_gid']), dbesc($resource_id), intval($page_owner_uid) ); @@ -331,20 +332,20 @@ function photos_post(&$a) { // make sure the linked item has the same permissions as the photo regardless of any other changes $x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d where id = %d", - dbesc($str_contact_allow), - dbesc($str_group_allow), - dbesc($str_contact_deny), - dbesc($str_group_deny), - intval($item_private), + dbesc($perm['allow_cid']), + dbesc($perm['allow_gid']), + dbesc($perm['deny_cid']), + dbesc($perm['deny_gid']), + intval($acl->is_private()), intval($item_id) ); // make sure the attach has the same permissions as the photo regardless of any other changes $x = q("update attach set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where hash = '%s' and uid = %d and is_photo = 1", - dbesc($str_contact_allow), - dbesc($str_group_allow), - dbesc($str_contact_deny), - dbesc($str_group_deny), + dbesc($perm['allow_cid']), + dbesc($perm['allow_gid']), + dbesc($perm['deny_cid']), + dbesc($perm['deny_gid']), dbesc($resource_id), intval($page_owner_uid) ); @@ -418,11 +419,11 @@ function photos_post(&$a) { $_REQUEST['source'] = 'photos'; require_once('include/attach.php'); - if(!local_channel()) { + if(! local_channel()) { $_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']); - $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']); - $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']); - $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']); + $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']); + $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']); + $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']); } $r = attach_store($a->channel,get_observer_hash(), '', $_REQUEST); @@ -557,14 +558,10 @@ function photos_content(&$a) { if($_is_owner) { $channel = $a->get_channel(); - $channel_acl = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); + $channel_acl = $acl->get(); - $lockstate = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'); + $lockstate = (($acl->is_private()) ? 'lock' : 'unlock'); } $aclselect = (($_is_owner) ? populate_acl($channel_acl,false) : ''); -- cgit v1.2.3 From d05fd9632e4dc60fc3d4043374f6332a1609857f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 27 Aug 2015 23:04:17 -0700 Subject: now we get to the heavy lifting with AccessList stuff --- mod/filestorage.php | 14 +++++++------- mod/settings.php | 31 ++++++++++++------------------- 2 files changed, 19 insertions(+), 26 deletions(-) (limited to 'mod') diff --git a/mod/filestorage.php b/mod/filestorage.php index 9787c0380..7ba8c1801 100644 --- a/mod/filestorage.php +++ b/mod/filestorage.php @@ -28,20 +28,20 @@ function filestorage_post(&$a) { return; } - $str_group_allow = perms2str($_REQUEST['group_allow']); - $str_contact_allow = perms2str($_REQUEST['contact_allow']); - $str_group_deny = perms2str($_REQUEST['group_deny']); - $str_contact_deny = perms2str($_REQUEST['contact_deny']); - $channel = $a->get_channel(); + + $acl = new AccessList($channel); + $acl->set_from_array($_REQUEST); + $x = $acl->get(); + $cloudPath = get_parent_cloudpath($channel_id, $channel['channel_address'], $resource); //get the object before permissions change so we can catch eventual former allowed members $object = get_file_activity_object($channel_id, $resource, $cloudPath); - attach_change_permissions($channel_id, $resource, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, $recurse); + attach_change_permissions($channel_id, $resource, $x['allow_cid'], $x['allow_gid'], $x['deny_cid'], $x['deny_gid'], $recurse); - file_activity($channel_id, $object, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, 'post', $notify); + file_activity($channel_id, $object, $x['allow_cid'], $x['allow_gid'], $x['deny_cid'], $x['deny_gid'], 'post', $notify); goaway($cloudPath); } diff --git a/mod/settings.php b/mod/settings.php index cbd6abafc..8bfff3765 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -311,17 +311,16 @@ function settings_post(&$a) { foreach($global_perms as $k => $v) { $set_perms .= ', ' . $v[0] . ' = ' . intval($_POST[$k]) . ' '; } - - $str_group_allow = perms2str($_POST['group_allow']); - $str_contact_allow = perms2str($_POST['contact_allow']); - $str_group_deny = perms2str($_POST['group_deny']); - $str_contact_deny = perms2str($_POST['contact_deny']); - $r = q("update channel set channel_allow_cid = '%s', channel_allow_gid = '%s', channel_deny_cid = '%s', channel_deny_gid = '%s' - where channel_id = %d", - dbesc($str_contact_allow), - dbesc($str_group_allow), - dbesc($str_contact_deny), - dbesc($str_group_deny), + $acl = new AccessList($channel); + $acl->set_from_array($_POST); + $x = $acl->get(); + + $r = q("update channel set channel_allow_cid = '%s', channel_allow_gid = '%s', + channel_deny_cid = '%s', channel_deny_gid = '%s' where channel_id = %d", + dbesc($x['allow_cid']), + dbesc($x['allow_gid']), + dbesc($x['deny_cid']), + dbesc($x['deny_gid']), intval(local_channel()) ); } @@ -983,14 +982,8 @@ function settings_content(&$a) { $stpl = get_markup_template('settings.tpl'); - $celeb = false; - - $perm_defaults = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); + $perm_defaults = $acl->get(); require_once('include/group.php'); $group_select = mini_group_select(local_channel(),$channel['channel_default_group']); -- cgit v1.2.3 From a42b23658752709f80da12051b0ee9c11b6a5580 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 28 Aug 2015 14:21:49 -0700 Subject: more AccessList stuff - this time it's mod-item, which is a biggie --- mod/item.php | 91 +++++++++++++----------------------------------------------- 1 file changed, 19 insertions(+), 72 deletions(-) (limited to 'mod') diff --git a/mod/item.php b/mod/item.php index 750512bcf..ec5d1b3a1 100644 --- a/mod/item.php +++ b/mod/item.php @@ -305,7 +305,7 @@ function item_post(&$a) { } } - $ACL = new AccessList($channel); + $acl = new AccessList($channel); $public_policy = ((x($_REQUEST,'public_policy')) ? escape_tags($_REQUEST['public_policy']) : map_scope($channel['channel_r_stream'],true)); @@ -318,28 +318,17 @@ function item_post(&$a) { $private = 0; // webpages are allowed to change ACLs after the fact. Normal conversation items aren't. if($webpage) { - $str_group_allow = perms2str($_REQUEST['group_allow']); - $str_contact_allow = perms2str($_REQUEST['contact_allow']); - $str_group_deny = perms2str($_REQUEST['group_deny']); - $str_contact_deny = perms2str($_REQUEST['contact_deny']); + $acl->set_from_arry($_REQUEST); } else { - $str_group_allow = $orig_post['allow_gid']; - $str_contact_allow = $orig_post['allow_cid']; - $str_group_deny = $orig_post['deny_gid']; - $str_contact_deny = $orig_post['deny_cid']; + $acl->set($orig_post); $public_policy = $orig_post['public_policy']; $private = $orig_post['item_private']; } - if((strlen($str_group_allow)) - || strlen($str_contact_allow) - || strlen($str_group_deny) - || strlen($str_contact_deny) - || strlen($public_policy) - || $private) { + if($private || $public_policy || $acl->is_private()) $private = 1; - } + $location = $orig_post['location']; $coord = $orig_post['coord']; @@ -383,38 +372,12 @@ function item_post(&$a) { } else { - - // if coming from the API and no privacy settings are set, - // use the user default permissions - as they won't have - // been supplied via a form. - - if(($api_source) - && (! array_key_exists('contact_allow',$_REQUEST)) - && (! array_key_exists('group_allow',$_REQUEST)) - && (! array_key_exists('contact_deny',$_REQUEST)) - && (! array_key_exists('group_deny',$_REQUEST))) { - $str_group_allow = $channel['channel_allow_gid']; - $str_contact_allow = $channel['channel_allow_cid']; - $str_group_deny = $channel['channel_deny_gid']; - $str_contact_deny = $channel['channel_deny_cid']; - } - elseif($walltowall) { - - // use the channel owner's default permissions - - $str_group_allow = $channel['channel_allow_gid']; - $str_contact_allow = $channel['channel_allow_cid']; - $str_group_deny = $channel['channel_deny_gid']; - $str_contact_deny = $channel['channel_deny_cid']; - } - else { - - // use the posted permissions - - $str_group_allow = perms2str($_REQUEST['group_allow']); - $str_contact_allow = perms2str($_REQUEST['contact_allow']); - $str_group_deny = perms2str($_REQUEST['group_deny']); - $str_contact_deny = perms2str($_REQUEST['contact_deny']); + if((! $walltowall) && + ((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); } @@ -426,33 +389,15 @@ function item_post(&$a) { $body .= trim($_REQUEST['attachment']); $postopts = ''; - $private = ( - ( strlen($str_group_allow) - || strlen($str_contact_allow) - || strlen($str_group_deny) - || strlen($str_contact_deny) - || strlen($public_policy) - ) ? 1 : 0); + $private = intval($acl->is_private() || ($public_policy)); // If this is a comment, set the permissions from the parent. if($parent_item) { $private = 0; - - if(($parent_item['item_private']) - || strlen($parent_item['allow_cid']) - || strlen($parent_item['allow_gid']) - || strlen($parent_item['deny_cid']) - || strlen($parent_item['deny_gid']) - || strlen($parent_item['public_policy'])) { - $private = (($parent_item['item_private']) ? $parent_item['item_private'] : 1); - } - + $acl->set($parent_item); + $private = intval($acl->is_private() || $parent_item['item_private']); $public_policy = $parent_item['public_policy']; - $str_contact_allow = $parent_item['allow_cid']; - $str_group_allow = $parent_item['allow_gid']; - $str_contact_deny = $parent_item['deny_cid']; - $str_group_deny = $parent_item['deny_gid']; $owner_hash = $parent_item['owner_xchan']; } @@ -507,6 +452,11 @@ function item_post(&$a) { } } + $gacl = $acl->get(); + $str_contact_allow = $gacl['allow_cid']; + $str_group_allow = $gacl['allow_gid']; + $str_contact_deny = $gacl['deny_cid']; + $str_group_deny = $gacl['deny_gid']; if($mimetype === 'text/bbcode') { @@ -571,9 +521,6 @@ function item_post(&$a) { $body = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','red_zrlify_img_callback',$body); - - - $body = bb_translate_video($body); /** -- cgit v1.2.3 From 7ba1217a13422ce967439c07b4ba0445bc526de1 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 30 Aug 2015 20:47:15 -0700 Subject: improvements to documentation search --- mod/help.php | 51 ++++++++++++++++++--------------------------------- mod/siteinfo.php | 1 - 2 files changed, 18 insertions(+), 34 deletions(-) (limited to 'mod') diff --git a/mod/help.php b/mod/help.php index 809313a3e..dd1dc9cd8 100644 --- a/mod/help.php +++ b/mod/help.php @@ -12,9 +12,6 @@ - - - function load_doc_file($s) { $lang = get_app()->language; if(! isset($lang)) @@ -32,21 +29,6 @@ function load_doc_file($s) { } function find_doc_file($s) { - - // If the file was edited more recently than we've stored a copy in the database, use the file. - // The stored database item will be searchable, the file won't be. - - $r = q("select item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and - sid = '%s' and item_type = %d limit 1", - dbesc($s), - intval(ITEM_TYPE_DOC) - ); - - if($r) { - if(file_exists($s) && (filemtime($s) > datetime_convert('UTC','UTC',$r[0]['edited'],'U'))) - return file_get_contents($s); - return($r[0]['body']); - } if(file_exists($s)) return file_get_contents($s); return ''; @@ -56,12 +38,9 @@ function search_doc_files($s) { $a = get_app(); - $itemspage = get_pconfig(local_channel(),'system','itemspage'); - $a->set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); - $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start'])); - - // If the file was edited more recently than we've stored a copy in the database, use the file. - // The stored database item will be searchable, the file won't be. + $itemspage = get_pconfig(local_channel(),'system','itemspage'); + $a->set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); + $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start'])); $regexop = db_getfunc('REGEXP'); @@ -72,11 +51,10 @@ function search_doc_files($s) { ); $r = fetch_post_tags($r,true); - require_once('include/html2plain.php'); for($x = 0; $x < count($r); $x ++) { - $r[$x]['text'] = html2plain(prepare_text($r[$x]['body'],$r[$x]['mimetype'], true)); + $r[$x]['text'] = $r[$x]['body']; $r[$x]['rank'] = 0; if($r[$x]['term']) { @@ -89,16 +67,20 @@ function search_doc_files($s) { if(stristr($r[$x]['sid'],$s)) $r[$x]['rank'] ++; $r[$x]['rank'] += substr_count(strtolower($r[$x]['text']),strtolower($s)); + // bias the results to the observer's native language + if($r[$x]['lang'] === $a->language) + $r[$x]['rank'] = $r[$x]['rank'] + 10; + } usort($r,'doc_rank_sort'); return $r; } -function doc_rank_sort($a,$b) { - if($a['rank'] == $b['rank']) +function doc_rank_sort($s1,$s2) { + if($s1['rank'] == $s2['rank']) return 0; - return (($a['rank'] < $b['rank']) ? 1 : (-1)); + return (($s1['rank'] < $s2['rank']) ? 1 : (-1)); } @@ -118,14 +100,17 @@ function store_doc_file($s) { if(strpos($s,'.md')) - $item['mimetype'] = 'text/markdown'; + $mimetype = 'text/markdown'; elseif(strpos($s,'.html')) - $item['mimetype'] = 'text/html'; + $mimetype = 'text/html'; else - $item['mimetype'] = 'text/bbcode'; + $mimetype = 'text/bbcode'; + + require_once('include/html2plain.php'); + $item['body'] = html2plain(prepare_text(file_get_contents($s),$mimetype, true)); + $item['mimetype'] = 'text/plain'; - $item['body'] = file_get_contents($s); $item['plink'] = z_root() . '/' . str_replace('doc','help',$s); $item['owner_xchan'] = $item['author_xchan'] = $sys['channel_hash']; $item['item_type'] = ITEM_TYPE_DOC; diff --git a/mod/siteinfo.php b/mod/siteinfo.php index 61c20d66f..8281a7a0a 100644 --- a/mod/siteinfo.php +++ b/mod/siteinfo.php @@ -84,7 +84,6 @@ function siteinfo_init(&$a) { 'register_policy' => $register_policy[$a->config['system']['register_policy']], 'directory_mode' => $directory_mode[$a->config['system']['directory_mode']], 'language' => get_config('system','language'), - 'diaspora_emulation' => get_config('system','diaspora_enabled'), 'rss_connections' => get_config('system','feed_contacts'), 'expiration' => $site_expire, 'default_service_restrictions' => $service_class, -- cgit v1.2.3 From e23f86faa91f6b12ad499d27d3a06a6873230714 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 30 Aug 2015 22:39:33 -0700 Subject: more work on doco search --- mod/help.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/help.php b/mod/help.php index dd1dc9cd8..16ec069a7 100644 --- a/mod/help.php +++ b/mod/help.php @@ -143,9 +143,12 @@ function help_content(&$a) { nav_set_selected('help'); if($_REQUEST['search']) { + + $o .= '

' . t('Documentation Search') . ' - ' . htmlspecialchars($_REQUEST['search']) . '

'; + $r = search_doc_files($_REQUEST['search']); if($r) { - $o .= '
    '; + $o .= '
      '; foreach($r as $rr) { $dirname = dirname($rr['sid']); $fname = basename($rr['sid']); -- cgit v1.2.3 From d7cf7316beaecc6efacc01d56dbb066af8174416 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 31 Aug 2015 20:55:25 -0700 Subject: change the likes db structure to make it more easily importable/exportable --- mod/like.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mod') diff --git a/mod/like.php b/mod/like.php index e79ff5f48..8789b7633 100755 --- a/mod/like.php +++ b/mod/like.php @@ -473,11 +473,12 @@ function like_content(&$a) { if($extended_like) { - $r = q("insert into likes (channel_id,liker,likee,iid,verb,target_type,target_id,target) values (%d,'%s','%s',%d,'%s','%s','%s','%s')", + $r = q("insert into likes (channel_id,liker,likee,iid,i_mid,verb,target_type,target_id,target) values (%d,'%s','%s',%d,'%s','%s','%s','%s','%s')", intval($ch[0]['channel_id']), dbesc($observer['xchan_hash']), dbesc($ch[0]['channel_hash']), intval($post_id), + dbesc($mid), dbesc($activity), dbesc(($tgttype)?$tgttype:$objtype), dbesc($obj_id), -- cgit v1.2.3 From 039f56f390c69ad0aedadcca3d611fea0d9eebf9 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 31 Aug 2015 20:58:05 -0700 Subject: mostly doc tweaks, some import/export work --- mod/import.php | 21 +++++++++++++++++++-- mod/like.php | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'mod') diff --git a/mod/import.php b/mod/import.php index bf1f0ca2e..fb04a021a 100644 --- a/mod/import.php +++ b/mod/import.php @@ -447,7 +447,7 @@ function import_post(&$a) { -// FIXME - ensure we have an xchan if somebody is trying to pull a fast one + // FIXME - ensure we have an xchan if somebody is trying to pull a fast one if($completed < 8) { $friends = 0; @@ -556,6 +556,23 @@ function import_post(&$a) { ref_session_write(session_id(), serialize($_SESSION)); } + + $objs = $data['obj']; + if($objs) { + foreach($objs as $obj) { + unset($obj['obj_id']); + $obj['channel'] = $channel['channel_id']; + + dbesc_array($obj); + $r = dbq("INSERT INTO obj (`" + . implode("`, `", array_keys($obj)) + . "`) VALUES ('" + . implode("', '", array_values($obj)) + . "')" ); + } + } + + $saved_notification_flags = notifications_off($channel['channel_id']); if($import_posts && array_key_exists('item',$data) && $data['item']) { @@ -614,7 +631,7 @@ function import_post(&$a) { -// FIXME - ensure we have a self entry if somebody is trying to pull a fast one + // FIXME - ensure we have a self entry if somebody is trying to pull a fast one // send out refresh requests // notify old server that it may no longer be primary. diff --git a/mod/like.php b/mod/like.php index 9077adbda..2992319af 100755 --- a/mod/like.php +++ b/mod/like.php @@ -486,9 +486,9 @@ function like_content(&$a) { dbesc($ch[0]['channel_hash']), intval($post_id), dbesc($activity), - dbesc(($tgttype)?$tgttype:$objtype), + dbesc(($tgttype)? $tgttype : $objtype), dbesc($obj_id), - dbesc(json_encode(($target)?$target:$object)) + dbesc(($target) ? $target : $object) ); }; -- cgit v1.2.3 From 417da13353431ddadafe661803115cf9dd9bf9ca Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 31 Aug 2015 21:12:37 -0700 Subject: this is a bit harder than anticipated. --- mod/import.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'mod') diff --git a/mod/import.php b/mod/import.php index fb04a021a..0c5ec2a4c 100644 --- a/mod/import.php +++ b/mod/import.php @@ -557,20 +557,21 @@ function import_post(&$a) { } - $objs = $data['obj']; - if($objs) { - foreach($objs as $obj) { - unset($obj['obj_id']); - $obj['channel'] = $channel['channel_id']; - - dbesc_array($obj); - $r = dbq("INSERT INTO obj (`" - . implode("`, `", array_keys($obj)) - . "`) VALUES ('" - . implode("', '", array_values($obj)) - . "')" ); - } - } +// This needs more work - we also need the term where otype = 6 to link with this, and the terms need to be relocated. +// $objs = $data['obj']; +// if($objs) { +// foreach($objs as $obj) { +// unset($obj['obj_id']); +// $obj['channel'] = $channel['channel_id']; + +// dbesc_array($obj); +// $r = dbq("INSERT INTO obj (`" +// . implode("`, `", array_keys($obj)) +// . "`) VALUES ('" +// . implode("', '", array_values($obj)) +// . "')" ); +// } +// } $saved_notification_flags = notifications_off($channel['channel_id']); -- cgit v1.2.3