Browse Source

Initial commit

master
Sven Slootweg 11 years ago
commit
17929c5197
  1. 22
      classes/class.country.php
  2. 29
      classes/class.location.php
  3. 20
      classes/class.paymentmethod.php
  4. 23
      classes/class.plan.locationoption.php
  5. 47
      classes/class.plan.php
  6. 21
      classes/class.plan.priceoption.php
  7. 29
      classes/class.provider.php
  8. 16
      classes/class.technology.php
  9. 16
      classes/class.virtualizationplatform.php
  10. 30
      cphp/base.php
  11. 143
      cphp/class.base.php
  12. 381
      cphp/class.databaserecord.php
  13. 64
      cphp/class.localizer.php
  14. 112
      cphp/class.templater.php
  15. 60
      cphp/components/component.errorhandler.php
  16. 379
      cphp/components/component.formbuilder.php
  17. 40
      cphp/components/component.router.php
  18. 36
      cphp/config.php
  19. 13
      cphp/include.constants.php
  20. 169
      cphp/include.datetime.php
  21. 90
      cphp/include.dependencies.php
  22. 12
      cphp/include.exceptions.php
  23. 145
      cphp/include.memcache.php
  24. 90
      cphp/include.misc.php
  25. 16
      cphp/include.mysql.php
  26. 5
      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
      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
      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
      css/smoothness/jquery-ui-1.8.18.custom.css
  70. 522
      css/table.css
  71. 679
      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
      index.php
  78. 4
      js/jquery-1.7.1.min.js
  79. 356
      js/jquery-ui-1.8.18.custom.min.js
  80. 519
      js/vps.js
  81. 24
      locales/english.lng
  82. 81
      mod.php
  83. 333
      quickadd.php
  84. 101
      templates/element.vps.tpl
  85. 67
      templates/frame.tpl
  86. 4
      templates/page.add.tpl
  87. 24
      templates/page.donate.tpl
  88. 200
      templates/page.list.tpl
  89. 1
      templates/page.main.tpl

22
classes/class.country.php

@ -0,0 +1,22 @@
<?php
if($_VPS !== true) { die("x"); }
class Country extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM countries WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM countries WHERE `Id` = '%d'";
public $table_name = "countries";
public $prototype = array(
'string' => array(
'Name' => "name",
'PrintableName' => "printable_name",
'Iso' => "iso",
'Iso3' => "iso3"
),
'numeric' => array(
'NumericCode' => "numcode"
)
);
}
?>

29
classes/class.location.php

@ -0,0 +1,29 @@
<?php
if($_VPS !== true) { die("x"); }
class Location extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM locations WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM locations WHERE `Id` = '%d'";
public $table_name = "locations";
public $prototype = array(
'string' => array(
'Location' => "Location",
'TestIp4' => "TestIp4",
'TestIp6' => "TestIp6",
'TestFile' => "TestFile"
),
'numeric' => array(
'CountryId' => "CountryId",
'ProviderId' => "ProviderId"
),
'country' => array(
'Country' => "CountryId"
),
'provider' => array(
'Provider' => "ProviderId"
)
);
}
?>

20
classes/class.paymentmethod.php

@ -0,0 +1,20 @@
<?php
if($_VPS !== true) { die("x"); }
class PaymentMethod extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM paymentmethods WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM paymentmethods WHERE `Id` = '%d'";
public $table_name = "paymentmethods";
public $prototype = array(
'string' => array(
'Name' => "Name",
'Icon' => "Icon"
),
'boolean' => array(
'IsAnonymous' => "Anonymous"
)
);
}
?>

23
classes/class.plan.locationoption.php

@ -0,0 +1,23 @@
<?php
if($_VPS !== true) { die("x"); }
class PlanLocationOption extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM plan_locationoptions WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM plan_locationoptions WHERE `Id` = '%d'";
public $table_name = "plan_locationoptions";
public $prototype = array(
'numeric' => array(
'PlanId' => "PlanId",
'LocationId' => "LocationId"
),
'plan' => array(
'Plan' => "PlanId"
),
'location' => array(
'Location' => "LocationId"
)
);
}
?>

47
classes/class.plan.php

@ -0,0 +1,47 @@
<?php
if($_VPS !== true) { die("x"); }
class Plan extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM plans WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM plans WHERE `Id` = '%d'";
public $table_name = "plans";
public $prototype = array(
'string' => array(
'Name' => "Name"
),
'numeric' => array(
'ProviderId' => "ProviderId",
'Traffic' => "Traffic",
'DiskSpace' => "DiskSpace",
'CpuCores' => "CpuCores",
'Bandwidth' => "Bandwidth",
'GuaranteedRam' => "GuaranteedRam",
'BurstRam' => "BurstRam",
'AllowsIrc' => "AllowsIrc",
'BackupSpace' => "BackupSpace",
'VirtualizationPlatformId' => "VirtualizationPlatformId"
),
'boolean' => array(
'IsUnmetered' => "Unmetered",
'HasIpv4' => "HasIpv4",
'HasIpv6' => "HasIpv6",
'FreeDns' => "FreeDns",
'OverageBilling' => "OverageBilling",
'DedicatedCpu' => "DedicatedCpu",
'Visible' => "Visible"
),
'timestamp' => array(
'LastUpdate' => "LastUpdated",
'SubmissionDate' => "SubmissionDate"
),
'provider' => array(
'Provider' => "ProviderId"
),
'virtualizationplatform' => array(
'VirtualizationPlatform' => "VirtualizationPlatformId"
)
);
}
?>

21
classes/class.plan.priceoption.php

@ -0,0 +1,21 @@
<?php
if($_VPS !== true) { die("x"); }
class PlanPriceOption extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM plan_priceoptions WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM plan_priceoptions WHERE `Id` = '%d'";
public $table_name = "plan_priceoptions";
public $prototype = array(
'numeric' => array(
'BillingPeriod' => "BillingPeriod",
'Price' => "Price",
'PlanId' => "PlanId"
),
'plan' => array(
'Plan' => "PlanId"
)
);
}
?>

29
classes/class.provider.php

