コード例 #1
0
ファイル: edit.php プロジェクト: ron4mac/joomla_com_usernotes
 public function __construct($config = array())
 {
     $udbPath = UserNotesHelper::userDataPath() . '/usernotes.db3';
     $db = JDatabaseDriver::getInstance(array('driver' => 'sqlite', 'database' => $udbPath));
     $config['dbo'] = $db;
     parent::__construct($config);
 }
コード例 #2
0
 /**
  * Method to get the field options.
  *
  * @return   array    The field option objects.
  * @since    1.0
  */
 public function getOptions()
 {
     $params = JComponentHelper::getParams('com_sichtweiten');
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $db = JDatabaseDriver::getInstance($option);
     } else {
         $db = JFactory::getDbo();
     }
     $query = $db->getQuery(true);
     $query->select('a.id AS value');
     $query->from('#__sicht_sichtweite AS a');
     $query->order('a.id ASC');
     // Get the options.
     $db->setQuery($query);
     $options = $db->loadObjectList();
     foreach ($options as $option) {
         $option->text = JText::_('COM_SICHTWEITEN_SICHTWEITE_VALUE_' . $option->value);
         $option->class = 'tiefe sichtweite' . $option->value;
     }
     return $options;
 }
コード例 #3
0
ファイル: driver.php プロジェクト: javigomez/neno
 /**
  * {@inheritdoc}
  *
  * @param   array $options Configuration options
  *
  * @return JDatabaseDriver
  *
  * @since 1.0
  */
 public static function getInstance($options = array())
 {
     $options['driver'] = isset($options['driver']) ? preg_replace('/[^A-Z0-9_\\.-]/i', '', $options['driver']) : 'mysqli';
     $options['database'] = isset($options['database']) ? $options['database'] : null;
     $options['select'] = isset($options['select']) ? $options['select'] : true;
     // Get an option hash to identify the instance
     $driverSignature = md5(serialize($options));
     // Check if the driver has been already instantiated
     if (empty(self::$instances[$driverSignature])) {
         // If the class doesn't exists, we cannot work with this driver.
         if (!self::isMySQL($options['driver'])) {
             // Let's using parent method
             return parent::getInstance($options);
         }
         // Let's create our driver instance using the options given.s
         try {
             /* @var $instance NenoDatabaseDriverMysqlx */
             $instance = new NenoDatabaseDriverMysqlx($options);
             $instance->refreshTranslatableTables();
         } catch (RuntimeException $ex) {
             throw new RuntimeException(sprintf('Unable to connect to the database. Error: %s', $ex->getMessage()));
         }
         // Save the instance into the instances set.
         self::$instances[$driverSignature] = $instance;
         // Load the tables configured to be translatable
         $instance->refreshTranslatableTables();
     }
     return self::$instances[$driverSignature];
 }
コード例 #4
0
ファイル: db.php プロジェクト: ron4mac/joomla_com_usernotes
 public static function convertDb($udbPath)
 {
     if (!file_exists($udbPath)) {
         return;
     }
     $attsDir = $udbPath . '/attach/';
     $db = JDatabaseDriver::getInstance(array('driver' => 'sqlite', 'database' => $udbPath . '/usernotes.db3'));
     $tbls = $db->getTableList();
     if (in_array('fileatt', $tbls)) {
         return;
     }
     // convert 'attached' table to 'fileatt' table with file sizes
     $db->setQuery('CREATE TABLE IF NOT EXISTS fileatt (contentID INTEGER NOT NULL, fsize INTEGER, attached TEXT)');
     $db->execute();
     $olds = $db->setQuery('SELECT * FROM attach')->loadAssocList();
     foreach ($olds as $old) {
         $atts = unserialize($old['attached']);
         foreach ($atts as $att) {
             $atfp = $old['contentID'] . '/' . $att;
             $atsz = file_exists($attsDir . $atfp) ? filesize($attsDir . $atfp) : 9999999999.0;
             $db->setQuery('INSERT INTO fileatt (contentID, fsize, attached) VALUES (' . $old['contentID'] . ', ' . $atsz . ', ' . $db->quote($att) . ')');
             //var_dump((string)$db);jexit();
             $db->execute();
         }
     }
     // remove the old 'attached table'
     //$db->setQuery('DROP TABLE IF EXISTS attach')->execute();
     // create view to sum the file sizes
     $db->setQuery('CREATE VIEW attsizsum AS SELECT SUM(fsize) AS totatt FROM fileatt');
     $db->execute();
     // add `secured` column to `notes`
     $db->setQuery('ALTER TABLE notes ADD COLUMN secured BOOLEAN DEFAULT NULL');
     $db->execute();
 }
コード例 #5
0
ファイル: web.php プロジェクト: realityking/jd12dk
 private function setUpDb()
 {
     $dbo = JDatabaseDriver::getInstance(array('driver' => 'sqlite', 'database' => '/Users/rouven/Sites/jd12dk/guestbook.sqlite'));
     $dbo->setQuery('CREATE TABLE IF NOT EXISTS Comments (Id INTEGER PRIMARY KEY, Name TEXT, Email TEXT, Comment Text, Ip INTEGER, date TEXT)');
     $dbo->execute();
     // Inject database into JFactory
     JFactory::$database = $dbo;
 }
コード例 #6
0
ファイル: database.php プロジェクト: educakanchay/kanchay
 /**
  * Method to get a JDatabaseDriver object.
  *
  * @param   string   $driver    The database driver to use.
  * @param   string   $host      The hostname to connect on.
  * @param   string   $user      The user name to connect with.
  * @param   string   $password  The password to use for connection authentication.
  * @param   string   $database  The database to use.
  * @param   string   $prefix    The table prefix to use.
  * @param   boolean  $select    True if the database should be selected.
  *
  * @return  JDatabaseDriver
  *
  * @since   1.6
  */
 public static function getDBO($driver, $host, $user, $password, $database, $prefix, $select = true)
 {
     static $db;
     if (!$db) {
         // Build the connection options array.
         $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix, 'select' => $select);
         // Get a database object.
         $db = JDatabaseDriver::getInstance($options);
     }
     return $db;
 }
