コード例 #1
0
ファイル: helper.php プロジェクト: jdrzaic/joomla-dummy
 /**
  * Get configuration data from database.
  *
  * If configuration data does not exist in database, default configuration
  * value declared in the <b>administrator/components/com_YourComponentName/config.xml</b>
  * file will be returned.
  *
  * @param   string  $component  Component to get configuration data for. Leave empty to get configuration data for requested component.
  *
  * @return  object  An instance of JObject class.
  */
 public static function get($component = '')
 {
     // Get component
     !empty($component) or $component = JFactory::getApplication()->input->getCmd('option');
     if (!isset(self::$config) or !isset(self::$config[$component])) {
         // Instantiate config object
         self::$config[$component] = new JObject();
         // Parse config.xml file for default parameter value
         if (is_readable(JPATH_ADMINISTRATOR . '/components/' . $component . '/config.xml')) {
             $xml = JSNUtilsXml::load(JPATH_ADMINISTRATOR . '/components/' . $component . '/config.xml');
             foreach ($xml->xpath('//field["name"]') as $field) {
                 self::$config[$component]->set((string) $field['name'], (string) $field['default']);
             }
         }
         // Get name of config data table
         $table = '#__jsn_' . preg_replace('/^com_/i', '', $component) . '_config';
         // Check if table exists
         $db = JFactory::getDbo();
         $ts = $db->getTableList();
         if (in_array($table = str_replace('#__', $db->getPrefix(), $table), $ts)) {
             // Build query to get component configuration
             $q = $db->getQuery(true);
             $q->select(array('name', 'value'));
             $q->from($table);
             $q->where('1');
             $db->setQuery($q);
             if ($rows = $db->loadObjectList()) {
                 // Finalize config params
                 foreach ($rows as $row) {
                     // Decode value if it is a JSON encoded string
                     if (substr($row->value, 0, 1) == '{' and substr($row->value, -1) == '}') {
                         $row->value = json_decode($row->value);
                     }
                     self::$config[$component]->set($row->name, $row->value);
                 }
             }
         } else {
             self::$config[$component]->set('config-table-not-exists', true);
         }
     }
     return self::$config[$component];
 }
コード例 #2
0
ファイル: message.php プロジェクト: jdrzaic/joomla-dummy
    /**
     * Generate markup for message configuration.
     *
     * @param   array  $msgs  Queried messages.
     *
     * @return  string
     */
    public static function showConfig($msgs = array())
    {
        // Parse configuration declaration
        $xml = JSNUtilsXml::load(JPATH_COMPONENT_ADMINISTRATOR . '/config.xml');
        $html[] = '
	<table border="0" class="table table-bordered">
		<thead>
			<tr>
				<th width="20" class="center">#</th>
				<th class="center">' . JText::_('JSN_EXTFW_MESSAGE') . '</th>
				<th width="150" nowrap="nowrap" class="center">' . JText::_('JSN_EXTFW_MESSAGE_SCREEN') . '</th>
				<th width="80" nowrap="nowrap" class="center">' . JText::_('JSN_EXTFW_MESSAGE_ORDER') . '</th>
				<th width="80" nowrap="nowrap" class="center">' . JText::_('JSN_EXTFW_MESSAGE_SHOW') . '</th>
			</tr>
		</thead>
		<tbody>';
        for ($i = 0, $n = count($msgs); $i < $n; $i++) {
            $msg =& $msgs[$i];
            $scr = $xml->xpath('//field[@type="messagelist"]/option[@value="' . $msg->msg_screen . '"]');
            $html[] = '
			<tr>
				<td class="center">' . ($i + 1) . '</td>
				<td><span title="::' . htmlspecialchars(strip_tags(JText::_('MESSAGE_' . $msg->msg_screen . '_' . $msg->ordering . '_PRIMARY'))) . '" class="editlinktip hasTip">' . JSNUtilsText::getWords(strip_tags(JText::_('MESSAGE_' . $msg->msg_screen . '_' . $msg->ordering . '_PRIMARY')), 15) . '</span></td>
				<td class="center">' . JText::_((string) $scr[0]) . '</td>
				<td class="center">' . $msg->ordering . '</td>
				<td class="center"><input type="checkbox"' . ($msg->published ? ' checked="checked"' : '') . ' value="' . $msg->msg_id . '" name="messages[]" /></td>
			</tr>';
            if ($msg->published) {
                $html[] = '<input type="hidden" name="messagelist[]" value="' . $msg->msg_id . '" />';
            }
        }
        $html[] = '
		</tbody>
	</table>
';
        return implode($html);
    }
