I am mikek's Blog

The personal blog of Mike Karthauser, who you may know from Brightstorm Limited or the internet.

fixing file uploads in croogo

I tend to keep my public_html folder at the same level as app folder when working in cakePHP.

Croogo is set up to serve the webroot folder from inside the app folder by default, so if you move your public_html directory then you’ll also need to ensure your file uploads still work.

look in app/views/helpers/image.php

and change the $fullpath and $url to match your directory path.

mine is

$fullpath = ROOT.DS.WEBROOT_DIR.DS.$uploadsDir.DS;
$url = ROOT.DS.WEBROOT_DIR.DS.$path;

Filed under: Uncategorized , ,

Dealing with wildcards in croogo

i’ve been looking into wildcards for visibility paths primarity so I can add a block into my news/view page without specifying all my news articles.

inside blocks function within croogo component, there is a query which checks the url:

'Block.visibility_paths LIKE' => '%"' . $this->controller->params['url']['url'] . '"%',

obviously, adding news/* wont match so no block in this instance.

The solution I settled on was to modify the conditions and add another check:

I replaced:

'conditions' => array(
'Block.status' => 1,
'Block.region_id' => $regionId,
'AND' => array(
array(
'OR' => array(
'Block.visibility_roles' => '',
'Block.visibility_roles LIKE' => '%"' . $this->roleId . '"%',
),
),
array(
'OR' => array(
'Block.visibility_paths' => '',
'Block.visibility_paths LIKE' => '%"' . $this->controller->params['url']['url'] . '"%',
//'Block.visibility_paths LIKE' => '%"' . 'controller:' . $this->params['controller'] . '"%',
//'Block.visibility_paths LIKE' => '%"' . 'controller:' . $this->params['controller'] . '/' . 'action:' . $this->params['action'] . '"%',
),
),
),
),

With:

'conditions' => array(
'Block.status' => 1,
'Block.region_id' => $regionId,
'AND' => array(
array(
'OR' => array(
'Block.visibility_roles' => '',
'Block.visibility_roles LIKE' => '%"' . $this->roleId . '"%',
),
),
array(
'OR' => array(
array('Block.visibility_paths LIKE' => '%"' . $this->controller->params['url']['url'] . '"%'),
array(
'Block.visibility_paths LIKE' => '%"' .
'controller:' . $this->controller->params['controller'] . '/' .
'action:' . $this->controller->params['action'] . '/'.
'type:' . $this->controller->params['named']['type'] .
'"%',
),
),
),
),
),

This then allows the addition of the following in visibility paths


controller:nodes/action:view/type:news

to get our result.

Filed under: code snippets, development , ,

Cleaning up repositories

I’ve given a lot of files that once were in a mercurial repository but now need adding into another one.

Like with svn, mercurial file trees have hidden folders containing details about the commit history. If these get added into a new repo, things stop working properly.

The trick is to recursively delete these folders then all is good.


// find and remove .hg files in the filesystem
find . -name ".hg" -exec rm -rf {} \;


// works with svn files as well
find . -name ".svn" -exec rm -rf {} \;

Filed under: code snippets, development , , ,

Enabling CSS for themes in Croogo

Croogo is a free and open source content management system, built on top of CakePHP framework.

A little tweak to your .htaccess file in Croogo will get your css serving correctly from within your themes directory.

Look in your webroot/.htaccess


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

And amend to:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Options -MultiViews

Filed under: code snippets, development ,

Viewing html source in mobile Safari on iPad and iPhone

A neat bit of javascript which allows you to view html source on an iPad or iPhone.


javascript:(function(){
var w = window.open('about:blank'),
s = w.document;
s.write('Source of ' + location.href + '');
s.close();

var pre = s.body.appendChild(s.createElement("pre"));
pre.style.overflow = 'auto';
pre.style.whiteSpace = 'pre-wrap';
pre.appendChild(s.createTextNode(document.documentElement.innerHTML));
})();

Just copy and save as a bookmarklet on mobile safari.

All credit for this goes to Rob Flaherty at Ravel Rumba.

For more details and a link to the bookmarklet – visit http://www.ravelrumba.com/blog/ipad-view-source-bookmarklet/

Filed under: code snippets

Rsync’ing backups

Syntax
$ rsync options source destination

To syncronise directories between servers you can do the follow:

rsync -avz LOCALDIRECTORY / REMOTEUSER@REMOTEHOST:REMOTEFILEPATH

See more

Filed under: development

CakePHP virtual Fields

Something pretty useful in the CakePHP right now is VirtualFields.

A virtual field is a way to combine several fields to make a new ‘virtual’ one that exists when you read from the model. So with ‘firstname’ and ‘surname’ you can make a ‘full_name’ field which will allow you to use this within a find(‘list’) – a notoriously tricky task otherwise.

To do this on the User Model for example, just add the following to your app/models/user.php.

var $virtualFields = array(
'full_name' => 'CONCAT(User.firstname, " ", User.surname)'
);

Simple and powerful.

Available in CakePHP 1.3.*

Filed under: code snippets , , ,

New label designs at wilko

Wilkinsons is a shop selling low priced general hardware, pharmacy and sundries.

On a trip recently we discoved that Wilkinsons have updated their own brand product labelling. The update has produced a charming and playful set of labels which we were so delighted with that we went round the store hunting for the new labelling, some of which included below.

complete food for adult working and sporting dogscomplete food for adult working and sporting dogs

tomato feedtomato feed

ant & crawling insect killerant & crawling insect killer

squeeze sponge mopsqueeze sponge mop

rose & flower bug killerrose & flower bug killer

To see more, check out my flickr set.

Filed under: Uncategorized

Strategic Content Management

“Trying to fix an organization’s content problems by installing a content management system (CMS) is like trying to save a marriage by booking a holiday.”

A very insightful article about writing content management systems – http://www.alistapart.com/articles/strategic-content-management/

Filed under: development , ,

Ordering results on google base

By default, results returned by the Google Base data API are sorted according to relevancy. You can change the order by using the orderby parameter. Possible values for this parameter can be found here:

http://code.google.com/apis/base/snippets-feed.html#Parameters

I’m particularly interested in returning the lowest price first which can be achieved by adding the following:
&orderby=price(float%20GBP)

to your base query.

to change sort order,

&sortorder=descending|descending

For more information about format and implementation
http://code.google.com/apis/base/samples/javascript/javascript-sample-autosmasher.html

Filed under: development , ,

what's hot

Flickr Photos

batteries

A4 scrap book

compost

More Photos

Sponsor Mike run the Bath Half marathon

mikek on twitter

Follow

Get every new post delivered to your Inbox.