Prism PHP Support

If you follow me on GitHub you may have noticed that I forked and committed quite a bit to the wonderful Prism JS project by Lea Verou. If you don't know what Prism is, it's a lightweight syntax highlighter written in JavaScript. It's what powers the syntax highlighting for my code blocks.

My major contribution to the project was full PHP highlighting support (including 5.3 and 5.4), as well as some improvements to the C-Like language and the inclusion of the CSS extras language. Take a look at the PHP snippet below which is taken from my Titon\Model project.

/**
 * @copyright	Copyright 2010-2013, The Titon Project
 * @license		http://opensource.org/licenses/bsd-license.php
 * @link		http://titon.io
 */
namespace Titon\Model;
use Titon\Common\Base;
use Titon\Common\Traits\Attachable;
use Titon\Model\Relation;
class Model extends Base {
	use Attachable;
	protected $_config = [
		'connection' => 'default',
		'table' => '',
		'prefix' => '',
		'primaryKey' => 'id',
		'displayField' => ['title', 'name', 'id'],
		'entity' => 'Titon\Model\Entity'
	];
	public function addRelation(Relation $relation) {
		$this->_relations[$relation->getAlias()] = $relation;
		$this->attachObject([
			'alias' => $relation->getAlias(),
			'class' => $relation->getModel(),
			'interface' => 'Titon\Model\Model'
		]);
		return $relation;
	}
	public function createTable(array $options = [], $temporary = false) {
		$schema = $this->getSchema();
		$schema->addOptions($options + [
			Dialect::ENGINE => 'InnoDB',
			Dialect::CHARACTER_SET => $this->getDriver()->getEncoding()
		]);
		return (bool) $this->query(Query::CREATE_TABLE)
			->attribute('temporary', $temporary)
			->schema($schema)
			->save();
	}
	public function getPrimaryKey() {
		return $this->cache(__METHOD__, function() {
			$pk = $this->config->primaryKey;
			$schema = $this->getSchema();
			if ($schema->hasColumn($pk)) {
				return $pk;
			}
			if ($pk = $schema->getPrimaryKey()) {
				return $pk['columns'][0];
			}
			return 'id';
		});
	}
}

The language also supports seamless integration with HTML markup. The snippet below is taken from my Titon\Debug project.

<div class="titon-debug">
	<div class="debug-head">
		<abbr title="<?php echo $file; ?>" class="debug-file">
			<?php echo self::parseFile($file) . ':'; ?><!--
			--><span class="debug-line"><?php echo $line; ?></span>
		</abbr>
	</div>
	<?php foreach ($vars as $var) { ?>
		<div class="debug-output">
			<?php if (isset($dump)) {
				echo self::_renderTemplate('table', array('value' => $var));
			} else { ?>
				<pre><code><?php echo \Titon\esc(print_r($var, true)); ?></code></pre>
			<?php } ?>
		</div>
	<?php } ?>
</div>

I hope you all find use in this contribution! Feel free to report any issues or suggestions to me.

GitHub, my new home

