Beispiel #1
0
 public function isFlooding()
 {
     $uid = GWF_Session::getUserID();
     $uname = GWF_Shoutbox::generateUsername();
     $euname = GDO::escape($uname);
     $table = GDO::table('GWF_Shoutbox');
     $max = $uid === 0 ? $this->module->cfgMaxPerDayGuest() : $this->module->cfgMaxPerDayUser();
     //		$cut = GWF_Time::getDate(GWF_Time::LEN_SECOND, time()-$this->module->cfgTimeout());
     //		$cnt = $table->countRows("shout_uname='$euname' AND shout_date>'$cut'");
     # Check captcha
     if ($this->module->cfgCaptcha()) {
         require_once GWF_CORE_PATH . 'inc/3p/Class_Captcha.php';
         if (!PhpCaptcha::Validate(Common::getPostString('captcha'), true)) {
             return GWF_HTML::err('ERR_WRONG_CAPTCHA');
         }
     }
     # Check date
     $timeout = $this->module->cfgTimeout();
     $last_date = $table->selectVar('MAX(shout_date)', "shout_uid={$uid} AND shout_uname='{$euname}'");
     $last_time = $last_date === NULL ? 0 : GWF_Time::getTimestamp($last_date);
     $next_time = $last_time + $timeout;
     if ($last_time + $timeout > time()) {
         return $this->module->error('err_flood_time', array(GWF_Time::humanDuration($next_time - time())));
     }
     # Check amount
     $today = GWF_Time::getDate(GWF_Date::LEN_SECOND, time() - $timeout);
     $count = $table->countRows("shout_uid={$uid} AND shout_date>='{$today}'");
     if ($count >= $max) {
         return $this->module->error('err_flood_limit', array($max));
     }
     # All fine
     return false;
 }
Beispiel #2
0
 public function displayNextChange()
 {
     if (NULL === ($last_change = $this->getVar('bmc_date'))) {
         return 'ERR 08815b';
     }
     $time = GWF_Time::getTimestamp($last_change);
     $wait = $time + self::CHANGE_TIMEOUT - time();
     return GWF_Time::humanDuration($wait);
 }
Beispiel #3
0
 public function displayTrackTime()
 {
     $date1 = $this->getVar('sitemas_firstdate');
     $date2 = $this->getVar('sitemas_date');
     $timestamp1 = GWF_Time::getTimestamp($date1);
     $timestamp2 = GWF_Time::getTimestamp($date2);
     $diff = $timestamp2 - $timestamp1;
     return GWF_Time::humanDuration($diff, 2);
 }
Beispiel #4
0
 public static function maySlap($slapper_id, $target_id, $timeout)
 {
     $slapper_id = (int) $slapper_id;
     $target_id = (int) $target_id;
     # No row yet
     if (false === ($row = self::table(__CLASS__)->selectFirstObject('*', "lsh_slapper={$slapper_id} AND lsh_target={$target_id}", 'lsh_date DESC'))) {
         return true;
     }
     $last_date = $row->getVar('lsh_date');
     $time = GWF_Time::getTimestamp($last_date);
     $remain = $time + $timeout - time();
     if ($remain > 0) {
         return $remain;
     }
     return true;
 }
Beispiel #5
0
 private function sanitize()
 {
     if (false === Common::getGet('no_session')) {
         return 'The mandatory parameter \'no_session\' is not set. Try \'&no_session=1\'.';
     }
     # Validate Date
     if (false !== ($date = Common::getGet('datestamp'))) {
         if (GWF_Time::isValidDate($date, false, GWF_Date::LEN_SECOND)) {
             $this->time = GWF_Time::getTimestamp($date);
         }
     }
     # Validate username
     if (false !== ($username = Common::getGet('username'))) {
         if (false === ($this->user = GWF_User::getByName($username))) {
             return GWF_HTML::err('ERR_UNKNOWN_USER');
         }
         if (false !== ($error = $this->module->isExcludedFromAPI($this->user, Common::getGet('password')))) {
             return $error;
         }
     }
     # Validate sitename
     if (false !== ($sitename = Common::getGet('sitename'))) {
         if (false === ($this->site = WC_Site::getByName($sitename)) && false === ($this->site = WC_Site::getByClassName($sitename))) {
             return $this->module->error('err_site');
         }
     }
     # Validate Limit
     if (in_array(Common::getGet('masterkey'), self::$masterKeys)) {
         $max_limit = PHP_INT_MAX;
     } elseif ($this->user === false && $this->site === false) {
         $max_limit = self::MAX_LIMIT_ALL;
     } else {
         $max_limit = self::MAX_LIMIT_SINGLE;
     }
     $this->limit = Common::clamp(Common::getGet('limit', self::DEFAULT_LIMIT), 1, $max_limit);
     //		if (!isset($no_block))
     //		{
     //			require_once 'core/module/WeChall/WC_API_Block.php';
     //			if (WC_API_Block::isBlocked())
     //			{
     //				return $this->module->error('err_api_block');
     //			}
     //		}
     return false;
 }
