Ejemplo n.º 1
0
	public function save()
	{
		$data = self::$registry->toString('INI');
		
		$db =& JFactory::getDBO();
		
		// An interesting discovery: if your component is manually updating its
		// component parameters before Live Update is called, then calling Live
		// Update will reset the modified component parameters because
		// JComponentHelper::getComponent() returns the old, cached version of
		// them. So, we have to forget the following code and shoot ourselves in
		// the feet. Dammit!!!
		/*
		jimport('joomla.html.parameter');
		jimport('joomla.application.component.helper');
		$component =& JComponentHelper::getComponent(self::$component);
		$params = new JParameter($component->params);
		$params->setValue(self::$key, $data);
		*/

		if( version_compare(JVERSION,'1.6.0','ge') ) {
			$sql = 'SELECT '.$db->nameQuote('params').' FROM '.$db->nameQuote('#__extensions').
				' WHERE '.$db->nameQuote('type').' = '.$db->Quote('component').' AND '.
				$db->nameQuote('element').' = '.$db->Quote(self::$component);
			$db->setQuery($sql);
		} else {
			$sql = 'SELECT '.$db->nameQuote('params').' FROM '.$db->nameQuote('#__components').
				' WHERE '.$db->nameQuote('option').' = '.$db->Quote(self::$component).
				" AND `parent` = 0 AND `menuid` = 0";
			$db->setQuery($sql);
		}
		$rawparams = $db->loadResult();
		$params = new JParameter($rawparams);
		$params->setValue(self::$key, $data);
		
		if( version_compare(JVERSION,'1.6.0','ge') )
		{
			// Joomla! 1.6
			$data = $params->toString('JSON');
			$sql = 'UPDATE `#__extensions` SET `params` = '.$db->Quote($data).' WHERE '.
				"`element` = ".$db->Quote(self::$component)." AND `type` = 'component'";
		}
		else
		{
			// Joomla! 1.5
			$data = $params->toString('INI');
			$sql = 'UPDATE `#__components` SET `params` = '.$db->Quote($data).' WHERE '.
				"`option` = ".$db->Quote(self::$component)." AND `parent` = 0 AND `menuid` = 0";
		}

		$db->setQuery($sql);
		$db->query();
	}
Ejemplo n.º 2
0
 /**
  * Set user state property into database.
  *
  * @param string $param property name
  * @param string $value property value
  */
 public static function setUserState($param, $value)
 {
     if (isset($_COOKIE['joomdoc'])) {
         $session = (int) $_COOKIE['joomdoc'];
     } else {
         $session = rand(100);
         $uri = JURI::getInstance();
         setcookie('joomdoc', $session, time() + 365 * 24 * 60 * 60, '/', $uri->toString(array('host')));
     }
     $db = JFactory::getDbo();
     $db->setQuery('SELECT `params` FROM `#__joomdoc_userstate` WHERE `session` = ' . $session);
     $params = new JParameter($db->loadResult());
     $params->setValue($param, $value);
     $params = $db->Quote($params->toString());
     $query = 'INSERT INTO `#__joomdoc_userstate` (`session`,`params`) VALUES (' . $session . ',' . $params . ') ';
     $query .= 'ON DUPLICATE KEY UPDATE `params` = ' . $params;
     $db->setQuery($query);
     $db->query();
 }
