| @@ -32,8 +32,15 @@ | ||
| 32 | 32 | * put your comment there... |
| 33 | 33 | * |
| 34 | 34 | * @var mixed |
| 35 | 35 | */ |
| 36 | + protected $onquerylinkedtemplates = array('parameters' => array('query')); | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * put your comment there... | |
| 40 | + * | |
| 41 | + * @var mixed | |
| 42 | + */ | |
| 36 | 43 | protected $onpinsblockfilters = array('parameters' => array( |
| 37 | 44 | 'params' => array('linksExpressionFlag', 'pinPoint', 'customPins') |
| 38 | 45 | ) |
| 39 | 46 | ); |
| @@ -47,13 +54,67 @@ | ||
| 47 | 54 | |
| 48 | 55 | /** |
| 49 | 56 | * put your comment there... |
| 50 | 57 | * |
| 58 | + * @var mixed | |
| 51 | 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 | + */ | |
| 52 | 113 | public function getOrder() { |
| 53 | 114 | return $this->ongetorder(get_option('meta-box-order_cjtoolbox')); |
| 54 | 115 | } |
| 55 | - | |
| 116 | + | |
| 56 | 117 | /** |
| 57 | 118 | * put your comment there... |
| 58 | 119 | * |
| 59 | 120 | * @param mixed $linksExpressionFlag |
| @@ -58,27 +119,99 @@ | ||
| 58 | 119 | * |
| 59 | 120 | * @param mixed $linksExpressionFlag |
| 60 | 121 | * @param mixed $pinPoint |
| 61 | 122 | * @param mixed $customPins |
| 123 | + * @param mixed $hookParams | |
| 62 | 124 | */ |
| 63 | - public function getPinsBlocks($linksExpressionFlag, $pinPoint, $customPins) { | |
| 125 | + public function getPinsBlocks( $linksExpressionFlag, $pinPoint, $customPins, $hookParams ) | |
| 126 | + { | |
| 64 | 127 | // Extendable! |
| 65 | - extract($this->onpinsblockfilters(compact('linksExpressionFlag', 'pinPoint', 'customPins'))); | |
| 128 | + extract( $this->onpinsblockfilters( compact( 'linksExpressionFlag', 'pinPoint', 'customPins' ) ) ); | |
| 129 | + | |
| 66 | 130 | // Import required libraries for CJTPinsBlockSQLView. |
| 67 | 131 | require_once CJTOOLBOX_TABLES_PATH . '/pins-blocks-view.php'; |
| 132 | + | |
| 68 | 133 | // Initialize new CJTPinsBlockSQLView view object. |
| 69 | - $dbDriver = new CJTMYSQLQueueDriver($GLOBALS['wpdb']); | |
| 70 | - $view = new CJTPinsBlockSQLView($dbDriver); | |
| 134 | + $dbDriver = new CJTMYSQLQueueDriver( $GLOBALS[ 'wpdb' ] ); | |
| 135 | + $view = new CJTPinsBlockSQLView( $dbDriver ); | |
| 136 | + | |
| 71 | 137 | // Apply filter to view. |
| 72 | - $view->filters($pinPoint, $customPins); | |
| 138 | + $view->filters( $pinPoint, $customPins ); | |
| 139 | + | |
| 140 | + # Allow Plugins/Extensions to change block core query | |
| 141 | + do_action( | |
| 142 | + | |
| 143 | + CJTPluggableHelper::ACTION_BLOCK_QUERY_BLOCKS, | |
| 144 | + | |
| 145 | + $view, | |
| 146 | + | |
| 147 | + $hookParams | |
| 148 | + | |
| 149 | + ); | |
| 150 | + | |
| 73 | 151 | // retreiving blocks data associated with current request. |
| 74 | - $blocks = $this->onrequestblocks($view->exec()); | |
| 152 | + $blocks = $this->onrequestblocks( $view->exec() ); | |
| 153 | + | |
| 154 | + # Filter queue blocks | |
| 155 | + $blocks = apply_filters( CJTPluggableHelper::FILTER_BLOCKS_COUPLING_MODEL_BLOCKS_QUEUE, $blocks, $hookParams ); | |
| 156 | + | |
| 75 | 157 | // Get links & expressions Blocks. |
| 76 | 158 | // NOTE: We need only blocks not presented in $blocks var -- exclude their id. |
| 77 | - $view->filters($linksExpressionFlag, array(), 'active', array_keys($blocks)); | |
| 159 | + $view->filters( $linksExpressionFlag, array(), 'active', array_keys( $blocks ) ); | |
| 160 | + | |
| 78 | 161 | // We'll process all blocks inside single loop. |
| 79 | - $blocks = $blocks + $this->onexpressionsandlinkedblocks($view->exec()); | |
| 162 | + $blocks = $blocks + $this->onexpressionsandlinkedblocks( $view->exec() ); | |
| 163 | + | |
| 80 | 164 | return $blocks; |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * put your comment there... | |
| 169 | + * | |
| 170 | + * @param mixed $blocks | |
| 171 | + * @param mixed $types | |
| 172 | + */ | |
| 173 | + public function getLinkedTemplates($blocks, $types = array('javascript', 'css')) { | |
| 174 | + // Accept single id too! | |
| 175 | + $blocks = (array) $blocks; | |
| 176 | + // Import dependencies! | |
| 177 | + cssJSToolbox::import('framework:db:mysql:xtable.inc.php', 'tables:template-revision.php'); | |
| 178 | + // Initialize vars. | |
| 179 | + $templates = array(); | |
| 180 | + $query['select'] = 'SELECT t.id, t.type, t.queueName, r.version, r.file, bt.blockId'; | |
| 181 | + $query['from'] = 'FROM #__cjtoolbox_block_templates bt LEFT JOIN #__cjtoolbox_templates t | |
| 182 | + ON bt.templateId = t.id | |
| 183 | + LEFT JOIN #__cjtoolbox_template_revisions r | |
| 184 | + ON bt.templateId = r.templateId'; | |
| 185 | + // Filter by blocks ids and getting the last revision of the template! | |
| 186 | + $query['where']['blocks'] = implode(',', $blocks); | |
| 187 | + $query['where']['attributes'] = CJTTemplateRevisionTable::FLAG_LAST_REVISION; | |
| 188 | + // Filter by type. | |
| 189 | + $query['where']['types'] = '"' . implode('","', $types) . '"'; | |
| 190 | + // Where clause. | |
| 191 | + $query['where'] = "WHERE bt.blockId IN ({$query['where']['blocks']}) AND | |
| 192 | + (r.attributes & {$query['where']['attributes']}) AND | |
| 193 | + t.type IN ({$query['where']['types']})"; | |
| 194 | + // Filering! | |
| 195 | + $query = $this->onquerylinkedtemplates($query); | |
| 196 | + $query = "{$query['select']} {$query['from']} {$query['where']}"; | |
| 197 | + $templates = cssJSToolbox::getInstance()->getDBDriver()->select($query); | |
| 198 | + return $templates; | |
| 199 | + } | |
| 200 | + | |
| 201 | + /** | |
| 202 | + * put your comment there... | |
| 203 | + * | |
| 204 | + * @param mixed $type | |
| 205 | + */ | |
| 206 | + public function getQueueObject($type) { | |
| 207 | + // Make sure Queue Object is ready/instantiated! | |
| 208 | + $globalQueueObjectName = "wp_{$type}"; | |
| 209 | + if (!isset($GLOBALS[$globalQueueObjectName])) { | |
| 210 | + $queueClass = 'WP_' . ucfirst($type); | |
| 211 | + $GLOBALS[$globalQueueObjectName] = new $queueClass(); | |
| 212 | + } | |
| 213 | + return $GLOBALS[$globalQueueObjectName]; | |
| 81 | 214 | } |
| 82 | 215 | |
| 83 | 216 | } // End class. |
| 84 | 217 | |