Permalink
Browse files

added a module structure

  • Loading branch information...
1 parent 15f1614 commit 4164139a0fc685587a196a0373fc3e6bce4e07c7 @xcaww committed Mar 18, 2011
View
@@ -17,10 +17,18 @@ function database_query($databaseQuery){
function generate_page($URL_page, $URL_query, $URL_i = false){
- require("./engine/gen/gen_page.php");
+ require("./engine/page.php");
$pageGen = new generatePage($URL_page, $URL_query, $URL_i);
}
+
+ function call_module($module){
+
+ require("./engine/module/" . $module['moduleName'] . "/" . $module['moduleName'] . ".php");
+ $this->module = new module($module);
+ return $this->module->process_module();
+
+ }
function execution_time(){
View
@@ -0,0 +1,40 @@
+<?php
+
+class database extends core{
+
+ function connect_database(){
+
+ $this->connectionLink = mysql_connect("localhost", "root", "rscbU");
+
+ if($this->connectionLink){
+
+ mysql_select_db("oskarr");
+
+ }else{
+
+ parent::send_error_log("Could not create a connection the to database");
+
+ }
+
+ }
+
+ function query($databaseQuery){
+
+ $query = mysql_query($databaseQuery);
+
+ if(!$query){
+
+ $errorMessage = (string) "query: " . mysql_error();
+ parent::send_error_log($errorMessage);
+
+ }else{
+
+ return $query;
+
+ }
+
+ }
+
+}
+
+
@@ -0,0 +1,69 @@
+<?php
+
+class module extends core{
+
+ function __construct($module){
+
+ $this->moduleData = $module;
+
+ }
+
+ function get_statistics($statistic){
+
+ $statisticResult = false;
+
+ switch ($statistic){
+
+ case "posts":
+
+ break;
+ case "channels":
+
+ $result = parent::database_query("
+ SELECT id
+ FROM channels
+ ");
+
+ if(mysql_num_rows($result)){
+
+ $statisticResult = (string) mysql_num_rows($result);
+
+ }
+
+ break;
+ default:
+ parent::send_error_log("module error: failed statistic selection");
+ break;
+
+ }
+
+ if($statisticResult != false){
+
+ return $statisticResult;
+
+ }else{
+
+ parent::send_error_log("module error: failed statistic data");
+
+ }
+
+ }
+
+ function process_module(){
+
+ parent::database_connect();
+ $query = explode(", ", $this->moduleData['moduleQuery']);
+
+ foreach($query as $statistic){
+
+ $this->returnedData[$statistic] = $this->get_statistics($statistic);
+
+ }
+
+ return $this->returnedData;
+
+ }
+
+}
+
+?>
View
@@ -0,0 +1,94 @@
+<?php
+
+class generatePage extends core{
+
+ function __construct($pageIdentifier, $pageQuery, $pageNumber){
+
+ $this->page = $pageIdentifier;
+ $this->query = $pageQuery;
+
+ if($pageNumber != false){
+
+ $this->number = $pageNumber;
+
+ }else{
+
+ $this->number = false;
+
+ }
+
+ parent::database_connect();
+ $this->validate_query();
+ $this->find_page();
+ $this->generate_page();
+
+ }
+
+ function validate_query(){
+
+ if(ctype_alnum($this->page) == true && ctype_alnum($this->query) == true && strlen($this->page) < 33 && strlen($this->query) < 57){
+
+ return true;
+
+ }else{
+
+ parent::send_error_log("bad page query: " . $this->page . "?" . $this->query . " -> " . $this->number);
+
+ }
+
+ }
+
+ function find_page(){
+
+ if(ctype_digit($this->page)){
+
+ $result = parent::database_query("
+ SELECT *
+ FROM pages
+ WHERE id = '" . $this->page . "'
+ ");
+
+ }elseif(ctype_alnum($this->page)){
+
+ $result = parent::database_query("
+ SELECT *
+ FROM pages
+ WHERE address = '" . $this->page . "'
+ ");
+
+ }else{
+
+ parent::send_error_log("bad page request: " . $this->page . "?" . $this->query);
+
+ }
+
+ while($row = mysql_fetch_array($result)){
+
+ $this->pageDetails['id'] = $row['id'];
+ $this->pageDetails['name'] = $row['name'];
+ $this->pageDetails['address'] = $row['address'];
+
+ }
+
+ if(!isset($this->pageDetails)){
+
+ parent::send_error_log("could not find page: " . $this->page . "?" . $this->query);
+
+ }
+
+ $this->pageDetails['query'] = $this->query;
+ $this->pageDetails['number'] = $this->number;
+ return true;
+
+ }
+
+ function generate_page(){
+
+ require("./engine/page/page_producer.php");
+ $producer = new pageProducer($this->pageDetails, $this->query);
+
+ }
+
+}
+
+?>
@@ -6,7 +6,7 @@ function __construct($channel, $page){
parent::database_connect();
$this->pageNumber = $page;
- $this->limitLength = "2";
+ $this->limitLength = "10";
$this->channel = parent::get_channel($channel, false);
$this->eval_max_pages();
$this->eval_limits();
@@ -16,7 +16,7 @@ function __construct($channel, $page){
function eval_max_pages(){
$result = parent::database_query("
- SELECT *
+ SELECT id
FROM posts
WHERE channel = '" . $this->channel['id'] . "' AND identifier = 'thread'
");
@@ -11,9 +11,11 @@ function __construct($pageDetails){
function construct_data(){
+
$this->arrayItems['template'] = "main_index.php";
$this->arrayItems['styles'] = "main_index.css";
$this->arrayItems['channels'] = $this->channels->get_channels();
+ $this->arrayItems['statistics'] = $this->channels->get_channel_statistics();
return $this->arrayItems;
@@ -8,6 +8,14 @@ function __construct(){
}
+ function get_channel_statistics(){
+
+ $module['moduleName'] = "statistics";
+ $module['moduleQuery'] = "channels"; //statistics pattern example: "channels, posts, most_active_channel" will be handled by a switch case that determines the result for the string piece given -> explode(", " $query)
+ return parent::call_module($module);
+
+ }
+
function get_channels(){
$result = parent::database_query("
@@ -6,16 +6,25 @@ font-family:Consolas;
font-size:12.5pt;
color:#FFF;
margin-bottom:25px;
-padding: 3px 5px;
+padding: 0;
height: 23px;
width: 100%;
}
+#channel_stats {
+background-color: #FFF;
+font-size:9pt;
+text-align: right;
+margin: 0;
+padding-right: 1px;
+color: #bfbfbf;
+}
+
#channel_list {
background-color: #e1e1e1;
width:100%;
vertical-align:text-top;
-padding: 5px;
+padding: 0;
}
#channel_list p {
@@ -24,6 +33,7 @@ font-size:11pt;
color:#000;
text-align: left;
line-height: 2;
+padding: 5px;
}
#channel_list a {
@@ -13,18 +13,37 @@
*/
function build_page($pageData){
-
+
echo "<link href=\".\engine\page\\{$pageData['pageAddress']}\product\\{$pageData['styles']}\" rel=\"stylesheet\" type=\"text/css\" />
<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"> <!-- Post Table -->
-
+
<tr>
- <td style=\"text-align: center; vertical-align: top; width: 600px;\"> <!-- Title & Post -->
+ <td style=\"text-align: center; vertical-align: top; width: 600px;\"> <!-- Title -->
<div id=\"channel_title\">
<span>Channels</span>
- </div>
+ </div>
+
+ </td>
+
+ </tr>
+
+ <tr>
+
+ <td>
+
+ <div id=\"channel_stats\">
+ <span>{$pageData['statistics']['channels']} Channels</span>
+ </div>
+
+ </td>
+
+ <tr>
+
+ <td style=\"text-align: center; vertical-align: top; width: 600px;\">
+
<div id=\"channel_list\">
<p>";
View
@@ -21,7 +21,7 @@
//load core function library + logger
require("./engine/core.php");
-require("./engine/database.class.php");
+require("./engine/database.php");
//Let's roll...
$core = new core();

0 comments on commit 4164139

Please sign in to comment.