Archive for the ‘PHP’ Category

wordpress theme updates

Try as I may to switch to another CMS, I keep falling back to WordPress. My last attempt was Drupal, which I quickly grew tired of. WordPress doesn’t do everything I would like it to do, but the things it does are amazing.

I’ve been working a bit on my theme to add some extra functionality. Here’s what we’ve gotten so far:

  • Three column format: My sidebar were getting a bit too long, so I split it in two.
  • Variable width layout: Because there are three columns, I needed a bit of extra horizontal space. I was getting tired of the fixed width/centered layout, so I implemented the variable width middle column to hold the main content.
  • HTML5: I’m using quite a few HTML5 specific tags in my theme, but everything should also be ok in older browsers too. It was a bit of a beast getting rid of the XHTML-ness that WordPress puts in automatically, but I’m getting there.
  • CSS 3: Some CSS 3 eye candy here and there (rounded corners, gradients, etc).

Now that the most current version of each of the major browsers support HTML5 and CSS 3, I’m going to be relying on them pretty heavily here.

And for those who refuse to upgrade … well, sorry :)

Comments? Smart remarks?

Creating your own self-signed certificates and keys (UPDATED)

I’ve set up a little PHP page that will generate self-signed certificates and bundle the associated private key in a PKCS12 file:

http://content.cryptofreek.org/pkcs12/

Basically it uses OpenSSL like this:

openssl genrsa -aes256 2048 > temp.key
openssl req -new -x509 -key temp.key -out temp.crt -days 365 -subj "/CN=John\ Doe/emailAddress=john.doe@mail.com"
openssl pkcs12 -export -in temp.crt -out temp.p12 -name "my self signed P12 from cryptofreek.org" -inkey temp.key

It’s a handy little utility; a quick and dirty way to generate certificates for testing. I’m sure that I will be broaden the features soon.

Originally wrote some bash scripts that used the “openssl” command on the server, but it was kinda hokey with a bit too much file IO.

Now, the backend has been rewritten to use the (sparsely documented) OpenSSL functions in PHP.

PHP HashTable implementation

Here’s a quick/dirty HashTable implementation for PHP (based on the Java Hashtable API).  There are probably better ones, but for what it’s worth … here ya go:

class CHashTable
{
  private $_arr = null;

  function __construct()
  {
    $this->_arr = array();
  }

  function clear()
  {
    unset( $this->_arr );
    $this->_arr = array();
  }

  function contains($value, $bStrict=false)
  {
    return in_array($value, $this->_arr, $bStrict);
  }

  function containsKey($key)
  {
    return array_key_exists($key, $this->_arr);
  }

  function containsValue($value, $bStrict=false)
  {
    return $this->contains($value, $bStrict);
  }

  function get($key)
  {
    $value = null;

    if( array_key_exists($key, $this->_arr) )
    {
      $value = $this->_arr[$key];
    }

    return $value;
  }

  function isEmpty()
  {
    return ($this->size()<=0);   }   function keys()   {     return array_keys($this->_arr);
  }

  function put($key, $value)
  {
    $this->_arr[$key] = $value;
  }

  function putAll($arr)
  {
    if( $arr!==null )
    {
      if( is_array($arr) )
      {
        $this->_arr = array_merge($this->_arr, $arr);
      }
      else if( $arr instanceof CHashTable )
      {
        $this->_arr = array_merge($this->_arr, $arr->_arr);
      }
    }
  }

  function remove($key)
  {
    unset( $this->_arr[$key] );
  }

  function size()
  {
    return count($this->_arr);
  }

  function toString()
  {
    return print_r($this->_arr, true);
  }

  function values()
  {
    return array_values($this->_arr);
  }
}

The term “hashtable” may be a little loose  here.  There is no hashing or indexing done to increase performance.  The purpose here was to have some PHP object class to mimic the behavior of a Java Hashtable; it is really use an API wrapper around some PHP associative array.  It makes my life easier when porting code.

There may be some issues here, I haven’t really put it through it’s paces yet.  I’m writing some database code and needed a base class for data objects that behaves like a Hashtable.

If you have any constructive comments/suggestions, let me know.  As always, the commenting rules apply…