function weaver_save_editor_css($mce_css_dir)
{
    // create a new editor-style.css file (sorry, no rtl) in the upload directory so will be multi-site compatible
    $base_style = get_template_directory() . '/editor-style.css';
    /* the default editor css file */
    if (!weaver_f_file_access_available() || !weaver_f_is_writable($mce_css_dir)) {
        return false;
        // just bail and let the default editor-style.css be used
    }
    /* delete current weaver-editor-style.css
          Copy default editor style to editor-style.css
          Add Weaver overrides to that file
          Close
       */
    if (!weaver_f_exists($base_style)) {
        return false;
    }
    $contents = weaver_f_get_contents($base_style);
    // get the core part
    $filename = trailingslashit($mce_css_dir) . 'weaver-editor-style.css';
    if (!($handle = weaver_f_open($filename, 'w'))) {
        // can't write - blow it off
        return false;
    }
    weaver_f_write($handle, $contents);
    // save new editor style css file
    weaver_f_write($handle, sprintf("\n/* Subtheme %s specific editor styling */\n", weaver_getopt('ttw_subtheme')));
    weaver_output_editor_style($handle);
    weaver_f_write($handle, sprintf("/* WEAVER 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", WEAVER_THEMENAME, WEAVER_VERSION, weaver_getopt('ttw_subtheme')));
    weaver_f_close($handle);
    return;
}
function weaver_save_current_css()
{
    // write the current generated CSS to a file - called only from Weaver Admin
    if (!weaver_f_file_access_available()) {
        weaver_f_file_access_fail('Limited file access. Probably running with reduced functionality.');
        return '';
    }
    $save_dir = weaver_f_uploads_base_dir() . 'weaver-subthemes';
    $save_url = weaver_f_uploads_base_url() . 'weaver-subthemes';
    $usename = 'style-weaver.css';
    $ttw_theme_dir_exists = weaver_f_mkdir($save_dir);
    if (!$ttw_theme_dir_exists) {
        weaver_f_file_access_fail('Unable to create directory. Probably a file system permission problem. Directory' . $save_dir);
    }
    $ttw_theme_dir_writable = $ttw_theme_dir_exists;
    if (!weaver_f_is_writable($save_dir)) {
        weaver_f_file_access_fail('Directory not writable. Probably a file system permission problem. Directory: ' . $save_dir);
        $ttw_theme_dir_writable = false;
    }
    $filename = $save_dir . '/' . $usename;
    // we will add txt
    if (!$ttw_theme_dir_writable || !$ttw_theme_dir_exists || !($handle = weaver_f_open($filename, 'w'))) {
        weaver_f_file_access_fail('Unable to create file. Probably a file system permission problem. File: ' . $filename);
        return '';
    }
    weaver_f_write($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", WEAVER_THEMENAME, WEAVER_VERSION, weaver_getopt('ttw_subtheme')));
    weaver_output_style($handle);
    if (!weaver_f_close($handle)) {
        weaver_f_file_access_fail('Unable to create file. Probably a file system permission problem. File: ' . $filename);
        return '';
    }
    require_once 'wvr-editorcss.php';
    weaver_save_editor_css($save_dir);
    return $save_url . '/' . $usename;
}
Exemple #3
0
function weaver_f_check_WP_Filesystem()
{
    if (!weaver_f_file_access_available()) {
        return false;
    }
    $save_dir = weaver_f_uploads_base_dir() . 'weaver-subthemes';
    if (!weaver_f_mkdir($save_dir)) {
        return false;
    }
    return true;
}
Exemple #4
0
function weaver_show_versions()
{
    printf("<h4>" . get_current_theme() . " Version Information</h4>\n");
    printf('<div class="wvr-help"><ul style="list-style-type=square !important">' . "\n");
    printf('<li>' . __('You are using %s.', WEAVER_TRANS) . "</li>\n", WEAVER_THEMEVERSION);
    if (defined('WEAVER_PLUS_VERSION')) {
        printf('<li>' . __('You are using %s.', WEAVER_TRANS) . "</li>\n", 'Weaver Plus ' . WEAVER_PLUS_VERSION);
    } else {
        printf('<li>' . __('You are not using %s.', WEAVER_TRANS) . "</li>\n", 'Weaver Plus');
    }
    if (function_exists('weaver_fileio_plugin')) {
        printf('<li>' . __('You are using %s.', WEAVER_TRANS) . "</li>\n", 'Weaver File Access Plugin');
    } else {
        if (weaver_f_file_access_available()) {
            printf('<li>' . __('You are using %s.', WEAVER_TRANS) . "</li>\n", 'WordPress WP_Filesystem');
        } else {
            printf('<li>' . __('You are not using %s.', WEAVER_TRANS) . "</li>\n", 'File Access');
        }
    }
    printf('<li>' . __('You are using <span class="b">WordPress %s</span>.') . "</li>\n", $GLOBALS['wp_version']);
    printf('<li>' . __('You are using %s.', WEAVER_TRANS) . "</li>\n", 'PHP ' . PHP_VERSION);
    printf("</ul></div>\n");
}
function weaver_upload_theme($filename)
{
    if (!weaver_f_exists($filename)) {
        return weaver_f_fail("Can't open {$filename}");
    }
    /* can't open */
    if (!weaver_f_file_access_available()) {
        // try an alternative approach - use the allowed file()
        $contents = implode('', file($filename));
    } else {
        $contents = weaver_f_get_contents($filename);
    }
    if (!$contents) {
        return weaver_f_fail("Can't open {$filename}");
    }
    return weaver_set_current_to_serialized_values($contents);
}
    function weaver_saverestore_admin()
    {
        /* admin tab for saving and restoring theme */
        if (!weaver_f_file_access_available()) {
            echo '<h2>Save/Restore Themes and Backups - DISABLED';
            weaver_help_link('help.html#SaveRestore', 'Help on Save/Restore Themes');
            echo '</h2>';
            echo '<p>Weaver will continue to function with reduced functionality. You will be able to change sub-themes,
	set your own options, and your theme will be displayed with in-line CSS. You won\'t be able to save backups
	of your work, or have page/post styling.</p>' . "\n";
            echo '<div style="display:none">';
            $upload_link = '';
        } else {
            $upload_link = weaver_write_current_theme('current_ttw_subtheme');
            // make a temp copy
        }
        $ttw_theme_dir = weaver_f_uploads_base_dir() . 'weaver-subthemes/';
        ?>

    <h2>Save/Restore Themes and Backups<?php 
        weaver_help_link('help.html#SaveRestore', 'Help on Save/Restore Themes');
        ?>
    </h2>
    <h4>You can save either all your settings in a backup file, or just theme related settings in a theme file:</h4>
    <ol style="font-size: 85%">
     <li>Save <em>all</em> your current settings in a backup file on your site's file system (in <?php 
        echo $ttw_theme_dir;
        ?>
). Automatically names the backup file to include current date and time.
     Survives Weaver Theme updates. -or-</li>
    <li>"Save in My Saved Theme" - Saves <em>all</em> settings in a special "My Saved Theme" backup file. Survives Weaver Theme updates. -or-</li>

    <li>Download current theme related settings to a file on your own computer. -or-</li>
   <li>Save theme related settings to a file on your Site's file system (in <?php 
        echo $ttw_theme_dir;
        ?>
.</li></ol>
<?php 
        if (weaver_allow_multisite()) {
            ?>
    <h4>You can restore a saved theme or backup file by:</h4>
    <ol style="font-size: 85%">
   <li>Picking "My Saved Theme" backup from the standard themes list. -or-</li>
   <li>Restoring a theme/backup that you saved in a file on your site (to current settings). -or-</li>
   <li>Uploading a theme/backup from a file saved on your own computer (to current settings).</li>
    </ol>
<?php 
        }
        if (!weaver_allow_multisite()) {
            ?>
    <h4>You will be unable to restore your saved file directly</h4>
    <p>Since this is a WordPress Multi-site installation, you are restricted from uploading
    a Weaver theme/backup from a saved file. However, the save file capability gives you the ability
    to save your work so you can transfer it to a WordPress site where you have full admin
    capabilities (non-Multi-site installation, for example), or to share with others. Please
    note that you <em>can</em> save your settings in "My Saved Theme" which will allow you
    to explore other predefined themes without losing your work.
    </p>
<?php 
        }
        ?>

    <hr />
    <h3><span style="color:blue;">Use "My Saved Theme"</span></h3>
    <?php 
        weaver_st_show_subtheme_form();
        /* add the picker for subthemes */
        ?>

        <hr />
    <h3><span style="color:blue;">Save Current Settings in Backup File</span></h3>
     <small><strong>Save</strong> <u>all</u> current options (both Main and Advanced) in a <strong>file</strong> on your
     WordPress Site's <em><?php 
        echo $ttw_theme_dir;
        ?>
</em> directory named 'weaver_backup_yyyy-mm-dd-hhmm.wvb'
     where the last part is a GMT based date and time stamp.
<?php 
        if (weaver_allow_multisite()) {
            ?>
    You will be able to restore this theme later using the <strong>Restore Saved Theme/Backup</strong> section.
<?php 
        }
        ?>
    Please be sure you've saved any changes you might have made.</small><br />
     <form enctype="multipart/form-data" name='backup-settings' method='post'>
	<span class='submit'><input name='backup_settings' type='submit' value='Backup All Current Settings'/></span>
    <?php 
        weaver_nonce_field('backup_settings');
        ?>
    </form><br />

    <hr />
    <h3><span style="color:blue;">Save Current Theme to File or Download to your computer</span></h3>
     <small><strong>Save</strong> current <em>theme related</em> settings (non-site specific settings), either by downloading
    to <strong>your computer</strong> or saving a <strong>file</strong> on your WordPress Site's <em><?php 
        echo $ttw_theme_dir;
        ?>
</em> directory.
<?php 
        if (weaver_allow_multisite()) {
            ?>
    You will be able to restore this theme later using the <strong>Restore Saved Theme/Backup</strong> section.
<?php 
        }
        ?>
    Please be sure you've saved any changes you might have made.</small><br /><br />

  <strong>Save as file on this website's server</strong>
 <p>Please provide a name for your file, then click the "Save File" button. <b>Warning:</b> Duplicate names will
    automatically overwrite existing file without notification.</p>
 <form enctype="multipart/form-data" name='savetheme' method='post'><table cellspacing='10' cellpadding='5'>
    <table>
    <td>Name for saved theme: <input type="text" name="savethemename" size="30" />&nbsp;<small>(Please use a meaningful
    name - do not provide file extension. Name might be altered to standard form.)</small></td></tr>
	<tr>
	<td><span class='submit'><input name='filesavetheme' type='submit' value='Save Theme in File'/></span>&nbsp;&nbsp;
	<small><strong>Save Theme in File</strong> - Theme will be saved in <em><?php 
        echo $ttw_theme_dir;
        ?>
</em> directory on your site server.</small></td>
        </tr>
    </table>
    <?php 
        weaver_nonce_field('filesavetheme');
        ?>
 </form><br />

    <strong>Download to your computer</strong>

 <p>Please <em>right</em>-click <a href="<?php 
        echo "{$upload_link}";
        ?>
"><strong>[* here *]</strong></a> to download the saved theme to your computer. </p>

<?php 
        if (weaver_allow_multisite()) {
            ?>
<hr />

    <h3><span style="color:blue;">Restore Saved Theme/Backup from file</span></h3>
    <small>You can restore a previously saved theme (.wvr) or backup (.wvb) file directly from your WordPress
    Site's <em><?php 
            echo $ttw_theme_dir;
            ?>
</em> directory, or from a file saved on your computer.
    Note: after you restore a saved theme, it will be loaded into the current settings. A <em>theme</em> restore will
    replace only settings that are not site-specific. A <em>backup</em> file will replace all current settings.
    If you've uploaded the theme from your computer, you might then want to also save a local copy on your
    website server.</small><br /><br />

    <form enctype="multipart/form-data" name='localrestoretheme' method='post'><table cellspacing='10' cellpadding='5'>
    <table>
    <tr><td><strong>Restore from file saved on this website's server</strong></td></tr>
    <tr>
        <td>Select theme/backup file: <?php 
            weaver_subtheme_list('ttw_restorename');
            ?>
&nbsp;Note: <strong>.wvr</strong> are Theme definitions. <strong>.wvb</strong> are full backups. (Restores to current settings.)</td></tr>
	<tr>
	<td><span class='submit'><input name='restoretheme' type='submit' value='Restore Theme/Backup'/></span>&nbsp;&nbsp;
	<small><strong>Restore</strong> a theme/backup  you've previously saved on your site's <em><?php 
            echo $ttw_theme_dir;
            ?>
</em> directory. Will replace current settings.</small></td>
    </tr>
        <tr><td>&nbsp;</td></tr>
    </table>
    <?php 
            weaver_nonce_field('restoretheme');
            ?>
    </form>
    <form enctype="multipart/form-data" action="<?php 
            echo $_SERVER["REQUEST_URI"];
            ?>
" method="POST">
	<table>
            <tr><td><strong>Upload file saved on your computer</strong></td></tr>
		<tr valign="top">
			<td>Select theme/backup file to upload: <input name="uploaded" type="file" />
			<input type="hidden" name="uploadit" value="yes" />&nbsp;(Restores to current settings.)
                        </td>
		</tr>
                <tr><td><span class='submit'><input name="uploadtheme" type="submit" value="Upload theme/backup" /></span>&nbsp;<small><strong>Upload and Restore</strong> a theme/backup from file on your computer. Will become current settings.</small></td></tr>
                <tr><td>&nbsp;</td></tr>
	</table>
	<?php 
            weaver_nonce_field('uploadtheme');
            ?>
    </form>

    <hr />

    <form enctype="multipart/form-data" name='maintaintheme' method='post'>
    <h3><span style="color:green;">Sub-theme and Backup File Maintenance</span></h3>
        <?php 
            weaver_subtheme_list('selectName');
            ?>

        <span class='submit'><input name='deletetheme' type='submit' value='Delete Sub-Theme/Backup File'/></span>
          <strong>Warning!</strong>This action can't be undone, so be sure you mean to delete a file!
	  <?php 
            weaver_nonce_field('deletetheme');
            ?>
    </form>
<?php 
        }
        if (!weaver_f_file_access_available()) {
            echo '</div> <!-- end of hiding save/restore because not file access available -->';
        }
        ?>
    <hr />
	<form name="ttw_resetweaver_form" method="post" onSubmit="return confirm('Are you sure you want to reset all Weaver settings?');">
	    <h3><span style="color:green;">Clear all Weaver Settings</span></h3>
	    <strong>Click the Clear button to reset all Weaver settings to the default values.</strong><br > <em>Warning: You will lose all current settings.</em> You should use "Backup All Current Settings" to save a copy
	    of your current settings before clearing! <span class="submit"><input type="submit" name="reset_weaver" value="Clear All Weaver Settings"/></span>
	    <?php 
        weaver_nonce_field('reset_weaver');
        ?>
	</form> <!-- ttw_resetweaver_form -->
    <hr />
<?php 
    }
