Commit ed685a22 authored by Simon Welsh's avatar Simon Welsh

Hack fixes

parent ab2dec77
<?php
<?hh
require 'xhp/init.php';
......@@ -23,13 +23,13 @@ final class DB {
public static function inst() {
static $inst = null;
if(!$inst) {
$inst = new self;
$inst = new self();
}
return $inst;
}
private function __construct() {
$this->con = pg_connect('user=simon password=pass dbname=logbot');
$this->con = pg_connect('user=simon password=pass dbname=logbot host=127.0.0.1');
}
public function query($sql) {
......@@ -54,7 +54,7 @@ final class DB {
function build_dates() {
static $dates = array();
if(!$dates) {
$r = new Redis;
$r = new Redis();
if($r->connect('localhost')) {
$r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$dates = $r->get('log:dates');
......@@ -86,7 +86,7 @@ function build_dates() {
}
function get_stats() {
$r = new Redis;
$r = new Redis();
if($r->connect('localhost')) {
$r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$stats = $r->get('log:stats');
......@@ -103,11 +103,10 @@ function get_stats() {
function build_stats(Redis $r) {
// SELECT COUNT(*) AS "Bitches", "Nick" FROM "Log" WHERE "Text" ILIKE '%cunt%' GROUP BY "Nick" ORDER BY "Bitches" DESC;
$stats = [];
$swears = array_filter(array_map('trim', file(__DIR__ . '/swears.txt')));
$swears = array_filter(array_map(fun('trim'), file(__DIR__ . '/swears.txt')));
natcasesort($swears);
$query = 'SELECT COUNT(*) AS "Number", "Nick" FROM "Log" WHERE "Text" ILIKE \'%%%s%%\' GROUP BY "Nick" ORDER BY "Number" DESC LIMIT 20;';
foreach($swears as $name) {
$res = DB::inst()->query(sprintf($query, $name));
$res = DB::inst()->query(sprintf('SELECT COUNT(*) AS "Number", "Nick" FROM "Log" WHERE "Text" ILIKE \'%%%s%%\' GROUP BY "Nick" ORDER BY "Number" DESC LIMIT 20;', $name));
$stats[$name] = [];
while($row = pg_fetch_array($res)) {
$stats[$name][$row[1]] = $row[0];
......
<?php
<?hh
class :logs:calendar extends :x:element {
attribute
......
<?php
<?hh
class :logs:document extends :x:element {
attribute
xhp_logs__head head @required,
xhp_x__base body @required;
:logs:head head @required,
:xhp body @required;
protected function render() {
return <x:doctype>
......
<?php
<?hh
class :logs:foot extends :x:element {
attribute
......
<?php
<?hh
class :logs:search extends :x:element {
protected function render() {
......
<?php
<?hh
class :logs:head extends :x:element {
attribute
......@@ -17,7 +17,7 @@ class :logs:head extends :x:element {
<meta name="robots" content={$this->getAttribute('robots')} />
<meta name="viewport" content="width=device-width, user-scalable=1" />
<link rel="stylesheet" type="text/css" href="logs.css?6" />
<script async="true" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script async={true} src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</head>;
}
}
<?php
<?hh
class :logs:info extends :x:element {
attribute string channel = '#silverstripe';
......
<?php
<?hh
class :logs:log extends :x:element {
attribute
......@@ -7,9 +7,9 @@ class :logs:log extends :x:element {
string format = 'H:i:s';
protected function render() {
$id = $this->getAttribute('id');
$log = $this->getAttribute('row');
$format = $this->getAttribute('format');
$id = $this->:id;
$log = $this->:row;
$format = $this->:format;
$logTime = strtotime($log['Time']);
$index = 'log_' . $log['ID'];
......@@ -83,10 +83,12 @@ class :logs:log extends :x:element {
$bits = preg_split("#$pattern#ix", $string, -1, PREG_SPLIT_DELIM_CAPTURE);
$ret = <x:frag />;
foreach($bits as $string) {
$matches = [];
if(preg_match("#$actual#ix", $string, $matches)) {
$input = $matches[0];
if(isset($matches[2]) && empty($matches[3]) && in_array(strtolower($matches[2]), ['php', 'yml', 'yaml', 'ss', 'xml', 'jpg', 'png', 'gif', 'jpeg', 'form', 'log', 'lock', 'json', 'main', 'js'])) {
goto LinkBase;
$ret->appendChild($string);
continue;
}
if(in_array(substr($input, -1), ['.',',','?'])) {
$right = substr($input, -1);
......@@ -98,7 +100,7 @@ class :logs:log extends :x:element {
$ret->appendChild(<a href={$url} rel="nofollow" target="_blank">{$input}</a>);
$ret->appendChild($right);
} else {
LinkBase: $ret->appendChild($string);
$ret->appendChild($string);
}
}
return $ret;
......
<?php
<?hh
class :logs:logs extends :x:element {
attribute
......@@ -9,7 +9,7 @@ class :logs:logs extends :x:element {
protected function render() {
$stamp = $this->getAttribute('stamp');
$format = $this->getAttribute('format');
$format = $this->:format ?: 'H:i:s';
$logs = $this->getAttribute('logs');
$class = trim('logs ' . $this->getAttribute('class'));
......
<?php
<?hh
class :logs:month extends :x:element {
attribute
......
<?php
<?hh
class :logs:sponsor extends :x:element {
protected function render() {
......
<?php
<?hh
class :logs:timezone extends :x:element {
protected function render() {
......
<?php
<?hh
class :logs:year extends :x:element {
attribute
......@@ -8,7 +8,7 @@ class :logs:year extends :x:element {
protected function render() {
$year = $this->getAttribute('year');
$nav = <div class="nav">
<h3><a name={$year}>{$year}</a></h3>
<h3><a name={''. $year}>{$year}</a></h3>
</div>;
$months = $this->getAttribute('months');
if(count($months) > 1) {
......
<?php
<?hh
class :logs:years extends :x:element {
attribute array years;
......
<?php
<?hh
error_reporting(E_ALL);
......
<?php
<?hh
error_reporting(E_ALL);
......
<?php
<?hh
error_reporting(E_ALL);
......
<?hh
/** THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT BY HAND **
*
* If you are using Composer, ignore this file.
*
* If you are not using Composer, you can use this function directly, but you
* probably just want to include init.php instead.
*/
namespace Facebook\XHPLib\Autoloader;
function autoload($class): bool {
$classmap = Map {
'HasXHPBaseHTMLHelpers' => '/src/html/HasXHPBaseHTMLHelpers.php',
'HasXHPHelpers' => '/src/html/XHPHelpers.php',
'ReflectionXHPAttribute' => '/src/core/ReflectionXHPAttribute.php',
'ReflectionXHPChildrenDeclaration' => '/src/core/ReflectionXHPChildrenDeclaration.php',
'ReflectionXHPChildrenExpression' => '/src/core/ReflectionXHPChildrenDeclaration.php',
'ReflectionXHPClass' => '/src/core/ReflectionXHPClass.php',
'XHPAlwaysValidChild' => '/src/core/XHPAlwaysValidChild.php',
'XHPAsync' => '/src/core/XHPAsync.php',
'XHPAttributeCoercion' => '/src/core/XHPAttributeCoercion.php',
'XHPAttributeCoercionMode' => '/src/core/XHPAttributeCoercion.php',
'XHPAttributeNotSupportedException' => '/src/exceptions/AttributeNotSupportedException.php',
'XHPAttributeRequiredException' => '/src/exceptions/AttributeRequiredException.php',
'XHPAttributeType' => '/src/core/ReflectionXHPAttribute.php',
'XHPAwaitable' => '/src/core/XHPAwaitable.php',
'XHPBaseHTMLHelpers' => '/src/html/XHPBaseHTMLHelpers.php',
'XHPChildrenConstraintType' => '/src/core/ReflectionXHPChildrenDeclaration.php',
'XHPChildrenDeclarationType' => '/src/core/ReflectionXHPChildrenDeclaration.php',
'XHPChildrenExpressionType' => '/src/core/ReflectionXHPChildrenDeclaration.php',
'XHPClassException' => '/src/exceptions/ClassException.php',
'XHPCoreRenderException' => '/src/exceptions/CoreRenderException.php',
'XHPException' => '/src/exceptions/Exception.php',
'XHPHasTransferAttributes' => '/src/core/XHPHasTransferAttributes.php',
'XHPHelpers' => '/src/html/XHPHelpers.php',
'XHPInvalidArrayAttributeException' => '/src/exceptions/InvalidArrayAttributeException.php',
'XHPInvalidArrayKeyAttributeException' => '/src/exceptions/InvalidArrayKeyAttributeException.php',
'XHPInvalidAttributeException' => '/src/exceptions/InvalidAttributeException.php',
'XHPInvalidChildrenException' => '/src/exceptions/InvalidChildrenException.php',
'XHPRenderArrayException' => '/src/exceptions/RenderArrayException.php',
'XHPRoot' => '/src/core/XHPRoot.php',
'XHPUnsafeRenderable' => '/src/core/XHPUnsafeRenderable.php',
'XHPUnsupportedAttributeTypeException' => '/src/exceptions/UnsupportedAttributeTypeException.php',
'xhp_a' => '/src/html/tags/a/A.php',
'xhp_abbr' => '/src/html/tags/a/Abbr.php',
'xhp_address' => '/src/html/tags/a/Address.php',
'xhp_area' => '/src/html/tags/a/Area.php',
'xhp_article' => '/src/html/tags/a/Article.php',
'xhp_aside' => '/src/html/tags/a/Aside.php',
'xhp_audio' => '/src/html/tags/a/Audio.php',
'xhp_b' => '/src/html/tags/b/B.php',
'xhp_base' => '/src/html/tags/b/Base.php',
'xhp_bdi' => '/src/html/tags/b/Bdi.php',
'xhp_bdo' => '/src/html/tags/b/Bdo.php',
'xhp_blockquote' => '/src/html/tags/b/Blockquote.php',
'xhp_body' => '/src/html/tags/b/Body.php',
'xhp_br' => '/src/html/tags/b/Br.php',
'xhp_button' => '/src/html/tags/b/Button.php',
'xhp_canvas' => '/src/html/tags/c/Canvas.php',
'xhp_caption' => '/src/html/tags/c/Caption.php',
'xhp_cite' => '/src/html/tags/c/Cite.php',
'xhp_code' => '/src/html/tags/c/Code.php',
'xhp_col' => '/src/html/tags/c/Col.php',
'xhp_colgroup' => '/src/html/tags/c/Colgroup.php',
'xhp_data' => '/src/html/tags/d/Data.php',
'xhp_datalist' => '/src/html/tags/d/Datalist.php',
'xhp_dd' => '/src/html/tags/d/Dd.php',
'xhp_del' => '/src/html/tags/d/Del.php',
'xhp_details' => '/src/html/tags/d/Details.php',
'xhp_dfn' => '/src/html/tags/d/Dfn.php',
'xhp_dialog' => '/src/html/tags/d/Dialog.php',
'xhp_div' => '/src/html/tags/d/Div.php',
'xhp_dl' => '/src/html/tags/d/Dl.php',
'xhp_dt' => '/src/html/tags/d/Dt.php',
'xhp_em' => '/src/html/tags/e/Em.php',
'xhp_embed' => '/src/html/tags/e/Embed.php',
'xhp_fieldset' => '/src/html/tags/f/Fieldset.php',
'xhp_figcaption' => '/src/html/tags/f/Figcaption.php',
'xhp_figure' => '/src/html/tags/f/Figure.php',
'xhp_footer' => '/src/html/tags/f/Footer.php',
'xhp_form' => '/src/html/tags/f/Form.php',
'xhp_h1' => '/src/html/tags/h/H1.php',
'xhp_h2' => '/src/html/tags/h/H2.php',
'xhp_h3' => '/src/html/tags/h/H3.php',
'xhp_h4' => '/src/html/tags/h/H4.php',
'xhp_h5' => '/src/html/tags/h/H5.php',
'xhp_h6' => '/src/html/tags/h/H6.php',
'xhp_head' => '/src/html/tags/h/Head.php',
'xhp_header' => '/src/html/tags/h/Header.php',
'xhp_hgroup' => '/src/html/tags/h/Hgroup.php',
'xhp_hr' => '/src/html/tags/h/Hr.php',
'xhp_html' => '/src/html/tags/h/Html.php',
'xhp_i' => '/src/html/tags/i/I.php',
'xhp_iframe' => '/src/html/tags/i/Iframe.php',
'xhp_img' => '/src/html/tags/i/Img.php',
'xhp_input' => '/src/html/tags/i/Input.php',
'xhp_ins' => '/src/html/tags/i/Ins.php',
'xhp_kbd' => '/src/html/tags/k/Kbd.php',
'xhp_keygen' => '/src/html/tags/k/Keygen.php',
'xhp_label' => '/src/html/tags/l/Label.php',
'xhp_legend' => '/src/html/tags/l/Legend.php',
'xhp_li' => '/src/html/tags/l/Li.php',
'xhp_link' => '/src/html/tags/l/Link.php',
'xhp_main' => '/src/html/tags/m/Main.php',
'xhp_map' => '/src/html/tags/m/Map.php',
'xhp_mark' => '/src/html/tags/m/Mark.php',
'xhp_menu' => '/src/html/tags/m/Menu.php',
'xhp_menuitem' => '/src/html/tags/m/Menuitem.php',
'xhp_meta' => '/src/html/tags/m/Meta.php',
'xhp_meter' => '/src/html/tags/m/Meter.php',
'xhp_nav' => '/src/html/tags/n/Nav.php',
'xhp_noscript' => '/src/html/tags/n/Noscript.php',
'xhp_object' => '/src/html/tags/o/Object.php',
'xhp_ol' => '/src/html/tags/o/Ol.php',
'xhp_optgroup' => '/src/html/tags/o/Optgroup.php',
'xhp_option' => '/src/html/tags/o/Option.php',
'xhp_output' => '/src/html/tags/o/Output.php',
'xhp_p' => '/src/html/tags/p/P.php',
'xhp_param' => '/src/html/tags/p/Param.php',
'xhp_picture' => '/src/html/tags/p/Picture.php',
'xhp_pre' => '/src/html/tags/p/Pre.php',
'xhp_progress' => '/src/html/tags/p/Progress.php',
'xhp_q' => '/src/html/tags/q/Q.php',
'xhp_rb' => '/src/html/tags/r/Rb.php',
'xhp_rp' => '/src/html/tags/r/Rp.php',
'xhp_rt' => '/src/html/tags/r/Rt.php',
'xhp_rtc' => '/src/html/tags/r/Rtc.php',
'xhp_ruby' => '/src/html/tags/r/Ruby.php',
'xhp_s' => '/src/html/tags/s/S.php',
'xhp_samp' => '/src/html/tags/s/Samp.php',
'xhp_script' => '/src/html/tags/s/Script.php',
'xhp_section' => '/src/html/tags/s/Section.php',
'xhp_select' => '/src/html/tags/s/Select.php',
'xhp_small' => '/src/html/tags/s/Small.php',
'xhp_source' => '/src/html/tags/s/Source.php',
'xhp_span' => '/src/html/tags/s/Span.php',
'xhp_strong' => '/src/html/tags/s/Strong.php',
'xhp_style' => '/src/html/tags/s/Style.php',
'xhp_sub' => '/src/html/tags/s/Sub.php',
'xhp_summary' => '/src/html/tags/s/Summary.php',
'xhp_sup' => '/src/html/tags/s/Sup.php',
'xhp_table' => '/src/html/tags/t/Table.php',
'xhp_tbody' => '/src/html/tags/t/Tbody.php',
'xhp_td' => '/src/html/tags/t/Td.php',
'xhp_template' => '/src/html/tags/t/Template.php',
'xhp_textarea' => '/src/html/tags/t/Textarea.php',
'xhp_tfoot' => '/src/html/tags/t/Tfoot.php',
'xhp_th' => '/src/html/tags/t/Th.php',
'xhp_thead' => '/src/html/tags/t/Thead.php',
'xhp_time' => '/src/html/tags/t/Time.php',
'xhp_title' => '/src/html/tags/t/Title.php',
'xhp_tr' => '/src/html/tags/t/Tr.php',
'xhp_track' => '/src/html/tags/t/Track.php',
'xhp_tt' => '/src/html/tags/t/Tt.php',
'xhp_u' => '/src/html/tags/u/U.php',
'xhp_ul' => '/src/html/tags/u/Ul.php',
'xhp_var' => '/src/html/tags/v/Var.php',
'xhp_video' => '/src/html/tags/v/Video.php',
'xhp_wbr' => '/src/html/tags/w/Wbr.php',
'xhp_x__composable_element' => '/src/core/ComposableElement.php',
'xhp_x__conditional_comment' => '/src/html/tags/c/ConditionalComment.php',
'xhp_x__doctype' => '/src/html/tags/d/Doctype.php',
'xhp_x__element' => '/src/core/Element.php',
'xhp_x__frag' => '/src/core/Frag.php',
'xhp_x__primitive' => '/src/core/Primitive.php',
'xhp_xhp' => '/src/core/XHP.php',
'xhp_xhp__html_element' => '/src/html/Element.php',
'xhp_xhp__html_singleton' => '/src/html/Singleton.php',
'xhp_xhp__pcdata_element' => '/src/html/PcdataElement.php',
'xhp_xhp__raw_pcdata_element' => '/src/html/RawPcdataElement.php',
};
if ($classmap->containsKey($class)) {
require_once(__DIR__.$classmap[$class]);
return class_exists($class, /* autoload = */ false);
}
return false;
}
\ No newline at end of file
<?hh
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
// Convert the composer-generated classmap into something usable without
// Composer.
namespace Facebook\XHPLib\Autoloader;
function generate() {
$root_dir = dirname(__DIR__);
$src_dir = $root_dir.'/src';
$in_file = $root_dir.'/vendor/composer/autoload_classmap.php';
$classmap = new Map(require($in_file));
$classmap = $classmap
->filter($path ==> strpos($path, $src_dir) === 0)
->map($path ==> substr($path, strlen($root_dir)));
// $classmap ~= Map { 'xhp_foo' => '/src/core/Foo.php' };
$classmap_source = str_replace('HH\Map', 'Map', var_export($classmap, true));
$classmap_source = str_replace("\n", "\n ", $classmap_source);
echo <<<EOF
<?hh
/** THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT BY HAND **
*
* If you are using Composer, ignore this file.
*
* If you are not using Composer, you can use this function directly, but you
* probably just want to include init.php instead.
*/
namespace Facebook\XHPLib\Autoloader;
function autoload(\$class): bool {
\$classmap = $classmap_source;
if (\$classmap->containsKey(\$class)) {
require_once(__DIR__.\$classmap[\$class]);
return class_exists(\$class, /* autoload = */ false);
}
return false;
}
EOF;
}
generate();
This diff is collapsed.
<?php
require_once 'core.php';
require_once 'html.php';
<?hh
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
// IF YOU ARE USING COMPOSER: use Composer's autoload, and ignore this file.
require_once(__DIR__.'/autoload-map.php');
spl_autoload_register('Facebook\XHPLib\Autoloader\autoload');
<?hh // strict
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
/**
* :x:element defines an interface that all user-land elements should subclass
* from. The main difference between :x:element and :x:primitive is that
* subclasses of :x:element should implement `render()` instead of `stringify`.
* This is important because most elements should not be dealing with strings
* of markup.
*/
abstract class :x:element extends :x:composable-element implements XHPRoot {
abstract protected function render(): XHPRoot;
final public function toString(): string {
return $this->asyncToString()->getWaitHandle()->join();
}
final public async function asyncToString(): Awaitable<string> {
$that = await $this->__flushRenderedRootElement();
$ret = await $that->asyncToString();
return $ret;
}
final protected async function __flushSubtree(): Awaitable<:x:primitive> {
$that = await $this->__flushRenderedRootElement();
return await $that->__flushSubtree();
}
protected async function __renderAndProcess(): Awaitable<XHPRoot> {
if (:xhp::$ENABLE_VALIDATION) {
$this->validateChildren();
}
if ($this instanceof XHPAwaitable) {
// UNSAFE - interfaces don't support 'protected': facebook/hhvm#4830
$composed = await $this->asyncRender();
} else {
$composed = $this->render();
}
$composed->__transferContext($this->getAllContexts());
if ($this instanceof XHPHasTransferAttributes) {
$this->transferAttributesToRenderedRoot($composed);
}
return $composed;
}
final protected async function __flushRenderedRootElement(
): Awaitable<:x:primitive> {
$that = $this;
// Flush root elements returned from render() to an :x:primitive
while ($that instanceof :x:element) {
$that = await $that->__renderAndProcess();
}
if ($that instanceof :x:primitive) {
return $that;
}
// render() must always (eventually) return :x:primitive
throw new XHPCoreRenderException($this, $that);
}
}
<?hh // strict
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
/**
* An <x:frag /> is a transparent wrapper around any number of elements. When
* you render it just the children will be rendered. When you append it to an
* element the <x:frag /> will disappear and each child will be sequentially
* appended to the element.
*/
class :x:frag extends :x:primitive {
protected function stringify(): string {
$buf = '';
foreach ($this->getChildren() as $child) {
$buf .= :xhp::renderChild($child);
}
return $buf;
}
}
<?hh // strict
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
/**
* :x:primitive lays down the foundation for very low-level elements. You
* should directly :x:primitive only if you are creating a core element that
* needs to directly implement stringify(). All other elements should subclass
* from :x:element.
*/
abstract class :x:primitive extends :x:composable-element implements XHPRoot {
abstract protected function stringify(): string;
final public function toString(): string {
return $this->asyncToString()->getWaitHandle()->join();
}
final public async function asyncToString(): Awaitable<string> {
$that = await $this->__flushSubtree();
return $that->stringify();
}
final private async function __flushElementChildren(): Awaitable<void> {
$children = $this->getChildren();
$awaitables = Map { };
foreach ($children as $idx => $child) {
if ($child instanceof :x:composable-element) {
$child->__transferContext($this->getAllContexts());
$awaitables[$idx] = $child->__flushSubtree();
}
}
if ($awaitables) {
$awaited = await HH\Asio\m($awaitables);
foreach ($awaited as $idx => $child) {
$children[$idx] = $child;
}
}
$this->replaceChildren($children);
}
final protected async function __flushSubtree(): Awaitable<:x:primitive> {
await $this->__flushElementChildren();
if (:xhp::$ENABLE_VALIDATION) {
$this->validateChildren();
}
return $this;
}
}
<?hh // strict
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.