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)));
        }
    }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $languages = $this->language_helper->get_available_languages();
     $installed_languages = array();
     foreach ($languages as $lang_info) {
         $lang_pack = array('lang_iso' => $lang_info['iso'], 'lang_dir' => $lang_info['iso'], 'lang_english_name' => htmlspecialchars($lang_info['name']), 'lang_local_name' => htmlspecialchars($lang_info['local_name'], ENT_COMPAT, 'UTF-8'), 'lang_author' => htmlspecialchars($lang_info['author'], ENT_COMPAT, 'UTF-8'));
         $this->db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $this->db->sql_build_array('INSERT', $lang_pack));
         $installed_languages[] = (int) $this->db->sql_nextid();
         if ($this->db->get_sql_error_triggered()) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message($error['message']);
         }
     }
     $sql = 'SELECT * FROM ' . PROFILE_FIELDS_TABLE;
     $result = $this->db->sql_query($sql);
     $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_LANG_TABLE);
     while ($row = $this->db->sql_fetchrow($result)) {
         foreach ($installed_languages as $lang_id) {
             $insert_buffer->insert(array('field_id' => $row['field_id'], 'lang_id' => $lang_id, 'lang_name' => strtoupper(substr($row['field_name'], 6)), 'lang_explain' => '', 'lang_default_value' => ''));
         }
     }
     $this->db->sql_freeresult($result);
     $insert_buffer->flush();
 }
    /**
     * Edit a comment
     *
     * @param	array	$data		Data to edit
     * @param	int		$comment_id	The comment ID
     * @return	null
     */
    public function edit($data, $comment_id)
    {
        $sql = 'UPDATE ' . DIR_COMMENT_TABLE . '
			SET ' . $this->db->sql_build_array('UPDATE', $data) . '
			WHERE comment_id = ' . (int) $comment_id;
        $this->db->sql_query($sql);
    }
Exemple #4
0
 /**
  * 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();
 }
 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}&amp;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}&amp;t={$topic_id}&amp;p={$post_id}&amp;mode={$mode}")));
     page_header($this->user->lang['POST_BOOKMARK_ADD']);
     $this->template->set_filenames(array('body' => $body . '.html'));
     page_footer();
     return new Response('', 200);
 }
Exemple #6
0
    /**
     * 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;
    }
Exemple #7
0
    /**
     * 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;
    }
    /**
     * Run database part for resetting a module
     *
     * @param \board3\portal\modules\module_interface $module Module to reset
     * @param int $module_id Module ID of module
     *
     * @return int Number of affected rows
     */
    public function reset_module($module, $module_id)
    {
        $sql_ary = array('module_name' => $module->get_name(), 'module_image_src' => $module->get_image(), 'module_group_ids' => '', 'module_image_height' => 16, 'module_image_width' => 16, 'module_status' => self::B3_MODULE_ENABLED);
        $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . '
					SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE module_id = ' . (int) $module_id;
        $this->db->sql_query($sql);
        return $this->db->sql_affectedrows();
    }
 /**
  * @param int $block_id
  * @return array
  */
 public function save($block_id)
 {
     $content = $this->request->variable('content', '', true);
     $cblocks = $this->_get_custom_blocks();
     $sql_data = array('block_id' => $block_id, 'block_content' => $content, 'bbcode_bitfield' => '', 'bbcode_options' => 7, 'bbcode_uid' => '');
     generate_text_for_storage($sql_data['block_content'], $sql_data['bbcode_uid'], $sql_data['bbcode_bitfield'], $sql_data['bbcode_options'], true, true, true);
     $sql = !isset($cblocks[$block_id]) ? 'INSERT INTO ' . $this->cblocks_table . ' ' . $this->db->sql_build_array('INSERT', $sql_data) : 'UPDATE ' . $this->cblocks_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_data) . ' WHERE block_id = ' . (int) $block_id;
     $this->db->sql_query($sql);
     $this->cache->destroy('pt_cblocks');
     return array('id' => $block_id, 'content' => $this->_get_content($sql_data), 'callback' => 'previewCustomBlock');
 }
