<?php

function my_taxonomies_products() {
$labels_products = array(
	'name'              => _x( 'Product Categories', 'taxonomy general name' ),
	'singular_name'     => _x( 'Product Category', 'taxonomy singular name' ),
	'search_items'      => __( 'Search Product Categories' ),
	'all_items'         => __( 'All Product Categories' ),
	'parent_item'       => __( 'Parent Product Category' ),
	'parent_item_colon' => __( 'Parent Product Category:' ),
	'edit_item'         => __( 'Edit Product Category' ), 
	'update_item'       => __( 'Update Product Category' ),
	'add_new_item'      => __( 'Add New Product Category' ),
	'new_item_name'     => __( 'New Product Category' ),
	'menu_name'         => __( 'Categories' ),
);
$args_products = array(
	'labels' => $labels_products,
	'hierarchical' => true,
);
register_taxonomy( 'kategorija', 'products', $args_products );
}
add_action( 'init', 'my_taxonomies_products', 0 );

//adding video panel

function product_videos() {
    add_meta_box( 
        'product_videos',
        __( 'Product video panel', 'myplugin_textdomain' ),
        'product_update_videos',
        'products',
        'normal',
        'high'
    );
}


function product_update_videos( $post ) {
echo "<style>";
?>
#product_videos input {
    width: 1345px !important;
    margin-bottom: 15px !important;
    margin-left: 5px !important;
}
#product_details input {
    width: 1345px !important;
    margin-left: 5px !important;
    margin-bottom: 15px !important;
    height: 30px !important;
}
#product_content input {
    margin-left: 5px !important;
}
#product_content input {
    margin-bottom: 15px !important;
    margin-left: 5px !important;
    width: 1325px !important;
}
<?php
echo "</style>";
echo "			<label>Youtube URL</label><input type=\"text\" id=\"product_video_youtube\" name=\"product_video_youtube\" value=\"" . get_post_meta($_GET['post'], 'product_video_youtube', true) . "\">";
echo "			<label>Dailymotion URL</label><input type=\"text\" id=\"product_video_dailymotion\" name=\"product_video_dailymotion\" value=\"" . get_post_meta($_GET['post'], 'product_video_dailymotion', true) . "\">";
}

add_action( 'add_meta_boxes', 'product_videos' );
add_action( 'save_post', 'contentsavevideos' );

function contentsavevideos( $post_id ) {
$product_video_youtube = $_POST['product_video_youtube'];
$product_video_dailymotion = $_POST['product_video_dailymotion'];

update_post_meta( $post_id, 'product_video_youtube', $product_video_youtube );
update_post_meta( $post_id, 'product_video_dailymotion', $product_video_dailymotion );
}

//end of video panel


//adding product details

function product_details() {
    add_meta_box( 
        'product_details',
        __( 'Product details', 'myplugin_textdomain' ),
        'product_details_content',
        'products',
        'normal',
        'high'
    );
}


function product_details_content( $post ) {
echo "<style>";
echo "</style>";
echo "<label>Details #1</label><input type=\"text\" id=\"product_details_1\" name=\"product_details_1\" value=\"" . get_post_meta($_GET['post'], 'product_details_1', true) . "\"><br />";
echo "<label>Details #2</label><input type=\"text\" id=\"product_details_2\" name=\"product_details_2\" value=\"" . get_post_meta($_GET['post'], 'product_details_2', true) . "\"><br />";
echo "<label>Details #3</label><input type=\"text\" id=\"product_details_3\" name=\"product_details_3\" value=\"" . get_post_meta($_GET['post'], 'product_details_3', true) . "\"><br />";
echo "<label>Details #4</label><input type=\"text\" id=\"product_details_4\" name=\"product_details_4\" value=\"" . get_post_meta($_GET['post'], 'product_details_4', true) . "\"><br />";
echo "<label>Details #5</label><input type=\"text\" id=\"product_details_5\" name=\"product_details_5\" value=\"" . get_post_meta($_GET['post'], 'product_details_5', true) . "\"><br />";
echo "<label>Details #6</label><input type=\"text\" id=\"product_details_6\" name=\"product_details_6\" value=\"" . get_post_meta($_GET['post'], 'product_details_6', true) . "\"><br />";
echo "<label>Details #7</label><input type=\"text\" id=\"product_details_7\" name=\"product_details_7\" value=\"" . get_post_meta($_GET['post'], 'product_details_7', true) . "\"><br />";
echo "<label>Details #8</label><input type=\"text\" id=\"product_details_8\" name=\"product_details_8\" value=\"" . get_post_meta($_GET['post'], 'product_details_8', true) . "\"><br />";
echo "<label>Details #9</label><input type=\"text\" id=\"product_details_9\" name=\"product_details_9\" value=\"" . get_post_meta($_GET['post'], 'product_details_9', true) . "\"><br />";
echo "<label>Details #10</label><input type=\"text\" id=\"product_details_10\" name=\"product_details_10\" value=\"" . get_post_meta($_GET['post'], 'product_details_10', true) . "\"><br />";
}

