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.
 
 
 
 
 
 

330 lines
8.0 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. $sql_extra = item_permissions_sql($owner_uid,$remote_contact,$groups);
  125. // get the tab navigation bar
  126. $tabs .= profile_tabs($a,false, $a->data['user']['nickname']);
  127. // The view mode part is similiar to /mod/events.php
  128. if($mode == 'view') {
  129. $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
  130. $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
  131. if(! $y)
  132. $y = intval($thisyear);
  133. if(! $m)
  134. $m = intval($thismonth);
  135. // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
  136. // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
  137. if($y < 1901)
  138. $y = 1900;
  139. if($y > 2099)
  140. $y = 2100;
  141. $nextyear = $y;
  142. $nextmonth = $m + 1;
  143. if($nextmonth > 12) {
  144. $nextmonth = 1;
  145. $nextyear ++;
  146. }
  147. $prevyear = $y;
  148. if($m > 1)
  149. $prevmonth = $m - 1;
  150. else {
  151. $prevmonth = 12;
  152. $prevyear --;
  153. }
  154. $dim = get_dim($y,$m);
  155. $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0);
  156. $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59);
  157. if ($a->argv[2] === 'json'){
  158. if (x($_GET,'start')) $start = date("Y-m-d h:i:s", $_GET['start']);
  159. if (x($_GET,'end')) $finish = date("Y-m-d h:i:s", $_GET['end']);
  160. }
  161. $start = datetime_convert('UTC','UTC',$start);
  162. $finish = datetime_convert('UTC','UTC',$finish);
  163. $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
  164. $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
  165. // put the event parametes in an array so we can better transmit them
  166. $event_params = array(
  167. 'event_id' => (x($_GET,'id') ? $_GET["id"] : 0),
  168. 'start' => $start,
  169. 'finish' => $finish,
  170. 'adjust_start' => $adjust_start,
  171. 'adjust_finish' => $adjust_finish,
  172. 'ignored' => $ignored,
  173. );
  174. // get events by id or by date
  175. if (x($_GET,'id')){
  176. $r = event_by_id($owner_uid, $event_params, $sql_extra);
  177. } else {
  178. $r = events_by_date($owner_uid, $event_params, $sql_extra);
  179. }
  180. $links = array();
  181. if(count($r)) {
  182. $r = sort_by_date($r);
  183. foreach($r as $rr) {
  184. $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j'));
  185. if(! x($links,$j))
  186. $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
  187. }
  188. }
  189. $events=array();
  190. // transform the event in a usable array
  191. if(count($r))
  192. $r = sort_by_date($r);
  193. $events = process_events($r);
  194. if ($a->argv[2] === 'json'){
  195. echo json_encode($events); killme();
  196. }
  197. // links: array('href', 'text', 'extra css classes', 'title')
  198. if (x($_GET,'id')){
  199. $tpl = get_markup_template("event.tpl");
  200. } else {
  201. // if (get_config('experimentals','new_calendar')==1){
  202. $tpl = get_markup_template("events-js.tpl");
  203. // } else {
  204. // $tpl = get_markup_template("events.tpl");
  205. // }
  206. }
  207. // Get rid of dashes in key names, Smarty3 can't handle them
  208. foreach($events as $key => $event) {
  209. $event_item = array();
  210. foreach($event['item'] as $k => $v) {
  211. $k = str_replace('-','_',$k);
  212. $event_item[$k] = $v;
  213. }
  214. $events[$key]['item'] = $event_item;
  215. }
  216. $o = replace_macros($tpl, array(
  217. '$baseurl' => $a->get_baseurl(),
  218. '$tabs' => $tabs,
  219. '$title' => t('Events'),
  220. '$view' => t('View'),
  221. '$previus' => array($a->get_baseurl()."/events/$prevyear/$prevmonth",t('Previous'),'',''),
  222. '$next' => array($a->get_baseurl()."/events/$nextyear/$nextmonth",t('Next'),'',''),
  223. '$calendar' => cal($y,$m,$links, ' eventcal'),
  224. '$events' => $events,
  225. "today" => t("today"),
  226. "month" => t("month"),
  227. "week" => t("week"),
  228. "day" => t("day"),
  229. ));
  230. if (x($_GET,'id')){ echo $o; killme(); }
  231. return $o;
  232. }
  233. if($mode == 'export') {
  234. if(! (intval($owner_uid))) {
  235. notice( t('User not found'));
  236. return;
  237. }
  238. if(! (feature_enabled($owner_uid, "export_calendar"))) {
  239. notice( t('Permission denied.') . EOL);
  240. return;
  241. }
  242. // Get the export data by uid
  243. $evexport = event_export($owner_uid, $format);
  244. if ($evexport["success"] == false ) {
  245. if($evexport["content"])
  246. notice( t('This calendar format is not supported') );
  247. else
  248. notice( t('No exportable data found'));
  249. return;
  250. }
  251. // If nothing went wrong we can echo the export content
  252. if ($evexport["success"] == true ) {
  253. header('Content-type: text/calendar');
  254. header('content-disposition: attachment; filename="' . t('calendar') . '-' . $nick . '.' . $evexport["extension"] . '"' );
  255. echo $evexport["content"];
  256. killme();
  257. }
  258. return;
  259. }
  260. }