Example #1
0
 /**
  * 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);
             }
         }
     }
 }
Example #2
0
 /**
  * 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_links($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' => 'links')));
     $categories = $db->query('SELECT * FROM ' . $table_prefix . 'links_categories');
     // TODO: Got an error mail about the above query failing. Investigate on next review of importer.
     $root_category = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'MIN(id)', array('c_name' => 'links'));
     foreach ($categories as $category) {
         $id = actual_add_catalogue_category('links', $category['title'], $category['cdescription'], '', $root_category, '');
         grant_catalogue_full_access($id);
         $rows = $db->query('SELECT * FROM ' . $table_prefix . 'links_links WHERE cid=' . $category['cid']);
         foreach ($rows as $i => $row) {
             $rows[$i]['validated'] = 1;
             $rows[$i]['date'] = $this->mysql_time_to_timestamp($row['date']);
         }
         $rows2 = $db->query('SELECT * FROM ' . $table_prefix . 'links_newlink');
         foreach ($rows2 as $i => $row) {
             $rows2[$i]['validated'] = 0;
             $rows2[$i]['hits'] = 0;
             $rows2[$i]['totalvotes'] = 0;
             $rows2[$i]['date'] = time();
         }
         $rows = array_merge($rows, $rows2);
         foreach ($rows as $row) {
             $member = $GLOBALS['FORUM_DRIVER']->get_member_from_username($row['name']);
             if (is_null($member)) {
                 $member = get_member();
             }
             $map = array($fields[0] => $row['title'], $fields[1] => $row['url'], $fields[2] => $row['description']);
             $new_id = actual_add_catalogue_entry($id, $row['validated'], '', 1, 1, 1, $map, $row['date'], $member);
             // Links rating
             if ($row['totalvotes'] != 0) {
                 $real_rating = $row['linkratingsummary'];
                 // Same scale as ocPortal :)
                 $GLOBALS['SITE_DB']->query_insert('rating', array('rating_for_type' => 'catalogues', 'rating_for_id' => strval($new_id), 'rating_member' => get_member(), 'rating_ip' => '127.0.0.1', 'rating_time' => time(), 'rating' => $real_rating));
             }
         }
     }
 }