Installation step for cakephp

Cakephp 1.3.6 Installation step

1.       Download cakephp 1.3.6 version(latest)

2.       Extract folder into your root directory

3.       Change app->config/core.php file line no. 204

              Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi'); 

 

change 1 character in the salt and you’ll be all set!

4.        Change app->config/core.php file line no. 209

Configure::write('Security.cipherSeed', '76859309657453542496749683645'); 

 

change the number in the cipherSeed and you’ll be all set!

5.  App/config directory filename database.php.default Rename to database.php

create databse and change into  database.php file hostname,login username,password and database name and prefix if you want

     var $default = array('driver' => 'mysql',

'connect' => 'mysql_connect',

'host' => 'localhost',

'login' => 'username',

'password' => 'password',

'database' => 'cakephp',

'prefix' => '');

  1. Editing this Page

To change the content of this page, create: APP/views/pages/home.ctp.
To change its layout, create: APP/views/layouts/default.ctp.
You can also add some CSS styles for your pages at: APP/webroot/css.

7.      Your index.php page as default.ctp is running now

 

How to resize and make thumbnail image in PHP?

One month ago I got a task to make thumbnail images and save them at different path.

There were lots of images, so it was very difficult to make thumbnail images and save them manually.

So for that I got a PHP script to make thumbnail images and save them at the given path.

Here is the script:

Step : 1 : Make a  “make_thumb” function to resize (make thumbnail) image and save it to the given path.

This function has four arguments:

  1. $source : Source image file path and name
  2. $target : Target file path and name
  3. $new_w : New width for the image
  4. $new_h : New height for the image
// This is the function that will create the thumbnail image from the given image
// The resize will be done considering the width and height defined, but without deforming the image
function make_thumb($source,$target,$new_w,$new_h)
{
// Call the function and get image extension.
$ext = getExtension($source);

// Creates the new image using the appropriate function from gd library
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($source);

if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($source);

if(!strcmp("gif",$ext))
$src_img=imagecreatefromgif($source);

// Gets the dimmensions of the image
$old_x = imagesx($src_img);
$old_y = imagesy($src_img);

// Next we will calculate the new dimensions for the thumbnail image
// The next steps will be taken:
// 1. Calculate the ratio by dividing the old dimensions with the new ones
// 2. If the ratio for the width is higher, the width will remain the one define in WIDTH variable
// And the height will be calculated so the image ratio will not change
// 3. Otherwise we will use the height ratio for the image
// As a result, only one of the dimensions will be from the fixed ones
$ratio1 = $old_x/$new_w;
$ratio2 = $old_y/$new_h;

if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}

if ($old_x > $thumb_w || $old_y > $thumb_h)
{
// We create a new image with the new dimensions
$dst_img=imagecreatetruecolor($thumb_w,$thumb_h);

// Resize the big image to the new created one
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

// Output the created image to the file. Now we will have the thumbnail into the file named by $target
if(!strcmp("png",$ext))
imagepng($dst_img,$target, 9);
elseif(!strcmp("gif",$ext))
imagegif($dst_img,$target);
else
imagejpeg($dst_img,$target, 100);
}
}

Step : 2 : Make a “getExtension” function to get the extension of given file.

And it has “filename” as an argument.

// This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1);
return $ext;
}

Step : 3 : Call “make_thumb” function and resize (make thumbnail) image.

Syntax :

make_thumb(“source image file path and name”, “target file path and name”, "new width for the image", "new height for the image");

For e.g.

make_thumb("C:/wamp/www/ThumbnailBlog/OrginalImages/abc.jpg", "C:/wamp/www/ThumbnailBlog/ThumbnailImages/xyz.jpg", 125, 125);

I hope this will help you….

Notes:

  • To use the given code you must have gd library support.
  • With the use of given code you could not increase height and width of image.
  • This code will be useful only with .jpg, .jpeg, .gif and .png entension.

Moving WordPress site from one server to Another Server

Step 1. Downloading Files:

Start by downloading your wordpress site folder from your already existing development  server.
Anything you have put into the local PC drive via FTP server or your server Cpanel.

Step 2. Exporting the Database:

In the hosting control panel for your existing build, you’ll need to get all of the data you’ve put into the system out. Using Tools > Export in WordPress is helpful but to ensure you get everything from the existing database, you should really use PHP MyAdmin and export all of the database tables.

Launch PHP MyAdmin, Log In using the existing database credentials, select the database you want to export from the left, then click the Export Tab. Select the Save Without Compression checkbox and you’ve got a backup on your desktop or local drive.

Step 3. Creating the New Database:

In the environment, Now you’ll need a new database. You will have both the Control Panel and FTP Details.  If you can’t get Control Panel access, have the client create a Database for you and have them list the Database Name, Username, Password and Host Name. That and FTP will do the trick – but the client may have to import the database for you. Configure the wp-config.php file for your new site/database and continue to Step 4.

