Beispiel #1
0
function format_event_html($ev)
{
    if (!(is_array($ev) && count($ev))) {
        return '';
    }
    $bd_format = t('l F d, Y \\@ g:i A');
    // Friday January 18, 2011 @ 8 AM
    $o = '<div class="vevent">' . "\r\n";
    $o .= '<p class="summary event-summary">' . bbcode($ev['summary']) . '</p>' . "\r\n";
    $o .= '<p class="description event-description">' . bbcode($ev['desc']) . '</p>' . "\r\n";
    $o .= '<p class="event-start">' . t('Starts:') . ' <abbr class="dtstart" title="' . datetime_convert('UTC', 'UTC', $ev['start'], $ev['adjust'] ? ATOM_TIME : 'Y-m-d\\TH:i:s') . '" >' . ($ev['adjust'] ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $ev['start'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $ev['start'], $bd_format))) . '</abbr></p>' . "\r\n";
    if (!$ev['nofinish']) {
        $o .= '<p class="event-end" >' . t('Finishes:') . ' <abbr class="dtend" title="' . datetime_convert('UTC', 'UTC', $ev['finish'], $ev['adjust'] ? ATOM_TIME : 'Y-m-d\\TH:i:s') . '" >' . ($ev['adjust'] ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $ev['finish'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $ev['finish'], $bd_format))) . '</abbr></p>' . "\r\n";
    }
    if (strlen($ev['location'])) {
        $o .= '<p class="event-location"> ' . t('Location:') . ' <span class="location">' . bbcode($ev['location']) . '</span></p>' . "\r\n";
        if (strpos($ev['location'], "[map") === False) {
            $map = generate_named_map($ev['location']);
            if ($map !== $ev['location']) {
                $o .= $map;
            }
        }
    }
    $o .= '</div>' . "\r\n";
    return $o;
}
Beispiel #2
0
function format_event_obj($jobject)
{
    $event = array();
    $object = json_decode($jobject, true);
    //ensure compatibility with older items - this check can be removed at a later point
    if (array_key_exists('description', $object)) {
        $bd_format = t('l F d, Y \\@ g:i A');
        // Friday January 18, 2011 @ 8:01 AM
        $event['header'] = replace_macros(get_markup_template('event_item_header.tpl'), array('$title' => bbcode($object['title']), '$dtstart_label' => t('Starts:'), '$dtstart_title' => datetime_convert('UTC', 'UTC', $object['dtstart'], $object['adjust'] ? ATOM_TIME : 'Y-m-d\\TH:i:s'), '$dtstart_dt' => $object['adjust'] ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtstart'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $object['dtstart'], $bd_format)), '$finish' => $object['nofinish'] ? false : true, '$dtend_label' => t('Finishes:'), '$dtend_title' => datetime_convert('UTC', 'UTC', $object['dtend'], $object['adjust'] ? ATOM_TIME : 'Y-m-d\\TH:i:s'), '$dtend_dt' => $object['adjust'] ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['dtend'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $object['dtend'], $bd_format))));
        $event['content'] = replace_macros(get_markup_template('event_item_content.tpl'), array('$description' => bbcode($object['description']), '$location_label' => t('Location:'), '$location' => bbcode($object['location'])));
    }
    return $event;
}
Beispiel #3
0
/**
 * @brief Returns an event as HTML
 *
 * @param array $ev
 * @return string
 */
function format_event_html($ev)
{
    require_once 'include/bbcode.php';
    if (!(is_array($ev) && count($ev))) {
        return '';
    }
    $bd_format = t('l F d, Y \\@ g:i A');
    // Friday January 18, 2011 @ 8:01 AM
    //todo: move this to template
    $o = '<div class="vevent">' . "\r\n";
    $o .= '<div class="event-title"><h3><i class="icon-calendar"></i>&nbsp;' . bbcode($ev['summary']) . '</h3></div>' . "\r\n";
    $o .= '<div class="event-start"><span class="event-label">' . t('Starts:') . '</span>&nbsp;<span class="dtstart" title="' . datetime_convert('UTC', 'UTC', $ev['start'], $ev['adjust'] ? ATOM_TIME : 'Y-m-d\\TH:i:s') . '" >' . ($ev['adjust'] ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $ev['start'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $ev['start'], $bd_format))) . '</span></div>' . "\r\n";
    if (!$ev['nofinish']) {
        $o .= '<div class="event-end" ><span class="event-label">' . t('Finishes:') . '</span>&nbsp;<span class="dtend" title="' . datetime_convert('UTC', 'UTC', $ev['finish'], $ev['adjust'] ? ATOM_TIME : 'Y-m-d\\TH:i:s') . '" >' . ($ev['adjust'] ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $ev['finish'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $ev['finish'], $bd_format))) . '</span></div>' . "\r\n";
    }
    $o .= '<div class="event-description">' . bbcode($ev['description']) . '</div>' . "\r\n";
    if (strlen($ev['location'])) {
        $o .= '<div class="event-location"><span class="event-label"> ' . t('Location:') . '</span>&nbsp;<span class="location">' . bbcode($ev['location']) . '</span></div>' . "\r\n";
    }
    $o .= '</div>' . "\r\n";
    return $o;
}
Beispiel #4
0
function advanced_profile(&$a)
{
    require_once 'include/text.php';
    if (!perm_is_allowed($a->profile['profile_uid'], get_observer_hash(), 'view_profile')) {
        return '';
    }
    $o = '';
    $o .= '<h2>' . t('Profile') . '</h2>';
    if ($a->profile['name']) {
        $tpl = get_markup_template('profile_advanced.tpl');
        $profile = array();
        $profile['fullname'] = array(t('Full Name:'), $a->profile['name']);
        if ($a->profile['gender']) {
            $profile['gender'] = array(t('Gender:'), $a->profile['gender']);
        }
        $ob_hash = get_observer_hash();
        if ($ob_hash && perm_is_allowed($a->profile['profile_uid'], $ob_hash, 'post_like')) {
            $profile['canlike'] = true;
            $profile['likethis'] = t('Like this channel');
            $profile['profile_guid'] = $a->profile['profile_guid'];
        }
        $likers = q("select liker, xchan.*  from likes left join xchan on liker = xchan_hash where channel_id = %d and target_type = '%s' and verb = '%s'", intval($a->profile['profile_uid']), dbesc(ACTIVITY_OBJ_PROFILE), dbesc(ACTIVITY_LIKE));
        $profile['likers'] = array();
        $profile['like_count'] = count($likers);
        $profile['like_button_label'] = tt('Like', 'Likes', $profile['like_count'], 'noun');
        if ($likers) {
            foreach ($likers as $l) {
                $profile['likers'][] = array('name' => $l['xchan_name'], 'url' => zid($l['xchan_url']));
            }
        }
        if ($a->profile['dob'] && $a->profile['dob'] != '0000-00-00') {
            $val = '';
            if (substr($a->profile['dob'], 5, 2) === '00' || substr($a->profile['dob'], 8, 2) === '00') {
                $val = substr($a->profile['dob'], 0, 4);
            }
            $year_bd_format = t('j F, Y');
            $short_bd_format = t('j F');
            if (!$val) {
                $val = intval($a->profile['dob']) ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)) : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format));
            }
            $profile['birthday'] = array(t('Birthday:'), $val);
        }
        if ($age = age($a->profile['dob'], $a->profile['timezone'], '')) {
            $profile['age'] = array(t('Age:'), $age);
        }
        if ($a->profile['marital']) {
            $profile['marital'] = array(t('Status:'), $a->profile['marital']);
        }
        if ($a->profile['with']) {
            $profile['marital']['with'] = bbcode($a->profile['with']);
        }
        if (strlen($a->profile['howlong']) && $a->profile['howlong'] !== NULL_DATE) {
            $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
        }
        if ($a->profile['sexual']) {
            $profile['sexual'] = array(t('Sexual Preference:'), $a->profile['sexual']);
        }
        if ($a->profile['homepage']) {
            $profile['homepage'] = array(t('Homepage:'), linkify($a->profile['homepage']));
        }
        if ($a->profile['hometown']) {
            $profile['hometown'] = array(t('Hometown:'), linkify($a->profile['hometown']));
        }
        if ($a->profile['keywords']) {
            $profile['keywords'] = array(t('Tags:'), $a->profile['keywords']);
        }
        if ($a->profile['politic']) {
            $profile['politic'] = array(t('Political Views:'), $a->profile['politic']);
        }
        if ($a->profile['religion']) {
            $profile['religion'] = array(t('Religion:'), $a->profile['religion']);
        }
        if ($txt = prepare_text($a->profile['about'])) {
            $profile['about'] = array(t('About:'), $txt);
        }
        if ($txt = prepare_text($a->profile['interest'])) {
            $profile['interest'] = array(t('Hobbies/Interests:'), $txt);
        }
        if ($txt = prepare_text($a->profile['likes'])) {
            $profile['likes'] = array(t('Likes:'), $txt);
        }
        if ($txt = prepare_text($a->profile['dislikes'])) {
            $profile['dislikes'] = array(t('Dislikes:'), $txt);
        }
        if ($txt = prepare_text($a->profile['contact'])) {
            $profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
        }
        if ($txt = prepare_text($a->profile['channels'])) {
            $profile['channels'] = array(t('My other channels:'), $txt);
        }
        if ($txt = prepare_text($a->profile['music'])) {
            $profile['music'] = array(t('Musical interests:'), $txt);
        }
        if ($txt = prepare_text($a->profile['book'])) {
            $profile['book'] = array(t('Books, literature:'), $txt);
        }
        if ($txt = prepare_text($a->profile['tv'])) {
            $profile['tv'] = array(t('Television:'), $txt);
        }
        if ($txt = prepare_text($a->profile['film'])) {
            $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
        }
        if ($txt = prepare_text($a->profile['romance'])) {
            $profile['romance'] = array(t('Love/Romance:'), $txt);
        }
        if ($txt = prepare_text($a->profile['work'])) {
            $profile['work'] = array(t('Work/employment:'), $txt);
        }
        if ($txt = prepare_text($a->profile['education'])) {
            $profile['education'] = array(t('School/education:'), $txt);
        }
        if ($a->profile['extra_fields']) {
            foreach ($a->profile['extra_fields'] as $f) {
                $x = q("select * from profdef where field_name = '%s' limit 1", dbesc($f));
                if ($x && ($txt = prepare_text($a->profile[$f]))) {
                    $profile[$f] = array($x[0]['field_desc'] . ':', $txt);
                }
            }
            $profile['extra_fields'] = $a->profile['extra_fields'];
        }
        $things = get_things($a->profile['profile_guid'], $a->profile['profile_uid']);
        //		logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA);
        return replace_macros($tpl, array('$title' => t('Profile'), '$canlike' => $profile['canlike'] ? true : false, '$likethis' => t('Like this thing'), '$profile' => $profile, '$things' => $things));
    }
    return '';
}
Beispiel #5
0
 function cal($y = 0, $m = 0, $links = false, $class = '')
 {
     // month table - start at 1 to match human usage.
     $mtab = array(' ', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
     $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
     $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
     if (!$y) {
         $y = $thisyear;
     }
     if (!$m) {
         $m = intval($thismonth);
     }
     $dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
     $f = get_first_dim($y, $m);
     $l = get_dim($y, $m);
     $d = 1;
     $dow = 0;
     $started = false;
     if ($y == $thisyear && $m == $thismonth) {
         $tddate = intval(datetime_convert('UTC', date_default_timezone_get(), 'now', 'j'));
     }
     $str_month = day_translate($mtab[$m]);
     $o = '<table class="calendar' . $class . '">';
     $o .= "<caption>{$str_month} {$y}</caption><tr>";
     for ($a = 0; $a < 7; $a++) {
         $o .= '<th>' . mb_substr(day_translate($dn[$a]), 0, 3, 'UTF-8') . '</th>';
     }
     $o .= '</tr><tr>';
     while ($d <= $l) {
         if ($dow == $f && !$started) {
             $started = true;
         }
         $today = isset($tddate) && $tddate == $d ? "class=\"today\" " : '';
         $o .= "<td {$today}>";
         $day = str_replace(' ', '&nbsp;', sprintf('%2.2d', $d));
         if ($started) {
             if (is_array($links) && isset($links[$d])) {
                 $o .= "<a href=\"{$links[$d]}\">{$day}</a>";
             } else {
                 $o .= $day;
             }
             $d++;
         } else {
             $o .= '&nbsp;';
         }
         $o .= '</td>';
         $dow++;
         if ($dow == 7 && $d <= $l) {
             $dow = 0;
             $o .= '</tr><tr>';
         }
     }
     if ($dow) {
         for ($a = $dow; $a < 7; $a++) {
             $o .= '<td>&nbsp;</td>';
         }
     }
     $o .= '</tr></table>' . "\r\n";
     return $o;
 }
Beispiel #6
0
function posted_dates($uid, $wall)
{
    $dnow = datetime_convert('', date_default_timezone_get(), 'now', 'Y-m-d');
    $dthen = first_post_date($uid, $wall);
    if (!$dthen) {
        return array();
    }
    // Set the start and end date to the beginning of the month
    $dnow = substr($dnow, 0, 8) . '01';
    $dthen = substr($dthen, 0, 8) . '01';
    $ret = array();
    // Starting with the current month, get the first and last days of every
    // month down to and including the month of the first post
    while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) {
        $dstart = substr($dnow, 0, 8) . '01';
        $dend = substr($dnow, 0, 8) . get_dim(intval($dnow), intval(substr($dnow, 5)));
        $start_month = datetime_convert('', '', $dstart, 'Y-m-d');
        $end_month = datetime_convert('', '', $dend, 'Y-m-d');
        $str = day_translate(datetime_convert('', '', $dnow, 'F Y'));
        $ret[] = array($str, $end_month, $start_month);
        $dnow = datetime_convert('', '', $dnow . ' -1 month', 'Y-m-d');
    }
    return $ret;
}
Beispiel #7
0
function events_content(&$a)
{
    if (!local_channel()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    nav_set_selected('all_events');
    if (argc() > 2 && argv(1) === 'ignore' && intval(argv(2))) {
        $r = q("update event set ignore = 1 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
    }
    if (argc() > 2 && argv(1) === 'unignore' && intval(argv(2))) {
        $r = q("update event set ignore = 0 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
    }
    $plaintext = true;
    //	if(feature_enabled(local_channel(),'richtext'))
    //		$plaintext = false;
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $plaintext ? 'none' : 'textareas'));
    $o = "";
    // tabs
    $channel = $a->get_channel();
    $tabs = profile_tabs($a, True, $channel['channel_address']);
    $mode = 'view';
    $y = 0;
    $m = 0;
    $ignored = x($_REQUEST, 'ignored') ? " and ignored = " . intval($_REQUEST['ignored']) . " " : '';
    if (argc() > 1) {
        if (argc() > 2 && argv(1) == 'event') {
            $mode = 'edit';
            $event_id = argv(2);
        }
        if (argc() > 2 && argv(1) === 'add') {
            $mode = 'add';
            $item_id = intval(argv(2));
        }
        if (argc() > 2 && argv(1) === 'drop') {
            $mode = 'drop';
            $event_id = argv(2);
        }
        if (argv(1) === 'new') {
            $mode = 'new';
            $event_id = '';
        }
        if (argc() > 2 && intval(argv(1)) && intval(argv(2))) {
            $mode = 'view';
            $y = intval(argv(1));
            $m = intval(argv(2));
        }
    }
    if ($mode === 'add') {
        event_addtocal($item_id, local_channel());
        killme();
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        $export = false;
        if (argc() === 4 && argv(3) === 'export') {
            $export = true;
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if (argv(1) === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", intval(local_channel()), intval($_GET['id']));
        } else {
            // fixed an issue with "nofinish" events not showing up in the calendar.
            // There's still an issue if the finish date crosses the end of month.
            // Noting this for now - it will need to be fixed here and in Friendica.
            // Ultimately the finish date shouldn't be involved in the query.
            $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n                              from event left join item on event_hash = resource_id \n\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored}\n\t\t\t\tAND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' ) \n\t\t\t\tOR  (  `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if ($r) {
            xchan_query($r);
            $r = fetch_post_tags($r, true);
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if ($r) {
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                // FIXME
                $edit = $rr['item_flags'] & ITEM_WALL ? array($a->get_baseurl() . '/events/event/' . $rr['event_hash'], t('Edit event'), '', '') : null;
                $drop = array($a->get_baseurl() . '/events/drop/' . $rr['event_hash'], t('Delete event'), '', '');
                $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                if (!$title) {
                    list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                    $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                }
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
            }
        }
        if ($export) {
            header('Content-type: text/calendar');
            header('content-disposition: attachment; filename="' . t('calendar') . '-' . $channel['channel_address'] . '.ics"');
            echo ical_wrapper($r);
            killme();
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            $tpl = get_markup_template("events-js.tpl");
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array($a->get_baseurl() . "/events/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'drop' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
        if ($r) {
            $r = q("delete from event where event_hash = '%s' and uid = %d limit 1", dbesc($event_id), intval(local_channel()));
            if ($r) {
                $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d", dbesc($event_id), intval(local_channel()));
                info(t('Event removed') . EOL);
            } else {
                notice(t('Failed to remove event') . EOL);
            }
            goaway(z_root() . '/events');
        }
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    $channel = $a->get_channel();
    // Passed parameters overrides anything found in the DB
    if ($mode === 'edit' || $mode === 'new') {
        if (!x($orig_event)) {
            $orig_event = array();
        }
        // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
        if (x($_REQUEST, 'nofinish')) {
            $orig_event['nofinish'] = $_REQUEST['nofinish'];
        }
        if (x($_REQUEST, 'adjust')) {
            $orig_event['adjust'] = $_REQUEST['adjust'];
        }
        if (x($_REQUEST, 'summary')) {
            $orig_event['summary'] = $_REQUEST['summary'];
        }
        if (x($_REQUEST, 'description')) {
            $orig_event['description'] = $_REQUEST['description'];
        }
        if (x($_REQUEST, 'location')) {
            $orig_event['location'] = $_REQUEST['location'];
        }
        if (x($_REQUEST, 'start')) {
            $orig_event['start'] = $_REQUEST['start'];
        }
        if (x($_REQUEST, 'finish')) {
            $orig_event['finish'] = $_REQUEST['finish'];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $t_orig = x($orig_event) ? $orig_event['summary'] : '';
        $d_orig = x($orig_event) ? $orig_event['description'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $event_xchan = x($orig_event) ? $orig_event['event_xchan'] : $channel['channel_hash'];
        $mid = x($orig_event) ? $orig_event['mid'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = ($orig_event['allow_cid'] === '<' . $channel['channel_hash'] . '>' || !$orig_event['allow_cid']) && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($orig_event['event_xchan']) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $stext = datetime_convert('UTC', $tz, $sdt);
        $stext = substr($stext, 0, 14) . "00:00";
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $ftext = datetime_convert('UTC', $tz, $fdt);
        $ftext = substr($ftext, 0, 14) . "00:00";
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $catsenabled = feature_enabled(local_channel(), 'categories');
        $category = '';
        if ($catsenabled && x($orig_event)) {
            $itm = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d limit 1", dbesc($orig_event['event_hash']), intval(local_channel()));
            $itm = fetch_post_tags($itm);
            if ($itm) {
                $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
                foreach ($cats as $cat) {
                    if (strlen($category)) {
                        $category .= ', ';
                    }
                    $category .= $cat['term'];
                }
            }
        }
        require_once 'include/acl_selectors.php';
        $perm_defaults = array('allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], 'deny_cid' => $channel['channel_deny_cid'], 'deny_gid' => $channel['channel_deny_gid']);
        $tpl = get_markup_template('event_form.tpl');
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$xchan' => $event_xchan, '$mid' => $mid, '$event_hash' => $event_id, '$title' => t('Event details'), '$desc' => t('Starting date and Title are required.'), '$catsenabled' => $catsenabled, '$placeholdercategory' => t('Categories (comma-separated list)'), '$category' => $category, '$s_text' => t('Event Starts:'), '$stext' => $stext, '$ftext' => $ftext, '$required' => ' <span class="required" title="' . t('Required') . '">*</span>', '$ModalCANCEL' => t('Cancel'), '$ModalOK' => t('OK'), '$s_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $syear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), 'start_text', true, true, '', '', true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $fyear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), 'finish_text', true, true, 'start_text'), '$adjust' => array('adjust', t('Adjust for viewer timezone'), $a_checked, t('Important for events that happen in a particular place. Not practical for global holidays.')), '$a_text' => t('Adjust for viewer timezone'), '$d_text' => t('Description:'), '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$t_text' => t('Title:'), '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$preview' => t('Preview'), '$permissions' => t('Permissions'), '$acl' => $orig_event['event_xchan'] ? '' : populate_acl(x($orig_event) ? $orig_event : $perm_defaults, false), '$submit' => t('Submit')));
        return $o;
    }
}
Beispiel #8
0
 function get_events()
 {
     require_once 'include/bbcode.php';
     $a = get_app();
     if (!local_user() || $a->is_mobile || $a->is_tablet) {
         return $o;
     }
     //		$mobile_detect = new Mobile_Detect();
     //		$is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
     //		if($is_mobile)
     //			return $o;
     $bd_format = t('g A l F d');
     // 8 AM Friday January 18
     $bd_short = t('F d');
     $r = q("SELECT `event`.* FROM `event`\n\t\t\t\tWHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` > '%s'\n\t\t\t\tORDER BY `start` ASC ", intval(local_user()), dbesc(datetime_convert('UTC', 'UTC', 'now + 6 days')), dbesc(datetime_convert('UTC', 'UTC', 'now - 1 days')));
     if ($r && count($r)) {
         $now = strtotime('now');
         $istoday = false;
         foreach ($r as $rr) {
             if (strlen($rr['name'])) {
                 $total++;
             }
             $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start'], 'Y-m-d');
             if ($strt === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
                 $istoday = true;
             }
         }
         $classtoday = $istoday ? 'event-today' : '';
         foreach ($r as &$rr) {
             if ($rr['adjust']) {
                 $md = datetime_convert('UTC', $a->timezone, $rr['start'], 'Y/m');
             } else {
                 $md = datetime_convert('UTC', 'UTC', $rr['start'], 'Y/m');
             }
             $md .= "/#link-" . $rr['id'];
             $title = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
             if (!$title) {
                 $title = t('[No description]');
             }
             $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start']);
             $today = substr($strt, 0, 10) === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d') ? true : false;
             $rr['link'] = $md;
             $rr['title'] = $title;
             $rr['date'] = day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . ($today ? ' ' . t('[today]') : '');
             $rr['startime'] = $strt;
             $rr['today'] = $today;
         }
     }
     $tpl = get_markup_template("events_reminder.tpl");
     return replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$classtoday' => $classtoday, '$count' => count($r), '$event_reminders' => t('Event Reminders'), '$event_title' => t('Events this week:'), '$events' => $r));
 }
Beispiel #9
0
 function get()
 {
     if (observer_prohibited()) {
         return;
     }
     $channel = null;
     if (argc() > 1) {
         $channel = channelx_by_nick(argv(1));
     }
     if (!$channel) {
         notice(t('Channel not found.') . EOL);
         return;
     }
     // since we don't currently have an event permission - use the stream permission
     if (!perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_stream')) {
         notice(t('Permissions denied.') . EOL);
         return;
     }
     $sql_extra = permissions_sql($channel['channel_id'], get_observer_hash(), 'event');
     $first_day = get_pconfig(local_channel(), 'system', 'cal_first_day');
     $first_day = $first_day ? $first_day : 0;
     $htpl = get_markup_template('event_head.tpl');
     \App::$page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => z_root(), '$module_url' => '/cal/' . $channel['channel_address'], '$modparams' => 2, '$lang' => \App::$language, '$first_day' => $first_day));
     $o = '';
     $tabs = profile_tabs($a, True, $channel['channel_address']);
     $mode = 'view';
     $y = 0;
     $m = 0;
     $ignored = x($_REQUEST, 'ignored') ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : '';
     // logger('args: ' . print_r(\App::$argv,true));
     if (argc() > 3 && intval(argv(2)) && intval(argv(3))) {
         $mode = 'view';
         $y = intval(argv(2));
         $m = intval(argv(3));
     }
     if (argc() <= 3) {
         $mode = 'view';
         $event_id = argv(2);
     }
     if ($mode == 'view') {
         /* edit/create form */
         if ($event_id) {
             $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval($channel['channel_id']));
             if (count($r)) {
                 $orig_event = $r[0];
             }
         }
         // Passed parameters overrides anything found in the DB
         if (!x($orig_event)) {
             $orig_event = array();
         }
         $tz = date_default_timezone_get();
         if (x($orig_event)) {
             $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
         }
         $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
         $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
         $sday = datetime_convert('UTC', $tz, $sdt, 'd');
         $shour = datetime_convert('UTC', $tz, $sdt, 'H');
         $sminute = datetime_convert('UTC', $tz, $sdt, 'i');
         $stext = datetime_convert('UTC', $tz, $sdt);
         $stext = substr($stext, 0, 14) . "00:00";
         $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
         $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
         $fday = datetime_convert('UTC', $tz, $fdt, 'd');
         $fhour = datetime_convert('UTC', $tz, $fdt, 'H');
         $fminute = datetime_convert('UTC', $tz, $fdt, 'i');
         $ftext = datetime_convert('UTC', $tz, $fdt);
         $ftext = substr($ftext, 0, 14) . "00:00";
         $type = x($orig_event) ? $orig_event['etype'] : 'event';
         $f = get_config('system', 'event_input_format');
         if (!$f) {
             $f = 'ymd';
         }
         $catsenabled = feature_enabled($channel['channel_id'], 'categories');
         $show_bd = perm_is_allowed($channel['channel_id'], get_observer_hash(), 'view_contacts');
         if (!$show_bd) {
             $sql_extra .= " and event.etype != 'birthday' ";
         }
         $category = '';
         $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
         $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
         if (!$y) {
             $y = intval($thisyear);
         }
         if (!$m) {
             $m = intval($thismonth);
         }
         // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
         // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
         if ($y < 1901) {
             $y = 1900;
         }
         if ($y > 2099) {
             $y = 2100;
         }
         $nextyear = $y;
         $nextmonth = $m + 1;
         if ($nextmonth > 12) {
             $nextmonth = 1;
             $nextyear++;
         }
         $prevyear = $y;
         if ($m > 1) {
             $prevmonth = $m - 1;
         } else {
             $prevmonth = 12;
             $prevyear--;
         }
         $dim = get_dim($y, $m);
         $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
         $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
         if (argv(2) === 'json') {
             if (x($_GET, 'start')) {
                 $start = $_GET['start'];
             }
             if (x($_GET, 'end')) {
                 $finish = $_GET['end'];
             }
         }
         $start = datetime_convert('UTC', 'UTC', $start);
         $finish = datetime_convert('UTC', 'UTC', $finish);
         $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
         $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
         if (x($_GET, 'id')) {
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d {$sql_extra} limit 1", intval($channel['channel_id']), intval($_GET['id']));
         } else {
             // fixed an issue with "nofinish" events not showing up in the calendar.
             // There's still an issue if the finish date crosses the end of month.
             // Noting this for now - it will need to be fixed here and in Friendica.
             // Ultimately the finish date shouldn't be involved in the query.
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                              from event left join item on event_hash = resource_id \n\t\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored} \n\t\t\t\t\tAND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) \n\t\t\t\t\tOR  (  adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) {$sql_extra} ", intval($channel['channel_id']), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
         }
         $links = array();
         if ($r) {
             xchan_query($r);
             $r = fetch_post_tags($r, true);
             $r = sort_by_date($r);
         }
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 if (!x($links, $j)) {
                     $links[$j] = z_root() . '/' . \App::$cmd . '#link-' . $j;
                 }
             }
         }
         $events = array();
         $last_date = '';
         $fmt = t('l, F j');
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt);
                 $d = day_translate($d);
                 $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c');
                 if ($rr['nofinish']) {
                     $end = null;
                 } else {
                     $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c');
                 }
                 $is_first = $d !== $last_date;
                 $last_date = $d;
                 $edit = false;
                 $drop = false;
                 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                 if (!$title) {
                     list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                     $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                 }
                 $html = format_event_html($rr);
                 $rr['desc'] = bbcode($rr['desc']);
                 $rr['location'] = bbcode($rr['location']);
                 $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
             }
         }
         if (argv(2) === 'json') {
             echo json_encode($events);
             killme();
         }
         // links: array('href', 'text', 'extra css classes', 'title')
         if (x($_GET, 'id')) {
             $tpl = get_markup_template("event_cal.tpl");
         } else {
             $tpl = get_markup_template("events_cal-js.tpl");
         }
         $nick = $channel['channel_address'];
         $o = replace_macros($tpl, array('$baseurl' => z_root(), '$new_event' => array(z_root() . '/cal', $event_id ? t('Edit Event') : t('Create Event'), '', ''), '$previus' => array(z_root() . "/cal/{$nick}/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array(z_root() . "/cal/{$nick}/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array(z_root() . "/cal/{$nick}/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events, '$upload' => t('Import'), '$submit' => t('Submit'), '$prev' => t('Previous'), '$next' => t('Next'), '$today' => t('Today'), '$form' => $form, '$expandform' => x($_GET, 'expandform') ? true : false, '$tabs' => $tabs));
         if (x($_GET, 'id')) {
             echo $o;
             killme();
         }
         return $o;
     }
 }
Beispiel #10
0
function advanced_profile(&$a)
{
    $o = '';
    $uid = $a->profile['uid'];
    $o .= replace_macros(get_markup_template('section_title.tpl'), array('$title' => t('Profile')));
    if ($a->profile['name']) {
        $tpl = get_markup_template('profile_advanced.tpl');
        $profile = array();
        $profile['fullname'] = array(t('Full Name:'), $a->profile['name']);
        if ($a->profile['gender']) {
            $profile['gender'] = array(t('Gender:'), $a->profile['gender']);
        }
        if ($a->profile['dob'] && $a->profile['dob'] != '0000-00-00') {
            $year_bd_format = t('j F, Y');
            $short_bd_format = t('j F');
            $val = intval($a->profile['dob']) ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)) : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format));
            $profile['birthday'] = array(t('Birthday:'), $val);
        }
        if ($age = age($a->profile['dob'], $a->profile['timezone'], '')) {
            $profile['age'] = array(t('Age:'), $age);
        }
        if ($a->profile['marital']) {
            $profile['marital'] = array(t('Status:'), $a->profile['marital']);
        }
        if ($a->profile['with']) {
            $profile['marital']['with'] = $a->profile['with'];
        }
        if (strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') {
            $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s'));
        }
        if ($a->profile['sexual']) {
            $profile['sexual'] = array(t('Sexual Preference:'), $a->profile['sexual']);
        }
        if ($a->profile['homepage']) {
            $profile['homepage'] = array(t('Homepage:'), linkify($a->profile['homepage']));
        }
        if ($a->profile['hometown']) {
            $profile['hometown'] = array(t('Hometown:'), linkify($a->profile['hometown']));
        }
        if ($a->profile['pub_keywords']) {
            $profile['pub_keywords'] = array(t('Tags:'), $a->profile['pub_keywords']);
        }
        if ($a->profile['politic']) {
            $profile['politic'] = array(t('Political Views:'), $a->profile['politic']);
        }
        if ($a->profile['religion']) {
            $profile['religion'] = array(t('Religion:'), $a->profile['religion']);
        }
        if ($txt = prepare_text($a->profile['about'])) {
            $profile['about'] = array(t('About:'), $txt);
        }
        if ($txt = prepare_text($a->profile['interest'])) {
            $profile['interest'] = array(t('Hobbies/Interests:'), $txt);
        }
        if ($txt = prepare_text($a->profile['likes'])) {
            $profile['likes'] = array(t('Likes:'), $txt);
        }
        if ($txt = prepare_text($a->profile['dislikes'])) {
            $profile['dislikes'] = array(t('Dislikes:'), $txt);
        }
        if ($txt = prepare_text($a->profile['contact'])) {
            $profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
        }
        if ($txt = prepare_text($a->profile['music'])) {
            $profile['music'] = array(t('Musical interests:'), $txt);
        }
        if ($txt = prepare_text($a->profile['book'])) {
            $profile['book'] = array(t('Books, literature:'), $txt);
        }
        if ($txt = prepare_text($a->profile['tv'])) {
            $profile['tv'] = array(t('Television:'), $txt);
        }
        if ($txt = prepare_text($a->profile['film'])) {
            $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
        }
        if ($txt = prepare_text($a->profile['romance'])) {
            $profile['romance'] = array(t('Love/Romance:'), $txt);
        }
        if ($txt = prepare_text($a->profile['work'])) {
            $profile['work'] = array(t('Work/employment:'), $txt);
        }
        if ($txt = prepare_text($a->profile['education'])) {
            $profile['education'] = array(t('School/education:'), $txt);
        }
        //show subcribed forum if it is enabled in the usersettings
        if (feature_enabled($uid, 'forumlist_profile')) {
            $profile['forumlist'] = array(t('Forums:'), forumlist_profile_advanced($uid));
        }
        if ($a->profile['uid'] == local_user()) {
            $profile['edit'] = array($a->get_baseurl() . '/profiles/' . $a->profile['id'], t('Edit profile'), "", t('Edit profile'));
        }
        return replace_macros($tpl, array('$title' => t('Profile'), '$profile' => $profile));
    }
    return '';
}
Beispiel #11
0
 function get_events()
 {
     require_once 'include/bbcode.php';
     $a = get_app();
     $o = '';
     if (!local_user()) {
         return $o;
     }
     $bd_format = t('g A l F d');
     // 8 AM Friday January 18
     $bd_short = t('F d');
     $r = q("SELECT `event`.* FROM `event` \n\t\tWHERE `event`.`uid` = %d AND `type` != 'birthday' AND `start` < '%s' AND `start` > '%s'\n\t\tORDER BY `start` ASC ", intval(local_user()), dbesc(datetime_convert('UTC', 'UTC', 'now + 6 days')), dbesc(datetime_convert('UTC', 'UTC', 'now - 1 days')));
     if ($r && count($r)) {
         $now = strtotime('now');
         $istoday = false;
         foreach ($r as $rr) {
             if (strlen($rr['name'])) {
                 $total++;
             }
             $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start'], 'Y-m-d');
             if ($strt === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d')) {
                 $istoday = true;
             }
         }
         $classtoday = $istoday ? ' event-today ' : '';
         $o .= '<div id="event-notice" class="birthday-notice fakelink' . $classtoday . '" onclick=openClose(\'event-wrapper\'); >' . t('Event Reminders') . ' ' . '(' . count($r) . ')' . '</div>';
         $o .= '<div id="event-wrapper" style="display: none;" ><div id="event-title">' . t('Events this week:') . '</div>';
         $o .= '<div id="event-title-end"></div>';
         foreach ($r as $rr) {
             if ($rr['adjust']) {
                 $md = datetime_convert('UTC', $a->timezone, $rr['start'], 'Y/m\\#\\l\\i\\n\\k\\-j');
             } else {
                 $md = datetime_convert('UTC', 'UTC', $rr['start'], 'Y/m\\#\\l\\i\\n\\k\\-j');
             }
             $title = substr(strip_tags(bbcode($rr['desc'])), 0, 32) . '... ';
             if (!$title) {
                 $title = t('[No description]');
             }
             $strt = datetime_convert('UTC', $rr['convert'] ? $a->timezone : 'UTC', $rr['start']);
             $today = substr($strt, 0, 10) === datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d') ? true : false;
             $o .= '<div class="event-list" id="event-' . $rr['eid'] . '"></a> <a href="events/' . $md . '">' . $title . '</a>' . day_translate(datetime_convert('UTC', $rr['adjust'] ? $a->timezone : 'UTC', $rr['start'], $bd_format)) . ($today ? ' ' . t('[today]') : '') . '</div>';
         }
         $o .= '</div></div>';
     }
     return $o;
 }
