public function page_header_after($event) { $context = $this->phpbb_container->get('template_context'); $rootref =& $context->get_root_ref(); if (isset($this->config['menu_enabled']) && $this->config['menu_enabled']) { $sql = 'SELECT * FROM ' . $this->menu_colors; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); if ($this->db->sql_affectedrows()) { $this->template->assign_vars(array('S_MENU_COLOR' => $row['color_name'], 'S_MENU_FONT_COLOR' => $row['color_text'], 'S_MENU_FONT_COLOR_HOVER' => $row['color_text_hover'], 'S_MENU_DECORATION' => $row['color_text_hover_decor'], 'S_MENU_WEIGHT' => $row['color_text_weight'], 'S_MENU_SEARCH' => $row['color_display_search'], 'S_MENU_TEXT_TRANSFORM' => $row['color_text_transform'], 'S_MENU_ALIGN' => $row['color_align'])); $sql = 'SELECT * FROM ' . $this->menu_buttons . ' WHERE button_display = 1 AND parent_id = 0 ORDER BY left_id'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { if ($row['button_only_registered'] && $this->user->data['user_id'] == ANONYMOUS || $row['button_only_guest'] && $this->user->data['user_id'] != ANONYMOUS) { continue; } if (preg_match("/\\{(.*)\\}/", $row['button_url'])) { $brackets = array("{", "}"); $var_name = strtoupper(str_replace($brackets, '', $row['button_url'])); $row['button_url'] = $rootref[$var_name]; } if (preg_match("/\\{(.*)\\}/", $row['button_name'])) { $brackets = array("{L_", "}"); $var_name = strtoupper(str_replace($brackets, '', $row['button_name'])); $row['button_name'] = $this->user->lang[$var_name]; } $this->template->assign_block_vars('buttons', array('ID' => $row['button_id'], 'URL' => $row['button_url'], 'NAME' => $row['button_name'], 'EXTERNAL' => $row['button_external'])); $sub_sql = 'SELECT * FROM ' . $this->menu_buttons . ' WHERE button_display = 1 AND parent_id = ' . $row['button_id'] . ' ORDER BY left_id'; $sub_result = $this->db->sql_query($sub_sql); while ($sub_row = $this->db->sql_fetchrow($sub_result)) { if ($sub_row['button_only_registered'] && $this->user->data['user_id'] == ANONYMOUS || $sub_row['button_only_guest'] && $this->user->data['user_id'] != ANONYMOUS) { continue; } if (preg_match("/\\{(.*)\\}/", $sub_row['button_url'])) { $brackets = array("{", "}"); $var_name = strtoupper(str_replace($brackets, '', $sub_row['button_url'])); $sub_row['button_url'] = $rootref[$var_name]; } if (preg_match("/\\{(.*)\\}/", $sub_row['button_name'])) { $brackets = array("{L_", "}"); $var_name = strtoupper(str_replace($brackets, '', $sub_row['button_name'])); $sub_row['button_name'] = $this->user->lang[$var_name]; } $this->template->assign_block_vars('buttons.sub', array('ID' => $sub_row['button_id'], 'URL' => $sub_row['button_url'], 'NAME' => $sub_row['button_name'], 'EXTERNAL' => $sub_row['button_external'])); } $this->db->sql_freeresult($sub_result); } $this->db->sql_freeresult($result); } } }
/** * Track an object. * * @param int $type Object type * @param int $id Object id * @param bool|int $time Optional track time to use, if none is given * the value from time() is used. */ public function track($type, $id, $time = false) { // Ignore $this->get_track_cookie(); // Cookie storage method if (!$this->user->data['is_registered']) { $this->track_cookie($type, $id, $time); return; } if ($this->get_track($type, $id, true) >= ($time === false ? time() : (int) $time)) { return; } $sql = 'UPDATE ' . $this->sql_table . ' SET track_time = ' . ($time === false ? time() : (int) $time) . ' WHERE track_type = ' . (int) $type . ' AND track_id = ' . (int) $id . ' AND track_user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) { $sql_ary = array('track_type' => (int) $type, 'track_id' => (int) $id, 'track_user_id' => (int) $this->user->data['user_id'], 'track_time' => $time === false ? time() : (int) $time); $this->db->sql_return_on_error(true); $this->db->sql_query('INSERT INTO ' . $this->sql_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary)); $this->db->sql_return_on_error(); } $this->store[$type][$id] = $time === false ? time() : (int) $time; }
/** * Update BBCode order fields in the db on move up/down * * @param string $action The action move_up|move_down * @return null * @access public */ public function move($action) { $bbcode_id = $this->request->variable('id', 0); if (!check_link_hash($this->request->variable('hash', ''), $action . $bbcode_id)) { trigger_error($this->user->lang('FORM_INVALID'), E_USER_WARNING); } // Get current order $sql = 'SELECT bbcode_order FROM ' . BBCODES_TABLE . "\n\t\t\tWHERE bbcode_id = {$bbcode_id}"; $result = $this->db->sql_query($sql); $current_order = (int) $this->db->sql_fetchfield('bbcode_order'); $this->db->sql_freeresult($result); // First one can't be moved up if ($current_order <= 1 && $action == 'move_up') { return; } $order_total = $current_order * 2 + $this->increment($action); // Update the db $sql = 'UPDATE ' . BBCODES_TABLE . ' SET bbcode_order = ' . $order_total . ' - bbcode_order WHERE ' . $this->db->sql_in_set('bbcode_order', array($current_order, $current_order + $this->increment($action))); $this->db->sql_query($sql); // Resync bbcode_order $this->resynchronize_bbcode_order(); // return a JSON response if this was an AJAX request if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('success' => (bool) $this->db->sql_affectedrows())); } }
/** * Update the users session in the table. */ public function update_session() { if ($this->user->data['user_id'] != ANONYMOUS) { $wwh_data = array('user_id' => $this->user->data['user_id'], 'user_ip' => $this->user->ip, 'username' => $this->user->data['username'], 'username_clean' => $this->user->data['username_clean'], 'user_colour' => $this->user->data['user_colour'], 'user_type' => $this->user->data['user_type'], 'viewonline' => $this->user->data['session_viewonline'], 'wwh_lastpage' => time()); $this->db->sql_return_on_error(true); $sql = 'UPDATE ' . WWH_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $wwh_data) . ' WHERE user_id = ' . (int) $this->user->data['user_id'] . "\n\t\t\t\t\tOR (user_ip = '" . $this->db->sql_escape($this->user->ip) . "'\n\t\t\t\t\t\tAND user_id = " . ANONYMOUS . ')'; $result = $this->db->sql_query($sql); $this->db->sql_return_on_error(false); if ((bool) $result === false) { // database does not exist yet... return; } $sql_affectedrows = (int) $this->db->sql_affectedrows(); if ($sql_affectedrows != 1) { if ($sql_affectedrows > 1) { // Found multiple matches, so we delete them and just add one $sql = 'DELETE FROM ' . WWH_TABLE . ' WHERE user_id = ' . (int) $this->user->data['user_id'] . "\n\t\t\t\t\t\t\tOR (user_ip = '" . $this->db->sql_escape($this->user->ip) . "'\n\t\t\t\t\t\t\t\tAND user_id = " . ANONYMOUS . ')'; $this->db->sql_query($sql); $this->db->sql_query('INSERT INTO ' . WWH_TABLE . ' ' . $this->db->sql_build_array('INSERT', $wwh_data)); } if ($sql_affectedrows == 0) { // No entry updated. Either the user is not listed yet, or has opened two links in the same time $sql = 'SELECT 1 as found FROM ' . WWH_TABLE . ' WHERE user_id = ' . (int) $this->user->data['user_id'] . "\n\t\t\t\t\t\t\tOR (user_ip = '" . $this->db->sql_escape($this->user->ip) . "'\n\t\t\t\t\t\t\t\tAND user_id = " . ANONYMOUS . ')'; $result = $this->db->sql_query($sql); $found = (int) $this->db->sql_fetchfield('found'); $this->db->sql_freeresult($result); if (!$found) { // He wasn't listed. $this->db->sql_query('INSERT INTO ' . WWH_TABLE . ' ' . $this->db->sql_build_array('INSERT', $wwh_data)); } } } } else { $this->db->sql_return_on_error(true); $sql = 'SELECT user_id FROM ' . WWH_TABLE . "\n\t\t\t\tWHERE user_ip = '" . $this->db->sql_escape($this->user->ip) . "'"; $result = $this->db->sql_query_limit($sql, 1); $this->db->sql_return_on_error(false); if ((bool) $result === false) { // database does not exist yet... return; } $user_logged = (int) $this->db->sql_fetchfield('user_id'); $this->db->sql_freeresult($result); if (!$user_logged) { $wwh_data = array('user_id' => $this->user->data['user_id'], 'user_ip' => $this->user->ip, 'username' => $this->user->data['username'], 'username_clean' => $this->user->data['username_clean'], 'user_colour' => $this->user->data['user_colour'], 'user_type' => $this->user->data['user_type'], 'viewonline' => 1, 'wwh_lastpage' => time()); $this->db->sql_query('INSERT INTO ' . WWH_TABLE . ' ' . $this->db->sql_build_array('INSERT', $wwh_data)); } } $this->db->sql_return_on_error(false); }
/** * {@inheritDoc} */ public function move($group_id, $delta) { $delta = (int) $delta; if (!$delta) { return false; } $move_up = $delta > 0 ? true : false; $current_value = $this->get_group_value($group_id); if ($current_value != self::GROUP_DISABLED) { $this->db->sql_transaction('begin'); // First we move all groups between our current value and the target value up/down 1, // so we have a gap for our group to move. $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_legend = group_legend' . ($move_up ? ' + 1' : ' - 1') . ' WHERE group_legend > ' . self::GROUP_DISABLED . ' AND group_legend' . ($move_up ? ' >= ' : ' <= ') . ($current_value - $delta) . ' AND group_legend' . ($move_up ? ' < ' : ' > ') . $current_value; $this->db->sql_query($sql); // Because there might be fewer groups above/below the group than we wanted to move, // we use the number of changed groups, to update the group. $delta = (int) $this->db->sql_affectedrows(); if ($delta) { // And now finally, when we moved some other groups and built a gap, // we can move the desired group to it. $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_legend = group_legend ' . ($move_up ? ' - ' : ' + ') . $delta . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); $this->db->sql_transaction('commit'); return true; } $this->db->sql_transaction('commit'); } return false; }
/** * Delete attachments from database table */ protected function delete_attachments_from_db() { /** * Perform additional actions before attachment(s) deletion * * @event core.delete_attachments_before * @var string mode Variable containing attachments deletion mode, can be: post|message|topic|attach|user * @var mixed ids Array or comma separated list of ids corresponding to the mode * @var bool resync Flag indicating if posts/messages/topics should be synchronized * @var string sql_id The field name to collect/delete data for depending on the mode * @var array post_ids Array with post ids for deleted attachment(s) * @var array topic_ids Array with topic ids for deleted attachment(s) * @var array message_ids Array with private message ids for deleted attachment(s) * @var array physical Array with deleted attachment(s) physical file(s) data * @since 3.1.7-RC1 */ $vars = array('mode', 'ids', 'resync', 'sql_id', 'post_ids', 'topic_ids', 'message_ids', 'physical'); extract($this->dispatcher->trigger_event('core.delete_attachments_before', compact($vars))); // Delete attachments $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $this->db->sql_in_set($this->sql_id, $this->ids); $sql .= $this->sql_where; $this->db->sql_query($sql); $this->num_deleted = $this->db->sql_affectedrows(); }
/** * {@inheritdoc} */ public function set_user_categories($forum_id) { // Set the collapsed category data array $this->set_collapsed_categories($forum_id); // Update the db with json encoded array of collapsed category data if ($this->user->data['is_registered']) { $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\tSET collapsible_categories = '" . $this->db->sql_escape(json_encode($this->collapsed_categories)) . "'\n\t\t\t\tWHERE user_id = " . (int) $this->user->data['user_id']; $this->db->sql_query($sql); // There was an error updating the user's data if (!$this->db->sql_affectedrows()) { return false; } } // Set a cookie with the collapsed category data and return true return $this->set_cookie_categories($forum_id); }
/** * Move module horizontally * * @param int $module_id Module ID * @param array $module_data Module data array * @param int $move_action The move action */ public function move_module_horizontal($module_id, $module_data, $move_action) { $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' SET module_order = module_order + 1 WHERE module_order >= ' . (int) $module_data['module_order'] . ' AND module_column = ' . (int) ($module_data['module_column'] + $move_action); $this->db->sql_query($sql); $updated = $this->db->sql_affectedrows(); $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' SET module_column = ' . (int) ($module_data['module_column'] + $move_action) . ' WHERE module_id = ' . (int) $module_id; $this->db->sql_query($sql); $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' SET module_order = module_order - 1 WHERE module_order >= ' . (int) $module_data['module_order'] . ' AND module_column = ' . (int) $module_data['module_column']; $this->db->sql_query($sql); // the module that needs to moved is in the last row if (!$updated) { $sql = 'SELECT MAX(module_order) as new_order FROM ' . PORTAL_MODULES_TABLE . ' WHERE module_order < ' . (int) $module_data['module_order'] . ' AND module_column = ' . (int) ($module_data['module_column'] + $move_action); $this->db->sql_query($sql); $new_order = $this->db->sql_fetchfield('new_order') + 1; $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' SET module_order = ' . (int) $new_order . ' WHERE module_id = ' . (int) $module_id; $this->db->sql_query($sql); } }
/** * Sets a configuration option's value only if the old_value matches the * current configuration value or the configuration value does not exist yet. * * @param string $key The configuration option's name * @param mixed $old_value Current configuration value or false to ignore * the old value * @param string $new_value New configuration value * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached * @return bool True if the value was changed, false otherwise */ public function set_atomic($key, $old_value, $new_value, $use_cache = true) { $sql = 'UPDATE ' . $this->table . " SET config_value = '" . $this->db->sql_escape($new_value) . "' WHERE config_name = '" . $this->db->sql_escape($key) . "'"; if ($old_value !== false) { $sql .= " AND config_value = '" . $this->db->sql_escape($old_value) . "'"; } $result = $this->db->sql_query($sql); if (!$this->db->sql_affectedrows($result) && isset($this->config[$key])) { return false; } if (!isset($this->config[$key])) { $sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', array( 'config_name' => $key, 'config_value' => $new_value, 'is_dynamic' => ($use_cache) ? 0 : 1)); $this->db->sql_query($sql); } if ($use_cache) { $this->cache->destroy('config'); } $this->config[$key] = $new_value; return true; }
/** * Delete a subscription * * @param string $item_type Type identifier of the subscription * @param int $item_id The id of the item * @param string $method The method of the notification e.g. 'board', 'email', or 'jabber' * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) */ public function delete_subscription($item_type, $item_id = 0, $method = null, $user_id = false) { if ($method === null) { foreach ($this->get_default_methods() as $method_name) { $this->delete_subscription($item_type, $item_id, $method_name, $user_id); } return; } $user_id = $user_id ?: $this->user->data['user_id']; $sql = 'UPDATE ' . $this->user_notifications_table . " SET notify = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " AND method = '" . $this->db->sql_escape($method) . "'"; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) { $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . $this->db->sql_build_array('INSERT', array( 'item_type' => $item_type, 'item_id' => (int) $item_id, 'user_id' => (int) $user_id, 'method' => $method, 'notify' => 0, )); $this->db->sql_query($sql); } }
/** * Set topic visibility * * Allows approving (which is akin to undeleting/restore) or soft deleting an entire topic. * Calls set_post_visibility as needed. * * Note: By default, when a soft deleted topic is restored. Only posts that * were approved at the time of soft deleting, are being restored. * Same applies to soft deleting. Only approved posts will be marked * as soft deleted. * If you want to update all posts, use the force option. * * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE} * @param $topic_id mixed Topic ID to act on * @param $forum_id int Forum where $topic_id is found * @param $user_id int User performing the action * @param $time int Timestamp when the action is performed * @param $reason string Reason why the visibilty was changed. * @param $force_update_all bool Force to update all posts within the topic * @return array Changed topic data, empty array if an error occured. */ public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false) { if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE))) { return array(); } if (!$force_update_all) { $sql = 'SELECT topic_visibility, topic_delete_time FROM ' . $this->topics_table . ' WHERE topic_id = ' . (int) $topic_id; $result = $this->db->sql_query($sql); $original_topic_data = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if (!$original_topic_data) { // The topic does not exist... return array(); } } // Note, we do not set a reason for the posts, just for the topic $data = array( 'topic_visibility' => (int) $visibility, 'topic_delete_user' => (int) $user_id, 'topic_delete_time' => ((int) $time) ?: time(), 'topic_delete_reason' => truncate_string($reason, 255, 255, false), ); $sql = 'UPDATE ' . $this->topics_table . ' SET ' . $this->db->sql_build_array('UPDATE', $data) . ' WHERE topic_id = ' . (int) $topic_id; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) { return array(); } if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED) { // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion. $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']); } else if (!$force_update_all && $original_topic_data['topic_visibility'] == ITEM_APPROVED && $visibility == ITEM_DELETED) { // If we're soft deleting a topic we only mark approved posts as soft deleted. $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility']); } else { $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true); } return $data; }
/** * Deletes an object identified by $this->sql_id_field * * @return int rows deleted */ public function delete() { $sql = 'DELETE FROM ' . $this->sql_table . ' WHERE ' . $this->sql_id_field . ' = ' . $this->{$this->sql_id_field}; $this->db->sql_query($sql); // Unset the sql indentifier field unset($this->{$this->sql_id_field}); return $this->db->sql_affectedrows(); }
/** * Close an announcement for a registered user * * @return bool True if successful, false otherwise * @access protected */ protected function update_board_announcement_status() { // Set announcement status to 0 for registered user $sql = 'UPDATE ' . USERS_TABLE . ' SET board_announcements_status = 0 WHERE user_id = ' . (int) $this->user->data['user_id'] . ' AND user_type <> ' . USER_IGNORE; $this->db->sql_query($sql); return (bool) $this->db->sql_affectedrows(); }
/** * Delete a page * * @param int $page_id The page identifier to delete * @return bool True if row was deleted, false otherwise * @throws \phpbb\pages\exception\out_of_bounds * @access public */ public function delete_page($page_id) { // Remove any existing page link data for this page // An exception will be thrown if page identifier is invalid $this->remove_page_links($page_id); // Delete the page from the database $sql = 'DELETE FROM ' . $this->pages_table . ' WHERE page_id = ' . (int) $page_id; $this->db->sql_query($sql); // Return true/false if a page was deleted return (bool) $this->db->sql_affectedrows(); }
/** * en/disables tagging engine in all forums (not categories and links). * * @param boolean $enable true to enable and false to disabl the engine * @return number of affected forums (should be the count of all forums (type FORUM_POST )) */ private function set_tags_enabled_in_all_forums($enable) { $sql_ary = array('rh_topictags_enabled' => $enable ? 1 : 0); $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE forum_type = ' . FORUM_POST . ' AND rh_topictags_enabled = ' . ($enable ? '0' : '1'); $this->db->sql_query($sql); $affected_rows = $this->db->sql_affectedrows(); $this->calc_count_tags(); return (int) $affected_rows; }
/** * Mass set configuration options: Receives an associative array, * treats array keys as configuration option names and associated * array values as their configuration option values. * * @param array $map Map from configuration names to values * * @return null */ public function set_array(array $map) { $this->db->sql_transaction('begin'); foreach ($map as $key => $value) { $sql = 'UPDATE ' . $this->table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($value) . "'\n\t\t\t\tWHERE config_name = '" . $this->db->sql_escape($key) . "'"; $result = $this->db->sql_query($sql); if (!$this->db->sql_affectedrows($result)) { $sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', array('config_name' => (string) $key, 'config_value' => (string) $value)); $this->db->sql_query($sql); } } $this->db->sql_transaction('commit'); }
/** * Set points config value. Creates missing config entry. */ function set_points_config($config_name, $config_value, $is_dynamic = false) { $sql = 'UPDATE ' . $this->points_config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($config_value) . "'\n\t\t\t\tWHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows() && !isset($points_config[$config_name])) { $sql = 'INSERT INTO ' . $this->points_config_table . ' ' . $this->db->sql_build_array('INSERT', array('config_name' => $config_name, 'config_value' => $config_value, 'is_dynamic' => $is_dynamic ? 1 : 0)); $this->db->sql_query($sql); } $points_config[$config_name] = $config_value; if (!$is_dynamic) { $this->cache->destroy('config'); } }
private function delete_template() { $noty_id = $this->request->variable('noty_id', 0); $row_id = $this->request->variable('row_id', 0); $sql = "DELETE FROM " . $this->adminnotifications_table . " WHERE noty_id=" . $noty_id; $this->db->sql_query($sql); $result = $this->db->sql_affectedrows($sql); if ($result == 0) { $this->error[] = array('error' => $this->user->lang['INCORRECT_SEARCH']); return; } $this->return = array('MESSAGE' => $this->user->lang['ACP_ADMINNOTIFICATIONS_DELETED'], 'ROW_ID' => $row_id); }
/** * Update profile field data directly */ public function update_profile_field_data($user_id, $cp_data) { if (!sizeof($cp_data)) { return; } $sql = 'UPDATE ' . $this->fields_data_table . ' SET ' . $this->db->sql_build_array('UPDATE', $cp_data) . ' WHERE user_id = ' . (int) $user_id; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) { $cp_data = $this->build_insert_sql_array($cp_data); $cp_data['user_id'] = (int) $user_id; $sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data); $this->db->sql_query($sql); } }
public function delete_thanks($post_id, $forum_id) { // $this->user->add_lang_ext('gfksx/ThanksForPosts', 'thanks_mod'); $to_id = $this->request->variable('to_id', 0); $forum_id = $forum_id ?: $this->request->variable('f', 0); $row = $this->get_post_info($post_id); // confirm $hidden = build_hidden_fields(array('to_id' => $to_id, 'rthanks' => $post_id)); /** * This event allows to interrupt before a thanks is deleted * * @event gfksx.thanksforposts.delete_thanks_before * @var int post_id The post id * @var int forum_id The forum id * @since 2.0.3 */ $vars = array('post_id', 'forum_id'); extract($this->phpbb_dispatcher->trigger_event('gfksx.thanksforposts.delete_thanks_before', compact($vars))); if (isset($this->config['remove_thanks']) ? !$this->config['remove_thanks'] : true) { trigger_error($this->user->lang['DISABLE_REMOVE_THANKS'] . '<br /><br />' . $this->user->lang('RETURN_POST', '<a href="' . append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$forum_id}&p={$post_id}#p{$post_id}") . '">', '</a>')); } if (confirm_box(true, 'REMOVE_THANKS', $hidden)) { if ($this->user->data['user_type'] != USER_IGNORE && !empty($to_id) && $this->auth->acl_get('f_thanks', $forum_id)) { $sql = "DELETE FROM " . $this->thanks_table . ' WHERE post_id =' . (int) $post_id . " AND user_id = " . (int) $this->user->data['user_id']; $this->db->sql_query($sql); $result = $this->db->sql_affectedrows($sql); if ($result != 0) { $lang_act = 'REMOVE'; $thanks_data = array('user_id' => (int) $this->user->data['user_id'], 'post_id' => $post_id, 'poster_id' => $to_id, 'topic_id' => (int) $row['topic_id'], 'forum_id' => $forum_id, 'thanks_time' => time(), 'username' => $this->user->data['username'], 'lang_act' => $lang_act, 'post_subject' => $row['post_subject']); $this->add_notification($thanks_data, 'gfksx.thanksforposts.notification.type.thanks_remove'); if (isset($this->config['thanks_info_page']) && $this->config['thanks_info_page']) { meta_refresh(1, append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$forum_id}&p={$post_id}#p{$post_id}")); trigger_error($this->user->lang['THANKS_INFO_' . $lang_act] . '<br /><br />' . $this->user->lang('RETURN_POST', '<a href="' . append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$forum_id}&p={$post_id}#p{$post_id}") . '">', '</a>')); } else { redirect(append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$forum_id}&p={$post_id}#p{$post_id}")); } } else { trigger_error($this->user->lang['INCORRECT_THANKS'] . '<br /><br />' . $this->user->lang('RETURN_POST', '<a href="' . append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$forum_id}&p={$post_id}#p{$post_id}") . '">', '</a>')); } } } else { confirm_box(false, 'REMOVE_THANKS', $hidden); redirect(append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$forum_id}&p={$post_id}#p{$post_id}")); } return; }
/** * {@inheritdoc} */ public function storeAccessToken($service, TokenInterface $token) { $service = $this->get_service_name_for_db($service); $this->cachedToken = $token; $data = array('oauth_token' => $this->json_encode_token($token)); $sql = 'UPDATE ' . $this->oauth_token_table . ' SET ' . $this->db->sql_build_array('UPDATE', $data) . ' WHERE user_id = ' . (int) $this->user->data['user_id'] . ' ' . ((int) $this->user->data['user_id'] === ANONYMOUS ? "AND session_id = '" . $this->db->sql_escape($this->user->data['session_id']) . "'" : '') . "\n\t\t\t\t\tAND provider = '" . $this->db->sql_escape($service) . "'"; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) { $data = array('user_id' => (int) $this->user->data['user_id'], 'provider' => $service, 'oauth_token' => $this->json_encode_token($token), 'session_id' => $this->user->data['session_id']); $sql = 'INSERT INTO ' . $this->oauth_token_table . $this->db->sql_build_array('INSERT', $data); $this->db->sql_query($sql); } return $this; }
/** * Delete a subscription * * @param string $item_type Type identifier of the subscription * @param int $item_id The id of the item * @param string $method The method of the notification e.g. '', 'email', or 'jabber' * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) */ public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false) { $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; // If no method, make sure that no other notification methods for this item are selected before deleting if ($method === '') { $sql = 'SELECT COUNT(*) as num_notifications FROM ' . $this->user_notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " AND method <> '' AND notify = 1"; $this->db->sql_query($sql); $num_notifications = $this->db->sql_fetchfield('num_notifications'); $this->db->sql_freeresult(); if ($num_notifications) { return; } } $sql = 'UPDATE ' . $this->user_notifications_table . " SET notify = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " AND method = '" . $this->db->sql_escape($method) . "'"; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) { $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . $this->db->sql_build_array('INSERT', array( 'item_type' => $item_type, 'item_id' => (int) $item_id, 'user_id' => (int) $user_id, 'method' => $method, 'notify' => 0, )); $this->db->sql_query($sql); } }
/** * Add an item which already has a database row at the end of the tree * * @param int $item_id The item to be added * @return array Array with updated data, if the item was added successfully * Empty array otherwise */ protected function add_item_to_nestedset($item_id) { $sql = 'SELECT MAX(' . $this->column_right_id . ') AS ' . $this->column_right_id . ' FROM ' . $this->table_name . ' ' . $this->get_sql_where('WHERE'); $result = $this->db->sql_query($sql); $current_max_right_id = (int) $this->db->sql_fetchfield($this->column_right_id); $this->db->sql_freeresult($result); $update_item_data = array($this->column_parent_id => 0, $this->column_left_id => $current_max_right_id + 1, $this->column_right_id => $current_max_right_id + 2, $this->column_item_parents => ''); $sql = 'UPDATE ' . $this->table_name . ' SET ' . $this->db->sql_build_array('UPDATE', $update_item_data) . ' WHERE ' . $this->column_item_id . ' = ' . (int) $item_id . ' AND ' . $this->column_parent_id . ' = 0 AND ' . $this->column_left_id . ' = 0 AND ' . $this->column_right_id . ' = 0'; $this->db->sql_query($sql); return $this->db->sql_affectedrows() == 1 ? $update_item_data : array(); }
/** * Deletes an item from the list and closes the gap in the position list. * * @param int $teampage_id teampage_id of the item to be deleted * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. * @return bool True if the item was deleted successfully */ public function delete_teampage($teampage_id, $skip_group = false) { $current_value = $this->get_teampage_value($teampage_id); if ($current_value != self::GROUP_DISABLED) { $sql = 'DELETE FROM ' . TEAMPAGE_TABLE . ' WHERE teampage_id = ' . $teampage_id . ' OR teampage_parent = ' . $teampage_id; $this->db->sql_query($sql); $delta = (int) $this->db->sql_affectedrows(); $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' SET teampage_position = teampage_position - ' . $delta . ' WHERE teampage_position > ' . $current_value; $this->db->sql_query($sql); $this->cache->destroy('sql', TEAMPAGE_TABLE); return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); return false; }
public function display_points() { // Grab some vars $action = $this->request->variable('action', ''); $id = $this->request->variable('id', 0); // Read out config data $sql_array = array('SELECT' => 'config_name, config_value', 'FROM' => array($this->points_config_table => 'c')); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $points_config[$row['config_name']] = $row['config_value']; } $this->db->sql_freeresult($result); $this->template->assign_vars(array_change_key_case($points_config, CASE_UPPER)); // Read out values data $sql_array = array('SELECT' => '*', 'FROM' => array($this->points_values_table => 'v')); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $points_values = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Form key add_form_key('acp_points'); $this->template->assign_vars(array('BASE' => $this->u_action)); $submit = $this->request->variable('submit', ''); if ($submit) { if (!check_form_key('acp_points')) { trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } // Values for phpbb_config $points_name = $this->request->variable('points_name', '', true); $points_enable = $this->request->variable('points_enable', 0); // Values for phpbb_points_config $points_disablemsg = $this->request->variable('points_disablemsg', '', true); $transfer_enable = $this->request->variable('transfer_enable', 0); $transfer_pm_enable = $this->request->variable('transfer_pm_enable', 0); $comments_enable = $this->request->variable('comments_enable', 0); $uplist_enable = $this->request->variable('uplist_enable', 0); $stats_enable = $this->request->variable('stats_enable', 0); $logs_enable = $this->request->variable('logs_enable', 0); $images_topic_enable = $this->request->variable('images_topic_enable', 0); $images_memberlist_enable = $this->request->variable('images_memberlist_enable', 0); // Values for phpbb_points_values $sql_ary = array('transfer_fee' => $this->request->variable('transfer_fee', 0), 'number_show_per_page' => $this->request->variable('number_show_per_page', 0), 'number_show_top_points' => $this->request->variable('number_show_top_points', 0), 'points_per_attach' => round($this->request->variable('points_per_attach', 0.0), 2), 'points_per_attach_file' => round($this->request->variable('points_per_attach_file', 0.0), 2), 'points_per_poll' => round($this->request->variable('points_per_poll', 0.0), 2), 'points_per_poll_option' => round($this->request->variable('points_per_poll_option', 0.0), 2), 'points_per_topic_word' => round($this->request->variable('points_per_topic_word', 0.0), 2), 'points_per_topic_character' => round($this->request->variable('points_per_topic_character', 0.0), 2), 'points_per_post_word' => round($this->request->variable('points_per_post_word', 0.0), 2), 'points_per_post_character' => round($this->request->variable('points_per_post_character', 0.0), 2), 'reg_points_bonus' => round($this->request->variable('reg_points_bonus', 0.0), 2), 'points_bonus_chance' => round($this->request->variable('points_bonus_chance', 0.0), 2), 'points_bonus_min' => round($this->request->variable('points_bonus_min', 0.0), 2), 'points_bonus_max' => round($this->request->variable('points_bonus_max', 0.0), 2), 'points_per_warn' => round($this->request->variable('points_per_warn', 0.0), 2)); // Check if number_show_per_page is at least 5 $per_page_check = $this->request->variable('number_show_per_page', 0); if ($per_page_check < 5) { trigger_error($this->user->lang['POINTS_SHOW_PER_PAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check if Transfer Fee percent is not more than 100% if ($sql_ary['transfer_fee'] > 100) { trigger_error($this->user->lang['POINTS_TRANSFER_FEE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } // Update values in phpbb_config if ($points_name != $this->config['points_name']) { $this->config->set('points_name', $points_name); } if ($points_enable != $this->config['points_enable']) { $this->config->set('points_enable', $points_enable); } // Update values in phpbb_points_config if ($points_disablemsg != $points_config['points_disablemsg']) { $this->functions_points->set_points_config('points_disablemsg', $points_disablemsg); } if ($transfer_enable != $points_config['transfer_enable']) { $this->functions_points->set_points_config('transfer_enable', $transfer_enable); } if ($transfer_pm_enable != $points_config['transfer_pm_enable']) { $this->functions_points->set_points_config('transfer_pm_enable', $transfer_pm_enable); } if ($comments_enable != $points_config['comments_enable']) { $this->functions_points->set_points_config('comments_enable', $comments_enable); } if ($uplist_enable != $points_config['uplist_enable']) { $this->functions_points->set_points_config('uplist_enable', $uplist_enable); } if ($stats_enable != $points_config['stats_enable']) { $this->functions_points->set_points_config('stats_enable', $stats_enable); } if ($logs_enable != $points_config['logs_enable']) { $this->functions_points->set_points_config('logs_enable', $logs_enable); } if ($images_topic_enable != $points_config['images_topic_enable']) { $this->functions_points->set_points_config('images_topic_enable', $images_topic_enable); } if ($images_memberlist_enable != $points_config['images_memberlist_enable']) { $this->functions_points->set_points_config('images_memberlist_enable', $images_memberlist_enable); } // Update values in phpbb_points_values $sql = 'UPDATE ' . $this->points_values_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary); $this->db->sql_query($sql); // Add logs $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_MOD_POINTS_SETTINGS'); trigger_error($this->user->lang['POINTS_CONFIG_SUCCESS'] . adm_back_link($this->u_action)); } else { $this->template->assign_vars(array('POINTS_NAME' => $this->config['points_name'], 'POINTS_PER_ATTACH' => $points_values['points_per_attach'], 'POINTS_PER_ATTACH_FILE' => $points_values['points_per_attach_file'], 'POINTS_PER_POLL' => $points_values['points_per_poll'], 'POINTS_PER_POLL_OPTION' => $points_values['points_per_poll_option'], 'POINTS_PER_TOPIC_WORD' => $points_values['points_per_topic_word'], 'POINTS_PER_TOPIC_CHARACTER' => $points_values['points_per_topic_character'], 'POINTS_PER_POST_WORD' => $points_values['points_per_post_word'], 'POINTS_PER_POST_CHARACTER' => $points_values['points_per_post_character'], 'POINTS_PER_WARN' => $points_values['points_per_warn'], 'REG_POINTS_BONUS' => $points_values['reg_points_bonus'], 'POINTS_BONUS_CHANCE' => $points_values['points_bonus_chance'], 'POINTS_BONUS_MIN' => $points_values['points_bonus_min'], 'POINTS_BONUS_MAX' => $points_values['points_bonus_max'], 'NUMBER_SHOW_TOP_POINTS' => $points_values['number_show_top_points'], 'NUMBER_SHOW_PER_PAGE' => $points_values['number_show_per_page'], 'TRANSFER_FEE' => $points_values['transfer_fee'], 'POINTS_ENABLE' => $this->config['points_enable'] ? true : false)); } // Delete all userlogs $reset_pointslogs = isset($_POST['action_points_logs']) ? true : false; if ($reset_pointslogs) { if (confirm_box(true)) { if (!$this->auth->acl_get('a_points')) { trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_layer = $this->db->get_sql_layer(); switch ($sql_layer) { case 'sqlite': case 'firebird': $this->db->sql_query('DELETE FROM ' . $this->table_points_log); break; default: $this->db->sql_query('TRUNCATE TABLE ' . $this->table_points_log); break; } $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_RESYNC_POINTSLOGSCOUNTS'); trigger_error($this->user->lang['LOG_RESYNC_POINTSLOGSCOUNTS'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('action_points_logs' => true)); // Display mode confirm_box(false, $this->user->lang['RESYNC_POINTSLOGS_CONFIRM'], $s_hidden_fields); } } // Delete all userpoints $reset_points_user = isset($_POST['action_points']) ? true : false; if ($reset_points_user) { if (confirm_box(true)) { if (!$this->auth->acl_get('a_points')) { trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_points = 0'); $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_RESYNC_POINTSCOUNTS'); trigger_error($this->user->lang['LOG_RESYNC_POINTSCOUNTS'] . adm_back_link($this->u_action)); } else { $s_hidden_fields = build_hidden_fields(array('action_points' => true)); // Display mode confirm_box(false, $this->user->lang['RESYNC_POINTS_CONFIRM'], $s_hidden_fields); } } // Transfer or set points for groups $group_transfer = isset($_POST['group_transfer']) ? true : false; $group_transfer_points = $this->request->variable('group_transfer_points', 0.0); $func = $this->request->variable('func', ''); $group_id = $this->request->variable('group_id', 0); $pm_subject = $this->request->variable('pm_subject', '', true); $pm_text = $this->request->variable('pm_text', '', true); $sql_array = array('SELECT' => 'group_id, group_name, group_type', 'FROM' => array(GROUPS_TABLE => 'g'), 'ORDER_BY' => 'group_name'); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $total_groups = $this->db->sql_affectedrows($result); $this->db->sql_freeresult($result); $this->template->assign_vars(array('U_SMILIES' => append_sid("{$this->phpbb_root_path}posting.{$this->phpEx}", 'mode=smilies'), 'S_GROUP_OPTIONS' => group_select_options($total_groups), 'U_ACTION' => $this->u_action)); // Update the points if ($group_transfer) { if (!check_form_key('acp_points')) { trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_array = array('SELECT' => 'group_type, group_name', 'FROM' => array(GROUPS_TABLE => 'g'), 'WHERE' => 'group_id = ' . (int) $group_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $group_name = $row['group_type'] == GROUP_SPECIAL ? $this->user->lang['G_' . $row['group_name']] : $row['group_name']; // Check if we try transfering to BOTS or GUESTS if ($row['group_name'] == 'BOTS' || $row['group_name'] == 'GUESTS') { trigger_error($this->user->lang['POINTS_GROUP_TRANSFER_SEL_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql_array = array('SELECT' => 'user_id', 'FROM' => array(USER_GROUP_TABLE => 'g'), 'WHERE' => 'user_pending <> ' . true . ' AND group_id = ' . (int) $group_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $user_ids = array(); while ($row = $this->db->sql_fetchrow($result)) { $user_ids[] = $row['user_id']; } $this->db->sql_freeresult($result); if (sizeof($user_ids)) { $userdata_group = implode(', ', $user_ids); if ($func == 'add') { $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = user_points + {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})"; $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_ADD'); } if ($func == 'substract') { $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = user_points - {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})"; $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_ADD'); } if ($func == 'set') { $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\tSET user_points = {$group_transfer_points}\n\t\t\t\t\t\tWHERE user_id IN ({$userdata_group})"; $this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_GROUP_TRANSFER_SET'); } $result = $this->db->sql_query($sql); // Send PM, if pm subject and pm comment is entered if ($pm_subject != '' || $pm_text != '') { if ($pm_subject == '' || $pm_text == '') { trigger_error($this->user->lang['POINTS_GROUP_TRANSFER_PM_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); } else { $sql_array = array('SELECT' => 'user_id, group_id', 'FROM' => array(USER_GROUP_TABLE => 'g'), 'WHERE' => 'user_pending <> ' . true . ' AND group_id = ' . (int) $group_id); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $group_to = array(); while ($row = $this->db->sql_fetchrow($result)) { $group_to[$row['group_id']] = 'to'; } // and notify PM to recipient of rating: require_once $this->phpbb_root_path . 'includes/functions_privmsgs.' . $this->phpEx; $poll = $uid = $bitfield = $options = ''; generate_text_for_storage($pm_subject, $uid, $bitfield, $options, false, false, false); generate_text_for_storage($pm_text, $uid, $bitfield, $options, true, true, true); $pm_data = array('address_list' => array('g' => $group_to), 'from_user_id' => $this->user->data['user_id'], 'from_username' => 'Points Transfer', 'icon_id' => 0, 'from_user_ip' => $this->user->data['user_ip'], 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $pm_text, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid); submit_pm('post', $pm_subject, $pm_data, false); $this->db->sql_freeresult($result); } $message = $this->user->lang['POINTS_GROUP_TRANSFER_PM_SUCCESS'] . adm_back_link($this->u_action); trigger_error($message); } else { $message = $this->user->lang['POINTS_GROUP_TRANSFER_SUCCESS'] . adm_back_link($this->u_action); trigger_error($message); } } } $this->template->assign_vars(array('S_POINTS_MAIN' => true, 'S_POINTS_ACTIVATED' => $this->config['points_enable'] ? true : false, 'U_ACTION' => $this->u_action)); // Version check $this->user->add_lang(array('install', 'acp/extensions', 'migrator')); $ext_name = 'dmzx/ultimatepoints'; $md_manager = new \phpbb\extension\metadata_manager($ext_name, $this->config, $this->phpbb_extension_manager, $this->template, $this->user, $this->phpbb_root_path); try { $this->metadata = $md_manager->get_metadata('all'); } catch (\phpbb\extension\exception $e) { trigger_error($e, E_USER_WARNING); } $md_manager->output_template_data(); try { $updates_available = $this->version_check($md_manager, $this->request->variable('versioncheck_force', false)); $this->template->assign_vars(array('S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')))); foreach ($updates_available as $branch => $version_data) { $this->template->assign_block_vars('updates_available', $version_data); } } catch (\RuntimeException $e) { $this->template->assign_vars(array('S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $this->user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : '')); } }
function main($id, $mode) { global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; global $helper, $root_path, $php_ext, $content_visibility; $this->user = $user; $this->db = $db; $this->tpl_name = 'ucp_psb'; $this->page_title = $user->lang('UCP_PSB_MANAGE'); $uid = $this->user->data['user_id']; $nbp = 0; $nbv = 0; $nba = 0; $nbma = 0; $nbmp = 0; // Submission if ($request->is_set_post('submit')) { if (!check_form_key('ucp_psb')) { trigger_error('FORM_INVALID'); } // Display number of older topics $nbma = $request->variable('nbma', 0); if ($nbma) { // Older topics without posts $sql = "SELECT COUNT(*) as nb "; $sql .= " FROM " . TOPICS_WATCH_TABLE; $sql .= " INNER JOIN " . TOPICS_TABLE; $sql .= " WHERE " . TOPICS_WATCH_TABLE . ".topic_id = "; $sql .= TOPICS_TABLE . ".topic_id AND "; $sql .= TOPICS_WATCH_TABLE . ".user_id = {$uid} AND "; $sql .= "(FROM_UNIXTIME(" . TOPICS_TABLE . ".topic_last_post_time)) < "; $sql .= "date_sub(now(), interval {$nbma} month)"; // var_dump ($sql); $res = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($res); $nbp = $row['nb']; $this->db->sql_freeresult($res); // Idem, without visits $sql = "SELECT COUNT(*) as nb "; $sql .= " FROM " . TOPICS_WATCH_TABLE; $sql .= " INNER JOIN " . TOPICS_TABLE; $sql .= " WHERE " . TOPICS_WATCH_TABLE . ".topic_id = "; $sql .= TOPICS_TABLE . ".topic_id AND "; $sql .= TOPICS_WATCH_TABLE . ".user_id = {$uid} AND "; $sql .= "(FROM_UNIXTIME(" . TOPICS_TABLE . ".topic_last_view_time)) < "; $sql .= "date_sub(now(), interval {$nbma} month)"; // var_dump ($sql); $res = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($res); $nbv = $row['nb']; $this->db->sql_freeresult($res); } // Topics to be purged $nbmp = $request->variable('nbmp', 0); $purgep = $request->variable('purgep', 0); $purgev = $request->variable('purgev', 0); if ($nbmp) { $delp = 0; $delv = 0; if ($purgep) { $sql = "DELETE " . TOPICS_WATCH_TABLE; $sql .= " FROM " . TOPICS_WATCH_TABLE; $sql .= " INNER JOIN " . TOPICS_TABLE; $sql .= " WHERE " . TOPICS_WATCH_TABLE . ".topic_id = "; $sql .= TOPICS_TABLE . ".topic_id AND "; $sql .= TOPICS_WATCH_TABLE . ".user_id = {$uid} AND "; $sql .= "(FROM_UNIXTIME(" . TOPICS_TABLE . ".topic_last_post_time)) < "; $sql .= "date_sub(now(), interval {$nbmp} month)"; // var_dump ($sql); $this->db->sql_query($sql); $delp = $this->db->sql_affectedrows(); } if ($purgev) { $sql = "DELETE " . TOPICS_WATCH_TABLE; $sql .= " FROM " . TOPICS_WATCH_TABLE; $sql .= " INNER JOIN " . TOPICS_TABLE; $sql .= " WHERE " . TOPICS_WATCH_TABLE . ".topic_id = "; $sql .= TOPICS_TABLE . ".topic_id AND "; $sql .= TOPICS_WATCH_TABLE . ".user_id = {$uid} AND "; $sql .= "(FROM_UNIXTIME(" . TOPICS_TABLE . ".topic_last_view_time)) < "; $sql .= "date_sub(now(), interval {$nbmp} month)"; // var_dump ($sql); $this->db->sql_query($sql); $delv = $this->db->sql_affectedrows(); } $del = $delp + $delv; if ($del) { // Information message $message = 'UCP_RESULT_PURGE' . $del; $params = "i=-lmdi-purgesub-ucp-ucp_psb_module&mode=purgesub"; meta_refresh(3, append_sid("{$phpbb_root_path}ucp.{$phpEx}", $params)); trigger_error($message); } } } // Total number of subscribed topics at this point of time (after or before) $sql = "select count(*) as nb from " . TOPICS_WATCH_TABLE; $sql .= " WHERE user_id = {$uid}"; $this->db->sql_query($sql); // var_dump ($sql); $res = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($res); $nbt = $row['nb']; $this->db->sql_freeresult($res); // Form and page display $form_key = 'ucp_psb'; add_form_key($form_key); if (!$nbv) { $nbv = $nbt; } if (!$nbp) { $nbp = $nbt; } $template->assign_vars(array('L_TITLE' => $user->lang['UCP_PSB_TITLE'], 'S_UCP_ACTION' => $this->u_action, 'UCP_PSB_NBT' => $nbt, 'UCP_PSB_NBP' => $nbp, 'UCP_PSB_NBV' => $nbv, 'PSB_NBA' => $nbma, 'PSB_NBP' => $nbmp)); }
public function test_insert() { $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $this->db->sql_build_array('INSERT', array('config_name' => 'bertie', 'config_value' => 'rules')); $this->db->sql_query($sql); $this->assertEquals(1, $this->db->sql_affectedrows()); }
/** * Set topic visibility * * Allows approving (which is akin to undeleting/restore) or soft deleting an entire topic. * Calls set_post_visibility as needed. * * Note: By default, when a soft deleted topic is restored. Only posts that * were approved at the time of soft deleting, are being restored. * Same applies to soft deleting. Only approved posts will be marked * as soft deleted. * If you want to update all posts, use the force option. * * @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE} * @param $topic_id mixed Topic ID to act on * @param $forum_id int Forum where $topic_id is found * @param $user_id int User performing the action * @param $time int Timestamp when the action is performed * @param $reason string Reason why the visibilty was changed. * @param $force_update_all bool Force to update all posts within the topic * @return array Changed topic data, empty array if an error occured. */ public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false) { if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE))) { return array(); } if (!$force_update_all) { $sql = 'SELECT topic_visibility, topic_delete_time FROM ' . $this->topics_table . ' WHERE topic_id = ' . (int) $topic_id; $result = $this->db->sql_query($sql); $original_topic_data = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if (!$original_topic_data) { // The topic does not exist... return array(); } } if (!function_exists('truncate_string')) { include $this->phpbb_root_path . 'includes/functions_content.' . $this->php_ext; } // Note, we do not set a reason for the posts, just for the topic $data = array('topic_visibility' => (int) $visibility, 'topic_delete_user' => (int) $user_id, 'topic_delete_time' => (int) $time ?: time(), 'topic_delete_reason' => truncate_string($reason, 255, 255, false)); /** * Perform actions right before the query to change topic visibility * * @event core.set_topic_visibility_before_sql * @var int visibility Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE} * @var int topic_id Topic of the post IDs to be modified. * @var int forum_id Forum ID that the topic_id resides in. * @var int user_id User ID doing this action. * @var int timestamp Timestamp of this action. * @var string reason Reason specified by the user for this change. * @var bool force_update_all Force an update on all posts within the topic, regardless of their current approval state. * @var array data The data array for this action. * @since 3.1.10-RC1 */ $vars = array('visibility', 'topic_id', 'forum_id', 'user_id', 'timestamp', 'reason', 'force_update_all', 'data'); extract($this->phpbb_dispatcher->trigger_event('core.set_topic_visibility_before_sql', compact($vars))); $sql = 'UPDATE ' . $this->topics_table . ' SET ' . $this->db->sql_build_array('UPDATE', $data) . ' WHERE topic_id = ' . (int) $topic_id; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows()) { return array(); } if (!$force_update_all && $original_topic_data['topic_delete_time'] && $original_topic_data['topic_visibility'] == ITEM_DELETED && $visibility == ITEM_APPROVED) { // If we're restoring a topic we only restore posts, that were soft deleted through the topic soft deletion. $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility'], $original_topic_data['topic_delete_time']); } else { if (!$force_update_all && $original_topic_data['topic_visibility'] == ITEM_APPROVED && $visibility == ITEM_DELETED) { // If we're soft deleting a topic we only mark approved posts as soft deleted. $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility']); } else { $this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true); } } /** * Perform actions after all steps to changing topic visibility * * @event core.set_topic_visibility_after * @var int visibility Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE} * @var int topic_id Topic of the post IDs to be modified. * @var int forum_id Forum ID that the topic_id resides in. * @var int user_id User ID doing this action. * @var int timestamp Timestamp of this action. * @var string reason Reason specified by the user for this change. * @var bool force_update_all Force an update on all posts within the topic, regardless of their current approval state. * @var array data The data array for this action. * @since 3.1.10-RC1 */ $vars = array('visibility', 'topic_id', 'forum_id', 'user_id', 'timestamp', 'reason', 'force_update_all', 'data'); extract($this->phpbb_dispatcher->trigger_event('core.set_topic_visibility_after', compact($vars))); return $data; }
function main($id, $mode) { global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; global $table_prefix; $this->db = $db; $user->add_lang('acp/common'); $this->tpl_name = 'acp_body'; $this->page_title = $user->lang('ACP_PSB_TITLE'); add_form_key('lmdi/purgesub'); $nbma = 0; $nbmp = 0; // Data submitted if ($request->is_set_post('submit')) { if (!check_form_key('lmdi/purgesub')) { trigger_error('FORM_INVALID'); } $nbma = $request->variable('nbma', 0); // Register the setting for the UCP in the config table if changed. $cod1 = $config['lmdi_purge_ucp']; $cod2 = $request->variable('psb_validation', 0); $mess = 0; if ($cod1 != $cod2) { $config->set('lmdi_purge_ucp', $cod2); $sql = "UPDATE " . MODULES_TABLE; $sql .= " SET module_display = {$cod2} "; $sql .= "WHERE module_langname = 'UCP_PSB'"; $this->db->sql_query($sql); $cache->purge(); $mess += 1; trigger_error($user->lang('PSB_SETTING_SAVED') . adm_back_link($this->u_action)); } // Purge older topics in topics_watch table $nbmp = $request->variable('nbmp', 0); $purgep = $request->variable('purgep', 0); $purgev = $request->variable('purgev', 0); if ($nbmp != 0) { $delp = 0; $delv = 0; if ($purgep) { $sql = "DELETE " . TOPICS_WATCH_TABLE . "\n\t\t\t\t\t\tFROM " . TOPICS_WATCH_TABLE . "\n\t\t\t\t\t\tINNER JOIN " . TOPICS_TABLE . "\n\t\t\t\t\t\tWHERE " . TOPICS_WATCH_TABLE . ".topic_id =" . TOPICS_TABLE . ".topic_id AND \n\t\t\t\t\t\t(FROM_UNIXTIME(" . TOPICS_TABLE . ".topic_last_post_time)) < date_sub(now(), interval {$nbmp} month)"; // var_dump ($sql); $this->db->sql_query($sql); $delp = $this->db->sql_affectedrows(); } if ($purgev) { $sql = "DELETE " . TOPICS_WATCH_TABLE . "\n\t\t\t\t\t\tFROM " . TOPICS_WATCH_TABLE . "\n\t\t\t\t\t\tINNER JOIN " . TOPICS_TABLE . "\n\t\t\t\t\t\tWHERE " . TOPICS_WATCH_TABLE . ".topic_id =" . TOPICS_TABLE . ".topic_id AND \n\t\t\t\t\t\t(FROM_UNIXTIME(" . TOPICS_TABLE . ".topic_last_view_time)) < date_sub(now(), interval {$nbmp} month)"; // var_dump ($sql); $this->db->sql_query($sql); $delv = $this->db->sql_affectedrows(); } $del = $delp + $delv; if ($del) { // Information message $message = $user->lang('UCP_RESULT_PURGE') . $del; trigger_error($message . adm_back_link($this->u_action)); } } } // Back to the form // Total number of subscribed topics $sql = "SELECT count(*) as nb from " . TOPICS_WATCH_TABLE; $res = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($res); $nbt = $row['nb']; $this->db->sql_freeresult($res); // Topics without new posts $sql = "SELECT COUNT(*) as nb \n\t\t\tFROM " . TOPICS_WATCH_TABLE . "\n\t\t\tINNER JOIN " . TOPICS_TABLE . "\n\t\t\tWHERE " . TOPICS_WATCH_TABLE . ".topic_id =" . TOPICS_TABLE . ".topic_id AND \n\t\t\t(FROM_UNIXTIME(" . TOPICS_TABLE . ".topic_last_post_time)) < date_sub(now(), interval {$nbma} month)"; // var_dump ($sql); $res = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($res); $nbp = $row['nb']; $this->db->sql_freeresult($res); // Topics without new views $sql = "SELECT COUNT(*) as nb \n\t\t\tFROM " . TOPICS_WATCH_TABLE . "\n\t\t\tINNER JOIN " . TOPICS_TABLE . "\n\t\t\tWHERE " . TOPICS_WATCH_TABLE . ".topic_id = " . TOPICS_TABLE . ".topic_id AND \n\t\t\t(FROM_UNIXTIME(" . TOPICS_TABLE . ".topic_last_view_time)) < date_sub(now(), interval {$nbma} month)"; // var_dump ($sql); $res = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($res); $nbv = $row['nb']; $this->db->sql_freeresult($res); // Display variables $template->assign_vars(array('U_ACTION' => $this->u_action, 'ACP_PSB_NBT' => $nbt, 'ACP_PSB_NBP' => $nbp, 'ACP_PSB_NBV' => $nbv, 'ACP_PSB_NBMA' => $nbma, 'ACP_PSB_NBMP' => $nbmp, 'S_PURGE_UCP' => $config['lmdi_purge_ucp'])); }