/** * Set param value * * By default, all values will be considered strings * * @param string parameter name * @param mixed parameter value * @param boolean true to set to NULL if empty value * @return boolean true, if a value has been set; false if it has not changed */ function set($parname, $parvalue, $make_null = false) { switch ($parname) { case 'params': return $this->set_param('params', 'string', serialize($parvalue), false); case 'name': return $this->set_param($parname, 'string', evo_substr($parvalue, 0, 255), false); } return $this->set_param($parname, 'string', $parvalue, $make_null); }
/** * Import users from phpbb into b2evo */ function phpbb_import_users() { global $DB, $phpbb_DB, $tableprefix; if (!phpbb_check_step('users')) { // Check current step return; // Exit here if we cannot process this step } phpbb_unset_var('users_count_imported'); phpbb_unset_var('users_count_updated'); phpbb_log(T_('Importing users...')); /** * @var array IDs of the Users; * Key is ID from phpBB * Value is new inserted ID from b2evo */ $users_IDs = array(); // Get ranks that will be imported ( array( phpbb_rank_ID => b2evo_group_ID ) ) $phpbb_ranks = phpbb_get_var('ranks'); // Remove ranks that will not be imported if (count($phpbb_ranks) > 0) { foreach ($phpbb_ranks as $rank_ID => $b2evo_group_ID) { if (empty($b2evo_group_ID)) { // Unset this rank, because it selected as no import unset($phpbb_ranks[$rank_ID]); } } } $phpbb_users_sql_where_ranks = ''; if (count($phpbb_ranks) > 0) { // Limit users by the selected ranks $phpbb_users_sql_where_ranks = ' OR u.user_rank IN ( ' . $phpbb_DB->quote(array_keys($phpbb_ranks)) . ' )'; } $DB->begin(); // Init SQL to get the users data and the count of the users $phpbb_users_SQL = new SQL(); $phpbb_users_SQL->FROM('BB_users u'); $phpbb_users_SQL->FROM_add('INNER JOIN BB_posts p ON p.poster_id = u.user_id'); // Get users which have at least one post $phpbb_users_SQL->WHERE('( u.user_rank IS NULL OR u.user_rank = 0' . $phpbb_users_sql_where_ranks . ' )'); $phpbb_users_SQL->ORDER_BY('u.user_id'); // Get the count of the topics $count_SQL = $phpbb_users_SQL; $count_SQL->SELECT('COUNT( DISTINCT u.user_id )'); $phpbb_users_count = $phpbb_DB->get_var($count_SQL->get()); if ($phpbb_users_count > 0) { phpbb_log(sprintf(T_('%s users have been found in the phpBB database'), $phpbb_users_count)); } else { // No users phpbb_log(T_('No users found in the phpBB database.'), 'error'); $DB->commit(); return; // Exit here } // Get the duplicated emails $emails_SQL = new SQL(); $emails_SQL->SELECT('user_email, ""'); $emails_SQL->FROM('BB_users'); $emails_SQL->GROUP_BY('user_email'); $emails_SQL->HAVING('COUNT( user_id ) > 1'); $phpbb_emails_duplicated = $phpbb_DB->get_assoc($emails_SQL->get()); phpbb_log(T_('Start importing <b>users</b> into the b2evolution database...'), 'message', ''); // Init SQL to get the users $users_SQL = $phpbb_users_SQL; $users_SQL->SELECT('u.user_id, u.user_active, u.username, u.user_password, u.user_email, u.user_lang, u.user_level, u.user_regdate, u.user_icq, u.user_website, u.user_aim, u.user_yim, u.user_msnm, u.user_interests, u.user_rank, u.user_allow_viewonline, u.user_notify_pm, u.user_avatar'); $users_SQL->GROUP_BY('u.user_id'); // Get all users IPs in one sql query $users_ips_SQL = new SQL(); $users_ips_SQL->SELECT('user_id, last_ip'); $users_ips_SQL->FROM('BB_sessions_keys'); $users_ips_SQL->ORDER_BY('last_login DESC'); $users_ips = $phpbb_DB->get_assoc($users_ips_SQL->get()); // Prepare to import avatars $do_import_avatars = false; $path_avatars = phpbb_get_var('path_avatars'); if (!empty($path_avatars)) { $path_avatars = preg_replace('/(\\/|\\\\)$/i', '', $path_avatars) . '/'; if (!empty($path_avatars) && file_exists($path_avatars) && is_dir($path_avatars)) { // Folder with avatars is correct, we can import avatars $do_import_avatars = true; } } $page = 0; $page_size = 1000; $phpbb_users_count_imported = 0; $phpbb_users_count_updated = 0; do { // Split by page to optimize process // It gives to save the memory rather than if we get all users by one query without LIMIT clause // Get the users $users_SQL->LIMIT($page * $page_size . ', ' . $page_size); $phpbb_users = $phpbb_DB->get_results($users_SQL->get()); $phpbb_users_count = count($phpbb_users); // Insert the new users foreach ($phpbb_users as $p => $phpbb_user) { if ($p % 100 == 0) { // Display the processing dots after 100 users phpbb_log(' .', 'message', ''); } if ($phpbb_user->user_id < 1) { // Skip the users with invalid ID phpbb_log(sprintf(T_('User "%s" with ID %s ignored'), $phpbb_user->username, $phpbb_user->user_id), 'error', ' ', '<br />'); continue; } if ($phpbb_user->username == '₯είίε') { // Special rule for this username $user_login = '******'; } else { // Replace unauthorized chars from username $user_login = preg_replace('/([^a-z0-9_])/i', '_', $phpbb_user->username); $user_login = evo_substr(evo_strtolower($user_login), 0, 20); } $user_has_duplicated_email = false; if (isset($phpbb_emails_duplicated[$phpbb_user->user_email])) { // The user has the duplicate email if (!empty($phpbb_emails_duplicated[$phpbb_user->user_email])) { // The other user already was imported with such email phpbb_log('<br />' . sprintf(T_('The phbBB users "%s" and "%s" have the same email address "%s" and will be merged in b2evolution as just "%s"'), $phpbb_emails_duplicated[$phpbb_user->user_email]['username'], $user_login, $phpbb_user->user_email, $phpbb_emails_duplicated[$phpbb_user->user_email]['username']), 'error', ' '); // Set link between current phpBB user ID and b2evo user ID of first user with this duplicated email address // This link will be used to merge the topics, comments and messages from all phpBB users with the same email address for ONE b2evo user $users_IDs[$phpbb_user->user_id] = $users_IDs[$phpbb_emails_duplicated[$phpbb_user->user_email]['user_ID']]; // Don't import this user unset($phpbb_users[$p]); continue; } $phpbb_emails_duplicated[$phpbb_user->user_email] = array('username' => $user_login, 'user_ID' => $phpbb_user->user_id); $user_has_duplicated_email = true; } // Check if this user already exists with same email address in b2evo DB $SQL = new SQL(); $SQL->SELECT('user_ID, user_login'); $SQL->FROM('T_users'); $SQL->WHERE('user_email = ' . $DB->quote($phpbb_user->user_email)); $b2evo_user = $DB->get_row($SQL->get()); if (!empty($b2evo_user)) { // User already exists in DB of b2evo // Don't insert this user // Update the link between IDs of this user from two databases $users_IDs[$phpbb_user->user_id] = $b2evo_user->user_ID; unset($phpbb_users[$p]); // Unset already existing user from this array to exclude the updating of the fields and settings $phpbb_users_count_updated++; if ($do_import_avatars) { // Import user's avatar phpbb_import_avatar($b2evo_user->user_ID, $path_avatars, $phpbb_user->user_avatar); } phpbb_log(sprintf(T_('The user #%s already exists with E-mail address "%s" in the b2evolution database -- Merging User "%s" with user "%s".'), $phpbb_user->user_id, $phpbb_user->user_email, $user_login, $b2evo_user->user_login), 'warning', ' ', '<br />'); continue; } // Check if this user already exists with same login in b2evo DB $user_login_number = 0; $next_login = $user_login; do { $SQL = new SQL(); $SQL->SELECT('user_ID'); $SQL->FROM('T_users'); $SQL->WHERE('user_login = '******'The login "%s" already exists with a different email address. The user "%s" will be imported as "%s"'), $user_login, $user_login, $next_login), 'warning', ' ', '<br />'); $user_login = $next_login; } if (!empty($users_ips[$phpbb_user->user_id])) { // Decode user ip from hex format $phpbb_user->user_ip = phpbb_decode_ip($users_ips[$phpbb_user->user_id]); } $user_data = array('user_login' => $user_login, 'user_pass' => $phpbb_user->user_password, 'user_email' => $phpbb_user->user_email, 'user_level' => $phpbb_user->user_level, 'user_status' => $phpbb_user->user_active == '1' ? 'autoactivated' : 'closed', 'user_created_datetime' => date('Y-m-d H:i:s', $phpbb_user->user_regdate), 'user_profileupdate_date' => date('Y-m-d', $phpbb_user->user_regdate), 'user_locale' => 'en-US'); if (!empty($phpbb_user->user_rank) && !empty($phpbb_ranks[$phpbb_user->user_rank])) { // Define the user's group $user_data['user_grp_ID'] = $phpbb_ranks[$phpbb_user->user_rank]; } if (!isset($user_data['user_grp_ID'])) { // Set default group $user_data['user_grp_ID'] = phpbb_get_var('group_default'); } // Add the DB quotes for the user fields $import_data = array(); foreach ($user_data as $field_value) { $import_data[] = $phpbb_DB->quote($field_value); } // *** EXECUTE QUERY TO INSERT NEW USER *** // $user_insert_result = mysql_query('INSERT INTO ' . $tableprefix . 'users ( ' . implode(', ', array_keys($user_data)) . ' ) VALUES ( ' . implode(', ', $import_data) . ' )', $DB->dbhandle); if (!$user_insert_result) { // User was not inserted phpbb_log(sprintf(T_('User "%s" with ID %s cannot be imported. MySQL error: %s.'), $phpbb_user->username, $phpbb_user->user_id, mysql_error($DB->dbhandle)), 'error', ' ', '<br />'); continue; } $user_ID = mysql_insert_id($DB->dbhandle); if ($do_import_avatars) { // Import user's avatar phpbb_import_avatar($user_ID, $path_avatars, $phpbb_user->user_avatar); } // Save new inserted ID of the user $users_IDs[$phpbb_user->user_id] = $user_ID; if ($user_has_duplicated_email) { $phpbb_emails_duplicated[$phpbb_user->user_email]['user_ID'] = $phpbb_user->user_id; } // Import the user's fields phpbb_import_user_fields($phpbb_user, $user_ID); // Import user's settings phpbb_import_user_settings($phpbb_user, $user_ID); $phpbb_users_count_imported++; } $page++; } while ($phpbb_users_count > 0); // Add temporary table to store the links between user's IDs from phpbb and b2evo tables phpbb_table_add('users'); phpbb_table_insert_links('users', $users_IDs); $DB->commit(); phpbb_set_var('users_count_imported', $phpbb_users_count_imported); phpbb_set_var('users_count_updated', $phpbb_users_count_updated); }
/** * Import WordPress data from XML file into b2evolution database */ function wpxml_import() { global $DB, $tableprefix; // Load classes: load_class('regional/model/_country.class.php', 'Country'); load_class('regional/model/_region.class.php', 'Region'); load_class('regional/model/_subregion.class.php', 'Subregion'); load_class('regional/model/_city.class.php', 'City'); // Set Blog from request blog ID $wp_blog_ID = param('wp_blog_ID', 'integer', 0); $BlogCache =& get_BlogCache(); $wp_Blog =& $BlogCache->get_by_ID($wp_blog_ID); // The import type ( replace | append ) $import_type = param('import_type', 'string', 'replace'); // Get XML file from request $xml_file = $_FILES['wp_file']; // Parse WordPress XML file into array $xml_data = wpxml_parser($xml_file['tmp_name']); $DB->begin(); if ($import_type == 'replace') { // Remove data from selected blog // Get existing categories $SQL = new SQL(); $SQL->SELECT('cat_ID'); $SQL->FROM('T_categories'); $SQL->WHERE('cat_blog_ID = ' . $DB->quote($wp_blog_ID)); $old_categories = $DB->get_col($SQL->get()); if (!empty($old_categories)) { // Get existing posts $SQL = new SQL(); $SQL->SELECT('post_ID'); $SQL->FROM('T_items__item'); $SQL->WHERE('post_main_cat_ID IN ( ' . implode(', ', $old_categories) . ' )'); $old_posts = $DB->get_col($SQL->get()); } echo T_('Removing the comments... '); evo_flush(); if (!empty($old_posts)) { $SQL = new SQL(); $SQL->SELECT('comment_ID'); $SQL->FROM('T_comments'); $SQL->WHERE('comment_post_ID IN ( ' . implode(', ', $old_posts) . ' )'); $old_comments = $DB->get_col($SQL->get()); $DB->query('DELETE FROM T_comments WHERE comment_post_ID IN ( ' . implode(', ', $old_posts) . ' )'); if (!empty($old_comments)) { $DB->query('DELETE FROM T_comments__votes WHERE cmvt_cmt_ID IN ( ' . implode(', ', $old_comments) . ' )'); } } echo T_('OK') . '<br />'; echo T_('Removing the posts... '); evo_flush(); if (!empty($old_categories)) { $DB->query('DELETE FROM T_items__item WHERE post_main_cat_ID IN ( ' . implode(', ', $old_categories) . ' )'); if (!empty($old_posts)) { // Remove the post's data from related tables $DB->query('DELETE FROM T_items__item_settings WHERE iset_item_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_items__prerendering WHERE itpr_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_items__subscriptions WHERE isub_item_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_items__version WHERE iver_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_postcats WHERE postcat_post_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_slug WHERE slug_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); } } echo T_('OK') . '<br />'; echo T_('Removing the categories... '); evo_flush(); $DB->query('DELETE FROM T_categories WHERE cat_blog_ID = ' . $DB->quote($wp_blog_ID)); echo T_('OK') . '<br />'; echo T_('Removing the tags that are no longer used... '); evo_flush(); if (!empty($old_posts)) { // Remove the tags // Get tags from selected blog $SQL = new SQL(); $SQL->SELECT('itag_tag_ID'); $SQL->FROM('T_items__itemtag'); $SQL->WHERE('itag_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); $old_tags_this_blog = array_unique($DB->get_col($SQL->get())); if (!empty($old_tags_this_blog)) { // Get tags from other blogs $SQL = new SQL(); $SQL->SELECT('itag_tag_ID'); $SQL->FROM('T_items__itemtag'); $SQL->WHERE('itag_itm_ID NOT IN ( ' . implode(', ', $old_posts) . ' )'); $old_tags_other_blogs = array_unique($DB->get_col($SQL->get())); $old_tags_other_blogs_sql = !empty($old_tags_other_blogs) ? ' AND tag_ID NOT IN ( ' . implode(', ', $old_tags_other_blogs) . ' )' : ''; // Remove the tags that are no longer used $DB->query('DELETE FROM T_items__tag WHERE tag_ID IN ( ' . implode(', ', $old_tags_this_blog) . ' )' . $old_tags_other_blogs_sql); } // Remove the links of tags with posts $DB->query('DELETE FROM T_items__itemtag WHERE itag_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); } echo T_('OK') . '<br /><br />'; } /* Import authors */ $authors = array(); $authors_IDs = array(); if (isset($xml_data['authors']) && count($xml_data['authors']) > 0) { global $Settings, $UserSettings; echo T_('Importing the users... '); evo_flush(); // Get existing users $SQL = new SQL(); $SQL->SELECT('user_login, user_ID'); $SQL->FROM('T_users'); $existing_users = $DB->get_assoc($SQL->get()); $authors_count = 0; foreach ($xml_data['authors'] as $author) { if (empty($existing_users[(string) $author['author_login']])) { // Insert new user into DB if User doesn't exist with current login name $GroupCache =& get_GroupCache(); if (!empty($author['author_group'])) { // Set user group from xml data if (($UserGroup =& $GroupCache->get_by_name($author['author_group'], false)) === false) { // If user's group doesn't exist yet, we should create new $UserGroup = new Group(); $UserGroup->set('name', $author['author_group']); $UserGroup->dbinsert(); } } else { // Set default user group is it is not defined in xml if (($UserGroup =& $GroupCache->get_by_name('Normal Users', false)) === false) { // Exit from import of users, because we cannot set default user group break; } } unset($author_created_from_country); if (!empty($author['author_created_from_country'])) { // Get country ID from DB by code $CountryCache =& get_CountryCache(); if (($Country =& $CountryCache->get_by_name($author['author_created_from_country'], false)) !== false) { $author_created_from_country = $Country->ID; } } // Get regional IDs by their names $author_regions = wp_get_regional_data($author['author_country'], $author['author_region'], $author['author_subregion'], $author['author_city']); $User = new User(); $User->set('login', $author['author_login']); $User->set('email', $author['author_email']); $User->set('firstname', $author['author_first_name']); $User->set('lastname', $author['author_last_name']); $User->set('pass', $author['author_pass']); $User->set_Group($UserGroup); $User->set('status', !empty($author['author_status']) ? $author['author_status'] : 'autoactivated'); $User->set('nickname', $author['author_nickname']); $User->set('url', $author['author_url']); $User->set('level', $author['author_level']); $User->set('locale', $author['author_locale']); $User->set('gender', $author['author_gender'] == 'female' ? 'F' : ($author['author_gender'] == 'male' ? 'M' : '')); if ($author['author_age_min'] > 0) { $User->set('age_min', $author['author_age_min']); } if ($author['author_age_max'] > 0) { $User->set('age_max', $author['author_age_max']); } if (isset($author_created_from_country)) { // User was created from this country $User->set('reg_ctry_ID', $author_created_from_country); } if (!empty($author_regions['country'])) { // Country $User->set('ctry_ID', $author_regions['country']); if (!empty($author_regions['region'])) { // Region $User->set('rgn_ID', $author_regions['region']); if (!empty($author_regions['subregion'])) { // Subregion $User->set('subrg_ID', $author_regions['subregion']); } if (!empty($author_regions['city'])) { // City $User->set('city_ID', $author_regions['city']); } } } $User->set('source', $author['author_source']); $User->set_datecreated($author['author_created_ts'], true); $User->set('lastseen_ts', $author['author_lastseen_ts']); $User->set('profileupdate_date', $author['author_profileupdate_date']); $User->dbinsert(); $user_ID = $User->ID; if (!empty($user_ID) && !empty($author['author_created_fromIPv4'])) { $UserSettings->set('created_fromIPv4', ip2int($author['author_created_fromIPv4']), $user_ID); } $authors_count++; } else { // Get ID of existing user $user_ID = $existing_users[(string) $author['author_login']]; } // Save user ID of current author $authors[$author['author_login']] = (string) $user_ID; $authors_IDs[$author['author_id']] = (string) $user_ID; } $UserSettings->dbupdate(); echo sprintf(T_('%d records'), $authors_count) . '<br />'; } /* Import categories */ $category_default = 0; // Get existing categories $SQL = new SQL(); $SQL->SELECT('cat_urlname, cat_ID'); $SQL->FROM('T_categories'); $SQL->WHERE('cat_blog_ID = ' . $DB->quote($wp_blog_ID)); $categories = $DB->get_assoc($SQL->get()); if (isset($xml_data['categories']) && count($xml_data['categories']) > 0) { echo T_('Importing the categories... '); evo_flush(); load_class('chapters/model/_chapter.class.php', 'Chapter'); load_funcs('locales/_charset.funcs.php'); $categories_count = 0; foreach ($xml_data['categories'] as $cat) { if (empty($categories[(string) $cat['category_nicename']])) { $Chapter = new Chapter(NULL, $wp_blog_ID); $Chapter->set('name', $cat['cat_name']); $Chapter->set('urlname', $cat['category_nicename']); $Chapter->set('description', $cat['category_description']); if (!empty($cat['category_parent']) && isset($categories[(string) $cat['category_parent']])) { // Set category parent ID $Chapter->set('parent_ID', $categories[(string) $cat['category_parent']]); } $Chapter->dbinsert(); // Save new category $categories[$cat['category_nicename']] = $Chapter->ID; if (empty($category_default)) { // Set first category as default $category_default = $Chapter->ID; } $categories_count++; } } if (empty($category_default)) { // Set first category as default foreach ($categories as $category_name => $category_ID) { $category_default = $category_ID; break; } } echo sprintf(T_('%d records'), $categories_count) . '<br />'; } /* Import tags */ $tags = array(); if (isset($xml_data['tags']) && count($xml_data['tags']) > 0) { echo T_('Importing the tags... '); evo_flush(); // Get existing tags $SQL = new SQL(); $SQL->SELECT('tag_name, tag_ID'); $SQL->FROM('T_items__tag'); $tags = $DB->get_assoc($SQL->get()); $tags_count = 0; foreach ($xml_data['tags'] as $tag) { if (empty($tags[(string) $tag['tag_name']])) { // Insert new tag into DB if tag doesn't exist with current name mysql_query('INSERT INTO ' . $tableprefix . 'items__tag ( tag_name ) VALUES ( ' . $DB->quote($tag['tag_name']) . ' )', $DB->dbhandle); $tag_ID = mysql_insert_id($DB->dbhandle); // Save new tag $tags[$tag['tag_name']] = (string) $tag_ID; $tags_count++; } } echo sprintf(T_('%d records'), $tags_count) . '<br />'; } /* Import posts */ $posts = array(); $comments = array(); if (isset($xml_data['posts']) && count($xml_data['posts']) > 0) { load_class('items/model/_item.class.php', 'Item'); // Set status's links between WP and b2evo names $post_statuses = array('publish' => 'published', 'pending' => 'deprecated', 'deprecated' => 'deprecated', 'protected' => 'protected', 'private' => 'private', 'redirected' => 'redirected', 'draft' => 'draft'); // Get post types $SQL = new SQL(); $SQL->SELECT('LOWER( ptyp_name ), ptyp_ID'); $SQL->FROM('T_items__type'); $post_types = $DB->get_assoc($SQL->get()); echo T_('Importing the posts... '); evo_flush(); foreach ($xml_data['posts'] as $post) { $author_ID = isset($authors[(string) $post['post_author']]) ? $authors[(string) $post['post_author']] : 1; $last_edit_user_ID = isset($authors[(string) $post['post_lastedit_user']]) ? $authors[(string) $post['post_lastedit_user']] : $author_ID; $post_main_cat_ID = $category_default; $post_extra_cat_IDs = array($post_main_cat_ID); $post_tags = array(); if (!empty($post['terms'])) { // Set categories and tags foreach ($post['terms'] as $term) { switch ($term['domain']) { case 'category': if (isset($categories[(string) $term['slug']])) { if ($post_main_cat_ID == $category_default) { // Set main category $post_main_cat_ID = $categories[(string) $term['slug']]; } else { // Set extra categories $post_extra_cat_IDs[] = $categories[(string) $term['slug']]; } } break; case 'post_tag': if (isset($tags[(string) $term['slug']])) { // Set tag $post_tags[] = $term['slug']; } break; } } } // Set post type ID $post_type_ID = isset($post_types[strtolower($post['post_type'])]) ? $post_types[strtolower($post['post_type'])] : '1'; // Get regional IDs by their names $item_regions = wp_get_regional_data($post['post_country'], $post['post_region'], $post['post_subregion'], $post['post_city']); $Item = new Item(); $Item->set('main_cat_ID', $post_main_cat_ID); $Item->set('creator_user_ID', $author_ID); $Item->set('lastedit_user_ID', $last_edit_user_ID); $Item->set('title', $post['post_title']); $Item->set('content', $post['post_content']); $Item->set('excerpt', $post['post_excerpt']); $Item->set('datestart', $post['post_date']); $Item->set('datecreated', !empty($post['post_datecreated']) ? $post['post_datecreated'] : $post['post_date']); $Item->set('datemodified', !empty($post['post_datemodified']) ? $post['post_datemodified'] : $post['post_date']); $Item->set('urltitle', !empty($post['post_urltitle']) ? $post['post_urltitle'] : $post['post_title']); $Item->set('status', isset($post_statuses[(string) $post['status']]) ? $post_statuses[(string) $post['status']] : 'draft'); $Item->set('comment_status', $post['comment_status'] == 'open' ? 'open' : 'closed'); $Item->set('ptyp_ID', $post_type_ID); if (empty($post['post_excerpt']) && !empty($post['post_content'])) { // Generate excerpt $Item->set('excerpt', wp_generate_excerpt($post['post_content'])); $Item->set('excerpt_autogenerated', '1'); } $Item->set('extra_cat_IDs', $post_extra_cat_IDs); $Item->set('dateset', $post['post_date_mode'] == 'set' ? 1 : 0); if (isset($authors[(string) $post['post_assigned_user']])) { $Item->set('assigned_user', $authors[(string) $post['post_assigned_user']]); } $Item->set('datedeadline', $post['post_datedeadline']); $Item->set('locale', $post['post_locale']); $Item->set('excerpt_autogenerated', $post['post_excerpt_autogenerated']); $Item->set('titletag', $post['post_titletag']); $Item->set('notifications_status', $post['post_notifications_status']); $Item->set('views', $post['post_views']); $Item->set('renderers', array($post['post_renderers'])); $Item->set('priority', $post['post_priority']); $Item->set('featured', $post['post_featured']); $Item->set('order', $post['post_order']); if (!empty($item_regions['country'])) { // Country $Item->set('ctry_ID', $item_regions['country']); if (!empty($item_regions['region'])) { // Region $Item->set('rgn_ID', $item_regions['region']); if (!empty($item_regions['subregion'])) { // Subregion $Item->set('subrg_ID', $item_regions['subregion']); } if (!empty($item_regions['city'])) { // City $Item->set('city_ID', $item_regions['city']); } } } if (count($post_tags) > 0) { $Item->tags = $post_tags; } $Item->dbinsert(); $posts[$post['post_id']] = $Item->ID; if (!empty($post['comments'])) { // Set comments $comments[$Item->ID] = $post['comments']; } } foreach ($xml_data['posts'] as $post) { // Set post parents if (!empty($post['post_parent']) && isset($posts[(string) $post['post_parent']])) { mysql_query('UPDATE ' . $tableprefix . 'items__item SET post_parent_ID = ' . $DB->quote($posts[(string) $post['post_parent']]) . ' WHERE post_ID = ' . $DB->quote($posts[(string) $post['post_id']]), $DB->dbhandle); } } echo sprintf(T_('%d records'), count($xml_data['posts'])) . '<br />'; } /* Import comments */ if (!empty($comments)) { echo T_('Importing the comments... '); evo_flush(); $comments_count = 0; $comments_IDs = array(); foreach ($comments as $post_ID => $comments) { if (empty($comments)) { // Skip if no comments continue; } foreach ($comments as $comment) { $comment_author_ID = 0; if (!empty($comment['comment_user_id']) && isset($authors_IDs[(string) $comment['comment_user_id']])) { // Author ID $comment_author_ID = $authors_IDs[(string) $comment['comment_user_id']]; } $comment_parent_ID = 0; if (!empty($comment['comment_parent']) && isset($comments_IDs[(string) $comment['comment_parent']])) { // Parent comment ID $comment_parent_ID = $comments_IDs[(string) $comment['comment_parent']]; } unset($comment_IP_country); if (!empty($comment['comment_IP_country'])) { // Get country ID by code $CountryCache =& get_CountryCache(); if ($Country =& $CountryCache->get_by_name($comment['comment_IP_country'], false)) { $comment_IP_country = $Country->ID; } } $Comment = new Comment(); $Comment->item_ID = $post_ID; $Comment->set('post_ID', $post_ID); if (!empty($comment_parent_ID)) { $Comment->set('in_reply_to_cmt_ID', $comment_parent_ID); } $Comment->set('date', $comment['comment_date']); if (!empty($comment_author_ID)) { $Comment->set('author_ID', $comment_author_ID); } $Comment->set('author', evo_substr($comment['comment_author'], 0, 100)); $Comment->set('author_IP', $comment['comment_author_IP']); $Comment->set('author_email', $comment['comment_author_email']); $Comment->set('content', $comment['comment_content']); if (empty($comment['comment_status'])) { // If comment status is empty (the export of wordpress doesn't provide this field) $Comment->set('status', $comment['comment_approved'] == '1' ? 'published' : 'draft'); } else { // Set status when we have predefined value $Comment->set('status', $comment['comment_status']); } if (!empty($comment_IP_country)) { // Country $Comment->set('IP_ctry_ID', $comment_IP_country); } $Comment->set('rating', $comment['comment_rating']); $Comment->set('featured', $comment['comment_featured']); $Comment->set('nofollow', $comment['comment_nofollow']); $Comment->set('helpful_addvotes', $comment['comment_helpful_addvotes']); $Comment->set('helpful_countvotes', $comment['comment_helpful_countvotes']); $Comment->set('spam_addvotes', $comment['comment_spam_addvotes']); $Comment->set('spam_countvotes', $comment['comment_spam_countvotes']); $Comment->set('karma', $comment['comment_karma']); $Comment->set('spam_karma', $comment['comment_spam_karma']); $Comment->set('allow_msgform', $comment['comment_allow_msgform']); $Comment->set('notif_status', $comment['comment_notif_status']); $Comment->dbinsert(); $comments_IDs[$comment['comment_id']] = $Comment->ID; $comments_count++; } } echo sprintf(T_('%d records'), $comments_count) . '<br />'; } $DB->commit(); }
/** * Remove trailing slash, if present * * @param string the path/url * @return string the path/url without trailing slash */ function no_trailing_slash($path) { if (evo_substr($path, -1) == '/') { return evo_substr($path, 0, evo_strlen($path) - 1); } else { return $path; } }
/** * Process Header information like subject and date of a mail. * * @param array $header header as set by mime_parser_class::Analyze() * @param string message subject by reference * @param string message date by reference * @return bool true if valid subject prefix is detected */ function pbm_process_header($header, &$subject, &$post_date) { global $Settings; $subject = $header['Subject']; $ddate = $header['Date']; $prefix = $Settings->get('eblog_subject_prefix'); pbm_msg('Subject: ' . $subject); if (evo_substr($subject, 0, evo_strlen($prefix)) !== $prefix) { pbm_msg('Subject prefix is not "' . $prefix . '", skip this email'); return false; } $subject = evo_substr($subject, evo_strlen($prefix)); // Parse Date if (!preg_match('#^(.{3}, )?(\\d{2}) (.{3}) (\\d{4}) (\\d{2}):(\\d{2}):(\\d{2})#', $ddate, $match)) { $ddate_U = @strtotime($ddate); if (empty($ddate_U) || strlen($ddate_U) < 2) { pbm_msg(sprintf(T_('Could not parse date header "%s"'), $ddate), true); return false; } } if (empty($ddate_U)) { $dmonths = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12); $ddate_H = $match[5]; $ddate_i = $match[6]; $ddate_s = $match[7]; if (!isset($dmonths[$match[3]])) { pbm_msg(T_('Invalid month name in message date string.'), true); return false; } $ddate_m = $dmonths[$match[3]]; $ddate_d = $match[2]; $ddate_Y = $match[4]; $ddate_U = mktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y); } $post_date = date('Y-m-d H:i:s', $ddate_U); return true; }
/** * Helper function for "Requested URI" column * @param integer Blog ID * @param string Requested URI * @param integer Output string lenght * @param string Display * @param string Controller * @return string */ function stats_format_req_URI($hit_blog_ID, $hit_uri, $max_len = 40, $hit_disp = NULL, $hit_ctrl = NULL, $hit_action = NULL) { if (!empty($hit_blog_ID)) { $BlogCache =& get_BlogCache(); $tmp_Blog =& $BlogCache->get_by_ID($hit_blog_ID); $full_url = $tmp_Blog->get_baseurl_root() . $hit_uri; } else { $full_url = $hit_uri; } $int_search_uri = urldecode($hit_uri); if (evo_strpos($int_search_uri, '?s=') !== false || evo_strpos($int_search_uri, '&s=') !== false) { // This is an internal search: preg_match('~[?&]s=([^&#]*)~', $int_search_uri, $res); $hit_uri = 'Internal search : ' . $res[1]; } elseif (evo_strlen($hit_uri) > $max_len) { $hit_uri = '...' . evo_substr($hit_uri, -$max_len); } if ($hit_disp != NULL || $hit_ctrl != NULL || $hit_action != NULL) { $hit_uri = ''; if ($hit_disp != NULL) { $hit_uri = '[disp=<a href="' . $full_url . '">' . $hit_disp . '</a>]'; } if ($hit_ctrl != NULL) { $hit_uri = $hit_uri . ' [ctrl=<a href="' . $full_url . '">' . $hit_ctrl . '</a>]'; } if ($hit_action != NULL) { $hit_uri = $hit_uri . ' [action=<a href="' . $full_url . '">' . $hit_action . '</a>]'; } return $hit_uri; } return '<a href="' . $full_url . '">' . $hit_uri . '</a>'; }
/** * check(-) */ function check($xhtml) { // Convert encoding: // TODO: use convert_encoding() if (empty($this->xml_parser_encoding) || $this->encoding != $this->xml_parser_encoding) { // we need to convert encoding: if (function_exists('mb_convert_encoding')) { // we can convert encoding to UTF-8 $this->encoding = 'UTF-8'; // Convert XHTML: $xhtml = mb_convert_encoding($xhtml, 'UTF-8'); } elseif (($this->encoding == 'ISO-8859-1' || empty($this->encoding)) && function_exists('utf8_encode')) { $this->encoding = 'UTF-8'; $xhtml = utf8_encode($xhtml); } } // Open comments or '<![CDATA[' are dangerous $xhtml = str_replace('<!', '', $xhtml); // Convert isolated & chars $xhtml = preg_replace('#(\\s)&(\\s)#', '\\1&\\2', $xhtml); $xhtml_head = '<?xml version="1.0"'; if (!empty($this->encoding)) { $xhtml_head .= ' encoding="' . $this->encoding . '"'; } $xhtml_head .= '?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"'; // Include entities: $xhtml_head .= '['; // Include latin1 entities (http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent): $xhtml_head .= file_get_contents(dirname(__FILE__) . '/_xhtml-lat1.ent'); // Include symbol entities (http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent): $xhtml_head .= file_get_contents(dirname(__FILE__) . '/_xhtml-symbol.ent'); // Include special entities (http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent): $xhtml_head .= file_get_contents(dirname(__FILE__) . '/_xhtml-special.ent'); $xhtml_head .= ']>'; $xhtml = $xhtml_head . '<body>' . $xhtml . '</body>'; unset($xhtml_head); if (!xml_parse($this->parser, $xhtml)) { $xml_error_code = xml_get_error_code($this->parser); $xml_error_string = xml_error_string($xml_error_code); switch ($xml_error_code) { case XML_ERROR_TAG_MISMATCH: $xml_error_string .= ': <code>' . $this->stack[count($this->stack) - 1] . '</code>'; break; } $pos = xml_get_current_byte_index($this->parser); $xml_error_string .= ' near <code>' . htmlspecialchars(evo_substr($xhtml, $this->last_checked_pos, $pos - $this->last_checked_pos + 20)) . '</code>'; $this->html_error(T_('Parser error: ') . $xml_error_string); } return $this->isOK(); }
$BlogCache =& get_BlogCache(); $Blog = $BlogCache->get_by_ID($blog, false, false); } } if ($inskin && !empty($Blog)) { // in-skin register, activate current Blog locale locale_activate($Blog->get('locale')); } if (!$Settings->get('newusers_canregister')) { $action = 'disabled'; } if ($register_user = $Session->get('core.register_user')) { // Get an user data from predefined session (after adding of a comment) $login = preg_replace('/[^a-z0-9 ]/i', '', $register_user['name']); $login = str_replace(' ', '_', $login); $login = evo_substr($login, 0, 20); $email = $register_user['email']; $Session->delete('core.register_user'); } switch ($action) { case 'register': // Stop a request from the blocked IP addresses antispam_block_ip(); // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('regform'); /* * Do the registration: */ $pass1 = param($dummy_fields['pass1'], 'raw', ''); $pass2 = param($dummy_fields['pass2'], 'raw', ''); // Call plugin event to allow catching input in general and validating own things from DisplayRegisterFormFieldset event
if (($edited_IPRange =& $IPRangeCache->get_by_ID($iprange_ID, false)) === false) { // We could not find the goal to edit: unset($edited_IPRange); forget_param('iprange_ID'); $Messages->add(sprintf(T_('Requested «%s» object does not exist any longer.'), T_('IP Range')), 'error'); } } switch ($action) { case 'ban': // only an action if further "actions" given // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('antispam'); // Check permission: $current_User->check_perm('spamblacklist', 'edit', true); // TODO: This should become different for 'edit'/'add' perm level - check for 'add' here. $keyword = evo_substr($keyword, 0, 80); param('delhits', 'integer', 0); $all_statuses = get_visibility_statuses('keys', array('trash', 'redirected')); $delstatuses = array(); foreach ($all_statuses as $status) { // collect which comments should be delteded if (param('del' . $status, 'integer', 0)) { // matching comments with this status should be deleted $delstatuses[] = $status; } } $delcomments = count($delstatuses); param('blacklist_locally', 'integer', 0); param('report', 'integer', 0); // Check if the string is too short, // it has to be a minimum of 5 characters to avoid being too generic
/** * Remove content after body terminators * * @param string Source content * @retrun string Limited content */ function dre_limit_by_terminators($content) { global $Settings; $repath_terminators = $Settings->get('repath_body_terminator'); if (!empty($repath_terminators)) { $repath_terminators = explode("\n", str_replace(array("\r", "\n\n"), "\n", $repath_terminators)); foreach ($repath_terminators as $repath_terminator) { // Limit by each terminator $repath_terminator = trim($repath_terminator); if (empty($repath_terminator)) { // Skip empty string continue; } if (!empty($repath_terminator) && ($os_terminator = evo_strpos($content, $repath_terminator)) !== false) { // Remove text after terminator string $content = evo_substr($content, 0, $os_terminator); } } } return $content; }
} // free the query result set mysql_free_result($res); // select the evolution db $db = mysql_select_db($evo_db, $con); if (!$db) { die('b2evolution database name is incorrect. Please check the name and try again.'); } foreach ($comments as $comment) { // escape the string and replace UNIX newlines to line breaks in order to // render properly in b2evolution $ccontent = mysql_real_escape_string($comment['content']); $ccontent = str_replace('\\r\\n', '<br />', $ccontent); // query to insert the comments into the b2evolution table $query = 'INSERT INTO ' . $b2 . 'comments (comment_ID, comment_post_ID, comment_type, comment_status, comment_author_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_allow_msgform) VALUES ("' . $comment['comment_id'] . '", "' . $comment['post_id'] . '", "' . $comment['type'] . '", "' . $comment['status'] . '", "' . $comment['author_id'] . '", "' . evo_substr($comment['author'], 0, 100) . '", "' . $comment['email'] . '", "' . $comment['url'] . '", "' . $comment['ip'] . '", "' . $comment['date'] . '", "' . $ccontent . '", "1");'; $flag = mysql_query($query); if (!$flag) { pre_dump($query); die('Comment importing failed. Please check your b2evolution installation.'); } } echo '<font color="#00CC00">Comments imported successfully!</font>'; // Now to import users. Note: all users other than admin will be imported and then they will be set to the default level // of 0 echo '<h2>Trying to import all users (except admin)</h2>'; $users = array(); // select the wordpress database $db = mysql_select_db($wp_db, $con); if (!$db) { die('WordPress database name is incorrect. Please check the name and try again.');