" . $error->getMessage() . "";
echo "
" . preg_replace('/#\d+/','- ',$error->getTraceAsString()) . "
";
}
function getPath($p,$st) {
$parent = substr($p,0,strpos($p,'/'));
if (empty($parent)) $parent = $p;
$db = loader::db();
$sql = "select cat_id, parent_cat_id from $st where cat_id = $parent";
$query = $db->execute($sql);
if ($query->EOF) throw new Exception('No such parent ID: ' . $parent);
$row = $query->fetchRow();
if ($row['parent_cat_id'] <= 1) return('/'.$p);
return(getPath($row['parent_cat_id'].'/'.$p,$st));
}
$homepage = empty($section_handle) ? Page::getByID(1) : Page::getByPath("/$section_handle");
if (is_null($homepage->cID)) {
$msdata = array('cName'=>$section_name, 'cHandle'=>$section_handle);
$homepage = Page::getByID(1)->add($ct,$msdata);
// Add page list block
$plBlock = BlockType::getByHandle('page_list');
$pldata = array('num'=>20, 'paginate'=>true, 'cParentID'=>$homepage->cID, 'cThis'=>1);
$newBlock = $homepage->addBlock($plBlock, "Main", $pldata);
}
// Get section list
$db = loader::db();
$sql = "SELECT * FROM $section_table WHERE parent_cat_id > 0 ORDER BY parent_cat_id, cat_id";
$query = $db->execute($sql) or die(mysql_error);
try {
// Loop through sections and add them
while ($row = $query->fetchRow()) {
$cid = $row['cat_id']; // Category ID
$pid = $row['parent_cat_id']; // parent Category ID
$title = trim($row['cat_name']);
$external = (($row['cat_type'] == 2) ? true : false);
$url = $row['cat_url'];
$data = array('cName'=>$title, 'cHandle'=>$cid);
($pid == 1) ? $path = "/$cid" : $path = getPath($pid,$section_table);
if (!empty($section_handle)) $path = "/" . $homepage->getCollectionHandle() . $path;
$path = preg_replace('#//#','/',$path); // in case the main section doesn't have handle
$parentpage = ($pid == 1) ? $homepage : Page::getByPath($path);
// If external link just add and skip to next record
if ($external) {
if ($parentpage->cID == null) {
printf('
Skipped page :: %s/%s :: %s!
',$pid,$cid,$title);
continue;
}
$parentpage->addCollectionAliasExternal($data['cName'],$url);
continue;
}
$page = Page::getByPath($parentpage->getCollectionPath() . '/' . $data[cHandle]);
if (is_null($page->cID)) $page = $parentpage->add($ct, $data);
// Add page list block
$plBlock = BlockType::getByHandle('page_list');
$pldata = array('num'=>20, 'paginate'=>true, 'cParentID'=>$page->cID, 'cThis'=>1);
$newBlock = $page->addBlock($plBlock, "Main", $pldata);
$newBlock->setCustomTemplate('content_intro.php');
// 3: Get Details for category
$sql = "SELECT * FROM $data_table WHERE cat_id = $cid ORDER BY data_id, data_active";
if ($limit) {
$sql .= " LIMIT $limit";
if ($offset) $sql .= " OFFSET $offset";
}
echo "* $sql
";
$q = $db->execute($sql);
while ($r = $q->fetchRow()) {
// Skip record if data_active is NULL
if ($r['data_active'] == NULL) continue;
$handle_sub = $r['data_id'];
$title = trim($r['data_title']);
$public = $r['data_active'];
// content text
if (isset($r['data_covered'])) {
$text = trim($r['data_covered']);
} else {
$short = trim($r['data_short']);
$full = trim($r['data_full']);
// combine the two fields and add a page break in between
$text = "$short$full";
$source = trim($r['data_source']);
}
// 4: Add subpages to category (for each detail)
$data = array();
$data['cName'] = $title;
$data['cHandle'] = $handle_sub;
$data['cDatePublic'] = $public;
$child = $page->add($ct,$data);
// If there is a news source for this page add it
// an attribute with the name news_source must be added first
// if (!empty($source)) $child->setAttribute('news_source',$source);
// 5: Add Content to subpage
$bt = BlockType::getByHandle('content');
$content = "$text";
$data = array();
$data['content'] = $content;
$data['uID'] = 0;
$child->addBlock($bt, 'Main', $data);
}
}
} catch (Exception $e) {
traceError($e);
}
} else if ($_POST['delete']) {
$home = Page::getByID(1);
$pages = $home->getCollectionChildrenArray();
echo "
\n";
foreach ($pages as $id) {
$page = Page::getByID($id);
if (!is_null($page->cID)) {
if (!$page->isSystemPage() && !$page->isAdminPage && $page->getCollectionName() != 'Site-migration' && $page->getCollectionName() != 'Data-migration') {
echo "- Deleting page: " . $page->getCollectionName() . "
\n";
$page->delete();
}
}
}
echo "
";
}
$db = Loader::db();
$dbq = $db->execute('show databases');
$db_list = array();
while ($row = $dbq->fetchRow()) {
$db_list[$row['Database']] = $row['Database'];
}
$fh = Loader::helper('form');
echo <<