/** * put your comment there... * */ public function downloadCodeFileAction() { // BlockId, currentActiveFile. $blockId = $_GET['blockId']; $fileId = $_GET['fileId']; $returnAs = $_GET['returnAs']; // Get current File Code. $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); $codeFile = $tblCodeFile->set('id', $fileId)->set('blockId', $blockId)->load()->getData(); // Return as downloadable-file or JSON. if ($returnAs == 'file') { // Get Download File info. $extension = $codeFile->type ? cssJSToolbox::$config->templates->types[$codeFile->type]->extension : 'txt'; $file = "{$codeFile->name}.{$extension}"; // Response Header parameters. header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename=\"{$file}\""); //<<< Note the " " surrounding the file name header('Content-Transfer-Encoding: binary'); header('Connection: Keep-Alive'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . strlen($codeFile->code)); // AJAX Controller parameters. $this->httpContentType = 'application/octet-stream'; } // Output code. $this->response = $codeFile->code; }
/** * put your comment there... * * @param mixed $id */ public function getBlockCode($id) { // Initialize. $code = ''; // Initialize. $tblCodeFiles = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); // Query Block Code Files. $codeFiles = $tblCodeFiles->set('blockId', $id)->fetchAll(); // Merge all code files. foreach ($codeFiles as $codeFile) { // Wrap by Tag + Merge files. $code .= $codeFile['tag'] ? sprintf($codeFile['tag'], " {$codeFile['code']} ") : $codeFile['code']; } // Return final code text. return $code; }
/** * put your comment there... * */ public function transit() { // Get block element. $register = $this->register(); $blockId = $register['blockId']; // CodeFiles table. $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); // Load Code Files if required. $register['packageParser']->fetchProperty($this->getNode(), 'code'); // Fetch form data / All scalar elements! $codeFileData = new CJT_Framework_Xml_Fetchscalars($this->getNode()); // Insert Code File. $tblCodeFile->setData($codeFileData)->set('blockId', $blockId)->save(true, true); // Chaining. return $this; }
/** * put your comment there... * */ protected function restoreRevisionAction() { // Initialize. $mdlBlocks = new CJTBlocksModel(); $tblCodeFile = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); // Get revision ID. $rId = (int) $_GET['rid']; $bId = (int) $_GET['bid']; // Get Revision Block + Revision Code. $revisionBlock = $mdlBlocks->getBlock($rId, array(), array('id', 'pinPoint', 'links', 'expressions', 'masterFile')); $revisionBlock->code = $tblCodeFile->set('blockId', $rId)->set('id', $revisionBlock->masterFile)->load()->getData()->code; // If code === null set it to empoty string '' as null woulod // prevent the field from being in the query, cause SQL error. if ($revisionBlock->code === null) { $revisionBlock->code = ''; } // Code File Fields. $revisionBlock->activeFileId = $revisionBlock->masterFile; $revisionBlock->masterFile = null; // This is just for querying CodeFile. DONT UPDATE. // Restore Block. $revisionBlock->id = $bId; $mdlBlocks->update($revisionBlock, true); $mdlBlocks->save(); // Return TRUE. $this->response = true; }
/** * put your comment there... * * @param mixed $block */ public function update($block, $updatePins) { $block = (array) $block; $blocks = new CJTBlocksTable($this->dbDriver); $pins = new CJTBlockPinsTable($this->dbDriver); // Update block pins if requested. if ($updatePins) { // Isolate block pins freom native block data. $pinsData = array_intersect_key($block, array_flip(array_keys(CJTBlockModel::getCustomPins()))); do_action(CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK_PINS, $block, $pinsData); $pins->update($block['id'], $pinsData); } // Update code file if (isset($block['activeFileId'])) { $codeFile = new CJTBlockFilesTable($this->dbDriver); $codeFile->set('blockId', $block['id'])->set('id', $block['activeFileId'])->set('code', $block['code'])->save(); } // Isolate block fields. $blockData = array_intersect_key($block, $blocks->getFields()); do_action(CJTPluggableHelper::FILTER_BLOCK_MODEL_PRE_UPDATE_BLOCK, $updatePins, $blockData); $blocks->update($blockData); }
/** * put your comment there... * */ public function switchAction() { // Block id. $blockId = (int) $_GET['blockId']; $fileId = (int) $_GET['codeFileId']; // Read Code File Record. $tblCodeFiles = new CJTBlockFilesTable(cssJSToolbox::getInstance()->getDBDriver()); $codeFile = $tblCodeFiles->set('blockId', $blockId)->set('id', $fileId)->load()->getData(); // Set author Active Code File Id. // TODO: Setting Active File ID should be in the MODEL! update_user_meta(get_current_user_id(), "cjt_block_active_file_{$blockId}", $fileId); // Return code file. $this->response = $codeFile; }
/** * put your comment there... * * @param mixed $block */ public function update($block, $updatePins) { // To be used by array_intersect_key. $block = (array) $block; // Create Tables objects. $blocks = new CJTBlocksTable($this->dbDriver); $pins = new CJTBlockPinsTable($this->dbDriver); // Update block pins if requested. if ($updatePins) { // Isolate block pins freom native block data. $pinsData = array_intersect_key($block, array_flip(array('pages', 'posts', 'categories'))); $pins->update($block['id'], $pinsData); } // Update code file if (isset($block['activeFileId'])) { $codeFile = new CJTBlockFilesTable($this->dbDriver); $codeFile->set('blockId', $block['id'])->set('id', $block['activeFileId'])->set('code', $block['code'])->save(); } // Isolate block fields. $blockData = array_intersect_key($block, $blocks->getFields()); $blocks->update($blockData); }