You are browsing the archive for web development.

PyroCMS Widget Creation for Affiliate Marketing – Section 1

8:51 AM in CSS, Frameworks, jQuery, PHP, Programming, PyroCMS by Vic Russell


PyroCMS is a very powerful and capable PHP-based CMS.  It is authored on top of the Codeigniter framework.  It is very fast, and scalable and very promising as a powerful PHP framework.

Download the affiliate.zip file here

Caveat: The documentation for PyroCMS (PCMS) is very sparse.  Any answer to any question can be exceedingly  difficult to find.  Check back often for additional links to developing documentation.

One of the new and useful features of PyroCMS is the addition of Widgets.  Now, we all know what a widget is, right?  Actually, in the PCMS world, the concept of widget is very accurate – it is a discrete entity (in this case, a class) that can be added to a page, section of a page (right sidebar, left sidebar, header, footer, content, etc) that can access the database as well as execute custom code and present content that you create, in a format you define. You can use this to display images, text, and any other content you decide is needed – EXCEPT for JavaScript.

Let me clarify the javascript problem: if you want to create a widget that allows you to enter javascript snippets, it will not work – the <script> tags as well as any document.write() methods are stripped out for security reasons and replaced with [removed].  I am searching for a workaround, but given the above statement regarding documentation, this might take some time.  [ note: The feature within the Codeigniter (CI) form_helper class that sanitizes strings is xss_clean and prep_for_form ]. Until then, I am adding the needed JavaScript in the class and view files.

There are adequate installation documentation and install examples on the web for installing PyroCMS and Codeigniter.  Here are a couple.

PyroCMS Installation

Installing Codeigniter (this is link is provided only for reference - you do not need to download and install CI as PyroCMS is built on top of CI)

It is critical that you define your database connection accurately, and remember your default user name and password.

Our Platform

I am using a Dell laptop with 2 GB of RAM and a dual core Athlon X2 processor (circa 2006) with WAMP (Windows Apache MySQL PHP) installed for development, PHP Designer 7 as the IDE (Eclipse is too heavy, but would work with a more powerful machine).  WAMP is a very easy install.

All of my web files are under C:\wamp\www\ - which is the default web root for a typical WAMP installation.

Lets create a widget in PyroCMS - 'affiliate'

There is no widget named affiliate that comes with your installation.  Therefore, any reference to a file or folder/directory implies you have added it or should add it.

Navigate to the widgets directory under the application directory

  • (note: I am a Linux developer first - some of my paths will have the forward Unix-style slash ( / ) rather than the backwards Windows-style slash ( \ ).  Make adjustments where needed if I forget to use Windows style slashes)

C:\wamp\www\pyrocms_directory\application\widgets\affiliate

First, create the directory within the ...\widgets\ path called affiliate.

PyroCMS Widget Directory Structure - randaweb

Widget Directory Structure

Copy the code from this link into a download folder, extract the files, then copy the the files into the above path.  You will copy the 'views' directory and the affiliate.php file into the affiliate directory (see folder screenshot).

Download the affiliate.zip file here

Within the 'views' directory, you will have two files:  display.php and form.php. These files, and the containing 'views' folder, will be  present in every PyroCMS widget you create - these files are required and necessary.

  • The first file you edit (or create, depending on your need) is the class file.  Remember to capitalize the name of the class - which must be the same name as the file (less the .php extension :-) ).

Here is a bare affiliate.php file after editing to add the fields needed for the new widget:

