Browse Source

Initial commit

Sven Slootweg 8 years ago
commit
17929c5197
89 changed files with 6653 additions and 0 deletions
  1. 22 0
      classes/class.country.php
  2. 29 0
      classes/class.location.php
  3. 20 0
      classes/class.paymentmethod.php
  4. 23 0
      classes/class.plan.locationoption.php
  5. 47 0
      classes/class.plan.php
  6. 21 0
      classes/class.plan.priceoption.php
  7. 29 0
      classes/class.provider.php
  8. 16 0
      classes/class.technology.php
  9. 16 0
      classes/class.virtualizationplatform.php
  10. 30 0
      cphp/base.php
  11. 143 0
      cphp/class.base.php
  12. 381 0
      cphp/class.databaserecord.php
  13. 64 0
      cphp/class.localizer.php
  14. 112 0
      cphp/class.templater.php
  15. 60 0
      cphp/components/component.errorhandler.php
  16. 379 0
      cphp/components/component.formbuilder.php
  17. 40 0
      cphp/components/component.router.php
  18. 36 0
      cphp/config.php
  19. 13 0
      cphp/include.constants.php
  20. 169 0
      cphp/include.datetime.php
  21. 90 0
      cphp/include.dependencies.php
  22. 12 0
      cphp/include.exceptions.php
  23. 145 0
      cphp/include.memcache.php
  24. 90 0
      cphp/include.misc.php
  25. 16 0
      cphp/include.mysql.php
  26. 5 0
      cphp/include.session.php
  27. BIN
      css/custom-theme/images/ui-bg_diagonals-medium_15_3d4b8a_40x40.png
  28. BIN
      css/custom-theme/images/ui-bg_flat_0_aaaaaa_40x100.png
  29. BIN
      css/custom-theme/images/ui-bg_glass_95_fef1ec_1x400.png
  30. BIN
      css/custom-theme/images/ui-bg_gloss-wave_16_121212_500x100.png
  31. BIN
      css/custom-theme/images/ui-bg_highlight-hard_55_555555_1x100.png
  32. BIN
      css/custom-theme/images/ui-bg_highlight-soft_35_adadad_1x100.png
  33. BIN
      css/custom-theme/images/ui-bg_highlight-soft_60_dddddd_1x100.png
  34. BIN
      css/custom-theme/images/ui-bg_inset-soft_15_121212_1x100.png
  35. BIN
      css/custom-theme/images/ui-icons_666666_256x240.png
  36. BIN
      css/custom-theme/images/ui-icons_aaaaaa_256x240.png
  37. BIN
      css/custom-theme/images/ui-icons_bbbbbb_256x240.png
  38. BIN
      css/custom-theme/images/ui-icons_c98000_256x240.png
  39. BIN
      css/custom-theme/images/ui-icons_cccccc_256x240.png
  40. BIN
      css/custom-theme/images/ui-icons_cd0a0a_256x240.png
  41. BIN
      css/custom-theme/images/ui-icons_f29a00_256x240.png
  42. 287 0
      css/custom-theme/jquery-ui-1.8.18.custom.css
  43. BIN
      css/dot-luv/images/ui-bg_diagonals-thick_15_0b3e6f_40x40.png
  44. BIN
      css/dot-luv/images/ui-bg_dots-medium_30_0b58a2_4x4.png
  45. BIN
      css/dot-luv/images/ui-bg_dots-small_20_333333_2x2.png
  46. BIN
      css/dot-luv/images/ui-bg_dots-small_30_a32d00_2x2.png
  47. BIN
      css/dot-luv/images/ui-bg_dots-small_40_00498f_2x2.png
  48. BIN
      css/dot-luv/images/ui-bg_flat_0_aaaaaa_40x100.png
  49. BIN
      css/dot-luv/images/ui-bg_flat_40_292929_40x100.png
  50. BIN
      css/dot-luv/images/ui-bg_gloss-wave_20_111111_500x100.png
  51. BIN
      css/dot-luv/images/ui-icons_00498f_256x240.png
  52. BIN
      css/dot-luv/images/ui-icons_98d2fb_256x240.png
  53. BIN
      css/dot-luv/images/ui-icons_9ccdfc_256x240.png
  54. BIN
      css/dot-luv/images/ui-icons_ffffff_256x240.png
  55. 565 0
      css/dot-luv/jquery-ui-1.8.18.custom.css
  56. BIN
      css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
  57. BIN
      css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
  58. BIN
      css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
  59. BIN
      css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
  60. BIN
      css/smoothness/images/ui-bg_glass_75_dadada_1x400.png
  61. BIN
      css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
  62. BIN
      css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
  63. BIN
      css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
  64. BIN
      css/smoothness/images/ui-icons_222222_256x240.png
  65. BIN
      css/smoothness/images/ui-icons_2e83ff_256x240.png
  66. BIN
      css/smoothness/images/ui-icons_454545_256x240.png
  67. BIN
      css/smoothness/images/ui-icons_888888_256x240.png
  68. BIN
      css/smoothness/images/ui-icons_cd0a0a_256x240.png
  69. 565 0
      css/smoothness/jquery-ui-1.8.18.custom.css
  70. 522 0
      css/table.css
  71. 679 0
      css/vps.css
  72. BIN
      images/icons/dedicated.png
  73. BIN
      images/icons/no.png
  74. BIN
      images/icons/shared.png
  75. BIN
      images/icons/unknown.png
  76. BIN
      images/icons/yes.png
  77. 313 0
      index.php
  78. 4 0
      js/jquery-1.7.1.min.js
  79. 356 0
      js/jquery-ui-1.8.18.custom.min.js
  80. 519 0
      js/vps.js
  81. 24 0
      locales/english.lng
  82. 81 0
      mod.php
  83. 333 0
      quickadd.php
  84. 101 0
      templates/element.vps.tpl
  85. 67 0
      templates/frame.tpl
  86. 4 0
      templates/page.add.tpl
  87. 24 0
      templates/page.donate.tpl
  88. 200 0
      templates/page.list.tpl
  89. 1 0
      templates/page.main.tpl

+ 22 - 0
classes/class.country.php

@ -0,0 +1,22 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class Country extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM countries WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM countries WHERE `Id` = '%d'";
8
	public $table_name = "countries";
9
	
10
	public $prototype = array(
11
		'string' => array(
12
			'Name'				=> "name",
13
			'PrintableName'		=> "printable_name",
14
			'Iso'				=> "iso",
15
			'Iso3'				=> "iso3"
16
		),
17
		'numeric' => array(
18
			'NumericCode'		=> "numcode"
19
		)
20
	);
21
}
22
?>

+ 29 - 0
classes/class.location.php

@ -0,0 +1,29 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class Location extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM locations WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM locations WHERE `Id` = '%d'";
8
	public $table_name = "locations";
9
	
10
	public $prototype = array(
11
		'string' => array(
12
			'Location'			=> "Location",
13
			'TestIp4'			=> "TestIp4",
14
			'TestIp6'			=> "TestIp6",
15
			'TestFile'			=> "TestFile"
16
		),
17
		'numeric' => array(
18
			'CountryId'			=> "CountryId",
19
			'ProviderId'		=> "ProviderId"
20
		),
21
		'country' => array(
22
			'Country'			=> "CountryId"
23
		),
24
		'provider' => array(
25
			'Provider'			=> "ProviderId"
26
		)
27
	);
28
}
29
?>

+ 20 - 0
classes/class.paymentmethod.php

@ -0,0 +1,20 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class PaymentMethod extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM paymentmethods WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM paymentmethods WHERE `Id` = '%d'";
8
	public $table_name = "paymentmethods";
9
	
10
	public $prototype = array(
11
		'string' => array(
12
			'Name'			=> "Name",
13
			'Icon'			=> "Icon"
14
		),
15
		'boolean' => array(
16
			'IsAnonymous'	=> "Anonymous"
17
		)
18
	);
19
}
20
?>

+ 23 - 0
classes/class.plan.locationoption.php

@ -0,0 +1,23 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class PlanLocationOption extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM plan_locationoptions WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM plan_locationoptions WHERE `Id` = '%d'";
8
	public $table_name = "plan_locationoptions";
9
	
10
	public $prototype = array(
11
		'numeric' => array(
12
			'PlanId'			=> "PlanId",
13
			'LocationId'		=> "LocationId"
14
		),
15
		'plan' => array(
16
			'Plan'				=> "PlanId"
17
		),
18
		'location' => array(
19
			'Location'			=> "LocationId"
20
		)
21
	);
22
}
23
?>

+ 47 - 0
classes/class.plan.php

@ -0,0 +1,47 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class Plan extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM plans WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM plans WHERE `Id` = '%d'";
8
	public $table_name = "plans";
9
	
