Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
7.1 KiB

  1. <?php
  2. /**
  3. * @file src/Content/ContactSelector.php
  4. */
  5. namespace Friendica\Content;
  6. use Friendica\Core\Addon;
  7. use Friendica\Core\L10n;
  8. use Friendica\Core\Protocol;
  9. use Friendica\Core\System;
  10. use Friendica\Database\DBA;
  11. use Friendica\Util\Network;
  12. use Friendica\Util\Strings;
  13. /**
  14. * @brief ContactSelector class
  15. */
  16. class ContactSelector
  17. {
  18. /**
  19. * @param string $current current
  20. * @param string $foreign_net network
  21. */
  22. public static function profileAssign($current, $foreign_net)
  23. {
  24. $o = '';
  25. $disabled = (($foreign_net) ? ' disabled="true" ' : '');
  26. $o .= "<select id=\"contact-profile-selector\" class=\"form-control\" $disabled name=\"profile-assign\" >\r\n";
  27. $s = DBA::select('profile', ['id', 'profile-name', 'is-default'], ['uid' => $_SESSION['uid']]);
  28. $r = DBA::toArray($s);
  29. if (DBA::isResult($r)) {
  30. foreach ($r as $rr) {
  31. $selected = (($rr['id'] == $current || ($current == 0 && $rr['is-default'] == 1)) ? " selected=\"selected\" " : "");
  32. $o .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
  33. }
  34. }
  35. $o .= "</select>\r\n";
  36. return $o;
  37. }
  38. /**
  39. * @param string $current current
  40. * @param boolean $disabled optional, default false
  41. * @return object
  42. */
  43. public static function pollInterval($current, $disabled = false)
  44. {
  45. $dis = (($disabled) ? ' disabled="disabled" ' : '');
  46. $o = '';
  47. $o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
  48. $rep = [
  49. 0 => L10n::t('Frequently'),
  50. 1 => L10n::t('Hourly'),
  51. 2 => L10n::t('Twice daily'),
  52. 3 => L10n::t('Daily'),
  53. 4 => L10n::t('Weekly'),
  54. 5 => L10n::t('Monthly')
  55. ];
  56. foreach ($rep as $k => $v) {
  57. $selected = (($k == $current) ? " selected=\"selected\" " : "");
  58. $o .= "<option value=\"$k\" $selected >$v</option>\r\n";
  59. }
  60. $o .= "</select>\r\n";
  61. return $o;
  62. }
  63. /**
  64. * @param string $network network
  65. * @param string $profile optional, default empty
  66. * @return string
  67. */
  68. public static function networkToName($network, $profile = "")
  69. {
  70. $nets = [
  71. Protocol::DFRN => L10n::t('Friendica'),
  72. Protocol::OSTATUS => L10n::t('OStatus'),
  73. Protocol::FEED => L10n::t('RSS/Atom'),
  74. Protocol::MAIL => L10n::t('Email'),
  75. Protocol::DIASPORA => L10n::t('Diaspora'),
  76. Protocol::ZOT => L10n::t('Zot!'),
  77. Protocol::LINKEDIN => L10n::t('LinkedIn'),
  78. Protocol::XMPP => L10n::t('XMPP/IM'),
  79. Protocol::MYSPACE => L10n::t('MySpace'),
  80. Protocol::GPLUS => L10n::t('Google+'),
  81. Protocol::PUMPIO => L10n::t('pump.io'),
  82. Protocol::TWITTER => L10n::t('Twitter'),
  83. Protocol::DIASPORA2 => L10n::t('Diaspora Connector'),
  84. Protocol::STATUSNET => L10n::t('GNU Social Connector'),
  85. Protocol::ACTIVITYPUB => L10n::t('ActivityPub'),
  86. Protocol::PNUT => L10n::t('pnut'),
  87. ];
  88. Addon::callHooks('network_to_name', $nets);
  89. $search = array_keys($nets);
  90. $replace = array_values($nets);
  91. $networkname = str_replace($search, $replace, $network);
  92. if ((in_array($network, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) {
  93. // Create the server url out of the profile url
  94. $parts = parse_url($profile);
  95. unset($parts['path']);
  96. $server_url = [Strings::normaliseLink(Network::unparseURL($parts))];
  97. // Fetch the server url
  98. $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]);
  99. if (!empty($gcontact) && !empty($gcontact['server_url'])) {
  100. $server_url[] = Strings::normaliseLink($gcontact['server_url']);
  101. }
  102. // Now query the GServer for the platform name
  103. $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
  104. if (DBA::isResult($gserver)) {
  105. if (!empty($gserver['platform'])) {
  106. $platform = $gserver['platform'];
  107. } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
  108. $platform = self::networkToName($gserver['network']);
  109. }
  110. if (!empty($platform)) {
  111. $networkname = $platform;
  112. if ($network == Protocol::ACTIVITYPUB) {
  113. $networkname .= ' (AP)';
  114. }
  115. }
  116. }
  117. }
  118. return $networkname;
  119. }
  120. /**
  121. * @param string $current optional, default empty
  122. * @param string $suffix optionsl, default empty
  123. */
  124. public static function gender($current = "", $suffix = "")
  125. {
  126. $o = '';
  127. $select = ['', L10n::t('Male'), L10n::t('Female'), L10n::t('Currently Male'), L10n::t('Currently Female'), L10n::t('Mostly Male'), L10n::t('Mostly Female'), L10n::t('Transgender'), L10n::t('Intersex'), L10n::t('Transsexual'), L10n::t('Hermaphrodite'), L10n::t('Neuter'), L10n::t('Non-specific'), L10n::t('Other'), L10n::t('Undecided')];
  128. Addon::callHooks('gender_selector', $select);
  129. $o .= "<select name=\"gender$suffix\" id=\"gender-select$suffix\" size=\"1\" >";
  130. foreach ($select as $selection) {
  131. if ($selection !== 'NOTRANSLATION') {
  132. $selected = (($selection == $current) ? ' selected="selected" ' : '');
  133. $o .= "<option value=\"$selection\" $selected >$selection</option>";
  134. }
  135. }
  136. $o .= '</select>';
  137. return $o;
  138. }
  139. /**
  140. * @param string $current optional, default empty
  141. * @param string $suffix optionsl, default empty
  142. */
  143. public static function sexualPreference($current = "", $suffix = "")
  144. {
  145. $o = '';
  146. $select = ['', L10n::t('Males'), L10n::t('Females'), L10n::t('Gay'), L10n::t('Lesbian'), L10n::t('No Preference'), L10n::t('Bisexual'), L10n::t('Autosexual'), L10n::t('Abstinent'), L10n::t('Virgin'), L10n::t('Deviant'), L10n::t('Fetish'), L10n::t('Oodles'), L10n::t('Nonsexual')];
  147. Addon::callHooks('sexpref_selector', $select);
  148. $o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
  149. foreach ($select as $selection) {
  150. if ($selection !== 'NOTRANSLATION') {
  151. $selected = (($selection == $current) ? ' selected="selected" ' : '');
  152. $o .= "<option value=\"$selection\" $selected >$selection</option>";
  153. }
  154. }
  155. $o .= '</select>';
  156. return $o;
  157. }
  158. /**
  159. * @param string $current optional, default empty
  160. */
  161. public static function maritalStatus($current = "")
  162. {
  163. $o = '';
  164. $select = ['', L10n::t('Single'), L10n::t('Lonely'), L10n::t('Available'), L10n::t('Unavailable'), L10n::t('Has crush'), L10n::t('Infatuated'), L10n::t('Dating'), L10n::t('Unfaithful'), L10n::t('Sex Addict'), L10n::t('Friends'), L10n::t('Friends/Benefits'), L10n::t('Casual'), L10n::t('Engaged'), L10n::t('Married'), L10n::t('Imaginarily married'), L10n::t('Partners'), L10n::t('Cohabiting'), L10n::t('Common law'), L10n::t('Happy'), L10n::t('Not looking'), L10n::t('Swinger'), L10n::t('Betrayed'), L10n::t('Separated'), L10n::t('Unstable'), L10n::t('Divorced'), L10n::t('Imaginarily divorced'), L10n::t('Widowed'), L10n::t('Uncertain'), L10n::t('It\'s complicated'), L10n::t('Don\'t care'), L10n::t('Ask me')];
  165. Addon::callHooks('marital_selector', $select);
  166. $o .= '<select name="marital" id="marital-select" size="1" >';
  167. foreach ($select as $selection) {
  168. if ($selection !== 'NOTRANSLATION') {
  169. $selected = (($selection == $current) ? ' selected="selected" ' : '');
  170. $o .= "<option value=\"$selection\" $selected >$selection</option>";
  171. }
  172. }
  173. $o .= '</select>';
  174. return $o;
  175. }
  176. }