Exemplo n.º 1
0
 function save($newsettings, $oldsettings)
 {
     $skin_field = isset($newsettings['skin']) ? $newsettings['skin'] : 'vanilla';
     $customization = $skin_field;
     $all_customizations = cuttz_customization_aggregator();
     if (is_array($all_customizations) && array_key_exists($skin_field, $all_customizations)) {
         // skin exists
         $current_customization = $all_customizations[$skin_field];
         if (is_array($current_customization) && array_key_exists('functions', $current_customization)) {
             include_once $current_customization['functions'];
         }
     } else {
         $skin_field = 'vanilla';
         if (is_array($all_customizations) && array_key_exists($skin_field, $all_customizations)) {
             //validate that vanilla exists
             $current_customization = $all_customizations['vanilla'];
             $newsettings['skin'] = 'vanilla';
             //what if someone deletes vanilla?
             if (is_array($current_customization) && array_key_exists('functions', $current_customization)) {
                 //if functions.php exists for vanilla, use it.
                 include_once $current_customization['functions'];
             }
         }
     }
     if (isset($newsettings['new-skin']) && !empty($newsettings['new-skin'])) {
         $new_skin = cuttz_ws($newsettings['new-skin']);
         if (!empty($new_skin) && !file_exists(CUTTZ_USER_SKINS . '/' . $new_skin)) {
             cuttz_init_path(CUTTZ_USER_SKINS . '/' . $new_skin);
             $functions_out = CUTTZ_USER_SKINS . '/' . $new_skin . '/functions.php';
             $msg = __("<?php\n/******** Place all your wp/php tweaks here ****************/\n/******** This is your skins functions.php file ******/\n", 'cuttz-framework');
             $functions_out = file_put_contents($functions_out, $msg);
             $style_out = CUTTZ_USER_SKINS . '/' . $new_skin . '/style.scss';
             $msg = __("/**************** Place all your css customizations in the style.scss file *****************/\n\n", 'cuttz-framework');
             $style_out = file_put_contents($style_out, $msg);
             //if can't be created then somehow push/or handle error
             if (!$style_out || !$functions_out) {
                 $newsettings['skin'] = $oldsettings['skin'];
             } else {
                 $newsettings['skin'] = $new_skin;
             }
         }
     }
     $newgkey = empty($newsettings['gfonts-api-key']) ? 'false' : trim($newsettings['gfonts-api-key']);
     $oldgkey = empty($oldsettings['gfonts-api-key']) ? 'false' : trim($oldsettings['gfonts-api-key']);
     if ($newgkey != $oldgkey) {
         //just reset the cuttz_fonts_list transient so that it can be rebuilt if a new key has been set
         delete_transient('cuttz_fonts_list');
     }
     if (function_exists('w3tc_flush_all')) {
         //check if W3Total cache is installed and active
         w3tc_flush_all();
         //flush the entire cache since we've updated theme settings, widget output and more
     }
     return $newsettings;
 }
Exemplo n.º 2
0
/**
 * Builds and returns a list of all available skins in Cuttz
 * @return array
 * @since 1.0
 */
function cuttz_customization_aggregator()
{
    $core_customizations = glob(CUTTZ_CORE_SKINS . '/*', GLOB_ONLYDIR);
    $user_customizations = glob(CUTTZ_USER_SKINS . '/*', GLOB_ONLYDIR);
    $extns = array('png', 'gif', 'jpg', 'jpeg');
    $extns = apply_filters('cuttz_screenshot_types', $extns);
    if (is_array($core_customizations)) {
        foreach ($core_customizations as $customization) {
            if (!file_exists($customization . '/functions.php') && !file_exists($customization . '/style.css') && !file_exists($customization . '/style.scss')) {
                continue;
            }
            $name = preg_replace('/[^A-Za-z0-9\\-\\s]/', '', basename($customization));
            $name = str_replace('-', ' ', $name);
            $name = ucwords(strtolower($name));
            $id = cuttz_ws(basename($customization));
            $all_customizations[$id] = array('name' => $name);
            $all_customizations[$id]['type'] = 'core';
            $all_customizations[$id]['dir'] = str_replace(' ', '%20', $customization);
            $all_customizations[$id]['url'] = str_replace(' ', '%20', CUTTZ_CORE_SKINS_URL . '/' . basename($customization));
            if (file_exists($customization . '/autogenerated.css')) {
                $all_customizations[$id]['style'] = str_replace(' ', '%20', CUTTZ_CORE_SKINS_URL . '/' . basename($customization) . '/autogenerated.css');
            }
            if (file_exists($customization . '/style.scss')) {
                $all_customizations[$id]['sass'] = str_replace(' ', '%20', CUTTZ_CORE_SKINS_URL . '/' . basename($customization) . '/style.scss');
            }
            if (file_exists($customization . '/functions.php')) {
                $all_customizations[$id]['functions'] = $customization . '/functions.php';
            }
            foreach ($extns as $extn) {
                if (file_exists($customization . "/screenshot.{$extn}")) {
                    $all_customizations[$id]['screenshot'] = str_replace(' ', '%20', CUTTZ_CORE_SKINS_URL . '/' . basename($customization) . "/screenshot.{$extn}");
                }
            }
        }
    }
    if (is_array($user_customizations)) {
        foreach ($user_customizations as $customization) {
            if (!file_exists($customization . '/functions.php') && !file_exists($customization . '/style.css') && !file_exists($customization . '/style.scss')) {
                continue;
            }
            $name = preg_replace('/[^A-Za-z0-9\\-\\s]/', '', basename($customization));
            $name = str_replace('-', ' ', $name);
            $name = ucwords(strtolower($name)) . ' (User)';
            $id = cuttz_ws(basename($customization));
            $all_customizations[$id] = array('name' => $name);
            $all_customizations[$id]['type'] = 'user';
            $all_customizations[$id]['dir'] = str_replace(' ', '%20', $customization);
            $all_customizations[$id]['url'] = str_replace(' ', '%20', CUTTZ_USER_SKINS_URL . '/' . basename($customization));
            if (file_exists($customization . '/autogenerated.css')) {
                $all_customizations[$id]['style'] = str_replace(' ', '%20', CUTTZ_USER_SKINS_URL . '/' . basename($customization) . '/autogenerated.css');
            } else {
                unset($all_customizations[$id]['style']);
            }
            if (file_exists($customization . '/style.scss')) {
                $all_customizations[$id]['sass'] = str_replace(' ', '%20', CUTTZ_USER_SKINS_URL . '/' . basename($customization) . '/style.scss');
            } else {
                unset($all_customizations[$id]['sass']);
            }
            if (file_exists($customization . '/functions.php')) {
                $all_customizations[$id]['functions'] = $customization . '/functions.php';
            } else {
                unset($all_customizations[$id]['functions']);
            }
            foreach ($extns as $extn) {
                if (file_exists($customization . "/screenshot.{$extn}")) {
                    $all_customizations[$id]['screenshot'] = str_replace(' ', '%20', CUTTZ_USER_SKINS_URL . '/customizations/' . basename($customization) . "/screenshot.{$extn}");
                }
            }
        }
    }
    $skins;
    if (!is_array($all_customizations)) {
        $skins = FALSE;
    } else {
        $skins = $all_customizations;
    }
    return apply_filters('cuttz_skins', $skins);
}