10
	public $prototype = array(
11
		'string' => array(
12
			'Name'						=> "Name"
13
		),
14
		'numeric' => array(
15
			'ProviderId'				=> "ProviderId",
16
			'Traffic'					=> "Traffic",
17
			'DiskSpace'					=> "DiskSpace",
18
			'CpuCores'					=> "CpuCores",
19
			'Bandwidth'					=> "Bandwidth",
20
			'GuaranteedRam'				=> "GuaranteedRam",
21
			'BurstRam'					=> "BurstRam",
22
			'AllowsIrc'					=> "AllowsIrc",
23
			'BackupSpace'				=> "BackupSpace",
24
			'VirtualizationPlatformId'	=> "VirtualizationPlatformId"
25
		),
26
		'boolean' => array(
27
			'IsUnmetered'				=> "Unmetered",
28
			'HasIpv4'					=> "HasIpv4",
29
			'HasIpv6'					=> "HasIpv6",
30
			'FreeDns'					=> "FreeDns",
31
			'OverageBilling'			=> "OverageBilling",
32
			'DedicatedCpu'				=> "DedicatedCpu",
33
			'Visible'					=> "Visible"
34
		),
35
		'timestamp' => array(
36
			'LastUpdate'				=> "LastUpdated",
37
			'SubmissionDate'			=> "SubmissionDate"
38
		),
39
		'provider' => array(
40
			'Provider'					=> "ProviderId"
41
		),
42
		'virtualizationplatform' => array(
43
			'VirtualizationPlatform'	=> "VirtualizationPlatformId"
44
		)
45
	);
46
}
47
?>

+ 21 - 0
classes/class.plan.priceoption.php

@ -0,0 +1,21 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class PlanPriceOption extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM plan_priceoptions WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM plan_priceoptions WHERE `Id` = '%d'";
8
	public $table_name = "plan_priceoptions";
9
	
10
	public $prototype = array(
11
		'numeric' => array(
12
			'BillingPeriod'		=> "BillingPeriod",
13
			'Price'				=> "Price",
14
			'PlanId'			=> "PlanId"
15
		),
16
		'plan' => array(
17
			'Plan'				=> "PlanId"
18
		)
19
	);
20
}
21
?>

+ 29 - 0
classes/class.provider.php

@ -0,0 +1,29 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class Provider extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM providers WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM providers WHERE `Id` = '%d'";
8
	public $table_name = "providers";
9
	
10
	public $prototype = array(
11
		'string' => array(
12
			'Name'				=> "Name",
13
			'Url'				=> "Url",
14
			'CompanyLocation'	=> "Location"
15
		),
16
		'numeric' => array(
17
			'PlanCount'			=> "PlanCount",
18
			'UsesMaxmind'		=> "Maxmind"
19
		),
20
		'boolean' => array(
21
			'Visible'			=> "Visible",
22
			'CustomPossible'	=> "CustomPossible"
23
		),
24
		'timestamp' => array(
25
			'SubmissionDate'	=> "SubmissionDate"
26
		)
27
	);
28
}
29
?>

+ 16 - 0
classes/class.technology.php

@ -0,0 +1,16 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class VirtualizationTechnology extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM technologies WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM technologies WHERE `Id` = '%d'";
8
	public $table_name = "technologies";
9
	
10
	public $prototype = array(
11
		'string' => array(
12
			'Name'				=> "Name"
13
		)
14
	);
15
}
16
?>

+ 16 - 0
classes/class.virtualizationplatform.php

@ -0,0 +1,16 @@
1
<?php
2
if($_VPS !== true) { die("x"); }
3
4
class VirtualizationPlatform extends CPHPDatabaseRecordClass
5
{
6
	public $fill_query = "SELECT * FROM virtualizationplatforms WHERE `Id` = '%d'";
7
	public $verify_query = "SELECT * FROM virtualizationplatforms WHERE `Id` = '%d'";
8
	public $table_name = "virtualizationplatforms";
9
	
10
	public $prototype = array(
11
		'string' => array(
12
			'Name'				=> "Name"
13
		)
14
	);
15
}
16
?>

+ 30 - 0
cphp/base.php

@ -0,0 +1,30 @@
1
<?php
2
require("include.constants.php");
3
4
require("config.php");
5
6
require("include.dependencies.php");
7
require("include.exceptions.php");
8
require("include.datetime.php");
9
require("include.misc.php");
10
11
require("include.memcache.php");
12
require("include.mysql.php");
13
require("include.session.php");
14
15
require("class.templater.php");
16
require("class.localizer.php");
17
18
$locale = new Localizer();
19
$locale->Load($cphp_locale_name);
20
21
setlocale(LC_ALL, $locale->locale);
22
23
require("class.base.php");
24
require("class.databaserecord.php");
25
26
foreach($cphp_components as $component)
27
{
28
	require("components/component.{$component}.php");
29
}
30
?>

+ 143 - 0
cphp/class.base.php

@ -0,0 +1,143 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
class CPHPBaseClass
5
{
6
	public $render_template = "";
7
	
8
	public function RenderTimeAgo($template, $property)
9
	{
10
		global $locale;
11
		
12
		$variable_name = "s{$property}";
13
		
14
		if(isset($this->$variable_name) && is_numeric($this->$variable_name))
15
		{
16
			$timestamp = $this->$variable_name;
17
			
18
			if($timestamp > time())
19
			{
20
				$sTimeAgo = $locale->strings['event-future'];
21
			}
22
			elseif($timestamp == time())
23
			{
24
				$sTimeAgo = $locale->strings['event-now'];
25
			}
26
			else
27
			{
28
				$date1 = new DateTime("@{$timestamp}", new DateTimeZone("GMT"));
29
				$date2 = new DateTime("now", new DateTimeZone("GMT"));
30
				
31
				$interval = $date1->diff($date2);
32
				$years = (int)$interval->format("%G"); 
33
				$months = (int)$interval->format("%m"); 
34
				$weeks = (int)$interval->format("%U"); 
35
				$days = (int)$interval->format("%d"); 
36
				$hours = (int)$interval->format("%H");
37
				$minutes = (int)$interval->format("%i");
38
				$seconds = (int)$interval->format("%S");
39
				
40
				if($years > 1)
41
				{
42
					$sTimeAgo = sprintf($locale->strings['event-years-ago'], $years);
43
				}
44
				elseif($years == 1)
45
				{
46
					$sTimeAgo = $locale->strings['event-1year-ago'];
47
				}
48
				elseif($months > 1)
49
				{
50
					$sTimeAgo = sprintf($locale->strings['event-months-ago'], $months);
51
				}
52
				elseif($months == 1)
53
				{
54
					$sTimeAgo = $locale->strings['event-1month-ago'];
55
				}
56
				elseif($weeks > 1)
57
				{
58
					$sTimeAgo = sprintf($locale->strings['event-weeks-ago'], $weeks);
59
				}
60
				elseif($weeks == 1)
61
				{
62
					$sTimeAgo = $locale->strings['event-1week-ago'];
63
				}
64
				elseif($days > 1)
65
				{
66
					$sTimeAgo = sprintf($locale->strings['event-days-ago'], $days);
67
				}
68
				elseif($days == 1)
69
				{
70
					$sTimeAgo = $locale->strings['event-1day-ago'];
71
				}
72
				elseif($hours > 1)
73
				{
74
					$sTimeAgo = sprintf($locale->strings['event-hours-ago'], $hours);
75
				}
76
				elseif($hours == 1)
77
				{
78
					$sTimeAgo = $locale->strings['event-1hour-ago'];
79
				}
80
				elseif($minutes > 1)
81
				{
82
					$sTimeAgo = sprintf($locale->strings['event-minutes-ago'], $minutes);
83
				}
84
				elseif($minutes == 1)
85
				{
86
					$sTimeAgo = $locale->strings['event-1minute-ago'];
87
				}
88
				elseif($seconds > 1)
89
				{
90
					$sTimeAgo = sprintf($locale->strings['event-seconds-ago'], $seconds);
91
				}
92
				elseif($seconds == 1)
93
				{
94
					$sTimeAgo = $locale->strings['event-1second-ago'];
95
				}
96
				else
97
				{
98
					// If you see this, there's probably something wrong.
99
					$sTimeAgo = $locale->strings['event-past'];
100
				}
101
				
102
			}
103
			
104
			$sDate = local_from_unix($timestamp, $locale->datetime_long);
105
			
106
			return $this->RenderTemplateExternal($template, array(
107
				'local-time'	=> $sDate,
108
				'time-ago'		=> $sTimeAgo,
109
				'timestamp'		=> $timestamp
110
			));
111
		}
112
		else
113
		{
114
			$classname = get_class($this);
115
			throw new Exception("Property {$classname}.{$property} does not exist or is not of a valid format.");
116
		}
117
	}
118
	
119
	public function RenderTemplateExternal($template, $strings)
120
	{
121
		return $this->DoRenderTemplate($template, $strings);
122
	}
123
	
124
	public function DoRenderTemplate($template, $strings)
125
	{
126
		global $locale;
127
		
128
		try
129
		{
130
			$tpl = new Templater();
131
			$tpl->Load($template);
132
			$tpl->Localize($locale->strings);
133
			$tpl->Compile($strings);
134
			return $tpl->Render();
135
		}
136
		catch(Exception $e)
137
		{
138
			$classname = get_class($this);
139
			throw new Exception("Failed to render template {$classname}.{$template}.");
140
		}
141
	}
142
}
143
?>

