function pagefromtemplate(&$event, $param) { if (strlen(trim($_REQUEST['newpagetemplate'])) > 0) { global $conf; global $INFO; global $ID; $tpl = io_readFile(wikiFN($_REQUEST['newpagetemplate'])); if ($this->getConf('userreplace')) { $stringvars = array_map(create_function('$v', 'return explode(",",$v,2);'), explode(';', $_REQUEST['newpagevars'])); foreach ($stringvars as $value) { $tpl = str_replace(trim($value[0]), trim($value[1]), $tpl); } } if ($this->getConf('standardreplace')) { // replace placeholders $file = noNS($ID); $page = strtr($file, '_', ' '); $tpl = str_replace(array('@ID@', '@NS@', '@FILE@', '@!FILE@', '@!FILE!@', '@PAGE@', '@!PAGE@', '@!!PAGE@', '@!PAGE!@', '@USER@', '@NAME@', '@MAIL@', '@DATE@'), array($ID, getNS($ID), $file, utf8_ucfirst($file), utf8_strtoupper($file), $page, utf8_ucfirst($page), utf8_ucwords($page), utf8_strtoupper($page), $_SERVER['REMOTE_USER'], $INFO['userinfo']['name'], $INFO['userinfo']['mail'], $conf['dformat']), $tpl); // we need the callback to work around strftime's char limit $tpl = preg_replace_callback('/%./', create_function('$m', 'return strftime($m[0]);'), $tpl); } $event->result = $tpl; $event->preventDefault(); } }
public function actionOptions() { $cors = $this->_request->getHeader('Access-Control-Request-Method'); if (!empty($cors)) { return $this->responseData('bdApi_ViewApi_Helper_Options'); } $action = $this->_input->filterSingle('action', XenForo_Input::STRING); $action = str_replace(array('-', '/'), ' ', utf8_strtolower($action)); $action = str_replace(' ', '', utf8_ucwords($action)); $methods = array(); /* @var $fc XenForo_FrontController */ $fc = XenForo_Application::get('_bdApi_fc'); XenForo_Application::set('_bdApi_disableBatch', true); foreach (array('Get', 'Post', 'Put') as $method) { $controllerMethod = sprintf('action%s%s', $method, $action); if (is_callable(array($this, $controllerMethod))) { $method = utf8_strtoupper($method); $methods[$method] = array(); bdApi_Input::bdApi_resetFilters(); $routeMatch = new XenForo_RouteMatch($this->_routeMatch->getControllerName(), sprintf('%s-%s', $method, $action)); try { $fc->dispatch($routeMatch); } catch (Exception $e) { // ignore } $params = bdApi_Input::bdApi_getFilters(); foreach (array_keys($params) as $paramKey) { if (in_array($paramKey, array('fields_include', 'fields_exclude', 'limit', 'locale', 'page'), true)) { // system wide params, ignore unset($params[$paramKey]); continue; } if (!isset($_GET[$paramKey]) && $this->_input->inRequest($paramKey)) { // apparently this param is set by the route class unset($params[$paramKey]); continue; } } ksort($params); $methods[$method]['parameters'] = array_values($params); } } $allowedMethods = array_keys($methods); $allowedMethods[] = 'OPTIONS'; $this->_response->setHeader('Allow', implode(',', $allowedMethods)); return $this->responseData('bdApi_ViewApi_Helper_Options', $methods); }
if (utf8_strlen($subject) > 70) { $errors[] = $lang_post['Too long subject']; } else { if ($forum_config['p_subject_all_caps'] == '0' && utf8_strtoupper($subject) == $subject && !$forum_page['is_admmod']) { $subject = utf8_ucwords(utf8_strtolower($subject)); } } } } // Clean up message from POST $message = forum_linebreaks(forum_trim($_POST['req_message'])); if (strlen($message) > FORUM_MAX_POSTSIZE_BYTES) { $errors[] = sprintf($lang_post['Too long message'], forum_number_format(strlen($message)), forum_number_format(FORUM_MAX_POSTSIZE_BYTES)); } else { if ($forum_config['p_message_all_caps'] == '0' && utf8_strtoupper($message) == $message && !$forum_page['is_admmod']) { $message = utf8_ucwords(utf8_strtolower($message)); } } // Validate BBCode syntax if ($forum_config['p_message_bbcode'] == '1' || $forum_config['o_make_links'] == '1') { if (!defined('FORUM_PARSER_LOADED')) { require FORUM_ROOT . 'include/parser.php'; } $message = preparse_bbcode($message, $errors); } if ($message == '') { $errors[] = $lang_post['No message']; } $hide_smilies = isset($_POST['hide_smilies']) ? 1 : 0; ($hook = get_hook('ed_end_validation')) ? eval($hook) : null; // Did everything go according to plan?
/** * UTF-8 aware alternative to ucwords * Uppercase the first character of each word in a string * * @param string $str String to be processed * * @return string String with first char of each word uppercase * * @see http://www.php.net/ucwords * @since 2.0 */ public static function ucwords($str) { if (!function_exists('utf8_ucwords')) { require_once __DIR__ . '/phputf8/ucwords.php'; } return utf8_ucwords($str); }
/** * Returns given word as CamelCased * * Converts a word like "send_email" to "SendEmail". It * will remove non alphanumeric character from the word, so * "who's online" will be converted to "WhoSOnline" * * @access public * @static * @see variablize * @param string $word Word to convert to camel case * @return string UpperCamelCasedWord */ public static function camelize($word, $ucfirst = true) { $word = self::latinize($word); if (preg_match('/[^A-Z^a-z^0-9]+/', $word) == 0) { return $ucfirst ? utf8_ucfirst($word) : $word; } $word = str_replace(' ', '', utf8_ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); if (!$ucfirst) { $word = substr_replace($word, strtolower(substr($word, 0, 1)), 0, 1); } return $word; }
} break; case 'personality': $form = array(); // Clean up signature from POST if ($pun_config['o_signatures'] == '1') { $form['signature'] = pun_linebreaks(pun_trim($_POST['signature'])); // Validate signature if (pun_strlen($form['signature']) > $pun_config['p_sig_length']) { message(sprintf($lang_prof_reg['Sig too long'], $pun_config['p_sig_length'], pun_strlen($form['signature']) - $pun_config['p_sig_length'])); } else { if (substr_count($form['signature'], "\n") > $pun_config['p_sig_lines'] - 1) { message(sprintf($lang_prof_reg['Sig too many lines'], $pun_config['p_sig_lines'])); } else { if ($form['signature'] && $pun_config['p_sig_all_caps'] == '0' && is_all_uppercase($form['signature']) && !$pun_user['is_admmod']) { $form['signature'] = utf8_ucwords(utf8_strtolower($form['signature'])); } } } // Validate BBCode syntax if ($pun_config['p_sig_bbcode'] == '1') { require PUN_ROOT . 'include/parser.php'; $errors = array(); $form['signature'] = preparse_bbcode($form['signature'], $errors, true); if (count($errors) > 0) { message('<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'); } } } break; case 'display':
/** * Changes a wiki page id into proper case (allowing for :'s etc...) * @param string $id page id * @return string */ private function _proper($id) { $id = str_replace(':', ': ', $id); // make a little whitespace before words so ucwords can work! $id = str_replace('_', ' ', $id); $id = utf8_ucwords($id); $id = str_replace(': ', ':', $id); return $id; }
/** * Verifies that the discussion title is valid * * @param string * * @return boolean */ protected function _verifyTitle(&$title) { // TODO: send these to callbacks to allow hookability? switch ($this->getOption(self::OPTION_ADJUST_TITLE_CASE)) { case 'ucfirst': // sentence case $title = utf8_ucfirst(utf8_strtolower($title)); break; case 'ucwords': // title case $title = utf8_ucwords(utf8_strtolower($title)); break; } if ($this->getOption(self::OPTION_TRIM_TITLE)) { $table = reset($this->_fields); $title = XenForo_Helper_String::wholeWordTrim($title, $table['title']['maxLength'] - 5); } return true; }
function testLinefeed() { $str = "iñt ërn âti\n ônà liz æti øn"; $ucwords = "Iñt Ërn Âti\n Ônà Liz Æti Øn"; $this->assertEqual(utf8_ucwords($str), $ucwords); }
function _handle_ajax($event) { if (strpos($event->data, 'data_page_') !== 0) { return; } $event->preventDefault(); $type = substr($event->data, 10); $aliases = $this->dthlp->_aliases(); if (!isset($aliases[$type])) { echo 'Unknown type'; return; } if ($aliases[$type]['type'] !== 'page') { echo 'AutoCompletion is only supported for page types'; return; } if (substr($aliases[$type]['postfix'], -1, 1) === ':') { // Resolve namespace start page ID global $conf; $aliases[$type]['postfix'] .= $conf['start']; } $search = $_POST['search']; $pages = ft_pageLookup($search, false, false); $regexp = '/^'; if ($aliases[$type]['prefix'] !== '') { $regexp .= preg_quote($aliases[$type]['prefix'], '/'); } $regexp .= '([^:]+)'; if ($aliases[$type]['postfix'] !== '') { $regexp .= preg_quote($aliases[$type]['postfix'], '/'); } $regexp .= '$/'; $result = array(); foreach ($pages as $page => $title) { $id = array(); if (!preg_match($regexp, $page, $id)) { // Does not satisfy the postfix and prefix criteria continue; } $id = $id[1]; if ($search !== '' && stripos($id, cleanID($search)) === false && stripos($title, $search) === false) { // Search string is not in id part or title continue; } if ($title === '') { $title = utf8_ucwords(str_replace('_', ' ', $id)); } $result[hsc($id)] = hsc($title); } $json = new JSON(); echo '(' . $json->encode($result) . ')'; }
/** * UTF-8 aware alternative to ucwords() * * Uppercase the first character of each word in a string. * * @param string $str String to be processed * * @return string String with first char of each word uppercase * * @see http://www.php.net/ucwords * @since 1.3.0 */ public static function ucwords($str) { return utf8_ucwords($str); }
/** * Returns the pagetemplate contents for the ID's namespace * * @author Andreas Gohr <*****@*****.**> */ function pageTemplate($data) { $id = $data[0]; global $conf; global $INFO; $path = dirname(wikiFN($id)); if (@file_exists($path . '/_template.txt')) { $tpl = io_readFile($path . '/_template.txt'); } else { // search upper namespaces for templates $len = strlen(rtrim($conf['datadir'], '/')); while (strlen($path) >= $len) { if (@file_exists($path . '/__template.txt')) { $tpl = io_readFile($path . '/__template.txt'); break; } $path = substr($path, 0, strrpos($path, '/')); } } if (!$tpl) { return ''; } // replace placeholders $file = noNS($id); $page = strtr($file, '_', ' '); $tpl = str_replace(array('@ID@', '@NS@', '@FILE@', '@!FILE@', '@!FILE!@', '@PAGE@', '@!PAGE@', '@!!PAGE@', '@!PAGE!@', '@USER@', '@NAME@', '@MAIL@', '@DATE@'), array($id, getNS($id), $file, utf8_ucfirst($file), utf8_strtoupper($file), $page, utf8_ucfirst($page), utf8_ucwords($page), utf8_strtoupper($page), $_SERVER['REMOTE_USER'], $INFO['userinfo']['name'], $INFO['userinfo']['mail'], $conf['dformat']), $tpl); // we need the callback to work around strftime's char limit $tpl = preg_replace_callback('/%./', create_function('$m', 'return strftime($m[0]);'), $tpl); return $tpl; }
function startescrow_send_message($body, $subject, $receiver_username, $amount, &$message_id) { global $lang_escrows, $forum_user, $forum_db, $forum_url, $forum_config, $forum_flash; $errors = array(); $receiver_id = startescrow_get_receiver_id($receiver_username, $errors); if ($receiver_id == 'NULL' && empty($errors)) { $errors[] = $lang_escrows['Empty receiver']; } // Clean up body from POST $body = forum_linebreaks($body); if ($body == '') { $errors[] = $lang_escrows['Empty body']; } elseif (strlen($body) > FORUM_MAX_POSTSIZE_BYTES) { $errors[] = sprintf($lang_escrows['Too long message'], forum_number_format(strlen($body)), forum_number_format(FORUM_MAX_POSTSIZE_BYTES)); } elseif ($forum_config['p_message_all_caps'] == '0' && utf8_strtoupper($body) == $body && !$forum_page['is_admmod']) { $body = utf8_ucwords(utf8_strtolower($body)); } // Validate BBCode syntax if ($forum_config['p_message_bbcode'] == '1' || $forum_config['o_make_links'] == '1') { global $smilies; if (!defined('FORUM_PARSER_LOADED')) { require FORUM_ROOT . 'include/parser.php'; } $body = preparse_bbcode($body, $errors); } // Sending message to the buyer $btcaddress = get_free_btcaddress($errors); //book the address if (count($errors)) { return $errors; } $now = time(); // Send new message // Save to DB $query = array('INSERT' => 'sender_id, receiver_id, status, lastedited_at, read_at, subject, body', 'INTO' => 'pun_pm_messages', 'VALUES' => $forum_user['id'] . ', ' . $receiver_id . ', \'sent\', ' . $now . ', 0, \'' . $forum_db->escape($subject) . '\', \'' . $forum_db->escape($body) . '\''); $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); $endtime = $now + $forum_config['o_empty_escrow_duration'] * 3600; $endtime = date('Y-m-d H:i:s ', $endtime); // Send message to the buyer $body = sprintf($lang_escrows['Escrow buyer message'], $endtime, $amount, $btcaddress); // Save to DB $query = array('INSERT' => 'receiver_id, sender_id, status, lastedited_at, read_at, subject, body', 'INTO' => 'pun_pm_messages', 'VALUES' => $forum_user['id'] . ', ' . $receiver_id . ', \'sent\', ' . $now . ', 0, \'' . $forum_db->escape($subject) . '\', \'' . $forum_db->escape($body) . '\''); $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); // ########### Add to escrows table $query = array('INSERT' => 'time, buyerid, sellerid, amount, subject, status, recivedtime, btcaddress', 'INTO' => 'escrows', 'VALUES' => $now . ', ' . $forum_user['id'] . ', ' . $receiver_id . ', ' . $amount . ', \'' . $forum_db->escape($subject) . '\', 0, 0, \'' . $btcaddress . '\''); $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); startescrow_clear_cache($receiver_id); // Clear cached 'New messages' in the user table $forum_flash->add_info($lang_escrows['Escrow started']); redirect(forum_link($forum_url['pun_pm_inbox']), $lang_escrows['Message sent']); }
function get_std_replacements() { if (!$this->getConf('stdreplace')) { return array(); } global $conf; global $INFO; global $ID; $file = noNS($ID); $page = cleanID($file); $names = array('ID', 'NS', 'FILE', '!FILE', '!FILE!', 'PAGE', '!PAGE', '!!PAGE', '!PAGE!', 'USER', 'DATE', 'EVENT'); $values = array($ID, getNS($ID), $file, utf8_ucfirst($file), utf8_strtoupper($file), $page, utf8_ucfirst($page), utf8_ucwords($page), utf8_strtoupper($page), $_SERVER['REMOTE_USER'], strftime($conf['dformat'], time()), $event->name); $std_replacements = array(); for ($i = 0; $i < count($names); $i++) { $std_replacements[$names[$i]] = $values[$i]; } return $std_replacements; }
public function update_profile($id, $info, $section) { $info = Container::get('hooks')->fire('model.profile.update_profile_start', $info, $id, $section); $username_updated = false; $section = Container::get('hooks')->fire('model.profile.update_profile_section', $section, $id, $info); // Validate input depending on section switch ($section) { case 'essentials': $form = array('timezone' => floatval(Input::post('form_timezone')), 'dst' => Input::post('form_dst') ? '1' : '0', 'time_format' => intval(Input::post('form_time_format')), 'date_format' => intval(Input::post('form_date_format'))); // Make sure we got a valid language string if (Input::post('form_language')) { $languages = \FeatherBB\Core\Lister::getLangs(); $form['language'] = Utils::trim(Input::post('form_language')); if (!in_array($form['language'], $languages)) { throw new Error(__('Bad request'), 404); } } if (User::get()->is_admmod) { $form['admin_note'] = Utils::trim(Input::post('admin_note')); // Are we allowed to change usernames? if (User::get()->g_id == ForumEnv::get('FEATHER_ADMIN') || User::get()->g_moderator == '1' && User::get()->g_mod_rename_users == '1') { $form['username'] = Utils::trim(Input::post('req_username')); if ($form['username'] != $info['old_username']) { $errors = ''; $errors = $this->check_username($form['username'], $errors, $id); if (!empty($errors)) { throw new Error($errors[0]); } $username_updated = true; } } // We only allow administrators to update the post count if (User::get()->g_id == ForumEnv::get('FEATHER_ADMIN')) { $form['num_posts'] = intval(Input::post('num_posts')); } } if (ForumSettings::get('o_regs_verify') == '0' || User::get()->is_admmod) { // Validate the email address $form['email'] = strtolower(Utils::trim(Input::post('req_email'))); if (!Container::get('email')->is_valid_email($form['email'])) { throw new Error(__('Invalid email')); } } break; case 'personal': $form = array('realname' => Input::post('form_realname') ? Utils::trim(Input::post('form_realname')) : '', 'url' => Input::post('form_url') ? Utils::trim(Input::post('form_url')) : '', 'location' => Input::post('form_location') ? Utils::trim(Input::post('form_location')) : ''); // Add http:// if the URL doesn't contain it already (while allowing https://, too) if (User::get()->g_post_links == '1') { if ($form['url'] != '') { $url = Url::is_valid($form['url']); if ($url === false) { throw new Error(__('Invalid website URL')); } $form['url'] = $url['url']; } } else { if (!empty($form['url'])) { throw new Error(__('Website not allowed')); } $form['url'] = ''; } if (User::get()->g_id == ForumEnv::get('FEATHER_ADMIN')) { $form['title'] = Utils::trim(Input::post('title')); } elseif (User::get()->g_set_title == '1') { $form['title'] = Utils::trim(Input::post('title')); if ($form['title'] != '') { // A list of words that the title may not contain // If the language is English, there will be some duplicates, but it's not the end of the world $forbidden = array('member', 'moderator', 'administrator', 'banned', 'guest', utf8_strtolower(__('Member')), utf8_strtolower(__('Moderator')), utf8_strtolower(__('Administrator')), utf8_strtolower(__('Banned')), utf8_strtolower(__('Guest'))); if (in_array(utf8_strtolower($form['title']), $forbidden)) { throw new Error(__('Forbidden title')); } } } break; case 'messaging': $form = array('jabber' => Utils::trim(Input::post('form_jabber')), 'icq' => Utils::trim(Input::post('form_icq')), 'msn' => Utils::trim(Input::post('form_msn')), 'aim' => Utils::trim(Input::post('form_aim')), 'yahoo' => Utils::trim(Input::post('form_yahoo'))); // If the ICQ UIN contains anything other than digits it's invalid if (preg_match('%[^0-9]%', $form['icq'])) { throw new Error(__('Bad ICQ')); } break; case 'personality': $form = array(); // Clean up signature from POST if (ForumSettings::get('o_signatures') == '1') { $form['signature'] = Utils::linebreaks(Utils::trim(Input::post('signature'))); // Validate signature if (Utils::strlen($form['signature']) > ForumSettings::get('p_sig_length')) { throw new Error(sprintf(__('Sig too long'), ForumSettings::get('p_sig_length'), Utils::strlen($form['signature']) - ForumSettings::get('p_sig_length'))); } elseif (substr_count($form['signature'], "\n") > ForumSettings::get('p_sig_lines') - 1) { throw new Error(sprintf(__('Sig too many lines'), ForumSettings::get('p_sig_lines'))); } elseif ($form['signature'] && ForumSettings::get('p_sig_all_caps') == '0' && Utils::is_all_uppercase($form['signature']) && !User::get()->is_admmod) { $form['signature'] = utf8_ucwords(utf8_strtolower($form['signature'])); } // Validate BBCode syntax if (ForumSettings::get('p_sig_bbcode') == '1') { $errors = array(); $form['signature'] = Container::get('parser')->preparse_bbcode($form['signature'], $errors, true); if (count($errors) > 0) { throw new Error('<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'); } } } break; case 'display': $form = array('disp_topics' => Utils::trim(Input::post('form_disp_topics')), 'disp_posts' => Utils::trim(Input::post('form_disp_posts')), 'show_smilies' => Input::post('form_show_smilies') ? '1' : '0', 'show_img' => Input::post('form_show_img') ? '1' : '0', 'show_img_sig' => Input::post('form_show_img_sig') ? '1' : '0', 'show_avatars' => Input::post('form_show_avatars') ? '1' : '0', 'show_sig' => Input::post('form_show_sig') ? '1' : '0'); if ($form['disp_topics'] != '') { $form['disp_topics'] = intval($form['disp_topics']); if ($form['disp_topics'] < 3) { $form['disp_topics'] = 3; } elseif ($form['disp_topics'] > 75) { $form['disp_topics'] = 75; } } if ($form['disp_posts'] != '') { $form['disp_posts'] = intval($form['disp_posts']); if ($form['disp_posts'] < 3) { $form['disp_posts'] = 3; } elseif ($form['disp_posts'] > 75) { $form['disp_posts'] = 75; } } // Make sure we got a valid style string if (Input::post('form_style')) { $styles = \FeatherBB\Core\Lister::getStyles(); $form['style'] = Utils::trim(Input::post('form_style')); if (!in_array($form['style'], $styles)) { throw new Error(__('Bad request'), 404); } } break; case 'privacy': $form = array('email_setting' => intval(Input::post('form_email_setting')), 'notify_with_post' => Input::post('form_notify_with_post') ? '1' : '0', 'auto_notify' => Input::post('form_auto_notify') ? '1' : '0'); if ($form['email_setting'] < 0 || $form['email_setting'] > 2) { $form['email_setting'] = ForumSettings::get('o_default_email_setting'); } break; default: throw new Error(__('Bad request'), 404); } $form = Container::get('hooks')->fire('model.profile.update_profile_form', $form, $section, $id, $info); // Single quotes around non-empty values and nothing for empty values $temp = array(); foreach ($form as $key => $input) { $temp[$key] = $input; } if (empty($temp)) { throw new Error(__('Bad request'), 404); } $update_user = DB::for_table('users')->where('id', $id)->find_one()->set($temp); $update_user = Container::get('hooks')->fireDB('model.profile.update_profile_query', $update_user); $update_user = $update_user->save(); // If we changed the username we have to update some stuff if ($username_updated) { $bans_updated = DB::for_table('bans')->where('username', $info['old_username']); $bans_updated = Container::get('hooks')->fireDB('model.profile.update_profile_bans_updated', $bans_updated); $bans_updated = $bans_updated->update_many('username', $form['username']); $update_poster_id = DB::for_table('posts')->where('poster_id', $id); $update_poster_id = Container::get('hooks')->fireDB('model.profile.update_profile_poster_id', $update_poster_id); $update_poster_id = $update_poster_id->update_many('poster', $form['username']); $update_posts = DB::for_table('posts')->where('edited_by', $info['old_username']); $update_posts = Container::get('hooks')->fireDB('model.profile.update_profile_posts', $update_posts); $update_posts = $update_posts->update_many('edited_by', $form['username']); $update_topics_poster = DB::for_table('topics')->where('poster', $info['old_username']); $update_topics_poster = Container::get('hooks')->fireDB('model.profile.update_profile_topics_poster', $update_topics_poster); $update_topics_poster = $update_topics_poster->update_many('poster', $form['username']); $update_topics_last_poster = DB::for_table('topics')->where('last_poster', $info['old_username']); $update_topics_last_poster = Container::get('hooks')->fireDB('model.profile.update_profile_topics_last_poster', $update_topics_last_poster); $update_topics_last_poster = $update_topics_last_poster->update_many('last_poster', $form['username']); $update_forums = DB::for_table('forums')->where('last_poster', $info['old_username']); $update_forums = Container::get('hooks')->fireDB('model.profile.update_profile_forums', $update_forums); $update_forums = $update_forums->update_many('last_poster', $form['username']); $update_online = DB::for_table('online')->where('ident', $info['old_username']); $update_online = Container::get('hooks')->fireDB('model.profile.update_profile_online', $update_online); $update_online = $update_online->update_many('ident', $form['username']); // If the user is a moderator or an administrator we have to update the moderator lists $group_id = DB::for_table('users')->where('id', $id); // TODO: restore hook // $group_id = Container::get('hooks')->fireDB('model.profile.update_profile_group_id', $update_online); $group_id = $group_id->find_one_col('group_id'); $group_mod = DB::for_table('groups')->where('g_id', $group_id); $group_mod = Container::get('hooks')->fireDB('model.profile.update_profile_group_mod', $group_mod); $group_mod = $group_mod->find_one_col('g_moderator'); if ($group_id == ForumEnv::get('FEATHER_ADMIN') || $group_mod == '1') { // Loop through all forums $result = $this->loop_mod_forums(); foreach ($result as $cur_forum) { $cur_moderators = $cur_forum['moderators'] != '' ? unserialize($cur_forum['moderators']) : array(); if (in_array($id, $cur_moderators)) { unset($cur_moderators[$info['old_username']]); $cur_moderators[$form['username']] = $id; uksort($cur_moderators, 'utf8_strcasecmp'); $update_mods = DB::for_table('forums')->where('id', $cur_forum['id'])->find_one()->set('moderators', serialize($cur_moderators)); $update_mods = Container::get('hooks')->fireDB('model.profile.update_profile_mods', $update_mods); $update_mods = $update_mods->save(); } } } // Regenerate the users info cache if (!Container::get('cache')->isCached('users_info')) { Container::get('cache')->store('users_info', Cache::get_users_info()); } $stats = Container::get('cache')->retrieve('users_info'); // Check if the bans table was updated and regenerate the bans cache when needed if ($bans_updated) { Container::get('cache')->store('bans', Cache::get_bans()); } } $section = Container::get('hooks')->fireDB('model.profile.update_profile', $section, $id); return Router::redirect(Router::pathFor('profileSection', array('id' => $id, 'section' => $section)), __('Profile redirect')); }
/** * Performs common page template replacements * This is the default action for COMMON_PAGE_FROMTEMPLATE * * @author Andreas Gohr <*****@*****.**> */ function parsePageTemplate(&$data) { extract($data); global $USERINFO; global $conf; // replace placeholders $file = noNS($id); $page = strtr($file, $conf['sepchar'], ' '); $tpl = str_replace(array('@ID@', '@NS@', '@FILE@', '@!FILE@', '@!FILE!@', '@PAGE@', '@!PAGE@', '@!!PAGE@', '@!PAGE!@', '@USER@', '@NAME@', '@MAIL@', '@DATE@'), array($id, getNS($id), $file, utf8_ucfirst($file), utf8_strtoupper($file), $page, utf8_ucfirst($page), utf8_ucwords($page), utf8_strtoupper($page), $_SERVER['REMOTE_USER'], $USERINFO['name'], $USERINFO['mail'], $conf['dformat']), $tpl); // we need the callback to work around strftime's char limit $tpl = preg_replace_callback('/%./', create_function('$m', 'return strftime($m[0]);'), $tpl); $data['tpl'] = $tpl; return $tpl; }
function pun_pm_preview($receiver, $subject, $body, &$errors) { global $forum_config, $forum_page, $lang_pun_pm, $forum_user; if ($body == '') { $errors[] = $lang_pun_pm['Empty body']; } elseif (strlen($body) > FORUM_MAX_POSTSIZE_BYTES) { $errors[] = sprintf($lang_pun_pm['Too long message'], forum_number_format(strlen($body)), forum_number_format(FORUM_MAX_POSTSIZE_BYTES)); } elseif ($forum_config['p_message_all_caps'] == '0' && utf8_strtoupper($body) == $body && !$forum_page['is_admmod']) { $body = utf8_ucwords(utf8_strtolower($body)); } // Validate BBCode syntax if ($forum_config['p_message_bbcode'] == '1' || $forum_config['o_make_links'] == '1') { global $smilies; if (!defined('FORUM_PARSER_LOADED')) { require FORUM_ROOT . 'include/parser.php'; } $body = preparse_bbcode($body, $errors); } ($hook = get_hook('pun_pm_fn_preview_pre_errors_check')) ? eval($hook) : null; if (count($errors)) { return false; } $message['sender'] = $forum_user['username']; $message['sender_id'] = $forum_user['id']; $message['body'] = $body; $message['subject'] = $subject; $message['status'] = 'draft'; $message['sent_at'] = time(); ($hook = get_hook('pun_pm_fn_preview_end')) ? eval($hook) : null; return pun_pm_message($message, 'inbox'); }
/** * Verifies that the discussion title is valid * * @param string * * @return boolean */ public function _verifyTitle(&$title) { // TODO: send these to callbacks to allow hookability? switch ($this->getOption(self::OPTION_ADJUST_TITLE_CASE)) { case 'ucfirst': // sentence case $title = utf8_ucfirst(utf8_strtolower($title)); break; case 'ucwords': // title case $title = utf8_ucwords(utf8_strtolower($title)); break; } return true; }
/** * @param Doku_Event $event */ function _handle_ajax(Doku_Event $event) { if ($event->data !== 'data_page') { return; } $event->stopPropagation(); $event->preventDefault(); $type = substr($_REQUEST['aliastype'], 10); $aliases = $this->dthlp->_aliases(); if (!isset($aliases[$type])) { echo 'Unknown type'; return; } if ($aliases[$type]['type'] !== 'page') { echo 'AutoCompletion is only supported for page types'; return; } if (substr($aliases[$type]['postfix'], -1, 1) === ':') { // Resolve namespace start page ID global $conf; $aliases[$type]['postfix'] .= $conf['start']; } $search = $_REQUEST['search']; $c_search = $search; $in_ns = false; if (!$search) { // No search given, so we just want all pages in the prefix $c_search = $aliases[$type]['prefix']; $in_ns = true; } $pages = ft_pageLookup($c_search, $in_ns, false); $regexp = '/^'; if ($aliases[$type]['prefix'] !== '') { $regexp .= preg_quote($aliases[$type]['prefix'], '/'); } $regexp .= '([^:]+)'; if ($aliases[$type]['postfix'] !== '') { $regexp .= preg_quote($aliases[$type]['postfix'], '/'); } $regexp .= '$/'; $result = array(); foreach ($pages as $page => $title) { $id = array(); if (!preg_match($regexp, $page, $id)) { // Does not satisfy the postfix and prefix criteria continue; } $id = $id[1]; if ($search !== '' && stripos($id, cleanID($search)) === false && stripos($title, $search) === false) { // Search string is not in id part or title continue; } if ($title === '') { $title = utf8_ucwords(str_replace('_', ' ', $id)); } $result[hsc($id)] = hsc($title); } $json = new JSON(); header('Content-Type: application/json'); echo $json->encode($result); }
/** * Performs common page template replacements * This works on data from COMMON_PAGETPL_LOAD * * @author Andreas Gohr <*****@*****.**> */ function parsePageTemplate(&$data) { /** * @var string $id the id of the page to be created * @var string $tpl the text used as template * @var string $tplfile the file above text was/should be loaded from * @var bool $doreplace should wildcard replacements be done on the text? */ extract($data); global $USERINFO; global $conf; // replace placeholders $file = noNS($id); $page = strtr($file, $conf['sepchar'], ' '); $tpl = str_replace(array('@ID@', '@NS@', '@FILE@', '@!FILE@', '@!FILE!@', '@PAGE@', '@!PAGE@', '@!!PAGE@', '@!PAGE!@', '@USER@', '@NAME@', '@MAIL@', '@DATE@'), array($id, getNS($id), $file, utf8_ucfirst($file), utf8_strtoupper($file), $page, utf8_ucfirst($page), utf8_ucwords($page), utf8_strtoupper($page), $_SERVER['REMOTE_USER'], $USERINFO['name'], $USERINFO['mail'], $conf['dformat']), $tpl); // we need the callback to work around strftime's char limit $tpl = preg_replace_callback('/%./', create_function('$m', 'return strftime($m[0]);'), $tpl); $data['tpl'] = $tpl; return $tpl; }
/** * UTF-8 aware alternative to ucwords * Uppercase the first character of each word in a string * * @param string $str String to be processed * * @return string String with first char of each word uppercase * * @see http://www.php.net/ucwords * @since 1.0 */ public static function ucwords($str) { require_once __DIR__ . '/phputf8/ucwords.php'; return utf8_ucwords($str); }
/** * UTF-8 aware alternative to ucwords * Uppercase the first character of each word in a string * * @param string $str String to be processed * * @return string String with first char of each word uppercase * * @see http://www.php.net/ucwords * @since 11.1 */ public static function ucwords($str) { jimport('phputf8.ucwords'); return utf8_ucwords($str); }
public function update_profile($id, $info, $section) { global $lang_common, $lang_profile, $lang_prof_reg, $pd; $username_updated = false; // Validate input depending on section switch ($section) { case 'essentials': $form = array('timezone' => floatval($this->request->post('form_timezone')), 'dst' => $this->request->post('form_dst') ? '1' : '0', 'time_format' => intval($this->request->post('form_time_format')), 'date_format' => intval($this->request->post('form_date_format'))); // Make sure we got a valid language string if ($this->request->post('form_language')) { $languages = forum_list_langs(); $form['language'] = feather_trim($this->request->post('form_language')); if (!in_array($form['language'], $languages)) { message($lang_common['Bad request'], '404'); } } if ($this->user->is_admmod) { $form['admin_note'] = feather_trim($this->request->post('admin_note')); // Are we allowed to change usernames? if ($this->user->g_id == FEATHER_ADMIN || $this->user->g_moderator == '1' && $this->user->g_mod_rename_users == '1') { $form['username'] = feather_trim($this->request->post('req_username')); if ($form['username'] != $info['old_username']) { // Check username require FEATHER_ROOT . 'lang/' . $this->user->language . '/register.php'; $errors = ''; $errors = check_username($form['username'], $errors, $id); if (!empty($errors)) { message($errors[0]); } $username_updated = true; } } // We only allow administrators to update the post count if ($this->user->g_id == FEATHER_ADMIN) { $form['num_posts'] = intval($this->request->post('num_posts')); } } if ($this->config['o_regs_verify'] == '0' || $this->user->is_admmod) { require FEATHER_ROOT . 'include/email.php'; // Validate the email address $form['email'] = strtolower(feather_trim($this->request->post('req_email'))); if (!is_valid_email($form['email'])) { message($lang_common['Invalid email']); } } break; case 'personal': $form = array('realname' => $this->request->post('form_realname') ? feather_trim($this->request->post('form_realname')) : '', 'url' => $this->request->post('form_url') ? feather_trim($this->request->post('form_url')) : '', 'location' => $this->request->post('form_location') ? feather_trim($this->request->post('form_location')) : ''); // Add http:// if the URL doesn't contain it already (while allowing https://, too) if ($this->user->g_post_links == '1') { if ($form['url'] != '') { $url = url_valid($form['url']); if ($url === false) { message($lang_profile['Invalid website URL']); } $form['url'] = $url['url']; } } else { if (!empty($form['url'])) { message($lang_profile['Website not allowed']); } $form['url'] = ''; } if ($this->user->g_id == FEATHER_ADMIN) { $form['title'] = feather_trim($this->request->post('title')); } elseif ($this->user->g_set_title == '1') { $form['title'] = feather_trim($this->request->post('title')); if ($form['title'] != '') { // A list of words that the title may not contain // If the language is English, there will be some duplicates, but it's not the end of the world $forbidden = array('member', 'moderator', 'administrator', 'banned', 'guest', utf8_strtolower($lang_common['Member']), utf8_strtolower($lang_common['Moderator']), utf8_strtolower($lang_common['Administrator']), utf8_strtolower($lang_common['Banned']), utf8_strtolower($lang_common['Guest'])); if (in_array(utf8_strtolower($form['title']), $forbidden)) { message($lang_profile['Forbidden title']); } } } break; case 'messaging': $form = array('jabber' => feather_trim($this->request->post('form_jabber')), 'icq' => feather_trim($this->request->post('form_icq')), 'msn' => feather_trim($this->request->post('form_msn')), 'aim' => feather_trim($this->request->post('form_aim')), 'yahoo' => feather_trim($this->request->post('form_yahoo'))); // If the ICQ UIN contains anything other than digits it's invalid if (preg_match('%[^0-9]%', $form['icq'])) { message($lang_prof_reg['Bad ICQ']); } break; case 'personality': $form = array(); // Clean up signature from POST if ($this->config['o_signatures'] == '1') { $form['signature'] = feather_linebreaks(feather_trim($this->request->post('signature'))); // Validate signature if (feather_strlen($form['signature']) > $this->config['p_sig_length']) { message(sprintf($lang_prof_reg['Sig too long'], $this->config['p_sig_length'], feather_strlen($form['signature']) - $this->config['p_sig_length'])); } elseif (substr_count($form['signature'], "\n") > $this->config['p_sig_lines'] - 1) { message(sprintf($lang_prof_reg['Sig too many lines'], $this->config['p_sig_lines'])); } elseif ($form['signature'] && $this->config['p_sig_all_caps'] == '0' && is_all_uppercase($form['signature']) && !$this->user->is_admmod) { $form['signature'] = utf8_ucwords(utf8_strtolower($form['signature'])); } // Validate BBCode syntax if ($this->config['p_sig_bbcode'] == '1') { require FEATHER_ROOT . 'include/parser.php'; $errors = array(); $form['signature'] = preparse_bbcode($form['signature'], $errors, true); if (count($errors) > 0) { message('<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'); } } } break; case 'display': $form = array('disp_topics' => feather_trim($this->request->post('form_disp_topics')), 'disp_posts' => feather_trim($this->request->post('form_disp_posts')), 'show_smilies' => $this->request->post('form_show_smilies') ? '1' : '0', 'show_img' => $this->request->post('form_show_img') ? '1' : '0', 'show_img_sig' => $this->request->post('form_show_img_sig') ? '1' : '0', 'show_avatars' => $this->request->post('form_show_avatars') ? '1' : '0', 'show_sig' => $this->request->post('form_show_sig') ? '1' : '0'); if ($form['disp_topics'] != '') { $form['disp_topics'] = intval($form['disp_topics']); if ($form['disp_topics'] < 3) { $form['disp_topics'] = 3; } elseif ($form['disp_topics'] > 75) { $form['disp_topics'] = 75; } } if ($form['disp_posts'] != '') { $form['disp_posts'] = intval($form['disp_posts']); if ($form['disp_posts'] < 3) { $form['disp_posts'] = 3; } elseif ($form['disp_posts'] > 75) { $form['disp_posts'] = 75; } } // Make sure we got a valid style string if ($this->request->post('form_style')) { $styles = forum_list_styles(); $form['style'] = feather_trim($this->request->post('form_style')); if (!in_array($form['style'], $styles)) { message($lang_common['Bad request'], '404'); } } break; case 'privacy': $form = array('email_setting' => intval($this->request->post('form_email_setting')), 'notify_with_post' => $this->request->post('form_notify_with_post') ? '1' : '0', 'auto_notify' => $this->request->post('form_auto_notify') ? '1' : '0'); if ($form['email_setting'] < 0 || $form['email_setting'] > 2) { $form['email_setting'] = $this->config['o_default_email_setting']; } break; default: message($lang_common['Bad request'], '404'); } // Single quotes around non-empty values and nothing for empty values $temp = array(); foreach ($form as $key => $input) { $temp[$key] = $input; } if (empty($temp)) { message($lang_common['Bad request'], '404'); } DB::for_table('users')->where('id', $id)->find_one()->set($temp)->save(); // If we changed the username we have to update some stuff if ($username_updated) { $bans_updated = DB::for_table('bans')->where('username', $info['old_username'])->update_many('username', $form['username']); DB::for_table('posts')->where('poster_id', $id)->update_many('poster', $form['username']); DB::for_table('posts')->where('edited_by', $info['old_username'])->update_many('edited_by', $form['username']); DB::for_table('topics')->where('poster', $info['old_username'])->update_many('poster', $form['username']); DB::for_table('topics')->where('last_poster', $info['old_username'])->update_many('last_poster', $form['username']); DB::for_table('forums')->where('last_poster', $info['old_username'])->update_many('last_poster', $form['username']); DB::for_table('online')->where('ident', $info['old_username'])->update_many('ident', $form['username']); // If the user is a moderator or an administrator we have to update the moderator lists $group_id = DB::for_table('users')->where('id', $id)->find_one_col('group_id'); $group_mod = DB::for_table('groups')->where('g_id', $group_id)->find_one_col('g_moderator'); if ($group_id == FEATHER_ADMIN || $group_mod == '1') { $select_mods = array('id', 'moderators'); $result = DB::for_table('forums')->select_many($select_mods)->find_many(); foreach ($result as $cur_forum) { $cur_moderators = $cur_forum['moderators'] != '' ? unserialize($cur_forum['moderators']) : array(); if (in_array($id, $cur_moderators)) { unset($cur_moderators[$info['old_username']]); $cur_moderators[$form['username']] = $id; uksort($cur_moderators, 'utf8_strcasecmp'); DB::for_table('forums')->where('id', $cur_forum['id'])->find_one()->set('moderators', serialize($cur_moderators))->save(); } } } // Regenerate the users info cache if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) { require FEATHER_ROOT . 'include/cache.php'; } generate_users_info_cache(); // Check if the bans table was updated and regenerate the bans cache when needed if ($bans_updated) { generate_bans_cache(); } } redirect(get_link('user/' . $id . '/section/' . $section . '/'), $lang_profile['Profile redirect']); }