Ejemplo n.º 3
0
 public function save()
 {
     $enableSRP = $this->input->get('srp', 0, 'bool');
     $enableAutoupdate = $this->input->get('autoupdate', 0, 'bool');
     $runConfwiz = $this->input->get('confwiz', 0, 'bool');
     $angieupgrade = $this->input->get('angieupgrade', 0, 'bool');
     $minStability = $this->input->get('minstability', 'stable', 'cmd');
     $acceptlicense = $this->input->get('acceptlicense', 0, 'bool');
     $acceptsupport = $this->input->get('acceptsupport', 0, 'bool');
     $acceptbackuptest = $this->input->get('acceptbackuptest', 0, 'bool');
     if (!in_array($minStability, array('alpha', 'beta', 'rc', 'stable'))) {
         $minStability = 'stable';
     }
     // SRP is only supported on MySQL databases
     if (!$this->isMySQL()) {
         $enableSRP = false;
     }
     $db = JFactory::getDBO();
     if ($enableSRP) {
         $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q('1'))->where($db->qn('element') . ' = ' . $db->q('srp'))->where($db->qn('folder') . ' = ' . $db->q('system'));
         $db->setQuery($query);
         $db->execute();
     } else {
         $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q('0'))->where($db->qn('element') . ' = ' . $db->q('srp'))->where($db->qn('folder') . ' = ' . $db->q('system'));
         $db->setQuery($query);
         $db->execute();
     }
     if ($enableAutoupdate) {
         $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q('1'))->where($db->qn('element') . ' = ' . $db->q('oneclickaction'))->where($db->qn('folder') . ' = ' . $db->q('system'));
         $db->setQuery($query);
         $db->execute();
         $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q('1'))->where($db->qn('element') . ' = ' . $db->q('akeebaupdatecheck'))->where($db->qn('folder') . ' = ' . $db->q('system'));
         $db->setQuery($query);
         $db->execute();
     } else {
         $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q('0'))->where($db->qn('element') . ' = ' . $db->q('oneclickaction'))->where($db->qn('folder') . ' = ' . $db->q('system'));
         $db->setQuery($query);
         $db->execute();
         $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q('0'))->where($db->qn('element') . ' = ' . $db->q('akeebaupdatecheck'))->where($db->qn('folder') . ' = ' . $db->q('system'));
         $db->setQuery($query);
         $db->execute();
     }
     if ($angieupgrade) {
         $this->_angieUpgrade();
     }
     // Update last version check and minstability. DO NOT USE JCOMPONENTHELPER!
     $sql = $db->getQuery(true)->select($db->qn('params'))->from($db->qn('#__extensions'))->where($db->qn('type') . ' = ' . $db->q('component'))->where($db->qn('element') . ' = ' . $db->q('com_akeeba'));
     $db->setQuery($sql);
     $rawparams = $db->loadResult();
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $params = new JRegistry();
         if (version_compare(JVERSION, '3.0', 'ge')) {
             $params->loadString($rawparams);
         } else {
             $params->loadJSON($rawparams);
         }
     } else {
         $params = new JParameter($rawparams);
     }
     if ($acceptlicense && $acceptsupport) {
         $version = AKEEBA_VERSION;
     } else {
         $version = '0.0.0';
     }
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $params->set('lastversion', $version);
         $params->set('minstability', $minStability);
         $params->set('acceptlicense', $acceptlicense);
         $params->set('acceptsupport', $acceptsupport);
         $params->set('acceptbackuptest', $acceptbackuptest);
         $params->set('angieupgrade', $angieupgrade ? 1 : 0);
     } else {
         $params->setValue('lastversion', $version);
         $params->setValue('minstability', $minStability);
         $params->setValue('acceptlicense', $acceptlicense);
         $params->setValue('acceptsupport', $acceptsupport);
         $params->setValue('acceptbackuptest', $acceptbackuptest);
         $params->setValue('angieupgrade', $angieupgrade ? 1 : 0);
     }
     $data = $params->toString('JSON');
     $sql = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('params') . ' = ' . $db->q($data))->where($db->qn('element') . ' = ' . $db->q('com_akeeba'))->where($db->qn('type') . ' = ' . $db->q('component'));
     $db->setQuery($sql);
     $db->execute();
     // Even better, create the "akeeba.lastversion.php" file with this information
     $fileData = "<" . "?php\ndefined('_JEXEC') or die();\ndefine('AKEEBA_LASTVERSIONCHECK','" . $version . "');";
     JLoader::import('joomla.filesystem.file');
     $fileName = JPATH_COMPONENT_ADMINISTRATOR . '/akeeba.lastversion.php';
     JFile::write($fileName, $fileData);
     // Force reload the Live Update information
     if ($version != '0.0.0') {
         $dummy = LiveUpdate::getUpdateInformation(true);
     }
     // Run the configuration wizard if requested
     $message = '';
     if ($runConfwiz) {
         $url = 'index.php?option=com_akeeba&view=confwiz';
     } else {
         $url = 'index.php?option=com_akeeba&view=cpanel';
     }
     if (!$acceptlicense) {
         JFactory::getApplication()->enqueueMessage(JText::_('AKEEBA_POSTSETUP_ERR_ACCEPTLICENSE'), 'error');
         $url = 'index.php?option=com_akeeba&view=postsetup';
     }
     if (!$acceptsupport) {
         JFactory::getApplication()->enqueueMessage(JText::_('AKEEBA_POSTSETUP_ERR_ACCEPTSUPPORT'), 'error');
         $url = 'index.php?option=com_akeeba&view=postsetup';
     }
     if (!$acceptbackuptest) {
         JFactory::getApplication()->enqueueMessage(JText::_('AKEEBA_POSTSETUP_ERR_ACCEPTBACKUPTEST'), 'error');
         $url = 'index.php?option=com_akeeba&view=postsetup';
     }
     JFactory::getApplication()->redirect($url);
 }
