Current file: /home/greg/workspace/PHPDS-dev-trunk/PHPDevShell/stable/trunk/includes/PHPDS_db.class.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
5.13%5.13%
5.13% 2 / 39 CRAP
12.00%12.00%
12.00% 18 / 150
 
PHPDS_db
0.00%0.00%
0.00% 0 / 1
5.13%5.13%
5.13% 2 / 39
12.00%12.00%
12.00% 18 / 150
 __construct($dependance)
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 3 / 3
 connect()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 newQuery($query)
0.00%0.00%
0.00% 0 / 1 20
0.00%0.00%
0.00% 0 / 9
 sqlQuery($query)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 invokeQuery($query_name)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 invokeQueryWith($query_name, $params)
100.00%100.00%
100.00% 1 / 1 2
100.00%100.00%
100.00% 4 / 4
 makeQuery($query_name)
0.00%0.00%
0.00% 0 / 1 13.49
40.74%40.74%
40.74% 11 / 27
 startTransaction()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 endTransaction()
0.00%0.00%
0.00% 0 / 1 20
0.00%0.00%
0.00% 0 / 8
 protect($param)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 debugConfig()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 5
 tableExist($table)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 countRows($table_name, $column = false)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 2
 logMenuAccess()
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 4
 logThis()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 getRoles($user_id = false, $return_array = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getGroups($user_id = false, $return_array = false, $alias_only = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 roleExist($role_id)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 groupExist($group_id)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 belongsToRole($user_id = false, $user_role)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 belongsToGroup($user_id = false, $user_group)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 setRoleQuery($query_request, $query_root_request = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 setGroupQuery($query_request, $query_root_request = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 settingsPrefix($custom_prefix = false)
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 9
 writeSettings($write_settings, $custom_prefix = '', $notes = array()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 deleteSettings($settings_to_delete = false, $custom_prefix = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getSettings($settings_required = false, $custom_prefix = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getEssentialSettings()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 6
 doesRecordExist($table_name, $search_column_names, $search_field_values, $column_name_for_exclusion = false, $exclude_field_value = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 selectQuick($from_table_name, $select_column_name, $where_column_name, $is_equal_to_column_value)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 deleteQuick($from_table_name, $where_column_name, $is_equal_to_column_value, $return_column_value = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 nameOfNewCopy($table_name, $name_field, $orig_name)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 installedPlugins()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 connectCacheServer()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 15
 cacheWrite($unique_key, $cache_data, $compress=false, $timeout=false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 cacheRead($unique_key)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 cacheClear($unique_key = false)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 cacheEmpty($unique_key)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 LoadPluginClasses ()
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 24


       1                 : <?php                                                                                                                                                                   
       2                 :                                                                                                                                                                         
       3                 : /**                                                                                                                                                                     
       4                 :  * PHPDevShell is a RAD Framework aimed at developing administrative applications.                                                                                      
       5                 :  *                                                                                                                                                                      
       6                 :  * @package PHPDevShell                                                                                                                                                 
       7                 :  * @link http://www.phpdevshell.org                                                                                                                                     
       8                 :  * @copyright Copyright (C) 2007 Jason Schoeman, All rights reserved.                                                                                                   
       9                 :  * @license GNU/LGPL, see readme/licensed_under_lgpl or http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html                                                          
      10                 :  *                                                                                                                                                                      
      11                 :  * Copyright notice: See readme/notice                                                                                                                                  
      12                 :  * By using PHPDevShell you agree to notice and license, if you dont agree to this notice/license you are not allowed to use PHPDevShell.                               
      13                 :  *                                                                                                                                                                      
      14                 :  */                                                                                                                                                                     
      15                 : require_once 'PHPDS_dbConnector.class.php';                                                                                                                             
      16                 : require_once 'PHPDS_query.class.php';                                                                                                                                   
      17                 :                                                                                                                                                                         
      18                 : /**                                                                                                                                                                     
      19                 :  * This is a new version of one the Big5: the db class                                                                                                                  
      20                 :  *                                                                                                                                                                      
      21                 :  * This new version supports connectors and queries class and should be compatible with the old one                                                                     
      22                 :  *                                                                                                                                                                      
      23                 :  * @version        1.0                                                                                                                                                  
      24                 :  * @date                20100219                                                                                                                                        
      25                 :  * @author         greg                                                                                                                                                 
      26                 :  *                                                                                                                                                                      
      27                 :  */                                                                                                                                                                     
      28                 : class PHPDS_db extends db                                                                                                                                               
      29                 : {                                                                                                                                                                       
      30                 :     /**                                                                                                                                                                 
      31                 :      * Contains servers name where PHPDevShell runs on.                                                                                                                 
      32                 :      *                                                                                                                                                                  
      33                 :      * @var string                                                                                                                                                      
      34                 :      */                                                                                                                                                                 
      35                 :     public $server;                                                                                                                                                     
      36                 :     /**                                                                                                                                                                 
      37                 :      * Contains database user name where PHPDevShell runs on.                                                                                                           
      38                 :      *                                                                                                                                                                  
      39                 :      * @var string                                                                                                                                                      
      40                 :      */                                                                                                                                                                 
      41                 :     public $dbUsername;                                                                                                                                                 
      42                 :     /**                                                                                                                                                                 
      43                 :      * Contains database user password where PHPDevShell runs on.                                                                                                       
      44                 :      *                                                                                                                                                                  
      45                 :      * @var string                                                                                                                                                      
      46                 :      */                                                                                                                                                                 
      47                 :     public $dbPassword;                                                                                                                                                 
      48                 :     /**                                                                                                                                                                 
      49                 :      * Contains database name where PHPDevShell runs on.                                                                                                                
      50                 :      *                                                                                                                                                                  
      51                 :      * @var string                                                                                                                                                      
      52                 :      */                                                                                                                                                                 
      53                 :     public $dbName;                                                                                                                                                     
      54                 :     /**                                                                                                                                                                 
      55                 :      * Contains connection data.                                                                                                                                        
      56                 :      *                                                                                                                                                                  
      57                 :      * @var object                                                                                                                                                      
      58                 :      */                                                                                                                                                                 
      59                 :     public $connection;                                                                                                                                                 
      60                 :     /**                                                                                                                                                                 
      61                 :      * Memcache object.                                                                                                                                                 
      62                 :      *                                                                                                                                                                  
      63                 :      * @var object                                                                                                                                                      
      64                 :      */                                                                                                                                                                 
      65                 :     public $memcache;                                                                                                                                                   
      66                 :     /**                                                                                                                                                                 
      67                 :      * Array for log data to be written.                                                                                                                                
      68                 :      *                                                                                                                                                                  
      69                 :      * @var string                                                                                                                                                      
      70                 :      */                                                                                                                                                                 
      71                 :     public $logArray;                                                                                                                                                   
      72                 :     /**                                                                                                                                                                 
      73                 :      * Count amount of queries used by the system.                                                                                                                      
      74                 :      * Currently it is on -2, we are not counting Start and End transaction.                                                                                            
      75                 :      *                                                                                                                                                                  
      76                 :      * @var integer                                                                                                                                                     
      77                 :      */                                                                                                                                                                 
      78                 :     public $countQueries = -2;                                                                                                                                          
      79                 :     /**                                                                                                                                                                 
      80                 :      * Contains array of all the plugins installed.                                                                                                                     
      81                 :      *                                                                                                                                                                  
      82                 :      * @var array                                                                                                                                                       
      83                 :      */                                                                                                                                                                 
      84                 :     public $pluginsInstalled;                                                                                                                                           
      85                 :     /**                                                                                                                                                                 
      86                 :      * Contains variable of logo.                                                                                                                                       
      87                 :      *                                                                                                                                                                  
      88                 :      * @var array                                                                                                                                                       
      89                 :      */                                                                                                                                                                 
      90                 :     public $pluginLogo;                                                                                                                                                 
      91                 :     /**                                                                                                                                                                 
      92                 :      * Essential settings array.                                                                                                                                        
      93                 :      *                                                                                                                                                                  
      94                 :      * @var array                                                                                                                                                       
      95                 :      */                                                                                                                                                                 
      96                 :     public $essentialSettings;                                                                                                                                          
      97                 :     /**                                                                                                                                                                 
      98                 :      * Display erroneous sql statements                                                                                                                                 
      99                 :      *                                                                                                                                                                  
     100                 :      * @var boolean                                                                                                                                                     
     101                 :      */                                                                                                                                                                 
     102                 :     public $displaySqlInError = false;                                                                                                                                  
     103                 :     /**                                                                                                                                                                 
     104                 :      * Stores results                                                                                                                                                   
     105                 :      *                                                                                                                                                                  
     106                 :      * @var string                                                                                                                                                      
     107                 :      */                                                                                                                                                                 
     108                 :     public $result;                                                                                                                                                     
     109                 :     /**                                                                                                                                                                 
     110                 :      * Database connector.                                                                                                                                              
     111                 :      * @var object                                                                                                                                                      
     112                 :      */                                                                                                                                                                 
     113                 :     protected $connector;                                                                                                                                               
     114                 :     /**                                                                                                                                                                 
     115                 :      * Query as string.                                                                                                                                                 
     116                 :      * @var string                                                                                                                                                      
     117                 :      */                                                                                                                                                                 
     118                 :     protected $defaultQuery; // PHPDS_query                                                                                                                             
     119                 :                                                                                                                                                                         
     120                 :     /**                                                                                                                                                                 
     121                 :      * Dependence constructor.                                                                                                                                          
     122                 :      * @param object $dependance                                                                                                                                        
     123                 :      */                                                                                                                                                                 
     124                 :     public function __construct($dependance)                                                                                                                            
     125                 :     {                                                                                                                                                                   
     126               1 :         $this->PHPDS_dependance($dependance);                                                                                                                           
     127               1 :         $this->connector = new PHPDS_PDOconnector($dependance);                                                                                                         
     128               1 :     }                                                                                                                                                                   
     129                 :                                                                                                                                                                         
     130                 :     /**                                                                                                                                                                 
     131                 :      * Force database connection.                                                                                                                                       
     132                 :      * FIX: Note this is used in core initiation to fix some dependent functions like mysql_real_escape_string requiring a DB connection.                               
     133                 :      * Only dbConnecter->query initiated the connection which was unfair to dependent functions.                                                                        
     134                 :      *                                                                                                                                                                  
     135                 :      * @date 20110622                                                                                                                                                   
     136                 :      * @author Jason Schoeman                                                                                                                                           
     137                 :      */                                                                                                                                                                 
     138                 :     public function connect()                                                                                                                                           
     139                 :     {                                                                                                                                                                   
     140               0 :         $this->connector->connect();                                                                                                                                    
     141               0 :     }                                                                                                                                                                   
     142                 :                                                                                                                                                                         
     143                 :     /**                                                                                                                                                                 
     144                 :      * Compatibility                                                                                                                                                    
     145                 :      * Do direct sql query without models.                                                                                                                              
     146                 :      *                                                                                                                                                                  
     147                 :      * @date 20110512                                                                                                                                                   
     148                 :      * @param string                                                                                                                                                    
     149                 :      * @version    1.0                                                                                                                                                  
     150                 :      * @author jason                                                                                                                                                    
     151                 :      * @return mixed                                                                                                                                                    
     152                 :      */                                                                                                                                                                 
     153                 :     public function newQuery($query)                                                                                                                                    
     154                 :     {                                                                                                                                                                   
     155                 :         try {                                                                                                                                                           
     156               0 :             if (empty($this->defaultQuery))                                                                                                                             
     157               0 :                     $this->defaultQuery = $this->makeQuery('PHPDS_query');                                                                                              
     158               0 :             $this->defaultQuery->sql($query);                                                                                                                           
     159               0 :             return $this->defaultQuery->query();                                                                                                                        
     160               0 :         } catch (Exception $e) {                                                                                                                                        
     161               0 :             if (empty($this->defaultQuery))                                                                                                                             
     162               0 :                 $msg = 'Unable to create default query: ' . $e->getMessage();                                                                                           
     163                 :             else                                                                                                                                                        
     164               0 :                 $msg = 'While running default query:<br /><pre>' . $this->defaultQuery->sql() . '</pre>' . $e->getMessage();                                            
     165               0 :             throw new PHPDS_databaseException($msg, 0, $e);                                                                                                             
     166                 :         }                                                                                                                                                               
     167                 :     }                                                                                                                                                                   
     168                 :                                                                                                                                                                         
     169                 :         /**                                                                                                                                                             
     170                 :          * Alias to newQuery                                                                                                                                            
     171                 :          *                                                                                                                                                              
     172                 :          * @param string $query                                                                                                                                         
     173                 :          * @return mixed                                                                                                                                                
     174                 :          */                                                                                                                                                             
     175                 :         public function sqlQuery($query)                                                                                                                                
     176                 :         {                                                                                                                                                               
     177               0 :             return $this->newQuery($query);                                                                                                                             
     178                 :         }                                                                                                                                                               
     179                 :                                                                                                                                                                         
     180                 :     /**                                                                                                                                                                 
     181                 :      * Locates the query class of the given name, loads it, intantiate it, send the query to the DB, and return the result                                              
     182                 :      *                                                                                                                                                                  
     183                 :      * @date 20100219                                                                                                                                                   
     184                 :      * @version 1.2                                                                                                                                                     
     185                 :      * @date 20100922 (1.2) (greg) now use invokeQueryWithArgs                                                                                                          
     186                 :      * @author greg                                                                                                                                                     
     187                 :      * @param $query_name string, the name of the query class (descendant of PHPDS_query)                                                                               
     188                 :      * @return array (usually), the result data of the query                                                                                                            
     189                 :      */                                                                                                                                                                 
     190                 :     public function invokeQuery($query_name) // actually more parameters can be given                                                                                   
     191                 :     {                                                                                                                                                                   
     192               0 :         $params = func_get_args();                                                                                                                                      
     193               0 :         array_shift($params); // first parameter of this function is $query_name                                                                                        
     194               0 :         return $this->invokeQueryWith($query_name, $params);                                                                                                            
     195                 :     }                                                                                                                                                                   
     196                 :                                                                                                                                                                         
     197                 :     /**                                                                                                                                                                 
     198                 :      * Locates the query class of the given name, loads it, intantiate it, send the query to the DB, and return the result                                              
     199                 :      *                                                                                                                                                                  
     200                 :      * @date 20100922 (1.0) (greg) added                                                                                                                                
     201                 :      * @version 1.0                                                                                                                                                     
     202                 :      * @author greg                                                                                                                                                     
     203                 :      * @param $query_name string, the name of the query class (descendant of PHPDS_query)                                                                               
     204                 :      * @param $args array of parameters                                                                                                                                 
     205                 :      * @return array (usually), the result data of the query                                                                                                            
     206                 :      */                                                                                                                                                                 
     207                 :     public function invokeQueryWith($query_name, $params)                                                                                                               
     208                 :     {                                                                                                                                                                   
     209              20 :         $query = $this->makeQuery($query_name);                                                                                                                         
     210              20 :         if (!is_a($query, 'PHPDS_query'))                                                                                                                               
     211              20 :                 throw new PHPDS_databaseException('Error invoking query');                                                                                              
     212              20 :         return $query->invoke($params);                                                                                                                                 
     213                 :     }                                                                                                                                                                   
     214                 :                                                                                                                                                                         
     215                 :     /**                                                                                                                                                                 
     216                 :      * Locates the query class of the given name, loads it, intantiate it, and returns the query object                                                                 
     217                 :      *                                                                                                                                                                  
     218                 :      * @date                20100219                                                                                                                                    
     219                 :      * @version     1.1                                                                                                                                                 
     220                 :      * @author        greg                                                                                                                                              
     221                 :      * @param         $query_name        string, the name of the query class (descendant of PHPDS_query)                                                                
     222                 :      * @return         PHPDS_query descendant, the query object                                                                                                         
     223                 :      */                                                                                                                                                                 
     224                 :     public function makeQuery($query_name)                                                                                                                              
     225                 :     {                                                                                                                                                                   
     226              20 :         $configuration = $this->configuration;                                                                                                                          
     227              20 :         $navigation = $this->navigation;                                                                                                                                
     228              20 :         $o = null;                                                                                                                                                      
     229              20 :         $good = (class_exists($query_name, false));                                                                                                                     
     230              20 :         if (!$good) {                                                                                                                                                   
     231               0 :             $phpds = $this->PHPDS_dependance();                                                                                                                         
     232               0 :             list($plugin, $menu_link) = $navigation->menuPath();                                                                                                        
     233               0 :             $query_file = 'models/' . $menu_link;                                                                                                                       
     234               0 :             $query_file = preg_replace('/\.php$/', '.query.php', $query_file);                                                                                          
     235               0 :             $query_file = $configuration['absolute_path'] . 'plugins/' . $plugin . '/' . $query_file;                                                                   
     236               0 :             $good = $phpds->sneakClass($query_name, $query_file);                                                                                                       
     237                 :             // Execute class file.                                                                                                                                      
     238               0 :             if (!$good) {                                                                                                                                               
     239               0 :                 $menu = $configuration['m'];                                                                                                                            
     240               0 :                 if (!empty($navigation->navigation[$menu])) {                                                                                                           
     241               0 :                     $plugin = $navigation->navigation[$menu]['plugin'];                                                                                                 
     242               0 :                     $query_file = $configuration['absolute_path'] . 'plugins/' . $plugin . '/models/plugin.query.php';                                                  
     243               0 :                     $good = $phpds->sneakClass($query_name, $query_file);                                                                                               
     244               0 :                 }                                                                                                                                                       
     245               0 :             }                                                                                                                                                           
     246               0 :         }                                                                                                                                                               
     247                 :         // All is good create class.                                                                                                                                    
     248              20 :         if ($good) {                                                                                                                                                    
     249              20 :             $o = $this->factory($query_name);                                                                                                                           
     250              20 :             if (!is_a($o, 'PHPDS_query')) throw new PHPDS_Exception('Error factoring query: object is not a PHPDS_query, maybe you mistyped the class superclass');     
     251              20 :             $o->connector($this->connector); // TODO: give the proper connector based the query needs                                                                   
     252              20 :         } else                                                                                                                                                          
     253               0 :                 throw new PHPDS_Exception('Error making query: unable to find class "' . $query_name . '".');                                                           
     254              20 :         return $o;                                                                                                                                                      
     255                 :     }                                                                                                                                                                   
     256                 :                                                                                                                                                                         
     257                 :     /**                                                                                                                                                                 
     258                 :      * Set the starting point for a SQL transaction                                                                                                                     
     259                 :      *                                                                                                                                                                  
     260                 :      * You should call end_transaction(true) for the queries to actually occur                                                                                          
     261                 :      */                                                                                                                                                                 
     262                 :     public function startTransaction()                                                                                                                                  
     263                 :     {                                                                                                                                                                   
     264               0 :         return $this->connector->startTransaction();                                                                                                                    
     265                 :     }                                                                                                                                                                   
     266                 :                                                                                                                                                                         
     267                 :     /**                                                                                                                                                                 
     268                 :      * Commits database transactions.                                                                                                                                   
     269                 :      *                                                                                                                                                                  
     270                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     271                 :      */                                                                                                                                                                 
     272                 :     public function endTransaction()                                                                                                                                    
     273                 :     {                                                                                                                                                                   
     274               0 :         $configuration = $this->configuration;                                                                                                                          
     275                 :         // Should we commit or rollback?                                                                                                                                
     276               0 :         if (($configuration['demo_mode'] == true)) {                                                                                                                    
     277               0 :             if ($configuration['user_role'] != $configuration['root_role']) {                                                                                           
     278                 :                 // Roll back all database changes.                                                                                                                      
     279               0 :                 return $this->connector->endTransaction(false);                                                                                                         
     280                 :             } else {                                                                                                                                                    
     281                 :                 // Commit all database changes.                                                                                                                         
     282               0 :                 return $this->connector->endTransaction(true);                                                                                                          
     283                 :             }                                                                                                                                                           
     284               0 :         } else if ($configuration['demo_mode'] == false) {                                                                                                              
     285                 :             // Commit all database changes.                                                                                                                             
     286               0 :             return $this->connector->endTransaction(true);                                                                                                              
     287                 :         }                                                                                                                                                               
     288               0 :     }                                                                                                                                                                   
     289                 :                                                                                                                                                                         
     290                 :     /**                                                                                                                                                                 
     291                 :      * Protect a single string from possible hacker (i.e. escape possible harmfull chars)                                                                               
     292                 :      *                                                                                                                                                                  
     293                 :      * Actually deleguate the action to the connector                                                                                                                   
     294                 :      *                                                                                                                                                                  
     295                 :      * @date 20100329                                                                                                                                                   
     296                 :      * @version 1.0                                                                                                                                                     
     297                 :      * @author greg                                                                                                                                                     
     298                 :      * @param $param string, the parameter to espace                                                                                                                    
     299                 :      * @return string, the escaped string                                                                                                                               
     300                 :      * @see includes/PHPDS_db_connector#protect()                                                                                                                       
     301                 :      */                                                                                                                                                                 
     302                 :     public function protect($param)                                                                                                                                     
     303                 :     {                                                                                                                                                                   
     304               0 :         return $this->connector->protect($param);                                                                                                                       
     305                 :     }                                                                                                                                                                   
     306                 :                                                                                                                                                                         
     307                 :     /**                                                                                                                                                                 
     308                 :      * Will convert object configuration into array for parsing.                                                                                                        
     309                 :      *                                                                                                                                                                  
     310                 :      */                                                                                                                                                                 
     311                 :     private function debugConfig()                                                                                                                                      
     312                 :     {                                                                                                                                                                   
     313               0 :         foreach ($this->configuration as $key => $extended_config) {                                                                                                    
     314               0 :             $converted_config[$key] = $extended_config;                                                                                                                 
     315               0 :         }                                                                                                                                                               
     316               0 :         $this->_log($converted_config);                                                                                                                                 
     317               0 :     }                                                                                                                                                                   
     318                 :                                                                                                                                                                         
     319                 :     /**                                                                                                                                                                 
     320                 :      * Checks if a database table exists.                                                                                                                               
     321                 :      *                                                                                                                                                                  
     322                 :      * @param string $table                                                                                                                                             
     323                 :      * @return boolean                                                                                                                                                  
     324                 :      */                                                                                                                                                                 
     325                 :     public function tableExist($table)                                                                                                                                  
     326                 :     {                                                                                                                                                                   
     327               0 :         return $this->invokeQuery('DB_tableExistsQuery', $table);                                                                                                       
     328                 :     }                                                                                                                                                                   
     329                 :                                                                                                                                                                         
     330                 :     /**                                                                                                                                                                 
     331                 :      * Simple method to count number of rows in a table.                                                                                                                
     332                 :      *                                                                                                                                                                  
     333                 :      * @param string $table_name                                                                                                                                        
     334                 :      * @param string $column                                                                                                                                            
     335                 :      * @return integer                                                                                                                                                  
     336                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     337                 :      */                                                                                                                                                                 
     338                 :     public function countRows($table_name, $column = false)                                                                                                             
     339                 :     {                                                                                                                                                                   
     340                 :         // Check what to count.                                                                                                                                         
     341               0 :         if (empty($column)) $column = '*';                                                                                                                              
     342               0 :         return $this->invokeQuery('DB_countRowsQuery', $column, $table_name);                                                                                           
     343                 :     }                                                                                                                                                                   
     344                 :                                                                                                                                                                         
     345                 :     /**                                                                                                                                                                 
     346                 :      * Method logs menu access per user.                                                                                                                                
     347                 :      *                                                                                                                                                                  
     348                 :      */                                                                                                                                                                 
     349                 :     public function logMenuAccess()                                                                                                                                     
     350                 :     {                                                                                                                                                                   
     351               0 :         $configuration = $this->configuration;                                                                                                                          
     352                 :         // Check if we need to log.                                                                                                                                     
     353                 :         // Log menu access...                                                                                                                                           
     354               0 :         if ($configuration['access_logging'] == true || isset($this->security->get['l']))                                                                               
     355               0 :             $this->invokeQuery('DB_logMenuAccessQuery', $configuration['m'], $configuration['user_id'], $configuration['time']);                                        
     356               0 :     }                                                                                                                                                                   
     357                 :                                                                                                                                                                         
     358                 :     /**                                                                                                                                                                 
     359                 :      * This method logs error and success entries to the database.                                                                                                      
     360                 :      *                                                                                                                                                                  
     361                 :      * @param integer $log_type                                                                                                                                         
     362                 :      * @param string $log_description                                                                                                                                   
     363                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     364                 :      *                                                                                                                                                                  
     365                 :      * @version 1.0.1     Changed mysql_escape_string() to mysql_real_escape_string() [see http://www.php.net/manual/en/function.mysql-escape-string.php ]              
     366                 :      */                                                                                                                                                                 
     367                 :     public function logThis()                                                                                                                                           
     368                 :     {                                                                                                                                                                   
     369               0 :         $this->invokeQuery('DB_logThisQuery', $this->logArray);                                                                                                         
     370               0 :     }                                                                                                                                                                   
     371                 :                                                                                                                                                                         
     372                 :     /**                                                                                                                                                                 
     373                 :      * This function gets all role id's for a given user id, while returning a string divided by ',' character or an array with ids.                                    
     374                 :      * To pull multiple user roles, provide a string for $user_ids like so: '2,5,10,19'.                                                                                
     375                 :      *                                                                                                                                                                  
     376                 :      * @deprecated                                                                                                                                                      
     377                 :      * @param string $user_id                                                                                                                                           
     378                 :      * @param boolean $return_array                                                                                                                                     
     379                 :      * @return mixed If $return_array = false a comma delimited string will be returned, else an array.                                                                 
     380                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     381                 :      */                                                                                                                                                                 
     382                 :     public function getRoles($user_id = false, $return_array = false)                                                                                                   
     383                 :     {                                                                                                                                                                   
     384               0 :         return $this->user->getRoles($user_id, $return_array);                                                                                                          
     385                 :     }                                                                                                                                                                   
     386                 :                                                                                                                                                                         
     387                 :     /**                                                                                                                                                                 
     388                 :      * This function gets all group id's for given user ids, while returning a string divided by ',' character or an array with ids.                                    
     389                 :      * To pull multiple user groups, provide a string for $user_ids like so : '2,5,10,19'.                                                                              
     390                 :      *                                                                                                                                                                  
     391                 :      * @deprecated                                                                                                                                                      
     392                 :      * @param string $user_id Leave this field empty if you want skip if user is root.                                                                                  
     393                 :      * @param boolean $return_array                                                                                                                                     
     394                 :      * @param string $alias_only If you would like only items of a certain alias to be called.                                                                          
     395                 :      * @return mixed If $return_array = false a comma delimited string will be returned, else an array.                                                                 
     396                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     397                 :      */                                                                                                                                                                 
     398                 :     public function getGroups($user_id = false, $return_array = false, $alias_only = false)                                                                             
     399                 :     {                                                                                                                                                                   
     400               0 :         return $this->user->getGroups($user_id, $return_array, $alias_only);                                                                                            
     401                 :     }                                                                                                                                                                   
     402                 :                                                                                                                                                                         
     403                 :     /**                                                                                                                                                                 
     404                 :      * Simple check to see if a certain role exists.                                                                                                                    
     405                 :      *                                                                                                                                                                  
     406                 :      * @deprecated                                                                                                                                                      
     407                 :      * @param integer $role_id                                                                                                                                          
     408                 :      * @return boolean                                                                                                                                                  
     409                 :      */                                                                                                                                                                 
     410                 :     public function roleExist($role_id)                                                                                                                                 
     411                 :     {                                                                                                                                                                   
     412               0 :         return $this->user->roleExist($role_id);                                                                                                                        
     413                 :     }                                                                                                                                                                   
     414                 :                                                                                                                                                                         
     415                 :     /**                                                                                                                                                                 
     416                 :      * Simple check to see if a certain group exists.                                                                                                                   
     417                 :      *                                                                                                                                                                  
     418                 :      * @deprecated                                                                                                                                                      
     419                 :      * @param integer $group_id                                                                                                                                         
     420                 :      * @return boolean                                                                                                                                                  
     421                 :      */                                                                                                                                                                 
     422                 :     public function groupExist($group_id)                                                                                                                               
     423                 :     {                                                                                                                                                                   
     424               0 :         return $this->user->groupExist($group_id);                                                                                                                      
     425                 :     }                                                                                                                                                                   
     426                 :                                                                                                                                                                         
     427                 :     /**                                                                                                                                                                 
     428                 :      * Check if user belongs to given role. Returns true if user belongs to user role.                                                                                  
     429                 :      *                                                                                                                                                                  
     430                 :      * @deprecated                                                                                                                                                      
     431                 :      * @param integer $user_id                                                                                                                                          
     432                 :      * @param integer $user_role                                                                                                                                        
     433                 :      * @return boolean Returns true if user belongs to user role.                                                                                                       
     434                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     435                 :      */                                                                                                                                                                 
     436                 :     public function belongsToRole($user_id = false, $user_role)                                                                                                         
     437                 :     {                                                                                                                                                                   
     438               0 :         return $this->user->belongsToRole($user_id, $user_role);                                                                                                        
     439                 :     }                                                                                                                                                                   
     440                 :                                                                                                                                                                         
     441                 :     /**                                                                                                                                                                 
     442                 :      * Check if user belongs to given group. Returns true if user belongs to user group.                                                                                
     443                 :      *                                                                                                                                                                  
     444                 :      * @deprecated                                                                                                                                                      
     445                 :      * @param integer $user_id                                                                                                                                          
     446                 :      * @param integer $user_group                                                                                                                                       
     447                 :      * @return boolean Returns true if user belongs to user group.                                                                                                      
     448                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     449                 :      */                                                                                                                                                                 
     450                 :     public function belongsToGroup($user_id = false, $user_group)                                                                                                       
     451                 :     {                                                                                                                                                                   
     452               0 :         return $this->user->belongsToGroup($user_id, $user_group);                                                                                                      
     453                 :     }                                                                                                                                                                   
     454                 :                                                                                                                                                                         
     455                 :     /**                                                                                                                                                                 
     456                 :      * Creates a query to extend a role query, it will return false if user is root so everything can get listed.                                                       
     457                 :      * This is meant to be used inside an existing role query.                                                                                                          
     458                 :      *                                                                                                                                                                  
     459                 :      * @deprecated                                                                                                                                                      
     460                 :      * @param string $query_request Normal query to be returned if user is not a root user.                                                                             
     461                 :      * @param string $query_root_request If you want a query to be processed for a root user seperately.                                                                
     462                 :      * @return mixed                                                                                                                                                    
     463                 :      */                                                                                                                                                                 
     464                 :     public function setRoleQuery($query_request, $query_root_request = false)                                                                                           
     465                 :     {                                                                                                                                                                   
     466               0 :         return $this->user->setRoleQuery($query_request, $query_root_request);                                                                                          
     467                 :     }                                                                                                                                                                   
     468                 :                                                                                                                                                                         
     469                 :     /**                                                                                                                                                                 
     470                 :      * Creates a query to extend a group query, it will return false if user is root so everything can get listed.                                                      
     471                 :      * This is meant to be used inside an existing group query.                                                                                                         
     472                 :      *                                                                                                                                                                  
     473                 :      * @deprecated                                                                                                                                                      
     474                 :      * @param string $query_request Normal query to be returned if user is not a root user.                                                                             
     475                 :      * @param string $query_root_request If you want a query to be processed for a root user seperately.                                                                
     476                 :      * @return mixed                                                                                                                                                    
     477                 :      */                                                                                                                                                                 
     478                 :     public function setGroupQuery($query_request, $query_root_request = false)                                                                                          
     479                 :     {                                                                                                                                                                   
     480               0 :         return $this->user->setGroupQuery($query_request, $query_root_request);                                                                                         
     481                 :     }                                                                                                                                                                   
     482                 :                                                                                                                                                                         
     483                 :     /**                                                                                                                                                                 
     484                 :      * Generates a prefix for plugin general settings.                                                                                                                  
     485                 :      *                                                                                                                                                                  
     486                 :      * @param string $custom_prefix                                                                                                                                     
     487                 :      * @return string Complete string with prefix.                                                                                                                      
     488                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     489                 :      */                                                                                                                                                                 
     490                 :     public function settingsPrefix($custom_prefix = false)                                                                                                              
     491                 :     {                                                                                                                                                                   
     492                 :         // Create prefix.                                                                                                                                               
     493               0 :         if ($custom_prefix == false) {                                                                                                                                  
     494                 :             // Get active plugin.                                                                                                                                       
     495               0 :             $active_plugin = $this->core->activePlugin();                                                                                                               
     496               0 :             if (!empty($active_plugin)) {                                                                                                                               
     497               0 :                 $prefix = $active_plugin . '_';                                                                                                                         
     498               0 :             } else {                                                                                                                                                    
     499               0 :                 $prefix = 'PHPDevShell_';                                                                                                                               
     500                 :             }                                                                                                                                                           
     501               0 :         } else {                                                                                                                                                        
     502               0 :             $prefix = $custom_prefix . '_';                                                                                                                             
     503                 :         }                                                                                                                                                               
     504               0 :         return $prefix;                                                                                                                                                 
     505                 :     }                                                                                                                                                                   
     506                 :                                                                                                                                                                         
     507                 :     /**                                                                                                                                                                 
     508                 :      * Used to write general plugin settings to the database.                                                                                                           
     509                 :      * Class will always use plugin name as prefix for settings if no custom prefix is provided.                                                                        
     510                 :      * <code>                                                                                                                                                           
     511                 :      * // Example:                                                                                                                                                      
     512                 :      * $db->writeSettings(array('setting_name'=>'value')[,'Example'][,array('setting_name'=>'note')]);                                                                  
     513                 :      * </code>                                                                                                                                                          
     514                 :      * @param array $write_settings This array should contain settings to write.                                                                                        
     515                 :      * @param string $custom_prefix If you would like to have a custom prefix added to your settings.                                                                   
     516                 :      * @param array $notes For adding notes about setting.                                                                                                              
     517                 :      * @return boolean On success true will be returned.                                                                                                                
     518                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     519                 :      */                                                                                                                                                                 
     520                 :     public function writeSettings($write_settings, $custom_prefix = '', $notes = array())                                                                               
     521                 :     {                                                                                                                                                                   
     522               0 :         return $this->invokeQuery('DB_writeSettingsQuery', $write_settings, $custom_prefix, $notes);                                                                    
     523                 :     }                                                                                                                                                                   
     524                 :                                                                                                                                                                         
     525                 :     /**                                                                                                                                                                 
     526                 :      * Delete all settings stored by a given plugins name, is used when uninstalling a plugin.                                                                          
     527                 :      *                                                                                                                                                                  
     528                 :      * Example:                                                                                                                                                         
     529                 :      * <code>                                                                                                                                                           
     530                 :      * deleteSettings(false, 'SimplePhonebook')                                                                                                                         
     531                 :      * </code>                                                                                                                                                          
     532                 :      *                                                                                                                                                                  
     533                 :      * @param array $settings_to_delete Use '*' to delete all settings for certain plugin.                                                                              
     534                 :      * @param string $custom_prefix                                                                                                                                     
     535                 :      * @return boolean                                                                                                                                                  
     536                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     537                 :      */                                                                                                                                                                 
     538                 :     public function deleteSettings($settings_to_delete = false, $custom_prefix = false)                                                                                 
     539                 :     {                                                                                                                                                                   
     540               0 :         return $this->invokeQuery('DB_deleteSettingsQuery', $settings_to_delete, $custom_prefix);                                                                       
     541                 :     }                                                                                                                                                                   
     542                 :                                                                                                                                                                         
     543                 :     /**                                                                                                                                                                 
     544                 :      * Loads and returns required settings from database.                                                                                                               
     545                 :      * Class will always use plugin name as prefix for settings if no custom prefix is provided.                                                                        
     546                 :      *                                                                                                                                                                  
     547                 :      * @param array $settings_required                                                                                                                                  
     548                 :      * @param string $prefix This allows you to use a prefix value of your choice to select a setting from another plugin, otherwise PHPDevShell will be used.          
     549                 :      * @return array An array will be returned containing all the values requested.                                                                                     
     550                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     551                 :      */                                                                                                                                                                 
     552                 :     public function getSettings($settings_required = false, $custom_prefix = false)                                                                                     
     553                 :     {                                                                                                                                                                   
     554               0 :         return $this->invokeQuery('DB_getSettingsQuery', $settings_required, $custom_prefix);                                                                           
     555                 :     }                                                                                                                                                                   
     556                 :                                                                                                                                                                         
     557                 :     /**                                                                                                                                                                 
     558                 :      * Used to get all essential system settings from the database, preventing multiple queries.                                                                        
     559                 :      *                                                                                                                                                                  
     560                 :      * @return array Contains array with essential settings.                                                                                                            
     561                 :      */                                                                                                                                                                 
     562                 :     public function getEssentialSettings()                                                                                                                              
     563                 :     {                                                                                                                                                                   
     564                 :         // Pull essential settings and assign it to essential_settings.                                                                                                 
     565               0 :         if ($this->cacheEmpty('essential_settings')) {                                                                                                                  
     566               0 :             $this->essentialSettings = $this->getSettings($this->configuration['preloaded_settings'], 'PHPDevShell');                                                   
     567                 :             // Write essential settings data to cache.                                                                                                                  
     568               0 :             $this->cacheWrite('essential_settings', $this->essentialSettings);                                                                                          
     569               0 :         } else {                                                                                                                                                        
     570               0 :             $this->essentialSettings = $this->cacheRead('essential_settings');                                                                                          
     571                 :         }                                                                                                                                                               
     572               0 :     }                                                                                                                                                                   
     573                 :                                                                                                                                                                         
     574                 :     /**                                                                                                                                                                 
     575                 :      * Determines whether the specified search string already exists in the specified field within the supplied table.                                                  
     576                 :      * Optional: Also looks at an id field (typically the primary key of a table) to make sure that the record you are working with                                     
     577                 :      * is NOT included in the search.                                                                                                                                   
     578                 :      * Usefull when modifying an existing record and you need first to check if another record with the same value doesn't already exist.                               
     579                 :      *                                                                                                                                                                  
     580                 :      * Please note that this function is not case sensitive.                                                                                                            
     581                 :      *                                                                                                                                                                  
     582                 :      * Usage Example :                                                                                                                                                  
     583                 :      * <code>                                                                                                                                                           
     584                 :      *     if ($db->doesRecordExist('_db_core_users', array('user_name', 'user_email'), array('root', 'titan@phpdevshell.org'), 'user_id', '123'))                      
     585                 :      *     {                                                                                                                                                            
     586                 :      *         $this->template->debugStr = "Found!";                                                                                                                    
     587                 :      *     }                                                                                                                                                            
     588                 :      *     else                                                                                                                                                         
     589                 :      *     {                                                                                                                                                            
     590                 :      *         $this->template->debugStr = "Not Found!";                                                                                                                
     591                 :      *     }                                                                                                                                                            
     592                 :      *                                                                                                                                                                  
     593                 :      *  // Or you could use single values instead of arrays.                                                                                                            
     594                 :      *     if ($db->does_record_exist('_db_core_users', 'user_name', 'root', 'user_id', '123'))                                                                         
     595                 :      *     {                                                                                                                                                            
     596                 :      *         $this->template->debugStr = "Found!";                                                                                                                    
     597                 :      *     }                                                                                                                                                            
     598                 :      *     else                                                                                                                                                         
     599                 :      *     {                                                                                                                                                            
     600                 :      *         $this->template->debugStr = "Not Found!";                                                                                                                
     601                 :      *     }                                                                                                                                                            
     602                 :      * </code>                                                                                                                                                          
     603                 :      *                                                                                                                                                                  
     604                 :      * @param string The name of the database table.                                                                                                                    
     605                 :      * @param mixed The array names of the columns in which to look for the search strings, a single value can also be given.                                           
     606                 :      * @param mixed In the same order as $search_column_name array, the search strings in array that should not be duplicated, a single value can also be given.        
     607                 :      * @param string The name of the primary key column name of the record you will be updating.                                                                        
     608                 :      * @param string The value of the primary key of the record you will be updating that should not be included in the search.                                         
     609                 :      * @return boolean If TRUE is returned it means the record already exists, FALSE means the record doesn't exist.                                                    
     610                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     611                 :      */                                                                                                                                                                 
     612                 :     public function doesRecordExist($table_name, $search_column_names, $search_field_values, $column_name_for_exclusion = false, $exclude_field_value = false)          
     613                 :     {                                                                                                                                                                   
     614               0 :         return $this->invokeQuery('DB_doesRecordExistQuery', $table_name, $search_column_names, $search_field_values, $column_name_for_exclusion, $exclude_field_value);
     615                 :     }                                                                                                                                                                   
     616                 :                                                                                                                                                                         
     617                 :     /**                                                                                                                                                                 
     618                 :      * Get a single result from database with minimal effort.                                                                                                           
     619                 :      *                                                                                                                                                                  
     620                 :      * @param string $from_table_name                                                                                                                                   
     621                 :      * @param string $select_column_name                                                                                                                                
     622                 :      * @param string $where_column_name                                                                                                                                 
     623                 :      * @param string $is_equal_to_column_value                                                                                                                          
     624                 :      * @return string                                                                                                                                                   
     625                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     626                 :      */                                                                                                                                                                 
     627                 :     public function selectQuick($from_table_name, $select_column_name, $where_column_name, $is_equal_to_column_value)                                                   
     628                 :     {                                                                                                                                                                   
     629               0 :         return $this->invokeQuery('DB_selectQuickQuery', $select_column_name, $from_table_name, $where_column_name, $is_equal_to_column_value);                         
     630                 :     }                                                                                                                                                                   
     631                 :                                                                                                                                                                         
     632                 :     /**                                                                                                                                                                 
     633                 :      * Delete data from the database with minimal effort.                                                                                                               
     634                 :      *                                                                                                                                                                  
     635                 :      * @param string $from_table_name                                                                                                                                   
     636                 :      * @param string $where_column_name                                                                                                                                 
     637                 :      * @param string $is_equal_to_column_value                                                                                                                          
     638                 :      * @param string $return_column_value                                                                                                                               
     639                 :      * @return string                                                                                                                                                   
     640                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     641                 :      */                                                                                                                                                                 
     642                 :     public function deleteQuick($from_table_name, $where_column_name, $is_equal_to_column_value, $return_column_value = false)                                          
     643                 :     {                                                                                                                                                                   
     644               0 :         return $this->invokeQuery('DB_deleteQuickQuery', $from_table_name, $where_column_name, $is_equal_to_column_value, $return_column_value);                        
     645                 :     }                                                                                                                                                                   
     646                 :                                                                                                                                                                         
     647                 :     /**                                                                                                                                                                 
     648                 :      * This method is used to generate a new name value for a particular string in the database.                                                                        
     649                 :      *                                                                                                                                                                  
     650                 :      * Usage Example :                                                                                                                                                  
     651                 :      * <code>                                                                                                                                                           
     652                 :      *  // This code generates a copy of the text "Some Value". The name_of_new_copy function                                                                           
     653                 :      *  // checks that it doesn't duplicate the name.                                                                                                                   
     654                 :      *  $result = $db->nameOfNewCopy('PHPDS_table', 'some_field', 'Some Value');                                                                                        
     655                 :      *                                                                                                                                                                  
     656                 :      *  // name_of_new_copy() returns 'Copy of Some Value', unless 'Copy of Some Value' already exists. If                                                              
     657                 :      *  // it does, the function will return with 'Copy (x) of Some Value' where x is the next available                                                                
     658                 :      *  // number that is not in use.                                                                                                                                   
     659                 :      * </code>                                                                                                                                                          
     660                 :      *                                                                                                                                                                  
     661                 :      * @param string The name of the table to search within.                                                                                                            
     662                 :      * @param string The fieldname to search withing.                                                                                                                   
     663                 :      * @param string The original text to search for.                                                                                                                   
     664                 :      * @author Don Schoeman <don@delphexonline.com>                                                                                                                     
     665                 :      */                                                                                                                                                                 
     666                 :     function nameOfNewCopy($table_name, $name_field, $orig_name)                                                                                                        
     667                 :     {                                                                                                                                                                   
     668               0 :         return $this->invokeQuery('DB_nameOfNewCopyQuery', $table_name, $name_field, $orig_name);                                                                       
     669                 :     }                                                                                                                                                                   
     670                 :                                                                                                                                                                         
     671                 :     /**                                                                                                                                                                 
     672                 :      * Writes array of all the installed plugins on the system.                                                                                                         
     673                 :      * @author Jason Schoeman <titan@phpdevshell.org>                                                                                                                   
     674                 :      */                                                                                                                                                                 
     675                 :     public function installedPlugins()                                                                                                                                  
     676                 :     {                                                                                                                                                                   
     677               0 :         $this->invokeQuery('DB_installedPluginsQuery');                                                                                                                 
     678               0 :     }                                                                                                                                                                   
     679                 :                                                                                                                                                                         
     680                 :     /**                                                                                                                                                                 
     681                 :      * Does the connection to the memcache server.                                                                                                                      
     682                 :      * Currently memcache is the primary supported engine.                                                                                                              
     683                 :      */                                                                                                                                                                 
     684                 :     public function connectCacheServer()                                                                                                                                
     685                 :     {                                                                                                                                                                   
     686               0 :         $configuration = $this->configuration;                                                                                                                          
     687                 :                                                                                                                                                                         
     688                 :         // Get cache configuration.                                                                                                                                     
     689               0 :         $conf['cache_refresh_intervals'] = $configuration['cache_refresh_intervals'];                                                                                   
     690                 :                                                                                                                                                                         
     691                 :         // Assign configuration arrays.                                                                                                                                 
     692               0 :         if ($configuration['cache_type'] != 'PHPDS_sessionCache') {                                                                                                     
     693               0 :             $conf['cache_host'] = $configuration['cache_host'];                                                                                                         
     694               0 :             $conf['cache_port'] = $configuration['cache_port'];                                                                                                         
     695               0 :             $conf['cache_persistent'] = $configuration['cache_persistent'];                                                                                             
     696               0 :             $conf['cache_weight'] = $configuration['cache_weight'];                                                                                                     
     697               0 :             $conf['cache_timeout'] = $configuration['cache_timeout'];                                                                                                   
     698               0 :             $conf['cache_retry_interval'] = $configuration['cache_retry_interval'];                                                                                     
     699               0 :             $conf['cache_status'] = $configuration['cache_status'];                                                                                                     
     700               0 :         }                                                                                                                                                               
     701                 :                                                                                                                                                                         
     702                 :         // Load Cache Class.                                                                                                                                            
     703               0 :         require_once 'cache/' . $configuration['cache_type'] . '.inc.php';                                                                                              
     704               0 :         $this->memcache = new $configuration['cache_type'];                                                                                                             
     705                 :                                                                                                                                                                         
     706                 :         // Check connection type.                                                                                                                                       
     707               0 :         $this->memcache->connectCacheServer($conf);                                                                                                                     
     708               0 :     }                                                                                                                                                                   
     709                 :                                                                                                                                                                         
     710                 :     /**                                                                                                                                                                 
     711                 :      * Writes new data to cache.                                                                                                                                        
     712                 :      * @param string $unique_key                                                                                                                                        
     713                 :      * @param mixed $cache_data                                                                                                                                         
     714                 :      * @param boolean $compress                                                                                                                                         
     715                 :      * @param int $timeout                                                                                                                                              
     716                 :      */                                                                                                                                                                 
     717                 :     public function cacheWrite($unique_key, $cache_data, $compress=false, $timeout=false)                                                                               
     718                 :     {                                                                                                                                                                   
     719                 :         // Check caching type.                                                                                                                                          
     720               0 :         $this->memcache->cacheWrite($unique_key, $cache_data, $compress, $timeout);                                                                                     
     721               0 :     }                                                                                                                                                                   
     722                 :                                                                                                                                                                         
     723                 :     /**                                                                                                                                                                 
     724                 :      * Return exising cache result to required item.                                                                                                                    
     725                 :      * @param mixed $unique_key                                                                                                                                         
     726                 :      * @return mixed                                                                                                                                                    
     727                 :      */                                                                                                                                                                 
     728                 :     public function cacheRead($unique_key)                                                                                                                              
     729                 :     {                                                                                                                                                                   
     730               0 :         return $this->memcache->cacheRead($unique_key);                                                                                                                 
     731                 :     }                                                                                                                                                                   
     732                 :                                                                                                                                                                         
     733                 :     /**                                                                                                                                                                 
     734                 :      * Clear specific or all cache memory.                                                                                                                              
     735                 :      * @param mixed $unique_key                                                                                                                                         
     736                 :      */                                                                                                                                                                 
     737                 :     public function cacheClear($unique_key = false)                                                                                                                     
     738                 :     {                                                                                                                                                                   
     739               0 :         $this->memcache->cacheClear($unique_key);                                                                                                                       
     740               0 :     }                                                                                                                                                                   
     741                 :                                                                                                                                                                         
     742                 :     /**                                                                                                                                                                 
     743                 :      * Checks if we have an empty cache container.                                                                                                                      
     744                 :      * @param mixed $unique_key                                                                                                                                         
     745                 :      * @return boolean                                                                                                                                                  
     746                 :      */                                                                                                                                                                 
     747                 :     public function cacheEmpty($unique_key)                                                                                                                             
     748                 :     {                                                                                                                                                                   
     749               0 :         return $this->memcache->cacheEmpty($unique_key);                                                                                                                
     750                 :     }                                                                                                                                                                   
     751                 :                                                                                                                                                                         
     752                 :     /**                                                                                                                                                                 
     753                 :      * Loads all available plugins into array.                                                                                                                          
     754                 :      *                                                                                                                                                                  
     755                 :      * @return Array                                                                                                                                                    
     756                 :      */                                                                                                                                                                 
     757                 :     public function LoadPluginClasses ()                                                                                                                                
     758                 :     {                                                                                                                                                                   
     759               0 :         $db = $this->db;                                                                                                                                                
     760               0 :         if ($db->cacheEmpty('PluginClasses')) {                                                                                                                         
     761               0 :             $pluginR = $db->invokeQuery('DB_readPluginClassRegistryQuery');                                                                                             
     762               0 :             if (! empty($pluginR)) {                                                                                                                                    
     763               0 :                 foreach ($pluginR as $p) {                                                                                                                              
     764               0 :                     $PluginClasses[$p['class_name']] = array(                                                                                                           
     765               0 :                         'class_name'=>'',                                                                                                                               
     766               0 :                         'alias'=>$p['alias'],                                                                                                                           
     767               0 :                         'plugin_folder'=>$p['plugin_folder']                                                                                                            
     768               0 :                     );                                                                                                                                                  
     769               0 :                     if (! empty($p['alias'])) {                                                                                                                         
     770               0 :                         $PluginClasses[$p['alias']] = array(                                                                                                            
     771               0 :                             'class_name'=>$p['class_name'],                                                                                                             
     772               0 :                             'plugin_folder'=>$p['plugin_folder']                                                                                                        
     773               0 :                         );                                                                                                                                              
     774               0 :                     }                                                                                                                                                   
     775               0 :                 }                                                                                                                                                       
     776               0 :                 $db->cacheWrite('PluginClasses', $PluginClasses);                                                                                                       
     777               0 :             }                                                                                                                                                           
     778               0 :         } else {                                                                                                                                                        
     779               0 :             $PluginClasses = $db->cacheRead('PluginClasses');                                                                                                           
     780                 :         }                                                                                                                                                               
     781                 :                                                                                                                                                                         
     782               0 :         if (! empty($PluginClasses)) {                                                                                                                                  
     783               0 :             return $PluginClasses;                                                                                                                                      
     784                 :         } else {                                                                                                                                                        
     785               0 :             return array();                                                                                                                                             
     786                 :         }                                                                                                                                                               
     787                 :     }                                                                                                                                                                   
     788                 : }                                                                                                                                                                       

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.6 and PHPUnit 3.5.14 at Mon Aug 8 22:35:38 PDT 2011.