".mysql_error());
$connexionbase = mysql_select_db("$base") or die("Can't connect to the database $base. MySQL said: ".mysql_error());
return(($connexion && $connexionbase));
}
function mysql_oops($query) {
$error = '
!', "$1", $pee);
if ($br) $pee = preg_replace('|(?)\s*\n|', " \n", $pee); // optionally make line breaks
$pee = preg_replace('!(?(?:table|ul|ol|li|pre|select|form|blockquote|p)>) !', "$1", $pee);
$pee = preg_replace('|
]*)>|i', "
", $pee);
$pee = str_replace('
', '
', $pee);
return $pee;
}
function autobrize($content) {
$content = preg_replace("/ \n/", "\n", $content);
$content = preg_replace("/ \n/", "\n", $content);
$content = preg_replace("/(\015\012)|(\015)|(\012)/", " \n", $content);
return($content);
}
function unautobrize($content) {
$content = preg_replace("/ \n/", "\n", $content); //for PHP versions before 4.0.5
$content = preg_replace("/ \n/", "\n", $content);
return($content);
}
function format_to_edit($content) {
global $autobr;
$content = stripslashes($content);
if ($autobr) { $content = unautobrize($content); }
$content = htmlspecialchars($content);
return($content);
}
function format_to_post($content) {
global $post_autobr,$comment_autobr;
$content = addslashes($content);
if ($post_autobr || $comment_autobr) { $content = autobrize($content); }
return($content);
}
function zeroise($number,$threshold) { // function to add leading zeros when necessary
$l=strlen($number);
if ($l<$threshold)
for ($i=0; $i<($threshold-$l); $i=$i+1) { $number='0'.$number; }
return($number);
}
function backslashit($string) {
$string = preg_replace('/([a-z])/i', '\\\\\1', $string);
return $string;
}
function mysql2date($dateformatstring, $mysqlstring, $use_b2configmonthsdays = 1) {
global $month, $weekday;
$m = $mysqlstring;
if (empty($m)) {
return false;
}
$i = mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4));
if (!empty($month) && !empty($weekday) && $use_b2configmonthsdays) {
$datemonth = $month[date('m', $i)];
$dateweekday = $weekday[date('w', $i)];
$dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit(substr($dateweekday, 0, 3)), $dateformatstring);
$dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
$dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
$dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit(substr($datemonth, 0, 3)), $dateformatstring);
$dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
}
$j = @date($dateformatstring, $i);
if (!$j) {
# // for debug purposes
# echo $i." ".$mysqlstring;
}
return $j;
}
function addslashes_gpc($gpc) {
if (!get_magic_quotes_gpc()) {
$gpc = addslashes($gpc);
}
return($gpc);
}
function date_i18n($dateformatstring, $unixtimestamp) {
global $month, $weekday;
$i = $unixtimestamp;
if ((!empty($month)) && (!empty($weekday))) {
$datemonth = $month[date('m', $i)];
$dateweekday = $weekday[date('w', $i)];
$dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit(substr($dateweekday, 0, 3)), $dateformatstring);
$dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
$dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
$dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit(substr($datemonth, 0, 3)), $dateformatstring);
$dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
}
$j = @date($dateformatstring, $i);
return $j;
}
function get_weekstartend($mysqlstring, $start_of_week) {
$my = substr($mysqlstring,0,4);
$mm = substr($mysqlstring,8,2);
$md = substr($mysqlstring,5,2);
$day = mktime(0,0,0, $md, $mm, $my);
$weekday = date('w',$day);
$i = 86400;
while ($weekday > $start_of_week) {
$weekday = date('w',$day);
$day = $day - 86400;
$i = 0;
}
$week['start'] = $day + 86400 - $i;
$week['end'] = $day + 691199;
return ($week);
}
function convert_chars($content,$flag="html") { // html/unicode entities output, defaults to html
$newcontent = "";
global $convert_chars2unicode, $convert_entities2unicode, $leavecodealone, $use_htmltrans;
global $b2_htmltrans, $b2_htmltranswinuni;
### this is temporary - will be replaced by proper config stuff
$convert_chars2unicode = 1;
if (($leavecodealone) || (!$use_htmltrans)) {
$convert_chars2unicode = 0;
}
###
// converts HTML-entities to their display values in order to convert them again later
$content = preg_replace("/(.+?)<\/title>/","",$content);
$content = preg_replace("/(.+?)<\/category>/","",$content);
# $content = str_replace("&","&",$content);
$content = strtr($content, $b2_htmltrans);
for ($i=0; $i=128) || ($j == "&") || (($jord>=128) && ($jord<=159))) {
$j = "".$jord.";";
}
break;
case "html":
if (($jord>=128) || (($jord>=128) && ($jord<=159))) {
$j = "".$jord.";"; // $j = htmlentities($j);
} elseif (($j == "&") && ($jnext != "#")) {
$j = "&";
}
break;
case "xml":
if ($jord>=128) {
$j = "".$jord.";"; // $j = htmlentities($j);
// $j = htmlentities($j);
} elseif (($j == "&") && ($jnext != "#")) {
$j = "&";
}
break;
}
}
$newcontent .= $j;
}
// now converting: Windows CP1252 => Unicode (valid HTML)
// (if you've ever pasted text from MSWord, you'll understand)
$newcontent = strtr($newcontent, $b2_htmltranswinuni);
// you can delete these 2 lines if you don't like and
$newcontent = str_replace(" "," ",$newcontent);
$newcontent = str_replace("","",$newcontent);
return($newcontent);
}
function convert_bbcode($content) {
global $b2_bbcode, $use_bbcode;
if ($use_bbcode) {
$content = preg_replace($b2_bbcode["in"], $b2_bbcode["out"], $content);
}
$content = convert_bbcode_email($content);
return ($content);
}
function convert_bbcode_email($content) {
global $use_bbcode;
$bbcode_email["in"] = array(
'#\[email](.+?)\[/email]#eis',
'#\[email=(.+?)](.+?)\[/email]#eis'
);
$bbcode_email["out"] = array(
"''.antispambot('\\1').''", // E-mail
"'\\2'"
);
$content = preg_replace($bbcode_email["in"], $bbcode_email["out"], $content);
return ($content);
}
function convert_gmcode($content) {
global $b2_gmcode, $use_gmcode;
if ($use_gmcode) {
$content = preg_replace($b2_gmcode["in"], $b2_gmcode["out"], $content);
}
return ($content);
}
function convert_smilies($content) {
global $smilies_directory, $use_smilies;
global $b2_smiliessearch, $b2_smiliesreplace;
if ($use_smilies) {
$content = str_replace($b2_smiliessearch, $b2_smiliesreplace, $content);
}
return ($content);
}
function antispambot($emailaddy, $mailto=0) {
$emailNOSPAMaddy = '';
srand ((float) microtime() * 1000000);
for ($i = 0; $i < strlen($emailaddy); $i = $i + 1) {
$j = floor(rand(0, 1+$mailto));
if ($j==0) {
$emailNOSPAMaddy .= ''.ord(substr($emailaddy,$i,1)).';';
} elseif ($j==1) {
$emailNOSPAMaddy .= substr($emailaddy,$i,1);
} elseif ($j==2) {
$emailNOSPAMaddy .= '%'.zeroise(dechex(ord(substr($emailaddy, $i, 1))), 2);
}
}
$emailNOSPAMaddy = str_replace('@','@',$emailNOSPAMaddy);
return $emailNOSPAMaddy;
}
function make_clickable($text) { // original function: phpBB, extended here for AIM & ICQ
$ret = " " . $text;
$ret = preg_replace("#([\n ])([a-z]+?)://([^, <>{}\n\r]+)#i", "\\1\\2://\\3", $ret);
$ret = preg_replace("#([\n ])aim:([^,< \n\r]+)#i", "\\1\\2\\3", $ret);
$ret = preg_replace("#([\n ])icq:([^,< \n\r]+)#i", "\\1\\2\\3", $ret);
$ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,< \n\r]*)?)#i", "\\1www.\\2.\\3\\4", $ret);
$ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([^,< \n\r]+)#i", "\\1\\2@\\3", $ret);
$ret = substr($ret, 1);
return($ret);
}
function is_email($user_email) {
$chars = "/^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$/i";
if(strstr($user_email, '@') && strstr($user_email, '.')) {
if (preg_match($chars, $user_email)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
function phpcurlme($string, $language = 'en') {
// by Matt - http://www.photomatt.net/scripts/phpcurlme
// This should take care of the single quotes
$string = preg_replace("/'([dmst])([ .,?!\)\/<])/i","’$1$2",$string);
$string = preg_replace("/'([lrv])([el])([ .,?!\)\/<])/i","’$1$2$3",$string);
$string = preg_replace("/([^=])(\s+)'([^ >])?(.*?)([^=])'(\s*)([^>&])/S","$1$2‘$3$4$5’$6$7",$string);
// time for the doubles
$string = preg_replace('/([^=])(\s+)"([^ >])?(.*?)([^=])"(\s*)([^>&])/S',"$1$2“$3$4$5”$6$7",$string);
// multi-paragraph
$string = preg_replace('/
"(.*)<\/p>/U',"
“$1
",$string);
// not a quote, but whatever
$string = str_replace('---','—',$string);
$string = str_replace('--','–',$string);
return $string;
}
function strip_all_but_one_link($text, $mylink) {
$match_link = '#()(.+?)()#';
preg_match_all($match_link, $text, $matches);
$count = count($matches[0]);
for ($i=0; $i<$count; $i++) {
if (!strstr($matches[0][$i], $mylink)) {
$text = str_replace($matches[0][$i], $matches[2][$i], $text);
}
}
return $text;
}
/***** // Formatting functions *****/
function get_lastpostdate() {
global $tableposts, $cache_lastpostdate, $use_cache, $time_difference, $pagenow;
if ((!isset($cache_lastpostdate)) OR (!$use_cache)) {
$now = date("Y-m-d H:i:s",(time() + ($time_difference * 3600)));
if ($pagenow != 'b2edit.php') {
$showcatzero = 'post_category > 0 AND';
} else {
$showcatzero = '';
}
$sql = "SELECT * FROM $tableposts WHERE $showcatzero post_date <= '$now' ORDER BY post_date DESC LIMIT 1";
$result = mysql_query($sql) or die("Your SQL query: $sql
MySQL said: ".mysql_error());
$querycount++;
$myrow = mysql_fetch_object($result);
$lastpostdate = $myrow->post_date;
$cache_lastpostdate = $lastpostdate;
// echo $lastpostdate;
} else {
$lastpostdate = $cache_lastpostdate;
}
return($lastpostdate);
}
function user_pass_ok($user_login,$user_pass) {
global $cache_userdata,$use_cache;
if ((empty($cache_userdata[$user_login])) OR (!$use_cache)) {
$userdata = get_userdatabylogin($user_login);
} else {
$userdata = $cache_userdata[$user_login];
}
return ($user_pass == $userdata['user_pass']);
}
function get_userdata($userid) {
global $tableusers,$querycount,$cache_userdata,$use_cache;
if ((empty($cache_userdata[$userid])) OR (!$use_cache)) {
$sql = "SELECT * FROM $tableusers WHERE ID = '$userid'";
$result = mysql_query($sql) or die("Your SQL query: $sql
MySQL said: ".mysql_error());
$myrow = mysql_fetch_array($result);
$querycount++;
$cache_userdata[$userid] = $myrow;
} else {
$myrow = $cache_userdata[$userid];
}
return($myrow);
}
function get_userdata2($userid) { // for team-listing
global $tableusers,$row;
$user_data['ID'] = $userid;
$user_data['user_login'] = $row->user_login;
$user_data['user_firstname'] = $row->user_firstname;
$user_data['user_lastname'] = $row->user_lastname;
$user_data['user_nickname'] = $row->user_nickname;
$user_data['user_level'] = $row->user_level;
$user_data['user_email'] = $row->user_email;
$user_data['user_url'] = $row->user_url;
return($user_data);
}
function get_userdatabylogin($user_login) {
global $tableusers,$querycount,$cache_userdata,$use_cache;
if ((empty($cache_userdata["$user_login"])) OR (!$use_cache)) {
$sql = "SELECT * FROM $tableusers WHERE user_login = '$user_login'";
$result = mysql_query($sql) or die("Your SQL query: $sql
MySQL said: ".mysql_error());
if (!$result) die($sql."
".mysql_error());
$myrow = mysql_fetch_array($result);
$querycount++;
$cache_userdata["$user_login"] = $myrow;
} else {
$myrow = $cache_userdata["$user_login"];
}
return($myrow);
}
function get_userid($user_login) {
global $tableusers,$querycount,$cache_userdata,$use_cache;
if ((empty($cache_userdata["$user_login"])) OR (!$use_cache)) {
$sql = "SELECT ID FROM $tableusers WHERE user_login = '$user_login'";
$result = mysql_query($sql) or die("No user with the login $user_login");
$myrow = mysql_fetch_array($result);
$querycount++;
$cache_userdata["$user_login"] = $myrow;
} else {
$myrow = $cache_userdata["$user_login"];
}
return($myrow[0]);
}
function get_usernumposts($userid) {
global $tableusers,$tablesettings,$tablecategories,$tableposts,$tablecomments,$querycount;
$sql = "SELECT * FROM $tableposts WHERE post_author = $userid";
$result = mysql_query($sql) or die("Your SQL query: $sql
MySQL said: ".mysql_error());
$querycount++;
return mysql_num_rows($result);
}
function get_settings($setting) {
global $tablesettings,$querycount,$cache_settings,$use_cache;
if ((empty($cache_settings)) OR (!$use_cache)) {
$sql = "SELECT * FROM $tablesettings";
$result = mysql_query($sql) or die("Your SQL query: $sql
MySQL said: ".mysql_error());
$querycount++;
$myrow = mysql_fetch_object($result);
$cache_settings = $myrow;
} else {
$myrow = $cache_settings;
}
return($myrow->$setting);
}
function get_postdata($postid) {
global $tableusers,$tablesettings,$tablecategories,$tableposts,$tablecomments,$querycount;
$sql = "SELECT * FROM $tableposts WHERE ID = $postid";
$result = mysql_query($sql) or die("Your SQL query: $sql
MySQL said: ".mysql_error());
$querycount++;
if (mysql_num_rows($result)) {
$myrow = mysql_fetch_object($result);
$postdata = array (
'ID' => $myrow->ID,
'Author_ID' => $myrow->post_author,
'Date' => $myrow->post_date,
'Content' => $myrow->post_content,
'Excerpt' => $myrow->post_excerpt,
'Title' => $myrow->post_title,
'Category' => $myrow->post_category,
);
return($postdata);
} else {
return false;
}
}
function get_postdata2($postid=0) { // less flexible, but saves mysql queries
global $row;
$postdata = array (
'ID' => $row->ID,
'Author_ID' => $row->post_author,
'Date' => $row->post_date,
'Content' => $row->post_content,
'Excerpt' => $row->post_excerpt,
'Title' => $row->post_title,
'Category' => $row->post_category,
# 'Notify' => $row->post_notifycomments,
# 'Clickable' => $row->post_make_clickable,
'Karma' => $row->post_karma // this isn't used yet
);
return($postdata);
}
function get_commentdata($comment_ID,$no_cache=0) { // less flexible, but saves mysql queries
global $rowc,$id,$commentdata,$tablecomments,$querycount;
if ($no_cache) {
$query="SELECT * FROM $tablecomments WHERE comment_ID = $comment_ID";
$result=mysql_query($query);
$querycount++;
$myrow = mysql_fetch_array($result);
} else {
$myrow['comment_ID']=$rowc->comment_ID;
$myrow['comment_post_ID']=$rowc->comment_post_ID;
$myrow['comment_author']=$rowc->comment_author;
$myrow['comment_author_email']=$rowc->comment_author_email;
$myrow['comment_author_url']=$rowc->comment_author_url;
$myrow['comment_author_IP']=$rowc->comment_author_IP;
$myrow['comment_date']=$rowc->comment_date;
$myrow['comment_content']=$rowc->comment_content;
$myrow['comment_karma']=$rowc->comment_karma;
if (strstr($myrow['comment_content'], '')) {
$myrow['comment_type'] = 'trackback';
} elseif (strstr($myrow['comment_content'], '')) {
$myrow['comment_type'] = 'pingback';
} else {
$myrow['comment_type'] = 'comment';
}
}
return($myrow);
}
function get_catname($cat_ID) {
global $tablecategories,$cache_catnames,$use_cache,$querycount;
if ((!$cache_catnames) || (!$use_cache)) {
$sql = "SELECT * FROM $tablecategories";
$result = mysql_query($sql) or die('Oops, couldn\'t query the db for categories.');
$querycount;
while ($row = mysql_fetch_object($result)) {
$cache_catnames[$row->cat_ID] = $row->cat_name;
}
}
$cat_name = $cache_catnames[$cat_ID];
return($cat_name);
}
function profile($user_login) {
global $user_data;
echo "$user_login";
}
function dropdown_categories($blog_ID=1) {
global $postdata,$tablecategories,$mode,$querycount;
$query="SELECT * FROM $tablecategories";
$result=mysql_query($query);
$querycount++;
$width = ($mode=="sidebar") ? "100%" : "170px";
echo '";
}
function touch_time($edit=1) {
global $month, $postdata, $time_difference;
// echo $postdata['Date'];
echo '
= "4.0.4pl1") {
if(extension_loaded("zlib")) { ob_start("ob_gzhandler"); }
} else if($phpver > "4.0") {
if(strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip')) {
if(extension_loaded("zlib")) { $do_gzip_compress = TRUE; ob_start(); ob_implicit_flush(0); header("Content-Encoding: gzip"); }
}
} //end gzip compression - that piece of script courtesy of the phpBB dev team
$gzip_compressed=1;
}
}
function alert_error($msg) { // displays a warning box with an error message (original by KYank)
global $$HTTP_SERVER_VARS;
?>
">go back