Пример #1
0
 /**
  * View an SQL log
  *
  * @return	@e void		[Outputs to screen]
  */
 protected function _view()
 {
     /* INIT */
     $file = trim($this->request['file']);
     /* Check file name */
     if (!preg_match("#^sql_error_log_(\\d+)_(\\d+)_(\\d+).cgi\$#", $file) or !is_file(IPS_CACHE_PATH . 'cache/' . $file)) {
         $this->registry->output->global_message = $this->lang->words['sqllog_nofile'];
         $this->_listCurrent();
         return;
     }
     /* Fetch size */
     $size = @filesize(IPS_CACHE_PATH . 'cache/' . $file);
     /* Fetch content */
     $classToLoad = IPSLib::loadLibrary(IPS_KERNEL_PATH . 'classFileManagement.php', 'classFileManagement');
     $classFileManagement = new $classToLoad();
     /* Get some tail! */
     $content = $classFileManagement->tailFile(IPS_CACHE_PATH . 'cache/' . $file, 300);
     $tailSize = IPSLib::strlenToBytes(strlen($content));
     /* Can't believe I typed that last comment */
     $this->registry->output->html .= $this->html->sqlLogsView($file, $size, htmlentities($content), $tailSize);
 }
Пример #2
0
 /**
  * Load cache(s)
  *
  * @param	array 	Array of caches to load: array( 'group_cache', 'forum_cache' )
  * @param	boolean	Set to FALSE to skip trying to load the caches from DB
  * @return	mixed	Loaded Cache
  * @author	MattMecham
  */
 protected static function _loadCaches($caches = array(), $loadFromDb = true, $init = false)
 {
     if (!is_array($caches) or !count($caches)) {
         return NULL;
     }
     $requestedCaches = $caches;
     $_seenKeys = array();
     //--------------------------------
     // Eaccelerator...
     //--------------------------------
     if (is_object(self::$cacheLib)) {
         $temp_cache = array();
         $new_cache_array = array();
         foreach ($caches as $key) {
             $temp_cache[$key] = self::$cacheLib->getFromCache($key);
             if (!$temp_cache[$key] or $temp_cache[$key] == 'rebuildCache') {
                 $new_cache_array[] = $key;
             } else {
                 if (is_string($temp_cache[$key]) and strpos($temp_cache[$key], "a:") !== false) {
                     self::$data_store[$key] = unserialize($temp_cache[$key]);
                     //-----------------------------------------
                     // Fallback fix if unserialize fails
                     //-----------------------------------------
                     if (!is_array(self::$data_store[$key])) {
                         $new_cache_array[] = $key;
                         continue;
                     }
                 } else {
                     if ($temp_cache[$key] == "EMPTY") {
                         self::$data_store[$key] = NULL;
                     } else {
                         self::$data_store[$key] = $temp_cache[$key];
                     }
                 }
                 $_seenKeys[$key] = $key;
             }
         }
         $caches = $new_cache_array;
         unset($new_cache_array, $temp_cache);
     }
     $_rebuild = array();
     if (count($caches) && $loadFromDb) {
         //--------------------------------
         // Get from DB...
         //--------------------------------
         ipsRegistry::DB()->build(array('select' => '*', 'from' => 'cache_store', 'where' => "cs_key IN ( '" . implode("','", $caches) . "' )"));
         $exe = ipsRegistry::DB()->execute();
         while ($r = ipsRegistry::DB()->fetch($exe)) {
             $_seenKeys[$r['cs_key']] = $r['cs_key'];
             //-----------------------------------------
             // Forcing rebuild?
             //-----------------------------------------
             if ($r['cs_rebuild']) {
                 if ($r['cs_key'] == 'licenseData') {
                     self::instance()->rebuildCache($r['cs_key']);
                     self::$data_store[$r['cs_key']] = self::instance()->getCache($r['cs_key']);
                 } else {
                     self::$rebuild_list[] = $r['cs_key'];
                 }
                 continue;
             }
             //-----------------------------------------
             // Debug?
             //-----------------------------------------
             if (IN_DEV) {
                 self::instance()->debugInfo[$r['cs_key']] = array('size' => IPSLib::strlenToBytes(strlen($r['cs_value'])));
             }
             //-----------------------------------------
             // Serialized array?
             //-----------------------------------------
             if ($r['cs_array'] or substr($r['cs_value'], 0, 2) == "a:") {
                 self::$data_store[$r['cs_key']] = unserialize($r['cs_value']);
                 if (!is_array(self::$data_store[$r['cs_key']])) {
                     self::$data_store[$r['cs_key']] = array();
                 }
             } else {
                 self::$data_store[$r['cs_key']] = $r['cs_value'] ? $r['cs_value'] : NULL;
             }
             //-----------------------------------------
             // Push to alt cache store
             //-----------------------------------------
             if (is_object(self::$cacheLib)) {
                 if (!$r['cs_value']) {
                     $r['cs_value'] = "EMPTY";
                 }
                 self::$cacheLib->putInCache($r['cs_key'], $r['cs_value'], 86400);
             }
         }
     }
     //-----------------------------------------
     // Make sure each key is in data_store otherwise
     // repeated calls will keep trying to load it
     //-----------------------------------------
     foreach ($requestedCaches as $_cache) {
         if (!in_array($_cache, $_seenKeys)) {
             self::$data_store[$_cache] = NULL;
         }
     }
 }