+ 381 - 0
cphp/class.databaserecord.php

@ -0,0 +1,381 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
abstract class CPHPDatabaseRecordClass extends CPHPBaseClass
5
{
6
	public $fill_query = "";
7
	public $verify_query = "";
8
	public $table_name = "";
9
	public $query_cache = 60;
10
	
11
	public $prototype = array();
12
	public $prototype_render = array();	
13
	public $uData = array();
14
	
15
	public $sId = 0;
16
	
17
	public function __construct($uDataSource, $uCommunityId = 0)
18
	{
19
		$this->ConstructDataset($uDataSource, $uCommunityId);
20
	}
21
	
22
	public function ConstructDataset($uDataSource, $uCommunityId = 0)
23
	{
24
		$bind_datasets = true;
25
		
26
		if(is_numeric($uDataSource))
27
		{
28
			if($uDataSource != 0)
29
			{
30
				if(!empty($this->fill_query))
31
				{
32
					$this->sId = (is_numeric($uDataSource)) ? $uDataSource : 0;
33
					
34
					$query = sprintf($this->fill_query, $uDataSource);
35
					if($result = mysql_query_cached($query, $this->query_cache))
36
					{
37
						$uDataSource = $result->data[0];
38
					}
39
					else
40
					{
41
						$classname = get_class($this);
42
						throw new NotFoundException("Could not locate {$classname} {$uDataSource} in database.");
43
					}
44
				}
45
				else
46
				{
47
					$classname = get_class($this);
48
					throw new PrototypeException("No fill query defined for {$classname} class.");
49
				}
50
			}
51
			else
52
			{
53
				$bind_datasets = false;
54
			}
55
		}
56
		elseif(is_object($uDataSource))
57
		{
58
			if(isset($uDataSource->data[0]))
59
			{
60
				$uDataSource = $uDataSource->data[0];
61
			}
62
			else
63
			{
64
				throw new NotFoundException("No result set present in object.");
65
			}
66
		}
67
		elseif(is_array($uDataSource))
68
		{
69
			if(isset($uDataSource[0]))
70
			{
71
				$uDataSource = $uDataSource[0];
72
			}
73
		}
74
		else
75
		{
76
			$classname = get_class($this);
77
			throw new ConstructorException("Invalid type passed on to constructor for object of type {$classname}.");
78
		}
79
		
80
		if($bind_datasets === true)
81
		{
82
			$this->sId = (is_numeric($uDataSource['Id'])) ? $uDataSource['Id'] : 0;
83
			
84
			$this->uData = $uDataSource;
85
			
86
			foreach($this->prototype as $type => $dataset)
87
			{
88
				$this->BindDataset($type, $dataset);
89
			}
90
			
91
			$this->sFound = true;
92
		}
93
		else
94
		{
95
			$this->sFound = false;
96
		}
97
		
98
		if(!empty($uCommunityId) && !empty($this->sCommunityId))
99
		{
100
			$sCommunityId = (is_numeric($uCommunityId)) ? $uCommunityId : 0;
101
			
102
			if($sCommunityId != $this->sCommunity->sId)
103
			{
104
				$classname = get_class($this);
105
				throw new OwnershipException("{$classname} {$this->sId} does not belong to Community {$sCommunityId}.");
106
			}
107
		}
108
	}
109
	
110
	public function BindDataset($type, $dataset)
111
	{
112
		global $cphp_class_map;
113
		
114
		if(is_array($dataset))
115
		{
116
			foreach($dataset as $variable_name => $column_name) 
117
			{
118
				$original_value = $this->uData[$column_name];
119
				
120
				switch($type)
121
				{
122
					case "string":
123
						$value = htmlspecialchars(stripslashes($original_value));
124
						$variable_type = CPHP_VARIABLE_SAFE;
125
						break;
126
					case "html":
127
						$value = filter_html(stripslashes($original_value));
128
						$variable_type = CPHP_VARIABLE_SAFE;
129
						break;
130
					case "simplehtml":
131
						$value = filter_html_strict(stripslashes($original_value));
132
						$variable_type = CPHP_VARIABLE_SAFE;
133
						break;
134
					case "nl2br":
135
						$value = nl2br(htmlspecialchars(stripslashes($original_value)), false);
136
						$variable_type = CPHP_VARIABLE_SAFE;
137
						break;
138
					case "numeric":
139
						$value = (is_numeric($original_value)) ? $original_value : 0;
140
						$variable_type = CPHP_VARIABLE_SAFE;
141
						break;
142
					case "timestamp":
143
						$value = unix_from_mysql($original_value);
144
						$variable_type = CPHP_VARIABLE_SAFE;
145
						break;
146
					case "boolean":
147
						$value = (empty($original_value)) ? false : true;
148
						$variable_type = CPHP_VARIABLE_SAFE;
149
						break;
150
					case "user":
151
						$value = new User($original_value);
152
						$variable_type = CPHP_VARIABLE_SAFE;
153
						break;
154
					case "none":
155
						$value = $original_value;
156
						$variable_type = CPHP_VARIABLE_UNSAFE;
157
						break;
158
					default:
159
						$found = false;
160
						foreach($cphp_class_map as $class_type => $class_name)
161
						{
162
							if($type == $class_type)
163
							{
164
								$value = new $class_name($original_value);
165
								$variable_type = CPHP_VARIABLE_SAFE;
166
								$found = true;
167
							}
168
						}
169
						
170
						if($found == false)
171
						{
172
							$classname = get_class($this);
173
							throw new Exception("Cannot determine type of dataset ({$type}) passed on to {$classname}.BindDataset."); 
174
							break;
175
						}
176
				}
177
				
178
				if($variable_type == CPHP_VARIABLE_SAFE)
179
				{
180
					$variable_name_safe = "s" . $variable_name;
181
					$this->$variable_name_safe = $value;
182
				}
183
				
184
				$variable_name_unsafe = "u" . $variable_name;
185
				$this->$variable_name_unsafe = $original_value;
186
			}
187
		}
188
		else
189
		{
190
			$classname = get_class($this);
191
			throw new Exception("Invalid dataset passed on to {$classname}.BindDataset."); 
192
		}
193
	}
194
	
195
	public function DoRenderInternalTemplate()
196
	{
197
		if(!empty($this->render_template))
198
		{
199
			$strings = array();
200
			foreach($this->prototype_render as $template_var => $object_var)
201
			{
202
				$variable_name = "s" . $object_var;
203
				$strings[$template_var] = $this->$variable_name;
204
			}
205
			return $this->DoRenderTemplate($this->render_template, $strings);
206
		}
207
		else
208
		{
209
			$classname = get_class($this);
210
			throw new Exception("Cannot render template: no template defined for {$classname} class.");
211
		}
212
	}
213
	
214
	public function InsertIntoDatabase()
215
	{
216
		if(!empty($this->verify_query))
217
		{
218
			if($this->sId == 0)
219
			{
220
				$insert_mode = CPHP_INSERTMODE_INSERT;
221
			}
222
			else
223
			{
224
				$query = sprintf($this->verify_query, $this->sId);
225
				if($result = mysql_query_cached($query))
226
				{
227
					$insert_mode = CPHP_INSERTMODE_UPDATE;
228
				}
229
				else
230
				{
231
					$insert_mode = CPHP_INSERTMODE_INSERT;
232
				}
233
			}
234
			
235
			$element_list = array();
236
			
237
			foreach($this->prototype as $type_key => $type_value)
238
			{
239
				foreach($type_value as $element_key => $element_value)
240
				{
241
					switch($type_key)
242
					{
243
						case "none":
244
						case "numeric":
245
						case "boolean":
246
						case "timestamp":
247
						case "string":
248
							$element_list[$element_value] = array(
249
								'key'	=> $element_key,
250
								'type'	=> $type_key
251
							);
252
							break;
253
						default:
254
							break;
255
					}
256
				}
257
			}
258
			
259
			$sKeyList = array();
260
			$sValueList = array();
261
			
262
			foreach($element_list as $sKey => $value)
263
			{				
264
				$variable_name_safe = "s" . $value['key'];
265
				$variable_name_unsafe = "u" . $value['key'];
266
				
267
				if(isset($this->$variable_name_safe) || isset($this->$variable_name_unsafe))
268
				{
269
					switch($value['type'])
270
					{
271
						case "none":
272
							$sFinalValue = mysql_real_escape_string($this->$variable_name_unsafe);
273
							break;
274
						case "numeric":
275
							$number = (isset($this->$variable_name_unsafe)) ? $this->$variable_name_unsafe : $this->$variable_name_safe;
276
							$sFinalValue = (is_numeric($number)) ? $number : 0;
277
							break;
278
						case "boolean":
279
							$bool = (isset($this->$variable_name_unsafe)) ? $this->$variable_name_unsafe : $this->$variable_name_safe;
280
							$sFinalValue = ($bool) ? "1" : "0";
281
							break;
282
						case "timestamp":
283
							$sFinalValue = (isset($this->$variable_name_safe)) ? mysql_from_unix($this->$variable_name_safe) : mysql_from_unix(unix_from_local($this->$variable_name_unsafe));
284
							break;
285
						case "string":
286
							$sFinalValue = (isset($this->$variable_name_unsafe)) ? mysql_real_escape_string($this->$variable_name_unsafe) : mysql_real_escape_string($this->$variable_name_safe);
287
							break;
288
						case "default":
289
							$sFinalValue = mysql_real_escape_string($this->$variable_name_unsafe);
290
							break;
291
					}
292
					
293
					$sFinalValue = "'{$sFinalValue}'";
294
					$sKey = "`{$sKey}`";
295
					
296
					$sKeyList[] = $sKey;
297
					$sValueList[] = $sFinalValue;
298
				}
299
				else
300
				{
301
					$classname = get_class($this);
302
					throw new Exception("Database insertion failed: prototype property {$value['key']} not found in object of type {$classname}.");
303
				}
304
			}
305
			
306
			
307
			if($insert_mode == CPHP_INSERTMODE_INSERT)
308
			{
309
				$sQueryKeys = implode(", ", $sKeyList);
310
				$sQueryValues = implode(", ", $sValueList);
311
				$query = "INSERT INTO {$this->table_name} ({$sQueryKeys}) VALUES ({$sQueryValues})";
312
			}
313
			elseif($insert_mode == CPHP_INSERTMODE_UPDATE)
314
			{
315
				$sKeyValueList = array();
316
				
317
				for($i = 0; $i < count($sKeyList); $i++)
318
				{
319
					$sKey = $sKeyList[$i];
320
					$sValue = $sValueList[$i];
321
					$sKeyValueList[] = "{$sKey} = {$sValue}";
322
				}
323
				
324
				$sQueryKeysValues = implode(", ", $sKeyValueList);
325
				$query = "UPDATE {$this->table_name} SET {$sQueryKeysValues} WHERE `Id` = '{$this->sId}'";
326
			}
327
			
328
			if($result = mysql_query($query))
329
			{
330
				if($insert_mode == CPHP_INSERTMODE_INSERT)
331
				{
332
					$this->sId = mysql_insert_id();
333
				}
334
				
335
				return $result;
336
			}
337
			else
338
			{
339
				$classname = get_class($this);
340
				throw new DatabaseException("Database insertion query failed in object of type {$classname}. Error message: " . mysql_error());
341
			}
342
		}
343
		else
344
		{
345
			$classname = get_class($this);
346
			throw new Exception("No verification query defined for {$classname} class.");
347
		}
348
	}
349
	
350
	public function RetrieveChildren($type, $field)
351
	{
352
		if(!isset($cphp_class_map[$type]))
353
		{
354
			$classname = get_class($this);
355
			throw new NotFoundException("Non-existent 'type' argument passed on to {$classname}.RetrieveChildren function.");
356
		}
357
		
358
		$parent_type = get_parent_class($cphp_class_map[$type]);
359
		if($parent_type !== "CPHPDatabaseRecordClass")
360
		{
361
			$parent_type = ($parent_type === false) ? "NONE" : $parent_type;
362
			$classname = get_class($this);
363
			throw new TypeException("{$classname}.RetrieveChildren expected 'type' argument of parent-type CPHPDatabaseRecordClass, but got {$parent_type} instead.");
364
		}
365
		
366
		$query = "";
367
	}
368
	
369
	public function PurgeCache()
370
	{
371
		$query = sprintf($this->fill_query, $this->sId);
372
		$key = md5($query) . md5($query . "x");
373
		mc_delete($key);
374
	}
375
	
376
	public function RenderTemplate()
377
	{
378
		return $this->DoRenderInternalTemplate();
379
	}
380
}
381
?>

