/** * @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>'; }
/** * Returns the Logo/headerimage path or hooks the entire header CSS to front-end. * @param bool $return * @return none/string * @since 1.0 */ function cuttz_logo($return = true) { $cuttz_logo; $cuttz_logo_path = ''; $logo_types = cuttz_logo_types(); $logo_dest = cuttz_get_res('dir') . 'img/logo.'; foreach ($logo_types as $ext) { if (file_exists($logo_dest . $ext)) { $cuttz_logo = cuttz_get_res('dirurl') . 'img/logo.' . $ext; $cuttz_logo_path = $logo_dest . $ext; } } if (!isset($cuttz_logo)) { $cuttz_logo = CHILD_URL . '/images/logo.svg'; } if ($return) { return $cuttz_logo; } if (file_exists($cuttz_logo_path)) { $logo_info = getimagesize($cuttz_logo); $logo_height = 'min-height:' . 0.5 * $logo_info[1] . 'px'; $cuttz_logo_css = '.cuttz.header-image .site-header .wrap {' . $logo_height . ';background-image :url(' . $cuttz_logo . '); background-repeat: no-repeat; background-position: left center; background-size: contain;}' . '.header-image .site-title a{' . $logo_height . ';}'; echo '<style type="text/css">' . $cuttz_logo_css . '</style>'; } }