Tag Archive for: easy

New Premium Plugin Available

22 Dec
December 22, 2011

Easy Custom CSS Stylesheets

I’ve been working on a new plugin for the past week or two, writing documentation for it, and testing it quite extensively. It finally got accepted on CodeCanyon, a marketplace for premium plugins and code.

My plugin is called Easy Custom CSS Stylesheets, and it allows you to create unlimited stylesheets which are stored in the database and link them to your site, or attach them to specific pages, posts, or special pages (Category page, home page, login page, etc). This eliminates the need of modifying your theme source which breaks the ability to update the theme and is generally a hassle.

I plan on adding the ability to do the same thing with JavaScript to the plugin soon as well. The plugin includes a JavaScript based code editor, complete with syntax highlighting, key binds and line numbers. You can even link to remote stylesheets, useful for importing fonts from Google Web Fonts or Typekit.

You can purchase it for $14 over at CodeCanyon.

Easy WordPress Theme Options

02 Aug
August 2, 2010

For the most up-to-date information visit the plugin page

I’ve been getting really annoyed every time I want to add options to my theme and I have to copy a huge mess of code that just isn’t fun to use. You know what I mean. Most theme developers now include configurable options in their themes, which if you ask me, isn’t super easy.

So the other day I set out to write a class that theme developers could package with their file and have easy access to theme options. It’s as easy as adding my theme_options.php file to an include folder in your theme directory, and then adding this code to your functions.php (Using your option values obviously).

Download my ThemeOptions class

require_once( 'includes/theme_options.php' );

define( 'THEME_NAME' , 'Theme Template' );
define( 'THEME_SHORTNAME' , 'themetpl' );

ThemeOptions::add( 'sample_text_field', 'Its a text field'  , array( 'desc' => 'A description of the theme option', 'type' => 'text', 'default' => 'Default Value' ) );
ThemeOptions::add( 'sample_textarea'  , 'Its a text area'   , array( 'desc' => 'A description of the theme option', 'type' => 'textarea', 'default' => "Text\nTest" ) );
ThemeOptions::add( 'sample_checkbox'  , 'Its a checkbox'    , array( 'desc' => 'A description of the theme option', 'type' => 'checkbox', 'default' => 'enabled' ) );
ThemeOptions::add( 'sample_select'    , 'Its a select thing', array( 'desc' => 'A description of the theme option', 'type' => 'select', 'default' => 'Option 2', 'values' => array( 'Option 1', 'Option 2', 'Option 3' ) ) );
ThemeOptions::add( 'sample_radio1'    , 'Its a radio field' , array( 'desc' => 'A description of the theme option', 'type' => 'radio', 'default' => 'val1', 'values' => array( 'val1' => 'Text 1' , 'val2' => 'Text 2' ) ) );
ThemeOptions::add( 'sample_radio2'    , 'Its a radio field' , array( 'desc' => 'A description of the theme option', 'type' => 'radio', 'default' => 'val2', 'values' => array( 'val1' => 'Text 1' , 'val2' => 'Text 2' ) ) );

Now this may seem confusing at first, but if we expand it out, you’ll see it’s similar to other WordPress functions (I did the code like that for that specific reason):

$args = array(
    'desc' => 'This is a description of the option',
    'type' => 'text',
    'default' => 'This is the default value'
);

ThemeOptions::add( 'option_id', 'Option Name', $args );

And to get a value:

$val = ThemeOptions::get('simple_text_field');

Isn’t that easier that what you’ve been doing? I’ve encapsulated my code into a nice class to make everything super simple. The results should look similar to this (Located in Appearance > Theme Options):

Screenshot of the Theme Options Page

Download my ThemeOptions class

Python PHP date() class

04 Jun
June 4, 2010

I haven’t been doing much PHP as of late, at least nothing special. I’ve been studying for my A+ Certification, working on Python/Django, and doing 3d modeling (With 3ds max), so I’ve had very little time to play around with PHP.

For Python however, I was unhappy with the date formatting functions available so I decided to write my own. It’s in the form of a class which uses PHP style date formatting with almost all of the PHP date() options (prefixed by a % though). I’ve attached the source code.

You just have to import my class, make an instance and call the desired function. Example:

from my.project.includes import pytime

pytime = PyTime()

print pytime.get_datetime(format="%l, %F %j%S, %Y at %H:%i") # Results with something similar to "Friday, June 4th, 2010 at 11:24"

Download my Python date formatting class now!

LAMP Server Setup Pt. 4

11 May
May 11, 2010

Now that we have a secure Apache HTTP server installation, we need to setup PHP. I will use PHP 5.2.13 for this tutorial, not 5.3 as I’ve found that breaks a lot of web applications.

For this, I will be compiling in the Suhosin patch and extension, and enabling various database and other modules that come in handy when working with PHP. I’ve found that I need these to be able to use various software packages.

The first step is to go to PHP.net and get the url for the download. For PHP 5.2.13 that url is http://ca.php.net/distributions/php-5.2.13.tar.bz2

# Setup a work directory
mkdir /root/phptemp; cd /root/phptemp
wget http://ca.php.net/distributions/php-5.2.13.tar.bz2
tar -jxvf php-5.2.13.tar.bz2

