Friday 26 February 2016

How to create widget post in sidebar

<?php
/*
Plugin Name: flippercode Widget Pack
Plugin URI: http://flippercode.com
Description: A plugin containing various widgets created in a Flippercode series on WordPress widgets
Version: 0.1
Author: flippercode
Author URI: http://flippercode.com
Text Domain: flippercode
License: GPLv2

*/


class FlipperText_Widget extends WP_Widget {

    public function __construct() {
    
        parent::__construct(
            'flippertext_widget',
            __( 'Flipper Text Widget', 'flippertextdomain' ),
            array(
                'classname'   => 'flippertext_widget',
                'description' => __( 'A basic text widget to demo the flipper series on creating your own widgets.', 'flippertextdomain' )
                )
        );
      
        load_plugin_textdomain( 'flippertextdomain', false, basename( dirname( __FILE__ ) ) . '/languages' );
      
    }

    /** 
     * Front-end display of widget.
     *
     * @see WP_Widget::widget()
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
 public function widget( $args, $instance ) {
        if ( ! isset( $args['widget_id'] ) ) {
            $args['widget_id'] = $this->id;
        }

        $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );

        /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
        $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );

        $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 2;
        if ( ! $number )
            $number = 5;
        $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;

        /**
         * Filter the arguments for the Recent Posts widget.
         *
         * @since 3.4.0
         *
         * @see WP_Query::get_posts()
         *
         * @param array $args An array of arguments used to retrieve the recent posts.
         */
        $r = new WP_Query( apply_filters( 'widget_posts_args', array(
            'posts_per_page'      => $number,
            'no_found_rows'       => true,
            'post_status'         => 'publish',
            'ignore_sticky_posts' => true
        ) ) );

        if ($r->have_posts()) :
        ?>
        <?php echo $args['before_widget']; ?>
        <?php if ( $title ) {
            echo $args['before_title'] . $title . $args['after_title'];
        } ?>
        <ul>
        <?php while ( $r->have_posts() ) : $r->the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
            <?php if ( $show_date ) : ?>
                <span class="post-date"><?php echo get_the_date(); ?></span>
            <?php endif; ?>
            </li>
        <?php endwhile; ?>
        </ul>
        <?php echo $args['after_widget']; ?>
        <?php
        // Reset the global $the_post as this query will have stomped on it
        wp_reset_postdata();

        endif;
    }

 
    /**
      * Sanitize widget form values as they are saved.
      *
      * @see WP_Widget::update()
      *
      * @param array $new_instance Values just sent to be saved.
      * @param array $old_instance Previously saved values from database.
      *
      * @return array Updated safe values to be saved.
      */
    public function update( $new_instance, $old_instance ) {       
        
        $instance = $old_instance;
        $instance['title'] = sanitize_text_field( $new_instance['title'] );
        $instance['number'] = (int) $new_instance['number'];
        $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
        return $instance;
        
    }
 
    /**
      * Back-end widget form.
      *
      * @see WP_Widget::form()
      *
      * @param array $instance Previously saved values from database.
      */
    public function form( $instance ) {   
    
        $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
        $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 2;
        $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
        ?>
        
        <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>

        <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
        <input class="tiny-text" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" /></p>

        <p><input class="checkbox" type="checkbox"<?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
        <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
    
    <?php
    }
    
}

/* Register the widget */
add_action( 'widgets_init', function(){
     register_widget( 'flippertext_widget' );
});

Tuesday 9 February 2016

How to create backend plugin in wordpress

<?php /*
Plugin Name: book management
Description: This plugin will add/edit/delete Funding Method.
Author: Brainz Technologies
Version: 1.0
*/
$siteurl = get_option('siteurl');
define('BOOKMETHD_FOLDER', dirname(plugin_basename(__FILE__)));
define('BOOKMETHD_URL', $siteurl.'/wp-content/plugins/' . BOOKMETHD_FOLDER);
define('BOOKMETHD_FILE_PATH', dirname(__FILE__));
define('BOOKMETHD_DIR_NAME', basename(BOOKMETHD_FILE_PATH));