@ -0,0 +1,29 @@
<?php
if($_VPS !== true) { die("x"); }
class Provider extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM providers WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM providers WHERE `Id` = '%d'";
public $table_name = "providers";
public $prototype = array(
'string' => array(
'Name' => "Name",
'Url' => "Url",
'CompanyLocation' => "Location"
),
'numeric' => array(
'PlanCount' => "PlanCount",
'UsesMaxmind' => "Maxmind"
),
'boolean' => array(
'Visible' => "Visible",
'CustomPossible' => "CustomPossible"
),
'timestamp' => array(
'SubmissionDate' => "SubmissionDate"
)
);
}
?>

16
classes/class.technology.php

@ -0,0 +1,16 @@
<?php
if($_VPS !== true) { die("x"); }
class VirtualizationTechnology extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM technologies WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM technologies WHERE `Id` = '%d'";
public $table_name = "technologies";
public $prototype = array(
'string' => array(
'Name' => "Name"
)
);
}
?>

16
classes/class.virtualizationplatform.php

@ -0,0 +1,16 @@
<?php
if($_VPS !== true) { die("x"); }
class VirtualizationPlatform extends CPHPDatabaseRecordClass
{
public $fill_query = "SELECT * FROM virtualizationplatforms WHERE `Id` = '%d'";
public $verify_query = "SELECT * FROM virtualizationplatforms WHERE `Id` = '%d'";
public $table_name = "virtualizationplatforms";
public $prototype = array(
'string' => array(
'Name' => "Name"
)
);
}
?>

30
cphp/base.php

@ -0,0 +1,30 @@
<?php
require("include.constants.php");
require("config.php");
require("include.dependencies.php");
require("include.exceptions.php");
require("include.datetime.php");
require("include.misc.php");
require("include.memcache.php");
require("include.mysql.php");
require("include.session.php");
require("class.templater.php");
require("class.localizer.php");
$locale = new Localizer();
$locale->Load($cphp_locale_name);
setlocale(LC_ALL, $locale->locale);
require("class.base.php");
require("class.databaserecord.php");
foreach($cphp_components as $component)
{
require("components/component.{$component}.php");
}
?>

143
cphp/class.base.php

@ -0,0 +1,143 @@
<?php
if($_CPHP !== true) { die(); }
class CPHPBaseClass
{
public $render_template = "";
public function RenderTimeAgo($template, $property)
{
global $locale;
$variable_name = "s{$property}";
if(isset($this->$variable_name) && is_numeric($this->$variable_name))
{
$timestamp = $this->$variable_name;
if($timestamp > time())
{
$sTimeAgo = $locale->strings['event-future'];
}
elseif($timestamp == time())
{
$sTimeAgo = $locale->strings['event-now'];
}
else
{
$date1 = new DateTime("@{$timestamp}", new DateTimeZone("GMT"));
$date2 = new DateTime("now", new DateTimeZone("GMT"));
$interval = $date1->diff($date2);
$years = (int)$interval->format("%G");
$months = (int)$interval->format("%m");
$weeks = (int)$interval->format("%U");
$days = (int)$interval->format("%d");
$hours = (int)$interval->format("%H");
$minutes = (int)$interval->format("%i");
$seconds = (int)$interval->format("%S");
if($years > 1)
{
$sTimeAgo = sprintf($locale->strings['event-years-ago'], $years);
}
elseif($years == 1)
{
$sTimeAgo = $locale->strings['event-1year-ago'];
}
elseif($months > 1)
{
$sTimeAgo = sprintf($locale->strings['event-months-ago'], $months);
}
elseif($months == 1)
{
$sTimeAgo = $locale->strings['event-1month-ago'];
}
elseif($weeks > 1)
{
$sTimeAgo = sprintf($locale->strings['event-weeks-ago'], $weeks);
}
elseif($weeks == 1)
{
$sTimeAgo = $locale->strings['event-1week-ago'];
}
elseif($days > 1)
{
$sTimeAgo = sprintf($locale->strings['event-days-ago'], $days);
}
elseif($days == 1)
{
$sTimeAgo = $locale->strings['event-1day-ago'];
}
elseif($hours > 1)
{
$sTimeAgo = sprintf($locale->strings['event-hours-ago'], $hours);
}
elseif($hours == 1)
{
$sTimeAgo = $locale->strings['event-1hour-ago'];
}
elseif($minutes > 1)
{
$sTimeAgo = sprintf($locale->strings['event-minutes-ago'], $minutes);
}
elseif($minutes == 1)
{
$sTimeAgo = $locale->strings['event-1minute-ago'];
}
elseif($seconds > 1)
{
$sTimeAgo = sprintf($locale->strings['event-seconds-ago'], $seconds);
}
elseif($seconds == 1)
{
$sTimeAgo = $locale->strings['event-1second-ago'];
}
else
{
// If you see this, there's probably something wrong.
$sTimeAgo = $locale->strings['event-past'];
}
}
$sDate = local_from_unix($timestamp, $locale->datetime_long);
return $this->RenderTemplateExternal($template, array(
'local-time' => $sDate,
'time-ago' => $sTimeAgo,
'timestamp' => $timestamp
));
}
else
{
$classname = get_class($this);
throw new Exception("Property {$classname}.{$property} does not exist or is not of a valid format.");
}
}
public function RenderTemplateExternal($template, $strings)
{
return $this->DoRenderTemplate($template, $strings);
}
public function DoRenderTemplate($template, $strings)
{
global $locale;
try
{
$tpl = new Templater();
$tpl->Load($template);
$tpl->Localize($locale->strings);
$tpl->Compile($strings);
return $tpl->Render();
}
catch(Exception $e)
{
$classname = get_class($this);
throw new Exception("Failed to render template {$classname}.{$template}.");
}
}
}
?>

381
cphp/class.databaserecord.php