Пример #3
0
 /**
  * Send batch to the backup server
  */
 public function sendBatch()
 {
     /* Fetch kernel class */
     require_once IPS_KERNEL_PATH . 'classFileManagement.php';
     $cfm = new classFileManagement();
     /* Fetch DB data */
     $tables = $this->_getDatabaseSchematics();
     $sqlRows = array();
     $touchedTables = array();
     $bytesUsed = '';
     $topId = 0;
     $delIds = array();
     /* Do we need to restart? */
     if ($this->checkForRestart()) {
         $this->populateLogWithAllTables();
         return true;
     }
     /* Little short cut */
     $p = $this->registry->dbFunctions()->getPrefix();
     /* Start looping on the table */
     $this->DB->build(array('select' => '*', 'from' => 'backup_queue', 'order' => 'queue_id', 'limit' => array(0, $this->Limits['rows'])));
     $o = $this->DB->execute();
     while ($row = $this->DB->fetch($o)) {
         $tbl = $this->_stripPrefix($row['queue_entry_table']);
         $sql = '';
         $fields = array();
         $touchedTables[$tbl] = $tbl;
         if ($row['queue_entry_sql']) {
             $sql = $row['queue_entry_sql'];
         } else {
             /* Get fields */
             foreach ($tables[$row['queue_entry_table']]['cols'] as $col) {
                 $fields[] = $col['Field'];
             }
             if (!count($fields)) {
                 /* Empty - so remove this queue row or we'll never progress */
                 $delIds[] = $row['queue_id'];
                 continue;
             }
             /* INSERT */
             if ($row['queue_entry_type'] == 1) {
                 /* Get data */
                 $pKey = $row['queue_entry_key'];
                 $pKeyVal = $this->_isConcat($pKey) ? addslashes($row['queue_entry_value']) : $row['queue_entry_value'];
                 $data = array();
                 $vals = array();
                 $data = $this->DB->buildAndFetch(array('select' => '`' . implode("`, `", $fields) . '`', 'from' => $tbl, 'where' => $pKey . "='" . $pKeyVal . "'"));
                 if (!is_array($data) or !count($data)) {
                     /* Empty - so remove this queue row or we'll never progress */
                     $delIds[] = $row['queue_id'];
                     continue;
                 }
                 foreach ($data as $k => $v) {
                     $vals[] = $this->_makeValueSafeForQuery($v);
                 }
                 $sql = "INSERT INTO " . $p . $tbl . "(`" . implode("`, `", $fields) . "`) " . "VALUES( '" . implode("', '", $vals) . "');";
             }
         }
         /* Got anything? */
         if (!$sql) {
             /* Empty - so remove this queue row or we'll never progress */
             $delIds[] = $row['queue_id'];
             continue;
         }
         /* check size */
         $bytesUsed += IPSLib::strlenToBytes(strlen($sql));
         /* Truth time! */
         if ($bytesUsed >= $this->Limits['bytes']) {
             break;
         } else {
             $sqlRows[] = $sql;
             /* top id to remove */
             $topId = $row['queue_id'];
         }
     }
     /* Anything to delete? */
     if (count($delIds)) {
         $this->DB->delete('backup_queue', 'queue_id IN (' . implode(',', array_values($delIds)) . ')');
     }
     /* What do we have? */
     if ($topId && count($sqlRows)) {
         $dataToSend = $this->_createTextToSend($sqlRows, array_keys($touchedTables));
         $returnedData = $cfm->postFileContents($this->_getBackupServerUrl(), array('backup_data' => @gzcompress($dataToSend), 'lkey' => ipsRegistry::$settings['ipb_reg_number']));
         $test = json_decode(trim($returnedData), true);
         if (is_array($test) && $test['status'] == 'ok') {
             $this->DB->delete('backup_queue', 'queue_id <= ' . intval($topId));
             $this->_addLog(intval($test['rows']), $test['status']);
             $this->Vars['rows_sent'] = intval($this->Vars['rows_sent']) + count($sqlRows);
             $this->Vars['rows_total'] = $this->_getStoredRowCount();
             $this->_setVars();
         } else {
             # Fail lol
             $this->_addLog(0, $test['status']);
         }
     }
 }