Step 4. Uploading

Backup the client’s existing website first. Then upload all of the appropriate wordpress folders to their host. At this point, you may want to delete the files in the root of their site and replace them with the wordpress root files to make the transition complete. Remember to update the wp-config.php first to be sure it will connect with the new database.

Changes in config.php file.

1)     Define new site URL . (see below figure)

2)     Database name

3)     Database user name

4)     User password

5)     Host server name

Using a web browser, navigate the website and type /wp-admin/ after the url. Hopefully you encounter the WordPress screen where you can name your site, sign in for the first time and see the system working correctly.

It’s a really good idea at this point to go to Settings > General and make sure the URL is pointing to the correct address of the live website.

 

Step 5. Importing the Data into the New Database:

Now you’ll want to get the data you have entered into the development site into the live site. This step is very similar to Step 2 – only the reverse. Log into PHP MyAdmin in the new hosting environment and click Import. Select the file from your desktop and you should have a working copy of the development site.

Step 6. Fixing some errors

Sometimes during transitions you will encounter problems where the live site is looking for file uploads that reference the old development URL address. The easiest way we have found to fix these problems is to install the Search and Replace through plugins and find the old URL and replace it with the new URL.

Hope this was helpful.

 

WordPress LightBox passing Get Variable Problem Solution

On 6th january i have got an Error in WordPress LightBox Plugin to pass GET Variable

I found the solution by Javascript

Here is code for that

1.This is my Scirpt put in Additional script in wordpress but you can also put in .js file anywhere on any php file


<script language="javascript">

function getVaribaleConcate(){

//these are the form object which i want to pass in get variable

var j = document.getElementById("eml").value;
 var s =  document.getElementById("ticket").value;
 document.getElementById("pad").href = "viewstatus.php?m=" + j;
 document.getElementById("pad").href += "&t=" + s;
 }
 </script>

You can Also put any no of variable in above code

Example


document.getElementById("pad").href += "&t=" + s;

this is the final string which assign to href of anchor tag

2.Now Call this from any Link Click Or From any Event And Call LightBox


&nbsp;

<a href=”Example.php?” onclick=” getVaribaleConcate()” rel=”LighBox”>Click Here</a>

Here LightBox Indicating the Code for Your LighBox Installplugin which is inbuilt in wordpress

href=example.php?  indicating  HyperReference File where we want to Submit our data

Onclick getVaribaleConcate() Use to concate The get Varible in url

3.The Example.php where the lightbox is calling and GetVariable is Display in that file


<?php

if(isset($_GET['m']) && isset($_GET['t']) && $_GET['m'] != '' && $_GET['t'] != '')

{

$email = $_GET['m'];

$ticket = $_GET['t'];

echo  $email . “<br/>”;

echo $ticket;

}

?>

I hope this code may be help u

🙂

Solving USPS shipping rate change issue with magento

On 2nd January 2011 USPS updated their shipping rates and made some changes to the data types and grammar of their third party connection module also they change method name. Many of the magento stores around the web stopped displaying the shipping rates from USPS. Here I am putting a guide to solve this issue and get the shipping rates displayed on magento store front.

I have tested this with Magento 1.3.0.0 and work with all other with relevant changes. Take care about the line numbers as those may change with respect to editor you use.

Step 1:

File location: /app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php

On line 279 you will find following code

