How to hide index.php from the url ?




In my last article we discussed about the “Add tool to reset locked feeds in Drupal 7“. If you would have work with PHP MVC frameworks you can find most of them are receiving all user requests via front access file like index.php. For example in CodeIgniter, Cygnite Framework, Yii using index.php, for Symfony app_dev.php etc. You may be wondering how to remove this index.php file from url to make it more seo friendly. Today let me show  you all how to remove index.php from the url and display more user friendly url to users using .htacces.

Step1: Create a new file named .htaccess in the same folder as your site’s main index.php file.

Step2: Please make  sure that mod_rewrite is on in your server using phpinfo();

Step3: Add the following lines of code in the newly created file-

<IfModule mod_rewrite.c>

            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php/$1 [L]         
            # RewriteRule ^(.*)$ /index.php?/$1 [L]

</IfModule>
Step4: Test your site links and url without index.php to ensure it is working correctly without index.php

 Hope this post helps. Keep visiting for more technical posts.

Add tool to reset locked feeds in Drupal 7


In my last article we discussed about Google latest update “Google revealed that they are using Ubuntu for their self-driving car“ Today I am going to show how to reset locked feeds. Recently while working with Drupal 7 this issue occurred and after spending long time by googling found the solution, which is shared with you all here. If a feeds batch import is interrupted or dropped because of network connection, server crash or for any unknown reason, import will be left as ‘locked state’, so that the use cannot try import again.

I have followed few steps to solve this issue mentioned below-

Step 1: Go to your file destination - site/all/modules/feeds/feeds.module

Step 2: We are going to change the “feed.module” file. Replace[-] and add [+] code below in the same file -

