News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1284084905:v:use_geshi-1:v:type-php

Started by SleePy, Sep 10, 2010, 02:15 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SleePy

class smcFunc
{
   private static $site_connections = array();
   private static $site_prefixes = array();

   public static function __callStatic($name, $arugments)
   {
      global $smcFunc;
      return call_user_func_array($smcFunc[$name], $arugments);
   }

   // What prefix?
   public static function dbPrefix($section, $write = false)
   {
      if (!isset(self::$site_prefixes[$section][$write !== false ? 'write' : 'read']))
         self::loadSiteDb($section, $write);

      return self::$site_prefixes[$section][$write !== false ? 'write' : 'read'];
   }

   // Is the database loaded?
   public static function dbConnection($section, $write = false)
   {
      if (!isset(self::$site_connections[$section][$write !== false ? 'write' : 'read']))
         self::loadSiteDb($section, $type);

      return self::$site_connections[$section][$write !== false ? 'write' : 'read'];
   }

   // This creates the connection if it doesn't exist.
   public static function loadSiteDb($section, $write = false, $return_connection = false)
   {
      global $site_section, $siteman_settings, $sitedb_settings;

      // No section, how lame is that.
      if (empty($section) && empty($site_section))
         trigger_error('site_load_db() no section set', E_ERROR);
      $section = empty($section) ? $site_section : $section;

      // Doing both?
      if ($write == 'both')
      {
         siteman_load_db($section, false);
         $write = true;
      }

      // Try to include our database information if we haven't already
      if (!empty($section) && !isset($site_connections[$section][$write ? 'write' : 'read']))
         require($siteman_settings['settings_dir'] . '/settings_' . $section . '.php');

      // Make the connection!
      $type = $write ? 'write' : 'read';
      if (!isset(self::$site_connections[$section][$type]))
      {
         // No read or write data? Its old skool and needs updating.
         if (!isset($sitedb_settings[$section][$type]))
         {
            $sitedb_settings[$section][$type] = $sitedb_settings[$section];

            if (empty($sitedb_settings[$section][$type]['prefix']))
               $sitedb_settings[$section][$type]['prefix'] = '';
         }
   
         // The actual connection.
         self::$site_connections[$section][$type] = smf_db_initiate($sitedb_settings[$section][$type]['server'], $sitedb_settings[$section][$type]['name'], $sitedb_settings[$section][$type]['user'], $sitedb_settings[$section][$type]['passwd'], $sitedb_settings[$section][$type]['prefix'], array('persist' => false));

         // Using a special connection?
         if ($return_connection)
            return array($sitedb_settings[$section][$type]['prefix'], $site_connections[$section][$type]);

         self::$site_prefixes[$section][$type] = '`' . $sitedb_settings[$section][$type]['name'] . '`.' . $sitedb_settings[$section][$type]['prefix'];
      }

      return self::$site_prefixes[$section][$type];
   }
}
No siggy! :D