Example #1
0
 public static function core($drop = false, &$success)
 {
     $db = gdo_db();
     $tables = self::get_core_tables();
     $success = true;
     $ret = '<br/><br/>';
     foreach ($tables as $classname) {
         $ret .= sprintf("Installing %s table ... ", $classname);
         if (false === ($result = GDO::table($classname)->createTable($drop))) {
             #error
             $ret .= '<b class="gwfinstallno">FAILED!<br/>' . PHP_EOL;
             $success = false;
         } else {
             #success
             $ret .= '<b class="gwfinstallyes">OK</b><br/>' . PHP_EOL;
         }
     }
     $ret .= '<br/>';
     /** Try to set a birthdate **/
     if (false === GWF_Settings::getSetting('gwf_site_birthday', false)) {
         $ret .= sprintf("Setting up a birthdate ... %s.", date('Ymd'));
         if (false === GWF_Settings::setSetting('gwf_site_birthday', date('Ymd'))) {
             $ret .= '<b class="gwfinstallno">Cannot set site birthdate.<br/>' . PHP_EOL;
             $success = false;
         }
     }
     return $ret;
 }
Example #2
0
 private static function initHooks()
 {
     if (self::$HOOKS === true) {
         if (false !== ($hooks = GWF_Settings::getSetting('gwf3_hooks', false))) {
             self::$HOOKS = unserialize($hooks);
         } else {
             self::$HOOKS = array();
         }
     }
 }
Example #3
0
 private function saveStoreSettings(array $data)
 {
     if (count($data) === 0) {
         $s = NULL;
     } else {
         $data = array_values($data);
         $s = serialize($data);
     }
     return GWF_Settings::setSetting($this->getStoreSettingsName(), $s);
 }