コード例 #3
0
ファイル: data.php プロジェクト: densem-2013/exikom
 /**
  * Do any preparation needed before doing real data restore.
  *
  * @param   string   &$backup       Path to folder containing extracted backup files.
  * @param   boolean  $checkEdition  Check for matching edition before restore?
  *
  * @return  void
  */
 protected function beforeRestore(&$backup, $checkEdition = true)
 {
     // Initialize variables
     $com = preg_replace('/^com_/i', '', JFactory::getApplication()->input->getCmd('option'));
     $info = JSNUtilsXml::loadManifestCache();
     $jVer = new JVersion();
     // Extract backup file
     if (!JArchive::extract($backup, substr($backup, 0, -4))) {
         throw new Exception(JText::_('JSN_EXTFW_DATA_EXTRACT_UPLOAD_FILE_FAIL'));
     }
     $backup = substr($backup, 0, -4);
     // Auto-detect backup XML file
     $files = glob("{$backup}/*.xml");
     foreach ($files as $file) {
         $this->data = JSNUtilsXml::load($file);
         // Check if this XML file contain backup data for our product
         if (strcasecmp($this->data->getName(), 'backup') == 0 and isset($this->data['extension-name']) and isset($this->data['extension-version']) and isset($this->data['joomla-version'])) {
             // Store backup XML file name
             $this->xml = basename($file);
             // Simply break the loop if we found backup file
             break;
         }
         unset($this->data);
     }
     if (isset($this->data)) {
         // Check if Joomla series match
         if (!$jVer->isCompatible((string) $this->data['joomla-version'])) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_JOOMLA_VERSION_NOT_MATCH'));
         }
         // Check if extension match
         if ((string) $this->data['extension-name'] != 'JSN ' . preg_replace('/JSN\\s*/i', '', JText::_($info->name))) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_INVALID_PRODUCT'));
         } elseif (isset($this->data['extension-edition']) and $checkEdition and (!($const = JSNUtilsText::getConstant('EDITION')) or (string) $this->data['extension-edition'] != $const)) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_INVALID_PRODUCT_EDITION'));
         } elseif (!version_compare($info->version, (string) $this->data['extension-version'], '=') and !$checkEdition) {
             // Get update link for out-of-date product
             $ulink = $info->authorUrl;
             if (isset($this->data['update-url'])) {
                 $ulink = (string) $this->data['update-url'];
             } elseif ($const = JSNUtilsText::getConstant('UPDATE_LINK')) {
                 $ulink = $const;
             }
             throw new Exception(JText::_('JSN_EXTFW_DATA_PRODUCT_VERSION_OUTDATE') . '&nbsp;<a href="' . $ulink . '" class="jsn-link-action">' . JText::_('JSN_EXTFW_GENERAL_UPDATE_NOW') . '</a>');
         } elseif (!version_compare($info->version, (string) $this->data['extension-version'], 'ge')) {
             // Get update link for out-of-date product
             $ulink = $info->authorUrl;
             if (isset($this->data['update-url'])) {
                 $ulink = (string) $this->data['update-url'];
             } elseif ($const = JSNUtilsText::getConstant('UPDATE_LINK')) {
                 $ulink = $const;
             }
             throw new Exception(JText::_('JSN_EXTFW_DATA_PRODUCT_VERSION_OUTDATE') . '&nbsp;<a href="' . $ulink . '" class="jsn-link-action">' . JText::_('JSN_EXTFW_GENERAL_UPDATE_NOW') . '</a>');
         }
     } else {
         throw new Exception(JText::_('JSN_EXTFW_DATA_BACKUP_XML_NOT_FOUND'));
     }
     $dataForm = $this->getForm();
     if (!empty($dataForm) && count($dataForm)) {
         foreach ($dataForm as $formId) {
             if (!empty($formId->form_id) && (int) $formId->form_id) {
                 $this->_db->setQuery("DROP TABLE IF EXISTS #__jsn_uniform_submissions_{$formId->form_id}");
                 $this->_db->execute();
             }
         }
     }
     if (JSNUniformHelper::checkTableSql('#__jsn_uniform_submissions') === false) {
         JSNUniformHelper::createTableIfNotExistsSubmissions();
     }
     if (JSNUniformHelper::checkTableSql('#__jsn_uniform_submission_data') === false) {
         JSNUniformHelper::createTableIfNotExistsSubmissionData();
     }
 }
