<?php
    //
    // trackback.php
    //
    // uses the 'PHP Trackback' class to implement MovableType's TrackBack specification
    //
    //
    include('cl_trackback.php');
    global $siteSettings;
     
    
	// Get permissions *once*
    if (isInGroup($CURRENTUSER, "admin"))
    {
        $verifyEditDelete = true;
    }
    else
    {
        $verifyEditDelete = false;
    } 





    switch($action ):
     
    case "g_default":
    
	drawMainTop();
    $blogid = $_GET['id'];
     
     
    $file = explode("/" , $_SERVER['SCRIPT_NAME'] );
    array_pop($file );
    $path = implode("/", $file );
     
    if ($_SERVER['SERVER_PORT'] == '80' )
        $website = "http://" . $_SERVER['SERVER_NAME'] . $path;
    else
        $website = "http://" . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $path;
     
     
     
    if ($siteSettings['slickurls'] == TRUE )
        $tburl = $siteSettings['siteurl'] . "/trackback/" . $blogid;
    else
        $tburl = $website . "/trackback.php?id=" . $blogid;
     
     
     
    print("<div class='quote'>");
    print("The TrackBack URL for this post is: " . $tburl );
    print("</div>");
    print("<br />");
    $references = mysql_query("SELECT * FROM trackbacks WHERE refID='" . $blogid . "'");
     
    while ($row = mysql_fetch_array($references ))
    {
		//
		// If you do not wish to follow Google's rel="nofollow" anti-spam effort, delete the rel='nofollow' from the TrackBack link
		// below.  
		//
        print(" <a href='" . $row['url'] . "' rel='nofollow' ><strong>" . $row['title'] . "</strong></a> at " . $row['blog_name'] . "<br />");
        print( $row['excerpt'] );

		if ($verifyEditDelete)
        {
			print("<small>");
            if( $siteSettings['slickurls'] == TRUE )
				print "<a href='" . $siteSettings['siteurl'] . "/index.php?shard=trackback&amp;action=delete&amp;id=" . $row['ID'] . "'>   [ Delete ]</a>";
			else
				print "<a href='index.php?shard=trackback&amp;action=delete&amp;id=" . $row['ID'] . "'>   [ Delete ]</a>";
            print("</small>");
        }

		print("<br /><br />");
	}
    drawMainBottom();
    break;
     
	//-------------------------------------------------------------------------------------
    // delete - delete a blog entry
    //-------------------------------------------------------------------------------------
    case "delete":
	
	$blogid = $_GET['id'];
	
	//We know blogid is the ID of the trackback to be deleted.  When we finish deleting we want
	//to emit a header() to take us to the original screen.  For that we need the refID of the parent
	$reference = mysql_query("SELECT refID FROM trackbacks WHERE ID='" . $blogid . "'");
	$refarray = mysql_fetch_row($reference );
    $refID = $refarray[ 0 ];

	if (isInGroup($CURRENTUSER, "admin"))
    {
		
        if ($siteSettings['slickurls'] == TRUE )
			$trackback = $siteSettings['siteurl'] . "/blog/trackback/" . $refID;
        else
            $trackback = "index.php?shard=trackback&action=g_default&id=" . $refID;

        $result = mysql_query("DELETE FROM trackbacks WHERE ID=" . $blogid );
         
		header("Location: " . $trackback );
		
    }
    break;



    case "g_ping":
    if (isInGroup($CURRENTUSER, "admin"))
    {
        drawMainTop();
         
        if ($siteSettings['slickurls'] == TRUE )
            $formaction = $siteSettings['siteurl'] . "/index.php?shard=trackback&amp;action=proc_new";
        else
            $formaction = 'index.php?shard=trackback&amp;action=proc_new';
         
         
        print("
            Create New TrackBack<br /><br />
            <form action=" . $formaction . " method=POST>
            
			Your Website Name:
            <br />
            <input class='titleinput' type='text' name='blogtitle' />
            TrackBack Ping Title:
            <br />
            <input class='titleinput' type='text' name='pingtitle' />
            TrackBack Ping URL:
            <br />
            <input class='titleinput' type='text' name='pingurl' />
            Permanet URL:
            <br />
            <input class='titleinput' type='text' name='permurl' />
            <br />
			Excerpt:
			<textarea class='bodyinput' name='excerpt' rows='10' cols='40'></textarea>
            <br />
            <input type='Submit' class='button' name='Submit' value='Submit' /></form>");
         
         
        drawMainBottom();
    }
    break;
     
    case "proc_new":
    
	$ping = $_REQUEST['pingurl'];
    $perm = $_REQUEST['permurl'];
    $title = $_REQUEST['pingtitle'];
	$blogtitle = $_REQUEST['blogtitle'];
    $excerpt = $_REQUEST['excerpt'];
    
	$trackback = new Trackback( $blogtitle ,'', 'UTF-8');
    $trackback->ping($ping , $perm , $title, $excerpt );
     
    if ($siteSettings['slickurls'] == TRUE )
        header("Location: " . $siteSettings['siteurl'] . "/blog");
    else
        header("Location: index.php?shard=blog");
       
    break;
     
    endswitch;
     
     
?>
