コード例 #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;
 }
コード例 #2
0
 /**
  * @brief Handles logo and favicon uploads.
  * @details [long description]
  * @return [description]
  */
 function upload()
 {
     if (!isset($_REQUEST['cuttz-branding-upload'])) {
         return;
     }
     check_admin_referer(CHILD_SETTINGS_FIELD_BRANDING);
     $res = '';
     $usr_img_dir = cuttz_get_res('dir') . 'img';
     cuttz_init_path($usr_img_dir);
     $tmp_icon = $_FILES['cuttz-icon']['tmp_name'];
     if (is_uploaded_file($tmp_icon)) {
         $file_parts = pathinfo($_FILES['cuttz-icon']['name']);
         $ext = $file_parts['extension'];
         $dest = $usr_img_dir . '/' . 'favicon.' . $ext;
         if (in_array($ext, cuttz_favicon_types())) {
             cuttz_remove_favicons();
             $res = move_uploaded_file($tmp_icon, $dest);
             if ($res) {
                 $favurl = cuttz_get_res('dirurl') . 'img/favicon.' . $ext;
                 wp_cache_flush();
                 $res = __('Favicon updated. Old favicon purged.', 'cuttz-framework');
             } else {
                 $res = __('Couldn\'t move file.', 'cuttz-framework');
                 if (!is_writable($dest)) {
                     $res .= __(' Destination is not writable.', 'cuttz-framework');
                 }
             }
         } else {
             $res .= ' ' . __('File type not allowed', 'cuttz-framework');
         }
     } else {
         //$res .= ' '.__('File could not be uploaded.','cuttz-framework');
     }
     $tmp_logo = $_FILES['cuttz-logo']['tmp_name'];
     if (is_uploaded_file($tmp_logo)) {
         $file_parts = pathinfo($_FILES['cuttz-logo']['name']);
         $ext = $file_parts['extension'];
         $dest = $usr_img_dir . '/' . 'logo.' . $ext;
         if (in_array($ext, cuttz_logo_types())) {
             cuttz_remove_logos();
             $res = move_uploaded_file($tmp_logo, $dest);
             if ($res) {
                 $favurl = cuttz_get_res('dirurl') . 'img/logo.' . $ext;
                 wp_cache_flush();
                 $res = __('Logo updated. Old logo purged.', 'cuttz-framework');
             } else {
                 $res = __('Couldn\'t move file.', 'cuttz-framework');
                 if (!is_writable($dest)) {
                     $res .= ' ' . __('Destination is not writable.', 'cuttz-framework');
                 }
             }
         } else {
             $res .= ' ' . __('File type not allowed', 'cuttz-framework');
         }
     } else {
         //$res .= ' '. __('File could not be uploaded.','cuttz-framework');
     }
     echo '<div id="message" class="updated"><p><strong>' . $res . '</strong></p></div>';
 }
コード例 #3
0
ファイル: css-gen.php プロジェクト: garywp/cuttz-framework
/**
 * Returns the requested resource (url or path of the requested directory or file from cuttz-user)
 * @param string $info (type of information requested… url/path of a directory or a file)
 * @param type $res (the resource for which the information has been requested… settings.css etc.)
 * @return type
 * @since 1.0
 */
function cuttz_get_res($info = false, $res = null)
{
    $loc = '';
    $uploads = wp_upload_dir();
    if ($info == 'fileurl' || $info == 'dirurl') {
        $loc = $uploads['baseurl'] . '/cuttz-user/';
    } else {
        $loc = $uploads['basedir'] . '/cuttz-user/';
    }
    global $cuttz_user_path;
    $cuttz_user_path = $uploads['basedir'] . '/cuttz-user';
    if (cuttz_init_path($cuttz_user_path)) {
        if ($info == 'dir' || $info == 'dirurl') {
            return $loc;
        }
        switch ($res) {
            case 'userphp':
                $loc .= 'functions.php';
                break;
            case 'usercss':
                $loc .= 'autogenerated.css';
                break;
            case 'usersass':
                $loc .= 'style.scss';
                break;
            case 'settingscss':
                $loc .= 'settings.css';
                break;
            default:
                break;
        }
        return $loc;
    }
    return false;
}