streams/Zotlabs/Module/Affinity.php

93 lines
3 KiB
PHP
Raw Normal View History

<?php
namespace Zotlabs\Module;
use Zotlabs\Lib\Apps;
use Zotlabs\Lib\Libsync;
2021-12-02 22:33:36 +00:00
use Zotlabs\Web\Controller;
2021-12-02 23:02:31 +00:00
class Affinity extends Controller
{
2021-12-02 23:02:31 +00:00
public function post()
{
2021-12-02 23:02:31 +00:00
if (!(local_channel() && Apps::system_app_installed(local_channel(), 'Friend Zoom'))) {
return;
}
2021-12-02 23:02:31 +00:00
if ($_POST['affinity-submit']) {
$cmax = intval($_POST['affinity_cmax']);
2021-12-03 03:01:39 +00:00
if ($cmax < 0 || $cmax > 99) {
2021-12-02 23:02:31 +00:00
$cmax = 99;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$cmin = intval($_POST['affinity_cmin']);
2021-12-03 03:01:39 +00:00
if ($cmin < 0 || $cmin > 99) {
2021-12-02 23:02:31 +00:00
$cmin = 0;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
set_pconfig(local_channel(), 'affinity', 'cmin', 0);
set_pconfig(local_channel(), 'affinity', 'cmax', $cmax);
2021-12-02 23:02:31 +00:00
info(t('Friend Zoom settings updated.') . EOL);
}
Libsync::build_sync_packet();
}
2021-12-02 23:02:31 +00:00
public function get()
{
2020-02-13 05:36:21 +00:00
$desc = t('This app (when installed) presents a slider control in your connection editor and also on your stream page. The slider represents your degree of friendship with each connection. It allows you to zoom in or out and display conversations from only your closest friends or everybody in your stream.');
$text = '<div class="section-content-info-wrapper">' . $desc . '</div>';
2021-12-02 23:02:31 +00:00
if (!(local_channel() && Apps::system_app_installed(local_channel(), 'Friend Zoom'))) {
return $text;
}
2021-12-02 23:02:31 +00:00
$text .= EOL . t('The number below represents the default maximum slider position for your stream page as a percentage.') . EOL . EOL;
2021-12-02 23:02:31 +00:00
$setting_fields = $text;
2021-12-02 23:02:31 +00:00
$cmax = intval(get_pconfig(local_channel(), 'affinity', 'cmax'));
$cmax = (($cmax) ? $cmax : 99);
2021-12-03 03:01:39 +00:00
// $setting_fields .= replace_macros(get_markup_template('field_input.tpl'), array(
// '$field' => array('affinity_cmax', t('Default maximum affinity level'), $cmax, t('0-99 default 99'))
// ));
2021-12-02 23:02:31 +00:00
if (Apps::system_app_installed(local_channel(), 'Friend Zoom')) {
$labels = array(
0 => t('Me'),
20 => t('Family'),
40 => t('Friends'),
60 => t('Peers'),
80 => t('Connections'),
99 => t('All')
);
call_hooks('affinity_labels', $labels);
$tpl = get_markup_template('affinity.tpl');
$x = replace_macros($tpl, [
'$cmin' => 0,
'$cmax' => $cmax,
'$lbl' => t('Default friend zoom in/out'),
'$refresh' => t('Refresh'),
'$labels' => $labels,
]);
$arr = array('html' => $x);
call_hooks('affinity_slider', $arr);
$setting_fields .= $arr['html'];
}
$s .= replace_macros(get_markup_template('generic_app_settings.tpl'), array(
'$addon' => array('affinity', '' . t('Friend Zoom Settings'), '', t('Submit')),
'$content' => $setting_fields
));
return $s;
}
2021-12-03 03:01:39 +00:00
}