Syntax Highlighted Source Code in WordPress
Adding syntax highlighted source code in WordPress doesn’t come without a plugin. WordPress by nature strips out any potentially dangerous code in the posts and pages, protecting you from yourself. There are two very good plugins to accomplish this. 1) SyntaxHighlighter2 and 2) Dean’s Code Highlighter. Both are good.
I prefer the first, but there are some problems with it when using some themes in WordPress and the current theme I have installed is one of them. To post source code with this plugin in WordPress, you place your code between the [sourcecode language="php"] [/sourcecode] tags.
The 2nd almost always works and I’m using it in this theme now. Using Dean’s Code Highlighter I can place my source code between the <pre lang=”PHP”> </pre> tags in my WordPress HTML editor and preserve code formatting and have intelligent syntax highlighting, based on GeSHi.
“Delphi” Sample:
-
for (x := 0 to 100) do begin
-
end;
“PHP” Sample:
-
for ($x= 0; $x= 100; $x++) {
-
}
“JavaScript” Sample:
-
for(i = 0; i < 5; i++){
-
}
“CSS” Sample:
-
body {
-
background-color: Black;
-
}
“XML” Sample:
-
<?xml version="1.0" encoding="UTF-8"?>
-
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
-
<url>
-
<loc>http://webjestic.net/</loc>
-
<changefreq>weekly</changefreq>
-
<priority>0.5</priority>
-
</url>
-
</urlset>
“XHTML” Sample:
-
<!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" dir="ltr" lang="en-US">
-
<head profile="http://gmpg.org/xfn/11">
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-
</head>
-
<body>
-
</body>
-
</html>
For a complete listing of all the supported languages, visit GeSHi.
Connecting to MySQL in Delphi for PHP (AppObsess)
In this video tutorial I begin building an ongoing project called AppObsess, which I will use as a generic and very simple application engine using the Smarty Template engine and the MySQL database. I begin this video series having applied the techniques from the other video’s: Creating Editable Forms for Smarty Templates and Creating Dynamic Smarty Variables in Delphi for PHP.
Connecting to a MySQL database in Delphi for PHP is an extremely simple task. In this video I create a data module and a config file containing the connection strings, include the files and execute the program. That’s the entire video in a nutshell. Most of the video is spent getting up to speed on the state of the application.
The core code is written in a file called maindb.php (the data module) and it looks like this:
-
$MainData->MySQLDB->Host = HOSTNAME;
-
$MainData->MySQLDB->DatabaseName = DATABASE;
-
$MainData->MySQLDB->UserName = USERNAME;
-
$MainData->MySQLDB->UserPassword = PASSWORD;
-
$MainData->MySQLDB->Open();
-
if (! $MainData->MySQLDB->Connected) {
-
}
As always, you should have much better error control handling then I added for this simple tutorial. My connection testing was just to make sure something stupid didn’t happen while I was creating this video.
The config.inc file is very simple as well and only contains the connection strings for MySQL. It looks like this:
The starting template I am using for this AppObsess web framework in Delphi for PHP is the Blue Obsess template available from my XHTML/CSS Templates page.
The starting database SQL I have for this application is:
-
DROP DATABASE IF EXISTS obsess;
-
CREATE DATABASE IF NOT EXISTS obsess;
-
USE obsess;
-
-
CREATE TABLE page (
-
id bigint(20) NOT NULL AUTO_INCREMENT,
-
page_name varchar(200) NOT NULL,
-
page_body text NOT NULL,
-
-
UNIQUE KEY page_name (page_name),
-
PRIMARY KEY (id, page_name)
-
) TYPE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1000;
If you would like to download this application in the state it is for this video, you can download it using the link below. The .SQL file, the template, and the Delphi for PHP project code is all included.
Download AppObsess-dev-001.zip here!
Creating Editable Forms for Smarty Templates in Delphi for PHP
Once you begin working with the Smarty Template engine in Delphi for PHP and once you learn how to include and update smarty variable tags, you’ll want to start including work areas for your data forms. With a lack of VCL documentation, it’s not obvious how to get your controls in the smarty template and get them positioned correctly.
Additionally, for several days I was stumped as to why I couldn’t get my Button code to execute when I used a smarty template. This video shows how to accomplish all these tasks. This video extends the lesson in Creating Dynamic Smarty Variables in Delphi for PHP and in Hello World (Delphi for PHP).
The main thing to remember in all of these lessons is that in obtaining the desired effect, we are basically configuring the proper Object Inspector Properties or extending the code within the Object Inspector Events for the proper objects.
Creating Dynamic Smarty Variables in Delphi for PHP
One of the first things you’ll notice when you begin working with Smarty Templates in the Delphi for PHP environment is that it’s not obvious how you can include custom or dynamic smarty variable tags into your template from Delphi for PHP.
This video was created to demonstrate exactly how to get dynamic smarty variables into your smarty templates and display the correct variable information. The main thing to know and understand is, that the VCL in Delphi for PHP has a certain time it executes the Smarty Engine events.
To access the correct time and place to assign your variables is to use the Forms->OnTemplate event and access the smarty object through the provided $params. In this video I’ve created 3 dynamic smarty tag variables. $MyTitle, $MyDescription, and $MyKewords. I assign the values of these variables in Delphi for PHP and placed them in the HTML smarty template.
-
function Unit1Template($sender, $params)
-
{
-
$template = $params[‘template’];
-
$template->_smarty->assign(‘MyTitle’, ‘My Custom Page Title’);
-
$template->_smarty->assign(‘MyDescription’, ‘My Custom description…’);
-
$template->_smarty->assign(‘MyKeywords’, ‘keyword 1, Smarty Keyword’);
-
}
If you’ve found this video posting useful, you might also be interested in the video posting that extends this lesson: Creating Editable Forms for Smarty Templates in Delphi for PHP.
Manually Creating Mirrored Images in Fireworks
Sometimes when creating reflective images in Adobe Fireworks using the menu driven method, there are pixel lines on the sides that aren’t completely faded out. If you experience this problem and are unable to successfully touch it up, you can use another method to create that mirrored image effect.
You can use a vector object to create the mirrored image reflection simply by applying a gradient effect and adding some transparency effects. This video shows you exactly how to do it.