<?php
if(!defined('BASEPATH')) exit('No direct script access permitted');
class Affiliate extends Widgets
{
// This section will appear when you click on the widget on the 'widgets' page of the admin
// interface (aka dashboard).  You access the admin interface using the following URL:
// http://your-host/your-pyrocms-base-dir/admin
public $title = 'Affiliate Widget';
public $description = 'Add Affiliate Links and Images';
public $author = 'Vic Russell';
public $website = 'http://www.randaweb.com';
public $version = '0.3';
// Now you define the fields that you will use in your widget.
// The widgets class will contain a 'name' field, so it is optional here
public $fields = array(
array(
'field' => 'aff_title',
'label' => 'Product Title',
'rules' => 'trim|max_length[254]'
),
array(
'field' => 'aff_order',
'label' => 'Add Order - 1 = new line',
'rules' => 'trim|max_length[3]|integer'
),
array(
'field' => 'aff_link',
'label' => 'Affiliate Link',
'rules' => 'required|trim'
),
array(
'field' => 'aff_alt',
'label' => 'Affiliate Alt Text',
'rules' => 'trim|prep_url|max_length[254]'
),
array(
'field' => 'aff_class',
'label' => 'CSS Class',
'rules' => 'trim|max_length[254]'
),
array(
'field' => 'aff_style',
'label' => 'CSS Style',
'rules' => 'trim'
),
array(
'field' => 'aff_source',
'label' => 'Affiliate Source)',
'rules' => 'trim|max_length[254]'
),
array(
'field' => 'aff_company',
'label' => 'Company Source for add',
'rules' => 'trim|max_length[254]'
)
);
public function run($options)
{
// The requisite 'run()' method that returns the data in the $output[] array //
if(empty($options['aff_title']))
{
return array('output' => '');
}
return array('output' => array($options['aff_title'], $options['aff_link'],
$options['aff_alt'], $options['aff_class'], $options['aff_style'],
$options['aff_source'], $options['aff_company'] ) );
}
}
/* Close class Affiliate */






Web Design and Development Links

2:18 PM in Programming by vrussell

Links to very interesting and useful sites that will help inspire, teach, and inform.

Design:

Smashing Magazine – User Interface concepts:  http://www.smashingmagazine.com/

Zen Garden – examples of how CSS can be beautiful:  http://www.csszengarden.com/

Design and Development:

SitePoint - amazing JavaScript and CSS references : http://www.sitepoint.com/

Read the rest of this entry →

PHP verus Java J2EE – with some Python Accolades

8:23 AM in Frameworks, Java J2EE, Linux, PHP, Programming, System Administration by Vic Russell

The ongoing debate by advocates in both camps is legion.  There are proponents of the scripting (PHP) model that argue time-to-go-live is much faster using php than java.  The Java camp argues that such a statement only makes manifest the PHP advocates ignorance of the Java web framework.

Having developed using both languages, I must say that while both are powerful, Java is hands down more powerful.  There is little you cannot do using the vast array of available libraries to perform the most complex task relatively easily.  And, there are plenty of Java developers in the world to man your project.

Having said that, Java development comes with a very high price.  Most Java-based web frameworks require a tremendous investment in initial training to learn how to use it efficiently – the available beans, servlets, and tag libraries, along with the methods and properties in each class, can be daunting.  The benefit comes once the framework is internalized by the developers – then productivity can be impressive.

PHP is a low upfront cost platform.  The language is intuitive, comprehensive, and interpreted.  Much of the overhead of Java is simply non-existent using a scripting language.

Request/Response – The nature of the web dictates that permanent connections are not established between site visitors and the server.  The stateless protocol that is HTML dictates this structural tenet.   A request is made by a client, the response is processed and delivered by the server(s).  The next request is processed, with the appropriate response, ad infinitum.  Any state fullness is handled by custom constructs – sessions or cookies are the most prevalent in use today.  Any process that can handle the request can deliver the response – the underlying program at the server does not matter to the requester, so long as the response is both valid and timely (<3 sec).

Creativity:  Java, in my opinion, takes away that freedom to quickly deploy a creative solution to a particular development challenge.  Instead of thinking outside the box, Java forces you to remain constrained within the rigorous rules of the particular framework. Since the Java app is running on the server at all times, awaiting a request to deliver a response, there is a great deal of ancillary work to do to add a single class or property.

Deployment:  In certain Java environments, you must compile the complete application, package it in a WAR file,  then move it into the application server ‘servers’ directory.  This can take many minutes given the complexity of the app and the power of the hardware and speed of the comm link.  A few simple changes can result in hours of debugging and testing.