Ejemplo n.º 4
0
 public function save()
 {
     $enableSRP = JRequest::getBool('srp', 0);
     $enableAutoupdate = JRequest::getBool('autoupdate', 0);
     $runConfwiz = JRequest::getBool('confwiz', 0);
     $db = JFactory::getDBO();
     if ($enableSRP) {
         if (version_compare(JVERSION, '1.6.0', 'ge')) {
             $query = "UPDATE #__extensions SET enabled=1 WHERE element='srp' AND folder='system'";
             $db->setQuery($query);
             $db->query();
         } else {
             $query = "UPDATE #__plugins SET published=1 WHERE element='srp' AND folder='system'";
             $db->setQuery($query);
             $db->query();
         }
     } else {
         if (version_compare(JVERSION, '1.6.0', 'ge')) {
             $query = "UPDATE #__extensions SET enabled=0 WHERE element='srp' AND folder='system'";
             $db->setQuery($query);
             $db->query();
         } else {
             $query = "UPDATE #__plugins SET published=0 WHERE element='srp' AND folder='system'";
             $db->setQuery($query);
             $db->query();
         }
     }
     if ($enableAutoupdate) {
         if (version_compare(JVERSION, '1.6.0', 'ge')) {
             $query = "UPDATE #__extensions SET enabled=1 WHERE element='oneclickaction' AND folder='system'";
             $db->setQuery($query);
             $db->query();
             $query = "UPDATE #__extensions SET enabled=1 WHERE element='akeebaupdatecheck' AND folder='system'";
             $db->setQuery($query);
             $db->query();
         } else {
             $query = "UPDATE #__plugins SET published=1 WHERE element='oneclickaction' AND folder='system'";
             $db->setQuery($query);
             $db->query();
             $query = "UPDATE #__plugins SET published=1 WHERE element='akeebaupdatecheck' AND folder='system'";
             $db->setQuery($query);
             $db->query();
         }
     } else {
         if (version_compare(JVERSION, '1.6.0', 'ge')) {
             $query = "UPDATE #__extensions SET enabled=0 WHERE element='oneclickaction' AND folder='system'";
             $db->setQuery($query);
             $db->query();
             $query = "UPDATE #__extensions SET enabled=0 WHERE element='akeebaupdatecheck' AND folder='system'";
             $db->setQuery($query);
             $db->query();
         } else {
             $query = "UPDATE #__plugins SET published=0 WHERE element='oneclickaction' AND folder='system'";
             $db->setQuery($query);
             $db->query();
             $query = "UPDATE #__plugins SET published=0 WHERE element='akeebaupdatecheck' AND folder='system'";
             $db->setQuery($query);
             $db->query();
         }
     }
     // Update last version check. DO NOT USE JCOMPONENTHELPER!
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $sql = 'SELECT ' . $db->nameQuote('params') . ' FROM ' . $db->nameQuote('#__extensions') . ' WHERE ' . $db->nameQuote('type') . ' = ' . $db->Quote('component') . ' AND ' . $db->nameQuote('element') . ' = ' . $db->Quote('com_akeeba');
         $db->setQuery($sql);
     } else {
         $sql = 'SELECT ' . $db->nameQuote('params') . ' FROM ' . $db->nameQuote('#__components') . ' WHERE ' . $db->nameQuote('option') . ' = ' . $db->Quote('com_akeeba') . " AND `parent` = 0 AND `menuid` = 0";
         $db->setQuery($sql);
     }
     $rawparams = $db->loadResult();
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $params = new JRegistry();
         $params->loadJSON($rawparams);
     } else {
         $params = new JParameter($rawparams);
     }
     $params->setValue('lastversion', AKEEBA_VERSION);
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         // Joomla! 1.6
         $data = $params->toString('JSON');
         $sql = 'UPDATE `#__extensions` SET `params` = ' . $db->Quote($data) . ' WHERE ' . "`element` = " . $db->Quote('com_akeeba') . " AND `type` = 'component'";
     } else {
         // Joomla! 1.5
         $data = $params->toString('INI');
         $sql = 'UPDATE `#__components` SET `params` = ' . $db->Quote($data) . ' WHERE ' . "`option` = " . $db->Quote('com_akeeba') . " AND `parent` = 0 AND `menuid` = 0";
     }
     $db->setQuery($sql);
     $db->query();
     // Even better, create the "akeeba.lastversion.php" file with this information
     $fileData = "<" . "?php\ndefined('_JEXEC') or die();\ndefine('AKEEBA_LASTVERSIONCHECK','" . AKEEBA_VERSION . "');";
     jimport('joomla.filesystem.file');
     $fileName = JPATH_COMPONENT_ADMINISTRATOR . '/akeeba.lastversion.php';
     JFile::write($fileName, $fileData);
     // Force reload the Live Update information
     $dummy = LiveUpdate::getUpdateInformation(true);
     // Run the configuration wizard if requested
     if ($runConfwiz) {
         $url = 'index.php?option=com_akeeba&view=confwiz';
     } else {
         $url = 'index.php?option=com_akeeba&view=cpanel';
     }
     $app = JFactory::getApplication();
     $app->redirect($url);
 }