+ 64 - 0
cphp/class.localizer.php

@ -0,0 +1,64 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
class Localizer
5
{
6
	public $strings = array();
7
	public $locale = "";
8
	public $datetime_short = "";
9
	public $datetime_long = "";
10
	public $date_short = "";
11
	public $date_long = "";
12
	public $time = "";
13
	
14
	public function Load($locale)
15
	{
16
		global $cphp_locale_path, $cphp_locale_ext;
17
		
18
		$this->strings = array();
19
		$lng_contents = file_get_contents("{$cphp_locale_path}/{$locale}.{$cphp_locale_ext}");
20
		if($lng_contents !== false)
21
		{
22
			$lines = explode("\n", $lng_contents);
23
			foreach($lines as $line)
24
			{
25
				$line = str_replace("\r", "", $line);
26
				if(preg_match("/(.+?[^\\\]);(.+)/", $line, $matches))
27
				{
28
					$key = trim(str_replace("\;", ";", $matches[1]));
29
					$value = trim(str_replace("\;", ";", $matches[2]));
30
					switch($key)
31
					{
32
						case "_locale":
33
							$this->locale = explode(",", $value);
34
							break;
35
						case "_datetime_short":
36
							$this->datetime_short = $value;
37
							break;
38
						case "_datetime_long":
39
							$this->datetime_long = $value;
40
							break;
41
						case "_date_short":
42
							$this->date_short = $value;
43
							break;
44
						case "_date_long":
45
							$this->date_long = $value;
46
							break;
47
						case "_time":
48
							$this->time = $value;
49
							break;
50
						default:
51
							$this->strings[$key] = $value;
52
							break;
53
					}
54
				}
55
			}
56
		}
57
		else
58
		{
59
			Throw new Exception("Failed to load locale {$locale}.");
60
		}
61
	}
62
}
63
64
?>

+ 112 - 0
cphp/class.templater.php

@ -0,0 +1,112 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
$template_cache = array();
5
6
class Templater
7
{
8
	private $basedir = "templates/";
9
	private $extension = ".tpl";
10
	private $tpl = NULL;
11
	private $tpl_rendered = NULL;
12
	
13
	public function Load($template)
14
	{
15
		global $template_cache;
16
		
17
		if(isset($template_cache[$template]))
18
		{
19
			$tpl_contents = $template_cache[$template];
20
		}
21
		else
22
		{
23
			$tpl_contents = file_get_contents($this->basedir . $template . $this->extension);
24
			$template_cache[$template] = $tpl_contents;
25
		}
26
		
27
		if($tpl_contents !== false)
28
		{
29
			$this->tpl = $tpl_contents;
30
			$this->tpl_rendered = $tpl_contents;
31
		}
32
		else
33
		{
34
			Throw new Exception("Failed to load template {$template}.");
35
		}
36
	}
37
	
38
	public function Reset()
39
	{
40
		if(!is_null($this->tpl))
41
		{
42
			$this->tpl_rendered = $this->tpl;
43
		}
44
		else
45
		{
46
			Throw new Exception("No template loaded.");
47
		}
48
	}
49
	
50
	public function Localize($strings)
51
	{
52
		if(!is_null($this->tpl))
53
		{
54
			preg_match_all("/<%!([a-zA-Z0-9_-]+)>/", $this->tpl_rendered, $strlist);
55
			foreach($strlist[1] as $str)
56
			{
57
				if(isset($strings[$str]))
58
				{
59
					$this->tpl_rendered = str_replace("<%!{$str}>", $strings[$str], $this->tpl_rendered);
60
				}
61
			}
62
		}
63
		else
64
		{
65
			Throw new Exception("No template loaded.");
66
		}
67
	}
68
	
69
	public function Compile($strings)
70
	{
71
		if(!is_null($this->tpl))
72
		{
73
			preg_match_all("/<%\?([a-zA-Z0-9_-]+)>/", $this->tpl_rendered, $strlist);
74
			foreach($strlist[1] as $str)
75
			{
76
				if(isset($strings[$str]))
77
				{
78
					$this->tpl_rendered = str_replace("<%?{$str}>", $strings[$str], $this->tpl_rendered);
79
				}
80
			}
81
		}
82
		else
83
		{
84
			Throw new Exception("No template loaded.");
85
		}
86
	}
87
	
88
	public function Render()
89
	{
90
		if(!is_null($this->tpl))
91
		{
92
			return $this->tpl_rendered;
93
		}
94
		else
95
		{
96
			Throw new Exception("No template loaded.");
97
		}
98
	}
99
	
100
	public function Output()
101
	{
102
		if(!is_null($this->tpl))
103
		{
104
			echo($this->tpl_rendered);
105
		}
106
		else
107
		{
108
			Throw new Exception("No template loaded.");
109
		}
110
	}
111
}
112
?>

