From 7110857caa2bec4dc45c2f2eeba3e537e82fae79 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Sat, 20 May 2017 17:02:17 -0400 Subject: Update wordpress-mobile-pack 3.0 Signed-off-by: Anthony G. Basile --- .../export/class-export-settings.php | 329 +++++++++++++++++++++ 1 file changed, 329 insertions(+) create mode 100755 plugins/wordpress-mobile-pack/export/class-export-settings.php (limited to 'plugins/wordpress-mobile-pack/export/class-export-settings.php') diff --git a/plugins/wordpress-mobile-pack/export/class-export-settings.php b/plugins/wordpress-mobile-pack/export/class-export-settings.php new file mode 100755 index 00000000..f68e2a39 --- /dev/null +++ b/plugins/wordpress-mobile-pack/export/class-export-settings.php @@ -0,0 +1,329 @@ + $blog_name, + 'start_url' => home_url(), + 'display' => 'standalone', + 'orientation' => 'any' + ); + + if (!class_exists('WMobilePack_Themes_Config')) { + require_once(WMP_PLUGIN_PATH . 'inc/class-wmp-themes-config.php'); + } + + $background_color = WMobilePack_Themes_Config::get_manifest_background(); + + if ($background_color !== false){ + $arr_manifest['theme_color'] = $background_color; + $arr_manifest['background_color'] = $background_color; + } + + } else { + + // remove domain name from the launch path + $launch_path = home_url(); + $launch_path = str_replace('http://' . $_SERVER['HTTP_HOST'], '', $launch_path); + $launch_path = str_replace('https://' . $_SERVER['HTTP_HOST'], '', $launch_path); + + $arr_manifest = array( + 'name' => $blog_name, + 'launch_path' => $launch_path, + 'developer' => array( + "name" => $blog_name + ) + ); + } + + // load icon from the local settings and folder + $icon_path = WMobilePack_Options::get_setting('icon'); + + if ($icon_path != '') { + + $WMP_Uploads = $this->get_uploads_manager(); + $icon_path = $WMP_Uploads->get_file_url($icon_path); + } + + // set icon depending on the manifest file type + if ($icon_path != '') { + + if ($_GET['content'] == 'androidmanifest') { + + $arr_manifest['icons'] = array( + array( + "src" => $icon_path, + "sizes" => "192x192" + ) + ); + + } else { + $arr_manifest['icons'] = array( + '152' => $icon_path, + ); + } + } + + return json_encode($arr_manifest); + + } + + /** + * Export manifest files for Android or Mozilla (Premium settings). + * + * The method receives a single GET param: + * + * - content = 'androidmanifest' or 'mozillamanifest' + * + * @return string + */ + public function export_manifest_premium(){ + + if (WMobilePack_Options::get_setting('premium_active') == 1 && WMobilePack_Options::get_setting('premium_api_key') != ''){ + + if (!class_exists('WMobilePack_Premium')) + require_once(WMP_PLUGIN_PATH.'inc/class-wmp-premium.php'); + + $premium_manager = new WMobilePack_Premium(); + $arr_config_premium = $premium_manager->get_premium_config(); + + if ($arr_config_premium !== null){ + + if (!isset($arr_config_premium['domain_name']) || $arr_config_premium['domain_name'] == '') { + + $blog_name = $arr_config_premium['title']; + + if (isset($arr_config_premium['kit_type']) && $arr_config_premium['kit_type'] == 'wpmp') { + $blog_name = urldecode($blog_name); + } + + // init response depending on the manifest type + if (isset($_GET['content']) && $_GET['content'] == 'androidmanifest') { + + $arr_manifest = array( + 'name' => $blog_name, + 'start_url' => home_url(), + 'display' => 'standalone' + ); + + } else { + + // remove domain name from the launch path + $launch_path = home_url(); + $launch_path = str_replace('http://' . $_SERVER['HTTP_HOST'], '', $launch_path); + $launch_path = str_replace('https://' . $_SERVER['HTTP_HOST'], '', $launch_path); + + $arr_manifest = array( + 'name' => $blog_name, + 'launch_path' => $launch_path, + 'developer' => array( + "name" => $blog_name + ) + ); + } + + // load icon path + $icon_path = false; + + if (isset($arr_config_premium['icon_path']) && $arr_config_premium['icon_path'] != '') { + + // Check if we have a secure https connection + $is_secure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443; + + $cdn_apps = $is_secure ? $arr_config_premium['cdn_apps_https'] : $arr_config_premium['cdn_apps']; + $icon_path = $cdn_apps . "/" . $arr_config_premium['shorten_url'] . '/' . $arr_config_premium['icon_path']; + } + + // set icon depending on the manifest file type + if ($icon_path != false) { + + if ($_GET['content'] == 'androidmanifest') { + + $arr_manifest['icons'] = array( + array( + "src" => $icon_path, + "sizes" => "192x192" + ) + ); + + } else { + $arr_manifest['icons'] = array( + '152' => $icon_path, + ); + } + } + + return json_encode($arr_manifest); + } + } + } + } + + /** + * + * Export settings file. + * + */ + public function export_settings() + { + + $app = $this->get_application_manager(); + $app_settings = $app->load_app_settings(); + + $frontend_path = plugins_url()."/".WMP_DOMAIN."/frontend/"; + $export_path = plugins_url()."/".WMP_DOMAIN."/export/"; + + $settings = array(); + + $settings['export'] = array( + + 'categories' => array( + 'find' => $export_path . 'content.php?content=exportcategories', + 'findOne' => $export_path . 'content.php?content=exportcategory' + ), + + 'posts' => array( + 'find' => $export_path . 'content.php?content=exportarticles', + 'findOne' => $export_path . 'content.php?content=exportarticle' + ), + + 'pages' => array( + 'find' => $export_path . 'content.php?content=exportpages', + 'findOne' => $export_path . 'content.php?content=exportpage' + ), + + 'comments' => array( + 'find' => $export_path . 'content.php?content=exportcomments', + 'insert' => $export_path . 'content.php?content=savecomment' + ) + ); + + $settings['translate'] = array( + 'path' => $export_path.'content.php?content=apptexts&locale='.get_locale().'&format=json', + 'language' => $app->get_language(get_locale()) + ); + + $settings['socialMedia'] = array( + 'facebook' => (bool)$app_settings['enable_facebook'], + 'twitter' => (bool)$app_settings['enable_twitter'], + 'google' => (bool)$app_settings['enable_google'] + ); + + $settings['commentsToken'] = $app_settings['comments_token']; + + if ($app_settings['posts_per_page'] == 'single') { + $settings['articlesPerCard'] = 1; + + } elseif ($app_settings['posts_per_page'] == 'double') { + $settings['articlesPerCard'] = 2; + + } else { + $settings['articlesPerCard'] = 'auto'; + } + + if ($app_settings['display_website_link']) { + $spliter = parse_url(home_url(), PHP_URL_QUERY) ? '&' : '?'; + $settings['websiteUrl'] = home_url() . $spliter . WMobilePack_Cookie::$prefix . 'theme_mode=desktop'; + } + + $settings['logo'] = $app_settings['logo']; + $settings['icon'] = $app_settings['icon']; + $settings['defaultCover'] = $app_settings['cover'] != '' ? $app_settings['cover'] : $frontend_path."images/pattern-".rand(1, 6).".jpg"; + + return json_encode($settings); + + } + + } +} -- cgit v1.2.3-65-gdbad