@ -0,0 +1,381 @@
<?php
if($_CPHP !== true) { die(); }
abstract class CPHPDatabaseRecordClass extends CPHPBaseClass
{
public $fill_query = "";
public $verify_query = "";
public $table_name = "";
public $query_cache = 60;
public $prototype = array();
public $prototype_render = array();
public $uData = array();
public $sId = 0;
public function __construct($uDataSource, $uCommunityId = 0)
{
$this->ConstructDataset($uDataSource, $uCommunityId);
}
public function ConstructDataset($uDataSource, $uCommunityId = 0)
{
$bind_datasets = true;
if(is_numeric($uDataSource))
{
if($uDataSource != 0)
{
if(!empty($this->fill_query))
{
$this->sId = (is_numeric($uDataSource)) ? $uDataSource : 0;
$query = sprintf($this->fill_query, $uDataSource);
if($result = mysql_query_cached($query, $this->query_cache))
{
$uDataSource = $result->data[0];
}
else
{
$classname = get_class($this);
throw new NotFoundException("Could not locate {$classname} {$uDataSource} in database.");
}
}
else
{
$classname = get_class($this);
throw new PrototypeException("No fill query defined for {$classname} class.");
}
}
else
{
$bind_datasets = false;
}
}
elseif(is_object($uDataSource))
{
if(isset($uDataSource->data[0]))
{
$uDataSource = $uDataSource->data[0];
}
else
{
throw new NotFoundException("No result set present in object.");
}
}
elseif(is_array($uDataSource))
{
if(isset($uDataSource[0]))
{
$uDataSource = $uDataSource[0];
}
}
else
{
$classname = get_class($this);
throw new ConstructorException("Invalid type passed on to constructor for object of type {$classname}.");
}
if($bind_datasets === true)
{
$this->sId = (is_numeric($uDataSource['Id'])) ? $uDataSource['Id'] : 0;
$this->uData = $uDataSource;
foreach($this->prototype as $type => $dataset)
{
$this->BindDataset($type, $dataset);
}
$this->sFound = true;
}
else
{
$this->sFound = false;
}
if(!empty($uCommunityId) && !empty($this->sCommunityId))
{
$sCommunityId = (is_numeric($uCommunityId)) ? $uCommunityId : 0;
if($sCommunityId != $this->sCommunity->sId)
{
$classname = get_class($this);
throw new OwnershipException("{$classname} {$this->sId} does not belong to Community {$sCommunityId}.");
}
}
}
public function BindDataset($type, $dataset)
{
global $cphp_class_map;
if(is_array($dataset))
{
foreach($dataset as $variable_name => $column_name)
{
$original_value = $this->uData[$column_name];
switch($type)
{
case "string":
$value = htmlspecialchars(stripslashes($original_value));
$variable_type = CPHP_VARIABLE_SAFE;
break;
case "html":
$value = filter_html(stripslashes($original_value));
$variable_type = CPHP_VARIABLE_SAFE;
break;
case "simplehtml":
$value = filter_html_strict(stripslashes($original_value));
$variable_type = CPHP_VARIABLE_SAFE;
break;
case "nl2br":
$value = nl2br(htmlspecialchars(stripslashes($original_value)), false);
$variable_type = CPHP_VARIABLE_SAFE;
break;
case "numeric":
$value = (is_numeric($original_value)) ? $original_value : 0;
$variable_type = CPHP_VARIABLE_SAFE;
break;
case "timestamp":
$value = unix_from_mysql($original_value);
$variable_type = CPHP_VARIABLE_SAFE;
break;
case "boolean":
$value = (empty($original_value)) ? false : true;
$variable_type = CPHP_VARIABLE_SAFE;
break;
case "user":
$value = new User($original_value);
$variable_type = CPHP_VARIABLE_SAFE;
break;
case "none":
$value = $original_value;
$variable_type = CPHP_VARIABLE_UNSAFE;
break;
default:
$found = false;
foreach($cphp_class_map as $class_type => $class_name)
{
if($type == $class_type)
{
$value = new $class_name($original_value);
$variable_type = CPHP_VARIABLE_SAFE;
$found = true;
}
}
if($found == false)
{
$classname = get_class($this);
throw new Exception("Cannot determine type of dataset ({$type}) passed on to {$classname}.BindDataset.");
break;
}
}
if($variable_type == CPHP_VARIABLE_SAFE)
{
$variable_name_safe = "s" . $variable_name;
$this->$variable_name_safe = $value;
}
$variable_name_unsafe = "u" . $variable_name;
$this->$variable_name_unsafe = $original_value;
}
}
else
{
$classname = get_class($this);
throw new Exception("Invalid dataset passed on to {$classname}.BindDataset.");
}
}
public function DoRenderInternalTemplate()
{
if(!empty($this->render_template))
{
$strings = array();
foreach($this->prototype_render as $template_var => $object_var)
{
$variable_name = "s" . $object_var;
$strings[$template_var] = $this->$variable_name;
}
return $this->DoRenderTemplate($this->render_template, $strings);
}
else
{
$classname = get_class($this);
throw new Exception("Cannot render template: no template defined for {$classname} class.");
}
}
public function InsertIntoDatabase()
{
if(!empty($this->verify_query))
{
if($this->sId == 0)
{
$insert_mode = CPHP_INSERTMODE_INSERT;
}
else
{
$query = sprintf($this->verify_query, $this->sId);
if($result = mysql_query_cached($query))
{
$insert_mode = CPHP_INSERTMODE_UPDATE;
}
else
{
$insert_mode = CPHP_INSERTMODE_INSERT;
}
}
$element_list = array();
foreach($this->prototype as $type_key => $type_value)
{
foreach($type_value as $element_key => $element_value)
{
switch($type_key)
{
case "none":
case "numeric":
case "boolean":
case "timestamp":
case "string":
$element_list[$element_value] = array(
'key' => $element_key,
'type' => $type_key
);
break;
default:
break;
}
}
}
$sKeyList = array();
$sValueList = array();
foreach($element_list as $sKey => $value)
{
$variable_name_safe = "s" . $value['key'];
$variable_name_unsafe = "u" . $value['key'];
if(isset($this->$variable_name_safe) || isset($this->$variable_name_unsafe))
{
switch($value['type'])
{
case "none":
$sFinalValue = mysql_real_escape_string($this->$variable_name_unsafe);
break;
case "numeric":
$number = (isset($this->$variable_name_unsafe)) ? $this->$variable_name_unsafe : $this->$variable_name_safe;
$sFinalValue = (is_numeric($number)) ? $number : 0;
break;
case "boolean":
$bool = (isset($this->$variable_name_unsafe)) ? $this->$variable_name_unsafe : $this->$variable_name_safe;
$sFinalValue = ($bool) ? "1" : "0";
break;
case "timestamp":
$sFinalValue = (isset($this->$variable_name_safe)) ? mysql_from_unix($this->$variable_name_safe) : mysql_from_unix(unix_from_local($this->$variable_name_unsafe));
break;
case "string":
$sFinalValue = (isset($this->$variable_name_unsafe)) ? mysql_real_escape_string($this->$variable_name_unsafe) : mysql_real_escape_string($this->$variable_name_safe);
break;
case "default":
$sFinalValue = mysql_real_escape_string($this->$variable_name_unsafe);
break;
}
$sFinalValue = "'{$sFinalValue}'";
$sKey = "`{$sKey}`";
$sKeyList[] = $sKey;
$sValueList[] = $sFinalValue;
}
else
{
$classname = get_class($this);
throw new Exception("Database insertion failed: prototype property {$value['key']} not found in object of type {$classname}.");
}
}
if($insert_mode == CPHP_INSERTMODE_INSERT)
{
$sQueryKeys = implode(", ", $sKeyList);
$sQueryValues = implode(", ", $sValueList);
$query = "INSERT INTO {$this->table_name} ({$sQueryKeys}) VALUES ({$sQueryValues})";
}
elseif($insert_mode == CPHP_INSERTMODE_UPDATE)
{
$sKeyValueList = array();
for($i = 0; $i < count($sKeyList); $i++)
{
$sKey = $sKeyList[$i];
$sValue = $sValueList[$i];
$sKeyValueList[] = "{$sKey} = {$sValue}";
}
$sQueryKeysValues = implode(", ", $sKeyValueList);
$query = "UPDATE {$this->table_name} SET {$sQueryKeysValues} WHERE `Id` = '{$this->sId}'";
}
if($result = mysql_query($query))
{
if($insert_mode == CPHP_INSERTMODE_INSERT)
{
$this->sId = mysql_insert_id();
}
return $result;
}
else
{
$classname = get_class($this);
throw new DatabaseException("Database insertion query failed in object of type {$classname}. Error message: " . mysql_error());
}
}
else
{
$classname = get_class($this);
throw new Exception("No verification query defined for {$classname} class.");
}
}
public function RetrieveChildren($type, $field)
{
if(!isset($cphp_class_map[$type]))
{
$classname = get_class($this);
throw new NotFoundException("Non-existent 'type' argument passed on to {$classname}.RetrieveChildren function.");
}
$parent_type = get_parent_class($cphp_class_map[$type]);
if($parent_type !== "CPHPDatabaseRecordClass")
{
$parent_type = ($parent_type === false) ? "NONE" : $parent_type;
$classname = get_class($this);
throw new TypeException("{$classname}.RetrieveChildren expected 'type' argument of parent-type CPHPDatabaseRecordClass, but got {$parent_type} instead.");
}
$query = "";
}
public function PurgeCache()
{
$query = sprintf($this->fill_query, $this->sId);
$key = md5($query) . md5($query . "x");
mc_delete($key);
}
public function RenderTemplate()
{
return $this->DoRenderInternalTemplate();
}
}
?>

