PluginProbe
CSS & JavaScript Toolbox / 7.1.2
CSS & JavaScript Toolbox v7.1.2
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 / models / coupling.php

coupling.php in CSS & JavaScript Toolbox 7.1.2, at models/coupling.php

197 lines 5.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 // Disallow direct access.
7 defined('ABSPATH') or die("Access denied");
8
9 // Import dependencies.
10 cssJSToolbox::import('tables:blocks.php');
11
12 /**
13 *
14 */
15 class CJTCouplingModel extends CJTHookableClass {
16
17 /**
18 * put your comment there...
19 *
20 * @var mixed
21 */
22 protected $onexpressionsandlinkedblocks = array('parameters' => array('blocks'));
23
24 /**
25 * put your comment there...
26 *
27 * @var mixed
28 */
29 protected $ongetorder = array('parameters' => array('order'));
30
31 /**
32 * put your comment there...
33 *
34 * @var mixed
35 */
36 protected $onquerylinkedtemplates = array('parameters' => array('query'));
37
38 /**
39 * put your comment there...
40 *
41 * @var mixed
42 */
43 protected $onpinsblockfilters = array('parameters' => array(
44 'params' => array('linksExpressionFlag', 'pinPoint', 'customPins')
45 )
46 );
47
48 /**
49 * put your comment there...
50 *
51 * @var mixed
52 */
53 protected $onrequestblocks = array('parameters' => array('blocks'));
54
55 /**
56 * put your comment there...
57 *
58 * @var mixed
59 */
60 public static $templateTypes = array('scripts' => 'javascript', 'styles' => 'css');
61
62 /**
63 * put your comment there...
64 *
65 * @param mixed $id
66 */
67 public function getBlockCode($id) {
68 // Initialize.
69 $code = '';
70 // Initialize.
71 $tblCodeFiles = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver());
72 // Query Block Code Files.
73 $codeFiles = $tblCodeFiles->set('blockId', $id)
74 ->fetchAll();
75 // Merge all code files.
76 foreach ($codeFiles as $codeFile) {
77 // Wrap by Tag + Merge files.
78 $code .= $codeFile['tag'] ? sprintf($codeFile['tag'], " {$codeFile['code']} ") : $codeFile['code'];
79 }
80 // Return final code text.
81 return $code;
82 }
83
84 /**
85 * put your comment there...
86 *
87 * @param mixed $blockId
88 */
89 public function getExecTemplatesCode($blockId) {
90 // Initialize.
91 $code = '';
92 // Get all HTML and PHP templates linked to the block.
93 $templates = $this->getLinkedTemplates($blockId, array('php', 'html'));
94 if (!empty($templates)) {
95 // Instantiate template model.
96 $templateModel = CJTModel::getInstance('template');
97 // Concat their codes.
98 foreach ($templates as $template) {
99 // Fetch template record with code loaded from file and decrypted if PHP!
100 $templateModel->inputs['id'] = $template->id;
101 $template = $templateModel->getItem();
102 // Concat
103 $code .= $template->code;
104 }
105 }
106 return $code;
107 }
108
109 /**
110 * put your comment there...
111 *
112 */
113 public function getOrder() {
114 return $this->ongetorder(get_option('meta-box-order_cjtoolbox'));
115 }
116
117 /**
118 * put your comment there...
119 *
120 * @param mixed $linksExpressionFlag
121 * @param mixed $pinPoint
122 * @param mixed $customPins
123 */
124 public function getPinsBlocks($linksExpressionFlag, $pinPoint, $customPins) {
125 // Extendable!
126 extract($this->onpinsblockfilters(compact('linksExpressionFlag', 'pinPoint', 'customPins')));
127 // Import required libraries for CJTPinsBlockSQLView.
128 require_once CJTOOLBOX_TABLES_PATH . '/pins-blocks-view.php';
129 // Initialize new CJTPinsBlockSQLView view object.
130 $dbDriver = new CJTMYSQLQueueDriver($GLOBALS['wpdb']);
131 $view = new CJTPinsBlockSQLView($dbDriver);
132 // Apply filter to view.
133 $view->filters($pinPoint, $customPins);
134 // retreiving blocks data associated with current request.
135 $blocks = $this->onrequestblocks($view->exec());
136 // Get links & expressions Blocks.
137 // NOTE: We need only blocks not presented in $blocks var -- exclude their id.
138 $view->filters($linksExpressionFlag, array(), 'active', array_keys($blocks));
139 // We'll process all blocks inside single loop.
140 $blocks = $blocks + $this->onexpressionsandlinkedblocks($view->exec());
141 return $blocks;
142 }
143
144 /**
145 * put your comment there...
146 *
147 * @param mixed $blocks
148 * @param mixed $types
149 */
150 public function getLinkedTemplates($blocks, $types = array('javascript', 'css')) {
151 // Accept single id too!
152 $blocks = (array) $blocks;
153 // Import dependencies!
154 cssJSToolbox::import('framework:db:mysql:xtable.inc.php', 'tables:template-revision.php');
155 // Initialize vars.
156 $templates = array();
157 $query['select'] = 'SELECT t.id, t.type, t.queueName, r.version, r.file, bt.blockId';
158 $query['from'] = 'FROM #__cjtoolbox_block_templates bt LEFT JOIN #__cjtoolbox_templates t
159 ON bt.templateId = t.id
160 LEFT JOIN #__cjtoolbox_template_revisions r
161 ON bt.templateId = r.templateId';
162 // Filter by blocks ids and getting the last revision of the template!
163 $query['where']['blocks'] = implode(',', $blocks);
164 $query['where']['attributes'] = CJTTemplateRevisionTable::FLAG_LAST_REVISION;
165 // Filter by type.
166 $query['where']['types'] = '"' . implode('","', $types) . '"';
167 // Where clause.
168 $query['where'] = "WHERE bt.blockId IN ({$query['where']['blocks']}) AND
169 (r.attributes & {$query['where']['attributes']}) AND
170 t.type IN ({$query['where']['types']})";
171 // Filering!
172 $query = $this->onquerylinkedtemplates($query);
173 $query = "{$query['select']} {$query['from']} {$query['where']}";
174 $templates = cssJSToolbox::getInstance()->getDBDriver()->select($query);
175 return $templates;
176 }
177
178 /**
179 * put your comment there...
180 *
181 * @param mixed $type
182 */
183 public function getQueueObject($type) {
184 // Make sure Queue Object is ready/instantiated!
185 $globalQueueObjectName = "wp_{$type}";
186 if (!isset($GLOBALS[$globalQueueObjectName])) {
187 $queueClass = 'WP_' . ucfirst($type);
188 $GLOBALS[$globalQueueObjectName] = new $queueClass();
189 }
190 return $GLOBALS[$globalQueueObjectName];
191 }
192
193 } // End class.
194
195
196 // Hookable!
197 CJTCouplingModel::define('CJTCouplingModel', array('hookType' => CJTWordpressEvents::HOOK_FILTER));