Category Archives: PHP

How-to for PHP

Setting Up Eclipse PDT with UniServer for PHP Development (Part 1 of 2)

General Observations

Not the most convenient or intuitive IDE in the world, Eclipse is still a convenient IDE to use if you are not into spending big money on other developers … but, would like some very useful tools for development. If set up correctly, Eclipse PDT can help develop PHP projects with very useful debug options.

Some of the problems with Eclipse PDT include:

  • Setup can be a pain, it is definitely not load and go
  • Extra effort my be needed if you are not using Zend Server
  • You define your projects, but, deleting projects is a nuisance to do

I should mention, I am not an Eclipse expert. Definitely, it was a massive effort to hunt and peck my way through the installation. This article is to help me remember the process the next time I need to go through the process. It has a bit of rambling side information for those of you that find this articles and are curious why I have elected to do some of the setup that I do to use Eclipse. I hope it helps you too.

Preparation to use Eclipse PDT

To use Eclipse PDT, you must have the ability to run PHP. This implies the availability of a Server environment. Preparation suggests you install an AMP environment. In the case of this article, I have a WAMP environment.

I am developing on a WAMP environment; Windows, Apache, MySql & PHP. To maintain the database, I like using phpMyAdmin. To meet my needs for Apache and mySQL, I have tried using Zend Server.

Zend Server is an interesting, having lots of bells and whistles, but, I find that it is a pain to install phpMyAdmin on Zend Server hosted on Windows. Zend Server has a “simple” button press “deployment” of phpMyAdmin on their Zend Server, but, it fails in Windows. Notes around the internet indicate it works in Unix and Linux but, phpMyAdmin does not deploy conveniently on Windows at this time … true.

Even more inconvenient, uninstall of Zend Server does not do a complete uninstall. Zend Server installs IBM DB2 Server, but, does not remove it in the uninstall. This incomplete uninstall leaves the IBM DB server blocking access to port 3306 for other WAMP package installs. If you want to use port 3306, for the database servers with some other WAMP package like Uniserver, Wampserver, UmAmp … you will need to be aware and uninstall the DB2 server separately. Failure to uninstall IBM DB2 results in the failure of other WAMP packages to install completely. In the future, I may try Zend Server again using a Linux environment, but, not on Windows … until they solve their Windows compatibility problem with phpMyAdmin.

On Windows, I find the Uniform Server (UniServer) extremely convenient to install. I have used UniServer for about 10 years and never have had problems with Uniserver. The installation is quick, simple, and always works. UniServer includes mySQL, PHP and phpMyAdmin and meets my development needs nicely. Load and go in a Windows development environment.

If you are looking to use Eclipse, I assume you have an AMP package installed. If you have a AMP package installed, you can skip to Installing Eclipse PDT. If you are using Windows and need a WAMP package, the following two short sections will help.

Find Uniform Server

Uniform Server can be found at http://www.uniformserver.com/. Go on over to the UniServer site and click Download to retrieve the latest version of UniServer.

Installation of UniServer

To install UniServer:

  • Choose a where you would like to install UniServer. Some would choose the “Windows File” directory, but, I prefer to place it elsewhere. Your development files will be placed in a subdirectory below this and I do not like my development files stored below the Windows/Program Files subdirectory.
  • run the unZip for the uniserver package into the chosen . A will be created, but, standard Windows install with registry is not used by the UniServer package. (The name of the server_subdirectory changes with version, so I will call that )
  • Create a shortcut on your desktop to /UniController.exe. This will be your access to the UniServer control panel.

You are now ready to move on to the hard part … installing and configuring Eclipse PDT.

Head on over to the next article to find details of the Eclipse PDT installation and configuration.

5 Steps to Adding Sidebar Block in Zen-Cart

You may find that you want to add a block to the sidebar in Zen-Cart. The content may be text, image, or other feature to extend the content on the cart. The generic concept of adding a block involves 5 steps. This article explains the steps. For simplicity, we will only add a text block.

Step 1; Create Sidebox Template

Add a new file to the server in the following directory: /includes/templates/<template-name>/sideboxes/. Name the file something relating to the contents of the sidebox. We will be adding a support phone number to call in a sidebox, so, we might name the file tpl_support_number.php. The file will include what you want to display in the box and will be assigned to the variable $content variable. Below is an example of the contents of the file.


  <?php
     /* Side Box Template  */
     $content = "For information about products or services, call (888) 555-1212" ;
  ?>

Step 2; Create Sidebox

Now, to create the actual box; add a new file to the server in the following directory: /includes/modules<template-name>/sideboxes. Name the file something relating to the contents of the sidebox. In our sample, we will call it support_number.php. The contents of this file will look like the sample below, but, modify the variables to relate to your template.


  <?php
  /**
   *  Support Number Sidebox - used to display a support message 
   *  in a sidebox.
   *
   */
   $show_message = true ;
   if ($show_message == true) {
       require(
         $template->get_template_dir('tpl_support_number.php', 
            DIR_WS_TEMPLATE, $current_page_base,
           'sideboxes') . '/tpl_support_number.php');
       $title = BOX_HEADING_SUPPORT_NUMBER ;
       $title_link = false;
       require($template->get_template_dir($column_box_default, 
           DIR_WS_TEMPLATE, $current_page_base,'common') . '/' . 
           $column_box_default);
   }
  ?>

