Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
Fix up auth fail and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Nowrotek authored and Rafael Nowrotek committed Aug 12, 2019
1 parent 0fb52b2 commit 1c20f89
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 69 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "benignware/wp-kicks-app-pro",
"version": "0.1.0-beta.16",
"version": "0.1.0-beta.17",
"type": "wordpress-theme",
"license": "MIT",
"description": "Wordpress Kickstarter Theme",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions front-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@

<?php
// Get each of our panels and show the post data.
if ( 0 !== twentyseventeen_panel_count() || is_customize_preview() ) : // If we have pages to show.

/**
* Filter number of front page sections in Twenty Seventeen.
*
* @since Twenty Seventeen 1.0
*
* @param int $num_sections Number of front page sections.
*/
$num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
global $twentyseventeencounter;

// Create a setting and control for each of the sections available in the theme.
for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) {
$twentyseventeencounter = $i;
twentyseventeen_front_page_section( null, $i );
}

endif; // The if ( 0 !== twentyseventeen_panel_count() ) ends here.
// if ( 0 !== twentyseventeen_panel_count() || is_customize_preview() ) : // If we have pages to show.
//
// /**
// * Filter number of front page sections in Twenty Seventeen.
// *
// * @since Twenty Seventeen 1.0
// *
// * @param int $num_sections Number of front page sections.
// */
// $num_sections = apply_filters( 'twentyseventeen_front_page_sections', 4 );
// global $twentyseventeencounter;
//
// // Create a setting and control for each of the sections available in the theme.
// for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) {
// $twentyseventeencounter = $i;
// twentyseventeen_front_page_section( null, $i );
// }
//
// endif; // The if ( 0 !== twentyseventeen_panel_count() ) ends here.
?>

</main><!-- #main -->
Expand Down
2 changes: 0 additions & 2 deletions lib/js/themalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@

defaultValue = trim(defaultValue);

console.log('SET VAR: ', key, defaultValue);

var defaultLabel = getLabel(defaultValue, ref);

switch (controlType) {
Expand Down
128 changes: 85 additions & 43 deletions lib/themalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ function get_color_by_name($name) {
)[$name] ?: $name;
}

function is_empty_value($value) {
return !isset($value) || $value === '' || $value === null;
}

