コード例 #1
0
 /**
  * Loads the configuration and works as singleton therefore called static. The call using the program cache
  * is 10 times faster then taking from the session. The session is still approx. 30 times faster then using the file.
  * The db is 10 times slower then the session.
  *
  * Performance:
  *
  * Fastest is
  * Program Cache: 1.5974044799805E-5
  * Session Cache: 0.00016094612121582
  *
  * First config db load: 0.00052118301391602
  * Parsed and in session: 0.001554012298584
  *
  * After install from file: 0.0040450096130371
  * Parsed and in session: 0.0051419734954834
  *
  *
  * Functions tests if already loaded in program cache, session cache, database and at last the file.
  *
  * Load the configuration values from the database into a session variable.
  * This step is done to prevent accessing the database for every configuration variable lookup.
  *
  * @author Max Milbers
  * @param $force boolean Forces the function to load the config from the db
  */
 public static function loadConfig($force = FALSE, $fresh = FALSE)
 {
     if ($fresh) {
         self::$_jpConfig = new VmConfig();
         return self::$_jpConfig;
     }
     vmSetStartTime('loadConfig');
     if (!$force) {
         if (!empty(self::$_jpConfig) && !empty(self::$_jpConfig->_params)) {
             return self::$_jpConfig;
         }
     }
     self::$_jpConfig = new VmConfig();
     if (!class_exists('VirtueMartModelConfig')) {
         require VMPATH_ADMIN . '/models/config.php';
     }
     $configTable = VirtueMartModelConfig::checkConfigTableExists();
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     self::$installed = true;
     $install = vRequest::getInt('install', false);
     $redirected = vRequest::getInt('redirected', false);
     $link = '';
     if (empty($configTable)) {
         self::$installed = false;
         $jlang = JFactory::getLanguage();
         $selectedLang = $jlang->getTag();
         if (empty($selectedLang)) {
             $selectedLang = $jlang->setLanguage($selectedLang);
         }
         $q = 'SELECT `element` FROM `#__extensions` WHERE type = "language" and enabled = "1"';
         $db->setQuery($q);
         $knownLangs = $db->loadColumn();
         //vmdebug('Selected language '.$selectedLang.' $knownLangs ',$knownLangs);
         if ($app->isAdmin() and !in_array($selectedLang, $knownLangs)) {
             $link = 'index.php?option=com_installer&view=languages';
             $msg = 'Install your selected language <b>' . $selectedLang . '</b> first in <a href="' . $link . '">joomla language manager</a>, just select then the component VirtueMart under menu "component", to proceed with the installation ';
             $app->enqueueMessage($msg);
         }
         self::$installed = VirtueMartModelConfig::checkVirtuemartInstalled();
         if (!self::$installed) {
             if (!$redirected and !$install) {
                 $link = 'index.php?option=com_virtuemart&view=updatesmigration&redirected=1';
                 $msg = '';
                 if ($app->isSite()) {
                     $link = JURI::root(true) . '/administrator/' . $link;
                 } else {
                     $msg = 'Install Virtuemart first, click on the menu component and select VirtueMart';
                 }
             }
         }
     } else {
         $query = ' SELECT `config` FROM `#__virtuemart_configs` WHERE `virtuemart_config_id` = "1";';
         $db->setQuery($query);
         self::$_jpConfig->_raw = $db->loadResult();
         //vmTime('time to load config','loadConfig');
     }
     if (empty(self::$_jpConfig->_raw)) {
         $_value = VirtueMartModelConfig::readConfigFile();
         if (!$_value) {
             vmError('Serious error, config file could not be filled with data');
             return FALSE;
         }
         $_value = join('|', $_value);
         self::$_jpConfig->_raw = $_value;
         self::$_jpConfig->setParams(self::$_jpConfig->_raw);
         self::$_jpConfig->storeConfig();
     } else {
         self::$_jpConfig->setParams(self::$_jpConfig->_raw);
     }
     self::$_secret = JFactory::getConfig()->get('secret');
     self::$_jpConfig->_params['sctime'] = microtime(TRUE);
     self::$_jpConfig->_params['vmlang'] = self::setdbLanguageTag();
     vmTime('time to load config', 'loadConfig');
     if ($app->isSite()) {
         // try plugins
         JPluginHelper::importPlugin('vmuserfield');
         $dispatcher = JDispatcher::getInstance();
         $dispatcher->trigger('plgVmInitialise', array());
     }
     if (!self::$installed) {
         $user = JFactory::getUser();
         if ($user->authorise('core.admin', 'com_virtuemart') and ($install or $redirected)) {
             VmConfig::$_jpConfig->set('dangeroustools', 1);
         }
         if (!empty($link)) {
             $app->redirect($link, $msg);
         }
     }
     return self::$_jpConfig;
 }
コード例 #2
0
    /**
     * Display the administrative ribbon menu.
     * @todo The link should be done better
     */
    static function showAdminMenu($vmView)
    {
        if (!isset(VmConfig::$installed)) {
            VmConfig::$installed = false;
        }
        if (!VmConfig::$installed) {
            return false;
        }
        $moduleId = vRequest::getInt('module_id', 0);
        $menuItems = AdminUIHelper::_getAdminMenu($moduleId);
        $app = JFactory::getApplication();
        $isSite = $app->isSite();
        ?>

		<div id="admin-ui-menu" class="admin-ui-menu">
		<?php 
        $modCount = 1;
        foreach ($menuItems as $item) {
            $html = '';
            foreach ($item['items'] as $link) {
                $target = '';
                if ($link['name'] == '-') {
                    // it was emtpy before
                } else {
                    if (strncmp($link['link'], 'http', 4) === 0) {
                        $url = $link['link'];
                        $target = 'target="_blank"';
                    } else {
                        $url = $link['link'] === '' ? 'index.php?option=com_virtuemart' : $link['link'];
                        $url .= $link['view'] ? "&view=" . $link['view'] : '';
                        $url .= $link['task'] ? "&task=" . $link['task'] : '';
                        $url .= $isSite ? '&tmpl=component&manage=1' : '';
                        // $url .= $link['extra'] ? $link['extra'] : '';
                    }
                    if ($vmView->manager($link['view']) || $target || $link['view'] == 'about' || $link['view'] == 'virtuemart') {
                        $html .= '
						<li>
							<a href="' . $url . '" ' . $target . '>
								<span class="vmicon-wrapper"><span class="' . $link['icon_class'] . '"></span></span>
								<span class="menu-subtitle">' . vmText::_($link['name']) . '</span>
							</a>
						</li>';
                    }
                }
            }
            if (!empty($html)) {
                ?>

				<h3 class="menu-title">
					<span class="menu-title-wrapper">
						<span class="vmicon-wrapper"><span class="<?php 
                echo vmText::_($item['items'][0]['icon_class']);
                ?>
"></span></span>
						<span class="menu-title-content"><?php 
                echo vmText::_($item['title']);
                ?>
</span>
					</span>
				</h3>

				<div class="menu-list">
					<ul>
						<?php 
                echo $html;
                ?>

					</ul>
				</div>
				<?php 
                $modCount++;
            }
        }
        ?>

		<div class="menu-notice"></div>
		</div>
	<?php 
    }