コード例 #7
0
	/**
	 * Sets up the fixture, for example, opens a network connection.
	 * This method is called before a test is executed.
	 *
	 * @return void
	 */
	protected function setUp()
	{

		$this->db = JDatabaseDriver::getInstance(
			array(
				'driver' => 'nosql',
				'database' => 'europa',
				'prefix' => '&',
			)
		);
	}
コード例 #8
0
ファイル: oracle.php プロジェクト: rvsjoen/joomla-platform
 /**
  * This method is called before the first test of this test class is run.
  *
  * An example DSN would be: dbname=//localhost:1521/joomla_ut;charset=AL32UTF8;user=utuser;pass=ut1234
  *
  * @return  void
  *
  * @since   12.1
  */
 public static function setUpBeforeClass()
 {
     // First let's look to see if we have a DSN defined or in the environment variables.
     if (defined('JTEST_DATABASE_ORACLE_DSN') || getenv('JTEST_DATABASE_ORACLE_DSN')) {
         $dsn = defined('JTEST_DATABASE_ORACLE_DSN') ? JTEST_DATABASE_ORACLE_DSN : getenv('JTEST_DATABASE_ORACLE_DSN');
     } else {
         return;
     }
     // First let's trim the oci: part off the front of the DSN if it exists.
     if (strpos($dsn, 'oci:') === 0) {
         $dsn = substr($dsn, 4);
     }
     // Split the DSN into its parts over semicolons.
     $parts = explode(';', $dsn);
     // Parse each part and populate the options array.
     foreach ($parts as $part) {
         list($k, $v) = explode('=', $part, 2);
         switch ($k) {
             case 'charset':
                 self::$_options['charset'] = $v;
                 break;
             case 'dbname':
                 $components = parse_url($v);
                 self::$_options['host'] = $components['host'];
                 self::$_options['port'] = $components['port'];
                 self::$_options['database'] = $components['path'];
                 break;
             case 'user':
                 self::$_options['user'] = $v;
                 break;
             case 'pass':
                 self::$_options['password'] = $v;
                 break;
         }
     }
     // Ensure some defaults.
     self::$_options['charset'] = isset(self::$_options['charset']) ? self::$_options['charset'] : 'AL32UTF8';
     self::$_options['port'] = isset(self::$_options['port']) ? self::$_options['port'] : 1521;
     try {
         // Attempt to instantiate the driver.
         self::$driver = JDatabaseDriver::getInstance(self::$_options);
     } catch (RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof Exception) {
         self::$driver = null;
     }
     // Setup the factory pointer for the driver and stash the old one.
     self::$_stash = JFactory::$database;
     JFactory::$database = self::$driver;
 }
コード例 #9
0
ファイル: cli.php プロジェクト: yatan/JiGS-PHP-RPG-engine
 /**
  * Allows the application to load a custom or default database driver.
  *
  * @param   JDatabaseDriver  $driver  An optional database driver object. If omitted, the application driver is created.
  *
  * @return  JApplicationBase This method is chainable.
  *
  * @since   12.1
  */
 public function loadDatabase(JDatabaseDriver $driver = null)
 {
     if ($driver === null) {
         $this->db = JDatabaseDriver::getInstance(array('driver' => $this->get('db_driver'), 'host' => $this->get('db_host'), 'user' => $this->get('db_user'), 'password' => $this->get('db_pass'), 'database' => $this->get('db_name'), 'prefix' => $this->get('db_prefix')));
         // Select the database.
         $this->db->select($this->get('db_name'));
     } else {
         $this->db = $driver;
     }
     // Set the database to our static cache.
     JFactory::$database = $this->db;
     return $this;
 }
コード例 #10
0
ファイル: mysql.php プロジェクト: SysBind/joomla-cms
 /**
  * This method is called before the first test of this test class is run.
  *
  * An example DSN would be: host=localhost;dbname=joomla_ut;user=utuser;pass=ut1234
  *
  * @return  void
  *
  * @since   12.1
  */
 public static function setUpBeforeClass()
 {
     if (PHP_MAJOR_VERSION >= 7) {
         self::markTestSkipped('ext/mysql is unsupported on PHP 7.');
     }
     // First let's look to see if we have a DSN defined or in the environment variables.
     if (defined('JTEST_DATABASE_MYSQL_DSN') || getenv('JTEST_DATABASE_MYSQL_DSN')) {
         $dsn = defined('JTEST_DATABASE_MYSQL_DSN') ? JTEST_DATABASE_MYSQL_DSN : getenv('JTEST_DATABASE_MYSQL_DSN');
     } else {
         return;
     }
     // First let's trim the mysql: part off the front of the DSN if it exists.
     if (strpos($dsn, 'mysql:') === 0) {
         $dsn = substr($dsn, 6);
     }
     // Split the DSN into its parts over semicolons.
     $parts = explode(';', $dsn);
     // Parse each part and populate the options array.
     foreach ($parts as $part) {
         list($k, $v) = explode('=', $part, 2);
         switch ($k) {
             case 'host':
                 self::$_options['host'] = $v;
                 break;
             case 'dbname':
                 self::$_options['database'] = $v;
                 break;
             case 'user':
                 self::$_options['user'] = $v;
                 break;
             case 'pass':
                 self::$_options['password'] = $v;
                 break;
         }
     }
     try {
         // Attempt to instantiate the driver.
         self::$driver = JDatabaseDriver::getInstance(self::$_options);
     } catch (RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof Exception) {
         self::$driver = null;
     }
     // Setup the factory pointer for the driver and stash the old one.
     self::$_stash = JFactory::$database;
     JFactory::$database = self::$driver;
 }