Exemple #10
0
    public function send_topic()
    {
        if ($this->user->data['is_registered'] && $this->user->data['user_lastvisit'] == 0) {
            $this->create_welcome_topic($this->user->data['user_id']);
            $sql_ary = array('user_lastvisit' => $this->user->data['session_last_visit']);
            $sql = 'UPDATE ' . USERS_TABLE . '
				SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
				WHERE user_id = ' . $this->user->data['user_id'];
            $result = $this->db->sql_query($sql);
            $this->db->sql_freeresult($result);
        }
    }
 /**
  * Post a new message to the shoutbox.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function post()
 {
     // We always disallow guests to post in the shoutbox.
     if (!$this->auth->acl_get('u_shoutbox_post') || $this->user->data['user_id'] == ANONYMOUS) {
         return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_NO_PERMISSION', 403);
     }
     if ($this->request->is_ajax()) {
         $message = $msg = trim(utf8_normalize_nfc($this->request->variable('text_shoutbox', '', true)));
         if (empty($message)) {
             return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_MESSAGE_EMPTY', 500);
         }
         $uid = $bitfield = $options = '';
         $allow_bbcode = $this->auth->acl_get('u_shoutbox_bbcode');
         $allow_urls = $allow_smilies = true;
         if (!function_exists('generate_text_for_storage')) {
             include $this->root_path . 'includes/functions_content.' . $this->php_ext;
         }
         generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
         $insert = array('post_message' => $message, 'post_time' => time(), 'user_id' => $this->user->data['user_id'], 'bbcode_options' => $options, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid);
         $sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', $insert);
         $this->db->sql_query($sql);
         if ($this->push->canPush()) {
             // User configured us to submit the shoutbox post to the iOS/Android app
             $this->push->post($msg, $insert['post_time'], $this->user->data['username'], $this->db->sql_nextid());
         }
         return new JsonResponse(array('OK'));
     } else {
         return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_ONLY_AJAX', 500);
     }
 }
Exemple #12
0
    /**
     * {@inheritdoc}
     */
    public function run()
    {
        $this->db->sql_return_on_error(true);
        $sql = 'SELECT group_id
			FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name = 'BOTS'";
        $result = $this->db->sql_query($sql);
        $group_id = (int) $this->db->sql_fetchfield('group_id');
        $this->db->sql_freeresult($result);
        if (!$group_id) {
            // If we reach this point then something has gone very wrong
            $this->io_handler->add_error_message('NO_GROUP');
        }
        foreach ($this->bot_list as $bot_name => $bot_ary) {
            $user_row = array('user_type' => USER_IGNORE, 'group_id' => $group_id, 'username' => $bot_name, 'user_regdate' => time(), 'user_password' => '', 'user_colour' => '9E8DA7', 'user_email' => '', 'user_lang' => $this->install_config->get('default_lang'), 'user_style' => 1, 'user_timezone' => 'UTC', 'user_dateformat' => $this->language->lang('default_dateformat'), 'user_allow_massemail' => 0, 'user_allow_pm' => 0);
            if (!function_exists('user_add')) {
                include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
            }
            $user_id = user_add($user_row);
            if (!$user_id) {
                // If we can't insert this user then continue to the next one to avoid inconsistent data
                $this->io_handler->add_error_message('CONV_ERROR_INSERT_BOT');
                continue;
            }
            $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array('bot_active' => 1, 'bot_name' => (string) $bot_name, 'user_id' => (int) $user_id, 'bot_agent' => (string) $bot_ary[0], 'bot_ip' => (string) $bot_ary[1]));
            $this->db->sql_query($sql);
        }
    }
Exemple #13
0
 /**
  * @param int  $user_id
  * @param bool $admin
  * @param bool $auto_login
  * @param bool $viewonline
  * @param string $redirect
  */
 public function generate_page($user_id, $admin, $auto_login, $viewonline, $redirect)
 {
     $this->user->add_lang_ext('paul999/tfa', 'common');
     $modules = $this->getModules();
     /**
      * @var module_interface $row
      */
     foreach ($modules as $row) {
         if ($row->is_usable($user_id)) {
             $this->template->assign_block_vars('tfa_options', array_merge(array('ID' => $row->get_name(), 'NAME' => $this->user->lang($row->get_translatable_name()), 'U_SUBMIT_AUTH' => $this->controller_helper->route('paul999_tfa_read_controller_submit', array('user_id' => (int) $user_id, 'admin' => (int) $admin, 'auto_login' => (int) $auto_login, 'viewonline' => (int) $viewonline, 'class' => $row->get_name()))), $row->login_start($user_id)));
         }
     }
     add_form_key('tfa_login_page');
     $random = sha1(random_bytes(32));
     if (!empty($this->user->data['tfa_random'])) {
         throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG');
     }
     $sql_ary = array('tfa_random' => $random, 'tfa_uid' => $user_id);
     $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\tWHERE\n\t\t\t\tsession_id = '" . $this->db->sql_escape($this->user->data['session_id']) . "' AND\n\t\t\t\tsession_user_id = " . (int) $this->user->data['user_id'];
     $this->db->sql_query($sql);
     $this->template->assign_vars(array('REDIRECT' => $redirect, 'RANDOM' => $random));
     page_header('TFA_KEY_REQUIRED');
     $this->template->set_filenames(array('body' => '@paul999_tfa/authenticate_main.html'));
     page_footer(false);
     // Do not include cron on this page!
 }