Step 3; Add Language Variables

Modify the english.php language file in /includes/languages/ to include the definitions for any text variables you have used in either file. In this example we created a new variable called BOX_HEADING_SUPPORT_NUMBER. So, we will add the following to the english.php file.


  // welcome box text in sideboxes/welcome.php
  define('BOX_HEADING_SUPPORT_NUMBER', 'SUPPORT INFO');

Step 4; Enable Sidebox:

Activate the sidebox as follows:

  • Login into Zen-Cart administration.
  • Hover over Tools.
  • Select “Layout Boxes Controller” from the drop down, a list of boxes will appear …  including your new box
  • Double-click the name of the new box you have created, in this sample, it will say …  sideboxes//support_number.php. In the upper right of the window you will see fields that you can edit.
  • Select to edit the information, an editable form will appear
  • Fill in the form, by:
    • Selecting the radio button next to “on” in “Left/Right Column Status”
    • Selecting the radio button to place the box on the “left” or “right” sidebar
    • Typing the correct number is the sort order field to display the box
    • and then clicking the Update button.

The sidebox is now enabled on the site

Step 5; Verify Sidebox:

Now, visit your store in a browser and make certain the sidebox displays.

 

SilverStripe editor need more Tags? Fix it!

SilverStripe

If you are having the problem that SilverStripe editor is striping out tags that you would like to use, fix it.

This article explains. SilverStripe uses the TinyMCE editor. SilverStripe has set up to permit you to add content to the /mysite/_config.php file and extend the tags that are accepted by the SilverStripe editor.

In the /mysite/_config.php file, add the following statement:


  HtmlEditorConfig::get('cms')->setOption(
    'extended_valid_elements',
    'img[id|class|src|alt|title|hspace|vspace|width|height|' .
    'align|onmouseover|onmouseout|name|usemap],' .
    'iframe[id|class|src|name|width|height|title|align|allowfullscreen|' .
    'frameborder|marginwidth|marginheight|scrolling],' .
    'object[classid|codebase|width|height|data|type],' . 
    'embed[id|class|src|type|pluginspage|width|height|autoplay],' .
    'param[name|value],' .
    'map[class|name|id],' .
    'area[shape|coords|href|target|alt],' . 
    'article[id|class|name|width|style],' .
    'section[id|class|name|width|style],' .
    'aside[id|class|name|width|style],' .
    'article[id|class|name|width|style],' .
    'ol[id|class|start|type]') ;

Use the format above to extend the editor to use any tags and tag attributes that you would like available to the editor. Above you see various tags and attributes being included, including HTML5 tags and attributes. You can include just the tags and attributes you believe you’ll need to support your use of the SilverStripe editor.

 

 

Finding the location of an IP Address

The following is a quick and simple way to find the general location of an IP Address. This tool only locates the region the IP Address is located in, not the exact location of the visitor. This identifies the location of the ISP that hosts the visitor. However, this can be useful.

[evalphp]
function theLocation($user_ip) {
$meta_tags =
get_meta_tags(‘http://www.geobytes.com/IPLocator.htm?GetLocation&template=php3.txt&IPAddress=’ . $user_ip) or die(‘Error getting meta tags’);
$city = $meta_tags[‘city’];
$state = $meta_tags[‘regioncode’];
$country = $meta_tags[‘fips104’];
$lat = $meta_tags[‘latitude’];
$lng = $meta_tags[‘longitude’];
return array($city, $state, $country, $lat, $lng ) ;
}
$visitor = $_SERVER[“REMOTE_ADDR”];

list($city, $state, $country, $lat, $lng) = theLocation($visitor) ;

echo “

Your Info: ” . $visitor . ” ⇒ ” . $city . “, ” . $state . “, ” . $country , “

” ;
[/evalphp]



    function theLocation($user_ip) {
        $meta_tags = get_meta_tags(
             'http://www.geobytes.com/IPLocator.htm?
             GetLocation&template=php3.txt&IPAddress=' . 
             $user_ip) or 
             die('Error getting meta tags');
        $city = $meta_tags['city'];
        $state = $meta_tags['regioncode'];
        $country = $meta_tags['fips104'];
        $lat = $meta_tags['latitude'];
        $long = $meta_tags['longitude'];
        return array($city, $state, $country, $lat, $lng ) ;
    }

    $visitor = $_SERVER["REMOTE_ADDR"];
  
    list($city, $state, $country, $lat, $lng) = 
        theLocation($visitor) ;
    echo "<p>Your Info: " . $visitor . 
            " &rArr; " . $city . ", " . 
            $state . ", " . $country , "</p>" ;

Warning: money_format does not work on Windows

Folks,

PHP logoI am certain you are far cleverer than I. I spent a couple of hours attempting to do some development with PHP function money_format(), and it did not work.

I wanted to use money_format() to convert a number formatted for currency. But, I wanted it function for development and for site.

I scratched my head over and over … leaving dandruff everywhere. After some reflection, and then search of the internet and reading the PHP documentation for money_format over and over … it dawned on me that the documentation said it does not work on a Windows system. I develop on a Windows system running Apache, and load to a server running Linux. Don’t use money_format if you develop on Windows … if you want to see function on your development environment.

Use number_format(), this works on both Windows and Linux. Much better.

Oh, and the currency symbol can be identified using localconv(), which returns an array with [currency_symbol].