+ 60 - 0
cphp/components/component.errorhandler.php

@ -0,0 +1,60 @@
1
<?php
2
cphp_dependency_provides("cphp_errorhandler", "0.1");
3
4
define("CPHP_ERRORHANDLER_TYPE_ERROR",			90001	);
5
define("CPHP_ERRORHANDLER_TYPE_INFO",			90002	);
6
define("CPHP_ERRORHANDLER_TYPE_WARNING",		90003	);
7
define("CPHP_ERRORHANDLER_TYPE_SUCCESS",		90004	);
8
9
class CPHPErrorHandler
10
{
11
	public $sErrorType = CPHP_ERRORHANDLER_TYPE_ERROR;
12
	public $sLogError = true;
13
	public $sTitle = "";
14
	public $sMessage = "";
15
	
16
	public function __construct($type, $title, $message, $log = true)
17
	{
18
		$this->sErrorType = $type;
19
		$this->sLogError = $log;
20
		$this->sTitle = $title;
21
		$this->sMessage = $message;
22
	}
23
	
24
	public function LogError($context, $message)
25
	{
26
		// FIXME placeholder function, error logging has not been implemented yet
27
	}
28
	
29
	public function Render()
30
	{
31
		global $locale;
32
		
33
		$template['error'] = new Templater();
34
		
35
		switch($this->sErrorType)
36
		{
37
			case CPHP_ERRORHANDLER_TYPE_ERROR:
38
				$template['error']->Load("errorhandler.error");
39
				break;
40
			case CPHP_ERRORHANDLER_TYPE_INFO:
41
				$template['error']->Load("errorhandler.info");
42
				break;
43
			case CPHP_ERRORHANDLER_TYPE_WARNING:
44
				$template['error']->Load("errorhandler.warning");
45
				break;
46
			case CPHP_ERRORHANDLER_TYPE_SUCCESS:
47
				$template['error']->Load("errorhandler.success");
48
				break;
49
		}
50
		
51
		$template['error']->Localize($locale->strings);
52
		$template['error']->Compile(array(
53
			'title'		=> $this->sTitle,
54
			'message'	=> $this->sMessage
55
		));
56
		
57
		return $template['error']->Render();
58
	}
59
}
60
?>

+ 379 - 0
cphp/components/component.formbuilder.php

@ -0,0 +1,379 @@
1
<?php
2
cphp_dependency_provides("cphp_formbuilder", "1.0");
3
4
$cphp_formbuilder_increment = 0;
5
6
abstract class CPHPFormBuilderBaseClass
7
{
8
	public $parameters = array();
9
	
10
	public function AddParameter($key, $value)
11
	{
12
		$this->parameters[$key] = $value;
13
	}
14
	
15
	public function RenderParameters($parameters)
16
	{
17
		if(empty($parameters))
18
		{
19
			return "";
20
		}
21
		
22
		$rendered = array();
23
		
24
		foreach($parameters as $key => $value)
25
		{
26
			$value = utf8entities($value);
27
			$rendered[] = "{$key}=\"{$value}\"";
28
		}
29
		
30
		return " " . implode(" ", $rendered);
31
	}
32
	
33
	public function RenderNote()
34
	{
35
		if(!empty($this->note))
36
		{
37
			return "<div class=\"cphp_fbd_note\">{$this->note}</div>";
38
		}
39
		else
40
		{
41
			return "";
42
		}
43
	}
44
}
45
46
abstract class CPHPFormBuilderContainer extends CPHPFormBuilderBaseClass
47
{
48
	public $elements = array();
49
	
50
	public function AddElement($element)
51
	{
52
		$this->elements[] = $element;
53
	}
54
}
55
56
class CPHPFormBuilder extends CPHPFormBuilderContainer
57
{
58
	public $method = "";
59
	public $action = "";
60
	
61
	public function __construct($method, $target)
62
	{
63
		$this->method = strtolower($method);
64
		$this->action = $target;
65
	}
66
	
67
	public function Render()
68
	{		
69
		$rendered_elements = "";
70
		
71
		foreach($this->elements as $element)
72
		{
73
			$rendered_elements .= $element->Render();
74
		}
75
		
76
		$this->AddParameter("method", $this->method);
77
		$this->AddParameter("action", $this->action);
78
		
79
		$rendered_parameters = $this->RenderParameters($this->parameters);
80
		
81
		return "<form{$rendered_parameters}>{$rendered_elements}</form>";
82
	}
83
}
84
85
class CPHPFormSection extends CPHPFormBuilderContainer
86
{
87
	public $label = "";
88
	public $fieldset = true;
89
	public $classname = "";
90
	
91
	public function __construct($fieldset = true, $label = "")
92
	{
93
		if(!empty($label))
94
		{
95
			$this->label = $label;
96
		}
97
		
98
		$this->fieldset = $fieldset;
99
	}
100
	
101
	public function Render()
102
	{
103
		if(!empty($this->label))
104
		{
105
			$legend = "<legend>{$this->label}</legend>";
106
		}
107
		else
108
		{
109
			$legend = "";
110
		}
111
		
112
		if($this->fieldset === true)
113
		{
114
			$this->classname = trim("{$this->classname} cphp_fbd_fieldset");
115
		}
116
		
117
		$rendered_elements = "";
118
		
119
		foreach($this->elements as $element)
120
		{
121
			$rendered_elements .= $element->Render();
122
		}
123
		
124
		if($this->fieldset === true)
125
		{
126
			$this->AddParameter("class", $this->classname);
127
			$rendered_parameters = $this->RenderParameters($this->parameters);
128
			return "<fieldset{$rendered_parameters}>{$legend}<div class=\"cphp_fbd_form\">{$rendered_elements}</div></fieldset>";
129
		}
130
		else
131
		{
132
			return "<div class=\"cphp_fbd_form\"{$rendered_parameters}>{$rendered_elements}</div>";
133
		}
134
	}
135
}
136
137
abstract class CPHPFormInputElement extends CPHPFormBuilderBaseClass
138
{
139
	public $id = "";
140
	public $name = "";
141
	public $value = "";
142
	public $label = "";
143
	
144
	public function __construct($label, $name, $value = "", $note = "", $id = "")
145
	{
146
		global $cphp_formbuilder_increment;
147
		
148
		$this->name = $name;
149
		$this->value = $value;
150
		$this->label = $label;
151
		$this->note = $note;
152
		
153
		if(empty($id))
154
		{
155
			$this->id = "cphp_fbd_{$cphp_formbuilder_increment}";
156
			$cphp_formbuilder_increment += 1;
157
		}
158
		else
159
		{
160
			$this->id = $id;
161
		}
162
	}
163
	
164
}
165
166
abstract class CPHPFormInput extends CPHPFormInputElement
167
{
168
	public function Render()
169
	{
170
		$this->AddParameter("id", $this->id);
171
		$this->AddParameter("type", $this->type);
172
		$this->AddParameter("name", $this->name);
173
		$this->AddParameter("value", $this->value);
174
		
175
		$rendered_parameters = $this->RenderParameters($this->parameters);
176
		$rendered_note = $this->RenderNote();
177
		
178
		return "<div class=\"cphp_fbd_row\"><div class=\"cphp_fbd_label\">{$this->label}{$rendered_note}</div><div class=\"cphp_fbd_field\"><input{$rendered_parameters}></div></div>";
179
	}
180
}
181
182
class CPHPFormTextInput extends CPHPFormInput
183
{
184
	public $type = "text";
185
}
186
187
class CPHPFormPasswordInput extends CPHPFormInput
188
{
189
	public $type = "password";
190
}
191
192
class CPHPFormDateInput extends CPHPFormInput
193
{
194
	public $type = "date";
195
}
196
197
class CPHPFormTimeInput extends CPHPFormInput
198
{
199
	public $type = "time";
200
}
201
202
class CPHPFormEmailInput extends CPHPFormInput
203
{
204
	public $type = "email";
205
}
206
207
class CPHPFormUrlInput extends CPHPFormInput
208
{
209
	public $type = "url";
210
}
211
212
class CPHPFormRangeInput extends CPHPFormInput
213
{
214
	public $type = "range";
215
}
216
217
class CPHPFormColorInput extends CPHPFormInput
218
{
219
	public $type = "color";
220
}
221
222
class CPHPFormSearchInput extends CPHPFormInput
223
{
224
	public $type = "search";
225
}
226
227
class CPHPFormCheckboxGroup extends CPHPFormBuilderContainer
228
{
229
	public function __construct($label, $note = "")
230
	{
231
		global $cphp_formbuilder_increment;
232
		
233
		$this->label = $label;
234
		$this->note = $note;
235
	}
236
	
237
	public function Render()
238
	{		
239
		$rendered_note = $this->RenderNote();
240
		
241
		$rendered_elements = "";
242
		
243
		foreach($this->elements as $element)
244
		{
245
			$rendered_elements .= $element->Render();
246
		}
247
		
248
		return "<div class=\"cphp_fbd_row\"><div class=\"cphp_fbd_label\">{$this->label}{$rendered_note}</div><div class=\"cphp_fbd_field\">{$rendered_elements}</div></div>";
249
	}
250
}
251
252
class CPHPFormCheckbox extends CPHPFormInputElement
253
{
254
	
255
	public function Render()
256
	{
257
		$this->AddParameter("id", $this->id);
258
		$this->AddParameter("type", "checkbox");
259
		$this->AddParameter("name", $this->name);
260
		
261
		if($this->value === true)
262
		{
263
			$this->AddParameter("checked", "");
264
		}
265
		
266
		$rendered_parameters = $this->RenderParameters($this->parameters);
267
		$rendered_note = $this->RenderNote();
268
		return "<div class=\"cphp_fbd_cblabel\"><input{$rendered_parameters}><label for=\"{$this->id}\">{$this->label}{$rendered_note}</label></div>";
269
	}
270
}
271
272
class CPHPFormRadioButton extends CPHPFormInput
273
{
274
	public $type = "radio";
275
}
276
277
class CPHPFormButton extends CPHPFormInputElement
278
{
279
	public $type = "button";
280
	
281
	public function Render()
282
	{
283
		$this->AddParameter("type", $this->type);
284
		$this->AddParameter("name", $this->name);
285
		$this->AddParameter("value", $this->value);
286
		
287
		$rendered_parameters = $this->RenderParameters($this->parameters);
288
		
289
		return "<div class=\"cphp_fbd_row\"><div class=\"cphp_fbd_label\"></div><div class=\"cphp_fbd_field\"><button{$rendered_parameters}>{$this->label}</button></div></div>";
290
	}
291
}
292
293
class CPHPFormSubmitButton extends CPHPFormButton
294
{
295
	public $type = "submit";
296
}
297
298
class CPHPFormResetButton extends CPHPFormButton
299
{
300
	public $type = "reset";
301
}
302
303
class CPHPFormSelect extends CPHPFormInputElement
304
{
305
	public $options = array();
306
	
307
	public function AddOption($option)
308
	{
309
		$this->options[] = $option;
310
	}
311
	
312
	public function Render()
313
	{
314
		$this->AddParameter("id", $this->id);
315
		$this->AddParameter("name", $this->name);
316
		
317
		$rendered_parameters = $this->RenderParameters($this->parameters);
318
		$rendered_note = $this->RenderNote();
319
		
320
		$list = "";
321
		
322
		foreach($this->options as $option)
323
		{
324
			$list .= $option->Render();
325
		}
326
		
327
		return "<div class=\"cphp_fbd_row\"><div class=\"cphp_fbd_label\">{$this->label}{$rendered_note}</div><div class=\"cphp_fbd_field\"><select{$rendered_parameters}>{$list}</select></div></div>";
328
	}
329
}
330
331
class CPHPFormSelectOptionGroup
332
{
333
	public $label = "";
334
	public $options = array();
335
	
336
	public function __construct($label)
337
	{
338
		$this->label = $label;
339
	}
340
	
341
	public function AddOption($option)
342
	{
343
		$this->options[] = $option;
344
	}
345
	
346
	public function Render()
347
	{
348
		$list = "";
349
		
350
		foreach($this->options as $option)
351
		{
352
			$list .= $option->Render();
353
		}
354
		
355
		return "<optgroup label=\"{$this->label}\">{$list}</optgroup>";
356
	}
357
}
358
359
class CPHPFormSelectOption
360
{
361
	public $value = "";
362
	public $description = "";
363
	public $selected = false;
364
	
365
	public function __construct($value, $description, $selected = false)
366
	{
367
		$this->value = $value;
368
		$this->description = $description;
369
		$this->selected = $selected;
370
	}
371
	
372
	public function Render()
373
	{
374
		$selected_attribute = ($selected) ? " selected" : "";
375
		
376
		return "<option value=\"{$this->value}\"{$selected_attribute}>{$this->description}</option>";
377
	}
378
}
379
?>

