/** * put your comment there... * */ public function transit() { // Initialize. $register = $this->register(); $paramId = $register['paramId']; $groupParamData = new CJT_Framework_Xml_Fetchscalars($this->getNode()); // Find group! $factory = $this->getFactory(); $groups = $factory->getCreatedObjects('form/group'); $paramGroupName = (string) $this->getNode()->attributes()->name; // Find the group to be associated with the parameter. foreach ($groups as $group) { // Find the group by the given name. if ($group->getName() == $paramGroupName) { // Check existntance! $tblGroupParam = CJTxTable::getInstance('group-parameter')->setTableKey(array('parameterId'))->set('parameterId', $paramId)->load(); // Add if not exists! if (!$tblGroupParam->get('groupId')) { // Get group id. $groupId = $group->register()->offsetGet('groupId'); // Prepare data. $groupParamData['parameterId'] = $paramId; $groupParamData['groupId'] = $groupId; // Save to database. $tblGroupParam->setTableKey(array('id'))->setData($groupParamData)->save(); } break; } } return $this; }
/** * put your comment there... * */ public function unlink() { // Delete record! $map = CJTxTable::getInstance('block-template')->setData($this->inputs)->delete(array_keys($this->inputs)); // Delete using compound key! // Fields will be cleared when deleted! return $map->getKey(); }
/** * Check weather a template is linked to specific block. * * Check database block_templates table for record with the given ids. * * @param Integer Block Id. * @param Integer Template Id. * @return boolean TRUE if linked, FALSE if not. */ public function isLinked($blockId, $templateId) { // Try to load block template table with the requested Ids. $tableBlockTemplate = CJTxTable::getInstance('block-template'); $tableBlockTemplate->set('blockId', $blockId)->set('templateId', $templateId)->load(array('blockId', 'templateId')); // Return TRUE if the blockId and the TemplateId returned from the load process! return $tableBlockTemplate->get('blockId') && $tableBlockTemplate->get('templateId'); }
/** * put your comment there... * * @param mixed $objectId * @param mixed $objectType * @param mixed $relType */ public function associateObject($objectId, $objectType, $relType) { // Initialize. $tblPckObjects = CJTxTable::getInstance('package-objects'); // Add Block-Template-Link=>Package reference. $tblPckObjects->setData(array('packageId' => $this->getId(), 'objectId' => $objectId, 'objectType' => $objectType, 'relType' => $relType))->save(); // Chain. return $this; }
/** * put your comment there... * */ public function builtinAuthors() { // Dependencies! cssJSToolbox::import('framework:db:mysql:xtable.inc.php'); // Add Wordpress author if its not already added! $wpAuthor = CJTxTable::getInstance('author')->set('id', CJTAuthorTable::WORDPRESS_AUTHOR_ID)->load(); // Make sure built-in (attributes = 1) Wordpress author (id = 1) is there! if (!$wpAuthor->get('id') || $wpAuthor->get('attributes') != 1) { $wpAuthor->setData(array('id' => CJTAuthorTable::WORDPRESS_AUTHOR_ID, 'name' => 'Wordpress', 'attributes' => CJTAuthorTable::FLAG_SYS_AUTHOR))->save(true); } return $this; }
/** * Do nothing! * */ public function transit() { // Initialize. $tblPckObjects = CJTxTable::getInstance('package-objects'); // Query package id. $tblPck = CJTxTable::getInstance('package'); $pckData = new CJT_Framework_Xml_Fetchscalars($this->getNode()); $tblPck->setData($pckData)->load(array('name')); // Add Block-Template-Link=>Package reference. $this->save($tblPckObjects, $tblPck->get('id')); // Chain. return $this; }
/** * put your comment there... * */ public function transit() { // Initialize. $register = $this->register(); $paramId = $register['paramId']; $typedefData = new CJT_Framework_Xml_Fetchscalars($this->getNode()); // Prepare data. $typedefData['parameterId'] = $paramId; // Save to database. $tblTypedef = CJTxTable::getInstance('parameter-typedef')->setData($typedefData)->save(); // Chaining. return $this; }
/** * put your comment there... * */ public function transit() { // Initialize. $register = $this->register(); $groupId = $register['groupId']; // Fetch form data / All scalar elements! $groupXFieldsData = new CJT_Framework_Xml_Fetchscalars($this->getNode()); $groupXFieldsData['groupId'] = $groupId; // Save Group XFIELDS data. CJTxTable::getInstance('form-group-xfields')->setData($groupXFieldsData)->save(); // Chaining. return $this; }
/** * put your comment there... * */ public function transit() { // Transit Link. parent::transit(); $register = $this->register(); // Add Package Ref record // ,only if this template is not bundled with the package. $packObjectsTbl = CJTxTable::getInstance('package-objects')->loadAsKey(array('packageId' => $register['packageId'], 'objectId' => $register['linkedTemplateId'], 'objectType' => 'template')); if (!$packObjectsTbl->get('relType')) { $pckHelper = new CJT_Models_Package_Xml_Definition_PackageHelper($register['packageId']); $pckHelper->associateObject($register['linkedTemplateId'], 'template', 'link'); } // Chaining. return $this; }
/** * put your comment there... * * @param mixed $blockId */ public function delete($blockIds) { // Initialize. $tblForm = CJTxTable::getInstance('form')->setTableKey(array('blockId')); // Delete all forms. foreach ($blockIds as $blockId) { // Delete the form! $tblForm->setData(array('blockId' => $blockId))->delete(); } // Delete form groups. $mdlGroups = new CJT_Models_Formgroups(); $mdlGroups->delete($blockIds); // Chaining. return $this; }
/** * put your comment there... * */ public function install() { // Get template and key refernces! $wpTemplate = $this->current(); $handle = $this->key(); // Use only templates defined with the internal file systems!! $devFile = str_replace(".{$this->type->extension}", ".dev.{$this->type->extension}", $wpTemplate->src); // Get display name from Queue name! $displayName = ucfirst(str_replace(array('-', '_'), ' ', $handle)); // Prepare periodically used vars! $time = current_time('mysql'); // Add queue object as CJT template! $template = CJTxTable::getInstance('template')->set('name', $displayName)->set('queueName', $handle)->set('type', $this->type->name)->set('creationDate', $time)->set('ownerId', get_current_user_id())->set('authorId', CJTAuthorTable::WORDPRESS_AUTHOR_ID)->set('state', 'published')->set('attributes', CJTTemplateTable::ATTRIBUTES_SYSTEM_FLAG)->save(); // Add revision for that template. $revision = CJTxTable::getInstance('template-revision')->set('templateId', $template->get('id'))->set('revisionNo', 1)->set('version', $wpTemplate->ver)->set('changeLog', 'Cached by CJT installer!')->set('state', 'release')->set('dateCreated', $time)->set('file', is_file(ABSPATH . "/{$devFile}") ? $devFile : $wpTemplate->src)->save(); }
/** * put your comment there... * * @param mixed $name */ public function useTheme($name) { // Get template name from theme name. // Template name is [BLOCKNAME-THEMENAME-theme]. $templateName = "{$this->source->name} - {$name} theme"; // Load template record from database. $tblTemplate = CJTxTable::getInstance('template')->setData(array('name' => $templateName))->load(array('name')); $mdlTemplate = CJTModel::getInstance('template'); $mdlTemplate->inputs['id'] = $tblTemplate->get('id'); $template = $mdlTemplate->getItem(); // Link Style sheet. $queueObject = CJTModel::getInstance('coupling')->getQueueObject('styles'); $queueObject->add($template->queueName, "/{$template->file}"); $queueObject->enqueue($template->queueName); // Chaining. return $this; }
/** * put your comment there... * */ public function transit() { // Initialize for linking templates. $register = $this->register(); $link = $this->getNode(); // Link block templates. // Get template object to link. $templateToLinkAttributes = (array) $link->attributes(); $templateToLinkAttributes = $templateToLinkAttributes['@attributes']; $tblTemplate = CJTxTable::getInstance('template')->setData($templateToLinkAttributes)->load(array_keys($templateToLinkAttributes)); if ($register['linkedTemplateId'] = $tblTemplate->get('id')) { // Always link as the block should be newely added // and in the normal cases its impossible to be alread linked! $tableBlockTemplate = CJTxTable::getInstance('block-template'); $tableBlockTemplate->set('blockId', $register['blockId'])->set('templateId', $register['linkedTemplateId'])->save(); } return $this; }
/** * Delete parameter or group or parameters * or all parameters associasted to specific block. * * Each Key might has only the parameterId or blockId or both of them. * * @param array array('blockId' => ID, 'parameterId' => 'ID). * @return */ public function delete($keys) { // Initialize. $tblParams = CJTxTable::getInstance('parameter')->setTableKey(array('blockId', 'parameterId')); // Delete parameters. foreach ($keys as $key) { // Allow only blockId to be passed as scalar! if (!is_array($key)) { $key = array($key); } // Blolckid passed @index 0 while parameters id @index 1 $key = array('blockId' => $key[0], 'parameterId' => isset($key[1]) ? $key[1] : null); // Delete record. $tblParams->setData($key)->delete(); } // Chaining. return $this; }
/** * put your comment there... * */ public function transit() { // Get block element. $register = $this->register(); $blockId = $register['blockId']; // Try to load the form $tblForm = CJTxTable::getInstance('form'); $tblForm->set('blockId', $blockId)->load(); // Add form is not exists. if (!$tblForm->get('name')) { // Fetch form data / All scalar elements! $formData = new CJT_Framework_Xml_Fetchscalars($this->getNode()); // Use blockId as formId. $formData['blockId'] = $blockId; // Set form data. $tblForm->setData($formData)->setTableKey(array('id'))->save(true); } // Save form id for the chain! $this->register()->offsetSet('formId', $blockId); // Chaining. return $this; }
/** * put your comment there... * */ public function transit() { // Initialize. $register = $this->register(); $blockId = $register['blockId']; $parent = isset($register['paramId']) ? $register['paramId'] : null; $paramData = new CJT_Framework_Xml_Fetchscalars($this->getNode()); // Block root parameter and child parameter names is unique $tblParam = CJTxTable::getInstance('parameter')->setTableKey(array('blockId', 'parent', 'name'))->set('blockId', $blockId)->set('parent', $parent)->set('name', $paramData['name'])->load(); // Add if doesn't exists! if (!$tblParam->get('id')) { // Set relation data. $paramData['blockId'] = $blockId; $paramData['parent'] = $parent; // Save into database. $tblParam->setTableKey(array('id'))->setData($paramData)->save(); } // Add (Or Override parent parameter id on the chain!) $register['paramId'] = $tblParam->get('id'); // Chaining. return $this; }
/** * put your comment there... * */ public function transit() { // Initialize. $register = $this->register(); $formId = $register['formId']; // Fetch form data / All scalar elements! $groupData = new CJT_Framework_Xml_Fetchscalars($this->getNode()); // Try to load the form $tblGroup = CJTxTable::getInstance('form-group'); // Each form has a unique group names! $tblGroup->setTableKey(array('formId', 'name'))->set('formId', $formId)->set('name', $groupData['name'])->load(); // Add form is not exists. if (!$tblGroup->get('id')) { // Use blockId as formId. $groupData['formId'] = $formId; // Set form data. $tblGroup->setTableKey(array('id'))->setData($groupData)->save(); } // Save form id for the chain! $register['groupId'] = $tblGroup->get('id'); // Chaining. return $this; }
/** * Delete parameter or group or parameters * or all parameters associasted to specific block. * * Each Key might has only the parameterId or blockId or both of them. * * @param array array('formId' => ID, 'groupId' => 'ID). * @return */ public function delete($keys) { // Initialize. $tblFormGroup = CJTxTable::getInstance('form-group')->setTableKey(array('formId', 'groupId')); $tblGroupXFields = CJTxTable::getInstance('form-group-xfields')->setTableKey(array('groupId')); $tblGroupParam = CJTxTable::getInstance('group-parameter')->setTableKey(array('groupId')); $tblParamTypedef = CJTxTable::getInstance('parameter-typedef')->setTableKey(array('parameterId')); // Delete groups.. foreach ($keys as $key) { // Allow only blockId to be passed as scalar! if (!is_array($key)) { $key = array($key); } // Blolckid passed @index 0 while parameters id @index 1 $key = array('formId' => $key[0], 'groupId' => isset($key[1]) ? $key[1] : null); // Get all exists ids $groups = $tblFormGroup->setData($key)->fetchAll(); // For each group get all assocuated parameters. foreach ($groups as $group) { // Delete GROUP XFields record associated with the group. $tblGroupXFields->set('groupId', $group['id'])->delete(); // Get all params. $params = $tblGroupParam->set('groupId', $group['id'])->fetchAll(); // Delete parameters typedef! foreach ($params as $param) { $tblParamTypedef->set('parameterId', $param['parameterId'])->delete(); } // Delete group parameters. $tblGroupParam->delete(); } // Delete groups. $tblFormGroup->delete(); } // Chaining. return $this; }
/** * put your comment there... * */ public function save() { // import libraries. cssJSToolbox::import('framework:db:mysql:xtable.inc.php'); // Initialize vars. $fSConfig = cssJSToolbox::$config->fileSystem; $currentUser = get_userdata(get_current_user_id()); $dbDriver = cssJSToolbox::getInstance()->getDBDriver(); $saveId = isset($this->inputs['item']['template']['id']) ? $this->inputs['item']['template']['id'] : null; // Load template data is exists (load), change values (setData). $template = CJTxTable::getInstance('template'); if ($saveId) { $template->set('id', $saveId)->load(); } $template->setData($this->inputs['item']['template'])->setQueueName(); $templateDirName = $template->get('queueName'); $templateDir = "wp-content/{$fSConfig->contentDir}/{$fSConfig->templatesDir}/{$templateDirName}"; if (!$template->get('id')) { // Add new Template // Search for author for the current local Wordpress user. // If not created in the Authors table create one! If created get the ID! $author = CJTxTable::getInstance('author', null, "SELECT * FROM #__cjtoolbox_authors \n\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE name = '{$currentUser->user_login}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t AND (attributes & 2);"); // Create Wordpress user in Authors table. if (!$author->get('id')) { $author->setData(array('name' => $currentUser->user_login, 'email' => $currentUser->user_email, 'url' => $currentUser->user_url, 'attributes' => 2))->save(); } // Set template data $template->set('ownerId', $currentUser->ID)->set('creationDate', current_time('mysql'))->set('authorId', $author->get('id')); } // Make sure directory created even if updating templats. // This case is needed when revisioned built-in templates (e.g jquery)!! if (!file_exists(ABSPATH . "/{$templateDir}")) { mkdir(ABSPATH . "/{$templateDir}", 0755); } // Save template. if (!$template->save()->get('id')) { throw new Exception('Error saving template into database!!!'); } /// Always create new revision. /// // Get last used Revision Number! $lastRevisionNo = (int) $dbDriver->getRow("SELECT max(revisionNo) revisionNo\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM #__cjtoolbox_template_revisions\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE templateId = {$template->get('id')}")->revisionNo; // Checki if there is a previous revision and if there is changes!! $lastRevision = CJTxTable::getInstance('template-revision', null, "SELECT * \n\t\t\t FROM #__cjtoolbox_template_revisions \n\t\t\t WHERE templateId = {$template->get('id')} AND revisionNo = {$lastRevisionNo}"); // Only add Revision if it has any field changed! $revisionData = $this->inputs['item']['revision']; $lastRevisionCode = $lastRevision->get('id') ? file_get_contents(ABSPATH . "/{$lastRevision->get('file')}") : null; $revisionHasChanges = $lastRevisionCode !== $revisionData['code'] || $lastRevision->get('state') !== $revisionData['state'] || $lastRevision->get('version') !== $revisionData['version'] || $lastRevision->get('changeLog') !== $revisionData['changeLog']; if ($revisionHasChanges) { $templateType = $template->get('type'); // New added revision number! $revisionNo = $lastRevisionNo + 1; // Get template revision extension. $extension = cssJSToolbox::$config->templates->types[$templateType]->extension; // Remove fields that not part of the revision table! $code = $this->inputs['item']['revision']['code']; unset($this->inputs['item']['revision']['code']); // Creae revision object. $revision = CJTxTable::getInstance('template-revision')->setData($this->inputs['item']['revision'])->set('templateId', $template->get('id'))->set('revisionNo', $revisionNo)->set('dateCreated', current_time('mysql'))->set('attributes', CJTTemplateRevisionTable::FLAG_LAST_REVISION)->set('file', "{$templateDir}/{$revisionNo}.{$extension}")->save(); // Encrypt PHP codes! if ($templateType == 'php') { $code = $this->encryptCode($code); } // Write revision content into Disk File! file_put_contents(ABSPATH . "/{$revision->get('file')}", $code); // Remove FLAG_LAST_REVISION flag from last revision so // our new revision will be the last one!! if ($lastRevision->get('id')) { $flagsOff = $lastRevision->get('attributes') & ~CJTTemplateRevisionTable::FLAG_LAST_REVISION; $lastRevision->set('attributes', $flagsOff)->save(); } } else { // Return last Revision! $revision = $lastRevision; } // Return revision object. return $revision->getData(); }
/** * put your comment there... * */ protected function getShortcodeAction() { // Get block id. $blockId = $_REQUEST['blockId']; // Load block $block = CJTxTable::getInstance('block')->setTableKey(array('id'))->setData(array('id' => $blockId))->load()->getData(); $blockForm = (array) CJTxTable::getInstance('form')->setTableKey(array('blockId'))->setData(array('blockId' => $blockId))->load()->getData(); // Load block parameters. $parameters = new CJT_Models_Block_Parameters_Parameters($blockId); $blockParams = new CJT_Framework_Developer_Interface_Block_Shortcode_Parameters_Parameters($parameters); // The the block has FORM associated if (isset($blockForm['blockId'])) { // If the data is submitted then load the parameters object with the post data! if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Get RAW data from the data submitted (avoid magic_quotes, Why called MAGIC!!!!)! $rawPostData = filter_input(INPUT_POST, 'form-data', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY); // Fill the form by the posted data $blockParams->setValue($rawPostData); // Validate the submitted data against their parameters. if ($blockParams->validate()) { // Generate and Return Shortcode string! $this->response['state'] = 'shortcode-notation'; $this->response['content'] = $blockParams->shortcode($block->name); } else { $this->response['state'] = 'invalid'; $this->response['content'] = $blockParams->getMessages(); } } else { $this->response['state'] = 'show-form'; } } else { // If block doesn't has a parameters defined return // the Shortcode code string from the parameters loader. $this->response['state'] = 'shortcode-notation'; $this->response['content'] = $blockParams->shortcode($block->name); } }
/** * Query Block based on the passed paramaters. * */ public function getBlockBy() { // import dependencies. cssJSToolbox::import('framework:db:mysql:xtable.inc.php'); return CJTxTable::getInstance('block')->set($this->inputs['filter']['field'], $this->inputs['filter']['value'])->load(array($this->inputs['filter']['field']))->getData(); }
/** * put your comment there... * */ public function __toString() { // Initialize. $replacement = ''; $model = CJTModel::getInstance('coupling'); // Get shortcode options. $this->options = array_merge($this->options, array_intersect_key($this->attributes, $this->options)); // Get shortcode parameters. $this->parameters = array_diff_key($this->attributes, array_flip(array('force', 'tag', 'name', 'id'))); // Get Block fields to be used to query the block. $blockQueryFields = array_intersect_key($this->attributes, array_flip(array('id', 'name'))); $coupling =& CJTBlocksCouplingController::theInstance(); // Import dependecies. cssJSToolbox::import('framework:db:mysql:xtable.inc.php', 'framework:php:evaluator:evaluator.inc.php'); // Query block. $block = CJTxTable::getInstance('block')->setData($blockQueryFields)->load(array_keys($blockQueryFields)); // Load using Creteria fields. // Get block code if exists and is active block. if ($block->get('id')) { if ($block->get('state') == 'active') { // Get stdCLass copy. $block = $block->getData(); // Output block if 'force="true" or only if it wasn't already in the header/footer! if ($this->options['force'] == 'true' || !in_array($block->id, $coupling->getOnActionIds())) { // Id is being used! $coupling->addOnActionIds((int) $block->id); // Retrieve block code-files. $block->code = $model->getBlockCode($block->id); // Import Executable (PHP and HTML) templates. $block->code = $block->code . $model->getExecTemplatesCode($block->id); // CJT Block Standard Parameters object. $spi = new CJT_Framework_Developer_Interface_Block_Shortcode_Shortcode($block, $this->parameters, $this->content); // Get block code, execute it as PHP! $blockCode = CJTPHPCodeEvaluator::getInstance($block)->exec(array('cb' => $spi))->getOutput(); // CJT Shortcode markup interface (CSMI)! // CSMI is HTML markup to identify the CJT block Shortcode replacement. $replacement = "<{$this->options['tag']} id='{$spi->containerElementId()}' class='csmi csmi-bid-{$block->id} csmi-{$block->name}'>{$this->content}{$blockCode}</{$this->options['tag']}>"; // Get linked templates. $linkedStylesheets = ''; $templates = $model->getLinkedTemplates($block->id); $reverseTypes = array_flip(CJTCouplingModel::$templateTypes); // Enqueue all scripts & Direct Output for all Style Sheets! foreach ($templates as $template) { // Get Template type name. $typeName = $reverseTypes[$template->type]; /** * @var WP_Dependencies */ $queue = $model->getQueueObject($typeName); if (!in_array($template->queueName, $queue->done)) { if (!isset($queue->registered[$template->queueName])) { $queue->add($template->queueName, "/{$template->file}", null, $template->version, 1); } // Enqueue template! $queue->enqueue($template->queueName); } } // Prepend linked Stylesheets to the replacement. if (isset($linkedStylesheets)) { $replacement = "<style type='text/css'>{$linkedStylesheets}</style>{$replacement}"; } } } } else { // Invalid Shortcode block query! $replacement = cssJSToolbox::getText('Could not find block specified! Please check out the Shortcode parameters.'); } // Return shortcode replacement string. return $replacement; }
/** * put your comment there... * */ public function upgrade() { /// Get current element. $id = $this->id(); $key = $this->key(); $block =& $this[$key]; // Prepare block data! $block['name'] = $block['block_name']; $block['state'] = 'active'; // Defautt to active! $block['location'] = $block['location'] == 'wp_head' ? 'header' : 'footer'; // Re-map location name! // Cache other fields before clening up deprecated block data! $scripts = explode(',', $block['scripts']); // Remove deprecated field! $this[$key] = array_diff_key($block, array_flip(array('block_name', 'scripts', 'meta'))); // Upgrade block (save into db, etc...) parent::upgrade(); // Associate block templates! if (!empty($scripts)) { $blockTemplates = CJTxTable::getInstance('block-template')->set('blockId', $id); $template = CJTxTable::getInstance('template')->setTableKey(array('queueName')); // For every script/template name find the id of the template and associate it to the block! foreach ($scripts as $scriptName) { // Get template id from name! $templateId = $template->setData(array('queueName' => $scriptName))->load()->get('id'); if ($templateId) { // Template found! // Add template! $blockTemplates->set('templateId', $templateId)->save(true); } } } // Return parent::blocks() returned value! return $this; }
/** * put your comment there... * * @param mixed $package */ public function save($package) { // Add package. return CJTxTable::getInstance('package')->setData($package)->save()->get('id'); }