64
cphp/class.localizer.php

@ -0,0 +1,64 @@
<?php
if($_CPHP !== true) { die(); }
class Localizer
{
public $strings = array();
public $locale = "";
public $datetime_short = "";
public $datetime_long = "";
public $date_short = "";
public $date_long = "";
public $time = "";
public function Load($locale)
{
global $cphp_locale_path, $cphp_locale_ext;
$this->strings = array();
$lng_contents = file_get_contents("{$cphp_locale_path}/{$locale}.{$cphp_locale_ext}");
if($lng_contents !== false)
{
$lines = explode("\n", $lng_contents);
foreach($lines as $line)
{
$line = str_replace("\r", "", $line);
if(preg_match("/(.+?[^\\\]);(.+)/", $line, $matches))
{
$key = trim(str_replace("\;", ";", $matches[1]));
$value = trim(str_replace("\;", ";", $matches[2]));
switch($key)
{
case "_locale":
$this->locale = explode(",", $value);
break;
case "_datetime_short":
$this->datetime_short = $value;
break;
case "_datetime_long":
$this->datetime_long = $value;
break;
case "_date_short":
$this->date_short = $value;
break;
case "_date_long":
$this->date_long = $value;
break;
case "_time":
$this->time = $value;
break;
default:
$this->strings[$key] = $value;
break;
}
}
}
}
else
{
Throw new Exception("Failed to load locale {$locale}.");
}
}
}
?>

112
cphp/class.templater.php

@ -0,0 +1,112 @@
<?php
if($_CPHP !== true) { die(); }
$template_cache = array();
class Templater
{
private $basedir = "templates/";
private $extension = ".tpl";
private $tpl = NULL;
private $tpl_rendered = NULL;
public function Load($template)
{
global $template_cache;
if(isset($template_cache[$template]))
{
$tpl_contents = $template_cache[$template];
}
else
{
$tpl_contents = file_get_contents($this->basedir . $template . $this->extension);
$template_cache[$template] = $tpl_contents;
}
if($tpl_contents !== false)
{
$this->tpl = $tpl_contents;
$this->tpl_rendered = $tpl_contents;
}
else
{
Throw new Exception("Failed to load template {$template}.");
}
}
public function Reset()
{
if(!is_null($this->tpl))
{
$this->tpl_rendered = $this->tpl;
}
else
{
Throw new Exception("No template loaded.");
}
}
public function Localize($strings)
{
if(!is_null($this->tpl))
{
preg_match_all("/<%!([a-zA-Z0-9_-]+)>/", $this->tpl_rendered, $strlist);
foreach($strlist[1] as $str)
{
if(isset($strings[$str]))
{
$this->tpl_rendered = str_replace("<%!{$str}>", $strings[$str], $this->tpl_rendered);
}
}
}
else
{
Throw new Exception("No template loaded.");
}
}
public function Compile($strings)
{
if(!is_null($this->tpl))
{
preg_match_all("/<%\?([a-zA-Z0-9_-]+)>/", $this->tpl_rendered, $strlist);
foreach($strlist[1] as $str)
{
if(isset($strings[$str]))
{
$this->tpl_rendered = str_replace("<%?{$str}>", $strings[$str], $this->tpl_rendered);
}
}
}
else
{
Throw new Exception("No template loaded.");
}
}
public function Render()
{
if(!is_null($this->tpl))
{
return $this->tpl_rendered;
}
else
{
Throw new Exception("No template loaded.");
}
}
public function Output()
{
if(!is_null($this->tpl))
{
echo($this->tpl_rendered);
}
else
{
Throw new Exception("No template loaded.");
}
}
}
?>

