Steps to remove System CSS and JS files in Drupal 7

When developing a Drupal 7 theme, some of the CSS and JS files will get automatically included. In this article, we are going to discuss about How to remove the System CSS and JS files from the Drupal 7 themes. We can achive this by using Drupal hook system. The hook system allows the developer to apply global controls and functionality without hacking theme files with PHP.

Zen theme is a best theme to start create a new Drupal 7 theme. In Zen theme certain system or module CSS and JavaScript files will creep into the theme as you develop the website. This makes it difficult to fully optimize a website as you end up serving requests for files that are often unused for displaying content to a visitor.

To remove these unwanted system CSS and JS files, add the below hook codes to your theme's template.php file:

To remove the system CSS files, use the below code.

function THEME_NAME_css_alter(&$css)
{
    unset($css[drupal_get_path('module', 'system').'/system.theme.css']);
    unset($css[drupal_get_path('module','system').'/system.base.css']);
    unset($css[drupal_get_path('module', 'system').'/system.messages.css']);
    unset($css[drupal_get_path('module', 'comment').'/comment.css']);
    unset($css[drupal_get_path('module', 'field').'/theme/field.css']);
    unset($css[drupal_get_path('module', 'mollom').'/mollom.css']);
    unset($css[drupal_get_path('module', 'node').'/node.css']);
    unset($css[drupal_get_path('module', 'search').'/search.css']);
    unset($css[drupal_get_path('module', 'user').'/user.css']);
    unset($css[drupal_get_path('module', 'views').'/css/views.css']);
    unset($css[drupal_get_path('module', 'ctools').'/css/ctools.css']);
    unset($css[drupal_get_path('module', 'panels').'/css/panels.css']);
}

To remove the system JS files, use the below code.

function THEME_NAME_js_alter(&$js)
{
    unset($js[drupal_get_path('module', 'panels').'/js/panels.js']);
    unset($js[drupal_get_path('module', 'views').'/js/views.js']);
    unset($js[drupal_get_path('module', 'views').'/js/ajax_view.js']);
    unset($js[drupal_get_path('module', 'views').'/js/base.js']);
}

By using the above drupal hooks code, we can remove the unwanted system CSS and JS files.

Retrive data by Multiple Order Priority in CakePHP

In CakePHP, we can retrive data from database in different ways. In this article, we are going to discuss about How to retrive the data by multiple order priority.

Use the below code to retrive the data from the database using multiple order priority in CakePHP.

$this->paginate = array(
        'conditions' => $conditions,
        'order' => array(
            'Post.name' => 'ASC',
            'Post.created' => 'DESC',
         
        ),
        'paramType' => 'querystring',

);
$this->set('posts', $this->paginate('Post'));

The above code will give the output as Post name Ascending order and Post created as Descending order.

Create PDF from HTML in Symfony2 - Snappy Bundle

In this article, we are going to discuss about How to create PDF from HTML in symfony 2 framework using Snappy bundle. Snappy is a Bundle that is used for the conversion utility wkhtmltopdf in PHP 5.3, allows us to generate PDF file from html document. KnpSnappyBundle provide integration with Symfony2 Framework.

To be able to do the conversion, we first used a binary download wkhtmltopdf here:
http://code.google.com/p/wkhtmltopdf/. Once download the binary file, then we can install. After we install, we can integrate with Symfony2 quickly and easily.

First, we used the configuration:

# app/config/config.yml
knp_snappy:
    pdf:
        enabled:    true
        binary:     C:\wkhtmltopdf\wkhtmltopdf.exe #path to binary wkhtmltopdf
        options:    []
       
Then, we download the vendor from the git repository

git submodule add https://github.com/knplabs/snappy.git vendor/snappy

Download the bundle from the below URL

git submodule add https://github.com/knplabs/KnpSnappyBundle.git vendor/bundles/Knp/Bundle/SnappyBundle

List the autoload by using the below code

$loader->registerNamespaces(array(
//................SNAPPY..........//
'Knp'                        => __DIR__.'/../vendor/bundles',
'Knp\\Snappy'                => __DIR__.'/../vendor/snappy/src'
//-----------------------------------------------
));

Add the Kernel using the below code

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        ...
        new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
        ...
     );
}

