WordPress – Disable Auto Save

WordPress’s Auto-Save feature is a really nice but there are some drawbacks… this feature increases your database usage. So for those of you that are on really bad shared hosting accounts or just want to turn it off, here’s a quick way of doing it.

Open and insert the following line in your wp-config.php file.

define('WP_POST_REVISIONS', false);

Another method is to remove all of the entries from the database from time to time. You can do tun this query to do it::

DELETE FROM wp_posts WHERE post_type = "revision"; 

Magento – How to run a SQL query against the database

In order to run a SQL query against the Magento database, you first need a resource model then a database connection.

$db = Mage::getResourceSingleton('core/resource')->getConnection('core_write');
$result = $db->query('SELECT 'entity_id' FROM 'catalog_product_entity');

if(!$result) {
    return FALSE;
}

$rows = $result->fetch(PDO::FETCH_ASSOC);

if(!$rows) {
    return FALSE;
}

print_r($rows);

Drupal – The Best and my Favorite Modules

I’ve worked with Drupal in the past for several projects and have come across some modules that have become my favorites. Here they are:

  • Tiny MCE

    This module was the first to integrate Moxiecode’s popular TinyMCE WYSIWYG editor into a Drupal site for editing advance site content.

  • Simple News

    Simplenews publishes and sends newsletters to lists of subscribers. Both anonymous and authenticated users can opt-in to different mailing lists. HTML email can be send by adding Mime Mail module.

  • Views

    The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented. Traditionally, Drupal has hard-coded most of this, particularly in how taxonomy and tracker lists are formatted.

  • Panels

    The Panels module allows a site administrator to create customized layouts for multiple uses. At its core it is a drag and drop content manager that lets you visually design a layout and place content within that layout.

  • Content Construction Kit (CCK)

    The Content Construction Kit allows you to add custom fields to nodes using a web browser.

  • Path Auto

    The Pathauto module automatically generates path aliases for various kinds of content (nodes, categories, users) without requiring the user to manually specify the path alias. This allows you to get aliases like /category/my-node-title.html instead of /node/123.

  • Five Star

    The Five Star voting module adds a clean, attractive voting widget to nodes in Drupal

  • Poor Mans Cron

    A module which runs the Drupal cron operations without needing the cron application.

  • Node Words

    This module allows you to set some meta tags for each node, view or panels page.

  • Global Redirect

    Checks the current URL for an alias and does a 301 redirect to it if it is not being used.

  • Page Title

    This module gives you granular control over the page title. You can specify patterns for how the title should be structured and, on content creation pages, specify the page title separately to the content’s title.

  • XML Sitemap

    The XML sitemap module creates a sitemap that conforms to the sitemaps.org specification. The sitemap created by the module can be automatically submitted to Ask, Google, Bing (formerly Windows Live Search), and Yahoo! search engines.

  • Print

    This module allows you to generate page, email and PDFprinter-friendly versions of any node.

  • Username Check

    This very simple module allows visitors to check username originality quickly using AJAX request during registration (completing registration form).

  • Node Hierarchy

    Node Hierarchy allows nodes to be children of other nodes creating a tree-like hierarchy of content.

Magento – Add a product with custom options to the cart through URL Querystring

Magento is truly a powerful and flexible platform! I enjoy working with it more and more every day. I recently came accross the need to add a product to the cart VIA the Querystring/URL. Guess what? Magento can do it and I’ll show you how!

Simple products are the easiest to add because there are fewer options that need to be passed. The basic structure is as follows.


http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]

Where [id] is the Magento ID of the product and [qty] is the Quantity you wish to add.

To add a simple product with custom options simply add options[id]=[value] to the end. The basic structure is:


http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]&options[id]=[value]

You can get the options id and value by viewing the source of the simple product page and it’s dropdowns.

PHP – Convert Array to Object with stdClass

The PHP stdClass() is something that isn’t well documented but i will try to shed some light into the matter. stdClass is a default PHP object which has no predefined members. The name stdClass is used internally by Zend and is reserved. So that means that you cannot define a class named stdClass in your PHP code.

It can be used to manually instantiate generic objects which you can then set member variables for, this is useful for passing objects to other functions or methods which expect to take an object as an argument. An even more likely usage is casting an array to an object which takes each value in the array and adds it as a member variable with the name based on the key in the array.

Here’s an example below that converts an array to an object below. This method is called Type Casting.

<?php
$person = array (
   'firstname' => 'Richard',
   'lastname' => 'Castera'
);

$p = (object) $person;
echo $p->firstname; // Will print 'Richard'
?>

Here’s an example below that converts a multi-dimensional array to an object. This is accomplished through recursion.

<?php
function arrayToObject($array) {
	if(!is_array($array)) {
		return $array;
	}
   
	$object = new stdClass();
	if (is_array($array) && count($array) > 0) {
	  foreach ($array as $name=>$value) {
	     $name = strtolower(trim($name));
	     if (!empty($name)) {
	        $object->$name = arrayToObject($value);
	     }
	  }
      return $object; 
	}
    else {
      return FALSE;
    }
}
?>
<?php
$person = array (
   'first' => array('name' => 'Richard')
);

$p = arrayToObject($person);
?>
<?php
// Now you can use $p like this:
echo $p->first->name; // Will print 'Richard'
?>