As I mentioned in my previous posts, I took the jump and moved over to GitHub. I moved over to a public repository system to make it easier on me pushing my code changes to the public (the current download system on my site isn't too intuitive). So over the past few weeks I have been slowly adding all my scripts to GitHub and pushing the code. Additionally, I have been uploading the old zipped versions of the scripts, which can be found on the respective repo's downloads page. I would of done and SVN import into Git, but it kept stalling every time I did so, oh well!

With the move to GitHub, I have updated all the download links and buttons on the site. It either asks you to download the files, or clone the repo (both of which will bring you to do the GitHub page). I do miss my download counter though... I really wish GitHub had a total downloads/clones feature.

Anyways, you can find my GitHub at the user milesj. I will be pushing all my changes and code here from now on using Git, but will still keep updating the change log on this site, and posting announcements about it. Now get to cloning!

Merry Gitmas

Well Christmas is right around the corner, and I would like to wish all of my readers and visitors a happy holiday! I hope you all enjoy the holidays with your friends and loved ones and get the most out of this break that you can. I know I sure will! Speaking of which, I am leaving tomorrow for Toronto, Canada, where I will be spending the next two weeks with my girlfriend and her fathers family, should be amazing to say the least!

The holidays are not what this blog post is really about, the main point is that I am now a member of GitHub. I know many of you have been asking me to do this for some time now. It took me a while to find a Windows solution that I was happy with, and to say the least, Git Extensions is working wonderfully so far! So wonderfully that I will be posting a few entries on how to install and use it. Right now all my CakePHP scripts are on GitHub for your cloning and forking pleasure. I will be adding my other classes shortly, but I'm sure most of you are more interested in the CakePHP ones, so enjoy!

If you find a bug in my script, either fork it and fix it, or post an issue on the GitHub page. I will merge with your changes if they work. Thanks again and Happy Holidays!

GitHub: http://github.com/milesj

Uploader Plugin officially released!

For the past month I have been talking about CakePHPs lack of a built in uploader component or mechanism, and how I wanted to build one. Well wouldn't it be great if I actually did build it? Oh wait, what is this? I did build one? Yes. Is it released? Yes. May I use it? Of course! The Uploader is primarily used as an all purpose file uploader and was built to not interact with a model/database. Here is a quick rundown of the plugin.

The plugin comes bundled with an uploader component and a validation behavior. The component is used to upload the files to a destination, resize or generate images, validate against mime types, log errors, scan for viruses and more. The behavior is used to add validation rules to a model to check against image uploads.

A big thank you to http://mark-story.com/ and Matt Curry for beta testing and giving input and ideas.

- Download Uploader v1.3 and view full documentation

Two new scripts, Resession and Decoda

It has been a while since I released some of my scripts, but now I have two to reveal! Well actually the Resession script has been up for nearly 2 months now, but I'm finally getting around to announcing. And without further ado, I give you Resession (Session Manager) and Decoda (A BBcode style parser).

Decoda

Decoda is a lightweight class that extracts and parses a custom markup language; based on the concept of BB code. Decoda supports all the basic HTML tags and manages special features for making links and emails auto-clickable, using shorthand emails and links, and finally allowing the user to add their own code tags.

Download the latest versions of Decoda

Resession

A small lightweight script that can manage and manipulate Session data. Calls session_start() in memory so that no header errors are thrown, as well as stores the session id in the object.

Download the latest version of Resession

If you have any suggestions for either of these classes, please feel free to comment this post or send me an email!

XAMPP in Windows: Setting up vHosts

If you have ever used a local server, you would immediately realize that you can only develop one site at a time using the given root. You could however setup multiple folders for different websites within your local servers root, but the problem with that is they would all share the same root, big problem! To fix this you would have to set up virtual hosts, or vhosts for short. A vhost is a small server side trick (using Apache) that allows for multiple domains (websites) under the same root or IP address.

To get this working in XAMPP, we will need to edit our hosts file and the httpd-vhosts.conf file within your XAMPP setup. But before we begin, lets set up a quick example of what we will be trying to achieve. We will want to setup two websites within the htdocs folder, we will create 2 folders with the first one "site1" and the second "site2" (you can name these whatever you wish).

The first thing we need to do is open the Windows hosts with Notepad, which can be located at C:/WINDOWS/system32/drivers/etc. If you are using Windows Vista, you will need to right click on Notepad and click "Run as Administrator" to be able to open the hosts file. Once you have opened the hosts file, add the following 2 lines to the file and save it.

127.0.0.1		site1
127.0.0.1		site2

Secondly we will need to open the vhosts file located at C:/xampp/apache/conf/extra/httpd-vhosts.conf and add the following code. Copy and paste this code for each additional vhost you wish to setup.

# Uncomment the following
NameVirtualHost *:80 
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot C:/xampp/htdocs/site1
	ServerName site1
	<Directory "C:/xampp/htdocs/site1">
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot C:/xampp/htdocs/site2
	ServerName site2
	<Directory "C:/xampp/htdocs/site2">
		Options Indexes FollowSymLinks Includes ExecCGI
		AllowOverride All
		Order allow,deny
		Allow from all
	</Directory>
</VirtualHost>

Once you have completed both these tasks you must restart Apache. Once restarted, you can go to http://site1/ and all files and folders within "site1" should be displayed. You may do this for as many websites as you wish, just make sure to complete both tasks!

Fixing a weird cache issue in Firefox

About two weeks ago my Firefox started acting up and would not cache pages correctly. Actually, the content would cache, but any image on the actual page would load 1 by 1 and I can watch it go in sequence. This was extremely annoying, especially working in PhpMyAdmin, watching each image icon load 1 by 1 until the page was complete. This process would take nearly 5x what it usually did, so it got quite annoying real fast. I wasn't sure what caused this to happen as all my settings were normal and untouched.

So once I had enough of this, I checked Firefoxs core config (by typing about:config in the address bar). I then typed "cache" in the filter field and once it populated, I noticed the following fields were set to false (turned off).

browser.cache.disk.enable
browser.cache.memory.enable

Once I reset these to defaults (enabling it to true), my weird image cache problem vanished. I am not entirely sure if messing with these settings are ok, so if anyone has any input on the subject it would be appreciated. But besides that, everything seems to be running smoothly, and I thought it would be a good idea to let others know in case they run into it as well.

Databasic v2.0 has arrived!

I am proud to present the new Databasic, version 2.0! Since I added quite a few new methods and functionality, rewrote and optimized most of the code, I felt it would be good to deem this version 2.0 instead of 1.11. The biggest new features in this version are support for multiple databases, using the create() method to create a database table, and the addition of many MySQL statement methods. Some of these new methods include drop(), truncate(), describe(), create() and optimize(). On top of all these additions, I have cleaned the code and fixed any bugs that were existent.

Note before upgrading! The new 2.0 version is not necessarily backwards compatible, the new system removes the constants that are used for the connection info, and instead uses a new method called store() that can store multiple connections. Finally the select() method has been changed, the arguments $limit and $offset have been removed and are now part of the $options array.

You may now subscribe to my newsletter, that will be send out emails when a script has a new version available.

Download Databasic v2.0
View the complete change log

XAMPP in Windows: Enabling InnoDB

I recently convinced my friend to start learning CakePHP and to install XAMPP for windows. Everything was going smoothly up until he needed to have the database engine InnoDB enabled. Here's a very quick tutorial on how to enable InnoDB on Windows XAMPP (might also work with other local servers).

I'm assuming you have installed the XAMPP directory into the root or C:/ drive. The first thing to do is to open the my.cnf located at C:/xampp/mysql/bin/my.cnf (Notice Your my.cnf file may have an icon that looks like a computer/phone and has a type called SpeedDial. Do not worry, this is the correct file. To open the file, first start Notepad and then locate the my.cnf file and open it). Locate the text below and add # to the beginning of it (# acts as a comment and disables the command).

#skip-innodb

The next and final step is to remove # from any line the begins with innodb_. Your file should now look something like the following. Once you have done this, save the file and InnoDB should be useable in your local server.

#skip-innodb
innodb_data_home_dir = "C:/xampp/mysql/"
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = "C:/xampp/mysql/"
innodb_log_arch_dir = "C:/xampp/mysql/"
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

Databasic v1.10.2 Released

I have just released a new version of my MySQL database class, Databasic. This new version fixes a few issues with binds, MySQL functions and little bugs here and there. I have also added an "takes x seconds to execute the query" to every query in debug mode, no idea why I didn't add it before!

Update! There was a small bug in version 1.10.1 concerning the execute() method. I just patched it to 1.10.2, enjoy!

Download Databasic v1.10.2
View the complete change log