Drupal Performance - Disable CSS Aggregation from database

Sometimes on our localbox [wamp : localhost] we found that when enabled css aggregation and javascript aggregation then we cannot able to access our admin area and user login area. I mean we cannot able to access the site because we enabled css aggregation. Now you cannot access the admin area and you cannot even login so what to do.
You have to disable your css aggregation from database using your phpmyadmin. Follow the below steps:
  1. Open phpmyadmin and select the database which is used by the drupal instance.
  2. Select the "variables" table.
  3. Search for "preprocess_css" in name field.
  4. Change the variable value to s:1:"0";
  5. And you are done.

So this is the way you can disable your css aggregation with the use of phpmyadmin. If you want to disable javascript aggregation, you have to follow the same steps and you have to search for "preprocess_js" in "variables" table in step 3. That's it!
If you have any tips like this let share here in comments.

Create a simple wordpress ajax contact form without plugin

In this article, we are going to discuss about How to create a simple wordpress ajax contact form without plugin. WordPress is an Open Source project, which means there are hundreds of people all over the world working on it. (More than most commercial platforms.) It also means you are free to use it for anything from your cat's home page to a Fortune 500 web site without paying anyone a license fee and a number of other important freedoms.

Below is the code to create a simple ajax contact form without plugin in wordpress.

Step 1 :

Add the below code to your functions.php file

<?php 
function addme_ajaxurl() {
?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
</script>
<?php
}
add_action('wp_head','addme_ajaxurl');