Exemple #14
0
    /**
     * grabs the list of the active users participating in chat
     * 
     * @return boolean
     */
    private function whois_online()
    {
        $check_time = time() - $this->session_time;
        $sql_ary = ['username' => $this->user->data['username'], 'user_colour' => $this->user->data['user_colour'], 'user_lastupdate' => time()];
        $sql = 'UPDATE ' . CHAT_SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " WHERE user_id = {$this->user->data['user_id']}";
        $this->db->sql_query($sql);
        $sql = 'DELETE FROM ' . CHAT_SESSIONS_TABLE . " WHERE user_lastupdate < {$check_time}";
        $this->db->sql_query($sql);
        $sql = 'SELECT *
			FROM ' . CHAT_SESSIONS_TABLE . "\n\t\t\tWHERE user_lastupdate > {$check_time}\n\t\t\tORDER BY username ASC";
        $result = $this->db->sql_query($sql);
        $status_time = time();
        while ($row = $this->db->sql_fetchrow($result)) {
            if ($row['user_id'] == $this->user->data['user_id']) {
                $this->last_post = $row['user_lastpost'];
                $login_time = $row['user_login'];
                $status_time = $this->last_post > $login_time ? $this->last_post : $login_time;
            }
            $status = $this->get_status($row['user_lastpost']);
            if ($this->check_hidden($row['user_id']) === false) {
                continue;
            } else {
                $this->template->assign_block_vars('whoisrow', ['USERNAME_FULL' => $this->clean_username(get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST'])), 'USER_COLOR' => $row['user_colour'], 'USER_STATUS' => $status]);
            }
        }
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(['LAST_TIME' => time(), 'S_WHOISONLINE' => true]);
        return false;
    }
Exemple #15
0
    /**
     * Set own position on map
     *
     * @return type
     */
    public function position()
    {
        if ($this->user->data['user_id'] == ANONYMOUS || !$this->auth->acl_get('u_usermap_add')) {
            trigger_error('NOT_AUTHORISED');
        }
        $data = array('user_usermap_lon' => substr($this->request->variable('lon', ''), 0, 10), 'user_usermap_lat' => substr($this->request->variable('lat', ''), 0, 10));
        if (confirm_box(true)) {
            if (!function_exists('validate_data')) {
                include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
            }
            $error = validate_data($data, array('user_usermap_lon' => array('match', false, self::REGEX_LON), 'user_usermap_lat' => array('match', false, self::REGEX_LAT)));
            if (sizeof($error)) {
                $error = array_map(array($this->user, 'lang'), $error);
                trigger_error(implode('<br>', $error));
            }
            $sql = 'UPDATE ' . USERS_TABLE . '
				SET ' . $this->db->sql_build_array('UPDATE', $data) . '
				WHERE user_id = ' . (int) $this->user->data['user_id'];
            $this->db->sql_query($sql);
            trigger_error('POSITION_SET');
        } else {
            confirm_box(false, $this->user->lang('CONFIRM_COORDINATES_SET', $data['user_usermap_lon'], $data['user_usermap_lat']), build_hidden_fields(array('lon' => $data['user_usermap_lon'], 'lat' => $data['user_usermap_lat'])));
        }
        return $this->index();
    }
    /**
     * Submit auto group rule form data
     *
     * @param int $autogroups_id An auto group identifier
     *                           A value of 0 is new, otherwise we're updating
     * @return null
     * @access protected
     */
    protected function submit_autogroup_rule($autogroups_id = 0)
    {
        $data = array('autogroups_type_id' => $this->request->variable('autogroups_type_id', 0), 'autogroups_min_value' => $this->request->variable('autogroups_min_value', 0), 'autogroups_max_value' => $this->request->variable('autogroups_max_value', 0), 'autogroups_group_id' => $this->request->variable('autogroups_group_id', 0), 'autogroups_default' => $this->request->variable('autogroups_default', false), 'autogroups_notify' => $this->request->variable('autogroups_notify', false));
        // Prevent form submit when no user groups are available or selected
        if (!$data['autogroups_group_id']) {
            trigger_error($this->user->lang('ACP_AUTOGROUPS_INVALID_GROUPS') . adm_back_link($this->u_action), E_USER_WARNING);
        }
        // Prevent form submit when min and max values are identical
        if ($data['autogroups_min_value'] == $data['autogroups_max_value']) {
            trigger_error($this->user->lang('ACP_AUTOGROUPS_INVALID_RANGE') . adm_back_link($this->u_action), E_USER_WARNING);
        }
        if ($autogroups_id != 0) {
            $sql = 'UPDATE ' . $this->autogroups_rules_table . '
				SET ' . $this->db->sql_build_array('UPDATE', $data) . '
				WHERE autogroups_id = ' . (int) $autogroups_id;
            $this->db->sql_query($sql);
        } else {
            $sql = 'INSERT INTO ' . $this->autogroups_rules_table . ' ' . $this->db->sql_build_array('INSERT', $data);
            $this->db->sql_query($sql);
            $autogroups_id = $this->db->sql_nextid();
        }
        // Apply the auto group to all users
        $this->manager->sync_autogroups($autogroups_id);
        // Log the action
        $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_AUTOGROUPS_SAVED_LOG', time());
        // Output message to user after submitting the form
        trigger_error($this->user->lang('ACP_AUTOGROUPS_SUBMIT_SUCCESS') . adm_back_link($this->u_action));
    }
Exemple #17
0
    /**
     * Submit all attachments.
     *
     * @param int $access
     * @param array $comments
     */
    public function submit($access = access::PUBLIC_LEVEL, $comments = array())
    {
        if (!$this->get_count()) {
            return;
        }
        // Update access and is_orphan
        $sql_ary = array('object_id' => $this->object_id, 'attachment_access' => $access, 'is_orphan' => 0);
        $sql = 'UPDATE ' . $this->attachments_table . '
			SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
			WHERE ' . $this->db->sql_in_set('attachment_id', $this->get_all_ids());
        $this->db->sql_query($sql);
        foreach ($this->get_all() as $id => $attach) {
            $attach->__set_array($sql_ary);
            $update = array();
            if (isset($comments[$id]) && $this->get('attachment_comment') != $comments[$id]) {
                $update['attachment_comment'] = $comments[$id];
            }
            if (isset($this->custom_order[$id]) && $attach->get('attachment_order') != $this->custom_order[$id]) {
                $update['attachment_order'] = (int) $this->custom_order[$id];
            }
            if ($update) {
                $attach->submit($update);
            }
        }
    }
    public function test_rename()
    {
        global $table_prefix;
        // uses auth, so we set up the mock/stub
        // to allow reading first forum
        $this->auth->expects($this->once())->method('acl_getf')->with($this->equalTo('f_read'))->willReturn(array(1 => array('f_read' => true)));
        $sql_array = array('tag' => 'tag1');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(1, $count);
        $sql_array = array('tag' => 'newtagname');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(0, $count);
        $tag_id = 1;
        $new_name_clean = "newtagname";
        $assigned_count = $this->tags_manager->rename($tag_id, $new_name_clean);
        $this->assertEquals(1, $assigned_count);
        $sql_array = array('tag' => 'tag1');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(0, $count);
        $sql_array = array('tag' => 'newtagname');
        $result = $this->db->sql_query('SELECT COUNT(*) as count
			FROM ' . $table_prefix . tables::TAGS . '
			WHERE ' . $this->db->sql_build_array('SELECT', $sql_array));
        $count = $this->db->sql_fetchfield('count');
        $this->assertEquals(1, $count);
    }
    /**
     * Edit a flag
     *
     * @param int $flag_id The flag identifier to edit
     * @return null
     * @access public
     */
    public function edit_flag($flag_id)
    {
        // Add form key
        add_form_key('edit_flag');
        $errors = array();
        $flag_row = array('flag_name' => utf8_normalize_nfc($this->request->variable('flag_name', '', true)), 'flag_image' => $this->request->variable('flag_image', ''));
        if ($this->request->is_set_post('submit')) {
            $errors = $this->check_flag($flag_row['flag_image'], $flag_row['flag_name'], $errors, 'edit_flag');
            if (!sizeof($errors)) {
                $sql = 'UPDATE ' . $this->flags_table . '
					SET ' . $this->db->sql_build_array('UPDATE', $flag_row) . '
					WHERE flag_id = ' . (int) $flag_id;
                $this->db->sql_query($sql);
                $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_FLAG_EDIT', time(), array($flag_row['flag_name']));
                $this->cache->destroy('_user_flags');
                $this->functions->cache_flags();
                trigger_error($this->user->lang['MSG_FLAG_EDITED'] . adm_back_link($this->u_action));
            }
        }
        $sql = 'SELECT flag_id, flag_name, flag_image
			FROM ' . $this->flags_table . '
			WHERE flag_id =' . (int) $flag_id;
        $result = $this->db->sql_query($sql);
        $flag_row = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        if (!$flag_row) {
            trigger_error($this->user->lang['FLAG_ERROR_NOT_EXIST'] . adm_back_link($this->u_action . '&amp;mode=manage'), E_USER_WARNING);
        }
        $this->template->assign_vars(array('L_TITLE' => $this->user->lang['FLAG_EDIT'], 'U_ACTION' => $this->u_action . "&amp;flag_id={$flag_id}&amp;action=edit", 'U_BACK' => $this->u_action . '&amp;mode=manage', 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'FLAG_NAME' => $flag_row['flag_name'], 'FLAG_IMAGE' => $flag_row['flag_image'], 'FLAG_ID' => $flag_row['flag_id'], 'S_ADD_FLAG' => true, 'S_ERROR' => sizeof($errors) ? true : false));
    }
Exemple #20
0
	/**
	* Add a new permission role
	*
	* @param string $role_name The new role name
	* @param string $role_type The type (u_, m_, a_)
	* @param string $role_description Description of the new role
	*
	* @return null
	*/
	public function role_add($role_name, $role_type, $role_description = '')
	{
		$sql = 'SELECT role_id
			FROM ' . ACL_ROLES_TABLE . "
			WHERE role_name = '" . $this->db->sql_escape($role_name) . "'";
		$this->db->sql_query($sql);
		$role_id = (int) $this->db->sql_fetchfield('role_id');

		if ($role_id)
		{
			return;
		}

		$sql = 'SELECT MAX(role_order) AS max_role_order
			FROM ' . ACL_ROLES_TABLE . "
			WHERE role_type = '" . $this->db->sql_escape($role_type) . "'";
		$this->db->sql_query($sql);
		$role_order = (int) $this->db->sql_fetchfield('max_role_order');
		$role_order = (!$role_order) ? 1 : $role_order + 1;

		$sql_ary = array(
			'role_name'			=> $role_name,
			'role_description'	=> $role_description,
			'role_type'			=> $role_type,
			'role_order'		=> $role_order,
		);

		$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
		$this->db->sql_query($sql);
	}
Exemple #21
0
    /**
     * Get the notification type id from the name
     *
     * @param string $notification_type_name The name
     * @return int the notification_type_id
     * @throws \phpbb\notification\exception
     */
    public function get_notification_type_id($notification_type_name)
    {
        $notification_type_ids = $this->cache->get('notification_type_ids');
        $this->db->sql_transaction('begin');
        if ($notification_type_ids === false) {
            $notification_type_ids = array();
            $sql = 'SELECT notification_type_id, notification_type_name
				FROM ' . $this->notification_types_table;
            $result = $this->db->sql_query($sql);
            while ($row = $this->db->sql_fetchrow($result)) {
                $notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id'];
            }
            $this->db->sql_freeresult($result);
            $this->cache->put('notification_type_ids', $notification_type_ids);
        }
        if (!isset($notification_type_ids[$notification_type_name])) {
            if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name])) {
                throw new \phpbb\notification\exception('NOTIFICATION_TYPE_NOT_EXIST', array($notification_type_name));
            }
            $sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array('notification_type_name' => $notification_type_name, 'notification_type_enabled' => 1));
            $this->db->sql_query($sql);
            $notification_type_ids[$notification_type_name] = (int) $this->db->sql_nextid();
            $this->cache->put('notification_type_ids', $notification_type_ids);
        }
        $this->db->sql_transaction('commit');
        return $notification_type_ids[$notification_type_name];
    }
