Archive

Archive for the ‘PHP’ Category

CakeFest 2011

September 9th, 2011 No comments
Categories: PHP Tags: , , ,

Fix for WP plugin Flickr Photo Album

September 7th, 2011 No comments

I use the WP plugin Flickr Photo Album a few years. Together with Firefox plugin Fotofox it makes inserting procedure of images into posts very simple. However, I found a problems with that plugin recently. I couldn’t activate it anymore. The page is just reloaded and plugin’s status remained ‘Inactive’. This simple modification fixes the problem. In the file tantan-flickr/flickr/class-admin.php change add_action to register_activation_hook function as follows.

add_action(‘admin_menu’, array(&$this, ‘addhooks’));
//add_action(‘activate_tantan-flickr/flickr.php’, array(&$this, ‘activate’));
register_activation_hook(__FILE__, array(&$this, ‘activate’));
//add_action(‘deactivate_tantan-flickr/flickr.php’, array(&$this, ‘deactivate’));
register_deactivation_hook(__FILE__, array(&$this, ‘deactivate’));
add_action(‘load-upload.php’, array(&$this, ‘addPhotosTab’));

Categories: PHP Tags: , , ,

Installation of Oracle client to Ubuntu 10.04 Lucid

June 2nd, 2010 1 comment

Recently I moved from Fedora 13 to Ubuntu 10.04 on my work laptop. So, I faced again with problem to setup Oracle PHP interface. Oracle provides RPMs only and not DEBs. So, to install the client RPMs should be converted to the DEBs. It can be done easily using utility alien:

sudo alien oracle-instantclient11.1-basic-11.1.0.7.0-1.i386.rpm
sudo alien oracle-instantclient11.1-devel-11.1.0.7.0-1.i386.rpm
sudo alien oracle-instantclient11.1-sqlplus-11.1.0.7.0-1.i386.rpm

They can be installed then with sudo dpkg -i.
Don’t forget to install PHP interface to Oracle:

sudo pear install pecl/oci8

That’s it. I spent no more 15 minutes to setup PHP Oracle interface under Ubuntu. Thanks to that post!

Categories: Linux, PHP Tags: , , ,

Trick with variable name transformation in CakePHP

February 26th, 2010 No comments

CakePHP is a good PHP MVC framework. You can study it easily and start developing web sites very fast. But it has some disadvantages, of course. One of them is strange rules for transformation variable name when it set in the controller. Statement

$my_var = 'Hello world!';
$this->set('my_var', $my_var);

will make the variable $my_var accessible in your view:
<?php echo $my_var; ?>
The phrase ‘Hello world!’ should appear on the web page. But if the same operation is done using function compact, the result is not predictable:
$my_var = 'Hello world!';
$this->set(compact('my_var'));

Instead of ‘Hello world!’ you’ll see the warning about undefined variable on your web page. It happens because cakePHP removes underscore and makes letter, followed by it, capital. So, instead of $my_var you should use $myVar in the view:
<?php echo $myVar; ?>

Note that this bug appears in the cakePHP version 1.2. It’s already fixed in the 1.3.

Categories: PHP Tags: , , ,

SugarCRM: check updating of object’s property

July 16th, 2009 2 comments

Sometimes it’s needed to know about updating of specified object’s property. SugarCRM keeps previous values for all object’s properties in the array fetched_row. For example, to realise it’s new object or just updated we should compare ID from that array and current value of object’s property:

  1. if($obj->fetched_row[‘id’] != $obj->id) {
  2.     echo "This’s a new object!\n";
  3. } else {
  4.     echo "This’s an existing object\n";
  5. }

That approach might be used in the handler of logic hook, for example, to perform some action when desire property is changed.

Categories: PHP Tags: ,

How to change WP password into database

July 16th, 2009 No comments

I did it a few times but always made a search and dug WordPress code. So, just generate a new password:

  1. PHP -r ‘echo crypt("new_wp_pass") . "\n";’

and update specified user in the table wp_users:

  1. UPDATE wp_users SET user_pass=‘generated password hash’ WHERE ID=‘desire user ID’;

Categories: Linux, PHP Tags: , ,

Run PHP script from command-line

September 7th, 2006 No comments

I came across a brief howto “Implementing with PHP: Standalone Scripts”. I’m Perl guy but I have to use PHP in command line to perform some SugarCRM backgound tasks. I found useful the part about parsing command-line arguments with Console/Getopt.php. It may do administration tasks much easier.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes