Esempio n. 1
0
File: event.php Progetto: Mauru/red
function bbtovcal($s)
{
    $o = '';
    $ev = bbtoevent($s);
    if ($ev['description']) {
        $o = format_event_html($ev);
    }
    return $o;
}
Esempio n. 2
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;
     }
 }
Esempio n. 3
0
function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = false, $forplaintext = false)
{
    $a = get_app();
    // Hide all [noparse] contained bbtags by spacefying them
    // POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image?
    $Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_spacefy', $Text);
    $Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_spacefy', $Text);
    $Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_spacefy', $Text);
    // Move all spaces out of the tags
    $Text = preg_replace("/\\[(\\w*)\\](\\s*)/ism", '$2[$1]', $Text);
    $Text = preg_replace("/(\\s*)\\[\\/(\\w*)\\]/ism", '[/$2]$1', $Text);
    // Extract the private images which use data urls since preg has issues with
    // large data sizes. Stash them away while we do bbcode conversion, and then put them back
    // in after we've done all the regex matching. We cannot use any preg functions to do this.
    $extracted = bb_extract_images($Text);
    $Text = $extracted['body'];
    $saved_image = $extracted['images'];
    // If we find any event code, turn it into an event.
    // After we're finished processing the bbcode we'll
    // replace all of the event code with a reformatted version.
    $ev = bbtoevent($Text);
    // Replace any html brackets with HTML Entities to prevent executing HTML or script
    // Don't use strip_tags here because it breaks [url] search by replacing & with amp
    $Text = str_replace("<", "&lt;", $Text);
    $Text = str_replace(">", "&gt;", $Text);
    // remove some newlines before the general conversion
    $Text = preg_replace("/\\s?\\[share(.*?)\\]\\s?(.*?)\\s?\\[\\/share\\]\\s?/ism", "[share\$1]\$2[/share]", $Text);
    $Text = preg_replace("/\\s?\\[quote(.*?)\\]\\s?(.*?)\\s?\\[\\/quote\\]\\s?/ism", "[quote\$1]\$2[/quote]", $Text);
    $Text = preg_replace("/\n\\[code\\]/ism", "[code]", $Text);
    $Text = preg_replace("/\\[\\/code\\]\n/ism", "[/code]", $Text);
    // Rearrange shares to attachments
    $Text = preg_replace_callback("((.*?)\\[class=(.*?)\\](.*?)\\[\\/class\\])ism", "bb_rearrange_share", $Text);
    // when the content is meant exporting to other systems then remove the avatar picture since this doesn't really look good on these systems
    if (!$tryoembed) {
        $Text = preg_replace("/\\[share(.*?)avatar\\s?=\\s?'.*?'\\s?(.*?)\\]\\s?(.*?)\\s?\\[\\/share\\]\\s?/ism", "\n[share\$1\$2]\$3[/share]", $Text);
    }
    // Convert new line chars to html <br /> tags
    // nlbr seems to be hopelessly messed up
    //	$Text = nl2br($Text);
    // We'll emulate it.
    $Text = trim($Text);
    $Text = str_replace("\r\n", "\n", $Text);
    // removing multiplicated newlines
    if (get_config("system", "remove_multiplicated_lines")) {
        $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n", "\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n");
        $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]", "\n[share ", "[/attachment]", "[h1]", "[/h1]", "[h2]", "[/h2]", "[h3]", "[/h3]", "[h4]", "[/h4]", "[h5]", "[/h5]", "[h6]", "[/h6]");
        do {
            $oldtext = $Text;
            $Text = str_replace($search, $replace, $Text);
        } while ($oldtext != $Text);
    }
    // Handle attached links or videos
    $Text = bb_attachment($Text, $simplehtml, $tryoembed);
    $Text = str_replace(array("\r", "\n"), array('<br />', '<br />'), $Text);
    if ($preserve_nl) {
        $Text = str_replace(array("\n", "\r"), array('', ''), $Text);
    }
    // Set up the parameters for a URL search string
    $URLSearchString = "^\\[\\]";
    // Set up the parameters for a MAIL search string
    $MAILSearchString = $URLSearchString;
    // Remove all hashtag addresses
    if ((!$tryoembed or $simplehtml) and !in_array($simplehtml, array(3, 7))) {
        $Text = preg_replace("/([#@])\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '$1$3', $Text);
    } elseif ($simplehtml == 3) {
        $Text = preg_replace("/([@])\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '$1<a href="$2">$3</a>', $Text);
    } elseif ($simplehtml == 7) {
        $Text = preg_replace("/([@])\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '$1<span class="vcard"><a href="$2" class="url" title="$3"><span class="fn nickname mention">$3</span></a></span>', $Text);
    }
    // Bookmarks in red - will be converted to bookmarks in friendica
    $Text = preg_replace("/#\\^\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '[bookmark=$1]$1[/bookmark]', $Text);
    $Text = preg_replace("/#\\^\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '[bookmark=$1]$2[/bookmark]', $Text);
    $Text = preg_replace("/#\\[url\\=[{$URLSearchString}]*\\]\\^\\[\\/url\\]\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/i", "[bookmark=\$1]\$2[/bookmark]", $Text);
    if (in_array($simplehtml, array(2, 6, 7, 8, 9))) {
        $Text = preg_replace_callback("/([^#@])\\[url\\=([^\\]]*)\\](.*?)\\[\\/url\\]/ism", "bb_expand_links", $Text);
        //$Text = preg_replace("/[^#@]\[url\=([^\]]*)\](.*?)\[\/url\]/ism",' $2 [url]$1[/url]',$Text);
        $Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", ' $2 [url]$1[/url]', $Text);
    }
    if ($simplehtml == 5) {
        $Text = preg_replace("/[^#@]\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '[url]$1[/url]', $Text);
    }
    // Perform URL Search
    if ($tryoembed) {
        $Text = preg_replace_callback("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", 'tryoembed', $Text);
    }
    if ($simplehtml == 5) {
        $Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url]$1[/url]', $Text);
    } else {
        $Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $Text);
    }
    // Handle Diaspora posts
    $Text = preg_replace_callback("&\\[url=/posts/([^\\[\\]]*)\\](.*)\\[\\/url\\]&Usi", 'bb_DiasporaLinks', $Text);
    // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
    //	if ($simplehtml != 7) {
    if (!$forplaintext) {
        $Text = preg_replace("/([^\\]\\='" . '"' . "]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1<a href="$2" target="_blank">$2</a>', $Text);
    } else {
        $Text = preg_replace("(\\[url\\]([{$URLSearchString}]*)\\[\\/url\\])ism", " \$1 ", $Text);
        $Text = preg_replace_callback("&\\[url=([^\\[\\]]*)\\]\\[img\\](.*)\\[\\/img\\]\\[\\/url\\]&Usi", 'bb_RemovePictureLinks', $Text);
    }
    //	}
    if ($tryoembed) {
        $Text = preg_replace_callback("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", 'tryoembed', $Text);
    }
    $Text = preg_replace("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<a href="$1" target="_blank">$1</a>', $Text);
    $Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
    //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
    // Red compatibility, though the link can't be authenticated on Friendica
    $Text = preg_replace("/\\[zrl\\=([{$URLSearchString}]*)\\](.*?)\\[\\/zrl\\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
    // we may need to restrict this further if it picks up too many strays
    // link acct:user@host to a webfinger profile redirector
    $Text = preg_replace('/acct:(.*?)@(.*?)([ ,])/', '<a href="' . $a->get_baseurl() . '/acctlink?addr=' . "\$1@\$2" . '" target="extlink" >acct:' . "\$1@\$2\$3" . '</a>', $Text);
    // Perform MAIL Search
    $Text = preg_replace("/\\[mail\\]([{$MAILSearchString}]*)\\[\\/mail\\]/", '<a href="mailto:$1">$1</a>', $Text);
    $Text = preg_replace("/\\[mail\\=([{$MAILSearchString}]*)\\](.*?)\\[\\/mail\\]/", '<a href="mailto:$1">$2</a>', $Text);
    // leave open the posibility of [map=something]
    // this is replaced in prepare_body() which has knowledge of the item location
    if (strpos($Text, '[/map]') !== false) {
        $Text = preg_replace_callback("/\\[map\\](.*?)\\[\\/map\\]/ism", 'bb_map_location', $Text);
    }
    if (strpos($Text, '[map=') !== false) {
        $Text = preg_replace_callback("/\\[map=(.*?)\\]/ism", 'bb_map_coords', $Text);
    }
    if (strpos($Text, '[map]') !== false) {
        $Text = preg_replace("/\\[map\\]/", '<div class="map"></div>', $Text);
    }
    // Check for headers
    $Text = preg_replace("(\\[h1\\](.*?)\\[\\/h1\\])ism", '<h1>$1</h1>', $Text);
    $Text = preg_replace("(\\[h2\\](.*?)\\[\\/h2\\])ism", '<h2>$1</h2>', $Text);
    $Text = preg_replace("(\\[h3\\](.*?)\\[\\/h3\\])ism", '<h3>$1</h3>', $Text);
    $Text = preg_replace("(\\[h4\\](.*?)\\[\\/h4\\])ism", '<h4>$1</h4>', $Text);
    $Text = preg_replace("(\\[h5\\](.*?)\\[\\/h5\\])ism", '<h5>$1</h5>', $Text);
    $Text = preg_replace("(\\[h6\\](.*?)\\[\\/h6\\])ism", '<h6>$1</h6>', $Text);
    // Check for bold text
    $Text = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '<strong>$1</strong>', $Text);
    // Check for Italics text
    $Text = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '<em>$1</em>', $Text);
    // Check for Underline text
    $Text = preg_replace("(\\[u\\](.*?)\\[\\/u\\])ism", '<u>$1</u>', $Text);
    // Check for strike-through text
    $Text = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '<strike>$1</strike>', $Text);
    // Check for over-line text
    $Text = preg_replace("(\\[o\\](.*?)\\[\\/o\\])ism", '<span class="overline">$1</span>', $Text);
    // Check for colored text
    $Text = preg_replace("(\\[color=(.*?)\\](.*?)\\[\\/color\\])ism", "<span style=\"color: \$1;\">\$2</span>", $Text);
    // Check for sized text
    // [size=50] --> font-size: 50px (with the unit).
    $Text = preg_replace("(\\[size=(\\d*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1px; line-height: initial;\">\$2</span>", $Text);
    $Text = preg_replace("(\\[size=(.*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1; line-height: initial;\">\$2</span>", $Text);
    // Check for centered text
    $Text = preg_replace("(\\[center\\](.*?)\\[\\/center\\])ism", "<div style=\"text-align:center;\">\$1</div>", $Text);
    // Check for list text
    $Text = str_replace("[*]", "<li>", $Text);
    // Check for style sheet commands
    $Text = preg_replace_callback("(\\[style=(.*?)\\](.*?)\\[\\/style\\])ism", "bb_cleanstyle", $Text);
    // Check for CSS classes
    $Text = preg_replace_callback("(\\[class=(.*?)\\](.*?)\\[\\/class\\])ism", "bb_cleanclass", $Text);
    // handle nested lists
    $endlessloop = 0;
    while ((strpos($Text, "[/list]") !== false && strpos($Text, "[list") !== false || strpos($Text, "[/ol]") !== false && strpos($Text, "[ol]") !== false || strpos($Text, "[/ul]") !== false && strpos($Text, "[ul]") !== false || strpos($Text, "[/li]") !== false && strpos($Text, "[li]") !== false) && ++$endlessloop < 20) {
        $Text = preg_replace("/\\[list\\](.*?)\\[\\/list\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=\\](.*?)\\[\\/list\\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=1\\](.*?)\\[\\/list\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)i)\\](.*?)\\[\\/list\\]/ism", '<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)I)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)a)\\](.*?)\\[\\/list\\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)A)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>', $Text);
        $Text = preg_replace("/\\[ul\\](.*?)\\[\\/ul\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
        $Text = preg_replace("/\\[ol\\](.*?)\\[\\/ol\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
        $Text = preg_replace("/\\[li\\](.*?)\\[\\/li\\]/ism", '<li>$1</li>', $Text);
    }
    $Text = preg_replace("/\\[th\\](.*?)\\[\\/th\\]/sm", '<th>$1</th>', $Text);
    $Text = preg_replace("/\\[td\\](.*?)\\[\\/td\\]/sm", '<td>$1</td>', $Text);
    $Text = preg_replace("/\\[tr\\](.*?)\\[\\/tr\\]/sm", '<tr>$1</tr>', $Text);
    $Text = preg_replace("/\\[table\\](.*?)\\[\\/table\\]/sm", '<table>$1</table>', $Text);
    $Text = preg_replace("/\\[table border=1\\](.*?)\\[\\/table\\]/sm", '<table border="1" >$1</table>', $Text);
    $Text = preg_replace("/\\[table border=0\\](.*?)\\[\\/table\\]/sm", '<table border="0" >$1</table>', $Text);
    $Text = str_replace('[hr]', '<hr />', $Text);
    // This is actually executed in prepare_body()
    $Text = str_replace('[nosmile]', '', $Text);
    // Check for font change text
    $Text = preg_replace("/\\[font=(.*?)\\](.*?)\\[\\/font\\]/sm", "<span style=\"font-family: \$1;\">\$2</span>", $Text);
    // Declare the format for [code] layout
    //	$Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism",'stripcode_br_cb',$Text);
    $CodeLayout = '<code>$1</code>';
    // Check for [code] text
    $Text = preg_replace("/\\[code\\](.*?)\\[\\/code\\]/ism", "{$CodeLayout}", $Text);
    // Declare the format for [spoiler] layout
    $SpoilerLayout = '<blockquote class="spoiler">$1</blockquote>';
    // Check for [spoiler] text
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/spoiler]") !== false and strpos($Text, "[spoiler]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[spoiler\\](.*?)\\[\\/spoiler\\]/ism", "{$SpoilerLayout}", $Text);
    }
    // Check for [spoiler=Author] text
    $t_wrote = t('$1 wrote:');
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/spoiler]") !== false and strpos($Text, "[spoiler=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[spoiler=[\"\\']*(.*?)[\"\\']*\\](.*?)\\[\\/spoiler\\]/ism", "<br /><strong class=" . '"spoiler"' . ">" . $t_wrote . "</strong><blockquote class=" . '"spoiler"' . ">\$2</blockquote>", $Text);
    }
    // Declare the format for [quote] layout
    $QuoteLayout = '<blockquote>$1</blockquote>';
    // Check for [quote] text
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/quote]") !== false and strpos($Text, "[quote]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[quote\\](.*?)\\[\\/quote\\]/ism", "{$QuoteLayout}", $Text);
    }
    // Check for [quote=Author] text
    $t_wrote = t('$1 wrote:');
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/quote]") !== false and strpos($Text, "[quote=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[quote=[\"\\']*(.*?)[\"\\']*\\](.*?)\\[\\/quote\\]/ism", "<br /><strong class=" . '"author"' . ">" . $t_wrote . "</strong><blockquote>\$2</blockquote>", $Text);
    }
    // [img=widthxheight]image source[/img]
    $Text = preg_replace_callback("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", 'bb_PictureCacheExt', $Text);
    $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="width: $1px;" >', $Text);
    $Text = preg_replace("/\\[zmg\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" src="$3" style="width: $1px;" >', $Text);
    // Images
    // [img]pathtoimage[/img]
    $Text = preg_replace_callback("/\\[img\\](.*?)\\[\\/img\\]/ism", 'bb_PictureCache', $Text);
    $Text = preg_replace("/\\[img\\](.*?)\\[\\/img\\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
    $Text = preg_replace("/\\[zmg\\](.*?)\\[\\/zmg\\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
    // Shared content
    $Text = preg_replace_callback("/(.*?)\\[share(.*?)\\](.*?)\\[\\/share\\]/ism", function ($match) use($simplehtml) {
        return bb_ShareAttributes($match, $simplehtml);
    }, $Text);
    $Text = preg_replace("/\\[crypt\\](.*?)\\[\\/crypt\\]/ism", '<br/><img src="' . $a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text);
    $Text = preg_replace("/\\[crypt(.*?)\\](.*?)\\[\\/crypt\\]/ism", '<br/><img src="' . $a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);
    //$Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);
    // Try to Oembed
    if ($tryoembed) {
        $Text = preg_replace("/\\[video\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4))\\[\\/video\\]/ism", '<video src="$1" controls="controls" width="' . $a->videowidth . '" height="' . $a->videoheight . '"><a href="$1">$1</a></video>', $Text);
        $Text = preg_replace("/\\[audio\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\\[\\/audio\\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $Text);
        $Text = preg_replace_callback("/\\[video\\](.*?)\\[\\/video\\]/ism", 'tryoembed', $Text);
        $Text = preg_replace_callback("/\\[audio\\](.*?)\\[\\/audio\\]/ism", 'tryoembed', $Text);
    } else {
        $Text = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/", '<a href="$1" target="_blank">$1</a>', $Text);
        $Text = preg_replace("/\\[audio\\](.*?)\\[\\/audio\\]/", '<a href="$1" target="_blank">$1</a>', $Text);
    }
    // html5 video and audio
    if ($tryoembed) {
        $Text = preg_replace("/\\[iframe\\](.*?)\\[\\/iframe\\]/ism", '<iframe src="$1" width="' . $a->videowidth . '" height="' . $a->videoheight . '"><a href="$1">$1</a></iframe>', $Text);
    } else {
        $Text = preg_replace("/\\[iframe\\](.*?)\\[\\/iframe\\]/ism", '<a href="$1">$1</a>', $Text);
    }
    // Youtube extensions
    if ($tryoembed) {
        $Text = preg_replace_callback("/\\[youtube\\](https?:\\/\\/www.youtube.com\\/watch\\?v\\=.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
        $Text = preg_replace_callback("/\\[youtube\\](www.youtube.com\\/watch\\?v\\=.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
        $Text = preg_replace_callback("/\\[youtube\\](https?:\\/\\/youtu.be\\/.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
    }
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/watch\\?v\\=(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/embed\\/(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/youtu.be\\/(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    if ($tryoembed) {
        $Text = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="https://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
    } else {
        $Text = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '<a href="https://www.youtube.com/watch?v=$1" target="_blank">https://www.youtube.com/watch?v=$1</a>', $Text);
    }
    if ($tryoembed) {
        $Text = preg_replace_callback("/\\[vimeo\\](https?:\\/\\/player.vimeo.com\\/video\\/[0-9]+).*?\\[\\/vimeo\\]/ism", 'tryoembed', $Text);
        $Text = preg_replace_callback("/\\[vimeo\\](https?:\\/\\/vimeo.com\\/[0-9]+).*?\\[\\/vimeo\\]/ism", 'tryoembed', $Text);
    }
    $Text = preg_replace("/\\[vimeo\\]https?:\\/\\/player.vimeo.com\\/video\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[vimeo]$1[/vimeo]', $Text);
    $Text = preg_replace("/\\[vimeo\\]https?:\\/\\/vimeo.com\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[vimeo]$1[/vimeo]', $Text);
    if ($tryoembed) {
        $Text = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="https://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $Text);
    } else {
        $Text = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '<a href="https://vimeo.com/$1" target="_blank">https://vimeo.com/$1</a>', $Text);
    }
    //	$Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
    // oembed tag
    $Text = oembed_bbcode2html($Text);
    // Avoid triple linefeeds through oembed
    $Text = str_replace("<br style='clear:left'></span><br /><br />", "<br style='clear:left'></span><br />", $Text);
    // If we found an event earlier, strip out all the event code and replace with a reformatted version.
    // Replace the event-start section with the entire formatted event. The other bbcode is stripped.
    // Summary (e.g. title) is required, earlier revisions only required description (in addition to
    // start which is always required). Allow desc with a missing summary for compatibility.
    if ((x($ev, 'desc') || x($ev, 'summary')) && x($ev, 'start')) {
        $sub = format_event_html($ev, $simplehtml);
        $Text = preg_replace("/\\[event\\-summary\\](.*?)\\[\\/event\\-summary\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-description\\](.*?)\\[\\/event\\-description\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-start\\](.*?)\\[\\/event\\-start\\]/ism", $sub, $Text);
        $Text = preg_replace("/\\[event\\-finish\\](.*?)\\[\\/event\\-finish\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-location\\](.*?)\\[\\/event\\-location\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-adjust\\](.*?)\\[\\/event\\-adjust\\]/ism", '', $Text);
    }
    //replace oneliner <code> with <key>
    $Text = preg_replace_callback("|(?!<br[^>]*>)<code>([^<]*)</code>(?!<br[^>]*>)|ism", 'bb_onelinecode_cb', $Text);
    // Unhide all [noparse] contained bbtags unspacefying them
    // and triming the [noparse] tag.
    $Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_unspacefy_and_trim', $Text);
    $Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_unspacefy_and_trim', $Text);
    $Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_unspacefy_and_trim', $Text);
    $Text = preg_replace('/\\[\\&amp\\;([#a-z0-9]+)\\;\\]/', '&$1;', $Text);
    $Text = preg_replace('/\\&\\#039\\;/', '\'', $Text);
    $Text = preg_replace('/\\&quot\\;/', '"', $Text);
    // fix any escaped ampersands that may have been converted into links
    $Text = preg_replace("/\\<([^>]*?)(src|href)=(.*?)\\&amp\\;(.*?)\\>/ism", '<$1$2=$3&$4>', $Text);
    $Text = preg_replace("/\\<([^>]*?)(src|href)=\"(?!http|ftp|mailto|gopher|cid)(.*?)\\>/ism", '<$1$2="">', $Text);
    if ($saved_image) {
        $Text = bb_replace_images($Text, $saved_image);
    }
    // Clean up the HTML by loading and saving the HTML with the DOM.
    // Bad structured html can break a whole page.
    // For performance reasons do it only with ativated item cache or at export.
    if (!$tryoembed or get_itemcachepath() != "") {
        $doc = new DOMDocument();
        $doc->preserveWhiteSpace = false;
        $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8");
        $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">';
        $encoding = '<?xml encoding="UTF-8">';
        @$doc->loadHTML($encoding . $doctype . "<html><body>" . $Text . "</body></html>");
        $doc->encoding = 'UTF-8';
        $Text = $doc->saveHTML();
        $Text = str_replace(array("<html><body>", "</body></html>", $doctype, $encoding), array("", "", "", ""), $Text);
        $Text = str_replace('<br></li>', '</li>', $Text);
        //$Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES');
    }
    // Clean up some useless linebreaks in lists
    //$Text = str_replace('<br /><ul','<ul ', $Text);
    //$Text = str_replace('</ul><br />','</ul>', $Text);
    //$Text = str_replace('</li><br />','</li>', $Text);
    //$Text = str_replace('<br /><li>','<li>', $Text);
    //	$Text = str_replace('<br /><ul','<ul ', $Text);
    call_hooks('bbcode', $Text);
    return trim($Text);
}
Esempio n. 4
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;
    }
}
Esempio n. 5
0
function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
{
    // Hide all [noparse] contained bbtags by spacefying them
    if (strpos($Text, '[noparse]') !== false) {
        $Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_spacefy', $Text);
    }
    if (strpos($Text, '[nobb]') !== false) {
        $Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_spacefy', $Text);
    }
    if (strpos($Text, '[pre]') !== false) {
        $Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_spacefy', $Text);
    }
    // If we find any event code, turn it into an event.
    // After we're finished processing the bbcode we'll
    // replace all of the event code with a reformatted version.
    $ev = bbtoevent($Text);
    // process [observer] tags before we do anything else because we might
    // be stripping away stuff that then doesn't need to be worked on anymore
    if ($cache) {
        $observer = false;
    } else {
        $observer = App::get_observer();
    }
    if (strpos($Text, '[/observer]') !== false || strpos($Text, '[/rpost]') !== false) {
        if ($observer) {
            $Text = preg_replace("/\\[observer\\=1\\](.*?)\\[\\/observer\\]/ism", '$1', $Text);
            $Text = preg_replace("/\\[observer\\=0\\].*?\\[\\/observer\\]/ism", '', $Text);
            $Text = preg_replace_callback("/\\[rpost(=(.*?))?\\](.*?)\\[\\/rpost\\]/ism", 'rpost_callback', $Text);
        } else {
            $Text = preg_replace("/\\[observer\\=1\\].*?\\[\\/observer\\]/ism", '', $Text);
            $Text = preg_replace("/\\[observer\\=0\\](.*?)\\[\\/observer\\]/ism", '$1', $Text);
            $Text = preg_replace("/\\[rpost(=.*?)?\\](.*?)\\[\\/rpost\\]/ism", '', $Text);
        }
    }
    if ($cache) {
        $channel = false;
    } else {
        $channel = App::get_channel();
    }
    if (strpos($Text, '[/channel]') !== false) {
        if ($channel) {
            $Text = preg_replace("/\\[channel\\=1\\](.*?)\\[\\/channel\\]/ism", '$1', $Text);
            $Text = preg_replace("/\\[channel\\=0\\].*?\\[\\/channel\\]/ism", '', $Text);
        } else {
            $Text = preg_replace("/\\[channel\\=1\\].*?\\[\\/channel\\]/ism", '', $Text);
            $Text = preg_replace("/\\[channel\\=0\\](.*?)\\[\\/channel\\]/ism", '$1', $Text);
        }
    }
    $x = bb_extract_images($Text);
    $Text = $x['body'];
    $saved_images = $x['images'];
    $Text = str_replace(array('[baseurl]', '[sitename]'), array(z_root(), get_config('system', 'sitename')), $Text);
    // Replace any html brackets with HTML Entities to prevent executing HTML or script
    // Don't use strip_tags here because it breaks [url] search by replacing & with amp
    $Text = str_replace("<", "&lt;", $Text);
    $Text = str_replace(">", "&gt;", $Text);
    // Convert new line chars to html <br /> tags
    // nlbr seems to be hopelessly messed up
    //	$Text = nl2br($Text);
    // We'll emulate it.
    $Text = str_replace("\r\n", "\n", $Text);
    $Text = str_replace(array("\r", "\n"), array('<br />', '<br />'), $Text);
    if ($preserve_nl) {
        $Text = str_replace(array("\n", "\r"), array('', ''), $Text);
    }
    $Text = str_replace(array("\t", "  "), array("&nbsp;&nbsp;&nbsp;&nbsp;", "&nbsp;&nbsp;"), $Text);
    // Set up the parameters for a URL search string
    $URLSearchString = "^\\[\\]";
    // Set up the parameters for a MAIL search string
    $MAILSearchString = $URLSearchString;
    // replace [observer.baseurl]
    if ($observer) {
        $s1 = '<span class="bb_observer" title="' . t('Different viewers will see this text differently') . '">';
        $s2 = '</span>';
        $obsBaseURL = $observer['xchan_connurl'];
        $obsBaseURL = preg_replace("/\\/poco\\/.*\$/", '', $obsBaseURL);
        $Text = str_replace('[observer.baseurl]', $obsBaseURL, $Text);
        $Text = str_replace('[observer.url]', $observer['xchan_url'], $Text);
        $Text = str_replace('[observer.name]', $s1 . $observer['xchan_name'] . $s2, $Text);
        $Text = str_replace('[observer.address]', $s1 . $observer['xchan_addr'] . $s2, $Text);
        $Text = str_replace('[observer.webname]', substr($observer['xchan_addr'], 0, strpos($observer['xchan_addr'], '@')), $Text);
        $Text = str_replace('[observer.photo]', $s1 . '[zmg]' . $observer['xchan_photo_l'] . '[/zmg]' . $s2, $Text);
    } else {
        $Text = str_replace('[observer.baseurl]', '', $Text);
        $Text = str_replace('[observer.url]', '', $Text);
        $Text = str_replace('[observer.name]', '', $Text);
        $Text = str_replace('[observer.address]', '', $Text);
        $Text = str_replace('[observer.webname]', '', $Text);
        $Text = str_replace('[observer.photo]', '', $Text);
    }
    // Perform URL Search
    $urlchars = '[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\@\\_\\~\\#\\%\\$\\!\\+\\,\\@]';
    if (strpos($Text, 'http') !== false) {
        $Text = preg_replace("/([^\\]\\='" . '"' . "\\/]|^|\\#\\^)(https?\\:\\/\\/{$urlchars}+)/ism", '$1<a href="$2" target="_blank" >$2</a>', $Text);
    }
    if (strpos($Text, '[/share]') !== false) {
        $Text = preg_replace_callback("/\\[share(.*?)\\](.*?)\\[\\/share\\]/ism", 'bb_ShareAttributes', $Text);
    }
    if ($tryoembed) {
        if (strpos($Text, '[/url]') !== false) {
            $Text = preg_replace_callback("/[^\\^]\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", 'tryoembed', $Text);
        }
    }
    if (strpos($Text, '[/url]') !== false) {
        $Text = preg_replace("/\\#\\^\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<span class="bookmark-identifier">#^</span><a class="bookmark" href="$1" target="_blank" >$1</a>', $Text);
        $Text = preg_replace("/\\#\\^\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<span class="bookmark-identifier">#^</span><a class="bookmark" href="$1" target="_blank" >$2</a>', $Text);
        $Text = preg_replace("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<a href="$1" target="_blank" >$1</a>', $Text);
        $Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<a href="$1" target="_blank" >$2</a>', $Text);
    }
    if (strpos($Text, '[/zrl]') !== false) {
        $Text = preg_replace("/\\#\\^\\[zrl\\]([{$URLSearchString}]*)\\[\\/zrl\\]/ism", '<span class="bookmark-identifier">#^</span><a class="zrl bookmark" href="$1" target="_blank" >$1</a>', $Text);
        $Text = preg_replace("/\\#\\^\\[zrl\\=([{$URLSearchString}]*)\\](.*?)\\[\\/zrl\\]/ism", '<span class="bookmark-identifier">#^</span><a class="zrl bookmark" href="$1" target="_blank" >$2</a>', $Text);
        $Text = preg_replace("/\\[zrl\\]([{$URLSearchString}]*)\\[\\/zrl\\]/ism", '<a class="zrl" href="$1" target="_blank" >$1</a>', $Text);
        $Text = preg_replace("/\\[zrl\\=([{$URLSearchString}]*)\\](.*?)\\[\\/zrl\\]/ism", '<a class="zrl" href="$1" target="_blank" >$2</a>', $Text);
    }
    // Remove bookmarks from UNO
    if (UNO) {
        $Text = str_replace('<span class="bookmark-identifier">#^</span>', '', $Text);
    }
    // Perform MAIL Search
    if (strpos($Text, '[/mail]') !== false) {
        $Text = preg_replace("/\\[mail\\]([{$MAILSearchString}]*)\\[\\/mail\\]/", '<a href="mailto:$1" target="_blank" >$1</a>', $Text);
        $Text = preg_replace("/\\[mail\\=([{$MAILSearchString}]*)\\](.*?)\\[\\/mail\\]/", '<a href="mailto:$1" target="_blank" >$2</a>', $Text);
    }
    // leave open the posibility of [map=something]
    // this is replaced in prepare_body() which has knowledge of the item location
    if (strpos($Text, '[/map]') !== false) {
        $Text = preg_replace_callback("/\\[map\\](.*?)\\[\\/map\\]/ism", 'bb_map_location', $Text);
    }
    if (strpos($Text, '[map=') !== false) {
        $Text = preg_replace_callback("/\\[map=(.*?)\\]/ism", 'bb_map_coords', $Text);
    }
    if (strpos($Text, '[map]') !== false) {
        $Text = preg_replace("/\\[map\\]/", '<div class="map"></div>', $Text);
    }
    // Check for bold text
    if (strpos($Text, '[b]') !== false) {
        $Text = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '<strong>$1</strong>', $Text);
    }
    // Check for Italics text
    if (strpos($Text, '[i]') !== false) {
        $Text = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '<em>$1</em>', $Text);
    }
    // Check for Underline text
    if (strpos($Text, '[u]') !== false) {
        $Text = preg_replace("(\\[u\\](.*?)\\[\\/u\\])ism", '<u>$1</u>', $Text);
    }
    // Check for strike-through text
    if (strpos($Text, '[s]') !== false) {
        $Text = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '<strike>$1</strike>', $Text);
    }
    // Check for over-line text
    if (strpos($Text, '[o]') !== false) {
        $Text = preg_replace("(\\[o\\](.*?)\\[\\/o\\])ism", '<span class="overline">$1</span>', $Text);
    }
    if (strpos($Text, '[sup]') !== false) {
        $Text = preg_replace("(\\[sup\\](.*?)\\[\\/sup\\])ism", '<sup>$1</sup>', $Text);
    }
    if (strpos($Text, '[sub]') !== false) {
        $Text = preg_replace("(\\[sub\\](.*?)\\[\\/sub\\])ism", '<sub>$1</sub>', $Text);
    }
    // Check for colored text
    if (strpos($Text, '[/color]') !== false) {
        $Text = preg_replace("(\\[color=(.*?)\\](.*?)\\[\\/color\\])ism", "<span style=\"color: \$1;\">\$2</span>", $Text);
    }
    // Check for sized text
    // [size=50] --> font-size: 50px (with the unit).
    if (strpos($Text, '[/size]') !== false) {
        $Text = preg_replace("(\\[size=(\\d*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1px;\">\$2</span>", $Text);
        $Text = preg_replace("(\\[size=(.*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1;\">\$2</span>", $Text);
    }
    // Check for h1
    if (strpos($Text, '[h1]') !== false) {
        $Text = preg_replace("(\\[h1\\](.*?)\\[\\/h1\\])ism", '<h1>$1</h1>', $Text);
    }
    // Check for h2
    if (strpos($Text, '[h2]') !== false) {
        $Text = preg_replace("(\\[h2\\](.*?)\\[\\/h2\\])ism", '<h2>$1</h2>', $Text);
    }
    // Check for h3
    if (strpos($Text, '[h3]') !== false) {
        $Text = preg_replace("(\\[h3\\](.*?)\\[\\/h3\\])ism", '<h3>$1</h3>', $Text);
    }
    // Check for h4
    if (strpos($Text, '[h4]') !== false) {
        $Text = preg_replace("(\\[h4\\](.*?)\\[\\/h4\\])ism", '<h4>$1</h4>', $Text);
    }
    // Check for h5
    if (strpos($Text, '[h5]') !== false) {
        $Text = preg_replace("(\\[h5\\](.*?)\\[\\/h5\\])ism", '<h5>$1</h5>', $Text);
    }
    // Check for h6
    if (strpos($Text, '[h6]') !== false) {
        $Text = preg_replace("(\\[h6\\](.*?)\\[\\/h6\\])ism", '<h6>$1</h6>', $Text);
    }
    // Check for table of content without params
    if (strpos($Text, '[toc]') !== false) {
        $Text = preg_replace("/\\[toc\\]/ism", '<ul id="toc"></ul>', $Text);
    }
    // Check for table of content with params
    if (strpos($Text, '[toc') !== false) {
        $Text = preg_replace("/\\[toc([^\\]]+?)\\]/ism", '<ul$1></ul>', $Text);
    }
    // Check for centered text
    if (strpos($Text, '[/center]') !== false) {
        $Text = preg_replace("(\\[center\\](.*?)\\[\\/center\\])ism", "<div style=\"text-align:center;\">\$1</div>", $Text);
    }
    // Check for footer
    if (strpos($Text, '[/footer]') !== false) {
        $Text = preg_replace("(\\[footer\\](.*?)\\[\\/footer\\])ism", "<div class=\"wall-item-footer\">\$1</div>", $Text);
    }
    // Check for list text
    $Text = str_replace("[*]", "<li>", $Text);
    // handle nested lists
    $endlessloop = 0;
    while ((strpos($Text, "[/list]") !== false && strpos($Text, "[list") !== false || strpos($Text, "[/ol]") !== false && strpos($Text, "[ol]") !== false || strpos($Text, "[/ul]") !== false && strpos($Text, "[ul]") !== false || strpos($Text, "[/dl]") !== false && strpos($Text, "[dl") !== false || strpos($Text, "[/li]") !== false && strpos($Text, "[li]") !== false) && ++$endlessloop < 20) {
        $Text = preg_replace("/\\[list\\](.*?)\\[\\/list\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=\\](.*?)\\[\\/list\\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=1\\](.*?)\\[\\/list\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)i)\\](.*?)\\[\\/list\\]/ism", '<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)I)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)a)\\](.*?)\\[\\/list\\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)A)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>', $Text);
        $Text = preg_replace("/\\[ul\\](.*?)\\[\\/ul\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
        $Text = preg_replace("/\\[ol\\](.*?)\\[\\/ol\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
        $Text = preg_replace("/\\[li\\](.*?)\\[\\/li\\]/ism", '<li>$1</li>', $Text);
        // [dl] tags have an optional [dl terms="bi"] form where bold/italic/underline/mono/large
        // etc. style may be specified for the "terms" in the definition list. The quotation marks
        // are also optional. The regex looks intimidating, but breaks down as:
        //   "[dl" <optional-whitespace> <optional-termStyles> "]" <matchGroup2> "[/dl]"
        // where optional-termStyles are: "terms=" <optional-quote> <matchGroup1> <optional-quote>
        $Text = preg_replace_callback('/\\[dl[[:space:]]*(?:terms=(?:&quot;|")?([a-zA-Z]+)(?:&quot;|")?)?\\](.*?)\\[\\/dl\\]/ism', 'bb_definitionList', $Text);
    }
    if (strpos($Text, '[th]') !== false) {
        $Text = preg_replace("/\\[th\\](.*?)\\[\\/th\\]/sm", '<th>$1</th>', $Text);
    }
    if (strpos($Text, '[td]') !== false) {
        $Text = preg_replace("/\\[td\\](.*?)\\[\\/td\\]/sm", '<td>$1</td>', $Text);
    }
    if (strpos($Text, '[tr]') !== false) {
        $Text = preg_replace("/\\[tr\\](.*?)\\[\\/tr\\]/sm", '<tr>$1</tr>', $Text);
    }
    if (strpos($Text, '[/table]') !== false) {
        $Text = preg_replace("/\\[table\\](.*?)\\[\\/table\\]/sm", '<table>$1</table>', $Text);
        $Text = preg_replace("/\\[table border=1\\](.*?)\\[\\/table\\]/sm", '<table border="1" >$1</table>', $Text);
        $Text = preg_replace("/\\[table border=0\\](.*?)\\[\\/table\\]/sm", '<table border="0" >$1</table>', $Text);
    }
    $Text = str_replace('</tr><br /><tr>', "</tr>\n<tr>", $Text);
    $Text = str_replace('[hr]', '<hr />', $Text);
    // This is actually executed in prepare_body()
    $Text = str_replace('[nosmile]', '', $Text);
    // Check for font change text
    if (strpos($Text, '[/font]') !== false) {
        $Text = preg_replace("/\\[font=(.*?)\\](.*?)\\[\\/font\\]/sm", "<span style=\"font-family: \$1;\">\$2</span>", $Text);
    }
    // Check for [code] text
    if (strpos($Text, '[code]') !== false) {
        $Text = preg_replace_callback("/\\[code\\](.*?)\\[\\/code\\]/ism", 'bb_code', $Text);
    }
    // Check for [spoiler] text
    $endlessloop = 0;
    while (strpos($Text, "[/spoiler]") !== false and strpos($Text, "[spoiler]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace_callback("/\\[spoiler\\](.*?)\\[\\/spoiler\\]/ism", 'bb_spoilertag', $Text);
    }
    // Check for [spoiler=Author] text
    $endlessloop = 0;
    while (strpos($Text, "[/spoiler]") !== false and strpos($Text, "[spoiler=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace_callback("/\\[spoiler=(.*?)\\](.*?)\\[\\/spoiler\\]/ism", 'bb_spoilertag', $Text);
    }
    // Check for [open] text
    $endlessloop = 0;
    while (strpos($Text, "[/open]") !== false and strpos($Text, "[open]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace_callback("/\\[open\\](.*?)\\[\\/open\\]/ism", 'bb_opentag', $Text);
    }
    // Check for [open=Title] text
    $endlessloop = 0;
    while (strpos($Text, "[/open]") !== false and strpos($Text, "[open=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace_callback("/\\[open=(.*?)\\](.*?)\\[\\/open\\]/ism", 'bb_opentag', $Text);
    }
    // Declare the format for [quote] layout
    $QuoteLayout = '<blockquote>$1</blockquote>';
    // Check for [quote] text
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/quote]") !== false and strpos($Text, "[quote]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[quote\\](.*?)\\[\\/quote\\]/ism", "{$QuoteLayout}", $Text);
    }
    // Check for [quote=Author] text
    $t_wrote = t('$1 wrote:');
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/quote]") !== false and strpos($Text, "[quote=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[quote=[\"\\']*(.*?)[\"\\']*\\](.*?)\\[\\/quote\\]/ism", "<span class=" . '"bb-quote"' . ">" . $t_wrote . "</span><blockquote>\$2</blockquote>", $Text);
    }
    // Images
    // [img]pathtoimage[/img]
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img\\](.*?)\\[\\/img\\]/ism", '<img style="max-width=100%;" src="$1" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" style="max-width=100%;" src="$1" alt="' . t('Image/photo') . '" />', $Text);
    }
    // [img float={left, right}]pathtoimage[/img]
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img float=left\\](.*?)\\[\\/img\\]/ism", '<img style="max-width=100%;" src="$1" style="float: left;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img float=right\\](.*?)\\[\\/img\\]/ism", '<img style="max-width=100%;" src="$1" style="float: right;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg float=left\\](.*?)\\[\\/zmg\\]/ism", '<img style="max-width=100%;" class="zrl" src="$1" style="float: left;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg float=right\\](.*?)\\[\\/zmg\\]/ism", '<img style="max-width=100%;" class="zrl" src="$1" style="float: right;" alt="' . t('Image/photo') . '" />', $Text);
    }
    // [img=widthxheight]pathtoimage[/img]
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="width: 100%; max-width: $1px;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" src="$3" style="width: 100%; max-width: $1px;" alt="' . t('Image/photo') . '" />', $Text);
    }
    // [img=widthxheight float={left, right}]pathtoimage[/img]
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*) float=left\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="width: 100%; max-width: $1px; float: left;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*) float=right\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="width: 100%; max-width: $1px; float: right;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg\\=([0-9]*)x([0-9]*) float=left\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" src="$3" style="width: 100%; max-width: $1px; float: left;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg\\=([0-9]*)x([0-9]*) float=right\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" src="$3" style="width: 100%; max-width: $1px; float: right;" alt="' . t('Image/photo') . '" />', $Text);
    }
    // style (sanitized)
    if (strpos($Text, '[/style]') !== false) {
        $Text = preg_replace_callback("(\\[style=(.*?)\\](.*?)\\[\\/style\\])ism", "bb_sanitize_style", $Text);
    }
    // crypt
    if (strpos($Text, '[/crypt]') !== false) {
        $x = random_string();
        $Text = preg_replace("/\\[crypt\\](.*?)\\[\\/crypt\\]/ism", '<br /><div id="' . $x . '"><img src="' . z_root() . '/images/lock_icon.gif" onclick="red_decrypt(\'rot13\',\'\',\'$1\',\'#' . $x . '\');" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br /></div>', $Text);
        $Text = preg_replace_callback("/\\[crypt (.*?)\\](.*?)\\[\\/crypt\\]/ism", 'bb_parse_crypt', $Text);
    }
    if (strpos($Text, '[/app]') !== false) {
        $Text = preg_replace_callback("/\\[app\\](.*?)\\[\\/app\\]/ism", 'bb_parse_app', $Text);
    }
    if (strpos($Text, '[/element]') !== false) {
        $Text = preg_replace_callback("/\\[element\\](.*?)\\[\\/element\\]/ism", 'bb_parse_element', $Text);
    }
    // html5 video and audio
    if (strpos($Text, '[/video]') !== false) {
        $Text = preg_replace_callback("/\\[video\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4|mpeg|mpg))\\[\\/video\\]/ism", 'tryzrlvideo', $Text);
    }
    if (strpos($Text, '[/audio]') !== false) {
        $Text = preg_replace_callback("/\\[audio\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4|mp3|opus))\\[\\/audio\\]/ism", 'tryzrlaudio', $Text);
    }
    if (strpos($Text, '[/zvideo]') !== false) {
        $Text = preg_replace_callback("/\\[zvideo\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4|mpeg|mpg))\\[\\/zvideo\\]/ism", 'tryzrlvideo', $Text);
    }
    if (strpos($Text, '[/zaudio]') !== false) {
        $Text = preg_replace_callback("/\\[zaudio\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4|mp3|opus))\\[\\/zaudio\\]/ism", 'tryzrlaudio', $Text);
    }
    // Try to Oembed
    if ($tryoembed) {
        if (strpos($Text, '[/video]') !== false) {
            $Text = preg_replace_callback("/\\[video\\](.*?)\\[\\/video\\]/ism", 'tryoembed', $Text);
        }
        if (strpos($Text, '[/audio]') !== false) {
            $Text = preg_replace_callback("/\\[audio\\](.*?)\\[\\/audio\\]/ism", 'tryoembed', $Text);
        }
        if (strpos($Text, '[/zvideo]') !== false) {
            $Text = preg_replace_callback("/\\[zvideo\\](.*?)\\[\\/zvideo\\]/ism", 'tryoembed', $Text);
        }
        if (strpos($Text, '[/zaudio]') !== false) {
            $Text = preg_replace_callback("/\\[zaudio\\](.*?)\\[\\/zaudio\\]/ism", 'tryoembed', $Text);
        }
    }
    // if video couldn't be embedded, link to it instead.
    if (strpos($Text, '[/video]') !== false) {
        $Text = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/", '<a href="$1" target="_blank" >$1</a>', $Text);
    }
    if (strpos($Text, '[/audio]') !== false) {
        $Text = preg_replace("/\\[audio\\](.*?)\\[\\/audio\\]/", '<a href="$1" target="_blank" >$1</a>', $Text);
    }
    if (strpos($Text, '[/zvideo]') !== false) {
        $Text = preg_replace("/\\[zvideo\\](.*?)\\[\\/zvideo\\]/", '<a class="zid" href="$1" target="_blank" >$1</a>', $Text);
    }
    if (strpos($Text, '[/zaudio]') !== false) {
        $Text = preg_replace("/\\[zaudio\\](.*?)\\[\\/zaudio\\]/", '<a class="zid" href="$1" target="_blank" >$1</a>', $Text);
    }
    if ($tryoembed) {
        if (strpos($Text, '[/iframe]') !== false) {
            $Text = preg_replace_callback("/\\[iframe\\](.*?)\\[\\/iframe\\]/ism", 'bb_iframe', $Text);
        }
    } else {
        if (strpos($Text, '[/iframe]') !== false) {
            $Text = preg_replace("/\\[iframe\\](.*?)\\[\\/iframe\\]/ism", '<a href="$1" target="_blank" >$1</a>', $Text);
        }
    }
    // oembed tag
    $Text = oembed_bbcode2html($Text);
    // Avoid triple linefeeds through oembed
    $Text = str_replace("<br style='clear:left'></span><br /><br />", "<br style='clear:left'></span><br />", $Text);
    // If we found an event earlier, strip out all the event code and replace with a reformatted version.
    // Replace the event-start section with the entire formatted event. The other bbcode is stripped.
    // Summary (e.g. title) is required, earlier revisions only required description (in addition to
    // start which is always required). Allow desc with a missing summary for compatibility.
    if ((x($ev, 'desc') || x($ev, 'summary')) && x($ev, 'start')) {
        $sub = format_event_html($ev);
        $sub = str_replace('$', "", $sub);
        $Text = preg_replace("/\\[event\\-start\\](.*?)\\[\\/event\\-start\\]/ism", $sub, $Text);
        $Text = preg_replace("/\\[event\\-summary\\](.*?)\\[\\/event\\-summary\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-description\\](.*?)\\[\\/event\\-description\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-finish\\](.*?)\\[\\/event\\-finish\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-id\\](.*?)\\[\\/event\\-id\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-location\\](.*?)\\[\\/event\\-location\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-adjust\\](.*?)\\[\\/event\\-adjust\\]/ism", '', $Text);
        $Text = str_replace("", '$', $Text);
    }
    // Unhide all [noparse] contained bbtags unspacefying them
    // and triming the [noparse] tag.
    if (strpos($Text, '[noparse]') !== false) {
        $Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_unspacefy_and_trim', $Text);
    }
    if (strpos($Text, '[nobb]') !== false) {
        $Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_unspacefy_and_trim', $Text);
    }
    if (strpos($Text, '[pre]') !== false) {
        $Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_unspacefy_and_trim', $Text);
    }
    $Text = preg_replace('/\\[\\&amp\\;([#a-z0-9]+)\\;\\]/', '&$1;', $Text);
    // fix any escaped ampersands that may have been converted into links
    if (strpos($Text, '&amp;') !== false) {
        $Text = preg_replace("/\\<(.*?)(src|href)=(.*?)\\&amp\\;(.*?)\\>/ism", '<$1$2=$3&$4>', $Text);
    }
    // This is subtle - it's an XSS filter. It only accepts links with a protocol scheme and where
    // the scheme begins with z (zhttp), h (http(s)), f (ftp), m (mailto), and named anchors.
    $Text = preg_replace("/\\<(.*?)(src|href)=\"[^zhfm#](.*?)\\>/ism", '<$1$2="">', $Text);
    $Text = bb_replace_images($Text, $saved_images);
    call_hooks('bbcode', $Text);
    return $Text;
}
Esempio n. 6
0
function bbcode($Text, $preserve_nl = false)
{
    // Extract a single private image which uses data url's since preg has issues with
    // large data sizes. Stash it away while we do bbcode conversion, and then put it back
    // in after we've done all the regex matching. We cannot use any preg functions to do this.
    $saved_image = '';
    $img_start = strpos($Text, '[img]data:');
    $img_end = strpos($Text, '[/img]');
    if ($img_start !== false && $img_end !== false && $img_end > $img_start) {
        $start_fragment = substr($Text, 0, $img_start);
        $img_start += strlen('[img]');
        $saved_image = substr($Text, $img_start, $img_end - $img_start);
        $end_fragment = substr($Text, $img_end + strlen('[/img]'));
        //		logger('saved_image: ' . $saved_image,LOGGER_DEBUG);
        $Text = $start_fragment . '[$#saved_image#$]' . $end_fragment;
    }
    // If we find any event code, turn it into an event.
    // After we're finished processing the bbcode we'll
    // replace all of the event code with a reformatted version.
    $ev = bbtoevent($Text);
    // Replace any html brackets with HTML Entities to prevent executing HTML or script
    // Don't use strip_tags here because it breaks [url] search by replacing & with amp
    $Text = str_replace("<", "&lt;", $Text);
    $Text = str_replace(">", "&gt;", $Text);
    // Convert new line chars to html <br /> tags
    $Text = nl2br($Text);
    if ($preserve_nl) {
        $Text = str_replace(array("\n", "\r"), array('', ''), $Text);
    }
    // Set up the parameters for a URL search string
    $URLSearchString = "^\\[\\]";
    // Set up the parameters for a MAIL search string
    $MAILSearchString = $URLSearchString;
    // Perform URL Search
    $Text = preg_replace("/([^\\]\\=]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
    $Text = preg_replace_callback("/\\[bookmark\\=([^\\]]*)\\].*?\\[\\/bookmark\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $Text);
    $Text = preg_replace_callback("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<a href="$1" target="external-link">$1</a>', $Text);
    $Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<a href="$1" target="external-link">$2</a>', $Text);
    //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
    // Perform MAIL Search
    $Text = preg_replace("/\\[mail\\]([{$MAILSearchString}]*)\\[\\/mail\\]/", '<a href="mailto:$1">$1</a>', $Text);
    $Text = preg_replace("/\\[mail\\=([{$MAILSearchString}]*)\\](.*?)\\[\\/mail\\]/", '<a href="mailto:$1">$2</a>', $Text);
    // Check for bold text
    $Text = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '<strong>$1</strong>', $Text);
    // Check for Italics text
    $Text = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '<em>$1</em>', $Text);
    // Check for Underline text
    $Text = preg_replace("(\\[u\\](.*?)\\[\\/u\\])ism", '<u>$1</u>', $Text);
    // Check for strike-through text
    $Text = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '<strike>$1</strike>', $Text);
    // Check for over-line text
    $Text = preg_replace("(\\[o\\](.*?)\\[\\/o\\])ism", '<span class="overline">$1</span>', $Text);
    // Check for colored text
    $Text = preg_replace("(\\[color=(.*?)\\](.*?)\\[\\/color\\])ism", "<span style=\"color: \$1;\">\$2</span>", $Text);
    // Check for sized text
    $Text = preg_replace("(\\[size=(.*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1;\">\$2</span>", $Text);
    // Check for list text
    if (stristr($Text, '[/list]')) {
        $Text = str_replace("[*]", "<li>", $Text);
    }
    if (stristr($Text, '[/list]')) {
        $Text = str_replace("[*]", "<li>", $Text);
    }
    $Text = preg_replace("/\\[list\\](.*?)\\[\\/list\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
    $Text = preg_replace("/\\[list=\\](.*?)\\[\\/list\\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $Text);
    $Text = preg_replace("/\\[list=1\\](.*?)\\[\\/list\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
    $Text = preg_replace("/\\[list=i\\](.*?)\\[\\/list\\]/sm", '<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>', $Text);
    $Text = preg_replace("/\\[list=I\\](.*?)\\[\\/list\\]/sm", '<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>', $Text);
    $Text = preg_replace("/\\[list=a\\](.*?)\\[\\/list\\]/sm", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>', $Text);
    $Text = preg_replace("/\\[list=A\\](.*?)\\[\\/list\\]/sm", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>', $Text);
    $Text = preg_replace("/\\[li\\](.*?)\\[\\/li\\]/sm", '<li>$1</li>', $Text);
    $Text = preg_replace("/\\[td\\](.*?)\\[\\/td\\]/sm", '<td>$1</td>', $Text);
    $Text = preg_replace("/\\[tr\\](.*?)\\[\\/tr\\]/sm", '<tr>$1</tr>', $Text);
    $Text = preg_replace("/\\[table\\](.*?)\\[\\/table\\]/sm", '<table>$1</table>', $Text);
    $Text = preg_replace("/\\[table border=1\\](.*?)\\[\\/table\\]/sm", '<table border="1" >$1</table>', $Text);
    $Text = preg_replace("/\\[table border=0\\](.*?)\\[\\/table\\]/sm", '<table border="0" >$1</table>', $Text);
    // Check for font change text
    $Text = preg_replace("/\\[font=(.*?)\\](.*?)\\[\\/font\\]/sm", "<span style=\"font-family: \$1;\">\$2</span>", $Text);
    // Declare the format for [code] layout
    $Text = preg_replace_callback("/\\[code\\](.*?)\\[\\/code\\]/ism", 'stripcode_br_cb', $Text);
    $CodeLayout = '<code>$1</code>';
    // Check for [code] text
    $Text = preg_replace("/\\[code\\](.*?)\\[\\/code\\]/ism", "{$CodeLayout}", $Text);
    // Declare the format for [quote] layout
    $QuoteLayout = '<blockquote>$1</blockquote>';
    // Check for [quote] text
    $Text = preg_replace("/\\[quote\\](.*?)\\[\\/quote\\]/ism", "{$QuoteLayout}", $Text);
    // [img=widthxheight]image source[/img]
    $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="height: $2px; width: $1px;" >', $Text);
    // Images
    // [img]pathtoimage[/img]
    $Text = preg_replace("/\\[img\\](.*?)\\[\\/img\\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
    // Try to Oembed
    $Text = preg_replace_callback("/\\[video\\](.*?)\\[\\/video\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace_callback("/\\[audio\\](.*?)\\[\\/audio\\]/ism", 'tryoembed', $Text);
    // html5 video and audio
    $Text = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/ism", '<video src="$1" controls="controls" width="425" height="350"><a href="$1">$1</a></video>', $Text);
    $Text = preg_replace("/\\[audio\\](.*?)\\[\\/audio\\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $Text);
    $Text = preg_replace("/\\[iframe\\](.*?)\\[\\/iframe\\]/ism", '<iframe src="$1" width="425" height="350"><a href="$1">$1</a></iframe>', $Text);
    /*if (get_pconfig(local_user(), 'oembed', 'use_for_youtube' )==1){
    		// use oembed for youtube links
    		$Text = preg_replace("/\[youtube\]/",'[embed]',$Text); 
    		$Text = preg_replace("/\[\/youtube\]/",'[/embed]',$Text); 
    	} else {*/
    // Youtube extensions
    $Text = preg_replace_callback("/\\[youtube\\](https?:\\/\\/www.youtube.com\\/watch\\?v\\=.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace_callback("/\\[youtube\\](https?:\\/\\/youtu.be\\/.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/watch\\?v\\=(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/embed\\/(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/youtu.be\\/(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    $Text = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '<iframe width="425" height="350" src="http://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
    //}
    $Text = preg_replace_callback("/\\[vimeo\\](https?:\\/\\/player.vimeo.com\\/video\\/[0-9]+).*?\\[\\/vimeo\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace_callback("/\\[vimeo\\](https?:\\/\\/vimeo.com\\/[0-9]+).*?\\[\\/vimeo\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace("/\\[vimeo\\]https?:\\/\\/player.vimeo.com\\/video\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[vimeo]$1[/vimeo]', $Text);
    $Text = preg_replace("/\\[vimeo\\]https?:\\/\\/vimeo.com\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[vimeo]$1[/vimeo]', $Text);
    $Text = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '<iframe width="425" height="350" src="http://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $Text);
    //	$Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
    // oembed tag
    $Text = oembed_bbcode2html($Text);
    // If we found an event earlier, strip out all the event code and replace with a reformatted version.
    if (x($ev, 'desc') && x($ev, 'start')) {
        $sub = format_event_html($ev);
        $Text = preg_replace("/\\[event\\-description\\](.*?)\\[\\/event\\-description\\]/ism", $sub, $Text);
        $Text = preg_replace("/\\[event\\-start\\](.*?)\\[\\/event\\-start\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-finish\\](.*?)\\[\\/event\\-finish\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-location\\](.*?)\\[\\/event\\-location\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-adjust\\](.*?)\\[\\/event\\-adjust\\]/ism", '', $Text);
    }
    // fix any escaped ampersands that may have been converted into links
    $Text = preg_replace("/\\<(.*?)(src|href)=(.*?)\\&amp\\;(.*?)\\>/ism", '<$1$2=$3&$4>', $Text);
    if (strlen($saved_image)) {
        $Text = str_replace('[$#saved_image#$]', '<img src="' . $saved_image . '" alt="' . t('Image/photo') . '" />', $Text);
    }
    call_hooks('bbcode', $Text);
    return $Text;
}
Esempio n. 7
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;
    }
}
Esempio n. 8
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;
    }
}
Esempio n. 9
0
File: bbcode.php Progetto: Mauru/red
function bbcode($Text, $preserve_nl = false, $tryoembed = true)
{
    $a = get_app();
    // Move all spaces out of the tags
    // ....Uhm why?
    // This is basically doing a trim() on the stuff in between tags, but it messes up
    // carefully crafted bbcode and especially other pre-formatted code.
    // Commenting out until we come up with a use case where it's needed. Then let's try and
    // special case rather than a heavy-handed approach like this.
    //	$Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
    //	$Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text);
    // Hide all [noparse] contained bbtags by spacefying them
    if (strpos($Text, '[noparse]') !== false) {
        $Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_spacefy', $Text);
    }
    if (strpos($Text, '[nobb]') !== false) {
        $Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_spacefy', $Text);
    }
    if (strpos($Text, '[pre]') !== false) {
        $Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_spacefy', $Text);
    }
    //  Not yet implemented - thinking this should display a map or perhaps be a map directive
    //	if (strpos($Text,'[location]') !== false) {
    //		$Text = preg_replace_callback("/\[location\](.*?)\[\/location\]/ism", 'bb_location',$Text);
    //	}
    // If we find any event code, turn it into an event.
    // After we're finished processing the bbcode we'll
    // replace all of the event code with a reformatted version.
    $ev = bbtoevent($Text);
    // process [observer] tags before we do anything else because we might
    // be stripping away stuff that then doesn't need to be worked on anymore
    $observer = $a->get_observer();
    if (strpos($Text, '[/observer]') !== false || strpos($Text, '[/rpost]') !== false) {
        if ($observer) {
            $Text = preg_replace("/\\[observer\\=1\\](.*?)\\[\\/observer\\]/ism", '$1', $Text);
            $Text = preg_replace("/\\[observer\\=0\\].*?\\[\\/observer\\]/ism", '', $Text);
            $Text = preg_replace_callback("/\\[rpost(=(.*?))?\\](.*?)\\[\\/rpost\\]/ism", 'rpost_callback', $Text);
        } else {
            $Text = preg_replace("/\\[observer\\=1\\].*?\\[\\/observer\\]/ism", '', $Text);
            $Text = preg_replace("/\\[observer\\=0\\](.*?)\\[\\/observer\\]/ism", '$1', $Text);
            $Text = preg_replace("/\\[rpost(=.*?)?\\](.*?)\\[\\/rpost\\]/ism", '', $Text);
        }
    }
    $channel = $a->get_channel();
    if (strpos($Text, '[/channel]') !== false) {
        if ($channel) {
            $Text = preg_replace("/\\[channel\\=1\\](.*?)\\[\\/channel\\]/ism", '$1', $Text);
            $Text = preg_replace("/\\[channel\\=0\\].*?\\[\\/channel\\]/ism", '', $Text);
        } else {
            $Text = preg_replace("/\\[channel\\=1\\].*?\\[\\/channel\\]/ism", '', $Text);
            $Text = preg_replace("/\\[channel\\=0\\](.*?)\\[\\/channel\\]/ism", '$1', $Text);
        }
    }
    $Text = str_replace(array('[baseurl]', '[sitename]'), array(z_root(), get_config('system', 'sitename')), $Text);
    // Replace any html brackets with HTML Entities to prevent executing HTML or script
    // Don't use strip_tags here because it breaks [url] search by replacing & with amp
    $Text = str_replace("<", "&lt;", $Text);
    $Text = str_replace(">", "&gt;", $Text);
    // Convert new line chars to html <br /> tags
    // nlbr seems to be hopelessly messed up
    //	$Text = nl2br($Text);
    // We'll emulate it.
    $Text = str_replace("\r\n", "\n", $Text);
    $Text = str_replace(array("\r", "\n"), array('<br />', '<br />'), $Text);
    if ($preserve_nl) {
        $Text = str_replace(array("\n", "\r"), array('', ''), $Text);
    }
    $Text = str_replace(array("\t", "  "), array("&nbsp;&nbsp;&nbsp;&nbsp;", "&nbsp;&nbsp;"), $Text);
    // Set up the parameters for a URL search string
    $URLSearchString = "^\\[\\]";
    // Set up the parameters for a MAIL search string
    $MAILSearchString = $URLSearchString;
    // replace [observer.baseurl]
    if ($observer) {
        $obsBaseURL = $observer['xchan_connurl'];
        $obsBaseURL = preg_replace("/\\/poco\\/.*\$/", '', $obsBaseURL);
        $Text = str_replace('[observer.baseurl]', $obsBaseURL, $Text);
        $Text = str_replace('[observer.url]', $observer['xchan_url'], $Text);
        $Text = str_replace('[observer.name]', $observer['xchan_name'], $Text);
        $Text = str_replace('[observer.address]', $observer['xchan_addr'], $Text);
        $Text = str_replace('[observer.webname]', substr($observer['xchan_addr'], 0, strpos($observer['xchan_addr'], '@')), $Text);
        $Text = str_replace('[observer.photo]', '[zmg]' . $observer['xchan_photo_l'] . '[/zmg]', $Text);
    } else {
        $Text = str_replace('[observer.baseurl]', '', $Text);
        $Text = str_replace('[observer.url]', '', $Text);
        $Text = str_replace('[observer.name]', '', $Text);
        $Text = str_replace('[observer.address]', '', $Text);
        $Text = str_replace('[observer.webname]', '', $Text);
        $Text = str_replace('[observer.photo]', '', $Text);
    }
    // Perform URL Search
    $urlchars = '[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\@\\_\\~\\#\\%\\$\\!\\+\\,]';
    if (strpos($Text, 'http') !== false) {
        $Text = preg_replace("/([^\\]\\='" . '"' . "]|^)(https?\\:\\/\\/{$urlchars}+)/ism", '$1<a href="$2" >$2</a>', $Text);
    }
    if (strpos($Text, '[/qr]') !== false) {
        $Text = preg_replace_callback("/\\[qr\\](.*?)\\[\\/qr\\]/ism", "bb_qr", $Text);
    }
    if (strpos($Text, '[/share]') !== false) {
        $Text = preg_replace_callback("/\\[share(.*?)\\](.*?)\\[\\/share\\]/ism", "bb_ShareAttributes", $Text);
    }
    if ($tryoembed) {
        if (strpos($Text, '[/url]') !== false) {
            $Text = preg_replace_callback("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", 'tryoembed', $Text);
        }
    }
    if (strpos($Text, '[/url]') !== false) {
        $Text = preg_replace("/\\#\\^\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<span class="bookmark-identifier">#^</span><a class="bookmark" href="$1" >$1</a>', $Text);
        $Text = preg_replace("/\\#\\^\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<span class="bookmark-identifier">#^</span><a class="bookmark" href="$1" >$2</a>', $Text);
        $Text = preg_replace("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<a href="$1" >$1</a>', $Text);
        $Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<a href="$1" >$2</a>', $Text);
    }
    if (strpos($Text, '[/zrl]') !== false) {
        $Text = preg_replace("/\\#\\^\\[zrl\\]([{$URLSearchString}]*)\\[\\/zrl\\]/ism", '<span class="bookmark-identifier">#^</span><a class="zrl bookmark" href="$1" >$1</a>', $Text);
        $Text = preg_replace("/\\#\\^\\[zrl\\=([{$URLSearchString}]*)\\](.*?)\\[\\/zrl\\]/ism", '<span class="bookmark-identifier">#^</span><a class="zrl bookmark" href="$1" >$2</a>', $Text);
        $Text = preg_replace("/\\[zrl\\]([{$URLSearchString}]*)\\[\\/zrl\\]/ism", '<a class="zrl" href="$1" >$1</a>', $Text);
        $Text = preg_replace("/\\[zrl\\=([{$URLSearchString}]*)\\](.*?)\\[\\/zrl\\]/ism", '<a class="zrl" href="$1" >$2</a>', $Text);
    }
    // Perform MAIL Search
    if (strpos($Text, '[/mail]') !== false) {
        $Text = preg_replace("/\\[mail\\]([{$MAILSearchString}]*)\\[\\/mail\\]/", '<a href="mailto:$1">$1</a>', $Text);
        $Text = preg_replace("/\\[mail\\=([{$MAILSearchString}]*)\\](.*?)\\[\\/mail\\]/", '<a href="mailto:$1">$2</a>', $Text);
    }
    // Check for bold text
    if (strpos($Text, '[b]') !== false) {
        $Text = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '<strong>$1</strong>', $Text);
    }
    // Check for Italics text
    if (strpos($Text, '[i]') !== false) {
        $Text = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '<em>$1</em>', $Text);
    }
    // Check for Underline text
    if (strpos($Text, '[u]') !== false) {
        $Text = preg_replace("(\\[u\\](.*?)\\[\\/u\\])ism", '<u>$1</u>', $Text);
    }
    // Check for strike-through text
    if (strpos($Text, '[s]') !== false) {
        $Text = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '<strike>$1</strike>', $Text);
    }
    // Check for over-line text
    if (strpos($Text, '[o]') !== false) {
        $Text = preg_replace("(\\[o\\](.*?)\\[\\/o\\])ism", '<span class="overline">$1</span>', $Text);
    }
    if (strpos($Text, '[sup]') !== false) {
        $Text = preg_replace("(\\[sup\\](.*?)\\[\\/sup\\])ism", '<sup>$1</sup>', $Text);
    }
    if (strpos($Text, '[sub]') !== false) {
        $Text = preg_replace("(\\[sub\\](.*?)\\[\\/sub\\])ism", '<sub>$1</sub>', $Text);
    }
    // Check for colored text
    if (strpos($Text, '[/color]') !== false) {
        $Text = preg_replace("(\\[color=(.*?)\\](.*?)\\[\\/color\\])ism", "<span style=\"color: \$1;\">\$2</span>", $Text);
    }
    // Check for sized text
    // [size=50] --> font-size: 50px (with the unit).
    if (strpos($Text, '[/size]') !== false) {
        $Text = preg_replace("(\\[size=(\\d*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1px;\">\$2</span>", $Text);
        $Text = preg_replace("(\\[size=(.*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1;\">\$2</span>", $Text);
    }
    // Check for h1
    if (strpos($Text, '[h1]') !== false) {
        $Text = preg_replace("(\\[h1\\](.*?)\\[\\/h1\\])ism", '<h1>$1</h1>', $Text);
    }
    // Check for h2
    if (strpos($Text, '[h2]') !== false) {
        $Text = preg_replace("(\\[h2\\](.*?)\\[\\/h2\\])ism", '<h2>$1</h2>', $Text);
    }
    // Check for h3
    if (strpos($Text, '[h3]') !== false) {
        $Text = preg_replace("(\\[h3\\](.*?)\\[\\/h3\\])ism", '<h3>$1</h3>', $Text);
    }
    // Check for h4
    if (strpos($Text, '[h4]') !== false) {
        $Text = preg_replace("(\\[h4\\](.*?)\\[\\/h4\\])ism", '<h4>$1</h4>', $Text);
    }
    // Check for h5
    if (strpos($Text, '[h5]') !== false) {
        $Text = preg_replace("(\\[h5\\](.*?)\\[\\/h5\\])ism", '<h5>$1</h5>', $Text);
    }
    // Check for h6
    if (strpos($Text, '[h6]') !== false) {
        $Text = preg_replace("(\\[h6\\](.*?)\\[\\/h6\\])ism", '<h6>$1</h6>', $Text);
    }
    // Check for centered text
    if (strpos($Text, '[/center]') !== false) {
        $Text = preg_replace("(\\[center\\](.*?)\\[\\/center\\])ism", "<div style=\"text-align:center;\">\$1</div>", $Text);
    }
    // Check for list text
    $Text = str_replace("[*]", "<li>", $Text);
    // handle nested lists
    $endlessloop = 0;
    while ((strpos($Text, "[/list]") !== false && strpos($Text, "[list") !== false || strpos($Text, "[/ol]") !== false && strpos($Text, "[ol]") !== false || strpos($Text, "[/ul]") !== false && strpos($Text, "[ul]") !== false || strpos($Text, "[/li]") !== false && strpos($Text, "[li]") !== false) && ++$endlessloop < 20) {
        $Text = preg_replace("/\\[list\\](.*?)\\[\\/list\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=\\](.*?)\\[\\/list\\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=1\\](.*?)\\[\\/list\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)i)\\](.*?)\\[\\/list\\]/ism", '<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)I)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)a)\\](.*?)\\[\\/list\\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)A)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>', $Text);
        $Text = preg_replace("/\\[ul\\](.*?)\\[\\/ul\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
        $Text = preg_replace("/\\[ol\\](.*?)\\[\\/ol\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
        $Text = preg_replace("/\\[li\\](.*?)\\[\\/li\\]/ism", '<li>$1</li>', $Text);
    }
    if (strpos($Text, '[th]') !== false) {
        $Text = preg_replace("/\\[th\\](.*?)\\[\\/th\\]/sm", '<th>$1</th>', $Text);
    }
    if (strpos($Text, '[td]') !== false) {
        $Text = preg_replace("/\\[td\\](.*?)\\[\\/td\\]/sm", '<td>$1</td>', $Text);
    }
    if (strpos($Text, '[tr]') !== false) {
        $Text = preg_replace("/\\[tr\\](.*?)\\[\\/tr\\]/sm", '<tr>$1</tr>', $Text);
    }
    if (strpos($Text, '[/table]') !== false) {
        $Text = preg_replace("/\\[table\\](.*?)\\[\\/table\\]/sm", '<table>$1</table>', $Text);
        $Text = preg_replace("/\\[table border=1\\](.*?)\\[\\/table\\]/sm", '<table border="1" >$1</table>', $Text);
        $Text = preg_replace("/\\[table border=0\\](.*?)\\[\\/table\\]/sm", '<table border="0" >$1</table>', $Text);
    }
    $Text = str_replace('[hr]', '<hr />', $Text);
    // This is actually executed in prepare_body()
    $Text = str_replace('[nosmile]', '', $Text);
    // Check for font change text
    if (strpos($Text, '[/font]') !== false) {
        $Text = preg_replace("/\\[font=(.*?)\\](.*?)\\[\\/font\\]/sm", "<span style=\"font-family: \$1;\">\$2</span>", $Text);
    }
    // Declare the format for [code] layout
    $CodeLayout = '<code>$1</code>';
    // Check for [code] text
    if (strpos($Text, '[code]') !== false) {
        $Text = preg_replace("/\\[code\\](.*?)\\[\\/code\\]/ism", "{$CodeLayout}", $Text);
    }
    // Declare the format for [spoiler] layout
    $SpoilerLayout = '<blockquote class="spoiler">$1</blockquote>';
    // Check for [spoiler] text
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/spoiler]") !== false and strpos($Text, "[spoiler]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[spoiler\\](.*?)\\[\\/spoiler\\]/ism", "{$SpoilerLayout}", $Text);
    }
    // Check for [spoiler=Author] text
    $t_wrote = t('$1 wrote:');
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/spoiler]") !== false and strpos($Text, "[spoiler=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[spoiler=[\"\\']*(.*?)[\"\\']*\\](.*?)\\[\\/spoiler\\]/ism", "<br /><strong class=" . '"spoiler"' . ">" . $t_wrote . "</strong><blockquote class=" . '"spoiler"' . ">\$2</blockquote>", $Text);
    }
    // Declare the format for [quote] layout
    $QuoteLayout = '<blockquote>$1</blockquote>';
    // Check for [quote] text
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/quote]") !== false and strpos($Text, "[quote]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[quote\\](.*?)\\[\\/quote\\]/ism", "{$QuoteLayout}", $Text);
    }
    // Check for [quote=Author] text
    $t_wrote = t('$1 wrote:');
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/quote]") !== false and strpos($Text, "[quote=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[quote=[\"\\']*(.*?)[\"\\']*\\](.*?)\\[\\/quote\\]/ism", "<br /><strong class=" . '"author"' . ">" . $t_wrote . "</strong><blockquote>\$2</blockquote>", $Text);
    }
    // Images
    // [img]pathtoimage[/img]
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img\\](.*?)\\[\\/img\\]/ism", '<img style="max-width=100%;" src="$1" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" style="max-width=100%;" src="$1" alt="' . t('Image/photo') . '" />', $Text);
    }
    // [img float={left, right}]pathtoimage[/img]
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img float=left\\](.*?)\\[\\/img\\]/ism", '<img style="max-width=100%;" src="$1" style="float: left;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img float=right\\](.*?)\\[\\/img\\]/ism", '<img style="max-width=100%;" src="$1" style="float: right;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg float=left\\](.*?)\\[\\/zmg\\]/ism", '<img style="max-width=100%;" class="zrl" src="$1" style="float: left;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg float=right\\](.*?)\\[\\/zmg\\]/ism", '<img style="max-width=100%;" class="zrl" src="$1" style="float: right;" alt="' . t('Image/photo') . '" />', $Text);
    }
    // [img=widthxheight]pathtoimage[/img]
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="width: 100%; max-width: $1px;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" src="$3" style="width: 100%; max-width: $1px;" alt="' . t('Image/photo') . '" />', $Text);
    }
    // [img=widthxheight float={left, right}]pathtoimage[/img]
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*) float=left\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="width: 100%; max-width: $1px; float: left;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/img]') !== false) {
        $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*) float=right\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="width: 100%; max-width: $1px; float: right;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg\\=([0-9]*)x([0-9]*) float=left\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" src="$3" style="width: 100%; max-width: $1px; float: left;" alt="' . t('Image/photo') . '" />', $Text);
    }
    if (strpos($Text, '[/zmg]') !== false) {
        $Text = preg_replace("/\\[zmg\\=([0-9]*)x([0-9]*) float=right\\](.*?)\\[\\/zmg\\]/ism", '<img class="zrl" src="$3" style="width: 100%; max-width: $1px; float: right;" alt="' . t('Image/photo') . '" />', $Text);
    }
    // style (sanitized)
    if (strpos($Text, '[/style]') !== false) {
        $Text = preg_replace_callback("(\\[style=(.*?)\\](.*?)\\[\\/style\\])ism", "bb_sanitize_style", $Text);
    }
    // crypt
    if (strpos($Text, '[/crypt]') !== false) {
        $x = random_string();
        $Text = preg_replace("/\\[crypt\\](.*?)\\[\\/crypt\\]/ism", '<br/><div id="' . $x . '"><img src="' . $a->get_baseurl() . '/images/lock_icon.gif" onclick="red_decrypt(\'rot13\',\'\',\'$1\',\'#' . $x . '\');" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br /></div>', $Text);
        $Text = preg_replace_callback("/\\[crypt (.*?)\\](.*?)\\[\\/crypt\\]/ism", 'bb_parse_crypt', $Text);
    }
    if (strpos($Text, '[/app]') !== false) {
        $Text = preg_replace_callback("/\\[app\\](.*?)\\[\\/app\\]/ism", 'bb_parse_app', $Text);
    }
    // html5 video and audio
    if (strpos($Text, '[/video]') !== false) {
        $Text = preg_replace_callback("/\\[video\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4))\\[\\/video\\]/ism", 'tryzrlvideo', $Text);
    }
    if (strpos($Text, '[/audio]') !== false) {
        $Text = preg_replace_callback("/\\[audio\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\\[\\/audio\\]/ism", 'tryzrlaudio', $Text);
    }
    // Try to Oembed
    if ($tryoembed) {
        if (strpos($Text, '[/video]') !== false) {
            $Text = preg_replace_callback("/\\[video\\](.*?)\\[\\/video\\]/ism", 'tryoembed', $Text);
        }
        if (strpos($Text, '[/audio]') !== false) {
            $Text = preg_replace_callback("/\\[audio\\](.*?)\\[\\/audio\\]/ism", 'tryoembed', $Text);
        }
    }
    // if video couldn't be embedded, link to it instead.
    if (strpos($Text, '[/video]') !== false) {
        $Text = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/", '<a href="$1">$1</a>', $Text);
    }
    if (strpos($Text, '[/audio]') !== false) {
        $Text = preg_replace("/\\[audio\\](.*?)\\[\\/audio\\]/", '<a href="$1">$1</a>', $Text);
    }
    if ($tryoembed) {
        if (strpos($Text, '[/iframe]') !== false) {
            $Text = preg_replace_callback("/\\[iframe\\](.*?)\\[\\/iframe\\]/ism", 'bbiframe', $Text);
        }
    } else {
        if (strpos($Text, '[/iframe]') !== false) {
            $Text = preg_replace("/\\[iframe\\](.*?)\\[\\/iframe\\]/ism", '<a href="$1">$1</a>', $Text);
        }
    }
    // Youtube extensions
    if (strpos($Text, '[youtube]') !== false) {
        if ($tryoembed) {
            $Text = preg_replace_callback("/\\[youtube\\](https?:\\/\\/www.youtube.com\\/watch\\?v\\=.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
            $Text = preg_replace_callback("/\\[youtube\\](www.youtube.com\\/watch\\?v\\=.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
            $Text = preg_replace_callback("/\\[youtube\\](https?:\\/\\/youtu.be\\/.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
        }
        $Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/watch\\?v\\=(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
        $Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/embed\\/(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
        $Text = preg_replace("/\\[youtube\\]https?:\\/\\/youtu.be\\/(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
        if ($tryoembed) {
            $Text = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="http://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
        } else {
            $Text = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", "http://www.youtube.com/watch?v=\$1", $Text);
        }
    }
    if (strpos($Text, '[vimeo]') !== false) {
        if ($tryoembed) {
            $Text = preg_replace_callback("/\\[vimeo\\](https?:\\/\\/player.vimeo.com\\/video\\/[0-9]+).*?\\[\\/vimeo\\]/ism", 'tryoembed', $Text);
            $Text = preg_replace_callback("/\\[vimeo\\](https?:\\/\\/vimeo.com\\/[0-9]+).*?\\[\\/vimeo\\]/ism", 'tryoembed', $Text);
        }
        $Text = preg_replace("/\\[vimeo\\]https?:\\/\\/player.vimeo.com\\/video\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[vimeo]$1[/vimeo]', $Text);
        $Text = preg_replace("/\\[vimeo\\]https?:\\/\\/vimeo.com\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[vimeo]$1[/vimeo]', $Text);
        if ($tryoembed) {
            $Text = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="http://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $Text);
        } else {
            $Text = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", "http://vimeo.com/\$1", $Text);
        }
    }
    // oembed tag
    $Text = oembed_bbcode2html($Text);
    // Avoid triple linefeeds through oembed
    $Text = str_replace("<br style='clear:left'></span><br /><br />", "<br style='clear:left'></span><br />", $Text);
    // If we found an event earlier, strip out all the event code and replace with a reformatted version.
    // Replace the event-start section with the entire formatted event. The other bbcode is stripped.
    // Summary (e.g. title) is required, earlier revisions only required description (in addition to
    // start which is always required). Allow desc with a missing summary for compatibility.
    if ((x($ev, 'desc') || x($ev, 'summary')) && x($ev, 'start')) {
        $sub = format_event_html($ev);
        $Text = preg_replace("/\\[event\\-summary\\](.*?)\\[\\/event\\-summary\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-description\\](.*?)\\[\\/event\\-description\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-start\\](.*?)\\[\\/event\\-start\\]/ism", $sub, $Text);
        $Text = preg_replace("/\\[event\\-finish\\](.*?)\\[\\/event\\-finish\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-location\\](.*?)\\[\\/event\\-location\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-adjust\\](.*?)\\[\\/event\\-adjust\\]/ism", '', $Text);
    }
    // Unhide all [noparse] contained bbtags unspacefying them
    // and triming the [noparse] tag.
    if (strpos($Text, '[noparse]') !== false) {
        $Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_unspacefy_and_trim', $Text);
    }
    if (strpos($Text, '[nobb]') !== false) {
        $Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_unspacefy_and_trim', $Text);
    }
    if (strpos($Text, '[pre]') !== false) {
        $Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_unspacefy_and_trim', $Text);
    }
    $Text = preg_replace('/\\[\\&amp\\;([#a-z0-9]+)\\;\\]/', '&$1;', $Text);
    // fix any escaped ampersands that may have been converted into links
    $Text = preg_replace("/\\<(.*?)(src|href)=(.*?)\\&amp\\;(.*?)\\>/ism", '<$1$2=$3&$4>', $Text);
    $Text = preg_replace("/\\<(.*?)(src|href)=\"[^hfm](.*?)\\>/ism", '<$1$2="">', $Text);
    call_hooks('bbcode', $Text);
    return $Text;
}
Esempio n. 10
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;
    }
}
Esempio n. 11
0
function bbcode($Text, $preserve_nl = false)
{
    $a = get_app();
    // Hide all [noparse] contained bbtags spacefying them
    $Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_spacefy', $Text);
    $Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_spacefy', $Text);
    $Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_spacefy', $Text);
    // Extract a single private image which uses data url's since preg has issues with
    // large data sizes. Stash it away while we do bbcode conversion, and then put it back
    // in after we've done all the regex matching. We cannot use any preg functions to do this.
    $saved_image = '';
    $img_start = strpos($Text, '[img]data:');
    $img_end = strpos($Text, '[/img]');
    if ($img_start !== false && $img_end !== false && $img_end > $img_start) {
        $start_fragment = substr($Text, 0, $img_start);
        $img_start += strlen('[img]');
        $saved_image = substr($Text, $img_start, $img_end - $img_start);
        $end_fragment = substr($Text, $img_end + strlen('[/img]'));
        //		logger('saved_image: ' . $saved_image,LOGGER_DEBUG);
        $Text = $start_fragment . '[$#saved_image#$]' . $end_fragment;
    }
    // If we find any event code, turn it into an event.
    // After we're finished processing the bbcode we'll
    // replace all of the event code with a reformatted version.
    $ev = bbtoevent($Text);
    // Replace any html brackets with HTML Entities to prevent executing HTML or script
    // Don't use strip_tags here because it breaks [url] search by replacing & with amp
    $Text = str_replace("<", "&lt;", $Text);
    $Text = str_replace(">", "&gt;", $Text);
    // Convert new line chars to html <br /> tags
    $Text = nl2br($Text);
    if ($preserve_nl) {
        $Text = str_replace(array("\n", "\r"), array('', ''), $Text);
    }
    // Set up the parameters for a URL search string
    $URLSearchString = "^\\[\\]";
    // Set up the parameters for a MAIL search string
    $MAILSearchString = $URLSearchString;
    // Perform URL Search
    $Text = preg_replace("/([^\\]\\=]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
    $Text = preg_replace_callback("/\\[bookmark\\=([^\\]]*)\\].*?\\[\\/bookmark\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $Text);
    $Text = preg_replace_callback("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<a href="$1" target="external-link">$1</a>', $Text);
    $Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<a href="$1" target="external-link">$2</a>', $Text);
    //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
    // we may need to restrict this further if it picks up too many strays
    // link acct:user@host to a webfinger profile redirector
    $Text = preg_replace('/acct:(.*?)@(.*?)([ ,])/', '<a href="' . $a->get_baseurl() . '/acctlink?addr=' . "\$1@\$2" . '" target="extlink" >acct:' . "\$1@\$2\$3" . '</a>', $Text);
    // Perform MAIL Search
    $Text = preg_replace("/\\[mail\\]([{$MAILSearchString}]*)\\[\\/mail\\]/", '<a href="mailto:$1">$1</a>', $Text);
    $Text = preg_replace("/\\[mail\\=([{$MAILSearchString}]*)\\](.*?)\\[\\/mail\\]/", '<a href="mailto:$1">$2</a>', $Text);
    // Check for bold text
    $Text = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '<strong>$1</strong>', $Text);
    // Check for Italics text
    $Text = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '<em>$1</em>', $Text);
    // Check for Underline text
    $Text = preg_replace("(\\[u\\](.*?)\\[\\/u\\])ism", '<u>$1</u>', $Text);
    // Check for strike-through text
    $Text = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '<strike>$1</strike>', $Text);
    // Check for over-line text
    $Text = preg_replace("(\\[o\\](.*?)\\[\\/o\\])ism", '<span class="overline">$1</span>', $Text);
    // Check for colored text
    $Text = preg_replace("(\\[color=(.*?)\\](.*?)\\[\\/color\\])ism", "<span style=\"color: \$1;\">\$2</span>", $Text);
    // Check for sized text
    // [size=50] --> font-size: 50px (with the unit).
    $Text = preg_replace("(\\[size=(\\d*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1px;\">\$2</span>", $Text);
    $Text = preg_replace("(\\[size=(.*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1;\">\$2</span>", $Text);
    // Check for centered text
    $Text = preg_replace("(\\[center\\](.*?)\\[\\/center\\])ism", "<div style=\"text-align:center;\">\$1</div>", $Text);
    // Check for list text
    $Text = str_replace("[*]", "<li>", $Text);
    $Text = preg_replace("/\\[li\\](.*?)\\[\\/li\\]/ism", '<li>$1</li>', $Text);
    // handle nested lists
    $endlessloop = 0;
    while (strpos($Text, "[/list]") !== false and strpos($Text, "[list") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[list\\](.*?)\\[\\/list\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=\\](.*?)\\[\\/list\\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=1\\](.*?)\\[\\/list\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)i)\\](.*?)\\[\\/list\\]/ism", '<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)I)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)a)\\](.*?)\\[\\/list\\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>', $Text);
        $Text = preg_replace("/\\[list=((?-i)A)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>', $Text);
    }
    $Text = preg_replace("/\\[ul\\](.*?)\\[\\/ul\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
    $Text = preg_replace("/\\[ol\\](.*?)\\[\\/ol\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
    $Text = preg_replace("/\\[th\\](.*?)\\[\\/th\\]/sm", '<th>$1</th>', $Text);
    $Text = preg_replace("/\\[td\\](.*?)\\[\\/td\\]/sm", '<td>$1</td>', $Text);
    $Text = preg_replace("/\\[tr\\](.*?)\\[\\/tr\\]/sm", '<tr>$1</tr>', $Text);
    $Text = preg_replace("/\\[table\\](.*?)\\[\\/table\\]/sm", '<table>$1</table>', $Text);
    $Text = preg_replace("/\\[table border=1\\](.*?)\\[\\/table\\]/sm", '<table border="1" >$1</table>', $Text);
    $Text = preg_replace("/\\[table border=0\\](.*?)\\[\\/table\\]/sm", '<table border="0" >$1</table>', $Text);
    $Text = str_replace('[hr]', '<hr />', $Text);
    // This is actually executed in prepare_body()
    $Text = str_replace('[nosmile]', '', $Text);
    // Check for font change text
    $Text = preg_replace("/\\[font=(.*?)\\](.*?)\\[\\/font\\]/sm", "<span style=\"font-family: \$1;\">\$2</span>", $Text);
    // Declare the format for [code] layout
    $Text = preg_replace_callback("/\\[code\\](.*?)\\[\\/code\\]/ism", 'stripcode_br_cb', $Text);
    $CodeLayout = '<code>$1</code>';
    // Check for [code] text
    $Text = preg_replace("/\\[code\\](.*?)\\[\\/code\\]/ism", "{$CodeLayout}", $Text);
    // Declare the format for [spoiler] layout
    $SpoilerLayout = '<blockquote class="spoiler">$1</blockquote>';
    // Check for [spoiler] text
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/spoiler]") !== false and strpos($Text, "[spoiler]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[spoiler\\](.*?)\\[\\/spoiler\\]/ism", "{$SpoilerLayout}", $Text);
    }
    // Check for [spoiler=Author] text
    $t_wrote = t('$1 wrote:');
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/spoiler]") !== false and strpos($Text, "[spoiler=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[spoiler=[\"\\']*(.*?)[\"\\']*\\](.*?)\\[\\/spoiler\\]/ism", "<br /><strong class=" . '"spoiler"' . ">" . $t_wrote . "</strong><blockquote class=" . '"spoiler"' . ">\$2</blockquote>", $Text);
    }
    // Declare the format for [quote] layout
    $QuoteLayout = '<blockquote>$1</blockquote>';
    // Check for [quote] text
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/quote]") !== false and strpos($Text, "[quote]") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[quote\\](.*?)\\[\\/quote\\]/ism", "{$QuoteLayout}", $Text);
    }
    // Check for [quote=Author] text
    $t_wrote = t('$1 wrote:');
    // handle nested quotes
    $endlessloop = 0;
    while (strpos($Text, "[/quote]") !== false and strpos($Text, "[quote=") !== false and ++$endlessloop < 20) {
        $Text = preg_replace("/\\[quote=[\"\\']*(.*?)[\"\\']*\\](.*?)\\[\\/quote\\]/ism", "<br /><strong class=" . '"author"' . ">" . $t_wrote . "</strong><blockquote>\$2</blockquote>", $Text);
    }
    // [img=widthxheight]image source[/img]
    //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '<img src="$3" style="height: $2px; width: $1px;" >', $Text);
    $Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="width: $1px;" >', $Text);
    // Images
    // [img]pathtoimage[/img]
    $Text = preg_replace("/\\[img\\](.*?)\\[\\/img\\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
    $Text = preg_replace("/\\[video\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4))\\[\\/video\\]/ism", '<video src="$1" controls="controls" width="425" height="350"><a href="$1">$1</a></video>', $Text);
    $Text = preg_replace("/\\[audio\\](.*?\\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\\[\\/audio\\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $Text);
    // Try to Oembed
    $Text = preg_replace_callback("/\\[video\\](.*?)\\[\\/video\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace_callback("/\\[audio\\](.*?)\\[\\/audio\\]/ism", 'tryoembed', $Text);
    // html5 video and audio
    $Text = preg_replace("/\\[iframe\\](.*?)\\[\\/iframe\\]/ism", '<iframe src="$1" width="425" height="350"><a href="$1">$1</a></iframe>', $Text);
    // Youtube extensions
    $Text = preg_replace_callback("/\\[youtube\\](https?:\\/\\/www.youtube.com\\/watch\\?v\\=.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace_callback("/\\[youtube\\](www.youtube.com\\/watch\\?v\\=.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace_callback("/\\[youtube\\](https?:\\/\\/youtu.be\\/.*?)\\[\\/youtube\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/watch\\?v\\=(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/embed\\/(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    $Text = preg_replace("/\\[youtube\\]https?:\\/\\/youtu.be\\/(.*?)\\[\\/youtube\\]/ism", '[youtube]$1[/youtube]', $Text);
    $Text = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '<iframe width="425" height="350" src="http://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
    $Text = preg_replace_callback("/\\[vimeo\\](https?:\\/\\/player.vimeo.com\\/video\\/[0-9]+).*?\\[\\/vimeo\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace_callback("/\\[vimeo\\](https?:\\/\\/vimeo.com\\/[0-9]+).*?\\[\\/vimeo\\]/ism", 'tryoembed', $Text);
    $Text = preg_replace("/\\[vimeo\\]https?:\\/\\/player.vimeo.com\\/video\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[vimeo]$1[/vimeo]', $Text);
    $Text = preg_replace("/\\[vimeo\\]https?:\\/\\/vimeo.com\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[vimeo]$1[/vimeo]', $Text);
    $Text = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '<iframe width="425" height="350" src="http://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $Text);
    //	$Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
    // oembed tag
    $Text = oembed_bbcode2html($Text);
    // If we found an event earlier, strip out all the event code and replace with a reformatted version.
    if (x($ev, 'desc') && x($ev, 'start')) {
        $sub = format_event_html($ev);
        $Text = preg_replace("/\\[event\\-description\\](.*?)\\[\\/event\\-description\\]/ism", $sub, $Text);
        $Text = preg_replace("/\\[event\\-start\\](.*?)\\[\\/event\\-start\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-finish\\](.*?)\\[\\/event\\-finish\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-location\\](.*?)\\[\\/event\\-location\\]/ism", '', $Text);
        $Text = preg_replace("/\\[event\\-adjust\\](.*?)\\[\\/event\\-adjust\\]/ism", '', $Text);
    }
    // Unhide all [noparse] contained bbtags unspacefying them
    // and triming the [noparse] tag.
    $Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_unspacefy_and_trim', $Text);
    $Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_unspacefy_and_trim', $Text);
    $Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_unspacefy_and_trim', $Text);
    $Text = preg_replace('/\\[\\&amp\\;([#a-z0-9]+)\\;\\]/', '&$1;', $Text);
    // fix any escaped ampersands that may have been converted into links
    $Text = preg_replace("/\\<(.*?)(src|href)=(.*?)\\&amp\\;(.*?)\\>/ism", '<$1$2=$3&$4>', $Text);
    if (strlen($saved_image)) {
        $Text = str_replace('[$#saved_image#$]', '<img src="' . $saved_image . '" alt="' . t('Image/photo') . '" />', $Text);
    }
    call_hooks('bbcode', $Text);
    return $Text;
}
Esempio n. 12
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');
         }
     }
 }