コード例 #1
0
 public function selectView()
 {
     // load a memcache object
     $memcache = MemcacheFactory::construct('query_memcache');
     // reduce path to just a dir structure. Remove funny stuff...
     // .. //
     $invalid_path_items = array('//', '..');
     $path = str_replace($invalid_path_items, '', $this->get('path'));
     $full_path = DIR_PUBLIC_HTML . $this->base_path . $path;
     $extension_stub_pos = strripos($full_path, '.');
     $extn = substr($full_path, -1 * (strlen($full_path) - $extension_stub_pos));
     $this->outputHeaders($extn, $full_path);
     // if we have a key, use it
     if (!SC::get('board_config.disable_query_memcache')) {
         $output = $memcache->get($this->getKeyFromPath($full_path));
     }
     if ($output) {
         echo '/' . '* cache=true *' . '/' . "\n";
         echo $output;
         exit;
     }
     $comments = array('cache=false');
     // check for rollup packages
     if (strpos($path, 'pkg-') !== false) {
         $comments[] = 'pkg=true';
         $output = $this->getRollupPackage($path);
     }
     // only minify in production
     // if (!SC::get('board_config.local_domain_enable') && $extn == '.js') {
     //     $comments[] = 'mini=true';
     //     $output = JSMin::minify($output);
     // }
     // store to memcache
     if (!SC::get('board_config.disable_query_memcache') && $memcache->add('key' . $this->getKeyFromPath($full_path), 1)) {
         $comments[] = 'cachewrite=true';
         $memcache->set($this->getKeyFromPath($full_path), $output, MEMCACHE_COMPRESSED, 86400);
     }
     echo '/' . '* ' . implode(';', $comments) . ' *' . '/' . "\n";
     echo $output;
     exit;
 }
コード例 #2
0
 function getCacheData()
 {
     $this->o->append('Default.debug.steps', __CLASS__ . '.' . __FUNCTION__);
     // check memcache for the data.
     $memcache = MemcacheFactory::construct('query_memcache');
     foreach ($this->ids as $id) {
         $memcache_keys[$id] = 'UserStatusBar_' . $id;
     }
     $cache = $memcache->get($memcache_keys);
     // check memcache for which keys we got and which we need.
     $records_found = $records_missing = array();
     foreach ($cache as $mem_cache) {
         $records_found[] = $mem_cache['user_id'];
     }
     // figure out which we still need to get.
     $records_missing = array_diff($records_found, $this->ids);
     if (count($records_missing) == 0 && count($this->ids) == count($cache)) {
         $this->setResponse($cache);
         return TRUE;
     }
     $this->set('missing', $records_missing);
     // we have a few queries to get the correct dataset.
     $dao = DAOFactory::create('users');
     $dao->setWhat("`user_id`, `username`, `user_allow_viewonline`, `user_session_time`, `user_journal_id`, " . "`user_receive_pm`, `user_viewemail`, `user_email`, `user_vend`, `user_website`, `user_icq`, " . "`user_aim`,`user_msnm`, `user_yim`");
     $dao->byIds($records_missing);
     $rs = $dao->execute();
     if (!$rs->isSuccess()) {
         throw new CircuitDatabaseException('Unable to retrieve userdata for statusbar.', $rs);
     }
     $newdata = array();
     while ($row = $rs->fetchRow(DB_ASSOC)) {
         $newdata[$row['user_id']] = $row;
     }
     // also get the home location and house preferences
     $dao = DAOFactory::create('gaiahousing');
     $dao->setWhat("`user_id`, `home_zip`, `home_privacy`");
     $dao->byIds($records_missing);
     $rs = $dao->execute();
     if (!$rs->isSuccess()) {
         throw new CircuitDatabaseException('Unable to retrieve housingdata for statusbar.', $rs);
     }
     while ($row = $rs->fetchRow(DB_ASSOC)) {
         $newdata[$row['user_id']]['home_zip'] = $row['home_zip'];
         $newdata[$row['user_id']]['home_privacy'] = $row['home_privacy'];
     }
     // go through each user';s data and get what's appropriate.
     $me = SC::get('userdata.user_id');
     $cutoff = SC::get('board_config.time_now') - 600;
     foreach ($newdata as $uid => $user) {
         // init the stat array
         $stats = array();
         // online offline status. will get edited later.
         if (isset($user['user_session_time']) && $user['user_session_time'] > $cutoff) {
             $stats['status'] = 'online';
         } else {
             $stats['status'] = 'offline';
         }
         // profile
         $stats['profile_url'] = append_sid("/profile/index.php?view=profile.ShowProfile&item=" . $uid);
         // housing
         if (isset($user['home_zip'])) {
             $stats['home_zip'] = $user['home_zip'];
             $stats['home_privacy'] = $user['home_privacy'];
         }
         // journal
         if (isset($user['user_journal_id'])) {
             $stats['journal_id'] = $user['user_journal_id'];
             $stats['journal_view'] = $user['journal_view'];
         }
         // private messages
         if (isset($user['user_receive_pm'])) {
             $stats['pm_receive'] = $user['user_receive_pm'];
         }
         // guilds
         if (isset($user['user_guild_count'])) {
             $stats['guilds_url'] = append_sid("/guilds/index.php?gmode=search&user_id=" . $uid);
         }
         // store (vend)
         if (isset($user['user_vend'])) {
             $stats['vend_url'] = append_sid('http://' . VEND_SERVER . "/gaia/vend.php?mystore=" . $user_id);
         }
         // trade
         $stats['trade_url'] = append_sid('http://' . BANK_SERVER . "/gaia/bank.php?mode=trade&uid=" . $user_id);
         // www
         if (isset($user['user_website'])) {
             $stats['www_url'] = external_url($user['user_website']);
         }
         // aim
         if (isset($user['user_aim'])) {
             $stats['aim_url'] = 'aim:goim?screenname=' . htmlspecialchars($user['user_aim']) . '&message=FHello+Are+you+there?';
         }
         // icq
         if (isset($user['user_icq'])) {
             $stats['icq_url'] = external_url('http://wwp.icq.com/scripts/search.dll?to=' . htmlspecialchars($user['user_icq']));
         }
         // yim
         if (isset($user['user_yim'])) {
             $stats['yim_url'] = external_url('http://edit.yahoo.com/config/send_webmesg?.target=' . htmlspecialchars($user['user_yim']) . '&.src=pg');
         }
         // msn
         if (isset($user['user_msnm'])) {
             $stats['msnm_url'] = append_sid("/profile/index.php?view=profile.ShowProfile&item=" . $uid);
         }
         // add to memcache and cache
         $memcache->set($memcache_keys[$uid], $stats, MEMCACHE_COMPRESSED, 300);
         $cache[$uid] = $stats;
     }
     // set into the observer for further usage
     $this->set('cachedata', $cache);
     return true;
 }