// this is the table prefix
global $wpdb;
$bookmethd_table_prefix = $wpdb->prefix;
define('BOOKMETHD_TABLE_PREFIX', $bookmethd_table_prefix);

register_activation_hook(__FILE__,'bookmethd_install');
register_deactivation_hook(__FILE__ ,'bookmethd_uninstall');

//table will be created when plugin is activated.
function bookmethd_install()
{
    global $wpdb;
    $table     = BOOKMETHD_TABLE_PREFIX."book_methods";
    $structure = "CREATE TABLE $table (
                 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,               
                 book_name VARCHAR(150) NOT NULL,
                 author VARCHAR(150) NOT NULL,
                 department VARCHAR(150) NOT NULL,
                price VARCHAR(150) NOT NULL,
                quantity VARCHAR(150) NOT NULL
                 );";
    $wpdb->query($structure);   
}

//table will be deleted when plugin is deactivated.
function bookmethd_uninstall()
{
    global $wpdb;
    $table     =  BOOKMETHD_TABLE_PREFIX."book_methods";
    $structure =  "DROP TABLE if exists $table";
    $wpdb->query($structure);
}

//show menu on left side
add_action('admin_menu','bookmethd_admin_menu');
function bookmethd_admin_menu(){
  add_menu_page('book Method','Manage book', 10, 'manage_book_method', 'wps_manage_book_method','21');
  add_submenu_page('manage_book_method','Add book ','Add new book',10,'addEdit_book_method','wps_addEdit_book_method');
}

function wps_manage_book_method(){
    include 'manage_book.php';
}


function wps_addEdit_book_method(){   
    $action  = $_GET['action'];
    if($action=='edit'){
        include 'addedit_book_method.php';
    }else{
        include 'add_book.php';       
    }
}

?>
<script type="text/javascript">
function deletebookName(id){ 
  if(confirm("Are you sure to delete?")){ 
   jQuery.ajax({
        url: "../wp-content/plugins/reg_form/delete_book_name.php",
        type: 'post',
        dataType: "html",
        data: { f_ID: id },
        success: function( data ) {
            window.location.href = "../wp-admin/admin.php?page=manage_book_method";
        }
    });
  }
}
</script>
<?php
function getdata( $atts )
{
  global $wpdb;
   $table = $wpdb->prefix."book_methods";
  if(!empty($atts['book_names_id']))  {
  echo "<pre>";
  print_r($atts);
 $book_names = $wpdb->get_results("SELECT * FROM $table where id='".($atts['book_names_id'])."'");
 }
 else
 {
 $book_names = $wpdb->get_results("SELECT * FROM $table");
 }
 $htm="";
 $htm.="<table border='0' cellpadding='2' cellspacing='2' width='70%' style='border:5px solid #cdcdcd;'>
 <tr><td><b>ID.No.</b></td>
 <td><b>Book name</b></td>
 <td><b>Author</b></td>
 <td><b>Department</b></td>
 <td><b>price</b></td>
 <td><b>Quantity</b></td>
  </tr>";
  if($book_names){
      $i=1;
     foreach($book_names as $book){
          $book_names_id=  $book->id;       
          $book_name   = $book->book_name;
           $author  = $book->author;
            $department     = $book->department;
             $price  = $book->price;
           $quantity  = $book->quantity;
  $htm.='<tr><td>'.$book_names_id.'</td>
  <td>'.$book_name.'</td>
  <td>'.$author.'</td>
  <td>'.$department.'</td>
  <td>'.$price.'</td>
  <td>'.$quantity.'</td>
  </tr>';
  }
  $htm.='</table>';
print $htm;
  }
  }
add_shortcode('arjun', 'getdata');


?>

Friday 8 January 2016

Show ,Hide Script in php useing button


    <input type="button" value="Hide Box" class="button-hide" />
    <input type="button" value="Show Box" class="button-show"  />
   


 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

    <script>
   
        $(document).ready(function() {
    
            $('.button-show').click(function(){
               
                $("#box").show();
                $("#box1").hide();

            });

            $('.button-hide').click(function(){

                $("#box").hide();
                $("#box1").show();

            });
        });
    </script>
    <script>
    $(document).ready(function() {
           
      $("#box").hide();
      $("#box1").hide();

         
        });

    </script>
 <form action="#" method="get" class="sidebar-form" id="box">
 <div class="input-group">
