예제 #1
0
/**
 * Creates new skin
 * @global WP_Filesystem $wp_filesystem
 * @param string $page
 * @param string $tab
 * @return boolean|string
 */
function aitCreateNewSkin($page, $tab)
{
    global $aitThemeConfig;
    if (empty($_POST)) {
        return false;
    }
    check_admin_referer('ait-create-new-skin');
    $passFields = array('create-new-skin', 'skin-name', 'skin-folder-name', 'skin-screenshot', 'skin-desc', 'skin-author', 'skin-overwrite');
    if (isset($_POST['create-new-skin'])) {
        $method = '';
        $url = wp_nonce_url(admin_url('admin.php?page=ait-admin-skins&tab=create-new-skin'), 'ait-create-new-skin');
        if (($creds = request_filesystem_credentials($url, $method, false, false, $passFields)) === false) {
            return true;
        }
        if (!WP_Filesystem($creds)) {
            request_filesystem_credentials($url, $method, true, false, $passFields);
            return true;
        }
        global $wp_filesystem;
        $name = strip_tags($_POST['skin-name']);
        $folderName = webalize($_POST['skin-folder-name']);
        $desc = strip_tags($_POST['skin-desc']);
        $author = strip_tags($_POST['skin-author']);
        $screenshot = strip_tags($_POST['skin-screenshot']);
        $overwrite = (isset($_POST['skin-overwrite']) and $_POST['skin-overwrite'] == 'true');
        $name = !empty($name) ? $name : THEME_SHORT_NAME . ' Skin ' . date('Y-m-d-H.i');
        $folder = !empty($folderName) ? $folderName : webalize($name);
        $skinDir = substr(THEME_SKINS_DIR, strlen(THEME_DIR) + 1) . "/{$folder}";
        $skinUrl = substr(THEME_SKINS_URL, strlen(THEME_URL) + 1) . "/{$folder}";
        $screenshotDest = '';
        $screenshotSrc = '';
        if (!empty($screenshot)) {
            $rawSrc = THEME_DIR . "/" . $screenshot;
            $src = THEME_DIR . "/" . substr($screenshot, strlen(THEME_URL) + 1);
            $screenshotDest = THEME_DIR . "/{$skinDir}/{$folder}-screenshot.png";
            if (is_file($rawSrc)) {
                $screenshotSrc = $rawSrc;
            } elseif (is_file($src)) {
                // it is from theme design dir
                $screenshotSrc = $src;
            } else {
                // it is from upload dir
                $u = wp_upload_dir();
                $baseUrl = $u['baseurl'];
                $baseDir = $u['basedir'];
                $src = $baseDir . "/" . substr($screenshot, strlen($baseUrl) + 1);
                if (is_file($src)) {
                    $screenshotSrc = $src;
                }
            }
        }
        $return = array('name' => $name, 'folder' => $folder, 'desc' => $desc, 'author' => $author, 'screenshot' => $screenshot);
        $o = get_option(AIT_OPTIONS_KEY);
        $t = aitGetOptionsTypes($aitThemeConfig, true);
        $options = array();
        $redirectTo = admin_url('admin.php?page=' . $page . "&tab={$tab}");
        if (!$overwrite and is_dir(THEME_DIR . "/{$skinDir}")) {
            echo '<div class="error"><p>' . sprintf(__('Skin with folder name <code>%s</code> already exists. Please choose other name.', THEME_CODE_NAME), $folder) . '</p></div>';
            $return['name'] = '';
            $return['author'] = '';
            return $return;
        }
        if (!is_dir(THEME_DIR . "/{$skinDir}")) {
            if (!$wp_filesystem->mkdir(THEME_DIR . "/{$skinDir}", FS_CHMOD_DIR)) {
                echo '<div class="error"><p>' . sprintf(__('Skin folder <code>%s</code> can not be created.', THEME_CODE_NAME), $skinDir) . '</p></div>';
                return $return;
            }
        }
        foreach ($t as $section => $vars) {
            foreach ($vars as $key => $type) {
                if (isset($o[$section]) and isset($o[$section][$key])) {
                    $value = $o[$section][$key];
                    if ($type == 'image-url' or $type == 'custom-css-vars') {
                        if (!empty($value)) {
                            $v = array();
                            if (!is_array($value)) {
                                $v[] = array('value' => $value);
                                // make array, compatibility with custom-css-vars array of cloned items
                            } elseif (is_array($value)) {
                                $v = $value;
                            }
                            foreach ($v as $val) {
                                if (isset($val['value']) and !empty($val['value'])) {
                                    if (is_file(THEME_DIR . "/" . ltrim($val['value'], '\\/'))) {
                                        $src = THEME_DIR . "/" . ltrim($val['value'], '\\/');
                                    } else {
                                        $src = THEME_DIR . "/" . substr($val['value'], strlen(THEME_URL) + 1);
                                    }
                                    if (is_file($src)) {
                                        // it is from theme design dir
                                        $path = "{$skinDir}/" . basename($val['value']);
                                        if ($type == 'custom-css-vars' and isset($val['variable'])) {
                                            $val['value'] = $path;
                                            $options[$section][$key][] = $val;
                                        } else {
                                            $options[$section][$key] = $path;
                                        }
                                        $dest = THEME_DIR . "/{$path}";
                                        $wp_filesystem->copy($src, $dest, $overwrite);
                                    } else {
                                        // it is from upload dir
                                        $u = wp_upload_dir();
                                        $baseUrl = $u['baseurl'];
                                        $baseDir = $u['basedir'];
                                        $src = $baseDir . "/" . substr($val['value'], strlen($baseUrl) + 1);
                                        if (is_file($src)) {
                                            $path = "{$skinDir}/" . basename($val['value']);
                                            if ($type == 'custom-css-vars' and isset($val['variable'])) {
                                                $val['value'] = $path;
                                                $options[$section][$key][] = $val;
                                            } else {
                                                $options[$section][$key] = $path;
                                            }
                                            $dest = THEME_DIR . "/{$path}";
                                            $wp_filesystem->copy($src, $dest, $overwrite);
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        $options[$section][$key] = $value;
                    }
                }
            }
        }
        if (!empty($screenshotSrc) and !empty($screenshotDest)) {
            $wp_filesystem->copy($screenshotSrc, $screenshotDest);
        }
        $neonContent = "name: {$name}\ndesc: {$desc}\nauthor: {$author}\ntheme: " . THEME_CODE_NAME;
        $neonFile = "{$skinDir}/{$folder}.neon";
        if (!$wp_filesystem->put_contents(THEME_DIR . "/{$neonFile}", $neonContent, FS_CHMOD_FILE)) {
            echo '<div class="error"><p>' . sprintf(__('Skin config file "%s" can not be created.', THEME_CODE_NAME), $neonFile) . '</p></div>';
            return $return;
        }
        $options['@skinInfo']['theme'] = THEME_CODE_NAME;
        $dump = serialize($options);
        $dumpFile = "{$skinDir}/{$folder}.ait-skin";
        if (!$wp_filesystem->put_contents(THEME_DIR . "/{$dumpFile}", $dump, FS_CHMOD_FILE)) {
            echo '<div class="error"><p>' . sprintf(__('Skin data file "%s" can not be created.', THEME_CODE_NAME), $dumpFile) . '</p></div>';
            return $return;
        }
        echo '<div class="updated"><p>' . sprintf(__('Your new skin "%s" has been successfully created. You can download it by clicking on Download button.', THEME_CODE_NAME), $name) . '</p></div>';
        $return['canDownload'] = true;
        return $return;
    }
}
예제 #2
0
<style>
table{ width:100%; margin:1em 0; } table th{ background: #eee; padding:5px; } table tr:nth-child(2n+1){ background:#fafafa; } table tr:hover{ background:#ccc; }  table td {padding:5px;} table td small {color:#666;} table td code{ background:none; padding:0; font-size:13px; }
</style>

<table>
	<tr>
		<th>Section</th>
		<th>Variable</th>
		<th>Input Type</th>
		<th>Default Value from config file</th>
		<th>Actual Value from DB</th>
	</tr>
	<?php 
    $c = aitGetThemeDefaultOptions($GLOBALS['aitThemeConfig']);
    $t = aitGetOptionsTypes($GLOBALS['aitThemeConfig']);
    $o = $GLOBALS['aitThemeOptions'];
    foreach ($c as $section => $options) {
        foreach ($options as $key => $value) {
            //echo $section . "\t\t\t" . $key. "\t\t\t";
            ?>
			<tr>
				<td><code><?php 
            echo $section;
            ?>
</code></td>
				<td><code><?php 
            echo $key;
            ?>
</code></td>
				<td><code><?php 
예제 #3
0
/**
 * Converts structured config array to simple key => value array
 * @param array $options Config array
 * @return array
 */
function aitPrepareVariablesForLess($options = array(), $configTypes = null)
{
    if (empty($options)) {
        $options = get_option(AIT_OPTIONS_KEY);
        if ($options === false) {
            $options = array();
        }
    }
    if ($configTypes === null) {
        $onlyDesignVars = true;
        $configTypes = aitGetOptionsTypes($GLOBALS['aitThemeConfig'], $onlyDesignVars);
    }
    $variables = array();
    foreach ($options as $section => $values) {
        foreach ($values as $option => $value) {
            if (isset($configTypes[$section][$option])) {
                if ($configTypes[$section][$option] == 'custom-css') {
                    continue;
                }
                if (is_string($value)) {
                    if (empty($value)) {
                        $variables[$option] = '';
                    } else {
                        $variables[$option] = $value;
                    }
                    // url to images must be in quotes
                    if (preg_match('/\\.(jpg|png|gif)/', $variables[$option]) !== 0) {
                        $variables[$option] = "\"{$variables[$option]}\"";
                    }
                } elseif (is_array($value) and isset($value['font']) and !empty($value['type'])) {
                    $font = str_replace('+', ' ', $value['font']);
                    $pos = strpos($font, ':');
                    if ($pos !== false) {
                        $font = substr($font, 0, $pos);
                    }
                    $variables[$option] = "'" . $font . "'";
                } elseif ($configTypes[$section][$option] == 'transparent' and is_array($value) and isset($value['color'])) {
                    if (startsWith('#', $value['color']) and $value['opacity'] == 1) {
                        $variables[$option] = $value['color'];
                    } else {
                        $rgba = "rgba(%s, %s, %s, %s);";
                        $rgb = hex2rgb($value['color']);
                        $rgba = sprintf($rgba, $rgb[0], $rgb[1], $rgb[2], $value['opacity']);
                        $ieFilter = "progid:DXImageTransform.Microsoft.gradient(startColorstr='#" . base_convert(floor($value['opacity'] * 255), 10, 16) . str_replace('#', '', $value['color']) . "',endColorstr='#" . base_convert(floor($value['opacity'] * 255), 10, 16) . str_replace('#', '', $value['color']) . "',GradientType=0)";
                        $variables[$option] = $rgba;
                        $variables[$option . '-ie'] = $ieFilter;
                    }
                } elseif ($configTypes[$section][$option] == 'custom-css-vars' and is_array($value)) {
                    foreach ($value as $var) {
                        if (isset($var['variable']) and isset($var['value']) and !empty($var['variable']) and !empty($var['value'])) {
                            if (preg_match('/\\.(jpg|png|gif)/', $var['value']) !== 0) {
                                $var['value'] = "\"{$var['value']}\"";
                            }
                            $variables[$var['variable']] = $var['value'];
                        }
                    }
                }
            }
        }
    }
    return $variables;
}