$data[$key . '_height'] = $val[1];
        $data[$key . '_image_url'] = $val['url'];
    }
    $data['source_id'] = 1;
    $data['date_created'] = $db->now();
    //echo '<pre>$data|';print_r($data);echo '|</pre>';
    $new_id = $db->insert('ad_reference', $data);
}
if ($new_id) {
    header('location:ad.promo-edit.php?ad_id=' . $new_id);
    die;
}
if ($_GET['update_wonderful']) {
    $wonderful_third_data = get_third_login('projectwonderful', $db);
    if ($wonderful_third_data && $wonderful_third_data['active'] == 1) {
        @($file_data = $fileops->read_file($wonderful_file_path . $wonderful_third_data['user_info']));
        if ($file_data) {
            $file_data = str_replace('pw:', '', $file_data);
            $fileops->set_file('../assets/data/projectwonderful.xml');
            $fileops->set_contents($file_data);
            $fileops->save_file();
        }
    }
}
/*****
 * ! Display logic
 */
// Get all ads.
$ad_list = get_ads(null, $db);
$current_theme = get_site_theme($milieu_list['tone_id']['value'], $db);
///////// Read PW data.
$page_type_list[2] = array('layout_type' => 'ht', 'function' => 'about-comic', 'label' => 'About the comic', 'image' => '../' . DIR_PATTERNS . 'ht.default.svg', 'description' => 'What you want new readers to know about your comic.', 'url' => '/about-comic');
$page_type_list[3] = array('layout_type' => 'hit', 'function' => 'cast', 'label' => 'Cast', 'image' => '../' . DIR_PATTERNS . 'hit.default.svg', 'description' => 'Name, quick bio and picture of each character.', 'url' => '/comic-characters');
$page_type_list[4] = array('layout_type' => 'hl', 'function' => 'links', 'label' => 'Links', 'image' => '../' . DIR_PATTERNS . 'hl.default.svg', 'description' => 'Simple title, optional descriptive text and URL.', 'url' => '/favorite-links');
$page_type_list[5] = array('layout_type' => 'ht', 'function' => 'faq', 'label' => 'FAQ', 'image' => '../' . DIR_PATTERNS . 'ht.default.svg', 'description' => 'Answers to questions you get asked often it’s worth a page.', 'url' => '/frequently-asked-questions');
$page_type_list[6] = array('layout_type' => 'free', 'function' => 'freeform', 'label' => 'Freeform', 'image' => '../' . DIR_PATTERNS . 'free.svg', 'description' => 'Add your own HTML. Anything goes.', 'url' => '/new-page');
$page_type_list[7] = array('layout_type' => 'ht', 'function' => 'welcome', 'label' => 'Welcome new readers', 'image' => '../' . DIR_PATTERNS . 'ht.default.svg', 'description' => 'Introduction to your comic.', 'url' => '/new-readers-begin-here');
$page_type_list[8] = array('layout_type' => 'hilt', 'function' => 'store', 'label' => 'Store', 'image' => '../' . DIR_PATTERNS . 'hit.default.svg', 'description' => 'Quick product teasers that you link to your ecommerce package.', 'url' => '/store');
/*****
 * Updates
 */
if ($_GET['id']) {
    $id = $_GET['id'];
    $layout_type_id = $page_type_list[$id]['layout_type'];
    $xml_source = '../' . DIR_PATTERNS . '' . $layout_type_id . '.xml';
    if (is_file($xml_source)) {
        $starter = $fileops->read_file($xml_source);
    } else {
        $starter = null;
    }
    // Let’s add some custom default data.
    if ($starter && $starter != null) {
        switch ($id) {
            case 1:
                $starter = str_replace('{function}', $page_type_list[1]['function'], $starter);
                $starter = str_replace('{heading1}', 'All about the artist', $starter);
                $starter = str_replace('{text1}', '(Psst — tell us something about yourself here.)', $starter);
                $starter = str_replace('{heading2}', '', $starter);
                $starter = str_replace('{text2}', '', $starter);
                $starter = str_replace('{heading3}', '', $starter);
                $starter = str_replace('{text3}', '', $starter);
                break;