<p>this is show content </p>
</div>
</form>
               
<form action="#" method="get" class="sidebar-form" id="box1">
<div class="input-group">
<p>this is hide  content </p>
</div>
</form>

Thursday 7 January 2016

how to insert image in database php

 $image=$_FILES['file']['name'];
 <form action=""  enctype="multipart/form-data" >
<input type="file" name="file" id="ExamDeclareResultYes" required/>
 </form

<?php
if(isset($_FILES['file'])){
      $errors= array();
      $file_name = $_FILES['file']['name'];
      $file_size =$_FILES['file']['size'];
      $file_tmp =$_FILES['file']['tmp_name'];
      $file_type=$_FILES['file']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['file']['name'])));
     
      $expensions= array("jpeg","jpg","png");
     
      if(in_array($file_ext,$expensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      }
     
      if($file_size > 2097152){
         $errors[]='File size must be excately 2 MB';
      }
     
      if(empty($errors)==true){
         move_uploaded_file($file_tmp,"/home/oyp001/public_html/test9/user/images/".$file_name);
         echo "Success";
      }else{
         print_r($errors);
      }
   }
?>   

how to create unik key in php

<?php

function NewGuid() {
    $s = strtoupper(md5(uniqid(rand(),true)));
    $guidText =
        substr($s,0,8) . '-' .
        substr($s,8,4) . '-' .
        substr($s,12,4). '-' .
        substr($s,16,4). '-' .
        substr($s,20);
    return $guidText;
}


$Guid = NewGuid();
echo $Guid;
?>

Tuesday 22 December 2015

paypal sandbox

paypal sandbox account testing -

1.  mm001-buyer@gmail.com
    mmbuyer123
 
2.  mm-seller@gmail.com
    mmseller

Wednesday 9 December 2015

how to Recover password script in php

<?php
session_start();
include('include/config.php');
include('include/header.php');
include_once("log_usr/cl_ne/classes/class.messages.php") ;
//include_once("classes/db_table_details.php");
include_once("log_usr/cl_ne/classes/functions.php");
include_once("log_usr/cl_ne/classes/class.validation.php");

    if (isset($_POST['username'])){

        $username = $_POST['username'];

        $query="select * from book_user_reg where book_user_email='$username'";

        $result   = mysqli_query($con,$query);

        $count=mysqli_num_rows($result);

        // If the count is equal to one, we will send message other wise display an error message.

        if($count==1)

        {

            $rows=mysqli_fetch_array($result);

            $pass  =  $rows['book_user_pwd'];//FETCHING PASS

            //echo "your pass is ::".($pass)."";

            $to = $rows['book_user_email'];

            //echo "your email is ::".$email;

            //Details for sending E-mail

            $from = "Coding Cyber";

            $url = "http://writeup.ecoveretail.com/";

            $body  =  "Coding Cyber password recovery Script

            -----------------------------------------------

            Url : $url;

            email Details is : $to;

            Here is your password  : $pass;

            Sincerely,

            Coding Cyber";

            $from = "manjeet@ecovesolutions.com";

            $subject = "CodingCyber Password recovered";

            $headers1 = "From: $from\n";

            $headers1 .= "Content-type: text/html;charset=iso-8859-1\r\n";

            $headers1 .= "X-Priority: 1\r\n";

            $headers1 .= "X-MSMail-Priority: High\r\n";

            $headers1 .= "X-Mailer: Just My Server\r\n";

            $sentmail = mail ( $to, $subject, $body, $headers1 );

        } else {

        if ($_POST ['email'] != "") {

        echo "<span style='color: #ff0000;'> Not found your email in our database</span>";

            }

            }

        //If the message is sent successfully, display sucess message otherwise display an error message.

        if($sentmail==1)

        {

            echo "<span style='color: #ff0000;'> Your Password Has Been Sent To Your Email Address.</span>";

        }

            else

            {

            if($_POST['email']!="")

            echo "<span style='color: #ff0000;'> Cannot send password to your e-mail address.Problem with sending mail...</span>";

        }

    }

    ?>
