/** * Get list of supported editions for current template. * * @return array */ protected function loadEditions() { $cacheFile = JPATH_SITE . '/templates/' . $this->data->template . '/editions.json'; // Retrieve template editions from cache file if (is_file($cacheFile) and is_readable($cacheFile)) { $editions = json_decode(JFile::read($cacheFile), true); if (!empty($editions)) { $this->editions = $editions; return $editions; } } try { $response = JSNTplHttpRequest::get(JSN_TPLFRAMEWORK_VERSIONING_URL . '?category=cat_template'); $json = json_decode(trim($response['body']), true); } catch (Exception $e) { // Do nothing } // Return only free edition if cannot parse data returned from server if (empty($json) or !is_array($json) or !isset($json['items'])) { $this->editions = array('FREE'); } else { $templateId = JSNTplHelper::getTemplateId($this->data->template); $this->editions = array('FREE'); foreach ($json['items'] as $item) { if (isset($item['identified_name']) && $templateId == $item['identified_name']) { if (isset($item['editions']) and is_array($item['editions'])) { foreach ($item['editions'] as $edition) { $e = strtoupper(trim($edition['edition'])); in_array($e, $this->editions) or $this->editions[] = $e; } } elseif (isset($item['edition']) and !empty($item['edition'])) { $e = strtoupper(trim($item['edition'])); in_array($e, $this->editions) or $this->editions[] = $e; } } } } // Cache edition data $buffer = json_encode($this->editions); JFile::write($cacheFile, $buffer); }
/** * Retrieve template detailed information and store * it in the memory * * @param string $name The template name * @return void */ private function _parseTemplateInfo($name) { if (!($details = JSNTplTemplateRecognization::detect($name))) { JFactory::getApplication()->enqueueMessage("The template {$name} is not a valid JoomlaShine template!"); } $this->template = array('name' => $name, 'realName' => JText::_($name), 'id' => JSNTplHelper::getTemplateId($name), 'edition' => JSNTplHelper::getTemplateEdition($name), 'version' => JSNTplHelper::getTemplateVersion($name)); }