Friday 17 June 2016

Wrap all into one div

How to wrap all into one div





Html


<div class='main'>
    <div class="a">a<div>
    <div class="b">b<div>
    <div class="c">c<div>
    <div id="d">d<div>
    <div class="e">e<div>
    <div id="f">f<div>
</div>



JQuery:

jQuery('.a, #d, .b, .c').wrapAll(jQuery('<div>').addClass('wrapbharat') );


Output after running jQuery will

<div class="main">
    <div class="wrapbharat"><div class="a">a<div>
    </div></div><div class="b">b<div>
    </div></div><div class="c">c<div>
    </div></div><div id="d">d<div>
    <div class="e">e<div>
    <div id="f">f<div>
</div>

Get Ip Address of website

How can I get the Ip Address of a website





Here are the providers link that give the Ip from website domain




IP & Domain Checker

Site 24x7

Check ip for any site on the web

Hcidata

You can also find by Terminal in Ubuntu & by Command Prompt in Windows systems by typing following commands

ping www.google.com

then it will show bytes from website ip




Monday 13 June 2016

How to add class external to anchor that has href to other sites

Add class external to anchor that has href to other sites and target _blank to open them to new tab



jQuery

jQuery('a').filter(function() {
   return this.hostname && this.hostname !== location.hostname;
}).addClass("external");
jQuery('.external').attr('target','_blank');

Confirm before delete


Confirm before delete








Html:

<a href="delete.php"  onclick="return doconfirm()">Delete</a>

Javascript Function:


function doconfirm()
{
    contact=confirm("Are you sure you want to delete this?");
    if(contact!=true)
    {
        return false;
    }
}

Add class depending href of anchor

Add class depending href of anchor from current url



This jquery will add class active to anchor tag having that href

ex. url is www.test.com#tag

var hash = jQuery(this).attr('href').split("#");  //  it will give tag as result

jQuery(('a[href$="#'+hash[1]+'"]')).parent().addClass('active');

// this will add class to that a which have #tag as its href

Note: you can use these also


= is exactly equal
!= is not equal
^= is starts with
$= is ends with
*= is contains
~= is contains word
|= is starts with prefix (i.e., |= "prefix" matches "prefix-...")


Enable htaccess if not enabled on your server

"Page Not Found" Errors on every page except homepage.

Site is hosted on digital ocean or have file structure as var/www/html/yoursite





Enabling mod_rewrite by typing following command

    sudo a2enmod rewrite

Than restart apache server by following command

    sudo service apache2 restart

Now open file /etc/apache2/sites-enabled/000-default.conf

or by typing command given below

   sudo nano /etc/apache2/sites-enabled/000-default.conf
  
Inside that file, you will find the <VirtualHost *:80>

<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>


after adding this your code should look like(indent shoud be proper)

<VirtualHost *:80>
    <Directory /var/www/html>

        . . .

    </Directory>

    . . .
</VirtualHost>

Now again restart server by typing command

   sudo service apache2 restart
  
Now add your htaccess and see that will work


Digital Ocean

Monday 6 June 2016

How to create Login Logout functionality with session ?

How to create Login Logout functionality with session ?



In Few Basic Steps we can create Login-Logout with session

Step 1 :   
   
    Load Libraries in autoload.php        //Location :    application/config/autoload.php
   
    $autoload['libraries'] = array('database', 'email', 'session');
   

Step 2 :   
   
    Load Drivers in autoload.php        //Location :    application/config/autoload.php
   
    $autoload['drivers'] = array('session');
   
   
Step 3 :   
   
    Load Helper Libraries in autoload.php        //Location :    application/config/autoload.php
   
    $autoload['helper'] = array('url', 'file');


Now Comes Logical part We will create Two Controller files & Two View Files One for Before Login & Another for After Login Functionalities

Our Two controller will "Account" and "User" and views will "login_view" and "dashboard_view"

Step 4 :   

    First Create view using simple form on login_view page
   
    Form Code:
   
    <form method="post" action="<?php echo site_url('account/login');?>">
        <table>
            <tr>
                <td><input type="text" name="email" value="" placeholder="E-mail"/></td>
            </tr>
            <tr>
                <td><input type="password" name="password" value="" placeholder="*****" /></td>
            </tr>
            <tr>
                <td><input type="submit" name="login" value="Login" /></td>
            </tr>
        </table>
    </form>


Step 5 :   
   
    Add login logic on Account Controller Page We will use simple & static you can use dynamic using database
   
    function login()
    {
        $email=$this->input->post('email');
        $password=$this->input->post('password');
        if($email=='test@gmail.com' && $password=='123456')
        {
            $session_data=array(
                                'id'=>1,
                                'email'=>$email,
                                'islogin'=>True,
                            );
            $this->session->set_data($session_data);
            redirect('user');
        }
    }
   
Step 6:

    On User Controller create the constructor function so that it will called before calling any function
   
    public function __contruct()
    {
        parent::__contruct();
        if((!$this->session->has_userdata('id'))||(!$this->session->has_userdata('email'))||(!$this->session->has_userdata('islogin')))
        {
            redirect('account/login');
        }
    }

Step 7:

    Create a function on User controller to show welcome page simply load welcome page
   
    function dashboard()
    {
        $this->load->view('dashboard');
    }
   
