Verify Item Purchases with the Envato API

This article focuses on how to simply and efficiently converse with Envato’s API in order to verify the authors’ customers’ purchase codes in the author’s own applications. I talk through all the steps to set up this function, covering how to create the unique API key required, using the PHP cURL function and interpreting the output.

<?php
    function verify_envato_purchase_code($code_to_verify) {
    // Your Username
    $username = 'USERNAME';
      
    // Set API Key  
    $api_key = 'API KEY';
      
    // Open cURL channel
    $ch = curl_init();
       
    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, "http://marketplace.envato.com/api/edge/". $username ."/". $api_key ."/verify-purchase:". $code_to_verify .".json");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       
    // Decode returned JSON
    $output = json_decode(curl_exec($ch), true);
       
    // Close Channel
    curl_close($ch);
       
    // Return output
    return $output;
}
  
$purchase_key = 'PURCHASE KEY TO CHECK';
  
$purchase_data = verify_envato_purchase_code( $purchase_key );
  
if( isset($purchase_data['verify-purchase']['buyer']) ) {
      
    echo '<strong>Valid License Key!</strong><br>Details;<ul>';
    echo '<li>Item ID: ' . $purchase_data['verify-purchase']['item_id'] . '</li>';
    echo '<li>Item Name: ' . $purchase_data['verify-purchase']['item_name'] . '</li>';
    echo '<li>Buyer: ' . $purchase_data['verify-purchase']['buyer'] . '</li>';
    echo '<li>License: ' . $purchase_data['verify-purchase']['licence'] . '</li>';
    echo '<li>Created At: ' . $purchase_data['verify-purchase']['created_at'] . '</li>';
    echo '</ul>'; 
} else {
   echo 'Invalid license key.';
}
?>

Sources:
http://www.wpeka.com/verify-item-purchases-envato.html
http://hbt.io/verify-item-purchases-envato/

Magento upgrading with Git

Git-Logo

It’s rather easy but you have to ensure that your site is based on some master repo that can be merged down the stream with earlier versions (repo that has all Magento versions as tags or branches that can be merged to latest from first). So here’s two scenarios to follow

1. My site is not in git

  1. start by cloning from master repo that has all magento versions (at least to the version you are currently using)
  2. get your clone and checkout new branch with the version you are currently using
  3. copy over your current site to this version
  4. after that done “git status” will show you the diff with original version you started with and all the edits you have made to it
  5. its now smart to move all core edits to local codepool and revert any changes in core to original files, move any edts in default or base templates to your own template and revert changes in default or base template files. Same goes with all the files that look modified against the original version. This gives you “all my changes are separate from original code and they will not conflict my upgrades”, it’s wise to commit this state
  6. If all things are separated from original files then it’s time to upgrade. Turn on default theme, disable all local and community extensions , merge the new version with your current branch. Visit the site to perform the upgrade
  7. Now your site is upgraded and you can turn on your theme and custom extensions one by one to see what is compatible and what not. Debug and solve one by one

My site is already in git

  1. if it is based on repo that has all versions you are in good condition (skip 2)
  2. if it’s not then you can add some repo that has it all as your remote and start with merging your current version and separating changes from original like described in first scenario
  3. make a new branch of your current site used
  4. merge with new version
  5. disable all local, community extensions, turn on default theme, and upgrade
  6. enable theme, extensions one by one and debug where conflicts happen

It’s common to have a git setup like follows:

  • MAGENTO MASTER -> REMOTE ORIGN THAT HAS ALL MAGENTO VERSIONS
  • YOUR MASTER -> REMOTE ORIGIN IS MAGENTO MASTER
    • branch: yoursite_dev
    • branch: yoursite_stage
    • branch: yoursite_live

You always develop on your_dev branch andif changes are ready for evaluation you merge _stage with _dev and if changes are approved you merge the state to _live either from _dev or from _stage.

commands based on theoretical endpoints

