Esempio n. 1
0
 public static function template_redirect()
 {
     global $wp_query;
     if (isset($wp_query->query_vars['wpak_addon_file']) && !empty($wp_query->query_vars['wpak_addon_file'])) {
         if (!empty($_GET['wpak_app_id'])) {
             $app_id = esc_attr($_GET['wpak_app_id']);
             //can be ID or slug
             $app = WpakApps::get_app($app_id);
             if (!empty($app)) {
                 $app_id = $app->ID;
                 $default_capability = current_user_can('wpak_edit_apps') ? 'wpak_edit_apps' : 'manage_options';
                 $capability = apply_filters('wpak_private_simulation_capability', $default_capability, $app_id);
                 if (WpakApps::get_app_simulation_is_secured($app_id) && !current_user_can($capability)) {
                     wp_nonce_ays('wpak-addon-file');
                 }
                 $file = $wp_query->query_vars['wpak_addon_file'];
                 if (preg_match('/([^\\/]+?)\\/(.+[\\.js|\\.css|\\.html])$/', $file, $matches)) {
                     $addon_slug = $matches[1];
                     $asset_file = $matches[2];
                     $app_addons = self::get_app_addons($app_id);
                     if (array_key_exists($addon_slug, $app_addons)) {
                         $addon = $app_addons[$addon_slug];
                         if ($asset_full_path = $addon->get_asset_file($asset_file)) {
                             $file_type = pathinfo($asset_full_path, PATHINFO_EXTENSION);
                             if ($file_type == 'js') {
                                 header("Content-type: text/javascript;  charset=utf-8");
                             } elseif ($file_type == 'css') {
                                 header("Content-type: text/css;  charset=utf-8");
                             } elseif ($file_type == 'html') {
                                 header("Content-type: text/html;  charset=utf-8");
                             }
                             echo file_get_contents($asset_full_path);
                             exit;
                         } else {
                             header("HTTP/1.0 404 Not Found");
                             _e('Addon file not found', WpAppKit::i18n_domain);
                             exit;
                         }
                     } else {
                         header("HTTP/1.0 404 Not Found");
                         _e('Addon not found for this app', WpAppKit::i18n_domain);
                         exit;
                     }
                 } else {
                     header("HTTP/1.0 404 Not Found");
                     _e('Wrong addon file', WpAppKit::i18n_domain);
                     exit;
                 }
             } else {
                 header("HTTP/1.0 404 Not Found");
                 _e('App not found', WpAppKit::i18n_domain) . ' : [' . $app_id . ']';
                 exit;
             }
         } else {
             header("HTTP/1.0 404 Not Found");
             _e('App id not found in _GET parmeters', WpAppKit::i18n_domain);
             exit;
         }
     }
 }
Esempio n. 2
0
 public static function template_redirect()
 {
     global $wp_query;
     if (isset($wp_query->query_vars['wpak_appli_file']) && !empty($wp_query->query_vars['wpak_appli_file'])) {
         if (!empty($_GET['wpak_app_id'])) {
             $app_id = esc_attr($_GET['wpak_app_id']);
             //can be ID or slug
             $app = WpakApps::get_app($app_id);
             if (!empty($app)) {
                 $app_id = $app->ID;
                 $default_capability = current_user_can('wpak_edit_apps') ? 'wpak_edit_apps' : 'manage_options';
                 $capability = apply_filters('wpak_private_simulation_capability', $default_capability, $app_id);
                 if (WpakApps::get_app_simulation_is_secured($app_id) && !current_user_can($capability)) {
                     wp_nonce_ays($action);
                 }
                 $file = $wp_query->query_vars['wpak_appli_file'];
                 switch ($file) {
                     case 'config.js':
                         header("Content-type: text/javascript;  charset=utf-8");
                         echo "/* Wp AppKit simulator config.js */\n";
                         self::get_config_js($app_id, true);
                         exit;
                     case 'config.xml':
                         header("Content-type: text/xml;  charset=utf-8");
                         self::get_config_xml($app_id, true);
                         exit;
                     default:
                         exit;
                 }
             } else {
                 echo __('App not found', WpAppKit::i18n_domain) . ' : [' . $app_id . ']';
                 exit;
             }
         } else {
             _e('App id not found in _GET parameters', WpAppKit::i18n_domain);
             exit;
         }
     }
 }