Пример #4
0
 /**
  * List all of the current caches
  *
  * @return	@e void		[Outputs to screen]
  */
 public function cacheOverview()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $content = "";
     $db_caches = array();
     $lib_caches = array();
     $cacheContent = array();
     $total = 0;
     //-----------------------------------------
     // Get stored caches
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'cache_store'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         $db_caches[$r['cs_key']] = $r;
     }
     //-----------------------------------------
     // Get core cache list
     //-----------------------------------------
     foreach ($this->registry->_fetchCoreVariables('cache') as $cache_name => $cache_data) {
         $cache_data['cache_name'] = $cache_name;
         $cache_data['_cache_size'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value'])));
         $cache_data['_cs_init_load'] = $db_caches[$cache_name]['cs_init_load'];
         $total += IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value']));
         $lib_caches['global'][$cache_name] = $cache_data;
     }
     //-----------------------------------------
     // Get all application's cache lists
     //-----------------------------------------
     foreach (IPSLib::getEnabledApplications() as $app_dir => $app_data) {
         $_file = IPSLib::getAppDir($app_dir) . '/extensions/coreVariables.php';
         if (is_file($_file)) {
             $CACHE = array();
             require $_file;
             /*maybeLibHook*/
             foreach ($CACHE as $cache_name => $cache_data) {
                 $cache_data['cache_name'] = $cache_name;
                 $cache_data['_cache_size'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value'])));
                 $cache_data['_cs_init_load'] = $db_caches[$cache_name]['cs_init_load'];
                 $total += IPSLib::strlenToBytes(strlen($db_caches[$cache_name]['cs_value']));
                 $lib_caches[$app_dir][$cache_name] = $cache_data;
             }
         }
     }
     foreach ($lib_caches as $app => $data) {
         ksort($lib_caches[$app]);
     }
     $total = IPSLib::sizeFormat($total);
     /* Content Cache Stuffs */
     if (IPSContentCache::isEnabled()) {
         /* Get all posts */
         $statsCache = ipsRegistry::cache()->getCache('stats');
         $cacheContent['posts'] = array('count' => intval($statsCache['total_replies'] + $statsCache['total_topics']));
         /* Get all members */
         $cacheContent['members'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'members'));
         /* Get cached post count */
         $cacheContent['cachedPosts'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'content_cache_posts'));
         /* Get cached sig count */
         $cacheContent['cachedSigs'] = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as count', 'from' => 'content_cache_sigs'));
         /* Work out percentages */
         $cacheContent['postPercent'] = ($cacheContent['posts']['count'] and $cacheContent['cachedPosts']['count']) ? sprintf("%.0f", $cacheContent['cachedPosts']['count'] / $cacheContent['posts']['count'] * 100) : 0;
         $cacheContent['sigPercent'] = ($cacheContent['members']['count'] and $cacheContent['cachedSigs']['count']) ? sprintf("%.0f", $cacheContent['cachedSigs']['count'] / $cacheContent['members']['count'] * 100) : 0;
     }
     $this->registry->output->html .= $this->html->cache_entry_wrapper($lib_caches, $total, $cacheContent);
 }
