function get($name, $get_miss_key_callback = '', $ttl = 604800) { if (empty($name)) { return is_array($name) ? array() : false; } $this->db->shard($name); $cached_items = array(); $this->prefix_len = strlen($this->prefix); $this->prefix_sql = SQLite3::escapeString($this->prefix); $name_ary = $name_sql = (array) $name; array_deep($name_sql, 'SQLite3::escapeString'); // get available items $rowset = $this->db->fetch_rowset("\n\t\t\tSELECT cache_name, cache_value\n\t\t\tFROM " . $this->cfg['table_name'] . "\n\t\t\tWHERE cache_name IN('{$this->prefix_sql}" . join("','{$this->prefix_sql}", $name_sql) . "') AND cache_expire_time > " . TIMENOW . "\n\t\t\tLIMIT " . count($name) . "\n\t\t"); $this->db->debug('start', 'unserialize()'); foreach ($rowset as $row) { $cached_items[substr($row['cache_name'], $this->prefix_len)] = unserialize($row['cache_value']); } $this->db->debug('stop'); // get miss items if ($get_miss_key_callback and $miss_key = array_diff($name_ary, array_keys($cached_items))) { foreach ($get_miss_key_callback($miss_key) as $k => $v) { $this->set($this->prefix . $k, $v, $ttl); $cached_items[$k] = $v; } } // return if (is_array($this->prefix . $name)) { return $cached_items; } else { return isset($cached_items[$name]) ? $cached_items[$name] : false; } }
function build_filelist_array() { $info = $this->tor_decoded['info']; if (isset($info['name.utf-8'])) { $info['name'] =& $info['name.utf-8']; } if (isset($info['files']) && is_array($info['files'])) { $this->root_dir = isset($info['name']) ? '../' . clean_tor_dirname($info['name']) : '...'; $this->multiple = true; foreach ($info['files'] as $f) { if (isset($f['path.utf-8'])) { $f['path'] =& $f['path.utf-8']; } if (!isset($f['path']) || !is_array($f['path'])) { continue; } array_deep($f['path'], 'clean_tor_dirname'); $length = isset($f['length']) ? (double) $f['length'] : 0; $subdir_count = count($f['path']) - 1; if ($subdir_count > 0) { $name = array_pop($f['path']); $cur_files_ary =& $this->files_ary; for ($i = 0, $j = 1; $i < $subdir_count; $i++, $j++) { $subdir = $f['path'][$i]; if (!isset($cur_files_ary[$subdir])) { $cur_files_ary[$subdir] = array(); } $cur_files_ary =& $cur_files_ary[$subdir]; if ($j == $subdir_count) { if (is_string($cur_files_ary)) { $GLOBALS['bnc_error'] = 1; break 1; } $cur_files_ary[] = $this->build_file_item($name, $length); } } @natsort($cur_files_ary); } else { $name = $f['path'][0]; $this->files_ary['/'][] = $this->build_file_item($name, $length); natsort($this->files_ary['/']); } } } else { $this->multiple = false; $name = isset($info['name']) ? clean_tor_dirname($info['name']) : ''; $length = isset($info['length']) ? (double) $info['length'] : 0; $this->files_ary['/'][] = $this->build_file_item($name, $length); natsort($this->files_ary['/']); } }
function _fetch_from_store() { if (!($items = $this->queued_items)) { return; } $prefix_len = strlen($this->prefix); $prefix_sql = SQLite3::escapeString($this->prefix); array_deep($items, 'SQLite3::escapeString'); $items_list = $prefix_sql . join("','{$prefix_sql}", $items); $rowset = $this->db->fetch_rowset("SELECT ds_title, ds_data FROM " . $this->cfg['table_name'] . " WHERE ds_title IN ('{$items_list}')"); $this->db->debug('start', "unserialize()"); foreach ($rowset as $row) { $this->data[substr($row['ds_title'], $prefix_len)] = unserialize($row['ds_data']); } $this->db->debug('stop'); }
function replace_synonyms($text) { static $syn_match = null, $syn_replace = null; if (is_null($syn_match)) { preg_match_all("#(\\w+) (\\w+)(\r?\n|\$)#", @file_get_contents(LANG_DIR . 'search_synonyms.txt'), $m); $syn_match = $m[2]; $syn_replace = $m[1]; array_deep($syn_match, 'pad_with_space'); array_deep($syn_replace, 'pad_with_space'); } return $syn_match && $syn_replace ? str_replace($syn_match, $syn_replace, $text) : $text; }
<?php if (!empty($setmodules)) { $module['FORUMS']['MANAGE'] = basename(__FILE__); return; } require './pagestart.php'; require INC_DIR . 'functions_group.php'; array_deep($_POST, 'trim'); $s = ''; $default_forum_auth = array('auth_view' => AUTH_ALL, 'auth_read' => AUTH_ALL, 'auth_post' => AUTH_REG, 'auth_reply' => AUTH_REG, 'auth_edit' => AUTH_REG, 'auth_delete' => AUTH_REG, 'auth_sticky' => AUTH_MOD, 'auth_announce' => AUTH_MOD, 'auth_vote' => AUTH_REG, 'auth_pollcreate' => AUTH_REG, 'auth_attachments' => AUTH_REG, 'auth_download' => AUTH_REG); $mode = @$_REQUEST['mode'] ? (string) $_REQUEST['mode'] : ''; $cat_forums = get_cat_forums(); if ($orphan_sf_sql = get_orphan_sf()) { fix_orphan_sf($orphan_sf_sql, TRUE); } $forum_parent = $cat_id = 0; $forumname = ''; if (isset($_REQUEST['addforum']) || isset($_REQUEST['addcategory'])) { $mode = isset($_REQUEST['addforum']) ? "addforum" : "addcat"; if ($mode == 'addforum' && isset($_POST['addforum']) && isset($_POST['forumname']) && is_array($_POST['addforum'])) { $req_cat_id = array_keys($_POST['addforum']); $cat_id = $req_cat_id[0]; $forumname = stripslashes($_POST['forumname'][$cat_id]); } } $show_main_page = false; if ($mode) { switch ($mode) { case 'addforum': case 'editforum':
function build_sql($sql_ary) { $sql = ''; array_deep($sql_ary, 'array_unique', false, true); foreach ($sql_ary as $clause => $ary) { switch ($clause) { case 'SELECT': $sql .= $ary ? ' SELECT ' . join(' ', $sql_ary['select_options']) . ' ' . join(', ', $ary) : ''; break; case 'FROM': $sql .= $ary ? ' FROM ' . join(', ', $ary) : ''; break; case 'INNER JOIN': $sql .= $ary ? ' INNER JOIN ' . join(' INNER JOIN ', $ary) : ''; break; case 'LEFT JOIN': $sql .= $ary ? ' LEFT JOIN ' . join(' LEFT JOIN ', $ary) : ''; break; case 'WHERE': $sql .= $ary ? ' WHERE ' . join(' AND ', $ary) : ''; break; case 'GROUP BY': $sql .= $ary ? ' GROUP BY ' . join(', ', $ary) : ''; break; case 'HAVING': $sql .= $ary ? ' HAVING ' . join(' AND ', $ary) : ''; break; case 'ORDER BY': $sql .= $ary ? ' ORDER BY ' . join(', ', $ary) : ''; break; case 'LIMIT': $sql .= $ary ? ' LIMIT ' . join(', ', $ary) : ''; break; } } return trim($sql); }
preg_match('#\\d+#', (string) $this->request['tpl_rules'], $m); $tpl_rules_post_id = isset($m[0]) ? (int) $m[0] : 0; $sql_args = array('tpl_name' => (string) $tpl_name, 'tpl_src_form' => (string) $tpl_src_form, 'tpl_src_title' => (string) $tpl_src_title, 'tpl_src_msg' => (string) $tpl_src_msg, 'tpl_comment' => (string) $tpl_comment, 'tpl_rules_post_id' => (int) $tpl_rules_post_id, 'tpl_last_edit_tm' => (int) TIMENOW, 'tpl_last_edit_by' => (int) $userdata['user_id']); break; } // выполнение switch ($mode) { // загрузка шаблона case 'load': $this->response['val']['tpl-name-save'] = $tpl_data['tpl_name']; $this->response['val']['tpl-src-form'] = $tpl_data['tpl_src_form']; $this->response['val']['tpl-src-title'] = $tpl_data['tpl_src_title']; $this->response['val']['tpl-src-msg'] = $tpl_data['tpl_src_msg']; $this->response['val']['tpl-comment-save'] = $tpl_data['tpl_comment']; $this->response['val']['tpl-rules-save'] = $tpl_data['tpl_rules_post_id']; array_deep($this->response['val'], 'html_ent_decode'); $this->response['val']['tpl-id-save'] = $tpl_id; $this->response['val']['tpl-last-edit-tst'] = $tpl_data['tpl_last_edit_tm']; $this->response['html']['tpl-name-old-save'] = $tpl_data['tpl_name']; $this->response['html']['tpl-last-edit-time'] = bb_date($tpl_data['tpl_last_edit_tm'], 'd-M-y H:i'); $this->response['html']['tpl-last-edit-by'] = get_username(intval($tpl_data['tpl_last_edit_by'])); $this->response['tpl_rules_href'] = POST_URL . $tpl_data['tpl_rules_post_id'] . '#' . $tpl_data['tpl_rules_post_id']; break; // включение / отключение шаблона в форуме // включение / отключение шаблона в форуме case 'assign': if (!($tpl_id = (int) $this->request['tpl_id'])) { $this->ajax_die('Выбранный шаблон не найден, создайте новый (empty tpl_id)'); } if (!($forum_id = (int) $this->request['forum_id'])) { $this->ajax_die('empty forum_id');
/** * SqlError * Private * @param string $msg error message (mysql_error($db)) * @param object $self is the $this where the error occured * @param bool $echo if true we do an echo else return string * @return array([html error text], [error number]); */ private function SqlError($msg = "NO MESSAGE PROVIDED", $self) { $Error = "NO ERROR MESSAGE FOUND"; $Errno = -1; if (is_null($self) || is_null($errDb = $self->getDb()) || $self->getDb() === 0) { if (isset($self->errno) && isset($self->error)) { $Errno = $self->errno; $Error = $self->error; } else { $Errno = -9999; $Error = "Self db not valid"; } } else { if (method_exists($self, 'getErrorInfo')) { $err = $self->getErrorInfo(); // from the database engine, like mysqli etc. $Error = $err['error']; $Errno = $err['errno']; } else { throw new Exception("method getErrorInfo missing"); } } if (($size = strlen($msg)) > 500) { $msg = "Message Too Long: {$size}"; } if (($size = strlen($Error)) > 500) { $Error = "Error Too Long: {$size}"; } $backtrace = debug_backtrace(); // trace back information $caller = $backtrace[1]; // Get caller information array_shift($backtrace); // SqlError array_shift($backtrace); // SqlException $firstcaller = ''; // Helper callback function if (!function_exists('array_deep')) { // If it does not already exist define it here function array_deep($a) { if (is_array($a)) { $a = array_map('array_deep', $a); $ret = ""; foreach ($a as $key => $val) { if (is_numeric($key)) { $ret .= "{$val}, "; } else { $ret .= "{$key}=>{$val}"; } } $ret = rtrim($ret, ", "); $a = "array({$ret})"; } else { if (is_string($a)) { if (strpos($a, "'")) { $a = "\"{$a}\""; } else { $a = "'{$a}', "; } } elseif (is_numeric($a)) { $a = "{$a}, "; } } return $a; } } $args = ''; if (count($backtrace)) { foreach ($backtrace as $bk) { $args = ''; if ($bk['args']) { foreach ($bk['args'] as $arg) { if (is_object($arg)) { continue; } if (is_string($arg)) { if (strpos($arg, "'")) { $args .= "\"{$arg}\", "; } else { $args .= "'{$arg}', "; } } elseif (is_numeric($arg)) { $args .= "{$arg}, "; } elseif (is_array($arg)) { $args .= array_deep($arg); } } $args = rtrim($args, ", "); } //if(($size = strlen($args)) > 500) $msg = "args Too Long: $size"; if ($bk['class']) { $classfunc = "<b>{$bk['class']}::{$bk['function']}({$args})</b>"; } else { $classfunc = "function <b>{$bk['function']}({$args})</b>"; } $firstcaller .= "{$classfunc}<br>in <b>{$bk['file']}</b><br>" . "on line <b>{$bk['line']}</b><br>"; } } $error = <<<EOF <p>"<i>{$msg}</i>" error="<i>{$Error}</i>", errno="<i>{$Errno}</i>"<br> called from <strong>{$caller['file']}</strong><br> on line <strong>{$caller['line']}</strong><br> EOF; if (isset($firstcaller)) { $error .= "Back Trace:<br>{$firstcaller}"; } return array($error, $Errno); }
} delete_permissions($group_id, null, $cat_id); store_permissions($group_id, $auth); update_user_level($user_id); $l_auth_return = $mode == 'user' ? $lang['CLICK_RETURN_USERAUTH'] : $lang['CLICK_RETURN_GROUPAUTH']; $message = $lang['AUTH_UPDATED'] . '<br /><br />'; $message .= sprintf($l_auth_return, '<a href="admin_ug_auth.php?mode=' . $mode . '">', '</a>') . '<br /><br />'; $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'); bb_die($message); } else { if ($submit && $mode == 'group' && is_array(@$_POST['auth'])) { if (!($group_data = get_group_data($group_id))) { bb_die($lang['GROUP_NOT_EXIST']); } $auth = array(); array_deep($_POST['auth'], 'intval'); foreach ($_POST['auth'] as $f_id => $bf_ary) { if (array_sum($bf_ary)) { $auth[$f_id] = bit2dec(array_keys($bf_ary, 1)); } } delete_permissions($group_id, null, $cat_id); store_permissions($group_id, $auth); update_user_level('all'); $l_auth_return = $lang['CLICK_RETURN_GROUPAUTH']; $message = $lang['AUTH_UPDATED'] . '<br /><br />'; $message .= sprintf($l_auth_return, '<a href="admin_ug_auth.php?mode=' . $mode . '">', '</a>') . '<br /><br />'; $message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'); bb_die($message); } }
$datastore->rm('cat_forums'); // Get current search settings if (!$set_default) { // Search in forum or category // Get requested cat_id $search_in_forums_fary = array(); if ($req_cat_id =& $_REQUEST[$cat_key]) { if (isset($cat_forum['c'][$req_cat_id])) { $valid_forums = $cat_forum['c'][$req_cat_id]; $forum_val = join(',', $valid_forums); } } else { if ($req_forums =& $_REQUEST[$forum_key]) { if ($req_forums != $search_all) { $req_forums = (array) $req_forums; array_deep($req_forums, 'intval'); $valid_forums = array_intersect($req_forums, $allowed_forums); $forum_val = join(',', $valid_forums); } } else { if (isset($previous_settings[$forum_key])) { $valid_forums = array_intersect(explode(',', $previous_settings[$forum_key]), $allowed_forums); $forum_val = join(',', $valid_forums); } } } if ($forum_val && $forum_val != $search_all) { $search_in_forums_ary = array_slice(explode(',', $forum_val), 0, $max_forums_selected); $search_in_forums_fary = array_flip($search_in_forums_ary); $search_in_forums_csv = join(',', $search_in_forums_ary); $forum_val = $search_in_forums_csv;
function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false) { if (is_array($var)) { foreach ($var as $k => $v) { if (is_array($v)) { if ($one_dimensional) { unset($var[$k]); } else { if ($array_only) { $var[$k] = $fn($v); } else { array_deep($var[$k], $fn); } } } else { if (!$array_only) { $var[$k] = $fn($v); } } } } else { if (!$array_only) { $var = $fn($var); } } }
function get_id_ary($ids) { $ids = is_string($ids) ? explode(',', $ids) : array_values((array) $ids); array_deep($ids, 'intval', 'one-dimensional'); return (array) $ids; }
function remove_stopwords($text) { static $stopwords = null; if (is_null($stopwords)) { $stopwords = explode(' ', str_compact(@file_get_contents(LANG_DIR . 'search_stopwords.txt'))); array_deep($stopwords, 'pad_with_space'); } return $stopwords ? str_replace($stopwords, ' ', $text) : $text; }
$all_forums = 0; // =| $sort_asc = 'ASC'; $sort_desc = 'DESC'; // Defaults $def_types = $all_types; $def_users = $all_users; $def_forums = $all_forums; $def_sort = $sort_desc; // Moderators data if (!($mod = $datastore->get('moderators'))) { $datastore->update('moderators'); $mod = $datastore->get('moderators'); } array_deep($mod['moderators'], 'html_entity_decode'); array_deep($mod['admins'], 'html_entity_decode'); $users = array($lang['ACTS_LOG_ALL_ACTIONS'] => $all_users) + array_flip($mod['moderators']) + array_flip($mod['admins']); unset($mod); // Forums data if (!($forums = $datastore->get('cat_forums'))) { $datastore->update('cat_forums'); $forums = $datastore->get('cat_forums'); } $f_data = $forums['f']; unset($forums); // Start $start = isset($_REQUEST['start']) ? abs(intval($_REQUEST['start'])) : 0; // Type $type_selected = array($def_types); $type_csv = ''; if ($var =& $_REQUEST[$type_key]) {