+ 40 - 0
cphp/components/component.router.php

@ -0,0 +1,40 @@
1
<?php
2
class CPHPRouter extends CPHPBaseClass
3
{
4
	public $routes = array();
5
	public $parameters = array();
6
	
7
	public function RouteRequest()
8
	{
9
		eval(extract_globals()); // hack hackity hack hack
10
		
11
		if(isset($_SERVER['REQUEST_URI']))
12
		{
13
			$requestpath = trim($_SERVER['REQUEST_URI']);
14
		}
15
		else
16
		{
17
			$requestpath = "/";
18
		}
19
		
20
		$found = false;  // Workaround because a break after an include apparently doesn't work in PHP.
21
		
22
		foreach($this->routes as $priority)
23
		{
24
			foreach($priority as $route_regex => $route_destination)
25
			{
26
				if($found === false)
27
				{
28
					$regex = str_replace("/", "\/", $route_regex);
29
					if(preg_match("/{$regex}/i", $requestpath, $matches))
30
					{
31
						$this->uParameters = $matches;
32
						include($route_destination);
33
						$found = true;
34
					}
35
				}
36
			}
37
		}
38
	}
39
}
40
?>

+ 36 - 0
cphp/config.php

@ -0,0 +1,36 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
$cphp_class_map = array(
5
	'country'			=> "Country",
6
	'provider'			=> "Provider",
7
	'plan'				=> "Plan",
8
	'paymentmethod'			=> "PaymentMethod",
9
	'virtualizationplatform'	=> "VirtualizationPlatform"
10
);
11
12
$cphp_locale_name = "english";
13
$cphp_locale_path = "locales";
14
$cphp_locale_ext  = "lng";
15
16
$cphp_usersettings[CPHP_SETTING_TIMEZONE] = "Europe/Amsterdam";
17
18
/* These are the memcache settings. You will need to have memcache set
19
 * up on your server to use these. Compression requires zlib. */
20
$cphp_memcache_enabled 		= true;			// Whether to user memcache.
21
$cphp_memcache_server		= "localhost";	// The hostname of the memcached
22
$cphp_memcache_port			= 11211;		// The port number of memcached
23
$cphp_memcache_compressed	= true;			// Whether to compress memcache objects
24
25
$cphp_mysql_enabled = true;
26
$cphp_mysql_host = "localhost";
27
$cphp_mysql_user = "vps";
28
$cphp_mysql_pass = "";
29
$cphp_mysql_db 	= "vps";
30
31
$cphp_components = array(
32
	"router",
33
	"formbuilder",
34
	"errorhandler"
35
);
36
?>

+ 13 - 0
cphp/include.constants.php

@ -0,0 +1,13 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
define("CPHP_SETTING_TIMEZONE",						1100	);
5
6
define("CPHP_VARIABLE_SAFE",						1260	);
7
define("CPHP_VARIABLE_UNSAFE",						1261	);
8
9
define("CPHP_INSERTMODE_INSERT",					1270	);
10
define("CPHP_INSERTMODE_UPDATE",					1271	);
11
12
define("CPHP_REGEX_EMAIL",							"/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i");
13
?>

+ 169 - 0
cphp/include.datetime.php