コード例 #11
0
ファイル: baseTest.php プロジェクト: prox91/joomla-dev
 /**
  * Prepares the environment before running a test.
  *
  * @return  void
  *
  * @since   1.0
  *
  */
 protected function setUp()
 {
     parent::setUp();
     $this->saveFactoryState();
     JFactory::$session = $this->getMockSession();
     JFactory::$application = MockWebServiceApplicationWeb::create($this);
     $options = array('driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'ws_');
     $driver = JDatabaseDriver::getInstance($options);
     $pdo = new PDO('sqlite::memory:');
     $pdo->exec(file_get_contents(JPATH_TESTS . '/schema/ws.sql')) or die(print_r($pdo->errorInfo()));
     TestReflection::setValue($driver, 'connection', $pdo);
     JFactory::$database = $driver;
     $this->_instance = new WebServiceModelBase(new JContentFactory(), $driver);
     $this->_state = TestReflection::invoke($this->_instance, 'getState');
 }
コード例 #12
0
 /**
  * Constructor.
  *
  * @param   array $config An optional associative array of configuration settings.
  *
  * @see     JModelLegacy
  * @since   1.0
  */
 public function __construct($config = array())
 {
     $params = JComponentHelper::getParams('com_sichtweiten');
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $config['dbo'] = JDatabaseDriver::getInstance($option);
     }
     parent::__construct($config);
 }
コード例 #13
0
 public function __construct($config = array())
 {
     $this->_storPath = UserNotesHelper::userDataPath();
     $udbPath = $this->_storPath . '/usernotes.db3';
     $doInit = !file_exists($udbPath);
     $option = array('driver' => 'sqlite', 'database' => $udbPath);
     $db = JDatabaseDriver::getInstance($option);
     $db->connect();
     $db->getConnection()->sqliteCreateFunction('b64d', 'base64_decode', 1);
     if ($doInit) {
         require_once JPATH_COMPONENT . '/helpers/db.php';
         UserNotesHelperDb::buildDb($db);
     }
     $config['dbo'] = $db;
     parent::__construct($config);
 }
コード例 #14
0
ファイル: Database.php プロジェクト: Rai-Ka/joomla-cms
 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   4.0
  */
 public function register(Container $container)
 {
     $container->alias('db', 'JDatabaseDriver')->alias('Joomla\\Database\\DatabaseInterface', 'JDatabaseDriver')->share('JDatabaseDriver', function (Container $container) {
         $conf = \JFactory::getConfig();
         $options = array('driver' => $conf->get('dbtype'), 'host' => $conf->get('host'), 'user' => $conf->get('user'), 'password' => $conf->get('password'), 'database' => $conf->get('db'), 'prefix' => $conf->get('dbprefix'));
         try {
             $db = \JDatabaseDriver::getInstance($options);
         } catch (\RuntimeException $e) {
             if (!headers_sent()) {
                 header('HTTP/1.1 500 Internal Server Error');
             }
             jexit('Database Error: ' . $e->getMessage());
         }
         $db->setDebug((bool) $conf->get('debug', false));
         return $db;
     }, true);
 }
コード例 #15
0
ファイル: locations.php プロジェクト: Bakual/Sichtweiten
 /**
  * Constructor.
  *
  * @param   array $config An optional associative array of configuration settings.
  *
  * @see     JModelLegacy
  * @since   1.0
  */
 public function __construct($config = array())
 {
     $this->filter_fields = array('tp.name', 'tp.bemerkungen', 'g.displayName');
     $params = JFactory::getApplication()->getParams();
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $config['dbo'] = JDatabaseDriver::getInstance($option);
     }
     parent::__construct($config);
 }
コード例 #16
0
 /**
  * This method is called before the first test of this test class is run.
  *
  * An example DSN would be: host=localhost;port=5432;dbname=joomla_ut;user=utuser;pass=ut1234
  *
  * @return  void
  *
  * @since   12.1
  */
 public static function setUpBeforeClass()
 {
     // First let's look to see if we have a DSN defined or in the environment variables.
     if (!defined('JTEST_DATABASE_SQLSRV_DSN') && !getenv('JTEST_DATABASE_SQLSRV_DSN')) {
         static::markTestSkipped('The SQL Server driver is not configured.');
     }
     $dsn = defined('JTEST_DATABASE_SQLSRV_DSN') ? JTEST_DATABASE_SQLSRV_DSN : getenv('JTEST_DATABASE_SQLSRV_DSN');
     // First let's trim the sqlsrv: part off the front of the DSN if it exists.
     if (strpos($dsn, 'sqlsrv:') === 0) {
         $dsn = substr($dsn, 7);
     }
     // Split the DSN into its parts over semicolons.
     $parts = explode(';', $dsn);
     // Parse each part and populate the options array.
     foreach ($parts as $part) {
         list($k, $v) = explode('=', $part, 2);
         switch ($k) {
             case 'host':
                 self::$options['host'] = $v;
                 break;
             case 'dbname':
                 self::$options['database'] = $v;
                 break;
             case 'user':
                 self::$options['user'] = $v;
                 break;
             case 'pass':
                 self::$options['password'] = $v;
                 break;
         }
     }
     try {
         // Attempt to instantiate the driver.
         static::$driver = JDatabaseDriver::getInstance(self::$options);
     } catch (RuntimeException $e) {
         static::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (static::$driver instanceof Exception) {
         static::$driver = null;
     }
     // Setup the factory pointer for the driver and stash the old one.
     self::$stash = JFactory::$database;
     JFactory::$database = static::$driver;
 }
コード例 #17
0
ファイル: locationlist.php プロジェクト: Bakual/Sichtweiten
 /**
  * Method to get the field options.
  *
  * @return   array    The field option objects.
  * @since    1.0
  */
 public function getGroups()
 {
     $params = JComponentHelper::getParams('com_sichtweiten');
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $db = JDatabaseDriver::getInstance($option);
     } else {
         $db = JFactory::getDbo();
     }
     $query = $db->getQuery(true);
     $query->select('a.id AS value');
     $query->select("CONCAT(a.name, ', ', c.name) AS text");
     $query->from('#__sicht_tauchplatz AS a');
     $query->select('b.displayName');
     $query->join('LEFT', '#__sicht_gewaesser AS b ON a.gewaesser_id = b.id');
     $query->order('b.displayName ASC, a.name ASC');
     $query->join('LEFT', '#__sicht_ort AS c ON a.ort_id = c.id');
     // Get the options.
     $db->setQuery($query);
     $options = $db->loadObjectList();
     $groups = array();
     $default = new stdClass();
     $default->value = '';
     $default->text = JText::_('COM_SICHTWEITEN_OPTION_SELECT_LOCATION');
     $default->displayName = '';
     array_unshift($options, $default);
     foreach ($options as $option) {
         if (!isset($groups[$option->displayName])) {
             $groups[$option->displayName] = array();
         }
         $groups[$option->displayName][] = $option;
     }
     return $groups;
 }