<?php @@ -219,6 +219,10 @@ function feeds_permission() {      $perms["clear $importer->id feeds"] = array(        'title' => t('Delete items from @name feeds', array('@name' => $importer->config['name'])),      ); + $perms["unlock $importer->id feeds"] = array( + 'title' => t('Unlock imports from @name feeds', array('@name' => $importer->config['name'])), + 'description' => t('If a feed importation breaks for some reason, users with this permission can unlock them.') + );    }    return $perms;  } @@ -272,6 +276,15 @@ function feeds_menu() {      'file' => 'feeds.pages.inc',      'type' => MENU_LOCAL_TASK,    ); + $items['import/%/unlock'] = array( + 'title' => 'Unlock', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('feeds_unlock_tab_form', 1), + 'access callback' => 'feeds_access', + 'access arguments' => array('unlock', 1), + 'file' => 'feeds.pages.inc', + 'type' => MENU_LOCAL_TASK, + );    $items['import/%/template'] = array(      'page callback' => 'feeds_importer_template',      'page arguments' => array(1), @@ -300,6 +313,16 @@ function feeds_menu() {      'type' => MENU_LOCAL_TASK,      'weight' => 11,    ); + $items['node/%node/unlock'] = array( + 'title' => 'Unlock', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('feeds_unlock_tab_form', NULL, 1), + 'access callback' => 'feeds_access', + 'access arguments' => array('unlock', 1), + 'file' => 'feeds.pages.inc', + 'type' => MENU_LOCAL_TASK, + 'weight' => 11, + );    // @todo Eliminate this step and thus eliminate clearing menu cache when    // manipulating importers.    foreach (feeds_importer_load_all() as $importer) { @@ -351,11 +374,12 @@ function feeds_theme() {   * The action to be performed. Possible values are:   * - import   * - clear + * - unlock   * @param $param   * Node object or FeedsImporter id.   */  function feeds_access($action, $param) { - if (!in_array($action, array('import', 'clear'))) { + if (!in_array($action, array('import', 'clear', 'unlock'))) {      // If $action is not one of the supported actions, we return access denied.      return FALSE;    } diff --git feeds.pages.inc feeds.pages.inc index 33310ec..238b0db 100644 ?>
After

Step 3: After replacing the above lines go to your file destination - site/all/modules/feeds/feeds.pages.inc. Then remove [-] and add [+] the following line given below in "feeds.pages.inc" file

<?php @@ -188,6 +188,65 @@ function feeds_delete_tab_form_submit($form, &$form_state) {  } /** + * Render a feeds unlock form. + * + * Used on both node pages and configuration pages. + * Therefore $node may be missing. + */ +function feeds_unlock_tab_form($form, &$form_state, $importer_id, $node = NULL) { + if (empty($node)) { + $source = feeds_source($importer_id); + $form['#redirect'] = 'import/' . $source->id; + } + else { + $importer_id = feeds_get_importer_id($node->type); + $source = feeds_source($importer_id, $node->nid); + $form['#redirect'] = 'node/' . $source->feed_nid; + } + // Form cannot pass on source object. + $form['#importer_id'] = $source->id; + $form['#feed_nid'] = $source->feed_nid; + $form['source_status'] = array( + '#type' => 'fieldset', + '#title' => t('Status'), + '#tree' => TRUE, + '#value' => feeds_source_status($source), + ); + if ($source->progressImporting() == FEEDS_BATCH_COMPLETE && $source->progressClearing() == FEEDS_BATCH_COMPLETE) { + $form['source_locked'] = array( + '#type' => 'markup', + '#title' => t('Not Locked'), + '#tree' => TRUE, + '#markup' => t('This importer is not locked, therefore it cannot be unlocked.'), + ); + $form['actions']['submit']['#disabled'] = TRUE; + $form['actions']['submit']['#value'] = t('Unlock (disabled)'); + } else { + $form['actions']['submit']['#value'] = t('Unlock'); + } + return $form; +} + +/** + * Form submit handler. Resets all feeds state. + */ +function feeds_unlock_tab_form_submit($form, &$form_state) { + drupal_set_message('Import Unlocked'); + $form_state['redirect'] = $form['#redirect']; + $feed_nid = empty($form['#feed_nid']) ? 0 : $form['#feed_nid']; + $importer_id = $form['#importer_id']; + + //Is there a more API-friendly way to set the state? + db_update('feeds_source') + ->condition('id', $importer_id) + ->condition('feed_nid', $feed_nid) + ->fields(array('state' => FALSE)) + ->execute(); +} + +/**   * Handle a fetcher callback.   */  function feeds_fetcher_callback($importer, $feed_nid = 0) { ?>

Step 4: Please clear cache of your drupal available in "admin/config/development/performance" path. Now upload your modified files.

Finally feed unlocked as well as imported and you will receive success message as above screenshot. Happy importing.

Keep visiting for more new articles.

Author Details :

This article is originally posted by Subramanian Jaganathan (Drupal Developer).   It was his real time experience and shared with us.  Write me to share your experience with us.

Google revealed that they are using Ubuntu for their self-driving car

                         In my last article I explain you “10 Basic standards and instructions to kick start your awesome project “  If you are technology freak like me then you would love to know during latest embedded  Linux conference Andrew Chatham has revealed that self-driven car by Google is lightly customized version of Ubuntu Linux operating system and some high quality laser, sensors. 

Ubuntu Linux is very well known operating system for open source application development and became very popular in embedded OS these days.

Is it not nice if we don’t have to worry to drive the car?

Human can drive the car manually or enjoy freedom like a passenger by allowing OS to operate the car automatically.

Yes it is Google latest innovation. Google can able to collect the data for Google maps using this invention.
In Andrew Chatham 24 minute speech showed how Google modified and customized Ubuntu operating system to manage to control the self-driving car. 

For more detailed information you can watch the video published on Aug 23, 2013.



Hope this small news will be surprised for Ubuntu lovers that Google known for modified version of Ubuntu at their workplace.


Keep visiting for more interesting articles. 

PHP coding standards and naming convention for professionals


                           In my last article I shown you How to get element position using jquery ? Today I would like to write some basic coding standards which can be followed in your next project. “Remember your single line of code reflect your skills.” Coding standards vary developer to developers and company to company. It is really creating trouble for developers when we need to enhance the application or review the code which is not your own. But there are best practices you can follow to improve your coding style which I drafted recently.  

10 basic standards and Instructions to kick start your awesome project -


  • Development Environment –
It’s better to use always IDE for your project development, which will minimize your development time. Try to use Net Beans/ Eclipse IDE which is most preferable or optionally you can use subline, notepad++,geany etc. for code alignment.  

  • Project Root Directory Name –
Remember never keep your project root directory name in uppercase characters. It should be always in lowercase. Because it is looking ugly when directory name shows in the browser url.
Always keep your project root directory name similar to your project name which is more meaningful and professional.

  • Configurations –
Before starting your main business logic code always have your configurations files inside the single directory like configurations etc. its applicable for core php coder, MVC frameworks follows it’s own standards and location.

  • File Name –
Have your filename meaningful as it is reflect functionality of the page.
 For example- Never keep your filename un-meaningful name as like (user1.php, TheDefination2forlibrary.php, Payment.php etc.). It is better to have your file name also in lowercase but in some case like if you are creating libraries or classes you also can have your file name (Authentication.php, Validator.php etc.)

  • Doc Block –
Every pages or classes should have documentation block to describe the purpose and information about the page which is most important.

For example –
/**
 * Documentation Block
 *
 *
 * @controller name – PHP Coding Standards
 * @descriptions     -  You can have your detailed description here.,…
 *
 * @category           - Coding Standards and Structures
 * @author               - Sanjoy Dey - Software Engineer
 * @created date   -    29-07-2013
 * @modified by     - ..........
 * @modified date -
 * @todo                 - If any
 * @warnings        - If any
 *
 */ 

  • Class Name and Method Name –
Have single space indent from left side of your editor to start your class name. Have your class opening braces in new line and end up same.
Method name should start with single tab from left side of your editor and new line after your class opening braces. You should be more careful to have your method names, because in the case of MVC pattern it displays in your browser url. You can follow different style to have your awesome method names as below –

For example –

 class Employee extends Users
{

   /**
    * This is default method for Employee controller (Brief details about your method)
    * @access public
    * @param1 int default NULL
    * @return void
    */
     public function get_users($id = NULL)
    {
              ……………………….
    }
 
    private function _where_user($id)
   {
               ……………………….
  }

   private function getDetailsByID ($id)
  {
              ……………………….
  }            

}


  • ·         Conditional Statements –


            Start your opening braces of conditional statement always from same line, the main idea behind this is to differentiate between class, method and conditional statements.
Have a double space to start your statement from the method starting point.
In the case of long conditional statement you can have a enter and start next condition.

For example-

if($condition1){
   ……………………
}else{
  ……………………
}

if($condition1 ==true && $condition2 == ‘user’
   && $condition3 == ‘1’ && $condition4 == false){
      ………………………
}

Same follows for looping statement. Example of nested loops using this convention:

                   for ( $i = 0; $i < 5; $i++ )
                   {
                         for ( $j = 0; $j < 4; $j++ )
                        {
                              for ( $k = 0; $k < 3; $k++ )
                              {
                                     for ( $m = 0; $m < 2; $m++ )
                                     {
                                            ………………………………………
                                     }
                             }
                        }
                   }


  • Variable Name –
Variable name should be in lowercase and if you want to keep brief name it can be followed by underscore.
Define your variables before using to avoid warnings.


  • PHP Standard Requirement –
Recently while reading about the namespaces I came across the PSR standards. You can follow anyone of the PSR-0, PSR1, PSR-2 standard.


  • Before Deploying Your Code –
We always write some sort of code for testing and have it commented. Never forget to remove those commented or unnecessary code from your files before deploying into the server. Finally remove unnecessary backup files.


Follow the standards to become a better PHP developer -


A good developer always follows coding standards. It’s really up to you what kind of standards you follow. Well hope all these above instructions and standards will help you in your upcoming project. Leave a comment if above standards and instructions help you on joint project. 

All the Best.. 

You can also join my technical groups and stay updated, You can simply click on the follow us links below-  
Follow Us On Facebook Open Source Web Developers by Appsntech facebook group Twitter Open Source Web Developers by Appsntech twitter group Google+ Open Source Web Developers by Appsntech Google group Linkedin Open Source Web Developers by Appsntech, LinkedIn group
Copyright @2011-2015 appsntech.com. All rights reserved. Powered By- Sanjoy Dey Productions