Example #4
0
function dog_svn_info($key, $repo, $user = '', $pass = '', $displayurl = '', $channels = array())
{
    $keyshort = $key;
    $key = 'DOG_SVNINFO_REVISION_' . $key;
    $svninfo = new GWF_SvnInfo();
    $svninfo->setRepository($repo, $user, $pass);
    if (0 == ($currentRevision = $svninfo->getCurrentRevision())) {
        return Dog_Log::debug('Fetching current revision failed.');
    }
    $lastRevision = GWF_Settings::getSetting($key, $currentRevision);
    if ($currentRevision <= $lastRevision) {
        GWF_Settings::setSetting($key, $currentRevision);
        return;
    }
    $svnlog = $svninfo->getLog($lastRevision + 1, $currentRevision);
    foreach ($svnlog as $entry) {
        $msg = sprintf('[%s] New revision %s by %s: %s', $keyshort, $entry['version-name'], $entry['creator-displayname'], html_entity_decode($entry['comment']));
        if ($displayurl != '') {
            $msg .= ' ( ' . str_replace('%REV%', $entry['version-name'], $displayurl) . ' )';
        }
        if (count($channels) === 0) {
            # To all servers in the main channel
            foreach (DOG::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels = $server->getChannels();
                if (count($channels) > 0) {
                    $channel = array_shift($channels);
                    $channel = $channel->getVar('chan_name');
                    $server->sendPRIVMSG($channel, $msg);
                }
            }
        } else {
            # To all servers in matching channels
            foreach (DOG::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels_now = $server->getChannels();
                foreach ($channels_now as $channel) {
                    $channel instanceof Dog_Channel;
                    $channel = $channel->getName();
                    foreach ($channels as $c) {
                        if (!strcasecmp($c, $channel)) {
                            $server->sendPRIVMSG($channel, $msg);
                        }
                    }
                }
            }
        }
    }
    GWF_Settings::setSetting($key, $currentRevision);
}
Example #5
0
 public function templateShow()
 {
     if (false === ($news = GWF_News::getNewsQuick($this->module->getNewsPerPage(), $this->catid, $this->page, GWF_Language::getCurrentID()))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     $date = count($news) > 0 ? $news[0]['news_date'] : GWF_Settings::getSetting('gwf_site_birthday') . '090000';
     $date = GWF_Time::displayDate($date);
     GWF_Website::setPageTitle($this->module->lang('pt_news', array($date)));
     GWF_Website::setMetaTags($this->module->lang('mt_news', array($date)));
     GWF_Website::setMetaDescr($this->module->lang('md_news', array($this->page, $this->nPages)));
     //		$mod_forum = GWF_Module::getModule('Forum', true);
     $tVars = array('news' => $news, 'titles' => GWF_News::getTitlesQuick($this->catid, GWF_Language::getCurrentID()), 'cats' => GWF_News::getCategories(), 'catid' => $this->catid, 'cat' => GWF_HTML::display($this->catTitle), 'page_menu' => $this->getPageMenu(), 'page' => $this->page, 'can_sign' => $this->module->canSignNewsletter(GWF_Session::getUser()), 'href_sign_news' => $this->module->hrefSignNewsletter(), 'may_add' => GWF_User::isAdminS() || GWF_User::isStaffS(), 'href_add' => $this->module->hrefAddNews());
     return $this->module->templatePHP('show.php', $tVars);
 }
Example #6
0
 /**
  * Cache Challenge Tag-Cloud, as it is only updated when a new challenge is added. 
  * @return unknown_type
  */
 public function cacheChallTags()
 {
     $tags = array();
     $challs = GDO::table('WC_Challenge')->selectObjects();
     foreach ($challs as $chall) {
         $chall instanceof WC_Challenge;
         $t = explode(',', trim($chall->getVar('chall_tags'), ','));
         $temp = array();
         foreach ($t as $st) {
             if ('' === ($st = trim($st))) {
                 continue;
             }
             if (!isset($tags[$st])) {
                 $tags[$st] = 0;
             }
             $tags[$st]++;
             $temp[] = $st;
         }
         $chall->saveVar('chall_tags', ',' . implode(',', $temp) . ',');
     }
     ksort($tags);
     $save = '';
     foreach ($tags as $tag => $count) {
         $save .= ':' . $tag . '-' . $count;
     }
     return GWF_Settings::setSetting('WC_CHALL_CLOUD', substr($save, 1));
     //		return $this->saveModuleVar('wc_ctags', substr($save, 1));
 }
Example #7
0
$lines = explode("\n", $content);
foreach ($lines as $line) {
    if ('' === ($line = trim($line))) {
        continue;
    }
    # Fetch line
    list($threadid, $lastdate, $lock, $url, $username, $title) = explode('::', $line);
    # Duplicate output?
    if ($lastdate === $date && strpos($known, ',' . $threadid . ',') !== false) {
        continue;
    }
    # Is it private?
    $lock = $lock === '0' ? '' : ' locked';
    # does the date change?
    if ($latest_date !== $lastdate) {
        $latest_date = $lastdate;
        $new_known = ',';
    }
    # Mark this thread as known for this datestamp
    $new_known .= $threadid . ',';
    # Output message
    if ($lock === ' locked') {
        $server->sendPrivmsg($channel, sprintf('[WeChall-Forum] New%s post: %s', $lock, $url));
    } else {
        $server->sendPrivmsg($channel, sprintf('[WeChall-Forum] New post by %s in %s: %s', $username, $title, $url));
    }
}
# Save state
GWF_Settings::setSetting('WC_FORUM_DATE', $lastdate);
GWF_Settings::setSetting('WC_FORUM_LAST', $new_known);
Example #8
0
function dog_wc_solvers($key, $name, $url, $channels = array(), $max_solvercount = 100, $format)
{
    # Date we want to query
    $lastdate = GWF_Settings::getSetting('DOG_SOLVERS_DATE_' . $key, '');
    if (strlen($lastdate) !== 14) {
        $lastdate = date('YmdHis');
        GWF_Settings::setSetting('DOG_SOLVERS_DATE_' . $key, $lastdate);
    }
    $lastpair = GWF_Settings::getSetting('DOG_SOLVERS_PAIR_' . $key, '');
    # Query URL
    $url = str_replace(array('%DATE%'), array($lastdate), $url);
    // 	echo $url.PHP_EOL;
    GWF_HTTP::setTimeout(3);
    GWF_HTTP::setConnectTimeout(2);
    if (false === ($content = GWF_HTTP::getFromURL($url))) {
        return;
    }
    GWF_HTTP::setTimeout();
    GWF_HTTP::setConnectTimeout();
    // 	echo $content.PHP_EOL;
    # Nothing happened
    if ($content === '') {
        return;
    }
    $lines = explode("\n", $content);
    $changed = false;
    $badlines = 0;
    $latestdate = $lastdate;
    $firstpair = false;
    foreach ($lines as $line) {
        // 		echo "$line\n";
        if ('' === ($line = trim($line))) {
            continue;
        }
        $thedata = explode('::', $line);
        if (count($thedata) !== 12) {
            $badlines++;
            echo 'Invalid line in dog_wc_solvers: ' . $line . PHP_EOL;
            if ($badlines > 3) {
                echo "BAD URL IS: {$url}\n";
                return;
            }
            continue;
        }
        $badlines = 0;
        $thedata = array_map('unescape_csv_like', $thedata);
        # Fetch line
        # uid::cid::solve_date::1st_look::viewcount::options::time_taken::tries::username::challname::solvecount::url
        list($uid, $cid, $solvedate, $firstdate, $views, $options, $timetaken, $tries, $username, $challname, $solvercount, $challurl) = $thedata;
        if (strlen($solvedate) !== 14) {
            echo "Dateformat in {$url} is invalid: {$solvedate}\n";
            return false;
        }
        $latestdate = $solvedate;
        $pair = "{$uid}:{$cid}";
        if ($firstpair === false) {
            $firstpair = $pair;
        }
        if ($pair === $lastpair) {
            break;
        }
        if ($solvercount > $max_solvercount) {
            continue;
        }
        $msg = sprintf($format, $name, $username, $challname, $solvercount, $challurl);
        if (count($channels) === 0) {
            # To all servers in the main channel
            foreach (Dog::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels = $server->getChannels();
                if (count($channels) > 0) {
                    $channel = array_shift($channels);
                    $channel = $channel->getName();
                    $server->sendPRIVMSG($channel, $msg);
                }
            }
        } else {
            # To all servers in matching channels
            foreach (Dog::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels_now = $server->getChannels();
                foreach ($channels_now as $channel) {
                    $channel instanceof Dog_Channel;
                    $channel = $channel->getName();
                    echo $channel . PHP_EOL;
                    foreach ($channels as $c) {
                        if (!strcasecmp($c, $channel)) {
                            $server->sendPRIVMSG($channel, $msg);
                        }
                    }
                }
            }
        }
        $changed = true;
    }
    # Save state
    if ($changed) {
        GWF_Settings::setSetting('DOG_SOLVERS_DATE_' . $key, $latestdate);
        GWF_Settings::setSetting('DOG_SOLVERS_PAIR_' . $key, $firstpair);
    }
}
Example #9
0
function math_pyramid_check(WC_Challenge $chall, $formula, $maxlen, $precision = 4)
{
    error_reporting(E_ERROR);
    GWF_Debug::setDieOnError(false);
    GWF_Debug::setMailOnError(false);
    $len = strlen($formula);
    $tests = array('0' => 0, '1' => 0.2357, '3.14' => 7.2971, '10' => 235.7023, '100' => 235702.2604);
    $eval = new EvalMath();
    $fa = "f(a) = {$formula}";
    if (false === $eval->evaluate($fa)) {
        echo GWF_HTML::error('Math Pyramid', $chall->lang('err_formula', array(htmlspecialchars($fa))));
        return false;
    }
    GWF_Debug::setDieOnError(true);
    GWF_Debug::setMailOnError(true);
    $back = GWF_HTML::message('Math Pyramid', $chall->lang('msg_formula', array(htmlspecialchars($fa))), false);
    $correct = 0;
    foreach ($tests as $a => $result) {
        $result2 = $eval->evaluate("f({$a})");
        $result = sprintf('%.0' . $precision . 'f', $result);
        $result2 = sprintf('%.0' . $precision . 'f', $result2);
        if ($result === $result2) {
            $back .= GWF_HTML::message('Math Pyramid', $chall->lang('msg_correct', array($a, $result2, $result)), false);
            $correct++;
        } else {
            $back .= GWF_HTML::error('Math Pyramid', $chall->lang('err_wrong', array($a, $result2, $result)), false);
        }
    }
    require_once GWF_CORE_PATH . 'module/WeChall/WC_MathChall.php';
    if ($chall->getID() > 0 && $correct === count($tests)) {
        if (false === WC_MathChall::insertSolution($chall->getID(), GWF_Session::getUserID(), $formula)) {
            $back .= GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
        } else {
            $back .= GWF_HTML::message('Math Pyramid', WC_HTML::lang('msg_wmc_sol_inserted', array($len, WC_MathChall::getLimitedHREF($chall, $len))), false);
        }
    }
    # Check Len
    if ($len > $maxlen) {
        $back .= GWF_HTML::error('Math Pyramid', $chall->lang('err_too_long', array($len, $maxlen)), false);
    }
    echo $back;
    if ($correct === count($tests) && $len <= $maxlen) {
        if ($len < $maxlen) {
            echo GWF_HTML::message('Math Pyramid', $chall->lang('msg_new_record', array($len, $maxlen)), false);
            GWF_Settings::setSetting('WC_MATH_PYRAMID', $len);
        }
        $chall->onChallengeSolved(GWF_Session::getUserID());
    }
}
Example #10
0
 public static function getBirthdate()
 {
     return GWF_Settings::getSetting('gwf_site_birthdate', date('Ymd'));
 }
Example #11
0
function dog_wc_forum($key, $name, $url, $channels = array(), $limit = 5, $onlygids = false, $skipgids = false)
{
    # Date we want to query
    $date = GWF_Settings::getSetting('DOG_FORUM_DATE_' . $key, date('Ymd000000'));
    if (strlen($date) !== 14) {
        $date = date('Ymd000000');
    }
    # We already know these threads for the current data stored
    $known = GWF_Settings::getSetting('DOG_FORUM_LAST_' . $key, ',');
    # Query URL
    $url = str_replace(array('%DATE%', '%LIMIT%'), array($date, $limit), $url);
    //	echo $url.PHP_EOL;
    GWF_HTTP::setTimeout(3);
    GWF_HTTP::setConnectTimeout(2);
    if (false === ($content = GWF_HTTP::getFromURL($url))) {
        return;
    }
    GWF_HTTP::setTimeout();
    GWF_HTTP::setConnectTimeout();
    //	echo $content.PHP_EOL;
    # Nothing happened
    if ($content === '') {
        return;
    }
    $latest_date = $date;
    $new_known = $known;
    $lines = explode("\n", $content);
    $changed = false;
    $badlines = 0;
    foreach ($lines as $line) {
        if ('' === ($line = trim($line))) {
            continue;
        }
        $thedata = explode('::', $line);
        if (count($thedata) !== 6) {
            $badlines++;
            echo 'Invalid line in dog_wc_forum: ' . $line . PHP_EOL;
            if ($badlines === 1) {
                echo "BAD URL IS: {$url}\n";
            }
            if ($badlines > 3) {
                return;
            }
            continue;
        }
        $badlines = 0;
        $thedata = array_map('unescape_csv_like', $thedata);
        # Fetch line
        list($threadid, $lastdate, $lock, $url, $username, $title) = $thedata;
        if (strlen($lastdate) !== 14) {
            echo "Dateformat in {$url} is invalid: {$lastdate}\n";
            return false;
        }
        $gid = (int) $lock;
        if (is_array($onlygids)) {
            if (!in_array($gid, $onlygids, true)) {
                //				echo "Not an only gid: $gid\n";
                continue;
            }
        }
        if (is_array($skipgids)) {
            if (in_array($gid, $skipgids, true)) {
                //				echo "Skipped gid: $gid\n";
                continue;
            }
        }
        # Duplicate output?
        if ($lastdate === $date && strpos($known, ',' . $threadid . ',') !== false) {
            continue;
        }
        # Is it private?
        $lock = $lock === '0' ? '' : ' locked';
        # does the date change?
        if ($latest_date !== $lastdate) {
            $latest_date = $lastdate;
            $new_known = ',';
        }
        # Mark this thread as known for this datestamp
        $new_known .= $threadid . ',';
        if (strpos($url, 'http') !== 0) {
            $url = 'http://' . $url;
        }
        # Output message
        if ($lock === ' locked') {
            $msg = sprintf('%s New%s post: %s', $name, $lock, $url);
        } else {
            $msg = sprintf('%s New post by %s in %s: %s', $name, $username, $title, $url);
        }
        if (count($channels) === 0) {
            # To all servers in the main channel
            foreach (Dog::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels = $server->getChannels();
                if (count($channels) > 0) {
                    $channel = array_shift($channels);
                    $channel = $channel->getVar('chan_name');
                    $server->sendPRIVMSG($channel, $msg);
                }
            }
        } else {
            # To all servers in matching channels
            foreach (Dog::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels_now = $server->getChannels();
                foreach ($channels_now as $channel) {
                    $channel instanceof Dog_Channel;
                    $channel = $channel->getName();
                    echo $channel . PHP_EOL;
                    foreach ($channels as $c) {
                        if (!strcasecmp($c, $channel)) {
                            $server->sendPRIVMSG($channel, $msg);
                        }
                    }
                }
            }
        }
        $changed = true;
    }
    # Save state
    if ($changed) {
        GWF_Settings::setSetting('DOG_FORUM_DATE_' . $key, $lastdate);
        GWF_Settings::setSetting('DOG_FORUM_LAST_' . $key, $new_known);
    }
}
Example #12
0
            $message = sprintf('There are %d new challenges on %s ( %s ).', $amt, $sitename, $url);
        } else {
            $message = sprintf('There is %d new challenge on %s ( %s ).', $amt, $sitename, $url);
        }
        foreach (Dog::getServers() as $s) {
            $s instanceof Dog_Server;
            $c = $s->getChannels();
            if (count($c) > 0) {
                $c = array_shift($c);
                $c instanceof Dog_Channel;
                //				echo $c->getName().': '.$message.PHP_EOL;
                if (stripos($s->getName(), 'idlemonkeys') === false) {
                    $s->sendPRIVMSG($c->getName(), $message);
                }
            }
        }
        if (isset($map[$sitename])) {
            $chan = $map[$sitename];
            foreach (Dog::getServers() as $s) {
                $s instanceof Dog_Server;
                foreach ($s->getChannels() as $c) {
                    $c instanceof Dog_Channel;
                    if (!strcasecmp($c->getName(), $chan)) {
                        $s->sendPRIVMSG($c->getName(), $message);
                    }
                }
            }
        }
        GWF_Settings::setSetting($setname, $challs);
    }
}
Example #13
0
 public function saveLinks()
 {
     return GWF_Settings::setSetting('dog_irc_links', $this->links_saved);
 }
Example #14
0
 public static function dummySong(Module_Slaytags $module, $error = 'GWFv3 ERROR', $timeout = 60)
 {
     GWF_Settings::setSetting(self::NP_KEY, '0');
     GWF_Settings::setSetting(self::NP_NEXT_KEY, time() + $timeout);
     return new Slay_Song(array('ss_id' => -1, 'ss_rko_id' => -1, 'ss_c64_id' => -1, 'ss_slay_id' => -1, 'ss_title' => $error, 'ss_artist' => $error, 'ss_composer' => $error, 'ss_lyrics' => 0, 'ss_taggers' => 0, 'ss_duration' => $timeout, 'ss_played' => 0, 'ss_options' => 0, 'ss_last_played' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'ss_tag_cache' => NULL, 'ss_r64_vote' => -1, 'ss_sid_path' => NULL));
 }