Пример #1
0
 public static function mobiloud_activate()
 {
     add_option('mobiloud_do_activation_redirect', true);
     if (!self::get_option('ml_activation_tracked', false)) {
         self::set_option('ml_activation_tracked', true);
         ml_track('plugin activated', array('mixpanel'));
     }
     if (!self::get_option('ml_activation_tracked_pa', false)) {
         self::set_option('ml_activation_tracked_pa', 'activated');
     }
     self::set_default_options();
     self::run_db_install();
 }
 public static function menu_get_started()
 {
     if (!isset($_GET['tab'])) {
         $_GET['tab'] = 'design';
     }
     $tab = sanitize_text_field($_GET['tab']);
     switch ($tab) {
         default:
         case 'design':
             wp_enqueue_script('wp-color-picker');
             wp_enqueue_media();
             wp_enqueue_style('wp-color-picker');
             wp_register_script('mobiloud-app-preview-js', MOBILOUD_PLUGIN_URL . '/assets/js/mobiloud-app-preview.js', array('jquery'));
             wp_enqueue_script('mobiloud-app-preview-js');
             wp_register_style('mobiloud-app-preview', MOBILOUD_PLUGIN_URL . "/assets/css/mobiloud-app-preview.css");
             wp_enqueue_style("mobiloud-app-preview");
             global $current_user;
             get_currentuserinfo();
             /**
              * Process Form
              */
             if (count($_POST) && check_admin_referer('form-get_started_design')) {
                 Mobiloud::set_option('ml_preview_upload_image', sanitize_text_field($_POST['ml_preview_upload_image']));
                 Mobiloud::set_option('ml_preview_theme_color', sanitize_text_field($_POST['ml_preview_theme_color']));
                 switch ($_POST['homepagetype']) {
                     case 'ml_home_article_list_enabled':
                         Mobiloud::set_option('ml_home_article_list_enabled', true);
                         Mobiloud::set_option('ml_home_page_enabled', false);
                         Mobiloud::set_option('ml_home_url_enabled', false);
                         break;
                     case 'ml_home_page_enabled':
                         Mobiloud::set_option('ml_home_article_list_enabled', false);
                         Mobiloud::set_option('ml_home_page_enabled', true);
                         Mobiloud::set_option('ml_home_url_enabled', false);
                         break;
                     case 'ml_home_url_enabled':
                         Mobiloud::set_option('ml_home_article_list_enabled', false);
                         Mobiloud::set_option('ml_home_page_enabled', false);
                         Mobiloud::set_option('ml_home_url_enabled', true);
                         break;
                 }
                 Mobiloud::set_option('ml_article_list_view_type', sanitize_text_field($_POST['ml_article_list_view_type']));
                 if (isset($_POST['ml_datetype'])) {
                     Mobiloud::set_option('ml_datetype', sanitize_text_field($_POST['ml_datetype']));
                 }
                 if (isset($_POST['ml_dateformat'])) {
                     Mobiloud::set_option('ml_dateformat', sanitize_text_field($_POST['ml_dateformat']));
                 }
                 Mobiloud::set_option('ml_home_page_id', sanitize_text_field($_POST['ml_home_page_id']));
                 Mobiloud::set_option('ml_home_url', sanitize_text_field($_POST['ml_home_url']));
                 Mobiloud::set_option('ml_show_article_list_menu_item', isset($_POST['ml_show_article_list_menu_item']));
                 Mobiloud::set_option('ml_article_list_menu_item_title', sanitize_text_field($_POST['ml_article_list_menu_item_title']));
                 self::set_task_status('design', 'complete');
             }
             if (strlen(trim(get_option('ml_preview_theme_color'))) <= 2) {
                 update_option("ml_preview_theme_color", '#1e73be');
             }
             $root_url = network_site_url('/');
             $plugins_url = plugins_url();
             $mobiloudPluginUrl = MOBILOUD_PLUGIN_URL;
             $mobiloudPluginVersion = MOBILOUD_PLUGIN_VERSION;
             $appname = get_bloginfo('name');
             if (!self::initial_details_saved()) {
                 self::render_part_view('initial_details', compact('current_user'));
             }
             self::render_view('get_started_design', 'get_started');
             //self::track_user_event('view_get_started_design');
             break;
         case 'menu_config':
             /**
              * Process Form
              */
             if (count($_POST) && check_admin_referer('form-get_started_menu_config')) {
                 ml_remove_all_categories();
                 if (count($_POST['ml-menu-categories'])) {
                     foreach ($_POST['ml-menu-categories'] as $cat_ID) {
                         ml_add_category(sanitize_text_field($cat_ID));
                     }
                 }
                 $menu_terms = array();
                 if (count($_POST['ml-menu-terms'])) {
                     foreach ($_POST['ml-menu-terms'] as $term) {
                         $menu_terms[] = $term;
                     }
                 }
                 Mobiloud::set_option('ml_menu_terms', $menu_terms);
                 $menu_tags = array();
                 if (count($_POST['ml-menu-tags'])) {
                     foreach ($_POST['ml-menu-tags'] as $tag) {
                         $menu_tags[] = $tag;
                     }
                 }
                 Mobiloud::set_option('ml_menu_tags', $menu_tags);
                 ml_remove_all_pages();
                 if (count($_POST['ml-menu-pages'])) {
                     foreach ($_POST['ml-menu-pages'] as $page_ID) {
                         ml_add_page(sanitize_text_field($page_ID));
                     }
                 }
                 $menu_links = array();
                 if (count($_POST['ml-menu-links'])) {
                     foreach ($_POST['ml-menu-links'] as $menu_link) {
                         $menu_link_vals = explode(":=:", $menu_link);
                         $menu_links[] = array('urlTitle' => sanitize_text_field($menu_link_vals[0]), 'url' => sanitize_text_field($menu_link_vals[1]));
                     }
                 }
                 Mobiloud::set_option('ml_menu_urls', $menu_links);
                 Mobiloud::set_option('ml_menu_show_favorites', $_POST['ml_menu_show_favorites'] == 'true');
                 Mobiloud::set_option('ml_show_android_cat_tabs', $_POST['ml_show_android_cat_tabs'] == 'true');
                 self::set_task_status('menu_config', 'complete');
                 self::track_user_event('menu_config_saved');
             }
             self::render_view('get_started_menu_config', 'get_started');
             self::track_user_event('view_get_started_menu_config');
             break;
         case 'test_app':
             $plugin_url = str_replace("mobiloud-mobile-app-plugin/", "", MOBILOUD_PLUGIN_URL);
             $check_url = 'http://www.mobiloud.com/simulator/check.php?url=' . urlencode(MOBILOUD_PLUGIN_URL);
             $loadDemo = false;
             $check_content = @file_get_contents($check_url);
             $error_reason = '';
             if (self::isJson($check_content)) {
                 $check_result = json_decode($check_content, true);
                 if (isset($check_result['error'])) {
                     $loadDemo = true;
                     $error_reason = $check_result['error'];
                 }
             } else {
                 $loadDemo = true;
                 $error_reason = 'we are unable to reach your site';
             }
             $params_array = array('plugin_url' => urldecode($plugin_url));
             $params = urlencode(json_encode($params_array));
             self::render_view('get_started_test_app', 'get_started', compact('loadDemo', 'params', 'error_reason'));
             self::track_user_event('view_get_started_test_app');
             self::set_task_status('test_app', 'complete');
             break;
         case 'publish':
             self::render_view('get_started_publish', 'get_started');
             self::track_user_event('view_get_started_publish');
             break;
     }
     if (Mobiloud::get_option('ml_activation_tracked_pa') == 'activated') {
         ml_track('Plugin installed', array('perfect_audience'));
         Mobiloud::set_option('ml_activation_tracked_pa', true);
     }
     if (is_null(get_option('ml_license_tracked', null)) && strlen(Mobiloud::get_option('ml_pb_app_id')) >= 0 && strlen(Mobiloud::get_option('ml_pb_secret_key')) >= 0) {
         ml_track('License details saved', array('perfect_audience'));
         update_option('ml_license_tracked', true);
     }
 }