Esempio n. 3
0
 public static function template_redirect()
 {
     global $wp_query;
     //The following is only for app simulation in browser
     if (isset($wp_query->query_vars['wpak_theme_file']) && !empty($wp_query->query_vars['wpak_theme_file'])) {
         $file = $wp_query->query_vars['wpak_theme_file'];
         //For assets files like fonts, images or css we can't
         //be sure that the wpak_app_id GET arg is there, because they can
         //be included directly in themes sources (CSS/HTML) where the WP AppKit API can't
         //be used. So, we can't check that the file comes from the right app
         //or theme > we just check that the theme the asset belongs to is a real
         //WP AppKit theme and that at least one app uses this theme :
         if (self::is_asset_file($file)) {
             if (preg_match('/([^\\/]+?)\\/(.+)$/', $file, $matches)) {
                 $theme_slug = $matches[1];
                 $theme_file = $matches[2];
                 if (self::is_theme($theme_slug) && self::theme_is_used($theme_slug)) {
                     if ($file_full_path = self::get_theme_file($theme_slug, $theme_file)) {
                         self::exit_send_theme_file($file_full_path);
                     }
                 } else {
                     header("HTTP/1.0 404 Not Found");
                     _e('Not a valid theme file', WpAppKit::i18n_domain);
                     exit;
                 }
             } else {
                 header("HTTP/1.0 404 Not Found");
                 _e('Not a valid theme file path', WpAppKit::i18n_domain);
                 exit;
             }
         } else {
             if (!empty($_GET['wpak_app_id'])) {
                 //For non considered asset files (like JS) we check that the file is
                 //asked for the correct app and for the theme of the app:
                 $app_id = esc_attr($_GET['wpak_app_id']);
                 //can be ID or slug
                 $app = WpakApps::get_app($app_id);
                 if (!empty($app)) {
                     $app_id = $app->ID;
                     $default_capability = current_user_can('wpak_edit_apps') ? 'wpak_edit_apps' : 'manage_options';
                     $capability = apply_filters('wpak_private_simulation_capability', $default_capability, $app_id);
                     if (WpakApps::get_app_simulation_is_secured($app_id) && !current_user_can($capability)) {
                         wp_nonce_ays('wpak-theme-file');
                     }
                     if (preg_match('/([^\\/]+?)\\/(.+)$/', $file, $matches)) {
                         $theme_slug = $matches[1];
                         $theme_file = $matches[2];
                         $app_theme = WpakThemesStorage::get_current_theme($app_id);
                         if ($theme_slug == $app_theme) {
                             if ($file_full_path = self::get_theme_file($theme_slug, $theme_file)) {
                                 self::exit_send_theme_file($file_full_path);
                             } else {
                                 header("HTTP/1.0 404 Not Found");
                                 _e('Theme file not found', WpAppKit::i18n_domain);
                                 exit;
                             }
                         } else {
                             header("HTTP/1.0 404 Not Found");
                             _e('Asked theme is not activated for the given app', WpAppKit::i18n_domain);
                             exit;
                         }
                     } else {
                         header("HTTP/1.0 404 Not Found");
                         _e('Wrong theme file', WpAppKit::i18n_domain);
                         exit;
                     }
                 } else {
                     header("HTTP/1.0 404 Not Found");
                     _e('App not found', WpAppKit::i18n_domain) . ' : [' . $app_id . ']';
                     exit;
                 }
             } else {
                 header("HTTP/1.0 404 Not Found");
                 _e('App id not found in _GET parmeters', WpAppKit::i18n_domain);
                 exit;
             }
         }
     }
 }