/** * Delete single package. * * This method is going to delete the package * and all the templates and blocks associated to it, * therefor it'll unlink/break-down the relationship * between those templates and blocks. * * @param Integer Package Id. * @return CJTPackageModel Return $this. */ public function delete($id) { // Initialize. $modelTemplates = CJTModel::getInstance('templates-manager'); $dbd = cssJSToolbox::getInstance()->getDBDriver(); $assoObjectsQueryTmp = 'SELECT objectId FROM #__cjtoolbox_package_objects WHERE packageId = %d AND objectType = "%s" AND relType = "%s";'; // Delete the package. CJTxTable::getInstance('package')->set('id', $id)->delete(); // Delete blocks. $blockIds = array_keys($dbd->select(sprintf($assoObjectsQueryTmp, $id, 'block', 'add'))); if (!empty($blockIds)) { // Delete blocks! CJTModel::getInstance('blocks')->delete($blockIds)->save(); } // Delete templates. $modelTemplates->inputs['ids'] = array_keys($dbd->select(sprintf($assoObjectsQueryTmp, $id, 'template', 'add'))); // Templates muct be in trash state before deleted! $modelTemplates->inputs['state'] = 'trash'; // Move to Trash + Delete only if there is at least one Id! empty($modelTemplates->inputs['ids']) or $modelTemplates->changeState() and $modelTemplates->delete(); // Delete package objects map. CJTxTable::getInstance('package-objects')->set('packageId', $id)->delete(array('packageId')); }
/** * put your comment there... * * @param mixed $blocks * @return CJTInstallerBlock */ public function __construct($blocks) { // Initialize! $this->model = CJTModel::getInstance('blocks'); // Initialize Array Iterator class! parent::__construct(is_array($blocks) ? $blocks : array()); }
/** * Uninstall CJT Plugin * installaion flags, setup-flags * and user data! * * @return void */ public function uninstallAction() { // Initializing! $model =& CJTModel::getInstance('uninstall'); // Uninstall everything! $model->expressUninstall(); }
/** * put your comment there... * * @param mixed $templates * @return CJTInstallerTemplate */ public function __construct($templates) { // Initialize! $this->model = CJTModel::getInstance('template'); // Initialize Iterator! parent::__construct(is_array($templates) ? $templates : array()); }
/** * put your comment there... * */ public function _checkInstallationState() { # Initialize $extensionClass = $this->extensionClass; $extension =& $this->extension; $extensionDeDoc =& $extension['defDoc']; $extensionState = new CJT_Framework_Extensions_Package_State_Extension($extensionDeDoc); # Upgrade and Install is the same both # required checking the packages inside # Package-Extension is a only a wrapper for packages inside! if ($extensionState->getState() != CJT_Framework_Extensions_Package_State_Extension::INSTALLED) { # Initialize $packageFileModel = CJTModel::getInstance('package-file'); $packageModel = CJTModel::getInstance('package'); $extensionDir = ABSPATH . PLUGINDIR . DIRECTORY_SEPARATOR . $extension['dir']; $packagesFolderPath = $extensionDir . DIRECTORY_SEPARATOR . (string) $extensionDeDoc->packages->attributes()->folder; # Getting packages state $extensionPackagesState = new CJT_Framework_Extensions_Package_State_Packages($extensionDeDoc); # Check packages foreach ($extensionPackagesState as $pckName => $package) { # Get state $pckState = $extensionPackagesState->getState(); # If not yet installed or requied upgrade if ($pckState != CJT_Framework_Extensions_Package_State_Packages::INSTALLED) { # Take action based on package installation state switch ($pckState) { case CJT_Framework_Extensions_Package_State_Packages::UPGRADE: # Delete package $packageModel->delete($package['id']); break; } # Get package file info. $packageFile = $packagesFolderPath . DIRECTORY_SEPARATOR . $package['file']; # Add/Create Package $packageCJTToken = $packageFileModel->parse(uniqid(), $packageFile); $packageId = $packageFileModel->install($packageCJTToken); # Mark as installed/created/added $extensionPackagesState->packageInstalled($packageId); } # Remove from queue $extensionPackagesState->removeOld(); } # Packages to delete! foreach ($extensionPackagesState->getDeletedPackages() as $name => $deletedPack) { # Delete package $packageModel->delete($deletedPack['id']); } # Upgrade packages state $extensionPackagesState->upgrade(); # Upgrade extension state $extensionState->upgrade($extension['defFile']); # Register uninstaller register_uninstall_hook($extension['pluginFile'], array(__CLASS__, "uninstall_{$extensionClass}")); } }
/** * Do nothing! * */ public function transit() { // Initialize. $register = $this->register(); $modelPackage = CJTModel::getInstance('package'); // Fetch package information with all readme and license tags locatted if // bundled with external files! $packageInfo = $register['packageParser']->getItem($this->getNode(), array('readme' => 'readme.txt', 'license' => 'license.txt')); // Add package to database! $register['packageId'] = $modelPackage->save($packageInfo); // Chain. return $this; }
/** * put your comment there... * */ public function transit() { // Initialize. $model = CJTModel::getInstance('blocks'); $register = $this->register(); // Prepare object + getting item to be saved into database. $block = $register['packageParser']->getItem($this->getNode()); // Set other block internal data. $block['created'] = $block['lastModified'] = current_time('mysql'); $block['owner'] = get_current_user_id(); // Create Block. /// Expose BlockId for other nodes. $register['blockId'] = $model->add($block); $model->save(); // Chaining. return $this; }
/** * put your comment there... * */ public function embedded() { // Read template revision. $revision = CJTxTable::getInstance('template-revision')->fetchLastRevision($this->inputs['templateId']); // Revision could not be queried!! if (!$revision->get('id')) { throw new Exception('Revision could not be found!!'); } $revisionFile = $revision->get('file'); // Read revision code. $code = file_get_contents(ABSPATH . "/{$revisionFile}"); // Decrypt PHP codes! if (preg_match('/\\.php$/', $revisionFile)) { $code = CJTModel::getInstance('template')->decryptCode($code); } return $code; }
/** * 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 __construct($type) { // Save type data for later use! $this->type = cssJSToolbox::$config->templates->types[$type]; $this->type->name = $type; // Get which Wordpress queue (wp_script, wp_styles) object to fetch data from. $wpQueueName = self::$typesMap[$type]; /** * @var CJTCouplingModel */ $coupling = CJTModel::getInstance('coupling'); // Initialize ArrayIterator with templates list! parent::__construct($coupling->getQueueObject($wpQueueName)->registered); // Import dependencies! cssJSToolbox::import('framework:db:mysql:xtable.inc.php'); CJTxTable::import('template'); CJTxTable::import('author'); }
/** * Do nothing! * */ public function transit() { // Initialize. $model = CJTModel::getInstance('template'); $node = $this->getNode(); $register = $this->register(); // Prepare object + getting item to be saved into database. $template = $register['packageParser']->getItem($node); // Insert template only if not exists. if (!$model->exists($template['name'])) { // Import template(s) helper. cssJSToolbox::import('includes:templates:templates.class.php'); // Set template revision. $model->inputs['item']['revision']['code'] = $template['code']; unset($template['code']); // Set template main data. $model->inputs['item']['template'] = $template; /** Get template Type! * Get type from external file extension if * the template code was linked to file. * If the template code were inline * then the type must be provided under * TYPE element! */ // If no type specified get it from the external file extension if (!isset($model->inputs['item']['template']['type'])) { // @WARNING: Get locatted file! $codeFileName = (string) $node->code->attributes()->locatted; if ($codeFileName) { // Get type from extension. $fileComponent = pathinfo($codeFileName); $model->inputs['item']['template']['type'] = CJTTemplates::getExtensionType($fileComponent['extension']); } } // Add template. $addedTemplate = $model->save(); // Expose template fields to be by used by other objects. $register['templateId'] = $addedTemplate->templateId; $register['templateFile'] = $addedTemplate->file; } // Chaining. return $this; }
/** * put your comment there... * * @param mixed $blockId */ public function getExecTemplatesCode($blockId) { // Initialize. $code = ''; // Get all HTML and PHP templates linked to the block. $templates = $this->getLinkedTemplates($blockId, array('php', 'html')); if (!empty($templates)) { // Instantiate template model. $templateModel = CJTModel::getInstance('template'); // Concat their codes. foreach ($templates as $template) { // Fetch template record with code loaded from file and decrypted if PHP! $templateModel->inputs['id'] = $template->id; $template = $templateModel->getItem(); // Concat $code .= $template->code; } } return $code; }
/** * Link external Resources (CSS, HTML, JS and PHP) * * The action is to create external link as CJT template * and link it to the target block. */ protected function linkExternalAction() { // Import dependencies. cssJSToolbox::import('includes:templates:templates.class.php'); // Initialize response as successed until error occured! $this->response = array('code' => 0, 'message' => ''); // List of all the external templates records to create! $externalTemplates = array(); // Read inputs. $externals = explode(',', $_REQUEST['externals']); $blockId = (int) $_REQUEST['blockId']; // Add as templates. foreach ($externals as $externalResourceURI) { // Use URI base name as Template Name and the extension as Template Type. $externalPathInfo = pathinfo($externalResourceURI); // Template Item. $item = array(); $item['template']['name'] = $externalPathInfo['basename']; $item['template']['type'] = CJTTemplates::getExtensionType($externalPathInfo['extension']); $item['template']['state'] = 'published'; // Get external URI code! $externalResponse = wp_remote_get($externalResourceURI); if ($error = $externalResponse instanceof WP_Error) { // State an error! $this->response['code'] = $externalResponse->get_error_code(); $this->response['message'] = $externalResponse->get_error_message($this->response['code']); break; } else { // Read code content. $item['revision']['code'] = wp_remote_retrieve_body($externalResponse); // Add to the save list! $externalTemplates[] = $item; } } // Save all templates if no error occured // Single error will halt all the linked externals! They all added as a single transaction. if (!$this->response['code']) { // Instantiate Template Models. $modelLookup = CJTModel::getInstance('templates-lookup'); $modelTemplate = CJTModel::getInstance('template'); $modelBlockTemplates = CJTModel::getInstance('block-templates'); // Add all templates. foreach ($externalTemplates as $item) { // Check existance. $modelTemplate->inputs['filter']['field'] = 'name'; $modelTemplate->inputs['filter']['value'] = $item['template']['name']; if (!($existsItem = $modelTemplate->getTemplateBy()) || !property_exists($existsItem, 'id') || !$existsItem->id) { // Create template. $modelTemplate->inputs['item'] = $item; $item = (array) $modelTemplate->save(); } else { // The returned item has 'id' field not 'templateId'!! $item = array('templateId' => $existsItem->id); } // Link only if not already linked! if (!$modelBlockTemplates->isLinked($blockId, $item['templateId'])) { // Link template to the block. $modelLookup->inputs['templateId'] = $item['templateId']; $modelLookup->inputs['blockId'] = $blockId; $modelLookup->link(); } } } }
/** * put your comment there... * */ public static function enqueueStyles() { $listTypeName = CJTModel::getInstance('extensions')->getListTypeName(); // Use related scripts. self::useStyles(__CLASS__, 'thickbox', "views:extensions:plugins-list:public:css:{CJTExtensionsPluginsListView-}{$listTypeName}"); }
/** * put your comment there... * * @param mixed $name */ public function getModel($name = null) { // Instantiate model if required! if ($name) { $this->model = CJTModel::getInstance($name); } return $this->ongetmodel($this->model); }
/** * 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; }