Page MenuHomeGitPull.it

No OneTemporary

Authored By
Unknown
Size
14 KB
Referenced Files
None
Subscribers
None
diff --git a/include/class-App.php b/include/class-App.php
index eafa9ad..72cfd12 100644
--- a/include/class-App.php
+++ b/include/class-App.php
@@ -1,31 +1,47 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
/**
* Methods of an App class
*/
trait AppTrait {
/**
* Get the App ID
*
* @return int
*/
public function getAppID() {
return $this->get( 'app_ID' );
}
/**
* Get the App name
*
* @return string
*/
public function getAppName() {
return $this->get( 'app_name' );
}
}
/**
* Class that can wrap an App retrieved from the database
*/
class App {
}
diff --git a/include/class-Page.php b/include/class-Page.php
index de5f0b2..789a473 100644
--- a/include/class-Page.php
+++ b/include/class-Page.php
@@ -1,71 +1,87 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
/**
* A website page
*
* It's useful to print the header, the footer, and who knows
*/
class Page {
/**
* Custom arguments
*
* @var array
*/
protected $args;
/**
* Constructor
*
* @param array $args Custom arguments
*/
public function __construct( $args = [] ) {
$this->args = $args;
$this->prepare();
}
/**
* Set a page argument
*
* @param $name string
* @param $value mixed
* @return self
*/
protected function setArg( $name, $value ) {
$this->args[ $name ] = $value;
return $this;
}
/**
* Set the page title
*
* @param $title string
* @return self
*/
protected function setTitle( $title ) {
return $this->setArg( 'title', $title );
}
/**
* Do something at startup
*/
protected function prepare() {
// actually nothing. You can override this!
}
/**
* Print the site header
*/
public function printHeader() {
template( 'header', $this->args );
}
/**
* Print the site footer
*/
public function printFooter() {
template( 'footer', $this->args );
}
}
diff --git a/include/class-PageHome.php b/include/class-PageHome.php
index 642ce12..a51c9c1 100644
--- a/include/class-PageHome.php
+++ b/include/class-PageHome.php
@@ -1,45 +1,61 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
/**
* Homepage of my website
*/
class PageHome extends Page {
/**
* User requested by ID
*/
public $requestedUser = false;
/**
* Do something at startup
*
* @override
*/
protected function prepare() {
// read the ID from the query string or zero
$id = $_GET['id'] ?? 0;
// make sure that it's an integer
$id = (int) $id;
// if it's non-zero
if( $id ) {
// query the User with that ID (or get NULL)
$this->requestedUser =
( new QueryUser() )
->whereUserID( $id )
->queryRow();
}
}
/**
* Get the requested User (if any!)
*
* @return User|null
*/
public function getRequestedUser() {
return $this->requestedUser;
}
}
diff --git a/include/class-PageLogin.php b/include/class-PageLogin.php
index 14a0ffa..b69f63e 100644
--- a/include/class-PageLogin.php
+++ b/include/class-PageLogin.php
@@ -1,48 +1,64 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
/**
* Login page of my website
*/
class PageLogin extends Page {
/**
* Do something at startup
*
* @override
*/
protected function prepare() {
// set the page title
$this->setTitle( __( "Login" ) );
// check if we should do the login
if( $this->isLoginFormSubmitted() ) {
// process the user_uid and the user_password sent via POST
login();
}
// eventually go to the homepage if logged-in
if( is_logged() ) {
http_redirect( '', 303 );
}
}
/**
* Check if the login form was submitted
*
* @return boolean
*/
public function isLoginFormSubmitted() {
return is_action( 'do-login' );
}
/**
* Check if the login failed
*
* @return boolean
*/
public function isLoginFormFailed() {
return $this->isLoginFormSubmitted() && !is_logged();
}
}
diff --git a/include/class-QueryApp.php b/include/class-QueryApp.php
index 9baf7a5..4ba6b93 100644
--- a/include/class-QueryApp.php
+++ b/include/class-QueryApp.php
@@ -1,40 +1,56 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
/**
* Methods for a QueryApp class
*/
trait QueryAppTrait {
/**
* Join a table with the App table
*
* @return
*/
public function joinApp( $type = 'INNER' ) {
return $this->joinOn( $type, 'app', 'app.app_ID', $this->APP_ID );
}
}
/**
* Execute a Query against an App
*/
class QueryApp extends Query {
use QueryAppTrait;
/**
* Constructor
*
* @param object $db Database connection
* @param string $class_name Default class name for the results
*/
public function __construct( $db = null, $class_name = 'App' ) {
// set the database connection and the default class name for the results
parent::__construct( $db, $class_name );
// set FROM table
$this->from( 'app' );
}
}
diff --git a/include/class-User.php b/include/class-User.php
index 5f821e4..448198e 100644
--- a/include/class-User.php
+++ b/include/class-User.php
@@ -1,48 +1,64 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
/**
* Class that can wrap an User retrieved from the database
*/
class User extends Sessionuser {
/**
* Constructor
*/
public function __construct() {
parent::__construct();
}
/**
* Get the User name
*
* @return string
*/
public function getUserName() {
return $this->get( 'user_name' );
}
/**
* Get the User ID
*
* @return int
*/
public function getUserID() {
return $this->getSessionuserID();
}
/**
* Check if the user is me
*
* @return boolean
*/
public function isUserMe() {
// if I'm logged, compare the IDs
if( is_logged() ) {
return $this->getUserID() === get_user()->getUserID();
}
return false;
}
}
diff --git a/include/functions.php b/include/functions.php
index a188f15..672ee1c 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,37 +1,53 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
// some functions you may want to have
/**
* Require a certain page from the template directory
*
* @param $name string Template name
* @param $args array Arguments to be passed to the template scope
*/
function template( $name, $args = [] ) {
// extract the variables from the provided array
extract( $args, EXTR_SKIP );
require ABSPATH . "/template/$name.php";
}
/**
* Require a specific permission
*
* @param string $permission
*/
function require_permission( $permission ) {
if( !has_permission( $permission ) ) {
if( is_logged() ) {
http_response_code( 403 );
die( "ARE YOU A PIRATE?" );
}
$url = http_build_get_query( 'login.php', [
'redirect' => $_SERVER['REQUEST_URI'],
] );
http_redirect( $url, 303 ); // HTTP 303 redirect: See Other
}
}
diff --git a/www/index.php b/www/index.php
index 78a6485..1e1b3b0 100644
--- a/www/index.php
+++ b/www/index.php
@@ -1,19 +1,35 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
// load everything
require '../load.php';
// this is the homepage (the business logic of this page it's in this class)
$page = new PageHome( [
'title' => __( "Welcome!" ),
] );
// I want this stylesheet
enqueue_js( 'my-style');
// print site header
$page->printHeader();
?>
<?php
$page->printFooter();
diff --git a/www/login.php b/www/login.php
index 6e5bb2a..75079a2 100644
--- a/www/login.php
+++ b/www/login.php
@@ -1,44 +1,60 @@
<?php
+# WikiCAPTCHA Control Room
+# Copyright (C) 2019 Valerio Bozzolan and contributors
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
// load everything
require '../load.php';
// this is the homepage (the business logic of this page it's in this class)
$page = new PageLogin();
// print site header
$page->printHeader();
?>
<!-- login failed warning -->
<?php if( $page->isLoginFormSubmitted() ): ?>
<div class="card-panel">
<p><?= __( "Login failed!" ) ?></p>
</div>
<?php endif ?>
<!-- login form -->
<form method="post">
<?php form_action( 'do-login' ) ?>
<!-- username -->
<p>
<label for="user-uid"><?= esc_html( __( "Username" ) ) ?></label>
<br />
<input type="text" id="user-uid" name="user_uid" />
</p>
<!-- password -->
<p>
<label for="user-pwd"><?= esc_html( __( "Password" ) ) ?></label>
<br />
<input type="password" id="user-pwd" name="user_password" />
</p>
<!-- submit button -->
<p><button><?= esc_html( __( "Login" ) ) ?></button></p>
</form>
<?php
$page->printFooter();

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 19, 04:01 (22 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264673
Default Alt Text
(14 KB)

Event Timeline