Skip to content

Commit 85c4283

Browse files
committed
pushing some good things
1 parent 70f1110 commit 85c4283

File tree

5 files changed

+80
-72
lines changed

5 files changed

+80
-72
lines changed

controller.php

+19-16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
if ( ! isset ( $_SESSION['id'] ) ) {
1212
$_SESSION['id'] = -1;
13+
/*
14+
* This sets the id to -1 if the user
15+
* is not logged in
16+
*/
1317
}
1418

1519
$app_root = dirname( __FILE__ ) . "/";
@@ -22,47 +26,46 @@
2226
include( $app_root . "libs/php/easter.php" );
2327
include( $app_root . "libs/php/core.php" );
2428

25-
if ($handle = opendir( $app_root . "model/" )) {
26-
while (false !== ($file = readdir($handle))) {
27-
// The "i" after the pattern delimiter indicates a case-insensitive search
28-
if ( $file != "." && $file != ".." ) {
29-
$ftest = $file;
29+
if ($handle = opendir( $app_root . "model/" )) { // open up the model directory
30+
while (false !== ($file = readdir($handle))) { // for each file
31+
if ( $file != "." && $file != ".." ) { // ignore . / ..
32+
$ftest = $file; // "backup" file
3033
if (preg_match("/.*\.php$/i", $ftest)) {
31-
include( $app_root . "model/" . $file );
34+
include( $app_root . "model/" . $file ); // include all .php files
3235
}
3336
}
3437
}
3538
}
3639

37-
header( "Wisdom-Turd: " . getQuip() );
40+
header( "Wisdom-Turd: " . getQuip() ); // wisdom turds!
3841

3942
if ( file_exists( $app_root . "install/install.php" ) ) {
40-
include( $app_root . "install/install.php" );
41-
include( $app_root . "view/view.php" );
42-
exit(0);
43+
include( $app_root . "install/install.php" ); // Disable access
44+
include( $app_root . "view/view.php" ); // if we're not set up.
45+
exit(0); // stop executing the controller code
4346
}
4447

4548
$p = htmlentities( $_GET['p'], ENT_QUOTES);
4649
$toks = explode( "/", $p );
4750

4851
$argv = $toks;
49-
$argc = sizeof( $toks );
52+
$argc = sizeof( $toks ); // these get passed to the view
5053

5154
if (
5255
isset ( $toks[0] ) &&
5356
$toks[0] != ""
54-
) {
57+
) { // if there's a directive, use it.
5558
$idz = $app_root . "content/" . basename( $toks[0] ) . ".php";
5659
if ( file_exists( $idz ) ) {
57-
include( $idz );
60+
include( $idz ); // all good :)
5861
} else {
59-
include( $app_root . "content/default.php" );
62+
include( $app_root . "content/default.php" ); // fake the err.
6063
}
6164
} else {
62-
header("Location: $SITE_PREFIX");
65+
header("Location: $SITE_PREFIX"); // redirect to the app root
6366
}
6467

65-
include( $app_root . "view/view.php" );
68+
include( $app_root . "view/view.php" ); // include the head/foot
6669

6770
?>
6871

model/bug.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,44 @@
88
* @license: AGPLv3
99
*/
1010

11-
if ( ! class_exists ( "bug" ) ) {
11+
if ( ! class_exists ( "bug" ) ) { // if we've included twice
1212

13-
if ( ! class_exists( "dbobj" ) ) {
14-
// last ditch...
13+
if ( ! class_exists( "dbobj" ) ) { // ensure we have the superclass
1514
$model_root = dirname( __FILE__ ) . "/";
1615
include( $model_root . "dbobj.php" );
1716
}
1817

19-
include ( $model_root . "user.php" );
20-
include ( $model_root . "project.php" );
18+
include ( $model_root . "user.php" ); // we need the user
19+
include ( $model_root . "project.php" ); // and project models
2120

2221
class bug extends dbobj {
2322
function bug() {
24-
dbobj::dbobj("bugs", "bID");
23+
dbobj::dbobj("bugs", "bID"); // SQL table `bugs', PK `bID'
2524
}
2625
// Let's add in some functionallity for user stuff.
2726
function getOwner( $bID ) {
2827
$this->getAllByPK( $bID );
2928
$row = $this->getNext();
3029
$u = new user();
3130
$u->getAllByPK( $row['owner'] );
32-
return $u->getNext();
31+
return $u->getNext(); // ( first row :P )
3332
}
3433
function getReporter( $bID ) {
3534
$this->getAllByPK( $bID );
3635
$row = $this->getNext();
3736
$u = new user();
3837
$u->getAllByPK( $row['reporter'] );
39-
return $u->getNext();
38+
return $u->getNext(); // ( first row :D )
4039
}
4140
function getProject( $pID ) {
4241
$this->getAllByPK( $pID );
4342
$row = $this->getNext();
4443
$p = new project();
4544
$p->getAllByPK( $row['package'] );
46-
return $p->getNext();
45+
return $p->getNext(); // ( first row :) )
4746
}
4847

49-
function getAllBugs() {
48+
function getAllBugs() {
5049
global $TABLE_PREFIX;
5150
$sql = new sql();
5251
$sql->query("SELECT * FROM " . $TABLE_PREFIX . "bugs;" );

model/cacheobj.php

+16-20
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,29 @@ function cacheobj( $table, $c_field ) {
3333
}
3434

3535
function checkAge( $ID, $minutes = '' ) {
36-
$minute = 60;
37-
$ttl = $minute * $minutes;
38-
$curTime = time();
39-
$this->getAllByID( $ID );
40-
$cachePull = $this->sql->getNextRow();
41-
$refTime = clean( $cachePull["timestamp"] );
42-
$content = clean( $cachePull["cached_contents"] );
43-
$timeDifference = $curTime - $refTime;
44-
45-
$ret = $ttl - $timeDifference;
46-
47-
return $ret;
36+
$minute = 60;
37+
$ttl = $minute * $minutes;
38+
$curTime = time();
39+
$this->getAllByID( $ID );
40+
$cachePull = $this->sql->getNextRow();
41+
$refTime = clean( $cachePull["timestamp"] );
42+
$content = clean( $cachePull["cached_contents"] );
43+
$timeDifference = $curTime - $refTime;
44+
$ret = $ttl - $timeDifference;
45+
return $ret;
4846
}
4947

5048
function updateStamp( $ID ) {
51-
$this->sql->query( "UPDATE " . $this->table . " SET timestamp=" . time() . " WHERE " . $this->c_field . "='" . $ID . "' ;" );
49+
$this->sql->query( "UPDATE " . $this->table . " SET timestamp=" . time() . " WHERE " . $this->c_field . "='" . $ID . "' ;" );
5250
}
5351

54-
function updateCached( $ID, $contents ) {
55-
$this->sql->query( "UPDATE " . $this->table . " SET cached_contents='" . $contents . "' WHERE " . $this->c_field . "='" . $ID . "' ;" );
56-
}
52+
function updateCached( $ID, $contents ) {
53+
$this->sql->query( "UPDATE " . $this->table . " SET cached_contents='" . $contents . "' WHERE " . $this->c_field . "='" . $ID . "' ;" );
54+
}
5755

5856
function getAllByID( $ID ) {
59-
$this->sql->query( "SELECT * FROM " . $this->table . " WHERE " . $this->c_field . " = '" . $ID . "';" );
60-
}
61-
62-
57+
$this->sql->query( "SELECT * FROM " . $this->table . " WHERE " . $this->c_field . " = '" . $ID . "';" );
58+
}
6359
}
6460

6561
}

model/events.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class events {
1414

1515
function events() {
1616
$model_root = dirname( __FILE__ ) . "/";
17-
$event_root = $model_root . "../events/";
17+
$event_root = $model_root . "../events/"; // full of fifo
1818
$this->folder_root = $event_root;
1919
}
2020

@@ -32,6 +32,17 @@ function broadcast( $note ) {
3232
}
3333
}
3434
}
35+
/*
36+
* OK what just went on was a bit confusing. Here's what it's doing:
37+
*
38+
* Find all files that match "*.hook" in ../events/ ( whube/events )
39+
* For each file in events ( that maches )
40+
* - Write to the file
41+
*
42+
* With a UNIX FIFO pipe, this Write will block until something
43+
* ( the plugin ) reads it.
44+
*
45+
*/
3546
}
3647
}
3748

model/twitter.php

+24-25
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,37 @@
1010
*/
1111

1212
if ( ! class_exists( "cacheobj" ) ) {
13-
// last ditch...
14-
$model_root = dirname( __FILE__ ) . "/";
15-
include( $model_root . "cacheobj.php" );
13+
// last ditch...
14+
$model_root = dirname( __FILE__ ) . "/";
15+
include( $model_root . "cacheobj.php" );
1616
}
1717

1818
if ( ! class_exists( "twitter" ) ) {
1919
class twitter extends cacheobj {
20-
var $count;
21-
var $friend_count;
22-
var $id;
20+
var $count;
21+
var $friend_count;
22+
var $id;
2323

24-
function twitter( $count = 1, $friend_count = 10 ) {
24+
function twitter( $count = 1, $friend_count = 10 ) {
2525
cacheobj::cacheobj("cache", "cache_id");
26-
$this->count = $count;
27-
$this->friend_count = $friend_count;
28-
$model_root = basename( __FILE__ ) . "/";
29-
include( $model_root . "../conf/twitter.php" );
30-
$this->id = $id;
31-
}
26+
$this->count = $count;
27+
$this->friend_count = $friend_count;
28+
$model_root = basename( __FILE__ ) . "/";
29+
include( $model_root . "../conf/twitter.php" );
30+
$this->id = $id;
31+
}
32+
33+
function showUpdates() {
34+
$age = $this->checkAge( "tweeter", 5 );
35+
if( $age <= 0 ) {
36+
$this->gatherTweet();
37+
}
38+
$this->getAllByID( "tweeter" );
39+
$cached = $this->sql->getNextRow();
3240

33-
function showUpdates() {
34-
$age = $this->checkAge( "tweeter", 5 );
35-
if( $age <= 0 ) {
36-
$this->gatherTweet();
37-
}
38-
39-
$this->getAllByID( "tweeter" );
40-
$cached = $this->sql->getNextRow();
41-
42-
$ret = $cached["cached_contents"];
43-
return $ret;
44-
}
41+
$ret = $cached["cached_contents"];
42+
return $ret;
43+
}
4544

4645
function gatherTweet() {
4746
$id = $this->id;

0 commit comments

Comments
 (0)