You are browsing the archive for CodeIgniter.

PyroCMS versus Concrete5

5:04 PM in CodeIgniter, Concrete5, PHP, Programming, PyroCMS by Vic Russell

We are testing multiple PHP frameworks and CMS platforms for affiliate websites hosted on Host Monster and Go Daddy.  This round, we are testing Concrete 5 and PyroCMS. Both Concrete 5 and PyroCMS are built on top of the Codeigniter framework - a very powerful and simple to learn  MVC framework written in the PHP programming language.

Concrete5 Link PyroCMS Link

I am not doing a review of the big frameworks at this time – Joomla, Mambo, WordPress (blog manager), CakePHP, etc – there is enough documentation out there that would render my opinion moot.   Besides, I champion the underdogs and fight for their success over established ‘big boys’ – particularly when the underdogs have features and/or performance that exceeds the established players.

Concrete5 – This is an edit-in-place PHP CMS framework with many add-ons (blocks) in the public domain, as well as professional-grade pay-for add-ons like Concrete 5′s shopping cart module. The main advantage to Concrete5 is the way pages are edited – they are done so in-place.  You log in, and if you have permissions, you are presented with an admin ribbon menu along the very top of the web page.  Clicking ‘Edit this page’ allows you to edit the page!  You can publish your changes immediately, preview them, or hold them for later publication – an expected feature in any true content management system.  I give this system 3.5 out of 5.0 – good docs, excellent add-ons, and the familiar Codeigniter MVC are all pluses.

PyroCMS is wicked fast.  However, the file structure is complex, and creating a custom theme is a challenge since there is about 10% of the documentation needed to be efficient/proficient with this framework.  The one area that isn’t difficult is the creation of ‘widgets’ – small discrete sections of code (classes) that can be included throughout your site.   There does not seem to be as many ‘widgets’ in the public domain as C5, but that will change once more developers get familiar with this true competitor.

After spending many hours attempting to customize PyroCMS, I determined that it is futile to continue down this path since I have sites I need to get up really fast.  I will continue to spend time with PCMS as it matures – I feel it has excellent potential, and, I like the admin interface style over edit in place (the C5 way).

Time will tell, but I am giving PyroCMS  an overall rating of 3.0 out of 5.0.  The main reason it gets such a high mark (before V 1.0)  is it is so darn fast, and, widgets are easy to create and a breeze to integrate – custom widgets are a core component of any good CMS.

VR

PyroCMS Widget Creation for Affiliate Marketing -Section 3

8:37 AM in CodeIgniter, Frameworks, PHP, Programming, PyroCMS by Vic Russell


Views

display.php

Now that we have created the affiliate.php class (section 1) and the form.php (section2), we have to write the code to display the widget content.  This is the display.php file within the ./affiliate/views folder.

One challenge I had with this was getting rid of the the default title that displays above all widgets.  Again, givent he sparse PyroCMS documentation, I had to use jQuery to hide the title – not the best solution, but it works.

Download the affiliate.zip file here

Another challenge is the float property when a widget is placed one next to the other.  There seems to be a 22px margin problem somewhere in the PyroCMS widget classes.  This is why there is the ‘style’ form element within the widget – this allows you to manually remove this by adding a negative margin-top (margin-top: -22px).  This is cumulative, so item # 3 is margin-top:-44px;  Item 4 is margin-top:-66px, etc.  Yes, this is a hack, but until familiarity with the core widget class is acquired, I don’t feel that breaking PyroCMS is a good solution.

Here is the code for the display.php

<?php
/*
Affiliate widget - actually affiliate widget
@author	Victor Russell
@ttd	remove title from this widget
--------------------------------------------------------------------------------
*/
?>
<style type='text/css'>
.display_none {
display: none;
}
.hspacer-12px {
margin: 0px;
clear:both;
display:block;
overflow:hidden;
width:100%;
height:12px;
}
</style>
<script type='text/javascript'>
// remove affiliate title via jQ
$(document).ready(function() {
$('.widget h3').addClass('display_none');
});
</script>
<?php
/* remove the default display of the title for the widget */
echo "\n<style type='text/css'>\n";
echo ".widget affiliate h3 { display: none; }\n";
echo "</style>\n\n";
/* Assign _ replaced title to temp variable, replacing spaces with underscores */
$temp_str = 'div_' . str_replace(" ","_",$options['aff_title'] );
/* Add a blank line IF the aff_''order'' is equal to 1 */
if($options['aff_order'] == '1')
{
echo "\n<div class='hspacer-12px'><!-- --></div>\n";
}
/* Create div for each affiliate ad, using the css defined in each entry */
echo "\n\n<div id='" . $temp_str . "' " .
"title='" . $options['aff_title'] . " \n '
class='" . $options['aff_class'] . " \n '
style='" . $options['aff_style'] . "' >\n ";
echo $options['aff_link'];
echo "\n</div><!-- |><| Close affiliate div for " . $options['aff_title'] . " --> \n";
?>

This display.php creates a DIV with the attributes of id, title, class, and style.  The content (the affiliate link HTML) is output using $options['aff_link'].

Enjoy!

Vic Russell

Russell and Associates

www.randaweb.com/forum

PyroCMS Widget Creation for Affiliate Marketing – Section 2

8:40 PM in CodeIgniter, CSS, PHP, Programming, PyroCMS by Vic Russell


Views

form.php and display.php

This is section 2 of the PyroCMS widget creation example.  As stated before, PCMS is built upon Codeigniter – a very powerful and easy to learn PHP Framework.  Codeigniter is MVC compliant.

