Archive for January, 2012

Detect Mobile User Agents & Browsers

Posted: January 31, 2012 in Mobile

Helping detect and better serve mobile browsers

Follow us on Twitter for updates! DetectMobiles

This PHP function lets you choose how to manage your mobile visitors, they can be redirected to a page built for mobiles or you can use it to decide which markup language and stylesheet to show that user.

It’s main function is to answer this question:

Is this visitor to my website using a mobile phone or PC?

Download Code

Download the code, unzip the archive then upload it to your website. Then view the usage guide or use the function generator to build a custom function to suit you and your mobile visitors.

 

Usage guide

It’s not rocket science, it’s easy to use!

But you need to understand at least basic PHP to get it working.

You need to include the file with the function then call the function before your PHP pages do anything else. See Support.

require_once('mobile_device_detect.php');
$mobile = mobile_device_detect();

The function has eight parameters that can be passed to it which define the way it handles different scenarios. These paramaters are:

  • iPhone – Set to true to treat iPhones as mobiles, false to treat them like full browsers or set a URL (including http://) to redirect iPhones and iPods to.
  • iPad – Set to true to treat iPads as mobiles, false to treat them like full browsers or set a URL (including http://) to redirect iPads to.
  • Android – Set to true to treat Android handsets as mobiles, false to treat them like full browsers or set a URL (including http://) to redirect Android and Google mobile users to.
  • Opera Mini – Set to true to treat Opera Mini like a mobile, false to treat it like full browser or set a URL (including http://) to redirect Opera Mini users to.
  • Blackberry – Set to true to treat Blackberry like a mobile, false to treat it like full browser or set a URL (including http://) to redirect Blackberry users to.
  • Palm – Set to true to treat Palm OS like a mobile, false to treat it like full browser or set a URL (including http://) to redirect Palm OS users to.
  • Windows – Set to true to treat Windows Mobiles like a mobile, false to treat it like full browser or set a URL (including http://) to redirect Windows Mobile users to.
  • Mobile Redirect URL – This should be full web address (including http://) of the site (or page) you want to send mobile visitors to. Leaving this blank will make the script return true when it detects a mobile.
  • Desktop Redirect URL – This should be full web address (including http://) of the site (or page) you want to send non-mobile visitors to. Leaving this blank will make the script return false when it fails to detect a mobile.

 

This is the second part of a two-part tutorial, in which we use PHP, MySQL and jQuery mobile to build a simple computer web store. In the previous part we created the models and the controllers, and this time we will be writing our views.

jQuery mobile

First, lets say a few words about the library we will be using. jQuery mobile is a user interface library that sits on top of jQuery and provides support for a wide array of devices in the form of ready to use widgets and a touch-friendly development environment. It is still in beta, but upgrading to the official 1.0 release will be as simple as swapping a CDN URL.

The library is built around progressive enhancement. You, as the developer, only need to concern yourself with outputting the correct HTML, and the library will take care of the rest. jQuery mobile makes use of the HTML5 data- attributes and by adding them, you instruct the library how it should render your markup.

In this tutorial we will be using some of the interface components that this library gives us – lists, header and footer bars and buttons, all of which are defined using the data-role attributes, which you will see in use in the next section.

Rendering Views

The views are PHP files, or templates, that generate HTML code. They are printed by the controllers using the render() helper function. We have 7 views in use for this website – _category.php, _product.php, _header.php, _footer.php, category.php, home.php and error.php, which are discussed later on. First, here is render() function:

includes/helpers.php

/* These are helper functions */

function render($template,$vars = array()){

	// This function takes the name of a template and
	// a list of variables, and renders it.

	// This will create variables from the array:
	extract($vars);

	// It can also take an array of objects
	// instead of a template name.
	if(is_array($template)){

		// If an array was passed, it will loop
		// through it, and include a partial view
		foreach($template as $k){

			// This will create a local variable
			// with the name of the object's class

			$cl = strtolower(get_class($k));
			$$cl = $k;

			include "views/_$cl.php";
		}

	}
	else {
		include "views/$template.php";
	}
}

The first argument of this function is the name of the template file in the views/ folder (without the .php extension). The next is an array with arguments. These are extracted and form real variables which you can use in your template.

There is one more way this function can be called – instead of a template name, you can pass an array with objects. If you recall from last time, this is what is returned by using the find() method. So basically if you pass the result of Category::find() to render, the function will loop through the array, get the class names of the objects inside it, and automatically include the _category.php template for each one. Some frameworks (Rails for example) call these partials.

Computer Store with PHP, MySQL and jQuery MobileComputer Store with PHP, MySQL and jQuery Mobile

The Views

Lets start off with the first view – the header. You can see that this template is simply the top part of a regular HTML5 page with interleaved PHP code. This view is used in home.php and category.php to promote code reuse.

includes/views/_header.php

<!DOCTYPE html>
<html>
	<head>
	<title><?php echo formatTitle($title)?></title> 

	<meta name="viewport" content="width=device-width, initial-scale=1" /> 

	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
    <link rel="stylesheet" href="assets/css/styles.css" />
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
</head>
<body> 

<div data-role="page">

	<div data-role="header" data-theme="b">
	    <a href="./" data-icon="home" data-iconpos="notext" data-transition="fade">Home</a>
		<h1><?php echo $title?></h1>
	</div>

	<div data-role="content">

In the head section we include jQuery and jQuery mobile from jQuery’s CDN, and two stylesheets. The body section is where it gets interesting. We define a div with the data-role=”page” attribute. This, along with the data-role=”content” div, are the two elements required by the library to be present on every page.

The data-role=”header” div is transformed into a header bar. The data-theme attribute chooses one of the 5 standard themes. Inside it, we have a link that is assigned a home icon, and has its text hidden. jQuery Mobile comes with a set of icons you can choose from.

The closing tags (and the footer bar) reside in the _footer.php view:

includes/views/_footer.php

	</div>

	<div data-role="footer" id="pageFooter">
		<h4><?php echo $GLOBALS['defaultFooter']?></h4>
	</div>
</div>

</body>
</html>

Nothing too fancy here. We only have a div with the data-role=”footer” attribute, and inside it we print the globally accessible $defaultFooter variable, defined in includes/config.php.

Neither of the above views are printed directly by our controllers. They are instead used by category.php and home.php:

includes/views/home.php

<?php render('_header',array('title'=>$title))?>

<p>Welcome! This is a demo for a ...</p>
<p>Remember to try browsing this ...</p>

<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
    <li data-role="list-divider">Choose a product category</li>
    <?php render($content) ?>
</ul>

<?php render('_footer')?>

If you may recall, the home view was rendered in the home controller. There we passed an array with all the categories, which is available here as $content. So what this view does, is to print the header, and footer, define a jQuery mobile listview (using the data-role attribute), and generate the markup of the categories passed by the controller, using this template (used implicitly by render()):

index.php/views/_category.php

<li <?php echo ($active == $category->id ? 'data-theme="a"' : '') ?>>
<a href="?category=<?php echo $category->id?>" data-transition="fade">
	<?php echo $category->name ?>
    <span><?php echo $category->contains?></span></a>
</li>

Notice that we have a $category PHP variable that points to the actual object this view is being generated for. This is done in lines 24/25 of the render function. When the user clicks one of the links generated by the above fragment, he will be taken to the /?category=someid url, which will show the category.php view, given below.

<?php render('_header',array('title'=>$title))?>

<div>
	<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="c">
        <?php render($products) ?>
    </ul>
</div>

<div>
    <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
        <li data-role="list-divider">Categories</li>
        <?php render($categories,array('active'=>$_GET['category'])) ?>
    </ul>
</div>

<?php render('_footer')?>

This file also uses the header, footer and _category views, but it also presents a column with products (passed by the category controller). The products are rendered using the _product.php partial:

<li>
	<img src="assets/img/<?php echo $product->id ?>.jpg" alt="<?php echo $product->name ?>" />
	<?php echo $product->name ?> <i><?php echo $product->manufacturer?></i>
	<b>$<?php echo $product->price?></b>
</li>

As we have an image as the first child of the li elements, it is automatically displayed as an 80px thumbnail by jQuery mobile.

One of the advantages to using the interface components defined in the library is that they are automatically scaled to the width of the device. But what about the columns we defined above? We will need to style them ourselves with some CSS3 magic:

assets/css/styles.css

media all and (min-width: 650px){

	.rightColumn{
		width:56%;
		float:right;
		margin-left:4%;
	}

	.leftColumn{
		width:40%;
		float:left;
	}

}

.product i{
	display:block;
	font-size:0.8em;
	font-weight:normal;
	font-style:normal;
}

.product img{
	margin:10px;
}

.product b{
	position: absolute;
	right: 15px;
	top: 15px;
	font-size: 0.9em;
}

.product{
	height: 80px;
}

Using a media query, we tell the browser that if the view area is wider than 650px, it should display the columns side by side. If it is not (or if the browser does not support media queries) they will be displayed one on top of the other, the regular “block” behavior.

We’re done!

In the second and last part of this tutorial, we wrote our views to leverage the wonderful features of jQuery mobile. With minimal effort on our part, we were able to describe the roles of our markup and easily create a fully fledged mobile website.


jQuery

In this two-part tutorial, we will be building a simple website with PHP and MySQL, using the Model-View-Controller (MVC) pattern. Finally, with the help of the jQuery Mobile framework, we will turn it into a touch-friendly mobile website, that works on any device and screen size.

In this first part, we concentrate on the backend, discussing the database and MVC organization. In part two, we are writing the views and integrating jQuery Mobile.

The File Structure

As we will be implementing the MVC pattern (in effect writing a simple micro-framework), it is natural to split our site structure into different folders for the models, views and controllers. Don’t let the number of files scare you – although we are using a lot of files, the code is concise and easy to follow.

The Directory StructureThe Directory Structure

The Database Schema

Our simple application operates with two types of resources – categories and products. These are given their own tables – jqm_categories, and jqm_products. Each product has a category field, which assigns it to a category.

jqm_categories Table Structurejqm_categories Table Structure

The categories table has an ID field, a name and a contains column, which shows how many products there are in each category.

jqm_products Table Structurejqm_products Table Structure

The product table has a name, manufacturer, price and a category field. The latter holds the ID of the category the product is added to.

You can find the SQL code to create these tables in tables.sql in the download archive. Execute it in the SQL tab of phpMyAdmin to have a working copy of this database. Remember to also fill in your MySQL login details in config.php.

The Models

The models in our application will handle the communication with the database. We have two types of resources in our application – products and categories. The models will expose an easy to use method – find() which will query the database behind the scenes and return an array with objects.

Before starting work on the models, we will need to establish a database connection. I am using the PHP PDO class, which means that it would be easy to use a different database than MySQL, if you need to.

includes/connect.php

/*
	This file creates a new MySQL connection using the PDO class.
	The login details are taken from includes/config.php.
*/

try {
	$db = new PDO(
		"mysql:host=$db_host;dbname=$db_name;charset=UTF-8",
		$db_user,
		$db_pass
	);

    $db->query("SET NAMES 'utf8'");
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
	error_log($e->getMessage());
	die("A database error was encountered");
}

This will put the $db connection object in the global scope, which we will use in our models. You can see them below.

includes/models/category.model.php

class Category{

	/*
		The find static method selects categories
		from the database and returns them as
		an array of Category objects.
	*/

	public static function find($arr = array()){
		global $db;

		if(empty($arr)){
			$st = $db->prepare("SELECT * FROM jqm_categories");
		}
		else if($arr['id']){
			$st = $db->prepare("SELECT * FROM jqm_categories WHERE id=:id");
		}
		else{
			throw new Exception("Unsupported property!");
		}

                // This will execute the query, binding the $arr values as query parameters
		$st->execute($arr);

		// Returns an array of Category objects:
		return $st->fetchAll(PDO::FETCH_CLASS, "Category");
	}
}

Both models are simple class definitions with a single static method – find(). In the fragment above, this method takes an optional array as a parameter and executes different queries as prepared statements.

In the return declaration, we are using the fetchAll method passing it the PDO::FETCH_CLASS constant. What this does, is to loop though all the result rows, and create a new object of the Category class. The columns of each row will be added as public properties to the object.

This is also the case with the Product model:

includes/models/product.model.php

class Product{

	// The find static method returns an array
	// with Product objects from the database.

	public static function find($arr){
		global $db;

		if($arr['id']){
			$st = $db->prepare("SELECT * FROM jqm_products WHERE id=:id");
		}
		else if($arr['category']){
			$st = $db->prepare("SELECT * FROM jqm_products WHERE category = :category");
		}
		else{
			throw new Exception("Unsupported property!");
		}

		$st->execute($arr);

		return $st->fetchAll(PDO::FETCH_CLASS, "Product");
	}
}

The return values of both find methods are arrays with instances of the class. We could possibly return an array of generic objects (or an array of arrays) in the find method, but creating specific instances will allow us to automatically style each object using the appropriate template in the views folder (the ones that start with an underscore). We will talk again about this in the next part of the tutorial.

There, now that we have our two models, lets move on with the controllers.

Computer Store with PHP, MySQL and jQuery MobileComputer Store with PHP, MySQL and jQuery Mobile

The controllers

The controllers use the find() methods of the models to fetch data, and render the appropriate views. We have two controllers in our application – one for the home page, and another one for the category pages.

includes/controllers/home.controller.php

/* This controller renders the home page */

class HomeController{
	public function handleRequest(){

		// Select all the categories:
		$content = Category::find();

		render('home',array(
			'title'		=> 'Welcome to our computer store',
			'content'	=> $content
		));
	}
}

Each controller defines a handleRequest() method. This method is called when a specific URL is visited. We will return to this in a second, when we discuss index.php.

In the case with the HomeController, handleRequest() just selects all the categories using the model’s find() method, and renders the home view (includes/views/home.php) using our render helper function (includes/helpers.php), passing a title and the selected categories. Things are a bit more complex in CategoryController:

includes/controllers/category.controller.php

/* This controller renders the category pages */

class CategoryController{
	public function handleRequest(){
		$cat = Category::find(array('id'=>$_GET['category']));

		if(empty($cat)){
			throw new Exception("There is no such category!");
		}

		// Fetch all the categories:
		$categories = Category::find();

		// Fetch all the products in this category:
		$products = Product::find(array('category'=>$_GET['category']));

		// $categories and $products are both arrays with objects

		render('category',array(
			'title'			=> 'Browsing '.$cat[0]->name,
			'categories'	=> $categories,
			'products'		=> $products
		));
	}
}

The first thing this controller does, is to select the category by id (it is passed as part of the URL). If everything goes to plan, it fetches a list of categories, and a list of products associated with the current one. Finally, the category view is rendered.

Now lets see how all of these work together, by inspecting index.php:

index.php

/*
	This is the index file of our simple website.
	It routes requests to the appropriate controllers
*/

require_once "includes/main.php";

try {

	if($_GET['category']){
		$c = new CategoryController();
	}
	else if(empty($_GET)){
		$c = new HomeController();
	}
	else throw new Exception('Wrong page!');

	$c->handleRequest();
}
catch(Exception $e) {
	// Display the error page using the "render()" helper function:
	render('error',array('message'=>$e->getMessage()));
}

This is the first file that is called on a new request. Depending on the $_GET parameters, it creates a new controller object and executes its handleRequest() method. If something goes wrong anywhere in the application, an exception will be generated which will find its way to the catch clause, and then in the error template.

One more thing that is worth noting, is the very first line of this file, where we require main.php. You can see it below:

main.php

/*
	This is the main include file.
	It is only used in index.php and keeps it much cleaner.
*/

require_once "includes/config.php";
require_once "includes/connect.php";
require_once "includes/helpers.php";
require_once "includes/models/product.model.php";
require_once "includes/models/category.model.php";
require_once "includes/controllers/home.controller.php";
require_once "includes/controllers/category.controller.php";

// This will allow the browser to cache the pages of the store.

header('Cache-Control: max-age=3600, public');
header('Pragma: cache');
header("Last-Modified: ".gmdate("D, d M Y H:i:s",time())." GMT");
header("Expires: ".gmdate("D, d M Y H:i:s",time()+3600)." GMT");

This file holds the require_once declarations for all the models, controllers and helper files. It also defines a few headers to enable caching in the browser (PHP disables caching by default), which speeds up the performance of the jQuery mobile framework.

Continue to Part 2

With this the first part of the tutorial is complete! Continue to part 2, where we will be writing the views and incorporate jQuery Mobile. Feel free to share your thoughts and suggestions in the comment section below.

Cake PHP 10 Topics to read

Posted: January 23, 2012 in Cakephp

Photoshop Shortcuts

Posted: January 20, 2012 in Uncategorized

 

Table of Contents:

  1. Select Tools
  2. View Images
  3. Puppet Warp
  4. Refine Edge
  5. Filter Gallery
  6. Liquify
  7. Vanishing Point
  8. Camera Raw Dialog Box
  9. Black-and-White Dialog Box
  10. Curves
  11. Select and Move Objects
  12. Transform Selections, Selection Borders, and Paths
  13. Edit Paths
  14. Painting
  15. Blending Modes
  16. Select and Edit text
  17. Format Type
  18. Slicing and Optimizing
  19. Photoshop CS5 Panels
  20. 3D tools (PS Extended)
  21. Measurement (PS Extended)
  22. DICOM files (PS Extended)
  23. Extract and Pattern Maker (plug-in)
  24. Function keys

1. Select Tools
v Move tool
m (shift+m) Rectangular Marquee Tool (Elliptical Marquee tool)
l (shift+l) Lasso tool (Polygonal Magnetic Lasso tool)
w (shift+w) Magic Wand tool (Quick Selection tool)
c (shift+c) Crop tool (Slide tool, Slide Select tool)
i (shift+i) Eyedropper tool (Color Sampler tool, Note Tool, Count Tool)
j (shift+j) Spot Healing Brush tool (Healing Brush tool, Patch tool, Red Eye tool)
b (shift+b) Brush tool (Pencil tool, Color Replacement tool, Mixer Brush tool)
s (shift+s) Clone Stamp tool (Pattern Stamp tool)
y (shift+y) History Brush tool (Art History Brush tool)
e (shift+e) Eraser tool (Background Eraser tool, Magic Eraser tool)
g (shift+g) Gradient tool (Paint Bucket tool)
o (shift+o) Dodge tool (Burn tool, Sponge tool)
p (shift+p) Pen tool (Freeform Pen tool)
t (shift+t) Horizontal Type tool (Vertical Type tool, Type Mask tools)
a (shift+a) Path Selection tool (Direct Selection tool)
u (shift+u) Rectangle tool (Rounded Rectangle tool, Ellipse tool, Polygon tool, Line tool, Custom Shape tool)
k (shift+k) 3D Object Rotate tool (Roll, Pan, Slide, Scale tool). PS extended only
n (shift+n) 3D Camera Rotate tool (Roll,Pan, Walk, Zoom tool). PS extended only
h Hand tool
r Rotate View tool
z Zoom tool

▲ up

2. View Images
ctrl+tab Cycle through open documents
shift+ctrl+tab Switch to previous document
shift+ctrl+w Close a file in Photoshop and open Bridge
q Toggle between Standard mode and Quick Mask mode
f / shift+f Toggle forward / toggle backward between Standard Screen Mode, Maximized Screen Mode, Full Screen Mode, and Full Screen Mode with menu bar
space+f / space+shift+f Toggle canvas color forward / toggle canvas color backwards
Double-click Hand tool Fit image in window
ctrl+1 Magnify 100%
space Temporary switch to Hand tool (when not in text-edit mode)
shift+drag
ctrl+space Temporarily switch to Zoom In tool
alt+space Temporarily switch to Zoom Out tool
space+drag Move Zoom marquee while dragging with the Zoom tool
shift+enter in Navigator panel zoom percentage box Apply zoom percentage, and keep zoom percentage box active
ctrl+drag over preview in Navigator panel Zoom in on specified area of an image
space+drag, or drag view area box in Navigator panel Scroll image with Hand tool
page up or page down Scroll up or down 1 screen
shift+page up or page down Scroll up or down 10 units
home or end Move view to upper-left corner or lower right corner
\ (backslash) Toggle layer mask on/off as rubylith (layer mask must be selected)

▲ up

3. Puppet Warp
esc Cancel completely
ctrl+z Undo last pin adjustment
ctrl+a Select all pins
ctrl+d Deselect all pins
shift+click Select multiple pins
shift+drag Move multiple selected pins
h Temporarily hide pins

▲ up

4. Refine Edge
ctrl+alt+r Open the Refine Edge dialog box
f Cycle forward through preview modes
shift+f Cycle (backward) through preview modes
x Toggle between original image and selection preview
p Toggle between original selection and refined version
j Toggle radius preview on and off
e Toggle between Refine Radius and Erase Refinements tools

▲ up

5. Filter Gallery
alt+click a filter Apply a new filter on top of selected
alt+click a disclosure triangle Open/close all disclosure triangles
ctrl Change Cancel button to Default
alt Change Cancel button to Reset
ctrl+z Undo/Redo
ctrl+shift+z Step forward
ctrl+alt+z Step backward

▲ up

6. Liquify
w Forward Warp tool
r Reconstruct tool
c Twirl Clockwise tool
s Pucker tool
b Bloat tool
o Push Left tool
m Mirror tool
t Turbulence tool
f Freeze Mask tool
d Thaw Mask tool
alt+tool Reverse direction for Bloat, Pucker, Push Left, and Mirror tools
alt+drag in preview with Reconstruct tool, Displace, Amplitwist, or Affine mode selected Continually sample the distortion
arrow left / arrow right in Brush Size, Density, Pressure, Rate, or Turbulent Jitter text box Decrease/increase brush size by 2 (or density, pressure, rate, or turbulent jitter by 1). Hold down shift to decrease/increase by 10
arrow left / arrow right with Brush Size, Density, Pressure, Rate, or Turbulent Jitter slider showing Decrease/increase brush size by 2 (or density, pressure, rate, or turbulent jitter by 1). Hold down shift to decrease/increase by 10
tab Cycle through controls on right from top
shift+tab Cycle through controls on right from bottom
alt Change Cancel to Reset

▲ up

7. Vanishing Point
x Zoom 2x (temporary)
ctrl++ / ctrl+- Zoom in / Zoom out
ctrl+0 Fit in view
Double-click Zoom tool Zoom to center at 100%
] / [ Increase / Decrease brush size (Brush, Stamp tools)
shift+] / shift+[ Increase / Decrease brush hardness (Brush, Stamp tools)
ctrl+z Undo last action
ctrl+shift+z Redo last action
ctrl+d Deselect all
ctrl+h Hide selection and planes
arrow keys Move selection 1 pixel
shift+arrow keys Move selection 10 pixels
ctrl+c Copy
ctrl+v Paste
ctrl+shift+t Repeat last duplicate and move
ctrl+alt+t Create a floating selection from the current selection
ctrl+drag Fill a selection with image under the pointer
ctrl+alt+drag Create a duplicate of the selection as a floating selection
alt+shift to rotate Constrain selection to a 15° rotation
ctrl+click the plane Select a plane under another selected plane
ctrl+drag Create 90 degree plane off parent plane
backspace Delete last node while creating plane
Double-click the Create Plane tool Make a full canvas plane, square to the camera
ctrl+shift+h Show/hide measurements (Photoshop Extended only)
ctrl+e Export to a DFX file (Photoshop Extended only)
ctrl+shift+e Export to a 3DS file (Photoshop Extended only)

▲ up

8. Camera Raw Dialog Box
z Zoom tool
h Hand tool
i White Balance tool
s Color Sampler tool
c Crop tool
a Straighten tool
b Spot Removal tool
e Red Eye Removal tool
ctrl+alt+1 Basic panel
ctrl+alt+2 Tone Curve panel
ctrl+alt+3 Detail panel
ctrl+alt+4 HSL/Grayscale panel
ctrl+alt+5 Split Toning panel
ctrl+alt+6 Lens Corrections panel
ctrl+alt+7 Camera Calibration panel
ctrl+alt+8 Presets panel
ctrl+alt+9 Open Snapshots panel
ctrl+alt+shift+t Parametric Curve Targeted Adjustment tool
ctrl+alt+shift+h Hue Targeted Adjustment tool
ctrl+alt+shift+s Saturation Targeted Adjustment tool
ctrl+alt+shift+l Luminance Targeted Adjustment tool
ctrl+alt+shift+g Grayscale Mix Targeted Adjustment tool
t Last-used Targeted Adjustment tool
k Adjustment Brush tool
g Graduated Filter tool
] / [ Increase/decrease brush size
shift+] / shift+[ Increase/decrease brush feather
= / – Increase/decrease Adjustment Brush tool flow in increments of 10
alt Temporarily switch from Add to Erase mode for the Adjustment Brush tool, or from Erase to Add mode
alt+] / alt+[ Increase/decrease temporary Adjustment Brush tool size
alt+shift+] / alt+shift+[ Increase/decrease temporary Adjustment Brush tool feather
alt+= / alt+- Increase/decrease temporary Adjustment Brush tool flow in increments of 10
n Switch to New mode from Add or Erase mode of the Adjustment Brush tool or the Graduated Filter
m Toggle Auto Mask for Adjustment Brush tool
y Toggle Show Mask for Adjustment Brush tool
v Toggle pins for Adjustment Brush tool, Toggle overlay for Graduated Filter, Spot Removal tool, or Red Eye Removal tool.
l or ctrl+] Rotate image left
r or ctrl+[ Rotate image right
ctrl++ / ctrl+- Zoom in / Zoom out
ctrl Temporarily switch to Zoom In tool. (Doesn’t work when Straighten tool is selected. If Crop tool is active, temporarily switches to Straighten tool.)
alt Temporarily switch to Zoom Out tool and change the Open Image button to Open Copy and the Cancel button to Reset.
p Toggle preview
f Full screen mode
shift Temporarily activate the White Balance tool and change the Open Image button to Open Object. (Does not work if Crop tool is active.)
Click the first point; shift+click additional points Select multiple points in Curves panel
ctrl+click in preview Add point to curve in Curves panel
arrow keys Move selected point in Curves panel (1 unit)
shift+arrow keys Move selected point in Curves panel (10 units)
ctrl+r Open selected images in Camera Raw dialog box from Bridge
shift+double-click image Open selected images from Bridge bypassing Camera Raw dialog box
alt+drag Exposure, Recovery, or Black sliders Display highlights that will be clipped in Preview
o Highlight clipping warning
u Shadows clipping warning
ctrl+1 … 5 (Filmstrip mode) Add 1 – 5 star rating
ctrl+. (period) / ctrl+, (comma) (Filmstrip mode) Increase/decrease rating
ctrl+6 (Filmstrip mode) Add red label
ctrl+7 (Filmstrip mode) Add yellow label
ctrl+8 (Filmstrip mode) Add green label
ctrl+9 (Filmstrip mode) Add blue label
ctrl+shift+0 (Filmstrip mode) Add purple label
ctrl+k Camera Raw preferences
ctrl+alt (on open) Deletes Adobe Camera Raw preferences

▲ up

9. Black-and-White Dialog Box
shift+ctrl+alt+b Open the Black-and-White dialog box
arrow up/arrow down Increase/decrease selected value by 1%
shift+arrow up/arrow down Increase/decrease selected value by 10%
Click+drag on the image Change the values of the closest color slider

▲ up

10. Curves
ctrl+m Open the Curves dialog box
+ / – Select next / previous point on the curve
shift+click the points Select multiple points on the curve
ctrl+d Deselect a point
Select a point and press delete Delete a point on the curve
arrow keys Move the selected point 1 unit
shift+arrow keys Move the selected point 10 units
alt+drag black/white point sliders Display highlights and shadows that will be clipped
ctrl+click the image Set a point to the composite curve
shift+ctrl+click the image Set a point to the channel curves
alt+click the field Toggle grid size

▲ up

11. Select and Move Objects
Any marquee tool (except single column and single row), press space+drag Reposition marquee while selecting
Any selection tool+shift+drag Add to a selection
Any selection tool+alt+drag Subtract from a selection
Any selection tool (except Quick Selection tool)+shift-alt+drag Intersect a selection
shift+drag Constrain marquee to square or circle (if no other selections are active)
alt+drag Draw marquee from center (if no other selections are active)
shift+alt+drag Constrain shape and draw marquee from center
ctrl Switch to Move tool (except when Hand, Slice, Path, Shape, or any Pen tool is selected)
alt+drag Switch from Magnetic Lasso tool to Lasso tool
alt+click Switch from Magnetic Lasso tool to polygonal Lasso tool
enter/esc or ctrl+. (period) Apply/cancel an operation of the Magnetic Lasso
Move tool+alt+drag selection Move copy of selection
Any selection+arrow keys Move selection area 1 pixel
Move tool+arrow keys Move selection 1 pixel
ctrl+arrow keys Move layer 1 pixel when nothing selected on layer
Magnetic Lasso tool+[ / ] Increase/decrease detection width
Crop tool+enter or esc Accept cropping or exit cropping
/ (forward slash) Toggle crop shield off and on
Ruler tool+alt+drag end point Make protractor
shift+drag guide Snap guide to ruler ticks (except when View Snap is unchecked)
alt+drag guide Convert between horizontal and vertical guide

▲ up

12. Transform Selections, Selection Borders, and Paths
alt Transform from center or reflect
shift Constrain
ctrl Distort
enter Apply
ctrl+. (period) or esc Cancel
ctrl+alt+t Free transform with duplicate data
ctrl+shift+alt+t Transform again with duplicate data

▲ up

13. Edit Paths
Direct selection tool+shift+click Select multiple anchor points
Direct selection tool+alt+click Select entire path
Pen (any Pen tool), Path Selection or Direct Selection tool+ctrl+alt+drag Duplicate a path
ctrl Switch from Path Selection, Pen, Add Anchor Point, Delete Anchor Point, or Convert Point tools, to Direct Selection tool
alt Switch from Pen tool or Freeform Pen tool to Convert Point tool when pointer is over anchor or direction point
Magnetic Pen tool, double-click Close path
Magnetic Pen tool, alt-double-click Close path with straight-line segment

▲ up

14. Painting
Any painting tool+shift+alt+right-click and drag Select foreground color from color picker
Any painting tool+alt or any shape tool+alt (except when Paths option is selected) Select foreground color from image with Eyedropper tool
Eyedropper tool+alt+click Select background color
Eyedropper tool+shift Color sampler tool
Color sampler tool+alt+click Deletes color sampler
Any painting or editing tool+1…9 Set opacity, tolerance, strength, or exposure for painting mode.

0 = 100%, 1 = 10%. Two numbers in quick succession (e.g. 45 = 45%)
When airbrush option is enabled, use shift+1…9)

Any painting or editing tool+shift+number keys Sets flow for painting mode

0 = 100%, 1 = 10%. Two numbers in quick succession (e.g. 45 = 45%)
When airbrush option is enabled, use shift+1…9)

alt+shift+1…9 Mixer Brush changes Mix setting
0…9 Mixer Brush changes Wet setting
0 Mixer Brush changes Wet and Mix to zero
shift++ / shift+- Cycle through blending modes
backspace or shift+backspace Open Fill dialog box on background or standard layer
alt+backspace or ctrl+backspace Fill with foreground or background color
ctrl+alt+backspace Fill from history
shift+backspace Displays Fill dialog box
/ (forward slash) Lock transparent pixels on/off
Any painting tool+shift+click Connects points with a straight line

▲ up

15. Blending Modes
shift++ / shift+- Cycle through blending modes
shift+alt+n Normal
shift+alt+i Dissolve
shift+alt+q Behind (Brush tool only)
shift+alt+r Clear (Brush tool only)
shift+alt+k Darken
shift+alt+m Multiply
shift+alt+b Color Burn
shift+alt+a Linear Burn
shift+alt+g Lighten
shift+alt+s Screen
shift+alt+d Color Dodge
shift+alt+w Linear Dodge
shift+alt+o Overlay
shift+alt+f Soft Light
shift+alt+h Hard Light
shift+alt+v Vivid Light
shift+alt+j Linear Light
shift+alt+z Pin Light
shift+alt+l Hard Mix
shift+alt+e Difference
shift+alt+x Exclusion
shift+alt+u Hue
shift+alt+t Saturation
shift+alt+c Color
shift+alt+y Luminosity
Sponge tool+shift+alt+d Desaturate
Sponge tool+shift+alt+s Saturate
Dodge tool/Burn tool+shift+alt+s Dodge/burn shadows
Dodge tool/Burn tool+shift+alt+m Dodge/burn midtones
Dodge tool/Burn tool+shift+alt+h Dodge/burn highlights
shift+alt+n Set blending mode to Threshold for bitmap images, Normal for all other images

▲ up

16. Select and Edit text
ctrl+drag type when Type layer is selected Move type in image
shift+arrow keys, ctrl+shift+arrow keys etc. Select Characters: Use Standard Windows Editing Shortcuts
shift+click Select characters from insertion point to mouse click point
shift+click Create a new text layer, when a text layer is selected in the Layers panel
Double-click, triple-click, quadruple-click, or quintuple-click Select a word, line, paragraph, or story
ctrl+h Show/Hide selection on selected type
ctrl Display the bounding box for transforming text when editing text, or activate Move tool if cursor is inside the bounding box
ctrl+drag a bounding box handle Scale text within a bounding box when resizing the bounding box
space+drag Move text box while creating text box

▲ up

17. Format Type
Horizontal Type tool+ctrl+shift+l, c, or r Align left, center, or right
Vertical Type tool+ctrl+shift+l, c, or r Align top, center, or bottom
ctrl+shift+x Choose 100% horizontal scale
ctrl+shift+alt+x Choose 100% vertical scale
ctrl+shift+alt+a Choose Auto leading
ctrl+shift+q Choose 0 for tracking
ctrl+shift+j Justify paragraph, left aligns last line
ctrl+shift+f Justify paragraph, justifies all
ctrl+shift+alt+h Toggle paragraph hyphenation on/off
ctrl+shift+alt+t Toggle single/every-line composer on/off
ctrl+shift+; Decrease or increase type size of selected text 2 points or pixels
alt+arrow down or arrow up Decrease or increase leading 2 points or pixels
shift+alt+arrow down or arrow up Decrease or increase baseline shift 2 points or pixels
alt+arrow left or arrow right Decrease or increase kerning/tracking 20/1000 ems

▲ up

18. Slicing and Optimizing
ctrl Toggle between Slice tool and Slice Selection tool
shift+drag Draw square slice
alt+drag Draw from center outward
shift+alt+drag Draw square slice from center outward
space+drag Reposition slice while creating slice
Right-click slice Open context-sensitive menu

▲ up

19. Photoshop CS5 Panels
All Panels
alt+click New button Set options for new items (except for Actions, Animation, Styles, Brushes, Tool Presets, and Layer Comps panels)
alt+click delete button Delete without confirmation (except for the Brush panel)
shift+enter Apply value and keep text box active
tab Show/Hide all panels
shift+tab Show/Hide all panels except the toolbox and options bar
Select tool and press enter Highlight options bar
shift+arrow up/arrow down Increase/decrease selected values by 10
Action Panel
alt+click the check mark next to a command Turn command on and all others off, or turns all commands on
alt+click Turn current modal control on and toggle all other modal controls
alt+double-click action or action set Change action or action set options
Double-click recorded command Display Options dialog box for recorded command
ctrl+double-click an action Play entire action
alt+click the triangle Collapse/expand all components of an action
ctrl+click the Play button Play a command
alt+click the New Action button Create new action and begin recording without confirmation
shift+click the action/ command Select contiguous items of the same kind
ctrl+click the action/ command Select discontiguous items of the same kind
Adjustment Panel
alt+3 (red),
alt+4 (green),
alt+5 (blue)
Choose specific channel for adjustment
alt+2 Choose composite channel for adjustment
delete or backspace Delete adjustment layer
alt+click Auto button Define Auto options for Levels or Curves
Animation Panel (Frames Mode)
shift+click second frame Select/deselect multiple contiguous frames
ctrl+click multiple frames Select/deselect multiple discontiguous frames
alt+Paste Frames command from the Panel pop-up menu Paste using previous settings without displaying the dialog box
Animation Panel (Timeline Mode, PS extended)
space Start playing the timeline or Animation panel
alt+click the current-time display in the upper-left corner of the timeline. Switch between timecode and frame numbers (current time view)
alt+click Expand and collapse list of layers
Hold down the shift key when clicking the next/previous Frame buttons (on either side of the Play button). Jump to the next/previous whole second in timeline
Hold down the shift key while dragging the current time. Increase playback speed
Hold down the ctrl key while dragging the current time. Decrease playback speed
shift+drag Snap an object (keyframe, the current time, layer in point, and so on) to the nearest object in timeline
alt+drag (first or last keyframe in the selection) Scale (evenly distribute to condensed or extended length) a selected group of multiple keyframes
arrow left or page up Back one frame
arrow right or page down Forward one frame
shift+arrow left or shift+page up Back ten frames
shift+arrow right or shift+page down Forward ten frames
home / end Move to the beginning / to the end of the timeline
shift+home / shift+end Move to the beginning / to the end of the work area
arrow up Move to “In” point of the current layer
arrow down Move to the “Out” point of the current layer
shift+arrow up / shift+arrow down Back 1 second / Forward 1 second
esc Return a rotated document to its original orientation
Brush Panel
alt+click brush Delete brush
Double-click brush Rename brush
alt+right click+drag left or right Change brush size
alt+right click+drag up or down Decrease/increase brush softness/hardness
, (comma) / . (period) Select previous/next brush size
shift+, (comma) / shift+. (period) Select first/ Select last brush
caps lock or shift+caps lock Display precise cross hair for brushes
shift+alt+p Toggle airbrush option
Channels Panel
ctrl+3 (red),
ctrl+4 (green),
ctrl+5 (blue)
Select individual channels
ctrl+2 Select composite channel
ctrl+click channel thumbnail, or
alt+ctrl+3 (red),
alt+ctrl+4 (green),
alt+ctrl+5 (blue)
Load channel as selection
ctrl+shift+click channel thumbnail. Add to current selection
ctrl+alt+click channel thumbnail Subtract from current selection
ctrl+shift+alt+click channel thumbnail Intersect with current selection
alt+click Save Selection As Channel button Set options for Save Selection As Channel button
ctrl+click Create New Channel button Create a new spot channel
shift+click color channel Select/deselect multiple color-channel selection
shift+click alpha channel Select/deselect alpha channel and show/hide as a rubylith overlay
Double-click alpha or spot channel thumbnail Display channel options
~ Toggle composite and grayscale mask in Quick Mask mode
Clone Source Panel
alt+shift Show Clone Source (overlays image)
alt+shift+arrow keys Nudge Clone Source
alt+shift+; Rotate Clone Source
alt+shift+[ or ] Scale (increase or reduce size) Clone Source
Color Panel
alt+click color in color bar Select background color
Right-click color bar Display Color Bar menu
shift+click color bar Cycle through color choices
History Panel
alt+new Snapshot Create a new snapshot
Double-click snapshot name Rename snapshot
ctrl+shift+z Step forward through image states
ctrl+alt+z Step backward through image states
alt+click the image state Duplicate any image state, except the current state
alt+clear History Permanently clear history (no Undo) in History panel pop-up menu
Info Panel
Click eyedropper icon Change color readout modes
Click crosshair icon Change measurement units
Layers Panel
ctrl+click layer thumbnail Load layer transparency as a selection
ctrl+shift+click layer thumbnail. Add to current selection
ctrl+alt+click layer thumbnail. Subtract from current selection
ctrl+shift+alt+click layer thumbnail. Intersect with current selection
ctrl+click filter mask thumbnail Load filter mask as a selection
ctrl+g Group layers
ctrl+shift+g Ungroup layers
ctrl+alt+g Create/release clipping mask
ctrl+alt+a Select all layers
ctrl+shift+e Merge visible layers
alt+click New Layer button Create new empty layer with dialog box
ctrl+click New Layer button Create new layer below target layer
alt+.. (period) Select top layer
alt+,, (comma) Select bottom layer
shift+alt+[ or ] Add to layer selection in Layers panel
alt+[ or ] Select next layer down/up
ctrl+[ or ] Move target layer down/up
ctrl+shift+alt+e Merge a copy of all visible layers into target layer
Highlight layers you want to merge, then ctrl+e Merge layers
ctrl+shift+[ or ] Move layer to bottom or top
alt+ Merge Down command from the Panel pop-up menu Copy current layer to layer below
alt+ Merge Visible command from the Panel pop-up menu Merge all visible layers to a new layer above the currently selected layer
Right-click the eye icon Show/hide this layer/layer group only or all layers/layer groups
alt+ click the eye icon Show/hide all other currently visible layers
/ (forward slash) Toggle lock transparency for target layer, or last applied lock
Double-click layer effect/style Edit layer effect/style, options
alt-double-click layer effect/style Hide layer effect/style
Double-click layer Edit layer style
shift+click vector mask thumbnail Disable/enable vector mask
Double-click layer mask thumbnail Open Layer Mask Display Options dialog box
shift+click layer mask thumbnail Toggle layer mask on/off
shift+click filter mask thumbnail Toggle filter mask on/off
alt+click layer mask thumbnail Toggle between layer mask/composite image
alt+click filter mask thumbnail Toggle between filter mask/composite image
\ (backslash), or shift+alt+click Toggle rubylith mode for layer mask on/off
Double-click type layer thumbnail Select all type; temporarily select Type tool
alt+click the line dividing two layers Create a clipping mask
Double-click the layer name Rename layer
Double-click the filter effect Edit filter settings
Double-click the Filter Blending icon Edit the Filter Blending options
ctrl+click New Group button Create new layer group below current layer/layer set
alt+click New Group button Create new layer group with dialog box
alt+click Add Layer Mask button Create layer mask that hides all/selection
ctrl+click Add Layer Mask button Create vector mask that reveals all/path area
ctrl+alt+click Add Layer Mask button Create vector mask that hides all or displays path area
Right-click layer group and choose Group Properties, or double-click group Display layer group properties
shift+click Select/deselect multiple contiguous layers
ctrl+click Select/deselect multiple discontiguous layers
Layers Comps Panel
alt+click Create New Layer Comp button Create new layer comp without the New Layer Comp box
Double-click layer comp Open Layer Comp Options dialog box
Double-click layer comp name Rename in-line
shift+click Select/deselect multiple contiguous layer comps
ctrl+click Select/deselect multiple discontiguous layer comps
Paths Panel
ctrl+click pathname Load path as selection
ctrl+shift+click pathname Add path to selection
ctrl+alt+click pathname Subtract path from selection
ctrl+shift+alt+click pathname Retain intersection of path as selection
ctrl+shift+h Hide path
alt+click button Set options for Fill Path with Foreground Color button, Stroke Path with Brush button, Load Path as a Selection button, Make Work Path from Selection button, and Create New Path button
Swatches Panel
Click in empty area of panel Create new swatch from foreground color
ctrl+click swatch Set swatch color as background color
alt+click swatch Delete swatch

▲ up

20. 3D tools (PS Extended)
n Enable 3D camera tools
alt+ctrl+x Hide nearest surface
alt+shift+ctrl+x Show all surfaces
right-click / alt Change between Rotate, Roll, Drag, Slide, and Scale 3D Object Tool
shift Scale on the Y plane

▲ up

21. Measurement (PS Extended)
shift+ctrl+m Record a measurement
ctrl+d Deselects all measurements
ctrl+a Selects all measurements
shift+ctrl+h Hide/show all measurements
backspace Removes a measurement
arrow keys Nudge the measurement
shift+arrow keys Nudge the measurement in increments
ctrl+left/right arrow key Extend/shorten selected measurement
shift+ctrl+left/right arrow key Extend/shorten selected measurement in increments
ctrl+up/down arrow key Rotate selected measurement

▲ up

22. DICOM files (PS Extended)
z Zoom tool
h Hand tool
w Window Level tool
ctrl+a Select all frames
ctrl+d Deselect all frames except the current frame
arrow keys Navigate through frames

▲ up

23. Extract and Pattern Maker (plug-in)
Extract and Pattern Maker
ctrl+0 Fit in window
ctrl++ / ctrl+- Zoom in / Zoom out
tab Cycle through controls on right from top
shift+tab Cycle through controls on right from bottom
space Temporarily activate Hand tool
alt Change Cancel to Reset
Extract Only
b Edge Highlighter tool
g Fill tool
i Eyedropper tool
c Cleanup tool
t Edge Touchup tool
alt+Edge Highlighter/Eraser tool Toggle between Edge Highlighter tool and Eraser tool
ctrl with Edge Highlighter tool selected Toggle Smart Highlighting
alt+delete Remove current highlight
ctrl+delete Highlight entire image
shift+click with Fill tool selected Fill foreground area and preview extraction
ctrl+drag Move mask when Edge Touchup tool is selected
alt+drag Add opacity when Cleanup tool is selected
x Toggle Show menu options in preview between Original and Extracted
shift+x Enable Cleanup and Edge Touchup tools before preview
f Cycle through Display menu in preview from top to bottom
shift+f Cycle through Display menu in preview from bottom to top
arrow down/arrow up in Brush Size text box Decrease/increase brush size by 1
arrow left/arrow right with Brush Size Slider showing Decrease/increase brush size by 1
0…9 Set strength of Cleanup or Edge Touchup tool
Pattern Maker Only
ctrl+d Delete current selection
ctrl+z Undo a selection move
ctrl+g Generate or generate again
shift+alt+select Intersect with current selection
x Toggle view: original/generated pattern
home Go to first tile in Tile History
end Go to last tile in Tile History
arrow left, page up Go to previous tile in Tile History
arrow right, page down Go to next tile in Tile History
delete Delete current tile from Tile History
arrow right, arrow left, arrow up, or arrow down Nudge selection when viewing the original
shift+arrow right, arrow left, arrow up, or arrow down Increase selection nudging when viewing the original

▲ up

24. Function keys
f1 Start Help
f2 Cut
f3 Copy
f4 Paste
f5 Show/Hide Brush panel
f6 Show/Hide Color panel
f7 Show/Hide Layers panel
f8 Show/Hide Info panel
f9 Show/Hide Actions panel
f12 Revert
shift+f5 Fill
shift+f6 Feather Selection
shift+f7 Inverse Selection

PHP script for MySQL database import

Posted: January 19, 2012 in Php

PHP script for MySQL database import

You should start by creating a file called for example import.php and placing it in your public_html folder.

Then edit the file and paste the following code in it:

 

 <?php

passthru(“nohup mysql -u USERNAME -pPASSWORD DBNAME < dump.sql“);

 ?>

 


Where USER,PASSWORD and DBNAME are your details for the database in which you want to import the dumped file, and dump.sql is the file you want to import. Make sure you give the correct path to the dump.sql file.

When you are ready, open your browser and type in the URL to the update.php file, e.g. http://yourdomain.com/update.php.
To test if the import was successful, log in to your phpMyAdmin tool from your cPanel and review the database.


Here is the fourth and last part of a tutorial on how to develop WordPress templates, it explains useful functions and useful plugins.

To access other parts of the tutorial see the WordPress Template Tutorial post.

Useful Functions

Here are some general utility functions, will sure come handy:

wp_head(); // Attach header
wp_footer(); // Attach footer
get_sidebar(); // Attach sidebar

get_option('home'); // Returns home url
get_bloginfo('url');
get_bloginfo('template_url');
$GLOBALS[$lang_home] = split("\?", get_option('home'));  // $lang_home[0] is like bloginfo('url') but without url variables

get_cat_name($cat_id);
get_cat_ID($cat_name);
single_term_title("", false); // Returns the CURRENT category title
get_category_link($cat_id);
get_category_parents($cat_id, FALSE, ' - ', FALSE); // arguments: (category), (display link), (separator), (nice name)  

// get_page id from name
function get_page_id($page_name){
	global $wpdb;
	$page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."'");
	return $page_name;
}

// print categories sorted by id
$subtitle = '';
$cats = get_the_category();
for($i=0;$i<count($cats);$i++){
	$subtitlearr[$cats[$i]->cat_ID]=$cats[$i]->cat_name;
}
ksort($subtitlearr);
$i=0;
foreach ($subtitlearr as $key => $value) {
	$i++;
	$subtitle .= $value;
	if($i!=(count($subtitlearr))){$subtitle .=" - ";}
}

// current cat also on posts
$var = get_the_category();
$cat = $var[0]->cat_ID;
$var=wp_list_categories('current_category='.$cat);

// get_the_content_with_formatting() for storing and editing the_content() inside a variable
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
	$content = get_the_content($more_link_text, $stripteaser, $more_file);
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]>', ']]&gt;', $content);
	return $content;
}

// WPML functions
ICL_LANGUAGE_CODE // Actual language code
icl_object_id(3, 'category', false, 'en'); // arguments: (the ID of the post, page, tag or category), (type – ‘post’, ‘page’, ‘post_tag’ or ‘category’), (return_original_if_missing), (language code to return id)

// get page meta for WPML, useful if you are storing some general data into pages
$t_lang = icl_object_id('268',  'page', false);
$desc = get_post_meta($t_lang, 'desc-machines', true);
echo $desc;

// Translate redirect with WPML, useful to put inside index.php if you want redirection only in index
$browser_lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$ref = split("\?", get_bloginfo('url'));
$ref2 = split("\?", $_SERVER['HTTP_REFERER']);
if(is_home()){
	if (($browser_lang != ICL_LANGUAGE_CODE) && (!stristr($ref2[0], $ref[0])) ) {
		$languages = icl_get_languages('skip_missing=1');
		foreach($languages as $l){
			if ($browser_lang == $l['language_code']) { /* native_name */
				header('Location:'.$ref[0].'?lang='.$l['language_code']); exit;
			}
		}
	}
}

// Find ID of Top-Most Parent Post
if ($post->post_parent)	{
	$ancestors=get_post_ancestors($post->ID);
	$root=count($ancestors)-1;
	$parent = $ancestors[$root];
} else {
	$parent = $post->ID;
}

// Breadcrumbs
echo '<ul>';
if (!is_home()) {
	echo '<li><a href="';
	echo get_option('home');
	echo '">';
	echo 'Home';
	echo "</a></li>";
	if (is_category() || is_single()) {
		echo '<li>';
		the_category(' </li><li> ');
		if (is_single()) {
			echo "</li><li>";
			the_title();
			echo '</li>';
		}
	} elseif (is_page()) {
		echo '<li>';
		echo the_title();
		echo '</li>';
	}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';
Useful Plugins

Here are the must have plugins:

  • WPML Multilingual: WPML combines multilingual content authoring with powerful translation management. It powers corporate sites and is simple enough for bloggers.
  • Magic Fields: Magic Fields is a feature rich WordPress CMS plugin.
  • WP Minify: This plugin uses the Minify engine to combine and compress JS and CSS files to improve page load time.
  • WP Super Cache: A very fast caching engine for WordPress that produces static html files.
  • WP htaccess Control: Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by WordPress.

Courtesy

Source: http://www.minimit.com/articles/wordpress-template-functions-plugins