irakli's blog

"More" Link's URL for a Block Display in Drupal6 Views2

It is only available in the top-level theme as a variable, but in case you need to derive the same value from the View object, per se, here it is:

$view->display[$view->current_display]->handler->get_path();

Replace a Function Name in Drupal Source Files

> perl -i -pe 's/oldname_/newname_/g' `find | grep "\.module$"`

Or if you want to first check the results:

> perl -pi.bak -e 's/oldname_/newname_/g' `find | grep "\.module$"`

which will create backup of original files. Those you can delete later with:

> find . -name "*.bak" -exec rm -rf {} \;

You can replace ".module" with ".inc" or "tpl\.php" if you also need those processed

SVN: Restore Deleted Folder from a Revision

Imagine a situation: you accidentally "svn removed" an entire directory tree from SVN. If the tree contained uncommitted code you can restore it from the backup, but you also need to restore things that were in the SVN. You can approach it multiple ways, but arguably the cleanest way is to simply revert to the revision before the deletion.

How do you do that in Subversion? The answer to this is quite short, but not necessarily obvious, so following is the list of example commands:

svn co -N SVN_PARENT_URL  . 
svn copy SVN_URL@REV FOLDERNAME
(Add-in or modify here any files that were not committed, before deletion)
svn commit -m "restoring" FOLDERNAME

example:

svn co -N https://svn.ex.com/repo/project/parentfolder@7537 . 
svn copy https://svn.ex.com/repo/project/parentfolder/deletedfoldername@7537 deletedfoldername
(Add-in or modify here any files that were not committed, before deletion)
svn commit -m "restoring" deletedfoldername

Bing it on, Google! Microsoft is Back!

People who know me know that I am the last person on earth to be a Microsoft fan. I have my reasons to be a tough critic of the Redmond company, but something that I did not expect to happen, has happened recently and giving well-deserved credit to them is due. The name is Bing and it launched today. It's absolutely AWESOME! I won't bore you with a description of what Bing is. You most probably already know it, but what you are about to find (on Bing, not on this blog :) ) is a truly new way to experience Web. It's not about just a search engine, anymore, it's the entire decision-making experience that matters.

Microsoft folks are right-on in their marketing: Bing is NOT a search engine, it's a "decision engine". Brilliant! Absolutely brilliant!

Stan Schroeder of Mashable wrote this morning: "Bing Opens Up. It’s Live.com, Wrapped In a Prettier Box." Sorry Stan, I don't know why you would say such thing, but I have to respectively disagree and say: "Bing could not be further from live.com or anything that existed before it, for that matter". It is NOT just a wrap around an old engine. The engine is new and fantastic!

Quick test: try searching for "usb flash 64GB" in google.com (just the straight search box, not any subsite) and then on bing.com (same here: main search box, not the shopping section) and just compare the results. Bing understands what I want to see and gives me very nice tools to quickly narrow-down results. Google is as naivly narrow-minded as it was 10 years ago, it's just that world is not the same as it was 10 years ago. Hello there, in Mountan View, is anybody home? We are in 2009, wake up!

Sane Backtrace in PHP

PHP error messages are quite helpful, most of the time. Sometimes they do fall short of telling us what went wrong, however. It's especially common when and if you use a development framework (e.g. Drupal). Frameworks often do output buffering and/or code eval()-ing, making debugger output incomprehensible.

In such cases PHP's debug_backtrace() function is a real savior. debug_backtrace() is also very helpful if you want to look at the execution stack in a complicated code, to better understand the code. This function shows the execution stack that lead to the current function and does it pretty well... "too well" sometimes :) Out-of-the-box version of the function shows the list of invoked functions, source files they belong to, line numbers in the source file and the argument values being passed. The latter can be a huge problem, if code is passing around large variables. Output on the screen may get so garbled (esp. if HTML is used in variables) that the entire exercise may lose its meaning.

