function setUp() { parent::setUp(); require_code('catalogues'); require_code('catalogues2'); $this->cat_id = actual_add_catalogue_category('Testing_category', 'Test_Cat', 'Testing_Cat', '', 1, '', 30, 60, NULL, NULL, NULL); $this->assertTrue('Testing_category' == $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'c_name ', array('id' => $this->cat_id))); }
function _create_catalogue_position($catalogue_name, $tree_pos, $cat, $location, &$tree) { foreach ($tree_pos as $name) { $tree =& $tree['children'][$name]; if (!isset($tree['cc_id'])) { $tree['cc_id'] = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories c LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=c.cc_title', 'c.id', array('cc_parent_id' => $cat, 'text_original' => $name)); if (is_null($tree['cc_id'])) { $tree['cc_id'] = actual_add_catalogue_category($catalogue_name, $name, '', '', $cat); } } $cat = $tree['cc_id']; } return $cat; }
/** * 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_catalogues($db, $table_prefix, $file_base) { require_code('catalogues2'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'catalogues', NULL, NULL, true); if (is_null($rows)) { return; } foreach ($rows as $row) { if (import_check_if_imported('catalogue', $row['c_name'])) { continue; } $test = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_name' => $row['c_name'])); if (is_null($test)) { $row['c_title'] = insert_lang($this->get_lang_string($db, $row['c_title']), 2); $row['c_description'] = insert_lang($this->get_lang_string($db, $row['c_description']), 2); if (!array_key_exists('c_display_type', $row)) { $row['c_display_type'] = $row['c_own_pages']; unset($row['c_own_pages']); } if (!array_key_exists('c_ecommerce', $row)) { $row['c_ecommerce'] = 0; } if (!array_key_exists('c_send_view_reports', $row)) { $row['c_send_view_reports'] = 0; } unset($row['c_own_template']); $GLOBALS['SITE_DB']->query_insert('catalogues', $row); import_id_remap_put('catalogue', $row['c_name'], $row['c_name']); $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'catalogue_fields WHERE ' . db_string_equal_to('c_name', $row['c_name'])); foreach ($rows2 as $row2) { if (import_check_if_imported('catalogue_field', strval($row2['id']))) { continue; } $row2['cf_name'] = insert_lang($this->get_lang_string($db, $row2['cf_name']), 2); $row2['cf_description'] = insert_lang($this->get_lang_string($db, $row2['cf_description']), 2); if (!array_key_exists('cf_put_in_category', $row2)) { $row2['cf_put_in_category'] = 1; } if (!array_key_exists('cf_put_in_search', $row2)) { $row2['cf_put_in_search'] = 1; } $old_id = $row2['id']; unset($row2['id']); $id_new = $GLOBALS['SITE_DB']->query_insert('catalogue_fields', $row2, true); import_id_remap_put('catalogue_field', $old_id, $id_new); } } else { warn_exit(do_lang_tempcode('CANNOT_MERGE_CATALOGUES')); } } $this->_import_review_supplement($db, $table_prefix, 'catalogues', 'catalogue_entry'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'catalogue_categories ORDER BY id'); $id = mixed(); foreach ($rows as $row) { if (import_check_if_imported('catalogue_category', strval($row['id']))) { continue; } if (is_null($row['cc_parent_id']) && $GLOBALS['SITE_DB']->query_value('catalogues', 'c_is_tree', array('c_name' => $row['c_name'])) == 1) { $real_root = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories', 'id', array('cc_parent_id' => NULL, 'c_name' => $row['c_name'])); if (!is_null($real_root)) { import_id_remap_put('catalogue_category', strval($row['id']), $real_root); continue; } } $id = get_param_integer('keep_preserve_ids', 0) == 0 ? NULL : $row['id']; $rep_image = array_key_exists('cc_rep_image', $row) ? $row['cc_rep_image'] : ''; $id_new = actual_add_catalogue_category($row['c_name'], $this->get_lang_string($db, $row['cc_title']), $this->get_lang_string($db, $row['cc_description']), $row['cc_notes'], is_null($row['cc_parent_id']) ? NULL : -$row['cc_parent_id'], $rep_image, array_key_exists('cc_move_days_lower', $row) ? $row['cc_move_days_lower'] : 30, array_key_exists('cc_move_days_higher', $row) ? $row['cc_move_days_higher'] : 60, array_key_exists('cc_move_target', $row) ? $row['cc_move_target'] : NULL, $row['cc_add_date'], $id); import_id_remap_put('catalogue_category', strval($row['id']), $id_new); } $rows = $GLOBALS['SITE_DB']->query('SELECT id,cc_parent_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_categories WHERE cc_parent_id<0'); foreach ($rows as $row) { $parent_id = import_id_remap_get('catalogue_category', -$row['cc_parent_id'], true); $GLOBALS['SITE_DB']->query_update('catalogue_categories', array('cc_parent_id' => $parent_id), array('id' => $row['id']), '', 1); } $rows = $db->query('SELECT * FROM ' . $table_prefix . 'catalogue_entries ORDER BY id'); $on_same_msn = $this->on_same_msn($file_base); foreach ($rows as $row) { if (!is_null(import_id_remap_get('catalogue_entry', strval($row['id']), true))) { continue; } $category_id = import_id_remap_get('catalogue_category', $row['cc_id'], true); if (is_null($category_id)) { continue; } $map = array(); // Tedious... foreach (array('long', 'short', 'float', 'integer') as $table) { $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'catalogue_efv_' . $table . ' WHERE ce_id=' . strval((int) $row['id']), NULL, NULL, true); if (!is_null($rows2)) { foreach ($rows2 as $row2) { $remapped = import_id_remap_get('catalogue_field', $row2['cf_id'], true); if (is_null($remapped)) { continue; } $value = $row2['cv_value']; if (is_integer($value)) { $value = strval($value); } elseif (is_float($value)) { $value = float_to_raw_string($value); } $map[$remapped] = $value; } } } $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'catalogue_efv_long_trans WHERE ce_id=' . strval((int) $row['id'])); foreach ($rows2 as $row2) { $remapped = import_id_remap_get('catalogue_field', $row2['cf_id'], true); if (is_null($remapped)) { continue; } $map[$remapped] = $this->get_lang_string($db, $row2['cv_value']); } $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'catalogue_efv_short_trans WHERE ce_id=' . strval((int) $row['id'])); foreach ($rows2 as $row2) { $remapped = import_id_remap_get('catalogue_field', $row2['cf_id'], true); if (is_null($remapped)) { continue; } $map[$remapped] = $this->get_lang_string($db, $row2['cv_value']); } $submitter = $on_same_msn ? $row['ce_submitter'] : import_id_remap_get('member', $row['ce_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']; $id_new = actual_add_catalogue_entry($category_id, $row['ce_validated'], $row['notes'], $row['allow_rating'], $row['allow_comments'], $row['allow_trackbacks'], $map, $row['ce_add_date'], $submitter, $row['ce_edit_date'], $row['ce_views'], $id); import_id_remap_put('catalogue_entry', strval($row['id']), $id_new); } $this->_import_catalogue_entry_linkage($db, $table_prefix, 'catalogue', NULL); $this->_import_catalogue_entry_linkage($db, $table_prefix, 'catalogue_category', 'catalogue_category'); }
/** * 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_catalogue_faqs($db, $table_prefix, $old_base_dir) { require_code('catalogues2'); require_code('catalogues'); $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'faqs'))); $categories = $db->query("SELECT title,id FROM " . $table_prefix . "sections WHERE title='FAQs'"); foreach ($categories as $category) { $cat_title = $category['title']; $cat_id = $GLOBALS['SITE_DB']->query("SELECT CC.id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "translate AS T INNER JOIN " . $GLOBALS['SITE_DB']->get_table_prefix() . "catalogue_categories AS CC ON T.id=CC.cc_title AND T.text_original='" . db_escape_string($cat_title) . "' AND CC.c_name='faqs'"); if (count($cat_id) == 0) { $id = actual_add_catalogue_category('faqs', $category['title'], do_lang('DEFAULT_CATALOGUE_FAQS_DESCRIPTION'), '', NULL, ''); grant_catalogue_full_access($id); } else { $id = $cat_id[0]['id']; } $rows = $db->query('SELECT * FROM ' . $table_prefix . 'content WHERE sectionid=' . strval($category['id']) . " AND title NOT IN ('Joomla','utf8_general_ci','Uncategorized','Menu Item Manager','remove an Article','Trashing an Article','locale setting','edit window')"); foreach ($rows as $i => $row) { $i = 0; $val = htmlentities($row['title'], ENT_QUOTES); $val_id = $GLOBALS['SITE_DB']->query("SELECT id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "translate WHERE text_original='" . db_escape_string($val) . "'"); if (count($val_id) > 0) { $val = $val_id[0]['id']; $query = "SELECT CE.id FROM " . $GLOBALS['SITE_DB']->get_table_prefix() . "catalogue_entries AS CE INNER JOIN " . $GLOBALS['SITE_DB']->get_table_prefix() . "catalogue_efv_short_trans AS CES ON CES.ce_id=CE.id AND CES.cv_value='" . strval($val) . "' AND CE.c_name='faqs' AND CE.cc_id=" . strval($id); $faq_id = $GLOBALS['SITE_DB']->query($query); } else { $faq_id = array(); } if (count($faq_id) == 0) { $introtext = html_to_comcode($row['introtext']); $map = array($fields[0] => $row['title'], $fields[1] => $introtext, $fields[2] => strval($i)); actual_add_catalogue_entry($id, 1, '', 1, 1, 1, $map); } } } }
/** * 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_reviews($db, $table_prefix, $old_base_dir) { require_code('menus2'); //check is the comment forum configured in ocPortal $this->test_for_comments_forum(); //include calatogue lib require_code('catalogues2'); // Can we comment the news? $com = 1; //get comments forum name $forum_name = get_option('comments_forum_name'); ocf_over_msn(); //used to fixed the correct forum prefix $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name); ocf_over_local(); //used to fixed the correct forum prefix //get specific reviews fields $catalogues = $db->query('SELECT * FROM ' . $table_prefix . 'reviews_sections'); $include_reviews_link = false; //include reviews link only once //go through all of the reviews sections foreach ($catalogues as $catalogue) { //make catalogue lang string $catalogue_name = strtoupper(preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', 'review_' . $catalogue['title']))); $catalogue['title'] = @html_entity_decode($catalogue['title'], ENT_QUOTES, get_charset()); $specific_fields = array(); // Add reviews catalogue if it doesn't already exist $current_review_catalogue = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_name' => strtolower($catalogue_name))); if (is_null($current_review_catalogue)) { $current_review_catalogue = actual_add_catalogue(strtolower($catalogue_name), $catalogue['title'], '', 0, 0, '', 30); $fields = array(array(do_lang('REVIEW_TITLE'), '', 'short_trans', 0, 1), array(do_lang('REVIEW_DESCRIPTION'), '', 'long_trans', 1, 1), array(do_lang('REVIEW_IMAGE'), '', 'picture', 0, 1), array(do_lang('REVIEW_REVIEW'), '', 'long_trans', 0, 1)); $specific_fields = array(); //add review/catalogue specific fields for ($i = 1; $i < 7; $i++) { if (strlen($catalogue['field' . strval($i)]) > 0) { //make lang string $lang_string = strtoupper(preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', $catalogue['field' . strval($i)]))); $lang_string = do_lang($lang_string, NULL, NULL, NULL, NULL, false); if (is_null($lang_string)) { $lang_string = $catalogue['field' . strval($i)]; } $fields[] = array($lang_string, '', 'long_trans', 0, 1); $specific_fields[] = $i; } } //add fields to catalogue foreach ($fields as $i => $field) { actual_add_catalogue_field(strtolower($catalogue_name), $field[0], '', $field[2], $i, $field[3], 1, 1, '', $field[4]); } } //import current reviews category $review_category_id = actual_add_catalogue_category(strtolower($catalogue_name), $catalogue['title'], '', '', NULL, ''); //include reviews link in main features menu if (!$include_reviews_link) { add_menu_item_simple('main_features', NULL, 'REVIEWS', 'site:catalogues:category:' . strval($review_category_id)); add_menu_item_simple('main_features', NULL, 'REVIEWS', 'site:catalogues:index:' . strtolower($catalogue_name)); $include_reviews_link = true; } $remappped_fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => strtolower($catalogue_name)))); //select all reviews for current review catalogue $rows = $db->query('SELECT r.id AS review_id, r.title AS review_title, r.description AS review_description, r.field1 AS rf1, r.field2 AS rf2, r.field3 AS rf3, r.field4 AS rf4, r.field5 AS rf5, r.field6 AS rf6, r.field7 AS rf7, r.*, rc.title AS rc_title, rc.description AS rc_description, rc.field1 AS rcf1, rc.field2 AS rcf2, rc.field3 AS rcf3, rc.field4 AS rcf4, rc.field5 AS rcf5, rc.field6 AS rcf6, rc.field7 AS rcf7, rc.* FROM ' . $table_prefix . 'reviews r LEFT JOIN ' . $table_prefix . 'reviews_sections rc ON r.id_cat=rc.id WHERE r.id_cat=' . strval($catalogue['id'])); foreach ($rows as $row) { ocf_over_msn(); //used to fixed the correct forum prefix $map = array($remappped_fields[0] => html_to_comcode($row['review_title']), $remappped_fields[1] => html_to_comcode($row['review_description']), $remappped_fields[2] => $row['image'], $remappped_fields[3] => html_to_comcode($row['review'])); $map_next_ind = count($map); foreach ($specific_fields as $field_num) { if (!isset($remappped_fields[$map_next_ind])) { break; } // Don't want to import non-used fields $map[$remappped_fields[$map_next_ind]] = html_to_comcode($row['rf' . strval($field_num + 1)]); $map_next_ind++; } $new_id = actual_add_catalogue_entry($review_category_id, $row['validate'], '', 0, 0, 0, $map, $row['date'], $GLOBALS['FORUM_DRIVER']->get_member_from_username($row['author']), NULL, $row['click']); ocf_over_local(); //used to fixed the correct forum prefix //import rating too $this->_import_ratings($db, 'catalogues', $row['id'], $new_id, $row['rate'], $table_prefix); // Comments $comments = $db->query('SELECT * FROM ' . $table_prefix . 'reviews_comments WHERE id=' . strval($row['review_id']) . ' ORDER BY data'); if (!is_null($forum_id)) { foreach ($comments as $comment) { $member = $comment['id_autore']; //$GLOBALS['FORUM_DRIVER']->get_member_from_username($comment['userid']); ocf_over_msn(); //used to fixed the correct forum prefix if (is_null($member)) { $member = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } ocf_over_local(); //used to fixed the correct forum prefix $title = $row['review_title']; $post = $comment['testo']; $content_url = build_url(array('page' => 'catalogues', 'id' => $new_id, 'type' => 'view'), get_module_zone('catalogues')); ocf_over_msn(); //used to fixed the correct forum prefix $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum_name, 'reviews_' . strval($new_id), $member, $title, html_to_comcode($post), $row['review_title'], do_lang('COMMENT'), $content_url->evaluate()); ocf_over_local(); //used to fixed the correct forum prefix } } } } }
/** * 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_contacts($db, $table_prefix, $old_base_dir) { require_code('catalogues2'); require_code('catalogues'); // Add contacts catalogue if it doesn't already exist $test = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_name' => 'contacts')); if (is_null($test)) { actual_add_catalogue('contacts', lang_code_to_default_content('CONTACTS', false, 2), insert_lang('', 2), 0, 0, '', 30); $fields = array(array('CONTACT_FIRST_NAME', '', 'short_text', 0, 1), array('CONTACT_LAST_NAME', '', 'short_text', 1, 1), array('EMAIL_ADDRESS', '', 'short_text', 0, 1), array('CONTACT_COMPANY', '', 'short_text', 0, 1), array('CONTACT_HOMEADDRESS', '', 'short_text', 0, 1), array('CONTACT_CITY', '', 'short_text', 0, 1), array('CONTACT_HOMEPHONE', '', 'short_text', 0, 1), array('CONTACT_WORKPHONE', '', 'short_text', 0, 1), array('CONTACT_HOMEPAGE', '', 'short_text', 0, 1), array('CONTACT_IM', '', 'short_text', 0, 1), array('CONTACT_EVENTS', '', 'long_text', 0, 1), array('CONTACT_NOTES', '', 'long_text', 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('contacts', lang_code_to_default_content($field[0], false, 3), insert_lang('', 2), $field[2], $i, $field[3], 1, 1, '', $field[4]); } } $id = actual_add_catalogue_category('contacts', 'ex-phpNuke', '', '', NULL, ''); $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'contacts'))); $contacts = $db->query('SELECT * FROM ' . $table_prefix . 'contactbook'); foreach ($contacts as $row) { $map = array($fields[0] => $row['firstname'], $fields[1] => $row['lastname'], $fields[2] => $row['email'], $fields[3] => $row['company'], $fields[4] => $row['homeaddress'], $fields[5] => $row['city'], $fields[6] => $row['homephone'], $fields[7] => $row['workphone'], $fields[8] => $row['homepage'], $fields[9] => $row['IM'], $fields[10] => $row['events'], $fields[11] => $row['notes']); actual_add_catalogue_entry($id, 1, '', 0, 0, 0, $map); } }
function do_work() { $num_wanted = 100000; require_code('config2'); set_option('post_history_days', '0'); // Needed for a little sanity in recent post retrieval set_value('disable_sunk', '1'); // members (remember to test the username autocompleter, and birthdays) // authors (remember to check author autocompleter and popup author list) // lots of people getting notifications on a forum // lots of people getting notifications on a topic require_code('authors'); require_code('ocf_members_action'); require_code('notifications'); for ($i = $GLOBALS['FORUM_DB']->query_value('f_members', 'COUNT(*)'); $i < $num_wanted; $i++) { $member_id = ocf_make_member(uniqid('', true), uniqid('', true), uniqid('', true) . '@example.com', array(), intval(date('d')), intval(date('m')), intval(date('Y')), array(), NULL, NULL, 1, NULL, NULL, '', NULL, '', 0, 0, 1, '', '', '', 1, 1, NULL, 1, 1, '', NULL, '', false); add_author(random_line(), '', $member_id, random_text(), random_text()); enable_notifications('ocf_topic', 'forum:' . strval(db_get_first_id()), $member_id); enable_notifications('ocf_topic', strval(db_get_first_id()), $member_id); // number of friends to a single member $GLOBALS['SITE_DB']->query_insert('chat_buddies', array('member_likes' => $member_id, 'member_liked' => db_get_first_id() + 1, 'date_and_time' => time()), false, true); } $member_id = db_get_first_id() + 2; // point earn list / gift points to a single member require_code('points2'); for ($j = $GLOBALS['SITE_DB']->query_value('gifts', 'COUNT(*)'); $j < $num_wanted; $j++) { give_points(10, $member_id, mt_rand(db_get_first_id(), min(100, $num_wanted - 1)), random_line(), false, false); } // number of friends of a single member for ($j = intval(floatval($GLOBALS['SITE_DB']->query_value('chat_buddies', 'COUNT(*)')) / 2.0); $j < $num_wanted; $j++) { $GLOBALS['SITE_DB']->query_insert('chat_buddies', array('member_likes' => $member_id, 'member_liked' => $j + db_get_first_id(), 'date_and_time' => time()), false, true); } echo 'done member/authors/points/notifications/friends stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // banners require_code('banners2'); for ($i = $GLOBALS['SITE_DB']->query_value('banners', 'COUNT(*)'); $i < $num_wanted; $i++) { add_banner(uniqid('', true), get_logo_url(), random_line(), random_text(), 100, get_base_url(), 3, '', db_get_first_id(), NULL, db_get_first_id() + 1, 1); } echo 'done banner stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // comcode pages require_code('files'); require_code('files2'); for ($i = $GLOBALS['SITE_DB']->query_value('comcode_pages', 'COUNT(*)'); $i < $num_wanted; $i++) { $file = uniqid('', true); /*$path=get_custom_file_base().'/site/pages/comcode_custom/'.fallback_lang().'/'.$file.'.txt'; $myfile=fopen($path,'wt'); fwrite($myfile,random_text()); fclose($myfile); sync_file($path); fix_permissions($path);*/ $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => 'site', 'the_page' => $file, 'p_parent_page' => '', 'p_validated' => 1, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => db_get_first_id(), 'p_show_as_edit' => 0)); } echo 'done comcode stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // zones require_code('zones2'); require_code('abstract_file_manager'); for ($i = $GLOBALS['SITE_DB']->query_value('zones', 'COUNT(*)'); $i < min($num_wanted, 1000); $i++) { actual_add_zone(uniqid('', true), random_line(), 'start', random_line(), 'default', 0, 0, 0); } echo 'done zone stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // calendar events require_code('calendar2'); for ($i = $GLOBALS['SITE_DB']->query_value('calendar_events', 'COUNT(*)'); $i < $num_wanted; $i++) { add_calendar_event(db_get_first_id(), '', NULL, 0, random_line(), random_text(), 1, 1, intval(date('Y')), intval(date('m')), intval(date('d')), 0, 0); } echo 'done event stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // chat rooms require_code('chat2'); require_code('chat'); for ($i = $GLOBALS['SITE_DB']->query_value('chat_rooms', 'COUNT(*)'); $i < $num_wanted; $i++) { $room_id = add_chatroom(random_text(), random_line(), mt_rand(db_get_first_id() + 1, $num_wanted - 1), strval(db_get_first_id() + 1), '', '', '', fallback_lang()); } $room_id = db_get_first_id() + 1; // messages in chat room for ($j = $GLOBALS['SITE_DB']->query_value('chat_messages', 'COUNT(*)'); $j < $num_wanted; $j++) { $_message_parsed = insert_lang_comcode(random_text(), 4); $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 0, 'ip_address' => '', 'room_id' => $room_id, 'user_id' => db_get_first_id(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font'))); } echo 'done chat stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // download categories under a subcategory require_code('downloads2'); $subcat_id = add_download_category(random_line(), db_get_first_id(), random_text(), ''); for ($i = $GLOBALS['SITE_DB']->query_value('download_categories', 'COUNT(*)'); $i < $num_wanted; $i++) { add_download_category(random_line(), $subcat_id, random_text(), ''); } // downloads (remember to test content by the single author) require_code('downloads2'); require_code('awards'); $time = time(); for ($i = $GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)'); $i < $num_wanted; $i++) { $content_id = add_download(db_get_first_id(), random_line(), get_logo_url(), random_text(), 'admin', random_text(), NULL, 1, 1, 1, 1, '', uniqid('', true) . '.jpg', 100, 110, 1); give_award(db_get_first_id(), strval($content_id), $time - $i); } $content_id = db_get_first_id(); $content_url = build_url(array('page' => 'downloads', 'type' => 'entry', 'id' => $content_id), 'site'); for ($j = $GLOBALS['SITE_DB']->query_value('trackbacks', 'COUNT(*)'); $j < $num_wanted; $j++) { // trackbacks $GLOBALS['SITE_DB']->query_insert('trackbacks', array('trackback_for_type' => 'downloads', 'trackback_for_id' => $content_id, 'trackback_ip' => '', 'trackback_time' => time(), 'trackback_url' => '', 'trackback_title' => random_line(), 'trackback_excerpt' => random_text(), 'trackback_name' => random_line())); // ratings $GLOBALS['SITE_DB']->query_insert('rating', array('rating_for_type' => 'downloads', 'rating_for_id' => $content_id, 'rating_member' => $j + 1, 'rating_ip' => '', 'rating_time' => time(), 'rating' => 3)); // posts in a comment topic $GLOBALS['FORUM_DRIVER']->make_post_forum_topic(get_option('comments_forum_name'), 'downloads_' . strval($content_id), get_member(), random_text(), random_line(), '', do_lang('COMMENT'), $content_url->evaluate(), NULL, NULL, 1, 1); } echo 'done download stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // forums under a forum (don't test it can display, just make sure the main index still works) require_code('ocf_forums_action'); for ($i = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)'); $i < $num_wanted; $i++) { ocf_make_forum(random_line(), random_text(), db_get_first_id(), array(), db_get_first_id() + 3); } // forum topics require_code('ocf_topics_action'); require_code('ocf_posts_action'); require_code('ocf_forums'); require_code('ocf_topics'); for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_topics', 'COUNT(*)')) / 2.0); $i < $num_wanted; $i++) { $topic_id = ocf_make_topic(db_get_first_id(), '', '', NULL, 1, 0, 0, 0, NULL, NULL, false); ocf_make_post($topic_id, random_line(), random_text(), 0, true, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, false); } // forum posts in a topic require_code('ocf_topics_action'); require_code('ocf_posts_action'); $topic_id = ocf_make_topic(db_get_first_id() + 1, '', '', NULL, 1, 0, 0, 0, NULL, NULL, false); for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)')) / 3.0); $i < $num_wanted; $i++) { ocf_make_post($topic_id, random_line(), random_text(), 0, true, 0, 0, NULL, NULL, NULL, mt_rand(db_get_first_id(), $num_wanted - 1), NULL, NULL, NULL, false, false); } echo 'done forum stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // clubs require_code('ocf_groups_action'); require_code('ocf_groups'); for ($i = $GLOBALS['FORUM_DB']->query_value('f_groups', 'COUNT(*)'); $i < $num_wanted; $i++) { ocf_make_group(random_line(), 0, 0, 0, random_line(), '', NULL, NULL, NULL, 5, 0, 70, 50, 100, 100, 30000, 700, 25, 1, 0, 0, 0, $i, 1, 0, 1); } echo 'done club stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // galleries under a subcategory require_code('galleries2'); $xsubcat_id = uniqid('', true); add_gallery($xsubcat_id, random_line(), random_text(), '', '', 'root'); for ($i = $GLOBALS['SITE_DB']->query_value('galleries', 'COUNT(*)'); $i < $num_wanted; $i++) { add_gallery(uniqid('', true), random_line(), random_text(), '', '', $xsubcat_id); } // images require_code('galleries2'); for ($i = $GLOBALS['SITE_DB']->query_value('images', 'COUNT(*)'); $i < $num_wanted; $i++) { add_image('', 'root', random_text(), get_logo_url(), get_logo_url(), 1, 1, 1, 1, ''); } // videos / validation queue require_code('galleries2'); for ($i = $GLOBALS['SITE_DB']->query_value('videos', 'COUNT(*)'); $i < $num_wanted; $i++) { add_video('', 'root', random_text(), get_logo_url(), get_logo_url(), 0, 1, 1, 1, '', 0, 0, 0); } echo 'done galleries stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // newsletter subscribers require_code('newsletter'); for ($i = $GLOBALS['SITE_DB']->query_value('newsletter', 'COUNT(*)'); $i < $num_wanted; $i++) { basic_newsletter_join(uniqid('', true) . '@example.com'); } echo 'done newsletter stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // polls (remember to test poll archive) require_code('polls'); for ($i = $GLOBALS['SITE_DB']->query_value('poll', 'COUNT(*)'); $i < $num_wanted; $i++) { $poll_id = add_poll(random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), 10, 0, 0, 0, 0, ''); } // votes on a poll $poll_id = db_get_first_id(); for ($j = $GLOBALS['SITE_DB']->query_value('poll_votes', 'COUNT(*)'); $j < $num_wanted; $j++) { $cast = mt_rand(1, 6); $ip = uniqid('', true); $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $poll_id, 'v_voter_id' => 2, 'v_voter_ip' => $ip, 'v_vote_for' => $cast)); } echo 'done polls stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // quizzes require_code('quiz'); for ($i = $GLOBALS['SITE_DB']->query_value('quizzes', 'COUNT(*)'); $i < $num_wanted; $i++) { add_quiz(random_line(), 0, random_text(), random_text(), random_text(), '', 0, time(), NULL, 3, 300, 'SURVEY', 1, '1) Some question'); } echo 'done quizzes stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // successful searches (to test the search recommender) // ACTUALLY: I have manually verified the code, it is an isolated portion // cedi pages (do a long descendant tree for some, and orphans for others) // cedi posts (remember to test cedi changes screen) require_code('cedi'); for ($i = $GLOBALS['SITE_DB']->query_value('seedy_pages', 'COUNT(*)'); $i < $num_wanted; $i++) { $page_id = cedi_add_page(random_line(), random_text(), '', 1); cedi_add_post($page_id, random_text(), 1, NULL, false); } echo 'done cedi stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // iotds require_code('iotds'); for ($i = $GLOBALS['SITE_DB']->query_value('iotd', 'COUNT(*)'); $i < $num_wanted; $i++) { add_iotd(get_logo_url(), random_line(), random_text(), get_logo_url(), 1, 0, 0, 0, ''); } echo 'done iotd stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // logged hack attempts for ($i = $GLOBALS['SITE_DB']->query_value('hackattack', 'COUNT(*)'); $i < $num_wanted; $i++) { $GLOBALS['SITE_DB']->query_insert('hackattack', array('url' => get_base_url(), 'data_post' => '', 'user_agent' => '', 'referer' => '', 'user_os' => '', 'the_user' => db_get_first_id(), 'date_and_time' => time(), 'ip' => uniqid('', true), 'reason' => 'ASCII_ENTITY_URL_HACK', 'reason_param_a' => '', 'reason_param_b' => '')); } // logged hits in one day require_code('site'); for ($i = $GLOBALS['SITE_DB']->query_value('stats', 'COUNT(*)'); $i < $num_wanted; $i++) { log_stats('/testing' . uniqid('', true), mt_rand(100, 2000)); } echo 'done logs stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // blogs and news entries (remember to test both blogs [categories] list, and a list of all news entries) require_code('news'); for ($i = $GLOBALS['SITE_DB']->query_value('news', 'COUNT(*)'); $i < $num_wanted; $i++) { add_news(random_line(), random_text(), 'admin', 1, 1, 1, 1, '', random_text(), NULL, NULL, NULL, db_get_first_id() + $i); } echo 'done news stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // support tickets require_code('tickets'); require_code('tickets2'); for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_topics', 'COUNT(*)')) / 2.0); $i < $num_wanted; $i++) { ticket_add_post(mt_rand(db_get_first_id(), $num_wanted - 1), uniqid('', true), db_get_first_id(), random_line(), random_text(), '', ''); } echo 'done tickets stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // catalogues require_code('catalogues2'); $root_id = db_get_first_id(); for ($i = $GLOBALS['SITE_DB']->query_value('catalogues', 'COUNT(*)'); $i < $num_wanted; $i++) { $catalogue_name = uniqid('', true); $root_id = actual_add_catalogue($catalogue_name, random_line(), random_text(), mt_rand(0, 3), 1, '', 30); } // catalogue categories under a subcategory (remember to test all catalogue views: atoz, index, and root cat) $catalogue_name = 'products'; $subcat_id = actual_add_catalogue_category($catalogue_name, random_line(), random_text(), '', $root_id); for ($j = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'COUNT(*)'); $j < $num_wanted; $j++) { actual_add_catalogue_category($catalogue_name, random_line(), random_text(), '', $subcat_id); } echo 'done catalogue stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // items in ecommerce store require_code('catalogues2'); $cat_id = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'MIN(id)', array('c_name' => 'products')); $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'products'))); for ($i = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'COUNT(*)'); $i < $num_wanted; $i++) { $map = array($fields[0] => random_line(), $fields[1] => uniqid('', true), $fields[2] => '1.0', $fields[3] => '1', $fields[4] => '0', $fields[5] => '1', $fields[6] => '0%', $fields[7] => get_logo_url(), $fields[8] => '2.0', $fields[9] => random_text()); $pid = actual_add_catalogue_entry($cat_id, 1, '', 1, 1, 1, $map); unset($map); } // outstanding ecommerce orders $pid = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'MIN(id)', array('c_name' => 'products')); require_code('shopping'); for ($j = $GLOBALS['SITE_DB']->query_value('shopping_cart', 'COUNT(*)'); $j < $num_wanted; $j++) { $product_det = array('product_id' => $pid, 'product_name' => $fields[0], 'product_code' => $fields[1], 'price' => $fields[2], 'tax' => preg_replace('#[^\\d\\.]#', '', $fields[6]), 'description' => $fields[9], 'quantity' => mt_rand(1, 20), 'product_type' => 'catalogue_items', 'product_weight' => $fields[8]); $GLOBALS['SITE_DB']->query_insert('shopping_cart', array('session_id' => mt_rand(0, 1000000), 'ordered_by' => mt_rand(db_get_first_id() + 1, $num_wanted - 1), 'product_id' => $product_det['product_id'], 'product_name' => $product_det['product_name'], 'product_code' => $product_det['product_code'], 'quantity' => $product_det['quantity'], 'price' => round(floatval($product_det['price']), 2), 'price_pre_tax' => $product_det['tax'], 'product_description' => $product_det['description'], 'product_type' => $product_det['product_type'], 'product_weight' => $product_det['product_weight'], 'is_deleted' => 0)); } for ($j = $GLOBALS['SITE_DB']->query_value('shopping_order', 'COUNT(*)'); $j < $num_wanted; $j++) { $order_id = $GLOBALS['SITE_DB']->query_insert('shopping_order', array('c_member' => mt_rand(db_get_first_id() + 1, $num_wanted - 1), 'session_id' => mt_rand(0, 1000000), 'add_date' => time(), 'tot_price' => '123.00', 'order_status' => 'ORDER_STATUS_awaiting_payment', 'notes' => '', 'purchase_through' => 'purchase_module', 'transaction_id' => '', 'tax_opted_out' => 0), true); $GLOBALS['SITE_DB']->query_insert('shopping_order_details', array('p_id' => 123, 'p_name' => random_line(), 'p_code' => 123, 'p_type' => 'catalogue_items', 'p_quantity' => 1, 'p_price' => '12.00', 'order_id' => $order_id, 'dispatch_status' => '', 'included_tax' => '1.00')); } echo 'done store stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } echo '{{DONE}}' . chr(10); }
/** * Standard aed_module add actualiser. * * @return ID_TEXT The entry added */ function add_actualisation() { require_code('catalogues2'); $name = post_param('name'); $title = post_param('title'); $description = post_param('description'); $display_type = post_param_integer('display_type'); $is_tree = post_param_integer('is_tree', 0); $this->is_tree_catalogue = $is_tree == 1; $notes = post_param('notes', ''); $submit_points = post_param_integer('submit_points', 0); $cat_tab = post_param_integer('cat_tab', 0); $ecommerce = post_param_integer('ecommerce', 0); $send_view_reports = post_param('send_view_reports'); // What fields do we have? $new = array(); foreach ($_POST as $key => $val) { if (!is_string($val) && !is_integer($val)) { continue; } if (get_magic_quotes_gpc()) { $val = stripslashes($val); } $matches = array(); if (preg_match('#new_field_(\\d*)_(.*)#A', $key, $matches) != 0) { $new[$matches[1]][$matches[2]] = $val; } } $num_fields = 0; foreach ($new as $field) { if ($field['name'] != '') { $num_fields++; } } if ($num_fields == 0) { warn_exit(do_lang_tempcode('NO_FIELDS')); } $category_id = actual_add_catalogue($name, $title, $description, $display_type, $is_tree, $notes, $submit_points, $ecommerce, $send_view_reports); $this->set_permissions($name); if (!is_null($category_id)) { $GLOBALS['MODULE_CMS_CATALOGUES']->cat_aed_module->set_permissions(strval($category_id)); } // Now onto the fields foreach ($new as $field) { if (!array_key_exists('default', $field)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if (!array_key_exists('description', $field)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if (!array_key_exists('name', $field)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if (!array_key_exists('order', $field)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if (!array_key_exists('type', $field) || $field['type'] == '') { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } if ($field['order'] == '') { $field['order'] = 0; } else { $field['order'] = intval($field['order']); } $defines_order = array_key_exists('defines_order', $field) ? intval($field['defines_order']) : 0; $visible = array_key_exists('visible', $field) ? intval($field['visible']) : 0; $searchable = array_key_exists('searchable', $field) ? intval($field['searchable']) : 0; $required = array_key_exists('required', $field) ? intval($field['required']) : 0; $put_in_category = array_key_exists('put_in_category', $field) ? intval($field['put_in_category']) : 0; $put_in_search = array_key_exists('put_in_search', $field) ? intval($field['put_in_search']) : 0; if ($field['name'] != '') { actual_add_catalogue_field($name, $field['name'], $field['description'], $field['type'], $field['order'], $defines_order, $visible, $searchable, $field['default'], $required, $put_in_category, $put_in_search); } } $add_to_menu = post_param_integer('add_to_menu', 0); if ($add_to_menu == 1) { require_code('menus2'); if ($is_tree == 1) { add_menu_item_simple('main_content', NULL, $title, '_SEARCH:catalogues:type=category:catalogue_name=' . $name); } else { add_menu_item_simple('main_content', NULL, $title, '_SEARCH:catalogues:type=index:' . $name); } } // Auto-fill feature $auto_fill = post_param('auto_fill'); if ($auto_fill != '') { $categories = array(); if (strpos($auto_fill, '|') === false) { $to_do = explode(',', $auto_fill); } else { $to_do = explode('|', $auto_fill); } foreach ($to_do as $doing) { if (trim($doing) == '') { continue; } $bits = explode('\\', $doing); $parent_id = $category_id; foreach ($bits as $bit) { $bit = trim($bit); if (array_key_exists($bit, $categories)) { if (!is_null($parent_id)) { $parent_id = $categories[$bit]; } } else { $_parent_id = actual_add_catalogue_category($name, $bit, '', '', $parent_id, ''); if (!is_null($parent_id)) { $parent_id = $_parent_id; } require_code('permissions2'); if (get_value('disable_cat_cat_perms') !== '1') { set_category_permissions_from_environment('catalogues_category', strval($parent_id), $this->permission_page); } $categories[$bit] = $parent_id; } } } } if ($is_tree == 0 && substr($name, 0, 1) != '_') { $this->do_next_description = paragraph(do_lang_tempcode('SUGGEST_ADD_CATEGORY_NEXT')); } return $name; }
/** * Standard modular install function. * * @param ?integer What version we're upgrading from (NULL: new install) * @param ?integer What hack version we're upgrading from (NULL: new-install/not-upgrading-from-a-hacked-version) */ function install($upgrade_from = NULL, $upgrade_from_hack = NULL) { require_lang('catalogues'); require_code('catalogues'); require_code('catalogues2'); if (is_null($upgrade_from)) { $GLOBALS['SITE_DB']->create_table('catalogues', array('c_name' => '*ID_TEXT', 'c_title' => 'SHORT_TRANS', 'c_description' => 'LONG_TRANS', 'c_display_type' => 'SHORT_INTEGER', 'c_is_tree' => 'BINARY', 'c_notes' => 'LONG_TEXT', 'c_add_date' => 'TIME', 'c_submit_points' => 'INTEGER', 'c_ecommerce' => 'BINARY', 'c_send_view_reports' => 'ID_TEXT')); $GLOBALS['SITE_DB']->create_table('catalogue_categories', array('id' => '*AUTO', 'c_name' => 'ID_TEXT', 'cc_title' => 'SHORT_TRANS', 'cc_description' => 'LONG_TRANS', 'rep_image' => 'URLPATH', 'cc_notes' => 'LONG_TEXT', 'cc_add_date' => 'TIME', 'cc_parent_id' => '?AUTO_LINK', 'cc_move_target' => '?AUTO_LINK', 'cc_move_days_lower' => 'INTEGER', 'cc_move_days_higher' => 'INTEGER')); $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'catstoclean', array('cc_move_target')); $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'cataloguefind', array('c_name')); } if (is_null($upgrade_from) || $upgrade_from < 6) { $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'cc_parent_id', array('cc_parent_id')); } if (is_null($upgrade_from)) { $GLOBALS['SITE_DB']->create_table('catalogue_fields', array('id' => '*AUTO', 'c_name' => 'ID_TEXT', 'cf_name' => 'SHORT_TRANS', 'cf_description' => 'LONG_TRANS', 'cf_type' => 'ID_TEXT', 'cf_order' => 'INTEGER', 'cf_defines_order' => 'SHORT_INTEGER', 'cf_visible' => 'BINARY', 'cf_searchable' => 'BINARY', 'cf_default' => 'LONG_TEXT', 'cf_required' => 'BINARY', 'cf_put_in_category' => 'BINARY', 'cf_put_in_search' => 'BINARY')); $GLOBALS['SITE_DB']->create_table('catalogue_entries', array('id' => '*AUTO', 'c_name' => 'ID_TEXT', 'cc_id' => 'AUTO_LINK', 'ce_submitter' => 'USER', 'ce_add_date' => 'TIME', 'ce_edit_date' => '?TIME', 'ce_views' => 'INTEGER', 'ce_views_prior' => 'INTEGER', 'ce_validated' => 'BINARY', 'notes' => 'LONG_TEXT', 'allow_rating' => 'BINARY', 'allow_comments' => 'SHORT_INTEGER', 'allow_trackbacks' => 'BINARY', 'ce_last_moved' => 'INTEGER')); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_views', array('ce_views')); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ces', array('ce_submitter')); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_validated', array('ce_validated')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_long_trans', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => 'LONG_TRANS')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_long', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => 'LONG_TEXT')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_short_trans', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => 'SHORT_TRANS')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_short', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => 'SHORT_TEXT')); } if (is_null($upgrade_from) || $upgrade_from < 6) { $GLOBALS['SITE_DB']->create_table('catalogue_entry_linkage', array('catalogue_entry_id' => '*AUTO_LINK', 'content_type' => 'ID_TEXT', 'content_id' => 'ID_TEXT')); $GLOBALS['SITE_DB']->create_index('catalogue_entry_linkage', 'custom_fields', array('content_type', 'content_id')); // This caches ancestor relationships. It is redundant to doing tree traversals on catalogue_categories.cc_id, allowing normal efficient SQL joins to be done instead // Note that self relationships (cc_id=cc_ancestor_id) are stored too, so that a single join covers that too. $GLOBALS['SITE_DB']->create_table('catalogue_cat_treecache', array('cc_id' => '*AUTO_LINK', 'cc_ancestor_id' => '*AUTO_LINK')); $GLOBALS['SITE_DB']->create_table('catalogue_childcountcache', array('cc_id' => '*AUTO_LINK', 'c_num_rec_children' => 'INTEGER', 'c_num_rec_entries' => 'INTEGER')); $GLOBALS['SITE_DB']->create_index('catalogue_cat_treecache', 'cc_ancestor_id', array('cc_ancestor_id')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_float', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => '?REAL')); $GLOBALS['SITE_DB']->create_table('catalogue_efv_integer', array('id' => '*AUTO', 'cf_id' => 'AUTO_LINK', 'ce_id' => 'AUTO_LINK', 'cv_value' => '?INTEGER')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_float', 'fcv_value', array('cv_value')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_integer', 'itv_value', array('cv_value')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_float', 'fcf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_integer', 'icf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_float', 'fce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_integer', 'ice_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_float', 'cefv_f_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_integer', 'cefv_i_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long', 'cefv_l_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', 'cefv_s_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long_trans', 'cefv_lt_combo', array('ce_id', 'cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short_trans', 'cefv_st_combo', array('ce_id', 'cf_id'), 'id'); } if (is_null($upgrade_from)) { // Add the default catalogues // ========================== $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); // Projects actual_add_catalogue('projects', lang_code_to_default_content('DEFAULT_CATALOGUE_PROJECTS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_PROJECTS_DESCRIPTION', true, 3), 0, 0, '', 30); $fields = array(array('NAME', 'DESCRIPTION_NAME', 'short_trans', 1, 1), array('MAINTAINER', 'DESCRIPTION_MAINTAINER', 'user', 0, 1), array('DESCRIPTION', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 1), array('PROJECT_PROGRESS', 'DESCRIPTION_PROJECT_PROGRESS', 'integer', 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('projects', lang_code_to_default_content($field[0], false, 3), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], 1, 1, '', $field[4]); } $cat_id = actual_add_catalogue_category('projects', lang_code_to_default_content('DEFAULT_CATALOGUE_PROJECTS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_PROJECTS_DESCRIPTION', true, 3), '', NULL, ''); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($cat_id), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'projects', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_PROJECTS_TITLE', '_SEARCH:catalogues:type=index:id=projects'); // Modifications actual_add_catalogue('modifications', lang_code_to_default_content('DEFAULT_CATALOGUE_MODIFICATIONS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_MODIFICATIONS_DESCRIPTION', true, 3), 1, 0, '', 60); $fields = array(array('NAME', 'DESCRIPTION_NAME', 'short_trans', 1, 1), array('IMAGE', 'DESCRIPTION_MODIFICATION_IMAGE_URL', 'picture', 0, 0), array('STATUS', 'DESCRIPTION_MODIFICATION_STATUS', 'short_trans', 0, 1), array('URL', 'DESCRIPTION_URL', 'url', 0, 0), array('DESCRIPTION', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 1), array('AUTHOR', 'DESCRIPTION_AUTHOR', 'short_text', 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('modifications', lang_code_to_default_content($field[0], false, 3), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], 1, 1, '', $field[4]); } foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'modifications', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_MODIFICATIONS_TITLE', '_SEARCH:catalogues:type=index:id=modifications'); // Hosted-sites actual_add_catalogue('hosted', lang_code_to_default_content('DEFAULT_CATALOGUE_HOSTED_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_HOSTED_DESCRIPTION', true, 3), 0, 0, '', 0); $fields = array(array('NAME', 'DESCRIPTION_NAME', 'short_trans', 1, 1), array('URL', 'DESCRIPTION_URL', 'url', 0, 0), array('DESCRIPTION', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 0)); foreach ($fields as $i => $field) { actual_add_catalogue_field('hosted', lang_code_to_default_content($field[0], false, 2), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], 1, 1, '', $field[4]); } $cat_id = actual_add_catalogue_category('hosted', lang_code_to_default_content('DEFAULT_CATALOGUE_HOSTED_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_HOSTED_DESCRIPTION', true, 3), '', NULL, ''); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($cat_id), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'hosted', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_HOSTED_TITLE', '_SEARCH:catalogues:type=index:id=hosted'); // Links $links_category = actual_add_catalogue('links', lang_code_to_default_content('DEFAULT_CATALOGUE_LINKS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_LINKS_DESCRIPTION', true, 3), 2, 1, '', 0); $fields = array(array('TITLE', 'DESCRIPTION_TITLE', 'short_trans', 1, 1, 1), array('URL', 'DESCRIPTION_URL', 'url', 0, 1, 0), array('DESCRIPTION', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('links', lang_code_to_default_content($field[0], false, 2), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], 1, 1, '', $field[4], $field[5]); } foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($links_category), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'links', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_LINKS_TITLE', '_SEARCH:catalogues:type=index:id=links'); // FAQs actual_add_catalogue('faqs', lang_code_to_default_content('DEFAULT_CATALOGUE_FAQS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_FAQS_DESCRIPTION', true, 3), 0, 0, '', 0); $fields = array(array('QUESTION', 'DESCRIPTON_QUESTION', 'short_trans', 0, 1, 1), array('ANSWER', '_DESCRIPTION_ANSWER', 'long_trans', 0, 1, 1), array('ORDER', 'DESCRIPTION_ORDER', 'auto_increment', 1, 0, 0)); foreach ($fields as $i => $field) { actual_add_catalogue_field('faqs', lang_code_to_default_content($field[0], false, 2), lang_code_to_default_content($field[1], true, 3), $field[2], $i, $field[3], $field[5], 1, '', $field[4]); } $cat_id = actual_add_catalogue_category('faqs', lang_code_to_default_content('DEFAULT_CATALOGUE_FAQS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_FAQS_DESCRIPTION', true, 3), '', NULL, ''); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($cat_id), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'faqs', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_FAQS_TITLE', '_SEARCH:catalogues:type=index:id=faqs'); // Contacts actual_add_catalogue('contacts', lang_code_to_default_content('CONTACTS', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_CONTACTS_DESCRIPTION', true, 3), 0, 0, '', 30); $fields = array(array('CONTACT_FIRST_NAME', '', 'short_text', 0, 1), array('CONTACT_LAST_NAME', '', 'short_text', 1, 1), array('EMAIL_ADDRESS', '', 'short_text', 0, 1), array('CONTACT_COMPANY', '', 'short_text', 0, 1), array('CONTACT_HOMEADDRESS', '', 'short_text', 0, 1), array('CONTACT_CITY', '', 'short_text', 0, 1), array('CONTACT_HOMEPHONE', '', 'short_text', 0, 1), array('CONTACT_WORKPHONE', '', 'short_text', 0, 1), array('CONTACT_HOMEPAGE', '', 'short_text', 0, 1), array('CONTACT_IM', '', 'short_text', 0, 1), array('CONTACT_EVENTS', '', 'long_text', 0, 1), array('CONTACT_NOTES', '', 'long_text', 0, 1), array('CONTACT_PHOTO', '', 'picture', 0, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('contacts', lang_code_to_default_content($field[0], false, 3), insert_lang('', 2), $field[2], $i, $field[3], 1, 1, '', $field[4]); } actual_add_catalogue_category('contacts', lang_code_to_default_content('CONTACTS', false, 2), '', '', NULL, ''); add_menu_item_simple('main_content', NULL, 'CONTACTS', '_SEARCH:catalogues:type=index:id=contacts'); $projects = add_menu_item_simple('collab_features', NULL, 'DEFAULT_CATALOGUE_PROJECTS_TITLE'); add_menu_item_simple('collab_features', $projects, 'VIEW', '_SEARCH:catalogues:id=projects:type=index', 0, 0, true, do_lang('ZONE_BETWEEN'), 1); add_menu_item_simple('collab_features', $projects, 'ADD', '_SEARCH:cms_catalogues:catalogue_name=projects:type=add_entry', 0, 0, true, do_lang('ZONE_BETWEEN'), 1); } if (is_null($upgrade_from) || $upgrade_from < 6) { $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_add_date', array('ce_add_date'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_c_name', array('c_name'), 'id'); } if (!is_null($upgrade_from) && $upgrade_from < 4) { $GLOBALS['SITE_DB']->delete_table_field('catalogues', 'c_own_template'); $GLOBALS['SITE_DB']->add_table_field('catalogues', 'c_cat_tab', 'BINARY', 0); $GLOBALS['SITE_DB']->add_table_field('catalogues', 'c_ecommerce', 'BINARY', 0); $GLOBALS['SITE_DB']->add_table_field('catalogue_entries', 'ce_views_prior', 'INTEGER'); $GLOBALS['SITE_DB']->add_table_field('catalogues', 'c_send_view_reports', 'ID_TEXT', 'never'); $GLOBALS['SITE_DB']->add_table_field('catalogue_categories', 'cc_move_target', '?AUTO_LINK', NULL); $GLOBALS['SITE_DB']->add_table_field('catalogue_categories', 'cc_move_days_lower', 'INTEGER', 30); $GLOBALS['SITE_DB']->add_table_field('catalogue_categories', 'cc_move_days_higher', 'INTEGER', 60); $GLOBALS['SITE_DB']->add_table_field('catalogue_entries', 'ce_last_moved', 'INTEGER', 0); $GLOBALS['SITE_DB']->query('UPDATE ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_entries SET ce_last_moved=ce_add_date'); } if (is_null($upgrade_from) || $upgrade_from < 3) { $cat_id = actual_add_catalogue('products', lang_code_to_default_content('DEFAULT_CATALOGUE_PRODUCTS_TITLE', false, 2), lang_code_to_default_content('DEFAULT_CATALOGUE_PRODUCTS_DESCRIPTION', false, 2), 1, 1, '', 0, 1); $fields = array(array('ECOM_CAT_product_title', 'DESCRIPTION_TITLE', 'short_trans', 1, 1, 1, 1), array('ECOM_CAT_item_code', 'ECOM_CATD_item_code', 'random', 0, 1, 1, 1), array('ECOM_CAT_price_pre_tax', 'ECOM_CATD_price_pre_tax', 'float', 0, 1, 1, 1), array('ECOM_CAT_stock_level', 'ECOM_CATD_stock_level', 'integer', 0, 0, 1, 0), array('ECOM_CAT_stock_level_warn_at', 'ECOM_CATD_stock_level_warn_at', 'integer', 0, 0, 0, 0), array('ECOM_CAT_stock_level_maintain', 'ECOM_CATD_stock_level_maintain', 'tick', 0, 1, 0, 0), array('ECOM_CAT_tax_type', 'ECOM_CATD_tax_type', 'list', 0, 1, 0, 0, "0%|5%|17.5%", 0), array('ECOM_CAT_image', 'ECOM_CATD_image', 'picture', 0, 0, 1, 1), array('ECOM_CAT_weight', 'ECOM_CATD_weight', 'float', 0, 1, 0, 0), array('ECOM_CAT_description', 'DESCRIPTION_DESCRIPTION', 'long_trans', 0, 1, 1, 1)); foreach ($fields as $i => $field) { actual_add_catalogue_field('products', lang_code_to_default_content($field[0], false, 3), lang_code_to_default_content($field[1], true, 3), $field[2] == 'tick' ? 'list' : $field[2], $i, $field[3], $field[5], $field[6], $field[2] == 'tick' ? do_lang('NO') . '|' . do_lang('YES') : (array_key_exists(7, $field) ? $field[7] : ''), $field[4], array_key_exists(5, $field) ? $field[5] : 0, array_key_exists(5, $field) ? $field[5] : 0); } foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_category', 'category_name' => strval($cat_id), 'group_id' => $group_id)); $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'catalogues_catalogue', 'category_name' => 'products', 'group_id' => $group_id)); } add_menu_item_simple('main_content', NULL, 'DEFAULT_CATALOGUE_PRODUCTS_TITLE', '_SEARCH:catalogues:type=category:catalogue_name=products'); add_specific_permission('CATALOGUES', 'high_catalogue_entry_timeout', false); } if (is_null($upgrade_from) || $upgrade_from < 3) { $GLOBALS['SITE_DB']->create_index('catalogue_efv_long', '#lcv_value', array('cv_value'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', '#scv_value', array('cv_value'), 'id'); } if (!is_null($upgrade_from) && $upgrade_from < 3) { $GLOBALS['SITE_DB']->add_table_field('catalogue_entries', 'allow_trackbacks', 'BINARY', 1); $GLOBALS['SITE_DB']->add_table_field('catalogue_entries', 'c_name', 'ID_TEXT'); $GLOBALS['SITE_DB']->add_table_field('catalogue_categories', 'rep_image', 'URLPATH'); $GLOBALS['SITE_DB']->add_table_field('catalogue_fields', 'cf_default', 'LONG_TEXT'); $GLOBALS['SITE_DB']->add_table_field('catalogue_fields', 'cf_searchable', 'BINARY', 1); $entries = $GLOBALS['SITE_DB']->query_select('catalogue_entries e LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_categories c ON e.cc_id=c.id', array('e.id', 'c.c_name')); foreach ($entries as $entry) { $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('c_name' => $entry['c_name']), array('id' => $entry['id']), '', 1); } } if (!is_null($upgrade_from) && $upgrade_from < 4) { $GLOBALS['SITE_DB']->alter_table_field('catalogues', 'c_own_pages', 'SHORT_INTEGER', 'c_display_type'); $GLOBALS['SITE_DB']->add_table_field('catalogue_fields', 'cf_put_in_category', 'BINARY', 1); $GLOBALS['SITE_DB']->add_table_field('catalogue_fields', 'cf_put_in_search', 'BINARY', 1); } if (is_null($upgrade_from) || $upgrade_from < 5) { //$GLOBALS['SITE_DB']->create_index('catalogue_efv_long','ilcv_value',array('cv_value'),'id'); Not allowed, LONG_TEXT can not be in key. People shouldn't order by this anyway $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', 'iscv_value', array('cv_value'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long', 'lcf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', 'scf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long_trans', 'ltcf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short_trans', 'stcf_id', array('cf_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long', 'lce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short', 'sce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long_trans', 'ltce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short_trans', 'stce_id', array('ce_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_entries', 'ce_cc_id', array('cc_id'), 'id'); $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'ftjoin_cctitle', array('cc_title')); $GLOBALS['SITE_DB']->create_index('catalogue_categories', 'ftjoin_ccdescrip', array('cc_description')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_long_trans', 'ltcv_value', array('cv_value')); $GLOBALS['SITE_DB']->create_index('catalogue_efv_short_trans', 'stcv_value', array('cv_value')); } if (!is_null($upgrade_from) && $upgrade_from < 6) { require_code('catalogues2'); rebuild_catalogue_cat_treecache(); // Move floats and integers into their own new tables if (function_exists('set_time_limit')) { @set_time_limit(0); } $sql_integer = db_string_equal_to('cf_type', 'integer') . ' OR ' . db_string_equal_to('cf_type', 'auto_increment') . ' OR ' . db_string_equal_to('cf_type', 'random') . ' OR ' . db_string_equal_to('cf_type', 'user') . ' OR ' . db_string_equal_to('cf_type', 'tick'); $sql_float = db_string_equal_to('cf_type', 'float'); foreach (array($sql_float => 'float', $sql_integer => 'integer') as $where => $new_type) { $fields = $GLOBALS['SITE_DB']->query('SELECT id FROM ' . get_table_prefix() . 'catalogue_fields WHERE ' . $where); foreach ($fields as $field) { do { $or_list = ''; $rows = $GLOBALS['SITE_DB']->query_select('catalogue_efv_short', array('*'), array('cf_id' => $field['id']), '', 100); foreach ($rows as $row) { if ($or_list != '') { $or_list .= ' OR '; } $or_list .= 'ce_id=' . strval($row['ce_id']) . ' AND cf_id=' . strval($row['cf_id']); unset($row['id']); if ($new_type == 'float') { $row['cv_value'] = $row['cv_value'] == '' ? NULL : floatval($row['cv_value']); } elseif ($new_type == 'integer') { $row['cv_value'] = $row['cv_value'] == '' ? NULL : intval($row['cv_value']); } $GLOBALS['SITE_DB']->query_insert('catalogue_efv_' . $new_type, $row); } if ($or_list != '') { $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'catalogue_efv_short WHERE ' . $or_list); } } while (count($rows) != 0); } } } }
/** * Find whether a content type has a tied catalogue. * * @param ID_TEXT Award hook codename * @return boolean Whether it has */ function has_tied_catalogue($content_type) { if (addon_installed('catalogues')) { require_code('hooks/systems/awards/' . $content_type); $ob = object_factory('Hook_awards_' . $content_type); $info = $ob->info(); if (array_key_exists('supports_custom_fields', $info) && $info['supports_custom_fields']) { $exists = !is_null($GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_name' => '_' . $content_type))); if ($exists) { $first_cat = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_categories', 'MIN(id)', array('c_name' => '_' . $content_type)); if (is_null($first_cat)) { require_code('catalogues2'); require_lang('catalogues'); actual_add_catalogue_category('_' . $content_type, do_lang('CUSTOM_FIELDS_FOR', $info['title']->evaluate()), '', '', NULL); } return true; } } } return false; }
/** * Converts a non-tree catalogue to a tree catalogue. * * @param ID_TEXT Catalogue name */ function catalogue_to_tree($catalogue_name) { $new_root = actual_add_catalogue_category($catalogue_name, do_lang('ROOT'), '', '', NULL, ''); $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'catalogue_categories SET cc_parent_id=' . strval($new_root) . ' WHERE id<>' . strval($new_root) . ' AND ' . db_string_equal_to('c_name', $catalogue_name)); $GLOBALS['SITE_DB']->query_update('catalogues', array('c_is_tree' => 1), array('c_name' => $catalogue_name), '', 1); }