PluginProbe
CSS & JavaScript Toolbox / 11.7
CSS & JavaScript Toolbox v11.7
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / framework / ServicesFW / Shortcode.service.class.php

Shortcode.service.class.php in CSS & JavaScript Toolbox 11.7, at framework/ServicesFW/Shortcode.service.class.php

103 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 /**
7 *
8 */
9 abstract class CJTServicesShortcodeService extends CJTServicesWPService {
10
11 /**
12 * put your comment there...
13 *
14 * @var mixed
15 */
16 private $callback;
17
18 /**
19 * put your comment there...
20 *
21 * @var mixed
22 */
23 private $shortcodes = array();
24
25 /**
26 * put your comment there...
27 *
28 */
29 public function __construct() {
30
31 $this->callback = array( $this, '_doShortcode' );
32 }
33
34 /**
35 * put your comment there...
36 *
37 * @param mixed $attrs
38 * @param mixed $content
39 * @param mixed $tag
40 */
41 public function _doShortcode($attrs, $content, $tag) {
42
43 # Get requested Shortcode config
44 $shortcode =& $this->shortcodes[ $tag ];
45 $shortcodeConfig =& $shortcode[ 'config' ];
46
47 # Push Shortcode parameters
48 $shortcodeConfig['parameters'] = array( 'attrs' => & $attrs, 'content' => & $content, 'tag' => & $tag );
49
50 # Get Controller
51 $this->controller =& $this->getControllerFactory()->getController( array_merge( $this->config, $shortcodeConfig ) );
52
53 # Dispatch action
54 $this->controller->dispatch( $shortcodeConfig[ 'route' ][ 'action' ] );
55
56 # Save models state
57 $this->controller->saveState();
58
59 # Return shortcoee replacement
60 return $this->controller->getResponse();
61 }
62
63 /**
64 * put your comment there...
65 *
66 * @param mixed $name
67 */
68 public function & addShortcode($name) {
69
70 # Create shortcode structure, add it to list
71 $this->shortcodes[ $name ] = array( 'name' => $name, 'config' => & $this->serviceConfig[ $name ] );
72
73 return $this;
74 }
75
76 /**
77 * put your comment there...
78 *
79 */
80 protected abstract function defineShortcodes();
81
82 /**
83 * put your comment there...
84 *
85 */
86 public function & start() {
87
88 # Let Model class define Shortcodes
89 $this->defineShortcodes();
90
91 # Add shortcodes at the correct hook
92 foreach ( $this->shortcodes as $shortcode ) {
93
94 # Register Wordpress shortcode
95 add_shortcode( $shortcode[ 'name' ], $this->callback );
96
97 }
98
99 return $this;
100 }
101
102 }
103