From 2254cd6cf75bd1dbebea1663cf9a277f47774d23 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 6 Nov 2014 14:15:07 -0500 Subject: [PATCH] Now have most functionality working. Updated descriptions/documentation in index.php file. --- controllers/admin.php | 2 +- index.php | 53 +++++++++++++++++++++++++----- lib/smartyTemplateSupport.php | 6 ++-- models/admin/add.php | 25 +++++++++++--- models/admin/display.php | 19 ++++++----- models/admin/list.php | 24 +++++++++++--- views/admin/prototype_add.html | 18 ++++++++-- views/admin/prototype_display.html | 16 ++++++--- views/admin/prototype_list.html | 25 ++++++++++++-- 9 files changed, 148 insertions(+), 40 deletions(-) diff --git a/controllers/admin.php b/controllers/admin.php index 379f121..d1c6101 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -62,7 +62,7 @@ class glmProtoAdmin require_once(GLM_PROTO_PLUGIN_DIR.'/models/admin/display.php'); return new glmProtoAdminDisplayModel($this->wpdb); break; - + default: break; diff --git a/index.php b/index.php index a629497..b1fae7b 100644 --- a/index.php +++ b/index.php @@ -46,25 +46,62 @@ Directory and File Structure here. (See "Process Flow" below.) controllers Directory containing any controllers. Typically there - would be admin and front controllers in this directory. + would be admin and front controllers in this directory. + These controllers do the general setup for the plugin, + determine and call the appropriate model, determine the + appropriate view, then merge any data returned by the model + with the view and output the result as appropriate. + + When executed, a model may determine that it cannot handle + the current request and return such a notice to the controller + possibly with a suggested model to execute. Models may also + return a desired view back to the controller based on the + result of processing, but should do so in a generic way so + as to permit multi-lingual output and use of multiple "skins" + (but not to the exception of appropriate use of WordPress + Themes). css Directory containing any css files specific to this plugin. + The use of additional styling should be kept to a minimum + so as to not interfere with the application of WordPress + default styling and Themes. js Directory containing any JAVAscript files specific to this - Plugin. + Plugin. This directory should be reserved for general script + files that provide functionality that can be used in various + views. Any JAVAscript that is specific to a view should be + located along with the associated view as it is logically + part of the view. lib Directory containing any class or function libraries that - are used generally by this plugin. + are used generally by this plugin. Any class or other code + that is specific to a particular model should be located + in, or along with, that model since it is logically + associated only with that model. + misc Directory containing ancillary directories and files. This + might be used for things like cach directories. An example + might be the "smarty" directory for Smaarty Templates. + models Directory containing model files that execute a specific process in this plugin. If this is a simple plugin, then the model files can be placed directly in this directory. If it's a more complex plugin, then there should be sub- directories for various groupings of related model files. + An individual model may consist of a grouping of files, + such as additional class files, that are specific only to + that model. In that case, these should be located in a + subdirectory under where the model file called by the + controller is located and that directory should be named + so as to be obviously associated with that model. + There are three special files in the models directory. These are activate.php, deactivate.php, and uninstall.php. These - are call via hooks setup in this file. + are called via hooks setup in this file and should always + be here. If they do not provide any real functionality, they + should at least be a shell that can be called for those + situations. views Directory containing view files for producing output upon request of a model file in the models directory. If this @@ -76,10 +113,10 @@ Directory and File Structure It may also be wise to use separate front and admin directories under views to keep things organized. - - misc Directory containing ancillary directories and files. This - might be used for things like cach directories. An example is - the "smarty" directory for Smaarty Templates. + Additionally, views may be grouped in such a way that they + support the selection of various "skins" that output in + different ways, although any styling should be provided by + WordPress Themes or use default WordPress styling. Process Flow diff --git a/lib/smartyTemplateSupport.php b/lib/smartyTemplateSupport.php index 9ffdda2..5efb8d4 100644 --- a/lib/smartyTemplateSupport.php +++ b/lib/smartyTemplateSupport.php @@ -90,16 +90,16 @@ abstract class smartyTemplateSupport * * @return void */ - public function templateAssign($param, $value = false) + public function templateAssign($param, $value = null) { // If this is a single assignment - if ($value != false) { + if ($value !== null) { $this->template->assign($param, $value); // Otherwise it's an array of parameter/value pairs - } else { + } elseif (is_array($param)) { while (list($key, $value) = each($param)) { $this->template->assign($key, $value); diff --git a/models/admin/add.php b/models/admin/add.php index bc9b817..373e246 100644 --- a/models/admin/add.php +++ b/models/admin/add.php @@ -49,11 +49,6 @@ class glmProtoAdminAddModel extends smartyTemplateSupport public function __construct($wpdb) { - // If there's any other display operation requested, don't do this one. - if (isset($_REQUEST['glm_proto_action'])) { - return; - } - // Save WordPress Database object $this->wpdb = $wpdb; @@ -63,6 +58,10 @@ class glmProtoAdminAddModel extends smartyTemplateSupport $templateData = array( 'glm_proto_title' => '', 'glm_proto_title_error' => '', + 'glm_proto_width' => '1500', + 'glm_proto_width_error' => '', + 'glm_proto_height' => '1200', + 'glm_proto_height_error' => '', 'glm_proto_background' => '', 'glm_proto_background_error' => '', 'glm_proto_prototype' => '', @@ -78,6 +77,8 @@ class glmProtoAdminAddModel extends smartyTemplateSupport // Clean up all input $templateData['glm_proto_title'] = sanitize_text_field($_REQUEST['glm_proto_title']); + $templateData['glm_proto_width'] = sanitize_text_field($_REQUEST['glm_proto_width']); + $templateData['glm_proto_height'] = sanitize_text_field($_REQUEST['glm_proto_height']); $templateData['glm_proto_background'] = sanitize_text_field($_REQUEST['glm_proto_background']); $templateData['glm_proto_prototype'] = sanitize_text_field($_REQUEST['glm_proto_prototype']); @@ -87,6 +88,18 @@ class glmProtoAdminAddModel extends smartyTemplateSupport $submitError = true; } + // Check width field + if ($templateData['glm_proto_width'] == '') { + $templateData['glm_proto_width_error'] = 'Required width not supplied'; + $submitError = true; + } + + // Check height field + if ($templateData['glm_proto_height'] == '') { + $templateData['glm_proto_height_error'] = 'Required height not supplied'; + $submitError = true; + } + // Check background image - Not required but must exist if provided if ($templateData['glm_proto_background'] != '' && !$this->glmProtoIsUploaded($templateData['glm_proto_background']) ) @@ -119,6 +132,8 @@ class glmProtoAdminAddModel extends smartyTemplateSupport $content = serialize( array( 'title' => $templateData['glm_proto_title'], + 'width' => $templateData['glm_proto_width'], + 'height' => $templateData['glm_proto_height'], 'background' => $templateData['glm_proto_background'], 'prototype' => $templateData['glm_proto_prototype'] ) diff --git a/models/admin/display.php b/models/admin/display.php index 9597c26..d9a050b 100644 --- a/models/admin/display.php +++ b/models/admin/display.php @@ -58,26 +58,29 @@ class glmProtoAdminDisplayModel extends smartyTemplateSupport FROM wp_posts WHERE post_type = 'glm_proto' AND id = $id - "); -var_dump($res); + ", ARRAY_A ); + // If we have results - if (is_array($res) && count($res) > 0) { - + + if ($res['post_content']) { + // Break out the prototype file data $d = unserialize($res['post_content']); - + $res['content'] = $d; + } - - - } + $this->templateAssign($res); + + } // Select view $this->templateFile = 'admin/prototype_display.html'; // Output our template results $this->template->display($this->templateFile); + exit; } diff --git a/models/admin/list.php b/models/admin/list.php index b39e63b..9ea18c1 100644 --- a/models/admin/list.php +++ b/models/admin/list.php @@ -52,11 +52,24 @@ class glmProtoAdminListModel extends smartyTemplateSupport // Get a current list of prototypes $list = $this->getList(); + + // If we have list entries + if ($list) { + + // Expand content array in case we need it + while (list($key, $value) = each($list)) { + $list[$key]['content'] = unserialize($value['post_content']); + } + + // Add data to templates + $this->templateAssign('haveList', true); + $this->templateAssign('prototypes', $list); + + } else { + $this->templateAssign('haveList', false); + } - // Clean up - - // Add template parameters - $this->templateAssign('prototypes', $list); + // Also add the current request URI to use for links back for display $this->templateAssign('request_uri', $_SERVER['REQUEST_URI']); // Select view @@ -79,7 +92,8 @@ class glmProtoAdminListModel extends smartyTemplateSupport $res = $this->wpdb->get_results( " SELECT id, DATE_FORMAT(post_date, '%Y-%m-%d') p_date, - post_title + post_title, + post_content FROM wp_posts WHERE post_type = 'glm_proto' ORDER BY post_date, post_title diff --git a/views/admin/prototype_add.html b/views/admin/prototype_add.html index 7224591..a9e990b 100644 --- a/views/admin/prototype_add.html +++ b/views/admin/prototype_add.html @@ -3,9 +3,8 @@

Add a New Prototype

- - +
+ + + + + + + +
@@ -13,6 +12,20 @@ {if $glm_proto_title_error != ''}
{$glm_proto_title_error}{/if}
+ + {if $glm_proto_width_error != ''}
{$glm_proto_width_error}{/if} +
+ + {if $glm_proto_height_error != ''}
{$glm_proto_height_error}{/if} +
@@ -34,7 +47,6 @@
-

* Required

diff --git a/views/admin/prototype_display.html b/views/admin/prototype_display.html index 1ed7e5a..273a109 100644 --- a/views/admin/prototype_display.html +++ b/views/admin/prototype_display.html @@ -1,5 +1,11 @@ -
- -

Display Prototype

- -
+ + + + Prototype: {$content.title} + + + +
+
+ + diff --git a/views/admin/prototype_list.html b/views/admin/prototype_list.html index 002ec3c..60ed29e 100644 --- a/views/admin/prototype_list.html +++ b/views/admin/prototype_list.html @@ -1,3 +1,11 @@ +

List of Prototypes

@@ -6,17 +14,30 @@ Date - Prototype Name + Prototype Name +   +{if $haveList} {foreach $prototypes as $p} {$p.p_date} - {$p.post_title} + {$p.post_title} + + View + Edit + Delete + {/foreach} +{else} + (no prototypes listed) +{/if}
+ -- 2.17.1