| @@ -5,24 +5,89 @@ | ||
| 5 | 5 | use ResponsiveMenu\View\View; |
| 6 | 6 | use ResponsiveMenu\Management\OptionManager; |
| 7 | 7 | use ResponsiveMenu\Formatters\Minifier; |
| 8 | 8 | |
| 9 | +/** | |
| 10 | +* Entry point for all front end functionality. | |
| 11 | +* | |
| 12 | +* All routing for the front end comes through the functions below. When a | |
| 13 | +* front end page is loaded in the browser it will come through here. | |
| 14 | +* | |
| 15 | +* @author Peter Featherstone <peter@featherstone.me> | |
| 16 | +* | |
| 17 | +* @since 3.0 | |
| 18 | +*/ | |
| 9 | 19 | class FrontController { |
| 10 | 20 | |
| 21 | + /** | |
| 22 | + * Constructor for setting up the FrontController. | |
| 23 | + * | |
| 24 | + * The constructor allows us to switch implementations for managing options | |
| 25 | + * and for rendering views. Useful for switching out mocked or stubbed | |
| 26 | + * classes during testing. | |
| 27 | + * | |
| 28 | + * @author Peter Featherstone <peter@featherstone.me> | |
| 29 | + * | |
| 30 | + * @since 3.0 | |
| 31 | + * | |
| 32 | + * @param OptionManager $manager Instance of a Management options class. | |
| 33 | + * @param View $view Instance of a View class for rendering. | |
| 34 | + */ | |
| 11 | 35 | public function __construct(OptionManager $manager, View $view) { |
| 12 | 36 | $this->manager = $manager; |
| 13 | 37 | $this->view = $view; |
| 14 | 38 | } |
| 15 | 39 | |
| 40 | + /** | |
| 41 | + * Main route for the front end. | |
| 42 | + * | |
| 43 | + * This is the default view for the plugin on an initial GET request to the | |
| 44 | + * front end page. | |
| 45 | + * | |
| 46 | + * @author Peter Featherstone <peter@featherstone.me> | |
| 47 | + * | |
| 48 | + * @since 3.0 | |
| 49 | + * | |
| 50 | + * @return string Output HTML from rendered view. | |
| 51 | + */ | |
| 16 | 52 | public function index() { |
| 17 | 53 | $options = $this->manager->all(); |
| 18 | 54 | $this->buildFrontEnd($options); |
| 19 | 55 | } |
| 20 | 56 | |
| 57 | + /** | |
| 58 | + * Preview route for the front end. | |
| 59 | + * | |
| 60 | + * This is the preview view for the plugin when the preview admin option is | |
| 61 | + * pressed. | |
| 62 | + * | |
| 63 | + * @author Peter Featherstone <peter@featherstone.me> | |
| 64 | + * | |
| 65 | + * @since 3.0 | |
| 66 | + * | |
| 67 | + * @return string Output HTML from rendered view. | |
| 68 | + */ | |
| 21 | 69 | public function preview() { |
| 22 | 70 | return $this->view->render('preview.html.twig'); |
| 23 | 71 | } |
| 24 | 72 | |
| 73 | + /** | |
| 74 | + * Helper private method to setup and build the front end. | |
| 75 | + * | |
| 76 | + * This is the preview view for the plugin when the preview admin option is | |
| 77 | + * pressed. We turn external files off to enable the preview options to | |
| 78 | + * take effect. | |
| 79 | + * | |
| 80 | + * TODO: This is a horrible method that really needs to be broken up in some | |
| 81 | + * way. There is a lot of setup and WordPress specific functionality going | |
| 82 | + * on here that would ideally be abstracted away. | |
| 83 | + * | |
| 84 | + * @author Peter Featherstone <peter@featherstone.me> | |
| 85 | + * | |
| 86 | + * @since 3.0 | |
| 87 | + * | |
| 88 | + * @param OptionsCollection $options A OptionsCollection object. | |
| 89 | + */ | |
| 25 | 90 | private function buildFrontEnd(OptionsCollection $options) { |
| 26 | 91 | add_filter('body_class', function($classes) use($options) { |
| 27 | 92 | $classes[] = 'responsive-menu-' . $options['animation_type'] . '-' . $options['menu_appear_from']; |
| 28 | 93 | return $classes; |
| @@ -29,10 +94,10 @@ | ||
| 29 | 94 | }); |
| 30 | 95 | |
| 31 | 96 | if($options['external_files'] == 'on'): |
| 32 | 97 | add_action('wp_enqueue_scripts', function() use($options) { |
| 33 | - $css_file = plugins_url() . '/responsive-menu-data/css/responsive-menu-' . get_current_blog_id() . '.css'; | |
| 34 | - $js_file = plugins_url() . '/responsive-menu-data/js/responsive-menu-' . get_current_blog_id() . '.js'; | |
| 98 | + $css_file = wp_upload_dir()['baseurl'] . '/responsive-menu/css/responsive-menu-' . get_current_blog_id() . '.css'; | |
| 99 | + $js_file = wp_upload_dir()['baseurl'] . '/responsive-menu/js/responsive-menu-' . get_current_blog_id() . '.js'; | |
| 35 | 100 | wp_enqueue_style('responsive-menu', $css_file, null, false); |
| 36 | 101 | wp_enqueue_script('responsive-menu', $js_file, ['jquery'], false, $options['scripts_in_footer'] == 'on' ? true : false); |
| 37 | 102 | }); |
| 38 | 103 | else: |