#Now we need to grab the latest Suhosin and hardened PHP patches
wget http://download.suhosin.org/suhosin-patch-5.2.13-0.9.7.patch.gz
wget http://download.suhosin.org/suhosin-0.9.31.tgz
tar -xvzf suhosin-0.9.31.tgz
gunzip suhosin-patch-5.2.13-0.9.7.patch.gz

#Please note that I skipped the signature testing of the two files. This is optional but recommended that you do not skip
cd php-5.2.13
patch -p 1 -i ../suhosin-patch-5.2.13-0.9.7.patch

The next step involves configuring PHP. You may need to modify some of the paths or install some required software packages

# Configure PHP with common modules
./configure --with-apxs2=/opt/httpd/bin/apxs --prefix=/opt/php --exec-prefix=/opt/php  --with-config-file-path=/opt/php/etc --without-sqlite --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config --with-zlib --with-bz2 --with-gd --with-curl --with-openssl --with-mcrypt --with-mhash --enable-mbstring --with-kerberos --with-imap-ssl -with-gettext --with-ttf --enable-exif --with-pear --enable-gd-native-ttf  --with-freetype-dir=/usr/include/freetype2/freetype --with-jpeg-dir=/usr/bin --with-png-dir=/usr/bin --enable-calendar --enable-sockets

# Compile
make

# make test may not work if you are upgrading and have disabled certain functions
make test

# Copy the binaries to their proper directories
make install
make clean

For 64 bit systems the configure code should be like this

./configure --with-apxs2=/usr/local/apache2/bin/apxs --without-sqlite --with-mysql --with-mysqli --with-zlib --with-bz2 --with-gd --with-curl --with-openssl --with-mcrypt --with-mhash --enable-mbstring --with-kerberos --with-imap-ssl --prefix=/usr --with-config-file-path=/etc -with-gettext --with-ttf --enable-exif --with-pear --enable-gd-native-ttf  --with-freetype-dir=/usr/include/freetype2/freetype --with-jpeg-dir=/usr/bin --with-png-dir=/usr/bin --enable-calendar --with-libdir=lib64

Ok, so now PHP is installed/upgraded and now we need to compile and install the Suhosin extension.

cd /root/phptemp;cd suhosin-0.9.31
phpize
./configure
make
make install
vi /etc/php.ini

Find the extensions section (Or just append to the bottom)

extension=suhosin.so

This is not a complete resource for install PHP and Suhosin. I really recommend you read about Suhosin on their website. It is best if you understand this really amazing product.

Now the Suhosin extension is installed, and enabled, but some of the other extensions may or may not of been enabled. Use the above syntax of extension=name.so to enable them, restarted Apache after each one to make sure everything works OK.

PHP can be dangerous if configured improperly, and very useful if configured properly. Here is some common options I use.

Disable some dangerous functions

disable_functions = "apache_child_terminate, apache_setenv, define_syslog_variables, escapeshellarg, escapeshellcmd, eval, exec, fp, fput, ftp_connect, ftp_exec, ftp_get,ftp_login, ftp_nb_fput,ftp_put, ftp_raw, ftp_rawlist, highlight_file, ini_alter, ini_get_all, ini_restore, inject_code, mysql_pconnect, openlog, passthru, php_uname, phpAds_remoteInfo, phpAds_XmlRpc, phpAds_xmlrpcDecode,phpAds_xmlrpcEncode, popen, posix_getpwuid, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid,posix_setuid, posix_setuid, posix_uname, shell_exec, syslog, system, xmlrpc_entity_decode,proc_close, proc_get_status, proc_nice, proc_open, proc_terminate"

I set all of my open_basedir options for each virtual host, but I also set a default option just in case. For my server, I have Apache setup using the webroot /chroot/www with a symlink /www pointing to /chroot/www. In my php.ini file, I set open_basedir = /www as a failsafe.

Load some useful extensions

extension=fileinfo.so
extension=imagick.so
extension=imap.so
extension=suhosin.so
extension=zip.so

LAMP Server Setup Pt. 1 – Installing Apache HTTP Server
LAMP Server Setup Pt. 2 – Installing Mod_Security
LAMP Server Setup Pt. 3 – Installing Mod_Chroot
LAMP Server Setup Pt. 4 – Installing PHP
LAMP Server Setup Pt. 5 – Configuring Apache

Linux – Resize a directory of pictures

03 May
May 3, 2010

In Linux, resizing a large amount of pictures is very simple. This is a neat little command line script perfect for making thumbnails to go on websites or what not, and I’ve used it in some PHP websites before.

for i in *.jpg; do convert -resize 640x480! -quality 75 "$i" thumb/"$i"; done

The script shouldn’t be too difficult to understand. It loops through every file in the directory ending with a .jpg extension. Change this as required. It than runs the convert program, part of the ImageMagick program which should be available via your distribution’s package manager. It resizes it to the dimensions specified (width x height in pixels). The thumbnails will have 75% quality (To reduce size), and be stored in the thumb sub directory of the current directory.