PHP Event API

Events

I tried a couple of existing plugin solutions most did 95% of what I needed and the other 5% was next to impossible to force.

After wasting days I decided I would write my own, what follows is an overview of Tentacle event API.

Contact me if you have any questions.

Registering an event:

[sourcecode language="php"]
function method_one (){
echo ‘one ‘;
}

function method_two (){
echo ‘two ‘;
}

event::on(‘event_trigger’, ‘method_one’, 2);
event::on(‘event_trigger’, ‘method_two’, 1);

event::trigger(‘event_trigger’);
[/sourcecode]

Turning events off:

[sourcecode language="php"]event::off(‘event_trigger’);

event::off(‘event_trigger’, ‘method_two’);

event::off(null, ‘method_one’);[/sourcecode]

Test if an event exists:

[sourcecode language="php"]var_dump(event::exists(‘event_trigger’));
[/sourcecode]
boolean true

Trigger an event:

[sourcecode language="php"]function method_name ( )
{
echo ‘my method name’;
}

event::on(‘event_name’, ‘method_name’);

event::trigger(‘event_name’);[/sourcecode]
my method name

Trigger an event and pass data to it:

[sourcecode language="php"]function method_data ( $text = ” )
{
echo ‘ 1 my method data is ‘.$text;
}

function method_data_two ( $text = ” )
{
echo ‘ 2 my method data is ‘.$text;
}

event::on(‘event_data’, ‘method_data’, 1);
event::on(‘event_data’, ‘method_data_two’, 2);

event::trigger(‘event_data’, ‘this’);[/sourcecode]
1 my method data is this 2 my method data is this

Triggering a class and passing data to the method

[sourcecode language="php"]class my
{
static function method_name ( $text = ” )
{
echo ‘my class method name is ‘.$text;
}
}

event::on(‘event_class’, ‘my::method_name’);

event::trigger(‘event_class’, ‘Lary’);[/sourcecode]
my class method name is Lary

Event chaining

[sourcecode language="php"]function method_sad ( $text = ” )
{
return str_replace(‘blah’, "sad", $text);
}

function method_happy ( $text = ” )
{
return str_replace(‘sad’, "happy", $text);
}

event::on(‘event_mood’, ‘method_sad’, 1);
event::on(‘event_mood’, ‘method_happy’, 2);

echo event::filter(‘event_mood’, ‘I am blah!’);
[/sourcecode]
I am happy!

Making of the Tentacle upgrade script

The best scenario for keeping Tentacle up to date is using to use Git.

If for some reason you can not use git then for the majority of users we have you covered.

Tentacle updates are powered by the Serpent API. Serpent is designed to allow developers to continue their normal workflow and control when Updates are made available.

By creating a version git tag I can publish an archive file that is ready for public use.

Tentacle will have a look at its own internal version and compare it with what is available over the API at http://api.tentaclecms.com/get/core/

Read More.

Implemented Bcrypt to Hash Stored Passwords

I made a large improvement to the way we hash our user passwords.

Originally Tentacle was using the default method of hashing passwords used in Dingo, This was a SHA1 hash. Still decent but not really up to newer standards.

When a log in is processed the username and password are submitted and the password is hashed.

password turns into something like 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 and is actually stored in the database this way.

It is then possible to use brute force to gain access to a site.

 

The a advantage of using Bcrypt and specifically phpass is that the passwords are all salted and the salt is random. That means that any hash of password will never be the same.

 

This method is commonly used in WordPress, Modules for Drupal, and Typo3.

 

Here is a great Info graphic on password security.

Transient data.

Transient data is a principal borrowed from WordPress.

I have never directly used the Transient Data API but after reading the Docs saw a solid fit for Tentacle.

Transient data offers a simple and standardized way of storing cached data in the database temporarily by giving it a custom name and a timeframe after which it will expire and be deleted.

In this example I am caching an RSS feed, I used CURL to get the XML and covered it to a string ( Because you can not serialize a SimpleXMLElement Object )

Read more

Content Creation vs Management

A typical Content Management System probably does a great job at managing content, its in the title after all. The web is more about how you use and present to others then how its managed.

Lets pretend that we are adding a foodie section to our site, Our site is 9 months old and has been designed and built by a small design company.

We decided that we want to post new recipes every week and its important to our brand that we are consistent.

We are going to include some basic information:

  • Title
  • Photos
  • Ingredients
  • Directions
  • Short bio and photo of the cook.

Read more

Hierarchical Data

I am proud to announce that Tentacle will now support sub pages! That’s right! Nest as many as you want!

One of the biggest challenges I had with building this CMS is the data structure.

On paper it looks easy.

Posts will have an ID, a Parent ID, Date, Title, and so on.

Read More.

Demo Tentacle CMS

A lot has happened behind the scenes over @tentaclecms. Over the last month we have added a fea really cool features.

One of those being the WordPress shortcode API ad well as Chyrps Module API.

I finally released a demo installation of Tentacle CMS, We are still in beta so please let us know if any issues you see.

Login: http://demo.tentaclecms.com/admin/

username: demo
password: demo

Check out the site tentaclecms.com and dont forget to follow us on Twitter @tentaclecms