Пример #5
0
 /**
  * Fetch Templates from the tree
  *
  * @access	public
  * @param	mixed		Skin key or	Skin set ID
  * @param	string		Type of data to return: 'allTemplates' will return the data [template_group][template_name], 'allNoContent' the same as 'allTemplates' minus the actual template content, 'groupNames'; [template_group] or groupTemplates, just that groups templates [template_name], groupTemplatesNoContent is the same as groupTemplates but template_content is removed
  * @param	string		Which group to use
  * @return	array 		Array of data depending on the params
  * <code>
  * Usage:
  * # To return all skin 'groups' (eg, skin_global, skin_topics, etc)
  * $groups = $skinFunctions->fetchTemplates( 1, 'groupNames' );
  * # To return all templates within group 'skin_global'
  * $templates = $skinFunctions->fetchTemplates( 1, 'groupTemplates', 'skin_global' );
  * # To return all templates in all groups
  * $templates = $skinFunctions->fetchTemplates( 1, 'allTemplates');
  * # To return all master templates for the mobile skin
  * $templates = $skinFunctions->fetchTemplates( 'mobile', 'allTemplates' );
  * </code>
  */
 public function fetchTemplates($setID, $type = 'allTemplates', $group = '')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $templates = array();
     $where = '';
     /* Did we pass a master key? - all root skins are 0  */
     if (!is_numeric($setID)) {
         $skinSetData = array('set_id' => 0, 'set_master_key' => $setID, 'set_key' => $setID, '_isMaster' => 1, '_parentTree' => array(), '_childTree' => array(), '_userAgents' => array(), '_cssGroupsArray' => array());
     } else {
         $skinSetData = $this->fetchSkinData($setID);
         $skinSetData['_isMaster'] = $skinSetData['_isMaster'] ? $skinSetData['_isMaster'] : 0;
     }
     /* Did we get a skin set? */
     if (!isset($skinSetData['_parentTree']) or !is_array($skinSetData['_parentTree'])) {
         return array();
     }
     //-----------------------------------------
     // Push root ID onto the END of the parent array
     //-----------------------------------------
     array_push($skinSetData['_parentTree'], 0);
     //-----------------------------------------
     // Push the current skin set ID onto the beginnging
     //-----------------------------------------
     if (is_numeric($setID)) {
         array_unshift($skinSetData['_parentTree'], $setID);
     }
     /* We want to capture only this set's master bits */
     $where = ' AND ( ( template_set_id > 0 AND ( template_master_key=\'\' OR template_master_key IS NULL ) ) OR ( template_set_id=0 AND template_master_key=\'' . $skinSetData['set_master_key'] . '\' ) )';
     /* First off, load 'root' skin as we tend to develop this the most and there is always a small chance other master skins won't
        contain all the template bits. We'll just load the group / name and leave the content blank to prevent parse errors, etc */
     if ($setID != 'root') {
         if (($type == 'groupTemplates' or $type == 'groupTemplatesNoContent') and $group != '') {
             $_w = " AND template_group='{$group}'";
         }
         $this->DB->build(array('select' => '*', 'from' => 'skin_templates', 'where' => "template_master_key='root'" . $_w, 'order' => 'template_group'));
         $this->DB->execute();
         while ($r = $this->DB->fetch()) {
             $r['template_content'] = '<!--no data in this master skin-->';
             if ($type == 'groupNames') {
                 $templates[$r['template_group']] = $r;
             } else {
                 if ($type == 'groupTemplates' or $type == 'groupTemplatesNoContent') {
                     $r['_templateSize'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($r['template_content'])));
                     if ($type == 'groupTemplatesNoContent') {
                         unset($r['template_data']);
                         unset($r['template_content']);
                     }
                     $templates[strtolower($r['template_name'])] = $r;
                 } else {
                     if ($type == 'allNoContent') {
                         unset($r['template_content']);
                     }
                     $templates[$r['template_group']][strtolower($r['template_name'])] = $r;
                 }
             }
         }
     }
     //-----------------------------------------
     // Ok, what to return?
     //-----------------------------------------
     if ($type == 'groupNames') {
         # Just return group titles
         $this->DB->build(array('select' => 'template_group, template_set_id, template_id, template_name, template_data,' . $this->DB->buildInstring("," . implode(",", $skinSetData['_parentTree']) . ",", $this->DB->buildConcat(array(array(',', 'string'), array('template_set_id'), array(',', 'string')))) . ' as theorder', 'from' => 'skin_templates', 'where' => "template_set_id IN (" . implode(",", $skinSetData['_parentTree']) . " )" . $where, 'order' => 'template_group, theorder DESC'));
         $newq = $this->DB->execute();
     } else {
         if (($type == 'groupTemplates' or $type == 'groupTemplatesNoContent') and $group != '') {
             # Return group template bits
             $this->DB->build(array('select' => '*,' . $this->DB->buildInstring("," . implode(",", $skinSetData['_parentTree']) . ",", $this->DB->buildConcat(array(array(',', 'string'), array('template_set_id'), array(',', 'string')))) . ' as theorder', 'from' => 'skin_templates', 'where' => "template_set_id IN (" . implode(",", $skinSetData['_parentTree']) . ") AND template_group='{$group}'" . $where, 'order' => 'template_name, theorder DESC'));
             $newq = $this->DB->execute();
         } else {
             # Return all...
             $this->DB->build(array('select' => '*,' . $this->DB->buildInstring("," . implode(",", $skinSetData['_parentTree']) . ",", $this->DB->buildConcat(array(array(',', 'string'), array('template_set_id'), array(',', 'string')))) . ' as theorder', 'from' => 'skin_templates', 'where' => "template_set_id IN (" . implode(",", $skinSetData['_parentTree']) . ")" . $where, 'order' => 'template_group, template_name, theorder DESC'));
             $newq = $this->DB->execute();
         }
     }
     //-----------------------------------------
     // Get all results
     //-----------------------------------------
     while ($r = $this->DB->fetch($newq)) {
         if (isset($r['template_name'])) {
             if (substr($r['template_name'], 0, 2) == '__') {
                 continue;
             }
         }
         //-----------------------------------------
         // Build counts
         //-----------------------------------------
         $this->_templateCount[$r['template_set_id']] = isset($this->_templateCount[$r['template_set_id']]) ? $this->_templateCount[$r['template_set_id']] : array();
         $this->_templateCount[$r['template_set_id']][$r['template_group']] = isset($this->_templateCount[$r['template_set_id']][$r['template_group']]) ? $this->_templateCount[$r['template_set_id']][$r['template_group']] : array('count' => 0);
         $this->_templateCount[$r['template_set_id']][$r['template_group']]['count']++;
         if ($type == 'groupNames') {
             $templates[$r['template_group']] = $r;
         } else {
             if ($type == 'groupTemplates' or $type == 'groupTemplatesNoContent') {
                 $r['_templateSize'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($r['template_content'])));
                 if ($type == 'groupTemplatesNoContent') {
                     unset($r['template_data']);
                     unset($r['template_content']);
                 }
                 $templates[strtolower($r['template_name'])] = $r;
             } else {
                 if ($type == 'allNoContent') {
                     unset($r['template_content']);
                 }
                 $templates[$r['template_group']][strtolower($r['template_name'])] = $r;
             }
         }
     }
     ksort($templates);
     foreach ($templates as $k => $v) {
         if (is_array($v)) {
             ksort($templates[$k]);
         }
     }
     return $templates;
 }
 /**
  * Load cache(s)
  *
  * @param	array 	Array of caches to load: array( 'group_cache', 'forum_cache' )
  * @return	mixed	Loaded Cache
  * @access 	private
  * @author	MattMecham
  */
 private static function _loadCaches($caches = array())
 {
     if (!is_array($caches) or !count($caches)) {
         return NULL;
     }
     //-----------------------------------------
     // Finalize
     //-----------------------------------------
     $cachelist = "'" . implode("','", $caches) . "'";
     //--------------------------------
     // Eaccelerator...
     //--------------------------------
     if (is_object(self::$cacheLib)) {
         $temp_cache = array();
         $new_cache_array = array();
         foreach ($caches as $key) {
             $temp_cache[$key] = self::$cacheLib->getFromCache($key);
             if (!$temp_cache[$key]) {
                 $new_cache_array[] = $key;
             } else {
                 if (is_string($temp_cache[$key]) and strstr($temp_cache[$key], "a:") !== false) {
                     self::instance()->data_store[$key] = unserialize($temp_cache[$key]);
                 } else {
                     if ($temp_cache[$key] == "EMPTY") {
                         self::instance()->data_store[$key] = NULL;
                     } else {
                         self::instance()->data_store[$key] = $temp_cache[$key];
                     }
                 }
             }
         }
         $cachearray = $new_cache_array;
         unset($new_cache_array, $temp_cache);
     }
     //--------------------------------
     // Get from DB...
     //--------------------------------
     if ($cachelist) {
         /* This is here for veeeeeery old 1.0.1 upgrades */
         if (!ipsRegistry::DB()->checkForTable('cache_store')) {
             ipsRegistry::DB()->query("create table " . ipsRegistry::dbFunctions()->getPrefix() . "cache_store (\r\n\t\t\t\t\t\t  cs_key varchar(255) NOT NULL default '',\r\n\t\t\t\t\t\t  cs_value text NULL,\r\n\t\t\t\t\t\t  cs_extra varchar(255) NOT NULL default '',\r\n\t\t\t\t\t\t  PRIMARY KEY(cs_key)\r\n\t\t\t\t\t\t);");
         }
         ipsRegistry::DB()->build(array('select' => '*', 'from' => 'cache_store', 'where' => "cs_key IN ( {$cachelist} )"));
         ipsRegistry::DB()->execute();
         $_seenKeys = array();
         while ($r = ipsRegistry::DB()->fetch()) {
             $_seenKeys[$r['cs_key']] = $r['cs_key'];
             self::instance()->debugInfo[$r['cs_key']] = array('size' => IPSLib::strlenToBytes(strlen($r['cs_value'])));
             if ($r['cs_array'] or substr($r['cs_value'], 0, 2) == "a:") {
                 self::instance()->data_store[$r['cs_key']] = unserialize($r['cs_value']);
                 if (!is_array(self::instance()->data_store[$r['cs_key']])) {
                     self::instance()->data_store[$r['cs_key']] = array();
                 }
             } else {
                 self::instance()->data_store[$r['cs_key']] = $r['cs_value'] ? $r['cs_value'] : NULL;
             }
             if (is_object(self::$cacheLib)) {
                 if (!$r['cs_value']) {
                     $r['cs_value'] = "EMPTY";
                 }
                 self::$cacheLib->putInCache($r['cs_key'], $r['cs_value']);
             }
         }
     }
     //-----------------------------------------
     // Make sure each key is in data_store otherwise
     // repeated calls will keep trying to load it
     //-----------------------------------------
     foreach ($caches as $_cache) {
         if (!in_array($_cache, $_seenKeys)) {
             self::instance()->data_store[$_cache] = NULL;
         }
     }
 }
 /**
  * Load cache(s)
  *
  * @param	array 	Array of caches to load: array( 'group_cache', 'forum_cache' )
  * @return	mixed	Loaded Cache
  * @access 	private
  * @author	MattMecham
  */
 private static function _loadCaches($caches = array())
 {
     if (!is_array($caches) or !count($caches)) {
         return NULL;
     }
     //-----------------------------------------
     // Finalize
     //-----------------------------------------
     $cachelist = "'" . implode("','", $caches) . "'";
     //--------------------------------
     // Eaccelerator...
     //--------------------------------
     if (is_object(self::$cacheLib)) {
         $temp_cache = array();
         $new_cache_array = array();
         foreach ($caches as $key) {
             $temp_cache[$key] = self::$cacheLib->getFromCache($key);
             if (!$temp_cache[$key]) {
                 $new_cache_array[] = $key;
             } else {
                 if (strstr($temp_cache[$key], "a:")) {
                     self::instance()->data_store[$key] = unserialize($temp_cache[$key]);
                 } else {
                     if ($temp_cache[$key] == "EMPTY") {
                         self::instance()->data_store[$key] = NULL;
                     } else {
                         self::instance()->data_store[$key] = $temp_cache[$key];
                     }
                 }
             }
         }
         $cachearray = $new_cache_array;
         unset($new_cache_array, $temp_cache);
     }
     //--------------------------------
     // Get from DB...
     //--------------------------------
     if ($cachelist) {
         ipsRegistry::DB()->build(array('select' => '*', 'from' => 'cache_store', 'where' => "cs_key IN ( {$cachelist} )"));
         ipsRegistry::DB()->execute();
         $_seenKeys = array();
         while ($r = ipsRegistry::DB()->fetch()) {
             $_seenKeys[$r['cs_key']] = $r['cs_key'];
             self::instance()->debugInfo[$r['cs_key']] = array('size' => IPSLib::strlenToBytes(strlen($r['cs_value'])));
             if ($r['cs_array'] or substr($r['cs_value'], 0, 2) == "a:") {
                 self::instance()->data_store[$r['cs_key']] = unserialize($r['cs_value']);
                 if (!is_array(self::instance()->data_store[$r['cs_key']])) {
                     self::instance()->data_store[$r['cs_key']] = array();
                 }
             } else {
                 self::instance()->data_store[$r['cs_key']] = $r['cs_value'] ? $r['cs_value'] : NULL;
             }
             if (is_object(self::$cacheLib)) {
                 if (!$r['cs_value']) {
                     $r['cs_value'] = "EMPTY";
                 }
                 self::$cacheLib->putInCache($r['cs_key'], $r['cs_value']);
             }
         }
     }
     //-----------------------------------------
     // Make sure each key is in data_store otherwise
     // repeated calls will keep trying to load it
     //-----------------------------------------
     foreach ($caches as $_cache) {
         if (!in_array($_cache, $_seenKeys)) {
             self::instance()->data_store[$_cache] = NULL;
         }
     }
 }