Exemple #22
0
	/**
	* 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;
	}
Exemple #23
0
    /**
     * Update link data (note, vote, comment)
     *
     * @param	int	$start
     * @param	int	$stop
     * @return	null
     */
    private function _sync_dir_links($start, $stop)
    {
        $sql_ary = array('link_comment' => 0, 'link_note' => 0, 'link_vote' => 0);
        $sql = 'UPDATE ' . DIR_LINK_TABLE . '
			SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
			WHERE link_id BETWEEN ' . (int) $start . ' AND ' . (int) $stop;
        $this->db->sql_query($sql);
        $sql = 'SELECT vote_link_id, COUNT(vote_note) AS nb_vote, SUM(vote_note) AS total FROM ' . DIR_VOTE_TABLE . '
			WHERE vote_link_id BETWEEN ' . (int) $start . ' AND ' . (int) $stop . '
			GROUP BY vote_link_id';
        $result = $this->db->sql_query($sql);
        while ($tmp = $this->db->sql_fetchrow($result)) {
            $sql = 'UPDATE ' . DIR_LINK_TABLE . '
				SET link_note = ' . (int) $tmp['total'] . ', link_vote = ' . (int) $tmp['nb_vote'] . '
				WHERE link_id = ' . (int) $tmp['vote_link_id'];
            $this->db->sql_query($sql);
        }
        $this->db->sql_freeresult($result);
        $sql = 'SELECT 	comment_link_id, COUNT(comment_id) AS nb_comment
			FROM ' . DIR_COMMENT_TABLE . '
			WHERE comment_link_id BETWEEN ' . (int) $start . ' AND ' . (int) $stop . '
			GROUP BY comment_link_id';
        $result = $this->db->sql_query($sql);
        while ($tmp = $this->db->sql_fetchrow($result)) {
            $sql = 'UPDATE ' . DIR_LINK_TABLE . '
				SET link_comment = ' . (int) $tmp['nb_comment'] . '
				WHERE link_id = ' . (int) $tmp['comment_link_id'];
            $this->db->sql_query($sql);
        }
        $this->db->sql_freeresult($result);
    }