Caching:  I would say that the biggest advantage in using Java is the caching mechanisms that are part of the web framework.  It is amazing how granular caching can be controlled.  There is an obvious performance benefit to this feature when running a very active site.

Testing:  When using an IDE like Eclipse, along with the appropriate plug-ins, one can be very efficient testing and debugging Java code.

Break-Fix: If there is one aspect of Java that really grates me it is the traceback output generated by errors.  Most of the info you get is useless; finding the key output is the challenge.  Once you get the hang of it, you learn to ignore 90% of the output.

Database Access:  Java’s JDBC interface and use of connection pools is time tested and reliable.  The connection open when the application starts, and are available immediately.  There are standard API’s for all major database platforms ready to be downloaded and configured.

Maintainability:  Maintaining an app is where most of the time will be spent on a live site.  If the application is difficult to code, it will be more difficult to de-code/debug.  Again, Java is a bit demanding when something goes awry.  To offset this challenge, very effective log4j logging should be used.

Infrastructure:  This is where the rubber meets the road – how long does it take to set up and configure a new server that can run production code and serve your customers?  Java is a real headache in this regard.  The amount of configuration files you have to update to meet the needs of your environment can take many hours to many days.  There are so many options that it becomes almost impossible to do so on the first try without the help of an experienced Java infrastructure guru.

PHP

PHP is a very comprehensive language.  There are many third party libraries that one can employ to perform the task that you need, that is, unless the build-in functions are sufficient.  I would argue that you can code 95% of a site using the built-in functions that PHP offers.  I do use the PEAR library, which is extremely useful as a DB API.

Testing is typically fast and efficient – particularly when you use Eclipse with PHP extensions or PHP Designer 7 as an IDE.   In PHP Designer 7, you can test multiple browsers without leaving the IDE.  It is a great product that is light-weight, offers Python, JavaScript, HTML, and support for may other languages.

Deployment: You copy your code to the server(s) and it is ready to be run.  That can be a single file or a directory.  There is no up-front compilation to worry about – just test the code and run.

When to use which language?

What skills do your developers have?  If they are Java guru’s, then a j2ee platform would probably be the way to go.  Those skilled in a ‘real’ programming language do not fare well when switching to a scripting language.  The complexity they are so used to is lost.

Also, a very high availability, high hit rate e-commerce web site can benefit from the J2EE framework.  The caching, db throughput, and stability of a java app (once you get it running) is impressive.

Other than the above, PHP has the advantages.  There is little argument against simplicity coupled with power.  Adding an additional os/web server VM to a (non-Windows) server farm is very inexpensive.  The added power and the redundancy of a new server is quite beneficial to any site that has a variable hit rate based on, say, time of year or time of day.

I have installed PHP on Windows and Linux systems very quickly.  That includes Apache 2 and MySQL servers that are required for a fully functional web site.  The WAMP server download (Windows, Apache, MySQL, PHP) takes about 10 minutes to download and install over a fast cable/dsl connection.

Another benefit is Microsofts support of PHP (and Python, another very robust scripting language for the web).  The CLR supports Iron PHP and Iron Python.  Your cost for adding a server will increase (MS Server License), but, if your team is .Net centric with a few PHP apps to support, this might be the way to go.

PHP is easy to learn.  With a decent mentor, a team can get up to speed in about a week.  Java can take a month to get to the same proficiency.  Now these are non-scientific estimates, so don’t flame this author for such an estimate.

Python is another language I have used.  As languages go, Python is beautiful.  By abandoning brackets and using spaces to format the various code blocks, the developer is forced into using good indentation, which results in very readable code.  Python is probably the best language for systems administration – think shell scripting on steroids.  It is blazing fast, robust, and has the advantage of many libraries to extend the base language – many coded in C/C++.  All in all, Python is the most enjoyable language I have yet to use, if that can be said about a programming language.  And, using IronPython and Microsofts CLR, you can use familiar IDE tools to develop.

If you want to get starting using Python, download the iPython application.  It is a command line environment that allows you to test simple to moderately complex code on demand.  A very effective learning tool and sys admin platform.