function get_color_value($value) {
if (preg_match('~^\s*var\(\s*--([a-zA-Z_-]+)\s*\)\s*$~', $value)) {
if (!preg_match('~^\s*(?:rgb|#)\s*\(~', $value)) {
return $value;
}

$value = get_color_by_name($value);
$value = preg_replace('~rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*1\s*\)~', 'rgb($1, $2, $3)', $value);

if (preg_match('~rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)~is', $value, $output, PREG_SET_ORDER)) {
$matches = $output[0];
if (preg_match('~rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)~', $value, $matches)) {
$value = preg_replace('~rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*1\s*\)~', 'rgb($1, $2, $3)', $value);

$value = call_user_func_array('sprintf', [
"#%02x%02x%02x", $matches[1], $matches[2], $matches[3]
]);
Expand Down Expand Up @@ -120,6 +125,8 @@ function register_theme_options($options) {
function register_theme_var($name, $attributes = []) {
global $theme_vars;

$default = $attributes['default'];

if (!isset($theme_vars)) {
$theme_vars = [];
}
Expand Down Expand Up @@ -165,14 +172,14 @@ function get_theme_fonts_x() {
$pattern = '~^\s*var\s*\(\s*--([a-zA-Z_-]*)\s*\)\s*$~';

foreach ($theme_options as $name => $attributes) {
$default = $defaults[$name] ?: $attributes['value'];
$default_value = $default ?: $attributes['default'];
$default = !is_empty_value($defaults[$name]) ? $defaults[$name] : $attributes['value'];
$default_value = $default;

$c = 0;
while (preg_match($pattern, $default, $matches)) {
while (preg_match($pattern, $default_value, $matches)) {
$next_name = $matches[1];
if ($defaults[$next_name]) {
$default = $defaults[$next_name];
if (!is_empty_value($defaults[$next_name])) {
$default_value = $defaults[$next_name];
}
$c++;

Expand All @@ -181,31 +188,39 @@ function get_theme_fonts_x() {
}
}

$default_value = !is_empty_value($default_value) ? $default_value : $attributes['default'];

$type = $attributes['type'];
$value = $default ?: $attributes['value'];
$value = !is_empty_value($default) ? $default : $attributes['value'];
$value = trim($value);

$is_reference = preg_match('~^\s*var\(\s*--([a-zA-Z_-]+)\s*\)\s*$~', $default, $matches);

if ($is_reference) {
$reference = $matches[1];
$reference_label = themalize_humanize($reference);
}

if ($type === 'color') {
$value = get_color_value($value);
// $value = get_color_value($value);
$default_value = get_color_value($default_value);
}

if ($type === 'font') {
$value = get_font_value($value);
// $value = get_font_value($value);
$default_value = get_font_value($default_value);
}

$is_reference = preg_match('~^\s*var\(\s*--([a-zA-Z_-]+)\s*\)\s*$~', $value, $matches);
// We currently cannot handle urls
if (preg_match('~url\s*\(~', $default_value)) {
continue;
};

if ($is_reference) {
$reference = $matches[1];
$reference_label = themalize_humanize($reference);
}

$setting_default = $is_reference ? $value : $default_value;

// echo '----> REGISTER THEME OPTION:' . $name . ' VALUE: ' . $value . ' DEFAULT: ' . $default;
// // print_r($attributes);
// echo '----> REGISTER THEME OPTION:' . $name . ' SETTING: ' . $setting_default . ' DEFAULT: ' . $default_value;
// // // print_r($attributes);
// echo '<br/>';

$setting = [
Expand Down Expand Up @@ -253,8 +268,6 @@ function get_theme_fonts_x() {
}))[0] ?: 'uncategorized';
}



$args = array_merge(array(
'label' => $label,
'section' => $section,
Expand Down Expand Up @@ -454,6 +467,8 @@ function load_theme_resources() {
function theme_fetch_resource($url) {
global $theme_resources;

// echo '<br/>FETCH URL ' . $url . '<br/>';

$local_directory_uris = array(
[ get_stylesheet_directory_uri(), get_stylesheet_directory() ],
[ get_template_directory_uri(), get_template_directory() ]
Expand All @@ -476,7 +491,7 @@ function($item) use($url) {
// echo '<br/>';

if (!file_exists($local_file)) {
echo 'FILE NOT FOUND';
echo '!!!!!!!! FILE NOT FOUND';
exit;
}

Expand All @@ -487,7 +502,7 @@ function($item) use($url) {

if ($content) {
// echo ' ----> SUCCESS <br/>';
// echo substr($content, 0, 100);
// echo substr($content, 0, 50);
// echo '<br/>';
return $content;
}
Expand Down Expand Up @@ -607,9 +622,18 @@ function get_theme_resources() {
global $theme_resources;

if (isset($theme_resources)) {
// echo 'RESOURCES IS SET';
return $theme_resources;
}

if (!is_admin()) {
$theme_resources = load_theme_resources();

if ($theme_resources) {
return $theme_resources;
}
}

$url = admin_url( 'admin-ajax.php' ) . '?action=theme_resources';
$urlinfo = parse_url($url);

Expand All @@ -624,26 +648,26 @@ function get_theme_resources() {
*/

$host = $_SERVER['SERVER_NAME'];
// $host = $_SERVER['SERVER_ADDR'];
$url = $urlinfo['scheme'] . '://' . $host . $urlinfo['path'] . ($urlinfo['query'] ? '?' . $urlinfo['query'] : '');

/*
echo $url;
exit;
*/

if (function_exists('curl_init')) {
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
// curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)');
curl_setopt($ch, CURLOPT_USERAGENT, 'Themalizer/0.1 (http://www.googlebot.com/bot.html)');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
// curl_setopt($ch, CURLOPT_TIMEOUT, 100); // Removed
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/0.1 (http://www.googlebot.com/bot.html)');
// curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100); // Removed
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Added

if ($_SERVER['PHP_AUTH_USER'] && $_SERVER['PHP_AUTH_PW']) {
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']);
}

$content = curl_exec($ch);

if ($content === false) {
Expand Down Expand Up @@ -689,7 +713,8 @@ function ajax_theme_resources() {
add_action( 'wp_ajax_nopriv_theme_resources', 'ajax_theme_resources');
add_action( 'wp_ajax_theme_resources', 'ajax_theme_resources');

add_action( 'wp_ajax_theme_vars', function() {

function ajax_theme_vars() {
$data = isset($_POST['data']) ? $_POST['data'] : array();

$theme_vars = x_get_theme_vars($data);
Expand All @@ -702,7 +727,10 @@ function ajax_theme_resources() {

// Don't forget to stop execution afterward.
wp_die();
});
}

add_action( 'wp_ajax_theme_vars', 'ajax_theme_vars');
add_action( 'wp_ajax_nopriv_theme_resources', 'ajax_theme_vars');


function load_theme_manifest($file) {
Expand Down Expand Up @@ -734,7 +762,11 @@ function get_theme_defaults() {

$defaults = array();
foreach ($theme_resources as $theme_resource) {
$defaults = array_merge($defaults, $theme_resource['vars']);
foreach ($theme_resource['vars'] as $key => $value) {
if (!is_empty_value($value)) {
$defaults[$key] = $value;
}
}
}

return $defaults;
Expand All @@ -749,10 +781,17 @@ function x_get_theme_vars($custom = array()) {
// Process regular vars
foreach ($theme_vars as $key => $data) {
// $value = isset($data['value']) ? $data['value'] : $data['default'];
$value = isset($defaults[$key]) ? $defaults[$key] : $data['value'];
$default = isset($defaults[$key]) ? $defaults[$key] : '';

if (!is_empty_value($default)) {
$value = $default;
} else {
$value = $data['value'];
}

$implicit = isset($data['implicit']) ? $data['implicit'] : false;

if ($value && !$implicit) {
if (!$implicit) {
try {
// We cannot process url for some reason
if (preg_match('~url\s*\(~', $value)) {
Expand All @@ -765,11 +804,14 @@ function x_get_theme_vars($custom = array()) {
if (isset($custom[$key])) {
// echo 'CUSTOM KEY: ' . $key;
// echo 'CUSTOM VALUE: ' . $custom[$key];
$value = $custom[$key] ?: $value;
$value = !is_empty_value($custom[$key]) ? $custom[key] : $value;
} else {
$value = get_theme_mod($key, $value);
}

// echo 'ADD VAR: ' . $key . ' -> ' . $value . ' default: ' . $default;
// echo '<br/>';

if ($value) {
$result[$key] = $value;
}
Expand All @@ -779,6 +821,7 @@ function x_get_theme_vars($custom = array()) {
exit;
}
}

}

// Process implicit vars
Expand All @@ -794,8 +837,8 @@ function x_get_theme_vars($custom = array()) {

while (preg_match($pattern, $source_value, $matches)) {
$source_var = $matches[1];
$source_value = $result[$source_var] ?: $source_value;
$source_default = $theme_vars[$source_var]['default'] ?: $source_default;
$source_value = !is_empty_value($result[$source_var]) ? $result[$source_var] : $source_value;
$source_default = !is_empty_value($theme_vars[$source_var]['default']) ? $theme_vars[$source_var]['default'] : $source_default;
}

if ($data['filter']) {
Expand All @@ -811,7 +854,6 @@ function x_get_theme_vars($custom = array()) {
}
}


return $result;
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-kicks-app-pro",
"version": "0.1.0-beta.16",
"version": "0.1.0-beta.17",
"description": "Wordpress theme",
"private": true,
"main": "dist/main.js",
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Theme Name: Kicks App Pro
Author: Rafael Nowrotek
Author URI: http://benignware.com
Description: Kickstarter Template
Version: 0.1.0-beta.16
Version: 0.1.0-beta.17
*/

* {
Expand Down

0 comments on commit 1c20f89

Please sign in to comment.