public function update() { global $settings, $db_type; global $time_start, $maintenance, $msubject, $mmessage, $mbname, $language; global $boardurl, $webmaster_email, $cookiename; global $db_server, $db_name, $db_user, $db_prefix, $db_persist, $db_error_send, $db_last_error; global $modSettings, $context, $sc, $user_info, $topic, $board, $txt; global $ssi_db_user, $scripturl, $ssi_db_passwd, $db_passwd; global $sourcedir, $boarddir; define('SUBSDIR', BOARDDIR . '/sources/subs'); require BOARDDIR . '/Settings.php'; require BOARDDIR . '/sources/Subs.php'; require BOARDDIR . '/sources/Load.php'; require_once SUBSDIR . '/Util.class.php'; $settings['theme_dir'] = $settings['default_theme_dir'] = BOARDDIR . '/Themes/default'; $settings['theme_url'] = $settings['default_theme_url'] = $boardurl . '/themes/default'; // Create a member $db = database(); $request = $db->insert('', '{db_prefix}members', array('member_name' => 'string-25', 'real_name' => 'string-25', 'passwd' => 'string', 'email_address' => 'string', 'id_group' => 'int', 'posts' => 'int', 'date_registered' => 'int', 'hide_email' => 'int', 'password_salt' => 'string', 'lngfile' => 'string', 'personal_text' => 'string', 'avatar' => 'string', 'member_ip' => 'string', 'member_ip2' => 'string', 'buddy_list' => 'string', 'pm_ignore_list' => 'string', 'message_labels' => 'string', 'website_title' => 'string', 'website_url' => 'string', 'location' => 'string', 'signature' => 'string', 'usertitle' => 'string', 'secret_question' => 'string', 'additional_groups' => 'string', 'ignore_boards' => 'string', 'openid_uri' => 'string'), array('test_admin', 'test_admin', sha1(strtolower(stripslashes('test_admin')) . stripslashes('test_admin_pwd')), '*****@*****.**', 1, 0, time(), 0, substr(md5(mt_rand()), 0, 4), '', '', '', '123.123.123.123', '123.123.123.123', '', '', '', '', '', '', '', '', '', '', '', ''), array('id_member')); $server_offset = @mktime(0, 0, 0, 1, 1, 1970); $timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . $server_offset / 3600; if (date_default_timezone_set($timezone_id)) { $db->insert('', $db_prefix . 'settings', array('variable' => 'string-255', 'value' => 'string-65534'), array('default_timezone', $timezone_id), array('variable')); } updateStats('member'); updateStats('message'); updateStats('topic'); loadLanguage('Install'); updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); }
function register($firstname, $middlename, $lastname, $email, $dob, $phone = NULL, $addrl1, $addrl2, $city, $state, $country, $zipcode) { $sql = "INSERT INTO customer (f_nm, m_nm, l_nm, email, dob, phone, street, adr_l2, city, state, country, zipcode, cr_dt)\nVALUES ('{$firstname}', '{$middlename}', '{$lastname}', '{$email}', '{$dob}', '{$phone}', '{$addrl1}', '{$addrl2}', '{$city}', '{$state}', '{$country}', '{$zipcode}', now());"; $h_success = "Location:reg_success.html"; $h_fail = "Location:reg_fail.php"; database($sql, $h_success, $h_fail); }
/** * Verifies the hook exists both in $modSettings and db (if permanent) * or just in $modSettings * * @param string[] $expected_hook - the call and file (optional) expected * @param bool $permanent - if the hook is perma or not */ private function _hook_exists($expected_hook, $permanent) { global $modSettings; $db = database(); $request = $db->query('', ' SELECT value FROM {db_prefix}settings WHERE variable = {string:hook_name}', array('hook_name' => $this->_hook_name)); list($db_hook_string) = $db->fetch_row($request); $db->free_result($request); $db_hooks = $this->_parse_hooks($db_hook_string); // If it is permanent and the system doesn't know anything about it: bad if ($permanent && !$this->_find_hook($expected_hook, $db_hooks)) { return false; } // If it is not permanent but it is in the db: bad again if (!$permanent && $this->_find_hook($expected_hook, $db_hooks)) { return false; } // If it is empty there is no hook if (empty($modSettings[$this->_hook_name])) { return false; } // Permanent or not it should be in $modSettings $db_hooks = $this->_parse_hooks($modSettings[$this->_hook_name]); if (!$this->_find_hook($expected_hook, $db_hooks)) { return false; } return true; }
function add_unit($ut_id, $type, $tw_id, $floor, $area) { $sql = "INSERT INTO unit (ut_id, type, tw_id, floor, area, cr_dt)\nVALUES ('{$ut_id}', '{$type}', '{$tw_id}', '{$floor}', '{$area}', now());"; $h_success = "Unit " . $ut_id . " Added Successfully"; $h_fail = "Location:reg_fail.php"; database($sql, $h_success, $h_fail); }
/** * Gets the badbehavior log entries that match the specified parameters. * * @package BadBehavior * @param int $start * @param int $items_per_page * @param string $sort * @param string|mixed[]|null $filter */ function getBadBehaviorLogEntries($start, $items_per_page, $sort, $filter = '') { global $scripturl; $db = database(); require_once EXTDIR . '/bad-behavior/bad-behavior/responses.inc.php'; $bb_entries = array(); $request = $db->query('', ' SELECT id, ip, date, request_method, request_uri, server_protocol, http_headers, user_agent, request_entity, valid, id_member, session FROM {db_prefix}log_badbehavior' . (!empty($filter) ? ' WHERE ' . $filter['variable'] . ' LIKE {string:filter}' : '') . ' ORDER BY id ' . ($sort === 'down' ? 'DESC' : '') . ' LIMIT ' . $start . ', ' . $items_per_page, array('filter' => !empty($filter) ? $filter['value']['sql'] : '')); for ($i = 0; $row = $db->fetch_assoc($request); $i++) { // Turn the key in to something nice to show $key_response = bb2_get_response($row['valid']); // Prevent undefined errors and log .. if (isset($key_response[0]) && $key_response[0] == '00000000') { $key_response['response'] = ''; $key_response['explanation'] = ''; $key_response['log'] = ''; } $bb_entries[$row['id']] = array('alternate' => $i % 2 == 0, 'ip' => $row['ip'], 'request_method' => $row['request_method'], 'server_protocol' => $row['server_protocol'], 'user_agent' => array('html' => $row['user_agent'], 'href' => base64_encode($db->escape_wildcard_string($row['user_agent']))), 'request_entity' => $row['request_entity'], 'valid' => array('code' => $row['valid'], 'response' => $key_response['response'], 'explanation' => $key_response['explanation'], 'log' => $key_response['log']), 'member' => array('id' => $row['id_member'], 'ip' => $row['ip'], 'session' => $row['session']), 'time' => standardTime($row['date']), 'html_time' => htmlTime($row['date']), 'timestamp' => forum_time(true, $row['date']), 'request_uri' => array('html' => htmlspecialchars((substr($row['request_uri'], 0, 1) === '?' ? $scripturl : '') . $row['request_uri'], ENT_COMPAT, 'UTF-8'), 'href' => base64_encode($db->escape_wildcard_string($row['request_uri']))), 'http_headers' => array('html' => str_replace("\n", '<br />', $row['http_headers']), 'href' => '#'), 'id' => $row['id']); } $db->free_result($request); return $bb_entries; }
/** * Parse smileys in the passed message. * * What it does: * - The smiley parsing function which makes pretty faces appear :). * - If custom smiley sets are turned off by smiley_enable, the default set of smileys will be used. * - These are specifically not parsed in code tags [url=mailto:Dad@blah.com] * - Caches the smileys from the database or array in memory. * - Doesn't return anything, but rather modifies message directly. * * @param string $message */ function parsesmileys(&$message) { global $modSettings, $txt, $user_info; static $smileyPregSearch = null, $smileyPregReplacements = array(); // No smiley set at all?! if ($user_info['smiley_set'] == 'none' || trim($message) == '') { return; } // If smileyPregSearch hasn't been set, do it now. if (empty($smileyPregSearch)) { // Use the default smileys if it is disabled. (better for "portability" of smileys.) if (empty($modSettings['smiley_enable'])) { $smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:)'); $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); $smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], $txt['icon_laugh'], $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', $txt['icon_angel']); } else { // Load the smileys in reverse order by length so they don't get parsed wrong. if (($temp = cache_get_data('parsing_smileys', 480)) == null) { $smileysfrom = array(); $smileysto = array(); $smileysdescs = array(); // @todo there is no reason $db should be used before this $db = database(); $db->fetchQueryCallback(' SELECT code, filename, description FROM {db_prefix}smileys ORDER BY LENGTH(code) DESC', array(), function ($row) use(&$smileysfrom, &$smileysto, &$smileysdescs) { $smileysfrom[] = $row['code']; $smileysto[] = htmlspecialchars($row['filename']); $smileysdescs[] = $row['description']; }); cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480); } else { list($smileysfrom, $smileysto, $smileysdescs) = $temp; } } // The non-breaking-space is a complex thing... $non_breaking_space = '\\x{A0}'; // This smiley regex makes sure it doesn't parse smileys within code tags (so [url=mailto:David@bla.com] doesn't parse the :D smiley) $smileyPregReplacements = array(); $searchParts = array(); $smileys_path = htmlspecialchars($modSettings['smileys_url'] . '/' . $user_info['smiley_set'] . '/'); for ($i = 0, $n = count($smileysfrom); $i < $n; $i++) { $specialChars = htmlspecialchars($smileysfrom[$i], ENT_QUOTES); $smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" title="' . strtr(htmlspecialchars($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley" />'; $smileyPregReplacements[$smileysfrom[$i]] = $smileyCode; $searchParts[] = preg_quote($smileysfrom[$i], '~'); if ($smileysfrom[$i] != $specialChars) { $smileyPregReplacements[$specialChars] = $smileyCode; $searchParts[] = preg_quote($specialChars, '~'); } } $smileyPregSearch = '~(?<=[>:\\?\\.\\s' . $non_breaking_space . '[\\]()*\\\\;]|^)(' . implode('|', $searchParts) . ')(?=[^[:alpha:]0-9]|$)~'; } // Replace away! $message = preg_replace_callback($smileyPregSearch, function ($matches) use($smileyPregReplacements) { return $smileyPregReplacements[$matches[0]]; }, $message); }
function add_plan($bill_plan, $name, $years, $roi) { $sql = "INSERT INTO bill_plan (bill_plan, name, no_years, roi, cr_dt)\nVALUES ('{$bill_plan}', '{$name}', '{$years}', '{$roi}', now());"; $h_success = "Billing Plan: " . $desc . " Added Successfully"; $h_success = "<script type='text/javascript'>alert('{$h_success}');</script>"; $h_fail = "Billing Plan: " . $bill_plan . " Not Added"; database($sql, $h_success, $h_fail); }
function add_user($ur_id, $password, $f_nm, $m_nm, $l_nm, $ur_type) { $sql = "INSERT INTO user001 (ur_id, password, f_nm, m_nm, l_nm, ur_type, cr_dt, cr_by) values ('{$ur_id}', '{$password}', '{$f_nm}', '{$m_nm}', '{$l_nm}', '{$ur_type}', now(), current_user());"; $h_success = "User: "******" Added Successfully"; $h_success = "<script type='text/javascript'>alert('{$h_success}');</script>"; $h_fail = "User: "******" Not Added"; database($sql, $h_success, $h_fail); }
function add_unit($ut_id, $type, $tw_id, $floor, $area) { $sql = "INSERT INTO unit (ut_id, type, tw_id, floor, area, cr_dt)\nVALUES ('{$ut_id}', '{$type}', '{$tw_id}', '{$floor}', '{$area}', now());"; $h_success = "Tower: " . $desc . " Added Successfully"; $h_success = "<script type='text/javascript'>alert('{$h_success}');</script>"; $h_fail = "Unit: " . $ut_id . " Not Added"; database($sql, $h_success, $h_fail); }
/** * Make a custom word index. * * @param $size */ function create_word_search($size) { $db = database(); $size = 'int'; $db->query('', ' CREATE TABLE {db_prefix}log_search_words ( id_word {raw:size} NOT NULL default {string:string_zero}, id_msg int(10) NOT NULL default {string:string_zero}, PRIMARY KEY (id_word, id_msg) )', array('size' => $size, 'string_zero' => '0')); }
/** * parseRequest() with a simple string board and no topic */ function testTablesExist() { $db = database(); $tables = $db->db_list_tables(); $known_tables = array('admin_info_files', 'antispam_questions', 'approval_queue', 'attachments', 'ban_groups', 'ban_items', 'board_permissions', 'boards', 'calendar', 'calendar_holidays', 'categories', 'collapsed_categories', 'custom_fields', 'custom_fields_data', 'group_moderators', 'follow_ups', 'log_actions', 'log_activity', 'log_badbehavior', 'log_banned', 'log_boards', 'log_comments', 'log_digest', 'log_errors', 'log_floodcontrol', 'log_group_requests', 'log_karma', 'log_likes', 'log_mark_read', 'log_member_notices', 'log_mentions', 'log_notify', 'log_online', 'log_packages', 'log_polls', 'log_reported', 'log_reported_comments', 'log_scheduled_tasks', 'log_search_messages', 'log_search_results', 'log_search_subjects', 'log_search_topics', 'log_spider_hits', 'log_spider_stats', 'log_subscribed', 'log_topics', 'mail_queue', 'membergroups', 'members', 'member_logins', 'message_icons', 'message_likes', 'messages', 'moderators', 'openid_assoc', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages', 'pm_recipients', 'pm_rules', 'polls', 'poll_choices', 'postby_emails', 'postby_emails_error', 'postby_emails_filters', 'scheduled_tasks', 'settings', 'sessions', 'smileys', 'spiders', 'subscriptions', 'themes', 'topics', 'user_drafts'); $exists = false; foreach ($known_tables as $table) { $exists = in_array($this->db_prefix . $table, $tables); $this->assertTrue($exists); } }
/** * Remove an auth from the database * * @param int $id_member the member's id * @param string $provider the provider they're using */ function deleteAuth($id_member, $provider) { $db = database(); $result = $db->query('', ' DELETE FROM {db_prefix}external_authentications WHERE provider = {string:provider} AND id_member = {int:id_member}', array('id_member' => $id_member, 'provider' => $provider)); // Return the amount of deleted auths, unless an error occured. return $result ? $db->affected_rows() : false; }
/** * static function saveTableSettings, now part of the Settings Form class * * @param mixed[] $config_vars the key names of the vars are the table cols * @param string $tablename name of the table the values will be saved in * @param string[] $index for compatability * @param integer $editid -1 add a row, otherwise edit a row with the supplied key value * @param string $editname used when editing a row, needs to be the name of the col to find $editid key value */ public static function saveTableSettings($config_vars, $tablename, $index = array(), $editid = -1, $editname = '') { $db = database(); // Init $insert_type = array(); $insert_value = array(); $update = false; // Cast all the config vars as defined foreach ($config_vars as $var) { if (!isset($var[1]) || !isset($_POST[$var[1]]) && $var[0] !== 'check') { continue; } elseif ($var[0] === 'check') { $insert_type[$var[1]] = 'int'; $insert_value[] = !empty($_POST[$var[1]]) ? 1 : 0; } elseif ($var[0] === 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) { $insert_type[$var[1]] = 'string'; $insert_value[] = $_POST[$var[1]]; } elseif ($var[0] === 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) { // For security purposes we need to validate this line by line. $options = array(); foreach ($_POST[$var[1]] as $invar) { if (in_array($invar, array_keys($var[2]))) { $options[] = $invar; } } $insert_type[$var[1]] = 'string'; $insert_value[] = serialize($options); } elseif ($var[0] == 'int') { $insert_type[$var[1]] = 'int'; $insert_value[] = (int) $_POST[$var[1]]; } elseif ($var[0] === 'float') { $insert_type[$var[1]] = 'float'; $insert_value[] = (double) $_POST[$var[1]]; } elseif ($var[0] === 'text' || $var[0] === 'large_text') { $insert_type[$var[1]] = 'string'; $insert_value[] = $_POST[$var[1]]; } } // Everything is now set so is this a new row or an edit? if ($editid !== -1 && !empty($editname)) { // Time to edit, add in the id col name, assumed to be primary/unique! $update = true; $insert_type[$editname] = 'int'; $insert_value[] = $editid; } // Do it !! $db->insert($update ? 'replace' : 'insert', '{db_prefix}' . $tablename, $insert_type, $insert_value, $index); }
/** * Get the admin info file from the database * * @param string $filename * * @return array */ function adminInfoFile($filename) { $db = database(); $file = array(); $request = $db->query('', ' SELECT data, filetype FROM {db_prefix}admin_info_files WHERE filename = {string:current_filename} LIMIT 1', array('current_filename' => $filename)); if ($db->num_rows($request) == 0) { fatal_lang_error('admin_file_not_found', true, array($filename)); } list($file['file_data'], $file['filetype']) = $db->fetch_row($request); $db->free_result($request); return $file; }
/** * Update a former karma action from executor to target. * * @package Karma * @param int $id_executor * @param int $id_target * @param int $direction - options: -1 or 1 */ function updateKarma($id_executor, $id_target, $direction) { $db = database(); // You decided to go back on your previous choice? $db->query('', ' UPDATE {db_prefix}log_karma SET action = {int:action}, log_time = {int:current_time} WHERE id_target = {int:id_target} AND id_executor = {int:current_member}', array('current_member' => $id_executor, 'action' => $direction, 'current_time' => time(), 'id_target' => $id_target)); // It was recently changed the OTHER way... so... reverse it! if ($direction == 1) { updateMemberData($_REQUEST['uid'], array('karma_good' => '+', 'karma_bad' => '-')); } else { updateMemberData($_REQUEST['uid'], array('karma_bad' => '+', 'karma_good' => '-')); } }
/** * Fixes corrupted serialized strings after a character set conversion. */ function fix_serialized_columns() { $db = database(); $request = $db->query('', ' SELECT id_action, extra FROM {db_prefix}log_actions WHERE action IN ({string:remove}, {string:delete})', array('remove' => 'remove', 'delete' => 'delete')); while ($row = $db->fetch_assoc($request)) { if (@unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\\d+;s:7:"subject";s:)(\\d+):"(.+)"(;s:6:"member";s:5:"\\d+";})$~', $row['extra'], $matches) === 1) { $db->query('', ' UPDATE {db_prefix}log_actions SET extra = {string:extra} WHERE id_action = {int:current_action}', array('current_action' => $row['id_action'], 'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4])); } } $db->free_result($request); // Refresh some cached data. updateSettings(array('memberlist_updated' => time())); }
/** * Get the recent topics to display. * * @package News * @param string $query_this_board passed to query, assumed raw and instered as such * @param int $board * @param int $limit */ function getXMLRecent($query_this_board, $board, $limit) { global $modSettings, $board, $context; $db = database(); $done = false; $loops = 0; while (!$done) { $optimize_msg = implode(' AND ', $context['optimize_msg']); $request = $db->query('', ' SELECT m.id_msg FROM {db_prefix}messages AS m INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) WHERE ' . $query_this_board . (empty($optimize_msg) ? '' : ' AND {raw:optimize_msg}') . (empty($board) ? '' : ' AND m.id_board = {int:current_board}') . ($modSettings['postmod_active'] ? ' AND m.approved = {int:is_approved}' : '') . ' ORDER BY m.id_msg DESC LIMIT {int:limit}', array('limit' => $limit, 'current_board' => $board, 'is_approved' => 1, 'optimize_msg' => $optimize_msg)); // If we don't have $limit results, try again with an unoptimized version covering all rows. if ($loops < 2 && $db->num_rows($request) < $limit) { $db->free_result($request); if (empty($_REQUEST['boards']) && empty($board)) { unset($context['optimize_msg']['lowest']); } else { $context['optimize_msg']['lowest'] = $loops ? 'm.id_msg >= t.id_first_msg' : 'm.id_msg >= (t.id_last_msg - t.id_first_msg) / 2'; } $loops++; } else { $done = true; } } $messages = array(); while ($row = $db->fetch_assoc($request)) { $messages[] = $row['id_msg']; } $db->free_result($request); // No messages found, then return nothing if (empty($messages)) { return array(); } // Find the most recent posts from our message list that this user can see. $request = $db->query('', ' SELECT m.smileys_enabled, m.poster_time, m.id_msg, m.subject, m.body, m.id_topic, t.id_board, b.name AS bname, t.num_replies, m.id_member, m.icon, mf.id_member AS id_first_member, IFNULL(mem.real_name, m.poster_name) AS poster_name, mf.subject AS first_subject, IFNULL(memf.real_name, mf.poster_name) AS first_poster_name, mem.hide_email, IFNULL(mem.email_address, m.poster_email) AS poster_email, m.modified_time FROM {db_prefix}messages AS m INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic) INNER JOIN {db_prefix}messages AS mf ON (mf.id_msg = t.id_first_msg) INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board) LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member) LEFT JOIN {db_prefix}members AS memf ON (memf.id_member = mf.id_member) WHERE m.id_msg IN ({array_int:message_list}) ' . (empty($board) ? '' : 'AND t.id_board = {int:current_board}') . ' ORDER BY m.id_msg DESC LIMIT {int:limit}', array('limit' => $limit, 'current_board' => $board, 'message_list' => $messages)); $data = array(); while ($row = $db->fetch_assoc($request)) { $data[] = $row; } $db->free_result($request); return $data; }
saveacct(); break; case "savemenu": require_once "admin/admin_menus_lib.php"; savemenu(); break; case "saveforum": require_once "admin/admin_forum_lib.php"; saveforum(); break; } $section = isset($_GET["section"]) ? $_GET["section"] : NULL; switch ($section) { case "databases": require_once "admin/admin_databases_lib.php"; database(); break; case "servers": require_once "admin/admin_servers_lib.php"; servers(); break; case "menus": require_once "admin/admin_menus_lib.php"; menus(); break; case "forum": require_once "admin/admin_forum_lib.php"; forum(); break; case "accounts": require_once "admin/admin_accounts_lib.php";
/** * Adds the questions to the db * * @param mixed[] $questions */ private function _insert($questions) { $db = database(); $db->insert('', '{db_prefix}antispam_questions', array('question' => 'string-65535', 'answer' => 'string-65535', 'language' => 'string-50'), $questions, array('id_question')); }
/** * Update topic subject. * * - If $all is true, for all messages in the topic, otherwise only the first message. * * @package Posts * @param mixed[] $topic_info topic information as returned by getTopicInfo() * @param string $custom_subject * @param string $response_prefix = '' * @param bool $all = false */ function topicSubject($topic_info, $custom_subject, $response_prefix = '', $all = false) { $db = database(); if ($all) { $db->query('', ' UPDATE {db_prefix}messages SET subject = {string:subject} WHERE id_topic = {int:current_topic}', array('current_topic' => $topic_info['id_topic'], 'subject' => $response_prefix . $custom_subject)); } $db->query('', ' UPDATE {db_prefix}messages SET subject = {string:custom_subject} WHERE id_msg = {int:id_first_msg}', array('id_first_msg' => $topic_info['id_first_msg'], 'custom_subject' => $custom_subject)); }
/** * Loads an email message from the database * * @param int $id id of the email to retrieve from the failed log */ private function _query_load_email($id) { $db = database(); // Nothing to load then if (empty($id)) { return ''; } $request = $db->query('', ' SELECT message FROM {db_prefix}postby_emails_error WHERE id_email = {int:id} LIMIT 1', array('id' => $id)); list($message) = $db->fetch_row($request); $db->free_result($request); return $message; }
/** * Creates a query for a column * * @param mixed[] $column */ private function _db_create_query_column($column) { // make sure db is available $db = database(); // Auto increment is easy here! if (!empty($column['auto'])) { $default = 'auto_increment'; } elseif (isset($column['default']) && $column['default'] !== null) { $default = 'default \'' . $db->escape_string($column['default']) . '\''; } else { $default = ''; } // Sort out the size... and stuff... $column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null; list($type, $size) = $this->db_calculate_type($column['type'], $column['size']); // Allow unsigned integers (mysql only) $unsigned = in_array($type, array('int', 'tinyint', 'smallint', 'mediumint', 'bigint')) && !empty($column['unsigned']) ? 'unsigned ' : ''; if ($size !== null) { $type = $type . '(' . $size . ')'; } // Now just put it together! return '`' . $column['name'] . '` ' . $type . ' ' . (!empty($unsigned) ? $unsigned : '') . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default; }
/** * Get index information. * * @param string $table_name * @param bool $detail * @param mixed[] $parameters * @return mixed */ public function db_list_indexes($table_name, $detail = false, $parameters = array()) { global $db_prefix; // Working with the db $db = database(); $table_name = str_replace('{db_prefix}', $db_prefix, $table_name); $result = $db->query('', ' SELECT CASE WHEN i.indisprimary THEN 1 ELSE 0 END AS is_primary, CASE WHEN i.indisunique THEN 1 ELSE 0 END AS is_unique, c2.relname AS name, pg_get_indexdef(i.indexrelid) AS inddef FROM pg_class AS c, pg_class AS c2, pg_index AS i WHERE c.relname = \'' . $table_name . '\' AND c.oid = i.indrelid AND i.indexrelid = c2.oid', array('security_override' => true)); $indexes = array(); while ($row = $db->fetch_assoc($result)) { // Try get the columns that make it up. if (preg_match('~\\(([^\\)]+?)\\)~i', $row['inddef'], $matches) == 0) { continue; } $columns = explode(',', $matches[1]); if (empty($columns)) { continue; } foreach ($columns as $k => $v) { $columns[$k] = trim($v); } // Fix up the name to be consistent cross databases if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) { $row['name'] = 'PRIMARY'; } else { $row['name'] = str_replace($table_name . '_', '', $row['name']); } if (!$detail) { $indexes[] = $row['name']; } else { $indexes[$row['name']] = array('name' => $row['name'], 'type' => $row['is_primary'] ? 'primary' : ($row['is_unique'] ? 'unique' : 'index'), 'columns' => $columns); } } $db->free_result($result); return $indexes; }
/** * This simple function gets a list of all administrators and sends them an email * to let them know a new member has joined. * Called by registerMember() function in subs/Members.subs.php. * Email is sent to all groups that have the moderate_forum permission. * The language set by each member is being used (if available). * * @param string $type types supported are 'approval', 'activation', and 'standard'. * @param int $memberID * @param string|null $member_name = null * @uses the Login language file. */ function sendAdminNotifications($type, $memberID, $member_name = null) { global $modSettings, $language, $scripturl, $user_info; $db = database(); // If the setting isn't enabled then just exit. if (empty($modSettings['notify_new_registration'])) { return; } // Needed to notify admins, or anyone require_once SUBSDIR . '/Mail.subs.php'; if ($member_name == null) { require_once SUBSDIR . '/Members.subs.php'; // Get the new user's name.... $member_info = getBasicMemberData($memberID); $member_name = $member_info['real_name']; } $groups = array(); // All membergroups who can approve members. $request = $db->query('', ' SELECT id_group FROM {db_prefix}permissions WHERE permission = {string:moderate_forum} AND add_deny = {int:add_deny} AND id_group != {int:id_group}', array('add_deny' => 1, 'id_group' => 0, 'moderate_forum' => 'moderate_forum')); while ($row = $db->fetch_assoc($request)) { $groups[] = $row['id_group']; } $db->free_result($request); // Add administrators too... $groups[] = 1; $groups = array_unique($groups); // Get a list of all members who have ability to approve accounts - these are the people who we inform. $request = $db->query('', ' SELECT id_member, lngfile, email_address FROM {db_prefix}members WHERE (id_group IN ({array_int:group_list}) OR FIND_IN_SET({raw:group_array_implode}, additional_groups) != 0) AND notify_types != {int:notify_types} ORDER BY lngfile', array('group_list' => $groups, 'notify_types' => 4, 'group_array_implode' => implode(', additional_groups) != 0 OR FIND_IN_SET(', $groups))); $current_language = $user_info['language']; while ($row = $db->fetch_assoc($request)) { $replacements = array('USERNAME' => $member_name, 'PROFILELINK' => $scripturl . '?action=profile;u=' . $memberID); $emailtype = 'admin_notify'; // If they need to be approved add more info... if ($type == 'approval') { $replacements['APPROVALLINK'] = $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve'; $emailtype .= '_approval'; } $emaildata = loadEmailTemplate($emailtype, $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']); // And do the actual sending... sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 0); } $db->free_result($request); if (isset($current_language) && $current_language != $user_info['language']) { loadLanguage('Login'); } }
/** * This function determines if a user has posted in the list of topics, * and returns the list of those topics they posted in. * * @param int $id_member member to check * @param int[] $topic_ids array of topics ids to check for participation */ function topicsParticipation($id_member, $topic_ids) { $db = database(); $topics = array(); $result = $db->query('', ' SELECT id_topic FROM {db_prefix}messages WHERE id_topic IN ({array_int:topic_list}) AND id_member = {int:current_member} GROUP BY id_topic LIMIT ' . count($topic_ids), array('current_member' => $id_member, 'topic_list' => $topic_ids)); while ($row = $db->fetch_assoc($result)) { $topics[] = $row; } $db->free_result($result); return $topics; }
/** * !!!Compatibility!!! * * This is not directly required any longer, but left for mod usage * * The harder one - wysiwyg to BBC! * * @param string $text * @return string */ function html_to_bbc($text) { global $modSettings, $scripturl, $context; $db = database(); // Replace newlines with spaces, as that's how browsers usually interpret them. $text = preg_replace("~\\s*[\r\n]+\\s*~", ' ', $text); // Though some of us love paragraphs, the parser will do better with breaks. $text = preg_replace('~</p>\\s*?<p~i', '</p><br /><p', $text); $text = preg_replace('~</p>\\s*(?!<)~i', '</p><br />', $text); // Safari/webkit wraps lines in Wysiwyg in <div>'s. if (isBrowser('webkit')) { $text = preg_replace(array('~<div(?:\\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br />', ''), $text); } // If there's a trailing break get rid of it - Firefox tends to add one. $text = preg_replace('~<br\\s?/?' . '>$~i', '', $text); // Remove any formatting within code tags. if (strpos($text, '[code') !== false) { $text = preg_replace('~<br\\s?/?' . '>~i', '#elk_br_spec_grudge_cool!#', $text); $parts = preg_split('~(\\[/code\\]|\\[code(?:=[^\\]]+)?\\])~i', $text, -1, PREG_SPLIT_DELIM_CAPTURE); // Only mess with stuff outside [code] tags. for ($i = 0, $n = count($parts); $i < $n; $i++) { // Value of 2 means we're inside the tag. if ($i % 4 == 2) { $parts[$i] = strip_tags($parts[$i]); } } $text = strtr(implode('', $parts), array('#elk_br_spec_grudge_cool!#' => '<br />')); } // Remove scripts, style and comment blocks. $text = preg_replace('~<script[^>]*[^/]?' . '>.*?</script>~i', '', $text); $text = preg_replace('~<style[^>]*[^/]?' . '>.*?</style>~i', '', $text); $text = preg_replace('~\\<\\!--.*?-->~i', '', $text); $text = preg_replace('~\\<\\!\\[CDATA\\[.*?\\]\\]\\>~i', '', $text); // Do the smileys ultra first! preg_match_all('~<img\\s+[^<>]*?id="*smiley_\\d+_([^<>]+?)[\\s"/>]\\s*[^<>]*?/*>(?:\\s)?~i', $text, $matches); if (!empty($matches[0])) { // Easy if it's not custom. if (empty($modSettings['smiley_enable'])) { $smileysfrom = array('>:D', ':D', '::)', '>:(', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)'); $smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif'); foreach ($matches[1] as $k => $file) { $found = array_search($file, $smileysto); // Note the weirdness here is to stop double spaces between smileys. if ($found) { $matches[1][$k] = '-[]-elk_smily_start#|#' . htmlspecialchars($smileysfrom[$found]) . '-[]-elk_smily_end#|#'; } else { $matches[1][$k] = ''; } } } else { // Load all the smileys. $names = array(); foreach ($matches[1] as $file) { $names[] = $file; } $names = array_unique($names); if (!empty($names)) { $request = $db->query('', ' SELECT code, filename FROM {db_prefix}smileys WHERE filename IN ({array_string:smiley_filenames})', array('smiley_filenames' => $names)); $mappings = array(); while ($row = $db->fetch_assoc($request)) { $mappings[$row['filename']] = htmlspecialchars($row['code']); } $db->free_result($request); foreach ($matches[1] as $k => $file) { if (isset($mappings[$file])) { $matches[1][$k] = '-[]-elk_smily_start#|#' . $mappings[$file] . '-[]-elk_smily_end#|#'; } } } } // Replace the tags! $text = str_replace($matches[0], $matches[1], $text); // Now sort out spaces $text = str_replace(array('-[]-elk_smily_end#|#-[]-elk_smily_start#|#', '-[]-elk_smily_end#|#', '-[]-elk_smily_start#|#'), ' ', $text); } // Only try to buy more time if the client didn't quit. if (connection_aborted() && $context['server']['is_apache']) { @apache_reset_timeout(); } $parts = preg_split('~(<[A-Za-z]+\\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE); $replacement = ''; $stack = array(); foreach ($parts as $part) { if (preg_match('~(<([A-Za-z]+)\\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1) { // If it's being closed instantly, we can't deal with it...yet. if ($matches[5] === '/') { continue; } else { // Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.) $styles = explode(';', strtr($matches[3], array('"' => ''))); $curElement = $matches[2]; $precedingStyle = $matches[1]; $afterStyle = $matches[4]; $curCloseTags = ''; $extra_attr = ''; foreach ($styles as $type_value_pair) { // Remove spaces and convert uppercase letters. $clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':')); // Something like 'font-weight: bold' is expected here. if (strpos($clean_type_value_pair, ':') === false) { continue; } // Capture the elements of a single style item (e.g. 'font-weight' and 'bold'). list($style_type, $style_value) = explode(':', $type_value_pair); $style_value = trim($style_value); switch (trim($style_type)) { case 'font-weight': if ($style_value === 'bold') { $curCloseTags .= '[/b]'; $replacement .= '[b]'; } break; case 'text-decoration': if ($style_value == 'underline') { $curCloseTags .= '[/u]'; $replacement .= '[u]'; } elseif ($style_value == 'line-through') { $curCloseTags .= '[/s]'; $replacement .= '[s]'; } break; case 'text-align': if ($style_value == 'left') { $curCloseTags .= '[/left]'; $replacement .= '[left]'; } elseif ($style_value == 'center') { $curCloseTags .= '[/center]'; $replacement .= '[center]'; } elseif ($style_value == 'right') { $curCloseTags .= '[/right]'; $replacement .= '[right]'; } break; case 'font-style': if ($style_value == 'italic') { $curCloseTags .= '[/i]'; $replacement .= '[i]'; } break; case 'color': $curCloseTags .= '[/color]'; $replacement .= '[color=' . $style_value . ']'; break; case 'font-size': // Sometimes people put decimals where decimals should not be. if (preg_match('~(\\d)+\\.\\d+(p[xt])~i', $style_value, $dec_matches) === 1) { $style_value = $dec_matches[1] . $dec_matches[2]; } $curCloseTags .= '[/size]'; $replacement .= '[size=' . $style_value . ']'; break; case 'font-family': // Only get the first freaking font if there's a list! if (strpos($style_value, ',') !== false) { $style_value = substr($style_value, 0, strpos($style_value, ',')); } $curCloseTags .= '[/font]'; $replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']'; break; // This is a hack for images with dimensions embedded. // This is a hack for images with dimensions embedded. case 'width': case 'height': if (preg_match('~[1-9]\\d*~i', $style_value, $dimension) === 1) { $extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"'; } break; case 'list-style-type': if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) { $extra_attr .= ' listtype="' . $listType[0] . '"'; } break; } } // Preserve some tags stripping the styling. if (in_array($matches[2], array('a', 'font', 'td'))) { $replacement .= $precedingStyle . $afterStyle; $curCloseTags = '</' . $matches[2] . '>' . $curCloseTags; } // If there's something that still needs closing, push it to the stack. if (!empty($curCloseTags)) { array_push($stack, array('element' => strtolower($curElement), 'closeTags' => $curCloseTags)); } elseif (!empty($extra_attr)) { $replacement .= $precedingStyle . $extra_attr . $afterStyle; } } } elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1) { // Is this the element that we've been waiting for to be closed? if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element']) { $byebyeTag = array_pop($stack); $replacement .= $byebyeTag['closeTags']; } else { $replacement .= $part; } } else { $replacement .= $part; } } // Now put back the replacement in the text. $text = $replacement; // We are not finished yet, request more time. if (connection_aborted() && $context['server']['is_apache']) { @apache_reset_timeout(); } // Let's pull out any legacy alignments. while (preg_match('~<([A-Za-z]+)\\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1) { // Find the position in the text of this tag over again. $start_pos = strpos($text, $matches[0]); if ($start_pos === false) { break; } // End tag? if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false) { $end_length = strlen('</' . $matches[1] . '>'); $end_pos = strpos($text, '</' . $matches[1] . '>', $start_pos); // Remove the align from that tag so it's never checked again. $tag = substr($text, $start_pos, strlen($matches[0])); $content = substr($text, $start_pos + strlen($matches[0]), $end_pos - $start_pos - strlen($matches[0])); $tag = str_replace($matches[2], '', $tag); // Put the tags back into the body. $text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos); } else { // Just get rid of this evil tag. $text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0])); } } // Let's do some special stuff for fonts - cause we all love fonts. while (preg_match('~<font\\s+([^<>]*)>~i', $text, $matches) === 1) { // Find the position of this again. $start_pos = strpos($text, $matches[0]); $end_pos = false; if ($start_pos === false) { break; } // This must have an end tag - and we must find the right one. $lower_text = strtolower($text); $start_pos_test = $start_pos + 4; // How many starting tags must we find closing ones for first? $start_font_tag_stack = 0; while ($start_pos_test < strlen($text)) { // Where is the next starting font? $next_start_pos = strpos($lower_text, '<font', $start_pos_test); $next_end_pos = strpos($lower_text, '</font>', $start_pos_test); // Did we past another starting tag before an end one? if ($next_start_pos !== false && $next_start_pos < $next_end_pos) { $start_font_tag_stack++; $start_pos_test = $next_start_pos + 4; } elseif ($start_font_tag_stack) { $start_font_tag_stack--; $start_pos_test = $next_end_pos + 4; } else { $end_pos = $next_end_pos; break; } } if ($end_pos === false) { break; } // Now work out what the attributes are. $attribs = fetchTagAttributes($matches[1]); $tags = array(); $sizes_equivalence = array(1 => '8pt', '10pt', '12pt', '14pt', '18pt', '24pt', '36pt'); foreach ($attribs as $s => $v) { if ($s == 'size') { // Cast before empty chech because casting a string results in a 0 and we don't have zeros in the array! ;) $v = (int) trim($v); $v = empty($v) ? 1 : $v; $tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]'); } elseif ($s == 'face') { $tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]'); } elseif ($s == 'color') { $tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]'); } } // As before add in our tags. $before = $after = ''; foreach ($tags as $tag) { $before .= $tag[0]; if (isset($tag[1])) { $after = $tag[1] . $after; } } // Remove the tag so it's never checked again. $content = substr($text, $start_pos + strlen($matches[0]), $end_pos - $start_pos - strlen($matches[0])); // Put the tags back into the body. $text = substr($text, 0, $start_pos) . $before . $content . $after . substr($text, $end_pos + 7); } // Almost there, just a little more time. if (connection_aborted() && $context['server']['is_apache']) { @apache_reset_timeout(); } if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1) { // A toggle that dermines whether we're directly under a <ol> or <ul>. $inList = false; // Keep track of the number of nested list levels. $listDepth = 0; // Map what we can expect from the HTML to what is supported. $listTypeMapping = array('1' => 'decimal', 'A' => 'upper-alpha', 'a' => 'lower-alpha', 'I' => 'upper-roman', 'i' => 'lower-roman', 'disc' => 'disc', 'square' => 'square', 'circle' => 'circle'); // $i: text, $i + 1: '/', $i + 2: tag, $i + 3: tail. for ($i = 0, $numParts = count($parts) - 1; $i < $numParts; $i += 4) { $tag = strtolower($parts[$i + 2]); $isOpeningTag = $parts[$i + 1] === ''; if ($isOpeningTag) { switch ($tag) { case 'ol': case 'ul': // We have a problem, we're already in a list. if ($inList) { // Inject a list opener, we'll deal with the ol/ul next loop. array_splice($parts, $i, 0, array('', '', str_repeat("\t", $listDepth) . '[li]', '')); $numParts = count($parts) - 1; // The inlist status changes a bit. $inList = false; } else { $inList = true; if ($tag === 'ol') { $listType = 'decimal'; } elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) { $listType = $listTypeMapping[$match[1]]; } else { $listType = null; } $listDepth++; $parts[$i + 2] = '[list' . ($listType === null ? '' : ' type=' . $listType) . ']' . "\n"; $parts[$i + 3] = ''; } break; case 'li': // This is how it should be: a list item inside the list. if ($inList) { $parts[$i + 2] = str_repeat("\t", $listDepth) . '[li]'; $parts[$i + 3] = ''; // Within a list item, it's almost as if you're outside. $inList = false; } else { // We are apparently in a list item. if ($listDepth > 0) { $parts[$i + 2] = '[/li]' . "\n" . str_repeat("\t", $listDepth) . '[li]'; $parts[$i + 3] = ''; } else { // Quickly create a list with an item. $listDepth++; $parts[$i + 2] = '[list]' . "\n\t" . '[li]'; $parts[$i + 3] = ''; } } break; } } else { switch ($tag) { case 'ol': case 'ul': // As we expected it, closing the list while we're in it. if ($inList) { $inList = false; $listDepth--; $parts[$i + 1] = ''; $parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]'; $parts[$i + 3] = ''; } else { // We're in a list item. if ($listDepth > 0) { // Inject closure for this list item first. // The content of $parts[$i] is left as is! array_splice($parts, $i + 1, 0, array('', '[/li]' . "\n", '', '')); $numParts = count($parts) - 1; // Now that we've closed the li, we're in list space. $inList = true; } else { $parts[$i + 1] = ''; $parts[$i + 2] = ''; $parts[$i + 3] = ''; } } break; case 'li': if ($inList) { // There's no use for a </li> after <ol> or <ul>, ignore. $parts[$i + 1] = ''; $parts[$i + 2] = ''; $parts[$i + 3] = ''; } else { // Remove the trailing breaks from the list item. $parts[$i] = preg_replace('~\\s*<br\\s*' . '/?' . '>\\s*$~', '', $parts[$i]); $parts[$i + 1] = ''; $parts[$i + 2] = '[/li]' . "\n"; $parts[$i + 3] = ''; // And we're back in the [list] space. $inList = true; } break; } } // If we're in the [list] space, no content is allowed. if ($inList && trim(preg_replace('~\\s*<br\\s*' . '/?' . '>\\s*~', '', $parts[$i + 4])) !== '') { // Fix it by injecting an extra list item. array_splice($parts, $i + 4, 0, array('', '', 'li', '')); $numParts = count($parts) - 1; } } $text = implode('', $parts); if ($inList) { $listDepth--; $text .= str_repeat("\t", $listDepth) . '[/list]'; } for ($i = $listDepth; $i > 0; $i--) { $text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]'; } } // I love my own image... while (preg_match('~<img\\s+([^<>]*)/*>~i', $text, $matches) === 1) { // Find the position of the image. $start_pos = strpos($text, $matches[0]); if ($start_pos === false) { break; } $end_pos = $start_pos + strlen($matches[0]); $params = ''; $had_params = array(); $src = ''; $attrs = fetchTagAttributes($matches[1]); foreach ($attrs as $attrib => $value) { if (in_array($attrib, array('width', 'height'))) { $params .= ' ' . $attrib . '=' . (int) $value; } elseif ($attrib == 'alt' && trim($value) != '') { $params .= ' alt=' . trim($value); } elseif ($attrib == 'src') { $src = trim($value); } } $tag = ''; if (!empty($src)) { // Attempt to fix the path in case it's not present. if (preg_match('~^https?://~i', $src) === 0 && is_array($parsedURL = parse_url($scripturl)) && isset($parsedURL['host'])) { $baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']); if (substr($src, 0, 1) === '/') { $src = $baseURL . $src; } else { $src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src; } } $tag = '[img' . $params . ']' . $src . '[/img]'; } // Replace the tag $text = substr($text, 0, $start_pos) . $tag . substr($text, $end_pos); } // The final bits are the easy ones - tags which map to tags which map to tags - etc etc. $tags = array('~<b(\\s(.)*?)*?' . '>~i' => '[b]', '~</b>~i' => '[/b]', '~<i(\\s(.)*?)*?' . '>~i' => '[i]', '~</i>~i' => '[/i]', '~<u(\\s(.)*?)*?' . '>~i' => '[u]', '~</u>~i' => '[/u]', '~<strong(\\s(.)*?)*?' . '>~i' => '[b]', '~</strong>~i' => '[/b]', '~<em(\\s(.)*?)*?' . '>~i' => '[i]', '~</em>~i' => '[/i]', '~<s(\\s(.)*?)*?' . '>~i' => "[s]", '~</s>~i' => "[/s]", '~<strike(\\s(.)*?)*?' . '>~i' => '[s]', '~</strike>~i' => '[/s]', '~<del(\\s(.)*?)*?' . '>~i' => '[s]', '~</del>~i' => '[/s]', '~<center(\\s(.)*?)*?' . '>~i' => '[center]', '~</center>~i' => '[/center]', '~<pre(\\s(.)*?)*?' . '>~i' => '[pre]', '~</pre>~i' => '[/pre]', '~<sub(\\s(.)*?)*?' . '>~i' => '[sub]', '~</sub>~i' => '[/sub]', '~<sup(\\s(.)*?)*?' . '>~i' => '[sup]', '~</sup>~i' => '[/sup]', '~<tt(\\s(.)*?)*?' . '>~i' => '[tt]', '~</tt>~i' => '[/tt]', '~<table(\\s(.)*?)*?' . '>~i' => '[table]', '~</table>~i' => '[/table]', '~<tr(\\s(.)*?)*?' . '>~i' => '[tr]', '~</tr>~i' => '[/tr]', '~<(td|th)\\s[^<>]*?colspan="?(\\d{1,2})"?.*?' . '>~ie' => 'str_repeat(\'[td][/td]\', $2 - 1) . \'[td]\'', '~<(td|th)(\\s(.)*?)*?' . '>~i' => '[td]', '~</(td|th)>~i' => '[/td]', '~<br(?:\\s[^<>]*?)?' . '>~i' => "\n", '~<hr[^<>]*>(\\n)?~i' => "[hr]\n\$1", '~(\\n)?\\[hr\\]~i' => "\n[hr]", '~^\\n\\[hr\\]~i' => "[hr]", '~<blockquote(\\s(.)*?)*?' . '>~i' => "<blockquote>", '~</blockquote>~i' => "</blockquote>", '~<ins(\\s(.)*?)*?' . '>~i' => "<ins>", '~</ins>~i' => "</ins>"); $text = preg_replace(array_keys($tags), array_values($tags), $text); // Please give us just a little more time. if (connection_aborted() && $context['server']['is_apache']) { @apache_reset_timeout(); } // Take care of any urls in the text $text = convert_urls($text); $text = strip_tags($text); // Some tags often end up as just dummy tags - remove those. $text = preg_replace('~\\[[bisu]\\]\\s*\\[/[bisu]\\]~', '', $text); // Fix up entities. $text = preg_replace('~&~i', '&#38;', $text); $text = legalise_bbc($text); return $text; }
/** * Callback function for createList(). */ function list_getNumSmileys() { $db = database(); $request = $db->query('', ' SELECT COUNT(*) FROM {db_prefix}smileys', array()); list($numSmileys) = $db->fetch_row($request); $db->free_result($request); return $numSmileys; }
/** * Creates a box that can be used for richedit stuff like BBC, Smileys etc. * @param mixed[] $editorOptions associative array of options => value * must contain: * - id => unique id for the css * - value => text for the editor or blank * Optionaly * - height => height of the intial box * - width => width of the box (100%) * - force_rich => force wysiwyg to be enabled * - disable_smiley_box => boolean to turn off the smiley box * - labels => array( * - 'post_button' => $txt['for post button'], * ), * - preview_type => 2 how to act on preview click, see template_control_richedit_buttons */ function create_control_richedit($editorOptions) { global $txt, $modSettings, $options, $context, $settings, $user_info, $scripturl; static $bbc_tags; $db = database(); // Load the Post language file... for the moment at least. loadLanguage('Post'); if (!empty($context['drafts_save']) || !empty($context['drafts_pm_save'])) { loadLanguage('Drafts'); } // Every control must have a ID! assert(isset($editorOptions['id'])); assert(isset($editorOptions['value'])); // Is this the first richedit - if so we need to ensure things are initialised and that we load all of the needed files if (empty($context['controls']['richedit'])) { // Store the name / ID we are creating for template compatibility. $context['post_box_name'] = $editorOptions['id']; // Some general stuff. $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set']; if (!empty($context['drafts_autosave']) && !empty($options['drafts_autosave_enabled'])) { $context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 30000 : $modSettings['drafts_autosave_frequency'] * 1000; } // This really has some WYSIWYG stuff. loadTemplate('GenericControls', 'jquery.sceditor'); if (!empty($context['theme_variant']) && file_exists($settings['theme_dir'] . '/css/' . $context['theme_variant'] . '/jquery.sceditor.elk' . $context['theme_variant'] . '.css')) { loadCSSFile($context['theme_variant'] . '/jquery.sceditor.elk' . $context['theme_variant'] . '.css'); } // JS makes the editor go round loadJavascriptFile(array('jquery.sceditor.min.js', 'jquery.sceditor.bbcode.min.js', 'jquery.sceditor.elkarte.js', 'post.js', 'splittag.plugin.js', 'dropAttachments.js')); addJavascriptVar(array('post_box_name' => $editorOptions['id'], 'elk_smileys_url' => $settings['smileys_url'], 'bbc_quote_from' => $txt['quote_from'], 'bbc_quote' => $txt['quote'], 'bbc_search_on' => $txt['search_on']), true); // Editor language file if (!empty($txt['lang_locale'])) { loadJavascriptFile($scripturl . '?action=jslocale;sa=sceditor', array('defer' => true), 'sceditor_language'); } // Drafts? if ((!empty($context['drafts_save']) || !empty($context['drafts_pm_save'])) && !empty($context['drafts_autosave']) && !empty($options['drafts_autosave_enabled'])) { loadJavascriptFile('drafts.plugin.js'); } // Mentions? if (!empty($context['mentions_enabled'])) { loadJavascriptFile(array('jquery.atwho.js', 'jquery.caret.min.js', 'mentioning.plugin.js')); } // Our not so concise shortcut line $context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) || !empty($context['drafts_pm_save']) ? '_drafts' : '') . (isBrowser('is_firefox') ? '_firefox' : '')]; // Spellcheck? $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && function_exists('pspell_new'); if ($context['show_spellchecking']) { // Some hidden information is needed in order to make spell check work. if (!isset($_REQUEST['xml'])) { $context['insert_after_template'] .= ' <form name="spell_form" id="spell_form" method="post" accept-charset="UTF-8" target="spellWindow" action="' . $scripturl . '?action=spellcheck"> <input type="hidden" name="spellstring" value="" /> <input type="hidden" name="fulleditor" value="" /> </form>'; } loadJavascriptFile('spellcheck.js', array('defer' => true)); } } // Start off the editor... $context['controls']['richedit'][$editorOptions['id']] = array('id' => $editorOptions['id'], 'value' => $editorOptions['value'], 'rich_active' => !empty($options['wysiwyg_default']) || !empty($editorOptions['force_rich']) || !empty($_REQUEST[$editorOptions['id'] . '_mode']), 'disable_smiley_box' => !empty($editorOptions['disable_smiley_box']), 'columns' => isset($editorOptions['columns']) ? $editorOptions['columns'] : 60, 'rows' => isset($editorOptions['rows']) ? $editorOptions['rows'] : 18, 'width' => isset($editorOptions['width']) ? $editorOptions['width'] : '100%', 'height' => isset($editorOptions['height']) ? $editorOptions['height'] : '250px', 'form' => isset($editorOptions['form']) ? $editorOptions['form'] : 'postmodify', 'bbc_level' => !empty($editorOptions['bbc_level']) ? $editorOptions['bbc_level'] : 'full', 'preview_type' => isset($editorOptions['preview_type']) ? (int) $editorOptions['preview_type'] : 1, 'labels' => !empty($editorOptions['labels']) ? $editorOptions['labels'] : array(), 'locale' => !empty($txt['lang_locale']) ? $txt['lang_locale'] : 'en_US'); // Switch between default images and back... mostly in case you don't have an PersonalMessage template, but do have a Post template. if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) { $temp1 = $settings['theme_url']; $settings['theme_url'] = $settings['default_theme_url']; $temp2 = $settings['images_url']; $settings['images_url'] = $settings['default_images_url']; $temp3 = $settings['theme_dir']; $settings['theme_dir'] = $settings['default_theme_dir']; } if (empty($bbc_tags)) { // The below array is used to show a command button in the editor, the execution // and display details of any added buttons must be defined in the javascript files // see jquery.sceditor.elkarte.js under the $.sceditor.plugins.bbcode.bbcode area // for examples of how to use the .set command to add codes. Include your new // JS with addInlineJavascript() or loadJavascriptFile() $bbc_tags['row1'] = array(array('bold', 'italic', 'underline', 'strike', 'superscript', 'subscript'), array('left', 'center', 'right', 'pre', 'tt'), array('font', 'size', 'color')); $bbc_tags['row2'] = array(array('quote', 'code', 'table'), array('bulletlist', 'orderedlist', 'horizontalrule'), array('spoiler', 'footnote'), array('image', 'link', 'email')); // Allow mods to add BBC buttons to the toolbar, actions are defined in the JS call_integration_hook('integrate_bbc_buttons', array(&$bbc_tags)); // Show the wysiwyg format and toggle buttons? $bbc_tags['row2'][] = array('removeformat', 'source'); // Generate a list of buttons that shouldn't be shown $disabled_tags = array(); if (!empty($modSettings['disabledBBC'])) { $disabled_tags = explode(',', $modSettings['disabledBBC']); } // Map codes to tags $translate_tags_to_code = array('b' => 'bold', 'i' => 'italic', 'u' => 'underline', 's' => 'strike', 'img' => 'image', 'url' => 'link', 'sup' => 'superscript', 'sub' => 'subscript', 'hr' => 'horizontalrule'); // Remove the toolbar buttons for any bbc tags that have been turned off in the ACP foreach ($disabled_tags as $tag) { // list is special, its prevents two tags if ($tag === 'list') { $context['disabled_tags']['bulletlist'] = true; $context['disabled_tags']['orderedlist'] = true; } elseif (isset($translate_tags_to_code[$tag])) { $context['disabled_tags'][$translate_tags_to_code[$tag]] = true; } // Tag is the same as the code, like font, color, size etc $context['disabled_tags'][trim($tag)] = true; } // Build our toolbar, taking in to account any bbc codes from integration $context['bbc_toolbar'] = array(); foreach ($bbc_tags as $row => $tagRow) { if (!isset($context['bbc_toolbar'][$row])) { $context['bbc_toolbar'][$row] = array(); } $tagsRow = array(); // For each row of buttons defined, lets build our tags foreach ($tagRow as $tags) { foreach ($tags as $tag) { // Just add this code in the existing grouping if (!isset($context['disabled_tags'][$tag])) { $tagsRow[] = $tag; } } // If the row is not empty, and the last added tag is not a space, add a space. if (!empty($tagsRow) && $tagsRow[count($tagsRow) - 1] != 'space') { $tagsRow[] = 'space'; } } // Build that beautiful button row if (!empty($tagsRow)) { $context['bbc_toolbar'][$row][] = implode(',', $tagsRow); } } } // Initialize smiley array... if not loaded before. if (empty($context['smileys']) && empty($editorOptions['disable_smiley_box'])) { $context['smileys'] = array('postform' => array(), 'popup' => array()); // Load smileys - don't bother to run a query if we're not using the database's ones anyhow. if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') { $context['smileys']['postform'][] = array('smileys' => array(array('code' => ':)', 'filename' => 'smiley.gif', 'description' => $txt['icon_smiley']), array('code' => ';)', 'filename' => 'wink.gif', 'description' => $txt['icon_wink']), array('code' => ':D', 'filename' => 'cheesy.gif', 'description' => $txt['icon_cheesy']), array('code' => ';D', 'filename' => 'grin.gif', 'description' => $txt['icon_grin']), array('code' => '>:(', 'filename' => 'angry.gif', 'description' => $txt['icon_angry']), array('code' => ':))', 'filename' => 'laugh.gif', 'description' => $txt['icon_laugh']), array('code' => ':(', 'filename' => 'sad.gif', 'description' => $txt['icon_sad']), array('code' => ':o', 'filename' => 'shocked.gif', 'description' => $txt['icon_shocked']), array('code' => '8)', 'filename' => 'cool.gif', 'description' => $txt['icon_cool']), array('code' => '???', 'filename' => 'huh.gif', 'description' => $txt['icon_huh']), array('code' => '::)', 'filename' => 'rolleyes.gif', 'description' => $txt['icon_rolleyes']), array('code' => ':P', 'filename' => 'tongue.gif', 'description' => $txt['icon_tongue']), array('code' => ':-[', 'filename' => 'embarrassed.gif', 'description' => $txt['icon_embarrassed']), array('code' => ':-X', 'filename' => 'lipsrsealed.gif', 'description' => $txt['icon_lips']), array('code' => ':-\\', 'filename' => 'undecided.gif', 'description' => $txt['icon_undecided']), array('code' => ':-*', 'filename' => 'kiss.gif', 'description' => $txt['icon_kiss']), array('code' => 'O:)', 'filename' => 'angel.gif', 'description' => $txt['icon_angel']), array('code' => ':\'(', 'filename' => 'cry.gif', 'description' => $txt['icon_cry'], 'isLast' => true)), 'isLast' => true); } elseif ($user_info['smiley_set'] != 'none') { if (($temp = cache_get_data('posting_smileys', 480)) == null) { $request = $db->query('', ' SELECT code, filename, description, smiley_row, hidden FROM {db_prefix}smileys WHERE hidden IN (0, 2) ORDER BY smiley_row, smiley_order', array()); while ($row = $db->fetch_assoc($request)) { $row['filename'] = htmlspecialchars($row['filename'], ENT_COMPAT, 'UTF-8'); $row['description'] = htmlspecialchars($row['description'], ENT_COMPAT, 'UTF-8'); $context['smileys'][empty($row['hidden']) ? 'postform' : 'popup'][$row['smiley_row']]['smileys'][] = $row; } $db->free_result($request); foreach ($context['smileys'] as $section => $smileyRows) { $last_row = null; foreach ($smileyRows as $rowIndex => $smileys) { $context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true; $last_row = $rowIndex; } if ($last_row !== null) { $context['smileys'][$section][$last_row]['isLast'] = true; } } cache_put_data('posting_smileys', $context['smileys'], 480); } else { $context['smileys'] = $temp; } // The smiley popup may take advantage of Jquery UI .... if (!empty($context['smileys']['popup'])) { $modSettings['jquery_include_ui'] = true; } } } // Set a flag so the sub template knows what to do... $context['show_bbc'] = !empty($modSettings['enableBBC']) && !empty($settings['show_bbc']); // Switch the URLs back... now we're back to whatever the main sub template is. (like folder in PersonalMessage.) if (isset($settings['use_default_images']) && $settings['use_default_images'] == 'defaults' && isset($settings['default_template'])) { $settings['theme_url'] = $temp1; $settings['images_url'] = $temp2; $settings['theme_dir'] = $temp3; } if (!empty($editorOptions['live_errors'])) { loadLanguage('Errors'); addInlineJavascript(' error_txts[\'no_subject\'] = ' . JavaScriptEscape($txt['error_no_subject']) . '; error_txts[\'no_message\'] = ' . JavaScriptEscape($txt['error_no_message']) . '; var subject_err = new errorbox_handler({ self: \'subject_err\', error_box_id: \'post_error\', error_checks: [{ code: \'no_subject\', efunction: function(box_value) { if (box_value.length === 0) return true; else return false; } }], check_id: "post_subject" }); var body_err_' . $editorOptions['id'] . ' = new errorbox_handler({ self: \'body_err_' . $editorOptions['id'] . '\', error_box_id: \'post_error\', error_checks: [{ code: \'no_message\', efunction: function(box_value) { if (box_value.length === 0) return true; else return false; } }], editor_id: \'' . $editorOptions['id'] . '\', editor: ' . JavaScriptEscape(' (function () { return $editor_data[\'' . $editorOptions['id'] . '\'].val(); });') . ' });', true); } }
/** * This function determines the actions of the members passed in urls. * * Adding actions to the Who's Online list: * Adding actions to this list is actually relatively easy... * - for actions anyone should be able to see, just add a string named whoall_ACTION. * (where ACTION is the action used in index.php.) * - for actions that have a subaction which should be represented differently, use whoall_ACTION_SUBACTION. * - for actions that include a topic, and should be restricted, use whotopic_ACTION. * - for actions that use a message, by msg or quote, use whopost_ACTION. * - for administrator-only actions, use whoadmin_ACTION. * - for actions that should be viewable only with certain permissions, use whoallow_ACTION and * add a list of possible permissions to the $allowedActions array, using ACTION as the key. * * @param mixed[]|string $urls a single url (string) or an array of arrays, each inner array being (serialized request data, id_member) * @param string|false $preferred_prefix = false * @return mixed[]|string an array of descriptions if you passed an array, otherwise the string describing their current location. */ function determineActions($urls, $preferred_prefix = false) { global $txt, $user_info, $modSettings, $scripturl; $db = database(); if (!allowedTo('who_view')) { return array(); } loadLanguage('Who'); // Actions that require a specific permission level. $allowedActions = array('admin' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'admin_forum', 'manage_permissions', 'send_mail', 'manage_attachments', 'manage_smileys', 'manage_boards', 'edit_news'), 'ban' => array('manage_bans'), 'boardrecount' => array('admin_forum'), 'calendar' => array('calendar_view'), 'editnews' => array('edit_news'), 'mailing' => array('send_mail'), 'maintain' => array('admin_forum'), 'manageattachments' => array('manage_attachments'), 'manageboards' => array('manage_boards'), 'memberlist' => array('view_mlist'), 'moderate' => array('access_mod_center', 'moderate_forum', 'manage_membergroups'), 'optimizetables' => array('admin_forum'), 'repairboards' => array('admin_forum'), 'search' => array('search_posts'), 'setcensor' => array('moderate_forum'), 'setreserve' => array('moderate_forum'), 'stats' => array('view_stats'), 'viewErrorLog' => array('admin_forum'), 'viewmembers' => array('moderate_forum')); // Provide integration a way to add to the allowed action array call_integration_hook('integrate_whos_online_allowed', array(&$allowedActions)); if (!is_array($urls)) { $url_list = array(array($urls, $user_info['id'])); } else { $url_list = $urls; } // These are done to query these in large chunks. (instead of one by one.) $topic_ids = array(); $profile_ids = array(); $board_ids = array(); $data = array(); foreach ($url_list as $k => $url) { // Get the request parameters.. $actions = @unserialize($url[0]); if ($actions === false) { continue; } // If it's the admin or moderation center, and there is an area set, use that instead. if (isset($actions['action']) && ($actions['action'] == 'admin' || $actions['action'] == 'moderate') && isset($actions['area'])) { $actions['action'] = $actions['area']; } // Check if there was no action or the action is display. if (!isset($actions['action']) || $actions['action'] == 'display') { // It's a topic! Must be! if (isset($actions['topic'])) { // Assume they can't view it, and queue it up for later. $data[$k] = $txt['who_hidden']; $topic_ids[(int) $actions['topic']][$k] = $txt['who_topic']; } elseif (isset($actions['board'])) { // Hide first, show later. $data[$k] = $txt['who_hidden']; $board_ids[$actions['board']][$k] = $txt['who_board']; } else { $data[$k] = replaceBasicActionUrl($txt['who_index']); } } elseif ($actions['action'] == '') { $data[$k] = replaceBasicActionUrl($txt['who_index']); } else { // Viewing/editing a profile. if ($actions['action'] == 'profile') { // Whose? Their own? if (empty($actions['u'])) { require_once SUBSDIR . '/Profile.subs.php'; $memID = currentMemberID(); if ($memID == $user_info['id']) { $actions['u'] = $url[1]; } else { $actions['u'] = $memID; } } $data[$k] = $txt['who_hidden']; $profile_ids[(int) $actions['u']][$k] = $actions['action'] == 'profile' ? $txt['who_viewprofile'] : $txt['who_profile']; } elseif (($actions['action'] == 'post' || $actions['action'] == 'post2' || $actions['action'] == 'topicbyemail') && empty($actions['topic']) && isset($actions['board'])) { $data[$k] = $txt['who_hidden']; if ($actions['action'] == 'topicbyemail') { $board_ids[(int) $actions['board']][$k] = $txt['who_topicbyemail']; } else { $board_ids[(int) $actions['board']][$k] = isset($actions['poll']) ? $txt['who_poll'] : $txt['who_post']; } } elseif (isset($actions['sa']) && isset($txt['whoall_' . $actions['action'] . '_' . $actions['sa']])) { $data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']]) ? $txt[$preferred_prefix . $actions['action'] . '_' . $actions['sa']] : $txt['whoall_' . $actions['action'] . '_' . $actions['sa']]; } elseif (isset($txt['whoall_' . $actions['action']])) { $data[$k] = $preferred_prefix && isset($txt[$preferred_prefix . $actions['action']]) ? $txt[$preferred_prefix . $actions['action']] : replaceBasicActionUrl($txt['whoall_' . $actions['action']]); } elseif (isset($txt['whotopic_' . $actions['action']])) { // Find out what topic they are accessing. $topic = (int) (isset($actions['topic']) ? $actions['topic'] : (isset($actions['from']) ? $actions['from'] : 0)); $data[$k] = $txt['who_hidden']; $topic_ids[$topic][$k] = $txt['whotopic_' . $actions['action']]; } elseif (isset($actions['sa']) && isset($txt['whotopic_' . $actions['action'] . '_' . $actions['sa']])) { // Find out what topic they are accessing. $topic = (int) (isset($actions['topic']) ? $actions['topic'] : (isset($actions['from']) ? $actions['from'] : 0)); $data[$k] = $txt['who_hidden']; $topic_ids[$topic][$k] = $txt['whotopic_' . $actions['action'] . '_' . $actions['sa']]; } elseif (isset($txt['whopost_' . $actions['action']])) { // Find out what message they are accessing. $msgid = (int) (isset($actions['msg']) ? $actions['msg'] : (isset($actions['quote']) ? $actions['quote'] : 0)); $result = $db->query('', ' SELECT m.id_topic, m.subject FROM {db_prefix}messages AS m INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board) INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ') WHERE m.id_msg = {int:id_msg} AND {query_see_board}' . ($modSettings['postmod_active'] ? ' AND m.approved = {int:is_approved}' : '') . ' LIMIT 1', array('is_approved' => 1, 'id_msg' => $msgid)); list($id_topic, $subject) = $db->fetch_row($result); $data[$k] = sprintf($txt['whopost_' . $actions['action']], $scripturl . '?topic=' . $id_topic . '.0', $subject); $db->free_result($result); if (empty($id_topic)) { $data[$k] = $txt['who_hidden']; } } elseif (allowedTo('moderate_forum') && isset($txt['whoadmin_' . $actions['action']])) { $data[$k] = $txt['whoadmin_' . $actions['action']]; } elseif (isset($allowedActions[$actions['action']])) { if (allowedTo($allowedActions[$actions['action']])) { if (isset($actions['sa']) && isset($txt['whoallow_' . $actions['action'] . '_' . $actions['sa']])) { $data[$k] = replaceBasicActionUrl($txt['whoallow_' . $actions['action'] . '_' . $actions['sa']]); } else { $data[$k] = replaceBasicActionUrl($txt['whoallow_' . $actions['action']]); } } elseif (in_array('moderate_forum', $allowedActions[$actions['action']])) { $data[$k] = $txt['who_moderate']; } elseif (in_array('admin_forum', $allowedActions[$actions['action']])) { $data[$k] = $txt['who_admin']; } else { $data[$k] = $txt['who_hidden']; } } elseif (!empty($actions['action'])) { $data[$k] = sprintf($txt['who_generic'], $actions['action']); } else { $data[$k] = $txt['who_unknown']; } } // Maybe the action is integrated into another system? if (count($integrate_actions = call_integration_hook('integrate_whos_online', array($actions))) > 0) { // Try each integraion hook with this url and see if they can fill in the details foreach ($integrate_actions as $integrate_action) { if (!empty($integrate_action)) { // Found it, all done then $data[$k] = $integrate_action; break; } } } } // Load topic names. if (!empty($topic_ids)) { require_once SUBSDIR . '/Topic.subs.php'; $topics_data = topicsList(array_keys($topic_ids)); foreach ($topics_data as $topic) { // Show the topic's subject for each of the members looking at this... foreach ($topic_ids[$topic['id_topic']] as $k => $session_text) { $data[$k] = sprintf($session_text, $scripturl . '?topic=' . $topic['id_topic'] . '.0', $topic['subject']); } } } // Load board names. if (!empty($board_ids)) { require_once SUBSDIR . '/Boards.subs.php'; $boards_list = getBoardList(array('included_boards' => array_keys($board_ids)), true); foreach ($boards_list as $board) { // Put the board name into the string for each member... foreach ($board_ids[$board['id_board']] as $k => $session_text) { $data[$k] = sprintf($session_text, $scripturl . '?board=' . $board['id_board'] . '.0', $board['board_name']); } } } // Load member names for the profile. if (!empty($profile_ids) && (allowedTo('profile_view_any') || allowedTo('profile_view_own'))) { require_once SUBSDIR . '/Members.subs.php'; $result = getBasicMemberData(array_keys($profile_ids)); foreach ($result as $row) { // If they aren't allowed to view this person's profile, skip it. if (!allowedTo('profile_view_any') && $user_info['id'] != $row['id_member']) { continue; } // Set their action on each - session/text to sprintf. foreach ($profile_ids[$row['id_member']] as $k => $session_text) { $data[$k] = sprintf($session_text, $scripturl . '?action=profile;u=' . $row['id_member'], $row['real_name']); } } } if (!is_array($urls)) { return isset($data[0]) ? $data[0] : false; } else { return $data; } }
function isJigou($userinfo) { $this->load > database(); if ($userinfo['isOrg'] == 1) { return false; } $jg = $this->db->query("SELECT * FROM `org_jigou` WHERE id=" . $userinfo['jigouId'])->row_array(); if (!$jg || $jg['fenxiao'] == 1) { return false; } $rOrg = $this->db->query("SELECT * FROM `org_users` WHERE wId='" . $userinfo['wId'] . "'")->row_array(); if ($rOrg) { if ($rOrg['isFx'] == 1) { $this->db->query("update users set `jerror`=1,`isOrg`=1 where userId=" . $userinfo['userId']); $add = array(); $add['isFx'] = 2; $this->db->update("org_users", $add, array("wId" => $userinfo['wId'])); return false; } } $insert = array(); $insert['cname'] = $userinfo['name']; $insert['mobilenumber'] = $userinfo['mobile']; $insert['touxiang'] = $userinfo['userpic']; $insert['wId'] = $userinfo['wId']; $insert['jigouId'] = $userinfo['jigouId']; $insert['addtime'] = date("Y-m-d H:i:s"); $insert['isFx'] = 2; $insert['flag'] = 1; $this->db->insert("org_users", $insert); $ids = $this->db->insert_id(); if ($ids > 0) { $this->db->query("update users set `jerror`=1,`isOrg`=1 where userId=" . $userinfo['userId']); $this->load->library('Randqrcode'); $sqls['data'] = "http://kimeng.4001881788.com/juan/jinming?ruserId=" . $ids . "&&jigouId=" . $userinfo['jigouId']; $qrpic = $this->randqrcode->qrcodeZc($sqls); $this->Common->imageWaterMark("./" . $qrpic, 5, "./static/v12/sy/logo.png"); $add = array(); $add['qrpic'] = $qrpic; $this->db->update("org_users", $add, array("id" => $ids)); $this->db->close(); } }