Skip to content

Commit

Permalink
New Obliq version, reorganize App Themes (#33)
Browse files Browse the repository at this point in the history
* Add json check to load language

* Add pagination to pages

* Update unit tests for export pages pagination

* Move lang and manifest to export_settings class

* Update unit tests for language and manifest

* Update export_settings endpoint & fix typo

* Update unit tests for export settings

* Update gulp tasks for compiling css files

* Update options class

* Remove hardcoded base-font-size from old theme scss

* Update Obliq css settings, use single default css file

* Make method not static

* Fix export content paths

* Add Obliq v2 files

* Update export settings tests

* Disable app loading on Firefox mobile and IE tablets

* Update detection tests

* Remove invalid cover_text setting

* Update export settings tests

* Modify theme config and compiling css

* Update themes unit tests

* Remove themes preview js files

* Remove magnific popup js files

* Reorganize app themes, switch theme

* Recompile admin css

* Change premium json paths

* Set version to 3.0, update change log

* Remove AMP integration

* Add manifest background color to app 2

* Update manifest colors

* Update message when selecting mobile theme

* Update plugin description

* Update social media links

* Select new theme at plugin activation

* Display admin notice for switching the mobile app theme

* Revize colors labels for Obliq v2

* Fix return to website url

* Update API key text from settings

* Remove Windows / IE support

* Update unit tests

* Fix comments button display, close comment form for Obliq v2

* Update export_manifest tests

* Update plugin description

* Update theme settings tests

* Add new PRO page and message for upgrading the mobile app

* Remove magnific-popup css

* Remove monetize section from settings tab

* Add discount notice in the pro tab

* Remove html tags from the translation files

* Fix padding for comments list in Obliq v2

* Remove settings param when connecting the API key
  • Loading branch information
anghelalexandra authored May 6, 2017
1 parent 04111cf commit aec7478
Show file tree
Hide file tree
Showing 103 changed files with 6,834 additions and 7,571 deletions.
140 changes: 106 additions & 34 deletions admin/class-admin-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,45 @@ protected function get_premium_manager()
}


/**
* Validate the new font settings, using the theme's configuration.
*
* @param $data = array with POST data
* @param $allowed_font_settings = array with the allowed font settings from the theme's configuration
*
* @return bool
*/
protected function validate_theme_fonts($data, $allowed_font_settings)
{

foreach (array('headlines', 'subtitles', 'paragraphs') as $font_type){

if (array_key_exists($font_type.'-font', $allowed_font_settings)) {

if (!isset($data['wmp_edittheme_font'.$font_type]) ||
!in_array($data['wmp_edittheme_font'.$font_type] - 1, array_keys(WMobilePack_Themes_Config::$allowed_fonts))){

return false;
}
}
}

return true;
}


/**
* Save new font settings into the database. Returns true if we need to compile the css file.
*
* @param $data = array with POST data
* @param $allowed_font_settings = array with the allowed font settings from the theme's configuration
*
* @return array with the following properties:
* - scss - If we need to compile the theme
* - updated - If any of the font settings have changed
*
*/
protected function update_theme_fonts($data)
protected function update_theme_fonts($data, $allowed_font_settings)
{

// check if we have to compile the scss file
Expand All @@ -86,33 +114,24 @@ protected function update_theme_fonts($data)
'updated' => false
);

$font_families = array();