Step 8:
   
    Create dashboard view to show welcome message and user email id
   
    <a href="<?php echo site_url('account/logout');?>">Logout</a>
   
    <h3>Hello <?php echo $this->session->userdata('email');?><h3>
   
Step 9:

    Create Logout functionality on Account controller page
   
    function logout()
    {
        $this->session->sess_destroy();
        redirect('account/login');
    }

Change Upload limit using htaccess in drupal


Change Upload limit using htaccess in drupal


find for mod_php5.c

and add these two lines

php_value upload_max_filesize 30M
php_value post_max_size 30M

if not found then add this code in your htaccess file



<IfModule mod_php5.c>
    php_value upload_max_filesize 30M
    php_value post_max_size 30M
</IfModule>

Remove all p tag contains space


How to remove all p tag contains space


Solution : 

jQuery('p').each(function(){
   var htm=jQuery(this).html();
  if(htm=='&nbsp;')
  {
    jQuery(this).remove();
  }
})

This small jquery will remove all empty p tag on page

To sort item alphabetically

To sort item alphabetically using jquery





Html:



        <ul id="list">
            <li id="34">Peter</li>
            <li id="92">Mary</li>
            <li id="49">Paul</li>
            <li id="12">Allen</li>
            <li id="24">James</li>
            <li id="83">Vicki</li>
            <li id="68">Brock</li>
            <li id="1200">Dana</li>
            <li id="56">Frank</li>
            <li id="128">Gil</li>
            <li id="146">Helen</li>
        </ul>
      
jQuery:


var mylist = jQuery('list');
var listitems = mylist.children('li').get();

listitems.sort(function(a, b)
{
   return jQuery(a).text().toUpperCase().localeCompare(jQuery(b).text().toUpperCase());
})

mylist.empty().append(listitems);

//$.each(listitems, function(idx, itm) { mylist.append(itm); });


Remove all empty tags in class

How to remove all empty tags in class






Solution:


jQuery(function() {
  jQuery(".region-content p:empty").remove();
});

I will remove all empty tag inside "region-content" class





Add css depending on device

How to add css depending on device like ipad, android, desktop etc  ?



Solution:


jQuery(document).ready(function(){
   
    var deviceAgent = navigator.userAgent.toLowerCase();
    alert(deviceAgent);
   
     if(deviceAgent.match(/android/i))
     {
            alert('android');
     }
       
     if(deviceAgent.match(/ipad/i))
     {
           jQuery('head').append("<link rel='stylesheet' href='android.css' type='text/css' />");
     }
       
  console.log(navigator.userAgent.toLowerCase());

})

Create page tpl for taxonomy vocabulary

How to create page tpl for taxonomy vocabulary



Solution:

find for themename_preprocess_page add this is template.php

if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)))
{
    $tid = arg(2);
   
    $vid = db_query("SELECT vid FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' => $tid))->fetchField();
   
    $vars['theme_hook_suggestions'][] = 'page__vocabulary__'.$vid;
}

now create tpl named as "page--vocabulary--X.tpl.php";

Lock may available Drupal

How to remove error lock may available in drupal

Drupal showing me an error
includes/database/database.inc on line 2171





open php.ini and my.cnf located on /opt/lampp/etc
find max and change all limits to 1024 and max_execution_time=0

Get field value in Form alter drupal 8

Get field value in Form alter drupal 8



syntax:    $form_state->getValue('machine name');


to get machine name print $form_state->getValue();    // it will show all value of form

$field_e_mail_address=$form_state->getValue('field_e_mail_address');
$emailId=$field_e_mail_address[0]['value'];


Print nid in drupal 8 twig file or template file

print nid in drupal 8 twig file or template file




add this code in  _preprocess_page in .theme file at following location

ryder/themes/theamname/theamname.theme

find for _preprocess_page and add this

    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node) {
      $variables['nodeid'] = $node->id();
    }

now in twig print as {{ nodeid }}

Remove welcome message in drupal from front page

How to remove welcome message in drupal from front page?



To Remove "Welcome Message & no frontpage content created yet" in drupal

open the teamplate file of the current default theme

and search for "_preprocess_page";
 now add code just before the closing of the function

 Code:


  if (drupal_is_front_page()) {
    unset($vars['page']['content']['system_main']['default_message']); //will remove message "no front page content is created"
    drupal_set_title(''); //removes welcome message (page title)
  }
 


For example:
 
function MYTHEME_preprocess_page(&$vars) {
  if (drupal_is_front_page()) {
    unset($vars['page']['content']['system_main']['default_message']); //will remove message "no front page content is created"
    drupal_set_title(''); //removes welcome message (page title)
  }
}

Sunday 5 June 2016

Remove index.php from codeigniter url placed in subdomain



<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /mop/index.php/$1 [L,QSA]
</IfModule>


Here mop is folder name placed in public_html
public_html/mop/index.php


Note: Replace mop with your folder name

Remove index.php from url codeigniter

How to remove index.php from url codeigniter


Goto        :    application->config->config.php

Find         :    $config['index_page'] = 'index.php';

Replace        :    $config['index_page'] = '';

Now create new htaccess file & paste following code and save by name as .htaccess on root directory of your project


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


Now Refresh the url index.php is removed from url