60
cphp/components/component.errorhandler.php

@ -0,0 +1,60 @@
<?php
cphp_dependency_provides("cphp_errorhandler", "0.1");
define("CPHP_ERRORHANDLER_TYPE_ERROR", 90001 );
define("CPHP_ERRORHANDLER_TYPE_INFO", 90002 );
define("CPHP_ERRORHANDLER_TYPE_WARNING", 90003 );
define("CPHP_ERRORHANDLER_TYPE_SUCCESS", 90004 );
class CPHPErrorHandler
{
public $sErrorType = CPHP_ERRORHANDLER_TYPE_ERROR;
public $sLogError = true;
public $sTitle = "";
public $sMessage = "";
public function __construct($type, $title, $message, $log = true)
{
$this->sErrorType = $type;
$this->sLogError = $log;
$this->sTitle = $title;
$this->sMessage = $message;
}
public function LogError($context, $message)
{
// FIXME placeholder function, error logging has not been implemented yet
}
public function Render()
{
global $locale;
$template['error'] = new Templater();
switch($this->sErrorType)
{
case CPHP_ERRORHANDLER_TYPE_ERROR:
$template['error']->Load("errorhandler.error");
break;
case CPHP_ERRORHANDLER_TYPE_INFO:
$template['error']->Load("errorhandler.info");
break;
case CPHP_ERRORHANDLER_TYPE_WARNING:
$template['error']->Load("errorhandler.warning");
break;
case CPHP_ERRORHANDLER_TYPE_SUCCESS:
$template['error']->Load("errorhandler.success");
break;
}
$template['error']->Localize($locale->strings);
$template['error']->Compile(array(
'title' => $this->sTitle,
'message' => $this->sMessage
));
return $template['error']->Render();
}
}
?>

379
cphp/components/component.formbuilder.php

@ -0,0 +1,379 @@
<?php
cphp_dependency_provides("cphp_formbuilder", "1.0");
$cphp_formbuilder_increment = 0;
abstract class CPHPFormBuilderBaseClass
{
public $parameters = array();
public function AddParameter($key, $value)
{
$this->parameters[$key] = $value;
}
public function RenderParameters($parameters)
{
if(empty($parameters))
{
return "";
}
$rendered = array();
foreach($parameters as $key => $value)
{
$value = utf8entities($value);
$rendered[] = "{$key}=\"{$value}\"";
}
return " " . implode(" ", $rendered);
}
public function RenderNote()
{
if(!empty($this->note))
{
return "<div class=\"cphp_fbd_note\">{$this->note}</div>";
}
else
{
return "";
}
}
}
abstract class CPHPFormBuilderContainer extends CPHPFormBuilderBaseClass
{
public $elements = array();
public function AddElement($element)
{
$this->elements[] = $element;
}
}
class CPHPFormBuilder extends CPHPFormBuilderContainer
{
public $method = "";
public $action = "";
public function __construct($method, $target)
{
$this->method = strtolower($method);
$this->action = $target;
}
public function Render()
{
$rendered_elements = "";
foreach($this->elements as $element)
{
$rendered_elements .= $element->Render();
}
$this->AddParameter("method", $this->method);
$this->AddParameter("action", $this->action);
$rendered_parameters = $this->RenderParameters($this->parameters);
return "<form{$rendered_parameters}>{$rendered_elements}</form>";
}
}
class CPHPFormSection extends CPHPFormBuilderContainer
{
public $label = "";
public $fieldset = true;
public $classname = "";
public function __construct($fieldset = true, $label = "")
{
if(!empty($label))
{
$this->label = $label;
}
$this->fieldset = $fieldset;
}
public function Render()
{
if(!empty($this->label))
{
$legend = "<legend>{$this->label}</legend>";
}
else
{
$legend = "";
}
if($this->fieldset === true)
{
$this->classname = trim("{$this->classname} cphp_fbd_fieldset");
}
$rendered_elements = "";
foreach($this->elements as $element)
{
$rendered_elements .= $element->Render();
}
if($this->fieldset === true)
{
$this->AddParameter("class", $this->classname);
$rendered_parameters = $this->RenderParameters($this->parameters);
return "<fieldset{$rendered_parameters}>{$legend}<div class=\"cphp_fbd_form\">{$rendered_elements}</div></fieldset>";
}
else
{
return "<div class=\"cphp_fbd_form\"{$rendered_parameters}>{$rendered_elements}</div>";
}
}
}
abstract class CPHPFormInputElement extends CPHPFormBuilderBaseClass
{
public $id = "";
public $name = "";
public $value = "";
public $label = "";
public function __construct($label, $name, $value = "", $note = "", $id = "")
{
global $cphp_formbuilder_increment;
$this->name = $name;
$this->value = $value;
$this->label = $label;
$this->note = $note;
if(empty($id))
{
$this->id = "cphp_fbd_{$cphp_formbuilder_increment}";
$cphp_formbuilder_increment += 1;
}
else
{
$this->id = $id;
}
}
}
abstract class CPHPFormInput extends CPHPFormInputElement
{
public function Render()
{
$this->AddParameter("id", $this->id);
$this->AddParameter("type", $this->type);
$this->AddParameter("name", $this->name);
$this->AddParameter("value", $this->value);
$rendered_parameters = $this->RenderParameters($this->parameters);
$rendered_note = $this->RenderNote();
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>";
}
}
class CPHPFormTextInput extends CPHPFormInput
{
public $type = "text";
}
class CPHPFormPasswordInput extends CPHPFormInput
{
public $type = "password";
}
class CPHPFormDateInput extends CPHPFormInput
{
public $type = "date";
}
class CPHPFormTimeInput extends CPHPFormInput
{
public $type = "time";
}
class CPHPFormEmailInput extends CPHPFormInput
{
public $type = "email";
}
class CPHPFormUrlInput extends CPHPFormInput
{
public $type = "url";
}
class CPHPFormRangeInput extends CPHPFormInput
{
public $type = "range";
}
class CPHPFormColorInput extends CPHPFormInput
{
public $type = "color";
}
class CPHPFormSearchInput extends CPHPFormInput
{
public $type = "search";
}
class CPHPFormCheckboxGroup extends CPHPFormBuilderContainer
{
public function __construct($label, $note = "")
{
global $cphp_formbuilder_increment;
$this->label = $label;
$this->note = $note;
}
public function Render()
{
$rendered_note = $this->RenderNote();
$rendered_elements = "";
foreach($this->elements as $element)
{
$rendered_elements .= $element->Render();
}
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>";
}
}
class CPHPFormCheckbox extends CPHPFormInputElement
{
public function Render()
{
$this->AddParameter("id", $this->id);
$this->AddParameter("type", "checkbox");
$this->AddParameter("name", $this->name);
if($this->value === true)
{
$this->AddParameter("checked", "");
}
$rendered_parameters = $this->RenderParameters($this->parameters);
$rendered_note = $this->RenderNote();
return "<div class=\"cphp_fbd_cblabel\"><input{$rendered_parameters}><label for=\"{$this->id}\">{$this->label}{$rendered_note}</label></div>";
}
}
class CPHPFormRadioButton extends CPHPFormInput
{
public $type = "radio";
}
class CPHPFormButton extends CPHPFormInputElement
{
public $type = "button";
public function Render()
{
$this->AddParameter("type", $this->type);
$this->AddParameter("name", $this->name);
$this->AddParameter("value", $this->value);
$rendered_parameters = $this->RenderParameters($this->parameters);
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>";
}
}
class CPHPFormSubmitButton extends CPHPFormButton
{
public $type = "submit";
}
class CPHPFormResetButton extends CPHPFormButton
{
public $type = "reset";
}
class CPHPFormSelect extends CPHPFormInputElement
{
public $options = array();
public function AddOption($option)
{
$this->options[] = $option;
}
public function Render()
{
$this->AddParameter("id", $this->id);
$this->AddParameter("name", $this->name);
$rendered_parameters = $this->RenderParameters($this->parameters);
$rendered_note = $this->RenderNote();
$list = "";
foreach($this->options as $option)
{
$list .= $option->Render();
}
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>";
}
}
class CPHPFormSelectOptionGroup
{
public $label = "";
public $options = array();
public function __construct($label)
{
$this->label = $label;
}
public function AddOption($option)
{
$this->options[] = $option;
}
public function Render()
{
$list = "";
foreach($this->options as $option)
{
$list .= $option->Render();
}
return "<optgroup label=\"{$this->label}\">{$list}</optgroup>";
}
}
class CPHPFormSelectOption
{
public $value = "";
public $description = "";
public $selected = false;
public function __construct($value, $description, $selected = false)
{
$this->value = $value;
$this->description = $description;
$this->selected = $selected;
}
public function Render()
{
$selected_attribute = ($selected) ? " selected" : "";
return "<option value=\"{$this->value}\"{$selected_attribute}>{$this->description}</option>";
}
}
?>