Exemple #24
0
    /**
     * {@inheritdoc}
     */
    public function get_auth_link_data($user_id = 0)
    {
        $block_vars = array();
        // Get all external accounts tied to the current user
        $data = array('user_id' => $user_id <= 0 ? (int) $this->user->data['user_id'] : (int) $user_id);
        $sql = 'SELECT oauth_provider_id, provider FROM ' . $this->auth_provider_oauth_token_account_assoc . '
			WHERE ' . $this->db->sql_build_array('SELECT', $data);
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        $oauth_user_ids = array();
        if ($rows !== false && sizeof($rows)) {
            foreach ($rows as $row) {
                $oauth_user_ids[$row['provider']] = $row['oauth_provider_id'];
            }
        }
        unset($rows);
        foreach ($this->service_providers as $service_name => $service_provider) {
            // Only include data if the credentials are set
            $credentials = $service_provider->get_service_credentials();
            if ($credentials['key'] && $credentials['secret']) {
                $actual_name = str_replace('auth.provider.oauth.service.', '', $service_name);
                $block_vars[$service_name] = array('HIDDEN_FIELDS' => array('link' => !isset($oauth_user_ids[$actual_name]), 'oauth_service' => $actual_name), 'SERVICE_NAME' => $this->user->lang['AUTH_PROVIDER_OAUTH_SERVICE_' . strtoupper($actual_name)], 'UNIQUE_ID' => isset($oauth_user_ids[$actual_name]) ? $oauth_user_ids[$actual_name] : null);
            }
        }
        return array('BLOCK_VAR_NAME' => 'oauth', 'BLOCK_VARS' => $block_vars, 'TEMPLATE_FILE' => 'ucp_auth_link_oauth.html');
    }
