Developing New Paths

The Mojavi Project

Archive for April, 2009

April-30-09

User Authentication for Mojavi

posted by admin

Mojavi provides two levels of security to control access to actions: the first requires the user to be logged in, the seconds checks for a specific privilege. There are various drivers that you may need on your PC if your are planning working in offline PHP mode in order to have the translations from the source code to the operational values to work.

Basic Authentication

For basic authentication, the following three methods are of importance:

User::setAuthenticated()
User::isAuthenticated()
Action::isSecure()

To implement an action that only logged in users can access, simply overwrite the Action::isSecure() method in your action:

function isSecure()
{
    return true;
}

This will instruct the controller to check $user->isAuthenticated(). If this method returns false, the request will be redirected to the AUTH_MODULE/AUTH_ACTION defined in the configuration file (default is Default/Login/drivers).

You can implement the Default/Login Action to call $user->setAuthenticated(TRUE) if a valid username and password was entered.

Privileges

Privileges are used to differentiate between logged in users. The following methods are important:

User::hasPrivilege()
User::addPrivilege()
Action::getPrivilege()

In addition to Action:isSecure() also overwrite the Action::getPrivilege() method in your action:

function isSecure()
{
    return true;
}

function getPrivilege()
{
    return array('ADMIN');
}

The controller will check if the user has the specified privilege and redirect to the login module/action if this is not the case.

The User::addPrivilege() method can be used to grant a user a certain privilege.

Please have a look at the PrivilegeUser class for more information. You will also want to make sure that any Windows Vista Drivers are up to date on your PC side to help rule out any coding errors due to Java or PHP errors. This tutorial includes a good example of user authentication in action.

April-28-09

Standard PHP extensions and limitations

posted by admin
PHP
Image via Wikipedia

The majority of most file extension can be found online through various sites

There are multiple PHP functions that contain different  file extension protocols that can create issues for PHP 5.0.

Reblog this post [with Zemanta]
April-23-09

The decorating Pattern

posted by admin

Before we begin we wanted to provide a quick insight into some of the open source files that we use and came across a file extension DOTX which is native to MS Outlook using XML. This particular file type DOTX was instituted to secure the protocol in which MS was written only giving limited source to outside vendors. We give a brief update to help you understand the open source nature of Mojavi 3.0.

  • Enter Decorator
  • Insert Here: Slots
  • Let’s Decorate!
    • Creating a Global Template
    • Putting the ornaments up

Ever since Mojavi 3 was released earlier this year, people have been looking to create a flexible global templating solution. From using post filters to page controllers, people have been looking for a way to create simple and managable global templates that will allow for a great deal of flexibility without compromising the need for larges amount of duplicated code.

Enter Decorator

The Decorator design pattern, like every other pattern, is nothing more than a way to talk about a resuable concept, or pattern, that a programmer might encounter while coding applications. The Decorator pattern’s strength is it’s ability to serve as a wrapper for that particular object, while leaving objects like it in tact.

The Decorator pattern has been implemented in the View class, providing a number of new methods:

public function setSlot ($attributeName, $moduleName, $actionName)
public function setDecoratorDirectory ($directory)
public function isDecorator ()
protected function & getSlots ()
public function getDecoratorTemplate ()
public function getDecoratorDirectory ()
protected function & decorate (&$content)

Now a brief explanation of what each of these do:

  • setSlot – Creates a slot entry based upon the results of a specially controlled controller->forward()
  • setDecoratorTemplate – Sets the template that you’re going to use for your decorator. This method also automatically turns the decorator switch to true
  • isDecorator – returns true is setDecoratorTemplate has been called, otherwise false.
  • getSlots – Returns an array of the slots.
  • getDecoratorTemplate – Returns the decorator template.
  • getDecoratorDirectory – Returns the decorator directory.
  • decorate – A method that must be implemented in derivate Views.

