/** * Delete user * * This function deletes the needed stuff when a user is deleted */ function blog_delete_user($user_id) { global $config, $db, $phpbb_root_path, $phpEx; $user_id = (int) $user_id; include "{$phpbb_root_path}blog/includes/constants.{$phpEx}"; if (!function_exists('setup_blog_search')) { include "{$phpbb_root_path}blog/includes/functions.{$phpEx}"; } if (!function_exists('put_blogs_in_cats')) { include "{$phpbb_root_path}blog/includes/functions_categories.{$phpEx}"; } $blog_search = setup_blog_search(); $num_blogs = $num_blog_replies = 0; $result = $db->sql_query('SELECT * FROM ' . BLOGS_TABLE . ' WHERE user_id = ' . $user_id); while ($row = $db->sql_fetchrow($result)) { $num_blogs++; $num_blog_replies += $row['blog_real_reply_count']; $blog_search->index_remove($row['blog_id']); put_blogs_in_cats($row['blog_id'], array(), true, 'soft_delete'); // Delete the Attachments $rids = array(); $sql = 'SELECT reply_id FROM ' . BLOGS_REPLY_TABLE . ' WHERE blog_id = ' . $row['blog_id']; $result1 = $db->sql_query($sql); while ($row1 = $db->sql_fetchrow($result1)) { $rids[] = $row1['reply_id']; } $db->sql_freeresult($result1); if (sizeof($rids)) { $sql = 'SELECT physical_filename FROM ' . BLOGS_ATTACHMENT_TABLE . ' WHERE blog_id = ' . $row['blog_id'] . ' OR ' . $db->sql_in_set('reply_id', $rids); } else { $sql = 'SELECT physical_filename FROM ' . BLOGS_ATTACHMENT_TABLE . ' WHERE blog_id = ' . $row['blog_id']; } $result1 = $db->sql_query($sql); while ($row1 = $db->sql_fetchrow($result1)) { @unlink($phpbb_root_path . $config['upload_path'] . '/blog_mod/' . $row1['physical_filename']); } $db->sql_freeresult($result1); if (sizeof($rids)) { $db->sql_query('DELETE FROM ' . BLOGS_ATTACHMENT_TABLE . ' WHERE blog_id = ' . $row['blog_id'] . ' OR ' . $db->sql_in_set('reply_id', $rids)); } else { $db->sql_query('DELETE FROM ' . BLOGS_ATTACHMENT_TABLE . ' WHERE blog_id = ' . $row['blog_id']); } // delete the blog $db->sql_query('DELETE FROM ' . BLOGS_TABLE . ' WHERE blog_id = ' . $row['blog_id']); // delete the replies $db->sql_query('DELETE FROM ' . BLOGS_REPLY_TABLE . ' WHERE blog_id = ' . $row['blog_id']); // delete from the blogs_in_categories $db->sql_query('DELETE FROM ' . BLOGS_IN_CATEGORIES_TABLE . ' WHERE blog_id = ' . $row['blog_id']); // delete from the blogs_ratings $db->sql_query('DELETE FROM ' . BLOGS_RATINGS_TABLE . ' WHERE blog_id = ' . $row['blog_id']); // Delete the subscriptions $db->sql_query('DELETE FROM ' . BLOGS_SUBSCRIPTION_TABLE . ' WHERE blog_id = ' . $row['blog_id']); // Delete the Polls $db->sql_query('DELETE FROM ' . BLOGS_POLL_OPTIONS_TABLE . ' WHERE blog_id = ' . $row['blog_id']); $db->sql_query('DELETE FROM ' . BLOGS_POLL_VOTES_TABLE . ' WHERE blog_id = ' . $row['blog_id']); } $db->sql_freeresult($result); $result = $db->sql_query('SELECT * FROM ' . BLOGS_REPLY_TABLE . ' WHERE user_id = ' . $user_id); while ($row = $db->sql_fetchrow($result)) { $num_blog_replies++; $blog_search->index_remove(false, $row['reply_id']); // Delete the Attachments $sql = 'SELECT physical_filename FROM ' . BLOGS_ATTACHMENT_TABLE . ' WHERE reply_id = ' . $row['reply_id']; $result1 = $db->sql_query($sql); while ($row1 = $db->sql_fetchrow($result1)) { @unlink($phpbb_root_path . $config['upload_path'] . '/blog_mod/' . $row1['physical_filename']); } $db->sql_freeresult($result1); $db->sql_query('DELETE FROM ' . BLOGS_ATTACHMENT_TABLE . ' WHERE reply_id = ' . $row['reply_id']); // delete the reply $db->sql_query('DELETE FROM ' . BLOGS_REPLY_TABLE . ' WHERE reply_id = ' . $row['reply_id']); } $db->sql_freeresult($result); $sql = 'UPDATE ' . USERS_TABLE . ' SET blog_count = 0 WHERE user_id = ' . $user_id; $db->sql_query($sql); // Resync reply counts resync_blog('reply_count'); resync_blog('real_reply_count'); set_config('num_blogs', $config['num_blogs'] - $num_blogs, true); set_config('num_blog_replies', $config['num_blog_replies'] - $num_blog_replies, true); }
/** * Reindex the blogs/replies */ function reindex($mode = '') { global $db, $user, $phpbb_root_path, $phpEx; global $part, $part_cnt, $section, $section_cnt; $section_cnt = 1; $blog_search = setup_blog_search(); if ($mode == 'delete') { $blog_search->delete_index(); } else { if ($section == 0) { $sql = 'SELECT * FROM ' . BLOGS_TABLE . ' WHERE blog_deleted = 0 AND blog_approved = 1 ORDER BY blog_id DESC'; $result = $db->sql_query_limit($sql, $this->selected_options['limit'], $part * $this->selected_options['limit']); while ($row = $db->sql_fetchrow($result)) { $blog_search->index('add', $row['blog_id'], 0, $row['blog_text'], $row['blog_subject'], $row['user_id']); } $sql = 'SELECT count(blog_id) AS cnt FROM ' . BLOGS_TABLE . ' WHERE blog_deleted = 0 AND blog_approved = 1'; $result = $db->sql_query($sql); $cnt = $db->sql_fetchrow($result); if ($cnt['cnt'] >= ($part + 1) * $this->selected_options['limit']) { $part++; $part_cnt = ceil($cnt['cnt'] / $this->selected_options['limit']); } else { $part = 0; $section++; } } else { $sql = 'SELECT * FROM ' . BLOGS_REPLY_TABLE . ' WHERE reply_deleted = 0 AND reply_approved = 1 ORDER BY reply_id DESC'; $result = $db->sql_query_limit($sql, $this->selected_options['limit'], $part * $this->selected_options['limit']); while ($row = $db->sql_fetchrow($result)) { $blog_search->index('add', $row['blog_id'], $row['reply_id'], $row['reply_text'], $row['reply_subject'], $row['user_id']); } $sql = 'SELECT count(reply_id) AS cnt FROM ' . BLOGS_REPLY_TABLE . ' WHERE reply_deleted = 0 AND reply_approved = 1'; $result = $db->sql_query($sql); $cnt = $db->sql_fetchrow($result); if ($cnt['cnt'] >= ($part + 1) * $this->selected_options['limit']) { $part++; $part_cnt = ceil($cnt['cnt'] / $this->selected_options['limit']); } else { $part = 0; $section++; } } } }
$template->assign_var('S_NO_SEARCH', true); trigger_error('NO_SEARCH'); } // Check search load limit if ($user->load && $config['limit_search_load'] && $user->load > doubleval($config['limit_search_load'])) { $template->assign_var('S_NO_SEARCH', true); trigger_error('NO_SEARCH_TIME'); } $keywords = request_var('keywords', '', true); $author = request_var('author', '', true); $terms = request_var('terms', 'all'); $sf = request_var('sf', ''); $search_url = blog_url(false, false, false, array('page' => 'search', 'author' => $author, 'keywords' => $keywords, 'terms' => $terms, 'sf' => $sf), array(), true); blog_plugins::plugin_do('search'); if ($keywords && $keywords != $user->lang['SEARCH_MINI'] || $author) { $blog_search = setup_blog_search(); $blog_ids = $reply_ids = array(); $highlight_match = $highlight = ''; $matches = array('(', ')', '|', '+', '-'); $highlight_words = str_replace($matches, ' ', $keywords); foreach (explode(' ', trim($highlight_words)) as $word) { if (trim($word)) { $highlight_match .= ($highlight_match != '' ? '|' : '') . str_replace('*', '\\w*?', preg_quote($word, '#')); } } $highlight = urlencode($highlight_words); if ($author && $keywords) { $uid = $blog_data->get_id_by_username($author); $blog_search->split_keywords($keywords, $terms); $ids = $blog_search->keyword_search($sf, $terms, 0); } else {
function ubm_custom_install($action, $version) { global $db, $user, $umil, $phpbb_root_path, $phpEx; switch ($version) { case '0.9.0': switch ($action) { case 'install': $umil->umil_start('INSTALLING_ARCHIVE_PLUGIN'); $sql_ary = array('plugin_name' => 'archive', 'plugin_enabled' => 1, 'plugin_version' => '1.0.0'); $sql = 'INSERT INTO ' . BLOGS_PLUGINS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $umil->umil_end(); $umil->umil_start('SETTING_DEFAULT_PERMISSIONS'); $role_data = array('ROLE_ADMIN_FULL' => array('a_blogmanage', 'a_blogdelete', 'a_blogreplydelete'), 'ROLE_MOD_FULL' => array('m_blogapprove', 'm_blogedit', 'm_bloglockedit', 'm_blogdelete', 'm_blogreport', 'm_blogreplyapprove', 'm_blogreplyedit', 'm_blogreplylockedit', 'm_blogreplydelete', 'm_blogreplyreport'), 'ROLE_MOD_STANDARD' => array('m_blogapprove', 'm_blogedit', 'm_bloglockedit', 'm_blogdelete', 'm_blogreport', 'm_blogreplyapprove', 'm_blogreplyedit', 'm_blogreplylockedit', 'm_blogreplydelete', 'm_blogreplyreport'), 'ROLE_MOD_QUEUE' => array('m_blogapprove', 'm_blogedit', 'm_bloglockedit', 'm_blogreplyapprove', 'm_blogreplyedit', 'm_blogreplylockedit'), 'ROLE_MOD_SIMPLE' => array('m_blogedit', 'm_bloglockedit', 'm_blogdelete', 'm_blogreplyedit', 'm_blogreplylockedit', 'm_blogreplydelete'), 'ROLE_USER_FULL' => array('u_blog_css', 'u_blog_style', 'u_blog_vote', 'u_blog_vote_change', 'u_blog_create_poll', 'u_blogattach', 'u_blognolimitattach', 'u_blogview', 'u_blogpost', 'u_blogedit', 'u_blogdelete', 'u_blognoapprove', 'u_blogreport', 'u_blogreply', 'u_blogreplyedit', 'u_blogreplydelete', 'u_blogreplynoapprove', 'u_blogbbcode', 'u_blogsmilies', 'u_blogimg', 'u_blogurl', 'u_blogflash', 'u_blogmoderate'), 'ROLE_USER_STANDARD' => array('u_blog_style', 'u_blog_vote', 'u_blog_vote_change', 'u_blog_create_poll', 'u_blogattach', 'u_blogview', 'u_blogpost', 'u_blogedit', 'u_blogdelete', 'u_blognoapprove', 'u_blogreport', 'u_blogreply', 'u_blogreplyedit', 'u_blogreplydelete', 'u_blogreplynoapprove', 'u_blogbbcode', 'u_blogsmilies', 'u_blogimg', 'u_blogurl', 'u_blogmoderate'), 'ROLE_USER_LIMITED' => array('u_blog_vote', 'u_blog_vote_change', 'u_blogview', 'u_blogpost', 'u_blogedit', 'u_blogreport', 'u_blogreply', 'u_blogreplyedit', 'u_blogbbcode', 'u_blogsmilies', 'u_blogimg', 'u_blogurl'), 'ROLE_USER_NOPM' => array('u_blog_style', 'u_blog_vote', 'u_blog_vote_change', 'u_blogview', 'u_blogpost', 'u_blogedit', 'u_blogreport', 'u_blogreply', 'u_blogreplyedit', 'u_blogbbcode', 'u_blogsmilies', 'u_blogimg', 'u_blogurl'), 'ROLE_USER_NOAVATAR' => array('u_blog_style', 'u_blog_vote', 'u_blog_vote_change', 'u_blogview', 'u_blogpost', 'u_blogedit', 'u_blogreport', 'u_blogreply', 'u_blogreplyedit', 'u_blogbbcode', 'u_blogsmilies', 'u_blogimg', 'u_blogurl')); foreach ($role_data as $role => $options) { $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '{$role}'"; $db->sql_query($sql); $role_id = $db->sql_fetchfield('role_id'); if ($role_id) { $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' WHERE ' . $db->sql_in_set('auth_option', $options); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $sql_ary = array('role_id' => $role_id, 'auth_option_id' => $row['auth_option_id'], 'auth_setting' => 1); $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); } } $role_id = false; } $umil->umil_end(); $umil->umil_start('ADDING_FIRST_BLOG'); if (!class_exists('bbcode_firstpass')) { include $phpbb_root_path . 'includes/message_parser.' . $phpEx; } $message_parser = new parse_message(); $blog_search = setup_blog_search(); $message_parser->message = $user->lang['WELCOME_MESSAGE']; $message_parser->parse(true, true, true); $sql_data = array('user_id' => $user->data['user_id'], 'user_ip' => $user->data['user_ip'], 'blog_time' => time(), 'blog_subject' => $user->lang['WELCOME_SUBJECT'], 'blog_text' => $message_parser->message, 'blog_checksum' => md5($message_parser->message), 'blog_approved' => 1, 'enable_bbcode' => 1, 'enable_smilies' => 1, 'enable_magic_url' => 1, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'blog_edit_reason' => '', 'poll_title' => ''); $sql = 'INSERT INTO ' . BLOGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data); $db->sql_query($sql); $blog_id = $db->sql_nextid(); $blog_search->index('add', $blog_id, 0, $message_parser->message, $user->lang['WELCOME_SUBJECT'], $user->data['user_id']); $sql = 'UPDATE ' . USERS_TABLE . ' SET blog_count = blog_count + 1 WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); $umil->umil_end(); break; } break; case '1.0.2': if ($action == 'update') { $umil->umil_start('FIXING_MAX_POLL_OPTIONS'); $db->sql_query('UPDATE ' . BLOGS_TABLE . ' SET poll_max_options = 1 WHERE poll_max_options < 1'); $umil->umil_end(); } break; case '1.0.4': if ($action == 'update') { $umil->umil_start('FIXING_MISSING_STYLES'); $style_ids = array(); $result = $db->sql_query('SELECT style_id FROM ' . STYLES_TABLE); while ($row = $db->sql_fetchrow($result)) { $style_ids[] = $row['style_id']; } $db->sql_freeresult($result); $db->sql_query('UPDATE ' . BLOGS_USERS_TABLE . ' SET blog_style = ' . $style_ids[0] . ' WHERE ' . $db->sql_in_set('blog_style', $style_ids, true)); $umil->umil_end(); } break; } }