Rss Feed
Tweeter button
Facebook button
Technorati button
Reddit button
Myspace button
Linkedin button
Webonews button
Delicious button
Digg button
Flickr button
Stumbleupon button
Newsvine button
Youtube button

Before understanding the advanced part of it let me explain you in brief about WordPress. It is an FOSS CMS i.e. content management system powered by PHP and MySQL. Among many features it provides the important features are plug-in architecture and a template system which makes this CMS a robust one. It is used by over 10% of global websites.

Now moving to one of the most exciting features coming in WordPress 3.0 is custom post types, which will vastly expand WordPress’ CMS capabilities. This feature will come handy especially when using WordPress as a CMS.

WordPress Custom Post types are basically different kinds of building blocks that when put together form our website. To understand it in a better way let us create our custom post type called “place”.

Any WordPress system will have functions.php in themes folder. This is the one of our interest. To achieve the purpose you will have to add the following code at the end of the functions.php file.

function post_type_place() {
	register_post_type('place', array('labels' => array('name'=>__('Places'),'add_new_item' => __( 'Add New Place' ),'edit_item' =>__( 'Edit Place' )),
                             'public' => true,
                             'show_ui' => true,
                             'supports' => array('title','author','editor',
                                        'post-thumbnails',
                                        'excerpts',
                                        'trackbacks',
                                        'custom-fields',
                                        'comments',
                                        'revisions'),
                                        'rewrite' => false,
                                        '_builtin' => false,
    									'_edit_link' => 'post.php?post=%d',
   										'capability_type' => 'post',
   										'hierarchical' => false,'query_var' => true
                                )
                      ); 

		// add to our plugin init function
		//for single template
		global $wp_rewrite;
		$place_structure = '/place/%category%/%place%';
		$wp_rewrite->add_rewrite_tag("%place%", '([^/]+)', "place=");
		$wp_rewrite->add_permastruct('place', $place_structure, false); 

		//for displaying tags
		register_taxonomy_for_object_type('post_tag', 'place'); 

		//for displaying categories
		register_taxonomy_for_object_type('category', 'place'); 

}
// Add filter to plugin init function

If you want you can use a single page template for displaying custom post. 

//function to redirect to place page(templating system)
// Add filter to plugin init function
add_filter('post_type_link', 'place_permalink', 10, 3);
// Adapted from get_permalink function in wp-includes/link-template.php
function place_permalink($permalink, $post_id, $leavename) {
	$post = get_post($post_id);
	$rewritecode = array(
		$leavename? '' : '%postname%',
		'%post_id%',
		'%category%',
		'%author%',
		$leavename? '' : '%pagename%',
	); 

	if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
		$unixtime = strtotime($post->post_date); 

		$category = '';
		if ( strpos($permalink, '%category%') !== false ) {
			$cats = get_the_category($post->ID);
			if ( $cats ) {
				usort($cats, '_usort_terms_by_ID'); // order by ID
				$category = $cats[0]->slug;
				if($category == "featured") { 

					$category = $cats[1]->slug;} 

				if ( $parent = $cats[0]->parent )
					$category = get_category_parents($parent, false, '/', true) . $category; 

			}
			// show default category in permalinks, without
			// having to assign it explicitly
			if ( empty($category) ) { 

				$default_category = get_category( get_option( 'default_category' ) );
				$category = is_wp_error( $default_category ) ? '' : $default_category->slug;
			}
		} 

		$author = '';
		if ( strpos($permalink, '%author%') !== false ) {
			$authordata = get_userdata($post->post_author);
			$author = $authordata->user_nicename;
		}
		$rewritereplace =
		array(
			$post->post_name,
			$post->ID,
			$category,
			$author,
			$post->post_name,
		);
		$permalink = str_replace($rewritecode, $rewritereplace, $permalink);
	} else { // if they're not using the fancy permalink option
	}
	return $permalink;
}
add_action('init', 'post_type_place');

Update the permalinks.

The newly created post type (place) will look like this in the WordPress administrator dashboard under the links panel:

Wordpress custom post

Now after creating a custom post you will want to use it. Now see the image below to understand how to add new place in WordPress.

Wordpress custom post

Once you add couple of places the list view under WordPress dashboard will look something like below.
Wordpress custom post list view

To be able to display the single-type-template using WordPress you will have to use a PHP file by the name single.php. To display newly created custom post you will have to use single-{posttype}.php. So in our case the filename would be single-place.php.

Similarly to archive the custom post use archive-{posttype}.php in WordPress. Normally, the archive-type-template use archive.php file. So in our case the archive template file name would be archive-place.php.

Share This Post
 

PHP Web Services have been popping up all over the internet since past few years. There could not be any better language than PHP for building your own Web Service in simplistic manner.

PHP is a great scripting language with many advantages. It provides the power to connect to variety databases (that are available with hosting providers) and easy development curve for faster development along with high response time on account of the underlying libraries compiled for performance.

A database is a crucial part of any PHP Web Service, however it is not mandatory to have one for Web Service. It is just that without it a Web Service is not that useful. It helps you store information about user query and visit information.

What are Web Services?

In a typical scenario, a visitor visits a website and uses the functionality provided by application hosted. HTTP request is send to the server from web browser and server responses are translated back by browser to display the desired result of the visitor.

But things have changed a lot with the evolution of web technologies. You don’t need to visit a website to use its service and functionality if it is providing a Web Service.

With Web Service you can exchange data between a server and a client using a standard XML format to ‘package’ requests and data so that both systems can ‘understand’ each other properly. Either a server or a client could be a Web Server, or any other electronic device you could think of for that matter.

