/** * Fix tree. * * @param int $i * @param string $pkey * @param string $table * @param int $parent_id * @param array $where * @return bool */ protected function fix_tree(&$i, $pkey, $table, $parent_id = 0, $where = array()) { $changes_made = false; $sql = 'SELECT * FROM ' . $table . ' WHERE parent_id = ' . (int) $parent_id . (!empty($where) ? ' AND ' . implode(' AND ', $where) : '') . ' ORDER BY left_id ASC'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { // First we update the left_id for this module if ($row['left_id'] != $i) { $this->db->sql_query(' UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('left_id' => $i)) . "\n\t\t\t\t\tWHERE {$pkey} = {$row[$pkey]}"); $changes_made = true; } $i++; // Then we go through any children and update their left/right id's $changes_made = $this->fix_tree($i, $pkey, $table, $row[$pkey], $where) || $changes_made; // Then we come back and update the right_id for this module if ($row['right_id'] != $i) { $this->db->sql_query(' UPDATE ' . $table . ' SET ' . $this->db->sql_build_array('UPDATE', array('right_id' => $i)) . "\n\t\t\t\t\tWHERE {$pkey} = {$row[$pkey]}"); $changes_made = true; } $i++; } $this->db->sql_freeresult($result); return $changes_made; }
public function memberlist_modify_query($event) { $sql_from = $event['sql_from']; $sql_where = $event['sql_where']; $user_from = $this->request->variable('user_from', '', true); $user_id = $this->request->variable('user_id', ''); $this->template->assign_vars(array('USER_FROM' => $user_from, 'USER_ID' => (int) $user_id)); if ($user_from) { $sql_from .= ', ' . PROFILE_FIELDS_DATA_TABLE . ' pf '; $pieces = explode(' ', $user_from); $sql_where .= ' AND (pf.pf_phpbb_location COLLATE utf8_general_ci '; $sql_where .= $this->db->sql_like_expression(str_replace('*', $this->db->get_any_char(), $pieces[0])); for ($i = 1; $i < sizeof($pieces); $i++) { $sql_where .= ' OR pf.pf_phpbb_location COLLATE utf8_general_ci '; $sql_where .= $this->db->sql_like_expression(str_replace('*', $this->db->get_any_char(), $pieces[$i])); } $sql_where .= ') AND u.user_id = pf.user_id'; $event['sql_where'] = $sql_where; $event['sql_from'] = $sql_from; } if ((int) $user_id) { $sql_where .= ' AND u.user_id = ' . $user_id . ''; $event['sql_where'] = $sql_where; } }
public function modify_posting($event) { if ($event['mode'] == 'post' && !$event['forum_id']) { $forum_ary = array(); $forum_read_ary = $this->auth->acl_getf('f_read'); foreach ($forum_read_ary as $forum_id => $allowed) { if ($allowed['f_read'] && $this->auth->acl_get('f_post', $forum_id)) { if (!$this->exclude_forum($forum_id, $this->config['newtopic_forum'])) { continue; } $forum_ary[] = (int) $forum_id; } } if (sizeof($forum_ary)) { // Fetching topics of public forums $sql = 'SELECT forum_id, forum_name, forum_type FROM ' . FORUMS_TABLE . "\n\t\t\t\t\tWHERE " . $this->db->sql_in_set('forum_id', $forum_ary) . "\n\t\t\t\t\t\tAND forum_type != " . FORUM_LINK; $result = $this->db->sql_query($sql); $forumrow = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); $s_forum_options = '<select id="f" name="f" onchange="this.form.submit();">'; foreach ($forumrow as $row) { $s_forum_options .= '<option value="' . $row['forum_id'] . '"' . ($row['forum_id'] == $forum_id ? ' selected="selected"' : '') . '' . ($row['forum_type'] == FORUM_CAT ? ' disabled="disabled" class="disabled-option"' : '') . '>' . ($row['forum_type'] != FORUM_CAT ? ' ' : '') . $row['forum_name'] . '</option>'; $forum_id = $row['forum_type'] == FORUM_POST ? $row['forum_id'] : ''; } $s_forum_options .= '</select>'; $this->template->assign_vars(array('S_FORUM_OPTIONS' => $s_forum_options, 'S_FORUM_OPT_TRUE' => $forum_id ? true : false)); $event['forum_id'] = $forum_id; } } }
/** * Creates a report entity in the database * * @param array $report_data * @return int the ID of the created entity */ protected function create_report(array $report_data) { $sql_ary = array('reason_id' => (int) $report_data['reason_id'], 'post_id' => $report_data['post_id'], 'pm_id' => $report_data['pm_id'], 'user_id' => (int) $this->user->data['user_id'], 'user_notify' => (int) $report_data['user_notify'], 'report_closed' => 0, 'report_time' => (int) time(), 'report_text' => (string) $report_data['report_text'], 'reported_post_text' => $report_data['reported_post_text'], 'reported_post_uid' => $report_data['reported_post_uid'], 'reported_post_bitfield' => $report_data['reported_post_bitfield'], 'reported_post_enable_bbcode' => $report_data['reported_post_enable_bbcode'], 'reported_post_enable_smilies' => $report_data['reported_post_enable_smilies'], 'reported_post_enable_magic_url' => $report_data['reported_post_enable_magic_url']); $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); return $this->db->sql_nextid(); }
/** * {@inheritdoc} */ public function run() { $this->db->sql_return_on_error(true); $table_prefix = $this->config->get('table_prefix'); $change_prefix = $this->config->get('change_table_prefix', true); if (!defined('CONFIG_TABLE')) { // CONFIG_TABLE is required by sql_create_index() to check the // length of index names. However table_prefix is not defined // here yet, so we need to create the constant ourselves. define('CONFIG_TABLE', $table_prefix . 'config'); } $db_table_schema = @file_get_contents($this->schema_file_path); $db_table_schema = json_decode($db_table_schema, true); $total = sizeof($db_table_schema); $i = $this->config->get('add_table_index', 0); $db_table_schema = array_slice($db_table_schema, $i); foreach ($db_table_schema as $table_name => $table_data) { $i++; $this->db_tools->sql_create_table($change_prefix ? $table_prefix . substr($table_name, 6) : $table_name, $table_data); // Stop execution if resource limit is reached if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0) { break; } } $this->config->set('add_table_index', $i); if ($i < $total) { throw new resource_limit_reached_exception(); } else { @unlink($this->schema_file_path); } }
public function create_welcome_topic($user_id) { if (!$this->config['welcomerobot_enable']) { return false; } if (!function_exists('get_username_string')) { include $this->root_path . 'includes/functions_content.' . $this->phpEx; } if (!function_exists('submit_post')) { include $this->root_path . 'includes/functions_posting.' . $this->phpEx; } $sql = 'SELECT * FROM ' . USERS_TABLE . "\n\t\t\tWHERE user_id = " . intval($user_id) . ""; $dbresult = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($dbresult); $this->db->sql_freeresult($dbresult); if (empty($row)) { return false; } $username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); $clean_username = utf8_clean_string($row['username']); $topic_title = str_replace(array('%user', '%robot', '%board'), array($clean_username, $this->config['welcomerobot_username'], $this->config['sitename']), $this->config['welcomerobot_title']); $topic_content = str_replace(array('%user', '%robot', '%board'), array($clean_username, $this->config['welcomerobot_username'], $this->config['sitename']), $this->config['welcomerobot_detail']); $poll = $uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage $allow_bbcode = $allow_urls = $allow_smilies = true; generate_text_for_storage($topic_content, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies); $data = array('forum_id' => $this->config['welcomerobot_forum'], 'topic_id' => 0, 'icon_id' => false, 'robot_name' => $this->config['welcomerobot_username'], 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $topic_content, 'message_md5' => md5($topic_content), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'post_edit_locked' => 0, 'topic_title' => $topic_title, 'notify_set' => false, 'notify' => false, 'post_time' => 0, 'forum_name' => '', 'enable_indexing' => true, 'force_approved_state' => true); submit_post('post', $topic_title, 'robot_name', POST_NORMAL, $poll, $data); return true; }
/** * Likes controller for route /like_post/{like} * * @param int @post_id The post to be edited. */ public function like_post($post_id) { // If unknown user or bot, cannot like. if ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['is_bot']) { return; } // Add language variables for response. $this->user->add_lang_ext('nuleaf/likes', 'likes'); // Grab forum id for permission. $sql = 'SELECT forum_id FROM ' . POSTS_TABLE . ' WHERE post_id = ' . $post_id; $result = $this->db->sql_query_limit($sql, 1); $forum_id = $this->db->sql_fetchrow($result)['forum_id']; $this->db->sql_freeresult($result); // Does the user have permission to like posts in this forum? if ($this->auth->acl_get('!f_like', $forum_id)) { $json_response = new json_response(); $json_response->send(array('error' => $this->user->lang('LIKE_NOT_AUTHORIZED'))); return; } if ($this->request->is_ajax()) { $liked = $this->likes_manager->is_liked($post_id); if ($liked) { // If post is already liked, unlike it. $likes_count = $this->likes_manager->unlike($post_id); } else { // Else like the post. $likes_count = $this->likes_manager->like($post_id); } // Since the post has now been liked/unliked, $liked is reversed. $json_response = new json_response(); $json_response->send(array('likes_count' => $likes_count, 'liked' => !$liked, 'LIKE_POST' => $this->user->lang('LIKE_POST'), 'UNLIKE_POST' => $this->user->lang('UNLIKE_POST'), 'LIKE_BUTTON' => $this->user->lang('LIKE_BUTTON'), 'UNLIKE_BUTTON' => $this->user->lang('UNLIKE_BUTTON'))); } }
/** * {@inheritdoc} */ public function get_template_side($module_id) { $style_count = 0; $style_select = ''; $sql = 'SELECT style_id, style_name FROM ' . STYLES_TABLE . ' WHERE style_active = 1 ORDER BY LOWER(style_name) ASC'; $result = $this->db->sql_query($sql, 3600); while ($row = $this->db->sql_fetchrow($result)) { $style = $this->request->variable('style', 0); if (!empty($style)) { $url = str_replace('style=' . $style, 'style=' . $row['style_id'], $this->modules_helper->route('board3_portal_controller')); } else { $url = $this->modules_helper->route('board3_portal_controller') . '?style=' . $row['style_id']; } ++$style_count; $style_select .= '<option value="' . $url . '"' . ($row['style_id'] == $this->user->style['style_id'] ? ' selected="selected"' : '') . '>' . utf8_htmlspecialchars($row['style_name']) . '</option>'; } $this->db->sql_freeresult($result); if (strlen($style_select)) { $this->template->assign_var('STYLE_SELECT', $style_select); } // Assign specific vars $this->template->assign_vars(array('S_STYLE_OPTIONS' => $this->config['override_user_style'] || $style_count < 2 ? '' : $style_select)); return 'stylechanger_side.html'; }
function main() { $sql = 'SELECT * FROM ' . $this->points_values_table; $result = $this->db->sql_query($sql); $points_values = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Add part to bar $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'info')), 'FORUM_NAME' => sprintf($this->user->lang['POINTS_INFO'], $this->config['points_name']))); // Read out all the need values $info_attach = $points_values['points_per_attach'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_attach']) . ' ' . $this->config['points_name']); $info_addtional_attach = $points_values['points_per_attach_file'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_attach_file']) . ' ' . $this->config['points_name']); $info_poll = $points_values['points_per_poll'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_poll']) . ' ' . $this->config['points_name']); $info_poll_option = $points_values['points_per_poll_option'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_poll_option']) . ' ' . $this->config['points_name']); $info_topic_word = $points_values['points_per_topic_word'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_topic_word']) . ' ' . $this->config['points_name']); $info_topic_character = $points_values['points_per_topic_character'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_topic_character']) . ' ' . $this->config['points_name']); $info_post_word = $points_values['points_per_post_word'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_post_word']) . ' ' . $this->config['points_name']); $info_post_character = $points_values['points_per_post_character'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_post_character']) . ' ' . $this->config['points_name']); $info_cost_warning = $points_values['points_per_warn'] == 0 ? sprintf($this->user->lang['INFO_NO_COST'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['points_per_warn']) . ' ' . $this->config['points_name']); $info_reg_bonus = $points_values['reg_points_bonus'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->functions_points->number_format_points($points_values['reg_points_bonus']) . ' ' . $this->config['points_name']); $info_points_bonus = $points_values['points_bonus_chance'] == 0 ? sprintf($this->user->lang['INFO_NO_POINTS'], $this->config['points_name']) : sprintf($this->user->lang['INFO_BONUS_CHANCE_EXPLAIN'], $this->functions_points->number_format_points($points_values['points_bonus_chance']), $this->functions_points->number_format_points($points_values['points_bonus_min']), $this->functions_points->number_format_points($points_values['points_bonus_max']), $this->config['points_name']); $this->template->assign_vars(array('USER_POINTS' => sprintf($this->functions_points->number_format_points($this->user->data['user_points'])), 'POINTS_NAME' => $this->config['points_name'], 'LOTTERY_NAME' => $points_values['lottery_name'], 'BANK_NAME' => $points_values['bank_name'], 'POINTS_INFO_DESCRIPTION' => sprintf($this->user->lang['POINTS_INFO_DESCRIPTION'], $this->config['points_name']), 'INFO_ATTACH' => $info_attach, 'INFO_ADD_ATTACH' => $info_addtional_attach, 'INFO_POLL' => $info_poll, 'INFO_POLL_OPTION' => $info_poll_option, 'INFO_TOPIC_WORD' => $info_topic_word, 'INFO_TOPIC_CHARACTER' => $info_topic_character, 'INFO_POST_WORD' => $info_post_word, 'INFO_POST_CHARACTER' => $info_post_character, 'INFO_COST_WARNING' => $info_cost_warning, 'INFO_REG_BONUS' => $info_reg_bonus, 'INFO_POINTS_BONUS' => $info_points_bonus, 'U_TRANSFER_USER' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'transfer_user')), 'U_LOGS' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'logs')), 'U_LOTTERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'lottery')), 'U_BANK' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'bank')), 'U_ROBBERY' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'robbery')), 'U_INFO' => $this->helper->route('dmzx_ultimatepoints_controller', array('mode' => 'info')), 'U_USE_TRANSFER' => $this->auth->acl_get('u_use_transfer'), 'U_USE_LOGS' => $this->auth->acl_get('u_use_logs'), 'U_USE_LOTTERY' => $this->auth->acl_get('u_use_lottery'), 'U_USE_BANK' => $this->auth->acl_get('u_use_bank'), 'U_USE_ROBBERY' => $this->auth->acl_get('u_use_robbery'))); // Generate the page page_header($this->user->lang['POINTS_INFO']); // Generate the page template $this->template->set_filenames(array('body' => 'points/points_info.html')); page_footer(); }
/** * Modified version of the jumpbox, just lists authed forums (in the correct order) */ function get_forum_list($ignore_id = false, $ignore_acl = false, $ignore_nonpost = false, $ignore_emptycat = true, $only_acl_post = false) { // This query is identical to the jumpbox one $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, forum_flags, forum_options, left_id, right_id FROM ' . FORUMS_TABLE . ' ORDER BY left_id ASC'; $result = $this->db->sql_query($sql, 600); // We include the forum root/index to make tree traversal easier $forum_list[0] = array('forum_id' => '0', 'forum_name' => $this->user->lang['FORUMS'], 'forum_type' => '0', 'link' => append_sid("{$this->root_path}index.{$this->phpEx}"), 'parent_id' => false, 'current' => false, 'current_child' => false, 'disabled' => false); // Sometimes it could happen that forums will be displayed here not be displayed within the index page // This is the result of forums not displayed at index, having list permissions and a parent of a forum with no permissions. // If this happens, the padding could be "broken" while ($row = $this->db->sql_fetchrow($result)) { $disabled = false; if (!$ignore_acl && $this->auth->acl_gets(array('f_list', 'f_read'), $row['forum_id'])) { if ($only_acl_post && !$this->auth->acl_get('f_post', $row['forum_id']) || !$this->auth->acl_get('m_approve', $row['forum_id']) && !$this->auth->acl_get('f_noapprove', $row['forum_id'])) { $disabled = true; } } else { if (!$ignore_acl) { continue; } } if (is_array($ignore_id) && in_array($row['forum_id'], $ignore_id) || $row['forum_id'] == $ignore_id || $row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id'] && $ignore_emptycat || $row['forum_type'] != FORUM_POST && $ignore_nonpost) { $disabled = true; } $u_viewforum = append_sid("{$this->root_path}viewforum.{$this->phpEx}", 'f=' . $row['forum_id']); $forum_list[$row['forum_id']] = array('forum_id' => $row['forum_id'], 'forum_name' => $row['forum_name'], 'forum_type' => $row['forum_type'], 'link' => $u_viewforum, 'parent_id' => $row['parent_id'], 'current' => false, 'current_child' => false, 'disabled' => $disabled); } $this->db->sql_freeresult($result); return $forum_list; }
public function handle_downloadlog() { if (!$this->auth->acl_get('a_')) { trigger_error('Access Denied'); } else { $this->user->add_lang_ext('dmzx/downloadlog', 'common'); $fileid = $this->request->variable('file', 0); $start = $this->request->variable('start', 0); // Pagination number from ACP $dll = $this->config['downloadlog_value']; // Generate pagination $sql = 'SELECT COUNT(downloadslog_id) AS total_downloadlogs FROM ' . $this->userdownloadslog_table . ' WHERE user_id = user_id AND file_id = ' . $fileid; $result = $this->db->sql_query($sql); $total_downloadlogs = (int) $this->db->sql_fetchfield('total_downloadlogs'); $sql = 'SELECT d.user_id, d.down_date, u.user_id, u.username, u.user_colour FROM ' . $this->userdownloadslog_table . ' d, ' . USERS_TABLE . ' u WHERE u.user_id = d.user_id AND file_id = ' . $fileid . ' ORDER BY d.down_date DESC'; $top_result = $this->db->sql_query_limit($sql, $dll, $start); while ($row = $this->db->sql_fetchrow($top_result)) { $this->template->assign_block_vars('downloaders', array('D_USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'D_TIME' => $this->user->format_date($row['down_date']))); } } $pagination_url = $this->helper->route('dmzx_downloadlog_controller', array('file' => $fileid)); //Start pagination $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_downloadlogs, $dll, $start); $this->template->assign_vars(array('DOWNLOADERS_USERS' => $total_downloadlogs == 1 ? $this->user->lang['DOWNLOADERS_COUNT'] : sprintf($this->user->lang['DOWNLOADERS_COUNTS'], $total_downloadlogs), 'DOWNLOADERS_VERSION' => $this->config['downloadlog_version'])); page_header('Downloaders Log', false); $this->template->set_filenames(array('body' => 'DownloadLog.html')); page_footer(); }
/** * Changes the regex replacement for second pass * * @param object $event * @return null * @access public */ public function modify_replies($event) { if (!function_exists('get_username_string')) { include $this->root_path . 'includes/functions_content.' . $this->php_ext; } // 1. output each line with user + post-count // 2. output in "inline-popup" like in "mark posts read" $topic_row = $event['topic_row']; $topic_id = $topic_row['TOPIC_ID']; $sql = 'SELECT COUNT(p.post_id) AS posts, p.poster_id, u.username, u.user_colour FROM phpbb_posts p, phpbb_users u WHERE p.topic_id = ' . (int) $topic_id . ' AND p.poster_id = u.user_id GROUP BY p.poster_id ORDER BY posts DESC'; $result = $this->db->sql_query_limit($sql, 5); while ($row = $this->db->sql_fetchrow($result)) { var_dump($row); $post_count = $row['posts']; $display_username = get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour']); echo $display_username . ' with ' . $post_count . 'posts<br />'; } $this->db->sql_freeresult($result); $topic_row['REPLIES'] = '<a href="#t=' . $topic_id . '" class="whoposted">' . $topic_row['REPLIES'] . '</a>'; $event['topic_row'] = $topic_row; }
public function page_header($event) { if ($this->auth->acl_get('u_did_you_know')) { $sql_layer = $this->db->get_sql_layer(); switch ($sql_layer) { case 'postgres': $random = 'RANDOM()'; break; case 'mssql': case 'mssql_odbc': $random = 'NEWID()'; break; default: $random = 'RAND()'; break; } $sql = 'SELECT word, bbcode_uid, bbcode_bitfield, bbcode_options FROM ' . $this->did_you_know . "\n\t\t\t\tWHERE lang_iso = '{$this->user->data['user_lang']}'\n\t\t\t\t\tOR lang_iso = 'default'\n\t\t\t\tORDER BY {$random}"; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $word = generate_text_for_display($row['word'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']); $this->template->assign_vars(array('DID_YOU_KNOW' => str_replace(""", '"', $word), 'S_DIDYOUKNOW' => !empty($this->user->data['user_didyouknow']) ? true : false, 'U_DYK_HIDE' => $this->helper->route('dmzx_didyouknow_controller', array('mode' => 'hide')))); } }
public function add_page_header_links($event) { if (!empty($this->config['allow_visits_counter'])) { $this->language->add_lang('common', 'dmzx/counter'); $sql = 'SELECT COUNT(*) AS visits_counter FROM ' . $this->visits_counter_table . ' WHERE ' . $this->db->sql_in_set('uvc_ip', $this->user->ip); $result = $this->db->sql_query($sql); $visits_counter = (int) $this->db->sql_fetchfield('visits_counter'); $this->db->sql_freeresult($result); $visits = $this->config['visits_counter']; if ($visits_counter == 0) { $sql_ary = array('uvc_ip' => $this->user->ip, 'uvc_timestamp' => time()); $sql = 'INSERT INTO ' . $this->visits_counter_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); $this->config->increment('visits_counter', 1, true); } else { $sql_ary = array('uvc_timestamp' => time()); $sql = 'UPDATE ' . $this->visits_counter_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE ' . $this->db->sql_in_set('uvc_ip', $this->user->ip); $this->db->sql_query($sql); } $timestamp = time() - 3600 * 24; $sql_ary = array($timestamp); $sql = 'DELETE FROM ' . $this->visits_counter_table . ' WHERE uvc_timestamp < ' . $timestamp; $this->db->sql_query($sql); $sql = 'SELECT COUNT(*) AS num_del FROM ' . $this->visits_counter_table . ' '; $result = $this->db->sql_query($sql); $visitsok = (int) $this->db->sql_fetchfield('num_del'); $this->template->assign_vars(array('UNIQUE_VISITS_COUNTER' => $this->language->lang('UNIQUE_VISITS_COUNTER', $visitsok))); } }
public function base() { $note = utf8_normalize_nfc($this->request->variable('note', '', true)); $submit = isset($_POST['submit']) ? true : false; $error = array(); // check if user s logged in, since this page can be used only after registration... if (!$this->user->data['is_registered']) { login_box($this->helper->route('vinny_usersnotes_controller')); } // ... and also this is not for bots (especially for bad ones :) if ($this->user->data['is_bot']) { redirect(append_sid("{$this->phpbb_root_path}index.{$this->phpEx}")); } $s_action = $this->helper->route('vinny_usersnotes_controller'); $s_hidden_fields = ''; add_form_key('postform'); // create a template variables $this->template->assign_vars(array('S_POST_ACTION' => $s_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'ERROR' => sizeof($error) ? implode('<br />', $error) : '')); if ($submit) { /*if(!check_form_key('postform')) { trigger_error('FORM_INVALID'); }*/ $sql = 'UPDATE ' . USERS_TABLE . ' SET user_note = "' . $note . '" WHERE user_id = ' . $this->user->data['user_id']; $this->db->sql_query($sql); meta_refresh(3, $this->helper->route('vinny_usersnotes_controller')); trigger_error(sprintf($this->user->lang['NOTES_SAVED'], $this->helper->route('vinny_usersnotes_controller'))); } // create a template variables $this->template->assign_vars(array('NOTE' => $this->user->data['user_note'])); $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['NOTES'])); return $this->helper->render('notes.html', $this->user->lang['NOTES']); }
public function main() { $topic_id = $this->request->variable('t', 0); $post_id = $this->request->variable('p', 0); $forum_id = $this->request->variable('f', 0); $mode = $this->request->variable('mode', ''); $book_submit = $this->request->variable('book', false); $viewtopic_url = append_sid("{$this->phpbb_root_path}viewtopic." . $this->php_ext . "", "f={$forum_id}&t={$topic_id}"); $return_link = '<br /><br />' . sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>'); $body = 'add_bookmark'; if ($mode == 'delete') { $sql = 'DELETE FROM ' . $this->postbookmark_table . "\n\t\t\t\tWHERE user_id = {$this->user->data['user_id']}\n\t\t\t\t\tAND post_id = {$post_id}"; $this->db->sql_query($sql); $message = $this->user->lang['POST_BOOKMARK_REMOVED']; $this->helper->output_response($message, $return_link, $viewtopic_url); } else { if ($mode == 'find') { $body = 'find_bookmark'; $this->helper->get_bookmarks($mode); } else { $bookmark_desc = $this->request->variable('bookmark_desc', '', true); if ($book_submit) { $sql = 'INSERT INTO ' . $this->postbookmark_table . ' ' . $this->db->sql_build_array('INSERT', array('user_id' => $this->user->data['user_id'], 'post_id' => $post_id, 'topic_id' => $topic_id, 'bookmark_time' => time(), 'bookmark_desc' => $bookmark_desc)); $this->db->sql_query($sql); $message = $this->user->lang['POST_BOOKMARK_ADDED']; $this->helper->output_response($message, $return_link, $viewtopic_url); } } } $this->template->assign_vars(array('U_POST_ACTION' => append_sid("{$this->phpbb_root_path}postbookmark", "f={$forum_id}&t={$topic_id}&p={$post_id}&mode={$mode}"))); page_header($this->user->lang['POST_BOOKMARK_ADD']); $this->template->set_filenames(array('body' => $body . '.html')); page_footer(); return new Response('', 200); }
/** * Delete a shoutbox post * * @param int $id * * @throws \paul999\ajaxshoutbox\exceptions\shoutbox_exception */ public function delete_post($id) { if (!$id) { $id = $this->request->variable('id', 0); } $sql = 'SELECT user_id FROM ' . $this->table . ' WHERE shout_id = ' . (int) $id; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow(); $this->db->sql_freeresult($result); if (!$row) { throw new shoutbox_exception('AJAX_SHOUTBOX_NO_SUCH_POST'); } if (!$this->auth->acl_get('m_shoutbox_delete')) { // User has no m_ permission. if ($row['user_id'] != $this->user->data['user_id']) { throw new shoutbox_exception('AJAX_SHOUTBOX_NO_SUCH_POST'); } if (!$this->auth->acl_get('u_shoutbox_delete')) { throw new shoutbox_exception('AJAX_SHOUTBOX_NO_PERMISSION'); } } if ($this->push->canPush()) { if ($this->push->delete($id) === false) { throw new shoutbox_exception('AJAX_SHOUTBOX_PUSH_NOT_AVAIL'); } } $sql = 'DELETE FROM ' . $this->table . ' WHERE shout_id = ' . (int) $id; $this->db->sql_query($sql); }
/** * @param array $sql_array */ private function _limit_by_group(array &$sql_array) { if (!empty($this->settings['group_ids'])) { $sql_array['FROM'][USER_GROUP_TABLE] = 'ug'; $sql_array['WHERE'][] = 't.topic_poster = ug.user_id'; $sql_array['WHERE'][] = $this->db->sql_in_set('ug.group_id', $this->settings['group_ids']); } }
/** * Set ColorizeIt options for a revision. * * @param array $options * @param int $revision_id * @param \phpbb\db\driver\driver_interface $db * * @return null */ public function submit_options($options, $revision_id, $db) { $options = serialize($options); $sql = 'UPDATE ' . TITANIA_REVISIONS_TABLE . ' SET revision_clr_options = "' . $db->sql_escape($options) . '" WHERE revision_id = ' . (int) $revision_id; $db->sql_query($sql); }
public function page_header($event) { $this->user->add_lang_ext('dmzx/totalavtiveext', 'common'); $sql = 'SELECT SUM(ext_active) AS count FROM ' . EXT_TABLE; $result = $this->db->sql_query($sql); $ext_count = (int) $this->db->sql_fetchfield('count'); $this->template->assign_vars(array('TOTAL_EXT' => $this->user->lang['TOTAL_EXT'] . ' <strong>' . number_format($ext_count) . '</strong>')); }
/** * Show all anniversaries * * @return void * @access public */ public function overview() { // Catch all anniversaries from the database $sql = 'SELECT anniversary_id, day, month, year, event, link FROM phpbb_consim_anniversary'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $this->template->assign_block_vars('Anniversaries', array('EVENT' => $row['event'], 'ODATE' => $row['year'] != 0 ? date("Y") - (int) $row['year'] . ". " : "", 'DAY' => $row['day'], 'MONTH' => $row['month'], 'YEAR' => $row['year'], 'LINK' => $row['link'], 'ID' => $row['anniversary_id'], 'DELETE' => build_url() . "&action=delete_anniversary&anniversary_id=" . $row['anniversary_id'])); } }
/** * @dataProvider data_attachment_delete */ public function test_attachment_delete($mode, $ids, $resync, $expected) { // We need to reset the attachment ID sequence to properly test this if ($this->db->get_sql_layer() === 'postgres') { $sql = 'ALTER SEQUENCE phpbb_attachments_seq RESTART WITH 1'; $this->db->sql_query($sql); } $this->assertSame($expected, $this->attachment_delete->delete($mode, $ids, $resync)); }
/** * Display the output for this extension * * @return null * @access public */ public function display_output() { // Add the language file $this->language->add_lang('acp_activesessions', 'david63/activesessions'); // Start initial var setup $action = $this->request->variable('action', ''); $start = $this->request->variable('start', 0); $fc = $this->request->variable('fc', ''); $sort_key = $this->request->variable('sk', 's'); $sd = $sort_dir = $this->request->variable('sd', 'd'); $sort_dir = $sort_dir == 'd' ? ' DESC' : ' ASC'; $order_ary = array('i' => 's.session_ip' . $sort_dir . ', u.username_clean ASC', 's' => 's.session_start' . $sort_dir . ', u.username_clean ASC', 'u' => 'u.username_clean' . $sort_dir); $filter_by = ''; if ($fc == 'other') { for ($i = ord($this->language->lang('START_CHARACTER')); $i <= ord($this->language->lang('END_CHARACTER')); $i++) { $filter_by .= ' AND u.username_clean ' . $this->db->sql_not_like_expression(utf8_clean_string(chr($i)) . $this->db->get_any_char()); } } else { if ($fc) { $filter_by .= ' AND u.username_clean ' . $this->db->sql_like_expression(utf8_clean_string(substr($fc, 0, 1)) . $this->db->get_any_char()); } } $sql = $this->db->sql_build_query('SELECT', array('SELECT' => 'u.user_id, u.username, u.username_clean, u.user_colour, s.*, f.forum_id, f.forum_name', 'FROM' => array(USERS_TABLE => 'u', SESSIONS_TABLE => 's'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 's.session_forum_id = f.forum_id')), 'WHERE' => 'u.user_id = s.session_user_id AND s.session_time >= ' . (time() - $this->config['session_length'] * 60) . $filter_by, 'ORDER_BY' => $sort_key == '' ? 'u.username_clean' : $order_ary[$sort_key])); $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start); while ($row = $this->db->sql_fetchrow($result)) { $this->template->assign_block_vars('active_sessions', array('ADMIN' => $row['session_admin'] ? $this->language->lang('YES') : $this->language->lang('NO'), 'AUTO_LOGIN' => $row['session_autologin'] ? $this->language->lang('YES') : $this->language->lang('NO'), 'BROWSER' => $row['session_browser'], 'FORUM' => $row['forum_id'] > 0 ? $row['forum_name'] : '', 'LAST_VISIT' => $this->user->format_date($row['session_last_visit']), 'SESSION_FORWARD' => $row['session_forwarded_for'], 'SESSION_ID' => $row['session_id'], 'SESSION_IP' => $row['session_ip'], 'SESSION_KEY' => $row['session_id'] . $row['user_id'], 'SESSION_ONLINE' => $row['session_viewonline'] ? $this->language->lang('YES') : $this->language->lang('NO'), 'SESSION_PAGE' => $row['session_page'], 'SESSION_START' => $this->user->format_date($row['session_start']), 'SESSION_TIME' => $this->user->format_date($row['session_time']), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))); } $this->db->sql_freeresult($result); $sort_by_text = array('u' => $this->language->lang('SORT_USERNAME'), 'i' => $this->language->lang('SESSION_IP'), 's' => $this->language->lang('SESSION_START')); $limit_days = array(); $s_sort_key = $s_limit_days = $s_sort_dir = $u_sort_param = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); // Get total session count for output $sql = $this->db->sql_build_query('SELECT', array('SELECT' => 'COUNT(s.session_id) AS total_sessions', 'FROM' => array(USERS_TABLE => 'u', SESSIONS_TABLE => 's'), 'WHERE' => 'u.user_id = s.session_user_id' . $filter_by)); $result = $this->db->sql_query($sql); $session_count = (int) $this->db->sql_fetchfield('total_sessions'); $this->db->sql_freeresult($result); $action = "{$this->u_action}&sk={$sort_key}&sd={$sd}"; $link = $session_count ? adm_back_link($action . '&start=' . $start) : ''; if ($session_count == 0) { trigger_error($this->language->lang('NO_SESSION_DATA') . $link); } $start = $this->pagination->validate_start($start, $this->config['topics_per_page'], $session_count); $this->pagination->generate_template_pagination($action, 'pagination', 'start', $session_count, $this->config['topics_per_page'], $start); $first_characters = array(); $first_characters[''] = $this->language->lang('ALL'); for ($i = ord($this->language->lang('START_CHARACTER')); $i <= ord($this->language->lang('END_CHARACTER')); $i++) { $first_characters[chr($i)] = chr($i); } $first_characters['other'] = $this->language->lang('OTHER'); foreach ($first_characters as $char => $desc) { $this->template->assign_block_vars('first_char', array('DESC' => $desc, 'U_SORT' => $action . '&fc=' . $char)); } $this->template->assign_vars(array('ACTIVE_SESSIONS_VERSION' => ext::ACTIVE_SESSIONS_VERSION, 'S_SORT_DIR' => $s_sort_dir, 'S_SORT_KEY' => $s_sort_key, 'TOTAL_USERS' => $this->language->lang('TOTAL_SESSIONS', (int) $session_count), 'U_ACTION' => $action)); }
public function attachments_data($event) { $topic_id = $event['topic_id']; $sql = 'SELECT COUNT(attach_id) as num_attachments FROM ' . ATTACHMENTS_TABLE . " a\n\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\tAND a.is_orphan = 0"; $result = $this->db->sql_query($sql); $num_attachments = $this->db->sql_fetchfield('num_attachments'); $this->db->sql_freeresult($result); $this->template->assign_vars(array('U_ATTACHMENTS_TOPIC' => $this->helper->route("bb3mobi_attach_cat", array('t' => $topic_id)), 'TOTAL_ATTACH_TOPIC' => (int) $num_attachments)); }
/** * Check if the provided user has a specific key in the table provided * * @param string $table Table to check in * @param int $user_id The specific user * @param string $where Extra where clause. Be sure to include AND * * @return bool */ protected function check_table_for_user($table, $user_id, $where = '') { $sql = 'SELECT COUNT(registration_id) as reg_id FROM ' . $this->db->sql_escape($table) . ' WHERE user_id = ' . (int) $user_id . ' ' . $where; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); return $row && $row['reg_id'] > 0; }
public function index_modify_page_title($event) { // Count the videos ... $sql = 'SELECT COUNT(video_id) AS total_videos FROM ' . $this->video_table; $result = $this->db->sql_query($sql); $total_videos = (int) $this->db->sql_fetchfield('total_videos'); $this->db->sql_freeresult($result); // Count the videos categories ... $sql = 'SELECT COUNT(video_cat_id) AS total_categories FROM ' . $this->video_cat_table . ''; $result = $this->db->sql_query($sql); $total_categories = (int) $this->db->sql_fetchfield('total_categories'); $this->db->sql_freeresult($result); // Count the videos views ... $sql = 'SELECT SUM(video_views) AS total_views FROM ' . $this->video_table; $result = $this->db->sql_query($sql); $total_views = (int) $this->db->sql_fetchfield('total_views'); $this->db->sql_freeresult($result); $total_videos; // Count the videos comments ... $sql = 'SELECT COUNT(cmnt_id) AS total_comments FROM ' . $this->video_cmnts_table; $result = $this->db->sql_query($sql); $total_comments = (int) $this->db->sql_fetchfield('total_comments'); $this->db->sql_freeresult($result); $l_total_video_s = $total_videos == 0 ? 'TOTAL_VIDEO_ZERO' : 'TOTAL_VIDEOS_OTHER'; $l_total_category_s = $total_categories == 0 ? 'TOTAL_CATEGORY_ZERO' : 'TOTAL_CATEGORIES_OTHER'; $l_total_view_s = $total_views == 0 ? 'TOTAL_VIEW_ZERO' : 'TOTAL_VIEWS_OTHER'; $l_total_comment_s = $total_comments == 0 ? 'TOTAL_COMMENT_ZERO' : 'TOTAL_COMMENTS_OTHER'; $this->template->assign_vars(array('TOTAL_VIDEOS_INDEX' => sprintf($this->user->lang[$l_total_video_s], $total_videos), 'TOTAL_CATEGORIES' => sprintf($this->user->lang[$l_total_category_s], $total_categories), 'TOTAL_VIEWS' => sprintf($this->user->lang[$l_total_view_s], $total_views), 'TOTAL_COMMENTS' => sprintf($this->user->lang[$l_total_comment_s], $total_comments), 'S_ENABLE_VIDEO_STATICS_ON_INDEX' => $this->config['enable_video_statics_on_index'])); }
/** * Runs this cron task. * * @return null */ public function run() { $sql = 'UPDATE ' . RATING_TABLE . ' SET `top_hits_before` = `top_hits`, `top_hosts_before` = `top_hosts`, `top_in_before` = `top_in`, `top_out_before` = `top_out`, `top_hits` = 0, `top_hosts` = 0, `top_in` = 0, `top_out` = 0 WHERE `top_id` BETWEEN 1 AND 100000 AND top_hosts > 1'; $this->db->sql_query($sql); $this->db->sql_query('TRUNCATE TABLE ' . RATING_CLICK_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . RATING_HITS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . RATING_ONLINE_TABLE); $this->db->sql_query('OPTIMIZE TABLE ' . RATING_TABLE); $this->db->sql_query('OPTIMIZE TABLE ' . RATING_CLICK_TABLE); $this->db->sql_query('OPTIMIZE TABLE ' . RATING_HITS_TABLE); $this->db->sql_query('OPTIMIZE TABLE ' . RATING_ONLINE_TABLE); //$this->config->set('rating_platforms_active', 0); $timestamp = time(); $timezone = new \DateTimeZone($this->config['board_timezone']); $time = $this->user->get_timestamp_from_format('Y-m-d H:i:s', date('Y', $timestamp) . '-' . date('m', $timestamp) . '-' . date('d', $timestamp) . ' 00:00:00', $timezone); $this->config->set('top_rating_last_gc', $time); }
/** * Fetches language entries for options from DB * * @param int $lang_id */ public function load_option_lang($lang_id) { $sql = 'SELECT field_id, option_id, lang_value FROM ' . $this->language_table . ' WHERE lang_id = ' . (int) $lang_id . "\n\t\t\t\tORDER BY option_id"; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $this->options_lang[$row['field_id']][$lang_id][$row['option_id'] + 1] = $row['lang_value']; } $this->db->sql_freeresult($result); }
public function load_language_on_setup($event) { // Initial reset of the module_display row in the module table if (!$this->config['lmdi_purge_ucp']) { $sql = "UPDATE " . MODULES_TABLE . "\n\t\t\t\tSET module_display = 0 \n\t\t\t\tWHERE module_langname = 'UCP_PSB'"; // var_dump ($sql); $this->db->sql_query($sql); } $lang_set_ext = $event['lang_set_ext']; $lang_set_ext[] = array('ext_name' => 'lmdi/purgesub', 'lang_set' => 'common'); $event['lang_set_ext'] = $lang_set_ext; }
public function marquer_photos_lues($event) { $user_id = $this->user->data["user_id"]; $lesPhotos = fonctionGetLastCommentaireForUser($user_id, 10, false); $lesPhotos = commentaireForUser($lesPhotos, $user_id); foreach ($lesPhotos['lignesMessage'] as $photo) { $query = "\n\t\t\t\tDELETE FROM `photo_track` \n\t\t\t\tWHERE user_id = '" . $user_id . "' \n\t\t\t\tAND photo_id = '" . $photo['photo_id'] . "' \n\t\t\t"; $this->db->sql_query($query); $query = "\n\t\t\t\tINSERT INTO `photo_track` \n\t\t\t\t(`user_id`, `photo_id`, `mark_time`) \n\t\t\t\tVALUES \n\t\t\t\t('" . $user_id . "', '" . $photo['photo_id'] . "', " . time() . ")\n\t\t\t"; $this->db->sql_query($query); } }