my-simon 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore.orig +55 -0
- data/DOC/Launch Check List.docx +0 -0
- data/DOC/Launch Check List.pdf +0 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +44 -0
- data/LICENSE.txt +20 -0
- data/README.md +21 -0
- data/README.rdoc +19 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/build/rakefile.rb +12 -0
- data/config.rb +24 -0
- data/lib/simon.rb +0 -5
- data/my-simon.gemspec +141 -0
- data/scaffolding/simon/controller.tpl +9 -0
- data/scaffolding/simon/model.tpl +10 -0
- data/scaffolding/simon/view.tpl +5 -0
- data/scaffolding/standards/html_template.html +44 -0
- data/scaffolding/standards/html_template.php +44 -0
- data/scaffolding/standards/jquery_plugin_template.js +45 -0
- data/scaffolding/standards/js_template.js +43 -0
- data/simon +282 -0
- data/test/helper.rb +18 -0
- data/test/test_simon.rb +7 -0
- data/www/.htaccess +488 -0
- data/www/404.html +32 -0
- data/www/crossdomain.xml +25 -0
- data/www/favicon.ico +0 -0
- data/www/index.php +17 -0
- data/www/lib/js/homePage.js +43 -0
- data/www/lib/js/jquery/JQbook.js +809 -0
- data/www/lib/js/jquery/jquery-1.8.0.min.js +27 -0
- data/www/lib/js/jquery/jquery.alphanumeric.js +82 -0
- data/www/lib/js/jquery/jquery.cookie.js +96 -0
- data/www/lib/js/jquery/jquery.easing.1.3.js +207 -0
- data/www/lib/js/main.js +117 -0
- data/www/lib/js/master.js +6 -0
- data/www/lib/js/plugins/handlebars-1.0.rc.1.js +1920 -0
- data/www/lib/js/plugins/modernizr-1.7.min.js +2 -0
- data/www/lib/js/plugins/swfobject.js +777 -0
- data/www/lib/js/plugins_mod/README.txt +3 -0
- data/www/lib/php/app.php +53 -0
- data/www/lib/php/controller/index.php +10 -0
- data/www/lib/php/controller/regex.php +23 -0
- data/www/lib/php/model/Book.php +8 -0
- data/www/lib/php/model/Model.php +8 -0
- data/www/lib/php/plugins/php-activerecord/ActiveRecord.php +44 -0
- data/www/lib/php/plugins/php-activerecord/lib/CallBack.php +226 -0
- data/www/lib/php/plugins/php-activerecord/lib/Column.php +155 -0
- data/www/lib/php/plugins/php-activerecord/lib/Config.php +288 -0
- data/www/lib/php/plugins/php-activerecord/lib/Connection.php +456 -0
- data/www/lib/php/plugins/php-activerecord/lib/ConnectionManager.php +38 -0
- data/www/lib/php/plugins/php-activerecord/lib/DateTime.php +45 -0
- data/www/lib/php/plugins/php-activerecord/lib/Exceptions.php +137 -0
- data/www/lib/php/plugins/php-activerecord/lib/Expressions.php +183 -0
- data/www/lib/php/plugins/php-activerecord/lib/Inflector.php +115 -0
- data/www/lib/php/plugins/php-activerecord/lib/Model.php +1673 -0
- data/www/lib/php/plugins/php-activerecord/lib/Reflections.php +86 -0
- data/www/lib/php/plugins/php-activerecord/lib/Relationship.php +637 -0
- data/www/lib/php/plugins/php-activerecord/lib/SQLBuilder.php +396 -0
- data/www/lib/php/plugins/php-activerecord/lib/Serialization.php +302 -0
- data/www/lib/php/plugins/php-activerecord/lib/Singleton.php +57 -0
- data/www/lib/php/plugins/php-activerecord/lib/Table.php +547 -0
- data/www/lib/php/plugins/php-activerecord/lib/Utils.php +351 -0
- data/www/lib/php/plugins/php-activerecord/lib/Validations.php +833 -0
- data/www/lib/php/plugins/php-activerecord/lib/adapters/MysqlAdapter.php +73 -0
- data/www/lib/php/plugins/php-activerecord/lib/adapters/OciAdapter.php +121 -0
- data/www/lib/php/plugins/php-activerecord/lib/adapters/PgsqlAdapter.php +104 -0
- data/www/lib/php/plugins/php-activerecord/lib/adapters/SqliteAdapter.php +81 -0
- data/www/lib/php/system/Config.php +174 -0
- data/www/lib/php/system/config.routes.php +29 -0
- data/www/lib/php/system/router.php +220 -0
- data/www/lib/php/template/footer.php +59 -0
- data/www/lib/php/template/header.php +74 -0
- data/www/lib/php/view/index.php +5 -0
- data/www/media/images/facebook_share.jpg +0 -0
- data/www/robots.txt +5 -0
- data/www/sandbox/readme.txt +3 -0
- data/www/sass/javascript.scss +1 -0
- data/www/sass/layout.scss +128 -0
- data/www/sass/master.scss +4 -0
- data/www/sass/reset.scss +47 -0
- data/www/sass/typography.scss +24 -0
- data/www/styles/javascript.css +1 -0
- data/www/styles/layout.css +186 -0
- data/www/styles/master.css +4 -0
- data/www/styles/reset.css +60 -0
- data/www/styles/typography.css +24 -0
- metadata +179 -7
@@ -0,0 +1,73 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* @package ActiveRecord
|
4
|
+
*/
|
5
|
+
namespace ActiveRecord;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Adapter for MySQL.
|
9
|
+
*
|
10
|
+
* @package ActiveRecord
|
11
|
+
*/
|
12
|
+
class MysqlAdapter extends Connection
|
13
|
+
{
|
14
|
+
static $DEFAULT_PORT = 3306;
|
15
|
+
|
16
|
+
public function limit($sql, $offset, $limit)
|
17
|
+
{
|
18
|
+
$offset = intval($offset);
|
19
|
+
$limit = intval($limit);
|
20
|
+
return "$sql LIMIT $offset,$limit";
|
21
|
+
}
|
22
|
+
|
23
|
+
public function query_column_info($table)
|
24
|
+
{
|
25
|
+
return $this->query("SHOW COLUMNS FROM $table");
|
26
|
+
}
|
27
|
+
|
28
|
+
public function query_for_tables()
|
29
|
+
{
|
30
|
+
return $this->query('SHOW TABLES');
|
31
|
+
}
|
32
|
+
|
33
|
+
public function create_column(&$column)
|
34
|
+
{
|
35
|
+
$c = new Column();
|
36
|
+
$c->inflected_name = Inflector::instance()->variablize($column['field']);
|
37
|
+
$c->name = $column['field'];
|
38
|
+
$c->nullable = ($column['null'] === 'YES' ? true : false);
|
39
|
+
$c->pk = ($column['key'] === 'PRI' ? true : false);
|
40
|
+
$c->auto_increment = ($column['extra'] === 'auto_increment' ? true : false);
|
41
|
+
|
42
|
+
if ($column['type'] == 'timestamp' || $column['type'] == 'datetime')
|
43
|
+
{
|
44
|
+
$c->raw_type = 'datetime';
|
45
|
+
$c->length = 19;
|
46
|
+
}
|
47
|
+
elseif ($column['type'] == 'date')
|
48
|
+
{
|
49
|
+
$c->raw_type = 'date';
|
50
|
+
$c->length = 10;
|
51
|
+
}
|
52
|
+
elseif ($column['type'] == 'time')
|
53
|
+
{
|
54
|
+
$c->raw_type = 'time';
|
55
|
+
$c->length = 8;
|
56
|
+
}
|
57
|
+
else
|
58
|
+
{
|
59
|
+
preg_match('/^([A-Za-z0-9_]+)(\(([0-9]+(,[0-9]+)?)\))?/',$column['type'],$matches);
|
60
|
+
|
61
|
+
$c->raw_type = (count($matches) > 0 ? $matches[1] : $column['type']);
|
62
|
+
|
63
|
+
if (count($matches) >= 4)
|
64
|
+
$c->length = intval($matches[3]);
|
65
|
+
}
|
66
|
+
|
67
|
+
$c->map_raw_type();
|
68
|
+
$c->default = $c->cast($column['default'],$this);
|
69
|
+
|
70
|
+
return $c;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
?>
|
@@ -0,0 +1,121 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* @package ActiveRecord
|
4
|
+
*/
|
5
|
+
namespace ActiveRecord;
|
6
|
+
|
7
|
+
use PDO;
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Adapter for OCI (not completed yet).
|
11
|
+
*
|
12
|
+
* @package ActiveRecord
|
13
|
+
*/
|
14
|
+
class OciAdapter extends Connection
|
15
|
+
{
|
16
|
+
static $QUOTE_CHARACTER = '';
|
17
|
+
static $DEFAULT_PORT = 1521;
|
18
|
+
|
19
|
+
protected function __construct($info)
|
20
|
+
{
|
21
|
+
try {
|
22
|
+
$this->connection = new PDO("oci:dbname=//$info->host/$info->db",$info->user,$info->pass,static::$PDO_OPTIONS);
|
23
|
+
} catch (PDOException $e) {
|
24
|
+
throw new DatabaseException($e);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
public function supports_sequences() { return true; }
|
29
|
+
|
30
|
+
public function get_next_sequence_value($sequence_name)
|
31
|
+
{
|
32
|
+
return $this->query_and_fetch_one('SELECT ' . $this->next_sequence_value($sequence_name) . ' FROM dual');
|
33
|
+
}
|
34
|
+
|
35
|
+
public function next_sequence_value($sequence_name)
|
36
|
+
{
|
37
|
+
return "$sequence_name.nextval";
|
38
|
+
}
|
39
|
+
|
40
|
+
public function date_to_string($datetime)
|
41
|
+
{
|
42
|
+
return $datetime->format('d-M-Y');
|
43
|
+
}
|
44
|
+
|
45
|
+
public function datetime_to_string($datetime)
|
46
|
+
{
|
47
|
+
return $datetime->format('d-M-Y h:i:s A');
|
48
|
+
}
|
49
|
+
|
50
|
+
// $string = DD-MON-YYYY HH12:MI:SS(\.[0-9]+) AM
|
51
|
+
public function string_to_datetime($string)
|
52
|
+
{
|
53
|
+
return parent::string_to_datetime(str_replace('.000000','',$string));
|
54
|
+
}
|
55
|
+
|
56
|
+
public function limit($sql, $offset, $limit)
|
57
|
+
{
|
58
|
+
$offset = intval($offset);
|
59
|
+
$stop = $offset + intval($limit);
|
60
|
+
return
|
61
|
+
"SELECT * FROM (SELECT a.*, rownum ar_rnum__ FROM ($sql) a " .
|
62
|
+
"WHERE rownum <= $stop) WHERE ar_rnum__ > $offset";
|
63
|
+
}
|
64
|
+
|
65
|
+
public function query_column_info($table)
|
66
|
+
{
|
67
|
+
$sql =
|
68
|
+
"SELECT c.column_name, c.data_type, c.data_length, c.data_scale, c.data_default, c.nullable, " .
|
69
|
+
"(SELECT a.constraint_type " .
|
70
|
+
"FROM all_constraints a, all_cons_columns b " .
|
71
|
+
"WHERE a.constraint_type='P' " .
|
72
|
+
"AND a.constraint_name=b.constraint_name " .
|
73
|
+
"AND a.table_name = t.table_name AND b.column_name=c.column_name) AS pk " .
|
74
|
+
"FROM user_tables t " .
|
75
|
+
"INNER JOIN user_tab_columns c on(t.table_name=c.table_name) " .
|
76
|
+
"WHERE t.table_name=?";
|
77
|
+
|
78
|
+
$values = array(strtoupper($table));
|
79
|
+
return $this->query($sql,$values);
|
80
|
+
}
|
81
|
+
|
82
|
+
public function query_for_tables()
|
83
|
+
{
|
84
|
+
return $this->query("SELECT table_name FROM user_tables");
|
85
|
+
}
|
86
|
+
|
87
|
+
public function create_column(&$column)
|
88
|
+
{
|
89
|
+
$column['column_name'] = strtolower($column['column_name']);
|
90
|
+
$column['data_type'] = strtolower(preg_replace('/\(.*?\)/','',$column['data_type']));
|
91
|
+
|
92
|
+
if ($column['data_default'] !== null)
|
93
|
+
$column['data_default'] = trim($column['data_default'],"' ");
|
94
|
+
|
95
|
+
if ($column['data_type'] == 'number')
|
96
|
+
{
|
97
|
+
if ($column['data_scale'] > 0)
|
98
|
+
$column['data_type'] = 'decimal';
|
99
|
+
elseif ($column['data_scale'] == 0)
|
100
|
+
$column['data_type'] = 'int';
|
101
|
+
}
|
102
|
+
|
103
|
+
$c = new Column();
|
104
|
+
$c->inflected_name = Inflector::instance()->variablize($column['column_name']);
|
105
|
+
$c->name = $column['column_name'];
|
106
|
+
$c->nullable = $column['nullable'] == 'Y' ? true : false;
|
107
|
+
$c->pk = $column['pk'] == 'P' ? true : false;
|
108
|
+
$c->length = $column['data_length'];
|
109
|
+
|
110
|
+
if ($column['data_type'] == 'timestamp')
|
111
|
+
$c->raw_type = 'datetime';
|
112
|
+
else
|
113
|
+
$c->raw_type = $column['data_type'];
|
114
|
+
|
115
|
+
$c->map_raw_type();
|
116
|
+
$c->default = $c->cast($column['data_default'],$this);
|
117
|
+
|
118
|
+
return $c;
|
119
|
+
}
|
120
|
+
};
|
121
|
+
?>
|
@@ -0,0 +1,104 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* @package ActiveRecord
|
4
|
+
*/
|
5
|
+
namespace ActiveRecord;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Adapter for Postgres (not completed yet)
|
9
|
+
*
|
10
|
+
* @package ActiveRecord
|
11
|
+
*/
|
12
|
+
class PgsqlAdapter extends Connection
|
13
|
+
{
|
14
|
+
static $QUOTE_CHARACTER = '"';
|
15
|
+
static $DEFAULT_PORT = 5432;
|
16
|
+
|
17
|
+
public function supports_sequences() { return true; }
|
18
|
+
|
19
|
+
public function get_sequence_name($table, $column_name)
|
20
|
+
{
|
21
|
+
return "{$table}_{$column_name}_seq";
|
22
|
+
}
|
23
|
+
|
24
|
+
public function next_sequence_value($sequence_name)
|
25
|
+
{
|
26
|
+
return "nextval('" . str_replace("'","\\'",$sequence_name) . "')";
|
27
|
+
}
|
28
|
+
|
29
|
+
public function limit($sql, $offset, $limit)
|
30
|
+
{
|
31
|
+
return $sql . ' LIMIT ' . intval($limit) . ' OFFSET ' . intval($offset);
|
32
|
+
}
|
33
|
+
|
34
|
+
public function query_column_info($table)
|
35
|
+
{
|
36
|
+
$sql = <<<SQL
|
37
|
+
SELECT a.attname AS field, a.attlen,
|
38
|
+
REPLACE(pg_catalog.format_type(a.atttypid, a.atttypmod),'character varying','varchar') AS type,
|
39
|
+
a.attnotnull AS not_nullable,
|
40
|
+
i.indisprimary as pk,
|
41
|
+
REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(s.column_default,'::[a-z_ ]+',''),'\'$',''),'^\'','') AS default
|
42
|
+
FROM pg_catalog.pg_attribute a
|
43
|
+
LEFT JOIN pg_catalog.pg_class c ON(a.attrelid=c.oid)
|
44
|
+
LEFT JOIN pg_catalog.pg_index i ON(c.oid=i.indrelid AND a.attnum=any(i.indkey))
|
45
|
+
LEFT JOIN information_schema.columns s ON(s.table_name=? AND a.attname=s.column_name)
|
46
|
+
WHERE a.attrelid = (select c.oid from pg_catalog.pg_class c inner join pg_catalog.pg_namespace n on(n.oid=c.relnamespace) where c.relname=? and pg_catalog.pg_table_is_visible(c.oid))
|
47
|
+
AND a.attnum > 0
|
48
|
+
AND NOT a.attisdropped
|
49
|
+
ORDER BY a.attnum
|
50
|
+
SQL;
|
51
|
+
$values = array($table,$table);
|
52
|
+
return $this->query($sql,$values);
|
53
|
+
}
|
54
|
+
|
55
|
+
public function query_for_tables()
|
56
|
+
{
|
57
|
+
return $this->query("SELECT tablename FROM pg_tables WHERE schemaname NOT IN('information_schema','pg_catalog')");
|
58
|
+
}
|
59
|
+
|
60
|
+
public function create_column(&$column)
|
61
|
+
{
|
62
|
+
$c = new Column();
|
63
|
+
$c->inflected_name = Inflector::instance()->variablize($column['field']);
|
64
|
+
$c->name = $column['field'];
|
65
|
+
$c->nullable = ($column['not_nullable'] ? false : true);
|
66
|
+
$c->pk = ($column['pk'] ? true : false);
|
67
|
+
$c->auto_increment = false;
|
68
|
+
|
69
|
+
if (substr($column['type'],0,9) == 'timestamp')
|
70
|
+
{
|
71
|
+
$c->raw_type = 'datetime';
|
72
|
+
$c->length = 19;
|
73
|
+
}
|
74
|
+
elseif ($column['type'] == 'date')
|
75
|
+
{
|
76
|
+
$c->raw_type = 'date';
|
77
|
+
$c->length = 10;
|
78
|
+
}
|
79
|
+
else
|
80
|
+
{
|
81
|
+
preg_match('/^([A-Za-z0-9_]+)(\(([0-9]+(,[0-9]+)?)\))?/',$column['type'],$matches);
|
82
|
+
|
83
|
+
$c->raw_type = (count($matches) > 0 ? $matches[1] : $column['type']);
|
84
|
+
$c->length = count($matches) >= 4 ? intval($matches[3]) : intval($column['attlen']);
|
85
|
+
|
86
|
+
if ($c->length < 0)
|
87
|
+
$c->length = null;
|
88
|
+
}
|
89
|
+
|
90
|
+
$c->map_raw_type();
|
91
|
+
|
92
|
+
if ($column['default'])
|
93
|
+
{
|
94
|
+
preg_match("/^nextval\('(.*)'\)$/",$column['default'],$matches);
|
95
|
+
|
96
|
+
if (count($matches) == 2)
|
97
|
+
$c->sequence = $matches[1];
|
98
|
+
else
|
99
|
+
$c->default = $c->cast($column['default'],$this);
|
100
|
+
}
|
101
|
+
return $c;
|
102
|
+
}
|
103
|
+
};
|
104
|
+
?>
|
@@ -0,0 +1,81 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* @package ActiveRecord
|
4
|
+
*/
|
5
|
+
namespace ActiveRecord;
|
6
|
+
|
7
|
+
use PDO;
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Adapter for SQLite.
|
11
|
+
*
|
12
|
+
* @package ActiveRecord
|
13
|
+
*/
|
14
|
+
class SqliteAdapter extends Connection
|
15
|
+
{
|
16
|
+
protected function __construct($info)
|
17
|
+
{
|
18
|
+
if (!file_exists($info->host))
|
19
|
+
throw new DatabaseException("Could not find sqlite db: $info->host");
|
20
|
+
|
21
|
+
$this->connection = new PDO("sqlite:$info->host",null,null,static::$PDO_OPTIONS);
|
22
|
+
}
|
23
|
+
|
24
|
+
public function limit($sql, $offset, $limit)
|
25
|
+
{
|
26
|
+
$offset = intval($offset);
|
27
|
+
$limit = intval($limit);
|
28
|
+
return "$sql LIMIT $offset,$limit";
|
29
|
+
}
|
30
|
+
|
31
|
+
public function query_column_info($table)
|
32
|
+
{
|
33
|
+
return $this->query("pragma table_info($table)");
|
34
|
+
}
|
35
|
+
|
36
|
+
public function query_for_tables()
|
37
|
+
{
|
38
|
+
return $this->query("SELECT name FROM sqlite_master");
|
39
|
+
}
|
40
|
+
|
41
|
+
public function create_column($column)
|
42
|
+
{
|
43
|
+
$c = new Column();
|
44
|
+
$c->inflected_name = Inflector::instance()->variablize($column['name']);
|
45
|
+
$c->name = $column['name'];
|
46
|
+
$c->nullable = $column['notnull'] ? false : true;
|
47
|
+
$c->pk = $column['pk'] ? true : false;
|
48
|
+
$c->auto_increment = $column['type'] == 'INTEGER' && $c->pk;
|
49
|
+
|
50
|
+
$column['type'] = preg_replace('/ +/',' ',$column['type']);
|
51
|
+
$column['type'] = str_replace(array('(',')'),' ',$column['type']);
|
52
|
+
$column['type'] = Utils::squeeze(' ',$column['type']);
|
53
|
+
$matches = explode(' ',$column['type']);
|
54
|
+
|
55
|
+
if (!empty($matches))
|
56
|
+
{
|
57
|
+
$c->raw_type = strtolower($matches[0]);
|
58
|
+
|
59
|
+
if (count($matches) > 1)
|
60
|
+
$c->length = intval($matches[1]);
|
61
|
+
}
|
62
|
+
|
63
|
+
$c->map_raw_type();
|
64
|
+
|
65
|
+
if ($c->type == Column::DATETIME)
|
66
|
+
$c->length = 19;
|
67
|
+
elseif ($c->type == Column::DATE)
|
68
|
+
$c->length = 10;
|
69
|
+
|
70
|
+
// From SQLite3 docs: The value is a signed integer, stored in 1, 2, 3, 4, 6,
|
71
|
+
// or 8 bytes depending on the magnitude of the value.
|
72
|
+
// so is it ok to assume it's possible an int can always go up to 8 bytes?
|
73
|
+
if ($c->type == Column::INTEGER && !$c->length)
|
74
|
+
$c->length = 8;
|
75
|
+
|
76
|
+
$c->default = $c->cast($column['dflt_value'],$this);
|
77
|
+
|
78
|
+
return $c;
|
79
|
+
}
|
80
|
+
};
|
81
|
+
?>
|
@@ -0,0 +1,174 @@
|
|
1
|
+
<?php
|
2
|
+
error_reporting(E_ALL);
|
3
|
+
ini_set('display_errors', '1');
|
4
|
+
|
5
|
+
// =======================
|
6
|
+
// = constants =
|
7
|
+
// =======================
|
8
|
+
define("LOCAL", "local_host_environment");
|
9
|
+
define("DEV", "dev_host_environment");
|
10
|
+
define("STAGE", "stage_host_environment");
|
11
|
+
define("PROD", "production_host_environment");
|
12
|
+
|
13
|
+
require_once DIR_PLUGINS.'/php-activerecord/ActiveRecord.php';
|
14
|
+
|
15
|
+
class Config {
|
16
|
+
|
17
|
+
|
18
|
+
private static $instance;
|
19
|
+
|
20
|
+
|
21
|
+
// =====================
|
22
|
+
// = production variables =
|
23
|
+
// =====================
|
24
|
+
|
25
|
+
var $environment;
|
26
|
+
var $dbhost;
|
27
|
+
var $dbuser;
|
28
|
+
var $dbpass;
|
29
|
+
var $dbname;
|
30
|
+
var $dbport;
|
31
|
+
var $cdn_path;
|
32
|
+
var $base_url;
|
33
|
+
var $use_min;
|
34
|
+
var $debug;
|
35
|
+
var $server_name;
|
36
|
+
var $analytics_id = "%google_id%";
|
37
|
+
var $protocol;
|
38
|
+
var $facebook_app_id;
|
39
|
+
var $page;
|
40
|
+
var $title = "Evolution Bureau |";
|
41
|
+
|
42
|
+
private function __construct($server_name = '') {
|
43
|
+
|
44
|
+
$this->_setprotocol();
|
45
|
+
|
46
|
+
$this->server_name = $server_name == ''?$_SERVER['SERVER_NAME']:$server_name;
|
47
|
+
|
48
|
+
|
49
|
+
switch($this->server_name) {
|
50
|
+
case "boiler.evb.com":
|
51
|
+
|
52
|
+
$this->environment = LOCAL;
|
53
|
+
$this->dbhost = '%l_host%';
|
54
|
+
$this->dbuser = "%l_user%";
|
55
|
+
$this->dbpass = "%l_pass%";
|
56
|
+
$this->dbname = "%l_dbname%";
|
57
|
+
$this->cdn_path = "/";
|
58
|
+
$this->base_url = "/";
|
59
|
+
$this->use_min = FALSE;
|
60
|
+
$this->debug = FALSE;
|
61
|
+
$this->facebook_app_id = "";
|
62
|
+
|
63
|
+
break;
|
64
|
+
|
65
|
+
case "production_url.com":
|
66
|
+
//turn off error reporting for production
|
67
|
+
error_reporting(0);
|
68
|
+
ini_set('display_errors', '0');
|
69
|
+
$this->environment = PROD;
|
70
|
+
$this->dbhost = 'localhost';
|
71
|
+
$this->dbuser = "root";
|
72
|
+
$this->dbpass = "root";
|
73
|
+
$this->dbname = "DATABASE_NAME";
|
74
|
+
$this->cdn_path = "";
|
75
|
+
$this->base_url = "/";
|
76
|
+
$this->use_min = FALSE;
|
77
|
+
$this->debug = FALSE;
|
78
|
+
$this->facebook_app_id = "";
|
79
|
+
|
80
|
+
break;
|
81
|
+
|
82
|
+
default:
|
83
|
+
trigger_error('No environment domain has been setup. (e.g. local, development, stage) ', E_USER_ERROR);
|
84
|
+
// =================================================================================
|
85
|
+
// = Please copy and paste a case in the switch statment for your local enviroment =
|
86
|
+
// =================================================================================
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
|
90
|
+
$this->_setup_db();
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
public static function getInstance() {
|
97
|
+
if (!isset(self::$instance)) {
|
98
|
+
$c = __CLASS__;
|
99
|
+
self::$instance = new $c;
|
100
|
+
}
|
101
|
+
|
102
|
+
return self::$instance;
|
103
|
+
}
|
104
|
+
|
105
|
+
public function app_vars_JSON(){
|
106
|
+
$ar = array(
|
107
|
+
"environment" => $this->environment,
|
108
|
+
"cdn_path" => $this->cdn_path,
|
109
|
+
"facebook_app_id" => $this->facebook_app_id,
|
110
|
+
"debug" => $this->debug,
|
111
|
+
"page" => $this->page,
|
112
|
+
"title" => $this->title,
|
113
|
+
"base_url" => $this->base_url,
|
114
|
+
);
|
115
|
+
return json_encode($ar);
|
116
|
+
}
|
117
|
+
|
118
|
+
public function setPage($p_page){
|
119
|
+
|
120
|
+
$this->page = $p_page;
|
121
|
+
}
|
122
|
+
|
123
|
+
public function getPageTitle(){
|
124
|
+
|
125
|
+
echo $this->title.'-> '.$this->page;
|
126
|
+
}
|
127
|
+
|
128
|
+
public function getBaseUrl() {
|
129
|
+
|
130
|
+
return $this->base_url;
|
131
|
+
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
public function getConnectionSettings() {
|
136
|
+
return array(
|
137
|
+
'hostname' => $this->dbhost,
|
138
|
+
'port' => $this->dbport, //'3306'
|
139
|
+
'username' => $this->dbuser,
|
140
|
+
'password' => $this->dbpass,
|
141
|
+
'database' => $this->dbname,
|
142
|
+
'debug' => $this->debug
|
143
|
+
);
|
144
|
+
}
|
145
|
+
|
146
|
+
private function _setprotocol(){
|
147
|
+
|
148
|
+
if($_SERVER['SERVER_PORT'] == 80){
|
149
|
+
$this->protocol = "http";
|
150
|
+
}else{
|
151
|
+
$this->protocol = "https";
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
private function _setup_db(){
|
156
|
+
|
157
|
+
$connections = array(
|
158
|
+
'development' => 'mysql://'.$this->dbuser.':'.$this->dbpass.'@'.$this->dbhost.'/'.$this->dbname
|
159
|
+
);
|
160
|
+
|
161
|
+
# must issue a "use" statement in your closure if passing variables
|
162
|
+
ActiveRecord\Config::initialize(function($cfg) use ($connections)
|
163
|
+
{
|
164
|
+
$cfg->set_model_directory($_SERVER['DOCUMENT_ROOT'].'/lib/php/model');
|
165
|
+
$cfg->set_connections($connections);
|
166
|
+
$cfg->set_default_connection('development');
|
167
|
+
});
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
?>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
Router::add('/', DIR_CTRL.'/index.php');
|
4
|
+
Router::add('#^/regex/(test1|test2|test3)/$#', DIR_CTRL.'/regex.php', Router::ROUTE_PCRE);
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Routes are added with the static method Router::add($pattern, $replacement)
|
8
|
+
* It is processed as preg_replace($pattern, $replace) in the router class, so
|
9
|
+
* use any style for $pattern. Though it would be best to use # for pattern
|
10
|
+
* delimiters and ${n} for the replacement string variables. To carry a string
|
11
|
+
* from the pattern, just put them in parentheses (). These are run in order,
|
12
|
+
* and first one that matches and has a readable controller file is used.
|
13
|
+
*
|
14
|
+
* PHP's preg_replace: http://php.net/preg_replace/
|
15
|
+
*
|
16
|
+
* examples:
|
17
|
+
*
|
18
|
+
* Router::add('#/#', DIR_CTRL.'index.php', Router::ROUTE_PCRE);
|
19
|
+
* sends index page to the index.php contoller
|
20
|
+
*
|
21
|
+
* Router::add('#/news/(archive|latest)/#', DIR_CTRL.'news.${1}.php', Router::ROUTE_PCRE);
|
22
|
+
* /news/archive/ goes to news.archive.php
|
23
|
+
*
|
24
|
+
* you can also do this
|
25
|
+
*
|
26
|
+
* Router::add('#/news/(archive|latest)/#', DIR_CTRL.'news/${1}.php', Router::ROUTE_PCRE);
|
27
|
+
* /news/archive/ goes to news/archive.php
|
28
|
+
*/
|
29
|
+
?>
|