Tuesday, April 23, 2013

PHP: Get File Names From A Specified Directory


Get file information from a given directory. Here the following example code to list the .php files in the particular folder.

Code:

$dir = $_SERVER['DOCUMENT_ROOT'].'/OpenInviter/';
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) { 
  if (eregi("\.php",$file)) 
   { # Look at only files with a .php extension
      $string .= "$file";
    $string .= "<br>";
      $fileCount++;
   }
}

if ($fileCount > 0) {
  echo sprintf("<strong>List of Files in <br> %s</strong>
%s<strong>Total Files: %s</strong>",$filePath,$string,$fileCount);
}

Output:

List of Files in  
autoupdate.php
config.php
default.php
example.php
index.php
notifier.php
openinviter.php
stats.php
Total Files: 8

Prestashop - Moving customers passwords to new site 1.4.9 to 1.5.x

Read the following steps and do it. 

Step 1:

Edit file ../config/settings.inc.php , and add :


define('_COOKIE_KEY_OLD_', 'YOUR_PS_V.1.4.9_COOKIE_KEY_');

Step 2:
Edit file ../override/classes/Customer.php, and add :

  public function getByEmail_old($email, $passwd = null, $ignore_guest = true)
        {
                if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
                        die (Tools::displayError());

                $sql = 'SELECT *
                                FROM `'._DB_PREFIX_.'customer`
                                WHERE `email` = \''.pSQL($email).'\'
                                        '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
                                        '.(isset($passwd) ? 'AND `passwd` = \''.Tools::encrypt_old($passwd).'\'' : '').'
                                        AND `deleted` = 0'.
                                        ($ignore_guest ? ' AND `is_guest` = 0' : '');

                $result = Db::getInstance()->getRow($sql);

                if (!$result)
                        return false;
                $this->id = $result['id_customer'];
                foreach ($result as $key => $value)
                        if (key_exists($key, $this))
                                $this->{$key} = $value;

                return $this;
        }


Step 3 :
Edit file ../override/classes/Tools.php, and add :

 public static function encrypt_old($passwd)
        {
                return md5(_COOKIE_KEY_OLD_.$passwd);
        }

Step 4:
Edit file ../override/controllers/front/AuthController.php, and add :

 protected function processSubmitLogin()
        {
                Hook::exec('actionBeforeAuthentication');
                $passwd = trim(Tools::getValue('passwd'));
                $email = trim(Tools::getValue('email'));
                if (empty($email))
                        $this->errors[] = Tools::displayError('E-mail address required');
                elseif (!Validate::isEmail($email))
                        $this->errors[] = Tools::displayError('Invalid e-mail address');
                elseif (empty($passwd))
                        $this->errors[] = Tools::displayError('Password is required');
                elseif (!Validate::isPasswd($passwd))
                        $this->errors[] = Tools::displayError('Invalid password');
                else
                {
                        $customer = new Customer();
                        $authentication = $customer->getByEmail(trim($email), trim($passwd));
                        $authentication_old = $customer->getByEmail_old(trim($email), trim($passwd));
                        if ((!$authentication AND !$authentication_old) || !$customer->id)
                                $this->errors[] = Tools::displayError('Authentication failed');
                        else
                        {
                                $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($customer->id);
                                $this->context->cookie->id_customer = (int)($customer->id);
                                $this->context->cookie->customer_lastname = $customer->lastname;
                                $this->context->cookie->customer_firstname = $customer->firstname;
                                $this->context->cookie->logged = 1;
                                $customer->logged = 1;
                                $this->context->cookie->is_guest = $customer->isGuest();
                                $this->context->cookie->passwd = $customer->passwd;
                                $this->context->cookie->email = $customer->email;
                                
                                // Add customer to the context
                                $this->context->customer = $customer;
                                
                                if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
                                        $this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
                                
                                // Update cart address
                                $this->context->cart->id = $this->context->cookie->id_cart;
                                $this->context->cart->setDeliveryOption(null);
                                $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
                                
                                $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
                                $this->context->cart->secure_key = $customer->secure_key;
                                $this->context->cart->update();
                                $this->context->cart->autosetProductAddress();

                                Hook::exec('actionAuthentication');

                                // Login information have changed, so we check if the cart rules still apply
                                CartRule::autoRemoveFromCart($this->context);
                                CartRule::autoAddToCart($this->context);

                                if (!$this->ajax)
                                {
                                        if ($back = Tools::getValue('back'))
                                                Tools::redirect(html_entity_decode($back));
                                        Tools::redirect('index.php?controller=my-account');
                                }
                        }
                }
                if ($this->ajax)
                {
                        $return = array(
                                'hasError' => !empty($this->errors),
                                'errors' => $this->errors,
                                'token' => Tools::getToken(false)
                        );
                        die(Tools::jsonEncode($return));
                }
                else
                        $this->context->smarty->assign('authentification_error', $this->errors);
        }

Finally
Create csv file to update XX_customer_group table database for all id_customer set group to 3 (customer), and import to your Prestashop database


Done :)

Filter out iframe using preg match for dailymotion video thumb image.


Get the Iframe src url.
Given  url  replace the term “embed”  to  “ thumbnail”.
Put this url to image src display the thumb image.

 Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Daily Motion Thumb Image</title>
</head>

<body>
<?php 