<html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Home: Webpage</title>

    </head>

    <body>
<div class="container">
    <form action="" method="post">

            <label> Enter your User ID : </label>

            <input id="username" type="text" name="username" />

            <input id="button" type="submit" name="button" value="Submit" />

        </form>
</div>
    </body>

    </html>
<?php include('include/footer.php'); ?>

Tuesday 3 November 2015

how to set wordpress menu

Click here 

http://code.tutsplus.com/tutorials/how-to-integrate-bootstrap-navbar-into-wordpress-theme--wp-33410

Saturday 31 October 2015

how to use Curl Fatch data in other website

<?php

function curl_download($Url){
 
    if (!function_exists('curl_init')){
        die('cURL is not installed. Install and try again.');
    }
 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    $start = strpos($output, '<h2 id="logo">cfghvbbv</h2>');
$end = strpos($output, '<p>', $start);
$length = $end-$start;
$output = substr($output, $start, $length);
   
   
   
   
 
    return $output;
}

print curl_download('http://www.gutenberg.org/browse/scores/top');

?>

Web Service in php

<?php 
  /* soak in the passed variable or set our own */
  $format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; //xml is the default
  /* connect to the db */
  $link = mysql_connect('localhost','envisiy9_update','T?pAT*{nC58E') or die('Cannot connect to the DB');
  mysql_select_db('envisiy9_SiteCMS',$link) or die('Cannot select the DB');
  /* grab the posts from the db */
  $query = "SELECT * FROM artists";
  $result = mysql_query($query,$link) or die('Errant query:  '.$query);
  /* create one master array of the records */
  $posts = array();
  if(mysql_num_rows($result)) {
    while($post = mysql_fetch_assoc($result)) {
      $posts[] = array('a_id'=>$post['a_id'],'artist_name'=>htmlentities($post['artist_name']));
    }
  }
  /* output in necessary format */
  if($format == 'json') {
   header('Content-type: application/json');
    echo json_encode(array('posts'=>$posts));
  }
  else {
    //header('Content-type: text/xml');
    echo '';
    foreach($posts as $index => $post) {
      if(is_array($post)) {
        foreach($post as $key => $value) {
          echo '<',$key,'>';
          if(is_array($value)) {
            foreach($value as $tag => $val) {
              echo '<',$tag,'>',htmlentities($val),'</',$tag,'>';
            }
          }
          echo '</',$key,'>';
        }
      }
    }
    echo '';
  }
  /* disconnect from the db */

?>


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

web service 2:

<?php 
  $link = mysql_connect('localhost','root','') or die('Cannot connect to the DB');
  mysql_select_db('angelfi4_cart',$link) or die('Cannot select the DB');
  /* grab the posts from the db */
  $query = "SELECT * FROM artists";
  $result = mysql_query($query,$link) or die('Errant query:  '.$query);
  /* create one master array of the records */
  $posts = array();
   $arts =array();
  if(mysql_num_rows($result)) {
    while($post = mysql_fetch_assoc($result)) {
   
     $query2 = "SELECT * FROM art where artist='".$post['a_id']."'";
     $result2 = mysql_query($query2,$link) or die('Errant query:  '.$query2);
    while($art = mysql_fetch_assoc($result2)) {
      $arts[] = array('image'=>'http://69.195.124.130/~envisiy9/manager/pictures/'.$art['image'],'price'=>htmlentities($art['price']),'title'=>htmlentities($art['title']),'dimensions'=>htmlentities($art['dimensions']));
    }

     $posts[] = array('a_id'=>$post['a_id'],'artist_name'=>htmlentities($post['artist_name']),'arts'=>$arts);
    
    }
  }
 
echo "<pre>";
print_r($posts);
 //header('Content-type: application/json');
 //echo json_encode(array('posts'=>$posts));



?>