Exemple #25
0
 public function posting_modify_submit_post_after($event)
 {
     // only trigger if mode is post
     $mchat_forums_allowed = array();
     if ($event['mode'] == 'post' || $event['mode'] == 'reply' || $event['mode'] == 'quote' || $event['mode'] == 'edit' && (isset($this->config['mchat_enable']) && $this->config['mchat_enable']) && (isset($this->config['mchat_new_posts']) && $this->config['mchat_new_posts'])) {
         if ($event['mode'] == 'post' && (isset($this->config['mchat_new_posts_topic']) && $this->config['mchat_new_posts_topic'])) {
             $mchat_new_data = $this->user->lang['MCHAT_NEW_TOPIC'];
         } else {
             if ($event['mode'] == 'quote' && (isset($this->config['mchat_new_posts_quote']) && $this->config['mchat_new_posts_quote'])) {
                 $mchat_new_data = $this->user->lang['MCHAT_NEW_QUOTE'];
             } else {
                 if ($event['mode'] == 'edit' && (isset($this->config['mchat_new_posts_edit']) && $this->config['mchat_new_posts_edit'])) {
                     $mchat_new_data = $this->user->lang['MCHAT_NEW_EDIT'];
                 } else {
                     if ($event['mode'] == 'reply' && (isset($this->config['mchat_new_posts_reply']) && $this->config['mchat_new_posts_reply'])) {
                         $mchat_new_data = $this->user->lang['MCHAT_NEW_REPLY'];
                     } else {
                         return;
                     }
                 }
             }
         }
         // Data...
         $message = utf8_normalize_nfc($mchat_new_data . ': [url=' . generate_board_url() . '/viewtopic.' . $this->phpEx . '?p=' . $event['data']['post_id'] . '#p' . $event['data']['post_id'] . ']' . $event['post_data']['post_subject'] . '[/url] ' . $this->user->lang['MCHAT_IN'] . ' [url=' . generate_board_url() . '/viewforum.' . $this->phpEx . '?f=' . $event['forum_id'] . ']' . $event['post_data']['forum_name'] . ' [/url] ' . $this->user->lang['MCHAT_IN_SECTION']);
         $uid = $bitfield = $options = '';
         // will be modified by generate_text_for_storage
         generate_text_for_storage($message, $uid, $bitfield, $options, true, false, false);
         $sql_ary = array('forum_id' => $event['forum_id'], 'post_id' => $event['post_id'], 'user_id' => $this->user->data['user_id'], 'user_ip' => $this->user->data['session_ip'], 'message' => $message, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'bbcode_options' => $options, 'message_time' => time());
         $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
         $this->db->sql_query($sql);
     }
 }
 public function insert_thanks($post_id, $user_id, $forum_id)
 {
     // $this->user->add_lang_ext('gfksx/ThanksForPosts', 'thanks_mod');
     $to_id = $this->request->variable('to_id', 0);
     $from_id = $this->request->variable('from_id', 0);
     $row = $this->get_post_info($post_id);
     if ($this->user->data['user_type'] != USER_IGNORE && !empty($to_id)) {
         if ($row['poster_id'] != $user_id && $row['poster_id'] == $to_id && !$this->already_thanked($post_id, $user_id) && ($this->auth->acl_get('f_thanks', $row['forum_id']) || !$row['forum_id'] && (isset($this->config['thanks_global_post']) ? $this->config['thanks_global_post'] : false)) && $from_id == $user_id) {
             $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' => (int) $row['forum_id'], 'thanks_time' => time());
             $sql = 'INSERT INTO ' . $this->thanks_table . ' ' . $this->db->sql_build_array('INSERT', $thanks_data);
             $this->db->sql_query($sql);
             $lang_act = 'GIVE';
             $thanks_data = array_merge($thanks_data, array('username' => $this->user->data['username'], 'lang_act' => $lang_act, 'post_subject' => $row['post_subject']));
             $this->add_notification($thanks_data);
             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 . '&amp;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 . '&amp;p=' . $post_id . '#p' . $post_id) . '">', '</a>'));
             } else {
                 redirect(append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $forum_id . '&amp;p=' . $post_id . '#p' . $post_id));
             }
         } else {
             if (!$row['forum_id'] && (isset($this->config['thanks_global_post']) ? !$this->config['thanks_global_post'] : true)) {
                 trigger_error($this->user->lang['GLOBAL_INCORRECT_THANKS'] . '<br /><br />' . $this->user->lang('RETURN_POST', '<a href="' . append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $forum_id . '&amp;p=' . $post_id . '#p' . $post_id) . '">', '</a>'));
             } 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 . '&amp;p=' . $post_id . '#p' . $post_id) . '">', '</a>'));
             }
         }
     }
     return;
 }
