Permalink
Browse files

Pushing roughly nine months worth of backlogged changes. Yowza.

  • Loading branch information...
1 parent 3a8016e commit feb81c82a8fb07343ee655684e817c76f3751b49 Tyler Hall committed Jul 26, 2010
View
@@ -1,4 +1,4 @@
-* Copyright (c) 2006 - 2009, Simple PHP Framework <tylerhall@gmail.com>
+* Copyright (c) 2006 - 2010, Simple PHP Framework <tylerhall@gmail.com>
* http://github.com/tylerhall/simple-php-framework/
* All rights reserved.
*
View
@@ -1,50 +0,0 @@
---
--- Table structure for table `sessions`
---
-
-CREATE TABLE `sessions` (
- `id` varchar(255) collate utf8_unicode_ci NOT NULL,
- `data` text collate utf8_unicode_ci NOT NULL,
- `updated_on` int(10) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-
--- --------------------------------------------------------
-
---
--- Table structure for table `users`
---
-
-CREATE TABLE `users` (
- `id` int(11) NOT NULL auto_increment,
- `username` varchar(65) collate utf8_unicode_ci NOT NULL,
- `password` varchar(65) collate utf8_unicode_ci NOT NULL,
- `level` enum('user','admin') collate utf8_unicode_ci NOT NULL,
- `email` varchar(65) collate utf8_unicode_ci default NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `username` (`username`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-
---
--- Table structure for table `stats`
---
-
-CREATE TABLE IF NOT EXISTS `stats` (
- `id` int(11) NOT NULL auto_increment,
- `dt` datetime NOT NULL default '0000-00-00 00:00:00',
- `referer` varchar(255) collate utf8_unicode_ci NOT NULL default '',
- `referer_is_local` tinyint(4) NOT NULL default '0',
- `url` varchar(255) collate utf8_unicode_ci NOT NULL default '',
- `page_title` varchar(255) collate utf8_unicode_ci NOT NULL default '',
- `search_terms` varchar(255) collate utf8_unicode_ci NOT NULL default '',
- `img_search` tinyint(4) NOT NULL default '0',
- `browser_family` varchar(255) collate utf8_unicode_ci NOT NULL default '',
- `browser_version` varchar(15) collate utf8_unicode_ci NOT NULL default '',
- `os` varchar(255) collate utf8_unicode_ci NOT NULL default '',
- `os_version` varchar(255) collate utf8_unicode_ci NOT NULL default '',
- `ip` varchar(15) collate utf8_unicode_ci NOT NULL default '',
- `user_agent` varchar(255) collate utf8_unicode_ci NOT NULL default '',
- `exec_time` float NOT NULL default '0',
- `num_queries` int(11) NOT NULL default '0',
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
@@ -1 +0,0 @@
-<?PHP phpinfo();
@@ -1,160 +0,0 @@
-<?php
-require_once 'PHPUnit/Framework.php';
-require_once 'includes/functions.inc.php';
-
-class FunctionsTest extends PHPUnit_Framework_TestCase
-{
- function testSlugify()
- {
- $this->assertEquals('hello-this-is-a-test-123', slugify('Hello! This is a test 1...2...3...'));
- }
-
- function testCalendar()
- {
- for($year = 1998; $year <= 2010; $year++)
- {
- for($month = 1; $month <= 12; $month++)
- {
- $this->info = "$month/$year";
- $this->assertEquals(5, count(calendar($month, $year)), '', 1);
- }
- }
- }
-
- function testPickOff()
- {
- $_SERVER['REQUEST_URI'] = '/people/tylerhall/tags/apple';
- $ret = pick_off();
- if($ret['people'] != 'tylerhall' || $ret['tags'] != 'apple' || count($ret) != 2)
- $this->fail($_SERVER['REQUEST_URI']);
- else
- return;
-
- $_SERVER['REQUEST_URI'] = '/people/tylerhall/tags/apple';
- $ret = pick_off(false);
- if($ret['people'] != 'tylerhall' || $ret['tags'] != 'apple' || count($ret) != 2)
- $this->fail($_SERVER['REQUEST_URI']);
- else
- return;
-
- $_SERVER['REQUEST_URI'] = '/newest/people/tylerhall/tags/apple';
- $ret = pick_off(true);
- if($ret[0] != 'newest' || $ret['people'] != 'tylerhall' || $ret['tags'] != 'apple' || count($ret) != 3)
- $this->fail($_SERVER['REQUEST_URI']);
- else
- return;
- }
-
- function testDater()
- {
- $ts = time();
- $date = date('Y-m-d H:i:s', $ts);
-
- $this->assertEquals($date, dater($ts, 'Y-m-d H:i:s'));
- $this->assertEquals($date, dater($date, 'Y-m-d H:i:s'));
- $this->assertEquals($date, dater(strtotime($date), 'Y-m-d H:i:s'));
- }
-
- function testFormatPhone()
- {
- $this->assertEquals("(615) 429-5938", format_phone('6154295938'));
- $this->assertEquals("(615) 429-5938", format_phone('615-429-5938'));
- $this->assertEquals("(615) 429-5938", format_phone("(615)-429-5938"));
- $this->assertEquals("(615) 429-5938", format_phone('615.429.5938'));
- $this->assertEquals('429-5938', format_phone('4295938'));
- $this->assertEquals('429-5938', format_phone('429-5938'));
- $this->assertEquals('429-5938', format_phone('429-5938'));
- $this->assertEquals('429-5938', format_phone('429.5938'));
- $this->assertEquals('429-5938', format_phone("429.ASF*^&%AS*^5938"));
- }
-
- function testRemoteFilesize()
- {
- $this->assertEquals('132729', remote_filesize("http://s3.amazonaws.com/amz.clickontyler.com/blog/105home.png"));
- }
-
- function testBytes2Str()
- {
- $arr = array('0.9B', '1B', '1.1B', '921.6B', '1KB', '1.1KB', '921.6KB', '1MB', '1.1MB', '921.6MB', '1GB', '1.1GB', '921.6GB', '1TB', '1.1TB', '921.6TB', '1PB', '1.1PB', '921.6PB', '1EB', '1.1EB', '921.6EB', '1ZB', '1.1ZB', '921.6ZB', '1YB', '1.1YB');
- for($i = 0; $i < 9; $i++)
- {
- $this->assertEquals(array_shift($arr), bytes2str(pow(1024, $i) *.9, 2));
- $this->assertEquals(array_shift($arr), bytes2str(pow(1024, $i), 2));
- $this->assertEquals(array_shift($arr), bytes2str(pow(1024, $i) * 1.1, 2));
- }
- }
-
- function testSlash()
- {
- $this->assertEquals('foobar/',slash('foobar/'));
- $this->assertEquals('/foobar/', slash('/foobar/'));
- $this->assertEquals('/foobar/', slash('/foobar'));
- $this->assertEquals('/foobar/', slash('/foobar///'));
- }
-
- function testUnslash()
- {
- $this->assertEquals('foobar', unslash('foobar/'));
- $this->assertEquals('/foobar', unslash('/foobar/'));
- $this->assertEquals('/foobar', unslash('/foobar'));
- $this->assertEquals('/foobar', unslash('/foobar///'));
- }
-
- function testGimme()
- {
- $arr = array(array(1, 3, 5, 7, 9),
- array(2, 4, 5, 6, 1),
- array(3, 1, 4, 4, 5));
- $this->assertEquals(array(1, 2, 3), gimme($arr));
- $this->assertEquals(array(3, 4, 1), gimme($arr, 1));
- $this->assertEquals(array(9, 1, 5), gimme($arr, 4));
- }
-
- function testValidEmail()
- {
- $this->assertTrue(valid_email("email@foo123.com"));
- $this->assertTrue(valid_email("my1email@123foo.com"));
- $this->assertTrue(valid_email("123mail@fo220o.com"));
- $this->assertTrue(valid_email("mail-123.hello@foo.com"));
- $this->assertTrue(valid_email("email+bucket@foo.com"));
- $this->assertTrue(valid_email("tylerhall@gmail.com", true));
- $this->assertFalse(valid_email("em ail@foo.com"));
- $this->assertFalse(valid_email("em\ail@foo.com"));
- $this->assertFalse(valid_email("em ail@ foo.com"));
- $this->assertFalse(valid_email("em ail@foo."));
- $this->assertFalse(valid_email("@"));
- $this->assertFalse(valid_email(''));
- $this->assertFalse(valid_email(' '));
- }
-
- function testMatch()
- {
- $str = 'aaabbbcdefg';
- $this->assertEquals('aaabbb', match('/[a-b]+/', $str));
- $this->assertEquals('bbbc', match('/a+(b*c)c*/', $str, 1));
- $this->assertFalse(match('/c[a-b]+/', $str));
- }
-
- function testPick()
- {
- $this->assertEquals(1, pick(1, 2, 3));
- $this->assertEquals(2, pick('', 2, 3));
- $this->assertEquals(2, pick(null, 2, 3));
- $this->assertEquals(2, pick(0, 2, 3));
- $this->assertEquals(3, pick('', '', 3));
- $this->assertEquals('', pick());
- $this->assertEquals(1, pick(1));
- }
-
- function testMimeType()
- {
- $this->assertEquals(mime_type('foo.tar.gz'), 'application/x-gzip');
- $this->assertEquals(mime_type('foo.tar.gz', 'text/plain'), 'application/x-gzip');
-
- $this->assertEquals(mime_type('foo.bar'), 'application/octet-stream');
- $this->assertEquals(mime_type('foo.bar', 'text/plain'), 'text/plain');
-
- $this->assertEquals(mime_type('TODO'), 'application/octet-stream');
- $this->assertEquals(mime_type('TODO', 'text/plain'), 'text/plain');
- }
-}
@@ -1,34 +0,0 @@
-<?php
-require_once 'PHPUnit/Framework.php';
-require_once 'includes/class.loop.php';
-
-class LoopTest extends PHPUnit_Framework_TestCase
-{
- public function testGet()
- {
- $l = new Loop('foo', 'bar', 'charlie');
- $this->assertEquals($l->get(), 'foo');
- $this->assertEquals($l->get(), 'bar');
- $this->assertEquals($l->get(), 'charlie');
- $this->assertEquals($l->get(), 'foo');
- }
-
- public function testToString()
- {
- $l = new Loop('foo', 'bar', 'charlie');
- $this->assertEquals($l->__tostring(), 'foo');
- $this->assertEquals($l->__tostring(), 'bar');
- $this->assertEquals($l->__tostring(), 'charlie');
- $this->assertEquals($l->__tostring(), 'foo');
- }
-
- public function testRandom()
- {
- $l = new Loop('foo', 'bar', 'charlie');
- $arr = array('foo', 'bar', 'charlie');
- $this->assertTrue(in_array($l->rand(), $arr));
- $this->assertTrue(in_array($l->rand(), $arr));
- $this->assertTrue(in_array($l->rand(), $arr));
- $this->assertTrue(in_array($l->rand(), $arr));
- }
-}
View
@@ -1,25 +0,0 @@
-<?PHP
- require '../includes/master.inc.php';
-
- $Auth->requireAdmin('../index.php');
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title>Simple PHP Framework</title>
- <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.5.2/build/reset-fonts-grids/reset-fonts-grids.css">
- <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.5.2/build/base/base-min.css">
- <link rel="stylesheet" href="../styles/screen.css" type="text/css" media="screen" title="Screen" charset="utf-8" />
-</head>
-
-<body>
- <h1>Simple PHP Framework</h1>
- <div id="main">
- <h2>Sample Admin Area</h2>
- <p>If you can view this page, you are logged in as an Admin level user.</p>
- </div>
-</body>
-</html>
View
@@ -1,2 +0,0 @@
-order deny,allow
-deny from all
@@ -1,101 +0,0 @@
-<?PHP
- // A quick and dirty command line argument parser. Written in about
- // an hour, so you might want to take this with a grain of salt or two.
- //
- // More info:
- // http://clickontyler.com/blog/2008/11/parse-command-line-arguments-in-php/
- //
- // Single letter options should be prefixed with a single
- // dash and can be grouped together. Examples:
- //
- // cmd -a
- // cmd -ab
- //
- // Values can be assigned to single letter options like so:
- //
- // cmd -a foo (a will be set to foo.)
- //
- // cmd -a foo -b (a will be set to foo.)
- //
- // cmd -ab foo (a and b will simply be set to true. foo is only listed as an argument.)
- //
- // You can also use the double-dash syntax. Examples:
- //
- // cmd --value
- //
- // cmd --value foo (value is set to foo)
- //
- // cmd --value=foo (value is set to foo)
- //
- // Single dash and double dash syntax may be mixed.
- //
- // Trailing arguments are treated as such. Examples:
- //
- // cmd -abc foo bar (foo and bar are listed as arguments)
- //
- // cmd -a foo -b bar charlie (only bar and charlie are arguments)
-
-
- class Args
- {
- private $flags;
- public $args;
-
- public function __construct()
- {
- $this->flags = array();
- $this->args = array();
-
- $argv = $GLOBALS['argv'];
- array_shift($argv);
-
- for($i = 0; $i < count($argv); $i++)
- {
- $str = $argv[$i];
-
- // --foo
- if(strlen($str) > 2 && substr($str, 0, 2) == '--')
- {
- $str = substr($str, 2);
- $parts = explode('=', $str);
- $this->flags[$parts[0]] = true;
-
- // Does not have an =, so choose the next arg as its value
- if(count($parts) == 1 && isset($argv[$i + 1]) && preg_match('/^--?.+/', $argv[$i + 1]) == 0)
- {
- $this->flags[$parts[0]] = $argv[$i + 1];
- }
- elseif(count($parts) == 2) // Has a =, so pick the second piece
- {
- $this->flags[$parts[0]] = $parts[1];
- }
- }
- elseif(strlen($str) == 2 && $str[0] == '-') // -a
- {
- $this->flags[$str[1]] = true;
- if(isset($argv[$i + 1]) && preg_match('/^--?.+/', $argv[$i + 1]) == 0)
- $this->flags[$str[1]] = $argv[$i + 1];
- }
- elseif(strlen($str) > 1 && $str[0] == '-') // -abcdef
- {
- for($j = 1; $j < strlen($str); $j++)
- $this->flags[$str[$j]] = true;
- }
- }
-
- for($i = count($argv) - 1; $i >= 0; $i--)
- {
- if(preg_match('/^--?.+/', $argv[$i]) == 0)
- $this->args[] = $argv[$i];
- else
- break;
- }
-
- $this->args = array_reverse($this->args);
- }
-
- public function flag($name)
- {
- return isset($this->flags[$name]) ? $this->flags[$name] : false;
- }
- }
Oops, something went wrong.

2 comments on commit feb81c8

@heller
heller commented on feb81c8 Jul 27, 2010

So was it not just me who had problems with keeping a session open after using the old change-username and change-password?

@tylerhall
Owner

The previous Auth class was a dinosaur that hadn't changed much in nearly four years. I believe its change username and password functions weren't ever tested enough (my fault). This new Auth class is a clean break. It's much more secure while still maintaining as much of the previous public facing interface as possible. I'm currently nearing the launch of a new, large website, which is why I finally took the time to rewrite Auth. I'll keep the class updated with the latest fixes as development on my other project progresses.

Please sign in to comment.