コード例 #4
0
 /**
  * Event handler to re-parse request URI.
  *
  * @return  void
  */
 public function onAfterRoute()
 {
     // Get installed Joomla version
     $JVersion = new JVersion();
     $JVersion = $JVersion->getShortVersion();
     $option = trim((string) $this->option);
     if (self::$_app->isAdmin() && version_compare($JVersion, '3.0', '>=') && in_array($option, JSNVersion::$products)) {
         $manifestFile = JPATH_ADMINISTRATOR . '/components/' . $option . '/' . str_replace('com_', '', $option) . '.xml';
         if (file_exists($manifestFile)) {
             $xml = JSNUtilsXml::load($manifestFile);
             $attr = $xml->attributes();
             if (count($attr)) {
                 if (isset($attr['version']) && (string) $attr['version'] != '') {
                     $version = (string) $attr['version'];
                     if ($option == 'com_imageshow') {
                         $version = str_replace('.x', '.0', $version);
                     }
                     if (version_compare($version, '3.0', '<')) {
                         // Check if all JSN Extensions are compatible with Joomla 3.x, if not, redirect to index.php and show a warning message
                         self::$_app->enqueueMessage(JText::sprintf('You are running a Joomla 2.5 version of %1$s on Joomla 3.x. Please download %1$s for Joomla 3.x and reinstall via Joomla! Installer to fix the problem.', 'JSN ' . ucfirst(str_replace('com_', '', $option))), 'warning');
                         self::$_app->redirect('index.php');
                         return false;
                     }
                 }
             }
         }
     }
     // Make sure our onAfterRender event handler is the last one executed
     self::$_app->registerEvent('onAfterRender', 'jsnExtFrameworkFinalize');
 }
コード例 #5
0
ファイル: model.php プロジェクト: jdrzaic/joomla-dummy
 /**
  * Do any preparation needed before installing update package.
  *
  * @param   string  $path  Path to downloaded update package.
  *
  * @return  void
  */
 protected function beforeInstall($path)
 {
     // Get product config
     $xml = JSNUtilsXml::load(JPATH_COMPONENT_ADMINISTRATOR . '/config.xml');
     // Build backup options
     $backupOptions = array('no-download' => true);
     if (is_array($xml->xpath('//field[@type="databackup"]/option'))) {
         foreach ($xml->xpath('//field[@type="databackup"]/option') as $option) {
             // Parse option parameters
             $value = array();
             if ((string) $option['type'] == 'tables') {
                 // Generate option value
                 foreach ($option->table as $param) {
                     $value[] = (string) $param;
                 }
             } elseif ((string) $option['type'] == 'files') {
                 // Generate option value
                 foreach ($option->folder as $param) {
                     $value[(string) $param] = (string) $param['filter'];
                 }
             } else {
                 continue;
             }
             $backupOptions[(string) $option['type']][] = json_encode($value);
         }
     }
     // Backup the product data
     try {
         $this->backup = new JSNDataModel();
         $this->backup = $this->backup->backup($backupOptions);
     } catch (Exception $e) {
         throw $e;
     }
 }
