Beispiel #1
0
/**
 * @param  App $a
 * @return string
 */
function admin_page_site(&$a)
{
    /* Installed langs */
    $lang_choices = array();
    $langs = glob('view/*/strings.php');
    if (is_array($langs) && count($langs)) {
        if (!in_array('view/en/strings.php', $langs)) {
            $langs[] = 'view/en/';
        }
        asort($langs);
        foreach ($langs as $l) {
            $t = explode("/", $l);
            $lang_choices[$t[1]] = $t[1];
        }
    }
    /* Installed themes */
    $theme_choices = array();
    $theme_choices_mobile = array();
    $theme_choices_mobile["---"] = t("No special theme for mobile devices");
    $files = glob('view/theme/*');
    if ($files) {
        foreach ($files as $file) {
            $f = basename($file);
            $theme_name = file_exists($file . '/experimental') ? sprintf("%s - (Experimental)", $f) : $f;
            if (file_exists($file . '/mobile')) {
                $theme_choices_mobile[$f] = $theme_name;
            } else {
                $theme_choices[$f] = $theme_name;
            }
        }
    }
    /* Community page style */
    $community_page_style_choices = array(CP_NO_COMMUNITY_PAGE => t("No community page"), CP_USERS_ON_SERVER => t("Public postings from users of this site"), CP_GLOBAL_COMMUNITY => t("Global community page"));
    /* OStatus conversation poll choices */
    $ostatus_poll_choices = array("-2" => t("Never"), "-1" => t("At post arrival"), "0" => t("Frequently"), "60" => t("Hourly"), "720" => t("Twice daily"), "1440" => t("Daily"));
    /* get user names to make the install a personal install of X */
    $user_names = array();
    $user_names['---'] = t('Multi user instance');
    $users = q("SELECT username, nickname FROM `user`");
    foreach ($users as $user) {
        $user_names[$user['nickname']] = $user['username'];
    }
    /* Banner */
    $banner = get_config('system', 'banner');
    if ($banner == false) {
        $banner = '<a href="http://friendica.com"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="http://friendica.com">Friendica</a></span>';
    }
    $banner = htmlspecialchars($banner);
    $info = get_config('config', 'info');
    $info = htmlspecialchars($info);
    // Automatically create temporary paths
    get_temppath();
    get_lockpath();
    get_itemcachepath();
    //echo "<pre>"; var_dump($lang_choices); die("</pre>");
    /* Register policy */
    $register_choices = array(REGISTER_CLOSED => t("Closed"), REGISTER_APPROVE => t("Requires approval"), REGISTER_OPEN => t("Open"));
    $ssl_choices = array(SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"), SSL_POLICY_FULL => t("Force all links to use SSL"), SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)"));
    if ($a->config['hostname'] == "") {
        $a->config['hostname'] = $a->get_hostname();
    }
    $t = get_markup_template("admin_site.tpl");
    return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Site'), '$submit' => t('Save Settings'), '$registration' => t('Registration'), '$upload' => t('File upload'), '$corporate' => t('Policies'), '$advanced' => t('Advanced'), '$performance' => t('Performance'), '$relocate' => t('Relocate - WARNING: advanced function. Could make this server unreachable.'), '$baseurl' => $a->get_baseurl(true), '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), 'UTF-8'), '$hostname' => array('hostname', t("Host name"), $a->config['hostname'], ""), '$sender_email' => array('sender_email', t("Sender Email"), $a->config['sender_email'], "The email address your server shall use to send notification emails from.", "", "", "email"), '$banner' => array('banner', t("Banner/Logo"), $banner, ""), '$shortcut_icon' => array('shortcut_icon', t("Shortcut icon"), get_config('system', 'shortcut_icon'), "Link to an icon that will be used for browsers."), '$touch_icon' => array('touch_icon', t("Touch icon"), get_config('system', 'touch_icon'), "Link to an icon that will be used for tablets and mobiles."), '$info' => array('info', t('Additional Info'), $info, t('For public servers: you can add additional information here that will be listed at dir.friendica.com/siteinfo.')), '$language' => array('language', t("System language"), get_config('system', 'language'), "", $lang_choices), '$theme' => array('theme', t("System theme"), get_config('system', 'theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices), '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system', 'mobile-theme'), t("Theme for mobile devices"), $theme_choices_mobile), '$ssl_policy' => array('ssl_policy', t("SSL link policy"), (string) intval(get_config('system', 'ssl_policy')), t("Determines whether generated links should be forced to use SSL"), $ssl_choices), '$force_ssl' => array('force_ssl', t("Force SSL"), get_config('system', 'force_ssl'), t("Force all Non-SSL requests to SSL - Attention: on some systems it could lead to endless loops.")), '$old_share' => array('old_share', t("Old style 'Share'"), get_config('system', 'old_share'), t("Deactivates the bbcode element 'share' for repeating items.")), '$hide_help' => array('hide_help', t("Hide help entry from navigation menu"), get_config('system', 'hide_help'), t("Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.")), '$singleuser' => array('singleuser', t("Single user instance"), get_config('system', 'singleuser'), t("Make this instance multi-user or single-user for the named user"), $user_names), '$maximagesize' => array('maximagesize', t("Maximum image size"), get_config('system', 'maximagesize'), t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")), '$maximagelength' => array('maximagelength', t("Maximum image length"), get_config('system', 'max_image_length'), t("Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.")), '$jpegimagequality' => array('jpegimagequality', t("JPEG image quality"), get_config('system', 'jpeg_quality'), t("Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.")), '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices), '$daily_registrations' => array('max_daily_registrations', t("Maximum Daily Registrations"), get_config('system', 'max_daily_registrations'), t("If registration is permitted above, this sets the maximum number of new user registrations to accept per day.  If register is set to closed, this setting has no effect.")), '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES, 'UTF-8'), t("Will be displayed prominently on the registration page.")), '$abandon_days' => array('abandon_days', t('Accounts abandoned after x days'), get_config('system', 'account_abandon_days'), t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')), '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system', 'allowed_sites'), t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")), '$allowed_email' => array('allowed_email', t("Allowed email domains"), get_config('system', 'allowed_email'), t("Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains")), '$block_public' => array('block_public', t("Block public"), get_config('system', 'block_public'), t("Check to block public access to all otherwise public personal pages on this site unless you are currently logged in.")), '$force_publish' => array('publish_all', t("Force publish"), get_config('system', 'publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")), '$global_directory' => array('directory_submit_url', t("Global directory update URL"), get_config('system', 'directory_submit_url'), t("URL to update the global directory. If this is not set, the global directory is completely unavailable to the application.")), '$thread_allow' => array('thread_allow', t("Allow threaded items"), get_config('system', 'thread_allow'), t("Allow infinite level threading for items on this site.")), '$newuser_private' => array('newuser_private', t("Private posts by default for new users"), get_config('system', 'newuser_private'), t("Set default post permissions for all new members to the default privacy group rather than public.")), '$enotify_no_content' => array('enotify_no_content', t("Don't include post content in email notifications"), get_config('system', 'enotify_no_content'), t("Don't include the content of a post/comment/private message/etc. in the email notifications that are sent out from this site, as a privacy measure.")), '$private_addons' => array('private_addons', t("Disallow public access to addons listed in the apps menu."), get_config('config', 'private_addons'), t("Checking this box will restrict addons listed in the apps menu to members only.")), '$disable_embedded' => array('disable_embedded', t("Don't embed private images in posts"), get_config('system', 'disable_embedded'), t("Don't replace locally-hosted private photos in posts with an embedded copy of the image. This means that contacts who receive posts containing private photos will have to authenticate and load each image, which may take a while.")), '$allow_users_remote_self' => array('allow_users_remote_self', t('Allow Users to set remote_self'), get_config('system', 'allow_users_remote_self'), t('With checking this, every user is allowed to mark every contact as a remote_self in the repair contact dialog. Setting this flag on a contact causes mirroring every posting of that contact in the users stream.')), '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system', 'block_extended_register'), t("Disallow users to register additional accounts for use as pages.")), '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system', 'no_openid'), t("OpenID support for registration and logins.")), '$no_regfullname' => array('no_regfullname', t("Fullname check"), !get_config('system', 'no_regfullname'), t("Force users to register with a space between firstname and lastname in Full name, as an antispam measure")), '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system', 'no_utf'), t("Use PHP UTF8 regular expressions")), '$community_page_style' => array('community_page_style', t("Community Page Style"), get_config('system', 'community_page_style'), t("Type of community page to show. 'Global community' shows every public posting from an open distributed network that arrived on this server."), $community_page_style_choices), '$max_author_posts_community_page' => array('max_author_posts_community_page', t("Posts per user on community page"), get_config('system', 'max_author_posts_community_page'), t("The maximum number of posts per user on the community page. (Not valid for 'Global Community')")), '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system', 'ostatus_disabled'), t("Provide built-in OStatus (StatusNet, GNU Social etc.) compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")), '$ostatus_poll_interval' => array('ostatus_poll_interval', t("OStatus conversation completion interval"), (string) intval(get_config('system', 'ostatus_poll_interval')), t("How often shall the poller check for new entries in OStatus conversations? This can be a very ressource task."), $ostatus_poll_choices), '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system', 'diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")), '$dfrn_only' => array('dfrn_only', t('Only allow Friendica contacts'), get_config('system', 'dfrn_only'), t("All contacts must use Friendica protocols. All other built-in communication protocols disabled.")), '$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system', 'verifyssl'), t("If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites.")), '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system', 'proxyuser'), ""), '$proxy' => array('proxy', t("Proxy URL"), get_config('system', 'proxy'), ""), '$timeout' => array('timeout', t("Network timeout"), x(get_config('system', 'curl_timeout')) ? get_config('system', 'curl_timeout') : 60, t("Value is in seconds. Set to 0 for unlimited (not recommended).")), '$delivery_interval' => array('delivery_interval', t("Delivery interval"), x(get_config('system', 'delivery_interval')) ? get_config('system', 'delivery_interval') : 2, t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), '$poll_interval' => array('poll_interval', t("Poll interval"), x(get_config('system', 'poll_interval')) ? get_config('system', 'poll_interval') : 2, t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), intval(get_config('system', 'maxloadavg')) > 0 ? get_config('system', 'maxloadavg') : 50, t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system', 'use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")), '$suppress_language' => array('suppress_language', t("Suppress Language"), get_config('system', 'suppress_language'), t("Suppress language information in meta information about a posting.")), '$suppress_tags' => array('suppress_tags', t("Suppress Tags"), get_config('system', 'suppress_tags'), t("Suppress showing a list of hashtags at the end of the posting.")), '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system', 'itemcache'), "The item caches buffers generated bbcode and external images."), '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system', 'itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")), '$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), get_config('system', 'max_comments'), t("How much comments should be shown for each post? Default value is 100.")), '$lockpath' => array('lockpath', t("Path for lock file"), get_config('system', 'lockpath'), "The lock file is used to avoid multiple pollers at one time. Only define a folder here."), '$temppath' => array('temppath', t("Temp path"), get_config('system', 'temppath'), "If you have a restricted system where the webserver can't access the system temp path, enter another path here."), '$basepath' => array('basepath', t("Base path to installation"), get_config('system', 'basepath'), "If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."), '$proxy_disabled' => array('proxy_disabled', t("Disable picture proxy"), get_config('system', 'proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")), '$old_pager' => array('old_pager', t("Enable old style pager"), get_config('system', 'old_pager'), t("The old style pager has page numbers but slows down massively the page speed.")), '$only_tag_search' => array('only_tag_search', t("Only search in tags"), get_config('system', 'only_tag_search'), t("On large systems the text search can slow down the system extremely.")), '$relocate_url' => array('relocate_url', t("New base url"), $a->get_baseurl(), "Change base url for this server. Sends relocate message to all DFRN contacts of all users."), '$form_security_token' => get_form_security_token("admin_site")));
}
Beispiel #2
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);
}
Beispiel #3
0
function clear_cache($basepath = "", $path = "")
{
    if ($path == "") {
        $basepath = get_itemcachepath();
        $path = $basepath;
    }
    if ($path == "" or !is_dir($path)) {
        return;
    }
    if (substr(realpath($path), 0, strlen($basepath)) != $basepath) {
        return;
    }
    $cachetime = (int) get_config('system', 'itemcache_duration');
    if ($cachetime == 0) {
        $cachetime = 86400;
    }
    if (is_writable($path)) {
        if ($dh = opendir($path)) {
            while (($file = readdir($dh)) !== false) {
                $fullpath = $path . "/" . $file;
                if (filetype($fullpath) == "dir" and $file != "." and $file != "..") {
                    clear_cache($basepath, $fullpath);
                }
                if (filetype($fullpath) == "file" and filectime($fullpath) < time() - $cachetime) {
                    unlink($fullpath);
                }
            }
            closedir($dh);
        }
    }
}