diff options
author | Habeas Codice <habeascodice@federated.social> | 2015-02-05 09:15:39 -0800 |
---|---|---|
committer | Habeas Codice <habeascodice@federated.social> | 2015-02-05 09:15:39 -0800 |
commit | 9ed23f9081b56369349d4e06c51e3856f950804e (patch) | |
tree | b3a1121ec41e04cce02cfa07fc958b95a3fd289b /include/ratenotif.php | |
parent | 88488fdfbb58aa04b450af1691aba7cea1bce8ab (diff) | |
parent | 646a874390be8f92736866118d7215e8cb80fb8a (diff) | |
download | volse-hubzilla-9ed23f9081b56369349d4e06c51e3856f950804e.tar.gz volse-hubzilla-9ed23f9081b56369349d4e06c51e3856f950804e.tar.bz2 volse-hubzilla-9ed23f9081b56369349d4e06c51e3856f950804e.zip |
Merge branch 'master' of https://github.com/friendica/red
Diffstat (limited to 'include/ratenotif.php')
-rw-r--r-- | include/ratenotif.php | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/include/ratenotif.php b/include/ratenotif.php new file mode 100644 index 000000000..4fa0077a6 --- /dev/null +++ b/include/ratenotif.php @@ -0,0 +1,124 @@ +<?php + +require_once('include/cli_startup.php'); +require_once('include/zot.php'); +require_once('include/queue_fn.php'); + + +function ratenotif_run($argv, $argc){ + + cli_startup(); + + $a = get_app(); + + require_once("session.php"); + require_once("datetime.php"); + require_once('include/items.php'); + require_once('include/Contact.php'); + + if($argc < 3) + return; + + + logger('ratenotif: invoked: ' . print_r($argv,true), LOGGER_DEBUG); + + $cmd = $argv[1]; + + $item_id = $argv[2]; + + + if($cmd === 'rating') { + $r = q("select * from xlink where xlink_id = %d and xlink_static = 1 limit 1", + intval($item_id) + ); + if(! $r) { + logger('rating not found'); + return; + } + + $encoded_item = array( + 'type' => 'rating', + 'encoding' => 'zot', + 'target' => $r[0]['xlink_link'], + 'rating' => intval($r[0]['xlink_rating']), + 'rating_text' => $r[0]['xlink_rating_text'], + 'signature' => $r[0]['xlink_sig'], + 'edited' => $r[0]['xlink_updated'] + ); + } + + $channel = channelx_by_hash($r[0]['xlink_xchan']); + if(! $channel) { + logger('no channel'); + return; + } + + + $primary = get_directory_primary(); + + if(! $primary) + return; + + + $interval = ((get_config('system','delivery_interval') !== false) + ? intval(get_config('system','delivery_interval')) : 2 ); + + $deliveries_per_process = intval(get_config('system','delivery_batch_count')); + + if($deliveries_per_process <= 0) + $deliveries_per_process = 1; + + $deliver = array(); + + $x = z_fetch_url($primary . '/regdir'); + if($x['success']) { + $j = json_decode($x['body'],true); + if($j && $j['success'] && is_array($j['directories'])) { + + foreach($j['directories'] as $h) { +// if($h == z_root()) +// continue; + + $hash = random_string(); + $n = zot_build_packet($channel,'notify',null,null,$hash); + + q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )", + dbesc($hash), + intval($channel['channel_account_id']), + intval($channel['channel_id']), + dbesc('zot'), + dbesc($h . '/post'), + intval(1), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc($n), + dbesc(json_encode($encoded_item)) + ); + } + $deliver[] = $hash; + + if(count($deliver) >= $deliveries_per_process) { + proc_run('php','include/deliver.php',$deliver); + $deliver = array(); + if($interval) + @time_sleep_until(microtime(true) + (float) $interval); + } + + + // catch any stragglers + + if(count($deliver)) { + proc_run('php','include/deliver.php',$deliver); + } + } + } + + logger('ratenotif: complete.'); + return; + +} + +if (array_search(__file__,get_included_files())===0){ + ratenotif_run($argv,$argc); + killme(); +} |