コード例 #18
0
 /**
  * Constructor.
  *
  * @param  array $config An optional associative array of configuration settings.
  *
  * @see    JController
  * @since  1.0
  */
 public function __construct($config = array())
 {
     if (empty($config['filter_fields'])) {
         // Filter Fields define valid ordering fields.
         $config['filter_fields'] = array('swm.id', 'swm.datum', 'swm.meldedatum', 'swm.user', 'tp.name');
         // Parent::getActiveFilters uses them for SearchTools. Has to match filter name (eg "foo" for "filters.foo")
         $config['filter_fields'][] = 'tauchplatz';
     }
     $params = JComponentHelper::getParams('com_sichtweiten');
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $config['dbo'] = JDatabaseDriver::getInstance($option);
     }
     parent::__construct($config);
 }
コード例 #19
0
ファイル: database.php プロジェクト: n3t/joomla-platform
 /**
  * This method is called before the first test of this test class is run.
  *
  * @return  void
  *
  * @since   12.1
  */
 public static function setUpBeforeClass()
 {
     // We always want the default database test case to use an SQLite memory database.
     $options = array('driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'jos_');
     try {
         // Attempt to instantiate the driver.
         self::$driver = JDatabaseDriver::getInstance($options);
         // Create a new PDO instance for an SQLite memory database and load the test schema into it.
         $pdo = new PDO('sqlite::memory:');
         $pdo->exec(file_get_contents(JPATH_TESTS . '/schema/ddl.sql'));
         // Set the PDO instance to the driver using reflection whizbangery.
         TestReflection::setValue(self::$driver, 'connection', $pdo);
     } catch (RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof Exception) {
         self::$driver = null;
     }
     // Setup the factory pointer for the driver and stash the old one.
     self::$_stash = JFactory::$database;
     JFactory::$database = self::$driver;
 }
コード例 #20
0
ファイル: tools.php プロジェクト: Bakual/Sichtweiten
 /**
  * Migrates data from extern database
  *
  * @throws Exception
  *
  * @since 1.2.0
  */
 public function migrate()
 {
     // Check for request forgeries
     JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_sichtweiten');
     if (!$params->get('extern_db')) {
         $app->enqueueMessage('Extern DB not enabled!');
         $app->redirect('index.php?option=com_sichtweiten&view=main');
         return;
     }
     $db = JFactory::getDbo();
     // Taken from https://docs.joomla.org/Connecting_to_an_external_database
     $option = array();
     $option['driver'] = $params->get('db_type', 'mysqli');
     $option['host'] = $params->get('db_host', 'localhost');
     $option['database'] = $params->get('db_database');
     $option['user'] = $params->get('db_user');
     $option['password'] = $params->get('db_pass');
     $option['prefix'] = $params->get('db_prefix', 'jos_');
     $dbExtern = JDatabaseDriver::getInstance($option);
     $tables = array('#__sicht_adresse', '#__sicht_bezeichnung', '#__sicht_gewaesser', '#__sicht_land', '#__sicht_ort', '#__sicht_sichtweite', '#__sicht_sichtweiteneintrag', '#__sicht_sichtweitenmeldung', '#__sicht_tauchpartner', '#__sicht_tauchplatz', '#__sicht_tiefenbereich', '#__sicht_user');
     $query = $dbExtern->getQuery(true);
     $query->select('*');
     foreach ($tables as $table) {
         $query->clear('from');
         $query->from($table);
         $dbExtern->setQuery($query);
         $list = $dbExtern->loadObjectList();
         foreach ($list as $tupel) {
             $db->insertObject($table, $tupel);
         }
     }
     $app->enqueueMessage('Data migrated!');
     $app->redirect('index.php?option=com_sichtweiten&view=main');
     return;
 }
コード例 #21
0
ファイル: userlist.php プロジェクト: Bakual/Sichtweiten
 /**
  * Method to get the field options.
  *
  * @return   array    The field option objects.
  * @since    1.0
  */
 public function getOptions()
 {
     $params = JComponentHelper::getParams('com_sichtweiten');
     if ($params->get('extern_db')) {
         // Taken from https://docs.joomla.org/Connecting_to_an_external_database
         $option = array();
         $option['driver'] = $params->get('db_type', 'mysqli');
         $option['host'] = $params->get('db_host', 'localhost');
         $option['database'] = $params->get('db_database');
         $option['user'] = $params->get('db_user');
         $option['password'] = $params->get('db_pass');
         $option['prefix'] = $params->get('db_prefix', 'jos_');
         $db = JDatabaseDriver::getInstance($option);
     } else {
         $db = JFactory::getDbo();
     }
     $query = $db->getQuery(true);
     $query->select('id AS value');
     $query->select('name AS text');
     $query->from('#__sicht_user');
     // Get the options.
     $db->setQuery($query);
     return $db->loadObjectList();
 }
コード例 #22
0
ファイル: factory.php プロジェクト: renzhewk/joomla-platform
 /**
  * Create an database object
  *
  * @return  JDatabaseDriver
  *
  * @see     JDatabaseDriver
  * @since   11.1
  */
 protected static function createDbo()
 {
     $conf = self::getConfig();
     $host = $conf->get('host');
     $user = $conf->get('user');
     $password = $conf->get('password');
     $database = $conf->get('db');
     $prefix = $conf->get('dbprefix');
     $driver = $conf->get('dbtype');
     $debug = $conf->get('debug');
     $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
     $db = JDatabaseDriver::getInstance($options);
     if ($db instanceof Exception) {
         if (!headers_sent()) {
             header('HTTP/1.1 500 Internal Server Error');
         }
         jexit('Database Error: ' . (string) $db);
     }
     if ($db->getErrorNum() > 0) {
         die(sprintf('Database connection error (%d): %s', $db->getErrorNum(), $db->getErrorMsg()));
     }
     $db->setDebug($debug);
     return $db;
 }
コード例 #23
0
ファイル: database.php プロジェクト: GitIPFire/Homeworks
	/**
	 * Method to return a JDatabaseDriver instance based on the given options.  There are three global options and then
	 * the rest are specific to the database driver.  The 'driver' option defines which JDatabaseDriver class is
	 * used for the connection -- the default is 'mysqli'.  The 'database' option determines which database is to
	 * be used for the connection.  The 'select' option determines whether the connector should automatically select
	 * the chosen database.
	 *
	 * Instances are unique to the given options and new objects are only created when a unique options array is
	 * passed into the method.  This ensures that we don't end up with unnecessary database connection resources.
	 *
	 * @param   array  $options  Parameters to be passed to the database driver.
	 *
	 * @return  JDatabaseDriver  A database object.
	 *
	 * @since       11.1
	 * @deprecated  13.1
	 */
	public static function getInstance($options = array())
	{
		JLog::add('JDatabase::getInstance() is deprecated, use JDatabaseDriver::getInstance() instead.', JLog::WARNING, 'deprecated');

		return JDatabaseDriver::getInstance($options);
	}
コード例 #24
0
    if ($ci->CiId == $infoUsuario->ciudad) {
        $departamentoActual = $ci->CiDepartamento;
    }
}
//Obtener Detalle Puntos
$db4 = JDatabaseDriver::getInstance(SMBrujula::getConexion());
$query4 = $db4->getQuery(true);
$query4->select($db4->quoteName(array('idtipopuntos', 'cantidadpuntos')));
$query4->from($db4->quoteName('mkPuntos'));
$query4->where($db4->quoteName('documentopuntos') . ' = ' . $db->quote($infoUsuario->documento));
$db4->setQuery($query4);
$puntos = $db4->loadObjectList();
$ptsPositivos = array();
$ptsNegativos = array();
foreach ($puntos as $pt) {
    $db5 = JDatabaseDriver::getInstance(SMBrujula::getConexion());
    $query5 = $db5->getQuery(true);
    $query5->select($db5->quoteName(array('nombretipopuntos')));
    $query5->from($db5->quoteName('mkTipoPuntos'));
    $query5->where($db5->quoteName('idtipopuntos') . ' = ' . $db->quote($pt->idtipopuntos));
    $db5->setQuery($query5);
    $pt->nombretipopuntos = $db5->loadResult();
    if ((int) $pt->cantidadpuntos > 0) {
        array_push($ptsPositivos, $pt);
    } else {
        array_push($ptsNegativos, $pt);
    }
}
$cc = $session->get('cedula');
// Get a db connection.
$db = JFactory::getDbo();
コード例 #25
0
ファイル: application.php プロジェクト: grlf/eyedock
 /**
  * Method to save the configuration data.
  *
  * @param   array  $data  An array containing all global config data.
  *
  * @return	boolean  True on success, false on failure.
  *
  * @since	1.6
  */
 public function save($data)
 {
     $app = JFactory::getApplication();
     // Check that we aren't setting wrong database configuration
     $options = array('driver' => $data['dbtype'], 'host' => $data['host'], 'user' => $data['user'], 'password' => JFactory::getConfig()->get('password'), 'database' => $data['db'], 'prefix' => $data['dbprefix']);
     try {
         $dbc = JDatabaseDriver::getInstance($options)->getVersion();
     } catch (Exception $e) {
         $app->enqueueMessage(JText::_('JLIB_DATABASE_ERROR_DATABASE_CONNECT'), 'error');
         return false;
     }
     // Save the rules
     if (isset($data['rules'])) {
         $rules = new JAccessRules($data['rules']);
         // Check that we aren't removing our Super User permission
         // Need to get groups from database, since they might have changed
         $myGroups = JAccess::getGroupsByUser(JFactory::getUser()->get('id'));
         $myRules = $rules->getData();
         $hasSuperAdmin = $myRules['core.admin']->allow($myGroups);
         if (!$hasSuperAdmin) {
             $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_REMOVING_SUPER_ADMIN'), 'error');
             return false;
         }
         $asset = JTable::getInstance('asset');
         if ($asset->loadByName('root.1')) {
             $asset->rules = (string) $rules;
             if (!$asset->check() || !$asset->store()) {
                 $app->enqueueMessage(JText::_('SOME_ERROR_CODE'), 'error');
                 return;
             }
         } else {
             $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND'), 'error');
             return false;
         }
         unset($data['rules']);
     }
     // Save the text filters
     if (isset($data['filters'])) {
         $registry = new Registry();
         $registry->loadArray(array('filters' => $data['filters']));
         $extension = JTable::getInstance('extension');
         // Get extension_id
         $extension_id = $extension->find(array('name' => 'com_config'));
         if ($extension->load((int) $extension_id)) {
             $extension->params = (string) $registry;
             if (!$extension->check() || !$extension->store()) {
                 $app->enqueueMessage(JText::_('SOME_ERROR_CODE'), 'error');
                 return;
             }
         } else {
             $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIG_EXTENSION_NOT_FOUND'), 'error');
             return false;
         }
         unset($data['filters']);
     }
     // Get the previous configuration.
     $prev = new JConfig();
     $prev = JArrayHelper::fromObject($prev);
     // Merge the new data in. We do this to preserve values that were not in the form.
     $data = array_merge($prev, $data);
     /*
      * Perform miscellaneous options based on configuration settings/changes.
      */
     // Escape the offline message if present.
     if (isset($data['offline_message'])) {
         $data['offline_message'] = JFilterOutput::ampReplace($data['offline_message']);
     }
     // Purge the database session table if we are changing to the database handler.
     if ($prev['session_handler'] != 'database' && $data['session_handler'] == 'database') {
         $table = JTable::getInstance('session');
         $table->purge(-1);
     }
     if (empty($data['cache_handler'])) {
         $data['caching'] = 0;
     }
     $path = JPATH_SITE . '/cache';
     // Give a warning if the cache-folder can not be opened
     if ($data['caching'] > 0 && $data['cache_handler'] == 'file' && @opendir($path) == false) {
         JLog::add(JText::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), JLog::WARNING, 'jerror');
         $data['caching'] = 0;
     }
     // Clean the cache if disabled but previously enabled.
     if (!$data['caching'] && $prev['caching']) {
         $cache = JFactory::getCache();
         $cache->clean();
     }
     // Create the new configuration object.
     $config = new Registry('config');
     $config->loadArray($data);
     // Overwrite the old FTP credentials with the new ones.
     $temp = JFactory::getConfig();
     $temp->set('ftp_enable', $data['ftp_enable']);
     $temp->set('ftp_host', $data['ftp_host']);
     $temp->set('ftp_port', $data['ftp_port']);
     $temp->set('ftp_user', $data['ftp_user']);
     $temp->set('ftp_pass', $data['ftp_pass']);
     $temp->set('ftp_root', $data['ftp_root']);
     // Clear cache of com_config component.
     $this->cleanCache('_system', 0);
     $this->cleanCache('_system', 1);
     // Write the configuration file.
     return $this->writeConfigFile($config);
 }