There are different methods for providing Web Services but the most common methods are SOAP, XML-RPC and REST.

What is NuSOAP?

NuSOAP is a group of PHP classes that allow developers to create and consume SOAP web services without needing any special PHP extensions.

It stands for Simple Object Access Protocol, and it is essentially a standard for exchanging XML based data via HTTP.

Having understood Web Services and NuSOAP let’s start building our own Web Service using PHP.

Requirements: PHP 5 and above, Apache Webserver, NuSOAP library and MySQL (required in case there are database interactions)

You can download NuSOAP (version 0.7.3) from http://sourceforge.net/projects/nusoap/files/nusoap/

To understand the concept of the Web Service are going to create a ‘calculator’ Web Service and consume it too.

Create a new project ‘webservice’ on the webroot and unzip the NuSOAP file and place it in this folder.

Firstly, create a new file calc_server.php in the NuSOAP directory (for demonstration purpose I have created it in NuSOAP directory).

The PHP file will look like this:

// load SOAP library

require_once("lib/nusoap.php");

// set namespace

localhost in my case

$ns = "http://localhost/";

// create SOAP server object

$server = new nusoap_server();

// setup WSDL file, a WSDL file can contain multiple services

$server->configureWSDL('Calculator', $ns);

$server->wsdl->schemaTargetNamespace = $ns;

// register a web service method

$server->register('ws_add',

array('int1' => 'xsd:integer','int2' => 'xsd:integer'),// input parameters

array('total' => 'xsd:integer'),// output parameter

$ns, // namespace

"$ns#ws_add", // soapaction

'rpc', // style

'encoded', // use

'adds two integer values and returns the result' // documentation

);

function ws_add($int1, $int2){

return new soapval('return','xsd:integer', add($int1, $int2));

}

// implementation of add function

function add($int1, $int2) {

return $int1 + $int2;

}

//substract method

$server->register('ws_substract',

array('int1' => 'xsd:integer', 'int2' => 'xsd:integer'),// input parameters

array('total' => 'xsd:integer'),// output parameter

$ns, // namespace

"$ns#ws_substract", // soapaction

'rpc', // style

'encoded', // use

'substracts two integer values and returns the result' // documentation

);

function ws_substract($int1, $int2) {

return new soapval('return','xsd:integer',substract($int1, $int2));

}

// implementation of add function

function substract($int1, $int2) {

if($int1 > $int2)

return $int1 - $int2;

else

return $int2 - $int1;

}

//multiplication

$server->register('ws_multiply',

array('int1' => 'xsd:integer', 'int2' => 'xsd:integer'),

array('total' => 'xsd:integer'),

$ns,

"$ns#ws_multiply", // soapaction

'rpc',

'encoded',

'multiplies two integers and returns the result'

);

function ws_multiply($int1, $int2) {

return new soapval('return', 'xsd:integer', multiply($int1, $int2));

}

// implementation of multiply function

function multiply($int1, $int2) {

return $int1 * $int2;

}

// service the methods

$server->service($HTTP_RAW_POST_DATA);

Save the file. It will look like this when you browse it.

PHP Web Service NuSOAP 1

(click image to enlarge)

NuSOAP library has a very good feature of Web Service Inspection. If you open

the calc_server.php file in a browser, you will see something like this:

PHP Web Service NuSOAP 2

(click image to enlarge)

With this we have now created our own ‘calculator’ Web Service. Now, let us understand how to consume this new created NuSOAP Web Service in PHP.

Create a new PHP file, say ‘calc_client.php’ and put the following code in it.

//client code

<?php

require_once('lib/nusoap.php');

//create a parameter array to pass to the webservicefunction call

$param = array('int1'=>'15.00', 'int2'=>'10');

//define the webservice

$wsdl = "http://localhost/webservice/nusoap/calc_server.php?wsdl";

//create client object

$client = new nusoap_client($wsdl, 'wsdl');

$response = $client->call('ws_add', $param);

//print the response

print_r($response);

?>

The result is the addition of 2 numbers and it will be displayed as below:

PHP Web Service NuSOAP 3

It is that simple to create and consume Web Service using NuSOAP library. Moreover, NuSOAP library can also use XML-RPC and REST methods for Web Services.

I have shown you creation and consumption of PHP Web Service using NuSOAP library. If you want to play more with it then perhaps you might even consider adding an interface to the client for INSERTing and UPDATEing new items.

Share This Post
 

Product outsourcing has become an inevitable for every growing ISV. With growth of the ISV the need to concentrate on few critical functions increases drastically. Hence and ISV has to outsource other important activities to remain focused and responsive the market.

As outsourced product development is maturing new models are emerging in course to mitigate the risk. Every model has its own share of pros and cons. The outsourcer has to select to most appropriate model for his kind of software outsourcing project.

Below are some of the emerging outsourced product development models.

1. Software Product Line

An ISV targets the needs of the prospective industry or function by creating a portfolio of products with variations in features and functions. This model has a base or core product and different products in the same line offers increasing feature sets.

2. Modular Development

In this model the product is developed in the form of modules. One module is developed at a time or different modules by different team all at once.

3. Co-development

In this model ISVs’ and outsourcing partner’s team work together. It is preferred model where the technical capability and bandwidth is available on both side. Typically in this model, outsourcing vendor provides resources and product development project is managed by the ISV.

4. End-to-end Development

In this model, the outsourced product development looks after every aspect of product development. This model is preferred where outsourcing partner has technical as well as technical capabilities and product development experience. This model help ISV focus on very critical aspect of software product business boosting its productivity and profitability.

Share This Post