add_action( 'add_meta_boxes', 'product_details' );
add_action( 'save_post', 'contentsavedetails' );

function contentsavedetails( $post_id ) {
$product_details_1 = $_POST['product_details_1'];
$product_details_2 = $_POST['product_details_2'];
$product_details_3 = $_POST['product_details_3'];
$product_details_4 = $_POST['product_details_4'];
$product_details_5 = $_POST['product_details_5'];
$product_details_6 = $_POST['product_details_6'];
$product_details_7 = $_POST['product_details_7'];
$product_details_8 = $_POST['product_details_8'];
$product_details_9 = $_POST['product_details_9'];
$product_details_10 = $_POST['product_details_10'];

update_post_meta( $post_id, 'product_details_1', $product_details_1 );
update_post_meta( $post_id, 'product_details_2', $product_details_2 );
update_post_meta( $post_id, 'product_details_3', $product_details_3 );
update_post_meta( $post_id, 'product_details_4', $product_details_4 );
update_post_meta( $post_id, 'product_details_5', $product_details_5 );
update_post_meta( $post_id, 'product_details_6', $product_details_6 );
update_post_meta( $post_id, 'product_details_7', $product_details_7 );
update_post_meta( $post_id, 'product_details_8', $product_details_8 );
update_post_meta( $post_id, 'product_details_9', $product_details_9 );
update_post_meta( $post_id, 'product_details_10', $product_details_10 );
}

//end of details



function register_custom_menu_page() {
    add_menu_page('Settings', 'Settings', 'add_users', 'admin-menu.php', '_custom_menu_page', null, 999); 
}
add_action('admin_menu', 'register_custom_menu_page');

//error_reporting(E_ALL);
//ini_set('display_errors', '0');


function get_slug(){
  $slug = basename(get_permalink());
  do_action('before_slug', $slug);
  $slug = apply_filters('slug_filter', $slug);
  if( $echo ) echo $slug;
  do_action('after_slug', $slug);
  return $slug;
}

function google_map_api() {
return "<div id=\"google-maps\"><script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=false\"></script><div style=\"overflow:hidden;height:315px;width:700px;\"><div id=\"gmap_canvas\" style=\"height:315px;width:700px;\"></div><style>#gmap_canvas img{max-width:none!important;background:none!important}</style><a class=\"google-map-code\" href=\"http://wordpress-themes.org\" id=\"get-map-data\">http://wordpress-themes.org</a></div><script type=\"text/javascript\"> function init_map(){var myOptions = {zoom:14,center:new google.maps.LatLng(46.1037593,19.652386699999965),mapTypeId: google.maps.MapTypeId.ROADMAP};map = new google.maps.Map(document.getElementById(\"gmap_canvas\"), myOptions);marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(46.1037593, 19.652386699999965)});infowindow = new google.maps.InfoWindow({content:\"<b>Vitalia</b><br/>Stipe Grgica<br/> Subotica\" });google.maps.event.addListener(marker, \"click\", function(){infowindow.open(map,marker);});infowindow.open(map,marker);}google.maps.event.addDomListener(window, 'load', init_map);</script></div>";
}