Beispiel #6
0
 public function calcTimeTaken($now)
 {
     return GWF_Time::getTimestamp($now) - GWF_Time::getTimestamp($this->getVar('csolve_1st_look'));
 }
Beispiel #7
0
 public function resetVotesSameSettings()
 {
     if ('' === ($expire_time = $this->getVar('vs_expire_date'))) {
         $expire_time = 0;
     } else {
         $expire_time = GWF_Time::getTimestamp($expire_time);
     }
     return $this->resetVotes($this->getMin(), $this->getMax(), $expire_time, $this->getOptions());
 }
Beispiel #8
0
<?php

$lang = array('en' => array('help' => 'Usage: %CMD% [<gwf_date>|<countrycode_iso1>]. Print the current bot-time, a gwf_date as uniox timestamp, or the current time in a country.', 'bot' => 'The bot\'s time is %s %s. Unix timestamp: %s', 'err_tz_stub' => 'I cannot parse timezones yet. I blame Hirsch.', 'err_date' => 'Invalid gwf_date!', 'out' => 'The date %s will have the unix timestamp of %d.'));
$plugin = Dog::getPlugin();
$message = $plugin->msg();
if ($message === '') {
    $timezone = date('T');
    $gdo_date = GWF_Time::getDate(GWF_Date::LEN_SECOND);
    $plugin->rply('bot', array(GWF_Time::displayDate($gdo_date), $timezone, time()));
} elseif (preg_match('/^[a-z]{2}$/i', $message)) {
    $plugin->rply('err_tz_stub');
} elseif (preg_match('/^[0-9]{2,21}$/', $message)) {
    if (!GWF_Time::isValidDate($message, false, strlen($message), 100000)) {
        $plugin->rply('err_date');
    } else {
        $plugin->rply('out', array(GWF_Time::displayDate($message), GWF_Time::getTimestamp($message)));
    }
} else {
    $plugin->showHelp();
}
Beispiel #9
0
 private function templateGraph()
 {
     $sites2 = $this->getSites2();
     //		echo 'User1';
     //		var_dump($this->user1->displayUsername());
     //		if ($this->user2 !== false) {
     //			echo 'User2';
     //			var_dump($this->user2->displayUsername());
     //		}
     //		echo 'Sites';
     //		var_dump($sites2);
     //		var_dump(sprintf('%d_%d_%d', Common::getGet('y'), Common::getGet('m'), Common::getGet('d')));
     //		echo 'Start';
     //		var_dump($this->start);
     //		echo 'End';
     //		var_dump($this->end);
     //		echo 'Icons';
     //		var_dump($this->withIcons);
     //		echo 'Numbers';
     //		var_dump($this->withNumbers);
     $dir = dirname(GWF_JPGRAPH_PATH) . '/';
     require_once $dir . 'jpgraph.php';
     require_once $dir . 'jpgraph_date.php';
     require_once $dir . 'jpgraph_line.php';
     require_once $dir . 'jpgraph_plotline.php';
     $xdata = array();
     $ydata = array();
     $ylast = array();
     $maxperc = 0;
     $db = gdo_db();
     $uid1 = $this->user1->getVar('user_id');
     $uid2 = $this->user2 === false ? 0 : $this->user2->getVar('user_id');
     //		$history = GWF_TABLE_PREFIX.'wc_user_history2';
     $start = GWF_Time::getTimestamp($this->start);
     $end = GWF_Time::getTimestamp($this->end) + GWF_Time::ONE_DAY;
     $no_data = true;
     $xdata[$uid1] = array();
     $ydata[$uid1] = array();
     $ylast[$uid1] = array();
     if ($uid2 === 0) {
         $where2 = '';
     } else {
         $where2 = " OR userhist_uid={$uid2}";
         $xdata[$uid2] = array();
         $ydata[$uid2] = array();
         $ylast[$uid2] = array();
     }
     require_once GWF_CORE_PATH . 'module/WeChall/WC_HistoryUser2.php';
     $history = GDO::table('WC_HistoryUser2');
     $where = "(userhist_uid={$uid1}{$where2}) AND userhist_date BETWEEN {$start} AND {$end}";
     $orderby = 'userhist_date ASC';
     if (false === ($result = $history->select('userhist_uid, userhist_sid, userhist_percent, userhist_date', $where, $orderby))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     //		$query = "SELECT userhist_uid, userhist_sid, userhist_percent, userhist_date FROM $history WHERE (userhist_uid=$uid1$where2) AND userhist_date BETWEEN $start AND $end ORDER BY userhist_date ASC";
     //		if (false === ($result = $db->queryRead($query))) {
     //			return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     //		}
     //		while (false !== ($row = $db->fetchRow($result)))
     while (false !== ($row = $history->fetch($result, GDO::ARRAY_N))) {
         $siteid = $row[1];
         if (!in_array($siteid, $sites2, true)) {
             continue;
             // site not wanted in graph...
         }
         $userid = $row[0];
         $percent = $row[2] / 100;
         $time = $row[3];
         if ($percent > $maxperc) {
             $maxperc = $percent;
         }
         if (!isset($xdata[$userid][$siteid])) {
             $xdata[$userid][$siteid] = array();
             $ydata[$userid][$siteid] = array();
             $ylast[$userid][$siteid] = 0;
             //				$first[$siteid] = $percent;
             if (!$this->withZoom) {
                 $xdata[$userid][$siteid][] = $start;
                 $ydata[$userid][$siteid][] = $percent;
             }
         }
         $xdata[$userid][$siteid][] = $time;
         $ydata[$userid][$siteid][] = $percent;
         $ylast[$userid][$siteid] = $percent;
         $no_data = false;
     }
     if (!$this->withZoom) {
         foreach (array_keys($ydata[$uid1]) as $siteid) {
             $xdata[$uid1][$siteid][] = $end;
             $ydata[$uid1][$siteid][] = $ylast[$uid1][$siteid];
         }
         if (isset($ydata[$uid2])) {
             foreach (array_keys($ydata[$uid2]) as $siteid) {
                 $xdata[$uid2][$siteid][] = $end;
                 $ydata[$uid2][$siteid][] = $ylast[$uid2][$siteid];
             }
         }
     }
     //		$xdata[$siteid][] = $end;
     //		$ydata[$siteid][] = $percent;
     //		$ylast[$siteid] = $percent;
     //		foreach ($sites2 as $siteid)
     //		{
     //			$xdata[$siteid][] = $end;
     //			$ydata[$siteid][] = isset($ylast[$siteid]) ;
     //		}
     //define the graph
     $dateformat = "d.M.y";
     $datemargin = strlen(date($dateformat)) * 11;
     //		$graph = new Graph($this->module->cfgGraphWidth()*2, $this->module->cfgGraphHeight()*2);
     $graph = new Graph($this->width, $this->height);
     if ($no_data) {
         $graph->SetScale('textint', 0, 100, 0, 1);
     } else {
         $graph->SetScale('datlin', 0, 100);
         $graph->xaxis->scale->SetDateFormat($dateformat);
     }
     $graph->SetColor(array(238, 238, 238));
     $graph->SetMarginColor(array(208, 211, 237));
     $graph->title->Set($this->getGraphTitle());
     $graph->yaxis->title->Set($this->module->lang('percentage'));
     $graph->SetShadow();
     $graph->xaxis->SetLabelAngle(90);
     $graph->img->SetMargin(40, 170, 20, $datemargin);
     //		$graph->img->SetMargin(40, 140, 0, $datemargin);
     $graph->legend->Pos(0.015, 0.05, "right", "top");
     $weights = array($uid1 => 3, $uid2 => 1);
     $labeled = array();
     //make a line for each site (and user)
     foreach ($ydata as $userid => $ydata2) {
         $curr_weight = $weights[$userid];
         foreach ($ydata2 as $siteid => $data) {
             //			var_dump($data);
             if (!isset($this->sites[$siteid])) {
                 continue;
             }
             $site = $this->sites[$siteid];
             $site instanceof WC_Site;
             $lineplot = new LinePlot($data, $xdata[$userid][$siteid]);
             list($color, $style) = $this->getColorAndStyle($site);
             $lineplot->SetStyle($style);
             $lineplot->SetColor($color);
             $lineplot->SetWeight($curr_weight);
             if ($this->withNumbers) {
                 $lineplot->value->Show();
             }
             if ($this->withIcons) {
                 $path = 'dbimg/logo_gif/' . $siteid . '.gif';
                 if (is_readable($path)) {
                     $lineplot->mark->SetType(MARK_IMG, $path, 0.5);
                 }
             }
             if (!in_array($siteid, $labeled, true)) {
                 $lineplot->SetLegend($site->getVar('site_name'));
                 $labeled[] = $siteid;
             }
             $graph->Add($lineplot);
         }
     }
     //		$graph->img->SetAntiAliasing();
     if ($no_data) {
         if (count($this->sites) === 0) {
             $text = $this->module->lang('err_no_sites');
         } else {
             $text = $this->module->lang('err_graph_empty');
         }
         $txt = new Text($text);
         //			$txt->SetFont(FF_ARIAL,FS_NORMAL,18);
         $txt->SetColor("#0000ff");
         $txt->SetPos(0.45, 0.45, 'center', 'center');
         $graph->AddText($txt);
     }
     $graph->Stroke();
     die;
 }
Beispiel #10
0
 private function getLastPostTime($user)
 {
     if (false === ($result = GDO::table('GWF_ForumPost')->selectVar('MAX(post_date)'))) {
         return 0;
     }
     return GWF_Time::getTimestamp($result);
 }
Beispiel #11
0
 private function graphUserLevel($type)
 {
     $dir = dirname(GWF_JPGRAPH_PATH) . '/';
     require_once $dir . 'jpgraph.php';
     require_once $dir . 'jpgraph_date.php';
     require_once $dir . 'jpgraph_line.php';
     require_once $dir . 'jpgraph_plotline.php';
     if (false === ($user = GWF_User::getByName(Common::getGet('username', '')))) {
         return $this->graphError(GWF_HTML::lang('ERR_UNKNOWN_USER'));
     }
     if (false !== ($vs = Common::getGet('vs'))) {
         $vs = GWF_User::getByName($vs);
     }
     $uh = GWF_TABLE_PREFIX . 'wc_user_history2';
     switch ($type) {
         case 'userhist_rank':
             $type2 = 'rank';
             break;
         case 'userhist_totalscore':
             $type2 = 'totalscore';
             break;
         default:
             die('Unknown Type');
     }
     if ($vs === false) {
         $graphtitle = $this->module->lang('alt_graph_' . $type2, array($user->displayUsername()));
     } else {
         $graphtitle = $this->module->lang('alt_graph_' . $type2 . '_vs', array($user->displayUsername(), $vs->displayUsername()));
     }
     $db = gdo_db();
     $uid = $user->getID();
     $query = "SELECT userhist_date,{$type} FROM {$uh} WHERE userhist_uid={$uid} ORDER BY userhist_date ASC";
     if (false === ($result = $db->queryRead($query))) {
         die(GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)));
     }
     $invert = $type2 === 'rank';
     $highestValue = 0;
     //		$lowestValue = 2111222333;
     $xdata = array();
     $ydata = array();
     if ($type2 === 'totalscore') {
         $xdata[] = GWF_Time::getTimestamp($user->getVar('user_regdate'));
         $ydata[] = 0;
         //			$highestValue = 20;
     } elseif ($type2 === 'rank') {
         $xdata[] = GWF_Time::getTimestamp($user->getVar('user_regdate'));
         $ydata[] = 0;
         //			$del = GWF_User::DELETED;
         //			$ydata[] = -GDO::table('GWF_User')->countRows("user_options&$del=0");
         //			$highestValue = -$ydata[0];
     }
     while (false !== ($row = $db->fetchRow($result))) {
         $time = intval($row[0]);
         $xdata[] = $time;
         $value = intval($row[1]);
         $ydata[] = $invert ? -$value : $value;
         $highestValue = $value > $highestValue ? $value : $highestValue;
         //			$lowestValue = $value < $lowestValue ? $value : $lowestValue;
     }
     $db->free($result);
     // Now the Opponent
     if ($vs !== false) {
         $uid2 = $vs->getID();
         $query = "SELECT userhist_date,{$type} FROM {$uh} WHERE userhist_uid={$uid2} ORDER BY userhist_date ASC";
         if (false === ($result = $db->queryRead($query))) {
             die(GWF_HTML::lang('ERR_DATABASE', array(__FILE__, __LINE__)));
         }
         $xdata2 = array();
         $ydata2 = array();
         if ($type2 === 'totalscore') {
             $xdata2[] = GWF_Time::getTimestamp($vs->getVar('user_regdate'));
             $ydata2[] = 0;
         } elseif ($type2 === 'rank') {
             $xdata2[] = GWF_Time::getTimestamp($vs->getVar('user_regdate'));
             $ydata2[] = 0;
             //				$del = GWF_User::DELETED;
             //				$ydata2[] = GDO::table('GWF_User')->countRows("user_options&$del=0");
             //				$highestValue = -$ydata2[0];
         }
         while (false !== ($row = $db->fetchRow($result))) {
             $time = intval($row[0]);
             $xdata2[] = $time;
             $value = intval($row[1]);
             $highestValue = $value > $highestValue ? $value : $highestValue;
             //				$lowestValue = $value < $lowestValue ? $value : $lowestValue;
             $ydata2[] = $invert ? -$value : $value;
         }
         $db->free($result);
     }
     if ($type2 === 'rank') {
         $ydata[0] = -$highestValue;
         $ydata2[0] = -$highestValue;
     }
     //		$this->max_rank = $highestValue;
     $dateformat = "M.y";
     $datemargin = strlen(date($dateformat)) * 11;
     //define the graph
     $graph = new Graph($this->module->cfgGraphWidth(), $this->module->cfgGraphHeight());
     if ($invert) {
         $graph->SetScale('datlin', -$highestValue, -1);
     } else {
         $graph->SetScale('datlin', 0, 1.05 * $highestValue);
     }
     $graph->title->Set($graphtitle);
     //		$graph->title->SetFont(FF_ARIAL, FS_NORMAL, 12);
     $graph->SetColor(array(238, 238, 238));
     $graph->SetMarginColor(array(208, 211, 237));
     $graph->SetShadow();
     $graph->xaxis->SetLabelAngle(90);
     //		$graph->xaxis->SetTickPositions($xticks, NULL, $xdataarray);
     $graph->xaxis->scale->SetDateFormat($dateformat);
     $graph->img->SetMargin(50, 40, 40, $datemargin);
     $graph->legend->Pos(0.011, 0.005, "right", "top");
     # Add plots
     $lineplot = new LinePlot($ydata, $xdata);
     $lineplot->SetColor("blue");
     $lineplot->SetWeight(2);
     $lineplot->SetLegend($user->getVar('user_name'));
     $graph->Add($lineplot);
     if ($vs !== false) {
         $lineplot = new LinePlot($ydata2, $xdata2);
         $lineplot->SetColor("red");
         $lineplot->SetWeight(2);
         $lineplot->SetLegend($vs->getVar('user_name'));
         $graph->Add($lineplot);
     }
     if ($invert) {
         $graph->yaxis->SetLabelFormatCallback(array($this, 'negation_callback'));
         $graph->xaxis->SetLabelSide(SIDE_DOWN);
         $graph->xaxis->setPos('min');
         //			$graph->yaxis->SetValueFormatCallback(array($this, 'negation_callback'));
     }
     GWF_HTTP::noCache();
     // Display the graph
     //		$graph->img->SetAntiAliasing();
     $graph->Stroke();
     die;
 }