abushyk2

Untitled

Apr 8th, 2020
218
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getCatCount($catID) {
  2.     $data = array();
  3.     $cache_file = SITEBILL_DOCUMENT_ROOT.'/cache/cache.topiccounts.txt';
  4.  
  5.     if(file_exists($cache_file) && (time()-filemtime($cache_file))<CACHE_LIFETIME){
  6.         $data = unserialize(file_get_contents($cache_file));
  7.     }else{
  8.         if(file_exists($cache_file)){
  9.             unlink($cache_file);
  10.         }
  11.                
  12.         $DBC=DBC::getInstance();
  13.         $query = 'SELECT COUNT(id) AS _cnt, topic_id FROM '.DB_PREFIX.'_data WHERE active = 1 GROUP BY topic_id';
  14.         if($stmt){
  15.             while($ar=$DBC->fetch($stmt)){
  16.                 $data[$ar['topic_id']] = $ar['_cnt'];
  17.             }
  18.         }          
  19.  
  20.         $f=fopen($cache_file, 'w');
  21.         fwrite($f, serialize($data));
  22.         fclose($f);
  23.     }
  24.    
  25.     if(isset($data[$catID])){
  26.         return $data[$catID];
  27.     }
  28.     return 0;
  29. }
RAW Paste Data