function setUp() { parent::setUp(); require_code('news'); $this->news_id = add_news_category('Today', 'news.gif', 'Headlines', NULL, NULL); // Test the forum was actually created $this->assertTrue('Today' == get_translated_text($GLOBALS['SITE_DB']->query_value('news_categories', 'nc_title ', array('id' => $this->news_id)))); }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_news_and_categories($db, $table_prefix, $file_base) { require_code('news'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'news_categories ORDER BY id', NULL, NULL, true); if (is_null($rows)) { return; } $on_same_msn = $this->on_same_msn($file_base); foreach ($rows as $row) { if (import_check_if_imported('news_category', strval($row['id']))) { continue; } $owner = $on_same_msn ? $row['nc_owner'] : import_id_remap_get('member', $row['nc_owner'], true); $id = get_param_integer('keep_preserve_ids', 0) == 0 ? NULL : $row['id']; $id_new = add_news_category($this->get_lang_string($db, $row['nc_title']), $row['nc_img'], $row['notes'], $owner, $id); import_id_remap_put('news_category', strval($row['id']), $id_new); } $this->_import_catalogue_entry_linkage($db, $table_prefix, 'news_category', 'news_category'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'news ORDER BY id'); foreach ($rows as $row) { if (import_check_if_imported('news', strval($row['id']))) { continue; } $news_category = array(); $rows2 = $db->query('SELECT news_entry_category FROM ' . $table_prefix . 'news_category_entries WHERE news_entry=' . strval((int) $row['id'])); foreach ($rows2 as $row2) { $next = import_id_remap_get('news_category', strval($row2['news_entry_category']), true); if (!is_null($next)) { $news_category[] = $next; } } $submitter = $on_same_msn ? $row['submitter'] : import_id_remap_get('member', $row['submitter'], true); if (is_null($submitter)) { $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } $id = get_param_integer('keep_preserve_ids', 0) == 0 ? NULL : $row['id']; $main_news_category = $row['news_category']; $main_news_category = import_id_remap_get('news_category', strval($main_news_category), true); if (is_null($main_news_category)) { $main_news_category = db_get_first_id(); } $id_new = add_news($this->get_lang_string($db, $row['title']), $this->get_lang_string($db, $row['news']), $row['author'], $row['validated'], $row['allow_rating'], $row['allow_comments'], $row['allow_trackbacks'], $row['notes'], $this->get_lang_string($db, $row['news_article']), $main_news_category, $news_category, $row['date_and_time'], $submitter, $row['news_views'], $row['edit_date'], $id, $row['news_image']); import_id_remap_put('news', strval($row['id']), $id_new); } $this->_import_review_supplement($db, $table_prefix, 'news', 'news'); $this->_import_catalogue_entry_linkage($db, $table_prefix, 'news', 'news'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'news_rss_cloud', NULL, NULL, true); if (!is_null($rows)) { foreach ($rows as $row) { unset($row['id']); $GLOBALS['SITE_DB']->query_insert('news_rss_cloud', $row); } } }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_news_and_categories($db, $table_prefix, $old_base_dir) { require_code('news'); $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'news'))); $categories = $db->query("SELECT id,title,description,image FROM " . $table_prefix . "sections WHERE title='News'"); foreach ($categories as $category) { $title = $category['title']; $cat_id = $GLOBALS['SITE_DB']->query_select('news_categories', array('id'), array('nc_title' => $title), '', 1); if (count($cat_id) == 0) { $cat_title = $category['title']; $category_id = $GLOBALS['SITE_DB']->query("SELECT N.id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "translate AS T INNER JOIN " . $GLOBALS['SITE_DB']->get_table_prefix() . "news_categories AS N ON T.id=N.nc_title AND " . db_string_equal_to('T.text_original', $cat_title)); if (count($category_id) == 0) { $desc = html_to_comcode($category['description']); $id = add_news_category($category['title'], $category['image'], $desc, NULL, NULL); } else { $id = $category_id[0]['id']; } } else { $id = $cat_id[0]['id']; } $rows = $db->query('SELECT * FROM ' . $table_prefix . 'content WHERE sectionid=' . strval($category['id'])); foreach ($rows as $row) { $val = $row['title']; $news_id = $GLOBALS['SITE_DB']->query("SELECT N.id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "translate AS T INNER JOIN " . $GLOBALS['SITE_DB']->get_table_prefix() . "news AS N ON T.id=N.title AND " . db_string_equal_to('T.text_original', $val) . " AND news_category=" . strval($id) . " AND news_category<>''"); if (count($news_id) == 0) { $title = $row['title']; $news = html_to_comcode($row['introtext']); $author = $db->query_value_null_ok('users', 'name', array('id' => $row['created_by'])); if (is_null($author)) { $author = do_lang('UNKNOWN'); } $access = $row['access']; if ($access == 0) { $validated = 1; } else { $validated = 0; } $allow_rating = 1; $allow_comments = 1; $allow_trackbacks = 1; $notes = ''; $news_article = ''; $main_news_category = $id; $news_category = NULL; $datetimearr = explode(' ', $row['created']); $datearr = explode('-', $datetimearr[0]); $timearr = explode(':', $datetimearr[1]); $date = intval($datearr[2]); $month = intval($datearr[1]); $year = intval($datearr[0]); $hour = intval($timearr[0]); $min = intval($timearr[1]); $sec = intval($timearr[2]); $time = mktime($hour, $min, $sec, $month, $date, $year); $submitter = import_id_remap_get('member', strval($row['created_by'])); $views = $row['hits']; $datetimearr = explode(' ', $row['modified']); $datearr = explode('-', $datetimearr[0]); $timearr = explode(':', $datetimearr[1]); $date = intval($datearr[2]); $month = intval($datearr[1]); $year = intval($datearr[0]); $hour = intval($timearr[0]); $min = intval($timearr[1]); $sec = intval($timearr[2]); $edit_date = mktime($hour, $min, $sec, $month, $date, $year); $nid = NULL; $image = 'newscats/' . preg_replace('#\\..*$#', '', $row['images']); @mkdir(get_custom_file_base() . '/themes/default/images_custom/newscats', 0777); fix_permissions(get_custom_file_base() . '/themes/default/images_custom/newscats', 0777); sync_file(get_custom_file_base() . '/themes/default/images_custom/newscats'); $newimagepath = get_custom_file_base() . '/themes/default/images_custom/newscats/' . rawurldecode($row['images']); $oldimagepath = $old_base_dir . "/images/stories/" . rawurldecode($row['images']); @copy($oldimagepath, $newimagepath); fix_permissions($newimagepath); sync_file($newimagepath); add_news($title, $news, $author, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $news_article, $main_news_category, $news_category, $time, $submitter, $views, $edit_date, $nid, $image); } } } }
/** * The actualiser to import wordpress blog * * @return tempcode The UI */ function _import_wordpress() { check_specific_permission('mass_import', NULL, NULL, 'cms_news'); $title = get_page_title('IMPORT_WP_DB'); require_code('rss'); require_code('news'); require_code('news2'); $GLOBALS['LAX_COMCODE'] = true; require_code('uploads'); is_swf_upload(true); $is_validated = post_param_integer('wp_auto_validate', 0); $to_own_account = post_param_integer('wp_add_to_own', 0); //Wordpress post xml file importing method if (get_param('method') == 'xml') { $rss_url = post_param('xml_url', NULL); if (array_key_exists('file_novalidate', $_FILES)) { if (is_swf_upload(true) && array_key_exists('file_novalidate', $_FILES) || array_key_exists('file_novalidate', $_FILES) && is_uploaded_file($_FILES['file_novalidate']['tmp_name'])) { $rss_url = $_FILES['file_novalidate']['tmp_name']; } else { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } } else { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } $rss = new rss($rss_url, true); if (!is_null($rss->error)) { warn_exit($rss->error); } $cat_id = NULL; $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); $extra_post_data = array(); foreach ($rss->gleamed_items as $item) { if (!array_key_exists('category', $item)) { $item['category'] = do_lang('NC_general'); } $extra_post_data[] = $item; foreach ($NEWS_CATS as $_cat => $news_cat) { if (get_translated_text($news_cat['nc_title']) == $item['category']) { $cat_id = $_cat; } } //Check for existing owner categories, if not create blog category for creator if ($to_own_account == 0) { $creator = $item['author']; $submitter_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($creator); } else { $submitter_id = get_member(); } //if(is_null($submitter_id)) continue; //Skip importing posts of nonexisting users $owner_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $submitter_id)); if (is_null($cat_id)) { $cat_id = add_news_category($item['category'], 'newscats/general', '', NULL); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } // Add news add_news($item['title'], html_to_comcode($item['news']), NULL, $is_validated, 1, 1, 1, '', array_key_exists('news_article', $item) ? html_to_comcode($item['news_article']) : '', $owner_category_id, array($cat_id), NULL, $submitter_id, 0, time(), NULL, ''); } if (url_is_local($rss_url)) { // Means it is a temp file @unlink($rss_url); } } elseif (get_param('method') == 'db') { import_wordpress_db(); } breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_BLOGS')), array('_SELF:_SELF:import_wordpress', do_lang_tempcode('IMPORT_WORDPRESS')))); breadcrumb_set_self(do_lang_tempcode('DONE')); return inform_screen($title, do_lang_tempcode('IMPORT_WORDPRESS_DONE')); }
/** * Import wordpress db */ function import_wordpress_db() { disable_php_memory_limit(); $data = get_wordpress_data(); $is_validated = post_param_integer('wp_auto_validate', 0); $to_own_account = post_param_integer('wp_add_to_own', 0); // Create members require_code('ocf_members_action'); require_code('ocf_groups'); $def_grp_id = get_first_default_group(); $cat_id = array(); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); foreach ($data as $values) { if (get_forum_type() == 'ocf') { $member_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $values['user_login'])); if (is_null($member_id)) { if (post_param_integer('wp_import_wordpress_users', 0) == 1) { $member_id = ocf_make_member($values['user_login'], $values['user_pass'], '', NULL, NULL, NULL, NULL, array(), NULL, $def_grp_id, 1, time(), time(), '', NULL, '', 0, 0, 1, '', '', '', 1, 0, '', 1, 1, '', NULL, '', false, 'wordpress'); } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username('admin'); // Set admin as owner if (is_null($member_id)) { $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id() + 1; } } } } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } // Guest user // If post should go to own account if ($to_own_account == 1) { $member_id = get_member(); } if (array_key_exists('POSTS', $values)) { // Create posts in blog foreach ($values['POSTS'] as $post_id => $post) { if (array_key_exists('category', $post)) { $cat_id = array(); foreach ($post['category'] as $cat_code => $category) { $cat_code = NULL; if ($category == 'Uncategorized') { continue; } // Skip blank category creation foreach ($NEWS_CATS as $id => $existing_cat) { if (get_translated_text($existing_cat['nc_title']) == $category) { $cat_code = $id; } } if (is_null($cat_code)) { $cat_code = add_news_category($category, 'newscats/community', $category); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*')); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } $cat_id = array_merge($cat_id, array($cat_code)); } } $owner_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $member_id)); if ($post['post_type'] == 'post') { $id = add_news($post['post_title'], html_to_comcode($post['post_content']), NULL, $is_validated, 1, $post['comment_status'] == 'closed' ? 0 : 1, 1, '', html_to_comcode($post['post_content']), $owner_category_id, $cat_id, NULL, $member_id, 0, time(), NULL, ''); } elseif ($post['post_type'] == 'page') { // If dont have permission to write comcode page, skip the post if (!has_submit_permission('high', get_member(), get_ip_address(), NULL, NULL)) { continue; } require_code('comcode'); // Save articles as new comcode pages $zone = filter_naughty(post_param('zone', 'site')); $lang = filter_naughty(post_param('lang', 'EN')); $file = preg_replace('/[^A-Za-z0-9]/', '_', $post['post_title']); // Filter non alphanumeric charactors $parent_page = post_param('parent_page', ''); $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt'); // Check existancy of new page $submiter = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file)); if (!is_null($submiter)) { continue; } // Skip existing titled articles - may need change require_code('submit'); give_submit_points('COMCODE_PAGE_ADD'); if (!addon_installed('unvalidated')) { $is_validated = 1; } $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $is_validated, 'p_edit_date' => NULL, 'p_add_date' => strtotime($post['post_date']), 'p_submitter' => $member_id, 'p_show_as_edit' => 0)); if (!file_exists($fullpath)) { $_content = html_to_comcode($post['post_content']); $myfile = @fopen($fullpath, 'wt'); if ($myfile === false) { intelligent_write_error($fullpath); } if (fwrite($myfile, $_content) < strlen($_content)) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); sync_file($fullpath); } require_code('seo2'); seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, post_param('meta_keywords', ''), post_param('meta_description', '')); require_code('permissions2'); set_page_permissions_from_environment($zone, $file); } $content_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $id), get_module_zone('news'), NULL, false, false, true); $content_title = $post['post_title']; // Add comments if (post_param_integer('wp_import_blog_comments', 0) == 1) { if (array_key_exists('COMMENTS', $post)) { $submitter = NULL; foreach ($post['COMMENTS'] as $comment) { $submitter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $comment['comment_author'])); if (is_null($submitter)) { $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } // If comment is made by a non-member, assign comment to guest account $forum = is_null(get_value('comment_forum__news')) ? get_option('comments_forum_name') : get_value('comment_forum__news'); $result = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, 'news_' . strval($id), $submitter, $post['post_title'], $comment['comment_content'], $content_title, do_lang('COMMENT'), $content_url, NULL, NULL, 1, 1, false); } } } } } } }
/** * Convert a named news category to an ocPortal news category ID. * * @param SHORT_TEXT Named news category * @param ID_TEXT The image code the news category will use * @return AUTO_LINK The news category ID */ function get_news_category_id($title, $image) { require_code('news'); require_code('galleries2'); $cat_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories c LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON c.nc_title=t.id', 'c.id', array('text_original' => $title)); if (is_null($cat_id)) { $cat_id = add_news_category($title, 'newscats/' . $image, ''); } return $cat_id; }
/** * Standard aed_module add actualiser. * * @return ID_TEXT The entry added */ function add_actualisation() { require_code('themes2'); $title = post_param('title'); $img = get_theme_img_code('newscats'); $notes = post_param('notes', ''); $id = add_news_category($title, $img, $notes); $this->set_permissions($id); return strval($id); }