foreach (array('headlines', 'subtitles', 'paragraphs') as $font_type) {
foreach (array('headlines', 'subtitles', 'paragraphs') as $font_type) {

// check if the font settings have changed
if (isset($data['wmp_edittheme_font'.$font_type])) {
if (isset($data['wmp_edittheme_font'.$font_type]) && array_key_exists($font_type.'-font', $allowed_font_settings)) {

// check if the font settings have changed
if ($data['wmp_edittheme_font'.$font_type] != WMobilePack_Options::get_setting('font_'.$font_type)) {

WMobilePack_Options::update_settings('font_' . $font_type, $data['wmp_edittheme_font' . $font_type]);
$response['updated'] = true;
}

// if a font different from the default ones was selected, we need to compile the css file
if ($data['wmp_edittheme_font' . $font_type] > 3) {
// if a font different from the default one was selected, we need to compile the css file
if ($data['wmp_edittheme_font'.$font_type] != 1) {
$response['scss'] = true;
}

$font_families[] = $data['wmp_edittheme_font'.$font_type];
}
}

// if the font settings are different for headlines, subtitles or paragraphs, we need to compile the css file
if (count(array_unique($font_families)) > 1){
$response['scss'] = true;
}

return $response;
}

Expand Down Expand Up @@ -145,8 +164,8 @@ protected function update_theme_color_scheme($data)
$response['updated'] = true;
}

// enable compiling for custom color schemes
if ($data['wmp_edittheme_colorscheme'] == 0) {
// enable compiling for the second & third color schemes
if ($data['wmp_edittheme_colorscheme'] != 1) {
$response['scss'] = true;
}
}
Expand All @@ -159,6 +178,7 @@ protected function update_theme_color_scheme($data)
* Save new colors settings into the database. Returns true if we need to compile the css file.
*
* @param $data = array with POST data
* @param $colors_variables = array with the color variables names from the theme configuration
*
* @return array with the following properties:
* - scss - If we need to compile the theme
Expand All @@ -167,7 +187,7 @@ protected function update_theme_color_scheme($data)
*
*
*/
protected function update_theme_colors($data)
protected function update_theme_colors($data, $colors_variables)
{

$response = array(
Expand All @@ -178,11 +198,10 @@ protected function update_theme_colors($data)
$arr_custom_colors = array();

// read theme and custom colors options
$selected_theme = WMobilePack_Options::get_setting('theme');
$selected_custom_colors = WMobilePack_Options::get_setting('custom_colors');

// how many colors does the theme have
$no_theme_colors = count(WMobilePack_Themes_Config::$color_schemes[$selected_theme]['vars']);
$no_theme_colors = count($colors_variables);

for ($i = 0; $i < $no_theme_colors; $i++) {

Expand Down Expand Up @@ -220,6 +239,25 @@ protected function update_theme_colors($data)
return $response;
}

/**
*
* Reset all theme settings when a theme is changed
*
*/
protected function reset_theme_settings()
{

// reset color schemes and fonts
WMobilePack_Options::update_settings('color_scheme', 1);
WMobilePack_Options::update_settings('custom_colors', array());
WMobilePack_Options::update_settings('font_headlines', 1);
WMobilePack_Options::update_settings('font_subtitles', 1);
WMobilePack_Options::update_settings('font_paragraphs', 1);
WMobilePack_Options::update_settings('font_size', 1);

$this->remove_custom_theme();
}


/**
*
Expand All @@ -243,6 +281,38 @@ protected function remove_custom_theme(){
}


/**
*
* Method used to switch to a new theme
*
*/
public function theme_switch()
{

if (current_user_can('manage_options')) {

$status = 0;

if (!empty($_GET) && isset($_GET['theme'])){
if (in_array($_GET['theme'], array_keys(WMobilePack_Themes_Config::get_allowed_themes()) )) {

$new_theme = $_GET['theme'];

if (WMobilePack_Options::get_setting('theme') != $new_theme){

$status = 1;
WMobilePack_Options::update_settings('theme', $new_theme);
$this->reset_theme_settings();
}
}
}

echo $status;
}

exit();
}

/**
*
* Method used to save the custom settings for a theme.
Expand All @@ -256,8 +326,6 @@ protected function remove_custom_theme(){
* - settings were not changed
* - other error messages resulted from compiling the theme
*
* @todo Revert to old fonts settings if the theme was not successfully compiled.
*
*/
public function theme_settings()
{
Expand All @@ -268,16 +336,20 @@ public function theme_settings()
'messages' => array()
);

// handle color schemes and fonts (look & feel page)
if (isset($_POST['wmp_edittheme_colorscheme']) && is_numeric($_POST['wmp_edittheme_colorscheme']) &&
isset($_POST['wmp_edittheme_fontheadlines']) && is_numeric($_POST['wmp_edittheme_fontheadlines']) &&
isset($_POST['wmp_edittheme_fontsubtitles']) && is_numeric($_POST['wmp_edittheme_fontsubtitles']) &&
isset($_POST['wmp_edittheme_fontparagraphs']) && is_numeric($_POST['wmp_edittheme_fontparagraphs'])){
// get the theme's configuration
$theme_config = WMobilePack_Themes_Config::get_theme_config();

if ($theme_config !== false) {

// build array with the allowed fonts sizes
$allowed_fonts_sizes = array();
foreach (WMobilePack_Themes_Config::$allowed_fonts_sizes as $allowed_font_size) {
$allowed_fonts_sizes[] = $allowed_font_size['size'];
}

if (in_array($_POST['wmp_edittheme_colorscheme'], array(0,1,2,3)) &&
in_array($_POST['wmp_edittheme_fontheadlines']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts)) &&
in_array($_POST['wmp_edittheme_fontsubtitles']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts)) &&
in_array($_POST['wmp_edittheme_fontparagraphs']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts))){
// handle color schemes and fonts (look & feel page)
if ($this->validate_theme_fonts($_POST, $theme_config['fonts']) &&
isset($_POST['wmp_edittheme_colorscheme']) && in_array($_POST['wmp_edittheme_colorscheme'], array(0,1,2,3))){

// check if the theme compiler can be successfully loaded
$wmp_themes_compiler = $this->get_theme_manager();
Expand All @@ -293,7 +365,7 @@ public function theme_settings()

if ($_POST['wmp_edittheme_colorscheme'] == 0) {

$updated_colors = $this->update_theme_colors($_POST);
$updated_colors = $this->update_theme_colors($_POST, $theme_config['vars']);

// if the colors were not successfully processed, display error message and exit
if ($updated_colors['error']) {
Expand All @@ -306,7 +378,7 @@ public function theme_settings()
}

// update fonts and check if we need to compile the scss file
$updated_fonts = $this->update_theme_fonts($_POST);
$updated_fonts = $this->update_theme_fonts($_POST, $theme_config['fonts']);

// update color scheme
$updated_color_scheme = $this->update_theme_color_scheme($_POST);
Expand Down Expand Up @@ -346,7 +418,7 @@ public function theme_settings()

} else {

// we have reverted to the first color scheme (which is 1), remove custom theme file
// we have reverted to the default theme settings, remove custom theme file
$this->remove_custom_theme();
$arr_response['status'] = 1;
}
Expand Down
11 changes: 7 additions & 4 deletions admin/class-admin-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class WMobilePack_Admin_Init
'capability' => 'wmp-options-settings',
'function' => 'settings',
'enqueue_hook' => 'wmp_admin_load_settings_js'
),
array(
'page_title' => "PRO",
'capability' => 'wmp-options-pro',
'function' => 'pro'
)
);

Expand Down Expand Up @@ -198,7 +203,7 @@ public function wmp_admin_menu()
public function wmp_admin_enqueue_scripts()
{
// enqueue styles
wp_enqueue_style(WMobilePack_Options::$prefix.'css_general', plugins_url(WMP_DOMAIN.'/admin/css/general.css'), array(), WMP_VERSION);
wp_enqueue_style(WMobilePack_Options::$prefix.'css_general', plugins_url(WMP_DOMAIN.'/admin/css/general-1493993256.css'), array(), WMP_VERSION);

// enqueue scripts
$dependencies = array('jquery-core', 'jquery-migrate');
Expand Down Expand Up @@ -227,9 +232,7 @@ public function wmp_admin_enqueue_scripts()
public function wmp_admin_load_themes_js()
{

wp_enqueue_style(WMobilePack_Options::$prefix.'css_magnific_popup', plugins_url(WMP_DOMAIN.'/admin/css/magnific-popup.css'), array(), '0.9.9');
wp_enqueue_script(WMobilePack_Options::$prefix.'js_magnific_popup', plugins_url(WMP_DOMAIN.'/admin/js/UI.Interface/Lib/jquery.magnific-popup.min.js'), array(), '0.9.9');
wp_enqueue_script(WMobilePack_Options::$prefix.'js_theming_preview', plugins_url(WMP_DOMAIN.'/admin/js/UI.Modules/Theming/WMP_THEMES_GALLERY.min.js'), array(), WMP_VERSION);
wp_enqueue_script(WMobilePack_Options::$prefix.'js_switchtheme', plugins_url(WMP_DOMAIN.'/admin/js/UI.Modules/Theming/WMP_SWITCH_THEME.min.js'), array(), WMP_VERSION);
}


Expand Down
32 changes: 20 additions & 12 deletions admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,20 @@ public function settings() {
include(WMP_PLUGIN_PATH.'admin/pages/settings.php');
}

/**
*
* Method used to render the PRO page from the admin area
*
*/
public function pro(){

include(WMP_PLUGIN_PATH.'admin/pages/pro.php');
}


/**
*
* Method used to render the Premium page from the admin area
* Method used to render the Premium page from the admin area (connected API key)
*
*/
public function premium(){
Expand Down Expand Up @@ -425,14 +434,13 @@ public static function upgrade_pro_link(){

if (array_key_exists('premium', $upgrade_content)) {

if (array_key_exists('packages', $upgrade_content['premium']) && is_array($upgrade_content['premium']['packages']) && count($upgrade_content['premium']['packages']) >= 1) {

$package = $upgrade_content['premium']['packages'][0];
if (isset($upgrade_content['premium']['packages']['upgrade_link']) &&
filter_var($upgrade_content['premium']['packages']['upgrade_link'], FILTER_VALIDATE_URL)) {

if (array_key_exists('button_link', $package)) {
return $package['button_link'];
}
return $upgrade_content['premium']['packages']['upgrade_link'];
}

return false;
}
}

Expand All @@ -453,16 +461,16 @@ public static function upgrade_pro_themes($upgrade_content = false){

if (is_array($upgrade_content) && !empty($upgrade_content)){

if (array_key_exists('premium', $upgrade_content)) {
if (array_key_exists('premium', $upgrade_content) && array_key_exists('themes', $upgrade_content['premium'])) {

if (array_key_exists('themes', $upgrade_content['premium']) && is_array($upgrade_content['premium']['themes'])) {
if (array_key_exists('list', $upgrade_content['premium']['themes']) && is_array($upgrade_content['premium']['themes']['list'])) {

foreach ($upgrade_content['premium']['themes'] as $theme){
foreach ($upgrade_content['premium']['themes']['list'] as $theme){

if (isset($theme['title']) &&
isset($theme['icon']) && filter_var($theme['icon'], FILTER_VALIDATE_URL) &&
(!isset($theme['bundle']) || is_numeric($theme['bundle'])) &&
(!isset($theme['preorder']) || is_numeric($theme['preorder']))
(!isset($theme['demo']['link']) || filter_var($theme['demo']['link'], FILTER_VALIDATE_URL)) &&
(!isset($theme['details']['link']) || filter_var($theme['details']['link'], FILTER_VALIDATE_URL))
){
$themes[] = $theme;
}
Expand Down
2 changes: 1 addition & 1 deletion admin/css/general.css → admin/css/general-1493993256.css

Large diffs are not rendered by default.

Loading

0 comments on commit aec7478

Please sign in to comment.