Finally test the above by using the below code

$html = $this->renderView('Testmodule:Test:index.html.twig', array(
  'some'  => 'somethingvalue'
));

return new Response(
    $this->get('knp_snappy.pdf')->getOutputFromHtml($html),
    200,
    array(
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'attachment; filename="file.pdf"'
    )

);

Steps to resolve domPDF image load problem in Cakephp

In this article, we are going to discuss about How to resolve the domPDF image load problem in CakePHP. domPDF is used to export the application data. If some images are available in the data, sometimes it will show all data in pdf without images. Here I'm going to provide solution to solve the domPDF image load problem in cakePHP.

It will shows the below error:

DOMPDF_ENABLE_REMOTE is set to FALSE

Solution:

Open the dompdf location where you store it and open the file name "dompdf_config.inc.php".

Search for the following line

def("DOMPDF_ENABLE_REMOTE", false);

and change the above line like bellow

def("DOMPDF_ENABLE_REMOTE", true);

All are done. Now correctly place the image path in your html code which are you want to show in your pdf.

Tips and Tricks to speed up your wordpress blog

Most of the users using wordpress as a blog. In this article, I'm going to provide some tips and tricks to speed up your wordpress blog.

1. Use caching

To use caching, Install the WP Super Cache plugin and enable the Gzip option. This will load only the appropriate cached content to visitors rather than loading every single script and element of your WordPress site. Your bandwidth is greatly reduced and you avoid your site going down during traffic spikes (and if you're making a kick-butt site with kick-butt content, you should expect them more often than not).

2. Reduce the CSS files to as few as possible

Combine multiple custom CSS files into one big one. The less individual CSS files the theme needs to read the faster it'll load. Simply copy/paste the code from individual CSS files into the main style.css or a custom.css file in your theme.

3. Reduce the Javascript files to as few as possible

Combine multiple .js files into one big one. The less individual .js files the theme needs to read the faster it'll load. You can copy/paste the code from individual Javascript files (/js/jquery.js, /js/jquery.slider.js, /js/jquery.tooltip.js) into a new single Javascript file (/js/jquery.js,jquery.slider.js,jquery.tooltip.js).

3. Put as much Javascript code as possible in the footer

In the footer.php file of your theme, or in the footer section in your theme's customization panel if applicable. This is so that the Javscript calls load last. This way, your visitors will be able to quickly read the content while the Javascript loads in the background.

4. Use as few plugins as possible

The less plugins need to load the more stable your WordPress site can be (and slightly faster in certain cases if a plugin isn't properly coded). Do that by seeing if you can copy/paste code or hand-code the functionality into your theme, or using a theme that has the functionality built-in, or having it designed or customized for you. This doesn't mean don't use any plugins, especially since this article is suggesting plugins for WordPress optimization – just stick to only the essential ones rather than random sidebar widgets and whatnot.

5. Speed up image loading

Use the Amazon S3 storage service to upload and host your files. The images will load faster and your visitors won't have to wait as long for them to load – especially important for web and visual designers with lots of images and portfolios to showcase. You can use the Amazon S3 for WordPress plugin to streamline image uploading and inserting into your pages and posts.

Optimize Magento shop for search engines (SEO)

In this article, we are going to discuss about How to optimize the Magento shop for search engines (SEO). For all sites we need to optimize for search engines. So that search engines will crawl our website ad show it in the search results.

Magento is the popular search engine friendly E-Commerce platforms. To optimize the magento shop, follow the below steps.

Step 1 : 

Log in to your Magento backend and navigate to "System->Configuration->Web->Search Engine Optimization" and set "Use Web Server Rewrites" to "Yes".

Step 2 :

In the "Url Options" section, set "Add Store Code to Urls" to "No", and "Redirect to Base URL if requested URL doesn't match it" to "Yes"

Step 3 :

Magento header settings - Go to "System->Configuration->Design->HTML Head" and do not forget to populate the content for the following fields:

  • Default Title
  • Title Prefix
  • Title Suffix
  • Default Description
  • Default Keywords
  • Default Robots
  • Logo Image Alt (in header section)
  • Welcome Text

These are easy configuration you could say. And you are right, but the importance of these steps are very important when it comes to SEO optimization.