Ejemplo n.º 5
0
 function install($theme)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $package = $this->_getPackageFromUpload();
     if (!$package) {
         JError::raiseWarning(1, JText::_('COM_PHOCAGALLERY_ERROR_FIND_INSTALL_PACKAGE'));
         $this->deleteTempFiles();
         return false;
     }
     if ($package['dir'] && JFolder::exists($package['dir'])) {
         $this->setPath('source', $package['dir']);
     } else {
         JError::raiseWarning(1, JText::_('COM_PHOCAGALLERY_ERROR_INSTALL_PATH_NOT_EXISTS'));
         $this->deleteTempFiles();
         return false;
     }
     // We need to find the installation manifest file
     if (!$this->_findManifest()) {
         JError::raiseWarning(1, JText::_('COM_PHOCAGALLERY_ERROR_FIND_INFO_INSTALL_PACKAGE'));
         $this->deleteTempFiles();
         return false;
     }
     // Files - copy files in manifest
     foreach ($this->_manifest->children() as $child) {
         if (is_a($child, 'JXMLElement') && $child->name() == 'files') {
             if ($this->parseFiles($child) === false) {
                 JError::raiseWarning(1, JText::_('COM_PHOCAGALLERY_ERROR_FIND_INFO_INSTALL_PACKAGE'));
                 $this->deleteTempFiles();
                 return false;
             }
         }
     }
     // File - copy the xml file
     $copyFile = array();
     $path['src'] = $this->getPath('manifest');
     // XML file will be copied too
     $path['dest'] = JPATH_SITE . DS . 'components' . DS . 'com_phocagallery' . DS . 'assets' . DS . 'images' . DS . basename($this->getPath('manifest'));
     $copyFile[] = $path;
     $this->copyFiles($copyFile, array());
     $this->deleteTempFiles();
     // -------------------
     // Themes
     // -------------------
     // Params -  Get new themes params
     $paramsThemes = $this->getParamsThemes();
     // -------------------
     // Component
     // -------------------
     if (isset($theme['component']) && $theme['component'] == 1) {
         $component = 'com_phocagallery';
         $paramsC = JComponentHelper::getParams($component);
         foreach ($paramsThemes as $keyT => $valueT) {
             $paramsC->setValue($valueT['name'], $valueT['value']);
         }
         $data['params'] = $paramsC->toArray();
         $table = JTable::getInstance('extension');
         $idCom = $table->find(array('element' => $component));
         $table->load($idCom);
         if (!$table->bind($data)) {
             JError::raiseWarning(500, 'Not a valid component');
             return false;
         }
         // pre-save checks
         if (!$table->check()) {
             JError::raiseWarning(500, $table->getError('Check Problem'));
             return false;
         }
         // save the changes
         if (!$table->store()) {
             JError::raiseWarning(500, $table->getError('Store Problem'));
             return false;
         }
     }
     // -------------------
     // Menu Categories
     // -------------------
     if (isset($theme['categories']) && $theme['categories'] == 1) {
         $link = 'index.php?option=com_phocagallery&view=categories';
         $where = array();
         $where[] = 'link = ' . $db->Quote($link);
         $query = 'SELECT id, params FROM #__menu WHERE ' . implode(' AND ', $where);
         $db->setQuery($query);
         $itemsCat = $db->loadObjectList();
         if (!empty($itemsCat)) {
             foreach ($itemsCat as $keyIT => $valueIT) {
                 $query = 'SELECT m.params FROM #__menu AS m WHERE m.id = ' . (int) $valueIT->id;
                 $db->setQuery($query);
                 $paramsCJSON = $db->loadResult();
                 //$paramsCJSON = $valueIT->params;
                 $paramsMc = new JParameter();
                 $paramsMc->loadJSON($paramsCJSON);
                 foreach ($paramsThemes as $keyT => $valueT) {
                     $paramsMc->setValue($valueT['name'], $valueT['value']);
                 }
                 $dataMc['params'] = $paramsMc->toArray();
                 $table =& JTable::getInstance('menu');
                 if (!$table->load((int) $valueIT->id)) {
                     JError::raiseWarning(500, 'Not a valid table');
                     return false;
                 }
                 if (!$table->bind($dataMc)) {
                     JError::raiseWarning(500, 'Not a valid table');
                     return false;
                 }
                 // pre-save checks
                 if (!$table->check()) {
                     JError::raiseWarning(500, $table->getError('Check Problem'));
                     return false;
                 }
                 // save the changes
                 if (!$table->store()) {
                     JError::raiseWarning(500, $table->getError('Store Problem'));
                     return false;
                 }
             }
         }
     }
     // -------------------
     // Menu Category
     // -------------------
     if (isset($theme['category']) && $theme['category'] == 1) {
         // Select all categories to get possible menu links
         $query = 'SELECT c.id FROM #__phocagallery_categories AS c';
         $db->setQuery($query);
         $categoriesId = $db->loadObjectList();
         // We get id from Phoca Gallery categories and try to find menu links from these categories
         if (!empty($categoriesId)) {
             foreach ($categoriesId as $keyI => $valueI) {
                 $link = 'index.php?option=com_phocagallery&view=category&id=' . (int) $valueI->id;
                 //$link		= 'index.php?option=com_phocagallery&view=category';
                 $where = array();
                 $where[] = 'link = ' . $db->Quote($link);
                 $query = 'SELECT id, params FROM #__menu WHERE ' . implode(' AND ', $where);
                 $db->setQuery($query);
                 $itemsCat = $db->loadObjectList();
                 if (!empty($itemsCat)) {
                     foreach ($itemsCat as $keyIT2 => $valueIT2) {
                         $query = 'SELECT m.params FROM #__menu AS m WHERE m.id = ' . (int) $valueIT2->id;
                         $db->setQuery($query);
                         $paramsCtJSON = $db->loadResult();
                         //$paramsCtJSON = $valueIT2->params;
                         $paramsMct = new JParameter();
                         $paramsMct->loadJSON($paramsCtJSON);
                         foreach ($paramsThemes as $keyT => $valueT) {
                             $paramsMct->setValue($valueT['name'], $valueT['value']);
                         }
                         $dataMct['params'] = $paramsMct->toArray();
                         $table =& JTable::getInstance('menu');
                         if (!$table->load((int) $valueIT2->id)) {
                             JError::raiseWarning(500, 'Not a valid table');
                             return false;
                         }
                         if (!$table->bind($dataMct)) {
                             JError::raiseWarning(500, 'Not a valid table');
                             return false;
                         }
                         // pre-save checks
                         if (!$table->check()) {
                             JError::raiseWarning(500, $table->getError('Check Problem'));
                             return false;
                         }
                         // save the changes
                         if (!$table->store()) {
                             JError::raiseWarning(500, $table->getError('Store Problem'));
                             return false;
                         }
                     }
                 }
             }
         }
     }
     return true;
 }