Passed
Push — master ( 408fa2...2f137e )
by Warwick
11:07 queued 12s
created
classes/frontend/class-layout.php 1 patch
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -10,154 +10,154 @@
 block discarded – undo
10 10
  */
11 11
 class Layout {
12 12
 
13
-	/**
14
-	 * Holds class instance
15
-	 *
16
-	 * @since 1.0.0
17
-	 *
18
-	 * @var      object \lsx\search\classes\frontend\Layout()
19
-	 */
20
-	protected static $instance = null;
21
-
22
-	/**
23
-	 * Contructor
24
-	 */
25
-	public function __construct() {
26
-		add_action( 'wp', array( $this, 'load_functions' ), 24 );
27
-	}
28
-
29
-	/**
30
-	 * Return an instance of this class.
31
-	 *
32
-	 * @since 1.0.0
33
-	 *
34
-	 * @return    object \lsx\search\classes\frontend\Layout()    A single instance of this class.
35
-	 */
36
-	public static function get_instance() {
37
-		// If the single instance hasn't been set, set it now.
38
-		if ( null == self::$instance ) {
39
-			self::$instance = new self();
40
-		}
41
-		return self::$instance;
42
-	}
43
-
44
-	/**
45
-	 * Check all settings.
46
-	 */
47
-	public function load_functions() {
48
-		$lsx_search = LSX_Search::get_instance();
49
-		if ( $lsx_search->frontend->search_enabled ) {
50
-			if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_layout_switcher_enable' ] ) ) {
51
-				add_filter( 'lsx_blog_customizer_show_switcher', array( $this, 'show_layout_switcher' ), 10, 1 );
52
-				add_filter( 'lsx_layout_switcher_options', array( $this, 'lsx_layout_switcher_options' ), 10, 1 );
53
-				add_filter( 'lsx_layout_switcher_page_key', array( $this, 'lsx_layout_switcher_page_key' ), 10, 1 );
54
-				add_filter( 'lsx_layout_switcher_options_default', array( $this, 'lsx_layout_switcher_options_default' ), 10, 1 );
55
-
56
-				// Layout Classes
57
-				add_filter( 'woocommerce_product_loop_start', array( $this, 'woocommerce_layout_class' ), 10, 1 );
58
-			}
59
-		}
60
-	}
61
-
62
-	/**
63
-	 * Display the woocommerce archive swticher.
64
-	 */
65
-	public function show_layout_switcher( $show = false ) {
66
-		if ( is_search() ) {
67
-			$archive_layout_switcher = get_theme_mod( 'lsx_blog_customizer_archive_layout_switcher', false );
68
-			if ( true === $archive_layout_switcher ) {
69
-				$show = true;
70
-			}
71
-		}
72
-		return $show;
73
-	}
74
-
75
-	/**
76
-	 * Remove the default and half-grid options from the results layouts.
77
-	 *
78
-	 * @param  array $layout_options
79
-	 * @return array
80
-	 */
81
-	public function lsx_layout_switcher_options( $layout_options ) {
82
-		unset( $layout_options['default'] );
83
-		unset( $layout_options['half-grid'] );
84
-		return $layout_options;
85
-	}
86
-
87
-	/**
88
-	 * Replace the key for the layout switcher.
89
-	 *
90
-	 * @param  string $page_key
91
-	 * @return string
92
-	 */
93
-	public function lsx_layout_switcher_page_key( $page_key ) {
94
-		$lsx_search = LSX_Search::get_instance();
95
-		$page_key   = str_replace( '_search', '', $lsx_search->frontend->search_prefix );
96
-		return $page_key;
97
-	}
98
-
99
-	/**
100
-	 * CHange the default layout to a grid layout.
101
-	 *
102
-	 * @param  string $default
103
-	 * @return string
104
-	 */
105
-	public function lsx_layout_switcher_options_default( $default = 'grid' ) {
106
-		$lsx_search = LSX_Search::get_instance();
107
-		$default    = 'grid';
108
-		if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) && ! empty( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) ) {
109
-			$default = $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ];
110
-		}
111
-		return $default;
112
-	}
113
-
114
-	/**
115
-	 * Controls the layout for the woocommerce shop page.
116
-	 */
117
-	public function woocommerce_layout_class( $output = '' ) {
118
-		$default_class = $this->lsx_layout_switcher_options_default();
119
-		$selected      = $this->get_layout_value_from_cookie( 'product' );
120
-		if ( '' !== $selected ) {
121
-			$default_class = $selected;
122
-		}
123
-		$output = str_replace( 'products', 'products ' . $default_class, $output );
124
-		return $output;
125
-	}
126
-
127
-	/**
128
-	 * Get layout value from cookie
129
-	 *
130
-	 * @since 1.0.0
131
-	 */
132
-	public function get_layout_value_from_cookie( $page_key = 'blog' ) {
133
-		$archive_layout = 'grid';
134
-
135
-		if ( isset( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ) ) {
136
-			$archive_layout_from_cookie = sanitize_key( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] );
137
-			$archive_layout_from_cookie = $this->sanitize_select_layout_switcher( $archive_layout_from_cookie );
138
-
139
-			if ( ! empty( $archive_layout_from_cookie ) ) {
140
-				$archive_layout = $archive_layout_from_cookie;
141
-			}
142
-		}
143
-		return $archive_layout;
144
-	}
145
-
146
-	/**
147
-	 * Sanitize select (layout switcher).
148
-	 *
149
-	 * @since 1.0.0
150
-	 */
151
-	public function sanitize_select_layout_switcher( $input ) {
152
-		$valid = array(
153
-			'list'      => esc_html__( 'List', 'lsx-search' ),
154
-			'grid'      => esc_html__( 'Grid', 'lsx-search' ),
155
-		);
156
-
157
-		if ( array_key_exists( $input, $valid ) ) {
158
-			return $input;
159
-		} else {
160
-			return '';
161
-		}
162
-	}
13
+     /**
14
+      * Holds class instance
15
+      *
16
+      * @since 1.0.0
17
+      *
18
+      * @var      object \lsx\search\classes\frontend\Layout()
19
+      */
20
+     protected static $instance = null;
21
+
22
+     /**
23
+      * Contructor
24
+      */
25
+     public function __construct() {
26
+          add_action( 'wp', array( $this, 'load_functions' ), 24 );
27
+     }
28
+
29
+     /**
30
+      * Return an instance of this class.
31
+      *
32
+      * @since 1.0.0
33
+      *
34
+      * @return    object \lsx\search\classes\frontend\Layout()    A single instance of this class.
35
+      */
36
+     public static function get_instance() {
37
+          // If the single instance hasn't been set, set it now.
38
+          if ( null == self::$instance ) {
39
+               self::$instance = new self();
40
+          }
41
+          return self::$instance;
42
+     }
43
+
44
+     /**
45
+      * Check all settings.
46
+      */
47
+     public function load_functions() {
48
+          $lsx_search = LSX_Search::get_instance();
49
+          if ( $lsx_search->frontend->search_enabled ) {
50
+               if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_layout_switcher_enable' ] ) ) {
51
+                    add_filter( 'lsx_blog_customizer_show_switcher', array( $this, 'show_layout_switcher' ), 10, 1 );
52
+                    add_filter( 'lsx_layout_switcher_options', array( $this, 'lsx_layout_switcher_options' ), 10, 1 );
53
+                    add_filter( 'lsx_layout_switcher_page_key', array( $this, 'lsx_layout_switcher_page_key' ), 10, 1 );
54
+                    add_filter( 'lsx_layout_switcher_options_default', array( $this, 'lsx_layout_switcher_options_default' ), 10, 1 );
55
+
56
+                    // Layout Classes
57
+                    add_filter( 'woocommerce_product_loop_start', array( $this, 'woocommerce_layout_class' ), 10, 1 );
58
+               }
59
+          }
60
+     }
61
+
62
+     /**
63
+      * Display the woocommerce archive swticher.
64
+      */
65
+     public function show_layout_switcher( $show = false ) {
66
+          if ( is_search() ) {
67
+               $archive_layout_switcher = get_theme_mod( 'lsx_blog_customizer_archive_layout_switcher', false );
68
+               if ( true === $archive_layout_switcher ) {
69
+                    $show = true;
70
+               }
71
+          }
72
+          return $show;
73
+     }
74
+
75
+     /**
76
+      * Remove the default and half-grid options from the results layouts.
77
+      *
78
+      * @param  array $layout_options
79
+      * @return array
80
+      */
81
+     public function lsx_layout_switcher_options( $layout_options ) {
82
+          unset( $layout_options['default'] );
83
+          unset( $layout_options['half-grid'] );
84
+          return $layout_options;
85
+     }
86
+
87
+     /**
88
+      * Replace the key for the layout switcher.
89
+      *
90
+      * @param  string $page_key
91
+      * @return string
92
+      */
93
+     public function lsx_layout_switcher_page_key( $page_key ) {
94
+          $lsx_search = LSX_Search::get_instance();
95
+          $page_key   = str_replace( '_search', '', $lsx_search->frontend->search_prefix );
96
+          return $page_key;
97
+     }
98
+
99
+     /**
100
+      * CHange the default layout to a grid layout.
101
+      *
102
+      * @param  string $default
103
+      * @return string
104
+      */
105
+     public function lsx_layout_switcher_options_default( $default = 'grid' ) {
106
+          $lsx_search = LSX_Search::get_instance();
107
+          $default    = 'grid';
108
+          if ( isset( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) && ! empty( $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ] ) ) {
109
+               $default = $lsx_search->frontend->options['display'][ $lsx_search->frontend->search_prefix . '_grid_list' ];
110
+          }
111
+          return $default;
112
+     }
113
+
114
+     /**
115
+      * Controls the layout for the woocommerce shop page.
116
+      */
117
+     public function woocommerce_layout_class( $output = '' ) {
118
+          $default_class = $this->lsx_layout_switcher_options_default();
119
+          $selected      = $this->get_layout_value_from_cookie( 'product' );
120
+          if ( '' !== $selected ) {
121
+               $default_class = $selected;
122
+          }
123
+          $output = str_replace( 'products', 'products ' . $default_class, $output );
124
+          return $output;
125
+     }
126
+
127
+     /**
128
+      * Get layout value from cookie
129
+      *
130
+      * @since 1.0.0
131
+      */
132
+     public function get_layout_value_from_cookie( $page_key = 'blog' ) {
133
+          $archive_layout = 'grid';
134
+
135
+          if ( isset( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] ) ) {
136
+               $archive_layout_from_cookie = sanitize_key( $_COOKIE[ 'lsx-' . $page_key . '-layout' ] );
137
+               $archive_layout_from_cookie = $this->sanitize_select_layout_switcher( $archive_layout_from_cookie );
138
+
139
+               if ( ! empty( $archive_layout_from_cookie ) ) {
140
+                    $archive_layout = $archive_layout_from_cookie;
141
+               }
142
+          }
143
+          return $archive_layout;
144
+     }
145
+
146
+     /**
147
+      * Sanitize select (layout switcher).
148
+      *
149
+      * @since 1.0.0
150
+      */
151
+     public function sanitize_select_layout_switcher( $input ) {
152
+          $valid = array(
153
+               'list'      => esc_html__( 'List', 'lsx-search' ),
154
+               'grid'      => esc_html__( 'Grid', 'lsx-search' ),
155
+          );
156
+
157
+          if ( array_key_exists( $input, $valid ) ) {
158
+               return $input;
159
+          } else {
160
+               return '';
161
+          }
162
+     }
163 163
 }
Please login to merge, or discard this patch.