(“foreach ($xml->Package->Postage as $postage) {”,

Add this code after above line:


$postage->MailService = str_replace("&lt;sup&gt;&amp;reg;&lt;/sup&gt;","",(string)$postage->MailService);

Step 2:

The fix for international is very similar to the original fix. Below the current fix about 20 lines you will find following code “foreach ($xml->Package->Service as $service) {“

Add this code after above line:


$service->SvcDescription = str_replace("&lt;sup&gt;&amp;reg;&lt;/sup& gt;","",(string)$service->SvcDescription);

Step: 3

Fix for First-class mail and international

Go to In file: /app/code/core/Mage/Usa/etc/config.xml

Find similar this:


<allowed_methods>Bound Printed Matter,Express Mail,Express Mail Flat-Rate Envelope,Express Mail Flat-Rate Envelope Hold For Pickup,Express Mail Flat-Rate Envelope Sunday/Holiday Guarantee,Express Mail Hold For Pickup,Express Mail International,Express Mail International (EMS) Flat-Rate Envelope,Express Mail PO to PO,Express Mail Sunday/Holiday Guarantee,First-Class Mail International Large Envelope,First-Class Mail International Letters,First-Class Mail International Package,First-Class,First-Class Mail,First-Class Mail Flat,First-Class Mail International,First-Class Mail Letter,First-Class Mail Parcel,Global Express Guaranteed,Global Express Guaranteed Non-Document Non-Rectangular,Global Express Guaranteed Non-Document Rectangular,Library Mail,Media Mail,Parcel Post,Priority Mail,Priority Mail Flat-Rate Box,Priority Mail Flat-Rate Envelope,Priority Mail International,Priority Mail International Flat-Rate Box,Priority Mail International Flat-Rate Envelope,Priority Mail International Large Flat-Rate Box,Priority Mail Large Flat-Rate Box,USPS GXG Envelopes</allowed_methods>

And Replace with this code


<allowed_methods>Bound Printed Matter,Express Mail,Express Mail Flat-Rate Envelope,Express Mail Flat-Rate Envelope Hold For Pickup,Express Mail Flat-Rate Envelope Sunday/Holiday Guarantee,Express Mail Hold For Pickup,Express Mail International (EMS),Express Mail International (EMS) Flat-Rate Envelope,Express Mail PO to PO,Express Mail Sunday/Holiday Guarantee,First-Class Mail International Large Envelope,First-Class Mail International Letters,First-Class Mail International Package,First-Class,First-Class Mail,First-Class Mail Flat,First-Class Mail International,First-Class Mail Letter,First-Class Mail Parcel,Global Express Guaranteed,Global Express Guaranteed Non-Document Non-Rectangular,Global Express Guaranteed Non-Document Rectangular,Library Mail,Media Mail,Parcel Post,Priority Mail,Priority Mail Flat-Rate Box,Priority Mail Flat-Rate Envelope,Priority Mail International,Priority Mail International Flat-Rate Box,Priority Mail International Flat-Rate Envelope,Priority Mail International Large Flat-Rate Box,Priority Mail Large Flat-Rate Box,USPS GXG Envelopes,First-Class Mail Package,First-Class Mail International Package**</allowed_methods>

Step: 4

Then Find similar this:


<methods>Bound Printed Matter,Express Mail,Express Mail Flat-Rate Envelope,Express Mail Flat-Rate Envelope Hold For Pickup,Express Mail Flat-Rate Envelope Sunday/Holiday Guarantee,Express Mail Hold For Pickup,Express Mail International (EMS),Express Mail International (EMS) Flat-Rate Envelope,Express Mail PO to PO,Express Mail Sunday/Holiday Guarantee,First-Class Mail International Large Envelope,First-Class Mail International Letters,First-Class Mail International Package,First-Class,First-Class Mail,First-Class Mail Flat,First-Class Mail International,First-Class Mail Letter,First-Class Mail Parcel,Global Express Guaranteed,Global Express Guaranteed Non-Document Non-Rectangular,Global Express Guaranteed Non-Document Rectangular,Library Mail,Media Mail,Parcel Post,Priority Mail,Priority Mail Flat-Rate Box,Priority Mail Flat-Rate Envelope,Priority Mail International,Priority Mail International Flat-Rate Box,Priority Mail International Flat-Rate Envelope,Priority Mail International Large Flat-Rate Box,Priority Mail Large Flat-Rate Box,USPS GXG Envelopes</methods>

And Replace with


<methods>Bound Printed Matter,Express Mail,Express Mail Flat-Rate Envelope,Express Mail Flat-Rate Envelope Hold For Pickup,Express Mail Flat-Rate Envelope Sunday/Holiday Guarantee,Express Mail Hold For Pickup,Express Mail International (EMS),Express Mail International (EMS) Flat-Rate Envelope,Express Mail PO to PO,Express Mail Sunday/Holiday Guarantee,First-Class Mail International Large Envelope,First-Class Mail International Letters,First-Class Mail International Package,First-Class,First-Class Mail,First-Class Mail Flat,First-Class Mail International,First-Class Mail Letter,First-Class Mail Parcel,Global Express Guaranteed,Global Express Guaranteed Non-Document Non-Rectangular,Global Express Guaranteed Non-Document Rectangular,Library Mail,Media Mail,Parcel Post,Priority Mail,Priority Mail Flat-Rate Box,Priority Mail Flat-Rate Envelope,Priority Mail International,Priority Mail International Flat-Rate Box,Priority Mail International Flat-Rate Envelope,Priority Mail International Large Flat-Rate Box,Priority Mail Large Flat-Rate Box,USPS GXG Envelopes,First-Class Mail Package,First-Class Mail International Package**</methods>

Step: 5

Go to In file /app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php

Find function getCode($type, $code='') and replace with this code

public function getCode($type, $code='')

{

$codes = array(

'service'=>array(

'FIRST CLASS' => Mage::helper('usa')->__('First-Class'),

'First-Class Mail International Package**' => Mage::helper('usa')->__('First-Class Mail International Package**'),

'PRIORITY'    => Mage::helper('usa')->__('Priority Mail'),

'EXPRESS'     => Mage::helper('usa')->__('Express Mail'),

'BPM'         => Mage::helper('usa')->__('Bound Printed Matter'),

'PARCEL'      => Mage::helper('usa')->__('Parcel Post'),

'MEDIA'       => Mage::helper('usa')->__('Media Mail'),

'LIBRARY'     => Mage::helper('usa')->__('Library'),

//                'ALL'         => Mage::helper('usa')->__('All Services'),

),

'method'=>array(

'First-Class',

'First-Class Mail International Package',

'Express Mail',

'Express Mail PO to PO',

'Priority Mail',

'Parcel Post',

'Express Mail Flat-Rate Envelope',

'Priority Mail Flat-Rate Box',

'Bound Printed Matter',

'Media Mail',

'Library Mail',

'Priority Mail Flat-Rate Envelope',

'Global Express Guaranteed',

'Global Express Guaranteed Non-Document Rectangular',

'Global Express Guaranteed Non-Document Non-Rectangular',

'Express Mail International (EMS)',

'Express Mail International (EMS) Flat Rate Envelope',

'Priority Mail International',

'Priority Mail International Flat Rate Box',

),

'service_to_code'=>array(

'First-Class'                      => 'FIRST CLASS',

'First-Class Mail International Package**'          => 'First-Class Mail International Package**',

'Express Mail'                     => 'EXPRESS',

'Express Mail PO to PO'            => 'EXPRESS',

'Priority Mail'                    => 'PRIORITY',

'Parcel Post'                      => 'PARCEL',

'Express Mail Flat-Rate Envelope'  => 'EXPRESS',

'Priority Mail Flat-Rate Box'      => 'PRIORITY',

'Bound Printed Matter'             => 'BPM',

'Media Mail'                       => 'MEDIA',

'Library Mail'                     => 'LIBRARY',

'Priority Mail Flat-Rate Envelope' => 'PRIORITY',

'Global Express Guaranteed'        => 'EXPRESS',

'Global Express Guaranteed Non-Document Rectangular'     => 'EXPRESS',

'Global Express Guaranteed Non-Document Non-Rectangular' => 'EXPRESS',

'Express Mail International (EMS)'                       => 'EXPRESS',

'Express Mail International (EMS) Flat-Rate Envelope'    => 'EXPRESS',

'Priority Mail International'                            => 'PRIORITY',

'Priority Mail International Flat-Rate Box'              => 'PRIORITY',

'Priority Mail International Large Flat-Rate Box'        => 'PRIORITY'

),

'first_class_mail_type'=>array(

'LETTER'      => Mage::helper('usa')->__('Letter'),

'FLAT'        => Mage::helper('usa')->__('Flat'),

'PARCEL'      => Mage::helper('usa')->__('Parcel'),

),

'container'=>array(

'VARIABLE'           => Mage::helper('usa')->__('Variable'),

'FLAT RATE BOX'      => Mage::helper('usa')->__('Flat Rate Box'),

'FLAT RATE ENVELOPE' => Mage::helper('usa')->__('Flat Rate Envelope'),

'RECTANGULAR'        => Mage::helper('usa')->__('Rectangular'),

'NONRECTANGULAR'     => Mage::helper('usa')->__('Non-rectangular'),

),

'size'=>array(

'REGULAR'     => Mage::helper('usa')->__('Regular'),

'LARGE'       => Mage::helper('usa')->__('Large'),

'OVERSIZE'    => Mage::helper('usa')->__('Oversize'),

),

'machinable'=>array(

'true'        => Mage::helper('usa')->__('Yes'),

'false'       => Mage::helper('usa')->__('No'),

),

);

$methods = $this->getConfigData('methods');

if (!empty($methods)) {

$codes['method'] = explode(",", $methods);

} else {

$codes['method'] = array();

}

if (!isset($codes[$type])) {

//            throw Mage::exception('Mage_Shipping', Mage::helper('usa')->__('Invalid USPS XML code type: %s', $type));

return false;

} elseif (''===$code) {

return $codes[$type];

}

if (!isset($codes[$type][$code])) {

//            throw Mage::exception('Mage_Shipping', Mage::helper('usa')->__('Invalid USPS XML code for type %s: %s', $type, $code));

return false;

} else {

return $codes[$type][$code];

}

}

Then refresh cache

Then go to shipping method in admin > under USPS > Allowed method > select First-Class Mail International Package** and First-Class Mail Package.

Refresh cache.

To prevent you from changing core code and can be removed once Magento has posted a fix. Move your code in app/local/ folder

example

File to be modified location: /app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php

Move to new location: /app/code/local/Mage/Usa/Model/Shipping/Carrier/Usps.php

And

/app/code/core/Mage/Usa/etc/config.xml

Move to new location:

/app/code/local/Mage/Usa/etc/config.xml

Hope this help 🙂