git clone git://github.com/speedupmate/Magento-CE-Mirror.git yourprojectdir
cd yourprojectdir
git fetch --tags
git tag
git checkout -b yoursite_dev magento-1.5.0.1
git checkout -b yoursite_stage yoursite_dev
git checkout -b yoursite_live yoursite_dev
git checkout yoursite_dev
git branch
//copy in your site
//separate changes or originals
//add any file/dir with local importance to .gitignore
//turn of your default theme, disable all local/community extensions and overrides
//assuming you are on dev branch commit your clean state
git merge magento-1.6.0.0
//visit the site to execute the upgrade
//enable your theme , extensions , debug

this gives you a starting point for scenario 1 and after that you could just copy in your site and start separating changes and making order in your current site and themes.

Source:
http://stackoverflow.com/a/7270590/1794834

PayPal Offerings Worldwide

paypal

Use PayPal to send and receive money worldwide. With over 230 million accounts worldwide and growing, we help you securely, easily and quickly pay and get paid locally and across borders.

https://www.paypal.com/us/cgi-bin/webscr?cmd=_display-country-functionality-outside

CakePHP How to change the X-Mailer

Basically, on your CakeEmail object:

$CakeEmail = new CakeEmail();
$CakeEmail->addHeaders(array('X-Mailer' => 'My custom X-Mailer'));

If set manually Cake will not add his default value ‘CakePHP Email’.

Source:
http://stackoverflow.com/a/18032036

Verify hex color string

Verify hex color string
Verify hex color string

This PHP script checks if a string $color is a hex color or not. The second IF statement will add the pound symbol at the beginning if it is missing from the hex color value.

//Check for a hex color string '#c1c2b4'
if(preg_match('/^#[a-f0-9]{6}$/i', $color)) //hex color is valid
{
	//Verified hex color
} 

//Check for a hex color string without hash 'c1c2b4'
elseif(preg_match('/^[a-f0-9]{6}$/i', $color)) //hex color is valid
{
	$fix_color = '#' . $color;
}

Source:
http://code.hyperspatial.com/250/verify-hex-color-string/

SSH: Backup all databases

You can dump all the databases into a single .sql file like so:

mysqldump --all-databases > database_backup.sql

Or you can dump them individually to a directory with the date of backup to /home/ by using a for loop, such as this:

now=$(date +"%m_%d_%Y");mkdir /home/mysql.back.$now && for i in $(mysql -BNe 'show databases'| grep -v _schema);do echo $i; sudo mysqldump $i > /home/mysql.back.$now/$i.sql ; done 

Split and merge large files

Use the split command to do this:

split --bytes=1024m bigfile.iso small_file_

That command will split bigfile.iso into files that are 1024 MB in size (1GB) and name the various parts small_file_aa, small_file_ab, etc. You can specify b for bytes, k for Kilobytes and m for Megabytes to specify sizes.

To join the files back together on Linux:

cat small_file_* > joined_file.iso

Similarly to join the split files on a Windows machine, use the copy command:

copy /b small_file_* joined_file.iso

Source:
http://linuxpoison.blogspot.com/2008/09/split-and-merge-large-files.html

Cakephp 2.0 default hash type

The default hash type of Cakephp 2.0 is sha1. But when you have set a Security.Salt in the core.php this will be added before your password and before the encryption is done.

To generate a password with Salt you can either create an User::add method in Cakephp and use the Authcomponent or create some your own. I needed it for fast checking user accounts with a javascript frontend (no views are used).

// Your salt from core.php
// Configure::write('Security.salt', 'e4ac429040b9d4552bc425b677b64aca104c5f84f');
$salt = 'e4ac429040b9d4552bc425b677b64aca104c5f84f';
$yourpassword = 'mysecret';
 
$password = sha1($salt.$yourpassword);
// The password to use in Cakephp with the Authcomponent
print $password;

Thats all, you use that password in your mysql admin tool to create users on the fly.

Source