Short snippet below sanitizes debug_backtrace() output to make it slimmer and more comprehensible:

$trace = debug_backtrace();
foreach ($trace as &$t) {
  unset($t['args']);
}
echo "<pre>".print_r ( $trace,true)."</pre>";
exit();

How to Enable Local SMTP (Postfix) on OS-X Leopard

OS-X Leopard comes pre-installed with a Postfix version. No need to install it via darwin ports or other such mess (actually uninstall it if you have previously manually installed it via ports or something similar). Postfix just needs to be enabled and following sequence of several easy steps explains how to do it:

 sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist

add following line before the closing </dict> tag:

<key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/>

Start service with

$ sudo launchctl
launchd% start org.postfix.master

You can also start simply with "sudo postfix start" but the above command will start via launch sequence and test the configuration you edited in the previous step.

Check that SMPT is running:

telnet localhost 25

For more information, see: Mac OS X Manual Page For launchd.plist

Drupal: Fatal error: Unsupported operand types in

If you have misfortune of having to upgrade Drupal5 website to Drupal6, there's a very good chance that at some point you will run into a fatal error:

Fatal error: Unsupported operand types in...

Fatal errors are never fun, but this one is particularly annoying and hard to hunt down. It helps to understand the cause of the problem, thought. Basically, the main problem is that Drupal url() and l() functions have changed their signatures in a major way. Function operands that used to be literals are supposed to be an array now.

Solution

You need to hunt-down all url() and l() functions and change their signature to Drupal6-compliant format. The functions can be used (and causing problem from) multiple locations: a tpl.php file, a module file or a code in a block in the database! This last one is particularly troublesome to hunt down and can cause the most problem. We suggest disabling all blocks for the time of upgrade by running:

UPDATE blocks set status=0

Also, to find which function causes the problem. open includes/common.inc and at the begining of url() and l() function definitions paste following code:

    if (!is_array($options)) {
      echo "<pre>";
      $backtrace = debug_backtrace();
      var_export($backtrace);
      exit();
    }

Typically first function call in the backtrace is the offender function.

Teaching Espresso Drupal PHP file Extensions (e.g. .module)

Espresso From MacRabbit (you may remember them for their splendid CSSEdit eidtor) is a new Web editor, for Macs, worth paying attention to. It handles the usual suspects: PHP, CSS, HTML, servers over SFTP, Amazon S3 etc with style out of the box and has numerous extensions for other things like Python, LUA, SQL, Regular Expressions etc. And it's only 1.x version, so you bet you can expect much more in coming versions.

One little shortcoming it had, for Drupal developers is that, there's no easy way to configure custom-for-Drupal PHP extensions: .module and .install to make Espresso recognize these as PHP files.

Joe Shindelar of Dreamformula has posted a nice blog post detailing the configuration of custom PHP extensions in Espresso.

Thank you, Joe!

Announcing: World Bank Open API 2.0

Blog post about the new World Bank API, how we designed it, why we are excited about it and why you could be, too:
http://www.agileapproach.com/blog-entry/world-bank-api-20-launch

Solving Doxygen Troubles With Drupal.

Drupal requires its source documentation to be compatible with DoxyGen. If you are working on a large project, you want to install DoxyGen and run it on cron to have nice, up-to-date API docs.

Unfortunatley, if you install Doxygen via yum (or any other auto-updater, I assume) it installs a fairly old 1.4.x branch that is incompatible with Drupal. Specifically, it completely ignores the .module and .install files and has poor support for .inc, from what I can tell. That's because Doxygen does not realize these are PHP source files.

What you want to do is to install the latest Doxygen release (1.5.8 at the time of this writing). In the new version, the author of Doxygen has generously added a configuration tag that allows mapping of arbitrary file extensions with language types. The setting you need in your doxygen configuration file is:

EXTENSION_MAPPING      = module=PHP install=PHP inc=PHP

Syndicate content