40
cphp/components/component.router.php

@ -0,0 +1,40 @@
<?php
class CPHPRouter extends CPHPBaseClass
{
public $routes = array();
public $parameters = array();
public function RouteRequest()
{
eval(extract_globals()); // hack hackity hack hack
if(isset($_SERVER['REQUEST_URI']))
{
$requestpath = trim($_SERVER['REQUEST_URI']);
}
else
{
$requestpath = "/";
}
$found = false; // Workaround because a break after an include apparently doesn't work in PHP.
foreach($this->routes as $priority)
{
foreach($priority as $route_regex => $route_destination)
{
if($found === false)
{
$regex = str_replace("/", "\/", $route_regex);
if(preg_match("/{$regex}/i", $requestpath, $matches))
{
$this->uParameters = $matches;
include($route_destination);
$found = true;
}
}
}
}
}
}
?>

36
cphp/config.php

@ -0,0 +1,36 @@
<?php
if($_CPHP !== true) { die(); }
$cphp_class_map = array(
'country' => "Country",
'provider' => "Provider",
'plan' => "Plan",
'paymentmethod' => "PaymentMethod",
'virtualizationplatform' => "VirtualizationPlatform"
);
$cphp_locale_name = "english";
$cphp_locale_path = "locales";
$cphp_locale_ext = "lng";
$cphp_usersettings[CPHP_SETTING_TIMEZONE] = "Europe/Amsterdam";
/* These are the memcache settings. You will need to have memcache set
* up on your server to use these. Compression requires zlib. */
$cphp_memcache_enabled = true; // Whether to user memcache.
$cphp_memcache_server = "localhost"; // The hostname of the memcached
$cphp_memcache_port = 11211; // The port number of memcached
$cphp_memcache_compressed = true; // Whether to compress memcache objects
$cphp_mysql_enabled = true;
$cphp_mysql_host = "localhost";
$cphp_mysql_user = "vps";
$cphp_mysql_pass = "";
$cphp_mysql_db = "vps";
$cphp_components = array(
"router",
"formbuilder",
"errorhandler"
);
?>

13
cphp/include.constants.php

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

169
cphp/include.datetime.php

