Now have most functionality working. Updated descriptions/documentation in index...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 6 Nov 2014 19:15:07 +0000 (14:15 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 6 Nov 2014 19:15:07 +0000 (14:15 -0500)
controllers/admin.php
index.php
lib/smartyTemplateSupport.php
models/admin/add.php
models/admin/display.php
models/admin/list.php
views/admin/prototype_add.html
views/admin/prototype_display.html
views/admin/prototype_list.html

index 379f121..d1c6101 100644 (file)
@@ -62,7 +62,7 @@ class glmProtoAdmin
                                        require_once(GLM_PROTO_PLUGIN_DIR.'/models/admin/display.php');
                                        return new glmProtoAdminDisplayModel($this->wpdb);
                                        break;
-                                               
+                                       
                                default:
                                        break;
                                                
index a629497..b1fae7b 100644 (file)
--- 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
 
index 9ffdda2..5efb8d4 100644 (file)
@@ -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);
index bc9b817..373e246 100644 (file)
@@ -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']
                                        )
index 9597c26..d9a050b 100644 (file)
@@ -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;
                
        }
 
index b39e63b..9ea18c1 100644 (file)
@@ -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
index 7224591..a9e990b 100644 (file)
@@ -3,9 +3,8 @@
        <h2>Add a New Prototype</h2>
 
        <form action="{$request_uri}" method="post" enctype="multipart/form-data">
-       
-               <table class="form-table">
                <input type="hidden" name="glm_proto_action" value="add_submit">
+               <table class="form-table">
                        <tr>
                                <th scope="row"><label for="glm_proto_title">Title for this Prototype <span class="glm-proto-required">*</span></label></th>
                                <td>
                                        {if $glm_proto_title_error != ''}<br><span class="glm-proto-error">{$glm_proto_title_error}</span>{/if}
                                </td>
                        </tr>
+                       <tr>
+                               <th scope="row"><label for="glm_proto_width">Desired initial display width<span class="glm-proto-required">*</span></label></th>
+                               <td>
+                                       <input name="glm_proto_width" type="text" id="glm_proto_width" value="{$glm_proto_width}" class="regular-text" style="width: 4em;" />
+                                       {if $glm_proto_width_error != ''}<br><span class="glm-proto-error">{$glm_proto_width_error}</span>{/if}
+                               </td>
+                       </tr>
+                       <tr>
+                               <th scope="row"><label for="glm_proto_height">Desired initial display height<span class="glm-proto-required">*</span></label></th>
+                               <td>
+                                       <input name="glm_proto_height" type="text" id="glm_proto_height" value="{$glm_proto_height}" class="regular-text" style="width: 4em;" />
+                                       {if $glm_proto_height_error != ''}<br><span class="glm-proto-error">{$glm_proto_height_error}</span>{/if}
+                               </td>
+                       </tr>
                        <tr>
                                <th scope="row"><label for="glm_proto_background">Prototype Background</label></th>
                                <td>
@@ -34,7 +47,6 @@
                                <td><input type="submit" name="Submit" value="Add this template" class="button-primary"></td>
                        </tr>
                </table>
-                               
                <p><span class="glm-proto-required">*</span> Required</p>
        </form>
        
index 1ed7e5a..273a109 100644 (file)
@@ -1,5 +1,11 @@
-<div class="wrap">
-
-       <h2>Display Prototype</h2>
-
-</div>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+       <head>
+               <title>Prototype: {$content.title}</title>
+               <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+       </head>
+       <body style="margin:0;padding:0; background: #e7e7df;">      
+               <div style="min-width:1400px;min-height:2500px; background: url({$content.prototype}) top center no-repeat; z-index: 10;"></div>
+               <div style="min-width:100%;min-height:784px; background: url($content.background) top left repeat-x; position: absolute; top: 0; z-index: -1;"></div>
+       </body>
+</html>
index 002ec3c..60ed29e 100644 (file)
@@ -1,3 +1,11 @@
+<script type="text/javascript">
+       function dispProtoWindow(url, w, h)
+       {
+               var disp_setting="toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=" + w + ", height=" + h + ", left=100, top=25";
+               window.open(url,"emDebugWindowFront",disp_setting);
+               return false;
+       }
+</script>
 <div class="wrap">
        
        <h2>List of Prototypes</h2>
                <thead>
                <tr>
                        <th>Date</th>
-                       <th style="width: 75%">Prototype Name</th>
+                       <th>Prototype Name</th>
+                       <th>&nbsp;</th>
                </tr>
                </thead>
                <tbody>
+{if $haveList}
        {foreach $prototypes as $p}
                        <tr>
                        <td>{$p.p_date}</td>
-                       <td><a href="{$request_uri}&glm_proto_action=display&proto_id={$p.id}" value="add_submit"">{$p.post_title}</a></td>
+                       <td>{$p.post_title}</td>
+                       <td>
+                               <a href="{$request_uri}&glm_proto_action=display&proto_id={$p.id}" name="Edit" class="button-primary"
+                                       onClick="dispProtoWindow('{$request_uri}&glm_proto_action=display&proto_id={$p.id}', {$p.content.width}, {$p.content.height}); return false;"
+                               >View</a>
+                               <a href="{$request_uri}&glm_proto_action=edit&proto_id={$p.id}" name="Edit" class="button-primary">Edit</a>
+                               <a href="{$request_uri}&glm_proto_action=delete&proto_id={$p.id}" name="Edit" class="button-primary">Delete</a>
+                       </td>
                        </tr>
        {/foreach}
+{else}
+                       <tr><td colspan="2">(no prototypes listed)</td></tr>
+{/if}
                </tbody>
        </table>
 
 </div>
+