Troy Thompson

Web Developer

  1. Remove Unwanted Drupal Module JS and CSS

    Published
    Tagged
    Content

    You need to edit the template.php in your drupal theme.

    Add the following.

    function _phptemplate_variables($hook, $vars = array() )
    {
    	$css = drupal_add_css();
    	unset($css['all']['module']);
    	unset($css['all']['module'][drupal_get_path('module','cck').'/date.css']);//xtra example
    	unset($css['all']['module'][drupal_get_path('module','cck').'/fieldgroup.css']);//xtra example
    	$css['all']['module']['modules/thickbox/thickbox.css'] = 1;
    	$vars['styles'] = drupal_get_css($css);
    
    	$js = drupal_add_js();
    	unset($js['module']['sites/all/modules/ubercart/uc_cart/uc_cart_block.js?79487']);
    	unset($js['module']['modules/thickbox/thickbox.js']);
    	$vars['scripts'] = drupal_get_js('header', $js);	
    
    	return $vars;
    }
    

  2. Searching on Multiple Fields in CakePHP

    Published
    Last Updated
    May 04 2008
    Tagged
    Content

    Lets say you want to provide users with a way to search for authors in CakePHP.

    Your authors table looks something like ( id, firstname, lastname, bio ).

    Usually when you want to search on something like this you would do the following.

    SELECT * FROM authors WHERE lname LIKE '%Jon%' OR lname LIKE '%Jon%';

    Great, you found Jon, but what if you replaced the above query with "Jon Doe"?

    SELECT * FROM authors WHERE lname LIKE '%Jon Doe%' OR lname LIKE '%Jon Doe%';

    Crap, we can't find Jon anymore. Okay how about the following:

    SELECT * FROM authors WHERE concat(fname,' ',lname) like '%Jon Doe%';

    Aha! We found Jon Doe again.

    But what if we searched for "Doe Jon". Again, we are not able to find Jon Doe.

    So now what? Well MySQL lets you build a fulltext index on multiple fields.
    Execute the following query.

    ALTER TABLE `authors` ADD FULLTEXT `fullname` (`fname`,`lname`);

    This allows us to do things like

    SELECT * FROM authors WHERE match(fname,lname) against ('doe jon' IN BOOLEAN MODE);

    And still get Jon Doe. :-)

    Now you can fight this fulltext search stuff all you want, but you're just going to end up with a huge query that doesn't perform as well as a fulltext query.

    If you have a database that does not support this, then you should consider upgrading if you can.
    Here is some code that creates a query that does a search on each field without fulltext indexing.

    Using a fulltext query in CakePHP is a matter of using the following condition ( yes, this is very hacky looking ):

    $paginator_options['conditions'] = array("1" => "1 AND MATCH(Author.fname,Author.lname) AGAINST('{$conditions['Author.search']}*' IN BOOLEAN MODE )");
    $this->set('authors', $this->paginate($paginator_options));

  3. Howto Create a hotkey to commit in Subclipse

    Published
    Tagged
    Content

    I use Subclipse as a plugin for Eclipse / Aptana, and there is no hotkey to perform a commit. This means anytime you want to commit something you have to navigate the file tree and then the context menus to commit, I'd rather not leave the keyboard to do a commit.

    So after some digging around I figured out how to add a hotkey, and I wanted to share.

    Open Eclipse / Aptana

    Window > Preferences

    In the filter box, type "keys"

    Scroll to "Save All" and double click it.

    In the Command field set change the Category to "SVN"

    Change the Name to "&Commit..."

    Change the key sequence to the key combo you want to perform a commit. I use alt + shift + s, but that might be weird for some folks.

    Click Add

    If you were successful you should be able to use your key combo to perform a commit for now on.

  4. 99 Boxes

    Published
    Tagged
    Content

    I used to have this game called 99 Boxes on my Palm, and a month go I felt like recreating it in jQuery for fun.
    I don't know who the original creator was, but this is the game.

    (more...)

  5. WordPress Minor update, and why I love SVN

    Published
    Tagged
    Content

    So a minor WordPress released an update 3 days ago. If you don't update, one could use xmlrpc.php to edit posts on your blog, too bad a majority of WordPress users do not know it or can't be troubled to upgrade.

    Honestly, if I were on 2.3.2 and didn't have SVN I probably would not upgrade either.

    However, I was able to upgrade 3 sites in less than 10 minutes with SVN. :-)

    Note, I use the branch and not the trunk, there is a misconception that if you're using SVN WordPress you're using bleeding edge software that is unstable.
    Even the WordPress Subversion Access page shows an example of checking out from the trunk, which is a bad idea unless your developing a plugin for a later version of WordPress.

    The WordPress branch has been stable for me so far, but I only update when I hear an announcement or I'm feeling experimental.

    You can also use svn externals to automatically update plugins.

    Just navigate to wordpress plugins directory
    type “svn pe svn:externals .”
    e.g.
    akismet http://svn.wp-plugins.org/akismet/trunk/
    audit-trail http://svn.wp-plugins.org/audit-trail/trunk/
    etc.

    Save, then "svn up".