コード例 #26
0
ファイル: database.php プロジェクト: klas/joomla-cms
 /**
  * Method to create a new database.
  *
  * @param   array  $options  The configuration options
  *
  * @return    boolean    True on success.
  *
  * @since    3.1
  */
 public function createDatabase($options)
 {
     // Get the application.
     /* @var InstallationApplicationWeb $app */
     $app = JFactory::getApplication();
     // Disable autoselect database before it's created.
     $tmpSelect = true;
     if (isset($options['db_select'])) {
         $tmpSelect = $options['db_select'];
     }
     $options['db_select'] = false;
     if (!($db = $this->initialise($options))) {
         return false;
     }
     // Get the options as a object for easier handling.
     $options = JArrayHelper::toObject($options);
     // Check database version.
     $type = $options->db_type;
     try {
         $db_version = $db->getVersion();
     } catch (RuntimeException $e) {
         /*
          * We may get here if the database doesn't exist, if so then explain that to users instead of showing the database connector's error
          * This only supports PostgreSQL and the PDO MySQL drivers presently
          *
          * Error Messages:
          * PDO MySQL: [1049] Unknown database 'database_name'
          * PostgreSQL: Error connecting to PGSQL database
          */
         if ($type == 'pdomysql' && strpos($e->getMessage(), '[1049] Unknown database') === 42) {
             /*
              * Now we're really getting insane here; we're going to try building a new JDatabaseDriver instance without the database name
              * in order to trick the connection into creating the database
              */
             $altDBoptions = array('driver' => $options->db_type, 'host' => $options->db_host, 'user' => $options->db_user, 'password' => $options->db_pass, 'prefix' => $options->db_prefix, 'select' => $options->db_select);
             $altDB = JDatabaseDriver::getInstance($altDBoptions);
             // Try to create the database now using the alternate driver
             try {
                 $this->createDb($altDB, $options, $altDB->hasUTFSupport());
             } catch (RuntimeException $e) {
                 // We did everything we could
                 $app->enqueueMessage(JText::_('INSTL_DATABASE_COULD_NOT_CREATE_DATABASE'), 'notice');
                 return false;
             }
             // If we got here, the database should have been successfully created, now try one more time to get the version
             try {
                 $db_version = $db->getVersion();
             } catch (RuntimeException $e) {
                 // We did everything we could
                 $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_COULD_NOT_CONNECT', $e->getMessage()), 'notice');
                 return false;
             }
         } elseif ($type == 'postgresql' && strpos($e->getMessage(), 'Error connecting to PGSQL database') === 42) {
             $app->enqueueMessage(JText::_('INSTL_DATABASE_COULD_NOT_CREATE_DATABASE'), 'notice');
             return false;
         } else {
             $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_COULD_NOT_CONNECT', $e->getMessage()), 'notice');
             return false;
         }
     }
     if (!$db->isMinimumVersion()) {
         $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_INVALID_' . strtoupper($type) . '_VERSION', $db_version), 'notice');
         return false;
     }
     if ($type == 'mysql' || $type == 'mysqli' || $type == 'pdomysql') {
         // @internal MySQL versions pre 5.1.6 forbid . / or \ or NULL.
         if (preg_match('#[\\\\/\\.\\0]#', $options->db_name) && !version_compare($db_version, '5.1.6', '>=')) {
             $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_INVALID_NAME', $db_version), 'notice');
             return false;
         }
     }
     // @internal Check for spaces in beginning or end of name.
     if (strlen(trim($options->db_name)) != strlen($options->db_name)) {
         $app->enqueueMessage(JText::_('INSTL_DATABASE_NAME_INVALID_SPACES'), 'notice');
         return false;
     }
     // @internal Check for asc(00) Null in name.
     if (strpos($options->db_name, chr(00)) !== false) {
         $app->enqueueMessage(JText::_('INSTL_DATABASE_NAME_INVALID_CHAR'), 'notice');
         return false;
     }
     // PostgreSQL database older than version 9.0.0 needs to run 'CREATE LANGUAGE' to create function.
     if ($options->db_type == 'postgresql' && !version_compare($db_version, '9.0.0', '>=')) {
         $db->setQuery("select lanpltrusted from pg_language where lanname='plpgsql'");
         try {
             $db->execute();
         } catch (RuntimeException $e) {
             $app->enqueueMessage(JText::_('JLIB_DATABASE_ERROR_DATABASE_QUERY'), 'notice');
             return false;
         }
         $column = $db->loadResult();
         if ($column != 't') {
             $db->setQuery("CREATE LANGUAGE plpgsql");
             try {
                 $db->execute();
             } catch (RuntimeException $e) {
                 $app->enqueueMessage(JText::_('JLIB_DATABASE_ERROR_DATABASE_QUERY'), 'notice');
                 return false;
             }
         }
     }
     // Get database's UTF support.
     $utfSupport = $db->hasUTFSupport();
     // Try to select the database.
     try {
         $db->select($options->db_name);
     } catch (RuntimeException $e) {
         // If the database could not be selected, attempt to create it and then select it.
         if ($this->createDb($db, $options, $utfSupport)) {
             $db->select($options->db_name);
         } else {
             $app->enqueueMessage(JText::sprintf('INSTL_DATABASE_ERROR_CREATE', $options->db_name), 'notice');
             return false;
         }
     }
     $options = (array) $options;
     // Remove *_errors value.
     foreach ($options as $i => $option) {
         if (isset($i['1']) && $i['1'] == '*') {
             unset($options[$i]);
             break;
         }
     }
     $options = array_merge(array('db_created' => 1), $options);
     // Restore autoselect value after database creation.
     $options['db_select'] = $tmpSelect;
     $session = JFactory::getSession();
     $session->set('setup.options', $options);
     return true;
 }
