Completed
Branch FET/asset-manager (433489)
by
unknown
32:42 queued 18:11
created
display_strategies/number_bubbles/NumberBubblesProgressStepsDisplay.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -16,29 +16,29 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * used for setting up css and js required for the display strategy
21
-     *
22
-     * @return void
23
-     */
24
-    public function enqueueStylesAndScripts()
25
-    {
26
-        // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css
27
-        wp_enqueue_style(
28
-            'ee_progress_steps_display_number_bubbles',
29
-            plugin_dir_url(__FILE__) . 'number_bubbles.css'
30
-        );
31
-    }
19
+	/**
20
+	 * used for setting up css and js required for the display strategy
21
+	 *
22
+	 * @return void
23
+	 */
24
+	public function enqueueStylesAndScripts()
25
+	{
26
+		// core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css
27
+		wp_enqueue_style(
28
+			'ee_progress_steps_display_number_bubbles',
29
+			plugin_dir_url(__FILE__) . 'number_bubbles.css'
30
+		);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * loads and returns a full server path to the template used for the display strategy
36
-     *
37
-     * @return string
38
-     */
39
-    public function getTemplate()
40
-    {
41
-        // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php';
42
-        return __DIR__ . DS . 'number_bubbles.template.php';
43
-    }
34
+	/**
35
+	 * loads and returns a full server path to the template used for the display strategy
36
+	 *
37
+	 * @return string
38
+	 */
39
+	public function getTemplate()
40
+	{
41
+		// return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php';
42
+		return __DIR__ . DS . 'number_bubbles.template.php';
43
+	}
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         // core/services/progress_steps/display_strategies/number_bubbles/number_bubbles.css
27 27
         wp_enqueue_style(
28 28
             'ee_progress_steps_display_number_bubbles',
29
-            plugin_dir_url(__FILE__) . 'number_bubbles.css'
29
+            plugin_dir_url(__FILE__).'number_bubbles.css'
30 30
         );
31 31
     }
32 32
 
@@ -39,6 +39,6 @@  discard block
 block discarded – undo
39 39
     public function getTemplate()
40 40
     {
41 41
         // return plugin_dir_path( __FILE__ ) . 'number_bubbles.template.php';
42
-        return __DIR__ . DS . 'number_bubbles.template.php';
42
+        return __DIR__.DS.'number_bubbles.template.php';
43 43
     }
44 44
 }
Please login to merge, or discard this patch.
core/services/progress_steps/ProgressStep.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      */
122 122
     protected function setId($id = '')