コード例 #6
0
ファイル: model.php プロジェクト: jdrzaic/joomla-dummy
 /**
  * Parse configuration declaration.
  *
  * This method parses the <b>administrator/components/com_YourComponentName/config.xml</b>
  * file for configuration declaration.
  *
  * @param   array    $data        Data to preset into form field.
  * @param   boolean  $loadData    Load data for form field or not?
  * @param   string   $configFile  Path to config declaration XML file.
  *
  * @return  array  Array of stdClass objects.
  */
 public function getForm($data = array(), $loadData = true, $configFile = '')
 {
     // Load configuration declaration
     if (empty($configFile)) {
         $xml = JSNUtilsXml::load(JPATH_COMPONENT_ADMINISTRATOR . '/config.xml');
     } else {
         $xml = JSNUtilsXml::load($configFile);
     }
     if (is_null($xml->section[0])) {
         return array();
     }
     // Automatically add script movement settings
     if (isset($xml->section[0]->group[0]->tab)) {
         $tab = $xml->section[0]->group[0]->addChild('tab');
         $tab->addAttribute('name', 'global-parameter-optimization');
         $tab->addAttribute('label', 'JSN_EXTFW_CONFIG_OPTIMIZATION');
         $fieldset = $tab->addChild('fieldset');
         $fieldset->addAttribute('name', 'optimization');
         $field = $fieldset->addChild('field');
     } elseif (isset($xml->section[0]->group[0]->fieldset)) {
         $fieldset = $xml->section[0]->group[0]->addChild('fieldset');
         $fieldset->addAttribute('name', 'optimization');
         $fieldset->addAttribute('label', 'JSN_EXTFW_CONFIG_OPTIMIZATION');
         $field = $fieldset->addChild('field');
     } else {
         $field = $xml->section[0]->group[0]->addChild('field');
     }
     $field->addAttribute('name', 'script_movement');
     $field->addAttribute('type', 'jsnradio');
     $field->addAttribute('default', 0);
     $field->addAttribute('filter', 'int');
     $field->addAttribute('label', 'JSN_EXTFW_CONFIG_OPTIMIZATION_SCRIPT_MOVEMENT_LABEL');
     $field->addAttribute('description', 'JSN_EXTFW_CONFIG_OPTIMIZATION_SCRIPT_MOVEMENT_DESC');
     $option = $field->addChild('option', 'JYES');
     $option->addAttribute('value', 1);
     $option = $field->addChild('option', 'JNO');
     $option->addAttribute('value', 0);
     if (isset($fieldset)) {
         $action = $fieldset->addChild('action');
         $action->addAttribute('label', 'JAPPLY');
         $action->addAttribute('task', 'configuration.save');
         $action->addAttribute('track', 1);
         $action->addAttribute('ajax', 1);
     }
     // Automatically add live update notification settings
     $group = $xml->section[0]->addChild('group');
     $group->addAttribute('name', 'update');
     $group->addAttribute('label', 'JSN_EXTFW_CONFIG_UPDATE');
     $group->addAttribute('icon', 'download');
     $fieldset = $group->addChild('fieldset');
     $fieldset->addAttribute('name', 'update');
     $field = $fieldset->addChild('field');
     $field->addAttribute('name', 'live_update_check_interval');
     $field->addAttribute('type', 'jsntext');
     $field->addAttribute('input-type', 'number');
     $field->addAttribute('default', 6);
     $field->addAttribute('filter', 'int');
     $field->addAttribute('exttext', JText::_('JSN_EXTFW_CONFIG_LIVE_UPDATE_CHECK_INTERVAL_UNIT'));
     $field->addAttribute('class', 'input-small validate-positive-number');
     $field->addAttribute('label', 'JSN_EXTFW_CONFIG_LIVE_UPDATE_CHECK_INTERVAL_LABEL');
     $field->addAttribute('description', 'JSN_EXTFW_CONFIG_LIVE_UPDATE_CHECK_INTERVAL_DESC');
     $field = $fieldset->addChild('field');
     $field->addAttribute('name', 'live_update_notification');
     $field->addAttribute('type', 'jsnradio');
     $field->addAttribute('default', 0);
     $field->addAttribute('filter', 'int');
     $field->addAttribute('label', 'JSN_EXTFW_CONFIG_LIVE_UPDATE_NOTIFICATION_LABEL');
     $field->addAttribute('description', 'JSN_EXTFW_CONFIG_LIVE_UPDATE_NOTIFICATION_DESC');
     $option = $field->addChild('option', 'JYES');
     $option->addAttribute('value', 1);
     $option = $field->addChild('option', 'JNO');
     $option->addAttribute('value', 0);
     $action = $fieldset->addChild('action');
     $action->addAttribute('label', 'JAPPLY');
     $action->addAttribute('task', 'configuration.save');
     $action->addAttribute('track', 1);
     $action->addAttribute('ajax', 1);
     // Parse configuration declaration
     return $this->loadSections($xml);
 }