add_shortcode( 'google-map', 'google_map_api' );

function contact_form_api_german() {
return "<form id=\"contact-us\" method=\"post\" action=\"#\">\n
<label>Név</label> <input type=\"text\" name=\"full-name\" id=\"full-name\"><div id=\"error-name\"></div><br />\n
<label>E-mail cím</label> <input type=\"text\" name=\"mail\" id=\"mail\"><div id=\"error-mail\"></div><br />\n
<label>Telefon</label> <input type=\"text\" name=\"phone\" id=\"phone\"><div id=\"error-phone\"></div><br />\n
<label>Üzenet</label> <textarea name=\"message\" id=\"message\"></textarea><div id=\"error-message\"></div>\n
<input id=\"send-button\" type=\"submit\" value=\"Küldés\">
<div id=\"response\"></div>\n
</form>\n";
}

function contact_form_api() {
return "<form id=\"contact-us\" method=\"post\" action=\"#\">\n
<label>Ime i prezime</label> <input type=\"text\" name=\"full-name\" id=\"full-name\"><div id=\"error-name\"></div><br />\n
<label>E-mail adresa</label> <input type=\"text\" name=\"mail\" id=\"mail\"><div id=\"error-mail\"></div><br />\n
<label>Telefon</label> <input type=\"text\" name=\"phone\" id=\"phone\"><div id=\"error-phone\"></div><br />\n
<label>Poruka</label> <textarea name=\"message\" id=\"message\"></textarea><div id=\"error-message\"></div>\n
<input id=\"send-button\" type=\"submit\" value=\"Pošalji\">
<div id=\"response\"></div>\n
</form>\n";
}

add_shortcode( 'contact-form', 'contact_form_api' );
add_shortcode( 'contact-form-german', 'contact_form_api_german' );

function wp_get_attachment_medium_url( $id )
{
	$full = ( wp_get_attachment_image_src( $id, 'full' ));
	$url = ( wp_get_attachment_image_src( $id, 'single-post' ));
	return "<a href=\"" . $full[0] . "\" class=\"fancybox\" rel=\"gallery\"><img src=\"" . $url[0] . "\" /></a>";
}

add_image_size('main-page', 300, 169);
add_image_size('single-post', 220, 170, true);

function codex_custom_init_products() {
  $labels_products = array(
    'name' => 'products',
    'singular_name' => 'products',
    'add_new' => 'Add new',
    'add_new_item' => 'Add new',
    'edit_item' => 'Edit product',
    'new_item' => 'Add new',
    'all_items' => 'All products',
    'view_item' => 'View products',
    'search_items' => 'Search products',
    'not_found' =>  'No products were found.',
    'not_found_in_trash' => 'No products were found in Trash', 
    'parent_item_colon' => '',
    'menu_name' => 'Products'
  );

$args_products = array(
    'labels' => $labels_products,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => array( 'slug' => 'products','with_front' => FALSE),
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => false,
    'menu_position' => null,

    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'has_archive', 'custom-fields'),
); 

register_post_type( 'products', $args_products );
}
add_action( 'init', 'codex_custom_init_products', 0);

// Localization
load_theme_textdomain('cp', TEMPLATEPATH.'/lang/');


// load admin menu
require_once ( TEMPLATEPATH . '/admin/admin-menu.php');


// Register Sidebar
if ( function_exists('register_sidebar') ) 
{
   register_sidebar(array(
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget' => '</div><!-- #END widgetcontent --></div><!-- #END widget --><div class="clear"></div>',
		'before_title' => '<h2 class="widgettitle">',
		'after_title' => '</h2><div class="widgetcontent">',
   ));
}


// remove nofollow attribute
function remove_nofollow($string) 
{
	$string = str_ireplace(' rel="nofollow"', '', $string);
	return $string;
}
add_filter('the_content', 'remove_nofollow');
add_filter('comment_text', 'remove_nofollow');