123 123
     {
124
-        if (! is_string($id)) {
124
+        if ( ! is_string($id)) {
125 125
             throw new InvalidDataTypeException('$id', $id, 'string');
126 126
         }
127 127
         $this->id = $id;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     protected function setOrder($order = 0)
146 146
     {
147
-        if (! is_int($order)) {
147
+        if ( ! is_int($order)) {
148 148
             throw new InvalidDataTypeException('$order', $order, 'integer');
149 149
         }
150 150
         $this->order = $order;
@@ -173,11 +173,11 @@  discard block
 block discarded – undo
173 173
      */
174 174
     protected function setHtmlClass($html_class)
175 175
     {
176
-        if (! is_string($html_class)) {
176
+        if ( ! is_string($html_class)) {
177 177
             throw new InvalidDataTypeException('$html_class', $html_class, 'string');
178 178
         }
179 179
         if (strpos($html_class, 'progress-step-') === false) {
180
-            $html_class = 'progress-step-' . $html_class;
180
+            $html_class = 'progress-step-'.$html_class;
181 181
         }
182 182
         $this->html_class = $html_class;
183 183
     }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     protected function setText($text)
201 201
     {
202
-        if (! is_string($text)) {
202
+        if ( ! is_string($text)) {
203 203
             throw new InvalidDataTypeException('$text', $text, 'string');
204 204
         }
205 205
         $this->text = $text;
Please login to merge, or discard this patch.
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -18,190 +18,190 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * @var boolean $current
23
-     */
24
-    private $current = false;
25
-
26
-
27
-    /**
28
-     * @var boolean $completed
29
-     */
30
-    private $completed = false;
31
-
32
-
33
-    /**
34
-     * @var string $html_class
35
-     */
36
-    private $html_class;
37
-
38
-    /**
39
-     * @var string $id
40
-     */
41
-    private $id = '';
42
-
43
-    /**
44
-     * @var int $order
45
-     */
46
-    private $order = 0;
47
-
48
-    /**
49
-     * @var string $text
50
-     */
51
-    private $text = '';
52
-
53
-
54
-    /**
55
-     * ProgressStep constructor
56
-     *
57
-     * @param int    $order
58
-     * @param string $id
59
-     * @param string $html_class
60
-     * @param string $text
61
-     * @throws InvalidDataTypeException
62
-     */
63
-    public function __construct($order, $id, $html_class, $text)
64
-    {
65
-        $this->setOrder($order);
66
-        $this->setId($id);
67
-        $this->setHtmlClass($html_class);
68
-        $this->setText($text);
69
-    }
70
-
71
-
72
-    /**
73
-     * @return boolean
74
-     */
75
-    public function isCurrent()
76
-    {
77
-        return $this->current;
78
-    }
79
-
80
-
81
-    /**
82
-     * @param boolean $current
83
-     */
84
-    public function setIsCurrent($current = true)
85
-    {
86
-        $this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN);
87
-    }
88
-
89
-
90
-    /**
91
-     * @return boolean
92
-     */
93
-    public function isCompleted()
94
-    {
95
-        return $this->completed;
96
-    }
97
-
98
-
99
-    /**
100
-     * @param boolean $completed
101
-     */
102
-    public function setIsCompleted($completed = true)
103
-    {
104
-        $this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN);
105
-    }
106
-
107
-
108
-    /**
109
-     * @return string
110
-     */
111
-    public function id()
112
-    {
113
-        return $this->id;
114
-    }
115
-
116
-
117
-    /**
118
-     * @access protected
119
-     * @param string $id
120
-     * @throws InvalidDataTypeException
121
-     */
122
-    protected function setId($id = '')
123
-    {
124
-        if (! is_string($id)) {
125
-            throw new InvalidDataTypeException('$id', $id, 'string');
126
-        }
127
-        $this->id = $id;
128
-    }
129
-
130
-
131
-    /**
132
-     * @return int
133
-     */
134
-    public function order()
135
-    {
136
-        return $this->order;
137
-    }
138
-
139
-
140
-    /**
141
-     * @access protected
142
-     * @param int $order
143
-     * @throws InvalidDataTypeException
144
-     */
145
-    protected function setOrder($order = 0)
146
-    {
147
-        if (! is_int($order)) {
148
-            throw new InvalidDataTypeException('$order', $order, 'integer');
149
-        }
150
-        $this->order = $order;
151
-    }
152
-
153
-
154
-    /**
155
-     * @return string
156
-     */
157
-    public function htmlClass()
158
-    {
159
-        $html_class = $this->html_class;
160
-        if ($this->isCurrent()) {
161
-            $html_class .= ' progress-step-active';
162
-        } elseif ($this->isCompleted()) {
163
-            $html_class .= ' progress-step-completed';
164
-        }
165
-        return $html_class;
166
-    }
167
-
168
-
169
-    /**
170
-     * @access protected
171
-     * @param string $html_class
172
-     * @throws InvalidDataTypeException
173
-     */
174
-    protected function setHtmlClass($html_class)
175
-    {
176
-        if (! is_string($html_class)) {
177
-            throw new InvalidDataTypeException('$html_class', $html_class, 'string');
178
-        }
179
-        if (strpos($html_class, 'progress-step-') === false) {
180
-            $html_class = 'progress-step-' . $html_class;
181
-        }
182
-        $this->html_class = $html_class;
183
-    }
184
-
185
-
186
-    /**
187
-     * @return string
188
-     */
189
-    public function text()
190
-    {
191
-        return $this->text;
192
-    }
193
-
194
-
195
-    /**
196
-     * @access protected
197
-     * @param string $text
198
-     * @throws InvalidDataTypeException
199
-     */
200
-    protected function setText($text)
201
-    {
202
-        if (! is_string($text)) {
203
-            throw new InvalidDataTypeException('$text', $text, 'string');
204
-        }
205
-        $this->text = $text;
206
-    }
21
+	/**
22
+	 * @var boolean $current
23
+	 */
24
+	private $current = false;
25
+
26
+
27
+	/**
28
+	 * @var boolean $completed
29
+	 */
30
+	private $completed = false;
31
+
32
+
33
+	/**
34
+	 * @var string $html_class
35
+	 */
36
+	private $html_class;
37
+
38
+	/**
39
+	 * @var string $id
40
+	 */
41
+	private $id = '';
42
+
43
+	/**
44
+	 * @var int $order
45
+	 */
46
+	private $order = 0;
47
+
48
+	/**
49
+	 * @var string $text
50
+	 */
51
+	private $text = '';
52
+
53
+
54
+	/**
55
+	 * ProgressStep constructor
56
+	 *
57
+	 * @param int    $order
58
+	 * @param string $id
59
+	 * @param string $html_class
60
+	 * @param string $text
61
+	 * @throws InvalidDataTypeException
62
+	 */
63
+	public function __construct($order, $id, $html_class, $text)
64
+	{
65
+		$this->setOrder($order);
66
+		$this->setId($id);
67
+		$this->setHtmlClass($html_class);
68
+		$this->setText($text);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @return boolean
74
+	 */
75
+	public function isCurrent()
76
+	{
77
+		return $this->current;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @param boolean $current
83
+	 */
84
+	public function setIsCurrent($current = true)
85
+	{
86
+		$this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN);
87
+	}
88
+
89
+
90
+	/**
91
+	 * @return boolean
92
+	 */
93
+	public function isCompleted()
94
+	{
95
+		return $this->completed;
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param boolean $completed
101
+	 */
102
+	public function setIsCompleted($completed = true)
103
+	{
104
+		$this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN);
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return string
110
+	 */
111
+	public function id()
112
+	{
113
+		return $this->id;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @access protected
119
+	 * @param string $id
120
+	 * @throws InvalidDataTypeException
121
+	 */
122
+	protected function setId($id = '')
123
+	{
124
+		if (! is_string($id)) {
125
+			throw new InvalidDataTypeException('$id', $id, 'string');
126
+		}
127
+		$this->id = $id;
128
+	}
129
+
130
+
131
+	/**
132
+	 * @return int
133
+	 */
134
+	public function order()
135
+	{
136
+		return $this->order;
137
+	}
138
+
139
+
140
+	/**
141
+	 * @access protected
142
+	 * @param int $order
143
+	 * @throws InvalidDataTypeException
144
+	 */
145
+	protected function setOrder($order = 0)
146
+	{
147
+		if (! is_int($order)) {
148
+			throw new InvalidDataTypeException('$order', $order, 'integer');
149
+		}
150
+		$this->order = $order;
151
+	}
152
+
153
+
154
+	/**
155
+	 * @return string
156
+	 */
157
+	public function htmlClass()
158
+	{
159
+		$html_class = $this->html_class;
160
+		if ($this->isCurrent()) {
161
+			$html_class .= ' progress-step-active';
162
+		} elseif ($this->isCompleted()) {
163
+			$html_class .= ' progress-step-completed';
164
+		}
165
+		return $html_class;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @access protected
171
+	 * @param string $html_class
172
+	 * @throws InvalidDataTypeException
173
+	 */
174
+	protected function setHtmlClass($html_class)
175
+	{
176
+		if (! is_string($html_class)) {
177
+			throw new InvalidDataTypeException('$html_class', $html_class, 'string');
178
+		}
179
+		if (strpos($html_class, 'progress-step-') === false) {
180
+			$html_class = 'progress-step-' . $html_class;
181
+		}
182
+		$this->html_class = $html_class;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @return string
188
+	 */
189
+	public function text()
190
+	{
191
+		return $this->text;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @access protected
197
+	 * @param string $text
198
+	 * @throws InvalidDataTypeException
199
+	 */
200
+	protected function setText($text)
201
+	{
202
+		if (! is_string($text)) {
203
+			throw new InvalidDataTypeException('$text', $text, 'string');
204
+		}
205
+		$this->text = $text;
206
+	}
207 207
 }
Please login to merge, or discard this patch.
core/services/progress_steps/ProgressStepCollection.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@
 block discarded – undo
17 17
 class ProgressStepCollection extends Collection
18 18
 {
19 19
 
20
-    /**
21
-     * ProgressStepCollection constructor.
22
-     *
23
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
24
-     */
25
-    public function __construct()
26
-    {
27
-        parent::__construct('\EventEspresso\core\services\progress_steps\ProgressStepInterface');
28
-    }
20
+	/**
21
+	 * ProgressStepCollection constructor.
22
+	 *
23
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
24
+	 */
25
+	public function __construct()
26
+	{
27
+		parent::__construct('\EventEspresso\core\services\progress_steps\ProgressStepInterface');
28
+	}
29 29
 }
Please login to merge, or discard this patch.
core/services/progress_steps/ProgressStepManager.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -26,227 +26,227 @@
 block discarded – undo
26 26
 class ProgressStepManager
27 27
 {
28 28
 
29
-    /**
30
-     * @var ProgressStepInterface[] $collection
31
-     */
32
-    private $collection;
33
-
34
-    /**
35
-     * @var string $default_step
36
-     */
37
-    private $default_step;
38
-
39
-    /**
40
-     * the key used for the URL param that denotes the current form step
41
-     * defaults to 'ee-form-step'
42
-     *
43
-     * @var string $form_step_url_key
44
-     */
45
-    private $form_step_url_key = '';
46
-
47
-    /**
48
-     * @var ProgressStepsDisplayInterface $display_strategy
49
-     */
50
-    private $display_strategy;
51
-
52
-    /**
53
-     * @var EE_Request $request
54
-     */
55
-    private $request;
56
-
57
-
58
-    /**
59
-     * ProgressStepManager constructor
60
-     *
61
-     * @param string              $display_strategy_name
62
-     * @param string              $default_step
63
-     * @param string              $form_step_url_key
64
-     * @param CollectionInterface $collection
65
-     * @param \EE_Request         $request
66
-     * @throws InvalidClassException
67
-     * @throws InvalidDataTypeException
68
-     * @throws InvalidInterfaceException
69
-     */
70
-    public function __construct(
71
-        $display_strategy_name = 'number_bubbles',
72
-        $default_step = '',
73
-        $form_step_url_key = '',
74
-        CollectionInterface $collection = null,
75
-        EE_Request $request = null
76
-    ) {
77
-        $this->setDisplayStrategy($display_strategy_name);
78
-        $this->setDefaultStep($default_step);
79
-        $this->setFormStepUrlKey($form_step_url_key);
80
-        if (! $collection instanceof CollectionInterface) {
81
-            $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface');
82
-        }
83
-        $this->collection = $collection;
84
-        if (! $request instanceof EE_Request) {
85
-            $request = \EE_Registry::instance()->load_core('Request');
86
-        }
87
-        $this->request = $request;
88
-    }
89
-
90
-
91
-    /**
92
-     * @param string $display_strategy_name
93
-     * @throws InvalidDataTypeException
94
-     * @throws InvalidClassException
95
-     */
96
-    protected function setDisplayStrategy($display_strategy_name = 'number_bubbles')
97
-    {
98
-        if (! is_string($display_strategy_name)) {
99
-            throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string');
100
-        }
101
-        // build up FQCN from incoming display strategy folder name
102
-        $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\';
103
-        $display_strategy_class .= $display_strategy_name . '\\';
104
-        $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name)));
105
-        $display_strategy_class .= 'ProgressStepsDisplay';
106
-        $display_strategy_class = apply_filters(
107
-            'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class',
108
-            $display_strategy_class
109
-        );
110
-        if (! class_exists($display_strategy_class)) {
111
-            throw new InvalidClassException($display_strategy_class);
112
-        }
113
-        $display_strategy = new $display_strategy_class();
114
-        if (! $display_strategy instanceof ProgressStepsDisplayInterface) {
115
-            throw new InvalidClassException(
116
-                $display_strategy_class,
117
-                sprintf(
118
-                    __('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'),
119
-                    $display_strategy_class,
120
-                    '\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface'
121
-                )
122
-            );
123
-        }
124
-        $this->display_strategy = $display_strategy;
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string $default_step
130
-     * @throws InvalidDataTypeException
131
-     */
132
-    public function setDefaultStep($default_step)
133
-    {
134
-        if (! is_string($default_step)) {
135
-            throw new InvalidDataTypeException('$default_step', $default_step, 'string');
136
-        }
137
-        $this->default_step = $default_step;
138
-    }
139
-
140
-
141
-    /**
142
-     * @param string $form_step_url_key
143
-     * @throws InvalidDataTypeException
144
-     */
145
-    public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
146
-    {
147
-        if (! is_string($form_step_url_key)) {
148
-            throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
149
-        }
150
-        $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
151
-    }
152
-
153
-
154
-    /**
155
-     * @param string $step
156
-     * @throws InvalidIdentifierException
157
-     */
158
-    public function setCurrentStep($step = '')
159
-    {
160
-        // use incoming value if it's set, otherwise use request param if it's set, otherwise use default
161
-        $step = ! empty($step)
162
-            ? $step
163
-            : $this->request->get($this->form_step_url_key, $this->default_step);
164
-        // grab the step previously known as current, in case we need to revert
165
-        $current_current_step = $this->collection->current();
166
-        // verify that requested step exists
167
-        if (! $this->collection->has($step)) {
168
-            throw new InvalidIdentifierException($step, $this->default_step);
169
-        }
170
-        if ($this->collection->setCurrent($step)) {
171
-            // if the old boss is the same as the new boss, then nothing changes
172
-            if ($this->collection->current() !== $current_current_step) {
173
-                $current_current_step->setIsCurrent(false);
174
-            }
175
-            $this->collection->current()->setIsCurrent();
176
-        } else {
177
-            $this->collection->setCurrent($current_current_step->id());
178
-            $current_current_step->setIsCurrent(true);
179
-        }
180
-    }
181
-
182
-
183
-    /**
184
-     * setPreviousStepsCompleted
185
-     */
186
-    public function setPreviousStepsCompleted()
187
-    {
188
-        $current_current_step = $this->collection->current();
189
-        $this->collection->rewind();
190
-        while ($this->collection->valid()) {
191
-            if ($this->collection->current() === $current_current_step) {
192
-                break;
193
-            }
194
-            $this->setCurrentStepCompleted();
195
-            $this->collection->next();
196
-        }
197
-        $this->collection->setCurrentUsingObject($current_current_step);
198
-        return false;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return ProgressStepInterface
204
-     */
205
-    public function currentStep()
206
-    {
207
-        return $this->collection->current();
208
-    }
209
-
210
-
211
-    /**
212
-     * @return ProgressStepInterface
213
-     */
214
-    public function nextStep()
215
-    {
216
-        return $this->collection->next();
217
-    }
218
-
219
-
220
-    /**
221
-     * @return void
222
-     */
223
-    public function enqueueStylesAndScripts()
224
-    {
225
-        $this->display_strategy->enqueueStylesAndScripts();
226
-    }
227
-
228
-
229
-    /**
230
-     * echos out HTML
231
-     *
232
-     * @return string
233
-     */
234
-    public function displaySteps()
235
-    {
236
-        return \EEH_Template::display_template(
237
-            $this->display_strategy->getTemplate(),
238
-            array('progress_steps' => $this->collection),
239
-            true
240
-        );
241
-    }
242
-
243
-
244
-    /**
245
-     * @param bool $completed
246
-     * @return \EventEspresso\core\services\progress_steps\ProgressStepInterface
247
-     */
248
-    public function setCurrentStepCompleted($completed = true)
249
-    {
250
-        return $this->collection->current()->setIsCompleted($completed);
251
-    }
29
+	/**
30
+	 * @var ProgressStepInterface[] $collection
31
+	 */
32
+	private $collection;
33
+
34
+	/**
35
+	 * @var string $default_step
36
+	 */
37
+	private $default_step;
38
+
39
+	/**
40
+	 * the key used for the URL param that denotes the current form step
41
+	 * defaults to 'ee-form-step'
42
+	 *
43
+	 * @var string $form_step_url_key
44
+	 */
45
+	private $form_step_url_key = '';
46
+
47
+	/**
48
+	 * @var ProgressStepsDisplayInterface $display_strategy
49
+	 */
50
+	private $display_strategy;
51
+
52
+	/**
53
+	 * @var EE_Request $request
54
+	 */
55
+	private $request;
56
+
57
+
58
+	/**
59
+	 * ProgressStepManager constructor
60
+	 *
61
+	 * @param string              $display_strategy_name
62
+	 * @param string              $default_step
63
+	 * @param string              $form_step_url_key
64
+	 * @param CollectionInterface $collection
65
+	 * @param \EE_Request         $request
66
+	 * @throws InvalidClassException
67
+	 * @throws InvalidDataTypeException
68
+	 * @throws InvalidInterfaceException
69
+	 */
70
+	public function __construct(
71
+		$display_strategy_name = 'number_bubbles',
72
+		$default_step = '',
73
+		$form_step_url_key = '',
74
+		CollectionInterface $collection = null,
75
+		EE_Request $request = null
76
+	) {
77
+		$this->setDisplayStrategy($display_strategy_name);
78
+		$this->setDefaultStep($default_step);
79
+		$this->setFormStepUrlKey($form_step_url_key);
80
+		if (! $collection instanceof CollectionInterface) {
81
+			$collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface');
82
+		}
83
+		$this->collection = $collection;
84
+		if (! $request instanceof EE_Request) {
85
+			$request = \EE_Registry::instance()->load_core('Request');
86
+		}
87
+		$this->request = $request;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @param string $display_strategy_name
93
+	 * @throws InvalidDataTypeException
94
+	 * @throws InvalidClassException
95
+	 */
96
+	protected function setDisplayStrategy($display_strategy_name = 'number_bubbles')
97
+	{
98
+		if (! is_string($display_strategy_name)) {
99
+			throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string');
100
+		}
101
+		// build up FQCN from incoming display strategy folder name
102
+		$display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\';
103
+		$display_strategy_class .= $display_strategy_name . '\\';
104
+		$display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name)));
105
+		$display_strategy_class .= 'ProgressStepsDisplay';
106
+		$display_strategy_class = apply_filters(
107
+			'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class',
108
+			$display_strategy_class
109
+		);
110
+		if (! class_exists($display_strategy_class)) {
111
+			throw new InvalidClassException($display_strategy_class);
112
+		}
113
+		$display_strategy = new $display_strategy_class();
114
+		if (! $display_strategy instanceof ProgressStepsDisplayInterface) {
115
+			throw new InvalidClassException(
116
+				$display_strategy_class,
117
+				sprintf(
118
+					__('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'),
119
+					$display_strategy_class,
120
+					'\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface'
121
+				)
122
+			);
123
+		}
124
+		$this->display_strategy = $display_strategy;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string $default_step
130
+	 * @throws InvalidDataTypeException
131
+	 */
132
+	public function setDefaultStep($default_step)
133
+	{
134
+		if (! is_string($default_step)) {
135
+			throw new InvalidDataTypeException('$default_step', $default_step, 'string');
136
+		}
137
+		$this->default_step = $default_step;
138
+	}
139
+
140
+
141
+	/**
142
+	 * @param string $form_step_url_key
143
+	 * @throws InvalidDataTypeException
144
+	 */
145
+	public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
146
+	{
147
+		if (! is_string($form_step_url_key)) {
148
+			throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
149
+		}
150
+		$this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param string $step
156
+	 * @throws InvalidIdentifierException
157
+	 */
158
+	public function setCurrentStep($step = '')
159
+	{
160
+		// use incoming value if it's set, otherwise use request param if it's set, otherwise use default
161
+		$step = ! empty($step)
162
+			? $step
163
+			: $this->request->get($this->form_step_url_key, $this->default_step);
164
+		// grab the step previously known as current, in case we need to revert
165
+		$current_current_step = $this->collection->current();
166
+		// verify that requested step exists
167
+		if (! $this->collection->has($step)) {
168
+			throw new InvalidIdentifierException($step, $this->default_step);
169
+		}
170
+		if ($this->collection->setCurrent($step)) {
171
+			// if the old boss is the same as the new boss, then nothing changes
172
+			if ($this->collection->current() !== $current_current_step) {
173
+				$current_current_step->setIsCurrent(false);
174
+			}
175
+			$this->collection->current()->setIsCurrent();
176
+		} else {
177
+			$this->collection->setCurrent($current_current_step->id());
178
+			$current_current_step->setIsCurrent(true);
179
+		}
180
+	}
181
+
182
+
183
+	/**
184
+	 * setPreviousStepsCompleted
185
+	 */
186
+	public function setPreviousStepsCompleted()
187
+	{
188
+		$current_current_step = $this->collection->current();
189
+		$this->collection->rewind();
190
+		while ($this->collection->valid()) {
191
+			if ($this->collection->current() === $current_current_step) {
192
+				break;
193
+			}
194
+			$this->setCurrentStepCompleted();
195
+			$this->collection->next();
196
+		}
197
+		$this->collection->setCurrentUsingObject($current_current_step);
198
+		return false;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return ProgressStepInterface
204
+	 */
205
+	public function currentStep()
206
+	{
207
+		return $this->collection->current();
208
+	}
209
+
210
+
211
+	/**
212
+	 * @return ProgressStepInterface
213
+	 */
214
+	public function nextStep()
215
+	{
216
+		return $this->collection->next();
217
+	}
218
+
219
+
220
+	/**
221
+	 * @return void
222
+	 */
223
+	public function enqueueStylesAndScripts()
224
+	{
225
+		$this->display_strategy->enqueueStylesAndScripts();
226
+	}
227
+
228
+
229
+	/**
230
+	 * echos out HTML
231
+	 *
232
+	 * @return string
233
+	 */
234
+	public function displaySteps()
235
+	{
236
+		return \EEH_Template::display_template(
237
+			$this->display_strategy->getTemplate(),
238
+			array('progress_steps' => $this->collection),
239
+			true
240
+		);
241
+	}
242
+
243
+
244
+	/**
245
+	 * @param bool $completed
246
+	 * @return \EventEspresso\core\services\progress_steps\ProgressStepInterface
247
+	 */
248
+	public function setCurrentStepCompleted($completed = true)
249
+	{
250
+		return $this->collection->current()->setIsCompleted($completed);
251
+	}
252 252
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
         $this->setDisplayStrategy($display_strategy_name);
78 78
         $this->setDefaultStep($default_step);
79 79
         $this->setFormStepUrlKey($form_step_url_key);
80
-        if (! $collection instanceof CollectionInterface) {
80
+        if ( ! $collection instanceof CollectionInterface) {
81 81
             $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface');
82 82
         }
83 83
         $this->collection = $collection;
84
-        if (! $request instanceof EE_Request) {
84
+        if ( ! $request instanceof EE_Request) {
85 85
             $request = \EE_Registry::instance()->load_core('Request');
86 86
         }
87 87
         $this->request = $request;
@@ -95,23 +95,23 @@  discard block
 block discarded – undo
95 95
      */
96 96
     protected function setDisplayStrategy($display_strategy_name = 'number_bubbles')
97 97
     {
98
-        if (! is_string($display_strategy_name)) {
98
+        if ( ! is_string($display_strategy_name)) {
99 99
             throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string');
100 100
         }
101 101
         // build up FQCN from incoming display strategy folder name
102 102
         $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\';
103
-        $display_strategy_class .= $display_strategy_name . '\\';
103
+        $display_strategy_class .= $display_strategy_name.'\\';
104 104
         $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name)));
105 105
         $display_strategy_class .= 'ProgressStepsDisplay';
106 106
         $display_strategy_class = apply_filters(
107 107
             'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class',
108 108
             $display_strategy_class
109 109
         );
110
-        if (! class_exists($display_strategy_class)) {
110
+        if ( ! class_exists($display_strategy_class)) {
111 111
             throw new InvalidClassException($display_strategy_class);
112 112
         }
113 113
         $display_strategy = new $display_strategy_class();
114
-        if (! $display_strategy instanceof ProgressStepsDisplayInterface) {
114
+        if ( ! $display_strategy instanceof ProgressStepsDisplayInterface) {
115 115
             throw new InvalidClassException(
116 116
                 $display_strategy_class,
117 117
                 sprintf(
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public function setDefaultStep($default_step)
133 133
     {
134
-        if (! is_string($default_step)) {
134
+        if ( ! is_string($default_step)) {
135 135
             throw new InvalidDataTypeException('$default_step', $default_step, 'string');
136 136
         }
137 137
         $this->default_step = $default_step;
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
146 146
     {
147
-        if (! is_string($form_step_url_key)) {
147
+        if ( ! is_string($form_step_url_key)) {
148 148
             throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
149 149
         }
150 150
         $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         // grab the step previously known as current, in case we need to revert
165 165
         $current_current_step = $this->collection->current();
166 166
         // verify that requested step exists
167
-        if (! $this->collection->has($step)) {
167
+        if ( ! $this->collection->has($step)) {
168 168
             throw new InvalidIdentifierException($step, $this->default_step);
169 169
         }
170 170
         if ($this->collection->setCurrent($step)) {
Please login to merge, or discard this patch.
core/services/context/ContextChecker.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -17,145 +17,145 @@
 block discarded – undo
17 17
 class ContextChecker
18 18
 {
19 19
 
20
-    /**
21
-     * A unique string used to identify where this ContextChecker is being employed
22
-     * Is currently only used within the hook name for the filterable return value of isAllowed().
23
-     *
24
-     * @var string $identifier
25
-     */
26
-    private $identifier;
27
-
28
-    /**
29
-     * A list of values to be compared against the slug of the Context class passed to isAllowed()
30
-     *
31
-     * @var array $acceptable_values
32
-     */
33
-    private $acceptable_values;
34
-
35
-    /**
36
-     * Closure that will be called to perform the evaluation within isAllowed().
37
-     * If none is provided, then a simple type sensitive in_array() check will be used
38
-     * and return true if the incoming Context::slug() is found within the array of $acceptable_values.
39
-     *
40
-     * @var Closure $evaluation_callback
41
-     */
42
-    private $evaluation_callback;
43
-
44
-
45
-    /**
46
-     * ContextChecker constructor.
47
-     *
48
-     * @param string       $identifier
49
-     * @param array        $acceptable_values
50
-     * @param Closure|null $evaluation_callback [optional]
51
-     */
52
-    public function __construct($identifier, array $acceptable_values, Closure $evaluation_callback = null)
53
-    {
54
-        $this->setIdentifier($identifier);
55
-        $this->setAcceptableValues($acceptable_values);
56
-        $this->setEvaluationCallback($evaluation_callback);
57
-    }
58
-
59
-
60
-    /**
61
-     * @param string $identifier
62
-     */
63
-    private function setIdentifier($identifier)
64
-    {
65
-        $this->identifier = sanitize_key($identifier);
66
-    }
67
-
68
-
69
-    /**
70
-     * @param array $acceptable_values
71
-     */
72
-    private function setAcceptableValues(array $acceptable_values)
73
-    {
74
-        $this->acceptable_values = $acceptable_values;
75
-    }
76
-
77
-
78
-    /**
79
-     * @param Closure $evaluation_callback
80
-     */
81
-    private function setEvaluationCallback(Closure $evaluation_callback = null)
82
-    {
83
-        $this->evaluation_callback = $evaluation_callback instanceof Closure
84
-            ? $evaluation_callback
85
-            : function (ContextInterface $context, $acceptable_values) {
86
-                return in_array($context->slug(), $acceptable_values, true);
87
-            };
88
-    }
89
-
90
-
91
-    /**
92
-     * @return string
93
-     */
94
-    protected function identifier()
95
-    {
96
-        return $this->identifier;
97
-    }
98
-
99
-
100
-    /**
101
-     * @return array
102
-     */
103
-    protected function acceptableValues()
104
-    {
105
-        return apply_filters(
106
-            "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__{$this->identifier}__acceptableValues",
107
-            $this->acceptable_values
108
-        );
109
-    }
110
-
111
-
112
-    /**
113
-     * @return Closure
114
-     */
115
-    protected function evaluationCallback()
116
-    {
117
-        return $this->evaluation_callback;
118
-    }
119
-
120
-
121
-    /**
122
-     * Returns true if the incoming Context class slug matches one of the preset acceptable values.
123
-     * The result is filterable using the identifier for this ContextChecker.
124
-     * example:
125
-     * If this ContextChecker's $identifier was set to "registration-checkout-type",
126
-     * then the filter here would be named:
127
-     *  "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed".
128
-     * Other code could hook into the filter in isAllowed() using the above name
129
-     * and test for additional acceptable values.
130
-     * So if the set of $acceptable_values was: [ "initial-visit",  "revisit" ]
131
-     * then adding a filter to
132
-     *  "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed",
133
-     * would allow you to perform your own conditional and allow "wait-list-checkout" as an acceptable value.
134
-     *  example:
135
-     *      add_filter(
136
-     *          'FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed',
137
-     *          function ($is_allowed, ContextInterface $context) { return $context->slug() === 'wait-list-checkout'
138
-     *                  ? true
139
-     *                  : $is_allowed;
140
-     *          },
141
-     *          10,
142
-     *          2
143
-     *      );
144
-     *
145
-     * @param ContextInterface $context
146
-     * @return boolean
147
-     */
148
-    public function isAllowed(ContextInterface $context)
149
-    {
150
-        $evaluation_callback = $this->evaluationCallback();
151
-        return filter_var(
152
-            apply_filters(
153
-                "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__{$this->identifier}__isAllowed",
154
-                $evaluation_callback($context, $this->acceptableValues()),
155
-                $context,
156
-                $this
157
-            ),
158
-            FILTER_VALIDATE_BOOLEAN
159
-        );
160
-    }
20
+	/**
21
+	 * A unique string used to identify where this ContextChecker is being employed
22
+	 * Is currently only used within the hook name for the filterable return value of isAllowed().
23
+	 *
24
+	 * @var string $identifier
25
+	 */
26
+	private $identifier;
27
+
28
+	/**
29
+	 * A list of values to be compared against the slug of the Context class passed to isAllowed()
30
+	 *
31
+	 * @var array $acceptable_values
32
+	 */
33
+	private $acceptable_values;
34
+
35
+	/**
36
+	 * Closure that will be called to perform the evaluation within isAllowed().
37
+	 * If none is provided, then a simple type sensitive in_array() check will be used
38
+	 * and return true if the incoming Context::slug() is found within the array of $acceptable_values.
39
+	 *
40
+	 * @var Closure $evaluation_callback
41
+	 */
42
+	private $evaluation_callback;
43
+
44
+
45
+	/**
46
+	 * ContextChecker constructor.
47
+	 *
48
+	 * @param string       $identifier
49
+	 * @param array        $acceptable_values
50
+	 * @param Closure|null $evaluation_callback [optional]
51
+	 */
52
+	public function __construct($identifier, array $acceptable_values, Closure $evaluation_callback = null)
53
+	{
54
+		$this->setIdentifier($identifier);
55
+		$this->setAcceptableValues($acceptable_values);
56
+		$this->setEvaluationCallback($evaluation_callback);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @param string $identifier
62
+	 */
63
+	private function setIdentifier($identifier)
64
+	{
65
+		$this->identifier = sanitize_key($identifier);
66
+	}
67
+
68
+
69
+	/**
70
+	 * @param array $acceptable_values
71
+	 */
72
+	private function setAcceptableValues(array $acceptable_values)
73
+	{
74
+		$this->acceptable_values = $acceptable_values;
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param Closure $evaluation_callback
80
+	 */
81
+	private function setEvaluationCallback(Closure $evaluation_callback = null)
82
+	{
83
+		$this->evaluation_callback = $evaluation_callback instanceof Closure
84
+			? $evaluation_callback
85
+			: function (ContextInterface $context, $acceptable_values) {
86
+				return in_array($context->slug(), $acceptable_values, true);
87
+			};
88
+	}
89
+
90
+
91
+	/**
92
+	 * @return string
93
+	 */
94
+	protected function identifier()
95
+	{
96
+		return $this->identifier;
97
+	}
98
+
99
+
100
+	/**
101
+	 * @return array
102
+	 */
103
+	protected function acceptableValues()
104
+	{
105
+		return apply_filters(
106
+			"FHEE__EventEspresso_core_domain_entities_context_ContextChecker__{$this->identifier}__acceptableValues",
107
+			$this->acceptable_values
108
+		);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return Closure
114
+	 */
115
+	protected function evaluationCallback()
116
+	{
117
+		return $this->evaluation_callback;
118
+	}
119
+
120
+
121
+	/**
122
+	 * Returns true if the incoming Context class slug matches one of the preset acceptable values.
123
+	 * The result is filterable using the identifier for this ContextChecker.
124
+	 * example:
125
+	 * If this ContextChecker's $identifier was set to "registration-checkout-type",
126
+	 * then the filter here would be named:
127
+	 *  "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed".
128
+	 * Other code could hook into the filter in isAllowed() using the above name
129
+	 * and test for additional acceptable values.
130
+	 * So if the set of $acceptable_values was: [ "initial-visit",  "revisit" ]
131
+	 * then adding a filter to
132
+	 *  "FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed",
133
+	 * would allow you to perform your own conditional and allow "wait-list-checkout" as an acceptable value.
134
+	 *  example:
135
+	 *      add_filter(
136
+	 *          'FHEE__EventEspresso_core_domain_entities_context_ContextChecker__registration-checkout-type__isAllowed',
137
+	 *          function ($is_allowed, ContextInterface $context) { return $context->slug() === 'wait-list-checkout'
138
+	 *                  ? true
139
+	 *                  : $is_allowed;
140
+	 *          },
141
+	 *          10,
142
+	 *          2
143
+	 *      );
144
+	 *
145
+	 * @param ContextInterface $context
146
+	 * @return boolean
147
+	 */
148
+	public function isAllowed(ContextInterface $context)
149
+	{
150
+		$evaluation_callback = $this->evaluationCallback();
151
+		return filter_var(
152
+			apply_filters(
153
+				"FHEE__EventEspresso_core_domain_entities_context_ContextChecker__{$this->identifier}__isAllowed",
154
+				$evaluation_callback($context, $this->acceptableValues()),
155
+				$context,
156
+				$this
157
+			),
158
+			FILTER_VALIDATE_BOOLEAN
159
+		);
160
+	}
161 161
 }
Please login to merge, or discard this patch.
core/services/loaders/LoaderDecorator.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * @var LoaderDecoratorInterface $loader
19
-     */
20
-    protected $loader;
17
+	/**
18
+	 * @var LoaderDecoratorInterface $loader
19
+	 */
20
+	protected $loader;
21 21
 
22 22
 
23
-    /**
24
-     * LoaderDecorator constructor.
25
-     *
26
-     * @param LoaderDecoratorInterface $loader
27
-     */
28
-    public function __construct(LoaderDecoratorInterface $loader)
29
-    {
30
-        $this->loader = $loader;
31
-    }
23
+	/**
24
+	 * LoaderDecorator constructor.
25
+	 *
26
+	 * @param LoaderDecoratorInterface $loader
27
+	 */
28
+	public function __construct(LoaderDecoratorInterface $loader)
29
+	{
30
+		$this->loader = $loader;
31
+	}
32 32
 }
Please login to merge, or discard this patch.
core/services/locators/Locator.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@
 block discarded – undo
17 17
 abstract class Locator implements LocatorInterface, Countable
18 18
 {
19 19
 
20
-    /**
21
-     * @var array $flags
22
-     */
23
-    protected $flags = array();
24
-
25
-
26
-    /**
27
-     * FileLocator constructor.
28
-     *
29
-     * @access public
30
-     * @param array $flags controls how files are found and/or file data is returned
31
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
32
-     */
33
-    public function __construct($flags = array())
34
-    {
35
-        if (empty($flags)) {
36
-            $flags = array(
37
-                FilesystemIterator::SKIP_DOTS,
38
-                FilesystemIterator::UNIX_PATHS,
39
-                FilesystemIterator::CURRENT_AS_PATHNAME,
40
-            );
41
-        }
42
-        $this->setFlags($flags);
43
-    }
44
-
45
-
46
-    /**
47
-     * @see    http://php.net/manual/en/class.filesystemiterator.php#filesystemiterator.constants
48
-     * @access public
49
-     * @param array $flags
50
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
51
-     */
52
-    public function setFlags($flags)
53
-    {
54
-        if (! is_array($flags)) {
55
-            throw new InvalidDataTypeException('$flags', $flags, 'array');
56
-        }
57
-        $this->flags = $flags;
58
-    }
20
+	/**
21
+	 * @var array $flags
22
+	 */
23
+	protected $flags = array();
24
+
25
+
26
+	/**
27
+	 * FileLocator constructor.
28
+	 *
29
+	 * @access public
30
+	 * @param array $flags controls how files are found and/or file data is returned
31
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
32
+	 */
33
+	public function __construct($flags = array())
34
+	{
35
+		if (empty($flags)) {
36
+			$flags = array(
37
+				FilesystemIterator::SKIP_DOTS,
38
+				FilesystemIterator::UNIX_PATHS,
39
+				FilesystemIterator::CURRENT_AS_PATHNAME,
40
+			);
41
+		}
42
+		$this->setFlags($flags);
43
+	}
44
+
45
+
46
+	/**
47
+	 * @see    http://php.net/manual/en/class.filesystemiterator.php#filesystemiterator.constants
48
+	 * @access public
49
+	 * @param array $flags
50
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
51
+	 */
52
+	public function setFlags($flags)
53
+	{
54
+		if (! is_array($flags)) {
55
+			throw new InvalidDataTypeException('$flags', $flags, 'array');
56
+		}
57
+		$this->flags = $flags;
58
+	}
59 59
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
      */
52 52
     public function setFlags($flags)
53 53
     {
54
-        if (! is_array($flags)) {
54
+        if ( ! is_array($flags)) {
55 55
             throw new InvalidDataTypeException('$flags', $flags, 'array');
56 56
         }
57 57
         $this->flags = $flags;
Please login to merge, or discard this patch.
core/services/shortcodes/ShortcodesManager.php 2 patches
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -29,203 +29,203 @@
 block discarded – undo
29 29
 class ShortcodesManager
30 30
 {
31 31
 
32
-    /**
33
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
34
-     */
35
-    private $legacy_shortcodes_manager;
36
-
37
-    /**
38
-     * @var ShortcodeInterface[] $shortcodes
39
-     */
40
-    private $shortcodes;
41
-
42
-
43
-    /**
44
-     * ShortcodesManager constructor
45
-     *
46
-     * @param LegacyShortcodesManager $legacy_shortcodes_manager
47
-     */
48
-    public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager)
49
-    {
50
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
51
-        // assemble a list of installed and active shortcodes
52
-        add_action(
53
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
54
-            array($this, 'registerShortcodes'),
55
-            999
56
-        );
57
-        //  call add_shortcode() for all installed shortcodes
58
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes'));
59
-        // check content for shortcodes the old way
60
-        add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5);
61
-        // check content for shortcodes the NEW more efficient way
62
-        add_action('template_redirect', array($this, 'templateRedirect'), 999);
63
-    }
64
-
65
-
66
-    /**
67
-     * @return CollectionInterface|ShortcodeInterface[]
68
-     * @throws InvalidIdentifierException
69
-     * @throws InvalidInterfaceException
70
-     * @throws InvalidFilePathException
71
-     * @throws InvalidEntityException
72
-     * @throws InvalidDataTypeException
73
-     * @throws InvalidClassException
74
-     */
75
-    public function getShortcodes()
76
-    {
77
-        if (! $this->shortcodes instanceof CollectionInterface) {
78
-            $this->shortcodes = $this->loadShortcodesCollection();
79
-        }
80
-        return $this->shortcodes;
81
-    }
82
-
83
-
84
-    /**
85
-     * @return CollectionInterface|ShortcodeInterface[]
86
-     * @throws InvalidIdentifierException
87
-     * @throws InvalidInterfaceException
88
-     * @throws InvalidFilePathException
89
-     * @throws InvalidEntityException
90
-     * @throws InvalidDataTypeException
91
-     * @throws InvalidClassException
92
-     */
93
-    protected function loadShortcodesCollection()
94
-    {
95
-        $loader = new CollectionLoader(
96
-            new CollectionDetails(
97
-                // collection name
98
-                'shortcodes',
99
-                // collection interface
100
-                'EventEspresso\core\services\shortcodes\ShortcodeInterface',
101
-                // FQCNs for classes to add (all classes within that namespace will be loaded)
102
-                array('EventEspresso\core\domain\entities\shortcodes'),
103
-                // filepaths to classes to add
104
-                array(),
105
-                // file mask to use if parsing folder for files to add
106
-                '',
107
-                // what to use as identifier for collection entities
108
-                // using CLASS NAME prevents duplicates (works like a singleton)
109
-                CollectionDetails::ID_CLASS_NAME
110
-            )
111
-        );
112
-        return $loader->getCollection();
113
-    }
114
-
115
-
116
-    /**
117
-     * @return void
118
-     * @throws DomainException
119
-     * @throws InvalidInterfaceException
120
-     * @throws InvalidIdentifierException
121
-     * @throws InvalidFilePathException
122
-     * @throws InvalidEntityException
123
-     * @throws InvalidDataTypeException
124
-     * @throws InvalidClassException
125
-     */
126
-    public function registerShortcodes()
127
-    {
128
-        try {
129
-            $this->shortcodes = apply_filters(
130
-                'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
131
-                $this->getShortcodes()
132
-            );
133
-            if (! $this->shortcodes instanceof CollectionInterface) {
134
-                throw new InvalidEntityException(
135
-                    $this->shortcodes,
136
-                    'CollectionInterface',
137
-                    sprintf(
138
-                        esc_html__(
139
-                            'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.',
140
-                            'event_espresso'
141
-                        ),
142
-                        is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes)
143
-                    )
144
-                );
145
-            }
146
-            $this->legacy_shortcodes_manager->registerShortcodes();
147
-        } catch (Exception $exception) {
148
-            new ExceptionStackTraceDisplay($exception);
149
-        }
150
-    }
151
-
152
-
153
-    /**
154
-     * @return void
155
-     */
156
-    public function addShortcodes()
157
-    {
158
-        try {
159
-            // cycle thru shortcode folders
160
-            foreach ($this->shortcodes as $shortcode) {
161
-                /** @var ShortcodeInterface $shortcode */
162
-                if ($shortcode instanceof EnqueueAssetsInterface) {
163
-                    add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10);
164
-                    add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11);
165
-                }
166
-                // add_shortcode() if it has not already been added
167
-                if (! shortcode_exists($shortcode->getTag())) {
168
-                    add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback'));
169
-                }
170
-            }
171
-            $this->legacy_shortcodes_manager->addShortcodes();
172
-        } catch (Exception $exception) {
173
-            new ExceptionStackTraceDisplay($exception);
174
-        }
175
-    }
176
-
177
-
178
-    /**
179
-     * callback for the "template_redirect" hook point
180
-     * checks posts for EE shortcodes, and initializes them,
181
-     * then toggles filter switch that loads core default assets
182
-     *
183
-     * @return void
184
-     */
185
-    public function templateRedirect()
186
-    {
187
-        global $wp_query;
188
-        if (empty($wp_query->posts)) {
189
-            return;
190
-        }
191
-        $load_assets = false;
192
-        // array of posts displayed in current request
193
-        $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts);
194
-        foreach ($posts as $post) {
195
-            // now check post content and excerpt for EE shortcodes
196
-            $load_assets = $this->parseContentForShortcodes($post->post_content)
197
-                ? true
198
-                : $load_assets;
199
-        }
200
-        if ($load_assets) {
201
-            $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true);
202
-            add_filter('FHEE_load_css', '__return_true');
203
-            add_filter('FHEE_load_js', '__return_true');
204
-        }
205
-    }
206
-
207
-
208
-    /**
209
-     * checks supplied content against list of shortcodes,
210
-     * then initializes any found shortcodes, and returns true.
211
-     * returns false if no shortcodes found.
212
-     *
213
-     * @param string $content
214
-     * @return bool
215
-     */
216
-    public function parseContentForShortcodes($content)
217
-    {
218
-        $has_shortcode = false;
219
-        if (empty($this->shortcodes)) {
220
-            return $has_shortcode;
221
-        }
222
-        foreach ($this->shortcodes as $shortcode) {
223
-            /** @var ShortcodeInterface $shortcode */
224
-            if (has_shortcode($content, $shortcode->getTag())) {
225
-                $shortcode->initializeShortcode();
226
-                $has_shortcode = true;
227
-            }
228
-        }
229
-        return $has_shortcode;
230
-    }
32
+	/**
33
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
34
+	 */
35
+	private $legacy_shortcodes_manager;
36
+
37
+	/**
38
+	 * @var ShortcodeInterface[] $shortcodes
39
+	 */
40
+	private $shortcodes;
41
+
42
+
43
+	/**
44
+	 * ShortcodesManager constructor
45
+	 *
46
+	 * @param LegacyShortcodesManager $legacy_shortcodes_manager
47
+	 */
48
+	public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager)
49
+	{
50
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
51
+		// assemble a list of installed and active shortcodes
52
+		add_action(
53
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
54
+			array($this, 'registerShortcodes'),
55
+			999
56
+		);
57
+		//  call add_shortcode() for all installed shortcodes
58
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes'));
59
+		// check content for shortcodes the old way
60
+		add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5);
61
+		// check content for shortcodes the NEW more efficient way
62
+		add_action('template_redirect', array($this, 'templateRedirect'), 999);
63
+	}
64
+
65
+
66
+	/**
67
+	 * @return CollectionInterface|ShortcodeInterface[]
68
+	 * @throws InvalidIdentifierException
69
+	 * @throws InvalidInterfaceException
70
+	 * @throws InvalidFilePathException
71
+	 * @throws InvalidEntityException
72
+	 * @throws InvalidDataTypeException
73
+	 * @throws InvalidClassException
74
+	 */
75
+	public function getShortcodes()
76
+	{
77
+		if (! $this->shortcodes instanceof CollectionInterface) {
78
+			$this->shortcodes = $this->loadShortcodesCollection();
79
+		}
80
+		return $this->shortcodes;
81
+	}
82
+
83
+
84
+	/**
85
+	 * @return CollectionInterface|ShortcodeInterface[]
86
+	 * @throws InvalidIdentifierException
87
+	 * @throws InvalidInterfaceException
88
+	 * @throws InvalidFilePathException
89
+	 * @throws InvalidEntityException
90
+	 * @throws InvalidDataTypeException
91
+	 * @throws InvalidClassException
92
+	 */
93
+	protected function loadShortcodesCollection()
94
+	{
95
+		$loader = new CollectionLoader(
96
+			new CollectionDetails(
97
+				// collection name
98
+				'shortcodes',
99
+				// collection interface
100
+				'EventEspresso\core\services\shortcodes\ShortcodeInterface',
101
+				// FQCNs for classes to add (all classes within that namespace will be loaded)
102
+				array('EventEspresso\core\domain\entities\shortcodes'),
103
+				// filepaths to classes to add
104
+				array(),
105
+				// file mask to use if parsing folder for files to add
106
+				'',
107
+				// what to use as identifier for collection entities
108
+				// using CLASS NAME prevents duplicates (works like a singleton)
109
+				CollectionDetails::ID_CLASS_NAME
110
+			)
111
+		);
112
+		return $loader->getCollection();
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return void
118
+	 * @throws DomainException
119
+	 * @throws InvalidInterfaceException
120
+	 * @throws InvalidIdentifierException
121
+	 * @throws InvalidFilePathException
122
+	 * @throws InvalidEntityException
123
+	 * @throws InvalidDataTypeException
124
+	 * @throws InvalidClassException
125
+	 */
126
+	public function registerShortcodes()
127
+	{
128
+		try {
129
+			$this->shortcodes = apply_filters(
130
+				'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
131
+				$this->getShortcodes()
132
+			);
133
+			if (! $this->shortcodes instanceof CollectionInterface) {
134
+				throw new InvalidEntityException(
135
+					$this->shortcodes,
136
+					'CollectionInterface',
137
+					sprintf(
138
+						esc_html__(
139
+							'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.',
140
+							'event_espresso'
141
+						),
142
+						is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes)
143
+					)
144
+				);
145
+			}
146
+			$this->legacy_shortcodes_manager->registerShortcodes();
147
+		} catch (Exception $exception) {
148
+			new ExceptionStackTraceDisplay($exception);
149
+		}
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return void
155
+	 */
156
+	public function addShortcodes()
157
+	{
158
+		try {
159
+			// cycle thru shortcode folders
160
+			foreach ($this->shortcodes as $shortcode) {
161
+				/** @var ShortcodeInterface $shortcode */
162
+				if ($shortcode instanceof EnqueueAssetsInterface) {
163
+					add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10);
164
+					add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11);
165
+				}
166
+				// add_shortcode() if it has not already been added
167
+				if (! shortcode_exists($shortcode->getTag())) {
168
+					add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback'));
169
+				}
170
+			}
171
+			$this->legacy_shortcodes_manager->addShortcodes();
172
+		} catch (Exception $exception) {
173
+			new ExceptionStackTraceDisplay($exception);
174
+		}
175
+	}
176
+
177
+
178
+	/**
179
+	 * callback for the "template_redirect" hook point
180
+	 * checks posts for EE shortcodes, and initializes them,
181
+	 * then toggles filter switch that loads core default assets
182
+	 *
183
+	 * @return void
184
+	 */
185
+	public function templateRedirect()
186
+	{
187
+		global $wp_query;
188
+		if (empty($wp_query->posts)) {
189
+			return;
190
+		}
191
+		$load_assets = false;
192
+		// array of posts displayed in current request
193
+		$posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts);
194
+		foreach ($posts as $post) {
195
+			// now check post content and excerpt for EE shortcodes
196
+			$load_assets = $this->parseContentForShortcodes($post->post_content)
197
+				? true
198
+				: $load_assets;
199
+		}
200
+		if ($load_assets) {
201
+			$this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true);
202
+			add_filter('FHEE_load_css', '__return_true');
203
+			add_filter('FHEE_load_js', '__return_true');
204
+		}
205
+	}
206
+
207
+
208
+	/**
209
+	 * checks supplied content against list of shortcodes,
210
+	 * then initializes any found shortcodes, and returns true.
211
+	 * returns false if no shortcodes found.
212
+	 *
213
+	 * @param string $content
214
+	 * @return bool
215
+	 */
216
+	public function parseContentForShortcodes($content)
217
+	{
218
+		$has_shortcode = false;
219
+		if (empty($this->shortcodes)) {
220
+			return $has_shortcode;
221
+		}
222
+		foreach ($this->shortcodes as $shortcode) {
223
+			/** @var ShortcodeInterface $shortcode */
224
+			if (has_shortcode($content, $shortcode->getTag())) {
225
+				$shortcode->initializeShortcode();
226
+				$has_shortcode = true;
227
+			}
228
+		}
229
+		return $has_shortcode;
230
+	}
231 231
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function getShortcodes()
76 76
     {
77
-        if (! $this->shortcodes instanceof CollectionInterface) {
77
+        if ( ! $this->shortcodes instanceof CollectionInterface) {
78 78
             $this->shortcodes = $this->loadShortcodesCollection();
79 79
         }
80 80
         return $this->shortcodes;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
                 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection',
131 131
                 $this->getShortcodes()
132 132
             );
133
-            if (! $this->shortcodes instanceof CollectionInterface) {
133
+            if ( ! $this->shortcodes instanceof CollectionInterface) {
134 134
                 throw new InvalidEntityException(
135 135
                     $this->shortcodes,
136 136
                     'CollectionInterface',
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                     add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11);
165 165
                 }
166 166
                 // add_shortcode() if it has not already been added
167
-                if (! shortcode_exists($shortcode->getTag())) {
167
+                if ( ! shortcode_exists($shortcode->getTag())) {
168 168
                     add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback'));
169 169
                 }
170 170
             }
Please login to merge, or discard this patch.
core/services/shortcodes/EspressoShortcode.php 2 patches
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -19,221 +19,221 @@
 block discarded – undo
19 19
 abstract class EspressoShortcode implements ShortcodeInterface
20 20
 {
21 21
 
22
-    /**
23
-     * transient prefix
24
-     *
25
-     * @type string
26
-     */
27
-    const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
28
-
29
-    /**
30
-     * @var PostRelatedCacheManager $cache_manager
31
-     */
32
-    private $cache_manager;
33
-
34
-    /**
35
-     * true if ShortcodeInterface::initializeShortcode() has been called
36
-     * if false, then that will get called before processing
37
-     *
38
-     * @var boolean $initialized
39
-     */
40
-    private $initialized = false;
41
-
42
-
43
-    /**
44
-     * EspressoShortcode constructor
45
-     *
46
-     * @param PostRelatedCacheManager $cache_manager
47
-     */
48
-    public function __construct(PostRelatedCacheManager $cache_manager)
49
-    {
50
-        $this->cache_manager = $cache_manager;
51
-    }
52
-
53
-
54
-    /**
55
-     * @return void
56
-     */
57
-    public function shortcodeHasBeenInitialized()
58
-    {
59
-        $this->initialized = true;
60
-    }
61
-
62
-
63
-    /**
64
-     * enqueues scripts then processes the shortcode
65
-     *
66
-     * @param array $attributes
67
-     * @return string
68
-     * @throws EE_Error
69
-     */
70
-    final public function processShortcodeCallback($attributes = array())
71
-    {
72
-        if ($this instanceof EnqueueAssetsInterface) {
73
-            if (is_admin()) {
74
-                $this->enqueueAdminScripts();
75
-            } else {
76
-                $this->enqueueScripts();
77
-            }
78
-        }
79
-        return $this->shortcodeContent(
80
-            $this->sanitizeAttributes((array)$attributes)
81
-        );
82
-    }
83
-
84
-
85
-    /**
86
-     * If shortcode caching is enabled for the shortcode,
87
-     * and cached results exist, then that will be returned
88
-     * else new content will be generated.
89
-     * If caching is enabled, then the new content will be cached for later.
90
-     *
91
-     * @param array $attributes
92
-     * @return mixed|string
93
-     * @throws EE_Error
94
-     */
95
-    private function shortcodeContent(array $attributes)
96
-    {
97
-        $shortcode = $this;
98
-        $post_ID = $this->currentPostID();
99
-        // something like "SC_EVENTS-123"
100
-        $cache_ID = $this->shortcodeCacheID($post_ID);
101
-        $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
102
-        return $this->cache_manager->get(
103
-            $cache_ID,
104
-            // serialized attributes
105
-            wp_json_encode($attributes),
106
-            // Closure for generating content if cache is expired
107
-            function () use ($shortcode, $attributes) {
108
-                if ($shortcode->initialized() === false) {
109
-                    $shortcode->initializeShortcode();
110
-                }
111
-                return $shortcode->processShortcode($attributes);
112
-            },
113
-            // filterable cache expiration set by each shortcode
114
-            apply_filters(
115
-                'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
116
-                $this->cacheExpiration(),
117
-                $this->getTag(),
118
-                $this
119
-            )
120
-        );
121
-    }
122
-
123
-
124
-    /**
125
-     * @return int
126
-     * @throws EE_Error
127
-     */
128
-    private function currentPostID()
129
-    {
130
-        // try to get EE_Event any way we can
131
-        $event = EEH_Event_View::get_event();
132
-        // then get some kind of ID
133
-        if ($event instanceof EE_Event) {
134
-            return $event->ID();
135
-        }
136
-        global $post;
137
-        if ($post instanceof WP_Post) {
138
-            return $post->ID;
139
-        }
140
-        return 0;
141
-    }
142
-
143
-
144
-    /**
145
-     * @param int $post_ID
146
-     * @return string
147
-     * @throws EE_Error
148
-     */
149
-    private function shortcodeCacheID($post_ID)
150
-    {
151
-        $tag = str_replace('ESPRESSO_', '', $this->getTag());
152
-        return "SC_{$tag}-{$post_ID}";
153
-    }
154
-
155
-
156
-    /**
157
-     * array for defining custom attribute sanitization callbacks,
158
-     * where keys match keys in your attributes array,
159
-     * and values represent the sanitization function you wish to be applied to that attribute.
160
-     * So for example, if you had an integer attribute named "event_id"
161
-     * that you wanted to be sanitized using absint(),
162
-     * then you would return the following:
163
-     *      array('event_id' => 'absint')
164
-     * Entering 'skip_sanitization' for the callback value
165
-     * means that no sanitization will be applied
166
-     * on the assumption that the attribute
167
-     * will be sanitized at some point... right?
168
-     * You wouldn't pass around unsanitized attributes would you?
169
-     * That would be very Tom Foolery of you!!!
170
-     *
171
-     * @return array
172
-     */
173
-    protected function customAttributeSanitizationMap()
174
-    {
175
-        return array();
176
-    }
177
-
178
-
179
-    /**
180
-     * Performs basic sanitization on shortcode attributes
181
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
182
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
183
-     * This can be overridden using the customAttributeSanitizationMap() method (see above),
184
-     * all other attributes would be sanitized using the defaults in the switch statement below
185
-     *
186
-     * @param array $attributes
187
-     * @return array
188
-     */
189
-    private function sanitizeAttributes(array $attributes)
190
-    {
191
-        $custom_sanitization = $this->customAttributeSanitizationMap();
192
-        foreach ($attributes as $key => $value) {
193
-            // is a custom sanitization callback specified ?
194
-            if (isset($custom_sanitization[$key])) {
195
-                $callback = $custom_sanitization[$key];
196
-                if ($callback === 'skip_sanitization') {
197
-                    $attributes[$key] = $value;
198
-                    continue;
199
-                }
200
-                if (function_exists($callback)) {
201
-                    $attributes[$key] = $callback($value);
202
-                    continue;
203
-                }
204
-            }
205
-            switch (true) {
206
-                case $value === null:
207
-                case is_int($value):
208
-                case is_float($value):
209
-                    // typical booleans
210
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true):
211
-                    $attributes[$key] = $value;
212
-                    break;
213
-                case is_string($value):
214
-                    $attributes[$key] = sanitize_text_field($value);
215
-                    break;
216
-                case is_array($value):
217
-                    $attributes[$key] = $this->sanitizeAttributes($value);
218
-                    break;
219
-                default:
220
-                    // only remaining data types are Object and Resource
221
-                    // which are not allowed as shortcode attributes
222
-                    $attributes[$key] = null;
223
-                    break;
224
-            }
225
-        }
226
-        return $attributes;
227
-    }
228
-
229
-
230
-    /**
231
-     * Returns whether or not this shortcode has been initialized
232
-     *
233
-     * @return boolean
234
-     */
235
-    public function initialized()
236
-    {
237
-        return $this->initialized;
238
-    }
22
+	/**
23
+	 * transient prefix
24
+	 *
25
+	 * @type string
26
+	 */
27
+	const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
28
+
29
+	/**
30
+	 * @var PostRelatedCacheManager $cache_manager
31
+	 */
32
+	private $cache_manager;
33
+
34
+	/**
35
+	 * true if ShortcodeInterface::initializeShortcode() has been called
36
+	 * if false, then that will get called before processing
37
+	 *
38
+	 * @var boolean $initialized
39
+	 */
40
+	private $initialized = false;
41
+
42
+
43
+	/**
44
+	 * EspressoShortcode constructor
45
+	 *
46
+	 * @param PostRelatedCacheManager $cache_manager
47
+	 */
48
+	public function __construct(PostRelatedCacheManager $cache_manager)
49
+	{
50
+		$this->cache_manager = $cache_manager;
51
+	}
52
+
53
+
54
+	/**
55
+	 * @return void
56
+	 */
57
+	public function shortcodeHasBeenInitialized()
58
+	{
59
+		$this->initialized = true;
60
+	}
61
+
62
+
63
+	/**
64
+	 * enqueues scripts then processes the shortcode
65
+	 *
66
+	 * @param array $attributes
67
+	 * @return string
68
+	 * @throws EE_Error
69
+	 */
70
+	final public function processShortcodeCallback($attributes = array())
71
+	{
72
+		if ($this instanceof EnqueueAssetsInterface) {
73
+			if (is_admin()) {
74
+				$this->enqueueAdminScripts();
75
+			} else {
76
+				$this->enqueueScripts();
77
+			}
78
+		}
79
+		return $this->shortcodeContent(
80
+			$this->sanitizeAttributes((array)$attributes)
81
+		);
82
+	}
83
+
84
+
85
+	/**
86
+	 * If shortcode caching is enabled for the shortcode,
87
+	 * and cached results exist, then that will be returned
88
+	 * else new content will be generated.
89
+	 * If caching is enabled, then the new content will be cached for later.
90
+	 *
91
+	 * @param array $attributes
92
+	 * @return mixed|string
93
+	 * @throws EE_Error
94
+	 */
95
+	private function shortcodeContent(array $attributes)
96
+	{
97
+		$shortcode = $this;
98
+		$post_ID = $this->currentPostID();
99
+		// something like "SC_EVENTS-123"
100
+		$cache_ID = $this->shortcodeCacheID($post_ID);
101
+		$this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
102
+		return $this->cache_manager->get(
103
+			$cache_ID,
104
+			// serialized attributes
105
+			wp_json_encode($attributes),
106
+			// Closure for generating content if cache is expired
107
+			function () use ($shortcode, $attributes) {
108
+				if ($shortcode->initialized() === false) {
109
+					$shortcode->initializeShortcode();
110
+				}
111
+				return $shortcode->processShortcode($attributes);
112
+			},
113
+			// filterable cache expiration set by each shortcode
114
+			apply_filters(
115
+				'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
116
+				$this->cacheExpiration(),
117
+				$this->getTag(),
118
+				$this
119
+			)
120
+		);
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return int
126
+	 * @throws EE_Error
127
+	 */
128
+	private function currentPostID()
129
+	{
130
+		// try to get EE_Event any way we can
131
+		$event = EEH_Event_View::get_event();
132
+		// then get some kind of ID
133
+		if ($event instanceof EE_Event) {
134
+			return $event->ID();
135
+		}
136
+		global $post;
137
+		if ($post instanceof WP_Post) {
138
+			return $post->ID;
139
+		}
140
+		return 0;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param int $post_ID
146
+	 * @return string
147
+	 * @throws EE_Error
148
+	 */
149
+	private function shortcodeCacheID($post_ID)
150
+	{
151
+		$tag = str_replace('ESPRESSO_', '', $this->getTag());
152
+		return "SC_{$tag}-{$post_ID}";
153
+	}
154
+
155
+
156
+	/**
157
+	 * array for defining custom attribute sanitization callbacks,
158
+	 * where keys match keys in your attributes array,
159
+	 * and values represent the sanitization function you wish to be applied to that attribute.
160
+	 * So for example, if you had an integer attribute named "event_id"
161
+	 * that you wanted to be sanitized using absint(),
162
+	 * then you would return the following:
163
+	 *      array('event_id' => 'absint')
164
+	 * Entering 'skip_sanitization' for the callback value
165
+	 * means that no sanitization will be applied
166
+	 * on the assumption that the attribute
167
+	 * will be sanitized at some point... right?
168
+	 * You wouldn't pass around unsanitized attributes would you?
169
+	 * That would be very Tom Foolery of you!!!
170
+	 *
171
+	 * @return array
172
+	 */
173
+	protected function customAttributeSanitizationMap()
174
+	{
175
+		return array();
176
+	}
177
+
178
+
179
+	/**
180
+	 * Performs basic sanitization on shortcode attributes
181
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
182
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
183
+	 * This can be overridden using the customAttributeSanitizationMap() method (see above),
184
+	 * all other attributes would be sanitized using the defaults in the switch statement below
185
+	 *
186
+	 * @param array $attributes
187
+	 * @return array
188
+	 */
189
+	private function sanitizeAttributes(array $attributes)
190
+	{
191
+		$custom_sanitization = $this->customAttributeSanitizationMap();
192
+		foreach ($attributes as $key => $value) {
193
+			// is a custom sanitization callback specified ?
194
+			if (isset($custom_sanitization[$key])) {
195
+				$callback = $custom_sanitization[$key];
196
+				if ($callback === 'skip_sanitization') {
197
+					$attributes[$key] = $value;
198
+					continue;
199
+				}
200
+				if (function_exists($callback)) {
201
+					$attributes[$key] = $callback($value);
202
+					continue;
203
+				}
204
+			}
205
+			switch (true) {
206
+				case $value === null:
207
+				case is_int($value):
208
+				case is_float($value):
209
+					// typical booleans
210
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true):
211
+					$attributes[$key] = $value;
212
+					break;
213
+				case is_string($value):
214
+					$attributes[$key] = sanitize_text_field($value);
215
+					break;
216
+				case is_array($value):
217
+					$attributes[$key] = $this->sanitizeAttributes($value);
218
+					break;
219
+				default:
220
+					// only remaining data types are Object and Resource
221
+					// which are not allowed as shortcode attributes
222
+					$attributes[$key] = null;
223
+					break;
224
+			}
225
+		}
226
+		return $attributes;
227
+	}
228
+
229
+
230
+	/**
231
+	 * Returns whether or not this shortcode has been initialized
232
+	 *
233
+	 * @return boolean
234
+	 */
235
+	public function initialized()
236
+	{
237
+		return $this->initialized;
238
+	}
239 239
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             }
78 78
         }
79 79
         return $this->shortcodeContent(
80
-            $this->sanitizeAttributes((array)$attributes)
80
+            $this->sanitizeAttributes((array) $attributes)
81 81
         );
82 82
     }
83 83
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
             // serialized attributes
105 105
             wp_json_encode($attributes),
106 106
             // Closure for generating content if cache is expired
107
-            function () use ($shortcode, $attributes) {
107
+            function() use ($shortcode, $attributes) {
108 108
                 if ($shortcode->initialized() === false) {
109 109
                     $shortcode->initializeShortcode();
110 110
                 }
Please login to merge, or discard this patch.