<?php

/**
 * Returns the services content
 *
 * This function will return the specified services
 * content. If the shortcode dataType parameter is
 * 'quote', the content will be the services quote
 * rather than the main content. This mean a customer
 * can remove the quotes by deleting the shortcode.
 *
 * @function get_services()
 *
 * @uses $iris_db::get_results(), wpautop()
 *
 * @param (string) $title the services title, $dataType the type of services content
 *
 * @return (string) the services post content
 * 
 * @since 1.0.0 
 *
 */
function get_services( $title, $dataType ) {
	
	global $iris_db;
	
	$services_array = $iris_db->get_results( "SELECT * FROM services WHERE service_name='$title'" );
	
	foreach ( $services_array as $services_item ) {
		
		if ( $dataType == 'quote' ) {
			
			return '<blockquote>' . $services_item->service_quote . '</blockquote>';
		} else if ( $dataType == 'content' ) {
			
			return wpautop( $services_item->service_data );
		}	
	}
}



/**
 * returns the services list
 *
 * This function will return the services list.
 * The list is made up of child pages to the
 * current page.
 *
 * @function list_services()
 *
 * @uses wp_list_pages()
 *
 * @param N/A
 *
 * @return (string) a list of services pages
 *
 * @deprecated 1.1.0 This function is very similar to add_index_page() so will been removed
 *
 */
function list_services() {
	
	return '<ul id="services-list">' . wp_list_pages( array( 'child_of' => get_the_ID(), 'title_li' => '', 'echo' => false ) ) . '</ul>';
}



/**
 * Obfuscates mailto: links in the mail content
 *
 * This function will replace plain text
 * mailto: links within the WoprdPress
 * content to obfuscated inline JavaScript.
 *
 * @function add_services()
 *
 * @uses get_services(), list_services()
 *
 * @param (array) $service[ (string) service_name, (string) service_data_type ]
 *
 * @return (string) either the services content or the list of services
 * 
 * @since 1.0.0 
 *
 */
function add_services( $service ) {
	
	$service = shortcode_atts( array( 'service_name' => '', 'services_data_type' => 'content' ), $service, 'services' );
	
	if ( $service['service_name'] != '' || $service['service_name'] != NULL ) {
		
		return get_services( $service['service_name'], $service['services_data_type'] );
	}
	return list_services();	
}
add_shortcode( 'services', 'add_services' );