Exemple #27
0
    /**
     * Installs BBCodes, used by migrations to perform add/updates
     *
     * @param array $bbcode_data Array of BBCode data to install
     * @return null
     * @access public
     */
    public function install_bbcodes($bbcode_data)
    {
        // Load the acp_bbcode class
        if (!class_exists('acp_bbcodes')) {
            include $this->phpbb_root_path . 'includes/acp/acp_bbcodes.' . $this->php_ext;
        }
        $bbcode_tool = new \acp_bbcodes();
        foreach ($bbcode_data as $bbcode_name => $bbcode_array) {
            // Build the BBCodes
            $data = $bbcode_tool->build_regexp($bbcode_array['bbcode_match'], $bbcode_array['bbcode_tpl']);
            $bbcode_array += array('bbcode_tag' => $data['bbcode_tag'], 'first_pass_match' => $data['first_pass_match'], 'first_pass_replace' => $data['first_pass_replace'], 'second_pass_match' => $data['second_pass_match'], 'second_pass_replace' => $data['second_pass_replace']);
            $sql = 'SELECT bbcode_id
				FROM ' . BBCODES_TABLE . "\n\t\t\t\tWHERE LOWER(bbcode_tag) = '" . strtolower($bbcode_name) . "'\n\t\t\t\tOR LOWER(bbcode_tag) = '" . strtolower($bbcode_array['bbcode_tag']) . "'";
            $result = $this->db->sql_query($sql);
            $row_exists = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            if ($row_exists) {
                // Update existing BBCode
                $bbcode_id = $row_exists['bbcode_id'];
                $sql = 'UPDATE ' . BBCODES_TABLE . '
					SET ' . $this->db->sql_build_array('UPDATE', $bbcode_array) . '
					WHERE bbcode_id = ' . $bbcode_id;
                $this->db->sql_query($sql);
            } else {
                // Create new BBCode
                $sql = 'SELECT MAX(bbcode_id) AS max_bbcode_id
					FROM ' . BBCODES_TABLE;
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                if ($row) {
                    $bbcode_id = $row['max_bbcode_id'] + 1;
                    // Make sure it is greater than the core BBCode ids...
                    if ($bbcode_id <= NUM_CORE_BBCODES) {
                        $bbcode_id = NUM_CORE_BBCODES + 1;
                    }
                } else {
                    $bbcode_id = NUM_CORE_BBCODES + 1;
                }
                if ($bbcode_id <= BBCODE_LIMIT) {
                    $bbcode_array['bbcode_id'] = (int) $bbcode_id;
                    $bbcode_array['display_on_posting'] = 0;
                    $this->db->sql_query('INSERT INTO ' . BBCODES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $bbcode_array));
                }
            }
        }
    }