コード例 #27
0
ファイル: application.php プロジェクト: N6REJ/joomla-cms
 /**
  * Method to save the configuration data.
  *
  * @param   array  $data  An array containing all global config data.
  *
  * @return	boolean  True on success, false on failure.
  *
  * @since	1.6
  */
 public function save($data)
 {
     $app = JFactory::getApplication();
     // Check that we aren't setting wrong database configuration
     $options = array('driver' => $data['dbtype'], 'host' => $data['host'], 'user' => $data['user'], 'password' => JFactory::getConfig()->get('password'), 'database' => $data['db'], 'prefix' => $data['dbprefix']);
     try {
         $dbc = JDatabaseDriver::getInstance($options)->getVersion();
     } catch (Exception $e) {
         $app->enqueueMessage(JText::_('JLIB_DATABASE_ERROR_DATABASE_CONNECT'), 'error');
         return false;
     }
     // Check if we can set the Force SSL option
     if ((int) $data['force_ssl'] !== 0 && (int) $data['force_ssl'] !== (int) JFactory::getConfig()->get('force_ssl', '0')) {
         try {
             // Make an HTTPS request to check if the site is available in HTTPS.
             $host = JUri::getInstance()->getHost();
             $options = new \Joomla\Registry\Registry();
             $options->set('userAgent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0');
             $options->set('transport.curl', array(CURLOPT_SSL_VERIFYPEER => false));
             $response = JHttpFactory::getHttp($options)->get('https://' . $host . JUri::root(true) . '/', array('Host' => $host), 10);
             // If available in HTTPS check also the status code.
             if (!in_array($response->code, array(200, 503, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310), true)) {
                 throw new RuntimeException('HTTPS version of the site returned an invalid HTTP status code.');
             }
         } catch (RuntimeException $e) {
             $data['force_ssl'] = 0;
             // Also update the user state
             $app->setUserState('com_config.config.global.data.force_ssl', 0);
             // Inform the user
             $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_SSL_NOT_AVAILABLE'), 'warning');
         }
     }
     // Save the rules
     if (isset($data['rules'])) {
         $rules = new JAccessRules($data['rules']);
         // Check that we aren't removing our Super User permission
         // Need to get groups from database, since they might have changed
         $myGroups = JAccess::getGroupsByUser(JFactory::getUser()->get('id'));
         $myRules = $rules->getData();
         $hasSuperAdmin = $myRules['core.admin']->allow($myGroups);
         if (!$hasSuperAdmin) {
             $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_REMOVING_SUPER_ADMIN'), 'error');
             return false;
         }
         $asset = JTable::getInstance('asset');
         if ($asset->loadByName('root.1')) {
             $asset->rules = (string) $rules;
             if (!$asset->check() || !$asset->store()) {
                 $app->enqueueMessage(JText::_('SOME_ERROR_CODE'), 'error');
                 return;
             }
         } else {
             $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_ROOT_ASSET_NOT_FOUND'), 'error');
             return false;
         }
         unset($data['rules']);
     }
     // Save the text filters
     if (isset($data['filters'])) {
         $registry = new Registry();
         $registry->loadArray(array('filters' => $data['filters']));
         $extension = JTable::getInstance('extension');
         // Get extension_id
         $extension_id = $extension->find(array('name' => 'com_config'));
         if ($extension->load((int) $extension_id)) {
             $extension->params = (string) $registry;
             if (!$extension->check() || !$extension->store()) {
                 $app->enqueueMessage(JText::_('SOME_ERROR_CODE'), 'error');
                 return;
             }
         } else {
             $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIG_EXTENSION_NOT_FOUND'), 'error');
             return false;
         }
         unset($data['filters']);
     }
     // Get the previous configuration.
     $prev = new JConfig();
     $prev = JArrayHelper::fromObject($prev);
     // Merge the new data in. We do this to preserve values that were not in the form.
     $data = array_merge($prev, $data);
     /*
      * Perform miscellaneous options based on configuration settings/changes.
      */
     // Escape the offline message if present.
     if (isset($data['offline_message'])) {
         $data['offline_message'] = JFilterOutput::ampReplace($data['offline_message']);
     }
     // Purge the database session table if we are changing to the database handler.
     if ($prev['session_handler'] != 'database' && $data['session_handler'] == 'database') {
         $table = JTable::getInstance('session');
         $table->purge(-1);
     }
     if (empty($data['cache_handler'])) {
         $data['caching'] = 0;
     }
     $path = JPATH_SITE . '/cache';
     // Give a warning if the cache-folder can not be opened
     if ($data['caching'] > 0 && $data['cache_handler'] == 'file' && @opendir($path) == false) {
         JLog::add(JText::sprintf('COM_CONFIG_ERROR_CACHE_PATH_NOTWRITABLE', $path), JLog::WARNING, 'jerror');
         $data['caching'] = 0;
     }
     // Clean the cache if disabled but previously enabled.
     if (!$data['caching'] && $prev['caching']) {
         $cache = JFactory::getCache();
         $cache->clean();
     }
     // Create the new configuration object.
     $config = new Registry('config');
     $config->loadArray($data);
     // Overwrite the old FTP credentials with the new ones.
     $temp = JFactory::getConfig();
     $temp->set('ftp_enable', $data['ftp_enable']);
     $temp->set('ftp_host', $data['ftp_host']);
     $temp->set('ftp_port', $data['ftp_port']);
     $temp->set('ftp_user', $data['ftp_user']);
     $temp->set('ftp_pass', $data['ftp_pass']);
     $temp->set('ftp_root', $data['ftp_root']);
     // Clear cache of com_config component.
     $this->cleanCache('_system', 0);
     $this->cleanCache('_system', 1);
     // Write the configuration file.
     return $this->writeConfigFile($config);
 }