You have updated the class file – affiliate.php.  In there, you defined the fields you will use in the admin interface to actually add the content for your affiliate link widget.

Download the affiliate.zip file here

Next, we edit the files contained in the ‘views’ sub-folder.  There will be two – ‘display.php’ and ‘form.php’.  They do exactly what they say they will do – display the content of the widget and create the form interface to add your content to the widget.

NOTE: I have kept the CSS and JavaScript in the files to ease the understanding of the PyroCMS widget creation.  This is not standard practice, but lets not add confusion to what may be a challenging topic by rigorously adhering to coding standards purity during the learning phase.

form.php

<?php
/**
* form.php for affiliate widget
* ==============================
* @author	Victor Russell - www.randaweb.com
*
* Create the form using Codeigniter form_helper and form_validation libraries
* form_input() and form_textarea() are used to display the content from the
* database.
*
**/
?>
<ol>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Affiliate Title (used for onhover - tooltips)</label>
<?php echo form_input(array('name'=>'aff_title', 'value' => $options['aff_title'] ) ); ?>
</li>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Row Break - 1 = new line/row</label>
<?php echo form_input(array('name'=>'aff_order', 'value' => $options['aff_order'],
'size' => '3', 'maxlength' => '3' ) ); ?>
</li>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Affiliate Link &lt;a&gt; *</label>
<?php echo form_textarea(array('name'=>'aff_link', 'value' => $options['aff_link'], 'rows' => '5' ) ); ?>
</li>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Affiliate Alt Text</label>
<?php echo form_input(array('name'=>'aff_alt', 'value' => $options['aff_alt'] ) ); ?>
</li>
<li style='margin-top: -2em;'>
<label>Affiliate CSS Class</label>
<?php echo form_input(array('name'=>'aff_class', 'value' => $options['aff_class'] ) ); ?>
</li>
<li style='margin-top: -2em;'>
<label>Affiliate CSS Style</label>
<?php echo form_textarea(array('name'=>'aff_style', 'value' => $options['aff_style'], 'rows' => '2' ) ); ?>
</li>
<li style='margin-top: -2em;'>
<label>Affiliate Source (CJ, ClickBank...) *</label>
<?php echo form_input(array('name'=>'aff_source', 'value' => $options['aff_source'] ) ); ?>
</li>
<li style='margin-top: -2em; margin-bottom:-1em;'>
<label>Affiliate Ad Company *</label>
<?php echo form_input(array('name'=>'aff_company', 'value' => $options['aff_company'] ) ); ?>
</li>
</ol>
<?php //echo js('codemirror/codemirror.js'); ?>
<?php /*<script type="text/javascript" defer="defer">
html_editor('html_editor', "25em");
</script> */ 
?>

The form.php is rather simple. The main hurdle you may have is the syntax used to create the form elements – this is Codeigniter’s style and is very powerful.  Once you really understand it, it is very simple.

Link to the very excellent Codeigniter documentation.  Click on the drop-down menu at the very top of the page and examine all of the classes, helpers, libraries, and other useful information.

Codeigniter form helper and form validation documentation

<label>Affiliate Source (CJ, ClickBank...) *</label>
<?php echo form_input(array('name'=>'aff_source', 'value' => $options['aff_source'] ) ); ?>

This code creates a form element label and the CI method of a input type=’text’ element.

The form_input() method creates the following (using ‘view generated source’ after rendering the page with an affiliate widget):

<input type="text" name="aff_title" value="">

The Codeigniter form validation class then checks the length of the fields, as well as other attributes (numeric, alphanumeric, integer, etc), against the array that you created in the ‘affiliate.php’ file.  If an error occurs, you will get a detailed error message near the top of the widget container telling you the field and error.  This occurs after you click ‘Save’.

For the PHP Codeigniter  form_textarea() method,

<?php echo form_textarea(array('name'=>'aff_style', 'value' => $options['aff_style'], 'rows' => '2' ) ); ?>

the resulting form element looks like this:

<textarea name="aff_link" cols="90" rows="5" value=""></textarea>

The one very important and simplification from standard form handling is the ‘value’ => $options['aff_style'] attribute. If there is content in the field, this array value is assigned as the value of the form element, displaying it for viewing and editing.

pyrocms widget affiliate form preview randaweb.com

Widget Form Preview

Affiliate Links

Because of the issue regarding Javascript inclusion in text areas and input fields, use only HTML-formated affiliate links from your provider (ClickBank, Commission Junction, etc).  Do not add any features that some providers have as options – such as CJ’s ‘Hide tracking code in link?’ and ‘Encrypt link?’ options – don’t use them or your links won’t work as expected.

Future

I am working on an automated affiliate link manager for PyroCMS – this will be a ‘module’ and not a ‘widget’.  This will allow you to program your site to populate a link section or sections with specific categories using your link providers API.

Thanks,

Vic Russell

Russell and Associates

www.randaweb.com/forum

randaweb@gmail.com

Quick Link To My Development Site

9:40 AM in 960grid, BlueprintCss, CodeIgniter, CSS, jQuery, Programming by Vic Russell

Here is a link to my dev server and the current dev projects I am involved with.

Finally have the CI site up and running on a hosted site:

www.randaweb.com

Here are links to our DEV server:

Page using the 960grid framework – many jQ features – check out each tab.

Page using the blueprint css framework – interesting MAC-like menu (hover over the solar system planets)

Another BP css page – sales page