Exemple #7
0
function weaver_uploadit()
{
    // upload theme from users computer
    // they've supplied and uploaded a file
    $ok = true;
    // no errors so far
    if (isset($_FILES['uploaded']['name'])) {
        $filename = $_FILES['uploaded']['name'];
    } else {
        $filename = "";
    }
    if (isset($_FILES['uploaded']['tmp_name'])) {
        $openname = $_FILES['uploaded']['tmp_name'];
    } else {
        $openname = "";
    }
    //Check the file extension
    $check_file = strtolower($filename);
    $ext_check = end(explode('.', $check_file));
    if (!weaver_f_file_access_available()) {
        $errors[] = "Sorry - Weaver unable to access files.<br />";
        $ok = false;
    }
    if ($filename == "") {
        $errors[] = "You didn't select a file to upload.<br />";
        $ok = false;
    }
    if ($ok && $ext_check != 'wvr' && $ext_check != 'wvb') {
        $errors[] = "Theme files must have <em>.wvr</em> or <em>.wvb</em> extension.<br />";
        $ok = false;
    }
    if ($ok) {
        if (!weaver_f_exists($openname)) {
            $errors[] = '<strong><em style="color:red;">' . __('Sorry, there was a problem uploading your file. You may need to check your folder permissions or other server settings.', WEAVER_TRANSADMIN) . '</em></strong>' . "<br />(Trying to use file '{$openname}')";
            $ok = false;
        }
    }
    if (!$ok) {
        echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">ERROR</em></strong></p><p>';
        foreach ($errors as $error) {
            echo $error . '<br />';
        }
        echo '</p></div>';
    } else {
        // OK - read file and save to My Saved Theme
        // $handle has file handle to temp file.
        $contents = weaver_f_get_contents($openname);
        if (!weaver_set_current_to_serialized_values($contents, 'weaver_uploadit:' . $openname)) {
            echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">' . __('Sorry, there was a problem uploading your file. The file you picked was not a valid Weaver theme file.', WEAVER_TRANSADMIN) . '</em></strong></p></div>';
        } else {
            $t = weaver_getopt('ttw_subtheme');
            if ($t == '') {
                $t = 'Wheat';
            }
            /* did we save a theme? */
            weaver_save_msg(__("Weaver theme options reset to uploaded theme, saved as: ", WEAVER_TRANSADMIN) . $t);
        }
    }
}