コード例 #28
0
ファイル: database.php プロジェクト: ziyou-liu/1line
 /**
  * Method to connect to the database server based on object properties.
  *
  * @return  void
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 protected function connect()
 {
     // Build the configuration object to use for JDatabaseDriver.
     $options = array('driver' => $this->driver, 'host' => $this->host, 'user' => $this->user, 'password' => $this->password, 'database' => $this->database, 'prefix' => $this->prefix);
     $db = JDatabaseDriver::getInstance($options);
     // Assign the database connector to the class.
     $this->db = $db;
 }
コード例 #29
0
 function onUserAfterDelete($user, $success, $msg)
 {
     //Load settings
     $option = array();
     $option['driver'] = $this->params->get('mysql-driver');
     $option['host'] = $this->params->get('mysql-host');
     $option['user'] = $this->params->get('mysql-user');
     $option['password'] = $this->params->get('mysql-pass');
     $option['database'] = $this->params->get('mysql-database');
     $option['dbprefix'] = $this->params->get('mysql-dbprefix');
     $option['lock'] = $this->params->get('wowlock');
     //Get Databasesession
     $db = JDatabaseDriver::getInstance($option);
     $query = $db->getQuery(true);
     if ($success) {
         //Lock or Delete WoW-Account?
         if ($option['lock'] == "lock") {
             $query->update($db->quoteName('account'))->set(array($db->quoteName('locked') . "='1'"))->where(array($db->quoteName('username') . '=' . "'" . $user['username'] . "'"));
         } elseif ($option['delete'] == "delete") {
             $query->delete($db->quoteName('account'))->where(array($db->quoteName('username') . '=' . "'" . $user['username'] . "'"));
         } else {
             //Plausi
             return;
         }
         $db->setQuery($query);
         $db->execute();
     }
 }
コード例 #30
0
ファイル: factory.php プロジェクト: houzhenggang/cobalt
 /**
  * Create an database object
  *
  * @return JDatabaseDriver
  *
  * @see     JDatabaseDriver
  * @since   11.1
  */
 protected static function createDbo()
 {
     $conf = self::getConfig();
     $host = $conf->get('host');
     $user = $conf->get('user');
     $password = $conf->get('password');
     $database = $conf->get('db');
     $prefix = $conf->get('dbprefix');
     $driver = $conf->get('dbtype');
     $debug = $conf->get('debug');
     $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
     try {
         $db = JDatabaseDriver::getInstance($options);
     } catch (RuntimeException $e) {
         if (!headers_sent()) {
             header('HTTP/1.1 500 Internal Server Error');
         }
         jexit('Database Error: ' . $e->getMessage());
     }
     $db->setDebug($debug);
     return $db;
 }