Merge branch 'dev' of /home/macgirvin/z into dev

This commit is contained in:
nobody 2021-03-31 18:30:58 -07:00
commit a125379844
12 changed files with 451 additions and 23 deletions

View file

@ -357,6 +357,32 @@ class Activity {
static function encode_simple_collection($items,$id,$type,$total = 0,$extra = null) {
$ret = [
'id' => z_root() . '/' . $id,
'type' => $type,
'totalItems' => $total,
];
if ($extra) {
$ret = array_merge($ret,$extra);
}
if ($items) {
if ($type === 'OrderedCollection') {
$ret['orderedItems'] = $items;
}
else {
$ret['items'] = $items;
}
}
return $ret;
}
static function decode_taxonomy($item) {

103
Zotlabs/Module/Album.php Normal file
View file

@ -0,0 +1,103 @@
<?php
namespace Zotlabs\Module;
use App;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\ActivityStreams;
use Zotlabs\Lib\Config;
use Zotlabs\Lib\LDSignatures;
use Zotlabs\Web\HTTPSig;
require_once('include/security.php');
require_once('include/attach.php');
require_once('include/photo_factory.php');
require_once('include/photos.php');
class Album extends Controller {
function init() {
if (ActivityStreams::is_as_request()) {
$sigdata = HTTPSig::verify(EMPTY_STR);
if ($sigdata['portable_id'] && $sigdata['header_valid']) {
$portable_id = $sigdata['portable_id'];
if (! check_channelallowed($portable_id)) {
http_status_exit(403, 'Permission denied');
}
if (! check_siteallowed($sigdata['signer'])) {
http_status_exit(403, 'Permission denied');
}
observer_auth($portable_id);
}
elseif (Config::get('system','require_authenticated_fetch',false)) {
http_status_exit(403,'Permission denied');
}
$observer_xchan = get_observer_hash();
$allowed = false;
$bear = Activity::token_from_request();
if ($bear) {
logger('bear: ' . $bear, LOGGER_DEBUG);
}
$channel = null;
if (argc() > 1) {
$channel = channelx_by_nick(argv(1));
}
if (! $channel) {
http_status_exit(404,'Not found.');
}
$sql_extra = permissions_sql($channel['channel_id'],$observer_xchan);
if (argc() > 2) {
$folder = argv(2);
$r = q("select * from attach where is_dir = 1 and hash = '%s' and uid = %d $sql_extra limit 1",
dbesc($folder),
intval($channel['channel_id'])
);
$allowed = (($r) ? attach_can_view($channel['channel_id'],$observer_xchan,$r[0]['hash'],$bear) : false);
}
else {
$folder = EMPTY_STR;
$allowed = perm_is_allowed($channel['channel_id'],$observer_xchan,'view_storage');
}
if (! $allowed) {
http_status_exit(403,'Permission denied.');
}
$x = q("select * from attach where folder = '%s' and uid = %d $sql_extra",
dbesc($folder),
intval($channel['channel_id'])
);
$contents = [];
if ($x) {
foreach ($x as $xv) {
if (intval($xv['is_dir'])) {
continue;
}
if (! attach_can_view($channel['channel_id'],$observer_xchan,$xv['hash'],$bear)) {
continue;
}
if (intval($xv['is_photo'])) {
$contents[] = z_root() . '/photo/' . $xv['hash'];
}
}
}
$obj = Activity::encode_simple_collection($contents, App::$query_string, 'OrderedCollection', count($contents));
as_return_and_die($obj,$channel);
}
}
}

View file

@ -20,6 +20,41 @@ class Outbox extends Controller {
function init() {
}
function post() {
if (argc() < 2) {
killme();
}
$channel = channelx_by_nick(argv(1));
if (! $channel) {
killme();
}
if (intval($channel['channel_system'])) {
killme();
}
$observer = App::get_observer();
if (! $observer) {
killme();
}
}
function get() {
if (observer_prohibited(true)) {
killme();
}

View file

@ -4,6 +4,7 @@ namespace Zotlabs\Module;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\ActivityStreams;
use Zotlabs\Lib\Config;
use Zotlabs\Lib\LDSignatures;
use Zotlabs\Web\HTTPSig;
@ -19,6 +20,22 @@ class Photo extends Controller {
if (ActivityStreams::is_as_request()) {
$sigdata = HTTPSig::verify(EMPTY_STR);
if ($sigdata['portable_id'] && $sigdata['header_valid']) {
$portable_id = $sigdata['portable_id'];
if (! check_channelallowed($portable_id)) {
http_status_exit(403, 'Permission denied');
}
if (! check_siteallowed($sigdata['signer'])) {
http_status_exit(403, 'Permission denied');
}
observer_auth($portable_id);
}
elseif (Config::get('system','require_authenticated_fetch',false)) {
http_status_exit(403,'Permission denied');
}
$observer_xchan = get_observer_hash();
$allowed = false;

View file

@ -740,13 +740,14 @@ class Photos extends Controller {
$order = 'created DESC';
$r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.imgscale, p.description, p.created FROM photo p INNER JOIN
(SELECT resource_id, max(imgscale) imgscale FROM photo left join attach on folder = '%s' and photo.resource_id = attach.hash WHERE attach.uid = %d AND imgscale <= 4 AND photo_usage IN ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY resource_id) ph
(SELECT resource_id, max(imgscale) imgscale FROM photo left join attach on folder = '%s' and photo.resource_id = attach.hash WHERE attach.uid = %d AND imgscale <= 4 AND photo_usage IN ( %d, %d, %d ) and is_nsfw = %d $sql_extra GROUP BY resource_id) ph
ON (p.resource_id = ph.resource_id AND p.imgscale = ph.imgscale)
ORDER BY $order LIMIT %d OFFSET %d",
dbesc($x['hash']),
intval($owner_uid),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
intval(PHOTO_COVER),
intval($unsafe),
intval(App::$pager['itemspage']),
intval(App::$pager['start'])

View file

@ -374,6 +374,7 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota, DAV\IMo
$args = [
'resource_id' => $hash,
'album' => $album,
'folder' => $this->folder_hash,
'os_syspath' => $f,
'os_path' => $xpath['os_path'],
'display_path' => $xpath['path'],

View file

@ -172,6 +172,7 @@ class File extends DAV\Node implements DAV\IFile {
$os_path = $r[0]['os_path'];
$display_path = $r[0]['display_path'];
$filename = $r[0]['filename'];
$folder_hash = $r[0]['folder'];
if (intval($r[0]['os_storage'])) {
$d = q("select folder, content from attach where hash = '%s' and uid = %d limit 1",
@ -261,6 +262,7 @@ class File extends DAV\Node implements DAV\IFile {
$args = [
'resource_id' => $this->data['hash'],
'album' => $album,
'folder' => $folder_hash,
'os_syspath' => $f,
'os_path' => $os_path,
'display_path' => $display_path,

View file

@ -214,22 +214,15 @@ To register a hook using a class method as a callback, a couple of things need t
function myplugin_load() {
Zotlabs\Extend\Hook::register('hook_name','addon/myplugin/myplugin.php','\\Myplugin::foo');
[b]or[/b]
Zotlabs\Extend\Hook::register('hook_name','addon/myplugin/myplugin.php',array('\\Myplugin','foo'));
/* The next line is identical in how it behaves, but uses a slightly different method */
Zotlabs\Extend\Hook::register('hook_name','addon/myplugin/myplugin.php', [ '\\Myplugin', 'foo' ]);
}
class Myplugin {
public static function foo($params) {
// handler for 'hook_name'
/* handler for 'hook_name' */
}
}
[/code]
If you want to keep your plugin hidden from the siteinfo page, simply create a file called '.hidden' in your addon directory
[code]
touch addon/<addon name>/.hidden
[/code]
***Porting Friendica Plugins***

245
doc/en/hooklist.mc Normal file
View file

@ -0,0 +1,245 @@
{{module}}_mod_aftercontent
{{module}}_mod_content
{{module}}_mod_init
{{module}}_mod_post
about_hook
accept_follow
account_downgrade
account_settings
account_settings_post
activity_filter
activity_mapper
activity_obj_mapper
activity_order
activity_received
activity_widget
addon_app_installed_filter
admin_aside
admin_channels
affinity_labels
affinity_slider
alter_pdl
anon_identity_init
api_format_items
api_not_found
api_perm_is_allowed
api_register
app_destroy
app_installed_filter
app_list
atom_author
atom_entry
atom_feed
atom_feed_end
atom_feed_top
atom_render_author
attach_upload_file
authenticate
author_is_pmable
bb_to_markdown
bb_to_markdown_bb
bb_translate_video
bbcode
bbcode_filter
build_pagehead
can_comment_on_post
change_channel
channel_apps
channel_links
channel_remove
channel_settings
chat_message
chat_post
check_account_email
check_account_invite
check_account_password
check_channelallowed
check_pubstream_channelallowed
check_siteallowed
comment_buttons
comments_are_now_closed
connect_premium
connection_remove
construct_page
contact_block_end
contact_edit
contact_edit_post
content_security_policy
conv_sort
conversation_start
cover_photo_content_end
create_channel_photo
create_identity
cron
cron_daily
cron_weekly
crypto_encapsulate
crypto_methods
crypto_unencapsulate
customitem_deliver
daemon_addon
daemon_release
daemon_summon
decode_note
default_profile_photo
directory_item
discover_channel_webfinger
display_item
display_settings
display_settings_post
dreport_is_storable
dreport_process
drop_item
dropdown_extras
email_send
encode_object
encode_person
enotify
enotify_format
enotify_mail
enotify_store
event_created
event_store_event
event_updated
extend_cookie
feature_enabled
feature_settings
feature_settings_post
federated_transports
fetch_and_store
file_thumbnail
follow
gender_selector
gender_selector_min
generate_map
generate_named_map
get_all_api_perms
get_all_perms
get_base_apps
get_best_language
get_default_export_sections
get_features
get_profile_photo
get_role_perms
get_system_apps
home_content
home_init
hostxrd
html2bb_video
html2bbcode
identity_basic_export
import_author
import_author_xchan
import_channel
import_directory_profile
import_foreign_channel_data
import_xchan
item_custom_display
item_store
item_store_before
item_store_update_before
item_translate
jot_networks
jot_tool
legal_webbie
legal_webbie_text
list_permission_roles
load_pdl
local_dir_update
location_move
logged_in
logger
logging_out
login_hook
magic_auth
magic_auth_success
main_slider
marital_selector
marital_selector_min
markdown_to_bb
markdown_to_bb_init
module_loaded
mood_verbs
nav
network_ping
network_to_name
new_cookie
nodeinfo
notifier_end
notifier_hub
notifier_normal
notifier_process
obj_verbs
oembed_action
oembed_probe
page_content_top
page_end
page_header
page_not_found
parse_link
pdl_selector
perm_is_allowed
permcats
permission_limits_get
permissions_list
photo_post_end
photo_upload_begin
photo_upload_end
photo_upload_file
photo_upload_form
poke_verbs
post_content
post_local
post_local_end
post_local_start
post_remote
post_remote_end
post_remote_update
post_remote_update_end
prepare_body
prepare_body_final
prepare_body_init
proc_run
process_channel_sync_delivery
profile_advanced
profile_edit
profile_photo_content_end
profile_post
profile_sidebar
profile_sidebar_enter
profile_tabs
pronouns_selector
pubstream_check_siteallowed
queue_deliver
register_account
render_location
replace_macros
reverse_magic_auth
service_plink
settings_form
settings_post
sexpref_selector
sexpref_selector_min
signing_methods
smilie
startup
status_editor
stream_content_init
stream_item
system_app_installed_filter
tagged
text_highlight
thread_action_menu
thread_author_menu
thumbnail
update_unseen
validate_channelname
webfinger
well_known
write_perms
zid
zid_init
zidify
zot_best_algorithm
zot_revision
zotinfo

View file

@ -931,7 +931,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if($is_photo) {
$args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => $pathname, 'os_syspath' => $os_basepath . $os_relpath, 'os_path' => $os_path, 'display_path' => $display_path, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options );
$args = array( 'source' => $source, 'visible' => $visible, 'resource_id' => $hash, 'album' => $pathname, 'folder' => $folder_hash, 'os_syspath' => $os_basepath . $os_relpath, 'os_path' => $os_path, 'display_path' => $display_path, 'filename' => $filename, 'getimagesize' => $gis, 'directory' => $direct, 'options' => $options );
if($arr['contact_allow'])
$args['contact_allow'] = $arr['contact_allow'];
if($arr['group_allow'])

View file

@ -426,13 +426,11 @@ function photo_upload($channel, $observer, $args) {
$object['to'] = Activity::map_acl(array_merge($ac, ['item_private' => 1 - intval($public) ]));
}
// @FIXME - update to collection
// $target = array(
// 'type' => ACTIVITY_OBJ_ALBUM,
// 'title' => (($album) ? $album : '/'),
// 'id' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album)
// );
$target = [
'type' => 'orderedCollection',
'name' => ((strlen($album)) ? $album : '/'),
'id' => z_root() . '/album/' . $channel['channel_address'] . ((isset($args['folder'])) ? '/' . $args['folder'] : EMPTY_STR)
];
// Create item container
if($args['item']) {
@ -449,8 +447,8 @@ function photo_upload($channel, $observer, $args) {
$item['obj_type'] = ACTIVITY_OBJ_PHOTO;
$item['obj'] = json_encode($object);
// $item['tgt_type'] = ACTIVITY_OBJ_ALBUM;
// $item['target'] = json_encode($target);
$item['tgt_type'] = 'orderedCollection';
$item['target'] = json_encode($target);
$force = true;
}
@ -501,8 +499,8 @@ function photo_upload($channel, $observer, $args) {
'verb' => ACTIVITY_POST,
'obj_type' => ACTIVITY_OBJ_PHOTO,
'obj' => json_encode($object),
// 'tgt_type' => ACTIVITY_OBJ_ALBUM,
// 'target' => json_encode($target),
'tgt_type' => 'orderedCollection',
'target' => json_encode($target),
'item_wall' => 1,
'item_origin' => 1,
'item_thread_top' => 1,

7
util/genhook Normal file
View file

@ -0,0 +1,7 @@
/bin/rm hook1
grep -r call_hooks --exclude-dir=.git --exclude-dir=cache --exclude-dir=logs --exclude-dir=store * > hook1
awk -F\' '{ print $2};' < hook1 > hook2
sed -i '/^\s*$/d' hook2
sort < hook2 | uniq > hooklist.mc
/bin/rm hook1
/bin/rm hook2