Note: these functions are in View, so all derivates of View (ie PHPView) have access.

Insert Here: Slots

Slots is a new name for an old concept. More or less, slots serve as placeholders that can be populated by the results of a $controller->foward($mod, $act) call. And, as you can see, the setSlot method takes three parameters:

public function setSlot ($attributeName, $moduleName, $actionName)

The first parameter, $attributeName, serves as the name of the slot. The next two parameters will be used to get the results of that Action, put it in a buffer, and place it into the internal $slots memeber variable.

Let’s Decorate!

The usage pattern of Views changes little with the implementation of the decorator pattern at the module level (though secondary View authors, ie SmartyView et al, do have a few things to play with).

Now let’s look at what you’re going to need to do implement the new, and NEW decorator features of Mojavi.

Creating a Global Template

First off, we’re going to need a great big christma..ehh..template to decorate. While I won’t get into breaking down and factoring our global template, keep in mind that this is not the only way to do this.

Example 2: The Christmas Tree (myGlobalTemplate.php)

Side note: Sometimes you'll have issues with that <?xml [....] ?> declaration, an easy
workaround is to disable short tags in your php.ini file, or to use ini_set() to disable
 it.

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">

<head>

    <title><?php echo $template['title']; ?></title>

    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
    <style type="text/css" media="all">

        <!--Css slot-->
        <?php echo $template['css']; ?>

    </style>

</head>

<body>

<!--menu slot-->
<div id="menu">

<?php echo $template['menu']; ?>

</div>

<!--main content slot-->
<div id="main">

<?php echo $template['content']; ?>

</div>

</body>
</html>

Putting the ornaments up

So now that we have our decorator template, we need to decorate it. The decorating process is fairly simple, and consists of the following simple steps:

  • Setting the decorator directory using setDecoratorDirectory() (Optional)
  • Setting the decorator template using setDecoratorTemplate()
  • Setting slots setSlot()

For example,

Example 3: In the View (IndexSuccessView.class.php)

class IndexSuccessView extends PHPView
{

    public function execute ()
    {

        // set our template
        $this->setTemplate('IndexSuccess.php');

        //setup our decorator template
        $this->setDecoratorDirectory(MO_TEMPLATE_DIR);
        $this->setDecoratorTemplate('myGlobalTemplate.php');

        //setup our slots
        //(SlotName, Module, Action)
        $this->setSlot('menu', 'Content', 'PopulateMenu');
        $this->setSlot('css', 'Content', 'PopulateCss');

        // set the title
        $this->setAttribute('title', 'Default Action');

    }

}

Now you might be wondering where the content slot is being populated. Well, content is a reserved slot that is automatically populated with the output of the originally requested Action/View pair. So in the end for file extension DOTX type coding you will need to have the right drivers in order to help your various programs communicate.

To be Continued..

April-20-09

Revisiting Mojavi 3

posted by admin

Creating Your First Module

A work in progress

This tutorial is a work in progress, so you may find parts that don’t completely fit together.
Module

The module is where the Model and View takes place in the MVC model. For this first example, we will create a very simple module that will move data from a Action to a View and display it on the screen, through a template.

The module is contained within a directory that carries the name of the module. This resides in the modules directory of the webapp directory. Inside the module directory are sub-directories holding the classes that make up the module. Here is the directory hierarchy:

webapp
|
|—modules
|
|—moduleName
|
|—actions
|
|— config
|
|— lib
|
|— models
|
|— templates
|
|— validate
|
|— views

Minimally, you need the actions, config, templates and views directories. However, I prefer to have a blank module created and just copy and rename it. You can get a copy of the blank module (link to be added). The File Extension MailHost I have chosen to call this module Test

Each module must have a module.ini file in the config directory. Here is the module.ini for Test