@ -0,0 +1,169 @@
<?php
if($_CPHP !== true) { die(); }
$timezones = array(
'Pacific/Kwajalein' => '(GMT-12:00) International Date Line West',
'Pacific/Midway' => '(GMT-11:00) Midway Island',
'Pacific/Samoa' => '(GMT-11:00) Samoa',
'Pacific/Honolulu' => '(GMT-10:00) Hawaii',
'America/Anchorage' => '(GMT-09:00) Alaska',
'America/Los_Angeles' => '(GMT-08:00) Pacific Time (US &amp; Canada)',
'America/Tijuana' => '(GMT-08:00) Tijuana, Baja California',
'America/Denver' => '(GMT-07:00) Mountain Time (US &amp; Canada)',
'America/Chihuahua' => '(GMT-07:00) Chihuahua',
'America/Mazatlan' => '(GMT-07:00) Mazatlan',
'America/Phoenix' => '(GMT-07:00) Arizona',
'America/Regina' => '(GMT-06:00) Saskatchewan',
'America/Tegucigalpa' => '(GMT-06:00) Central America',
'America/Chicago' => '(GMT-06:00) Central Time (US &amp; Canada)',
'America/Mexico_City' => '(GMT-06:00) Mexico City',
'America/Monterrey' => '(GMT-06:00) Monterrey',
'America/New_York' => '(GMT-05:00) Eastern Time (US &amp; Canada)',
'America/Bogota' => '(GMT-05:00) Bogota',
'America/Lima' => '(GMT-05:00) Lima',
'America/Rio_Branco' => '(GMT-05:00) Rio Branco',
'America/Indiana/Indianapolis' => '(GMT-05:00) Indiana (East)',
'America/Caracas' => '(GMT-04:30) Caracas',
'America/Halifax' => '(GMT-04:00) Atlantic Time (Canada)',
'America/Manaus' => '(GMT-04:00) Manaus',
'America/Santiago' => '(GMT-04:00) Santiago',
'America/La_Paz' => '(GMT-04:00) La Paz',
'America/St_Johns' => '(GMT-03:30) Newfoundland',
'America/Argentina/Buenos_Aires' => '(GMT-03:00) Georgetown',
'America/Sao_Paulo' => '(GMT-03:00) Brasilia',
'America/Godthab' => '(GMT-03:00) Greenland',
'America/Montevideo' => '(GMT-03:00) Montevideo',
'Atlantic/South_Georgia' => '(GMT-02:00) Mid-Atlantic',
'Atlantic/Azores' => '(GMT-01:00) Azores',
'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde Is.',
'Europe/Dublin' => '(GMT) Dublin',
'Europe/Lisbon' => '(GMT) Lisbon',
'Europe/London' => '(GMT) London',
'Africa/Monrovia' => '(GMT) Monrovia',
'Atlantic/Reykjavik' => '(GMT) Reykjavik',
'Africa/Casablanca' => '(GMT) Casablanca',
'Europe/Belgrade' => '(GMT+01:00) Belgrade',
'Europe/Bratislava' => '(GMT+01:00) Bratislava',
'Europe/Budapest' => '(GMT+01:00) Budapest',
'Europe/Ljubljana' => '(GMT+01:00) Ljubljana',
'Europe/Prague' => '(GMT+01:00) Prague',
'Europe/Sarajevo' => '(GMT+01:00) Sarajevo',
'Europe/Skopje' => '(GMT+01:00) Skopje',
'Europe/Warsaw' => '(GMT+01:00) Warsaw',
'Europe/Zagreb' => '(GMT+01:00) Zagreb',
'Europe/Brussels' => '(GMT+01:00) Brussels',
'Europe/Copenhagen' => '(GMT+01:00) Copenhagen',
'Europe/Madrid' => '(GMT+01:00) Madrid',
'Europe/Paris' => '(GMT+01:00) Paris',
'Africa/Algiers' => '(GMT+01:00) West Central Africa',
'Europe/Amsterdam' => '(GMT+01:00) Amsterdam',
'Europe/Berlin' => '(GMT+01:00) Berlin',
'Europe/Rome' => '(GMT+01:00) Rome',
'Europe/Stockholm' => '(GMT+01:00) Stockholm',
'Europe/Vienna' => '(GMT+01:00) Vienna',
'Europe/Minsk' => '(GMT+02:00) Minsk',
'Africa/Cairo' => '(GMT+02:00) Cairo',
'Europe/Helsinki' => '(GMT+02:00) Helsinki',
'Europe/Riga' => '(GMT+02:00) Riga',
'Europe/Sofia' => '(GMT+02:00) Sofia',
'Europe/Tallinn' => '(GMT+02:00) Tallinn',
'Europe/Vilnius' => '(GMT+02:00) Vilnius',
'Europe/Athens' => '(GMT+02:00) Athens',
'Europe/Bucharest' => '(GMT+02:00) Bucharest',
'Europe/Istanbul' => '(GMT+02:00) Istanbul',
'Asia/Jerusalem' => '(GMT+02:00) Jerusalem',
'Asia/Amman' => '(GMT+02:00) Amman',
'Asia/Beirut' => '(GMT+02:00) Beirut',
'Africa/Windhoek' => '(GMT+02:00) Windhoek',
'Africa/Harare' => '(GMT+02:00) Harare',
'Asia/Kuwait' => '(GMT+03:00) Kuwait',
'Asia/Riyadh' => '(GMT+03:00) Riyadh',
'Asia/Baghdad' => '(GMT+03:00) Baghdad',
'Africa/Nairobi' => '(GMT+03:00) Nairobi',
'Asia/Tbilisi' => '(GMT+03:00) Tbilisi',
'Europe/Moscow' => '(GMT+03:00) Moscow',
'Europe/Volgograd' => '(GMT+03:00) Volgograd',
'Asia/Tehran' => '(GMT+03:30) Tehran',
'Asia/Muscat' => '(GMT+04:00) Muscat',
'Asia/Baku' => '(GMT+04:00) Baku',
'Asia/Yerevan' => '(GMT+04:00) Yerevan',
'Asia/Yekaterinburg' => '(GMT+05:00) Ekaterinburg',
'Asia/Karachi' => '(GMT+05:00) Karachi',
'Asia/Tashkent' => '(GMT+05:00) Tashkent',
'Asia/Kolkata' => '(GMT+05:30) Calcutta',
'Asia/Colombo' => '(GMT+05:30) Sri Jayawardenepura',
'Asia/Katmandu' => '(GMT+05:45) Kathmandu',
'Asia/Dhaka' => '(GMT+06:00) Dhaka',
'Asia/Almaty' => '(GMT+06:00) Almaty',
'Asia/Novosibirsk' => '(GMT+06:00) Novosibirsk',
'Asia/Rangoon' => '(GMT+06:30) Yangon (Rangoon)',
'Asia/Krasnoyarsk' => '(GMT+07:00) Krasnoyarsk',
'Asia/Bangkok' => '(GMT+07:00) Bangkok',
'Asia/Jakarta' => '(GMT+07:00) Jakarta',
'Asia/Brunei' => '(GMT+08:00) Beijing',
'Asia/Chongqing' => '(GMT+08:00) Chongqing',
'Asia/Hong_Kong' => '(GMT+08:00) Hong Kong',
'Asia/Urumqi' => '(GMT+08:00) Urumqi',
'Asia/Irkutsk' => '(GMT+08:00) Irkutsk',
'Asia/Ulaanbaatar' => '(GMT+08:00) Ulaan Bataar',
'Asia/Kuala_Lumpur' => '(GMT+08:00) Kuala Lumpur',
'Asia/Singapore' => '(GMT+08:00) Singapore',
'Asia/Taipei' => '(GMT+08:00) Taipei',
'Australia/Perth' => '(GMT+08:00) Perth',
'Asia/Seoul' => '(GMT+09:00) Seoul',
'Asia/Tokyo' => '(GMT+09:00) Tokyo',
'Asia/Yakutsk' => '(GMT+09:00) Yakutsk',
'Australia/Darwin' => '(GMT+09:30) Darwin',
'Australia/Adelaide' => '(GMT+09:30) Adelaide',
'Australia/Canberra' => '(GMT+10:00) Canberra',
'Australia/Melbourne' => '(GMT+10:00) Melbourne',
'Australia/Sydney' => '(GMT+10:00) Sydney',
'Australia/Brisbane' => '(GMT+10:00) Brisbane',
'Australia/Hobart' => '(GMT+10:00) Hobart',
'Asia/Vladivostok' => '(GMT+10:00) Vladivostok',
'Pacific/Guam' => '(GMT+10:00) Guam',
'Pacific/Port_Moresby' => '(GMT+10:00) Port Moresby',
'Asia/Magadan' => '(GMT+11:00) Magadan',
'Pacific/Fiji' => '(GMT+12:00) Fiji',
'Asia/Kamchatka' => '(GMT+12:00) Kamchatka',
'Pacific/Auckland' => '(GMT+12:00) Auckland',
'Pacific/Tongatapu' => '(GMT+13:00) Nukualofa'
);
function unix_from_local($timestamp)
{
global $user_preferences;
date_default_timezone_set($user_preferences[CPHP_SETTING_TIMEZONE]);
return strtotime($timestamp);
}
function unix_from_mysql($timestamp)
{
date_default_timezone_set("GMT");
return strtotime($timestamp);
}
function local_from_unix($timestamp, $format)
{
global $user_preferences;
date_default_timezone_set($user_preferences[CPHP_SETTING_TIMEZONE]);
return strftime($format, $timestamp);
}
function gmt_from_unix($timestamp, $format)
{
date_default_timezone_set("GMT");
return strftime($format, $timestamp);
}
function mysql_from_unix($timestamp)
{
date_default_timezone_set("GMT");
return date("Y-m-d H:i:s", $timestamp);
}
function floor_to_day($timestamp)
{
return floor($timestamp / (60 * 60 * 24)) * (60 * 60 * 24);
}
?>

