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.
 
 
 
 
 
 

335 lines
8.3 KiB

  1. <?php
  2. /**
  3. * @file mod/cal.php
  4. * @brief The calendar module
  5. * This calendar is for profile visitors and contains only the events
  6. * of the profile owner
  7. */
  8. require_once('include/event.php');
  9. require_once('include/redir.php');
  10. function cal_init(&$a) {
  11. if($a->argc > 1)
  12. auto_redir($a, $a->argv[1]);
  13. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  14. return;
  15. }
  16. nav_set_selected('events');
  17. $o = '';
  18. if($a->argc > 1) {
  19. $nick = $a->argv[1];
  20. $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
  21. dbesc($nick)
  22. );
  23. if(! count($user))
  24. return;
  25. $a->data['user'] = $user[0];
  26. $a->profile_uid = $user[0]['uid'];
  27. // if it's a json request abort here becaus we don't
  28. // need the widget data
  29. if ($a->argv[2] === 'json')
  30. return;
  31. $profile = get_profiledata_by_nick($nick, $a->profile_uid);
  32. if((intval($profile['page-flags']) == PAGE_COMMUNITY) || (intval($profile['page-flags']) == PAGE_PRVGROUP))
  33. $account_type = t('Forum');
  34. else
  35. $account_type = "";
  36. $tpl = get_markup_template("vcard-widget.tpl");
  37. $vcard_widget .= replace_macros($tpl, array(
  38. '$name' => $profile['name'],
  39. '$photo' => $profile['photo'],
  40. '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
  41. '$account_type' => $account_type,
  42. '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
  43. ));
  44. $cal_widget = widget_events();
  45. if(! x($a->page,'aside'))
  46. $a->page['aside'] = '';
  47. $a->page['aside'] .= $vcard_widget;
  48. $a->page['aside'] .= $cal_widget;
  49. }
  50. return;
  51. }
  52. function cal_content(&$a) {
  53. nav_set_selected('events');
  54. $editselect = 'none';
  55. if( feature_enabled(local_user(), 'richtext') )
  56. $editselect = 'textareas';
  57. // First day of the week (0 = Sunday)
  58. $firstDay = get_pconfig(local_user(),'system','first_day_of_week');
  59. if ($firstDay === false) $firstDay=0;
  60. // get the translation strings for the callendar
  61. $i18n = get_event_strings();
  62. $htpl = get_markup_template('event_head.tpl');
  63. $a->page['htmlhead'] .= replace_macros($htpl,array(
  64. '$baseurl' => $a->get_baseurl(),
  65. '$module_url' => '/cal/' . $a->data['user']['nickname'],
  66. '$modparams' => 2,
  67. '$i18n' => $i18n,
  68. '$editselect' => $editselect
  69. ));
  70. $etpl = get_markup_template('event_end.tpl');
  71. $a->page['end'] .= replace_macros($etpl,array(
  72. '$baseurl' => $a->get_baseurl(),
  73. '$editselect' => $editselect
  74. ));
  75. $o ="";
  76. $mode = 'view';
  77. $y = 0;
  78. $m = 0;
  79. $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0);
  80. if($a->argc == 4) {
  81. if($a->argv[2] == 'export') {
  82. $mode = 'export';
  83. $format = $a->argv[3];
  84. }
  85. }
  86. //
  87. // Setup permissions structures
  88. //
  89. $contact = null;
  90. $remote_contact = false;
  91. $contact_id = 0;
  92. $owner_uid = $a->data['user']['uid'];
  93. $nick = $a->data['user']['nickname'];
  94. if(is_array($_SESSION['remote'])) {
  95. foreach($_SESSION['remote'] as $v) {
  96. if($v['uid'] == $a->profile['profile_uid']) {
  97. $contact_id = $v['cid'];
  98. break;
  99. }
  100. }
  101. }
  102. if($contact_id) {
  103. $groups = init_groups_visitor($contact_id);
  104. $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  105. intval($contact_id),
  106. intval($a->profile['profile_uid'])
  107. );
  108. if(count($r)) {
  109. $contact = $r[0];
  110. $remote_contact = true;
  111. }
  112. }
  113. if(! $remote_contact) {
  114. if(local_user()) {
  115. $contact_id = $_SESSION['cid'];
  116. $contact = $a->contact;
  117. }
  118. }
  119. $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
  120. if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
  121. notice( t('Access to this profile has been restricted.') . EOL);
  122. return;
  123. }
  124. // get the permissions
  125. $sql_perms = item_permissions_sql($owner_uid,$remote_contact,$groups);
  126. // we only want to have the events of the profile owner
  127. $sql_extra = " AND `event`.`cid` = 0 " . $sql_perms;
  128. // get the tab navigation bar
  129. $tabs .= profile_tabs($a,false, $a->data['user']['nickname']);
  130. // The view mode part is similiar to /mod/events.php
  131. if($mode == 'view') {
  132. $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
  133. $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
  134. if(! $y)
  135. $y = intval($thisyear);
  136. if(! $m)
  137. $m = intval($thismonth);
  138. // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
  139. // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
  140. if($y < 1901)
  141. $y = 1900;
  142. if($y > 2099)
  143. $y = 2100;
  144. $nextyear = $y;
  145. $nextmonth = $m + 1;
  146. if($nextmonth > 12) {
  147. $nextmonth = 1;
  148. $nextyear ++;
  149. }
  150. $prevyear = $y;
  151. if($m > 1)
  152. $prevmonth = $m - 1;
  153. else {
  154. $prevmonth = 12;
  155. $prevyear --;
  156. }
  157. $dim = get_dim($y,$m);
  158. $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
  159. $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
  160. if ($a->argv[2] === 'json'){
  161. if (x($_GET,'start')) $start = date("Y-m-d h:i:s", $_GET['start']);
  162. if (x($_GET,'end')) $finish = date("Y-m-d h:i:s", $_GET['end']);
  163. }
  164. $start = datetime_convert('UTC','UTC',$start);
  165. $finish = datetime_convert('UTC','UTC',$finish);
  166. $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
  167. $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
  168. // put the event parametes in an array so we can better transmit them
  169. $event_params = array(
  170. 'event_id' => (x($_GET,'id') ? $_GET["id"] : 0),
  171. 'start' => $start,
  172. 'finish' => $finish,
  173. 'adjust_start' => $adjust_start,
  174. 'adjust_finish' => $adjust_finish,
  175. 'ignored' => $ignored,
  176. );
  177. // get events by id or by date
  178. if (x($_GET,'id')){
  179. $r = event_by_id($owner_uid, $event_params, $sql_extra);
  180. } else {
  181. $r = events_by_date($owner_uid, $event_params, $sql_extra);
  182. }
  183. $links = array();
  184. if(count($r)) {
  185. $r = sort_by_date($r);
  186. foreach($r as $rr) {
  187. $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
  188. if(! x($links,$j))
  189. $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
  190. }
  191. }
  192. $events=array();
  193. // transform the event in a usable array
  194. if(count($r))
  195. $r = sort_by_date($r);
  196. $events = process_events($r);
  197. if ($a->argv[2] === 'json'){
  198. echo json_encode($events); killme();
  199. }
  200. // links: array('href', 'text', 'extra css classes', 'title')
  201. if (x($_GET,'id')){
  202. $tpl = get_markup_template("event.tpl");
  203. } else {
  204. // if (get_config('experimentals','new_calendar')==1){
  205. $tpl = get_markup_template("events-js.tpl");
  206. // } else {
  207. // $tpl = get_markup_template("events.tpl");
  208. // }
  209. }
  210. // Get rid of dashes in key names, Smarty3 can't handle them
  211. foreach($events as $key => $event) {
  212. $event_item = array();
  213. foreach($event['item'] as $k => $v) {
  214. $k = str_replace('-','_',$k);
  215. $event_item[$k] = $v;
  216. }
  217. $events[$key]['item'] = $event_item;
  218. }
  219. $o = replace_macros($tpl, array(
  220. '$baseurl' => $a->get_baseurl(),
  221. '$tabs' => $tabs,
  222. '$title' => t('Events'),
  223. '$view' => t('View'),
  224. '$previus' => array($a->get_baseurl()."/events/$prevyear/$prevmonth",t('Previous'),'',''),
  225. '$next' => array($a->get_baseurl()."/events/$nextyear/$nextmonth",t('Next'),'',''),
  226. '$calendar' => cal($y,$m,$links, ' eventcal'),
  227. '$events' => $events,
  228. "today" => t("today"),
  229. "month" => t("month"),
  230. "week" => t("week"),
  231. "day" => t("day"),
  232. ));
  233. if (x($_GET,'id')){ echo $o; killme(); }
  234. return $o;
  235. }
  236. if($mode == 'export') {
  237. if(! (intval($owner_uid))) {
  238. notice( t('User not found'));
  239. return;
  240. }
  241. // Test permissions
  242. // Respect the export feature setting for all other /cal pages if it's not the own profile
  243. if( ((local_user() !== $owner_uid)) && ! feature_enabled($owner_uid, "export_calendar")) {
  244. notice( t('Permission denied.') . EOL);
  245. return;
  246. }
  247. // Get the export data by uid
  248. $evexport = event_export($owner_uid, $format);
  249. if ($evexport["success"] == false ) {
  250. if($evexport["content"])
  251. notice( t('This calendar format is not supported') );
  252. else
  253. notice( t('No exportable data found'));
  254. return;
  255. }
  256. // If nothing went wrong we can echo the export content
  257. if ($evexport["success"] == true ) {
  258. header('Content-type: text/calendar');
  259. header('content-disposition: attachment; filename="' . t('calendar') . '-' . $nick . '.' . $evexport["extension"] . '"' );
  260. echo $evexport["content"];
  261. killme();
  262. }
  263. return;
  264. }
  265. }