; +—————————————————————————-+
; | This file is part of the Mojavi package. |
; | Copyright (c) 2003, 2004 Sean Kerr. |
; | |
; | For the full copyright and license information, please view the LICENSE |
; | file that was distributed with this source code. You can also view the |
; | LICENSE file online at http://www.mojavi.org. |
; | ————————————————————————– |
; | MODULE INFORMATION FILE |
; +—————————————————————————-+

[module]

ENABLED = “On”

TITLE = “Getting Started Test Module”

VERSION = “0.1″

NAME = “TestModule”

AUTHOR = “Richard D Shank”

HOMEPAGE = “http://www.mojavi.org”

DESCRIPTION = “A test module”

The module is pretty self explanitory. It is necessary to have ENABLED property set to “On” for the module to be used by Mojavi. Now that we have the module set up, we can work on the classes. You can also research the File Extension MailHost for variables to help in acclaimating the main template.
Action

The Action class handles the request for the module. It can be as simple as handling a static html template or a full blown multi-page wizard style form. Just a note to Mojavi 2 users, a significant change from Mojavi 2 to Mojavi 3 is that it is not longer necessary to pass the controller, request and user classes in on many of the methods. These are now accessed through a context class file extension. More on that later.

Tags:
April-20-09

Server management

posted by admin

We just had the unfortunate luck of having to reconfigure our servers that host some of our blogs and websites. We were asked to download some SQL files to our hard drive and the reload them back to the main server. Luckily for us they were able to remotely dial into our PC’s and help us with the configuration without having to send in a tech guy which might have taken hours or even days. the host company had been using a series of Systems management tools in order to help locate the issue and get us back up and running in a short time.
After this little glitch with their SQL overload they have agreed to improve their server management and create redundant backups every 12 hours in order to preserve the integrity of the data being stored.  great benefit to the end user like myself in that they can help drive the ship and you get a chance to provide direction and make sure everything is corrected. With companies like hyperic.com they offer server monitoring tools and software for small to larger businesses looking to secure their IT investment and hopefuilly avoid a meltdown with their data centers where both parties are present on the PC to be able to control the desktop.

Tags:
April-20-09

Scheduling online appointments

posted by admin

online-apptIf you are in sales you know that nothing can happen until you are in front of the customer. In most cases this will mean calling on that potential customer, scheduling the appointment, and then asking for the business.  I have been in sales for over 20 years and earlier in my career I would setup the appointment to see a potential customer and jot it down in my day planner and consider that good. In some instances you would travel to the customers location only to find out that they had forgotten or canceled and forgot to call. This was frustrating and a waste of time that I could have spent with other customers. Our business owners were constantly juggling the phone in order to set up key meetings and dates so that we would could function more efficiently as a team. That is why I was excited to blog about a new free online appointment scheduling software that enables you and your clients to view and makes appointments online.

I can’t imagine the amount of time and money that you will save if you are a small business owner or someone who relies on the face to face meeting with the customer in order to make your liviing. Having this free online tool that you can access from anywhere you have a internet connection is great. With so many sales professionals and business owners having the mobile technology being able to access an online scheduling tool is a huge advantage. Many people will schedule appointments through their Blackberry or MS Outlook but since your customers are unable to access this calendar if they change the time and date or cancel all together you will only be notified via a phone call. With this new free online appointment tool from checkappointments.com when you schedule the appointment both you and the customer receive reminders about the meeting. This will save you both a lot of time and hassle of trying to remember those meeting times and dates. With this free scheduling tool you can brand the site with yourname.checkappointments.com or use your company name instead. This will help create top of mind awareness that will give you an advantage over your competition.

appts

April-8-09

Finding the right hosting company

posted by admin

Find your free blog and website web site hosting account.