@ -0,0 +1,169 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
$timezones = array(
5
	'Pacific/Kwajalein' => 				'(GMT-12:00) International Date Line West',
6
	'Pacific/Midway' => 				'(GMT-11:00) Midway Island',
7
	'Pacific/Samoa' => 					'(GMT-11:00) Samoa',
8
	'Pacific/Honolulu' => 				'(GMT-10:00) Hawaii',
9
	'America/Anchorage' => 				'(GMT-09:00) Alaska',
10
	'America/Los_Angeles' => 			'(GMT-08:00) Pacific Time (US &amp; Canada)',
11
	'America/Tijuana' => 				'(GMT-08:00) Tijuana, Baja California',
12
	'America/Denver' => 				'(GMT-07:00) Mountain Time (US &amp; Canada)',
13
	'America/Chihuahua' => 				'(GMT-07:00) Chihuahua',
14
	'America/Mazatlan' => 				'(GMT-07:00) Mazatlan',
15
	'America/Phoenix' => 				'(GMT-07:00) Arizona',
16
	'America/Regina' => 				'(GMT-06:00) Saskatchewan',
17
	'America/Tegucigalpa' => 			'(GMT-06:00) Central America',
18
	'America/Chicago' => 				'(GMT-06:00) Central Time (US &amp; Canada)',
19
	'America/Mexico_City' => 			'(GMT-06:00) Mexico City',
20
	'America/Monterrey' => 				'(GMT-06:00) Monterrey',
21
	'America/New_York' => 				'(GMT-05:00) Eastern Time (US &amp; Canada)',
22
	'America/Bogota' => 				'(GMT-05:00) Bogota',
23
	'America/Lima' => 					'(GMT-05:00) Lima',
24
	'America/Rio_Branco' => 			'(GMT-05:00) Rio Branco',
25
	'America/Indiana/Indianapolis' => 	'(GMT-05:00) Indiana (East)',
26
	'America/Caracas' => 				'(GMT-04:30) Caracas',
27
	'America/Halifax' => 				'(GMT-04:00) Atlantic Time (Canada)',
28
	'America/Manaus' => 				'(GMT-04:00) Manaus',
29
	'America/Santiago' => 				'(GMT-04:00) Santiago',
30
	'America/La_Paz' => 				'(GMT-04:00) La Paz',
31
	'America/St_Johns' => 				'(GMT-03:30) Newfoundland',
32
	'America/Argentina/Buenos_Aires' => '(GMT-03:00) Georgetown',
33
	'America/Sao_Paulo' =>				'(GMT-03:00) Brasilia',
34
	'America/Godthab' => 				'(GMT-03:00) Greenland',
35
	'America/Montevideo' => 			'(GMT-03:00) Montevideo',
36
	'Atlantic/South_Georgia' => 		'(GMT-02:00) Mid-Atlantic',
37
	'Atlantic/Azores' => 				'(GMT-01:00) Azores',
38
	'Atlantic/Cape_Verde' => 			'(GMT-01:00) Cape Verde Is.',
39
	'Europe/Dublin' => 					'(GMT) Dublin',
40
	'Europe/Lisbon' => 					'(GMT) Lisbon',
41
	'Europe/London' => 					'(GMT) London',
42
	'Africa/Monrovia' => 				'(GMT) Monrovia',
43
	'Atlantic/Reykjavik' =>				'(GMT) Reykjavik',
44
	'Africa/Casablanca' => 				'(GMT) Casablanca',
45
	'Europe/Belgrade' => 				'(GMT+01:00) Belgrade',
46
	'Europe/Bratislava' => 				'(GMT+01:00) Bratislava',
47
	'Europe/Budapest' => 				'(GMT+01:00) Budapest',
48
	'Europe/Ljubljana' => 				'(GMT+01:00) Ljubljana',
49
	'Europe/Prague' => 					'(GMT+01:00) Prague',
50
	'Europe/Sarajevo' => 				'(GMT+01:00) Sarajevo',
51
	'Europe/Skopje' => 					'(GMT+01:00) Skopje',
52
	'Europe/Warsaw' => 					'(GMT+01:00) Warsaw',
53
	'Europe/Zagreb' => 					'(GMT+01:00) Zagreb',
54
	'Europe/Brussels' => 				'(GMT+01:00) Brussels',
55
	'Europe/Copenhagen' => 				'(GMT+01:00) Copenhagen',
56
	'Europe/Madrid' => 					'(GMT+01:00) Madrid',
57
	'Europe/Paris' => 					'(GMT+01:00) Paris',
58
	'Africa/Algiers' => 				'(GMT+01:00) West Central Africa',
59
	'Europe/Amsterdam' => 				'(GMT+01:00) Amsterdam',
60
	'Europe/Berlin' => 					'(GMT+01:00) Berlin',
61
	'Europe/Rome' => 					'(GMT+01:00) Rome',
62
	'Europe/Stockholm' =>				'(GMT+01:00) Stockholm',
63
	'Europe/Vienna' => 					'(GMT+01:00) Vienna',
64
	'Europe/Minsk' => 					'(GMT+02:00) Minsk',
65
	'Africa/Cairo' =>		 			'(GMT+02:00) Cairo',
66
	'Europe/Helsinki' =>				'(GMT+02:00) Helsinki',
67
	'Europe/Riga' =>		 			'(GMT+02:00) Riga',
68
	'Europe/Sofia' =>		 			'(GMT+02:00) Sofia',
69
	'Europe/Tallinn' =>		 			'(GMT+02:00) Tallinn',
70
	'Europe/Vilnius' =>		 			'(GMT+02:00) Vilnius',
71
	'Europe/Athens' =>		 			'(GMT+02:00) Athens',
72
	'Europe/Bucharest' =>				'(GMT+02:00) Bucharest',
73
	'Europe/Istanbul' =>				'(GMT+02:00) Istanbul',
74
	'Asia/Jerusalem' =>		 			'(GMT+02:00) Jerusalem',
75
	'Asia/Amman' =>		 				'(GMT+02:00) Amman',
76
	'Asia/Beirut' =>		 			'(GMT+02:00) Beirut',
77
	'Africa/Windhoek' =>				'(GMT+02:00) Windhoek',
78
	'Africa/Harare' =>		 			'(GMT+02:00) Harare',
79
	'Asia/Kuwait' =>		 			'(GMT+03:00) Kuwait',
80
	'Asia/Riyadh' =>		 			'(GMT+03:00) Riyadh',
81
	'Asia/Baghdad' =>		 			'(GMT+03:00) Baghdad',
82
	'Africa/Nairobi' =>		 			'(GMT+03:00) Nairobi',
83
	'Asia/Tbilisi' =>		 			'(GMT+03:00) Tbilisi',
84
	'Europe/Moscow' =>		 			'(GMT+03:00) Moscow',
85
	'Europe/Volgograd' =>				'(GMT+03:00) Volgograd',
86
	'Asia/Tehran' =>		 			'(GMT+03:30) Tehran',
87
	'Asia/Muscat' =>		 			'(GMT+04:00) Muscat',
88
	'Asia/Baku' =>		 				'(GMT+04:00) Baku',
89
	'Asia/Yerevan' =>		 			'(GMT+04:00) Yerevan',
90
	'Asia/Yekaterinburg' =>				'(GMT+05:00) Ekaterinburg',
91
	'Asia/Karachi' =>		 			'(GMT+05:00) Karachi',
92
	'Asia/Tashkent' =>		 			'(GMT+05:00) Tashkent',
93
	'Asia/Kolkata' =>		 			'(GMT+05:30) Calcutta',
94
	'Asia/Colombo' =>		 			'(GMT+05:30) Sri Jayawardenepura',
95
	'Asia/Katmandu' =>		 			'(GMT+05:45) Kathmandu',
96
	'Asia/Dhaka' =>		 				'(GMT+06:00) Dhaka',
97
	'Asia/Almaty' =>		 			'(GMT+06:00) Almaty',
98
	'Asia/Novosibirsk' =>		 		'(GMT+06:00) Novosibirsk',
99
	'Asia/Rangoon' =>		 			'(GMT+06:30) Yangon (Rangoon)',
100
	'Asia/Krasnoyarsk' =>		 		'(GMT+07:00) Krasnoyarsk',
101
	'Asia/Bangkok' =>		 			'(GMT+07:00) Bangkok',
102
	'Asia/Jakarta' =>		 			'(GMT+07:00) Jakarta',
103
	'Asia/Brunei' =>		 			'(GMT+08:00) Beijing',
104
	'Asia/Chongqing' =>		 			'(GMT+08:00) Chongqing',
105
	'Asia/Hong_Kong' =>		 			'(GMT+08:00) Hong Kong',
106
	'Asia/Urumqi' =>		 			'(GMT+08:00) Urumqi',
107
	'Asia/Irkutsk' =>		 			'(GMT+08:00) Irkutsk',
108
	'Asia/Ulaanbaatar' =>		 		'(GMT+08:00) Ulaan Bataar',
109
	'Asia/Kuala_Lumpur' =>		 		'(GMT+08:00) Kuala Lumpur',
110
	'Asia/Singapore' =>			 		'(GMT+08:00) Singapore',
111
	'Asia/Taipei' =>			 		'(GMT+08:00) Taipei',
112
	'Australia/Perth' =>		 		'(GMT+08:00) Perth',
113
	'Asia/Seoul' =>				 		'(GMT+09:00) Seoul',
114
	'Asia/Tokyo' =>				 		'(GMT+09:00) Tokyo',
115
	'Asia/Yakutsk' =>			 		'(GMT+09:00) Yakutsk',
116
	'Australia/Darwin' =>		 		'(GMT+09:30) Darwin',
117
	'Australia/Adelaide' =>		 		'(GMT+09:30) Adelaide',
118
	'Australia/Canberra' =>		 		'(GMT+10:00) Canberra',
119
	'Australia/Melbourne' =>			'(GMT+10:00) Melbourne',
120
	'Australia/Sydney' =>		 		'(GMT+10:00) Sydney',
121
	'Australia/Brisbane' =>		 		'(GMT+10:00) Brisbane',
122
	'Australia/Hobart' =>		 		'(GMT+10:00) Hobart',
123
	'Asia/Vladivostok' =>		 		'(GMT+10:00) Vladivostok',
124
	'Pacific/Guam' =>			 		'(GMT+10:00) Guam',
125
	'Pacific/Port_Moresby' =>			'(GMT+10:00) Port Moresby',
126
	'Asia/Magadan' =>			 		'(GMT+11:00) Magadan',
127
	'Pacific/Fiji' =>			 		'(GMT+12:00) Fiji',
128
	'Asia/Kamchatka' =>			 		'(GMT+12:00) Kamchatka',
129
	'Pacific/Auckland' =>		 		'(GMT+12:00) Auckland',
130
	'Pacific/Tongatapu' =>		 		'(GMT+13:00) Nukualofa'
131
);
132
133
function unix_from_local($timestamp)
134
{
135
	global $user_preferences;
136
	date_default_timezone_set($user_preferences[CPHP_SETTING_TIMEZONE]);
137
	return strtotime($timestamp);
138
}
139
140
function unix_from_mysql($timestamp)
141
{
142
	date_default_timezone_set("GMT");
143
	return strtotime($timestamp);
144
}
145
146
function local_from_unix($timestamp, $format)
147
{
148
	global $user_preferences;
149
	date_default_timezone_set($user_preferences[CPHP_SETTING_TIMEZONE]);
150
	return strftime($format, $timestamp);
151
}
152
153
function gmt_from_unix($timestamp, $format)
154
{
155
	date_default_timezone_set("GMT");
156
	return strftime($format, $timestamp);
157
}
158
159
function mysql_from_unix($timestamp)
160
{
161
	date_default_timezone_set("GMT");
162
	return date("Y-m-d H:i:s", $timestamp);
163
}
164
165
function floor_to_day($timestamp)
166
{
167
	return floor($timestamp / (60 * 60 * 24)) * (60 * 60 * 24);
168
}
169
?>