// the new search widget
function cp_search_widget() 
{
	?>
	<div class="widget">
		<h2 class="widgettitle"><?php _e('Search', 'cp'); ?></h2>
		<div class="widgetcontent">
			<div class="widgetsearchform"><?php include(TEMPLATEPATH.'/searchform.php');?></div>
		</div>
	</div>
	<div class="clear"></div>
	<?php
}
register_sidebar_widget('CP Search', 'cp_search_widget');


// unregister the standard search widget
function cp_unregister_widgets() 
{
	unregister_widget('WP_Widget_Search');         
}
add_action('widgets_init', 'cp_unregister_widgets');  



// Add support for post thumbnails -- only WP 2.9+
if ( function_exists('add_theme_support') ) 
{
	add_theme_support('post-thumbnails');
	set_post_thumbnail_size(150,150);
}


// new comment function
function cp_comment_author_link() 
{
	$comment_author_link = get_comment_author_link();
	if ( ereg(']* class=[^>]+>', $comment_author_link) ) 
	{
		$comment_author_link = ereg_replace('(]* class=[\'"]?)', '\\1url ' , $comment_author_link );
	} 
	else 
	{
		$comment_author_link = ereg_replace('(<a )/', '\\1class="url "' , $comment_author_link );
	}
    echo $comment_author_link;
}


function cp_comment_author_avatar() 
{
	$email = get_comment_author_email();
	$avatar = str_replace("class='avatar", "class='photo avatar", get_avatar("$email", "42" ) );
	echo $avatar;
}


function cp_comments( $comment, $args, $depth ) 
{

	$GLOBALS['comment'] = $comment; ?>
                 
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
		
		<a name="comment-<?php comment_ID() ?>"></a>
		
		<div class="comment-meta">
      
			<span class="name"><?php cp_comment_author_avatar(); ?></span>

			<?php if ( (get_comment_type() == "comment") ) { cp_comment_author_link(); } ?>
			<?php if ( (get_comment_type() == "pingback") or (get_comment_type() == "trackback") ) { ?><?php cp_comment_author_link(); ?><br /><?php } ?>
      	
			<?php if ( (get_comment_type() == "comment") or (get_comment_type() == "pingback") or (get_comment_type() == "trackback") ) { ?>
           		
				<span class="comment-date"> <?php _e('on', 'cp'); ?> <?php echo get_comment_date( __('F jS, Y', 'cp') ); ?> <?php _e('at', 'cp'); ?> <?php echo get_comment_time(); ?></span>
				<span class="edit"><?php edit_comment_link( __('Edit', 'cp'), '', '' ); ?></span>
				<span class="permalink"><a class="comment-permalink" href="<?php echo get_comment_link(); ?>" title="<?php _e('Direct link to this comment', 'cp'); ?>">#</a></span>
           		
			<?php } ?>
	     
		</div>
    	
		<div class="comment-entry" id="comment-<?php comment_ID(); ?>">
			
			<?php comment_text() ?>

			<?php if ( $comment->comment_approved == '0') { ?> <p class='comment-unapproved'><?php _e('Your comment is awaiting moderation.', 'cp'); ?></p> <?php } ?>
			
			<div class="comment-reply">

				<?php comment_reply_link( array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']) ) ) ?>

			</div>
			
		</div>

		<div class="clear"></div>   

	<?php 
} 

/* ------------------------ */
/*  define some shortcodes  */
/*  used in footer text     */
/* ------------------------ */

function cp_shortcode_copyright()
{
	return sprintf('&copy; %1$s <a href="%2$s" title="%3$s">%3$s</a> ', date('Y'), get_bloginfo('url'), get_bloginfo('name') );
}

function cp_shortcode_wordpress()
{
	return sprintf('%1$s <a href="http://wordpress.org" title="Wordpress">Wordpress</a> ', __('Powered by', 'cp') );
}

function cp_shortcode_credit()
{
	return sprintf('%1$s <a target="_blank" href="http://cproell.de/" title="Christian Proell">CP-Themes</a> ', __('Theme by', 'cp') );
}

add_shortcode ('copyright', 'cp_shortcode_copyright'); 
add_shortcode ('wordpress', 'cp_shortcode_wordpress');
add_shortcode ('credit', 'cp_shortcode_credit');


?>