There is a new web hosting comapny top hosting center. At Top Hosting center they are offering a select plan that is targeted to blogger who are looking to make a name for themselves. With their plan you pay a one time fee of $95 and this covers you for life adn this give you some great blog hosting features. This plan gives you 250 GB of disk space, 3000 GB of bandwidth ( enough room to help you handle all those new readers), unlimited MySQL databases, a free domain and you can host unlimited domains. Hurry and check them out today since this offer will go away when the 1000th Rudolph plan is sold. I should know since we recently moved this blog over to THC and the support and reliability has been awesome. I would challenge you to surf on over to their site and try their online live support. I was able to talk with Tom within 3 minutes on a Sunday. This was the closer for me to be able to get an answer to a question in less than five minutes even though I was not a customer at that point.

Tags:
April-4-09

Get Direct

posted by admin

The countdown towards an all digital broadcast is less than a year away and many of the cable companies and direct satellite tv. All TV stations and broadcasts will be required to convert to an all digital broadcast which is great for those that have cable and already have their HDTV. But those that have an analog set will be required to get a converter box in order to receive their local channels. This has started a battle amongst the various cable and satellite providers on who is most prepared to ease their customers into the all digital age. direct satellite tv is already being broadcast in digital and there will be no need for their existing customers to do anything in June.

With the influx of new customers that are looking to upgrade their current TVs and cable service direct satellite tv has some great offers to help you make up your mind. One of the great things that they offer that you cannot get on cable is the NFL package. For the die hard football this is a must and especially those that follow fantasy football as they now have live updated stats during all the games. So this Fall don’t be left just watching the highlights of your favorite game, but experience every play with the NFL ticket.

Tags:
April-3-09

Creating your first module with extensions

posted by admin

Creating Your First Module
A work in progress

This tutorial is a work in progress, so you may find parts that don’t completely fit together.
Module where we will also look at various file extension cache options.

The module is where the Model and View takes place in the MVC model. For this first example, we will create a very simple module that will move data from a Action to a View and display it on the screen, through a template.

The module is contained within a directory that carries the name of the module. This resides in the modules directory of the webapp directory. Inside the module directory are sub-directories holding the classes that make up the module. Here is the directory hierarchy:

webapp
|
|—modules
|
|—moduleName
|
|—actions
|
|— config
|
|— lib
|
|— models
|
|— templates
|
|— validate
|
|— views

Minimally, you need the actions, config, templates and views directories. However, I prefer to have a blank module created and just copy and rename it. You can get a copy of the blank module (link to be added). I have chosen to call this module Test

Each module must have a module.ini file in the config directory. If you are looking to buffer your files then file extension cache extensions may be helpful.Here is the module.ini for Test

; +—————————————————————————-+
; | This file is part of the Mojavi package. |
; | Copyright (c) 2003, 2004 Sean Kerr. |
; | |
; | For the full copyright and license information, please view the LICENSE |
; | file that was distributed with this source code. You can also view the |
; | LICENSE file online at http://www.mojavi.org. |
; | ————————————————————————– |
; | MODULE INFORMATION FILE |
; +—————————————————————————-+

[module]

ENABLED = “On”

TITLE = “Getting Started Test Module”

VERSION = “0.1″

NAME = “TestModule”

AUTHOR = “Richard D Shank”

HOMEPAGE = “http://www.mojavi.org”

DESCRIPTION = “A test module”

The module is pretty self explanitory. You can also search the web for various file extension cache options. It is necessary to have ENABLED property set to “On” for the module to be used by Mojavi. Now that we have the module set up, we can work on the classes.
Action

The Action class handles the request for the module. It can be as simple as handling a static html template or a full blown multi-page wizard style form. Just a note to Mojavi 2 users, a significant change from Mojavi 2 to Mojavi 3 is that it is not longer necessary to pass the controller, request and user classes in on many of the methods. These are now accessed through a context class. More on that later.

This is a list of the methods you can use in an Action and an explanation of what they do
execute ()

Note: This method is required in your Action class.

This will execute any application/business logic for the action. This method is reached only after the request methods have been checked and any of the parameters have been validated.