+ 90 - 0
cphp/include.dependencies.php

@ -0,0 +1,90 @@
1
<?php
2
$cphp_dependencies = array();
3
$cphp_last_dependency = "";
4
5
function cphp_dependency_provides($component, $version)
6
{
7
	global $cphp_dependencies, $cphp_last_dependency;
8
	$cphp_dependencies[$component] = $version;
9
	$cphp_last_dependency = $component;
10
}
11
12
function cphp_dependency_requires($component, $version)
13
{
14
	global $cphp_dependencies, $cphp_last_dependency;
15
	
16
	if(!isset($cphp_dependencies[$component]))
17
	{
18
		die("The {$cphp_last_dependency} component requires the {$component} component to be loaded, but this is not the case.");
19
	}
20
	
21
	$current_version = $cphp_dependencies[$component];
22
	
23
	if(!cphp_dependency_match($current_version, $version))
24
	{
25
		die("The {$cphp_last_dependency} component requires the {$component} component with version {$version} to be loaded, but an incompatible version ({$current_version}) was found.");
26
	}
27
}
28
29
function cphp_dependency_match($available, $required)
30
{
31
	if(strpos($required, ",") !== false)
32
	{
33
		$ranges = explode(",", $required);
34
	}
35
	else
36
	{
37
		$ranges[] = $version;
38
	}
39
	
40
	foreach($ranges as $range)
41
	{
42
		if(strpos($required, "|") !== false)
43
		{
44
			list($min, $max) = explode("|", $range);
45
			
46
			$f_min = (float) $min;
47
			$f_max = (float) $max;
48
			$f_cur = (float) $available;
49
			
50
			if(empty($min) && empty($max))
51
			{
52
				return true;
53
			}
54
			elseif(empty($min))
55
			{
56
				if($f_cur < $f_max)
57
				{
58
					return true;
59
				}
60
				else
61
				{
62
					return false;
63
				}
64
			}
65
			elseif(empty($max))
66
			{
67
				if($f_cur > $f_min)
68
				{
69
					return true;
70
				}
71
				else
72
				{
73
					return false;
74
				}
75
			}
76
			else
77
			{
78
				if($f_cur > $f_min && $f_cur < $f_max)
79
				{
80
					return true;
81
				}
82
				else
83
				{
84
					return false;
85
				}
86
			}
87
		}
88
	}
89
}
90
?>

+ 12 - 0
cphp/include.exceptions.php

@ -0,0 +1,12 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
class OwnershipException extends Exception {}
5
class UserAccessException extends Exception {}
6
class NotFoundException extends Exception {}
7
class PrototypeException extends Exception {}
8
class ConstructorException extends Exception {}
9
class MissingDataException extends Exception {}
10
class DatabaseException extends Exception {}
11
class TypeException extends Exception {}
12
?>

+ 145 - 0
cphp/include.memcache.php

@ -0,0 +1,145 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
if($cphp_memcache_enabled)
5
{
6
	$memcache = new Memcache;
7
	$cphp_memcache_established = $memcache->connect($cphp_memcache_server, $cphp_memcache_port);
8
9
	if($cphp_memcache_established !== false)
10
	{
11
		$cphp_memcache_connected = true;
12
	}
13
	else
14
	{
15
		$cphp_memcache_connected = false;
16
	}
17
}
18
19
function mc_get($key)
20
{
21
	global $cphp_memcache_enabled, $cphp_memcache_connected, $memcache;
22
	
23
	if($cphp_memcache_enabled === false || $cphp_memcache_connected === false)
24
	{
25
		return false;
26
	}
27
	else
28
	{
29
		$get_result = $memcache->get($key);
30
		if($get_result !== false)
31
		{
32
			return $get_result;
33
		}
34
		else
35
		{
36
			return false;
37
		}
38
	}
39
}
40
41
function mc_set($key, $value, $expiry)
42
{
43
	global $cphp_memcache_enabled, $cphp_memcache_connected, $cphp_memcache_compressed, $memcache;
44
	
45
	if($cphp_memcache_enabled === false || $cphp_memcache_connected === false)
46
	{
47
		return false;
48
	}
49
	else
50
	{
51
		if($cphp_memcache_compressed === true)
52
		{
53
			$flag = MEMCACHE_COMPRESSED;
54
		}
55
		else
56
		{
57
			$flag = false;
58
		}
59
		
60
		$set_result = $memcache->set($key, $value, $flag, $expiry);
61
		return $set_result;
62
	}
63
}
64
65
function mc_delete($key)
66
{
67
	global $cphp_memcache_enabled, $cphp_memcache_connected, $memcache;
68
	
69
	if($cphp_memcache_enabled === false || $cphp_memcache_connected === false)
70
	{
71
		return false;
72
	}
73
	else
74
	{
75
		return $memcache->delete($key);
76
	}
77
}
78
79
function mysql_query_cached($query, $expiry = 60, $key = "")
80
{
81
	if($key == "")
82
	{
83
		$key = md5($query) . md5($query . "x");
84
	}
85
	
86
	if($res = mc_get($key))
87
	{
88
		$return_object->source = "memcache";
89
		$return_object->data = $res;
90
		return $return_object;
91
	}
92
	else
93
	{
94
		if($res = mysql_query($query))
95
		{
96
			$found = false;
97
			
98
			while($row = mysql_fetch_assoc($res))
99
			{
100
				$return_object->data[] = $row;
101
				$found = true;
102
			}
103
			
104
			if($found === true)
105
			{
106
				$return_object->source = "database";
107
				mc_set($key, $return_object->data, $expiry);
108
				return $return_object;
109
			}
110
			else
111
			{
112
				return false;
113
			}
114
		}
115
		else
116
		{
117
			return false;
118
		}
119
	}
120
}
121
122
function file_get_contents_cached($path, $expiry = 3600)
123
{
124
	if($res = mc_get(md5($path) . md5($path . "x")))
125
	{
126
		$return_object->source = "memcache";
127
		$return_object->data = $res;
128
		return $return_object;
129
	}
130
	else
131
	{
132
		if($result = file_get_contents($path))
133
		{
134
			$return_object->source = "disk";
135
			$return_object->data = $result;
136
			mc_set(md5($path) . md5($path . "x"), $return_object->data, $expiry);
137
			return $return_object;
138
		}
139
		else
140
		{
141
			return false;
142
		}
143
	}
144
}
145
?>

+ 90 - 0
cphp/include.misc.php

@ -0,0 +1,90 @@
1
<?php
2
if($_CPHP !== true) { die(); }
3
4
function random_string($length)
5
{
6
	$output = "";
7
	for ($i = 0; $i < $length; $i++) 
8
	{ 
9
		$output .= substr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 61), 1); 
10
	}
11
	return $output;
12
}
13
14
function extract_globals()
15
{
16
    $vars = array();
17
    
18
    foreach($GLOBALS as $key => $value){
19
        $vars[] = "$".$key;
20
    }
21
    
22
    return "global " . join(",", $vars) . ";";