Ejemplo n.º 1
0
function ttw_generate_wphead()
{
    /* this guy does ALL the work for generating theme look - it writes out the over-rides to the standard style.css */
    global $ttw_options, $ttwHeadOptions;
    printf("<!-- This site is using %s %s subtheme: %s -->\n", TTW_THEMENAME, TTW_VERSION, ttw_getopt('ttw_subtheme'));
    if (!ttw_getadminopt('ttw_hide_metainfo')) {
        echo str_replace("\\", "", ttw_getadminopt('ttw_metainfo') . "\n");
    }
    // handle 3 stylesheed situations
    //	default: used weaver-style.css
    //	no weaver-style.css: when first installed, there will not be a weaver-style.css, so use inline instead
    //	force inline: user wants inline css
    $css_file = ttw_get_css_filename();
    // fetch the name of the css file
    if (ttw_getadminopt('ttw_force_inline_css') || !file_exists($css_file)) {
        // generate inline CSS
        get_template_part('ttw-generatecss');
        // require_once('ttw-generatecss.php');	// include only now at runtime.
        echo '<style type="text/css">' . "\n";
        $output = fopen('php://output', 'w+');
        ttw_output_style($output);
        echo "</style> <!-- end of main options style section -->\n";
    } else {
        printf("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"%s\" />\n", ttw_get_css_url());
    }
    /* now head options */
    echo str_replace("\\", "", ttw_getopt('ttw_theme_head_opts'));
    echo str_replace("\\", "", ttw_getopt('ttw_head_opts'));
    /* let the user have the last word! */
    do_action('ttwx_extended_wp_head');
    /* call extended wp_head stuff */
    do_action('ttwx_super_wp_head');
    // future header plugin
    echo "\n<!-- End of Weaver options -->\n";
}
Ejemplo n.º 2
0
function ttw_save_current_css()
{
    // write the current generated CSS to a file
    $wpdir = wp_upload_dir();
    // get the upload directory
    $save_dir = $wpdir['basedir'] . '/weaver-subthemes';
    $save_url = $wpdir['baseurl'] . '/weaver-subthemes';
    $usename = 'style-weaver.css';
    $ttw_theme_dir_exists = wp_mkdir_p($save_dir);
    $ttw_theme_dir_writable = $ttw_theme_dir_exists;
    if (!$ttw_theme_dir_exists) {
        // it either already exisits, or was created
        echo '<div class="error"><p>';
        echo 'It looks like <strong>' . $save_dir . '</strong> does not exist.<br /><br /> This error is unusual and probably involves a site configuration issue. Have you changed hosts recently?';
        echo "\nThis message might have some useful information:<br />\n";
        var_dump($wpdir);
        echo '</p></div><br />';
    } else {
        if (!is_writable($save_dir)) {
            if (!is_writable($save_dir)) {
                echo '<div class="error"><p>';
                echo 'It looks like <strong>' . $save_dir . '</strong> is not writable.<br /><br /> You will need to directory writable in order to save sub-themes on your site.<br /><br />Maybe <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">This Article</a> from WordPress will help.';
                echo '</p></div><br />';
                $ttw_theme_dir_writable = false;
            }
        }
    }
    $filename = $save_dir . '/' . $usename;
    // we will add txt
    if (!$ttw_theme_dir_writable || !($handle = fopen($filename, 'w'))) {
        ?>
	    <h4>Sorry, something went wrong.</h4>
	    <p>Unable to create the file to save the theme CSS file on your site host. It is likely
	    some kind of file permission problem. The site will continue to function properly
	    using inline CSS, but this message will continue to be displayed.</p>
	    <?php 
        return '';
    }
    fwrite($handle, sprintf("/* WARNING: Do not edit this file. It is dynamically generated. Any edits you make will be overwritten. */\n/* This file generated using %s %s subtheme: %s */\n", TTW_THEMENAME, TTW_VERSION, ttw_getopt('ttw_subtheme')));
    ttw_output_style($handle);
    fclose($handle);
    return $save_url . '/' . $usename;
}