PluginProbe
CSS & JavaScript Toolbox / 11.6
CSS & JavaScript Toolbox v11.6
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 / developer / interface / block / shortcode / parameters / parameters.php

parameters.php in CSS & JavaScript Toolbox 11.6, at framework/developer/interface/block/shortcode/parameters/parameters.php

155 lines 4.6 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 class CJT_Framework_Developer_Interface_Block_Shortcode_Parameters_Parameters
10 extends CJT_Framework_Developer_Interface_Block_Parameters_Parameters {
11
12 /**
13 * Block programming interface (BPI).
14 *
15 * @param mixed $name
16 */
17 public function get($name) {
18 // Initialize.
19 $value = NULL;
20 // Get param key from the given name.
21 $key = strtolower($name);
22 if (!isset($this->params[$key])) {
23 echo cssJSToolbox::getText("Parameter {$name} is not found!");
24 }
25 else {
26 $value = $this->params[$key]->getValue();
27 }
28 // Allow writing it in the original case inside the code
29 // however its only retrived by the lowercvase letter.
30 return $value;
31 }
32
33 /**
34 * put your comment there...
35 *
36 */
37 protected function getFactory() {
38 return new CJT_Framework_Developer_Interface_Block_Shortcode_Parameters_Factory();
39 }
40
41 /**
42 * put your comment there...
43 *
44 * @param mixed $strings
45 * @param mixed $content
46 * @return CJT_Framework_Developer_Interface_Block_Shortcode_Parameters_Parameters
47 */
48 public function loadString($strings, $content) {
49 // Get the name of the CONTENT PARAMETER -- If EXISTS!
50 // THEN PUSH IT AS ITS PASSED AS SHORTCODR ATTRIBUTE.
51 if ($contentParameter = $this->getContentParameter()) {
52 $strings[$contentParameter->getDefinition()->getName(true)] = $content;
53 }
54 // Load all parameters with shortcde parameters.
55 foreach ($this->getParams() as $name => $param) {
56 // Dont override default value unless parameter is passed!
57 if (isset($strings[$name])) {
58 $param->loadString($strings[$name]);
59 }
60 // Validate type!
61 if (!$param->validate()) {
62 echo cssJSToolbox::getText("Invalid Shortcode parameter: {$type->getMessage()}");
63 }
64 // Remove the value from the stringsValue allow validating if
65 // any invalid parameter name is passed!
66 // See after the loop.
67 unset($strings[$name]);
68 }
69 // If there is any string values still exists then invalid parameter is passed.
70 if (!empty($strings)) {
71 echo cssJSToolbox::getText("Invalid Shortcode parameter(s) has been passed! Please check parameters name.");
72 }
73 return $this;
74 }
75
76 /**
77 * put your comment there...
78 *
79 * @param mixed $excludes
80 * @param array Parameters to include (Will be merged to params)
81 * @return string JSON of the parameters list.
82 */
83 public function json($excludes = null, $includes = null) {
84 // Initialize.
85 $params = array();
86 $json = '';
87 // Build exclude list.
88 $excludes = explode(',', $excludes);
89 // Get all parameters.
90 foreach ($this->getParams() as $name => $param) {
91 // Process only parameters not in the eexclude list.
92 if (!in_array($name, $excludes)) {
93 $definition = $param->getDefinition();
94 // Get parameter real name.
95 $realName = $definition->getName();
96 // Don't use optional parameters with no values passed.
97 $value = $param->getValue(true);
98 $isOptional = !$definition->getRequired();
99 if ($isOptional) {
100 $stack = array($value);
101 do {
102 // Get current value.
103 $current = array_shift($stack);
104 // Add to process later.
105 if (!is_scalar($current)) {
106 $stack += (array) $current;
107 }
108 // Once a non-empty value is found use it!
109 else if ($current) {
110 $params[$realName] = $value;
111 break; // Exit the loop!
112 }
113 } while (!empty($stack));
114 }
115 else {
116 $params[$realName] = $value;
117 }
118 }
119 }
120 // Merge INCLUDE List!
121 $includes && ($params = array_merge($params, $includes));
122 // Get JSON.
123 $json = json_encode($params);
124 // Returns.
125 return $json;
126 }
127
128 /**
129 * put your comment there...
130 *
131 * @param mixed $blockName
132 */
133 public function shortcode($blockName) {
134 // Initialize.
135 $shortcode = "[cjtoolbox name='{$blockName}'%s]%s[/cjtoolbox]"; // <-- CODE MODIFIED BY RBJ
136 $shortcodeContent = '';
137 $params = $this->getParams();
138 $attributes = array();
139 // Process all parameters except of the Shortcode Content parameter.
140 if ($contentParameter = $this->getContentParameter()) {
141 // Remove it from the list as it will be added as content rather than attribute.
142 unset($params[$contentParameter->getDefinition()->getName(true)]);
143 // Get Content Parameter data.
144 $shortcodeContent = $contentParameter->getValue();
145 }
146 // Aggregate all parameters strings in one array!
147 foreach ($params as $param) {
148 $attributes[] = $param->shortcode();
149 }
150 // Join with a TAB character + Add Content Parameter!
151 return sprintf($shortcode, join("\t\t\n", $attributes), $shortcodeContent);
152 }
153
154 } // End class
155