public function bbcode($str, $truncate = null, $type = NULL, $pid = NULL, $id = NULL) { //evitare il parsing del bbcode nel tag code $codes = $this->getCodes($str); $index = 0; foreach ($codes as $code) { $totalcode = $code['code']; $lang = $code['lang']; $str = str_ireplace("[code={$lang}]{$totalcode}[/code]", ">>>{$index}<<<", $str); ++$index; } $domain = System::getResourceDomain(); $str = static::hashtag($str); $str = str_replace("\n", '<br />', $str); $validURL = function ($m) { $m[1] = trim($m[1]); if (!Utils::isValidURL($m[1])) { $m[1] = 'http://' . $m[1]; if (!Utils::isValidURL($m[1])) { return '<b>' . $this->user->lang('INVALID_URL') . '</b>'; } } $url = preg_match('#^(?:https?|ftp):\\/\\/#i', $m[1]) ? $m[1] : 'http://' . $m[1]; return isset($m[2]) ? '<a href="' . Messages::stripTags($url) . '" onclick="window.open(this.href); return false">' . $m[2] . '</a>' : '<a href="' . Messages::stripTags($url) . '" onclick="window.open(this.href); return false">' . $m[1] . '</a>'; }; $str = preg_replace_callback('#\\[url="(.+?)"\\](.+?)\\[/url\\]#i', function ($m) use($validURL) { return $validURL($m); }, $str); $str = preg_replace_callback('#\\[url=(.+?)\\](.+?)\\[/url\\]#i', function ($m) use($validURL) { return $validURL($m); }, $str); $str = preg_replace_callback('#\\[url\\](.+?)\\[/url\\]#i', function ($m) use($validURL) { return $validURL($m); }, $str); $str = preg_replace('#\\[i\\](.+?)\\[/i\\]#i', '<span style="font-style:italic">$1</span>', $str); $str = preg_replace('#\\[cur\\](.+?)\\[/cur\\]#i', '<span style="font-style:italic">$1</span>', $str); $str = preg_replace('#\\[gist\\]([0-9a-z]+)\\[/gist\\]#i', '<div class="gistLoad" data-id="$1" id="gist-$1">' . $this->user->lang('LOADING') . '...</div>', $str); $str = preg_replace('#\\[b\\](.+?)\\[/b\\]#i', '<span style="font-weight:bold">$1</span>', $str); $str = preg_replace('#\\[del\\](.+?)\\[/del\\]#i', '<del>$1</del>', $str); $str = preg_replace('#\\[u\\](.+?)\\[/u\\]#i', '<u>$1</u>', $str); $str = preg_replace('#\\[hr\\]#i', '<hr style="clear:both" />', $str); $str = preg_replace('#\\[small\\](.+?)\\[/small\\]#i', '<span style="font-size:7pt">$1</span>', $str); $str = preg_replace('#\\[big\\](.+?)\\[/big\\]#i', '<span style="font-size:14pt">$1</span>', $str); $str = preg_replace('#\\[wat\\]#i', '<span style="font-size:22pt">WAT</span>', $str); $str = preg_replace_callback('#\\[user\\](.+?)\\[/user\\]#i', function ($m) { return '<a href="/' . Utils::userLink($m[1]) . "\">{$m[1]}</a>"; }, $str); $str = preg_replace_callback('#\\[project\\](.+?)\\[/project\\]#i', function ($m) { return '<a href="/' . Utils::projectLink($m[1]) . "\">{$m[1]}</a>"; }, $str); $str = preg_replace_callback('#\\[wiki=([a-z]{2})\\](.+?)\\[/wiki\\]#i', function ($m) { return '<a href="http://' . $m[1] . '.wikipedia.org/wiki/' . urlencode(str_replace(' ', '_', html_entity_decode($m[2], ENT_QUOTES, 'UTF-8'))) . "\" onclick=\"window.open(this.href); return false\">{$m[2]} @Wikipedia - {$m[1]}</a>"; }, $str); $str = preg_replace_callback("#(\\[math\\]|\\[m\\])(.+?)(\\[/math\\]|\\[/m\\])#i", function ($m) { return $m[1] . strip_tags($m[2]) . $m[3]; }, $str); $str = preg_replace_callback('#\\[list\\](.+?)\\[\\/list\\]#i', function ($m) { $arr = array_filter(explode('[*]', trim(trim($m[1]), '<br />'))); if (empty($arr)) { return $m[0]; } $ret = '<ul>'; foreach ($arr as $v) { $ret .= '<li>' . trim($v) . '</li>'; } $ret .= '</ul>'; return $ret; }, $str, 20); //ok $str = preg_replace_callback('#\\[list[\\s]+type="(1|a|i)"\\](.+?)\\[\\/list\\]#i', function ($m) { $arr = array_filter(explode('[*]', trim(trim($m[2]), '<br />'))); if (empty($arr)) { return $m[0]; } $ret = '<ol type="' . $m[1] . '">'; foreach ($arr as $v) { $ret .= '<li>' . trim($v) . '</li>'; } $ret .= '</ol>'; return $ret; }, $str, 10); //ok $str = preg_replace_callback('#\\[list[\\s]+start="(\\-?\\d+)"\\](.+?)\\[\\/list\\]#i', function ($m) { $arr = array_filter(explode('[*]', trim(trim($m[2]), '<br />'))); if (empty($arr)) { return $m[0]; } $ret = '<ol start="' . $m[1] . '">'; foreach ($arr as $v) { $ret .= '<li>' . trim($v) . '</li>'; } $ret .= '</ol>'; return $ret; }, $str, 10); //ok $str = preg_replace_callback('#\\[list[\\s]+start="(\\-?\\d+)"[\\s]+type="(1|a|i)"\\](.+?)\\[\\/list\\]#i', function ($m) { $arr = array_filter(explode('[*]', trim(trim($m[3]), '<br />'))); if (empty($arr)) { return $m[0]; } $ret = '<ol start="' . $m[1] . '" type="' . $m[2] . '">'; foreach ($arr as $v) { $ret .= '<li>' . trim($v) . '</li>'; } $ret .= '</ol>'; return $ret; }, $str, 10); //ok $str = preg_replace_callback('#\\[list[\\s]+type="(1|a|i)"[\\s]+start="(\\-?\\d+)"\\](.+?)\\[\\/list\\]#i', function ($m) { $arr = array_filter(explode('[*]', trim(trim($m[3]), '<br />'))); if (empty($arr)) { return $m[0]; } $ret = '<ol start="' . $m[2] . '" type="' . $m[1] . '">'; foreach ($arr as $v) { $ret .= '<li>' . trim($v) . '</li>'; } $ret .= '</ol>'; return $ret; }, $str, 10); // Quote in comments, new version while (preg_match('#\\[commentquote=(.+?)\\](.+?)\\[/commentquote\\]#i', $str)) { $str = preg_replace_callback('#\\[commentquote=(.+?)\\](.+?)\\[/commentquote\\]#i', function ($m) { return '<div class="qu_main"><div class="qu_user">' . $m[1] . '</div>' . $m[2] . '</div>'; }, $str, 1); } while (preg_match('#\\[quote=(.+?)\\](.+?)\\[/quote\\]#i', $str)) { $str = preg_replace_callback('#\\[quote=(.+?)\\](.+?)\\[/quote\\]#i', function ($m) use($domain) { return '<div class="quote"> <div style="font-weight: bold">' . $m[1] . ':</div> <span style="float: left; margin-top: 5px"> <img src="' . $domain . '/static/images/oquotes.gif" alt="quote" width="20" height="11" /> </span> <div style="font-style:italic"> <blockquote style="margin-left: 3%">' . trim($m[2]) . '</blockquote> </div> <span style="float: right"> <img src="' . $domain . '/static/images/cquotes.gif" alt="cquote" width="20" height="11" /> </span> </div>'; }, $str, 1); } while (preg_match('#\\[quote\\](.+?)\\[/quote\\]#i', $str)) { $str = preg_replace_callback('#\\[quote\\](.+?)\\[/quote\\]#i', function ($m) use($domain) { return '<div class="quote"> <span style="float: left; margin-top: 5px"> <img src="' . $domain . '/static/images/oquotes.gif" alt="quote" width="20" height="11" /> </span> <div style="font-style:italic"> <blockquote style="margin-left: 3%">' . trim($m[1]) . '</blockquote> </div> <span style="float: right"> <img src="' . $domain . '/static/images/cquotes.gif" alt="cquote" width="20" height="11" /> </span> </div>'; }, $str, 1); } while (preg_match('#\\[spoiler\\](.+?)\\[/spoiler\\]#i', $str)) { $str = preg_replace('#\\[spoiler\\](.+?)\\[/spoiler]#i', '<div class="spoiler" onclick="var c = $(this).children(\'div\'); c.toggle(\'fast\'); c.on(\'click\',function(e) {e.stopPropagation();});"> <span style="font-weight: bold; cursor:pointer">SPOILER:</span> <div style="display:none"><hr /></div> <div style="display:none; margin-left:3%;overflow:hidden">$1</div> </div>', $str, 1); } while (preg_match('#\\[spoiler=(.+?)\\](.+?)\\[/spoiler\\]#i', $str)) { $str = preg_replace('#\\[spoiler=(.+?)\\](.+?)\\[/spoiler]#i', '<div class="spoiler" onclick="var c = $(this).children(\'div\'); c.toggle(\'fast\'); c.on(\'click\',function(e) {e.stopPropagation();});"> <span style="font-weight: bold; cursor:pointer">$1:</span> <div style="display:none"><hr /></div> <div style="display:none; margin-left:3%;overflow:hidden">$2</div> </div>', $str, 1); } $str = preg_replace_callback('#\\[music\\]\\s*(.+?)\\s*\\[/music\\]#i', function ($m) use($truncate) { $uri = strip_tags(html_entity_decode($m[1], ENT_QUOTES, 'UTF-8')); if (stripos($uri, 'spotify') !== false) { if (preg_match('#^(?:spotify:track:[\\d\\w]+)|(?:spotify:user:[\\w\\d]+:playlist:[\\w\\d]+)$#i', $uri)) { $ID = $uri; } else { if (preg_match('#^https?://(?:open|play)\\.spotify\\.com/track/[\\w\\d]+$#i', $uri)) { $ID = 'spotify:track:' . basename($uri); } else { if (preg_match('#^https?://(?:open|play)\\.spotify\\.com/user/([\\w\\d]+)/playlist/[\\w\\d]+#i', $uri, $matches)) { $ID = "spotify:user:{$matches[1]}:playlist:" . basename($uri); } else { return $m[0]; } } } return '<iframe src="https://embed.spotify.com/?uri=' . $ID . '" width="300" height="80" frameborder="0" allowtransparency="true"></iframe>'; } else { if (preg_match('#^https?://soundcloud\\.com/\\S+/\\S+$#i', $uri)) { return '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=' . rawurlencode($uri) . '"></iframe>'; } else { if (preg_match('#^https?://(?:www\\.)?deezer\\.com/(track|album|playlist)/(\\d+)$#', $uri, $match)) { $a_type = $match[1] . ($match[1] == 'track' ? 's' : ''); $a_height = $truncate ? '80' : '240'; return "<iframe src='//www.deezer.com/plugins/player?height={$a_height}&type={$a_type}&id={$match[2]}' width='100%' height='{$a_height}' scrolling='no' frameborder='no'></iframe>"; } else { if (filter_var($uri, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) { return '<audio preload="none" controls src="' . htmlspecialchars($uri, ENT_QUOTES, 'UTF-8') . '"></audio>'; } else { return $m[0]; } } } } }, $str, 10); $str = preg_replace_callback('#\\[twitter\\]\\s*(.+?)\\s*\\[/twitter\\]#i', function ($m) use($truncate) { // The reason for the 'data-uuid' attribute is in the jclass.js file, in the loadTweet function. // with a fixed height (220px - when truncate is true - js trimmer can handle post size if (!(is_numeric($m[1]) || Utils::isValidURL($m[1]))) { return $m[0]; } return '<img data-id="' . htmlspecialchars($m[1], ENT_QUOTES, 'UTF-8') . '" data-uuid="' . mt_rand() . '" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" onload="N.loadTweet(this)"' . ($truncate ? ' height="220"' : '') . '>'; }, $str, 10); if ($truncate) { $videoCallback = function ($m) { $v_url = html_entity_decode($m[1], ENT_QUOTES, 'UTF-8'); $output = []; if (preg_match(static::YOUTUBE_REGEXP, $v_url, $match)) { $output = ['youtube', $match[1], '//i1.ytimg.com/vi/' . $match[1] . '/hqdefault.jpg', 130]; } else { if (preg_match(static::VIMEO_REGEXP, $v_url, $match)) { $output = ['vimeo', $match[1], 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 130, 'N.vimeoThumbnail(this)']; } else { if (preg_match(static::DMOTION_REGEXP, $v_url, $match)) { $output = ['dailymotion', $match[1], 'https://www.dailymotion.com/thumbnail/video/' . $match[1], 100]; } else { if (preg_match(static::FACEBOOK_REGEXP, $v_url, $match)) { $output = ['facebook', $match[1], 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 100, 'N.facebookThumbnail(this)']; } else { if (preg_match(static::NERDZCRUSH_REGEXP, $v_url, $match)) { $output = ['nerdzcrush', $match[1], 'https://media.nerdz.eu/' . $match[1] . '.jpg', 130]; } else { return $m[0]; } } } } } return '<a class="yt_frame" data-vid="' . $output[1] . '" data-host="' . $output[0] . '">' . '<span>' . $this->user->lang('VIDEO') . '</span>' . '<img src="' . $output[2] . '" alt="" width="130" height="' . $output[3] . '" style="float:left;margin-right:4px"' . (isset($output[4]) ? 'onload="' . $output[4] . '"' : '') . ' />' . '</a>'; }; $str = preg_replace_callback('#\\[video\\]\\s*(https?:\\/\\/[\\S]+)\\s*\\[\\/video\\]#i', $videoCallback, $str, 10); // don't break older posts and preserve the [yt] and [youtube] tags. $str = preg_replace_callback('#\\[yt\\]\\s*(https?:\\/\\/[\\S]+)\\s*\\[\\/yt\\]#i', $videoCallback, $str, 10); $str = preg_replace_callback('#\\[youtube\\]\\s*(https?:\\/\\/[\\S]+)\\s*\\[\\/youtube\\]#i', $videoCallback, $str, 10); $str = preg_replace_callback('#\\[img\\](.+?)\\[/img\\]#i', function ($m) { $url = Utils::getValidImageURL($m[1]); return '<a href="' . $url . '" target="_blank" class="img_frame" onclick="$(this).toggleClass(\'img_frame-extended\'); return false;"> <span> ' . $this->user->lang('IMAGES') . ' </span> <img src="' . $url . '" alt="" onload="N.imgLoad(this)" onerror="N.imgErr(this)" /> </a>'; }, $str, 10); } else { $videoCallback = function ($m) { $v_url = html_entity_decode($m[1], ENT_QUOTES, 'UTF-8'); $iframe_code = ''; if (preg_match(static::YOUTUBE_REGEXP, $v_url, $match)) { $iframe_code = '<iframe title="YouTube video" style="width:560px; height:340px; border:0px; margin: auto;" src="//www.youtube.com/embed/' . $match[1] . '?wmode=opaque"></iframe>'; } else { if (preg_match(static::VIMEO_REGEXP, $v_url, $match)) { $iframe_code = '<iframe src="//player.vimeo.com/video/' . $match[1] . '?badge=0&color=ffffff" width="500" height="281" style="margin: auto" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; } else { if (preg_match(static::DMOTION_REGEXP, $v_url, $match)) { $iframe_code = '<iframe frameborder="0" style="margin: auto" width="480" height="270" src="//www.dailymotion.com/embed/video/' . $match[1] . '" allowfullscreen></iframe>'; } else { if (preg_match(static::FACEBOOK_REGEXP, $v_url, $match)) { $iframe_code = '<iframe style="margin: auto" src="https://www.facebook.com/video/embed?video_id=' . $match[1] . '" frameborder="0"></iframe>'; } else { if (preg_match(static::NERDZCRUSH_REGEXP, $v_url, $match)) { $iframe_code = '<div class="nerdzcrush" data-media="' . $match[1] . '#noautoplay,noloop"></div>'; } else { return $m[0]; } } } } } return '<div style="width:100%; text-align:center"><br />' . $iframe_code . '</div>'; }; $str = preg_replace_callback('#\\[video\\]\\s*(https?:\\/\\/[\\S]+)\\s*\\[\\/video\\]#i', $videoCallback, $str, 10); $str = preg_replace_callback('#\\[yt\\]\\s*(https?:\\/\\/[\\S]+)\\s*\\[\\/yt\\]#i', $videoCallback, $str, 10); $str = preg_replace_callback('#\\[youtube\\]\\s*(https?:\\/\\/[\\S]+)\\s*\\[\\/youtube\\]#i', $videoCallback, $str, 10); $str = preg_replace_callback('#\\[img\\](.+?)\\[/img\\]#i', function ($m) { return '<img src="' . Utils::getValidImageURL($m[1]) . '" alt="" style="max-width: 79%; max-height: 89%" onerror="N.imgErr(this)" />'; }, $str); } while ($index > 0) { --$index; $lang = $codes[$index]['lang']; $totalcode = $codes[$index]['code']; $tag = $codes[$index]['tag']; $str = str_ireplace(">>>{$index}<<<", "[{$tag}={$lang}]{$totalcode}[/{$tag}]", $str); } return $this->parseCode($codes, $str, $type, $pid, $id); }
require_once $_SERVER['DOCUMENT_ROOT'] . '/pages/register.php'; $user->getTPL()->assign($vals); require_once $_SERVER['DOCUMENT_ROOT'] . '/pages/common/vars.php'; $user->getTPL()->draw('project/private'); } else { $mem = $project->getMembers($info->counter); $icansee = true; if ($vals['logged_b'] && !$info->visible) { $icansee = $_SESSION['id'] == $project->getOwner() || in_array($_SESSION['id'], $mem); } if (!$icansee) { $user->getTPL()->assign($vals); require_once $_SERVER['DOCUMENT_ROOT'] . '/pages/common/vars.php'; $user->getTPL()->draw('project/invisible'); } else { $vals['photo_n'] = !empty($info->photo) ? Utils::getValidImageURL($info->photo) : 'https://www.gravatar.com/avatar/'; $vals['onerrorimgurl_n'] = '/static/images/onErrorImg.php'; $vals['id_n'] = $info->counter; $vals['name_n'] = $info->name; $vals['name4link_n'] = \NERDZ\Core\Utils::projectLink($info->name); if (!($o = Db::query(['SELECT EXTRACT(EPOCH FROM "creation_time") AS creation_time from "groups" WHERE "counter" = :id', [':id' => $info->counter]], Db::FETCH_OBJ))) { die($user->lang('ERROR')); } $vals['creationtime_n'] = $user->getDateTime($o->creation_time); $vals['members_n'] = count($mem); $vals['members_a'] = []; $i = 0; foreach ($mem as $uid) { if (!($uname = User::getUsername($uid))) { continue; }