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.
 
 
 
 
 
 

369 lines
10 KiB

  1. <?php
  2. /**
  3. * Name: Vier
  4. * Version: 1.2
  5. * Author: Fabio <http://kirgroup.com/profile/fabrixxm>
  6. * Author: Ike <http://pirati.ca/profile/heluecht>
  7. * Author: Beanow <https://fc.oscp.info/profile/beanow>
  8. * Maintainer: Ike <http://pirati.ca/profile/heluecht>
  9. * Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
  10. */
  11. use Friendica\App;
  12. use Friendica\Content\ForumManager;
  13. use Friendica\Core\Addon;
  14. use Friendica\Core\Config;
  15. use Friendica\Core\L10n;
  16. use Friendica\Core\Renderer;
  17. use Friendica\Core\Search;
  18. use Friendica\Database\DBA;
  19. use Friendica\DI;
  20. use Friendica\Model\Contact;
  21. use Friendica\Model\GContact;
  22. use Friendica\Util\Proxy as ProxyUtils;
  23. use Friendica\Util\Strings;
  24. function vier_init(App $a)
  25. {
  26. $a->theme_events_in_profile = false;
  27. Renderer::setActiveTemplateEngine('smarty3');
  28. if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . $a->user['nickname']) || $a->argv[0] === 'network' && local_user()) {
  29. vier_community_info();
  30. DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
  31. }
  32. if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
  33. DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
  34. DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
  35. }
  36. /// @todo deactivated since it doesn't work with desktop browsers at the moment
  37. //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
  38. DI::page()['htmlhead'] .= <<< EOT
  39. <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
  40. <script type="text/javascript">
  41. function showThread(id) {
  42. $("#collapsed-comments-" + id).show()
  43. $("#collapsed-comments-" + id + " .collapsed-comments").show()
  44. }
  45. function hideThread(id) {
  46. $("#collapsed-comments-" + id).hide()
  47. $("#collapsed-comments-" + id + " .collapsed-comments").hide()
  48. }
  49. function cmtBbOpen(id) {
  50. $("#comment-edit-bb-" + id).show();
  51. }
  52. function cmtBbClose(id) {
  53. $("#comment-edit-bb-" + id).hide();
  54. }
  55. </script>
  56. EOT;
  57. if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
  58. DI::page()['htmlhead'] .= <<< EOT
  59. <script>
  60. $(document).ready(function() {
  61. $(".mobile-aside-toggle a").click(function(e){
  62. e.preventDefault();
  63. $("aside").toggleClass("show");
  64. });
  65. $(".tabs").click(function(e){
  66. $(this).toggleClass("show");
  67. });
  68. });
  69. </script>
  70. EOT;
  71. }
  72. // Hide the left menu bar
  73. /// @TODO maybe move this static array out where it should belong?
  74. if (empty(DI::page()['aside']) && in_array($a->argv[0], ["community", "events", "help", "delegation", "notifications",
  75. "probe", "webfinger", "login", "invite", "credits"])) {
  76. DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
  77. }
  78. }
  79. function get_vier_config($key, $default = false, $admin = false)
  80. {
  81. if (local_user() && !$admin) {
  82. $result = DI::pConfig()->get(local_user(), "vier", $key);
  83. if (!is_null($result)) {
  84. return $result;
  85. }
  86. }
  87. $result = Config::get("vier", $key);
  88. if (!is_null($result)) {
  89. return $result;
  90. }
  91. return $default;
  92. }
  93. function vier_community_info()
  94. {
  95. $a = DI::app();
  96. $show_pages = get_vier_config("show_pages", 1);
  97. $show_profiles = get_vier_config("show_profiles", 1);
  98. $show_helpers = get_vier_config("show_helpers", 1);
  99. $show_services = get_vier_config("show_services", 1);
  100. $show_friends = get_vier_config("show_friends", 1);
  101. $show_lastusers = get_vier_config("show_lastusers", 1);
  102. // get_baseurl
  103. $url = DI::baseUrl();
  104. $aside['$url'] = $url;
  105. // comunity_profiles
  106. if ($show_profiles) {
  107. $r = GContact::suggestionQuery(local_user(), 0, 9);
  108. $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
  109. if (DBA::isResult($r)) {
  110. $aside['$comunity_profiles_title'] = L10n::t('Community Profiles');
  111. $aside['$comunity_profiles_items'] = [];
  112. foreach ($r as $rr) {
  113. $entry = Renderer::replaceMacros($tpl, [
  114. '$id' => $rr['id'],
  115. '$profile_link' => 'follow/?url='.urlencode($rr['url']),
  116. '$photo' => ProxyUtils::proxifyUrl($rr['photo'], false, ProxyUtils::SIZE_MICRO),
  117. '$alt_text' => $rr['name'],
  118. ]);
  119. $aside['$comunity_profiles_items'][] = $entry;
  120. }
  121. }
  122. }
  123. // last 9 users
  124. if ($show_lastusers) {
  125. $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ");
  126. $order = " ORDER BY `register_date` DESC ";
  127. $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
  128. $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
  129. FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
  130. WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
  131. 0,
  132. 9
  133. );
  134. if (DBA::isResult($r)) {
  135. $aside['$lastusers_title'] = L10n::t('Last users');
  136. $aside['$lastusers_items'] = [];
  137. foreach ($r as $rr) {
  138. $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
  139. $entry = Renderer::replaceMacros($tpl, [
  140. '$id' => $rr['id'],
  141. '$profile_link' => $profile_link,
  142. '$photo' => DI::baseUrl()->remove($rr['thumb']),
  143. '$alt_text' => $rr['name']]);
  144. $aside['$lastusers_items'][] = $entry;
  145. }
  146. }
  147. }
  148. //right_aside FIND FRIENDS
  149. if ($show_friends && local_user()) {
  150. $nv = [];
  151. $nv['findpeople'] = L10n::t('Find People');
  152. $nv['desc'] = L10n::t('Enter name or interest');
  153. $nv['label'] = L10n::t('Connect/Follow');
  154. $nv['hint'] = L10n::t('Examples: Robert Morgenstein, Fishing');
  155. $nv['findthem'] = L10n::t('Find');
  156. $nv['suggest'] = L10n::t('Friend Suggestions');
  157. $nv['similar'] = L10n::t('Similar Interests');
  158. $nv['random'] = L10n::t('Random Profile');
  159. $nv['inv'] = L10n::t('Invite Friends');
  160. $nv['directory'] = L10n::t('Global Directory');
  161. $nv['global_dir'] = Search::getGlobalDirectory();
  162. $nv['local_directory'] = L10n::t('Local Directory');
  163. $aside['$nv'] = $nv;
  164. }
  165. //Community_Pages at right_aside
  166. if ($show_pages && local_user()) {
  167. $cid = $_GET['cid'] ?? null;
  168. //sort by last updated item
  169. $lastitem = true;
  170. $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
  171. $total = count($contacts);
  172. $visible_forums = 10;
  173. if (count($contacts)) {
  174. $id = 0;
  175. foreach ($contacts as $contact) {
  176. $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
  177. $entry = [
  178. 'url' => 'network?cid=' . $contact['id'],
  179. 'external_url' => Contact::magicLink($contact['url']),
  180. 'name' => $contact['name'],
  181. 'cid' => $contact['id'],
  182. 'selected' => $selected,
  183. 'micro' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
  184. 'id' => ++$id,
  185. ];
  186. $entries[] = $entry;
  187. }
  188. $tpl = Renderer::getMarkupTemplate('widget_forumlist_right.tpl');
  189. $page = Renderer::replaceMacros(
  190. $tpl,
  191. [
  192. '$title' => L10n::t('Forums'),
  193. '$forums' => $entries,
  194. '$link_desc' => L10n::t('External link to forum'),
  195. '$total' => $total,
  196. '$visible_forums' => $visible_forums,
  197. '$showmore' => L10n::t('show more')]
  198. );
  199. $aside['$page'] = $page;
  200. }
  201. }
  202. // END Community Page
  203. // helpers
  204. if ($show_helpers) {
  205. $r = [];
  206. $helperlist = Config::get("vier", "helperlist");
  207. $helpers = explode(",", $helperlist);
  208. if ($helpers) {
  209. $query = "";
  210. foreach ($helpers as $index => $helper) {
  211. if ($query != "") {
  212. $query .= ",";
  213. }
  214. $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'";
  215. }
  216. $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
  217. }
  218. foreach ($r as $index => $helper) {
  219. $r[$index]["url"] = Contact::magicLink($helper["url"]);
  220. }
  221. $r[] = ["url" => "help/Quick-Start-guide", "name" => L10n::t("Quick Start")];
  222. $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
  223. if ($r) {
  224. $helpers = [];
  225. $helpers['title'] = ["", L10n::t('Help'), "", ""];
  226. $aside['$helpers_items'] = [];
  227. foreach ($r as $rr) {
  228. $entry = Renderer::replaceMacros($tpl, [
  229. '$url' => $rr['url'],
  230. '$title' => $rr['name'],
  231. ]);
  232. $aside['$helpers_items'][] = $entry;
  233. }
  234. $aside['$helpers'] = $helpers;
  235. }
  236. }
  237. // end helpers
  238. // connectable services
  239. if ($show_services) {
  240. /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
  241. $r = [];
  242. if (Addon::isEnabled("buffer")) {
  243. $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
  244. }
  245. if (Addon::isEnabled("blogger")) {
  246. $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
  247. }
  248. if (Addon::isEnabled("dwpost")) {
  249. $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
  250. }
  251. if (Addon::isEnabled("ifttt")) {
  252. $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
  253. }
  254. if (Addon::isEnabled("statusnet")) {
  255. $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
  256. }
  257. /// @TODO old-lost code (and below)?
  258. //if (Addon::isEnabled("ijpost")) {
  259. // $r[] = array("photo" => "images/", "name" => "");
  260. //}
  261. if (Addon::isEnabled("libertree")) {
  262. $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
  263. }
  264. //if (Addon::isEnabled("ljpost")) {
  265. // $r[] = array("photo" => "images/", "name" => "");
  266. //}
  267. if (Addon::isEnabled("pumpio")) {
  268. $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
  269. }
  270. if (Addon::isEnabled("tumblr")) {
  271. $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
  272. }
  273. if (Addon::isEnabled("twitter")) {
  274. $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
  275. }
  276. if (Addon::isEnabled("wppost")) {
  277. $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
  278. }
  279. if (function_exists("imap_open") && !Config::get("system", "imap_disabled") && !Config::get("system", "dfrn_only")) {
  280. $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
  281. }
  282. $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
  283. if (DBA::isResult($r)) {
  284. $con_services = [];
  285. $con_services['title'] = ["", L10n::t('Connect Services'), "", ""];
  286. $aside['$con_services'] = $con_services;
  287. foreach ($r as $rr) {
  288. $entry = Renderer::replaceMacros($tpl, [
  289. '$url' => $url,
  290. '$photo' => $rr['photo'],
  291. '$alt_text' => $rr['name'],
  292. ]);
  293. $aside['$connector_items'][] = $entry;
  294. }
  295. }
  296. }
  297. //end connectable services
  298. //print right_aside
  299. $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
  300. DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
  301. }