Example #1
0
 /**
  * Someone requested chat stuff.
  * @param Module_Chat $module
  * @return unknown_type
  */
 public static function onRequest(Module_Chat $module)
 {
     //		GWF_ChatMsg::cleanupTable($module);
     $time = time();
     $sessid = GWF_Session::getSessID();
     if (false === ($nick = $module->getNickname())) {
         $nick = self::getRandomNickS($sessid);
     }
     $table = self::table(__CLASS__);
     if (false === ($row = $table->getRow($sessid))) {
         # Unknown row
         $row = new self(array('chaton_sessid' => $sessid, 'chaton_name' => $nick, 'chaton_timejoin' => $time, 'chaton_timeaccess' => $time));
         $row->replace();
     } else {
         if ($row->getVar('chaton_timeleft') > 0) {
             $row->saveVars(array('chaton_timejoin' => $time, 'chaton_timeaccess' => $time, 'chaton_timeleft' => 0));
         } else {
             if ($row->getVar('chaton_name') !== $nick) {
                 $row->saveVars(array('chaton_timeleft' => $time));
                 $row = new self(array('chaton_sessid' => $sessid, 'chaton_name' => $nick, 'chaton_timejoin' => $time, 'chaton_timeaccess' => $time));
                 $row->replace();
             } else {
                 $row->saveVars(array('chaton_timeaccess' => $time));
             }
         }
     }
     self::cleanupTable($module);
     return '';
 }
Example #2
0
 /**
  * Get a counter and count up by one.
  * @param string $key
  * @return string the value
  */
 public static function getAndCount($key, $by = 1)
 {
     if (false === ($row = self::table(__CLASS__)->getRow($key))) {
         $row = new self(array('count_key' => $key, 'count_value' => $by));
         $row->insert();
     } else {
         $row->increase('count_value', $by);
     }
     return $row->getVar('count_value');
 }
Example #3
0
 public static function populateFile($basedir, $fullpath)
 {
     $mtime = GWF_Time::getDate(GWF_Date::LEN_SECOND, filemtime($fullpath));
     if (false === ($row = self::getByPath($fullpath))) {
         $row = new self(array('vsf_id' => 0, 'vsf_dir' => $basedir, 'vsf_path' => $fullpath, 'vsf_hash' => self::hash(file_get_contents($fullpath)), 'vsf_date' => $mtime));
         return $row->insert();
     }
     if ($row->getVar('vsf_date') < $mtime) {
         return $row->saveVars(array('vsf_hash' => self::hash(file_get_contents($fullpath)), 'vsf_date' => $mtime));
     }
     return true;
 }
Example #4
0
 public static function onViewed(GWF_User $user)
 {
     $userid = $user->getID();
     $av = $user->getVar('user_avatar_v');
     if (false === ($row = self::getByID($userid))) {
         $row = new self(array('ag_uid' => $userid, 'ag_hits' => 1, 'ag_version' => $av));
         if (false === $row->insert()) {
             return false;
         }
         $row->setVar('ag_uid', $user);
         return true;
     }
     if ($row->getVar('ag_version') !== $av) {
         return $row->saveVars(array('ag_hits' => 1, 'ag_version' => $av));
     }
     return $row->increase('ag_hits', 1);
 }
Example #5
0
 public static function populateFile($basedir, $fullpath, $modulename = true, $designname = true)
 {
     if (self::isBlacklisted($fullpath)) {
         return true;
     }
     if (false === ($mtimeOld = GWF_Time::getDate(GWF_Date::LEN_SECOND, @filemtime($fullpath)))) {
         echo GWF_HTML::err('ERR_FILE_NOT_FOUND', array($fullpath));
         return false;
     }
     # Get modulename
     if (is_string($modulename)) {
         // keep
     } elseif ($basedir === 'modules') {
         $modulename = substr($fullpath, 8);
         $modulename = Common::substrUntil($modulename, '/');
     } else {
         $modulename = '';
     }
     # Get designname
     if (is_string($designname)) {
         // keep
     }
     if (preg_match('#.*(^|/)tpl/([^/]+)/.+$#D', $fullpath, $matches)) {
         $designname = $matches[2];
     } else {
         $designname = '';
     }
     self::$size_unpacked += filesize($fullpath);
     if (false === ($row = self::getByPath($fullpath))) {
         //			echo GWF_HTML::message('New File Detected', 'New File: '.$fullpath);
         $row = new self(array('vsf_id' => 0, 'vsf_dir' => $basedir, 'vsf_path' => $fullpath, 'vsf_module' => $modulename, 'vsf_design' => $designname, 'vsf_hash' => self::hash(file_get_contents($fullpath)), 'vsf_date' => $mtimeOld, 'vsf_size' => filesize($fullpath)));
         return $row->insert();
     }
     $mtimeDB = $row->getVar('vsf_date');
     if ($mtimeOld != $mtimeDB) {
         //			echo GWF_HTML::message('New File Detected', 'Updated: '.$fullpath. 'OLD='.$mtimeOld.' | DB='.$mtimeDB);
         return $row->saveVars(array('vsf_hash' => self::hash(file_get_contents($fullpath)), 'vsf_date' => $mtimeOld, 'vsf_size' => filesize($fullpath)));
     }
     return true;
 }
Example #6
0
 private static function createSession($create_etag = false)
 {
     $sessid = GWF_Random::randomKey(self::SESS_ENTROPY);
     $session = new self(array('sess_id' => 0, 'sess_sid' => $sessid, 'sess_user' => NULL, 'sess_data' => NULL, 'sess_time' => time(), 'sess_ip' => NULL, 'sess_lasturl' => NULL));
     if (false === $session->insert()) {
         return false;
     }
     self::$SESSION = $session;
     //		if ($create_etag)
     //		{
     //			self::setETag($session->getVar('sess_id'), 0, $sessid);
     //		}
     self::setCookies($session->getVar('sess_id'), 0, $sessid);
     return true;
 }