Пример #8
0
 /**
  * Fetch a report
  *
  * @access	public
  * @param	int			Session ID
  * @return	array
  */
 public function fetchReport($diffSessionID)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $return = array('counts' => array('missing' => 0, 'changed' => 0), 'data' => array());
     //-----------------------------------------
     // Get data
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'skin_merge_changes', 'where' => 'change_session_id=' . $diffSessionID, 'order' => 'change_data_group ASC, change_data_title ASC'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         //-----------------------------------------
         // Gen data
         //-----------------------------------------
         $row['_key'] = $row['change_key'];
         $row['_size'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(IPSText::mbstrlen($row['change_data_content'])));
         //-----------------------------------------
         // Diff type
         //-----------------------------------------
         if ($row['change_is_new']) {
             $row['_is'] = 'new';
             $return['counts']['missing']++;
         } else {
             $row['_is'] = 'changed';
             $return['counts']['changed']++;
         }
         /* Is it CSS? */
         if ($row['change_data_type'] == 'css') {
             $row['change_data_group'] = 'css';
             $row['change_data_title'] .= '.css';
         }
         /* Fetch basic stats */
         if ($row['change_data_content']) {
             $row['_diffs'] = substr_count($row['change_data_content'], '-ips-match:1');
         }
         if ($row['change_merge_content'] and stristr($row['change_merge_content'], '<ips:conflict')) {
             $row['_conflicts'] = substr_count($row['change_merge_content'], '<ips:conflict');
         }
         //-----------------------------------------
         // Add data...
         //-----------------------------------------
         $return['data'][$row['change_data_group']][$row['_key']] = $row;
     }
     return $return;
 }
 /**
  * Fetch Templates from the tree
  *
  * @access	public
  * @param	int			Skin set ID
  * @param	string		Type of data to return: 'allTemplates' will return the data [template_group][template_name], 'allNoContent' the same as 'allTemplates' minus the actual template content, 'groupNames'; [template_group] or groupTemplates, just that groups templates [template_name], groupTemplatesNoContent is the same as groupTemplates but template_content is removed
  * @param	string		Which group to use
  * @return	array 		Array of data depending on the params
  * <code>
  * Usage:
  * # To return all skin 'groups' (eg, skin_global, skin_topics, etc)
  * $groups = $skinFunctions->fetchTemplates( 1, 'groupNames' );
  * # To return all templates within group 'skin_global'
  * $templates = $skinFunctions->fetchTemplates( 1, 'groupTemplates', 'skin_global' );
  * # To return all templates in all groups
  * $templates = $skinFunctions->fetchTemplates( 1, 'allTemplates');
  * </code>
  */
 public function fetchTemplates($setID, $type = 'allTemplates', $group = '')
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $templates = array();
     //-----------------------------------------
     // Try and get the skin from the cache
     //-----------------------------------------
     $skinSetData = $this->fetchSkinData($setID);
     //-----------------------------------------
     // Push root ID onto the END of the parent array
     //-----------------------------------------
     array_push($skinSetData['_parentTree'], 0);
     //-----------------------------------------
     // Push the current skin set ID onto the beginnging
     //-----------------------------------------
     array_unshift($skinSetData['_parentTree'], $setID);
     //-----------------------------------------
     // Ok, what to return?
     //-----------------------------------------
     if ($type == 'groupNames') {
         # Just return group titles
         $this->DB->build(array('select' => 'template_group, template_set_id, template_id, template_name, template_data,' . $this->DB->buildInstring("," . implode(",", $skinSetData['_parentTree']) . ",", $this->DB->buildConcat(array(array(',', 'string'), array('template_set_id'), array(',', 'string')))) . ' as theorder', 'from' => 'skin_templates', 'where' => "template_set_id IN (" . implode(",", $skinSetData['_parentTree']) . " )", 'order' => 'template_group, theorder DESC'));
         $newq = $this->DB->execute();
     } else {
         if (($type == 'groupTemplates' or $type == 'groupTemplatesNoContent') and $group != '') {
             # Return group template bits
             $this->DB->build(array('select' => '*,' . $this->DB->buildInstring("," . implode(",", $skinSetData['_parentTree']) . ",", $this->DB->buildConcat(array(array(',', 'string'), array('template_set_id'), array(',', 'string')))) . ' as theorder', 'from' => 'skin_templates', 'where' => "template_set_id IN (" . implode(",", $skinSetData['_parentTree']) . ") AND template_group='{$group}'", 'order' => 'template_name, theorder DESC'));
             $newq = $this->DB->execute();
         } else {
             # Return all...
             $this->DB->build(array('select' => '*,' . $this->DB->buildInstring("," . implode(",", $skinSetData['_parentTree']) . ",", $this->DB->buildConcat(array(array(',', 'string'), array('template_set_id'), array(',', 'string')))) . ' as theorder', 'from' => 'skin_templates', 'where' => "template_set_id IN (" . implode(",", $skinSetData['_parentTree']) . ")", 'order' => 'template_group, template_name, theorder DESC'));
             $newq = $this->DB->execute();
         }
     }
     //-----------------------------------------
     // Get all results
     //-----------------------------------------
     while ($r = $this->DB->fetch($newq)) {
         if (isset($r['template_name'])) {
             if (substr($r['template_name'], 0, 2) == '__') {
                 continue;
             }
         }
         //-----------------------------------------
         // Build counts
         //-----------------------------------------
         $this->_templateCount[$r['template_set_id']] = isset($this->_templateCount[$r['template_set_id']]) ? $this->_templateCount[$r['template_set_id']] : array();
         $this->_templateCount[$r['template_set_id']][$r['template_group']] = isset($this->_templateCount[$r['template_set_id']][$r['template_group']]) ? $this->_templateCount[$r['template_set_id']][$r['template_group']] : array('count' => 0);
         $this->_templateCount[$r['template_set_id']][$r['template_group']]['count']++;
         if ($type == 'groupNames') {
             $templates[$r['template_group']] = $r;
         } else {
             if ($type == 'groupTemplates' or $type == 'groupTemplatesNoContent') {
                 $r['_templateSize'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(strlen($r['template_content'])));
                 if ($type == 'groupTemplatesNoContent') {
                     unset($r['template_data']);
                     unset($r['template_content']);
                 }
                 $templates[strtolower($r['template_name'])] = $r;
             } else {
                 if ($type == 'allNoContent') {
                     unset($r['template_content']);
                 }
                 $templates[$r['template_group']][strtolower($r['template_name'])] = $r;
             }
         }
     }
     ksort($templates);
     return $templates;
 }
 /**
  * Fetch a report
  *
  * @access	public
  * @param	int			Session ID
  * @return	array
  */
 public function fetchReport($diffSessionID)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $return = array('counts' => array('missing' => 0, 'changed' => 0), 'data' => array());
     //-----------------------------------------
     // Get data
     //-----------------------------------------
     $this->DB->build(array('select' => '*', 'from' => 'template_diff_changes', 'where' => 'diff_session_id=' . $diffSessionID, 'order' => 'diff_change_func_group ASC, diff_change_func_name ASC'));
     $this->DB->execute();
     while ($row = $this->DB->fetch()) {
         //-----------------------------------------
         // Gen data
         //-----------------------------------------
         $row['_key'] = $diffSessionID . ':' . $row['diff_change_func_group'] . ':' . $row['diff_change_func_name'];
         $row['_size'] = IPSLib::sizeFormat(IPSLib::strlenToBytes(IPSText::mbstrlen($row['diff_change_content'])));
         //-----------------------------------------
         // Diff type
         //-----------------------------------------
         if (!$row['diff_change_type']) {
             $row['_is'] = 'new';
             $return['counts']['missing']++;
         } else {
             $row['_is'] = 'changed';
             $return['counts']['changed']++;
         }
         //-----------------------------------------
         // Add data...
         //-----------------------------------------
         $return['data'][$row['diff_change_func_group']][$row['_key']] = $row;
     }
     return $return;
 }