Exemple #28
0
 /**
  * Add new condition type
  *
  * @param string $autogroups_type_name The name of the auto group type
  *
  * @return int The identifier of the new condition type
  * @access public
  */
 public function add_autogroups_type($autogroups_type_name)
 {
     // Insert the type name into the database
     $sql = 'INSERT INTO ' . $this->autogroups_types_table . ' ' . $this->db->sql_build_array('INSERT', array('autogroups_type_name' => (string) $autogroups_type_name));
     $this->db->sql_query($sql);
     // Return the id of the newly inserted condition type
     return (int) $this->db->sql_nextid();
 }
Exemple #29
0
 /**
  * Получение данных о пользователе
  * @param $u_id
  * @return mixed
  */
 public function updateUserData($u_id, $data)
 {
     $sql = "UPDATE " . USERS_TABLE . "\n\t\t\tSET " . $this->db->sql_build_array("UPDATE", $data) . "\n\t\t\tWHERE user_id = '" . $u_id . "'";
     $result = $this->db->sql_query($sql);
     $row = $this->db->sql_fetchrow($result);
     $this->db->sql_freeresult();
     return $row;
 }
    function add_points_to_table($post_id, $points, $mode, $attachments, $poll)
    {
        $sql_ary = array('points_' . $mode . '_received' => $points, 'points_attachment_received' => $attachments, 'points_poll_received' => $poll, 'points_received' => $points);
        $sql = 'UPDATE ' . POSTS_TABLE . '
				SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
				WHERE post_id = ' . (int) $post_id;
        $this->db->sql_query($sql);
    }