image name) //======================================================================================================== $sm[':D'] = $sm[':oD'] = $sm[':-D'] = $sm[':))'] = $sm[':o))'] = $sm[':-))'] = 'biggrin.gif'; $sm[':)'] = $sm[':o)'] = $sm[':-)'] = 'smile.gif'; $sm[';)'] = $sm[';o)'] = $sm[';-)'] = 'wink.gif'; $sm[':|'] = $sm[':o|'] = $sm[':-|'] = 'neutral.gif'; $sm[':/'] = $sm[':o/'] = $sm[':-/'] = 'unsure.gif'; $sm[':['] = $sm[':o['] = $sm[':-['] = $sm[':('] = $sm[':o('] = $sm[':-('] = 'sad.gif'; $sm[':P'] = $sm[':oP'] = $sm[':-P'] = 'tongue.gif'; $sm[':o'] = $sm[':oO'] = $sm[':-o'] = 'surprised.gif'; $sm[':x'] = $sm[':ox'] = $sm[':-x'] = 'angry.gif'; $sm['->'] = $sm['=>'] = $sm['->'] = $sm['=>'] = 'arrow.gif'; $sm[':wstydliwy:'] = 'blush.gif'; $sm[':zmieszany:'] = 'confused.gif'; $sm[':cwaniak:'] = 'cool.gif'; $sm[':smutny:'] = 'cry.gif'; $sm[':omg:'] = 'eek.gif'; $sm[':diabel:'] = 'evil.gif'; $sm[':wykrzyknik:'] = 'exclaim.gif'; $sm[':zadowolony:'] = 'glad.gif'; $sm[':pomysl:'] = 'idea.gif'; $sm[':lol:'] = 'lol.gif'; $sm[':nieprzyzwoity:'] = 'naughty.gif'; $sm[':pytanie:'] = 'question.gif'; $sm[':zamyslony:'] = 'rollseyes.gif'; $sm[':milo:'] = 'smirk.gif'; $sm[':zmeczony:'] = 'tired.gif'; $sm[':pijany:'] = 'zonked.gif'; ?> ' . mysql_errno() . ': ' . mysql_error() . '
'; } //------------------------------------------------------------------------------------------------------ // Connect with MySQL server and select database // Arguments: server name, user name, user password, database name // function db_open($db_server, $db_user, $db_pass, $db_name) { $status = true; if(!@mysql_connect($db_server, $db_user, $db_pass)) { sql_error(); $status = false; } else if(!@mysql_select_db($db_name)) { sql_error(); $status = false; } return $status; } //------------------------------------------------------------------------------------------------------ // Convert timestamp to YYYY-MM-DD HH:MM:SS // Arguments: timestamp (YYYYMMDDHHMMSS) // function timeStamp($ts) { return substr($ts, 0, 4) . '-' . substr($ts, 4, 2) . '-' . substr($ts, 6, 2) . ' ' . substr($ts, 8, 2) . ':' . substr($ts, 10, 2) . ':' . substr($ts, 12); } //------------------------------------------------------------------------------------------------------ // Cut text to a specified length // Arguments: text, length // function cutString($str, $length) { if(strlen($str) > $length) { $words = explode(' ', $str); $wCnt = count($words); if($wCnt == 1) { $str = substr($str, 0, $length) . '...'; } else { $str = ''; $cnt = 0; while($cnt < $wCnt && strlen($str) < $length) { $str .= trim($words[$cnt++]) . ' '; } if($cnt < $wCnt) $str .= '...'; } } return $str; } //------------------------------------------------------------------------------------------------------ // Search text between start-tag and end-tag // Arguments: text, start-tag, end-tag // function searchCode($str, $pStart, $pEnd) { $matches = array(); $a = strlen($pStart); $b = strlen($pEnd); do { $y = 0; if(strlen($str) > strlen($pStart) + strlen($pEnd)) { $s = strtolower($str); $x = strpos($s, $pStart); $y = strpos($s, $pEnd, $x + $a); $z = strpos($s, $pStart, $x + $a); if($x >= 0 && $y) { while($z && $z < $y) { $y = strpos($s, $pEnd, $y + $b); $z = strpos($s, $pStart, $z + $a); } $y += $b; $matches[] = substr($str, $x, $y - $x); $str = substr($str, $y); } } } while($x >= 0 && $y > 0); return $matches; } //------------------------------------------------------------------------------------------------------ // Convert text between start-tag and end-tag to base64 // Arguments: text, start-tag, end-tag // function encodeString($str, $pStart, $pEnd) { $matches = searchCode($str, $pStart, $pEnd); for($i = 0; $i < count($matches); $i++) { $str = str_replace($matches[$i], chr(1) . base64_encode($matches[$i]) . chr(2), $str); } return $str; } //------------------------------------------------------------------------------------------------------ // Decode base64-text // Arguments: text // function decodeString($str) { if(preg_match_all('/' . chr(1) . '([^' . chr(2) . ']+)' . chr(2) . '/', $str, $m)) { for($i = 0; $i < count($m[0]); $i++) { $str = str_replace($m[0][$i], base64_decode($m[1][$i]), $str); } } return $str; } //------------------------------------------------------------------------------------------------------ // Delete repeated characters (more than 3 times) // Arguments: text // function checkRepeats($str) { $newstr = substr($str, 0, 3); for($i = 3; $i < strlen($str); $i++) { if($str[$i] != $str[$i-1] || $str[$i] != $str[$i-2] || $str[$i] != $str[$i-3]) $newstr .= $str[$i]; } return $newstr; } //------------------------------------------------------------------------------------------------------ // Replace long words with image // Arguments: text, max. word length // function checkLongWords($str, $wordLength) { global $imgPath; if($wordLength && strlen($str) > $wordLength) { $html = array(); if(preg_match_all('/<[a-z\/][^>]+>/i', $str, $m)) { for($i = 0; $i < count($m[0]); $i++) { $html[$i] = $m[0][$i]; $str = str_replace($m[0][$i], " &HTML$i; ", $str); } } $str = str_replace("\r\n", "\n", $str); $str = str_replace("\r", "\n", $str); $lines = explode("\n", $str); $str = ''; for($i = 0; $i < count($lines); $i++) { $words = explode(' ', $lines[$i]); for($j = 0; $j < count($words); $j++) { $word = function_exists('html_entity_decode') ? html_entity_decode($words[$j]) : $words[$j]; if(strlen($word) > $wordLength && !preg_match('/&#\d{1,6};/', $words[$j])) { if(preg_match('%^(ftp|https?)://%i', $word)) { $str .= "" . substr($word, 0, $wordLength) . '...' . ''; } else $str .= ''; } else $str .= $words[$j] . ' '; } if($i < count($lines) - 1) $str .= "\n"; } if(preg_match_all('/ &HTML(\d+); /', $str, $m)) { for($i = 0; $i < count($m[0]); $i++) { $str = str_replace($m[0][$i], $html[$m[1][$i]], $str); } } } return $str; } //------------------------------------------------------------------------------------------------------ // Add image size and replace oversized images with thumbnail and invalid images with icon // Arguments: text, max. image width // function checkImages($str, $maxWidth) { global $imgPath; if(preg_match_all('/ src="([^">]+)"/i', $str, $m)) { for($i = 0; $i < count($m[0]); $i++) { list($width, $height, $type) = @getimagesize($m[1][$i]); if(!$width || $type < 1 || $type > 3) { $width = 17; $height = 14; $img = $imgPath . 'noimage.gif'; } else if($width > $maxWidth) { $perc = $maxWidth / $width; $width = round($width * $perc); $height = round($height * $perc); $img = $imgPath . "thumbnail.php?width=$width&height=$height&file=" . urlencode($m[1][$i]); } else $img = $m[1][$i]; if($img != $imgPath . 'nourl.gif' && $img != $imgPath . 'nohtml.gif') { $size = 'width="' . $width . '" height="' . $height . '"'; $str = str_replace($m[0][$i], ' src="' . $img . '" ' . $size, $str); } } } return $str; } //------------------------------------------------------------------------------------------------------ // Replace smilies // Arguments: text // function replaceSmilies($str) { global $sm, $imgPath; if(count($sm)) { $str = str_replace('://', ':/', $str); reset($sm); while(list($code, $img) = each($sm)) { $image = ''; $str = str_replace($code, $image, $str); } $str = str_replace(':/', '://', $str); } return $str; } //------------------------------------------------------------------------------------------------------ // Replace bad words with image // Arguments: text // function replaceNonos($str) { global $nonos, $imgPath; $repl = ''; $c = '(\_|[^\d\w\r\n])*'; $cl = strlen($c); for($i = 0; $i < count($nonos); $i++) { $expr = chunk_split($nonos[$i], 1, $c); $str = preg_replace('/' . substr($expr, 0, strlen($expr) - $cl) . '/i', $repl, $str); } return $str; } //------------------------------------------------------------------------------------------------------ // Replace URLs with image // Arguments: text // function replaceURLs($str) { global $allowUBBs, $imgPath; if($allowUBBs) $str = encodeString($str, '[code]', '[/code]'); $valid_url1 = '(https?|ftp):\/\/([\w._-]+:[\w._-]+@)?[\w#._\/~-]+(\?([\w_-]+(=[\w+%?#_-]+(&(amp;)?)?)?)*)?'; $valid_url2 = 'www\.\w[\w-]+\.[\w#._\/~-]+(\?([\w_-]+(=[\w+%?#_-]+(&(amp;)?)?)?)*)?'; $img = ' '; $str = preg_replace('/]+>[^<]*/i', $img, $str); $str = preg_replace('/