function cs_cache_save($name, $content, $ttl = 0) { global $cs_main; if (is_bool($content)) { cs_error($name, 'cs_cache_save - It is not allowed to just store a boolean'); } elseif (!is_writeable('uploads/cache/') and $cs_main['mod'] != 'install') { cs_error('uploads/cache/' . $token . '.tmp', 'cs_cache_save - Unable to write cache file'); } return $content; }
function cs_cache_save($name, $content, $ttl = 0) { $token = empty($ttl) ? $name : 'ttl_' . $name; cs_cache_delete($token); if (is_bool($content)) { cs_error($name, 'cs_cache_save - It is not allowed to just store a boolean'); } else { apc_store($token, $content, $ttl); } return $content; }
function cs_phpconfigcheck($name, $exception = 0) { $value = strtolower(ini_get($name)); $array_false = array('0', 'off', 'false'); $array_true = array('1', 'on', 'true'); if (empty($value) or in_array($value, $array_false)) { return false; } elseif (!empty($exception) or in_array($value, $array_true)) { return true; } else { cs_error(__FILE__, 'PHP configuration of "' . $name . '" is not within expected values: "' . $value . '"'); } }
function cs_update_rss($mod, $action, $name, $desc, $array, $abcode = 0) { global $cs_main; $cs_main['rss'] = 1; $abcode = is_array($abcode) ? $abcode : array(0 => 1, 1 => 0, 2 => 0, 3 => 0, 4 => 0); $target = 'uploads/rss/'; $name_sec = htmlspecialchars($name, ENT_NOQUOTES, $cs_main['charset']); $desc_sec = htmlspecialchars($desc, ENT_NOQUOTES, $cs_main['charset']); if (is_writeable($target)) { include_once 'system/output/rss_20.php'; $content = cs_rss_mode(1); $content .= cs_rss_channel(1, $mod, $name_sec, $cs_main['php_self']['website'], $desc_sec); if (!empty($array)) { foreach ($array as $item) { if (!empty($item['id']) and !empty($item['title']) and !empty($item['text'])) { $title = htmlspecialchars($item['title'], ENT_NOQUOTES, $cs_main['charset']); $link = $cs_main['php_self']['website'] . cs_url($mod, $action, 'id=' . $item['id'], 'index'); $text = empty($item['readmore']) ? $item['text'] : $item['readmore']; $text = cs_secure($text, $abcode[0], $abcode[1], $abcode[2], $abcode[3], $abcode[4]); $text = '<![CDATA[ ' . $text . ' ]]>'; if (!empty($abcode[3])) { # use full uri if needed in html content $url_pre = $cs_main['php_self']['website'] . $cs_main['php_self']['dirname']; $pattern = "=(background|href|src)\\=\"(?!http|\\/)(.*?)\"=i"; $text = preg_replace($pattern, "\\1=\"" . $url_pre . "\\2\"", $text); } $date = empty($item['time']) ? 0 : date('D, d M Y H:i:s', $item['time']) . ' +0000'; # author is presented as 'email (nick)' $author = (empty($item['nick']) or empty($item['author'])) ? '' : $item['author'] . ' (' . cs_secure($item['nick']) . ')'; $category = empty($item['cat']) ? '' : htmlspecialchars($item['cat'], ENT_NOQUOTES, $cs_main['charset']); $content .= cs_rss_item($title, $link, $text, $date, $author, $category); } } } $content .= cs_rss_channel(0); $content .= cs_rss_mode(0); $save_file = fopen($target . $mod . '.xml', 'w'); # set stream encoding if possible to avoid converting issues if (function_exists('stream_encoding')) { stream_encoding($save_file, $cs_main['charset']); } fwrite($save_file, $content); fclose($save_file); @chmod($target . $mod . '.xml', 0755); } else { cs_error($target, 'cs_update_rss - Unable to write into directory'); } $cs_main['rss'] = 0; }
function cs_mail_smtp($mail, $options) { # mail content $nl = "\n"; # smtp following rfc 821 $nl_con = "\r\n"; $timeout = 10; $smtp_con = fsockopen($options['smtp_host'], $options['smtp_port'], $errno, $errstr, $timeout); if (!empty($errno)) { cs_error(__FILE__, 'cs_mail_smtp - ' . $errno . ' - ' . $errstr); return false; } else { $host = empty($_SERVER['SERVER_ADDR']) ? $_SERVER['LOCAL_ADDR'] : $_SERVER['SERVER_ADDR']; $mail_top = $mail['headers'] . "To: " . $mail['to'] . $nl . "Subject: " . $mail['subject']; $mail_data = $mail_top . $nl . $nl . $mail['message'] . $nl_con . "."; $mail_com = array('helo' => 'HELO ' . $host, 'login' => 'AUTH LOGIN', 'user' => base64_encode($options['smtp_user']), 'pw' => base64_encode($options['smtp_pw']), 'from' => 'MAIL FROM:' . $mail['from'], 'to' => 'RCPT TO:' . $mail['to'], 'data' => 'DATA', 'response' => $mail_data, 'quit' => 'QUIT'); stream_set_timeout($smtp_con, $timeout); global $cs_logs; if (empty($cs_logs['sql'][__FILE__])) { $cs_logs['sql'][__FILE__] = ''; } static $num = 0; $num++; $log = 'MAIL ' . $num . "\n"; $log .= 'connect: ' . fread($smtp_con, 2048); $cs_logs['sql'][__FILE__] .= $log; foreach ($mail_com as $com_info => $command) { fwrite($smtp_con, $command . $nl_con); $read = fread($smtp_con, 2048); $code = (int) substr($read, 0, 3); $cs_logs['sql'][__FILE__] .= $com_info . ': ' . $read; if ($code >= 400) { cs_error($com_info, 'cs_mail_smtp - Bad status code: ' . substr($read, 0, -2)); return false; } } return true; } }
function cs_resample($image, $target, $max_width, $max_height) { $gd_info = gd_info(); $im_info = array(); if (file_exists($image)) { $im_info = getimagesize($image); } else { cs_error(__FILE__, 'Image file does not exist: "' . $image . '"'); return false; } if ($im_info[2] == 1 and !empty($gd_info["GIF Read Support"])) { $src = ImageCreateFromGIF($image); } elseif ($im_info[2] == 2 and (!empty($gd_info["JPG Support"]) or !empty($gd_info["JPEG Support"]))) { $src = ImageCreateFromJPEG($image); } elseif ($im_info[2] == 3 and !empty($gd_info["PNG Support"])) { $src = ImageCreateFromPNG($image); } else { cs_error(__FILE__, 'Image filetype is not supported: "' . $image . '"'); return false; } $factor = max($im_info[1] / $max_height, $im_info[0] / $max_width); $im_new[0] = floor($im_info[0] / $factor); $im_new[1] = floor($im_info[1] / $factor); $dst = ImageCreateTrueColor($im_new[0], $im_new[1]); ImageAlphaBlending($dst, false); ImageSaveAlpha($dst, true); ImageCopyResampled($dst, $src, 0, 0, 0, 0, $im_new[0], $im_new[1], $im_info[0], $im_info[1]); if ($im_info[2] == 1) { $return = ImageGIF($dst, $target) ? 1 : 0; } elseif ($im_info[2] == 2) { $return = ImageJPEG($dst, $target, 100) ? 1 : 0; } elseif ($im_info[2] == 3) { $return = ImagePNG($dst, $target) ? 1 : 0; } else { cs_error(__FILE__, 'Failed to write resampled image file: "' . $target . '"'); return false; } return $return; }
function cs_cache_save($name, $content, $ttl = 0) { $token = empty($ttl) ? $name : 'ttl_' . $name; cs_cache_delete($token); global $cs_main; if (is_bool($content)) { cs_error($name, 'cs_cache_save - It is not allowed to just store a boolean'); } elseif (is_writeable('uploads/cache/')) { $store = serialize($content); $cache_file = 'uploads/cache/' . $token . '.tmp'; $save_cache = fopen($cache_file, 'a'); # set stream encoding if possible to avoid converting issues if (function_exists('stream_encoding')) { stream_encoding($save_cache, $cs_main['charset']); } fwrite($save_cache, $store); fclose($save_cache); chmod($cache_file, 0755); } elseif ($cs_main['mod'] != 'install') { cs_error('uploads/cache/' . $token . '.tmp', 'cs_cache_save - Unable to write cache file'); } return $content; }
function cs_cache_template($filename) { global $cs_main; $tpl_real = 'templates/' . $cs_main['template'] . '/' . $filename; $tpl_temp = 'tpl_' . $cs_main['template'] . '_' . $cs_main['php_self']['filename'] . '_' . $filename; $tpl_data = cs_cache_load($tpl_temp); if ($tpl_data != false) { if ($cs_main['cache_mode'] != 'file' or filemtime($tpl_real) < filemtime('uploads/cache/' . $tpl_temp . '.tmp')) { return $tpl_data; } } $tpl_data = file_get_contents($tpl_real); $tpl_path = $cs_main['php_self']['dirname'] . 'templates/' . $cs_main['template']; $tpl_data = str_replace('{func:path}', $cs_main['php_self']['dirname'], $tpl_data); if (strpos($tpl_data, 'id="csp_content"') !== false) { cs_error($tpl_real, 'cs_cache_template - The ID tag "csp_content" is reserved for AJAX'); } if (strpos($tpl_data, '{func:stylesheet}') === false) { $tpl_data = str_ireplace('</head>', '{func:stylesheet}</head>', $tpl_data); } if (strpos($tpl_data, '{func:javascript}') === false) { $tpl_data = str_ireplace('</body>', '{func:javascript}</body>', $tpl_data); } if (strpos($tpl_data, '{func:debug}') === false) { $tpl_data = preg_replace('=\\<body(.*?)\\>=si', "<body\\1{func:body_add}>\n{func:debug}", $tpl_data, 1); } else { $tpl_data = preg_replace('=\\<body(.*?)\\>=si', '<body\\1{func:body_add}>', $tpl_data, 1); } $pattern = "=\\<link(.*?)href\\=\"(?!http|\\/)(.*?)\"(.*?)\\>=i"; $tpl_data = preg_replace($pattern, "<link\\1href=\"" . $tpl_path . "/\\2\"\\3>", $tpl_data); $pattern = "=(background|src)\\=\"(?!http|\\/)(.*?)\"=i"; $tpl_data = preg_replace($pattern, "\\1=\"" . $tpl_path . "/\\2\"", $tpl_data); $tpl_data = preg_replace_callback('={url(?:_([\\w]*?))?:([\\w]*?)(?:_([\\w]*?)((?::(?:(?:[\\S]*?{[\\S]*?}[\\S]*?)*?|[\\S]*?))*?))?}=i', 'cs_templateurl', $tpl_data); $tpl_data = str_replace('{func:charset}', $cs_main['charset'], $tpl_data); $tpl_data = cs_tokenizer_split($tpl_data); return cs_cache_save($tpl_temp, $tpl_data); }
function cs_cups_addteam2match($cups_id, $teamid, $prevmatchid, $prevmatchround, $prevmatchlb, $matchid, $is_admin) { $return = true; $match = cs_sql_select(__FILE__, 'cupmatches', '*', 'cups_id = ' . $cups_id . ' AND cupmatches_match = ' . $matchid, 0, 0, 1); if (empty($match['cupmatches_id'])) { cs_error(__FILE__, 'ERROR: unknown match #' . $matchid . ' for cup #' . $cups_id, 1); return false; } /* get the other match which is referencing to this match */ $othermatch = cs_sql_select(__FILE__, 'cupmatches', '*', 'cups_id = ' . $cups_id . ' AND (cupmatches_nextmatch = ' . $matchid . ' OR cupmatches_nextmatchlb = ' . $matchid . ') AND cupmatches_match <> ' . $prevmatchid, 0, 0, 1); if (empty($match['cupmatches_id'])) { cs_error(__FILE__, 'ERROR: unknown other match for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); return false; } /* determine on which position this team has to be put */ if ($match['cupmatches_loserbracket'] == 0) { if ($match['cupmatches_match'] != 0) { /* this match is in the winner bracket, so both previous matches should be from the same round */ if ($prevmatchround != $othermatch['cupmatches_round']) { cs_error(__FILE__, 'ERROR: other match for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid . ' not in the same round', 1); $return = false; } /* place the team according to match number */ if ($prevmatchid < $othermatch['cupmatches_match']) { /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } else { /* grand final or 3rd place match */ if ($prevmatchlb == 1 || $othermatch['cupmatches_loserbracket'] == 1) { /* grand final, since one of them comes from a loserbracket */ if ($prevmatchlb == 0) { /* team coming from wb */ /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB GF: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB GF: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* team coming from lb */ /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB GF: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB GF: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } else { /* 3rd place match */ /* place the team according to match number */ if ($prevmatchid < $othermatch['cupmatches_match']) { /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB 3RD: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB 3RD: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING WB 3RD: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR WB 3RD: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } } } else { if ($prevmatchlb == 0 || $othermatch['cupmatches_loserbracket'] == 0) { /* one of them comes from the winner bracket, so it's a half round match */ if ($prevmatchlb == 0) { /* team comes from wb */ if ($othermatch['cupmatches_loserbracket'] == 0) { /* both come from wb (first round LB) */ if ($prevmatchid < $othermatch['cupmatches_match']) { /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB 1RD: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB 1RD: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB 1RD: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB 1RD: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } else { /* this team comes from wb, place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB FWB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB FWB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } } else { /* team comes from lb */ /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB FWB: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB FWB: position2 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } else { /* both of them coming from LB */ /* place the team according to match number */ if ($prevmatchid < $othermatch['cupmatches_match']) { /* place on position 1 */ if ($match['squad1_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNIGN LB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad1_id'); } else { /* place on position 2 */ if ($match['squad2_id'] != CS_CUPS_TEAM_UNKNOWN) { if ($is_admin) { cs_error(__FILE__, 'WARNING LB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } else { cs_error(__FILE__, 'ERROR LB: position1 in use other for match #' . $matchid . ' for cup #' . $cups_id . ' and prevmatch #' . $prevmatchid, 1); } $return = false; } $cells = array('squad2_id'); } } } /* we have determined the position */ $values = array($teamid); cs_sql_update(__FILE__, 'cupmatches', $cells, $values, $match['cupmatches_id']); if (function_exists('cs_datacache_load')) { cs_datacache_clear('cups'); } /* if there were any admin matchedits, fix tree recursively */ cs_cups_autofix($cups_id); return $return; }
if (version_compare(phpversion(), '5.2.0', '>')) { session_set_cookie_params(0, $cs_main['cookie']['path'], $cs_main['cookie']['domain'], FALSE, TRUE); } else { session_set_cookie_params(0, $cs_main['cookie']['path'], $cs_main['cookie']['domain']); } session_name('cs' . md5($cs_main['cookie']['domain'])); session_start(); # xsrf protection if ($cs_main['xsrf_protection'] === TRUE && !empty($_POST)) { $needed_keys = isset($_SESSION['cs_xsrf_keys']) ? $_SESSION['cs_xsrf_keys'] : array(); $given_key = isset($_POST['cs_xsrf_key']) ? $_POST['cs_xsrf_key'] : ''; if (empty($given_key) || !in_array($given_key, $needed_keys)) { $_SESSION['cs_xsrf_keys'] = array(); $referer = empty($_SERVER['HTTP_REFERER']) ? 'empty' : $_SERVER['HTTP_REFERER']; if (!empty($cs_main['developer'])) { cs_error(__FILE__, 'XSRF Protection triggered: Array(' . implode(', ', $needed_keys) . ') does not include "' . $given_key . '", Referer: ' . $referer); } cs_redirect(false, $cs_main['def_mod'], $cs_main['def_action']); } } if (empty($_SESSION['users_id'])) { if (isset($_POST['login'])) { $login['method'] = 'form'; $login['nick'] = $_POST['nick']; $login['password'] = $_POST['password']; if ($cs_db['hash'] == 'md5') { $login['securepw'] = md5($login['password']); } if ($cs_db['hash'] == 'sha1') { $login['securepw'] = sha1($login['password']); }
for ($run = 0; $run < $count_voted; $run++) { $votes_cells = array('voted_fid', 'users_id', 'voted_time', 'voted_answer', 'voted_ip', 'voted_mod'); $votes_save = array($votes_id, $users_id, $time, $voted_answer[$run], $users_ip, $mod); if (!empty($voted_answer[$run])) { cs_sql_insert(__FILE__, 'voted', $votes_cells, $votes_save); } else { cs_error(__FILE__, 'Empty answer for multivote with ID ' . $cs_votes_id); } } } else { $votes_cells = array('voted_fid', 'users_id', 'voted_time', 'voted_answer', 'voted_ip', 'voted_mod'); $votes_save = array($votes_id, $users_id, $time, $voted_answer, $users_ip, $mod); if (!empty($voted_answer)) { cs_sql_insert(__FILE__, 'voted', $votes_cells, $votes_save); } else { cs_error(__FILE__, 'Empty answer for singlevote with ID ' . $cs_votes_id); } } cs_redirect($cs_lang['create_done'], 'votes', 'list'); } else { $votes_form = 0; cs_redirect($cs_lang['error_occurred'], 'votes', 'list'); } } if (!empty($cs_votes) and !empty($votes_form)) { $from = 'voted'; $select = 'voted_id, users_id, voted_ip, voted_answer'; $where = "voted_fid = \"" . $votes_id . "\" AND voted_mod = 'votes'"; $cs_voted = cs_sql_select(__FILE__, $from, $select, $where, '', '0', '0'); $voted_loop = count($cs_voted); $check_user_voted = 0;
function php_error($errno, $errmsg, $filename, $linenum) { global $cs_logs, $cs_main; $silent = error_reporting() === 0 ? 1 : 0; $errortype = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice'); // Added E_Strict for PHP 5 Version $errortype['2048'] = 'Strict Notice/Error'; // Added E_RECOVERABLE_ERROR for PHP 5.2.0 Version if (substr(phpversion(), 0, 3) >= '5.2') { $errortype['4096'] = 'Recoverable Error'; } // Added E_DEPRECATED & E_USER_DEPRECATED for PHP 5.3.0 Version if (substr(phpversion(), 0, 3) >= '5.3') { $errortype['8192'] = 'Deprecate Notice'; $errortype['16384'] = 'User Deprecated Warning'; } $error = empty($silent) ? '' : '(@) '; $error .= $errortype[$errno] . ": " . $errmsg . " in " . $filename . " on line " . $linenum . "\r\n"; $cs_logs['php_errors'] = empty($cs_logs['php_errors']) ? '' : $cs_logs['php_errors']; $cs_logs['php_errors'] .= '<strong>PHP-Warning:</strong> ' . $error . "<br />"; if (empty($silent)) { cs_error($filename, 'PHP ' . $errortype[$errno] . ' on line ' . $linenum . ' -> ' . trim($errmsg), 1); } }
function cs_template($cs_micro, $tpl_file = 'index.htm') { global $account, $cs_logs, $cs_main; if ((empty($cs_main['public']) or $tpl_file == 'admin.htm' and $account['access_clansphere'] < 3) and $account['access_clansphere'] < $cs_main['maintenance_access']) { $cs_main['show'] = 'mods/users/login.php'; $tpl_file = 'login.htm'; $cs_main['ajax'] = 0; } if (!empty($account['users_tpl'])) { $cs_main['template'] = $account['users_tpl']; } if (!empty($_GET['template'])) { $cs_main['template'] = str_replace(array('.', '/'), '', $_GET['template']); } if (!empty($_SESSION['tpl_preview'])) { $cs_main['template'] = str_replace(array('.', '/'), '', $_SESSION['tpl_preview']); } if ($tpl_file == 'error.htm') { $cs_main['template'] = 'install'; } if ($cs_main['template'] != $cs_main['def_tpl'] and !is_dir('templates/' . $cs_main['template'])) { $cs_main['template'] = $cs_main['def_tpl']; } $tpl_path = $cs_main['def_path'] . '/templates/' . $cs_main['template'] . '/' . $tpl_file; if (!file_exists($tpl_path)) { cs_error($tpl_path, 'cs_template - Template file not found'); $msg = 'Template file not found: ' . $tpl_file; if ($tpl_file != 'error.htm') { die(cs_error_internal('tpl', $msg)); } else { die($msg); } } # Initalize array of upcoming additions and get show content $replace = array('func:body_add' => ''); $replace['func:show'] = '<div id="csp_content">' . cs_contentload($cs_main['show']) . '</div>'; if (isset($cs_main['ajax']) and $cs_main['ajax'] == 2 or !empty($account['users_ajax']) and !empty($account['access_ajax'])) { $replace['func:body_add'] = ' onload="Clansphere.initialize(' . $cs_main['mod_rewrite'] . ',\'' . $_SERVER['SCRIPT_NAME'] . '\',' . $cs_main['ajax_reload'] * 1000 . ')"'; } # Provide the def_title and a title with more information $replace['func:title_website'] = htmlentities($cs_main['def_title'], ENT_QUOTES, $cs_main['charset']); $replace['func:title'] = cs_title(); # Fetch template file and parse exploded contents $template = cs_cache_template($tpl_file); $template = cs_tokenizer_parse($template); # Add scriptload to replaces global $cs_main; $replace['func:stylesheet'] = empty($cs_main['scriptload']['stylesheet']) ? '' : $cs_main['scriptload']['stylesheet']; $replace['func:javascript'] = empty($cs_main['scriptload']['javascript']) ? '' : $cs_main['scriptload']['javascript']; # Prepare debug and log data $debug = ''; $logsql = ''; if (!empty($cs_main['developer']) or $account['access_clansphere'] > 4) { $cs_logs['php_errors'] = nl2br($cs_logs['php_errors']); $cs_logs['errors'] = nl2br($cs_logs['errors']); $logsql = cs_log_format('sql'); } else { $cs_logs['php_errors'] = ''; $cs_logs['errors'] = 'Developer mode is turned off'; } if (!empty($cs_main['debug'])) { $data = array('data'); $data['data']['log_sql'] = $logsql; $data['data']['php_errors'] = $cs_logs['php_errors']; $data['data']['csp_errors'] = $cs_logs['errors']; $debug = cs_subtemplate(__FILE__, $data, 'clansphere', 'debug'); } $replace['func:queries'] = $cs_logs['queries']; $replace['func:errors'] = $cs_logs['php_errors'] . $cs_logs['errors']; $replace['func:sql'] = $logsql; $replace['func:debug'] = $debug; $replace['func:parse'] = cs_parsetime($cs_micro); $replace['func:memory'] = function_exists('memory_get_usage') ? cs_filesize(memory_get_usage()) : '-'; if (function_exists('memory_get_peak_usage')) { $replace['func:memory'] .= ' [peak ' . cs_filesize(memory_get_peak_usage()) . ']'; } # Assemble content parts $result = ''; foreach ($template as $num => $content) { if (array_key_exists($content, $replace)) { $result .= $replace[$content]; } else { $result .= $content; } } # Enable zlib output compression if possible if (!empty($cs_main['zlib']) and extension_loaded('zlib')) { ob_start('ob_gzhandler'); } # Send content type header with charset header('Content-type: text/html; charset=' . $cs_main['charset']); return $result; }
$sql_infos = cs_sql_version(__FILE__); foreach ($modules as $mod) { if (!empty($mod['tables'][0])) { $tables = ''; $counts = ''; if (!empty($mod['icon'])) { $data['statistic'][$run]['icon'] = cs_icon($mod['icon']); } else { $data['statistic'][$run]['icon'] = ''; } $data['statistic'][$run]['url'] = cs_url('modules', 'view', 'dir=' . $mod['dir']); $data['statistic'][$run]['name'] = $mod['name']; asort($mod['tables']); foreach ($mod['tables'] as $mod_table) { if (isset($static[$mod_table])) { cs_error(__FILE__, 'SQL-Table "' . $mod_table . '" is owned by two modules: "' . $static[$mod_table] . '" and "' . $mod['dir'] . '"'); } else { $static[$mod_table] = $mod['dir']; $tables .= $mod_table . cs_html_br(1); $datasets = cs_sql_count(__FILE__, $mod_table); $counts .= $datasets . cs_html_br(1); $total_tables++; $total_datasets = $total_datasets + $datasets; } } $data['statistic'][$run]['tables'] = $tables; $data['statistic'][$run]['counts'] = $counts; $run++; } } $data['data']['tables'] = $total_tables;
function cs_filetype($name) { global $cs_main; switch ($name) { case 'ace': case 'zip': case 'rar': case 'tar': case '7z': case 'iso': $ext = 'archive'; break; case 'bmp': case 'gif': case 'jpeg': case 'jpg': case 'png': case 'psd': case 'ico': $ext = 'image'; break; case 'midi': case 'mp3': case 'wav': case 'wma': case 'ogg': $ext = 'sound'; break; case 'pdf': $ext = 'pdf'; break; case 'php': $ext = 'php'; break; case 'dir': $ext = 'dir'; break; case 'exe': $ext = 'executable'; break; case 'sql': $ext = 'database'; break; case 'html': case 'shtml': case 'xml': $ext = 'html'; break; case 'txt': case 'ini': $ext = 'text'; break; case 'doc': case 'docx': case 'tpl': case 'odt': $ext = 'document'; break; case 'mov': case 'mpeg': case 'mpg': case 'rm': case 'wmv': case 'swf': $ext = 'video'; break; default: $ext = 'unknown'; } $iconpath = 'symbols/files/filetypes/' . $ext . '.gif'; if (file_exists($iconpath)) { return cs_html_img($iconpath, 16, 16, 0, $name); } else { cs_error($iconpath, 'cs_fileicon - File not found'); } }
function cs_url($mod, $action = 'list', $more = 0, $base = 0, $placeholder = 0) { global $cs_main, $account; if (!file_exists('mods/' . $mod . '/' . $action . '.php')) { if (empty($placeholder)) { cs_error('mods/' . $mod . '/' . $action . '.php', 'cs_url - File not found'); } else { return $action == 'list' ? '{url:' . $mod . '}' : '{url:' . $mod . '_' . $action . '}'; } } $return = $cs_main['php_self']['dirname']; if (empty($cs_main['mod_rewrite'])) { $base = empty($base) ? $cs_main['php_self']['basename'] : $base . '.php'; $return .= $base . '?mod=' . $mod . '&action=' . $action; return empty($more) ? $return : $return . '&' . $more; } else { $base = empty($base) ? $cs_main['php_self']['filename'] : $base; $return .= $base . '/' . $mod . '/' . $action; return empty($more) ? $return : $return . '/' . strtr($more, array('&' => '/', '=' => '/', '&' => '/')); } }
<?php // ClanSphere 2010 - www.clansphere.net // $Id$ $cs_lang = cs_translate('users'); $data = array(); $data['options'] = cs_sql_option(__FILE__, 'users'); $styles_array = array('horizontal', 'icons', 'picture'); $style = ''; if (!empty($_GET['style'])) { if (in_array($_GET['style'], $styles_array)) { $style = '_' . $_GET['style']; } else { cs_error($_GET['style'], 'The given navlogin style cannot be found'); } } global $login; if (empty($login['mode'])) { if (empty($login['nick'])) { $login['nick'] = 'Nick'; if ($data['options']['login'] == 'email') { $login['nick'] = 'E-Mail'; } } if (empty($login['password'])) { $login['password'] = '******'; } $data['form']['navlogin'] = cs_url('users', 'login'); $data['login']['nick'] = cs_secure($login['nick']); $data['login']['password'] = cs_secure($login['password']); $data['link']['uri'] = cs_url_self();