Beispiel #12
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $o = "";
    // tabs
    $o .= profile_tabs($a, True);
    $o .= '<h2>' . t('Events') . '</h2>';
    $mode = 'view';
    $y = 0;
    $m = 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\tWHERE `event`.`uid` = %d\n\t\t\tAND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' ) \n\t\t\tOR  (  `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ", intval(local_user()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $o .= '<div id="new-event-link"><a href="' . $a->get_baseurl() . '/events/new' . '" >' . t('Create New Event') . '</a></div>';
        $o .= '<div id="event-calendar-wrapper">';
        $o .= '<a href="' . $a->get_baseurl() . '/events/' . $prevyear . '/' . $prevmonth . '" class="prevcal"><div id="event-calendar-prev" class="icon prev" title="' . t('Previous') . '"></div></a>';
        $o .= cal($y, $m, $links, ' eventcal');
        $o .= '<a href="' . $a->get_baseurl() . '/events/' . $nextyear . '/' . $nextmonth . '" class="nextcal"><div id="event-calendar-next" class="icon next" title="' . t('Next') . '"></div></a>';
        $o .= '</div>';
        $o .= '<div class="event-calendar-end"></div>';
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                if ($d !== $last_date) {
                    $o .= '<hr /><a name="link-' . $j . '" ><div class="event-list-date">' . $d . '</div></a>';
                }
                $last_date = $d;
                if ($rr['author-name']) {
                    $o .= '<a href="' . $rr['author-link'] . '" ><img src="' . $rr['author-avatar'] . '" height="32" width="32" />' . $rr['author-name'] . '</a>';
                }
                $o .= format_event_html($rr);
                $o .= !$rr['cid'] ? '<a href="' . $a->get_baseurl() . '/events/event/' . $rr['id'] . '" title="' . t('Edit event') . '" class="edit-event-link icon pencil"></a>' : '';
                if ($rr['plink']) {
                    $o .= '<a href="' . $rr['plink'] . '" title="' . t('link to source') . '" target="external-link" class="plink-event-link icon remote-link"></a></div>';
                }
                $o .= '<div class="clear"></div>';
            }
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $htpl = get_markup_template('event_head.tpl');
        $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl()));
        $tpl = get_markup_template('event_form.tpl');
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = x($orig_event) && $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $dateformat = datesel_format($f);
        $timeformat = t('hour:minute');
        require_once 'include/acl_selectors.php';
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$e_text' => t('Event details'), '$e_desc' => sprintf(t('Format is %s %s. Starting date and Description are required.'), $dateformat, $timeformat), '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ', '$s_dsel' => datesel($f, 'start', $syear + 5, $syear, false, $syear, $smonth, $sday), '$s_tsel' => timesel('start', $shour, $sminute), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datesel($f, 'finish', $fyear + 5, $fyear, false, $fyear, $fmonth, $fday), '$f_tsel' => timesel('finish', $fhour, $fminute), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:') . ' <span class="required">*</span>', '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$acl' => $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user, false), '$submit' => t('Submit')));
        return $o;
    }
}
Beispiel #13
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    if ($a->argc == 1) {
        $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
    }
    if ($a->argc > 2 && $a->argv[1] === 'ignore' && intval($a->argv[2])) {
        $r = q("update event set ignore = 1 where id = %d and uid = %d", intval($a->argv[2]), intval(local_user()));
    }
    if ($a->argc > 2 && $a->argv[1] === 'unignore' && intval($a->argv[2])) {
        $r = q("update event set ignore = 0 where id = %d and uid = %d", intval($a->argv[2]), intval(local_user()));
    }
    if ($a->theme_events_in_profile) {
        nav_set_selected('home');
    } else {
        nav_set_selected('events');
    }
    $editselect = 'none';
    if (feature_enabled(local_user(), 'richtext')) {
        $editselect = 'textareas';
    }
    // First day of the week (0 = Sunday)
    $firstDay = get_pconfig(local_user(), 'system', 'first_day_of_week');
    if ($firstDay === false) {
        $firstDay = 0;
    }
    $i18n = array("firstDay" => $firstDay, "Sun" => t("Sun"), "Mon" => t("Mon"), "Tue" => t("Tue"), "Wed" => t("Wed"), "Thu" => t("Thu"), "Fri" => t("Fri"), "Sat" => t("Sat"), "Sunday" => t("Sunday"), "Monday" => t("Monday"), "Tuesday" => t("Tuesday"), "Wednesday" => t("Wednesday"), "Thursday" => t("Thursday"), "Friday" => t("Friday"), "Saturday" => t("Saturday"), "Jan" => t("Jan"), "Feb" => t("Feb"), "Mar" => t("Mar"), "Apr" => t("Apr"), "May" => t("May"), "Jun" => t("Jun"), "Jul" => t("Jul"), "Aug" => t("Aug"), "Sep" => t("Sept"), "Oct" => t("Oct"), "Nov" => t("Nov"), "Dec" => t("Dec"), "January" => t("January"), "February" => t("February"), "March" => t("March"), "April" => t("April"), "May" => t("May"), "June" => t("June"), "July" => t("July"), "August" => t("August"), "September" => t("September"), "October" => t("October"), "November" => t("November"), "December" => t("December"), "today" => t("today"), "month" => t("month"), "week" => t("week"), "day" => t("day"));
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl(), '$i18n' => $i18n, '$editselect' => $editselect));
    $etpl = get_markup_template('event_end.tpl');
    $a->page['end'] .= replace_macros($etpl, array('$baseurl' => $a->get_baseurl(), '$editselect' => $editselect));
    $o = "";
    // tabs
    if ($a->theme_events_in_profile) {
        $tabs = profile_tabs($a, True);
    }
    $mode = 'view';
    $y = 0;
    $m = 0;
    $ignored = x($_REQUEST, 'ignored') ? intval($_REQUEST['ignored']) : 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if ($a->argv[1] === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`\n\t\t\t\tLEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`\n\t\t\t\tWHERE `event`.`uid` = %d AND `event`.`id` = %d", intval(local_user()), intval($_GET['id']));
        } else {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event`\n\t\t\t\tLEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid`\n\t\t\t\tWHERE `event`.`uid` = %d and event.ignore = %d\n\t\t\t\tAND ((`adjust` = 0 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')\n\t\t\t\tOR  (`adjust` = 1 AND (`finish` >= '%s' OR (nofinish AND start >= '%s')) AND `start` <= '%s')) ", intval(local_user()), intval($ignored), dbesc($start), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                $edit = !$rr['cid'] ? array($a->get_baseurl() . '/events/event/' . $rr['id'], t('Edit event'), '', '') : null;
                $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                if (!$title) {
                    list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                    $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                }
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'start' => $start, 'end' => $end, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('link to source'), '', ''));
            }
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            //			if (get_config('experimentals','new_calendar')==1){
            $tpl = get_markup_template("events-js.tpl");
            //			} else {
            //				$tpl = get_markup_template("events.tpl");
            //			}
        }
        // Get rid of dashes in key names, Smarty3 can't handle them
        foreach ($events as $key => $event) {
            $event_item = array();
            foreach ($event['item'] as $k => $v) {
                $k = str_replace('-', '_', $k);
                $event_item[$k] = $v;
            }
            $events[$key]['item'] = $event_item;
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    // Passed parameters overrides anything found in the DB
    if ($mode === 'edit' || $mode === 'new') {
        if (!x($orig_event)) {
            $orig_event = array();
        }
        // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
        if (x($_REQUEST, 'nofinish')) {
            $orig_event['nofinish'] = $_REQUEST['nofinish'];
        }
        if (x($_REQUEST, 'adjust')) {
            $orig_event['adjust'] = $_REQUEST['adjust'];
        }
        if (x($_REQUEST, 'summary')) {
            $orig_event['summary'] = $_REQUEST['summary'];
        }
        if (x($_REQUEST, 'description')) {
            $orig_event['description'] = $_REQUEST['description'];
        }
        if (x($_REQUEST, 'location')) {
            $orig_event['location'] = $_REQUEST['location'];
        }
        if (x($_REQUEST, 'start')) {
            $orig_event['start'] = $_REQUEST['start'];
        }
        if (x($_REQUEST, 'finish')) {
            $orig_event['finish'] = $_REQUEST['finish'];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $t_orig = x($orig_event) ? $orig_event['summary'] : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid or $mode !== 'new') {
            $sh_checked .= ' disabled="disabled" ';
        }
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        require_once 'include/acl_selectors.php';
        if ($mode === 'new') {
            $acl = $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user);
        }
        $tpl = get_markup_template('event_form.tpl');
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$title' => t('Event details'), '$desc' => t('Starting date and Title are required.'), '$s_text' => t('Event Starts:') . ' <span class="required" title="' . t('Required') . '">*</span>', '$s_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $syear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), 'start_text', true, true, '', '', true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $fyear + 5), DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), 'finish_text', true, true, 'start_text'), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:'), '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$t_text' => t('Title:') . ' <span class="required" title="' . t('Required') . '">*</span>', '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$preview' => t('Preview'), '$acl' => $acl, '$submit' => t('Submit')));
        return $o;
    }
}
function advanced_profile(&$a)
{
    $o .= '';
    $o .= '<h2>' . t('Profile') . '</h2>';
    if ($a->profile['name']) {
        $tpl = get_markup_template('profile_advanced.tpl');
        $profile = array();
        $profile['fullname'] = array(t('Full Name:'), $a->profile['name']);
        if ($a->profile['gender']) {
            $profile['gender'] = array(t('Gender:'), $a->profile['gender']);
        }
        if ($a->profile['dob'] && $a->profile['dob'] != '0000-00-00') {
            $year_bd_format = t('j F, Y');
            $short_bd_format = t('j F');
            $val = intval($a->profile['dob']) ? day_translate(datetime_convert('UTC', 'UTC', $a->profile['dob'] . ' 00:00 +00:00', $year_bd_format)) : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr($a->profile['dob'], 6) . ' 00:00 +00:00', $short_bd_format));
            $profile['birthday'] = array(t('Birthday:'), $val);
        }
        if ($age = age($a->profile['dob'], $a->profile['timezone'], '')) {
            $profile['age'] = array(t('Age:'), $age);
        }
        if ($a->profile['marital']) {
            $profile['marital'] = array(t('Status:'), $a->profile['marital']);
        }
        if ($a->profile['with']) {
            $profile['marital']['with'] = $a->profile['with'];
        }
        if ($a->profile['sexual']) {
            $profile['sexual'] = array(t('Sexual Preference:'), $a->profile['sexual']);
        }
        if ($a->profile['homepage']) {
            $profile['homepage'] = array(t('Homepage:'), linkify($a->profile['homepage']));
        }
        if ($a->profile['pub_keywords']) {
            $profile['pub_keywords'] = array(t('Tags:'), $a->profile['pub_keywords']);
        }
        if ($a->profile['politic']) {
            $profile['politic'] = array(t('Political Views:'), $a->profile['politic']);
        }
        if ($a->profile['religion']) {
            $profile['religion'] = array(t('Religion:'), $a->profile['religion']);
        }
        if ($txt = prepare_text($a->profile['about'])) {
            $profile['about'] = array(t('About:'), $txt);
        }
        if ($txt = prepare_text($a->profile['interest'])) {
            $profile['interest'] = array(t('Hobbies/Interests:'), $txt);
        }
        if ($txt = prepare_text($a->profile['contact'])) {
            $profile['contact'] = array(t('Contact information and Social Networks:'), $txt);
        }
        if ($txt = prepare_text($a->profile['music'])) {
            $profile['music'] = array(t('Musical interests:'), $txt);
        }
        if ($txt = prepare_text($a->profile['book'])) {
            $profile['book'] = array(t('Books, literature:'), $txt);
        }
        if ($txt = prepare_text($a->profile['tv'])) {
            $profile['tv'] = array(t('Television:'), $txt);
        }
        if ($txt = prepare_text($a->profile['film'])) {
            $profile['film'] = array(t('Film/dance/culture/entertainment:'), $txt);
        }
        if ($txt = prepare_text($a->profile['romance'])) {
            $profile['romance'] = array(t('Love/Romance:'), $txt);
        }
        if ($txt = prepare_text($a->profile['work'])) {
            $profile['work'] = array(t('Work/employment:'), $txt);
        }
        if ($txt = prepare_text($a->profile['education'])) {
            $profile['education'] = array(t('School/education:'), $txt);
        }
    }
    return replace_macros($tpl, array('$title' => t('Profile'), '$profile' => $profile));
}
Beispiel #15
0
function events_content(&$a)
{
    if (!local_user()) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $htpl = get_markup_template('event_head.tpl');
    $a->page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => $a->get_baseurl()));
    $o = "";
    // tabs
    $tabs = profile_tabs($a, True);
    $mode = 'view';
    $y = 0;
    $m = 0;
    if ($a->argc > 1) {
        if ($a->argc > 2 && $a->argv[1] == 'event') {
            $mode = 'edit';
            $event_id = intval($a->argv[2]);
        }
        if ($a->argv[1] === 'new') {
            $mode = 'new';
            $event_id = 0;
        }
        if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) {
            $mode = 'view';
            $y = intval($a->argv[1]);
            $m = intval($a->argv[2]);
        }
    }
    if ($mode == 'view') {
        $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
        $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
        if (!$y) {
            $y = intval($thisyear);
        }
        if (!$m) {
            $m = intval($thismonth);
        }
        // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
        // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
        if ($y < 1901) {
            $y = 1900;
        }
        if ($y > 2099) {
            $y = 2100;
        }
        $nextyear = $y;
        $nextmonth = $m + 1;
        if ($nextmonth > 12) {
            $nextmonth = 1;
            $nextyear++;
        }
        $prevyear = $y;
        if ($m > 1) {
            $prevmonth = $m - 1;
        } else {
            $prevmonth = 12;
            $prevyear--;
        }
        $dim = get_dim($y, $m);
        $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
        $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
        if ($a->argv[1] === 'json') {
            if (x($_GET, 'start')) {
                $start = date("Y-m-d h:i:s", $_GET['start']);
            }
            if (x($_GET, 'end')) {
                $finish = date("Y-m-d h:i:s", $_GET['end']);
            }
        }
        $start = datetime_convert('UTC', 'UTC', $start);
        $finish = datetime_convert('UTC', 'UTC', $finish);
        $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
        $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
        if (x($_GET, 'id')) {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\t\tWHERE `event`.`uid` = %d AND `event`.`id` = %d", intval(local_user()), intval($_GET['id']));
        } else {
            $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`,\n\t\t\t\t`item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` \n\t\t\t\tWHERE `event`.`uid` = %d\n\t\t\t\tAND (( `adjust` = 0 AND `start` >= '%s' AND `start` <= '%s' ) \n\t\t\t\tOR  (  `adjust` = 1 AND `start` >= '%s' AND `start` <= '%s' )) ", intval(local_user()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
        }
        $links = array();
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                if (!x($links, $j)) {
                    $links[$j] = $a->get_baseurl() . '/' . $a->cmd . '#link-' . $j;
                }
            }
        }
        $events = array();
        $last_date = '';
        $fmt = t('l, F j');
        if (count($r)) {
            $r = sort_by_date($r);
            foreach ($r as $rr) {
                $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j');
                $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt);
                $d = day_translate($d);
                $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c');
                if ($rr['nofinish']) {
                    $end = null;
                } else {
                    $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c');
                }
                $is_first = $d !== $last_date;
                $last_date = $d;
                $edit = !$rr['cid'] ? array($a->get_baseurl() . '/events/event/' . $rr['id'], t('Edit event'), '', '') : null;
                list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                $title = strip_tags($title);
                $html = format_event_html($rr);
                $rr['desc'] = bbcode($rr['desc']);
                $rr['location'] = bbcode($rr['location']);
                $events[] = array('id' => $rr['id'], 'start' => $start, 'end' => $end, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('link to source'), '', ''));
            }
        }
        if ($a->argv[1] === 'json') {
            echo json_encode($events);
            killme();
        }
        // links: array('href', 'text', 'extra css classes', 'title')
        if (x($_GET, 'id')) {
            $tpl = get_markup_template("event.tpl");
        } else {
            if (get_config('experimentals', 'new_calendar') == 1) {
                $tpl = get_markup_template("events-js.tpl");
            } else {
                $tpl = get_markup_template("events.tpl");
            }
        }
        $o = replace_macros($tpl, array('$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, '$title' => t('Events'), '$new_event' => array($a->get_baseurl() . '/events/new', t('Create New Event'), '', ''), '$previus' => array($a->get_baseurl() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array($a->get_baseurl() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events));
        if (x($_GET, 'id')) {
            echo $o;
            killme();
        }
        return $o;
    }
    if ($mode === 'edit' && $event_id) {
        $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()));
        if (count($r)) {
            $orig_event = $r[0];
        }
    }
    if ($mode === 'edit' || $mode === 'new') {
        $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
        $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
        $d_orig = x($orig_event) ? $orig_event['desc'] : '';
        $l_orig = x($orig_event) ? $orig_event['location'] : '';
        $eid = x($orig_event) ? $orig_event['id'] : 0;
        $cid = x($orig_event) ? $orig_event['cid'] : 0;
        $uri = x($orig_event) ? $orig_event['uri'] : '';
        if (!x($orig_event)) {
            $sh_checked = '';
        } else {
            $sh_checked = $orig_event['allow_cid'] === '<' . local_user() . '>' && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
        }
        if ($cid) {
            $sh_checked .= ' disabled="disabled" ';
        }
        $tpl = get_markup_template('event_form.tpl');
        $sdt = x($orig_event) ? $orig_event['start'] : 'now';
        $fdt = x($orig_event) ? $orig_event['finish'] : 'now';
        $tz = date_default_timezone_get();
        if (x($orig_event)) {
            $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
        }
        $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
        $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
        $sday = datetime_convert('UTC', $tz, $sdt, 'd');
        $shour = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0;
        $sminute = x($orig_event) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0;
        $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
        $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
        $fday = datetime_convert('UTC', $tz, $fdt, 'd');
        $fhour = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0;
        $fminute = x($orig_event) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0;
        $f = get_config('system', 'event_input_format');
        if (!$f) {
            $f = 'ymd';
        }
        $dateformat = datesel_format($f);
        $timeformat = t('hour:minute');
        require_once 'include/acl_selectors.php';
        $o .= replace_macros($tpl, array('$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$cid' => $cid, '$uri' => $uri, '$title' => t('Event details'), '$desc' => sprintf(t('Format is %s %s. Starting date and Description are required.'), $dateformat, $timeformat), '$s_text' => t('Event Starts:') . ' <span class="required">*</span> ', '$s_dsel' => datesel($f, 'start', $syear + 5, $syear, false, $syear, $smonth, $sday), '$s_tsel' => timesel('start', $shour, $sminute), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), '$f_dsel' => datesel($f, 'finish', $fyear + 5, $fyear, false, $fyear, $fmonth, $fday), '$f_tsel' => timesel('finish', $fhour, $fminute), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:') . ' <span class="required">*</span>', '$d_orig' => $d_orig, '$l_text' => t('Location:'), '$l_orig' => $l_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$acl' => $cid ? '' : populate_acl(x($orig_event) ? $orig_event : $a->user, false), '$submit' => t('Submit')));
        return $o;
    }
}
Beispiel #16
0
function posted_dates($uid, $wall)
{
    $dnow = datetime_convert('', date_default_timezone_get(), 'now', 'Y-m-d');
    $dthen = first_post_date($uid, $wall);
    if (!$dthen) {
        return array();
    }
    // If it's near the end of a long month, backup to the 28th so that in
    // consecutive loops we'll always get a whole month difference.
    if (intval(substr($dnow, 8)) > 28) {
        $dnow = substr($dnow, 0, 8) . '28';
    }
    if (intval(substr($dthen, 8)) > 28) {
        $dthen = substr($dthen, 0, 8) . '28';
    }
    $ret = array();
    // Starting with the current month, get the first and last days of every
    // month down to and including the month of the first post
    while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) {
        $dstart = substr($dnow, 0, 8) . '01';
        $dend = substr($dnow, 0, 8) . get_dim(intval($dnow), intval(substr($dnow, 5)));
        $start_month = datetime_convert('', '', $dstart, 'Y-m-d');
        $end_month = datetime_convert('', '', $dend, 'Y-m-d');
        $str = day_translate(datetime_convert('', '', $dnow, 'F Y'));
        $ret[] = array($str, $end_month, $start_month);
        $dnow = datetime_convert('', '', $dnow . ' -1 month', 'Y-m-d');
    }
    return $ret;
}
Beispiel #17
0
function format_event_diaspora($ev)
{
    $a = get_app();
    if (!(is_array($ev) && count($ev))) {
        return '';
    }
    $bd_format = t('l F d, Y \\@ g:i A');
    // Friday January 18, 2011 @ 8 AM
    $o = 'Friendica event notification:' . "\n";
    $o .= '**' . ($ev['summary'] ? bb2diaspora($ev['summary']) : bb2diaspora($ev['desc'])) . '**' . "\n";
    $o .= t('Starts:') . ' ' . '[' . ($ev['adjust'] ? day_translate(datetime_convert('UTC', 'UTC', $ev['start'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $ev['start'], $bd_format))) . '](' . $a->get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC', 'UTC', $ev['start'])) . ")\n";
    if (!$ev['nofinish']) {
        $o .= t('Finishes:') . ' ' . '[' . ($ev['adjust'] ? day_translate(datetime_convert('UTC', 'UTC', $ev['finish'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $ev['finish'], $bd_format))) . '](' . $a->get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC', 'UTC', $ev['finish'])) . ")\n";
    }
    if (strlen($ev['location'])) {
        $o .= t('Location:') . bb2diaspora($ev['location']) . "\n";
    }
    $o .= "\n";
    return $o;
}
Beispiel #18
0
 function init()
 {
     $result = array();
     $notifs = array();
     $result['notify'] = 0;
     $result['home'] = 0;
     $result['network'] = 0;
     $result['intros'] = 0;
     $result['mail'] = 0;
     $result['register'] = 0;
     $result['events'] = 0;
     $result['events_today'] = 0;
     $result['birthdays'] = 0;
     $result['birthdays_today'] = 0;
     $result['all_events'] = 0;
     $result['all_events_today'] = 0;
     $result['notice'] = array();
     $result['info'] = array();
     $t0 = dba_timer();
     header("content-type: application/json");
     $vnotify = false;
     $item_normal = item_normal();
     if (local_channel()) {
         $vnotify = get_pconfig(local_channel(), 'system', 'vnotify');
         $evdays = intval(get_pconfig(local_channel(), 'system', 'evdays'));
         $ob_hash = get_observer_hash();
     }
     // if unset show all visual notification types
     if ($vnotify === false) {
         $vnotify = -1;
     }
     if ($evdays < 1) {
         $evdays = 3;
     }
     /**
      * If you have several windows open to this site and switch to a different channel
      * in one of them, the others may get into a confused state showing you a page or options 
      * on that page which were only valid under the old identity. You session has changed.
      * Therefore we send a notification of this fact back to the browser where it is picked up
      * in javascript and which reloads the page it is on so that it is valid under the context
      * of the now current channel. 
      */
     $result['invalid'] = intval($_GET['uid']) && intval($_GET['uid']) != local_channel() ? 1 : 0;
     /**
      * Send all system messages (alerts) to the browser.
      * Some are marked as informational and some represent
      * errors or serious notifications. These typically
      * will popup on the current page (no matter what page it is)
      */
     if (x($_SESSION, 'sysmsg')) {
         foreach ($_SESSION['sysmsg'] as $m) {
             $result['notice'][] = array('message' => $m);
         }
         unset($_SESSION['sysmsg']);
     }
     if (x($_SESSION, 'sysmsg_info')) {
         foreach ($_SESSION['sysmsg_info'] as $m) {
             $result['info'][] = array('message' => $m);
         }
         unset($_SESSION['sysmsg_info']);
     }
     if (!($vnotify & VNOTIFY_INFO)) {
         $result['info'] = array();
     }
     if (!($vnotify & VNOTIFY_ALERT)) {
         $result['notice'] = array();
     }
     if (\App::$install) {
         echo json_encode($result);
         killme();
     }
     /**
      * Update chat presence indication (if applicable)
      */
     if (get_observer_hash() && !$result['invalid']) {
         $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1", dbesc(get_observer_hash()), dbesc($_SERVER['REMOTE_ADDR']));
         $basic_presence = false;
         if ($r) {
             $basic_presence = true;
             q("update chatpresence set cp_last = '%s' where cp_id = %d", dbesc(datetime_convert()), intval($r[0]['cp_id']));
         }
         if (!$basic_presence) {
             q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client)\n\t\t\t\t\tvalues( '%s', '%s', '%s', '%s' ) ", dbesc(get_observer_hash()), dbesc(datetime_convert()), dbesc('online'), dbesc($_SERVER['REMOTE_ADDR']));
         }
     }
     /**
      * Chatpresence continued... if somebody hasn't pinged recently, they've most likely left the page
      * and shouldn't count as online anymore. We allow an expection for bots.
      */
     q("delete from chatpresence where cp_last < %s - INTERVAL %s and cp_client != 'auto' ", db_utcnow(), db_quoteinterval('3 MINUTE'));
     if (!local_channel() || $result['invalid']) {
         echo json_encode($result);
         killme();
     }
     /**
      * Everything following is only permitted under the context of a locally authenticated site member.
      */
     /**
      * Handle "mark all xyz notifications read" requests.
      */
     // mark all items read
     if (x($_REQUEST, 'markRead') && local_channel()) {
         switch ($_REQUEST['markRead']) {
             case 'network':
                 $r = q("update item set item_unseen = 0 where item_unseen = 1 and uid = %d", intval(local_channel()));
                 break;
             case 'home':
                 $r = q("update item set item_unseen = 0 where item_unseen = 1 and item_wall = 1  and uid = %d", intval(local_channel()));
                 break;
             case 'messages':
                 $r = q("update mail set mail_seen = 1 where mail_seen = 0 and channel_id = %d ", intval(local_channel()));
                 break;
             case 'all_events':
                 $r = q("update event set `dismissed` = 1 where `dismissed` = 0 and uid = %d AND dtstart < '%s' AND dtstart > '%s' ", intval(local_channel()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')));
                 break;
             case 'notify':
                 $r = q("update notify set seen = 1 where uid = %d", intval(local_channel()));
                 break;
             default:
                 break;
         }
     }
     if (x($_REQUEST, 'markItemRead') && local_channel()) {
         $r = q("update item set item_unseen = 0 where parent = %d and uid = %d", intval($_REQUEST['markItemRead']), intval(local_channel()));
     }
     /**
      * URL ping/something will return detail for "something", e.g. a json list with which to populate a notification
      * dropdown menu.
      */
     if (argc() > 1 && argv(1) === 'notify') {
         $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_channel()));
         if ($t && intval($t[0]['total']) > 49) {
             $z = q("select * from notify where uid = %d\n\t\t\t\t\tand seen = 0 order by created desc limit 50", intval(local_channel()));
         } else {
             $z1 = q("select * from notify where uid = %d\n\t\t\t\t\tand seen = 0 order by created desc limit 50", intval(local_channel()));
             $z2 = q("select * from notify where uid = %d\n\t\t\t\t\tand seen = 1 order by created desc limit %d", intval(local_channel()), intval(50 - intval($t[0]['total'])));
             $z = array_merge($z1, $z2);
         }
         if (count($z)) {
             foreach ($z as $zz) {
                 $notifs[] = array('notify_link' => z_root() . '/notify/view/' . $zz['id'], 'name' => $zz['xname'], 'url' => $zz['url'], 'photo' => $zz['photo'], 'when' => relative_date($zz['created']), 'hclass' => $zz['seen'] ? 'notify-seen' : 'notify-unseen', 'message' => strip_tags(bbcode($zz['msg'])));
             }
         }
         echo json_encode(array('notify' => $notifs));
         killme();
     }
     if (argc() > 1 && argv(1) === 'messages') {
         $channel = \App::get_channel();
         $t = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan \n\t\t\t\twhere channel_id = %d and mail_seen = 0 and mail_deleted = 0 \n\t\t\t\tand from_xchan != '%s' order by created desc limit 50", intval(local_channel()), dbesc($channel['channel_hash']));
         if ($t) {
             foreach ($t as $zz) {
                 $notifs[] = array('notify_link' => z_root() . '/mail/' . $zz['id'], 'name' => $zz['xchan_name'], 'url' => $zz['xchan_url'], 'photo' => $zz['xchan_photo_s'], 'when' => relative_date($zz['created']), 'hclass' => intval($zz['mail_seen']) ? 'notify-seen' : 'notify-unseen', 'message' => t('sent you a private message'));
             }
         }
         echo json_encode(array('notify' => $notifs));
         killme();
     }
     if (argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) {
         $result = array();
         $r = q("SELECT * FROM item\n\t\t\t\tWHERE item_unseen = 1 and uid = %d {$item_normal}\n\t\t\t\tand author_xchan != '%s' ORDER BY created DESC limit 300", intval(local_channel()), dbesc($ob_hash));
         if ($r) {
             xchan_query($r);
             foreach ($r as $item) {
                 if (argv(1) === 'home' && !intval($item['item_wall'])) {
                     continue;
                 }
                 $result[] = \Zotlabs\Lib\Enotify::format($item);
             }
         }
         //		logger('ping (network||home): ' . print_r($result, true), LOGGER_DATA);
         echo json_encode(array('notify' => $result));
         killme();
     }
     if (argc() > 1 && argv(1) === 'intros') {
         $result = array();
         $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ORDER BY abook_created DESC LIMIT 50", intval(local_channel()));
         if ($r) {
             foreach ($r as $rr) {
                 $result[] = array('notify_link' => z_root() . '/connections/ifpending', 'name' => $rr['xchan_name'], 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], 'when' => relative_date($rr['abook_created']), 'hclass' => 'notify-unseen', 'message' => t('added your channel'));
             }
         }
         logger('ping (intros): ' . print_r($result, true), LOGGER_DATA);
         echo json_encode(array('notify' => $result));
         killme();
     }
     if (argc() > 1 && argv(1) === 'all_events') {
         $bd_format = t('g A l F d');
         // 8 AM Friday January 18
         $result = array();
         $r = q("SELECT * FROM event left join xchan on event_xchan = xchan_hash\n\t\t\t\tWHERE `event`.`uid` = %d AND dtstart < '%s' AND dtstart > '%s' and `dismissed` = 0\n\t\t\t\tand etype in ( 'event', 'birthday' )\n\t\t\t\tORDER BY `dtstart` DESC LIMIT 1000", intval(local_channel()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')));
         if ($r) {
             foreach ($r as $rr) {
                 if ($rr['adjust']) {
                     $md = datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'Y/m');
                 } else {
                     $md = datetime_convert('UTC', 'UTC', $rr['dtstart'], 'Y/m');
                 }
                 $strt = datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['dtstart']);
                 $today = substr($strt, 0, 10) === datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d') ? true : false;
                 $when = day_translate(datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['dtstart'], $bd_format)) . ($today ? ' ' . t('[today]') : '');
                 $result[] = array('notify_link' => z_root() . '/events', 'name' => $rr['xchan_name'], 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], 'when' => $when, 'hclass' => 'notify-unseen', 'message' => t('posted an event'));
             }
         }
         logger('ping (all_events): ' . print_r($result, true), LOGGER_DATA);
         echo json_encode(array('notify' => $result));
         killme();
     }
     /**
      * Normal ping - just the counts, no detail
      */
     if ($vnotify & VNOTIFY_SYSTEM) {
         $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_channel()));
         if ($t) {
             $result['notify'] = intval($t[0]['total']);
         }
     }
     $t1 = dba_timer();
     if ($vnotify & (VNOTIFY_NETWORK | VNOTIFY_CHANNEL)) {
         $r = q("SELECT id, item_wall FROM item\n\t\t\t\tWHERE item_unseen = 1 and uid = %d\n\t\t\t\t{$item_normal}\n\t\t\t\tand author_xchan != '%s'", intval(local_channel()), dbesc($ob_hash));
         if ($r) {
             $arr = array('items' => $r);
             call_hooks('network_ping', $arr);
             foreach ($r as $it) {
                 if (intval($it['item_wall'])) {
                     $result['home']++;
                 } else {
                     $result['network']++;
                 }
             }
         }
     }
     if (!($vnotify & VNOTIFY_NETWORK)) {
         $result['network'] = 0;
     }
     if (!($vnotify & VNOTIFY_CHANNEL)) {
         $result['home'] = 0;
     }
     $t2 = dba_timer();
     if ($vnotify & VNOTIFY_INTRO) {
         $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ", intval(local_channel()));
         $t3 = dba_timer();
         if ($intr) {
             $result['intros'] = intval($intr[0]['total']);
         }
     }
     $t4 = dba_timer();
     $channel = \App::get_channel();
     if ($vnotify & VNOTIFY_MAIL) {
         $mails = q("SELECT count(id) as total from mail\n\t\t\t\tWHERE channel_id = %d AND mail_seen = 0 and from_xchan != '%s' ", intval(local_channel()), dbesc($channel['channel_hash']));
         if ($mails) {
             $result['mail'] = intval($mails[0]['total']);
         }
     }
     if ($vnotify & VNOTIFY_REGISTER) {
         if (\App::$config['system']['register_policy'] == REGISTER_APPROVE && is_site_admin()) {
             $regs = q("SELECT count(account_id) as total from account where (account_flags & %d) > 0", intval(ACCOUNT_PENDING));
             if ($regs) {
                 $result['register'] = intval($regs[0]['total']);
             }
         }
     }
     $t5 = dba_timer();
     if ($vnotify & (VNOTIFY_EVENT | VNOTIFY_EVENTTODAY | VNOTIFY_BIRTHDAY)) {
         $events = q("SELECT etype, dtstart, adjust FROM `event`\n\t\t\t\tWHERE `event`.`uid` = %d AND dtstart < '%s' AND dtstart > '%s' and `dismissed` = 0\n\t\t\t\tand etype in ( 'event', 'birthday' )\n\t\t\t\tORDER BY `dtstart` ASC ", intval(local_channel()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')));
         if ($events) {
             $result['all_events'] = count($events);
             if ($result['all_events']) {
                 $str_now = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d');
                 foreach ($events as $x) {
                     $bd = false;
                     if ($x['etype'] === 'birthday') {
                         $result['birthdays']++;
                         $bd = true;
                     } else {
                         $result['events']++;
                     }
                     if (datetime_convert('UTC', intval($x['adjust']) ? date_default_timezone_get() : 'UTC', $x['dtstart'], 'Y-m-d') === $str_now) {
                         $result['all_events_today']++;
                         if ($bd) {
                             $result['birthdays_today']++;
                         } else {
                             $result['events_today']++;
                         }
                     }
                 }
             }
         }
     }
     if (!($vnotify & VNOTIFY_EVENT)) {
         $result['all_events'] = $result['events'] = 0;
     }
     if (!($vnotify & VNOTIFY_EVENTTODAY)) {
         $result['all_events_today'] = $result['events_today'] = 0;
     }
     if (!($vnotify & VNOTIFY_BIRTHDAY)) {
         $result['birthdays'] = 0;
     }
     $x = json_encode($result);
     $t6 = dba_timer();
     //	logger('ping timer: ' . sprintf('%01.4f %01.4f %01.4f %01.4f %01.4f %01.4f',$t6 - $t5, $t5 - $t4, $t4 - $t3, $t3 - $t2, $t2 - $t1, $t1 - $t0));
     echo $x;
     killme();
 }
Beispiel #19
0
/**
 * @brief do several updates when pinged.
 *
 * This function does several tasks. Whenever called it checks for new messages,
 * introductions, notifications, etc. and returns a json with the results.
 *
 * @param App &$a
 * @result JSON
 */
function ping_init(&$a)
{
    $result = array();
    $notifs = array();
    $result['notify'] = 0;
    $result['home'] = 0;
    $result['network'] = 0;
    $result['intros'] = 0;
    $result['mail'] = 0;
    $result['register'] = 0;
    $result['events'] = 0;
    $result['events_today'] = 0;
    $result['birthdays'] = 0;
    $result['birthdays_today'] = 0;
    $result['all_events'] = 0;
    $result['all_events_today'] = 0;
    $result['notice'] = array();
    $result['info'] = array();
    $t0 = dba_timer();
    header("content-type: application/json");
    /**
     * If you have several windows open to this site and switch to a different channel
     * in one of them, the others may get into a confused state showing you a page or options 
     * on that page which were only valid under the old identity. You session has changed.
     * Therefore we send a notification of this fact back to the browser where it is picked up
     * in javascript and which reloads the page it is on so that it is valid under the context
     * of the now current channel. 
     */
    $result['invalid'] = intval($_GET['uid']) && intval($_GET['uid']) != local_user() ? 1 : 0;
    /**
     * Send all system messages (alerts) to the browser.
     * Some are marked as informational and some represent
     * errors or serious notifications. These typically
     * will popup on the current page (no matter what page it is)
     */
    if (x($_SESSION, 'sysmsg')) {
        foreach ($_SESSION['sysmsg'] as $m) {
            $result['notice'][] = array('message' => $m);
        }
        unset($_SESSION['sysmsg']);
    }
    if (x($_SESSION, 'sysmsg_info')) {
        foreach ($_SESSION['sysmsg_info'] as $m) {
            $result['info'][] = array('message' => $m);
        }
        unset($_SESSION['sysmsg_info']);
    }
    if ($a->install) {
        echo json_encode($result);
        killme();
    }
    /**
     * Update chat presence indication (if applicable)
     */
    if (get_observer_hash() && !$result['invalid']) {
        $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1", dbesc(get_observer_hash()), dbesc($_SERVER['REMOTE_ADDR']));
        $basic_presence = false;
        if ($r) {
            $basic_presence = true;
            q("update chatpresence set cp_last = '%s' where cp_id = %d limit 1", dbesc(datetime_convert()), intval($r[0]['cp_id']));
        }
        if (!$basic_presence) {
            q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client)\n\t\t\t\tvalues( '%s', '%s', '%s', '%s' ) ", dbesc(get_observer_hash()), dbesc(datetime_convert()), dbesc('online'), dbesc($_SERVER['REMOTE_ADDR']));
        }
    }
    /**
     * Chatpresence continued... if somebody hasn't pinged recently, they've most likely left the page
     * and shouldn't count as online anymore. We allow an expection for bots.
     */
    q("delete from chatpresence where cp_last < UTC_TIMESTAMP() - INTERVAL 3 MINUTE and cp_client != 'auto' ");
    if (!local_user() || $result['invalid']) {
        echo json_encode($result);
        killme();
    }
    /**
     * Everything following is only permitted under the context of a locally authenticated site member.
     */
    /**
     * Handle "mark all xyz notifications read" requests.
     */
    // mark all items read
    if (x($_REQUEST, 'markRead') && local_user()) {
        switch ($_REQUEST['markRead']) {
            case 'network':
                $r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and uid = %d", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(local_user()));
                break;
            case 'home':
                $r = q("update item set item_flags = ( item_flags ^ %d ) where (item_flags & %d) and (item_flags & %d) and uid = %d", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(ITEM_WALL), intval(local_user()));
                break;
            case 'messages':
                $r = q("update mail set mail_flags = ( mail_flags ^ %d ) where channel_id = %d and not (mail_flags & %d)", intval(MAIL_SEEN), intval(local_user()), intval(MAIL_SEEN));
                break;
            case 'all_events':
                $r = q("update event set `ignore` = 1 where `ignore` = 0 and uid = %d", intval(local_user()));
                break;
            case 'notify':
                $r = q("update notify set seen = 1 where uid = %d", intval(local_user()));
                break;
            default:
                break;
        }
    }
    /**
     * URL ping/something will return detail for "something", e.g. a json list with which to populate a notification
     * dropdown menu.
     */
    if (argc() > 1 && argv(1) === 'notify') {
        $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_user()));
        if ($t && intval($t[0]['total']) > 49) {
            $z = q("select * from notify where uid = %d\n\t\t\t\tand seen = 0 order by date desc limit 0, 50", intval(local_user()));
        } else {
            $z1 = q("select * from notify where uid = %d\n\t\t\t\tand seen = 0 order by date desc limit 0, 50", intval(local_user()));
            $z2 = q("select * from notify where uid = %d\n\t\t\t\tand seen = 1 order by date desc limit 0, %d", intval(local_user()), intval(50 - intval($t[0]['total'])));
            $z = array_merge($z1, $z2);
        }
        if (count($z)) {
            foreach ($z as $zz) {
                $notifs[] = array('notify_link' => $a->get_baseurl() . '/notify/view/' . $zz['id'], 'name' => '', 'url' => $zz['url'], 'photo' => $zz['photo'], 'when' => relative_date($zz['date']), 'class' => $zz['seen'] ? 'notify-seen' : 'notify-unseen', 'message' => strip_tags(bbcode($zz['msg'])));
            }
        }
        echo json_encode(array('notify' => $notifs));
        killme();
    }
    if (argc() > 1 && argv(1) === 'messages') {
        $channel = $a->get_channel();
        $t = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan \n\t\t\twhere channel_id = %d and not ( mail_flags & %d ) and not (mail_flags & %d ) \n\t\t\tand from_xchan != '%s' order by created desc limit 0,50", intval(local_user()), intval(MAIL_SEEN), intval(MAIL_DELETED), dbesc($channel['channel_hash']));
        if ($t) {
            foreach ($t as $zz) {
                $notifs[] = array('notify_link' => $a->get_baseurl() . '/mail/' . $zz['id'], 'name' => $zz['xchan_name'], 'url' => $zz['xchan_url'], 'photo' => $zz['xchan_photo_s'], 'when' => relative_date($zz['created']), 'class' => $zz['mail_flags'] & MAIL_SEEN ? 'notify-seen' : 'notify-unseen', 'message' => t('sent you a private message'));
            }
        }
        echo json_encode(array('notify' => $notifs));
        killme();
    }
    if (argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) {
        $result = array();
        $r = q("SELECT * FROM item\n\t\t\tWHERE item_restrict = %d and ( item_flags & %d ) and uid = %d", intval(ITEM_VISIBLE), intval(ITEM_UNSEEN), intval(local_user()));
        if ($r) {
            xchan_query($r);
            foreach ($r as $item) {
                if (argv(1) === 'home' && !($item['item_flags'] & ITEM_WALL)) {
                    continue;
                }
                $result[] = format_notification($item);
            }
        }
        logger('ping (network||home): ' . print_r($result, true), LOGGER_DATA);
        echo json_encode(array('notify' => $result));
        killme();
    }
    if (argc() > 1 && argv(1) === 'intros') {
        $result = array();
        $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) and not ((abook_flags & %d) or (xchan_flags & %d))", intval(local_user()), intval(ABOOK_FLAG_PENDING), intval(ABOOK_FLAG_SELF | ABOOK_FLAG_IGNORED), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN));
        if ($r) {
            foreach ($r as $rr) {
                $result[] = array('notify_link' => $a->get_baseurl() . '/connedit/' . $rr['abook_id'], 'name' => $rr['xchan_name'], 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], 'when' => relative_date($rr['abook_created']), 'class' => 'notify-unseen', 'message' => t('added your channel'));
            }
        }
        logger('ping (intros): ' . print_r($result, true), LOGGER_DATA);
        echo json_encode(array('notify' => $result));
        killme();
    }
    if (argc() > 1 && argv(1) === 'all_events') {
        $bd_format = t('g A l F d');
        // 8 AM Friday January 18
        $result = array();
        $r = q("SELECT * FROM event left join xchan on event_xchan = xchan_hash\n\t\t\tWHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0\n\t\t\tORDER BY `start` DESC ", intval(local_user()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + 7 days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')));
        if ($r) {
            foreach ($r as $rr) {
                if ($rr['adjust']) {
                    $md = datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'Y/m');
                } else {
                    $md = datetime_convert('UTC', 'UTC', $rr['start'], 'Y/m');
                }
                $strt = datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['start']);
                $today = substr($strt, 0, 10) === datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d') ? true : false;
                $when = day_translate(datetime_convert('UTC', $rr['adjust'] ? date_default_timezone_get() : 'UTC', $rr['start'], $bd_format)) . ($today ? ' ' . t('[today]') : '');
                $result[] = array('notify_link' => $a->get_baseurl() . '/events', 'name' => $rr['xchan_name'], 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], 'when' => $when, 'class' => 'notify-unseen', 'message' => t('posted an event'));
            }
        }
        logger('ping (all_events): ' . print_r($result, true), LOGGER_DATA);
        echo json_encode(array('notify' => $result));
        killme();
    }
    /**
     * Normal ping - just the counts, no detail
     */
    $t = q("select count(*) as total from notify where uid = %d and seen = 0", intval(local_user()));
    if ($t) {
        $result['notify'] = intval($t[0]['total']);
    }
    $t1 = dba_timer();
    $r = q("SELECT id, item_restrict, item_flags FROM item\n\t\tWHERE (item_restrict = %d) and ( item_flags & %d ) and uid = %d", intval(ITEM_VISIBLE), intval(ITEM_UNSEEN), intval(local_user()));
    if (count($r)) {
        $arr = array('items' => $r);
        call_hooks('network_ping', $arr);
        foreach ($r as $it) {
            if ($it['item_flags'] & ITEM_WALL) {
                $result['home']++;
            } else {
                $result['network']++;
            }
        }
    }
    $t2 = dba_timer();
    $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) and not ((abook_flags & %d) or (xchan_flags & %d))", intval(local_user()), intval(ABOOK_FLAG_PENDING), intval(ABOOK_FLAG_SELF | ABOOK_FLAG_IGNORED), intval(XCHAN_FLAGS_DELETED | XCHAN_FLAGS_ORPHAN));
    $t3 = dba_timer();
    if ($intr) {
        $result['intros'] = intval($intr[0]['total']);
    }
    $t4 = dba_timer();
    $channel = get_app()->get_channel();
    $mails = q("SELECT count(id) as total from mail\n\t\tWHERE channel_id = %d AND not (mail_flags & %d) and from_xchan != '%s' ", intval(local_user()), intval(MAIL_SEEN), dbesc($channel['channel_hash']));
    if ($mails) {
        $result['mail'] = intval($mails[0]['total']);
    }
    if ($a->config['system']['register_policy'] == REGISTER_APPROVE && is_site_admin()) {
        $regs = q("SELECT count(account_id) as total from account where (account_flags & %d)", intval(ACCOUNT_PENDING));
        if ($regs) {
            $result['register'] = intval($regs[0]['total']);
        }
    }
    $t5 = dba_timer();
    $events = q("SELECT type, start, adjust FROM `event`\n\t\tWHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0\n\t\tORDER BY `start` ASC ", intval(local_user()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + 7 days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')));
    if ($events) {
        $result['all_events'] = count($events);
        if ($result['all_events']) {
            $str_now = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d');
            foreach ($events as $x) {
                $bd = false;
                if ($x['type'] === 'birthday') {
                    $result['birthdays']++;
                    $bd = true;
                } else {
                    $result['events']++;
                }
                if (datetime_convert('UTC', intval($x['adjust']) ? date_default_timezone_get() : 'UTC', $x['start'], 'Y-m-d') === $str_now) {
                    $result['all_events_today']++;
                    if ($bd) {
                        $result['birthdays_today']++;
                    } else {
                        $result['events_today']++;
                    }
                }
            }
        }
    }
    $x = json_encode($result);
    $t6 = dba_timer();
    //	logger('ping timer: ' . sprintf('%01.4f %01.4f %01.4f %01.4f %01.4f %01.4f',$t6 - $t5, $t5 - $t4, $t4 - $t3, $t3 - $t2, $t2 - $t1, $t1 - $t0));
    echo $x;
    killme();
}
Beispiel #20
0
 function get()
 {
     if (argc() > 2 && argv(1) == 'ical') {
         $event_id = argv(2);
         require_once 'include/security.php';
         $sql_extra = permissions_sql(local_channel());
         $r = q("select * from event where event_hash = '%s' {$sql_extra} limit 1", dbesc($event_id));
         if ($r) {
             header('Content-type: text/calendar');
             header('content-disposition: attachment; filename="' . t('event') . '-' . $event_id . '.ics"');
             echo ical_wrapper($r);
             killme();
         } else {
             notice(t('Event not found.') . EOL);
             return;
         }
     }
     if (!local_channel()) {
         notice(t('Permission denied.') . EOL);
         return;
     }
     nav_set_selected('all_events');
     if (argc() > 2 && argv(1) === 'ignore' && intval(argv(2))) {
         $r = q("update event set dismissed = 1 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
     }
     if (argc() > 2 && argv(1) === 'unignore' && intval(argv(2))) {
         $r = q("update event set dismissed = 0 where id = %d and uid = %d", intval(argv(2)), intval(local_channel()));
     }
     $first_day = get_pconfig(local_channel(), 'system', 'cal_first_day');
     $first_day = $first_day ? $first_day : 0;
     $htpl = get_markup_template('event_head.tpl');
     \App::$page['htmlhead'] .= replace_macros($htpl, array('$baseurl' => z_root(), '$module_url' => '/events', '$modparams' => 1, '$lang' => \App::$language, '$first_day' => $first_day));
     $o = '';
     $channel = \App::get_channel();
     $mode = 'view';
     $y = 0;
     $m = 0;
     $ignored = x($_REQUEST, 'ignored') ? " and dismissed = " . intval($_REQUEST['ignored']) . " " : '';
     // logger('args: ' . print_r(\App::$argv,true));
     if (argc() > 1) {
         if (argc() > 2 && argv(1) === 'add') {
             $mode = 'add';
             $item_id = intval(argv(2));
         }
         if (argc() > 2 && argv(1) === 'drop') {
             $mode = 'drop';
             $event_id = argv(2);
         }
         if (argc() > 2 && intval(argv(1)) && intval(argv(2))) {
             $mode = 'view';
             $y = intval(argv(1));
             $m = intval(argv(2));
         }
         if (argc() <= 2) {
             $mode = 'view';
             $event_id = argv(1);
         }
     }
     if ($mode === 'add') {
         event_addtocal($item_id, local_channel());
         killme();
     }
     if ($mode == 'view') {
         /* edit/create form */
         if ($event_id) {
             $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
             if (count($r)) {
                 $orig_event = $r[0];
             }
         }
         $channel = \App::get_channel();
         // Passed parameters overrides anything found in the DB
         if (!x($orig_event)) {
             $orig_event = array();
         }
         // In case of an error the browser is redirected back here, with these parameters filled in with the previous values
         /*
         if(x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish'];
         if(x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust'];
         if(x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary'];
         if(x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description'];
         if(x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location'];
         if(x($_REQUEST,'start')) $orig_event['dtstart'] = $_REQUEST['start'];
         if(x($_REQUEST,'finish')) $orig_event['dtend'] = $_REQUEST['finish'];
         if(x($_REQUEST,'type')) $orig_event['etype'] = $_REQUEST['type'];
         */
         $n_checked = x($orig_event) && $orig_event['nofinish'] ? ' checked="checked" ' : '';
         $a_checked = x($orig_event) && $orig_event['adjust'] ? ' checked="checked" ' : '';
         $t_orig = x($orig_event) ? $orig_event['summary'] : '';
         $d_orig = x($orig_event) ? $orig_event['description'] : '';
         $l_orig = x($orig_event) ? $orig_event['location'] : '';
         $eid = x($orig_event) ? $orig_event['id'] : 0;
         $event_xchan = x($orig_event) ? $orig_event['event_xchan'] : $channel['channel_hash'];
         $mid = x($orig_event) ? $orig_event['mid'] : '';
         if (!x($orig_event)) {
             $sh_checked = '';
         } else {
             $sh_checked = ($orig_event['allow_cid'] === '<' . $channel['channel_hash'] . '>' || !$orig_event['allow_cid']) && !$orig_event['allow_gid'] && !$orig_event['deny_cid'] && !$orig_event['deny_gid'] ? '' : ' checked="checked" ';
         }
         if ($orig_event['event_xchan']) {
             $sh_checked .= ' disabled="disabled" ';
         }
         $sdt = x($orig_event) ? $orig_event['dtstart'] : 'now';
         $fdt = x($orig_event) ? $orig_event['dtend'] : '+1 hour';
         $tz = date_default_timezone_get();
         if (x($orig_event)) {
             $tz = $orig_event['adjust'] ? date_default_timezone_get() : 'UTC';
         }
         $syear = datetime_convert('UTC', $tz, $sdt, 'Y');
         $smonth = datetime_convert('UTC', $tz, $sdt, 'm');
         $sday = datetime_convert('UTC', $tz, $sdt, 'd');
         $shour = datetime_convert('UTC', $tz, $sdt, 'H');
         $sminute = datetime_convert('UTC', $tz, $sdt, 'i');
         $stext = datetime_convert('UTC', $tz, $sdt);
         $stext = substr($stext, 0, 14) . "00:00";
         $fyear = datetime_convert('UTC', $tz, $fdt, 'Y');
         $fmonth = datetime_convert('UTC', $tz, $fdt, 'm');
         $fday = datetime_convert('UTC', $tz, $fdt, 'd');
         $fhour = datetime_convert('UTC', $tz, $fdt, 'H');
         $fminute = datetime_convert('UTC', $tz, $fdt, 'i');
         $ftext = datetime_convert('UTC', $tz, $fdt);
         $ftext = substr($ftext, 0, 14) . "00:00";
         $type = x($orig_event) ? $orig_event['etype'] : 'event';
         $f = get_config('system', 'event_input_format');
         if (!$f) {
             $f = 'ymd';
         }
         $catsenabled = feature_enabled(local_channel(), 'categories');
         $category = '';
         if ($catsenabled && x($orig_event)) {
             $itm = q("select * from item where resource_type = 'event' and resource_id = '%s' and uid = %d limit 1", dbesc($orig_event['event_hash']), intval(local_channel()));
             $itm = fetch_post_tags($itm);
             if ($itm) {
                 $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
                 foreach ($cats as $cat) {
                     if (strlen($category)) {
                         $category .= ', ';
                     }
                     $category .= $cat['term'];
                 }
             }
         }
         require_once 'include/acl_selectors.php';
         $acl = new \Zotlabs\Access\AccessList($channel);
         $perm_defaults = $acl->get();
         $permissions = x($orig_event) ? $orig_event : $perm_defaults;
         //print_r(acl2json($permissions['allow_gid'])); killme();
         $tpl = get_markup_template('event_form.tpl');
         $form = replace_macros($tpl, array('$post' => z_root() . '/events', '$eid' => $eid, '$type' => $type, '$xchan' => $event_xchan, '$mid' => $mid, '$event_hash' => $event_id, '$summary' => array('summary', $event_id ? t('Edit event title') : t('Event title'), $t_orig, t('Required'), '*'), '$catsenabled' => $catsenabled, '$placeholdercategory' => t('Categories (comma-separated list)'), '$c_text' => $event_id ? t('Edit Category') : t('Category'), '$category' => $category, '$required' => '<span class="required" title="' . t('Required') . '">*</span>', '$s_dsel' => datetimesel($f, new \DateTime(), \DateTime::createFromFormat('Y', $syear + 5), \DateTime::createFromFormat('Y-m-d H:i', "{$syear}-{$smonth}-{$sday} {$shour}:{$sminute}"), $event_id ? t('Edit start date and time') : t('Start date and time'), 'start_text', true, true, '', '', true, $first_day), '$n_text' => t('Finish date and time are not known or not relevant'), '$n_checked' => $n_checked, '$f_dsel' => datetimesel($f, new \DateTime(), \DateTime::createFromFormat('Y', $fyear + 5), \DateTime::createFromFormat('Y-m-d H:i', "{$fyear}-{$fmonth}-{$fday} {$fhour}:{$fminute}"), $event_id ? t('Edit finish date and time') : t('Finish date and time'), 'finish_text', true, true, 'start_text', '', false, $first_day), '$nofinish' => array('nofinish', t('Finish date and time are not known or not relevant'), $n_checked, '', array(t('No'), t('Yes')), 'onclick="enableDisableFinishDate();"'), '$adjust' => array('adjust', t('Adjust for viewer timezone'), $a_checked, t('Important for events that happen in a particular place. Not practical for global holidays.'), array(t('No'), t('Yes'))), '$a_text' => t('Adjust for viewer timezone'), '$d_text' => $event_id ? t('Edit Description') : t('Description'), '$d_orig' => $d_orig, '$l_text' => $event_id ? t('Edit Location') : t('Location'), '$l_orig' => $l_orig, '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, '$share' => array('distr', t('Share this event'), $sh_checked, '', array(t('No'), t('Yes'))), '$preview' => t('Preview'), '$perms_label' => t('Permission settings'), '$acl' => $orig_event['event_xchan'] ? '' : populate_acl(x($orig_event) ? $orig_event : $perm_defaults, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_stream')), '$allow_cid' => acl2json($permissions['allow_cid']), '$allow_gid' => acl2json($permissions['allow_gid']), '$deny_cid' => acl2json($permissions['deny_cid']), '$deny_gid' => acl2json($permissions['deny_gid']), '$submit' => t('Submit'), '$advanced' => t('Advanced Options')));
         /* end edit/create form */
         $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y');
         $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm');
         if (!$y) {
             $y = intval($thisyear);
         }
         if (!$m) {
             $m = intval($thismonth);
         }
         $export = false;
         if (argc() === 4 && argv(3) === 'export') {
             $export = true;
         }
         // Put some limits on dates. The PHP date functions don't seem to do so well before 1900.
         // An upper limit was chosen to keep search engines from exploring links millions of years in the future.
         if ($y < 1901) {
             $y = 1900;
         }
         if ($y > 2099) {
             $y = 2100;
         }
         $nextyear = $y;
         $nextmonth = $m + 1;
         if ($nextmonth > 12) {
             $nextmonth = 1;
             $nextyear++;
         }
         $prevyear = $y;
         if ($m > 1) {
             $prevmonth = $m - 1;
         } else {
             $prevmonth = 12;
             $prevyear--;
         }
         $dim = get_dim($y, $m);
         $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0);
         $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59);
         if (argv(1) === 'json') {
             if (x($_GET, 'start')) {
                 $start = $_GET['start'];
             }
             if (x($_GET, 'end')) {
                 $finish = $_GET['end'];
             }
         }
         $start = datetime_convert('UTC', 'UTC', $start);
         $finish = datetime_convert('UTC', 'UTC', $finish);
         $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start);
         $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish);
         if (x($_GET, 'id')) {
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                                from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", intval(local_channel()), intval($_GET['id']));
         } elseif ($export) {
             $r = q("SELECT * from event where uid = %d\n\t\t\t\t\tAND (( `adjust` = 0 AND ( `dtend` >= '%s' or nofinish = 1 ) AND `dtstart` <= '%s' ) \n\t\t\t\t\tOR  (  `adjust` = 1 AND ( `dtend` >= '%s' or nofinish = 1 ) AND `dtstart` <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
         } else {
             // fixed an issue with "nofinish" events not showing up in the calendar.
             // There's still an issue if the finish date crosses the end of month.
             // Noting this for now - it will need to be fixed here and in Friendica.
             // Ultimately the finish date shouldn't be involved in the query.
             $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan\n\t                              from event left join item on event_hash = resource_id \n\t\t\t\t\twhere resource_type = 'event' and event.uid = %d {$ignored} \n\t\t\t\t\tAND (( adjust = 0 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' ) \n\t\t\t\t\tOR  (  adjust = 1 AND ( dtend >= '%s' or nofinish = 1 ) AND dtstart <= '%s' )) ", intval(local_channel()), dbesc($start), dbesc($finish), dbesc($adjust_start), dbesc($adjust_finish));
         }
         $links = array();
         if ($r && !$export) {
             xchan_query($r);
             $r = fetch_post_tags($r, true);
             $r = sort_by_date($r);
         }
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 if (!x($links, $j)) {
                     $links[$j] = z_root() . '/' . \App::$cmd . '#link-' . $j;
                 }
             }
         }
         $events = array();
         $last_date = '';
         $fmt = t('l, F j');
         if ($r) {
             foreach ($r as $rr) {
                 $j = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j');
                 $d = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt);
                 $d = day_translate($d);
                 $start = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c');
                 if ($rr['nofinish']) {
                     $end = null;
                 } else {
                     $end = $rr['adjust'] ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c');
                 }
                 $is_first = $d !== $last_date;
                 $last_date = $d;
                 $edit = local_channel() && $rr['author_xchan'] == get_observer_hash() ? array(z_root() . '/events/' . $rr['event_hash'] . '?expandform=1', t('Edit event'), '', '') : false;
                 $drop = array(z_root() . '/events/drop/' . $rr['event_hash'], t('Delete event'), '', '');
                 $title = strip_tags(html_entity_decode(bbcode($rr['summary']), ENT_QUOTES, 'UTF-8'));
                 if (!$title) {
                     list($title, $_trash) = explode("<br", bbcode($rr['desc']), 2);
                     $title = strip_tags(html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
                 }
                 $html = format_event_html($rr);
                 $rr['desc'] = bbcode($rr['desc']);
                 $rr['location'] = bbcode($rr['location']);
                 $events[] = array('id' => $rr['id'], 'hash' => $rr['event_hash'], 'start' => $start, 'end' => $end, 'drop' => $drop, 'allDay' => false, 'title' => $title, 'j' => $j, 'd' => $d, 'edit' => $edit, 'is_first' => $is_first, 'item' => $rr, 'html' => $html, 'plink' => array($rr['plink'], t('Link to Source'), '', ''));
             }
         }
         if ($export) {
             header('Content-type: text/calendar');
             header('content-disposition: attachment; filename="' . t('calendar') . '-' . $channel['channel_address'] . '.ics"');
             echo ical_wrapper($r);
             killme();
         }
         if (\App::$argv[1] === 'json') {
             echo json_encode($events);
             killme();
         }
         // links: array('href', 'text', 'extra css classes', 'title')
         if (x($_GET, 'id')) {
             $tpl = get_markup_template("event.tpl");
         } else {
             $tpl = get_markup_template("events-js.tpl");
         }
         $o = replace_macros($tpl, array('$baseurl' => z_root(), '$new_event' => array(z_root() . '/events', $event_id ? t('Edit Event') : t('Create Event'), '', ''), '$previus' => array(z_root() . "/events/{$prevyear}/{$prevmonth}", t('Previous'), '', ''), '$next' => array(z_root() . "/events/{$nextyear}/{$nextmonth}", t('Next'), '', ''), '$export' => array(z_root() . "/events/{$y}/{$m}/export", t('Export'), '', ''), '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events, '$view_label' => t('View'), '$month' => t('Month'), '$week' => t('Week'), '$day' => t('Day'), '$prev' => t('Previous'), '$next' => t('Next'), '$today' => t('Today'), '$form' => $form, '$expandform' => x($_GET, 'expandform') ? true : false));
         if (x($_GET, 'id')) {
             echo $o;
             killme();
         }
         return $o;
     }
     if ($mode === 'drop' && $event_id) {
         $r = q("SELECT * FROM `event` WHERE event_hash = '%s' AND `uid` = %d LIMIT 1", dbesc($event_id), intval(local_channel()));
         $sync_event = $r[0];
         if ($r) {
             $r = q("delete from event where event_hash = '%s' and uid = %d limit 1", dbesc($event_id), intval(local_channel()));
             if ($r) {
                 $r = q("update item set resource_type = '', resource_id = '' where resource_type = 'event' and resource_id = '%s' and uid = %d", dbesc($event_id), intval(local_channel()));
                 $sync_event['event_deleted'] = 1;
                 build_sync_packet(0, array('event' => array($sync_event)));
                 info(t('Event removed') . EOL);
             } else {
                 notice(t('Failed to remove event') . EOL);
             }
             goaway(z_root() . '/events');
         }
     }
 }