add_action('wp_ajax_submit_form', 'submit_form_callback');
function submit_form_callback(){

$params = array();
    parse_str($_POST['data'], $params);

$name = trim($params['name']);
$email = $params['email'];
$message = $params['message'];
$subject = $params['subject'];
$site_owners_email = 'email@sitename.com'; // Replace this with your own email address

if ($name=="") {
$error['name'] = "Please enter your name";
}

if (!preg_match('/^[a-z0-9&.-_+]+@[a-z0-9-]+.([a-z0-9-]+.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}

if ($message== "") {
$error['message'] = "Please leave a comment.";
}
if ($subject=="") {
$error['subject'] = "Please leave a subject.";
}
if (!$error) {

$mail = mail($site_owners_email, $subject, $message,
"From: ".$name." <".$email.">rn"
."Reply-To: ".$email."rn"
."X-Mailer: PHP/" . phpversion());
$success['success'] = "<div class='success'>" . $name . ", We've received your email. We'll be in touch with you as soon as possible! </div>";

echo json_encode($success);

} # end if no error
else {

echo json_encode($error);
} # end if there was an error sending

    die(); // this is required to return a proper result
}
?>

Step 2 :

Add the below code in your html and JavaScript where you want show your form

<form method="post" action="#" name="contact-form" id="contact-form">
  <div id="main">
    <div id="response"></div>
    <div class="fullwidth">
        <label>Name:</label>
        <p>
        <input type="text" name="name" id="name" size="30" />
        </p>
    </div>
    <div class="fullwidth">
        <label>Email:</label>
        <p>
            <input type="text" name="email" id="email" size="30" />
        </p>
    </div>
    <div class="fullwidth">
        <label>Subject:</label>
        <p>
            <input type="text" name="subject" id="subject" size="30" />
        </p>
    </div>
    <div class="fullwidth">
        <label>Message:</label>
        <p>
            <textarea name="message" id="message" cols="30" rows="10"></textarea>
        </p>
        <p>
            <input  class="contact_button button" type="submit" name="submit" id="submit" value="Email Us!" />
        </p>
    </div>
    <div class="fullwidth"></div>
</div>
</form>
<script type="text/javascript">                
    $( "form" ).on( "submit", function( event ) {
        event.preventDefault();
        $('#response').empty();
        var data = {
                action: 'submit_form',
                data: $( this ).serialize()
            };
        $.post(ajaxurl, data, function(response) {
            console.log(response);
            if(response.success){
                $('#response').append(response.success);
            }
            if(response.name){
                $('#response').append(response.name + "<br>");
            }
            if(response.email){
                $('#response').append(response.email + "<br>");
            }
            if(response.message){
                $('#response').append(response.message + "<br>");
            }
            if(response.subject){
                $('#response').append(response.subject + "<br>");
            }
        },'json');
    
    });
</script>

Images Hotlink Protection using htaccess in Joomla

In this article, we are going to discss about How to protect the image Hotlink using htaccess in Joomla. Currently there are 2 ways to protect your images from being used illegally by other website and to prevent bandwidth loss. One general way is to activate and use built in Hotlink Protection in your cPanel and the other way is by directly editing your .htaccess file.

Setting up .htaccess specific to Joomla is a little bit different from ordinary website. It depends on your server type and also your access to this file.

But for some reason, not all .htaccess setting work on any server such as those who hosted their website on litespeed server. For the purpose of adding the function of hotlink protection, you may need to add in these lines on the very top of your .htaccess file.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.yourdomain.com/x.gif [R,NC,L]

Why at the top?

To be true, I'm not in the position of really understanding the terms and explaining it to you. However, in Joomla 2.5 (as I know), you will need to put it on top of the list or else it won't work (It took me 2 days to figured it out...only after my web host provider informed me).

One thing that to note here - when you are using cPanel to manage your hotlink protection, it will automatically update your .htaccess file BUT the updated lines are usually added at the bottom of the .htaccess file. If that happened, you just need to relocate the lines.

For some reason, for those hosting on speedlite server, you'll need to extra lines:

RewriteEngine on
RewriteOptions Inherit
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?exadomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.exadomain.com/x.gif [R,NC,L]

As I said before, just contact your hosting provider should you encountered problem pertaining your .htaccess file (only after you failed to follow general guide). After all, your payment for hosting inclusive of after sale services.

Zend Framework - Content Indexing using Zend_Search_Lucene component

In this article, we are going to discuss about in Zend Framework How to index the content using Zend_Search_Lucene component. Lucene is indexing and retrieval library that originally was developed in Java technology and supported by the Apache Software Foundation. When the data has been indexed in the file system, it does not require a database server. Zend_Search_Lucene is one of the components of the Zend Framework that implements this technology.

Zend_Search_Lucene supports the following features:

  1. Ranking of search results 
  2. Powerful query types: Boolean, wildcard, phrase queries 
  3. Search by specific field


Ok, let's go to the example:

Suppose we have data that we store the article in our index file system. We have a call controller Zend_Search_Lucene components as follows:

class TestluceneController extends Zend_Controller_Action
{
    public function init()
    {
        /* Initialize action controller here */
        $this->indexPath = APPLICATION_PATH.'/indexsearch/index';
    }
}

In the init function, we declare the path where we store the index. If so, we created an action to index data from the database, such as the following:

//...................
public function reindexAction()
{
    // action body
    //just SAMPLE , access to db
    // ( in your REAL DEVELOPMENT, access to db is only in model ) !!!!
    //asumption , 'db' is already registered in registry !!!
    $db = Zend_Registry::get('db');
    $fetch = $db->query("select * from articles")->fetchAll();

    $index = Zend_Search_Lucene::create($this->indexPath);

    foreach($fetch as $key=>$row)
    {
        $doc = new Zend_Search_Lucene_Document();
        $doc->addField(Zend_Search_Lucene_Field::Text('title', $row['title']));
        $doc->addField(Zend_Search_Lucene_Field::UnStored('content', $row['content'] ));

        $index->addDocument($doc);
        echo 'Added ' . $row['title'] . ' to index.
';
    }
    //optimize index...
    $index->optimize();

    die;
}
//................................

Well, we run the action reindexAction first before attempting to scan the data. If so, now we can test:

//.......Search data is already indexed.
public function searchAction()
{
    $data  = array();

    // If a search_query parameter has been posted, search the index.
    $indexopen = Zend_Search_Lucene::open($this->indexPath);
     // Get results.
    $data  = $indexopen->find('"PHP framework" AND "Zend Framework"');
    foreach($data as $key=>$row)
    {
        echo $row->title; echo "<br>";
    }
    die;
}
//......................

Steps to add Icon to New Products in Magento

In this article, we are going to discuss about steps to add Icon to new products in Magento. As your inventory rises it's always very necessary to make your products stand out using an unique icon. Visitors to your website will be able to notice which products are newly arrived as the icon will show up in wherever you set it to in your theme.

Step 1 : Manage attributes

Go to Catalogue -> Attributes -> Manage Attributes. Set up a new attribute at this page and call it 'Boolean'. Set its ID as new_product. Under your advanced options, you will have the option to select it as a front end product. Do this. Now you simply have to add the new attribute to your custom attribute if you are using one. If not, set it to default. Save the new product.

You will now have a new product in your catalogue which has a Boolean flag set to yes. The next stage involves taking this new product icon and putting it in your front end.

Step 2 : Make it show

Now that you have a product icon with a Boolean flag, it's time to make this show on your front end. This is achieved by accessing template files: templates/catalog/product/list.phtml andtemplates/catalog/product/view/media.phtml.

<div class="product-image">
<?php if($_product->getNewProduct()) { ?>
<div class="new-product"></div>
<?php } 
$_img = '<img id="image" src="'.$this->helper('catalog/image')
->init($_product, 'image').'" 
alt="'.$this->htmlEscape($this->getImageLabel()).'" 
title="'.$this->htmlEscape($this->getImageLabel()).'" />';
echo $_helper->productAttribute($_product, $_img, 'image');
?>
</div>

As you can see, above, your new product is shows in '$_product->getNewProduct'. The next step is to ensure that your CSS is set up to show your product with Boolean flag. You need to make the product_class relative to the position of the icon. So:

.products-grid .product-image { position: relative; display:block; width:244px; height:156px; margin:0 0 10px; }
.new-product { 
position: absolute;
 right: 0;
 top: 0;
 width: 65px;
 height: 66px;
 display: block;
 z-index: 2;
 background: url(../images/new-product.png) no-repeat;
}

Step 3 : Save

Save your changes and ensure that your code is correct before doing so. Now, every time you add a new product and it goes on sale through your front end, it'll have an icon and Boolean flag.

Using the Database for Sessions in CakePHP 1.3.3

In this article, we are going to discuss about How to use database for session in CakePHP version 1.3.3. In CakePHP 1.3.3, I had difficulty in finding the schema for the sessions table without using the command line to generate the table.

Below is the raw SQL, that can be used to create the table. I'm sure it will be useful in future for me so I thought I'd share.

CREATE TABLE `cake_sessions` (
  `id` varchar(255) NOT NULL DEFAULT '',
  `data` text,
  `expires` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
);

Now you just need to modify the core.php file so that the database is used for Sessions instead of the default:

Configure::write('Session.save', 'database');

Update

To create the Sessions table from the console simply navigate to the /cake/console directory in the command line and run:

php cake.php schema create Sessions

Steps to install new theme in YII PHP Framework

In this article, we are going to discuss about the step by step procedure to install the new theme in YII PHP Framework. In web application, designing  also has same importance as development because user interface matters. If UI is not user friendly then ultimately application won't be useful. Here i'll show you brand new theme installation on yii php framework.

First we need some template compatible with yii framework. I found two template link which is free Theme1 Theme2  download both templates from given links. After downloading complete follow the steps.

Step 1:

Open your YII app folder where you've installed yii framework app.

Step 2:

Copy the template folder and paste it into the theme directory which exist in your app folder (/yiiapp/themes/)

Step 3:

Open the protected folder and find config directory and open it, in config directory there is one main.php file open it in any text editor.(/yiiapp/protected/config/main.php)

Step 4:

Make the following changes in the main.php ('theme'=>'themename',) here is the screen shoot of main.php file


Step 5: 

It simply route your theme folder and find cleangrad if found load it

Step 6:

Check theme has been installed successfully. (http://localhost/yiiapp/