Marc Blase

Fix WordPress’ default attachment “link to” setting

I say fix since this is a mild annoyance of mine. Anywho, here’s the fix.

1. Direct your web browser to: http://MY_DOMAIN_NAME.TLD/wp-admin/options.php

2. Look for image_default_link_type

3. Fix it. Delete the contents of the corresponding field. If you want to change it, the available values are: “”, “file”, “post”.

Published on August 15, 2014

World Clock

Awesome World Clock created by xkcd.

Published on February 26, 2014

How to CHMOD web files properly

To change all the directories to 755 (-rwxr-xr-x):

find /path/to/web/dir -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r–r–):

find /path/to/web/dir -type f -exec chmod 644 {} \;

chmod 644 {} \; specifies the command that will be executed by find for each file. {} is replaced by the file path, and the semicolon denotes the end of the command (escaped, otherwise it would be interpreted by the shell instead of find).

or alternatively, you could do the following:

chmod -R a+rX ./*

The X (that is capital X, not small x!) is ignored for files (unless they are executable for someone already) but is used for directories.

Thanks for the answers once again Stack Overflow.

Published on January 15, 2014

Millionaire Chicken

I am posting this here for the sake of posterity. Without further ado:

Millionaire Chicken Recipe

Published on January 1, 2014

2013 Top Listens

Straight from my LastFM profile:

  1. Guards (244)
  2. Born Ruffians (204)
  3. Courtney Barnett (204)
  4. Ghost Wave (194)
  5. Shout Out Louds (170)
  6. Mikal Cronin (166)
  7. The National (164)
  8. Yo La Tengo (156)
  9. BOAT (147)
  10. Arcade Fire (142)
  11. Diarrhea Planet (142)
  12. Beach Fossils (141)
  13. Colleen Green (134)
  14. Frankie Rose (132)
  15. Phosphorescent (129)
  16. Palma Violets (117)
  17. Bored Nothing (113)
  18. Ducktails (111)
  19. Psychic Ills (110)
  20. IO Echo (108)
  21. Starfucker (105)
  22. Mazes (99)
  23. Portugal. The Man (97)
  24. Belle and Sebastian (96)
  25. Deer Tick (96)
  26. Parenthetical Girls (93)
  27. The Joy Formidable (91)
  28. Those Darlins (89)
  29. HAIM (88)
  30. The Little Ones (88)
  31. The Pack A.D. (88)
  32. Surfer Blood (88)
  33. Psychic Friend (87)
  34. Dead Gaze (86)
  35. Foxygen (84)
  36. Surf City (81)
  37. Bass Drum of Death (80)
  38. The Spinto Band (78)
  39. Gold Fields (78)
  40. Bent Shapes (77)
  41. Nude Beach (76)
  42. Shannon and the Clams (74)
  43. Austra (72)
  44. Brazos (71)
  45. Daughn Gibson (71)
  46. The Thermals (70)
  47. The Avett Brothers (70)
  48. Lightning Dust (70)
  49. Small Black (70)
  50. Crocodiles (69)
Published on January 1, 2014

Sorry ‘cp’ I’m gonna be spending more time with ‘rsync’ now

So just updated my dev machine and was transferring files back to it via cp which was taking a long time. I just wanted to know how far along the command had progressed via a percentage/progress bar/etc. so that I could get a cup of coffee, or make lunch – if it was gonna take a very long time. I know it’s possible to do this but not by using cp alone.

So I found rsync after a little bit of googling. The part that I really like about it is the --progress option, which let’s you know via stdout how far along the command is.

Here is a basic example:

rsync --progress -a /path/to/source /path/to/destination

– This will copy a directory, show progress, and maintain ownership, permissions, modified via the -a option (Archive).

or, over the network:

rsync -zP /path/to/source handle@domain.tld:/path/to/destination

– This will copy source over the network connection specified, use compression, show progress and allow for continuing interrupted transfers.

P.S. As a preemptive measure you could also run du -sh on dirs before copying to get an idea of how big they actually are.

Published on December 3, 2013

Don’t store anything you need in /tmp

I know better but thought I’d write it here so I don’t forget. Again. Darn.

Here’s a black hole.
153309main_hidden_blackhole_lg
Image credit: NASA

Published on October 21, 2013

PHP and JS Email Obfuscator

I have been using some great email obfuscation code created by Ross Killen ,Tim Williams and Andrew Moulden. And like Andrew’s generator that allows for “link text”, I needed a PHP solution for sites I’m developing. So here’s my twist:

function munge($address,$link_text) {
	$address = strtolower($address);
	$coded = "";
	$unmixedkey = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.@-_";
	$inprogresskey = $unmixedkey;
	$mixedkey="";
	$unshuffled = strlen($unmixedkey);
	for ($i = 1; $i <= strlen($unmixedkey); $i++) {
        // set i = 1 because i = 0 was throwing an offset error in PHP 
		$ranpos = rand(0,$unshuffled-1);
		$nextchar = $inprogresskey{$ranpos};
		$mixedkey .= $nextchar;
		$before = substr($inprogresskey,0,$ranpos);
		$after = substr($inprogresskey,$ranpos+1,$unshuffled-($ranpos+1));
		$inprogresskey = $before.''.$after;
		$unshuffled -= 1;
	}
	$cipher = $mixedkey;
	$shift = strlen($address);
	$txt = "<script type=\"text/javascript\" language=\"javascript\">\n" .
           "<!-"."-\n" .
           "// Email obfuscator script 2.1 by Tim Williams, University of Arizona\n".
		   "// Random encryption key feature by Andrew Moulden, Site Engineering Ltd\n".
		   "// PHP version coded by Ross Killen, Celtic Productions Ltd\n".
		   "// This code is freeware provided these six comment lines remain intact\n".
		   "// A wizard to generate this code is at http://www.jottings.com/obfuscator/\n".
		   "// The PHP code may be obtained from http://www.celticproductions.net/\n\n";
		   
	for ($j=0; $j<strlen($address); $j++) {
		if (strpos($cipher,$address{$j}) == -1 ) {
			$chr = $address{$j};
			$coded .= $address{$j};
		} else {
			$chr = (strpos($cipher,$address{$j}) + $shift) %
			strlen($cipher);
			$coded .= $cipher{$chr};
		}
	}
	
	if($link_text):
	
		$link_text_block = "document.write(\"<a href='mailto:\"+link+\"'>" . $link_text . "</a>\")\n";
		
	else:
		
		$link_text_block = "document.write(\"<a href='mailto:\"+link+\"'>\"+link+\"</a>\")\n";
		
	endif;
		
	$txt .= "\ncoded = \"" . $coded . "\"\n" .
			"  key = \"".$cipher."\"\n".
			"  shift=coded.length\n".
			"  link=\"\"\n".
			"  for (i=0; i<coded.length; i++) {\n" .
			"    if (key.indexOf(coded.charAt(i))==-1) {\n" .
			"      ltr = coded.charAt(i)\n" .
			"      link += (ltr)\n" .
			"    }\n" .
			"    else {     \n".
			"      ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length\n".
			"      link += (key.charAt(ltr))\n".
			"    }\n".
			"  }\n".
			// Original link markup
			//"document.write(\"<a href='mailto:\"+link+\"'>\"+link+\"</a>\")\n" .
			// Link markup from above
                        $link_text_block .
			"\n".
			"//-"."->\n" .
			"<" . "/script><noscript>Please turn on javascript to email me." .
			"<"."/noscript>";
	
	return $txt;
}
Published on October 16, 2013

Force page template on child pages in WordPress

This is something that could come in handy. I’ve found a need for it in using the Nextgen Gallery plugin with the gallery page link setting enabled.

// Force page template on child pages
$page_children = get_pages('child_of=13');
foreach($page_children as $child){
	$current_page_template = get_post_meta($child->ID,'_wp_page_template',true);
	if($current_page_template != 'page-OTHER_PAGE_TEMPLATE.php') update_post_meta($child->ID,'_wp_page_template','page-PARENT_PAGE_TEMPLATE.php');
}
Published on August 21, 2013

Download CSS images with WGET

Sometimes you just don’t have the access you need when working on a site. While the thought of downloading all the included files individually sounds like fun, there’s always a better use of time. So I did some research and found that the best solution is via the command line using WGET. Here’s the command:

wget --page-requisites http://site/path/page.html

If you need to download a whole site, give this a go:

wget -m -p -E -k -K -np http://site/path/

Thanks stackoverflow users for this solution.

UPDATE:

I ran into an issue in trying to backup a WP site for a client where the original dev took it hostage and wouldn’t release it. They had turned on the “Discourage search engines” option in the admin and WGET was failing. So here’s a new method to circumvent a robots.txt file with Disallow: /.

wget -e robots=off -k -K  -E -r -l 10 -p -N -F --restrict-file-names=windows -nH http://DOMAIN.TLD/

UPDATE:

I ran into an issue with a client site hosted on a SaaS Member Solutions website. Some of the assets/URLs/etc if not used/placed properly would use the clients proxy URL for the service, eg. https://client-service-url.com — so when running the above WGET commands anything that used the proxy URL would not be downloaded. Thus spawned the following which uses the -D flag.

wget -e robots=off -k -K -r -l 3 -E -p -N -F --restrict-file-names=windows -D CLIENT_DOMAIN.com,CLIENT_VARIANT_DOMAIN.com -w 1 -nH https://CLIENT_DOMAIN.com
Published on July 9, 2013