Thursday 23 June 2011

To Remove Email Validation in WordPress

In one of my project i had to assigned existing Mail Ids to new users added by Admin in WordPress. so i do following steps.
1) if we are adding new users to a Blog then wpmu_validate_user_signup() validates username and email id for each new user. this is called at wp_admin/user_new.php.

2) This function and other WordPress functions are defined in wp_include/ms_functions.php. wpmu_validate_user_signup() is written at line-516 in ms_function.php. here email_exists($emailid) is called to check the existence of mail id supplied with new username.
3) email_exists() function is defined at Line 1312 at wp_includes/user.php.

by commenting the code at email_exists() i can easily by pass the validation of existing email id check, and thus can create number of users with same mail Id.

Monday 20 June 2011

How To Print HTML From Iframe

 There are many times requirement to print pdf  or HTML content from Iframe. i will show how i had done printing of  iframe directly to printer. here i am calling a html contents into iframe, that was the same html which i used to create a pdf file by HTML2PDF.

<?php $printpdfpath="http://mysite.com/pdfhtml.php";?>
<div>
<iframe name="my_iframe" id="my_iframe"  width="100" height="100" src="<?php echo $printpdfpath;?>" frameborder="0"></iframe>
</div>
first i create an html page at my server and put above code there. which include an Iframe  to show html. now
<input type="button"  id="pdf"  value="Print" onclick="printIframe();">
<script>
function printIframe()
{
    var id="my_iframe";
    var iframe = document.frames ? document.frames[id] : document.getElementById(id);
    var ifWin = iframe.contentWindow || iframe;
    iframe.focus();
    ifWin.printpdfdata(); //a function in iframe html code
    return false;
}

</script>
that function printIframe(); is a cross browser to print content of HTML inside the iframe. and ifWin.printpdfdata(); is a function written in pdfhtml.php to call the print function.
<script>
function printpdfdata(){
     print();
    setTimeout('window.close()',1000);
</script> 

Friday 17 June 2011

To Create Iframe Dyanamically

 Below is the Javascript function to create Iframe at any click event of link or button
<script>
function makeFrame(){
   var aa = document.getElementById('pdfpath').value;
   ifrm = document.createElement("IFRAME");     //will create an Element IFrame
   ifrm.setAttribute("src", aa);  
   ifrm.style.width = 200+"px";
   ifrm.style.height = 200+"px";  
   ifrm.setAttribute("id", "my_iframe");
   document.body.appendChild(ifrm);
}
</script>

How To Print PDF From Iframe

There are many times requirement to print pdf from Iframe. or PDF embedded in HTML. i will show how i had done printing of PDF from iframe directly to printer.
<?php $printpdfpath="http://mysite.com/upload/sample1.pdf";?>

<div>
<iframe name="my_iframe" id="my_iframe"  width="100" height="100" src="<?php echo $printpdfpath;?>" frameborder="0"></iframe>

<embed
    type="application/pdf"
    src="<?php echo $printpdfpath;?>"
    id="pdfDocument"
    width="100"
    height="100">
</embed>
</div>
first i create an html page at my server and put above code there. which include an Iframe and <embed> to show pdf at html. now
<input type="button"  id="pdf"  value="Print" onclick="printIframe();">

<script>
function printIframe()
{
    if (navigator.userAgent.indexOf("Firefox")!=-1){
        var iframe_window = window.frames["my_iframe"];       
        frame_window.print();
    }
    else if(navigator.userAgent.indexOf("MSIE")!=-1){
        var x = document.getElementById("pdfDocument");
        x.print();       
    }
    else if(navigator.userAgent.indexOf("Chrome")!=-1){
        document.my_iframe.focus();
        document.my_iframe.print();   
    }
    else{   
        // Safari browser or other one   
        //document.getElementById('my_iframe').focus();
        //document.getElementById('my_iframe').onload = setTimeout('iframe.print()',2500);
        //var ifWin = document.getElementById('my_iframe').contentWindow;
        //ifWin.focus();
        //ifWin.print();
        //printpdf();
       
    }   

}
</script>
at above javascript i had put a check for different browser, there is problem with safari to print pdf via Iframe. many time developers face this while using above function which i had commented at Safari section. they print blank pages. so i had use printpdf(); a user define function to call pop window to print.

Thursday 2 June 2011

how to adjust webpage content accoding to screen resolution

i had a sample code which can be used in website to automatically set web page content according to screen resolution. suppose if we change our screen resolution from 1024×768 to 800×600, then many times horizontal bar appears on webpage. so to reset all contents and images on a page there is a js file and php file to reset the screen contents.  download the sample code from zip file.
http://www.keepandshare.com/doc/2846924/set-webpage-according-to-screen-resolution-121k?da=y