function af_ela_super_archive($arguments = '')
{
    global $wpdb, $af_ela_cache_root;
    $settings = get_option('af_ela_options');
    $is_initialized = get_option('af_ela_is_initialized');
    if (!$settings) {
        echo '<div id="af-ela"><p class="alert">Plugin is not initialized. Admin or blog owner, <a href="' . get_settings('siteurl') . '/wp-admin/options-general.php?page=af-extended-live-archive/af-extended-live-archive-options.php">visit the ELA option panel</a> in your admin section.</p></div>';
        return false;
    }
    $settings['loading_content'] = urldecode($settings['loading_content']);
    $settings['idle_content'] = urldecode($settings['idle_content']);
    $settings['selected_text'] = urldecode($settings['selected_text']);
    $settings['truncate_title_text'] = urldecode($settings['truncate_title_text']);
    $settings['paged_post_next'] = urldecode($settings['paged_post_next']);
    $settings['paged_post_prev'] = urldecode($settings['paged_post_prev']);
    $options = get_option('af_ela_super_archive');
    if ($options === false) {
        // create and store default options
        $options = array();
        $options['num_posts'] = 0;
        $options['last_post_id'] = 0;
    }
    $num_posts = $wpdb->get_var("\n\t\tSELECT COUNT(ID) \n\t\tFROM {$wpdb->posts} \n\t\tWHERE post_status = 'publish'");
    $last_post_id = $wpdb->get_var("\n\t\tSELECT ID \n\t\tFROM {$wpdb->posts} \n\t\tWHERE post_status = 'publish' \n\t\tORDER BY post_date DESC LIMIT 1");
    if (!is_dir($af_ela_cache_root) || !is_file($af_ela_cache_root . 'years.dat') || $num_posts != $options['num_posts'] || $last_post_id != $options['last_post_id']) {
        $options['num_posts'] = $num_posts;
        $options['last_post_id'] = $last_post_id;
        update_option('af_ela_super_archive', $options);
        $res = af_ela_create_cache($settings);
        if ($res === false) {
            // we could not create the cache, bail with error message
            echo '<div id="' . $settings['id'] . '"><p class="' . $settings['error_class'] . '">Could not create cache. Make sure the wp-content folder is writable by the web server. If you have doubts, set the permission on wp-content to 0777</p></div>';
            return false;
        }
    }
    $year = date('Y');
    $plugin_path = get_settings('siteurl') . '/wp-content/plugins/king-frontend/plugins/af-extended-live-archive';
    $text .= <<<TEXT

<script src="{$plugin_path}/includes/af-extended-live-archive.js.php" type="text/javascript"></script>
<div id="{$settings['id']}"></div>

TEXT;
    echo $text;
}
function af_ela_option_init($reset = false)
{
    global $af_ela_cache_root;
    if (!$reset) {
        $settings = get_option('af_ela_options');
    }
    if (!($is_initialized = get_option('af_ela_is_initialized')) || empty($settings) || strstr(trim(af_ela_info('currentversion')), trim($is_initialized)) === false || strstr(trim($settings['installed_version']), trim($is_initialized)) === false || $reset) {
        $cache = new af_ela_classCacheFile('');
        $cache->deleteFile();
        $initSettings = array('id' => 'af-ela', 'installed_version' => af_ela_info('currentversion'), 'charset' => get_bloginfo('charset'), 'newest_first' => '1', 'num_entries' => 0, 'num_entries_tagged' => 0, 'num_comments' => 0, 'fade' => 0, 'hide_pingbacks_and_trackbacks' => 0, 'use_default_style' => 1, 'paged_posts' => 0, 'selected_text' => '', 'selected_class' => 'selected', 'comment_text' => '(%)', 'number_text' => '(%)', 'number_text_tagged' => '(%)', 'closed_comment_text' => '', 'day_format' => '', 'error_class' => 'alert', 'truncate_title_length' => '0', 'truncate_cat_length' => '25', 'truncate_title_text' => '&#8230;', 'truncate_title_at_space' => 1, 'abbreviated_month' => 0, 'tag_soup_cut' => 0, 'tag_soup_X' => 0, 'paged_post_num' => 10, 'paged_post_next' => 'next posts >>', 'paged_post_prev' => '<< previous posts', 'menu_order' => 'chrono,cats', 'menu_month' => 'By date', 'menu_cat' => 'By category', 'menu_tag' => 'By tags', 'before_child' => '&nbsp;&nbsp;&nbsp;', 'after_child' => '', 'loading_content' => '...loading', 'idle_content' => '', 'excluded_categories' => '0');
        if (!empty($settings)) {
            $newSettings = array_merge($initSettings, $settings);
        } else {
            $newSettings = $initSettings;
        }
        $newSettings['last_modified'] = gmdate("D, d M Y H:i:s", time());
        $newSettings['installed_version'] = af_ela_info('currentversion');
        update_option('af_ela_options', $newSettings, 'Set of Options for Extended Live Archive');
        update_option('af_ela_option_mode', get_option('af_ela_options') ? 1 : 0, 'ELA option mode');
        $res = true;
        if (!is_dir($af_ela_cache_root)) {
            if (!($res = af_ela_create_cache_dir())) {
                ?>
		<div class="updated"><p><strong>Unable to create cache directory. Check your server credentials on the wp-content directory.</strong></p></div>
	<?php 
                return;
            } else {
                if ($res === true) {
                    $res = af_ela_create_cache($settings);
                    if ($res === true) {
                        ?>
		<div class="updated"><p><strong>The cache files have been created for the first time. You should be up and running. Enjoy.</strong></p></div>
	<?php 
                    } else {
                        ?>
		<div class="updated"><p><strong>Unable to create the cache files. Check your server credentials on the wp-content/af-extended-live-archive directory. </strong></p></div>
	<?php 
                        return;
                    }
                }
            }
        } else {
            if (af_ela_create_cache($settings)) {
                if (!$reset) {
                    ?>
		<div class="updated"><p><strong>The cache files have been updated. You should be up and running. Enjoy.</strong></p></div>
	<?php 
                }
            } else {
                ?>
		<div class="updated"><p><strong>Unable to update the cache files to the newer version of the plugin. Check your server credentials on the wp-content/af-extended-live-archive directory. </strong></p></div>
	<?php 
                return;
            }
        }
        update_option('af_ela_is_initialized', af_ela_info('currentversion'), 'ELA plugin has already been initialized');
    }
}