}
/**
- * @param string $type
+ * Display a generic filter widget based on a list of options
+ *
+ * The options array must be the following format:
+ * [
+ * [
+ * 'ref' => {filter value},
+ * 'name' => {option name}
+ * ],
+ * ...
+ * ]
+ *
+ * @param string $type The filter query string key
* @param string $title
* @param string $desc
- * @param string $all
- * @param string $baseUrl
+ * @param string $all The no filter label
+ * @param string $baseUrl The full page request URI
* @param array $options
- * @param string $selected
+ * @param string $selected The currently selected filter option value
* @return string
* @throws \Exception
*/
- public static function filter($type, $title, $desc, $all, $baseUrl, array $options, $selected = null)
+ private static function filter($type, $title, $desc, $all, $baseUrl, array $options, $selected = null)
{
$queryString = parse_url($baseUrl, PHP_URL_QUERY);
$queryArray = [];
]);
}
+ /**
+ * Return networks widget
+ *
+ * @param string $baseurl baseurl
+ * @param string $selected optional, default empty
+ * @return string
+ * @throws \Exception
+ */
+ public static function contactRels($baseurl, $selected = '')
+ {
+ if (!local_user()) {
+ return '';
+ }
+
+ $options = [
+ ['ref' => 'followers', 'name' => L10n::t('Followers')],
+ ['ref' => 'following', 'name' => L10n::t('Following')],
+ ['ref' => 'mutuals', 'name' => L10n::t('Mutual friends')],
+ ];
+
+ return self::filter(
+ 'rel',
+ L10n::t('Relationships'),
+ '',
+ L10n::t('All Contacts'),
+ $baseurl,
+ $options,
+ $selected
+ );
+ }
+
/**
* Return networks widget
*
$a = self::getApp();
$nets = defaults($_GET, 'nets', '');
+ $rel = defaults($_GET, 'rel' , '');
if (empty($a->page['aside'])) {
$a->page['aside'] = '';
$findpeople_widget = '';
$follow_widget = '';
$networks_widget = '';
+ $rel_widget = '';
} else {
$vcard_widget = '';
$findpeople_widget = Widget::findPeople();
}
$networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
+ $rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
}
if ($contact['uid'] != 0) {
$groups_widget = null;
}
- $a->page['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget;
+ $a->page['aside'] .= $vcard_widget . $findpeople_widget . $follow_widget . $groups_widget . $networks_widget . $rel_widget;
$tpl = Renderer::getMarkupTemplate('contacts-head.tpl');
$a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
$search = Strings::escapeTags(trim(defaults($_GET, 'search', '')));
$nets = Strings::escapeTags(trim(defaults($_GET, 'nets' , '')));
+ $rel = Strings::escapeTags(trim(defaults($_GET, 'rel' , '')));
$tabs = [
[
$sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
}
+ switch ($rel) {
+ case 'followers': $sql_extra .= " AND `rel` IN (1, 3)"; break;
+ case 'following': $sql_extra .= " AND `rel` IN (2, 3)"; break;
+ case 'mutuals': $sql_extra .= " AND `rel` = 3"; break;
+ }
+
$sql_extra .= " AND NOT `deleted` ";
$sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : '');
}
}
+ switch ($rel) {
+ case 'followers': $header = L10n::t('Followers'); break;
+ case 'following': $header = L10n::t('Following'); break;
+ case 'mutuals': $header = L10n::t('Mutual friends'); break;
+ default: $header = L10n::t('Contacts');
+ }
+
switch ($type) {
case 'blocked': $header .= ' - ' . L10n::t('Blocked'); break;
case 'hidden': $header .= ' - ' . L10n::t('Hidden'); break;