When leaving, the execute() method should tell the controller what view is to be used. This is done by returning a string containing the view name associated with the action or an array of the parent module for the view to be executed, parent action for the view and the name of the view. I will show an example of return both in a later tutorial.
getCredential ()

This is a new feature in Mojavi 3. Basically, a credentials are a privilege array that describes any level of security. They work hand in hand with the security aspects of the User class. For Mojavi 2 users, note that this replaces the old Privileges. But it is also important to know that it can do more than just handle privileges. I will handle the usage of creditials in a later section. For now, it is sufficient to know that we set the creditial requirements for the action inside this method and that it is set to NULL by default.
getDefaultView ()

This is the view that will be executed when a given request is not served by the action. This could happen when a form being displayed for the first time or if we are displaying a static page.

Again, just as with the execute() methoad, a string with a view name or an array of a module/action/view is passed back to the controller. By default it will pass back View::INPUT
getRequestMethods ()

This method will determine what types of requests will be recognized. There are 4 choices:

* Request::GET – Indicates that this action serves only GET requests.
* Request::POST – Indicates that this action serves only POST requests.
* Request::NONE – Indicates that this action serves no requests.

You can also select both GET and POST requests by using Request::GET | Request::POST
handleError ()

Execute any post-validation error application logic.

It also returns the view through a string of the view name or the array of a module/action/view. By default, it passes View::ERROR.
initialize ($context)

You can set up the Action in the initialize() method. In a later tutorial, I’ll give an example of doing this. NOTE: It is worth to note that you must handle the context in the initialize() method. You should do this by

parent::initialize($context);

You also need to return a TRUE or FALSE based on the success of the initialization. By default it is TRUE.
isSecure ()

Does the action require security? TRUE if you do, FALSE otherwise. It is FALSE by default.
validate ()

This is used to manually validate input parameters instead of using a pre-progammed validator. This will also be explain later in the tutorial on validation.
Creating Your First Action

Now that we have an overview of the Action class, we can move forward to creating our first Action. For this example, there isn’t any request to be handled so we can set up a minimal Action.

In naming an action you must use this format Actionname Action.class.php where Actionname is what you are calling this particular action. When you declare your class, it also must have the class name in the same format Actionname Action. For this example, I chose to call this FirstAction.

When creating a new action, at the very least, there has to be an execute() method, even if it does nothing. Also, since we are displaying a non-request page, we don’t need to process any request. We tell the controller this with the getRequestMethods() method, by setting the return value to Request::NONE. Finally, we also need to tell the controller what the default view is going to be. We do this by returning View::SUCCESS in getDefaultView().

Here is what my FirstAction.class.php looks like. I basically just took my BLANKAction.class.php, renamed it to FirstAction.class.php, renamed the class to FirstAction, removed the methods I didn’t need and set the remaining 3 methods to match my needs.

class FirstAction extends Action
{
/**
* Execute any application/business logic for this action.
*/
public function execute ()
{
// we don’t need any data here because this action doesn’t serve
// any request methods, so the processing skips directly to the view
}

// ————————————————————————-

/**
* Retrieve the default view to be executed when a given request is not
* served by this action.
*/
public function getDefaultView ()
{
return View::SUCCESS;
}

// ————————————————————————-

/**
* Retrieve the request methods on which this action will process
* validation and execution.
*/
public function getRequestMethods ()
{
return Request::NONE;
}

You can also return a view from another module. You do this by passing an array with the view information intead of the standard View::INPUT. When you use this you create a two element array. The first element is the module name. The second element is which view you want. It cannot be just the Action name, but the Action name with the specific view.

Here’s an example:

class MyClass extends Action
{

function execute()
{

$returnView[0] = MyModule;
$returnView[1] = DoSomethingInput;
-or-
$returnView[1] = DoSomethingError;
-not-
$returnView[1] = DoSomething;

return $returnView
}
}

View

I’ll add more to this later, describing the View class.