90
cphp/include.dependencies.php

@ -0,0 +1,90 @@
<?php
$cphp_dependencies = array();
$cphp_last_dependency = "";
function cphp_dependency_provides($component, $version)
{
global $cphp_dependencies, $cphp_last_dependency;
$cphp_dependencies[$component] = $version;
$cphp_last_dependency = $component;
}
function cphp_dependency_requires($component, $version)
{
global $cphp_dependencies, $cphp_last_dependency;
if(!isset($cphp_dependencies[$component]))
{
die("The {$cphp_last_dependency} component requires the {$component} component to be loaded, but this is not the case.");
}
$current_version = $cphp_dependencies[$component];
if(!cphp_dependency_match($current_version, $version))
{
die("The {$cphp_last_dependency} component requires the {$component} component with version {$version} to be loaded, but an incompatible version ({$current_version}) was found.");
}
}
function cphp_dependency_match($available, $required)
{
if(strpos($required, ",") !== false)
{
$ranges = explode(",", $required);
}
else
{
$ranges[] = $version;
}
foreach($ranges as $range)
{
if(strpos($required, "|") !== false)
{
list($min, $max) = explode("|", $range);
$f_min = (float) $min;
$f_max = (float) $max;
$f_cur = (float) $available;
if(empty($min) && empty($max))
{
return true;
}
elseif(empty($min))
{
if($f_cur < $f_max)
{
return true;
}
else
{
return false;
}
}
elseif(empty($max))
{
if($f_cur > $f_min)
{
return true;
}
else
{
return false;
}
}
else
{
if($f_cur > $f_min && $f_cur < $f_max)
{
return true;
}
else
{
return false;
}
}
}
}
}
?>

12
cphp/include.exceptions.php

@ -0,0 +1,12 @@
<?php
if($_CPHP !== true) { die(); }
class OwnershipException extends Exception {}
class UserAccessException extends Exception {}
class NotFoundException extends Exception {}
class PrototypeException extends Exception {}
class ConstructorException extends Exception {}
class MissingDataException extends Exception {}
class DatabaseException extends Exception {}
class TypeException extends Exception {}
?>

145
cphp/include.memcache.php

@ -0,0 +1,145 @@
<?php
if($_CPHP !== true) { die(); }
if($cphp_memcache_enabled)
{
$memcache = new Memcache;
$cphp_memcache_established = $memcache->connect($cphp_memcache_server, $cphp_memcache_port);
if($cphp_memcache_established !== false)
{
$cphp_memcache_connected = true;
}
else
{
$cphp_memcache_connected = false;
}
}
function mc_get($key)
{
global $cphp_memcache_enabled, $cphp_memcache_connected, $memcache;
if($cphp_memcache_enabled === false || $cphp_memcache_connected === false)
{
return false;
}
else
{
$get_result = $memcache->get($key);
if($get_result !== false)
{
return $get_result;
}
else
{
return false;
}
}
}
function mc_set($key, $value, $expiry)
{
global $cphp_memcache_enabled, $cphp_memcache_connected, $cphp_memcache_compressed, $memcache;
if($cphp_memcache_enabled === false || $cphp_memcache_connected === false)
{
return false;
}
else
{
if($cphp_memcache_compressed === true)
{
$flag = MEMCACHE_COMPRESSED;
}
else
{
$flag = false;
}
$set_result = $memcache->set($key, $value, $flag, $expiry);
return $set_result;
}
}
function mc_delete($key)
{
global $cphp_memcache_enabled, $cphp_memcache_connected, $memcache;
if($cphp_memcache_enabled === false || $cphp_memcache_connected === false)
{
return false;
}
else
{
return $memcache->delete($key);
}
}
function mysql_query_cached($query, $expiry = 60, $key = "")
{
if($key == "")
{
$key = md5($query) . md5($query . "x");
}
if($res = mc_get($key))
{
$return_object->source = "memcache";
$return_object->data = $res;
return $return_object;
}
else
{
if($res = mysql_query($query))