$str = "<iframe frameborder=\"0\" width=\"480\" height=\"270\" src=\"http://www.dailymotion.com/embed/video/xz7bnq\"></iframe><br /><a href=\"http://www.dailymotion.com/video/xz7bnq_nabilla-discotheque-le-29-ou-pas_news\" target=\"_blank\">NABILLA @ Discoth&egrave;que LE 29... Ou Pas...</a> <i>par <a href=\"http://www.dailymotion.com/discothequele29\" target=\"_blank\">discothequele29</a></i>" ;

$str1 = stripslashes($str);
preg_match('/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $str1, $matches);
echo '1'.($matches[0])."<br/>"; //only the <iframe ...></iframe> part
echo '2'.($matches[1])."<br/>";

$php_mot_url = $matches[1];

$php_mot_url1 = str_replace("embed","thumbnail",$matches[1]);

echo "<br/> <br/>";

?>

<img src="<?php echo $php_mot_url1; ?>">
</body>
</html>

OUTPUT:


Friday, April 19, 2013

Facebook application creation and Facebook like with counts

To display facebook like with counts in your site is very easy.

First to know how to create an application in facebook.
1)Login in your facebook account.
2)Then go to https://developers.facebook.com/ and click APP menu link.
3)And click + Create New app .
4)Give your App Name (application name) in the popup.
5)After give your site link in Website with Facebook Login and click the save button
6)Now you get the App ID/API Key .




Post this content before </head> in your site.

<head prefix="og: http://ogp.me/ns/fb#">
<meta property="og:title" content="Your site title"/>
<meta property="og:description" content="Your site description" />
<meta property="og:site_name" content="Your site long description"/>
<meta property="og:url" content="http://www.yoursite.com/"/>
<meta property="og:type" content="site" />
<meta property="fb:app_id" content="XXXXXXXXX "/>

Give your application id in the XXXXXXXXX . And place the following code , where you want the fb like and count should be display in your site.

<script>
var fb_js = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=XXXXXXXXX";
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = fb_js;
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
  <div class="fb-like" data-href="http://www.yoursite.com/" data-send="false" data-layout="button_count" data-width="450" data-show-faces="true"></div>




Fianlly you get FB like with counts in your site...cheers and enjoy!!!

Jquery UI Auto Complete Search Text after Use Ajax .



we have using jquery cdn path for css and js files.

suppose you need more infomartion please go to this link http://jqueryui.com/autocomplete/

we are special thanks To Jquery. visit http://www.jquery.com/   

Run  :   http://localhost/jquery_autocomplete.php

 

After Searching :

 
 

Create Two php Files:

First File Name :  jquery_autocomplete.php

Put Below Content and save.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jquery Auto Complete</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script>
                               
        $(function(){
                                 var eventnames = [{"value":"D98D3924-A88E-48EE-9EC4-A909CAD99FC8","label":"Event Test1 - EVC1","desc":"EVC1"},{"value":"0F22BEC9-872A-4F9F-BF73-483666EFE972","label":"Event Test1 - EVC2","desc":"EVC2"},{"value":"6EAA04AF-015E-471A-897E-7C618BE280D2","label":"IPL 15-2013 - EVC3","desc":"EVC3"},{"value":"2F5AF158-A559-482E-A649-08A94B1F6AEE","label":"IPL 16 - EVC4","desc":"EVC4"}];
                                 var check_url = "http://localhost/ajx_chk.php";
                                                                 
                                 $( "#eventname" ).autocomplete({
                                    minLength: 0,
                                                source: eventnames,
                                                 focus: function( event, ui ) {
                                                                $( "#eventname" ).val( ui.item.label );
                                                                return false;
                                                                },
                                                  select: function( event, ui ) {
                                                                $( "#eventname" ).val( ui.item.label );
                                                                $( "#eventid" ).val( ui.item.value );
                                                                $( "#eventcode" ).val( ui.item.desc );
                                                                var eid = $( "#eventid" ).val();
                                                                var ecode = $( "#eventcode" ).val();
                                                                var data_v = "eid="+eid+"&ecode="+ecode;
                                                                                 $.ajax({
                                                                                                type:"POST" ,
                                                                                                url:check_url ,
                                                                                                data:data_v ,
                                                                                                async:false ,
                                                                                                success: function(html_v)
                                                                                                {
                                                                                                   $("#ajx_cnt").html(html_v);
                                                                                                }
                                                                  });
                                                               
                                                                 return false;
                                                                }
                                                 
                                                }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
                                                     return $( "<li>" )
                                                                 .append( "<a>" + item.label+"</a>" )
                                                                 .appendTo( ul );
                                                                };
                                 
                                 $("form#formtt").submit(function () { return false; });
                                 
                                });
                               
                               
 </script>
</head>

<body>
   <form method="post" action="" name="frm1" id="formtt">                                                                         
        <input type="text"  id="eventname" value="" name="eventname" class="txt_f">
        <input type="hidden"  id="eventcode" value="" name="eventcode" >
        <input type="hidden"  id="eventid" value="" name="eventid" >
    </form>   

  <div id="ajx_cnt">
   
  </div>

</body>
</html>


Create Another One file
File Name: ajx_chk.php
Put Below Content and save.
<p>Test Sample</p>
<?php
  echo  "<pre>";
 print_r($_POST);
 echo "</pre>";
?>