Search This Blog

Monday 31 December 2012

Download a file using PHP script

Wednesday 12 December 2012

Integrating with Facebook with Wordpress

1. Install the APP in Facebook http://apps.facebook.com/rssgraffiti/
a. This will just push the post to Face Book

2. Create an application in Facebook https://developers.facebook.com/blog/post/2012/06/12/facebook-integration-for-wordpress/ and Install the WP Extension http://wordpress.org/extend/plugins/facebook/
a. Like, Send, Subscribe buttons
b. WP Widgets for following:
i. Recommendations
ii. Recent Activity
iii. Like, Send, and Subscribe buttons.
c. Short codes for Like and Send buttons

Force URLs to lowercase with Apache rewrite and PHP

Force URLs to lowercase with Apache rewrite and PHP:
#### Add following code to HTaccess ###########
RewriteEngine on
RewriteBase /
# force url to lowercase if upper case is found
RewriteCond %{REQUEST_URI} [A-Z]
# Exclude images being redirected
RewriteCond %{REQUEST_URI} !(\.jpg|\.png|\.gif|\.css|\.jpeg|\.js|\.bmp|\.swf)$ [NC]
# ensure it is not a file on the drive first
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule (.*) rewrite-strtolower.php?rewrite-strtolower-url=$1 [QSA,L]


######## Create PHP file with name rewrite-strtolower.php and add the followinf code into that file. Place this php file smae folder as htaccess

if(isset($_GET['rewrite-strtolower-url'])) {
    $url = $_GET['rewrite-strtolower-url'];
    unset($_GET['rewrite-strtolower-url']);
    $params = http_build_query($_GET);
    if(strlen($params)) {
        $params = '?' . $params;
    }
    header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . strtolower($url) . $params, true, 301);
    exit;
}
header("HTTP/1.0 404 Not Found");
die('Unable to convert the URL to lowercase. You must supply a URL to work upon.');

Monday 10 December 2012

Adding upload field in contact form and send as attachment


Adding upload field in contact form and send as attachment
http://www.blog.magepsycho.com/adding-upload-field-in-contact-form-and-send-as-attachment/

Create Dynamic CMS Navigation For Magento Frontend
http://www.blog.magepsycho.com/create-dynamic-cms-navigation-for-magento-frontend/


Merging registration form with default login page of magento (creating mini registration form)
http://www.blog.magepsycho.com/merging-registration-form-with-default-login-page-of-magento-creating-mini-registration-form/

Disable Local Modules:
Even you disable all the local modules using following code in app/etc/local.xml:
<disable_local_modules>true</disable_local_modules>

or

using following code in app/etc/modules/*.xml
<active>false</active>

How to check if customer is already logged in from another location?
http://www.blog.magepsycho.com/how-to-check-if-customer-is-already-logged-in-from-another-location/

Configuring Magento for Development / Debug Mode
http://www.blog.magepsycho.com/configuring-magento-for-development-debug-mode/

How to use WYSIWYG editor (TinyMCE) in custom Admin Magento Module
http://www.blog.magepsycho.com/how-to-use-wysiwyg-editor-tinymce-in-custom-admin-magento-module/

Updating product qty in Magento in an easier & faster way
http://www.blog.magepsycho.com/updating-product-qty-in-magento-in-an-easier-faster-way/

Using Magento header / footer outside of Magento
http://www.blog.magepsycho.com/using-magento-header-footer-outside-of-magento/

Usage of <can_be_empty> tag for system configuration multi-select field
http://www.blog.magepsycho.com/usage-of-can_be_empty-tag-for-system-configuration-multi-select-field/







Sunday 9 December 2012

Adding a mass action to Magento Grid

http://www.blog.magepsycho.com/adding-new-mass-action-to-admin-grid-in-magento/

Adding a new button on order view page:
http://stackoverflow.com/questions/10691895/magento-add-button-to-sales-order-view-page-observer-event

Add a comments field to checkout page for the order:
http://www.magecorner.com/magento-order-comments/

Adding custom system config xml in Magento:
http://www.ecomdev.org/2010/10/27/custom-configuration-fields-in-magento.html

Adding a button to system configuration:
http://www.atwix.com/magento/add-button-to-system-configuration/


DB queries profiler:
Magento provides an ability for developers to track database queries. For this purpose you should use a built in DB resource profiler. It can help you to inspect database queries, detect the longest query, detect the slowest query, etc.. Here is a small example on how to use a DB profiler for your own needs :
$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')->getProfiler();
foreach ($profiler->getQueryProfiles() as $query) {
    $queryTime[] = $query->getElapsedSecs(); // Get the query execution time
    $queryRaw[] = $query->getQuery(); // Get the query text
}

Thursday 6 December 2012

Frequently used Putty commands

Database Dump:
mysqldump -u username -h localhost -p dbname > filename.sql

Import Database Dump:
mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

Tar a folder:
tar -cv foldername > foldername.tar

GZip the tar file:
gzip foldername.tar

Extract tar.gz file:
tar -zxvf yourfile.tar.gz

Extract .bz2 file:
bunzip2  yourfile.bz2

Extract tar.bz2file:
tar jxf backup.tar.bz2

Copy files from source to destination:
scp local.xml username@hostnameORipaddress:FullFolderTargetPath


All the above commands require password.

Issues with MySql Dump:
mysqldump: Got error: 1016: Can’t open file: … (errno: 24) when using LOCK TABLES

Check and change the file permissions:

mysqldump: Got error: 1016:
http://voidweb.com/2011/05/mysqldump-got-error-1016-cant-open-file-errno-24-when-using-lock-tables/




Linux remove entire directory including all files and sub-directories command

To remove all directories and subdirectories use rm command. For example remove *.doc files and all subdirectories and files inside letters directory, type the following command (warning all files including subdirectories will be deleted permanently):

$ rm -rf letters/

Where,

    -r : Attempt to remove the file hierarchy rooted in each file argument i.e. recursively remove subdirectories and files from the specified directory.
    -f : Attempt to remove the files without prompting for confirmation, regardless of the file's permissions

Copy files and folders from one directory to another:
http://www.cyberciti.biz/faq/copy-folder-linux-command-line/

Tuesday 4 December 2012

PHP: Find secure connection

<?php
$secure_connection = false;
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'
    || $_SERVER['SERVER_PORT'] == 443) {

    $secure_connection = true;
}
?>

<?php if($secure_connection): ?>
  // Secure content goes here...
<?php else: ?>
  // Unsecure content goes here...
<?php endif; ?>